use of org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct in project titan.EclipsePlug-ins by eclipse.
the class ASN1_Choice_Type method generateCodeIsPresentBoundChosen.
@Override
public /**
* {@inheritDoc}
*/
void generateCodeIsPresentBoundChosen(final JavaGenData aData, final ExpressionStruct expression, final List<ISubReference> subreferences, final int subReferenceIndex, final String globalId, final String externalId, final boolean isTemplate, final Operation_type optype, String field) {
if (subreferences == null || getIsErroneous(CompilationTimeStamp.getBaseTimestamp())) {
return;
}
if (subReferenceIndex >= subreferences.size()) {
return;
}
final StringBuilder closingBrackets = new StringBuilder();
if (isTemplate) {
boolean anyvalueReturnValue = true;
if (optype == Operation_type.ISPRESENT_OPERATION) {
anyvalueReturnValue = isPresentAnyvalueEmbeddedField(expression, subreferences, subReferenceIndex);
} else if (optype == Operation_type.ISCHOOSEN_OPERATION) {
anyvalueReturnValue = false;
}
expression.expression.append(MessageFormat.format("if({0}) '{'\n", globalId));
expression.expression.append(MessageFormat.format("switch({0}.getSelection()) '{'\n", externalId));
expression.expression.append("case UNINITIALIZED_TEMPLATE:\n");
expression.expression.append(MessageFormat.format("{0} = false;\n", globalId));
expression.expression.append("break;\n");
expression.expression.append("case ANY_VALUE:\n");
expression.expression.append(MessageFormat.format("{0} = {1};\n", globalId, anyvalueReturnValue ? "true" : "false"));
expression.expression.append("break;\n");
expression.expression.append("case SPECIFIC_VALUE:{\n");
closingBrackets.append("break;}\n");
closingBrackets.append("default:\n");
closingBrackets.append(MessageFormat.format("{0} = false;\n", globalId));
closingBrackets.append("break;\n");
closingBrackets.append("}\n");
closingBrackets.append("}\n");
}
final ISubReference subReference = subreferences.get(subReferenceIndex);
if (!(subReference instanceof FieldSubReference)) {
ErrorReporter.INTERNAL_ERROR("Code generator reached erroneous type reference `" + getFullName() + "''");
expression.expression.append("FATAL_ERROR encountered");
return;
}
final Identifier fieldId = ((FieldSubReference) subReference).getId();
expression.expression.append(MessageFormat.format("if({0}) '{'\n", globalId));
expression.expression.append(MessageFormat.format("{0} = {1}.isChosen({2}.union_selection_type.ALT_{3});\n", globalId, externalId, getGenNameValue(aData, expression.expression, myScope), FieldSubReference.getJavaGetterName(fieldId.getName())));
expression.expression.append("}\n");
final CompField compField = getComponentByName(fieldId);
final Type nextType = compField.getType();
expression.expression.append(MessageFormat.format("if({0}) '{'\n", globalId));
closingBrackets.insert(0, "}\n");
final String temporalId = aData.getTemporaryVariableName();
final String temporalId2 = aData.getTemporaryVariableName();
expression.expression.append(MessageFormat.format("{0}{1} {2} = new {0}{1}({3});\n", getGenNameValue(aData, expression.expression, myScope), isTemplate ? "_template" : "", temporalId, externalId));
expression.expression.append(MessageFormat.format("{0}{1} {2} = {3}.get{4}();\n", nextType.getGenNameValue(aData, expression.expression, myScope), isTemplate ? "_template" : "", temporalId2, temporalId, FieldSubReference.getJavaGetterName(fieldId.getName())));
if (optype == Operation_type.ISBOUND_OPERATION) {
expression.expression.append(MessageFormat.format("{0} = {1}.isBound();\n", globalId, temporalId2));
} else if (optype == Operation_type.ISPRESENT_OPERATION) {
expression.expression.append(MessageFormat.format("{0} = {1}.isPresent({2});\n", globalId, temporalId2, isTemplate && aData.getAllowOmitInValueList() ? "true" : ""));
} else if (optype == Operation_type.ISCHOOSEN_OPERATION) {
expression.expression.append(MessageFormat.format("{0} = {1}.isBound();\n", globalId, temporalId2));
if (subReferenceIndex == subreferences.size() - 1) {
expression.expression.append(MessageFormat.format("if ({0}) '{'\n", globalId));
expression.expression.append(MessageFormat.format("{0} = {1}.isChosen({2});\n", globalId, temporalId2, field));
expression.expression.append("}\n");
}
}
nextType.generateCodeIsPresentBoundChosen(aData, expression, subreferences, subReferenceIndex + 1, globalId, temporalId2, isTemplate, optype, field);
expression.expression.append(closingBrackets);
}
use of org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct in project titan.EclipsePlug-ins by eclipse.
the class SelectCase method generateCode.
/**
* Add generated java code for a single select case.
*
* @param aData the structure to put imports into and get temporal variable names from.
* @param source the source code generated
* @param name the name to compare the branch variables to (expression or temporary name)
* @param unReachable tells whether this branch is already unreachable because of previous conditions
*/
public void generateCode(final JavaGenData aData, final StringBuilder source, final String name, final AtomicBoolean unreach) {
ExpressionStruct expression = new ExpressionStruct();
StringBuilder condition = new StringBuilder();
if (templateInstances != null) {
for (int i = 0; i < templateInstances.getNofTis(); i++) {
final String tmp = aData.getTemporaryVariableName();
final TemplateInstance templateInstance = templateInstances.getInstanceByIndex(i);
final TTCN3Template templateBody = templateInstance.getTemplateBody();
final boolean isValue = templateInstance.getDerivedReference() == null && templateBody.isValue(CompilationTimeStamp.getBaseTimestamp());
final IType last = templateInstance.getExpressionGovernor(CompilationTimeStamp.getBaseTimestamp(), Expected_Value_type.EXPECTED_DYNAMIC_VALUE);
if (i > 0) {
condition.append(" || ");
}
if (isValue) {
final String genName = last.getGenNameValue(aData, expression.expression, last.getMyScope());
expression.expression.append(MessageFormat.format("{0} {1} = new {0} (", genName, tmp));
IValue value = templateBody.getValue();
value.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), null);
value.generateCodeExpressionMandatory(aData, expression, true);
expression.expression.append(");\n");
condition.append(MessageFormat.format("{0}.operatorEquals({1})", tmp, name));
} else {
final String genName = last.getGenNameTemplate(aData, expression.expression, last.getMyScope());
expression.expression.append(MessageFormat.format("{0} {1} = new {0} (", genName, tmp));
templateInstance.generateCode(aData, expression, Restriction_type.TR_NONE);
expression.expression.append(");\n");
condition.append(MessageFormat.format("{0}.match({1})", tmp, name));
}
}
source.append(expression.preamble);
source.append(expression.expression);
source.append(expression.postamble);
getLocation().update_location_object(aData, source);
source.append("if (").append(condition).append(") {\n");
statementBlock.generateCode(aData, source);
source.append("}\n");
} else {
statementBlock.generateCode(aData, source);
unreach.set(true);
}
}
use of org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct in project titan.EclipsePlug-ins by eclipse.
the class SelectUnionCase_Statement method generateCode.
@Override
public /**
* {@inheritDoc}
*/
void generateCode(final JavaGenData aData, final StringBuilder source) {
final ExpressionStruct expressionStruct = new ExpressionStruct();
expression.generateCodeExpression(aData, expressionStruct, true);
source.append(expressionStruct.preamble);
source.append(MessageFormat.format("switch({0}.get_selection()) '{'\n", expressionStruct.expression));
selectUnionCases.generateCode(aData, source);
source.append("}\n");
source.append(expressionStruct.postamble);
}
use of org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct in project titan.EclipsePlug-ins by eclipse.
the class Send_Statement method generateCode.
@Override
public /**
* {@inheritDoc}
*/
void generateCode(final JavaGenData aData, final StringBuilder source) {
final ExpressionStruct expression = new ExpressionStruct();
portReference.generateCode(aData, expression);
expression.expression.append(".send(");
final TTCN3Template templateBody = parameter.getTemplateBody();
if (parameter.getDerivedReference() == null && Template_type.SPECIFIC_VALUE.equals(templateBody.getTemplatetype()) && ((SpecificValue_Template) templateBody).isValue(CompilationTimeStamp.getBaseTimestamp())) {
// optimize for value
final IValue value = ((SpecificValue_Template) templateBody).getValue();
// FIXME check if casting is needed
value.generateCodeExpressionMandatory(aData, expression, true);
} else {
// real template, can not be optimized
parameter.generateCode(aData, expression, Restriction_type.TR_NONE);
}
expression.expression.append(", ");
if (toClause == null) {
expression.expression.append("new TitanComponent(TitanComponent.SYSTEM_COMPREF)");
} else {
toClause.generateCodeExpression(aData, expression, true);
}
expression.expression.append(")");
expression.mergeExpression(source);
}
use of org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct in project titan.EclipsePlug-ins by eclipse.
the class Setverdict_Statement method generateCode.
@Override
public /**
* {@inheritDoc}
*/
void generateCode(final JavaGenData aData, final StringBuilder source) {
final ExpressionStruct expression = new ExpressionStruct();
aData.addCommonLibraryImport("TTCN_Runtime");
expression.expression.append("TTCN_Runtime.setverdict(");
verdictValue.generateCodeExpression(aData, expression, false);
if (verdictReason != null) {
expression.expression.append(", ");
final ExpressionStruct reason = new ExpressionStruct();
verdictReason.generateCodeExpression(aData, reason);
if (reason.preamble.length() > 0) {
expression.preamble.append(reason.preamble);
}
if (reason.postamble.length() > 0) {
expression.postamble.append(reason.postamble);
}
expression.expression.append(reason.expression);
expression.expression.append(".getValue().toString()");
}
expression.expression.append(')');
expression.mergeExpression(source);
}
Aggregations