use of org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute in project titan.EclipsePlug-ins by eclipse.
the class Definition method checkErroneousAttributes.
protected void checkErroneousAttributes(final CompilationTimeStamp timestamp) {
erroneousAttributes = null;
if (withAttributesPath != null) {
final MultipleWithAttributes attribs = withAttributesPath.getAttributes();
if (attribs == null) {
return;
}
for (int i = 0; i < attribs.getNofElements(); i++) {
final SingleWithAttribute actualAttribute = attribs.getAttribute(i);
if (actualAttribute.getAttributeType() == Attribute_Type.Erroneous_Attribute) {
final int nofQualifiers = (actualAttribute.getQualifiers() == null) ? 0 : actualAttribute.getQualifiers().getNofQualifiers();
final List<IType> referencedTypeArray = new ArrayList<IType>(nofQualifiers);
final List<ArrayList<Integer>> subrefsArrayArray = new ArrayList<ArrayList<Integer>>(nofQualifiers);
final List<ArrayList<IType>> typeArrayArray = new ArrayList<ArrayList<IType>>(nofQualifiers);
if (nofQualifiers == 0) {
actualAttribute.getLocation().reportSemanticError("At least one qualifier must be specified for the `erroneous' attribute");
} else {
// existing fields
for (int qi = 0; qi < nofQualifiers; qi++) {
final Qualifier actualQualifier = actualAttribute.getQualifiers().getQualifierByIndex(qi);
final IType definitionType = getType(timestamp);
// construct a reference
final Reference reference = new Reference(null);
reference.addSubReference(new FieldSubReference(identifier));
for (int ri = 0; ri < actualQualifier.getNofSubReferences(); ri++) {
reference.addSubReference(actualQualifier.getSubReferenceByIndex(ri));
}
reference.setLocation(actualQualifier.getLocation());
reference.setMyScope(getMyScope());
IType fieldType = definitionType.getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_CONSTANT, false);
ArrayList<Integer> subrefsArray = null;
ArrayList<IType> typeArray = null;
if (fieldType != null) {
subrefsArray = new ArrayList<Integer>();
typeArray = new ArrayList<IType>();
final boolean validIndexes = definitionType.getSubrefsAsArray(timestamp, reference, 1, subrefsArray, typeArray);
if (!validIndexes) {
fieldType = null;
subrefsArray = null;
typeArray = null;
}
if (reference.refersToStringElement()) {
actualQualifier.getLocation().reportSemanticError("Reference to a string element cannot be used in this context");
fieldType = null;
subrefsArray = null;
typeArray = null;
}
}
referencedTypeArray.add(fieldType);
subrefsArrayArray.add(subrefsArray);
typeArrayArray.add(typeArray);
}
}
// parse the attr. spec.
final ErroneousAttributeSpecification errAttributeSpecification = parseErrAttrSpecString(actualAttribute.getAttributeSpecification());
if (errAttributeSpecification != null) {
if (erroneousAttributes == null) {
erroneousAttributes = new ErroneousAttributes(getType(timestamp));
}
erroneousAttributes.addSpecification(errAttributeSpecification);
errAttributeSpecification.check(timestamp, getMyScope());
// err.attr.spec. pairs
for (int qi = 0; qi < nofQualifiers; qi++) {
if (referencedTypeArray.get(qi) != null && errAttributeSpecification.getIndicator() != Indicator_Type.Invalid_Indicator) {
final Qualifier actualQualifier = actualAttribute.getQualifiers().getQualifierByIndex(qi);
erroneousAttributes.addFieldErr(actualQualifier, errAttributeSpecification, subrefsArrayArray.get(qi), typeArrayArray.get(qi));
}
}
}
}
}
if (erroneousAttributes != null) {
erroneousAttributes.check(timestamp);
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute in project titan.EclipsePlug-ins by eclipse.
the class Definition method hasImplicitOmitAttribute.
/**
* Checks if this definition has an implicit omit attribute or not.
*
* @param timestamp
* the timestamp of the actual semantic check cycle.
*
* @return true if it has an implicit omit attribute, false if no
* attribute is given or explicit omit is specified.
*/
public boolean hasImplicitOmitAttribute(final CompilationTimeStamp timestamp) {
if (withAttributesPath == null) {
return false;
}
final List<SingleWithAttribute> realAttributes = withAttributesPath.getRealAttributes(timestamp);
SingleWithAttribute tempAttribute;
for (int i = realAttributes.size() - 1; i >= 0; i--) {
tempAttribute = realAttributes.get(i);
if (tempAttribute != null && Attribute_Type.Optional_Attribute.equals(tempAttribute.getAttributeType())) {
final String tempSpecification = tempAttribute.getAttributeSpecification().getSpecification();
if ("implicit omit".equals(tempSpecification)) {
return true;
} else if ("explicit omit".equals(tempSpecification)) {
return false;
}
}
}
return false;
}
use of org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute in project titan.EclipsePlug-ins by eclipse.
the class Def_Type method analyzeExtensionAttributes.
/**
* Convert and check the encoding attributes applied to this function.
*
* @param timestamp
* the timestamp of the actual build cycle.
*/
public void analyzeExtensionAttributes(final CompilationTimeStamp timestamp, final WithAttributesPath withAttributesPath) {
final List<SingleWithAttribute> realAttributes = withAttributesPath.getRealAttributes(timestamp);
SingleWithAttribute attribute;
List<AttributeSpecification> specifications = null;
for (int i = 0, size = realAttributes.size(); i < size; i++) {
attribute = realAttributes.get(i);
if (Attribute_Type.Extension_Attribute.equals(attribute.getAttributeType())) {
final Qualifiers qualifiers = attribute.getQualifiers();
if (qualifiers == null || qualifiers.getNofQualifiers() == 0) {
if (specifications == null) {
specifications = new ArrayList<AttributeSpecification>();
}
specifications.add(attribute.getAttributeSpecification());
} else {
for (int j = 0, size2 = qualifiers.getNofQualifiers(); j < size2; j++) {
final Qualifier tempQualifier = qualifiers.getQualifierByIndex(i);
final ISubReference tempSubReference = tempQualifier.getSubReferenceByIndex(0);
if (tempSubReference.getReferenceType() == Subreference_type.arraySubReference) {
tempQualifier.getLocation().reportSemanticError(Qualifier.INVALID_INDEX_QUALIFIER);
} else {
tempQualifier.getLocation().reportSemanticError(MessageFormat.format(Qualifier.INVALID_FIELD_QUALIFIER, tempSubReference.getId().getDisplayName()));
}
}
}
}
}
if (specifications == null) {
return;
}
final List<ExtensionAttribute> attributes = new ArrayList<ExtensionAttribute>();
for (int i = 0; i < specifications.size(); i++) {
final AttributeSpecification specification = specifications.get(i);
final ExtensionAttributeAnalyzer analyzer = new ExtensionAttributeAnalyzer();
analyzer.parse(specification);
final List<ExtensionAttribute> temp = analyzer.getAttributes();
if (temp != null) {
attributes.addAll(temp);
}
}
for (int i = 0; i < attributes.size(); i++) {
final ExtensionAttribute extensionAttribute = attributes.get(i);
switch(extensionAttribute.getAttributeType()) {
case ANYTYPE:
case VERSION:
case REQUIRES:
case TITANVERSION:
break;
default:
// only extension attributes are allowed ... and
// only because they can not be stopped earlier.
extensionAttribute.getLocation().reportSemanticError("Extension attributes are not supported for types");
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute in project titan.EclipsePlug-ins by eclipse.
the class TTCN3Module method analyzeExtensionAttributes.
/**
* Convert and check the version, requires and titan version extension attributes.
*
* @param timestamp
* the timestamp of the actual build cycle.
*/
private void analyzeExtensionAttributes(final CompilationTimeStamp timestamp) {
if (withAttributesPath == null) {
return;
}
final List<SingleWithAttribute> realAttributes = withAttributesPath.getRealAttributes(timestamp);
SingleWithAttribute attribute;
List<AttributeSpecification> specifications = null;
for (int i = 0; i < realAttributes.size(); i++) {
attribute = realAttributes.get(i);
if (Attribute_Type.Extension_Attribute.equals(attribute.getAttributeType())) {
final Qualifiers qualifiers = attribute.getQualifiers();
if (qualifiers == null || qualifiers.getNofQualifiers() == 0) {
if (specifications == null) {
specifications = new ArrayList<AttributeSpecification>();
}
specifications.add(attribute.getAttributeSpecification());
}
}
}
if (specifications == null) {
return;
}
final List<ExtensionAttribute> attributes = new ArrayList<ExtensionAttribute>();
AttributeSpecification specification;
for (int i = 0; i < specifications.size(); i++) {
specification = specifications.get(i);
final ExtensionAttributeAnalyzer analyzer = new ExtensionAttributeAnalyzer();
analyzer.parse(specification);
final List<ExtensionAttribute> temp = analyzer.getAttributes();
if (temp != null) {
attributes.addAll(temp);
}
}
ExtensionAttribute extensionAttribute;
for (int i = 0; i < attributes.size(); i++) {
extensionAttribute = attributes.get(i);
switch(extensionAttribute.getAttributeType()) {
case VERSION:
{
final ModuleVersionAttribute moduleVersion = (ModuleVersionAttribute) extensionAttribute;
moduleVersion.parse();
if (versionNumber != null) {
moduleVersion.getLocation().reportSemanticError("Duplicate version attribute");
} else {
setVersion(moduleVersion.getVersionNumber());
}
break;
}
case REQUIRES:
{
final VersionRequirementAttribute versionReq = (VersionRequirementAttribute) extensionAttribute;
versionReq.parse();
ImportModule theImport = null;
final String requiredModuleName = versionReq.getRequiredModule().getName();
for (final ImportModule impMod : importedModules) {
if (requiredModuleName.equals(impMod.getIdentifier().getName())) {
theImport = impMod;
break;
}
}
if (theImport == null) {
final String message = MessageFormat.format(ImportModule.MISSINGMODULE, versionReq.getRequiredModule().getDisplayName());
versionReq.getRequiredModule().getLocation().reportSemanticError(message);
} else {
final TTCN3Module theImportedModule = (TTCN3Module) theImport.getReferredModule();
// make sure the version attribute is parsed (if any)
theImportedModule.check(timestamp);
final ProductIdentity requiredVersion = versionReq.getVersionNumber();
if (requiredVersion != null && theImportedModule.versionNumber != null && theImportedModule.versionNumber.compareTo(requiredVersion) < 0) {
final String message = MessageFormat.format("Module `{0}'' requires version {1} of module `{2}'', but only version {3} is available", identifier.getDisplayName(), requiredVersion.toString(), theImportedModule.getIdentifier().getDisplayName(), theImportedModule.versionNumber.toString());
versionReq.getLocation().reportSemanticError(message);
}
}
break;
}
case TITANVERSION:
{
final TitanVersionAttribute titanReq = (TitanVersionAttribute) extensionAttribute;
titanReq.parse();
final ProductIdentity requiredTITANVersion = titanReq.getVersionNumber();
final String temp = CompilerVersionInformationCollector.getCompilerProductNumber();
final ProductIdentity compilerVersion = ProductIdentityHelper.getProductIdentity(temp, null);
if (requiredTITANVersion != null && compilerVersion != null && compilerVersion.compareTo(requiredTITANVersion) < 0) {
final String message = MessageFormat.format("Module `{0}'' requires TITAN version {1}, but version {2} is used right now", identifier.getDisplayName(), requiredTITANVersion.toString(), compilerVersion.toString());
titanReq.getLocation().reportSemanticError(message);
}
if (requiredTITANVersion != null && GeneralConstants.ON_THE_FLY_ANALYZER_VERSION != null && GeneralConstants.ON_THE_FLY_ANALYZER_VERSION.compareTo(requiredTITANVersion) < 0) {
final String message = MessageFormat.format("Module `{0}'' requires TITAN version {1}, but the on-the-fly analyzer is of version {2}", identifier.getDisplayName(), requiredTITANVersion.toString(), GeneralConstants.ON_THE_FLY_ANALYZER_VERSION.toString());
titanReq.getLocation().reportSemanticError(message);
}
break;
}
default:
// we don't care
break;
}
}
}
use of org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute in project titan.EclipsePlug-ins by eclipse.
the class Type method checkEncode.
/**
* Checks the encodings supported by the type (when using new codec handling).
* TTCN-3 types need to have an 'encode' attribute to support an encoding.
* ASN.1 types automatically support BER, PER and JSON encodings, and XER
* encoding, if set by the compiler option.
*/
public void checkEncode(final CompilationTimeStamp timestamp) {
switch(getTypeRefdLast(timestamp).getTypetypeTtcn3()) {
case TYPE_NULL:
case TYPE_BOOL:
case TYPE_INTEGER:
case TYPE_REAL:
case TYPE_TTCN3_ENUMERATED:
case TYPE_BITSTRING:
case TYPE_HEXSTRING:
case TYPE_OCTETSTRING:
case TYPE_CHARSTRING:
case TYPE_UCHARSTRING:
case TYPE_OBJECTID:
case TYPE_TTCN3_CHOICE:
case TYPE_SEQUENCE_OF:
case TYPE_SET_OF:
case TYPE_TTCN3_SEQUENCE:
case TYPE_TTCN3_SET:
case TYPE_VERDICT:
case TYPE_ARRAY:
case TYPE_ANYTYPE:
if (!isAsn()) {
final WithAttributesPath attributePath = getAttributePath();
if (attributePath != null) {
final MultipleWithAttributes multipleWithAttributes = attributePath.getAttributes();
if (multipleWithAttributes != null) {
for (int i = 0; i < multipleWithAttributes.getNofElements(); i++) {
final SingleWithAttribute singleWithAttribute = multipleWithAttributes.getAttribute(i);
if (singleWithAttribute.getAttributeType() == Attribute_Type.Encode_Attribute) {
final Attribute_Modifier_type mod = singleWithAttribute.getModifier();
final Qualifiers qualifiers = singleWithAttribute.getQualifiers();
if (qualifiers != null && qualifiers.getNofQualifiers() > 0) {
for (int j = 0; j < qualifiers.getNofQualifiers(); j++) {
final Qualifier qualifier = qualifiers.getQualifierByIndex(j);
final List<ISubReference> fieldsOrArrays = new ArrayList<ISubReference>();
for (int k = 0; k < qualifier.getNofSubReferences(); k++) {
fieldsOrArrays.add(qualifier.getSubReferenceByIndex(k));
}
final Reference reference = new Reference(null, fieldsOrArrays);
final IType type = getFieldType(timestamp, reference, 0, Expected_Value_type.EXPECTED_CONSTANT, false);
if (type != null) {
if (type.getMyScope() != myScope) {
qualifier.getLocation().reportSemanticWarning("Encode attribute is ignored, because it refers to a type from a different type definition");
} else {
type.addCoding(timestamp, singleWithAttribute.getAttributeSpecification().getSpecification(), mod, false);
}
}
}
} else {
addCoding(timestamp, singleWithAttribute.getAttributeSpecification().getSpecification(), mod, false);
}
}
}
}
if (ownerType != TypeOwner_type.OT_TYPE_DEF) {
return;
}
WithAttributesPath globalAttributesPath;
final Def_Type def = (Def_Type) owner;
final Group nearest_group = def.getParentGroup();
if (nearest_group == null) {
// no group, use the module
Module myModule = myScope.getModuleScope();
globalAttributesPath = ((TTCN3Module) myModule).getAttributePath();
} else {
globalAttributesPath = nearest_group.getAttributePath();
}
if (globalAttributesPath != null) {
boolean hasGlobalOverride = false;
boolean modifierConflict = false;
Attribute_Modifier_type firstModifier = Attribute_Modifier_type.MOD_NONE;
final List<SingleWithAttribute> realAttributes = globalAttributesPath.getRealAttributes(timestamp);
for (int i = 0; i < realAttributes.size(); i++) {
final SingleWithAttribute singleWithAttribute = realAttributes.get(i);
if (singleWithAttribute.getAttributeType() == Attribute_Type.Encode_Attribute) {
Attribute_Modifier_type modifier = singleWithAttribute.getModifier();
if (i == 0) {
firstModifier = modifier;
} else if (!modifierConflict && modifier != firstModifier) {
modifierConflict = true;
singleWithAttribute.getLocation().reportSemanticError("All 'encode' attributes of a group or module must have the same modifier ('override', '@local' or none)");
}
if (modifier == Attribute_Modifier_type.MOD_OVERRIDE) {
hasGlobalOverride = true;
}
if (hasGlobalOverride && modifierConflict) {
break;
}
}
}
// make a list of the type and its field and element types that inherit
// the global 'encode' attributes
// overriding global attributes are inherited by types with no coding
// table (no 'encode' attributes) of their own
// non-overriding global attributes are inherited by types that have
// no coding table of their own and cannot use the coding table of any
// other type
final ArrayList<IType> typeList = new ArrayList<IType>();
getTypesWithNoCodingTable(timestamp, typeList, hasGlobalOverride);
if (!typeList.isEmpty()) {
for (int i = 0; i < realAttributes.size(); i++) {
final SingleWithAttribute singleWithAttribute = realAttributes.get(i);
if (singleWithAttribute.getAttributeType() == Attribute_Type.Encode_Attribute) {
for (int j = typeList.size() - 1; j >= 0; j--) {
typeList.get(j).addCoding(timestamp, singleWithAttribute.getAttributeSpecification().getSpecification(), Attribute_Modifier_type.MOD_NONE, true);
}
}
}
typeList.clear();
}
}
}
} else {
// ASN.1 types automatically have BER, PER, XER, OER and JSON encoding
switch(ownerType) {
case OT_TYPE_ASS:
case OT_RECORD_OF:
case OT_COMP_FIELD:
case OT_SELTYPE:
case OT_FIELDSETTING:
// FIXME implement once PER, JSON, OER or XER gets supported
break;
default:
break;
}
}
break;
default:
// the rest of the types can't have 'encode' attributes
break;
}
}
Aggregations