use of org.eclipse.titan.designer.AST.TTCN3.values.Integer_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;
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value in project titan.EclipsePlug-ins by eclipse.
the class ShiftLeftExpression 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;
long shiftSize;
switch(last1.getValuetype()) {
case BITSTRING_VALUE:
string = ((Bitstring_Value) last1).getValue();
shiftSize = ((Integer_Value) last2).getValue();
lastValue = new Bitstring_Value(shiftLeft(string, shiftSize));
lastValue.copyGeneralProperties(this);
break;
case HEXSTRING_VALUE:
string = ((Hexstring_Value) last1).getValue();
shiftSize = ((Integer_Value) last2).getValue();
lastValue = new Hexstring_Value(shiftLeft(string, shiftSize));
lastValue.copyGeneralProperties(this);
break;
case OCTETSTRING_VALUE:
string = ((Octetstring_Value) last1).getValue();
shiftSize = ((Integer_Value) last2).getValue() * 2;
lastValue = new Octetstring_Value(shiftLeft(string, shiftSize));
lastValue.copyGeneralProperties(this);
break;
default:
setIsErroneous(true);
break;
}
return lastValue;
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value in project titan.EclipsePlug-ins by eclipse.
the class SizeOfExpression 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;
}
final long i = checkExpressionOperands(timestamp, expectedValue, referenceChain);
if (i != -1) {
lastValue = new Integer_Value(i);
lastValue.copyGeneralProperties(this);
}
if (getIsErroneous(timestamp) || isUnfoldable(timestamp, referenceChain)) {
return lastValue;
}
return lastValue;
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value in project titan.EclipsePlug-ins by eclipse.
the class Str2IntExpression 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) || isUnfoldable(timestamp, referenceChain)) {
return lastValue;
}
final IValue last = value.getValueRefdLast(timestamp, referenceChain);
if (last.getIsErroneous(timestamp)) {
return lastValue;
}
switch(last.getValuetype()) {
case CHARSTRING_VALUE:
{
String string = ((Charstring_Value) last).getValue();
string = string.trim();
try {
lastValue = new Integer_Value(string);
} catch (NumberFormatException e) {
// It seems to be a double check. The string
// must hold a
// valid number at this point. The exception is
// thrown by
// BigInteger not Integer_Value.
lastValue = new Integer_Value(0L);
}
break;
}
default:
return this;
}
lastValue.copyGeneralProperties(this);
return lastValue;
}
use of org.eclipse.titan.designer.AST.TTCN3.values.Integer_Value in project titan.EclipsePlug-ins by eclipse.
the class SubstrExpression method checkExpressionOperandsHelper.
private void checkExpressionOperandsHelper(final CompilationTimeStamp timestamp, final IValue value1, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
if (value1 == null || value2 == null || value3 == null || getIsErroneous(timestamp)) {
return;
}
long valueSize = -1;
if (!value1.isUnfoldable(timestamp)) {
IValue temp = value1.setLoweridToReference(timestamp);
temp = temp.getValueRefdLast(timestamp, referenceChain);
switch(temp.getValuetype()) {
case BITSTRING_VALUE:
valueSize = ((Bitstring_Value) temp).getValueLength();
break;
case HEXSTRING_VALUE:
valueSize = ((Hexstring_Value) temp).getValueLength();
break;
case OCTETSTRING_VALUE:
valueSize = ((Octetstring_Value) temp).getValueLength();
break;
case CHARSTRING_VALUE:
valueSize = ((Charstring_Value) temp).getValueLength();
break;
case UNIVERSALCHARSTRING_VALUE:
valueSize = ((UniversalCharstring_Value) temp).getValueLength();
break;
case SEQUENCEOF_VALUE:
valueSize = ((SequenceOf_Value) temp).getNofComponents();
if (valueSize == 0) {
templateInstance1.getLocation().reportSemanticError(OPERANDERROR11);
}
break;
case SETOF_VALUE:
valueSize = ((SetOf_Value) temp).getNofComponents();
if (valueSize == 0) {
templateInstance1.getLocation().reportSemanticError(OPERANDERROR11);
}
break;
default:
break;
}
}
if (valueSize < 0) {
return;
}
if (value2.isUnfoldable(timestamp)) {
if (!value3.isUnfoldable(timestamp)) {
final IValue last3 = value3.getValueRefdLast(timestamp, expectedValue, referenceChain);
final long last3Value = ((Integer_Value) last3).getValue();
if (last3Value > valueSize) {
location.reportSemanticError(MessageFormat.format(OPERANDERROR6, last3Value, valueSize));
setIsErroneous(true);
}
}
} else {
final IValue last2 = value2.getValueRefdLast(timestamp, expectedValue, referenceChain);
final long last2Value = ((Integer_Value) last2).getValue();
if (value3.isUnfoldable(timestamp)) {
if (last2Value > valueSize) {
location.reportSemanticError(MessageFormat.format(OPERANDERROR7, last2Value, valueSize));
setIsErroneous(true);
}
} else {
final IValue last3 = value3.getValueRefdLast(timestamp, expectedValue, referenceChain);
final long last3Value = ((Integer_Value) last3).getValue();
if (last2Value + last3Value > valueSize) {
location.reportSemanticError(MessageFormat.format(OPERANDERROR8, last2Value, last3Value, valueSize));
setIsErroneous(true);
}
}
}
}
Aggregations