use of org.eclipse.titan.designer.AST.TTCN3.types.CompField in project titan.EclipsePlug-ins by eclipse.
the class Anytype_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, final 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.getName());
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.types.CompField in project titan.EclipsePlug-ins by eclipse.
the class TTCN3_Set_Type method getRawLength.
@Override
public /**
* {@inheritDoc}
*/
int getRawLength() {
int rawLength = 0;
for (int i = 0; i < getNofComponents(); i++) {
final CompField cf = getComponentByIndex(i);
if (cf.isOptional()) {
rawLength = -1;
return rawLength;
}
final int l = cf.getType().getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp()).getRawLength();
if (l == -1) {
rawLength = -1;
return rawLength;
}
final Type t = cf.getType();
if (t.rawAttribute != null && (t.rawAttribute.pointerto != null || t.rawAttribute.lengthto != null)) {
rawLength = -1;
return rawLength;
}
rawLength += l;
}
return rawLength;
}
use of org.eclipse.titan.designer.AST.TTCN3.types.CompField in project titan.EclipsePlug-ins by eclipse.
the class TTCN3_Set_Type method checkThisNamedTemplateList.
/**
* Checks the provided named template list against this type.
*
* @param timestamp the timestamp of the actual semantic check cycle.
* @param templateList the template list to check
* @param isModified is the template modified or not ?
* @param implicitOmit indicates whether the template has the implicit omit attribute set or not.
*/
private boolean checkThisNamedTemplateList(final CompilationTimeStamp timestamp, final Named_Template_List templateList, final boolean isModified, final boolean implicitOmit, final Assignment lhs) {
templateList.removeGeneratedValues();
boolean selfReference = false;
final Map<String, NamedTemplate> componentMap = new HashMap<String, NamedTemplate>();
final int nofTypeComponents = getNofComponents();
final int nofTemplateComponents = templateList.getNofTemplates();
final Map<String, CompField> realComponents = compFieldMap.getComponentFieldMap(timestamp);
for (int i = 0; i < nofTemplateComponents; i++) {
final NamedTemplate namedTemplate = templateList.getTemplateByIndex(i);
final Identifier identifier = namedTemplate.getName();
final String templateName = identifier.getName();
if (realComponents.containsKey(templateName)) {
if (componentMap.containsKey(templateName)) {
namedTemplate.getLocation().reportSemanticError(MessageFormat.format(DUPLICATETEMPLATEFIELDFIRST, identifier.getDisplayName()));
componentMap.get(templateName).getLocation().reportSemanticError(MessageFormat.format(DUPLICATETEMPLATEFIELDAGAIN, identifier.getDisplayName()));
} else {
componentMap.put(templateName, namedTemplate);
}
final CompField componentField = getComponentByName(identifier.getName());
final Type type = componentField.getType();
ITTCN3Template componentTemplate = namedTemplate.getTemplate();
componentTemplate.setMyGovernor(type);
componentTemplate = type.checkThisTemplateRef(timestamp, componentTemplate);
final boolean isOptional = componentField.isOptional();
selfReference |= componentTemplate.checkThisTemplateGeneric(timestamp, type, isModified, isOptional, isOptional, true, implicitOmit, lhs);
} else {
namedTemplate.getLocation().reportSemanticError(MessageFormat.format(NONEXISTENTTEMPLATEFIELDREFERENCE, identifier.getDisplayName(), getTypename()));
}
}
if (!isModified && strictConstantCheckingSeverity) {
// check missing fields
for (int i = 0; i < nofTypeComponents; i++) {
final Identifier identifier = getComponentIdentifierByIndex(i);
if (!componentMap.containsKey(identifier.getName())) {
if (getComponentByIndex(i).isOptional() && implicitOmit) {
templateList.addNamedValue(new NamedTemplate(new Identifier(Identifier_type.ID_TTCN, identifier.getDisplayName()), new OmitValue_Template(), false));
} else {
templateList.getLocation().reportSemanticError(MessageFormat.format(MISSINGTEMPLATEFIELD, identifier.getDisplayName(), getTypename()));
}
}
}
}
return selfReference;
}
Aggregations