subroutinenew_nodeprivate
subroutine new_node(t, parent, tag, id)
Add a child with tag tag to node parent, returning it.
Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
| t | type(tree_t) | inout | the conversion | |
| parent | integer | in | the parent | |
| tag | character(len=*) | in | the tag | |
| id | integer | out | 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