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