fdoc

subroutinefind_type_usesprivate

subroutine find_type_uses(site)

Find where each type is used, once, so that the page of a type does not search the whole project. A specific procedure counts as its generic, which often is the only one with a page. The methods of a type are left out, as each of them takes it, and so are local variables.

Arguments

NameTypeIntentAttributesDescription
sitetype(site_t)inout

the site

Calls

Called by

Source

Show the code
subroutine find_type_uses(site)
    type(site_t), intent(inout) :: site     !! the site
    integer, allocatable :: generic_of(:)
    integer :: k, j, slots, parent, owner

    associate (list => site%p%list)
        allocate (site%use_slot(list%n), source=0)
        allocate (generic_of(list%n), source=0)
        slots = 0
        do k = 1, list%n
            associate (e => list%box(k)%e)
                if (e%kind == E_TYPE) then
                    slots = slots + 1
                    site%use_slot(k) = slots
                else if (e%kind == E_INTERFACE .and. allocated(e%more%modproc_ids)) then
                    do j = 1, size(e%more%modproc_ids)
                        if (e%more%modproc_ids(j) > 0) generic_of(e%more%modproc_ids(j)) = k
                    end do
                end if
            end associate
        end do
        allocate (site%type_uses(slots))
        do k = 1, list%n
            associate (v => list%box(k)%e)
                if (v%kind /= E_VARIABLE .or. v%proto_id == 0 .or. v%parent == 0) cycle
                if (site%use_slot(v%proto_id) == 0) cycle
                parent = v%parent
                associate (uses => site%type_uses(site%use_slot(v%proto_id)), up => list%box(parent)%e)
                    select case (up%kind)
                    case (E_TYPE)
                        if (parent /= v%proto_id .and. is_shown(list, parent)) call add_use(uses%components, parent)
                    case (E_MODULE, E_SUBMODULE)
                        if (is_shown(list, k)) call add_use(uses%variables, k)
                    case (E_SUBROUTINE, E_FUNCTION, E_MODPROC)
                        if (up%bound_to == v%proto_id) cycle
                        owner = parent
                        if (list%box(up%parent)%e%kind == E_INTERFACE) owner = up%parent
                        if (generic_of(parent) > 0) owner = generic_of(parent)
                        if (.not. is_shown(list, owner)) cycle
                        if (up%result == k) then
                            call add_use(uses%results, owner)
                        else if (allocated(up%more%arg_ids)) then
                            if (findloc(up%more%arg_ids, k, 1) > 0) call add_use(uses%arguments, owner)
                        end if
                    end select
                end associate
            end associate
        end do
        do k = 1, slots
            associate (uses => site%type_uses(k))
                call sort_by_name(list, uses%arguments)
                call sort_by_name(list, uses%results)
                call sort_by_name(list, uses%components)
                call sort_by_name(list, uses%variables)
            end associate
        end do
    end associate
end subroutine find_type_uses