use of org.eclipse.titan.designer.AST.ASN1.types.Open_Type 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);
}
use of org.eclipse.titan.designer.AST.ASN1.types.Open_Type in project titan.EclipsePlug-ins by eclipse.
the class Type method checkThisVariant.
@Override
public /**
* {@inheritDoc}
*/
void checkThisVariant(final CompilationTimeStamp timestamp, final SingleWithAttribute singleWithAttribute, final boolean global) {
final IType type = getTypeWithCodingTable(timestamp, false);
if (type == null) {
// FIXME as only RAW is supported for now, we can not report this error
// if (!global) {
// singleWithAttribute.getLocation().reportSemanticError(MessageFormat.format("No encoding rules defined for type `{0}''", getTypename()));
// }
} else {
final List<String> codingStrings = singleWithAttribute.getAttributeSpecification().getEncodings();
// gather the built-in codecs referred to by the variant's encoding strings
final ArrayList<MessageEncoding_type> codings = new ArrayList<IType.MessageEncoding_type>();
boolean erroneous = false;
if (codingStrings == null) {
if (type.getCodingTable().size() > 1) {
if (!global) {
singleWithAttribute.getLocation().reportSemanticError(MessageFormat.format("The encoding reference is mandatory for variant attributes of type `{0}''", getTypename()));
}
erroneous = true;
} else if (type.getCodingTable().get(0).builtIn) {
codings.add(type.getCodingTable().get(0).builtInCoding);
} else {
// PER or custom encoding
final MessageEncoding_type coding = "PER".equals(type.getCodingTable().get(0).customCoding.name) ? MessageEncoding_type.PER : MessageEncoding_type.CUSTOM;
singleWithAttribute.getLocation().reportSemanticWarning(MessageFormat.format("Variant attributes related to `{0}'' encoding are ignored", coding.getEncodingName()));
}
} else {
for (int i = 0; i < codingStrings.size(); i++) {
final String encodingString = codingStrings.get(i);
final MessageEncoding_type coding = getEncodingType(encodingString);
if (!hasEncoding(timestamp, coding, encodingString)) {
erroneous = true;
// FIXME RAW restriction only exists because that is the only supported encoding right now
if (!global && coding == MessageEncoding_type.RAW) {
if (coding == MessageEncoding_type.CUSTOM) {
singleWithAttribute.getLocation().reportSemanticError(MessageFormat.format("Type `{0}'' does not support {1} encoding", getTypename(), coding.getEncodingName()));
} else {
singleWithAttribute.getLocation().reportSemanticError(MessageFormat.format("Type `{0}'' does not support custom encoding `{1}''", getTypename(), encodingString));
}
}
} else if (coding != MessageEncoding_type.PER && coding != MessageEncoding_type.CUSTOM) {
codings.add(coding);
} else {
// PER or custom encoding
singleWithAttribute.getLocation().reportSemanticWarning(MessageFormat.format("Variant attributes related to {0} encoding are ignored", coding.getEncodingName()));
}
}
}
// FIXME implement checks
// TODO only raw data is extracted
final VariantAttributeAnalyzer analyzer = new VariantAttributeAnalyzer();
boolean newRaw = false;
final AtomicBoolean rawFoud = new AtomicBoolean(false);
if (rawAttribute == null) {
IType t_refd = this;
while (t_refd.getRawAttribute() == null && t_refd instanceof Referenced_Type) {
final IReferenceChain referenceChain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
t_refd = ((Referenced_Type) t_refd).getTypeRefd(timestamp, referenceChain);
referenceChain.release();
}
rawAttribute = new RawAST(t_refd.getRawAttribute(), getDefaultRawFieldLength());
newRaw = true;
}
analyzer.parse(rawAttribute, singleWithAttribute.getAttributeSpecification(), getLengthMultiplier(), rawFoud);
if (!rawFoud.get() && newRaw) {
rawAttribute = null;
}
}
if (global) {
// send global variant attributes to field/element types
switch(getTypetype()) {
case TYPE_TTCN3_CHOICE:
case TYPE_TTCN3_SEQUENCE:
case TYPE_TTCN3_SET:
for (int i = 0; i < ((TTCN3_Set_Seq_Choice_BaseType) this).getNofComponents(); i++) {
((TTCN3_Set_Seq_Choice_BaseType) this).getComponentByIndex(i).getType().checkThisVariant(timestamp, singleWithAttribute, global);
}
break;
case TYPE_ASN1_CHOICE:
case TYPE_ASN1_SEQUENCE:
case TYPE_ASN1_SET:
for (int i = 0; i < ((ASN1_Set_Seq_Choice_BaseType) this).getNofComponents(timestamp); i++) {
((ASN1_Set_Seq_Choice_BaseType) this).getComponentByIndex(i).getType().checkThisVariant(timestamp, singleWithAttribute, global);
}
break;
case TYPE_ANYTYPE:
for (int i = 0; i < ((Anytype_Type) this).getNofComponents(); i++) {
((Anytype_Type) this).getComponentByIndex(i).getType().checkThisVariant(timestamp, singleWithAttribute, global);
}
break;
case TYPE_OPENTYPE:
for (int i = 0; i < ((Open_Type) this).getNofComponents(); i++) {
((Open_Type) this).getComponentByIndex(i).getType().checkThisVariant(timestamp, singleWithAttribute, global);
}
break;
case TYPE_ARRAY:
((Array_Type) this).getElementType().checkThisVariant(timestamp, singleWithAttribute, global);
break;
case TYPE_SEQUENCE_OF:
((SequenceOf_Type) this).getOfType().checkThisVariant(timestamp, singleWithAttribute, global);
break;
case TYPE_SET_OF:
((SetOf_Type) this).getOfType().checkThisVariant(timestamp, singleWithAttribute, global);
break;
default:
break;
}
}
}
use of org.eclipse.titan.designer.AST.ASN1.types.Open_Type in project titan.EclipsePlug-ins by eclipse.
the class IsChoosenExpression method checkExpressionOperands.
/**
* Checks the parameters of the expression and if they are valid in
* their position in the expression or not.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
* @param expectedValue
* the kind of value expected.
* @param referenceChain
* a reference chain to detect cyclic references.
*/
private void checkExpressionOperands(final CompilationTimeStamp timestamp, final Expected_Value_type expectedValue, final IReferenceChain referenceChain) {
if (lastTimeoperandsChecked != null && !lastTimeoperandsChecked.isLess(timestamp)) {
return;
}
lastTimeoperandsChecked = timestamp;
value = null;
identifier = null;
if (reference == null || reference.getSubreferences().size() < 2) {
setIsErroneous(true);
return;
}
final Reference tempReference = reference.newInstance();
tempReference.setFullNameParent(this);
tempReference.setMyScope(getMyScope());
final ISubReference subreference = tempReference.removeLastSubReference();
if (Subreference_type.fieldSubReference.equals(subreference.getReferenceType())) {
identifier = ((FieldSubReference) subreference).getId();
} else {
setIsErroneous(true);
return;
}
final Assignment assignment = tempReference.getRefdAssignment(timestamp, true);
if (assignment == null) {
setIsErroneous(true);
return;
}
IType governor;
switch(assignment.getAssignmentType()) {
case A_CONST:
case A_EXT_CONST:
case A_MODULEPAR:
case A_VAR:
case A_PAR_VAL:
case A_PAR_VAL_IN:
case A_PAR_VAL_OUT:
case A_PAR_VAL_INOUT:
{
value = new Referenced_Value(tempReference);
value.setLocation(tempReference.getLocation());
value.setMyScope(getMyScope());
final BridgingNamedNode tempNamedNode = new BridgingNamedNode(this, OPERAND);
value.setFullNameParent(tempNamedNode);
governor = value.getExpressionGovernor(timestamp, expectedValue);
if (governor == null) {
setIsErroneous(true);
} else {
value.setMyGovernor(governor);
final IValue tempValue2 = governor.checkThisValueRef(timestamp, value);
if (tempValue2.getIsErroneous(timestamp)) {
setIsErroneous(true);
}
}
break;
}
case A_TEMPLATE:
case A_VAR_TEMPLATE:
case A_PAR_TEMP_IN:
case A_PAR_TEMP_OUT:
case A_PAR_TEMP_INOUT:
{
template = new Referenced_Template(tempReference);
template.setLocation(tempReference.getLocation());
template.setMyScope(getMyScope());
final BridgingNamedNode tempNamedNode = new BridgingNamedNode(this, OPERAND);
template.setFullNameParent(tempNamedNode);
if (Expected_Value_type.EXPECTED_DYNAMIC_VALUE.equals(expectedValue) || Expected_Value_type.EXPECTED_DYNAMIC_VALUE.equals(expectedValue)) {
governor = template.getExpressionGovernor(timestamp, Expected_Value_type.EXPECTED_TEMPLATE);
} else {
governor = template.getExpressionGovernor(timestamp, expectedValue);
}
if (governor == null) {
setIsErroneous(true);
} else {
template.setMyGovernor(governor);
final TTCN3Template last = template.getTemplateReferencedLast(timestamp, referenceChain);
if (last.getIsErroneous(timestamp)) {
setIsErroneous(true);
}
}
if (!Expected_Value_type.EXPECTED_TEMPLATE.equals(expectedValue) && !Expected_Value_type.EXPECTED_DYNAMIC_VALUE.equals(expectedValue)) {
if (Expected_Value_type.EXPECTED_CONSTANT.equals(expectedValue)) {
template.getLocation().reportSemanticError(MessageFormat.format(CONSTANTREFERENCEEXPECTED, assignment.getDescription()));
} else {
template.getLocation().reportSemanticError(MessageFormat.format(STATICREFERENCEEXPECTED, assignment.getDescription()));
}
setIsErroneous(true);
}
break;
}
default:
tempReference.getLocation().reportSemanticError(MessageFormat.format(VALUETEMPLATEEXPECTED, assignment.getDescription()));
setIsErroneous(true);
return;
}
if (governor != null) {
governor = governor.getTypeRefdLast(timestamp);
if (!governor.getIsErroneous(timestamp)) {
CompField field = null;
switch(governor.getTypetype()) {
case TYPE_ASN1_CHOICE:
if (((ASN1_Choice_Type) governor).hasComponentWithName(identifier)) {
field = ((ASN1_Choice_Type) governor).getComponentByName(identifier);
}
break;
case TYPE_TTCN3_CHOICE:
if (((TTCN3_Choice_Type) governor).hasComponentWithName(identifier.getName())) {
field = ((TTCN3_Choice_Type) governor).getComponentByName(identifier.getName());
}
break;
case TYPE_OPENTYPE:
if (((Open_Type) governor).hasComponentWithName(identifier)) {
field = ((Open_Type) governor).getComponentByName(identifier);
}
break;
case TYPE_ANYTYPE:
if (((Anytype_Type) governor).hasComponentWithName(identifier.getName())) {
field = ((Anytype_Type) governor).getComponentByName(identifier.getName());
}
break;
default:
location.reportSemanticError(MessageFormat.format(OPERANDERROR, governor.getTypename()));
setIsErroneous(true);
return;
}
if (null == field) {
location.reportSemanticError(MessageFormat.format(MISSINGFIELD, governor.getTypename(), identifier.getDisplayName()));
setIsErroneous(true);
}
}
}
}
use of org.eclipse.titan.designer.AST.ASN1.types.Open_Type in project titan.EclipsePlug-ins by eclipse.
the class Named_Template_List method generateCodeInit.
@Override
public /**
* {@inheritDoc}
*/
void generateCodeInit(final JavaGenData aData, final StringBuilder source, final String name) {
if (lastTimeBuilt != null && !lastTimeBuilt.isLess(aData.getBuildTimstamp())) {
return;
}
lastTimeBuilt = aData.getBuildTimstamp();
if (asValue != null) {
asValue.generateCodeInit(aData, source, name);
return;
}
if (myGovernor == null) {
return;
}
// FIXME actually a bit more complex
final IType type = myGovernor.getTypeRefdLast(CompilationTimeStamp.getBaseTimestamp());
if (type == null) {
return;
}
if (namedTemplates.getNofTemplates() == 0) {
aData.addBuiltinTypeImport("TitanNull_Type");
source.append(MessageFormat.format("{0}.assign(TitanNull_Type.NULL_VALUE);\n", name));
}
// else is not needed as the loop will not run
for (int i = 0; i < namedTemplates.getNofTemplates(); i++) {
final NamedTemplate namedTemplate = namedTemplates.getTemplateByIndex(i);
final String fieldName = namedTemplate.getName().getName();
// FIXME handle needs_temp_ref case
final String generatedFieldName = FieldSubReference.getJavaGetterName(fieldName);
final TTCN3Template template = namedTemplate.getTemplate();
if (template.needsTemporaryReference()) {
Type fieldType;
switch(type.getTypetype()) {
case TYPE_SIGNATURE:
fieldType = ((Signature_Type) type).getParameterByName(fieldName).getType();
break;
case TYPE_TTCN3_SEQUENCE:
fieldType = ((TTCN3_Sequence_Type) type).getComponentByName(fieldName).getType();
break;
case TYPE_TTCN3_SET:
fieldType = ((TTCN3_Set_Type) type).getComponentByName(fieldName).getType();
break;
case TYPE_ASN1_SEQUENCE:
fieldType = ((ASN1_Sequence_Type) type).getComponentByName(new Identifier(Identifier_type.ID_NAME, fieldName)).getType();
break;
case TYPE_ASN1_SET:
fieldType = ((ASN1_Set_Type) type).getComponentByName(new Identifier(Identifier_type.ID_NAME, fieldName)).getType();
break;
case TYPE_ASN1_CHOICE:
fieldType = ((ASN1_Choice_Type) type).getComponentByName(new Identifier(Identifier_type.ID_NAME, fieldName)).getType();
break;
case TYPE_TTCN3_CHOICE:
fieldType = ((TTCN3_Choice_Type) type).getComponentByName(fieldName).getType();
break;
case TYPE_OPENTYPE:
fieldType = ((Open_Type) type).getComponentByName(new Identifier(Identifier_type.ID_NAME, fieldName)).getType();
break;
case TYPE_ANYTYPE:
fieldType = ((Anytype_Type) type).getComponentByName(fieldName).getType();
break;
default:
ErrorReporter.INTERNAL_ERROR("FATAL ERROR while processing named template list `" + getFullName() + "''");
return;
}
final String tempId = aData.getTemporaryVariableName();
source.append("{\n");
source.append(MessageFormat.format("{0} {1} = {2}.get{3}();\n", fieldType.getGenNameTemplate(aData, source, myScope), tempId, name, generatedFieldName));
template.generateCodeInit(aData, source, tempId);
source.append("}\n");
} else {
final String embeddedName = MessageFormat.format("{0}.get{1}()", name, generatedFieldName);
template.generateCodeInit(aData, source, embeddedName);
}
}
if (lengthRestriction != null) {
if (getCodeSection() == CodeSectionType.CS_POST_INIT) {
lengthRestriction.reArrangeInitCode(aData, source, myScope.getModuleScope());
}
lengthRestriction.generateCodeInit(aData, source, name);
}
if (isIfpresent) {
source.append(name);
source.append(".set_ifPresent();\n");
}
}
Aggregations