fdoc

subroutinecompare_twoprivate

subroutine compare_two(c, op, a, b, holds)

One comparison.

Arguments

NameTypeIntentAttributesDescription
ctype(fypp_t)inout

the state

opintegerin

the comparison

atype(value_t)in

the first operand

btype(value_t)in

the second operand

holdslogicalout

the result

Calls

Source

Show the code
subroutine compare_two(c, op, a, b, holds)
    type(fypp_t), intent(inout) :: c    !! the state
    integer, intent(in) :: op           !! the comparison
    type(value_t), intent(in) :: a      !! the first operand
    type(value_t), intent(in) :: b      !! the second operand
    logical, intent(out) :: holds       !! the result
    integer :: k, step

    holds = .false.
    select case (op)
    case (C_EQ)
        holds = equal(a, b)
    case (C_NE)
        holds = .not. equal(a, b)
    case (C_IN, C_NOT_IN)
        if (b%kind == V_STR .and. a%kind == V_STR) then
            holds = index(b%text, a%text) > 0
        else if (b%kind == V_LIST .or. b%kind == V_TUPLE .or. b%kind == V_DICT) then
            step = merge(2, 1, b%kind == V_DICT)
            do k = 1, size(b%items), step
                if (equal(a, b%items(k))) holds = .true.
            end do
        else
            call fail(c, "the right operand of 'in' cannot be searched")
        end if
        if (op == C_NOT_IN) holds = .not. holds
    case default
        if (a%kind == V_STR .and. b%kind == V_STR) then
            select case (op)
            case (C_LT); holds = llt(a%text, b%text)
            case (C_GT); holds = lgt(a%text, b%text)
            case (C_LE); holds = lle(a%text, b%text)
            case default; holds = lge(a%text, b%text)
            end select
        else if (a%kind == V_STR .or. b%kind == V_STR .or. a%kind > V_INT .or. b%kind > V_INT) then
            call fail(c, 'values cannot be ordered')
        else
            select case (op)
            case (C_LT); holds = a%number < b%number
            case (C_GT); holds = a%number > b%number
            case (C_LE); holds = a%number <= b%number
            case default; holds = a%number >= b%number
            end select
        end if
    end select
end subroutine compare_two

Graphs

Calls

Called by