Search in sources :

Example 6 with Boolean_Value

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

the class OrExpression 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);
    if (Value_type.BOOLEAN_VALUE.equals(last1.getValuetype())) {
        if (((Boolean_Value) last1).getValue()) {
            lastValue = new Boolean_Value(true);
            lastValue.copyGeneralProperties(this);
        } else {
            final Boolean_Value temp = (Boolean_Value) value2.getValueRefdLast(timestamp, referenceChain);
            lastValue = new Boolean_Value(temp.getValue());
            lastValue.copyGeneralProperties(this);
        }
    } else {
        // we must keep the left operand because of the
        // potential side effects
        // the right operand can only be eliminated if it is a
        // literal "false"
        final IValue last2 = value2.getValueRefdLast(timestamp, referenceChain);
        if (Value_type.BOOLEAN_VALUE.equals(last2.getValuetype()) && !((Boolean_Value) last2).getValue()) {
            final Boolean_Value temp = (Boolean_Value) value1.getValueRefdLast(timestamp, referenceChain);
            lastValue = new Boolean_Value(temp.getValue());
            lastValue.copyGeneralProperties(this);
        }
    }
    return lastValue;
}
Also used : Boolean_Value(org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value) IValue(org.eclipse.titan.designer.AST.IValue)

Example 7 with Boolean_Value

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

the class EqualsExpression 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 == null || last2 == null) {
        setIsErroneous(true);
        return lastValue;
    }
    lastValue = new Boolean_Value(last1.checkEquality(timestamp, last2));
    lastValue.copyGeneralProperties(this);
    return lastValue;
}
Also used : Boolean_Value(org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value) IValue(org.eclipse.titan.designer.AST.IValue)

Example 8 with Boolean_Value

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

the class AndExpression 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)) {
        setIsErroneous(true);
        return lastValue;
    }
    final IValue last1 = value1.getValueRefdLast(timestamp, referenceChain);
    if (Value_type.BOOLEAN_VALUE.equals(last1.getValuetype())) {
        if (((Boolean_Value) last1).getValue()) {
            final Boolean_Value temp = (Boolean_Value) value2.getValueRefdLast(timestamp, referenceChain);
            lastValue = new Boolean_Value(temp.getValue());
            lastValue.copyGeneralProperties(this);
        } else {
            lastValue = new Boolean_Value(false);
            lastValue.copyGeneralProperties(this);
        }
    } else {
        // we must keep the left operand because of the
        // potential side effects
        // the right operand can only be eliminated if it is a
        // literal "true"
        final IValue last2 = value2.getValueRefdLast(timestamp, referenceChain);
        if (Value_type.BOOLEAN_VALUE.equals(last2.getValuetype()) && ((Boolean_Value) last2).getValue()) {
            final Boolean_Value temp = (Boolean_Value) value1.getValueRefdLast(timestamp, referenceChain);
            lastValue = new Boolean_Value(temp.getValue());
            lastValue.copyGeneralProperties(this);
        }
    }
    return lastValue;
}
Also used : Boolean_Value(org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value) IValue(org.eclipse.titan.designer.AST.IValue)

Example 9 with Boolean_Value

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

the class GreaterThanOrEqualExpression 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 10 with Boolean_Value

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

the class If_Clause method generateCode.

/**
 * Add generated java code for a single if clause.
 *
 * @param aData the structure to put imports into and get temporal variable names from.
 * @param source the source code generated
 * @param blockCount the number of block already created
 * @param unReachable tells whether this branch is already unreachable because of previous conditions
 * @param eachFalse true if the branches so far all evaluated to a false condition in compile time.
 *
 * TODO: if we can generate "else if" -s the blockCount is not needed
 */
public void generateCode(final JavaGenData aData, final StringBuilder source, final AtomicInteger blockCount, final AtomicBoolean unReachable, final AtomicBoolean eachFalse) {
    if (unReachable.get()) {
        return;
    }
    if (!expression.isUnfoldable(CompilationTimeStamp.getBaseTimestamp())) {
        final IValue last = expression.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_DYNAMIC_VALUE, null);
        if (((Boolean_Value) last).getValue()) {
            unReachable.set(true);
        } else {
            return;
        }
    }
    if (!eachFalse.get()) {
        source.append("else ");
    }
    if (!unReachable.get()) {
        if (!eachFalse.get()) {
            source.append("{\n");
            blockCount.incrementAndGet();
        }
        expression.getLocation().update_location_object(aData, source);
        if (expression.returnsNative()) {
            expression.generateCodeTmp(aData, source, "if (", blockCount);
            source.append(')');
        } else {
            aData.addBuiltinTypeImport("TitanBoolean");
            expression.generateCodeTmp(aData, source, "if (TitanBoolean.getNative(", blockCount);
            source.append(") )");
        }
    }
    eachFalse.set(false);
    source.append("{\n");
    statementblock.generateCode(aData, source);
    source.append("}\n");
}
Also used : Boolean_Value(org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value) IValue(org.eclipse.titan.designer.AST.IValue)

Aggregations

Boolean_Value (org.eclipse.titan.designer.AST.TTCN3.values.Boolean_Value)23 IValue (org.eclipse.titan.designer.AST.IValue)22 Integer_Value (org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value)6 IType (org.eclipse.titan.designer.AST.IType)5 Type_type (org.eclipse.titan.designer.AST.IType.Type_type)4 SpecificValue_Template (org.eclipse.titan.designer.AST.TTCN3.templates.SpecificValue_Template)4 Boolean_Type (org.eclipse.titan.designer.AST.TTCN3.types.Boolean_Type)4 EnumItem (org.eclipse.titan.designer.AST.TTCN3.types.EnumItem)4 TTCN3_Enumerated_Type (org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Enumerated_Type)4 Bitstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Bitstring_Value)4 Charstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Charstring_Value)4 Enumerated_Value (org.eclipse.titan.designer.AST.TTCN3.values.Enumerated_Value)4 Octetstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Octetstring_Value)4 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)3 Referenced_Value (org.eclipse.titan.designer.AST.TTCN3.values.Referenced_Value)3 Referenced_Template (org.eclipse.titan.designer.AST.TTCN3.templates.Referenced_Template)2 TTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.TTCN3Template)2 Hexstring_Value (org.eclipse.titan.designer.AST.TTCN3.values.Hexstring_Value)2 Real_Value (org.eclipse.titan.designer.AST.TTCN3.values.Real_Value)2 Undefined_LowerIdentifier_Value (org.eclipse.titan.designer.AST.TTCN3.values.Undefined_LowerIdentifier_Value)2