Search in sources :

Example 21 with Integer_Value

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

the class RotateRightExpression 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 string;
    int shiftSize;
    switch(last1.getValuetype()) {
        case BITSTRING_VALUE:
            string = ((Bitstring_Value) last1).getValue();
            shiftSize = ((Integer_Value) last2).intValue();
            lastValue = new Bitstring_Value(rotateRight(string, shiftSize));
            lastValue.copyGeneralProperties(this);
            break;
        case HEXSTRING_VALUE:
            string = ((Hexstring_Value) last1).getValue();
            shiftSize = ((Integer_Value) last2).intValue();
            lastValue = new Hexstring_Value(rotateRight(string, shiftSize));
            lastValue.copyGeneralProperties(this);
            break;
        case OCTETSTRING_VALUE:
            string = ((Octetstring_Value) last1).getValue();
            shiftSize = ((Integer_Value) last2).intValue() * 2;
            lastValue = new Octetstring_Value(rotateRight(string, shiftSize));
            lastValue.copyGeneralProperties(this);
            break;
        case CHARSTRING_VALUE:
            string = ((Charstring_Value) last1).getValue();
            shiftSize = ((Integer_Value) last2).intValue();
            lastValue = new Charstring_Value(rotateRight(string, shiftSize));
            lastValue.copyGeneralProperties(this);
            break;
        case UNIVERSALCHARSTRING_VALUE:
            final UniversalCharstring string2 = ((UniversalCharstring_Value) last1).getValue();
            shiftSize = ((Integer_Value) last2).intValue();
            lastValue = new UniversalCharstring_Value(rotateRight(string2, shiftSize));
            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) 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)

Example 22 with Integer_Value

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

the class LessThanExpression 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 23 with Integer_Value

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

the class ModuloExpression 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:
            final BigInteger i1 = ((Integer_Value) last1).getValueValue();
            final BigInteger i2Abs = ((Integer_Value) last2).getValueValue().abs();
            final BigInteger temp = i1.remainder(i2Abs);
            final BigInteger result = i1.compareTo(BigInteger.ZERO) >= 0 ? temp : (temp.equals(BigInteger.ZERO) ? BigInteger.ZERO : temp.add(i2Abs));
            lastValue = new Integer_Value(result);
            lastValue.copyGeneralProperties(this);
            break;
        default:
            break;
    }
    return lastValue;
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Integer_Value(org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value) BigInteger(java.math.BigInteger)

Example 24 with Integer_Value

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

the class SubstractExpression 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:
            // If the operands exist they must be of the same type.
            lastValue = ((Integer_Value) last1).subtract((Integer_Value) last2);
            lastValue.copyGeneralProperties(this);
            break;
        case REAL_VALUE:
            final double f1 = ((Real_Value) last1).getValue();
            final double f2 = ((Real_Value) last2).getValue();
            lastValue = new Real_Value(f1 - f2);
            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) Real_Value(org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)

Example 25 with Integer_Value

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

the class Macro_Value method evaluateMacro.

/**
 * Evaluates the value of the macro.
 *
 * @param expectedValue the kind of the value to be expected
 *
 * @return the actual or the evaluated value
 */
private IValue evaluateMacro(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return lastValue;
    }
    lastTimeChecked = timestamp;
    lastValue = this;
    switch(value) {
        case MODULEID:
            if (myScope != null && myScope.getModuleScope() != null) {
                final Module module = myScope.getModuleScope();
                if (module.getIdentifier() != null) {
                    lastValue = new Charstring_Value(module.getIdentifier().getDisplayName());
                    lastValue.copyGeneralProperties(this);
                }
            }
            break;
        case DEFINITIONID:
            if (myScope != null) {
                final StatementBlock block = myScope.getStatementBlockScope();
                if (block != null) {
                    final Definition definition = block.getMyDefinition();
                    if (definition != null) {
                        lastValue = new Charstring_Value(definition.getIdentifier().getDisplayName());
                        lastValue.copyGeneralProperties(this);
                    }
                }
            } else {
                setIsErroneous(true);
            }
            break;
        case TESTCASEID:
            if (myScope != null) {
                final StatementBlock block = myScope.getStatementBlockScope();
                if (block != null) {
                    final Definition definition = block.getMyDefinition();
                    if (definition == null) {
                        location.reportSemanticError(TESCASEIDINCONTROLPART);
                        setIsErroneous(true);
                    } else {
                        if (Assignment_type.A_TESTCASE.semanticallyEquals(definition.getAssignmentType())) {
                            // folding is possible in testcases only
                            lastValue = new Charstring_Value(definition.getIdentifier().getDisplayName());
                            lastValue.copyGeneralProperties(this);
                        }
                    }
                } else {
                    location.reportSemanticError(TESTCASEIDNOTALLOWED);
                    setIsErroneous(true);
                }
            } else {
                setIsErroneous(true);
            }
            break;
        case FILENAME:
        case BFILENAME:
            if (NULL_Location.INSTANCE.equals(location)) {
                setIsErroneous(true);
            } else {
                lastValue = new Charstring_Value(location.getFile().getName());
                lastValue.copyGeneralProperties(this);
            }
            break;
        case FILEPATH:
            if (NULL_Location.INSTANCE.equals(location)) {
                setIsErroneous(true);
            } else {
                String canonicalPath;
                final IPath absolutePath = location.getFile().getLocation();
                if (absolutePath == null) {
                    location.reportSemanticError(UNDETERMINABLEPATH);
                    canonicalPath = location.getFile().getName();
                    setIsErroneous(true);
                } else {
                    final File file = absolutePath.toFile();
                    try {
                        canonicalPath = file.getCanonicalPath();
                    } catch (IOException e) {
                        location.reportSemanticError(UNDETERMINABLEPATH);
                        canonicalPath = location.getFile().getName();
                        setIsErroneous(true);
                    }
                }
                lastValue = new Charstring_Value(canonicalPath);
                lastValue.copyGeneralProperties(this);
            }
            break;
        case LINENUMBER:
            if (NULL_Location.INSTANCE.equals(location)) {
                setIsErroneous(true);
            } else {
                lastValue = new Charstring_Value(Long.toString(location.getLine()));
                lastValue.copyGeneralProperties(this);
            }
            break;
        case LINENUMBER_C:
            if (NULL_Location.INSTANCE.equals(location)) {
                setIsErroneous(true);
            } else {
                lastValue = new Integer_Value(location.getLine());
                lastValue.copyGeneralProperties(this);
            }
            break;
        case SCOPE:
            if (myScope != null) {
                lastValue = new Charstring_Value(myScope.getScopeMacroName());
                lastValue.copyGeneralProperties(this);
            } else {
                location.reportSemanticError(UNDETERMINABLESCOPE);
                setIsErroneous(true);
            }
            break;
        default:
            setIsErroneous(true);
    }
    return lastValue;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Definition(org.eclipse.titan.designer.AST.TTCN3.definitions.Definition) IOException(java.io.IOException) Module(org.eclipse.titan.designer.AST.Module) File(java.io.File) StatementBlock(org.eclipse.titan.designer.AST.TTCN3.statements.StatementBlock)

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