fdoc

subroutineimport_namesprivate

subroutine import_names(p, which, used, spec)

Add to module which what it makes public of what use with spec imports from module used.

Arguments

NameTypeIntentAttributesDescription
ptype(project_t)inout

the project

whichintegerin

position in p%modules of the importing module

usedintegerin

position in p%modules of the used module

speccharacter(len=*)in

what follows the module name

Calls

Source

Show the code
subroutine import_names(p, which, used, spec)
    type(project_t), intent(inout) :: p     !! the project
    integer, intent(in) :: which            !! position in `p%modules` of the importing module
    integer, intent(in) :: used             !! position in `p%modules` of the used module
    character(len=*), intent(in) :: spec    !! what follows the module name
    type(rename_t), allocatable :: renames(:)
    type(name_index_t) :: wanted
    logical :: only
    integer :: k

    call read_use_spec(spec, only, renames)
    do k = size(renames), 1, -1
        call index_set(wanted, renames(k)%used, k)
    end do
    call import_category(p%pub(used)%procs, p%pub(which)%procs)
    call import_category(p%pub(used)%absints, p%pub(which)%absints)
    call import_category(p%pub(used)%types, p%pub(which)%types)
    call import_category(p%pub(used)%vars, p%pub(which)%vars)

contains

    !> Import the names of one category.
    subroutine import_category(from, to)
        type(symbol_list_t), intent(in) :: from     !! the used module's names
        type(symbol_list_t), intent(inout) :: to    !! the importing module's names
        integer :: k, j

        do k = 1, from%n
            if (.not. only) then
                if (is_public_here(from%s(k)%name)) call add_symbol(to, from%s(k)%name, from%s(k)%id)
                cycle
            end if
            j = index_find(wanted, from%s(k)%name)
            if (j == 0) cycle
            if (is_public_here(renames(j)%local)) call add_symbol(to, renames(j)%local, from%s(k)%id)
        end do
    end subroutine import_category

    !> True if the importing module makes `name` public.
    logical function is_public_here(name)
        character(len=*), intent(in) :: name    !! the name
        is_public_here = p%list%box(p%modules(which))%e%permission == 'public' .or. &
                         index_find(p%pub(which)%public_list, name) > 0
    end function is_public_here

end subroutine import_names

Graphs

Calls

Called by