Search in sources :

Example 16 with Expected_Value_type

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

the class Int2HexExpression 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)) {
        return lastValue;
    }
    if (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;
    }
    final Integer_Value i1 = (Integer_Value) last1;
    final long i2 = ((Integer_Value) last2).getValue();
    lastValue = new Hexstring_Value(int2hex(i1, (int) i2));
    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) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)

Example 17 with Expected_Value_type

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

the class Int2HexExpression 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 long i2 = ((Integer_Value) last2).getValue();
                    if (i2 < 0) {
                        value2.getLocation().reportSemanticError(OPERANDERROR4);
                        setIsErroneous(true);
                    } else if (last1 != null && !last1.isUnfoldable(timestamp) && Value.Value_type.INTEGER_VALUE.equals(last1.getValuetype())) {
                        if ((((Integer_Value) last1).shiftRight((int) i2 * 4)).signum() > 0) {
                            location.reportSemanticError(MessageFormat.format(OPERANDERROR5, ((Integer_Value) last1).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 18 with Expected_Value_type

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

the class Int2OctExpression 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;
    Integer_Value i1 = new Integer_Value(0);
    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())) {
                i1 = (Integer_Value) last1;
                if (i1.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 long i2 = ((Integer_Value) last2).getValue();
                    if (i2 < 0) {
                        value2.getLocation().reportSemanticError(OPERANDERROR4);
                        setIsErroneous(true);
                    } else if (last1 != null && !last1.isUnfoldable(timestamp) && Value.Value_type.INTEGER_VALUE.equals(last1.getValuetype())) {
                        if ((i1.shiftRight((int) i2 * 8)).signum() > 0) {
                            location.reportSemanticError(MessageFormat.format(OPERANDERROR5, ((Integer_Value) last1).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) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) Type_type(org.eclipse.titan.designer.AST.IType.Type_type)

Example 19 with Expected_Value_type

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

the class Int2StrExpression 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)) {
        return lastValue;
    }
    switch(last.getValuetype()) {
        case INTEGER_VALUE:
            lastValue = new Charstring_Value(((Integer_Value) last).getValueValue().toString());
            lastValue.copyGeneralProperties(this);
            break;
        default:
            setIsErroneous(true);
            break;
    }
    return lastValue;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Charstring_Value(org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value)

Example 20 with Expected_Value_type

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

the class IsBoundExpression 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 (templateInstance == null) {
        return lastValue;
    }
    checkExpressionOperands(timestamp, expectedValue, referenceChain);
    if (getIsErroneous(timestamp)) {
        return lastValue;
    }
    if (isUnfoldable(timestamp, referenceChain)) {
        return lastValue;
    }
    ITTCN3Template template = templateInstance.getTemplateBody();
    template = template.getTemplateReferencedLast(timestamp);
    boolean result = false;
    if (template.getTemplatetype() == Template_type.TEMPLATE_REFD) {
        final TTCN3Template last = template.getTemplateReferencedLast(timestamp);
        if (last != null && Template_type.SPECIFIC_VALUE.equals(last.getTemplatetype())) {
            result = ((SpecificValue_Template) last).getValue().evaluateIsbound(timestamp, ((Referenced_Template) template).getReference(), 1);
        }
    } else if (template.getTemplatetype() == Template_type.SPECIFIC_VALUE) {
        final IValue value = ((SpecificValue_Template) template).getValue();
        if (value.getValuetype() == Value_type.REFERENCED_VALUE) {
            result = value.evaluateIsbound(timestamp, ((Referenced_Value) value).getReference(), 1);
        } else {
            result = !value.getIsErroneous(timestamp);
        }
    }
    lastValue = new Boolean_Value(result);
    lastValue.copyGeneralProperties(this);
    return lastValue;
}
Also used : ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) Boolean_Value(org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value) SpecificValue_Template(org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template) IValue(org.eclipse.titan.designer.AST.IValue) Referenced_Template(org.eclipse.titan.designer.AST.TTCN3.templates.Referenced_Template) ITTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template) TTCN3Template(org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template)

Aggregations

IValue (org.eclipse.titan.designer.AST.IValue)149 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)54 IType (org.eclipse.titan.designer.AST.IType)47 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)45 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)39 Charstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value)37 Expected_Value_type (org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type)31 Octetstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value)24 ISubReference (org.eclipse.titan.designer.AST.ISubReference)21 Bitstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Bitstring_Value)21 Hexstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Hexstring_Value)20 Identifier (org.eclipse.titan.designer.AST.Identifier)17 SpecificValue_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template)17 Boolean_Value (org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value)14 Type (org.eclipse.titan.designer.AST.Type)14 Assignment (org.eclipse.titan.designer.AST.Assignment)13 Real_Value (org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)13 UniversalCharstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value)12 CharstringExtractor (org.eclipse.titan.designer.AST.TTCN3.values.CharstringExtractor)11 Value (org.eclipse.titan.designer.AST.Value)11