Search in sources :

Example 36 with IValue

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

the class Xor4bExpression 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);
    String str1;
    String str2;
    switch(last1.getValuetype()) {
        case BITSTRING_VALUE:
            str1 = ((Bitstring_Value) last1).getValue();
            str2 = ((Bitstring_Value) last2).getValue();
            lastValue = new Bitstring_Value(xor4b(str1, str2));
            lastValue.copyGeneralProperties(this);
            break;
        case HEXSTRING_VALUE:
            str1 = ((Hexstring_Value) last1).getValue();
            str2 = ((Hexstring_Value) last2).getValue();
            lastValue = new Hexstring_Value(xor4b(str1, str2));
            lastValue.copyGeneralProperties(this);
            break;
        case OCTETSTRING_VALUE:
            str1 = ((Octetstring_Value) last1).getValue();
            str2 = ((Octetstring_Value) last2).getValue();
            lastValue = new Octetstring_Value(xor4b(str1, str2));
            lastValue.copyGeneralProperties(this);
            break;
        default:
            setIsErroneous(true);
            break;
    }
    return lastValue;
}
Also used : Hexstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Hexstring_Value) IValue(org.eclipse.titan.designer.AST.IValue) Bitstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Bitstring_Value) Octetstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value)

Example 37 with IValue

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

the class RegexpExpression 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 || templateInstance1 == null) {
        return Type_type.TYPE_UNDEFINED;
    }
    if (last.getIsErroneous(timestamp)) {
        setIsErroneous(true);
        return Type_type.TYPE_UNDEFINED;
    }
    final ITTCN3Template template = templateInstance1.getTemplateBody().setLoweridToReference(timestamp);
    final Type_type tempType = template.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
    switch(tempType) {
        case TYPE_CHARSTRING:
        case TYPE_UCHARSTRING:
            return tempType;
        case TYPE_UNDEFINED:
            return tempType;
        default:
            setIsErroneous(true);
            return Type_type.TYPE_UNDEFINED;
    }
}
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)

Example 38 with IValue

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

the class RegexpExpression 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;
    setIsErroneous(false);
    if (templateInstance1 != null) {
        IType governor1 = templateInstance1.getExpressionGovernor(timestamp, internalExpectation);
        ITTCN3Template template = templateInstance1.getTemplateBody();
        if (governor1 == null) {
            template = template.setLoweridToReference(timestamp);
            governor1 = template.getExpressionGovernor(timestamp, internalExpectation);
        }
        if (governor1 == null) {
            if (!template.getIsErroneous(timestamp)) {
                templateInstance1.getLocation().reportSemanticError(CANNOT_DETERMINE_ARG_TYPE);
            }
            setIsErroneous(true);
            return;
        }
        IsValueExpression.checkExpressionTemplateInstance(timestamp, this, templateInstance1, governor1, referenceChain, expectedValue);
        if (getIsErroneous(timestamp)) {
            return;
        }
        final ITTCN3Template temp = template.setLoweridToReference(timestamp);
        temp.checkSpecificValue(timestamp, false);
        switch(governor1.getTypeRefdLast(timestamp).getTypetypeTtcn3()) {
            case TYPE_CHARSTRING:
            case TYPE_UCHARSTRING:
                break;
            case TYPE_UNDEFINED:
                setIsErroneous(true);
                break;
            default:
                location.reportSemanticError(OPERANDERROR1);
                setIsErroneous(true);
                break;
        }
    }
    if (templateInstance2 != null) {
        IType governor2 = templateInstance2.getExpressionGovernor(timestamp, internalExpectation);
        ITTCN3Template temp = templateInstance2.getTemplateBody();
        if (governor2 == null) {
            temp = temp.setLoweridToReference(timestamp);
            governor2 = temp.getExpressionGovernor(timestamp, internalExpectation);
        }
        if (governor2 == null) {
            if (!temp.getIsErroneous(timestamp)) {
                templateInstance2.getLocation().reportSemanticError(CANNOT_DETERMINE_ARG_TYPE);
            }
            setIsErroneous(true);
            return;
        }
        IsValueExpression.checkExpressionTemplateInstance(timestamp, this, templateInstance2, governor2, referenceChain, expectedValue);
        if (getIsErroneous(timestamp)) {
            return;
        }
        switch(governor2.getTypeRefdLast(timestamp).getTypetype()) {
            case TYPE_CHARSTRING:
            case TYPE_UCHARSTRING:
                break;
            case TYPE_UNDEFINED:
                setIsErroneous(true);
                break;
            default:
                location.reportSemanticError(OPERANDERROR2);
                setIsErroneous(true);
                break;
        }
    }
    if (value3 != null) {
        final IValue temp = value3.setLoweridToReference(timestamp);
        final Type_type tempType3 = temp.getExpressionReturntype(timestamp, expectedValue);
        switch(tempType3) {
            case TYPE_INTEGER:
                final IValue last3 = temp.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(OPERANDERROR5, ((Integer_Value) last3).getValueValue()));
                        setIsErroneous(true);
                    }
                }
                break;
            case TYPE_UNDEFINED:
                setIsErroneous(true);
                break;
            default:
                location.reportSemanticError(OPERANDERROR3);
                setIsErroneous(true);
                break;
        }
    }
// TODO add regexp specific checks once patterns become
// supported
}
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) IType(org.eclipse.titan.designer.AST.IType)

Example 39 with IValue

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

the class RemoveBomExpression 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)) {
        return lastValue;
    }
    if (isUnfoldable(timestamp, referenceChain)) {
        return lastValue;
    }
    final IValue last = value.getValueRefdLast(timestamp, referenceChain);
    if (last.getIsErroneous(timestamp)) {
        setIsErroneous(true);
        return lastValue;
    }
    switch(last.getValuetype()) {
        case OCTETSTRING_VALUE:
            {
                final String octetString = ((Octetstring_Value) last).getValue();
                lastValue = new Octetstring_Value(calculateValue(octetString));
                lastValue.copyGeneralProperties(this);
                break;
            }
        default:
            setIsErroneous(true);
            break;
    }
    return lastValue;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Octetstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value)

Example 40 with IValue

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

the class ReplaceExpression method checkExpressionOperandsHelper.

private void checkExpressionOperandsHelper(final CompilationTimeStamp timestamp, final IValue value1, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
    if (templateInstance1 == null || getIsErroneous(timestamp)) {
        return;
    }
    long valueSize = -1;
    if (!value1.isUnfoldable(timestamp)) {
        IValue temp = value1.setLoweridToReference(timestamp);
        temp = temp.getValueRefdLast(timestamp, referenceChain);
        switch(temp.getValuetype()) {
            case BITSTRING_VALUE:
                valueSize = ((Bitstring_Value) temp).getValueLength();
                break;
            case HEXSTRING_VALUE:
                valueSize = ((Hexstring_Value) temp).getValueLength();
                break;
            case OCTETSTRING_VALUE:
                valueSize = ((Octetstring_Value) temp).getValueLength();
                break;
            case CHARSTRING_VALUE:
                valueSize = ((Charstring_Value) temp).getValueLength();
                break;
            case UNIVERSALCHARSTRING_VALUE:
                valueSize = ((UniversalCharstring_Value) temp).getValueLength();
                break;
            case SETOF_VALUE:
                valueSize = ((SetOf_Value) temp).getNofComponents();
                break;
            case SEQUENCEOF_VALUE:
                valueSize = ((SequenceOf_Value) temp).getNofComponents();
                break;
            default:
                break;
        }
    }
    if (valueSize < 0) {
        return;
    }
    if (value2 == null || value3 == null || templateInstance4 == null) {
        return;
    }
    if (value2.isUnfoldable(timestamp)) {
        if (!value3.isUnfoldable(timestamp)) {
            final IValue last3 = value3.getValueRefdLast(timestamp, expectedValue, referenceChain);
            final long last3Value = ((Integer_Value) last3).getValue();
            if (last3Value > valueSize) {
                location.reportSemanticError(MessageFormat.format(OPERANDERROR8, last3Value, valueSize));
                setIsErroneous(true);
            }
        }
    } else {
        final IValue last2 = value2.getValueRefdLast(timestamp, expectedValue, referenceChain);
        final long last2Value = ((Integer_Value) last2).getValue();
        if (value3.isUnfoldable(timestamp)) {
            if (last2Value > valueSize) {
                location.reportSemanticError(MessageFormat.format(OPERANDERROR9, last2Value, valueSize));
                setIsErroneous(true);
            }
        } else {
            final IValue last3 = value3.getValueRefdLast(timestamp, expectedValue, referenceChain);
            final long last3Value = ((Integer_Value) last3).getValue();
            if (last2Value + last3Value > valueSize) {
                location.reportSemanticError(MessageFormat.format(OPERANDERROR10, last2Value, last3Value, valueSize));
                setIsErroneous(true);
            }
        }
    }
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) 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