Search in sources :

Example 11 with IValue

use of org.eclipse.titan.designer.AST.IValue in project titan.EclipsePlug-ins by eclipse.

the class Str2HexExpression 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)) {
        return lastValue;
    }
    switch(last.getValuetype()) {
        case CHARSTRING_VALUE:
            final String string = ((Charstring_Value) last).getValue();
            lastValue = new Hexstring_Value(string.toUpperCase());
            break;
        default:
            return this;
    }
    lastValue.copyGeneralProperties(this);
    return lastValue;
}
Also used : Hexstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Hexstring_Value) IValue(org.eclipse.titan.designer.AST.IValue) Charstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value)

Example 12 with IValue

use of org.eclipse.titan.designer.AST.IValue in project titan.EclipsePlug-ins by eclipse.

the class Str2IntExpression 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 (value == null) {
        return;
    }
    value.setLoweridToReference(timestamp);
    final Type_type tempType = value.getExpressionReturntype(timestamp, expectedValue);
    switch(tempType) {
        case TYPE_CHARSTRING:
            final IValue last = value.getValueRefdLast(timestamp, expectedValue, referenceChain);
            if (!last.isUnfoldable(timestamp)) {
                String string = ((Charstring_Value) last).getValue();
                string = string.trim();
                if (!string.isEmpty() && string.charAt(0) == '+') {
                    string = string.substring(1);
                }
                try {
                    new Integer_Value(string);
                } catch (NumberFormatException e) {
                    // The exception is thrown by BigInteger
                    // not Integer_Value.
                    value.getLocation().reportSemanticError(OPERANDERROR2);
                }
            }
            return;
        case TYPE_UNDEFINED:
            setIsErroneous(true);
            return;
        default:
            if (!isErroneous) {
                location.reportSemanticError(OPERANDERROR1);
                setIsErroneous(true);
            }
            return;
    }
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Charstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value) Type_type(org.eclipse.titan.designer.AST.IType.Type_type) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)

Example 13 with IValue

use of org.eclipse.titan.designer.AST.IValue in project titan.EclipsePlug-ins by eclipse.

the class StringConcatenationExpression 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)) {
        return lastValue;
    }
    switch(last1.getValuetype()) {
        case BITSTRING_VALUE:
            {
                final String string1 = ((Bitstring_Value) last1).getValue();
                final String string2 = ((Bitstring_Value) last2).getValue();
                lastValue = new Bitstring_Value(string1 + string2);
                lastValue.copyGeneralProperties(this);
                break;
            }
        case HEXSTRING_VALUE:
            {
                final String string1 = ((Hexstring_Value) last1).getValue();
                final String string2 = ((Hexstring_Value) last2).getValue();
                lastValue = new Hexstring_Value(string1 + string2);
                lastValue.copyGeneralProperties(this);
                break;
            }
        case OCTETSTRING_VALUE:
            {
                final String string1 = ((Octetstring_Value) last1).getValue();
                final String string2 = ((Octetstring_Value) last2).getValue();
                lastValue = new Octetstring_Value(string1 + string2);
                lastValue.copyGeneralProperties(this);
                break;
            }
        case CHARSTRING_VALUE:
            {
                final String string1 = ((Charstring_Value) last1).getValue();
                if (Value_type.UNIVERSALCHARSTRING_VALUE.equals(last2.getValuetype())) {
                    final UniversalCharstring string2 = ((UniversalCharstring_Value) last2).getValue();
                    lastValue = new UniversalCharstring_Value(new UniversalCharstring(string1).append(string2));
                } else {
                    final String string2 = ((Charstring_Value) last2).getValue();
                    lastValue = new Charstring_Value(string1 + string2);
                }
                lastValue.copyGeneralProperties(this);
                break;
            }
        case UNIVERSALCHARSTRING_VALUE:
            {
                final UniversalCharstring string1 = ((UniversalCharstring_Value) last1).getValue();
                if (Value_type.UNIVERSALCHARSTRING_VALUE.equals(last2.getValuetype())) {
                    final UniversalCharstring string2 = ((UniversalCharstring_Value) last2).getValue();
                    lastValue = new UniversalCharstring_Value(new UniversalCharstring(string1).append(string2));
                } else {
                    final String string2 = ((Charstring_Value) last2).getValue();
                    lastValue = new UniversalCharstring_Value(new UniversalCharstring(string1).append(string2));
                }
                lastValue.copyGeneralProperties(this);
                break;
            }
        default:
            setIsErroneous(true);
            break;
    }
    return lastValue;
}
Also used : Hexstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Hexstring_Value) UniversalCharstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value) IValue(org.eclipse.titan.designer.AST.IValue) 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) UniversalCharstring(org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring) Octetstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value)

Example 14 with IValue

use of org.eclipse.titan.designer.AST.IValue in project titan.EclipsePlug-ins by eclipse.

the class StringConcatenationExpression method getExpressionReturntype.

@Override
public /**
 * {@inheritDoc}
 */
Type_type getExpressionReturntype(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue) {
    final IValue last = getValueRefdLast(timestamp, expectedValue, null);
    if (last == null || value1 == null || value2 == null) {
        return Type_type.TYPE_UNDEFINED;
    }
    if (last.getIsErroneous(timestamp)) {
        setIsErroneous(true);
        return Type_type.TYPE_UNDEFINED;
    }
    Type_type tempType;
    if (last == this) {
        // not good, but in case of recursive call this is the
        // only way out.
        value1.setLoweridToReference(timestamp);
        tempType = value1.getExpressionReturntype(timestamp, expectedValue);
        if (!Type_type.TYPE_UCHARSTRING.equals(tempType)) {
            value2.setLoweridToReference(timestamp);
            tempType = value2.getExpressionReturntype(timestamp, expectedValue);
        }
    } else {
        last.setLoweridToReference(timestamp);
        tempType = last.getExpressionReturntype(timestamp, expectedValue);
    }
    switch(tempType) {
        case TYPE_BITSTRING:
        case TYPE_HEXSTRING:
        case TYPE_OCTETSTRING:
        case TYPE_CHARSTRING:
        case TYPE_UCHARSTRING:
        case TYPE_SET_OF:
        case TYPE_SEQUENCE_OF:
            return tempType;
        case TYPE_UNDEFINED:
            return tempType;
        default:
            setIsErroneous(true);
            return Type_type.TYPE_UNDEFINED;
    }
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Type_type(org.eclipse.titan.designer.AST.IType.Type_type)

Example 15 with IValue

use of org.eclipse.titan.designer.AST.IValue in project titan.EclipsePlug-ins by eclipse.

the class SubstrExpression method generateCodeExpressionExpression.

@Override
public /**
 * {@inheritDoc}
 */
void generateCodeExpressionExpression(final JavaGenData aData, final ExpressionStruct expression) {
    if (lastValue != null && lastValue != this) {
        lastValue.generateCodeExpression(aData, expression, true);
        return;
    }
    final IValue lastValue2 = value2.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE, null);
    final IValue lastValue3 = value3.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE, null);
    // TODO handle the needs conversion case
    final Type_type expressionType = templateInstance1.getExpressionReturntype(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
    switch(expressionType) {
        case TYPE_BITSTRING:
        case TYPE_HEXSTRING:
        case TYPE_OCTETSTRING:
        case TYPE_CHARSTRING:
        case TYPE_UCHARSTRING:
            {
                aData.addCommonLibraryImport("AdditionalFunctions");
                expression.expression.append("AdditionalFunctions.subString( ");
                final ITTCN3Template temp = templateInstance1.getTemplateBody();
                if (temp.isValue(CompilationTimeStamp.getBaseTimestamp())) {
                    final IValue value = temp.getValue();
                    value.generateCodeExpressionMandatory(aData, expression, true);
                } else {
                    templateInstance1.generateCode(aData, expression, Restriction_type.TR_NONE);
                }
                expression.expression.append(", ");
                if (lastValue2.isUnfoldable(CompilationTimeStamp.getBaseTimestamp()) || !((Integer_Value) lastValue2).isNative()) {
                    lastValue2.generateCodeExpressionMandatory(aData, expression, true);
                } else {
                    final long tempNative = ((Integer_Value) lastValue2).getValue();
                    expression.expression.append(tempNative);
                }
                expression.expression.append(", ");
                if (lastValue3.isUnfoldable(CompilationTimeStamp.getBaseTimestamp()) || !((Integer_Value) lastValue3).isNative()) {
                    lastValue3.generateCodeExpressionMandatory(aData, expression, true);
                } else {
                    final long tempNative = ((Integer_Value) lastValue3).getValue();
                    expression.expression.append(tempNative);
                }
                expression.expression.append(')');
                break;
            }
        case TYPE_SEQUENCE_OF:
        case TYPE_SET_OF:
            templateInstance1.generateCode(aData, expression, Restriction_type.TR_NONE);
            expression.expression.append(".substr( ");
            if (lastValue2.isUnfoldable(CompilationTimeStamp.getBaseTimestamp()) || !((Integer_Value) lastValue2).isNative()) {
                lastValue2.generateCodeExpressionMandatory(aData, expression, true);
            } else {
                final long tempNative = ((Integer_Value) lastValue2).getValue();
                expression.expression.append(tempNative);
            }
            expression.expression.append(", ");
            if (lastValue3.isUnfoldable(CompilationTimeStamp.getBaseTimestamp()) || !((Integer_Value) lastValue3).isNative()) {
                lastValue3.generateCodeExpressionMandatory(aData, expression, true);
            } else {
                final long tempNative = ((Integer_Value) lastValue3).getValue();
                expression.expression.append(tempNative);
            }
            expression.expression.append(')');
            break;
        default:
            ErrorReporter.INTERNAL_ERROR("FATAL ERROR while generating code for expression `" + getFullName() + "''");
            break;
    }
}
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)

Aggregations

IValue (org.eclipse.titan.designer.AST.IValue)431 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)105 IType (org.eclipse.titan.designer.AST.IType)97 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)79 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)78 ISubReference (org.eclipse.titan.designer.AST.ISubReference)49 Charstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value)41 Value (org.eclipse.titan.designer.AST.Value)35 Identifier (org.eclipse.titan.designer.AST.Identifier)34 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)33 Assignment (org.eclipse.titan.designer.AST.Assignment)30 Real_Value (org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)28 Octetstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value)26 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)25 Reference (org.eclipse.titan.designer.AST.Reference)25 Bitstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Bitstring_Value)23 ValueCheckingOptions (org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)22 Hexstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Hexstring_Value)22 SpecificValue_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template)21 Boolean_Value (org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value)21