use of org.eclipse.titan.designer.AST.TTCN3.types.CompField in project titan.EclipsePlug-ins by eclipse.
the class ASN1_Choice_Type method getFieldType.
@Override
public /**
* {@inheritDoc}
*/
IType getFieldType(final CompilationTimeStamp timestamp, final Reference reference, final int actualSubReference, final Expected_Value_type expectedIndex, final IReferenceChain refChain, final boolean interruptIfOptional) {
final List<ISubReference> subreferences = reference.getSubreferences();
if (subreferences.size() <= actualSubReference) {
return this;
}
final ISubReference subreference = subreferences.get(actualSubReference);
switch(subreference.getReferenceType()) {
case arraySubReference:
subreference.getLocation().reportSemanticError(MessageFormat.format(ArraySubReference.INVALIDSUBREFERENCE, getTypename()));
return null;
case fieldSubReference:
final Identifier id = subreference.getId();
final CompField compField = components.getCompByName(id);
if (compField == null) {
subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.NONEXISTENTSUBREFERENCE, ((FieldSubReference) subreference).getId().getDisplayName(), getTypename()));
return null;
}
final Expected_Value_type internalExpectation = (expectedIndex == Expected_Value_type.EXPECTED_TEMPLATE) ? Expected_Value_type.EXPECTED_DYNAMIC_VALUE : expectedIndex;
return compField.getType().getFieldType(timestamp, reference, actualSubReference + 1, internalExpectation, refChain, interruptIfOptional);
case parameterisedSubReference:
subreference.getLocation().reportSemanticError(MessageFormat.format(FieldSubReference.INVALIDSUBREFERENCE, ((ParameterisedSubReference) subreference).getId().getDisplayName(), getTypename()));
return null;
default:
subreference.getLocation().reportSemanticError(ISubReference.INVALIDSUBREFERENCE);
return null;
}
}
use of org.eclipse.titan.designer.AST.TTCN3.types.CompField 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.types.CompField in project titan.EclipsePlug-ins by eclipse.
the class ASN1_Choice_Type method checkCodingAttributes.
@Override
public /**
* {@inheritDoc}
*/
void checkCodingAttributes(final CompilationTimeStamp timestamp, final IReferenceChain refChain) {
if (refChain.contains(this)) {
return;
}
refChain.add(this);
refChain.markState();
for (int i = 0; i < getNofComponents(timestamp); i++) {
final CompField cf = getComponentByIndex(i);
cf.getType().checkCodingAttributes(timestamp, refChain);
}
refChain.previousState();
}
use of org.eclipse.titan.designer.AST.TTCN3.types.CompField in project titan.EclipsePlug-ins by eclipse.
the class ASN1_Choice_Type method isCompatible.
@Override
public /**
* {@inheritDoc}
*/
boolean isCompatible(final CompilationTimeStamp timestamp, final IType otherType, final TypeCompatibilityInfo info, final TypeCompatibilityInfo.Chain leftChain, final TypeCompatibilityInfo.Chain rightChain) {
check(timestamp);
otherType.check(timestamp);
final IType temp = otherType.getTypeRefdLast(timestamp);
if (getIsErroneous(timestamp) || temp.getIsErroneous(timestamp) || this == temp) {
return true;
}
if (null == info || noStructuredTypeCompatibility) {
return this == temp;
}
switch(temp.getTypetype()) {
case TYPE_ASN1_CHOICE:
{
final ASN1_Choice_Type temporalType = (ASN1_Choice_Type) temp;
if (this == temporalType) {
return true;
}
TypeCompatibilityInfo.Chain lChain = leftChain;
TypeCompatibilityInfo.Chain rChain = rightChain;
if (null == lChain) {
lChain = info.getChain();
lChain.add(this);
}
if (null == rChain) {
rChain = info.getChain();
rChain.add(temporalType);
}
for (int i = 0, size = getNofComponents(timestamp); i < size; i++) {
final CompField cf = getComponentByIndex(i);
final IType cfType = cf.getType().getTypeRefdLast(timestamp);
for (int j = 0, size2 = temporalType.getNofComponents(timestamp); j < size2; j++) {
final CompField temporalCompField = temporalType.getComponentByIndex(j);
final IType tempTypeCompFieldType = temporalCompField.getType().getTypeRefdLast(timestamp);
if (!cf.getIdentifier().getDisplayName().equals(temporalCompField.getIdentifier().getDisplayName())) {
continue;
}
lChain.markState();
rChain.markState();
lChain.add(cfType);
rChain.add(tempTypeCompFieldType);
if (cfType.equals(tempTypeCompFieldType) || (lChain.hasRecursion() && rChain.hasRecursion()) || cfType.isCompatible(timestamp, tempTypeCompFieldType, info, lChain, rChain)) {
info.setNeedsConversion(true);
lChain.previousState();
rChain.previousState();
return true;
}
lChain.previousState();
rChain.previousState();
}
}
info.setErrorStr(MessageFormat.format(NOCOMPATIBLEFIELD, temp.getTypename(), getTypename()));
return false;
}
case TYPE_TTCN3_CHOICE:
{
final TTCN3_Choice_Type temporalType = (TTCN3_Choice_Type) temp;
TypeCompatibilityInfo.Chain lChain = leftChain;
TypeCompatibilityInfo.Chain rChain = rightChain;
if (lChain == null) {
lChain = info.getChain();
lChain.add(this);
}
if (rChain == null) {
rChain = info.getChain();
rChain.add(temporalType);
}
for (int i = 0, size = getNofComponents(timestamp); i < size; i++) {
final CompField cf = getComponentByIndex(i);
final IType compFieldType = cf.getType().getTypeRefdLast(timestamp);
for (int j = 0, size2 = temporalType.getNofComponents(); j < size2; j++) {
final CompField temporalCompField = temporalType.getComponentByIndex(j);
final IType tempTypeCompFieldType = temporalCompField.getType().getTypeRefdLast(timestamp);
if (!cf.getIdentifier().getDisplayName().equals(temporalCompField.getIdentifier().getDisplayName())) {
continue;
}
lChain.markState();
rChain.markState();
lChain.add(compFieldType);
rChain.add(tempTypeCompFieldType);
if (compFieldType.equals(tempTypeCompFieldType) || (lChain.hasRecursion() && rChain.hasRecursion()) || compFieldType.isCompatible(timestamp, tempTypeCompFieldType, info, lChain, rChain)) {
info.setNeedsConversion(true);
lChain.previousState();
rChain.previousState();
return true;
}
lChain.previousState();
rChain.previousState();
}
}
info.setErrorStr(MessageFormat.format(NOCOMPATIBLEFIELD, temp.getTypename(), getTypename()));
return false;
}
case TYPE_ASN1_SEQUENCE:
case TYPE_TTCN3_SEQUENCE:
case TYPE_SEQUENCE_OF:
case TYPE_ARRAY:
case TYPE_ASN1_SET:
case TYPE_TTCN3_SET:
case TYPE_SET_OF:
case TYPE_ANYTYPE:
info.setErrorStr(NOTCOMPATIBLEUNION);
return false;
default:
return false;
}
}
use of org.eclipse.titan.designer.AST.TTCN3.types.CompField in project titan.EclipsePlug-ins by eclipse.
the class TableConstraint method collectTypesOfOpenType.
private void collectTypesOfOpenType(final CompilationTimeStamp aTimestamp, ObjectSet aObjectSet, final Open_Type aOpenType, final Identifier aObjectSetId) {
if (aObjectSet instanceof Referenced_ObjectSet) {
if (((Referenced_ObjectSet) aObjectSet).isReferencedDefinedReference()) {
aObjectSet = aObjectSet.getRefdLast(aTimestamp, null);
} else if (((Referenced_ObjectSet) aObjectSet).isReferencedInformationFromObj()) {
// TODO: How to handle this?
return;
} else {
// impossible, try it
return;
}
}
// now aObjectSet is instanceof ObjectSet_definition:
List<IObjectSet_Element> oses = ((ObjectSet_definition) aObjectSet).getObjectSetElements();
for (IObjectSet_Element ose : oses) {
if (ose instanceof ReferencedObject) {
// fspec
ose = ((ReferencedObject) ose).getRefdLast(aTimestamp);
}
if (ose instanceof Object_Definition) {
final Object_Definition od = (Object_Definition) ose;
FieldSetting fs = od.getFieldSettingWithNameDefault(objectClassFieldname, false);
if (fs != null) {
// TODO: handle FieldSetting options: FieldSetting_Type, FieldSetting_ObjectSet, FieldSetting_Value
if (fs instanceof FieldSetting_Type) {
final FieldSetting_Type fst = (FieldSetting_Type) fs;
final IASN1Type type = fst.getSetting();
final AtomicBoolean isStrange = new AtomicBoolean();
Identifier id = getOpenTypeAlternativeName(aTimestamp, (Type) type, isStrange);
if (!aOpenType.hasComponentWithName(id)) {
aOpenType.addComponent(new CompField(id, (Type) type, false, null));
if (isStrange.get()) {
aOpenType.getLocation().reportSemanticWarning(MessageFormat.format("Strange alternative name (`{0}') was added to open type `{1}'", id.getDisplayName(), aOpenType.getFullName()));
}
}
} else {
// TODO: is it possible FieldSetting_ObjectSet, FieldSetting_Value ??
continue;
}
} else {
fs = od.getFieldSettingWithNameDefault(aObjectSetId, false);
if (fs == null) {
continue;
}
if (fs instanceof FieldSetting_ObjectSet) {
final ISetting objectSet1 = fs.getSetting();
ObjectSet objectSet2;
if (objectSet1 instanceof ObjectSet) {
objectSet2 = (ObjectSet) objectSet1;
} else {
// unexpected case
continue;
}
if (objectSet2 == aObjectSet) {
// to prevent infinite loop
continue;
}
collectTypesOfOpenType(aTimestamp, objectSet2, aOpenType, aObjectSetId);
} else {
// TODO: is it possible??
continue;
}
}
}
}
// for
aOpenType.check(aTimestamp);
}
Aggregations