fdoc

subroutinetype_treeprivate

subroutine type_tree(site, b)

Write the types of the project as a tree, by what they extend, if any type extends another. A type that extends one from elsewhere is at the top, with what it extends.

Arguments

NameTypeIntentAttributesDescription
sitetype(site_t)in

the site

btype(buffer_t)inout

the HTML

Calls

Called by

Source

Show the code
subroutine type_tree(site, b)
    type(site_t), intent(in) :: site        !! the site
    type(buffer_t), intent(inout) :: b      !! the HTML
    type(index_list_t), allocatable :: children(:)
    integer, allocatable :: slot(:), roots(:)
    integer :: k, parent

    associate (types => site%members(LIST_TYPES)%ids, list => site%p%list)
        allocate (slot(list%n), source=0)
        do k = 1, size(types)
            slot(types(k)) = k
        end do
        allocate (children(size(types)), roots(0))
        do k = 1, size(types)
            parent = list%box(types(k))%e%extends_id
            if (parent > 0) then
                if (slot(parent) > 0 .and. parent /= types(k)) then
                    call push_int(children(slot(parent))%ids, types(k))
                    cycle
                end if
            end if
            call push_int(roots, types(k))
        end do
        if (size(roots) == size(types)) return
        call add(b, '<h2 id="hierarchy">Hierarchy</h2>'//achar(10)//'<ul class="tree types">')
        call sort_by_name(list, roots)
        do k = 1, size(roots)
            call tree_node(roots(k), 1)
        end do
        call add(b, '</ul>'//achar(10)//'<h2 id="all-types">All types</h2>'//achar(10))
    end associate

contains

    !> Write type `id` and what extends it.
    recursive subroutine tree_node(id, depth)
        integer, intent(in) :: id       !! the type
        integer, intent(in) :: depth    !! how deep it is, against a loop in what extends what

        associate (e => site%p%list%box(id)%e, here => slot(id))
            call add(b, '<li>')
            if (allocated(children(here)%ids) .and. depth < MAX_NESTING) call add(b, '<details open><summary>')
            call side_icon(e, b)
            call link_to(site, id, e%name, b)
            if (e%extends_id > 0 .and. depth == 1 .and. allocated(e%more%extends)) then
                call add(b, ' <span class="where">extends ')
                call link_to(site, e%extends_id, e%more%extends, b)
                call add(b, '</span>')
            end if
            if (allocated(children(here)%ids) .and. depth < MAX_NESTING) then
                call add(b, '</summary><ul>')
                call sort_by_name(site%p%list, children(here)%ids)
                block
                    integer :: j

                    do j = 1, size(children(here)%ids)
                        call tree_node(children(here)%ids(j), depth + 1)
                    end do
                end block
                call add(b, '</ul></details>')
            end if
            call add(b, '</li>')
        end associate
    end subroutine tree_node

end subroutine type_tree