fdoc

subroutineload_project_sources

subroutine load_project_sources(s, p, stat, errmsg)

Find, load and parse the source files, and merge the results into p.

Arguments

NameTypeIntentAttributesDescription
stype(settings_t)in

the settings

ptype(project_t)out

the project

statintegerout

nonzero on failure

errmsgcharacter(len=:)outallocatable

what is wrong

Calls

Called by

Source

Show the code
subroutine load_project_sources(s, p, stat, errmsg)
    type(settings_t), intent(in) :: s                   !! the settings
    type(project_t), intent(out) :: p                   !! the project
    integer, intent(out) :: stat                        !! nonzero on failure
    character(len=:), allocatable, intent(out) :: errmsg  !! what is wrong
    type(string_t), allocatable :: paths(:), texts(:), raws(:)
    type(entity_list_t), allocatable :: lists(:)
    integer :: k

    stat = 0
    call find_sources(s, paths)
    if (size(paths) == 0) then
        stat = 1
        errmsg = 'No source files with appropriate extension found in specified directory.'
        return
    end if
    allocate (texts(size(paths)), lists(size(paths)), raws(size(paths)))
    ! files that go through an external command share its temporary files, so they take turns
    call progress_start('Reading files', size(paths))
    !$omp parallel do schedule(dynamic) num_threads(max(1, s%parallel)) default(shared) private(k)
    do k = 1, size(paths)
        if (.not. runs_command(s, paths(k)%s)) call read_source(s, paths(k)%s, raws(k)%s, texts(k)%s)
        call progress_tick()
    end do
    !$omp end parallel do
    do k = 1, size(paths)
        if (runs_command(s, paths(k)%s)) call read_source(s, paths(k)%s, raws(k)%s, texts(k)%s)
        call expand_includes(s%include, parent_directory(paths(k)%s), texts(k)%s, 1)
    end do
    call progress_finish()

    call progress_start('Parsing files', size(paths))
    !$omp parallel do schedule(dynamic) num_threads(max(1, s%parallel)) default(shared)
    do k = 1, size(paths)
        call parse_file(paths(k)%s, texts(k)%s, s, lists(k))
        call progress_tick()
    end do
    !$omp end parallel do
    call progress_finish()

    do k = 1, size(lists)
        call move_alloc(raws(k)%s, lists(k)%box(1)%e%source_text)
        call merge_list(p, lists(k))
    end do
end subroutine load_project_sources