Search in sources :

Example 66 with Integer_Value

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

the class RemainderExpression 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 == null || last2 == null) {
        setIsErroneous(true);
        return lastValue;
    }
    switch(last1.getValuetype()) {
        case INTEGER_VALUE:
            lastValue = ((Integer_Value) last1).remainder((Integer_Value) last2);
            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)

Example 67 with Integer_Value

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

the class RemainderExpression 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) {
    Type_type tempType1 = null;
    Type_type tempType2 = null;
    if (value1 != null) {
        value1.setLoweridToReference(timestamp);
        tempType1 = value1.getExpressionReturntype(timestamp, expectedValue);
        switch(tempType1) {
            case TYPE_INTEGER:
                value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
                break;
            case TYPE_UNDEFINED:
                setIsErroneous(true);
                break;
            default:
                value1.getLocation().reportSemanticError(FIRSTOPERANDERROR);
                setIsErroneous(true);
                break;
        }
    }
    if (value2 != null) {
        value2.setLoweridToReference(timestamp);
        tempType2 = value2.getExpressionReturntype(timestamp, expectedValue);
        switch(tempType2) {
            case TYPE_INTEGER:
                final IValue lastValue = value2.getValueRefdLast(timestamp, expectedValue, referenceChain);
                if (lastValue != null && !lastValue.isUnfoldable(timestamp) && Value.Value_type.INTEGER_VALUE.equals(lastValue.getValuetype())) {
                    if (((Integer_Value) lastValue).equals(new Integer_Value(0))) {
                        value2.getLocation().reportSemanticError(ZEROOPERANDERROR);
                        setIsErroneous(true);
                    }
                }
                break;
            case TYPE_UNDEFINED:
                setIsErroneous(true);
                break;
            default:
                value2.getLocation().reportSemanticError(SECONDOPERANDERROR);
                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 68 with Integer_Value

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

the class ReplaceExpression 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;
    IValue value1 = null;
    if (templateInstance1 != null) {
        final ITTCN3Template temp = templateInstance1.getTemplateBody();
        switch(temp.getTemplatetype()) {
            case SPECIFIC_VALUE:
                break;
            case TEMPLATE_LIST:
            case NAMED_TEMPLATE_LIST:
            case INDEXED_TEMPLATE_LIST:
                templateInstance1.getLocation().reportSemanticError(OPERANDERROR13);
                setIsErroneous(true);
                return;
            default:
                templateInstance1.getLocation().reportSemanticError(OPERANDERROR5);
                setIsErroneous(true);
                return;
        }
        // temp is specific value:
        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(OPERANDERROR5);
                setIsErroneous(true);
                break;
        }
    }
    if (value2 != null) {
        value2.setLoweridToReference(timestamp);
        final Type_type 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(OPERANDERROR11, ((Integer_Value) last2).getValueValue()));
                        setIsErroneous(true);
                    }
                }
                break;
            case TYPE_UNDEFINED:
                setIsErroneous(true);
                break;
            default:
                value2.getLocation().reportSemanticError(OPERANDERROR1);
                setIsErroneous(true);
                break;
        }
    }
    if (value3 != null) {
        value3.setLoweridToReference(timestamp);
        final Type_type 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(OPERANDERROR4);
                            setIsErroneous(true);
                        }
                    } else {
                        value3.getLocation().reportSemanticError(MessageFormat.format(OPERANDERROR12, ((Integer_Value) last3).getValueValue()));
                        setIsErroneous(true);
                    }
                }
                break;
            case TYPE_UNDEFINED:
                setIsErroneous(true);
                break;
            default:
                value3.getLocation().reportSemanticError(OPERANDERROR2);
                setIsErroneous(true);
                break;
        }
    }
    Type_type tempType4 = null;
    IValue value4 = null;
    if (templateInstance4 != null) {
        final ITTCN3Template temp = templateInstance4.getTemplateBody();
        switch(temp.getTemplatetype()) {
            case SPECIFIC_VALUE:
                value4 = ((SpecificValue_Template) temp).getSpecificValue();
                break;
            case TEMPLATE_LIST:
                if (!((Template_List) temp).isValue(timestamp)) {
                    templateInstance4.getLocation().reportSemanticError(OPERANDERROR6);
                    setIsErroneous(true);
                    return;
                }
            case NAMED_TEMPLATE_LIST:
            case INDEXED_TEMPLATE_LIST:
                tempType4 = templateInstance4.getExpressionReturntype(timestamp, expectedValue);
                if (Type_type.TYPE_UNDEFINED.equals(tempType4)) {
                    templateInstance4.getLocation().reportSemanticError(OPERANDERROR13);
                }
                return;
            default:
                templateInstance4.getLocation().reportSemanticError(OPERANDERROR6);
                setIsErroneous(true);
                return;
        }
        value4.setLoweridToReference(timestamp);
        tempType4 = value4.getExpressionReturntype(timestamp, internalExpectation);
        switch(tempType4) {
            case TYPE_BITSTRING:
            case TYPE_HEXSTRING:
            case TYPE_OCTETSTRING:
            case TYPE_CHARSTRING:
            case TYPE_UCHARSTRING:
            case TYPE_SET_OF:
            case TYPE_SEQUENCE_OF:
                value4.getValueRefdLast(timestamp, internalExpectation, referenceChain);
                break;
            case TYPE_UNDEFINED:
                setIsErroneous(true);
                break;
            default:
                location.reportSemanticError(OPERANDERROR6);
                setIsErroneous(true);
                break;
        }
    }
    if (tempType1 != null && tempType4 != null && !tempType1.equals(tempType4) && !getIsErroneous(timestamp)) {
        location.reportSemanticError(OPERANDERROR7);
        setIsErroneous(true);
    }
    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 69 with Integer_Value

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

the class ReplaceExpression 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 (templateInstance1 == null || value2 == null || value3 == null || templateInstance4 == null) {
        setIsErroneous(true);
        return lastValue;
    }
    checkExpressionOperands(timestamp, expectedValue, referenceChain);
    if (getIsErroneous(timestamp)) {
        return lastValue;
    }
    if (isUnfoldable(timestamp, referenceChain)) {
        return lastValue;
    }
    ITTCN3Template temp = templateInstance1.getTemplateBody();
    final IValue value1 = ((SpecificValue_Template) temp).getSpecificValue();
    final IValue v1 = value1.getValueRefdLast(timestamp, referenceChain);
    final IValue v2 = value2.getValueRefdLast(timestamp, referenceChain);
    final IValue v3 = value3.getValueRefdLast(timestamp, referenceChain);
    temp = templateInstance4.getTemplateBody();
    final IValue value4 = ((SpecificValue_Template) temp).getSpecificValue();
    final IValue v4 = value4.getValueRefdLast(timestamp, referenceChain);
    final Value_type vt = v1.getValuetype();
    final int index = ((Integer_Value) v2).intValue();
    final int len = ((Integer_Value) v3).intValue();
    switch(vt) {
        case BITSTRING_VALUE:
            {
                final String v1Str = ((Bitstring_Value) v1).getValue();
                final String v4Str = ((Bitstring_Value) v4).getValue();
                String result = v1Str.substring(0, index);
                result = result.concat(v4Str);
                result = result.concat(v1Str.substring(index + len));
                lastValue = new Bitstring_Value(result);
                lastValue.copyGeneralProperties(this);
                break;
            }
        case HEXSTRING_VALUE:
            {
                final String v1Str = ((Hexstring_Value) v1).getValue();
                final String v4Str = ((Hexstring_Value) v4).getValue();
                String result = v1Str.substring(0, index);
                result = result.concat(v4Str);
                result = result.concat(v1Str.substring(index + len));
                lastValue = new Hexstring_Value(result);
                lastValue.copyGeneralProperties(this);
                break;
            }
        case OCTETSTRING_VALUE:
            {
                final String v1Str = ((Octetstring_Value) v1).getValue();
                final String v4Str = ((Octetstring_Value) v4).getValue();
                String result = v1Str.substring(0, index * 2);
                result = result.concat(v4Str);
                result = result.concat(v1Str.substring((index + len) * 2));
                lastValue = new Octetstring_Value(result);
                lastValue.copyGeneralProperties(this);
                break;
            }
        case CHARSTRING_VALUE:
            {
                final String v1Str = ((Charstring_Value) v1).getValue();
                final String v4Str = ((Charstring_Value) v4).getValue();
                String result = v1Str.substring(0, index);
                result = result.concat(v4Str);
                result = result.concat(v1Str.substring(index + len));
                lastValue = new Charstring_Value(result);
                lastValue.copyGeneralProperties(this);
                break;
            }
        case UNIVERSALCHARSTRING_VALUE:
            {
                final UniversalCharstring v1Str = ((UniversalCharstring_Value) v1).getValue();
                final UniversalCharstring v4Str = ((UniversalCharstring_Value) v4).getValue();
                final UniversalCharstring result = v1Str.substring(0, index);
                // This append() is not like concat().
                result.append(v4Str);
                result.append(v1Str.substring(index + len));
                lastValue = new UniversalCharstring_Value(result);
                lastValue.copyGeneralProperties(this);
                break;
            }
        default:
            setIsErroneous(true);
            break;
    }
    return lastValue;
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) Hexstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Hexstring_Value) UniversalCharstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) UniversalCharstring(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring) Octetstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value) IValue(org.eclipse.titan.designer.AST.IValue) SpecificValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template) Expected_Value_type(org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type) Bitstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Bitstring_Value) UniversalCharstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value) Charstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value)

Example 70 with Integer_Value

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

the class RotateLeftExpression 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) {
    Type_type tempType1 = null;
    Type_type tempType2 = null;
    long valueSize = 0;
    long rotationSize = 0;
    IValue tempValue;
    if (value1 != null) {
        value1.setLoweridToReference(timestamp);
        tempType1 = value1.getExpressionReturntype(timestamp, expectedValue);
        switch(tempType1) {
            case TYPE_BITSTRING:
                tempValue = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
                if (Value_type.BITSTRING_VALUE.equals(tempValue.getValuetype())) {
                    valueSize = ((Bitstring_Value) tempValue).getValueLength();
                }
                break;
            case TYPE_HEXSTRING:
                tempValue = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
                if (Value_type.HEXSTRING_VALUE.equals(tempValue.getValuetype())) {
                    valueSize = ((Hexstring_Value) tempValue).getValueLength();
                }
                break;
            case TYPE_OCTETSTRING:
                tempValue = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
                if (Value_type.OCTETSTRING_VALUE.equals(tempValue.getValuetype())) {
                    valueSize = ((Octetstring_Value) tempValue).getValueLength();
                }
                break;
            case TYPE_CHARSTRING:
                tempValue = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
                if (Value_type.CHARSTRING_VALUE.equals(tempValue.getValuetype())) {
                    valueSize = ((Charstring_Value) tempValue).getValueLength();
                }
                break;
            case TYPE_UCHARSTRING:
                tempValue = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
                if (Value_type.UNIVERSALCHARSTRING_VALUE.equals(tempValue.getValuetype())) {
                    valueSize = ((UniversalCharstring_Value) tempValue).getValueLength();
                }
                break;
            case TYPE_SET_OF:
                tempValue = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
                if (Value_type.SEQUENCEOF_VALUE.equals(tempValue.getValuetype())) {
                    tempValue = tempValue.setValuetype(timestamp, Value_type.SETOF_VALUE);
                }
                if (Value_type.SETOF_VALUE.equals(tempValue.getValuetype())) {
                    valueSize = ((SetOf_Value) tempValue).getNofComponents();
                }
                break;
            case TYPE_SEQUENCE_OF:
                tempValue = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
                if (Value_type.SEQUENCEOF_VALUE.equals(tempValue.getValuetype())) {
                    valueSize = ((SequenceOf_Value) tempValue).getNofComponents();
                } else if (Value_type.SETOF_VALUE.equals(tempValue.getValuetype())) {
                    valueSize = ((SetOf_Value) tempValue).getNofComponents();
                }
                break;
            case TYPE_ARRAY:
                tempValue = value1.getValueRefdLast(timestamp, expectedValue, referenceChain);
                if (Value_type.SEQUENCEOF_VALUE.equals(tempValue.getValuetype())) {
                    tempValue = tempValue.setValuetype(timestamp, Value_type.ARRAY_VALUE);
                }
                if (Value_type.ARRAY_VALUE.equals(tempValue.getValuetype())) {
                    valueSize = ((Array_Value) tempValue).getNofComponents();
                }
                break;
            case TYPE_UNDEFINED:
                setIsErroneous(true);
                break;
            default:
                location.reportSemanticError(FIRSTOPERANDERROR);
                setIsErroneous(true);
                break;
        }
    }
    if (value2 != null) {
        value2.setLoweridToReference(timestamp);
        tempType2 = value2.getExpressionReturntype(timestamp, expectedValue);
        switch(tempType2) {
            case TYPE_INTEGER:
                tempValue = value2.getValueRefdLast(timestamp, expectedValue, referenceChain);
                if (Value_type.INTEGER_VALUE.equals(tempValue.getValuetype()) && !getIsErroneous(timestamp)) {
                    if (!((Integer_Value) tempValue).isNative()) {
                        value2.getLocation().reportSemanticError(MessageFormat.format(LARGEINTEGERSECONDOPERANDERROR, ((Integer_Value) tempValue).getValueValue()));
                        setIsErroneous(true);
                        break;
                    }
                    rotationSize = ((Integer_Value) tempValue).getValue();
                    if (value1 != null && !value1.isUnfoldable(timestamp)) {
                        final String severtiy = Platform.getPreferencesService().getString(ProductConstants.PRODUCT_ID_DESIGNER, PreferenceConstants.REPORTINCORRECTSHIFTROTATESIZE, GeneralConstants.WARNING, null);
                        if (valueSize == 0 || valueSize == 1) {
                            location.reportConfigurableSemanticProblem(severtiy, EFFECTLESSROTATION);
                        } else if (rotationSize < 0) {
                            location.reportConfigurableSemanticProblem(severtiy, NEGATIVEROTATEPROBLEM);
                        } else if (rotationSize == 0) {
                            location.reportConfigurableSemanticProblem(severtiy, ZEROROTATEPROBLEM);
                        } else if (rotationSize > valueSize) {
                            location.reportConfigurableSemanticProblem(severtiy, MessageFormat.format(TOOBIGROTATEPROBLEM, valueSize, rotationSize, rotationSize % valueSize));
                        }
                    }
                }
                break;
            case TYPE_UNDEFINED:
                setIsErroneous(true);
                break;
            default:
                location.reportSemanticError(SECONDOPERANDERROR);
                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) SetOf_Value(org.eclipse.titan.designer.AST.TTCN3.values.SetOf_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