Search in sources :

Example 6 with Integer_Type

use of org.eclipse.titan.designer.AST.TTCN3.types.Integer_Type in project titan.EclipsePlug-ins by eclipse.

the class RangeLenghtRestriction method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    lastTimeChecked = timestamp;
    final Integer_Type integer = new Integer_Type();
    lower.setMyGovernor(integer);
    IValue last = integer.checkThisValueRef(timestamp, lower);
    integer.checkThisValueLimit(timestamp, last, expectedValue, false, false, true, false);
    IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    final IValue valueLower = last.getValueRefdLast(timestamp, chain);
    chain.release();
    if (last.getIsErroneous(timestamp)) {
        return;
    }
    BigInteger lowerInt;
    switch(valueLower.getValuetype()) {
        case INTEGER_VALUE:
            {
                lowerInt = ((Integer_Value) valueLower).getValueValue();
                if (lowerInt.compareTo(BigInteger.ZERO) == -1) {
                    final String message = MessageFormat.format("The lower boundary of the length restriction must be a non-negative integer value instead of {0}", lowerInt);
                    valueLower.getLocation().reportSemanticError(message);
                }
                break;
            }
        default:
            lowerInt = BigInteger.ZERO;
            break;
    }
    if (upper == null) {
        return;
    }
    upper.setMyGovernor(integer);
    last = integer.checkThisValueRef(timestamp, upper);
    integer.checkThisValueLimit(timestamp, last, expectedValue, false, false, true, false);
    chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    final IValue valueUpper = last.getValueRefdLast(timestamp, chain);
    chain.release();
    if (last.getIsErroneous(timestamp)) {
        return;
    }
    BigInteger upperInt;
    switch(valueUpper.getValuetype()) {
        case INTEGER_VALUE:
            {
                upperInt = ((Integer_Value) valueUpper).getValueValue();
                if (upperInt.compareTo(BigInteger.ZERO) == -1) {
                    final String message = MessageFormat.format("The upper boundary of the length restriction must be a non-negative integer value instead of {0}", upperInt);
                    valueUpper.getLocation().reportSemanticError(message);
                } else if (upperInt.compareTo(lowerInt) == -1) {
                    getLocation().reportSemanticError(MessageFormat.format("The upper boundary of the length restriction ({0}) cannot be smaller than the lower boundary {1}", upperInt, lowerInt));
                }
                break;
            }
        default:
            break;
    }
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Integer_Type(org.eclipse.titan.designer.AST.TTCN3.types.Integer_Type) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) BigInteger(java.math.BigInteger)

Example 7 with Integer_Type

use of org.eclipse.titan.designer.AST.TTCN3.types.Integer_Type in project titan.EclipsePlug-ins by eclipse.

the class SingleLenghtRestriction method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    lastTimeChecked = timestamp;
    if (value == null) {
        return;
    }
    final Integer_Type integer = new Integer_Type();
    value.setMyGovernor(integer);
    IValue last = integer.checkThisValueRef(timestamp, value);
    integer.checkThisValue(timestamp, last, null, new ValueCheckingOptions(expectedValue, false, false, true, false, false));
    final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    last = last.getValueRefdLast(timestamp, chain);
    chain.release();
    if (last.getIsErroneous(timestamp)) {
        return;
    }
    switch(last.getValuetype()) {
        case INTEGER_VALUE:
            {
                final BigInteger temp = ((Integer_Value) last).getValueValue();
                if (temp.compareTo(BigInteger.ZERO) == -1) {
                    value.getLocation().reportSemanticError(MessageFormat.format("The length restriction must be a non-negative integer value instead of {0}", temp));
                    value.setIsErroneous(true);
                }
                break;
            }
        default:
            break;
    }
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Integer_Type(org.eclipse.titan.designer.AST.TTCN3.types.Integer_Type) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) BigInteger(java.math.BigInteger) ValueCheckingOptions(org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)

Aggregations

Integer_Type (org.eclipse.titan.designer.AST.TTCN3.types.Integer_Type)7 IValue (org.eclipse.titan.designer.AST.IValue)4 Referenced_Type (org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type)4 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)3 Def_Type (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type)3 CharString_Type (org.eclipse.titan.designer.AST.TTCN3.types.CharString_Type)3 SequenceOf_Type (org.eclipse.titan.designer.AST.TTCN3.types.SequenceOf_Type)3 SetOf_Type (org.eclipse.titan.designer.AST.TTCN3.types.SetOf_Type)3 TTCN3_Enumerated_Type (org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Enumerated_Type)3 Range_ParsedSubType (org.eclipse.titan.designer.AST.TTCN3.types.subtypes.Range_ParsedSubType)3 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)3 Type (org.eclipse.titan.designer.AST.Type)3 BigInteger (java.math.BigInteger)2 IType (org.eclipse.titan.designer.AST.IType)2 ValueCheckingOptions (org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)2 Charstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value)2 Real_Value (org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)2 BridgingNamedNode (org.eclipse.titan.designer.AST.BridgingNamedNode)1 Reference (org.eclipse.titan.designer.AST.Reference)1 Def_Port (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Port)1