fdoc

subroutineevaluate_slicerecursiveprivate

recursive subroutine evaluate_slice(c, id, v)

a[first:last].

Arguments

NameTypeIntentAttributesDescription
ctype(fypp_t)inout

the state

idintegerin

the expression

vtype(value_t)out

the result

Calls

Source

Show the code
recursive subroutine evaluate_slice(c, id, v)
    type(fypp_t), intent(inout) :: c    !! the state
    integer, intent(in) :: id           !! the expression
    type(value_t), intent(out) :: v     !! the result
    type(value_t) :: a, bound
    integer :: n, first, last

    call evaluate(c, c%exprs(id)%a, a)
    if (allocated(c%error)) return
    select case (a%kind)
    case (V_STR); n = len(a%text)
    case (V_LIST, V_TUPLE); n = size(a%items)
    case default
        call fail(c, 'a value cannot be sliced')
        return
    end select
    first = 0
    last = n
    if (c%exprs(id)%b > 0) then
        call evaluate(c, c%exprs(id)%b, bound)
        first = bound%number
    end if
    if (c%exprs(id)%c > 0) then
        call evaluate(c, c%exprs(id)%c, bound)
        last = bound%number
    end if
    if (first < 0) first = max(first + n, 0)
    if (last < 0) last = max(last + n, 0)
    first = min(first, n)
    last = min(last, n)
    if (a%kind == V_STR) then
        call make_string(a%text(first + 1:last), v)
    else
        v%kind = a%kind
        call copy_items(a%items(first + 1:last), v%items)
    end if
end subroutine evaluate_slice

Graphs

Calls

Called by