subroutinerun_clauserecursiveprivate
recursive subroutine run_clause(c, id, k, items, n)
Run clause k of comprehension id, collecting items.
Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
| c | type(fypp_t) | inout | the state | |
| id | integer | in | the comprehension | |
| k | integer | in | the clause | |
| items | type(value_t) | inout | allocatabledimension(:) | the items |
| n | integer | inout | how many there are |
Calls
Source
Show the code
recursive subroutine run_clause(c, id, k, items, n)
type(fypp_t), intent(inout) :: c !! the state
integer, intent(in) :: id !! the comprehension
integer, intent(in) :: k !! the clause
type(value_t), allocatable, intent(inout) :: items(:) !! the items
integer, intent(inout) :: n !! how many there are
type(value_t), allocatable :: list(:), grown(:)
type(value_t) :: iterable, test
integer :: j, m, clause, saved
logical :: keep
if (allocated(c%error)) return
if (k > size(c%exprs(id)%args)) then
if (n == size(items)) then
allocate (grown(2*n))
do j = 1, n
call move_value(items(j), grown(j))
end do
call move_alloc(grown, items)
end if
n = n + 1
call evaluate(c, c%exprs(id)%a, items(n))
return
end if
clause = c%exprs(id)%args(k)
call evaluate(c, c%exprs(clause)%a, iterable)
if (allocated(c%error)) return
call items_of(c, iterable, list)
if (allocated(c%error)) return
saved = c%num_bound
do j = 1, size(list)
c%num_bound = saved
call bind_targets(c, c%exprs(clause)%names, list(j))
keep = .true.
do m = 1, size(c%exprs(clause)%args)
call evaluate(c, c%exprs(clause)%args(m), test)
keep = keep .and. truth_of(test)
end do
if (keep) call run_clause(c, id, k + 1, items, n)
end do
c%num_bound = saved
end subroutine run_clause