use of org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct in project titan.EclipsePlug-ins by eclipse.
the class ASN1_Set_Seq_Choice_BaseType 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();
final CompField compField = getComponentByName(fieldId);
final Type nextType = compField.getType();
final boolean nextOptional = !isTemplate && compField.isOptional();
if (nextOptional) {
expression.expression.append(MessageFormat.format("if({0}) '{'\n", globalId));
closingBrackets.insert(0, "}\n");
final String temporalId = aData.getTemporaryVariableName();
expression.expression.append(MessageFormat.format("Optional<{0}{1}> {2} = {3}.get{4}();\n", nextType.getGenNameValue(aData, expression.expression, myScope), isTemplate ? "_template" : "", temporalId, externalId, FieldSubReference.getJavaGetterName(fieldId.getName())));
if (subReferenceIndex == subreferences.size() - 1) {
expression.expression.append(MessageFormat.format("switch({0}.getSelection()) '{'\n", temporalId));
expression.expression.append("case OPTIONAL_UNBOUND:\n");
expression.expression.append(MessageFormat.format("{0} = false;\n", globalId));
expression.expression.append("break;\n");
expression.expression.append("case OPTIONAL_OMIT:\n");
expression.expression.append(MessageFormat.format("{0} = {1};\n", globalId, optype == Operation_type.ISBOUND_OPERATION ? "true" : "false"));
expression.expression.append("break;\n");
expression.expression.append("default:\n");
expression.expression.append("{\n");
final String temporalId2 = aData.getTemporaryVariableName();
expression.expression.append(MessageFormat.format("{0}{1} {2} = {3}.constGet();\n", nextType.getGenNameValue(aData, expression.expression, myScope), isTemplate ? "_template" : "", temporalId2, temporalId));
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}.isChosen({2});\n", globalId, temporalId2, field));
}
expression.expression.append("break;}\n");
expression.expression.append("}\n");
// at the end of the reference chain
nextType.generateCodeIsPresentBoundChosen(aData, expression, subreferences, subReferenceIndex + 1, globalId, temporalId2, isTemplate, optype, field);
} else {
// still more to go
expression.expression.append(MessageFormat.format("switch({0}.getSelection()) '{'\n", temporalId));
expression.expression.append("case OPTIONAL_UNBOUND:\n");
expression.expression.append("case OPTIONAL_OMIT:\n");
expression.expression.append(MessageFormat.format("{0} = false;\n", globalId));
expression.expression.append("break;\n");
expression.expression.append("default:\n");
expression.expression.append("break;\n");
expression.expression.append("}\n");
expression.expression.append(MessageFormat.format("if({0}) '{'\n", globalId));
closingBrackets.insert(0, "}\n");
final String temporalId2 = aData.getTemporaryVariableName();
expression.expression.append(MessageFormat.format("{0}{1} {2} = {3}.constGet();\n", nextType.getGenNameValue(aData, expression.expression, myScope), isTemplate ? "_template" : "", temporalId2, temporalId));
expression.expression.append(MessageFormat.format("{0} = {1}.isBound();\n", globalId, temporalId2));
nextType.generateCodeIsPresentBoundChosen(aData, expression, subreferences, subReferenceIndex + 1, globalId, temporalId2, isTemplate, optype, field);
}
} else {
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}.{2}({3});\n", globalId, temporalId2, subReferenceIndex != subreferences.size() - 1 ? "isBound" : "isPresent", subReferenceIndex == subreferences.size() - 1 && 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 ASN1_Set_Type method isPresentAnyvalueEmbeddedField.
@Override
public /**
* {@inheritDoc}
*/
boolean isPresentAnyvalueEmbeddedField(final ExpressionStruct expression, final List<ISubReference> subreferences, final int beginIndex) {
if (subreferences == null || getIsErroneous(CompilationTimeStamp.getBaseTimestamp())) {
return true;
}
if (beginIndex >= subreferences.size()) {
return true;
}
final ISubReference subReference = subreferences.get(beginIndex);
if (!(subReference instanceof FieldSubReference)) {
ErrorReporter.INTERNAL_ERROR("Code generator reached erroneous type reference `" + getFullName() + "''");
expression.expression.append("FATAL_ERROR encountered");
return true;
}
final Identifier fieldId = ((FieldSubReference) subReference).getId();
final CompField compField = getComponentByName(fieldId);
if (compField.isOptional()) {
return false;
}
return compField.getType().isPresentAnyvalueEmbeddedField(expression, subreferences, beginIndex + 1);
}
use of org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct in project titan.EclipsePlug-ins by eclipse.
the class Referenced_Value method generateCodeInit.
@Override
public /**
* {@inheritDoc}
*/
StringBuilder generateCodeInit(final JavaGenData aData, final StringBuilder source, final String name) {
final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
final IValue last = getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), referenceChain);
referenceChain.release();
if (last == this) {
final ExpressionStruct expression = new ExpressionStruct();
expression.expression.append(name);
expression.expression.append(".assign(");
reference.generateConstRef(aData, expression);
expression.expression.append(")");
expression.mergeExpression(source);
return source;
}
// the code generation is based on the referred value
if (last.canGenerateSingleExpression() && myScope.getModuleScope() == last.getMyScope().getModuleScope()) {
// simple substitution for in-line values within the same module
source.append(MessageFormat.format("{0}.assign({1});\n", name, last.generateSingleExpression(aData)));
} else {
// TODO might need initialization see needs_init_precede
// TODO Value.cc:generate_code_init_refd
source.append(MessageFormat.format("{0}.assign({1});\n", name, last.getGenNameOwn(myScope)));
}
return source;
}
use of org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct in project titan.EclipsePlug-ins by eclipse.
the class ComponentCreateExpression method generateCodeExpressionExpression.
@Override
public /**
* {@inheritDoc}
*/
void generateCodeExpressionExpression(final JavaGenData aData, final ExpressionStruct expression) {
aData.addCommonLibraryImport("TTCN_Runtime");
expression.expression.append("TTCN_Runtime.create_component(");
// the type of the component (module name and identifier)
final Assignment assignment = componentReference.getRefdAssignment(CompilationTimeStamp.getBaseTimestamp(), false);
if (assignment == null || !Assignment_type.A_TYPE.equals(assignment.getAssignmentType())) {
ErrorReporter.INTERNAL_ERROR("FATAL ERROR while generating code for expression `" + getFullName() + "''");
return;
}
IType componentType = assignment.getType(CompilationTimeStamp.getBaseTimestamp()).getFieldType(CompilationTimeStamp.getBaseTimestamp(), componentReference, 1, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
if (componentType == null) {
ErrorReporter.INTERNAL_ERROR("FATAL ERROR while generating code for expression `" + getFullName() + "''");
return;
}
componentType = componentType.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
if (!Type_type.TYPE_COMPONENT.equals(componentType.getTypetype())) {
ErrorReporter.INTERNAL_ERROR("FATAL ERROR while generating code for expression `" + getFullName() + "''");
return;
}
((Component_Type) componentType).getComponentBody().generateCodeComponentTypeName(expression);
expression.expression.append(", ");
// third argument: component name
if (name != null) {
final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
final IValue last = name.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), referenceChain);
referenceChain.release();
if (Value_type.CHARSTRING_VALUE.equals(last.getValuetype())) {
// TODO check why translate
expression.expression.append(MessageFormat.format("\"{0}\"", ((Charstring_Value) last).getValue()));
} else {
name.generateCodeExpressionMandatory(aData, expression, false);
}
} else {
expression.expression.append("null");
}
expression.expression.append(", ");
// fourth argument location
if (location != null) {
final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
final IValue last = location.getValueRefdLast(CompilationTimeStamp.getBaseTimestamp(), referenceChain);
referenceChain.release();
if (Value_type.CHARSTRING_VALUE.equals(last.getValuetype())) {
// TODO check why translate
expression.expression.append(MessageFormat.format("\"{0}\"", ((Charstring_Value) last).getValue()));
} else {
location.generateCodeExpressionMandatory(aData, expression, false);
}
} else {
expression.expression.append("null");
}
// fifth argument: alive flag
expression.expression.append(MessageFormat.format(", {0})", isAlive ? "true" : "false"));
}
use of org.eclipse.titan.designer.AST.TTCN3.values.expressions.ExpressionStruct in project titan.EclipsePlug-ins by eclipse.
the class Expression_Value method generateCodeInit.
@Override
public /**
* {@inheritDoc}
*/
StringBuilder generateCodeInit(final JavaGenData aData, final StringBuilder source, final String name) {
final ExpressionStruct expression = new ExpressionStruct();
expression.expression.append(name);
expression.expression.append(".assign(");
generateCodeExpression(aData, expression, false);
expression.expression.append(')');
expression.mergeExpression(source);
return source;
}
Aggregations