Search in sources :

Example 86 with Integer_Value

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

the class SubstrExpression method checkExpressionOperands.

/**
 * Checks the parameters of the expression and if they are valid in
 * their position in the expression or not.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param expectedValue
 *                the kind of value expected.
 * @param referenceChain
 *                a reference chain to detect cyclic references.
 */
private void checkExpressionOperands(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    final Expected_Value_type internalExpectation = Expected_Value_type.EXPECTED_DYNAMIC_VALUE.equals(expectedValue) ? Expected_Value_type.EXPECTED_TEMPLATE : expectedValue;
    Type_type tempType1 = null;
    Type_type tempType2 = null;
    Type_type tempType3 = null;
    IValue value1 = null;
    if (templateInstance1 != null) {
        final ITTCN3Template temp = templateInstance1.getTemplateBody();
        if (!Template_type.SPECIFIC_VALUE.equals(temp.getTemplatetype())) {
            templateInstance1.getLocation().reportSemanticError(OPERANDERROR1);
            setIsErroneous(true);
        }
        value1 = ((SpecificValue_Template) temp).getSpecificValue();
        value1.setLoweridToReference(timestamp);
        tempType1 = value1.getExpressionReturntype(timestamp, internalExpectation);
        switch(tempType1) {
            case TYPE_BITSTRING:
            case TYPE_HEXSTRING:
            case TYPE_OCTETSTRING:
            case TYPE_CHARSTRING:
            case TYPE_UCHARSTRING:
            case TYPE_SET_OF:
            case TYPE_SEQUENCE_OF:
                value1.getValueRefdLast(timestamp, internalExpectation, referenceChain);
                break;
            case TYPE_UNDEFINED:
                setIsErroneous(true);
                break;
            default:
                templateInstance1.getLocation().reportSemanticError(OPERANDERROR1);
                setIsErroneous(true);
                break;
        }
    }
    if (value2 != null) {
        value2.setLoweridToReference(timestamp);
        tempType2 = value2.getExpressionReturntype(timestamp, expectedValue);
        switch(tempType2) {
            case TYPE_INTEGER:
                final IValue last2 = value2.getValueRefdLast(timestamp, expectedValue, referenceChain);
                if (!last2.isUnfoldable(timestamp) && Value.Value_type.INTEGER_VALUE.equals(last2.getValuetype())) {
                    if (((Integer_Value) last2).isNative()) {
                        final long i = ((Integer_Value) last2).getValue();
                        if (i < 0) {
                            value2.getLocation().reportSemanticError(OPERANDERROR3);
                            setIsErroneous(true);
                        }
                    } else {
                        value2.getLocation().reportSemanticError(MessageFormat.format(OPERANDERROR9, ((Integer_Value) last2).getValueValue()));
                        setIsErroneous(true);
                    }
                }
                break;
            case TYPE_UNDEFINED:
                setIsErroneous(true);
                break;
            default:
                location.reportSemanticError(OPERANDERROR2);
                setIsErroneous(true);
                break;
        }
    }
    if (value3 != null) {
        value3.setLoweridToReference(timestamp);
        tempType3 = value3.getExpressionReturntype(timestamp, expectedValue);
        switch(tempType3) {
            case TYPE_INTEGER:
                final IValue last3 = value3.getValueRefdLast(timestamp, expectedValue, referenceChain);
                if (!last3.isUnfoldable(timestamp) && Value.Value_type.INTEGER_VALUE.equals(last3.getValuetype())) {
                    if (((Integer_Value) last3).isNative()) {
                        final long i = ((Integer_Value) last3).getValue();
                        if (i < 0) {
                            value3.getLocation().reportSemanticError(OPERANDERROR5);
                            setIsErroneous(true);
                        }
                    } else {
                        value3.getLocation().reportSemanticError(MessageFormat.format(OPERANDERROR10, ((Integer_Value) last3).getValueValue()));
                        setIsErroneous(true);
                    }
                }
                break;
            case TYPE_UNDEFINED:
                setIsErroneous(true);
                break;
            default:
                location.reportSemanticError(OPERANDERROR4);
                setIsErroneous(true);
                break;
        }
    }
    checkExpressionOperandsHelper(timestamp, value1, expectedValue, referenceChain);
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) IValue(org.eclipse.titan.designer.AST.IValue) Type_type(org.eclipse.titan.designer.AST.IType.Type_type) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Expected_Value_type(org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type)

Example 87 with Integer_Value

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

the class GreaterThanExpression 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:
            {
                lastValue = new Boolean_Value(((Integer_Value) last1).compareTo((Integer_Value) last2) > 0);
                lastValue.copyGeneralProperties(this);
                break;
            }
        case REAL_VALUE:
            {
                final double float1 = ((Real_Value) last1).getValue();
                final double float2 = ((Real_Value) last2).getValue();
                lastValue = new Boolean_Value(Double.compare(float1, float2) > 0);
                lastValue.copyGeneralProperties(this);
                break;
            }
        case ENUMERATED_VALUE:
            {
                IType governor1 = last1.getExpressionGovernor(timestamp, expectedValue);
                governor1 = governor1.getTypeRefdLast(timestamp);
                IType governor2 = last2.getExpressionGovernor(timestamp, expectedValue);
                governor2 = governor2.getTypeRefdLast(timestamp);
                if (governor1 instanceof TTCN3_Enumerated_Type) {
                    final EnumItem item1 = ((TTCN3_Enumerated_Type) governor1).getEnumItemWithName(((Enumerated_Value) last1).getValue());
                    final EnumItem item2 = ((TTCN3_Enumerated_Type) governor2).getEnumItemWithName(((Enumerated_Value) last2).getValue());
                    lastValue = new Boolean_Value(((Integer_Value) item1.getValue()).intValue() > ((Integer_Value) item2.getValue()).intValue());
                    lastValue.copyGeneralProperties(this);
                } else {
                    final EnumItem item1 = ((ASN1_Enumerated_Type) governor1).getEnumItemWithName(((Enumerated_Value) last1).getValue());
                    final EnumItem item2 = ((ASN1_Enumerated_Type) governor2).getEnumItemWithName(((Enumerated_Value) last2).getValue());
                    lastValue = new Boolean_Value(((Integer_Value) item1.getValue()).intValue() > ((Integer_Value) item2.getValue()).intValue());
                    lastValue.copyGeneralProperties(this);
                }
                break;
            }
        default:
            setIsErroneous(true);
    }
    return lastValue;
}
Also used : Boolean_Value(org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value) IValue(org.eclipse.titan.designer.AST.IValue) TTCN3_Enumerated_Type(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Enumerated_Type) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) EnumItem(org.eclipse.titan.designer.AST.TTCN3.types.EnumItem) Enumerated_Value(org.eclipse.titan.designer.AST.TTCN3.values.Enumerated_Value) IType(org.eclipse.titan.designer.AST.IType)

Example 88 with Integer_Value

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

the class Hex2IntExpression method hex2int.

public static Integer_Value hex2int(final String hexString) {
    final byte[] bytes = hexString.getBytes();
    int startIndex = 0;
    while (startIndex < bytes.length && '0' == bytes[startIndex]) {
        startIndex++;
    }
    BigInteger result = BigInteger.ZERO;
    for (int i = startIndex; i < bytes.length; i++) {
        result = result.shiftLeft(4);
        result = result.add(BigInteger.valueOf(BitstringUtilities.charToHexdigit(bytes[i])));
    }
    return new Integer_Value(result);
}
Also used : Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) BigInteger(java.math.BigInteger)

Example 89 with Integer_Value

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

the class Int2BitExpression method checkExpressionOperands.

/**
 * Checks the parameters of the expression and if they are valid in
 * their position in the expression or not.
 *
 * @param timestamp
 *                the timestamp of the actual semantic check cycle.
 * @param expectedValue
 *                the kind of value expected.
 * @param referenceChain
 *                a reference chain to detect cyclic references.
 */
private void checkExpressionOperands(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    if (value1 == null || value2 == null) {
        return;
    }
    IValue last1 = null;
    IValue last2 = null;
    value1.setLoweridToReference(timestamp);
    final Type_type tempType1 = value1.getExpressionReturntype(timestamp, expectedValue);
    switch(tempType1) {
        case TYPE_INTEGER:
            last1 = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
            if (!last1.isUnfoldable(timestamp) && Value.Value_type.INTEGER_VALUE.equals(last1.getValuetype())) {
                if (((Integer_Value) last1).signum() < 0) {
                    value1.getLocation().reportSemanticError(OPERANDERROR2);
                    setIsErroneous(true);
                }
            }
            break;
        case TYPE_UNDEFINED:
            setIsErroneous(true);
            break;
        default:
            if (!isErroneous) {
                location.reportSemanticError(OPERANDERROR1);
                setIsErroneous(true);
            }
            break;
    }
    value2.setLoweridToReference(timestamp);
    final Type_type tempType2 = value2.getExpressionReturntype(timestamp, expectedValue);
    switch(tempType2) {
        case TYPE_INTEGER:
            last2 = value2.getValueRefdLast(timestamp, expectedValue, referenceChain);
            if (!last2.isUnfoldable(timestamp) && Value.Value_type.INTEGER_VALUE.equals(last2.getValuetype())) {
                if (((Integer_Value) last2).isNative()) {
                    final int i2 = ((Integer_Value) last2).intValue();
                    if (i2 < 0) {
                        value2.getLocation().reportSemanticError(OPERANDERROR4);
                        setIsErroneous(true);
                    } else if (last1 != null && !last1.isUnfoldable(timestamp) && Value.Value_type.INTEGER_VALUE.equals(last1.getValuetype())) {
                        final Integer_Value i1 = (Integer_Value) last1;
                        if ((i1.shiftRight(i2).compareTo(new Integer_Value(0))) > 0) {
                            location.reportSemanticError(MessageFormat.format(OPERANDERROR5, i1.intValue(), i2));
                            setIsErroneous(true);
                        }
                    }
                } else {
                    value2.getLocation().reportSemanticError(MessageFormat.format(OPERANDERROR6, ((Integer_Value) last2).getValueValue()));
                    setIsErroneous(true);
                }
            }
            break;
        case TYPE_UNDEFINED:
            setIsErroneous(true);
            break;
        default:
            if (!isErroneous) {
                location.reportSemanticError(OPERANDERROR3);
                setIsErroneous(true);
            }
            break;
    }
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Type_type(org.eclipse.titan.designer.AST.IType.Type_type) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)

Example 90 with Integer_Value

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

the class UnaryMinusExpression 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 (value == null) {
        return lastValue;
    }
    checkExpressionOperands(timestamp, expectedValue, referenceChain);
    if (getIsErroneous(timestamp) || isUnfoldable(timestamp, referenceChain)) {
        return lastValue;
    }
    final IValue last = value.getValueRefdLast(timestamp, referenceChain);
    if (last.getIsErroneous(timestamp)) {
        setIsErroneous(true);
        return lastValue;
    }
    switch(last.getValuetype()) {
        case INTEGER_VALUE:
            lastValue = ((Integer_Value) last).negate();
            lastValue.copyGeneralProperties(this);
            break;
        case REAL_VALUE:
            final double tempFloat = ((Real_Value) last).getValue();
            lastValue = new Real_Value(-1 * tempFloat);
            lastValue.copyGeneralProperties(this);
            break;
        default:
            setIsErroneous(true);
            break;
    }
    return lastValue;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Real_Value(org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)

Aggregations

IValue (org.eclipse.titan.designer.AST.IValue)91 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)87 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)23 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)19 IType (org.eclipse.titan.designer.AST.IType)17 Charstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value)15 Real_Value (org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)15 BigInteger (java.math.BigInteger)13 Bitstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Bitstring_Value)12 Value (org.eclipse.titan.designer.AST.Value)12 Octetstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value)11 ISubReference (org.eclipse.titan.designer.AST.ISubReference)10 Identifier (org.eclipse.titan.designer.AST.Identifier)10 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)9 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)9 Hexstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Hexstring_Value)9 HashMap (java.util.HashMap)8 Boolean_Value (org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value)8 UniversalCharstring (org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring)8 UniversalCharstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value)8