use of org.eclipse.titan.designer.AST.IValue in project titan.EclipsePlug-ins by eclipse.
the class ReplaceExpression method generateCodeExpressionExpression.
@Override
public /**
* {@inheritDoc}
*/
void generateCodeExpressionExpression(final JavaGenData aData, final ExpressionStruct expression) {
if (lastValue != null && lastValue != this) {
lastValue.generateCodeExpression(aData, expression, true);
return;
}
final IValue lastValue2 = value2.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE, null);
final IValue lastValue3 = value3.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE, null);
// TODO handle the needs conversion case
final Type_type expressionType = templateInstance1.getExpressionReturntype(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_TEMPLATE);
switch(expressionType) {
case TYPE_BITSTRING:
case TYPE_HEXSTRING:
case TYPE_OCTETSTRING:
case TYPE_CHARSTRING:
case TYPE_UCHARSTRING:
aData.addCommonLibraryImport("AdditionalFunctions");
expression.expression.append("AdditionalFunctions.replace( ");
templateInstance1.generateCode(aData, expression, Restriction_type.TR_NONE);
expression.expression.append(", ");
if (lastValue2.isUnfoldable(CompilationTimeStamp.getBaseTimestamp()) || !((Integer_Value) lastValue2).isNative()) {
lastValue2.generateCodeExpressionMandatory(aData, expression, true);
} else {
final long tempNative = ((Integer_Value) lastValue2).getValue();
expression.expression.append(tempNative);
}
expression.expression.append(", ");
if (lastValue3.isUnfoldable(CompilationTimeStamp.getBaseTimestamp()) || !((Integer_Value) lastValue3).isNative()) {
lastValue3.generateCodeExpressionMandatory(aData, expression, true);
} else {
final long tempNative = ((Integer_Value) lastValue3).getValue();
expression.expression.append(tempNative);
}
expression.expression.append(", ");
templateInstance4.generateCode(aData, expression, Restriction_type.TR_NONE);
expression.expression.append(')');
break;
case TYPE_SEQUENCE_OF:
case TYPE_SET_OF:
// TODO: need to test
templateInstance1.generateCode(aData, expression, Restriction_type.TR_NONE);
expression.expression.append(".replace( ");
if (lastValue2.isUnfoldable(CompilationTimeStamp.getBaseTimestamp()) || !((Integer_Value) lastValue2).isNative()) {
lastValue2.generateCodeExpressionMandatory(aData, expression, true);
} else {
final long tempNative = ((Integer_Value) lastValue2).getValue();
expression.expression.append(tempNative);
}
expression.expression.append(", ");
if (lastValue3.isUnfoldable(CompilationTimeStamp.getBaseTimestamp()) || !((Integer_Value) lastValue3).isNative()) {
lastValue3.generateCodeExpressionMandatory(aData, expression, true);
} else {
final long tempNative = ((Integer_Value) lastValue3).getValue();
expression.expression.append(tempNative);
}
expression.expression.append(", ");
templateInstance4.generateCode(aData, expression, Restriction_type.TR_NONE);
expression.expression.append(')');
break;
default:
ErrorReporter.INTERNAL_ERROR("FATAL ERROR while generating code for expression `" + getFullName() + "''");
break;
}
}
use of org.eclipse.titan.designer.AST.IValue in project titan.EclipsePlug-ins by eclipse.
the class ReplaceExpression 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.IValue in project titan.EclipsePlug-ins by eclipse.
the class RotateLeftExpression 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;
}
if (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(rotateLeft(string, shiftSize));
lastValue.copyGeneralProperties(this);
break;
case HEXSTRING_VALUE:
string = ((Hexstring_Value) last1).getValue();
shiftSize = ((Integer_Value) last2).intValue();
lastValue = new Hexstring_Value(rotateLeft(string, shiftSize));
lastValue.copyGeneralProperties(this);
break;
case OCTETSTRING_VALUE:
string = ((Octetstring_Value) last1).getValue();
shiftSize = ((Integer_Value) last2).intValue() * 2;
lastValue = new Octetstring_Value(rotateLeft(string, shiftSize));
lastValue.copyGeneralProperties(this);
break;
case CHARSTRING_VALUE:
string = ((Charstring_Value) last1).getValue();
shiftSize = ((Integer_Value) last2).intValue();
lastValue = new Charstring_Value(rotateLeft(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(rotateLeft(string2, shiftSize));
lastValue.copyGeneralProperties(this);
break;
default:
setIsErroneous(true);
break;
}
return lastValue;
}
use of org.eclipse.titan.designer.AST.IValue 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.IValue in project titan.EclipsePlug-ins by eclipse.
the class IsValueExpression method checkExpressionTemplateInstance.
/**
* Checks if the templateinstance parameter (which is a parameter of the
* expression parameter) is actually a constant or static value or not.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param expression
* the expression to report the possible errors to.
* @param instance
* the template instance parameter of the expression to
* be checked.
* @param type
* the type against which the template instance shall be
* checked.
* @param referenceChain
* the referencechain to detect circular references.
* @param expectedValue
* the expected value of the template instance.
*/
public static void checkExpressionTemplateInstance(final CompilationTimeStamp timestamp, final Expression_Value expression, final TemplateInstance instance, final IType type, final IReferenceChain referenceChain, final Expected_Value_type expectedValue) {
Expected_Value_type internalExpectation;
if (Expected_Value_type.EXPECTED_DYNAMIC_VALUE.equals(expectedValue)) {
internalExpectation = Expected_Value_type.EXPECTED_TEMPLATE;
} else {
internalExpectation = expectedValue;
}
instance.check(timestamp, type);
if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(internalExpectation) && instance.getDerivedReference() != null) {
if (Expected_Value_type.EXPECTED_CONSTANT.equals(internalExpectation)) {
instance.getLocation().reportSemanticError(CONSTEXPECTED1);
} else {
instance.getLocation().reportSemanticError(STATICEXPECTED1);
}
expression.setIsErroneous(true);
}
ITTCN3Template template = instance.getTemplateBody();
if (template.getIsErroneous(timestamp)) {
expression.setIsErroneous(true);
return;
}
switch(template.getTemplatetype()) {
case TEMPLATE_REFD:
if (Expected_Value_type.EXPECTED_TEMPLATE.equals(internalExpectation)) {
template = template.getTemplateReferencedLast(timestamp, referenceChain);
if (template.getIsErroneous(timestamp)) {
expression.setIsErroneous(true);
}
} else {
if (Expected_Value_type.EXPECTED_CONSTANT.equals(internalExpectation)) {
instance.getLocation().reportSemanticError(MessageFormat.format(CONSTEXPECTED2, ((Referenced_Template) template).getReference().getRefdAssignment(timestamp, true).getDescription()));
} else {
instance.getLocation().reportSemanticError(MessageFormat.format(STATICEXPECTED2, ((Referenced_Template) template).getReference().getRefdAssignment(timestamp, true).getDescription()));
}
expression.setIsErroneous(true);
}
break;
case SPECIFIC_VALUE:
final IValue tempValue = ((SpecificValue_Template) template).getSpecificValue();
switch(tempValue.getValuetype()) {
case REFERENCED_VALUE:
type.checkThisValueRef(timestamp, tempValue);
break;
case EXPRESSION_VALUE:
tempValue.getValueRefdLast(timestamp, referenceChain);
break;
default:
break;
}
if (tempValue.getIsErroneous(timestamp)) {
expression.setIsErroneous(true);
}
break;
default:
break;
}
}
Aggregations