fdoc

subroutinenew_nodeprivate

subroutine new_node(t, parent, tag, id)

Add a child with tag tag to node parent, returning it.

Arguments

NameTypeIntentAttributesDescription
ttype(tree_t)inout

the conversion

parentintegerin

the parent

tagcharacter(len=*)in

the tag

idintegerout

the new node

Calls

Source

Show the code
subroutine new_node(t, parent, tag, id)
    type(tree_t), intent(inout) :: t        !! the conversion
    integer, intent(in) :: parent           !! the parent
    character(len=*), intent(in) :: tag     !! the tag
    integer, intent(out) :: id              !! the new node
    type(node_t), allocatable :: grown(:)
    integer :: k

    if (t%n == size(t%nodes)) then
        allocate (grown(2*t%n))
        do k = 1, t%n
            call move_alloc(t%nodes(k)%tag, grown(k)%tag)
            call move_alloc(t%nodes(k)%text, grown(k)%text)
            call move_alloc(t%nodes(k)%attrs, grown(k)%attrs)
            call move_alloc(t%nodes(k)%kids, grown(k)%kids)
        end do
        call move_alloc(grown, t%nodes)
    end if
    t%n = t%n + 1
    id = t%n
    t%nodes(id)%tag = tag
    t%nodes(id)%text = ''
    t%nodes(id)%attrs = ''
    allocate (t%nodes(id)%kids(0))
    call push_int(t%nodes(parent)%kids, id)
end subroutine new_node

Graphs

Calls

Called by