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;
}
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;
}
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;
}
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;
}
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");
}
Aggregations