use of org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type in project titan.EclipsePlug-ins by eclipse.
the class SubstrExpression 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 (templateInstance1 == null || value2 == null || value3 == null) {
return lastValue;
}
checkExpressionOperands(timestamp, expectedValue, referenceChain);
if (getIsErroneous(timestamp) || isUnfoldable(timestamp, referenceChain)) {
return lastValue;
}
final ITTCN3Template temp = templateInstance1.getTemplateBody();
final IValue value1 = ((SpecificValue_Template) temp).getSpecificValue();
final IValue v1 = value1.getValueRefdLast(timestamp, referenceChain);
final IValue v2 = value2.getValueRefdLast(timestamp, referenceChain);
final IValue v3 = value3.getValueRefdLast(timestamp, referenceChain);
final int index = (int) ((Integer_Value) v2).getValue();
final int len = (int) ((Integer_Value) v3).getValue();
switch(v1.getValuetype()) {
case BITSTRING_VALUE:
lastValue = new Bitstring_Value(((Bitstring_Value) v1).getValue().substring(index, index + len));
lastValue.copyGeneralProperties(this);
break;
case HEXSTRING_VALUE:
lastValue = new Hexstring_Value(((Hexstring_Value) v1).getValue().substring(index, index + len));
lastValue.copyGeneralProperties(this);
break;
case OCTETSTRING_VALUE:
lastValue = new Octetstring_Value(((Octetstring_Value) v1).getValue().substring(index * 2, (index + len) * 2));
lastValue.copyGeneralProperties(this);
break;
case CHARSTRING_VALUE:
lastValue = new Charstring_Value(((Charstring_Value) v1).getValue().substring(index, index + len));
lastValue.copyGeneralProperties(this);
break;
case UNIVERSALCHARSTRING_VALUE:
lastValue = new UniversalCharstring_Value(((UniversalCharstring_Value) v1).getValue().substring(index, index + len));
lastValue.copyGeneralProperties(this);
break;
default:
setIsErroneous(true);
break;
}
return lastValue;
}
use of org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type in project titan.EclipsePlug-ins by eclipse.
the class SubstrExpression method isUnfoldable.
@Override
public /**
* {@inheritDoc}
*/
boolean isUnfoldable(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
if (templateInstance1 == null || value2 == null || value3 == null || getIsErroneous(timestamp)) {
return true;
}
ITTCN3Template template = templateInstance1.getTemplateBody();
if (template == null || !Template_type.SPECIFIC_VALUE.equals(template.getTemplatetype())) {
return true;
}
final IValue value1 = ((SpecificValue_Template) template).getSpecificValue();
if (value1 == null) {
return true;
}
template = template.setLoweridToReference(timestamp);
final Type_type tempType = template.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
switch(tempType) {
case TYPE_BITSTRING:
case TYPE_HEXSTRING:
case TYPE_OCTETSTRING:
case TYPE_CHARSTRING:
case TYPE_UCHARSTRING:
break;
default:
return true;
}
return value1.isUnfoldable(timestamp, expectedValue, referenceChain) || value2.isUnfoldable(timestamp, expectedValue, referenceChain) || value3.isUnfoldable(timestamp, expectedValue, referenceChain);
}
use of org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type in project titan.EclipsePlug-ins by eclipse.
the class SubstrExpression method getExpressionReturntype.
@Override
public /**
* {@inheritDoc}
*/
Type_type getExpressionReturntype(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue) {
final IValue last = getValueRefdLast(timestamp, expectedValue, null);
if (last == null || templateInstance1 == null) {
return Type_type.TYPE_UNDEFINED;
}
if (last.getIsErroneous(timestamp)) {
setIsErroneous(true);
return Type_type.TYPE_UNDEFINED;
}
final ITTCN3Template template = templateInstance1.getTemplateBody().setLoweridToReference(timestamp);
final Type_type tempType = template.getExpressionReturntype(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
switch(tempType) {
case TYPE_BITSTRING:
case TYPE_HEXSTRING:
case TYPE_OCTETSTRING:
case TYPE_CHARSTRING:
case TYPE_UCHARSTRING:
case TYPE_SET_OF:
case TYPE_SEQUENCE_OF:
return tempType;
case TYPE_UNDEFINED:
return tempType;
default:
setIsErroneous(true);
return Type_type.TYPE_UNDEFINED;
}
}
use of org.eclipse.titan.designer.AST.TTCN3.Expected_Value_type in project titan.EclipsePlug-ins by eclipse.
the class Int2CharExpression 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_INTEGER:
final IValue last = value.getValueRefdLast(timestamp, expectedValue, referenceChain);
if (!last.isUnfoldable(timestamp) && Value.Value_type.INTEGER_VALUE.equals(last.getValuetype())) {
final Integer_Value i = (Integer_Value) last;
if (i.signum() < 0 || i.compareTo(new Integer_Value(127)) > 0) {
value.getLocation().reportSemanticError(OPERANDERROR2);
setIsErroneous(true);
}
}
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 Int2FloatExpression 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)) {
return lastValue;
}
if (isUnfoldable(timestamp, referenceChain)) {
return lastValue;
}
final IValue last = value.getValueRefdLast(timestamp, referenceChain);
if (last.getIsErroneous(timestamp)) {
setIsErroneous(true);
return lastValue;
}
switch(last.getValuetype()) {
case INTEGER_VALUE:
lastValue = new Real_Value(((Integer_Value) last).floatValue());
lastValue.copyGeneralProperties(this);
break;
default:
setIsErroneous(true);
break;
}
return lastValue;
}
Aggregations