fdoc

subroutineparse_file

subroutine parse_file(path, text, s, list)

Parse source text of file path into list, whose first entity is the file.

Arguments

NameTypeIntentAttributesDescription
pathcharacter(len=*)in

the file

textcharacter(len=*)in

the text to parse

stype(settings_t)in

the settings

listtype(entity_list_t)out

the entities

Calls

Source

Show the code
subroutine parse_file(path, text, s, list)
    character(len=*), intent(in) :: path        !! the file
    character(len=*), intent(in) :: text        !! the text to parse
    type(settings_t), intent(in) :: s           !! the settings
    type(entity_list_t), intent(out) :: list    !! the entities
    type(source_t) :: src
    type(statement_view_t), allocatable :: views(:)
    type(structure_t) :: st
    type(diagnostic_t), allocatable :: diags(:)
    type(doc_lines_t), allocatable :: docs(:)
    type(string_t), allocatable :: file_doc(:)
    type(association_t), allocatable :: associations(:)
    character(len=:), allocatable :: line
    integer :: stack(0:MAX_DEPTH)
    integer :: top, k, root, current, id, depth, caller, level

    call parse_source(text, src)
    call set_views(src, views)
    call analyze_structure(src, views, st, diags)
    call collect_docs(src, s, docs, file_doc)

    root = list%add(E_FILE, 0)
    list%box(root)%e%name = path
    list%box(root)%e%file = root
    call set_doc(list%box(root)%e, s, file_doc)
    call inherit_display(list, root, s)
    stack(0) = root
    top = 0
    level = 0
    allocate (associations(0))

    do k = 1, src%stmts%n
        if (src%stmts%s(k)%kind /= SK_CODE) cycle
        associate (info => st%info(k))
            ! fformat knows the structure, including what a statement label closes: close what it
            ! says is closed here. A middle statement such as `contains` is at its construct's depth.
            depth = st%depth(k)
            if (info%role == ROLE_MIDDLE) depth = depth + 1
            do while (top > depth)
                if (stack(top) > 0) call close_unit(list, stack(top), s)
                top = top - 1
            end do
            current = stack(top)
            caller = nearest_caller(list, stack, top)
            if (caller > 0) call statement_calls(views(k), info, list%box(caller)%e, associations, level)
            select case (info%role)
            case (ROLE_OPEN)
                id = 0
                if (current > 0) then
                    call statement_text(src, k, line)
                    call open_unit(list, current, info%construct, line, k, src, docs(k), s, id)
                end if
                if (top < MAX_DEPTH) then
                    top = top + 1
                    stack(top) = id
                end if
            case (ROLE_MIDDLE)
                if (current > 0 .and. info%construct == C_CONTAINS) then
                    list%box(current)%e%in_contains = .true.
                    if (list%box(current)%e%kind == E_TYPE) list%box(current)%e%child_permission = 'public'
                end if
            case (ROLE_CLOSE)
                continue
            case default
                if (current > 0) then
                    call statement_text(src, k, line)
                    call parse_statement(list, current, line, docs(k), s)
                end if
            end select
        end associate
    end do
    do while (top > 0)
        if (stack(top) > 0) call close_unit(list, stack(top), s)
        top = top - 1
    end do
end subroutine parse_file

Graphs

Calls

Called by