fdoc

subroutinelocate_in_fileprivate

subroutine locate_in_file(site, ids)

Find the code of entities ids, all from one file. They are in source order, so each search starts where the last one found something. Only the lines that name a construct are searched, as a name that is not in the file, like those Fypp makes, would otherwise cost two readings of the file.

Arguments

NameTypeIntentAttributesDescription
sitetype(site_t)inout

the site

idsintegerindimension(:)

the entities

Calls

Source

Show the code
subroutine locate_in_file(site, ids)
    type(site_t), intent(inout) :: site     !! the site
    integer, intent(in) :: ids(:)           !! the entities
    character(len=:), allocatable :: low
    integer, allocatable :: starts(:), stops(:)
    integer :: k, cursor, found, first, last

    ! on the heap and lowered in place, as a whole file would not fit on the stack of a thread
    low = site%p%list%box(site%p%list%box(ids(1))%e%file)%e%source_text
    call lower_in_place(low)
    call construct_lines(low, starts, stops)
    cursor = 1
    do k = 1, size(ids)
        associate (e => site%p%list%box(ids(k))%e)
            select case (e%kind)
            case (E_SUBROUTINE)
                call find_source(low, starts, stops, cursor, 'subroutine', lowercase(e%name), found, first, last)
                if (first == 0 .and. cursor > 1) &
                    call find_source(low, starts, stops, 1, 'subroutine', lowercase(e%name), found, first, last)
            case (E_FUNCTION)
                call find_source(low, starts, stops, cursor, 'function', lowercase(e%name), found, first, last)
                if (first == 0 .and. cursor > 1) &
                    call find_source(low, starts, stops, 1, 'function', lowercase(e%name), found, first, last)
            case default
                call find_source(low, starts, stops, cursor, 'type', lowercase(e%name), found, first, last)
                if (first == 0 .and. cursor > 1) &
                    call find_source(low, starts, stops, 1, 'type', lowercase(e%name), found, first, last)
            end select
            if (first == 0) cycle
            e%source_first = first
            e%source_last = last
            cursor = found
        end associate
    end do
end subroutine locate_in_file

Graphs

Calls

Called by