Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding to type_list pointer to last: type_list_item #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions src/fortran_yaml_c_types.f90
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ subroutine node_dump(self,unit,indent)

type,extends(type_node) :: type_list
type (type_list_item),pointer :: first => null()
type (type_list_item),pointer :: last => null()
contains
procedure :: append => list_append
procedure :: dump => list_dump
Expand Down Expand Up @@ -548,20 +549,16 @@ subroutine list_append(self, node)
class(type_list), intent(inout) :: self
class(type_node), target :: node

type(type_list_item), pointer :: item

if (.not.associated(self%first)) then
! This will be the first pair.
! This will be the first item.
allocate(self%first)
self%first%node => node
self%last => self%first
else
! Try to find a pair with the same key, or failing that, the last pair.
item => self%first
do while (associated(item%next))
item => item%next
end do
allocate(item%next)
item%next%node => node
! Append on the end of the list.
allocate(self%last%next)
self%last%next%node => node
self%last => self%last%next
end if
end subroutine

Expand Down