Skip to content

Commit

Permalink
Merge branch 'nvidia_fix_01' of https://github.com/EmilyBourne/json-f…
Browse files Browse the repository at this point in the history
…ortran into develop
  • Loading branch information
jacobwilliams committed May 19, 2024
2 parents fff5372 + 7695f8c commit a6acfce
Showing 1 changed file with 32 additions and 39 deletions.
71 changes: 32 additions & 39 deletions src/json_value_module.F90
Original file line number Diff line number Diff line change
Expand Up @@ -9542,58 +9542,51 @@ end subroutine json_get_array
! This routine calls the user-specified [[json_traverse_callback_func]]
! for each element of the structure.

subroutine json_traverse(json,p,traverse_callback)
recursive subroutine json_traverse(json,p,traverse_callback)

implicit none

class(json_core),intent(inout) :: json
type(json_value),pointer,intent(in) :: p
procedure(json_traverse_callback_func) :: traverse_callback

logical(LK) :: finished !! can be used to stop the process

if (.not. json%exception_thrown) call traverse(p)

contains

recursive subroutine traverse(p)

!! recursive [[json_value]] traversal.

implicit none

type(json_value),pointer,intent(in) :: p
type(json_value),pointer :: element !! a child element
integer(IK) :: i !! counter
integer(IK) :: icount !! number of children

type(json_value),pointer :: element !! a child element
integer(IK) :: i !! counter
integer(IK) :: icount !! number of children
logical(LK) :: finished !! can be used to stop the process

if (json%exception_thrown) return
call traverse_callback(json,p,finished) ! first call for this object
if (finished) return
if (json%exception_thrown) return

!for arrays and objects, have to also call for all children:
if (p%var_type==json_array .or. p%var_type==json_object) then

icount = json%count(p) ! number of children
if (icount>0) then
element => p%children ! first one
do i = 1, icount ! call for each child
if (.not. associated(element)) then
call json%throw_exception('Error in json_traverse: '//&
'Malformed JSON linked list')
return
end if
call traverse(element)
if (finished .or. json%exception_thrown) exit
element => element%next
end do
end if
nullify(element)
!! recursive [[json_value]] traversal.

if (json%exception_thrown) return
call traverse_callback(json,p,finished) ! first call for this object
if (finished) return

!for arrays and objects, have to also call for all children:
if (p%var_type==json_array .or. p%var_type==json_object) then

print *, loc(p), associated(p)
icount = json%count(p) ! number of children
print *, icount
if (icount>0) then
print *, icount, ">0"
element => p%children ! first one
do i = 1, icount ! call for each child
if (.not. associated(element)) then
call json%throw_exception('Error in json_traverse: '//&
'Malformed JSON linked list')
return
end if
call json%traverse(element, traverse_callback)
if (finished .or. json%exception_thrown) exit
element => element%next
end do
end if
nullify(element)

end subroutine traverse
end if

end subroutine json_traverse
!*****************************************************************************************
Expand Down

0 comments on commit a6acfce

Please sign in to comment.