Search in sources :

Example 26 with Real_Value

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

the class ExecuteExpression 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 Assignment assignment = reference.getRefdAssignment(timestamp, true);
    if (assignment == null) {
        setIsErroneous(true);
    } else if (!Assignment_type.A_TESTCASE.semanticallyEquals(assignment.getAssignmentType())) {
        reference.getLocation().reportSemanticError(MessageFormat.format("Reference to a testcase was expected in the argument instead of {0}", assignment.getDescription()));
        setIsErroneous(true);
    }
    if (timerValue != null) {
        timerValue.setLoweridToReference(timestamp);
        final Type_type tempType = timerValue.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
        switch(tempType) {
            case TYPE_REAL:
                final IValue last = timerValue.getValueRefdLast(timestamp, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, referenceChain);
                if (!last.isUnfoldable(timestamp)) {
                    final Real_Value real = (Real_Value) last;
                    final double i = real.getValue();
                    if (i < 0.0) {
                        timerValue.getLocation().reportSemanticError(MessageFormat.format(NEGATIVEDURATION, real.createStringRepresentation()));
                    } else if (real.isPositiveInfinity()) {
                        timerValue.getLocation().reportSemanticError(MessageFormat.format(FLOATEXPECTED, real.createStringRepresentation()));
                    }
                }
                return;
            case TYPE_UNDEFINED:
                setIsErroneous(true);
                return;
            default:
                if (!isErroneous) {
                    timerValue.getLocation().reportSemanticError(OPERANDERROR);
                    setIsErroneous(true);
                }
                return;
        }
    }
    checkExpressionDynamicPart(expectedValue, OPERATIONNAME, true, false, false);
}
Also used : Assignment(org.eclipse.titan.designer.AST.Assignment) IValue(org.eclipse.titan.designer.AST.IValue) Type_type(org.eclipse.titan.designer.AST.IType.Type_type) Real_Value(org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)

Example 27 with Real_Value

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

the class Float2IntExpression 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_REAL:
            {
                final IValue last = value.getValueRefdLast(timestamp, expectedValue, referenceChain);
                if (!last.isUnfoldable(timestamp)) {
                    final Real_Value real = (Real_Value) last;
                    if (real.isSpecialFloat()) {
                        value.getLocation().reportSemanticError(MessageFormat.format(OPERANDERROR2, real.createStringRepresentation()));
                        setIsErroneous(true);
                    }
                }
                return;
            }
        case TYPE_UNDEFINED:
            setIsErroneous(true);
            return;
        default:
            if (!isErroneous) {
                location.reportSemanticError(OPERANDERROR);
                setIsErroneous(true);
            }
            return;
    }
}
Also used : IValue(org.eclipse.titan.designer.AST.IValue) Type_type(org.eclipse.titan.designer.AST.IType.Type_type) Real_Value(org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)

Example 28 with Real_Value

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

the class LessThanOrEqualExpression 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 29 with Real_Value

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

the class MultiplyExpression 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;
    }
    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;
    }
    if (isUnfoldable(timestamp, referenceChain)) {
        if (last1.isUnfoldable(timestamp) || last2.isUnfoldable(timestamp)) {
            return lastValue;
        }
        switch(last1.getValuetype()) {
            case INTEGER_VALUE:
                final Integer_Value zero = new Integer_Value(0L);
                if (((Integer_Value) last1).equals(zero) || ((Integer_Value) last2).equals(zero)) {
                    lastValue = zero;
                    lastValue.copyGeneralProperties(this);
                }
                break;
            case REAL_VALUE:
                if (Double.compare(((Real_Value) last1).getValue(), 0) == 0 || Double.compare(((Real_Value) last2).getValue(), 0) == 0) {
                    lastValue = new Real_Value(0);
                    lastValue.copyGeneralProperties(this);
                }
                break;
            default:
                setIsErroneous(true);
                break;
        }
    } else {
        switch(last1.getValuetype()) {
            case INTEGER_VALUE:
                // If the operands exist they must be of the
                // same type.
                lastValue = ((Integer_Value) last1).multiply((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 30 with Real_Value

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

the class GreaterThanExpression 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)

Aggregations

IValue (org.eclipse.titan.designer.AST.IValue)33 Real_Value (org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)27 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)14 IType (org.eclipse.titan.designer.AST.IType)9 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)9 Boolean_Value (org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value)6 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)5 TTCN3_Enumerated_Type (org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Enumerated_Type)5 Charstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value)5 Assignment (org.eclipse.titan.designer.AST.Assignment)4 EnumItem (org.eclipse.titan.designer.AST.TTCN3.types.EnumItem)4 Enumerated_Value (org.eclipse.titan.designer.AST.TTCN3.values.Enumerated_Value)4 UniversalCharstring (org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring)3 UniversalCharstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.UniversalCharstring_Value)3 BridgingNamedNode (org.eclipse.titan.designer.AST.BridgingNamedNode)2 ValueCheckingOptions (org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)2 Reference (org.eclipse.titan.designer.AST.Reference)2 ActualParameterList (org.eclipse.titan.designer.AST.TTCN3.definitions.ActualParameterList)2 FormalParameterList (org.eclipse.titan.designer.AST.TTCN3.definitions.FormalParameterList)2 Integer_Type (org.eclipse.titan.designer.AST.TTCN3.types.Integer_Type)2