use of org.eclipse.titan.designer.AST.Type in project titan.EclipsePlug-ins by eclipse.
the class TTCN3_Set_Seq_Choice_BaseType method checkSetSeqRawCodingAttributes.
/**
* Check the raw coding attributes of TTCN3 record and set types.
*
* @param timestamp the timestamp of the actual semantic check cycle.
*/
protected void checkSetSeqRawCodingAttributes(final CompilationTimeStamp timestamp) {
// check raw attributes
if (rawAttribute != null) {
if (rawAttribute.taglist != null) {
for (int c = 0; c < rawAttribute.taglist.size(); c++) {
final rawAST_single_tag singleTag = rawAttribute.taglist.get(c);
final Identifier fieldname = singleTag.fieldName;
if (!hasComponentWithName(fieldname.getName())) {
fieldname.getLocation().reportSemanticError(MessageFormat.format("Invalid field name `{0}'' in RAW parameter TAG for type `{1}''", fieldname.getDisplayName(), getTypename()));
continue;
}
if (singleTag.keyList != null) {
for (int a = 0; a < singleTag.keyList.size(); a++) {
final Reference reference = new Reference(null);
reference.addSubReference(new FieldSubReference(fieldname));
for (int b = 0; b < singleTag.keyList.get(a).keyField.names.size(); b++) {
reference.addSubReference(new FieldSubReference(singleTag.keyList.get(a).keyField.names.get(b)));
}
final IType t = getFieldType(timestamp, reference, 0, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
if (t != null) {
final Value v = singleTag.keyList.get(a).v_value;
if (v != null) {
v.setMyScope(getMyScope());
v.setMyGovernor(t);
final IValue tempValue = t.checkThisValueRef(timestamp, v);
t.checkThisValue(timestamp, tempValue, null, new ValueCheckingOptions(Expected_Value_type.EXPECTED_CONSTANT, false, false, false, false, false));
}
}
}
}
}
}
if (rawAttribute.ext_bit_groups != null) {
for (int a = 0; a < rawAttribute.ext_bit_groups.size(); a++) {
final rawAST_ext_bit_group tempExtBitGroup = rawAttribute.ext_bit_groups.get(a);
final Identifier fromIdentifier = tempExtBitGroup.from;
final Identifier toIdentifier = tempExtBitGroup.to;
boolean foundError = false;
if (!hasComponentWithName(fromIdentifier.getName())) {
fromIdentifier.getLocation().reportSemanticError(MessageFormat.format("Invalid field name `{0}'' in RAW parameter EXTENSION_BIT_GROUP for type `{1}''", fromIdentifier.getDisplayName(), getTypename()));
foundError = true;
}
if (!hasComponentWithName(toIdentifier.getName())) {
toIdentifier.getLocation().reportSemanticError(MessageFormat.format("Invalid field name `{0}'' in RAW parameter EXTENSION_BIT_GROUP for type `{1}''", toIdentifier.getDisplayName(), getTypename()));
foundError = true;
}
if (!foundError) {
boolean foundStart = false;
for (int i = 0; i < getNofComponents(); i++) {
final Identifier tempId = getComponentByIndex(i).getIdentifier();
if (tempId.equals(fromIdentifier)) {
foundStart = true;
} else if (tempId.equals(toIdentifier)) {
if (!foundStart) {
getLocation().reportSemanticError(MessageFormat.format("Invalid field order in RAW parameter EXTENSION_BIT_GROUP for type `{0}'': `{1}'', `{2}''", getTypename(), fromIdentifier.getDisplayName(), toIdentifier.getDisplayName()));
}
break;
}
}
}
}
}
if (rawAttribute.paddall != RawAST.XDEFDEFAULT) {
for (int i = 0; i < getNofComponents(); i++) {
final CompField cField = getComponentByIndex(i);
final Type fieldType = cField.getType();
RawAST fieldRawAttribute = fieldType.rawAttribute;
if (fieldRawAttribute == null) {
IType t = fieldType;
if (t instanceof Referenced_Type) {
final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
t = ((Referenced_Type) t).getTypeRefd(timestamp, referenceChain);
referenceChain.release();
}
while (t.getRawAttribute() == null && t instanceof Referenced_Type) {
final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
t = ((Referenced_Type) t).getTypeRefd(timestamp, referenceChain);
referenceChain.release();
}
fieldRawAttribute = new RawAST(t.getRawAttribute(), fieldType.getDefaultRawFieldLength());
fieldType.setRawAttributes(fieldRawAttribute);
}
if (fieldRawAttribute.padding == 0) {
fieldRawAttribute.padding = rawAttribute.padding;
}
if (fieldRawAttribute.prepadding == 0) {
fieldRawAttribute.prepadding = rawAttribute.prepadding;
}
if (fieldRawAttribute.padding_pattern_length == 0 && rawAttribute.padding_pattern_length > 0) {
fieldRawAttribute.padding_pattern = rawAttribute.padding_pattern;
fieldRawAttribute.padding_pattern_length = rawAttribute.padding_pattern_length;
}
}
}
if (rawAttribute.fieldorder != RawAST.XDEFDEFAULT) {
for (int i = 0; i < getNofComponents(); i++) {
final CompField cField = getComponentByIndex(i);
final Type fieldType = cField.getType();
RawAST fieldRawAttribute = fieldType.rawAttribute;
if (fieldRawAttribute == null) {
fieldRawAttribute = new RawAST(fieldType.getDefaultRawFieldLength());
fieldType.setRawAttributes(fieldRawAttribute);
}
if (fieldRawAttribute.fieldorder == RawAST.XDEFDEFAULT) {
fieldRawAttribute.fieldorder = rawAttribute.fieldorder;
}
}
}
}
if (rawAttribute != null && rawAttribute.presence != null) {
if (rawAttribute.presence.keyList != null) {
for (int a = 0; a < rawAttribute.presence.keyList.size(); a++) {
final rawAST_tag_field_value tempTagFieldValue = rawAttribute.presence.keyList.get(a);
final Reference reference = new Reference(null);
reference.addSubReference(new FieldSubReference(tempTagFieldValue.keyField.names.get(0)));
for (int b = 1; b < tempTagFieldValue.keyField.names.size(); b++) {
reference.addSubReference(new FieldSubReference(tempTagFieldValue.keyField.names.get(b)));
}
final IType t = getFieldType(timestamp, reference, 0, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
if (t != null) {
final Value v = tempTagFieldValue.v_value;
if (v != null) {
v.setMyScope(getMyScope());
v.setMyGovernor(t);
final IValue tempValue = t.checkThisValueRef(timestamp, v);
t.checkThisValue(timestamp, tempValue, null, new ValueCheckingOptions(Expected_Value_type.EXPECTED_CONSTANT, false, false, false, false, false));
}
}
}
}
}
// number of bits used to store all previous fields
int usedBits = 0;
for (int i = 0; i < getNofComponents(); i++) {
final CompField cField = getComponentByIndex(i);
final Type fieldType = cField.getType();
fieldType.forceRaw(timestamp);
final RawAST rawPar = fieldType.rawAttribute;
if (rawPar != null) {
final Identifier fieldId = cField.getIdentifier();
final IType fieldTypeLast = fieldType.getTypeRefdLast(timestamp);
if (rawPar.prepadding != 0) {
usedBits = (usedBits + rawPar.prepadding - 1) / rawPar.prepadding * rawPar.prepadding;
}
if (rawPar.intX && fieldTypeLast.getTypetype() == Type_type.TYPE_INTEGER) {
if (usedBits % 8 != 0 && (rawAttribute == null || rawAttribute.fieldorder != RawAST.XDEFMSB)) {
getLocation().reportSemanticError(MessageFormat.format("Using RAW parameter IntX in a record/set with FIELDORDER set to 'lsb' is only supported if the IntX field starts at the beginning of a new octet. There are {0} unused bits in the last octet before field {1}.", 8 - (usedBits % 8), fieldId.getDisplayName()));
}
} else if (rawPar.fieldlength > 0) {
usedBits += rawPar.fieldlength;
}
if (rawPar.padding != 0) {
usedBits = (usedBits + rawPar.padding - 1) / rawPar.padding * rawPar.padding;
}
if (rawPar.lengthto != null) {
for (int j = 0; j < rawPar.lengthto.size(); j++) {
final Identifier id = rawPar.lengthto.get(j);
if (!hasComponentWithName(id.getName())) {
id.getLocation().reportSemanticError(MessageFormat.format("Invalid fieldname in RAW parameter LENGTHTO for field {0}: {1}", fieldId.getDisplayName(), id.getDisplayName()));
}
}
}
if (rawPar.lengthto != null) {
switch(fieldTypeLast.getTypetype()) {
case TYPE_INTEGER:
case TYPE_INTEGER_A:
break;
case TYPE_TTCN3_CHOICE:
for (int fi = 0; fi < ((TTCN3_Choice_Type) fieldTypeLast).getNofComponents(); fi++) {
final Type_type tt = ((TTCN3_Choice_Type) fieldTypeLast).getComponentByIndex(fi).getType().getTypetype();
if (tt != Type_type.TYPE_INTEGER && tt != Type_type.TYPE_INTEGER_A) {
getLocation().reportSemanticError("The union type LENGTHTO field must contain only integer fields");
}
}
break;
case TYPE_ASN1_CHOICE:
for (int fi = 0; fi < ((ASN1_Choice_Type) fieldTypeLast).getNofComponents(timestamp); fi++) {
final Type_type tt = ((ASN1_Choice_Type) fieldTypeLast).getComponentByIndex(fi).getType().getTypetype();
if (tt != Type_type.TYPE_INTEGER && tt != Type_type.TYPE_INTEGER_A) {
getLocation().reportSemanticError("The union type LENGTHTO field must contain only integer fields");
}
}
break;
case TYPE_ANYTYPE:
case TYPE_OPENTYPE:
case TYPE_TTCN3_SEQUENCE:
case TYPE_ASN1_SEQUENCE:
case TYPE_TTCN3_SET:
case TYPE_ASN1_SET:
if (rawPar.lengthindex != null) {
// will be checked in the next step
break;
}
default:
getLocation().reportSemanticError(MessageFormat.format("The LENGTHTO field must be an integer or union type instead of `{0}''", fieldTypeLast.getTypename()));
break;
}
}
if (rawPar.lengthto != null && rawPar.lengthindex != null) {
final Identifier id = rawPar.lengthindex.names.get(0);
switch(fieldTypeLast.getTypetype()) {
case TYPE_TTCN3_CHOICE:
case TYPE_TTCN3_SEQUENCE:
case TYPE_TTCN3_SET:
if (!((TTCN3_Set_Seq_Choice_BaseType) fieldTypeLast).hasComponentWithName(id.getName())) {
id.getLocation().reportSemanticError(MessageFormat.format("Invalid fieldname in RAW parameter LENGTHINDEX for field {0}: {1}", fieldId.getDisplayName(), id.getDisplayName()));
}
break;
case TYPE_ASN1_CHOICE:
case TYPE_ASN1_SEQUENCE:
case TYPE_ASN1_SET:
if (!((ASN1_Set_Seq_Choice_BaseType) fieldTypeLast).hasComponentWithName(id)) {
id.getLocation().reportSemanticError(MessageFormat.format("Invalid fieldname in RAW parameter LENGTHINDEX for field {0}: {1}", fieldId.getDisplayName(), id.getDisplayName()));
}
break;
default:
fieldId.getLocation().reportSemanticError(MessageFormat.format("Invalid fieldmember type in RAW parameter LENGTHINDEX for field {0}.", fieldId.getDisplayName()));
break;
}
}
if (rawPar.pointerto != null) {
final Identifier id = rawPar.pointerto;
boolean errorFound = false;
int pointed = 0;
if (!hasComponentWithName(id.getName())) {
id.getLocation().reportSemanticError(MessageFormat.format("Invalid fieldname in RAW parameter POINTERTO for field {0}: {1}", fieldId.getDisplayName(), id.getDisplayName()));
errorFound = true;
}
if (!errorFound) {
pointed = getComponentIndexByName(id);
if (pointed <= i) {
id.getLocation().reportSemanticError(MessageFormat.format("Pointer must precede the pointed field. Incorrect field name `{0}'' in RAW parameter POINTERTO for field `{1}''", id.getDisplayName(), fieldId.getDisplayName()));
errorFound = true;
}
}
if (!errorFound && rawPar.ptrbase != null) {
final Identifier idf2 = rawPar.ptrbase;
if (!hasComponentWithName(idf2.getName())) {
idf2.getLocation().reportSemanticError(MessageFormat.format("Invalid field name `{0}'' in RAW parameter PTROFFSET for field `{1}''", idf2.getDisplayName(), fieldId.getDisplayName()));
errorFound = true;
}
if (!errorFound && getComponentIndexByName(idf2) > pointed) {
idf2.getLocation().reportSemanticError(MessageFormat.format("Pointer base must precede the pointed field. Incorrect field name `{0}'' in RAW parameter PTROFFSET for field `{1}''", idf2.getDisplayName(), fieldId.getDisplayName()));
}
}
}
if (rawPar.presence != null && rawPar.presence.keyList != null) {
for (int a = 0; a < rawPar.presence.keyList.size(); a++) {
final rawAST_tag_field_value tempTagFieldValue = rawPar.presence.keyList.get(a);
final Reference reference = new Reference(null);
reference.addSubReference(new FieldSubReference(tempTagFieldValue.keyField.names.get(0)));
for (int b = 1; b < tempTagFieldValue.keyField.names.size(); b++) {
reference.addSubReference(new FieldSubReference(tempTagFieldValue.keyField.names.get(b)));
}
final IType t = getFieldType(timestamp, reference, 0, Expected_Value_type.EXPECTED_DYNAMIC_VALUE, false);
if (t != null) {
final Value v = tempTagFieldValue.v_value;
if (v != null) {
v.setMyScope(getMyScope());
v.setMyGovernor(t);
final IValue tempValue = t.checkThisValueRef(timestamp, v);
t.checkThisValue(timestamp, tempValue, null, new ValueCheckingOptions(Expected_Value_type.EXPECTED_CONSTANT, false, false, false, false, false));
}
}
}
}
if (rawPar.crosstaglist != null) {
for (int c = 0; c < rawPar.crosstaglist.size(); c++) {
final rawAST_single_tag singleTag = rawPar.crosstaglist.get(c);
final Identifier idf = singleTag.fieldName;
switch(fieldTypeLast.getTypetype()) {
case TYPE_TTCN3_CHOICE:
case TYPE_TTCN3_SEQUENCE:
case TYPE_TTCN3_SET:
if (!((TTCN3_Set_Seq_Choice_BaseType) fieldTypeLast).hasComponentWithName(idf.getName())) {
idf.getLocation().reportSemanticError(MessageFormat.format("Invalid fieldname in RAW parameter CROSSTAG for field {0}: {1}", fieldId.getDisplayName(), idf.getDisplayName()));
}
break;
case TYPE_ASN1_CHOICE:
case TYPE_ASN1_SEQUENCE:
case TYPE_ASN1_SET:
if (!((ASN1_Set_Seq_Choice_BaseType) fieldTypeLast).hasComponentWithName(idf)) {
idf.getLocation().reportSemanticError(MessageFormat.format("Invalid fieldname in RAW parameter CROSSTAG for field {0}: {1}", fieldId.getDisplayName(), idf.getDisplayName()));
}
break;
default:
fieldId.getLocation().reportSemanticError(MessageFormat.format("Invalid fieldmember type in RAW parameter CROSSTAG for field {0}.", fieldId.getDisplayName()));
break;
}
if (singleTag.keyList != null) {
for (int a = 0; a < singleTag.keyList.size(); a++) {
IType t2 = this;
boolean errorFound = false;
boolean allow_omit = false;
final rawAST_tag_field_value tagField = singleTag.keyList.get(a);
for (int b = 0; b < tagField.keyField.names.size() && !errorFound; b++) {
final Identifier idf2 = tagField.keyField.names.get(b);
CompField cf2 = null;
switch(t2.getTypetype()) {
case TYPE_TTCN3_CHOICE:
case TYPE_TTCN3_SEQUENCE:
case TYPE_TTCN3_SET:
if (!((TTCN3_Set_Seq_Choice_BaseType) t2).hasComponentWithName(idf2.getName())) {
idf2.getLocation().reportSemanticError(MessageFormat.format("Invalid fieldname in RAW parameter CROSSTAG for field {0}: {1}", fieldId.getDisplayName(), idf2.getDisplayName()));
errorFound = true;
} else {
cf2 = ((TTCN3_Set_Seq_Choice_BaseType) t2).getComponentByName(idf2.getName());
}
break;
case TYPE_ASN1_CHOICE:
case TYPE_ASN1_SEQUENCE:
case TYPE_ASN1_SET:
if (!((ASN1_Set_Seq_Choice_BaseType) t2).hasComponentWithName(idf2)) {
idf2.getLocation().reportSemanticError(MessageFormat.format("Invalid fieldname in RAW parameter CROSSTAG for field {0}: {1}", fieldId.getDisplayName(), idf2.getDisplayName()));
errorFound = true;
} else {
cf2 = ((ASN1_Set_Seq_Choice_BaseType) t2).getComponentByName(idf2);
}
break;
default:
fieldId.getLocation().reportSemanticError(MessageFormat.format("Invalid fieldmember type in RAW parameter CROSSTAG for field {0}.", fieldId.getDisplayName()));
errorFound = true;
break;
}
if (b == 0) {
final int fieldIndex = getComponentIndexByName(idf2);
if (fieldIndex == i) {
idf2.getLocation().reportSemanticError(MessageFormat.format("RAW parameter CROSSTAG for field `{0}'' cannot refer to the field itself", idf2.getDisplayName()));
errorFound = true;
} else if (fieldIndex > i) {
if (cField.isOptional()) {
// TODO || fieldType.getRawLength() < 0
idf2.getLocation().reportSemanticError(MessageFormat.format("Field `{0}'' that CROSSTAG refers to must precede field `{1}'' or field `{1}'' must be mandatory with fixed length", idf2.getDisplayName(), fieldId.getDisplayName()));
errorFound = true;
}
}
}
if (!errorFound) {
t2 = cf2.getType().getTypeRefdLast(timestamp);
if (b == tagField.keyField.names.size() - 1 && cf2.isOptional()) {
allow_omit = true;
}
}
}
if (!errorFound) {
final Value v = singleTag.keyList.get(a).v_value;
if (v != null) {
v.setMyScope(getMyScope());
v.setMyGovernor(t2);
final IValue tempValue = t2.checkThisValueRef(timestamp, v);
t2.checkThisValue(timestamp, tempValue, null, new ValueCheckingOptions(Expected_Value_type.EXPECTED_CONSTANT, false, allow_omit, false, false, false));
}
}
}
}
}
}
}
}
}
use of org.eclipse.titan.designer.AST.Type in project titan.EclipsePlug-ins by eclipse.
the class TTCN3_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, 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.Type in project titan.EclipsePlug-ins by eclipse.
the class PortTypeBody method checkUserAttribute.
/**
* Checks the attributes for the specific case when the port is of user type.
*
* @param timestamp the time stamp of the actual semantic check cycle.
*/
private void checkUserAttribute(final CompilationTimeStamp timestamp) {
if (providerReference == null) {
return;
}
providerType = null;
PortTypeBody providerBody = null;
final Assignment assignment = providerReference.getRefdAssignment(timestamp, true);
if (assignment != null) {
if (Assignment_type.A_TYPE.semanticallyEquals(assignment.getAssignmentType())) {
final IType type = assignment.getType(timestamp).getTypeRefdLast(timestamp);
if (Type_type.TYPE_PORT.equals(type.getTypetype())) {
providerType = type;
providerBody = ((Port_Type) type).getPortBody();
} else {
providerReference.getLocation().reportSemanticError(MessageFormat.format("Type reference `{0}'' does not refer to a port type", providerReference.getDisplayName()));
}
} else {
providerReference.getLocation().reportSemanticError(MessageFormat.format("Reference `{0}'' does not refer to a type", providerReference.getDisplayName()));
}
}
// checking the consistency of attributes in this and provider_body
if (providerBody != null && !TestPortAPI_type.TP_INTERNAL.equals(testportType)) {
if (!PortType_type.PT_PROVIDER.equals(providerBody.portType)) {
providerReference.getLocation().reportSemanticError(MessageFormat.format("The referenced port type `{0}'' must have the `provider'' attribute", providerType.getTypename()));
}
switch(providerBody.testportType) {
case TP_REGULAR:
if (TestPortAPI_type.TP_ADDRESS.equals(testportType)) {
providerReference.getLocation().reportSemanticError(MessageFormat.format("Attribute `address'' cannot be used because the provider port type `{0}''" + " does not have attribute `address''", providerType.getTypename()));
}
break;
case TP_INTERNAL:
providerReference.getLocation().reportSemanticError(MessageFormat.format("Missing attribute `internal''. Provider port type `{0}'' has attribute `internal''," + " which must be also present here", providerType.getTypename()));
break;
case TP_ADDRESS:
break;
default:
break;
}
// inherit the test port API type from the provider
testportType = providerBody.testportType;
}
// check the incoming mappings
if (inMappings != null && inMappings.getNofMappings() != 0) {
inMappings.check(timestamp);
if (providerBody != null) {
if (providerBody.inMessages != null) {
// check if all source types are present on the `in' list of the provider
for (int i = 0, size = inMappings.getNofMappings(); i < size; i++) {
final Type sourceType = inMappings.getMappingByIndex(i).getSourceType();
// }
if (sourceType != null && !providerBody.inMessages.hasType(timestamp, sourceType)) {
sourceType.getLocation().reportSemanticError(MessageFormat.format("Source type `{0}'' of the `in'' mapping is not present " + "on the list of incoming messages in provider port type `{1}''", sourceType.getTypename(), providerType.getTypename()));
}
}
// check if all types of the `in' list of the provider are handled by the mappings
for (int i = 0, size = providerBody.inMessages.getNofTypes(); i < size; i++) {
final IType messageType = providerBody.inMessages.getTypeByIndex(i);
if (!inMappings.hasMappingForType(timestamp, messageType)) {
inMappings.getLocation().reportSemanticError(MessageFormat.format("Incoming message type `{0}'' of provider port type `{1}'' is not handled by the incoming mappings", messageType.getTypename(), providerType.getTypename()));
inMappings.hasMappingForType(timestamp, messageType);
}
}
} else {
inMappings.getLocation().reportSemanticError(MessageFormat.format("Invalid incoming mappings. Provider port type `{0}' does not have incoming message types'", providerType.getTypename()));
}
}
// checking target types
for (int i = 0, size = inMappings.getNofMappings(); i < size; i++) {
final TypeMapping mapping = inMappings.getMappingByIndex(i);
for (int j = 0, nofTargets = mapping.getNofTargets(); j < nofTargets; j++) {
final Type targetType = mapping.getTargetByIndex(j).getTargetType();
if (targetType != null && (inMessages == null || !inMessages.hasType(timestamp, targetType))) {
targetType.getLocation().reportSemanticError(MessageFormat.format("Target type `{0}'' of the `in'' mapping is not present on the list of incoming messages in user port type `{1}''", targetType.getTypename(), myType.getTypename()));
}
}
}
} else if (providerBody != null && providerBody.inMessages != null) {
location.reportSemanticError(MessageFormat.format("Missing `in'' mappings to handle the incoming message types of provider port type `{0}''", providerType.getTypename()));
}
if (outMappings != null && outMappings.getNofMappings() != 0) {
outMappings.check(timestamp);
if (outMessages != null) {
// check if all source types are present on the `in' list of the provider
for (int i = 0, size = outMappings.getNofMappings(); i < size; i++) {
final Type sourceType = outMappings.getMappingByIndex(i).getSourceType();
if (sourceType != null && !outMessages.hasType(timestamp, sourceType)) {
sourceType.getLocation().reportSemanticError(MessageFormat.format("Source type `{0}'' of the `out'' mapping is not present on the list of outgoing messages in user port type `{1}''", sourceType.getTypename(), myType.getTypename()));
}
}
// check if all types of the `in' list of the provider are handled by the mappings
for (int i = 0, size = outMessages.getNofTypes(); i < size; i++) {
final IType messageType = outMessages.getTypeByIndex(i);
if (!outMappings.hasMappingForType(timestamp, messageType)) {
outMappings.getLocation().reportSemanticError(MessageFormat.format("Outgoing message type `{0}'' of user port type `{1}'' is not handled by the outgoing mappings", messageType.getTypename(), myType.getTypename()));
}
}
} else {
outMappings.getLocation().reportSemanticError(MessageFormat.format("Invalid outgoing mappings. User port type `{0}'' does not have outgoing message types", myType.getTypename()));
}
// checking target types
if (providerBody != null) {
for (int i = 0, size = outMappings.getNofMappings(); i < size; i++) {
final TypeMapping mapping = outMappings.getMappingByIndex(i);
for (int j = 0, nofTargets = mapping.getNofTargets(); j < nofTargets; j++) {
final Type targetType = mapping.getTargetByIndex(j).getTargetType();
if (targetType != null && (providerBody.outMessages == null || !providerBody.outMessages.hasType(timestamp, targetType))) {
targetType.getLocation().reportSemanticError(MessageFormat.format("Target type `{0}'' of the `out'' mapping is not present " + "on the list of outgoing messages in provider port type `{1}''", targetType.getTypename(), providerType.getTypename()));
}
}
}
}
} else if (outMessages != null) {
location.reportSemanticError(MessageFormat.format("Missing `out'' mapping to handle the outgoing message types of user port type `{0}''", myType.getTypename()));
}
// checking the compatibility of signature lists
if (providerBody == null) {
return;
}
if (inSignatures != null) {
for (int i = 0, size = inSignatures.getNofTypes(); i < size; i++) {
final IType signatureType = inSignatures.getTypeByIndex(i);
if (providerBody.inSignatures == null || !providerBody.inSignatures.hasType(timestamp, signatureType)) {
final IType last = signatureType.getTypeRefdLast(timestamp);
if (!last.getIsErroneous(timestamp) && Type_type.TYPE_SIGNATURE.equals(last.getTypetype())) {
final Signature_Type lastSignature = (Signature_Type) last;
if (!lastSignature.isNonblocking() || lastSignature.getSignatureExceptions() != null) {
signatureType.getLocation().reportSemanticError(MessageFormat.format("Incoming signature `{0}'' of user port type `{1}'' is not present on the list " + "of incoming signatures in provider port type `{2}''", signatureType.getTypename(), myType.getTypename(), providerType.getTypename()));
}
}
}
}
}
if (providerBody.inSignatures != null) {
for (int i = 0, size = providerBody.inSignatures.getNofTypes(); i < size; i++) {
final IType signatureType = providerBody.inSignatures.getTypeByIndex(i);
if (inSignatures == null || !inSignatures.hasType(timestamp, signatureType)) {
location.reportSemanticError(MessageFormat.format("Incoming signature `{0}'' of provider port type `{1}'' " + "is not present on the list of incoming signatures in user port type `{2}''", signatureType.getTypename(), providerType.getTypename(), myType.getTypename()));
}
}
}
if (outSignatures != null) {
for (int i = 0, size = outSignatures.getNofTypes(); i < size; i++) {
final IType signatureType = outSignatures.getTypeByIndex(i);
if (providerBody.outSignatures == null || !providerBody.outSignatures.hasType(timestamp, signatureType)) {
signatureType.getLocation().reportSemanticError(MessageFormat.format("Outgoing signature `{0}'' of user port type `{1}'' is not present " + "on the list of outgoing signatures in provider port type `{2}''", signatureType.getTypename(), myType.getTypename(), providerType.getTypename()));
}
}
}
if (providerBody.outSignatures != null) {
for (int i = 0, size = providerBody.outSignatures.getNofTypes(); i < size; i++) {
final IType signatureType = providerBody.outSignatures.getTypeByIndex(i);
if (outSignatures == null || !outSignatures.hasType(timestamp, signatureType)) {
final IType last = signatureType.getTypeRefdLast(timestamp);
if (!last.getIsErroneous(timestamp) && Type_type.TYPE_SIGNATURE.equals(last.getTypetype())) {
final Signature_Type lastSignature = (Signature_Type) last;
if (!lastSignature.isNonblocking() || lastSignature.getSignatureExceptions() != null) {
location.reportSemanticError(MessageFormat.format("Outgoing signature `{0}'' of provider port type `{1}'' is not present " + "on the list of outgoing signatures in user port type `{2}''", signatureType.getTypename(), providerType.getTypename(), myType.getTypename()));
}
}
}
}
}
}
use of org.eclipse.titan.designer.AST.Type in project titan.EclipsePlug-ins by eclipse.
the class SignatureExceptions method updateSyntax.
@Override
public /**
* {@inheritDoc}
*/
void updateSyntax(final TTCN3ReparseUpdater reparser, final boolean isDamaged) throws ReParseException {
if (isDamaged) {
throw new ReParseException();
}
Type exception;
for (int i = 0, size = exceptionTypes.size(); i < size; i++) {
exception = exceptionTypes.get(i);
exception.updateSyntax(reparser, isDamaged);
reparser.updateLocation(exception.getLocation());
}
}
use of org.eclipse.titan.designer.AST.Type in project titan.EclipsePlug-ins by eclipse.
the class Anytype_Type method checkThisValueAnytype.
private boolean checkThisValueAnytype(final CompilationTimeStamp timestamp, final Anytype_Value value, final Assignment lhs, final Expected_Value_type expectedValue, final boolean incompleteAllowed, final boolean strElem) {
boolean selfReference = false;
final Identifier name = value.getName();
if (!hasComponentWithName(name.getName())) {
value.getLocation().reportSemanticError(MessageFormat.format(NONEXISTENTUNION, name.getDisplayName(), getFullName()));
setIsErroneous(true);
return selfReference;
}
final Type alternativeType = getComponentByName(name.getName()).getType();
IValue alternativeValue = value.getValue();
alternativeValue.setMyGovernor(alternativeType);
alternativeValue = alternativeType.checkThisValueRef(timestamp, alternativeValue);
selfReference = alternativeType.checkThisValue(timestamp, alternativeValue, lhs, new ValueCheckingOptions(expectedValue, incompleteAllowed, false, true, false, strElem));
value.setLastTimeChecked(timestamp);
return selfReference;
}
Aggregations