subroutinedefine_macrorecursiveprivate
recursive subroutine define_macro(c, id)
Define the macro of node id, evaluating its defaults now.
Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
| c | type(fypp_t) | inout | the state | |
| id | integer | in | the node |
Calls
Source
Show the code
recursive subroutine define_macro(c, id)
type(fypp_t), intent(inout) :: c !! the state
integer, intent(in) :: id !! the node
type(macro_t), allocatable :: grown(:)
type(value_t) :: v
integer :: k, n
if (c%num_macros == size(c%macros)) then
allocate (grown(2*c%num_macros))
do k = 1, c%num_macros
grown(k)%node = c%macros(k)%node
call move_alloc(c%macros(k)%params, grown(k)%params)
call move_alloc(c%macros(k)%has_default, grown(k)%has_default)
call move_alloc(c%macros(k)%defaults, grown(k)%defaults)
call move_alloc(c%macros(k)%captured, grown(k)%captured)
call move_alloc(c%macros(k)%values, grown(k)%values)
end do
call move_alloc(grown, c%macros)
end if
c%num_macros = c%num_macros + 1
n = size(c%nodes(id)%block%targets)
associate (m => c%macros(c%num_macros))
m%node = id
m%params = c%nodes(id)%block%targets
allocate (m%has_default(n), m%defaults(n))
m%has_default = c%nodes(id)%block%args > 0
end associate
do k = 1, n
if (c%nodes(id)%block%args(k) > 0) then
call evaluate(c, c%nodes(id)%block%args(k), c%macros(c%num_macros)%defaults(k))
end if
end do
if (c%frame > 0) then
c%macros(c%num_macros)%captured = c%frames(c%frame)%ids(:c%frames(c%frame)%n)
call copy_items(c%frames(c%frame)%values(:c%frames(c%frame)%n), c%macros(c%num_macros)%values)
else
allocate (c%macros(c%num_macros)%captured(0), c%macros(c%num_macros)%values(0))
end if
v%kind = V_MACRO
v%number = c%num_macros
call define(c, c%nodes(id)%name, v)
end subroutine define_macro