Search in sources :

Example 16 with Real_Value

use of org.eclipse.titan.designer.AST.TTCN3.values.Real_Value in project titan.EclipsePlug-ins by eclipse.

the class SubType method addTtcnRange.

private boolean addTtcnRange(final CompilationTimeStamp timestamp, final Value min, final boolean minExclusive, final Value max, final boolean maxExclusive, final int restrictionIndex) {
    switch(subtypeType) {
        case ST_INTEGER:
        case ST_FLOAT:
        case ST_CHARSTRING:
        case ST_UNIVERSAL_CHARSTRING:
            break;
        default:
            myOwner.getLocation().reportSemanticError(MessageFormat.format("Range subtyping is not allowed for type `{0}''", myOwner.getTypename()));
            return false;
    }
    if (min == null || max == null) {
        return false;
    }
    IValue vmin = null, vmax = null;
    min.setMyScope(myOwner.getMyScope());
    min.setMyGovernor(myOwner);
    BridgingNamedNode bridge = new BridgingNamedNode(myOwner, myOwner.getFullName() + ".<range_restriction_" + restrictionIndex + "_lower>");
    min.setFullNameParent(bridge);
    IValue last = myOwner.checkThisValueRef(timestamp, min);
    IType lastOwner = myOwner.getTypeRefdLast(timestamp);
    if (lastOwner instanceof Integer_Type) {
        ((Integer_Type) lastOwner).checkThisValueLimit(timestamp, last, Expected_Value_type.EXPECTED_CONSTANT, false, false, false, false);
    } else {
        myOwner.checkThisValue(timestamp, last, null, new ValueCheckingOptions(Expected_Value_type.EXPECTED_CONSTANT, false, false, false, false, false));
    }
    IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    vmin = last.getValueRefdLast(timestamp, chain);
    chain.release();
    max.setMyScope(myOwner.getMyScope());
    max.setMyGovernor(myOwner);
    bridge = new BridgingNamedNode(myOwner, myOwner.getFullName() + ".<range_restriction_" + restrictionIndex + "_upper>");
    max.setFullNameParent(bridge);
    last = myOwner.checkThisValueRef(timestamp, max);
    lastOwner = myOwner.getTypeRefdLast(timestamp);
    if (lastOwner instanceof Integer_Type) {
        ((Integer_Type) lastOwner).checkThisValueLimit(timestamp, last, Expected_Value_type.EXPECTED_CONSTANT, false, false, false, false);
    } else {
        myOwner.checkThisValue(timestamp, last, null, new ValueCheckingOptions(Expected_Value_type.EXPECTED_CONSTANT, false, false, false, false, false));
    }
    chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    vmax = last.getValueRefdLast(timestamp, chain);
    chain.release();
    if (vmin.getIsErroneous(timestamp) || vmin.isUnfoldable(timestamp)) {
        // the error was already reported
        return false;
    }
    if (vmax.getIsErroneous(timestamp) || vmax.isUnfoldable(timestamp)) {
        // the error was already reported
        return false;
    }
    SubtypeConstraint rangeConstraint;
    switch(subtypeType) {
        case ST_INTEGER:
            {
                IntegerLimit minLimit;
                if (Value_type.REAL_VALUE.equals(vmin.getValuetype())) {
                    final Real_Value real = (Real_Value) vmin;
                    if (real.isNegativeInfinity()) {
                        minLimit = IntegerLimit.MINIMUM;
                    } else {
                        minLimit = IntegerLimit.MAXIMUM;
                    }
                } else {
                    minLimit = new IntegerLimit(((Integer_Value) vmin).getValueValue());
                }
                IntegerLimit maxLimit;
                if (Value_type.REAL_VALUE.equals(vmax.getValuetype())) {
                    final Real_Value real = (Real_Value) vmax;
                    if (real.isPositiveInfinity()) {
                        maxLimit = IntegerLimit.MAXIMUM;
                    } else {
                        maxLimit = IntegerLimit.MINIMUM;
                    }
                } else {
                    maxLimit = new IntegerLimit(((Integer_Value) vmax).getValueValue());
                }
                if (minExclusive) {
                    if (minLimit.compareTo(IntegerLimit.MINIMUM) == 0) {
                        myOwner.getLocation().reportSemanticError("invalid lower boundary, -infinity cannot be excluded from an integer subtype range");
                        return false;
                    }
                    if (minLimit.compareTo(IntegerLimit.MAXIMUM) == 0) {
                        myOwner.getLocation().reportSemanticError("!infinity is not a valid lower boundary");
                        return false;
                    }
                    minLimit = (IntegerLimit) minLimit.increment();
                }
                if (maxExclusive) {
                    if (maxLimit.compareTo(IntegerLimit.MAXIMUM) == 0) {
                        myOwner.getLocation().reportSemanticError("invalid upper boundary, infinity cannot be excluded from an integer subtype range");
                        return false;
                    }
                    if (maxLimit.compareTo(IntegerLimit.MINIMUM) == 0) {
                        myOwner.getLocation().reportSemanticError("!-infinity is not a valid upper boundary");
                        return false;
                    }
                    maxLimit = (IntegerLimit) maxLimit.decrement();
                }
                if (maxLimit.compareTo(minLimit) < 0) {
                    Location.interval(min.getLocation(), max.getLocation()).reportSemanticError("lower boundary is bigger than upper boundary in integer subtype range");
                    return false;
                }
                rangeConstraint = new RangeListConstraint(minLimit, maxLimit);
                break;
            }
        case ST_FLOAT:
            {
                if (Double.isNaN(((Real_Value) vmin).getValue())) {
                    min.getLocation().reportSemanticError("lower boundary cannot be not_a_number in float subtype range");
                    return false;
                }
                if (Double.isNaN(((Real_Value) vmax).getValue())) {
                    max.getLocation().reportSemanticError("upper boundary cannot be not_a_number in float subtype range");
                    return false;
                }
                RealLimit minLimit = new RealLimit(((Real_Value) vmin).getValue());
                RealLimit maxLimit = new RealLimit(((Real_Value) vmax).getValue());
                if (minExclusive) {
                    if (minLimit.compareTo(RealLimit.MAXIMUM) == 0) {
                        myOwner.getLocation().reportSemanticError("!infinity is not a valid lower boundary");
                        return false;
                    }
                    minLimit = (RealLimit) minLimit.increment();
                }
                if (maxExclusive) {
                    if (maxLimit.compareTo(RealLimit.MINIMUM) == 0) {
                        myOwner.getLocation().reportSemanticError("!-infinity is not a valid upper boundary");
                        return false;
                    }
                    maxLimit = (RealLimit) maxLimit.decrement();
                }
                if (maxLimit.compareTo(minLimit) < 0) {
                    Location.interval(min.getLocation(), max.getLocation()).reportSemanticError("lower boundary is bigger than upper boundary in float subtype range");
                    return false;
                }
                rangeConstraint = new RealRangeListConstraint(minLimit, maxLimit);
                break;
            }
        case ST_CHARSTRING:
            {
                boolean erroneous = false;
                if (Value_type.REAL_VALUE.equals(vmin.getValuetype()) && ((Real_Value) vmin).isNegativeInfinity()) {
                    getParsedLocation().reportSemanticError("lower boundary of a charstring subtype range cannot be -infinity");
                    erroneous = true;
                }
                if (Value_type.REAL_VALUE.equals(vmax.getValuetype()) && ((Real_Value) vmax).isPositiveInfinity()) {
                    getParsedLocation().reportSemanticError("upper boundary of a charstring subtype range cannot be infinity");
                    erroneous = true;
                }
                if (erroneous) {
                    return false;
                }
                String minString;
                switch(vmin.getValuetype()) {
                    case CHARSTRING_VALUE:
                        minString = ((Charstring_Value) vmin).getValue();
                        break;
                    case UNIVERSALCHARSTRING_VALUE:
                        {
                            final UniversalCharstring ustr = ((UniversalCharstring_Value) vmin).getValue();
                            if ((ustr.length() < 1) || !ustr.get(0).isValidChar()) {
                                min.getLocation().reportSemanticError("lower boundary of charstring subtype range is not a valid char");
                                return false;
                            }
                            minString = String.valueOf((char) ustr.get(0).cell());
                            break;
                        }
                    default:
                        return false;
                }
                String maxString;
                switch(vmax.getValuetype()) {
                    case CHARSTRING_VALUE:
                        maxString = ((Charstring_Value) vmax).getValue();
                        break;
                    case UNIVERSALCHARSTRING_VALUE:
                        {
                            final UniversalCharstring ustr = ((UniversalCharstring_Value) vmax).getValue();
                            if ((ustr.length() < 1) || !ustr.get(0).isValidChar()) {
                                max.getLocation().reportSemanticError("upper boundary of charstring subtype range is not a valid char");
                                return false;
                            }
                            maxString = String.valueOf((char) ustr.get(0).cell());
                            break;
                        }
                    default:
                        return false;
                }
                if (minString.length() != 1) {
                    min.getLocation().reportSemanticError("lower boundary of charstring subtype range must be a single element string");
                    return false;
                }
                if (maxString.length() != 1) {
                    max.getLocation().reportSemanticError("upper boundary of charstring subtype range must be a single element string");
                    return false;
                }
                CharLimit minLimit = new CharLimit(minString.charAt(0));
                CharLimit maxLimit = new CharLimit(maxString.charAt(0));
                if (minExclusive) {
                    if (minLimit.compareTo(CharLimit.MAXIMUM) == 0) {
                        min.getLocation().reportSemanticError("exclusive lower boundary is not a legal charstring character");
                        return false;
                    }
                    minLimit = (CharLimit) minLimit.increment();
                }
                if (maxExclusive) {
                    if (maxLimit.compareTo(CharLimit.MINIMUM) == 0) {
                        max.getLocation().reportSemanticError("exclusive upper boundary is not a legal charstring character");
                        return false;
                    }
                    maxLimit = (CharLimit) maxLimit.decrement();
                }
                if (maxLimit.compareTo(minLimit) < 0) {
                    Location.interval(min.getLocation(), max.getLocation()).reportSemanticError("lower boundary is bigger than upper boundary in charstring subtype range");
                    return false;
                }
                rangeConstraint = new StringSetConstraint(StringSubtypeTreeElement.StringType.CHARSTRING, StringSetConstraint.ConstraintType.ALPHABET_CONSTRAINT, new RangeListConstraint(minLimit, maxLimit));
                break;
            }
        case ST_UNIVERSAL_CHARSTRING:
            {
                boolean erroneous = false;
                if (Value_type.REAL_VALUE.equals(vmin.getValuetype()) && ((Real_Value) vmin).isNegativeInfinity()) {
                    min.getLocation().reportSemanticError("lower boundary of a universal charstring subtype range cannot be -infinity");
                    erroneous = true;
                }
                if (Value_type.REAL_VALUE.equals(vmax.getValuetype()) && ((Real_Value) vmax).isPositiveInfinity()) {
                    max.getLocation().reportSemanticError("upper boundary of a universal charstring subtype range cannot be infinity");
                    erroneous = true;
                }
                if (erroneous) {
                    return false;
                }
                UniversalCharstring minString;
                switch(vmin.getValuetype()) {
                    case CHARSTRING_VALUE:
                        minString = new UniversalCharstring(((Charstring_Value) vmin).getValue());
                        break;
                    case UNIVERSALCHARSTRING_VALUE:
                        minString = ((UniversalCharstring_Value) vmin).getValue();
                        break;
                    default:
                        return false;
                }
                UniversalCharstring maxString;
                switch(vmax.getValuetype()) {
                    case CHARSTRING_VALUE:
                        maxString = new UniversalCharstring(((Charstring_Value) vmax).getValue());
                        break;
                    case UNIVERSALCHARSTRING_VALUE:
                        maxString = ((UniversalCharstring_Value) vmax).getValue();
                        break;
                    default:
                        return false;
                }
                if (minString.length() != 1) {
                    min.getLocation().reportSemanticError("lower boundary of universal charstring subtype range must be a single element string");
                    return false;
                }
                if (maxString.length() != 1) {
                    max.getLocation().reportSemanticError("upper boundary of universal charstring subtype range must be a single element string");
                    return false;
                }
                UCharLimit minLimit = new UCharLimit(minString.get(0));
                UCharLimit maxLimit = new UCharLimit(maxString.get(0));
                if (minExclusive) {
                    if (minLimit.compareTo(UCharLimit.MAXIMUM) == 0) {
                        min.getLocation().reportSemanticError("exclusive lower boundary is not a legal universal charstring character");
                        return false;
                    }
                    minLimit = (UCharLimit) minLimit.increment();
                }
                if (maxExclusive) {
                    if (maxLimit.compareTo(UCharLimit.MINIMUM) == 0) {
                        max.getLocation().reportSemanticError("exclusive upper boundary is not a legal universal charstring character");
                        return false;
                    }
                    maxLimit = (UCharLimit) maxLimit.decrement();
                }
                if (maxLimit.compareTo(minLimit) < 0) {
                    Location.interval(min.getLocation(), max.getLocation()).reportSemanticError("lower boundary is bigger than upper boundary in universal charstring subtype range");
                    return false;
                }
                rangeConstraint = new StringSetConstraint(StringSubtypeTreeElement.StringType.UNIVERSAL_CHARSTRING, StringSetConstraint.ConstraintType.ALPHABET_CONSTRAINT, new RangeListConstraint(minLimit, maxLimit));
                break;
            }
        default:
            ErrorReporter.INTERNAL_ERROR();
            return false;
    }
    subtypeConstraint = (subtypeConstraint == null) ? rangeConstraint : subtypeConstraint.union(rangeConstraint);
    return true;
}
Also used : UniversalCharstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value) PatternString(org.eclipse.titan.designer.AST.TTCN3.templates.PatternString) UniversalCharstring(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring) BridgingNamedNode(org.eclipse.titan.designer.AST.BridgingNamedNode) IType(org.eclipse.titan.designer.AST.IType) Real_Value(org.eclipse.titan.designer.AST.TTCN3.values.Real_Value) IValue(org.eclipse.titan.designer.AST.IValue) Integer_Type(org.eclipse.titan.designer.AST.TTCN3.types.Integer_Type) Charstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value) UniversalCharstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) ValueCheckingOptions(org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)

Example 17 with Real_Value

use of org.eclipse.titan.designer.AST.TTCN3.values.Real_Value in project titan.EclipsePlug-ins by eclipse.

the class SubType method checkThisValue.

/**
 * Checks if a given value is valid according to this sub-type.
 *
 * @param timestamp
 *                the time stamp of the actual semantic check cycle.
 * @param value
 *                the value to be checked
 */
public void checkThisValue(final CompilationTimeStamp timestamp, final IValue value) {
    if (getIsErroneous(timestamp) || (subtypeConstraint == null)) {
        return;
    }
    if (value.getIsErroneous(timestamp)) {
        return;
    }
    final IValue last = value.getValueRefdLast(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, null);
    if (last.getIsErroneous(timestamp)) {
        return;
    }
    boolean isValid = true;
    switch(last.getValuetype()) {
        case INTEGER_VALUE:
            if (subtypeType != SubType_type.ST_INTEGER) {
                ErrorReporter.INTERNAL_ERROR();
                return;
            }
            isValid = subtypeConstraint.isElement(new IntegerLimit(((Integer_Value) last).getValueValue()));
            break;
        case REAL_VALUE:
            if (subtypeType == SubType_type.ST_FLOAT) {
                isValid = subtypeConstraint.isElement(((Real_Value) last).getValue());
                break;
            } else if (subtypeType == SubType_type.ST_INTEGER) {
                final Real_Value real = (Real_Value) last;
                if (real.isNegativeInfinity()) {
                    isValid = subtypeConstraint.isElement(IntegerLimit.MINIMUM);
                    break;
                } else if (real.isPositiveInfinity()) {
                    isValid = subtypeConstraint.isElement(IntegerLimit.MAXIMUM);
                    break;
                }
            }
            ErrorReporter.INTERNAL_ERROR();
            return;
        case BOOLEAN_VALUE:
            if (subtypeType != SubType_type.ST_BOOLEAN) {
                ErrorReporter.INTERNAL_ERROR();
                return;
            }
            isValid = subtypeConstraint.isElement(((Boolean_Value) last).getValue());
            break;
        case VERDICT_VALUE:
            if (subtypeType != SubType_type.ST_VERDICTTYPE) {
                ErrorReporter.INTERNAL_ERROR();
                return;
            }
            isValid = subtypeConstraint.isElement(((Verdict_Value) last).getValue());
            break;
        case BITSTRING_VALUE:
            if (subtypeType != SubType_type.ST_BITSTRING) {
                ErrorReporter.INTERNAL_ERROR();
                return;
            }
            isValid = subtypeConstraint.isElement(((Bitstring_Value) last).getValue());
            break;
        case HEXSTRING_VALUE:
            if (subtypeType != SubType_type.ST_HEXSTRING) {
                ErrorReporter.INTERNAL_ERROR();
                return;
            }
            isValid = subtypeConstraint.isElement(((Hexstring_Value) last).getValue());
            break;
        case OCTETSTRING_VALUE:
            if (subtypeType != SubType_type.ST_OCTETSTRING) {
                ErrorReporter.INTERNAL_ERROR();
                return;
            }
            isValid = subtypeConstraint.isElement(((Octetstring_Value) last).getValue());
            break;
        case CHARSTRING_VALUE:
            switch(subtypeType) {
                case ST_CHARSTRING:
                    isValid = subtypeConstraint.isElement(((Charstring_Value) last).getValue());
                    break;
                case ST_UNIVERSAL_CHARSTRING:
                    isValid = subtypeConstraint.isElement(new UniversalCharstring(((Charstring_Value) last).getValue()));
                    break;
                default:
                    ErrorReporter.INTERNAL_ERROR();
                    return;
            }
            break;
        case UNIVERSALCHARSTRING_VALUE:
            if (subtypeType != SubType_type.ST_UNIVERSAL_CHARSTRING) {
                ErrorReporter.INTERNAL_ERROR();
                return;
            }
            isValid = subtypeConstraint.isElement(((UniversalCharstring_Value) last).getValue());
            break;
        case SEQUENCEOF_VALUE:
        case SETOF_VALUE:
        case OBJECTID_VALUE:
        case ENUMERATED_VALUE:
        case CHOICE_VALUE:
        case SEQUENCE_VALUE:
        case SET_VALUE:
        case FUNCTION_REFERENCE_VALUE:
        case ALTSTEP_REFERENCE_VALUE:
        case TESTCASE_REFERENCE_VALUE:
            if (value.isUnfoldable(timestamp)) {
                return;
            }
            isValid = subtypeConstraint.isElement(last);
            break;
        default:
            return;
    }
    if (!isValid) {
        value.getLocation().reportSemanticError(MessageFormat.format("{0} is not a valid value for type `{1}'' which has subtype {2}", last.createStringRepresentation(), myOwner.getTypename(), subtypeConstraint.toString()));
    }
}
Also used : Hexstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Hexstring_Value) UniversalCharstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value) Boolean_Value(org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value) IValue(org.eclipse.titan.designer.AST.IValue) Bitstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Bitstring_Value) Charstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value) UniversalCharstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value) Verdict_Value(org.eclipse.titan.designer.AST.TTCN3.values.Verdict_Value) UniversalCharstring(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring) Real_Value(org.eclipse.titan.designer.AST.TTCN3.values.Real_Value) Octetstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value)

Example 18 with Real_Value

use of org.eclipse.titan.designer.AST.TTCN3.values.Real_Value in project titan.EclipsePlug-ins by eclipse.

the class DivideExpression method evaluateValue.

@Override
public /**
 * {@inheritDoc}
 */
IValue evaluateValue(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return lastValue;
    }
    isErroneous = false;
    lastTimeChecked = timestamp;
    lastValue = this;
    if (value1 == null || value2 == null) {
        return lastValue;
    }
    checkExpressionOperands(timestamp, expectedValue, referenceChain);
    if (getIsErroneous(timestamp) || isUnfoldable(timestamp, referenceChain)) {
        return lastValue;
    }
    final IValue last1 = value1.getValueRefdLast(timestamp, referenceChain);
    final IValue last2 = value2.getValueRefdLast(timestamp, referenceChain);
    if (last1.getIsErroneous(timestamp) || last2.getIsErroneous(timestamp)) {
        setIsErroneous(true);
        return lastValue;
    }
    switch(last1.getValuetype()) {
        case INTEGER_VALUE:
            // If the operands exist they must be of the same type.
            lastValue = ((Integer_Value) last1).divide((Integer_Value) last2);
            lastValue.copyGeneralProperties(this);
            break;
        case REAL_VALUE:
            final double f1 = ((Real_Value) last1).getValue();
            final double f2 = ((Real_Value) last2).getValue();
            lastValue = new Real_Value(f1 / f2);
            lastValue.copyGeneralProperties(this);
            break;
        default:
            setIsErroneous(true);
            break;
    }
    return lastValue;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Real_Value(org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)

Example 19 with Real_Value

use of org.eclipse.titan.designer.AST.TTCN3.values.Real_Value in project titan.EclipsePlug-ins by eclipse.

the class Start_Timer_Statement method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    lastTimeChecked = timestamp;
    checkTimerReference(timestamp, timerReference);
    if (timerValue == null) {
        final Assignment assignment = timerReference.getRefdAssignment(timestamp, true);
        if (assignment != null && Assignment_type.A_TIMER.semanticallyEquals(assignment.getAssignmentType())) {
            final Def_Timer defTimer = (Def_Timer) assignment;
            if (!defTimer.hasDefaultDuration(timestamp, timerReference)) {
                location.reportSemanticError(MessageFormat.format(MISSINGDEFAULTDURATION, assignment.getDescription()));
            }
        }
    } else {
        timerValue.setLoweridToReference(timestamp);
        final Type_type temporalType = timerValue.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
        switch(temporalType) {
            case TYPE_REAL:
                {
                    final IValue last = timerValue.getValueRefdLast(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, null);
                    if (!last.isUnfoldable(timestamp)) {
                        final Real_Value real = (Real_Value) last;
                        final double val = real.getValue();
                        if (val < 0.0) {
                            timerValue.getLocation().reportSemanticError(MessageFormat.format(NEGATIVEDURATION, real));
                        } else if (real.isPositiveInfinity()) {
                            timerValue.getLocation().reportSemanticError(MessageFormat.format(INFINITYDURATION, real.createStringRepresentation()));
                        }
                    }
                    return;
                }
            case TYPE_UNDEFINED:
                return;
            default:
                timerValue.getLocation().reportSemanticError(FLOATEXPECTED);
                return;
        }
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) IValue(org.eclipse.titan.designer.AST.IValue) Def_Timer(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Timer) Type_type(org.eclipse.titan.designer.AST.IType.Type_type) Real_Value(org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)

Example 20 with Real_Value

use of org.eclipse.titan.designer.AST.TTCN3.values.Real_Value in project titan.EclipsePlug-ins by eclipse.

the class Testcase_Instance_Statement method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    lastTimeChecked = timestamp;
    if (testcaseReference == null) {
        return;
    }
    final Assignment assignment = testcaseReference.getRefdAssignment(timestamp, true);
    if (assignment == null) {
        return;
    }
    if (!Assignment_type.A_TESTCASE.semanticallyEquals(assignment.getAssignmentType())) {
        testcaseReference.getLocation().reportSemanticError(MessageFormat.format(TESTCASEEXPECTED, assignment.getFullName()));
        return;
    }
    if (myStatementBlock.getScopeRunsOn() != null) {
        testcaseReference.getLocation().reportSemanticError(DEFINITIONWITHOUTRUNSONEXPECTED);
        return;
    }
    if (timerValue != null) {
        timerValue.setLoweridToReference(timestamp);
        final Type_type temporalType = timerValue.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
        switch(temporalType) {
            case TYPE_REAL:
                final IValue last = timerValue.getValueRefdLast(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, null);
                if (!last.isUnfoldable(timestamp)) {
                    final Real_Value real = (Real_Value) last;
                    final double i = real.getValue();
                    if (i < 0.0) {
                        timerValue.getLocation().reportSemanticError(MessageFormat.format(NEGATIVEDURATION, real.createStringRepresentation()));
                    } else if (real.isPositiveInfinity()) {
                        timerValue.getLocation().reportSemanticError(MessageFormat.format(FLOATEXPECTED2, real.createStringRepresentation()));
                    }
                }
                break;
            default:
                timerValue.getLocation().reportSemanticError(FLOATEXPECTED);
                break;
        }
    }
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) IValue(org.eclipse.titan.designer.AST.IValue) Type_type(org.eclipse.titan.designer.AST.IType.Type_type) Real_Value(org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)

Aggregations

IValue (org.eclipse.titan.designer.AST.IValue)33 Real_Value (org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)27 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)14 IType (org.eclipse.titan.designer.AST.IType)9 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)9 Boolean_Value (org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value)6 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)5 TTCN3_Enumerated_Type (org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Enumerated_Type)5 Charstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value)5 Assignment (org.eclipse.titan.designer.AST.Assignment)4 EnumItem (org.eclipse.titan.designer.AST.TTCN3.types.EnumItem)4 Enumerated_Value (org.eclipse.titan.designer.AST.TTCN3.values.Enumerated_Value)4 UniversalCharstring (org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring)3 UniversalCharstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value)3 BridgingNamedNode (org.eclipse.titan.designer.AST.BridgingNamedNode)2 ValueCheckingOptions (org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)2 Reference (org.eclipse.titan.designer.AST.Reference)2 ActualParameterList (org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList)2 FormalParameterList (org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList)2 Integer_Type (org.eclipse.titan.designer.AST.TTCN3.types.Integer_Type)2