fdoc

subroutinerender_callrecursiveprivate

recursive subroutine render_call(c, id, out, top)

Render a call: the block is the last positional argument.

Arguments

NameTypeIntentAttributesDescription
ctype(fypp_t)inout

the state

idintegerin

the node

outtype(buffer_t)inout

the output

toplogicalin

true if this is not going into a macro's result

Calls

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

Graphs

Calls

Called by