fdoc

subroutineadd_linksprivate

subroutine add_links(json, node, p, id)

Add the links of entity id to node.

Arguments

NameTypeIntentAttributesDescription
jsontype(json_core)inout

the JSON handler

nodetype(json_value)inpointer

the object

ptype(project_t)in

the project

idintegerin

the entity

Calls

Source

Show the code
subroutine add_links(json, node, p, id)
    type(json_core), intent(inout) :: json          !! the JSON handler
    type(json_value), pointer, intent(in) :: node   !! the object
    type(project_t), intent(in) :: p                !! the project
    integer, intent(in) :: id                       !! the entity
    type(string_t), allocatable :: names(:)
    integer :: k

    associate (e => p%list%box(id)%e)
        allocate (names(0))
        if (allocated(e%more%uses) .and. e%kind /= E_BOUNDPROC) then
            do k = 1, size(e%more%uses)
                call push(names, e%more%uses(k)%module)
            end do
            call add_list('uses', names)
        end if
        if (allocated(e%call_ids)) then
            names = [string_t ::]
            do k = 1, size(e%call_ids)
                call push(names, lowercase(p%list%box(e%call_ids(k))%e%name))
            end do
            if (allocated(e%more%unknown_calls)) then
                do k = 1, size(e%more%unknown_calls)
                    call push(names, e%more%unknown_calls(k)%s)
                end do
            end if
            call add_list('calls', names)
        end if
        if (allocated(e%more%binding_ids)) call add_ids('bindings', e%more%binding_ids, e%more%bindings)
        if (allocated(e%more%modproc_ids)) call add_ids('modprocs', e%more%modproc_ids, e%more%modprocs)
        if (e%kind == E_SUBMODULE) then
            if (e%ancestor_id > 0) call json%add(node, 'ancestor', lowercase(p%list%box(e%ancestor_id)%e%name))
        end if
        if (e%kind == E_TYPE .and. e%extends_id > 0) then
            call json%add(node, 'extends', lowercase(p%list%box(e%extends_id)%e%name))
        end if
    end associate

contains

    !> Add sorted `list` under `key`.
    subroutine add_list(key, list)
        character(len=*), intent(in) :: key                 !! the key
        type(string_t), allocatable, intent(inout) :: list(:)   !! the strings
        type(json_value), pointer :: array
        integer :: j

        call sort_strings(list)
        call json%create_array(array, key)
        call json%add(node, array)
        do j = 1, size(list)
            call json%add(array, '', list(j)%s)
        end do
    end subroutine add_list

    !> Add the names of `ids`, or of `fallback` where an id is 0, under `key`.
    subroutine add_ids(key, ids, fallback)
        character(len=*), intent(in) :: key         !! the key
        integer, intent(in) :: ids(:)               !! the entities
        type(string_t), intent(in) :: fallback(:)   !! the names as written
        type(string_t), allocatable :: list(:)
        integer :: j

        allocate (list(0))
        do j = 1, size(ids)
            if (ids(j) > 0) then
                call push(list, lowercase(p%list%box(ids(j))%e%name))
            else
                call push(list, lowercase(fallback(j)%s))
            end if
        end do
        call add_list(key, list)
    end subroutine add_ids

end subroutine add_links

Graphs

Calls

Called by