subroutinerender_callrecursiveprivate
recursive subroutine render_call(c, id, out, top)
Render a call: the block is the last positional argument.
Arguments
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
| c | type(fypp_t) | inout | the state | |
| id | integer | in | the node | |
| out | type(buffer_t) | inout | the output | |
| top | logical | in | true if this is not going into a macro's result |
Calls
- evaluate_args
- open_scope
- render_body
- close_scope
- take
- make_string
- lookup
- fail
- call_macro
- write_value
- record_span
- add
Source
Show the code
recursive subroutine render_call(c, id, out, top)
type(fypp_t), intent(inout) :: c !! the state
integer, intent(in) :: id !! the node
type(buffer_t), intent(inout) :: out !! the output
logical, intent(in) :: top !! true if this is not going into a macro's result
type(value_t), allocatable :: positional(:), by_keyword(:), args(:)
integer, allocatable :: keywords(:)
type(value_t) :: target, v
type(buffer_t) :: body
character(len=:), allocatable :: text
integer :: n, m, first
logical :: found
call evaluate_args(c, c%nodes(id)%expr, positional, n, keywords, by_keyword)
if (allocated(c%error)) return
call open_scope(c, c%frame)
if (allocated(c%error)) return
call render_body(c, c%nodes(id)%block%bodies(1), body, .false.)
call close_scope(c)
if (allocated(c%error)) return
call take(body, text)
m = len(text)
if (m > 0) then
if (text(m:m) == NL) m = m - 1
end if
allocate (args(n + 1))
args(1:n) = positional(1:n)
call make_string(text(:m), args(n + 1))
call lookup(c, c%nodes(id)%name, target, found)
if (.not. found) then
call fail(c, 'the macro '//c%names(c%nodes(id)%name)%s//' is not defined')
return
end if
if (target%kind /= V_MACRO) then
call fail(c, c%names(c%nodes(id)%name)%s//' is not a macro')
return
end if
call call_macro(c, target%number, args, keywords, by_keyword, v)
if (allocated(c%error)) return
first = out%n
call write_value(v, .false., out)
if (top) call record_span(c, first, out%n)
if (c%nodes(id)%on_lines) call add(out, NL)
end subroutine render_call