use of org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type in project titan.EclipsePlug-ins by eclipse.
the class Str2FloatExpression 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();
double number;
if ("-infinity".equals(string)) {
number = Float.NEGATIVE_INFINITY;
} else if ("infinity".equals(string)) {
number = Float.POSITIVE_INFINITY;
} else if ("not_a_number".equals(string)) {
number = Float.NaN;
} else {
try {
number = Double.parseDouble(string);
} catch (NumberFormatException e) {
number = 0;
}
}
lastValue = new Real_Value(number);
break;
}
default:
return this;
}
lastValue.copyGeneralProperties(this);
return lastValue;
}
use of org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type in project titan.EclipsePlug-ins by eclipse.
the class Str2HexExpression 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_CHARSTRING:
final IValue last = value.getValueRefdLast(timestamp, expectedValue, referenceChain);
if (!last.isUnfoldable(timestamp)) {
final String string = ((Charstring_Value) last).getValue();
final byte[] bytes = string.getBytes();
for (int i = 0; i < bytes.length; i++) {
final byte c = bytes[i];
final boolean isLetter = (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f');
final boolean isDigit = c >= '0' && c <= '9';
if (!(isLetter || isDigit)) {
value.getLocation().reportSemanticError(OPERANDERROR2);
setIsErroneous(true);
return;
}
}
}
return;
case TYPE_UNDEFINED:
setIsErroneous(true);
return;
default:
if (!isErroneous) {
location.reportSemanticError(OPERANDERROR1);
setIsErroneous(true);
}
return;
}
}
use of org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type in project titan.EclipsePlug-ins by eclipse.
the class Str2HexExpression 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:
final String string = ((Charstring_Value) last).getValue();
lastValue = new Hexstring_Value(string.toUpperCase());
break;
default:
return this;
}
lastValue.copyGeneralProperties(this);
return lastValue;
}
use of org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type in project titan.EclipsePlug-ins by eclipse.
the class Str2IntExpression 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_CHARSTRING:
final IValue last = value.getValueRefdLast(timestamp, expectedValue, referenceChain);
if (!last.isUnfoldable(timestamp)) {
String string = ((Charstring_Value) last).getValue();
string = string.trim();
if (!string.isEmpty() && string.charAt(0) == '+') {
string = string.substring(1);
}
try {
new Integer_Value(string);
} catch (NumberFormatException e) {
// The exception is thrown by BigInteger
// not Integer_Value.
value.getLocation().reportSemanticError(OPERANDERROR2);
}
}
return;
case TYPE_UNDEFINED:
setIsErroneous(true);
return;
default:
if (!isErroneous) {
location.reportSemanticError(OPERANDERROR1);
setIsErroneous(true);
}
return;
}
}
use of org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type in project titan.EclipsePlug-ins by eclipse.
the class StringConcatenationExpression 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)) {
return lastValue;
}
switch(last1.getValuetype()) {
case BITSTRING_VALUE:
{
final String string1 = ((Bitstring_Value) last1).getValue();
final String string2 = ((Bitstring_Value) last2).getValue();
lastValue = new Bitstring_Value(string1 + string2);
lastValue.copyGeneralProperties(this);
break;
}
case HEXSTRING_VALUE:
{
final String string1 = ((Hexstring_Value) last1).getValue();
final String string2 = ((Hexstring_Value) last2).getValue();
lastValue = new Hexstring_Value(string1 + string2);
lastValue.copyGeneralProperties(this);
break;
}
case OCTETSTRING_VALUE:
{
final String string1 = ((Octetstring_Value) last1).getValue();
final String string2 = ((Octetstring_Value) last2).getValue();
lastValue = new Octetstring_Value(string1 + string2);
lastValue.copyGeneralProperties(this);
break;
}
case CHARSTRING_VALUE:
{
final String string1 = ((Charstring_Value) last1).getValue();
if (Value_type.UNIVERSALCHARSTRING_VALUE.equals(last2.getValuetype())) {
final UniversalCharstring string2 = ((UniversalCharstring_Value) last2).getValue();
lastValue = new UniversalCharstring_Value(new UniversalCharstring(string1).append(string2));
} else {
final String string2 = ((Charstring_Value) last2).getValue();
lastValue = new Charstring_Value(string1 + string2);
}
lastValue.copyGeneralProperties(this);
break;
}
case UNIVERSALCHARSTRING_VALUE:
{
final UniversalCharstring string1 = ((UniversalCharstring_Value) last1).getValue();
if (Value_type.UNIVERSALCHARSTRING_VALUE.equals(last2.getValuetype())) {
final UniversalCharstring string2 = ((UniversalCharstring_Value) last2).getValue();
lastValue = new UniversalCharstring_Value(new UniversalCharstring(string1).append(string2));
} else {
final String string2 = ((Charstring_Value) last2).getValue();
lastValue = new UniversalCharstring_Value(new UniversalCharstring(string1).append(string2));
}
lastValue.copyGeneralProperties(this);
break;
}
default:
setIsErroneous(true);
break;
}
return lastValue;
}
Aggregations