Search in sources :

Example 1 with ExtensionAttributeAnalyzer

use of org.eclipse.titan.designer.parsers.extensionattributeparser.ExtensionAttributeAnalyzer in project titan.EclipsePlug-ins by eclipse.

the class Def_Extfunction method analyzeExtensionAttributes.

/**
 * Convert and check the encoding attributes applied to this external
 * function.
 *
 * @param timestamp
 *                the timestamp of the actual build cycle.
 */
public void analyzeExtensionAttributes(final CompilationTimeStamp timestamp) {
    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());
            }
        }
    }
    if (specifications == null) {
        return;
    }
    final List<ExtensionAttribute> attributes = new ArrayList<ExtensionAttribute>();
    AttributeSpecification specification;
    for (int i = 0, size = specifications.size(); i < 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, size = attributes.size(); i < size; i++) {
        extensionAttribute = attributes.get(i);
        switch(extensionAttribute.getAttributeType()) {
            case PROTOTYPE:
                if (EncodingPrototype_type.NONE.equals(prototype)) {
                    prototype = ((PrototypeAttribute) extensionAttribute).getPrototypeType();
                } else {
                    location.reportSemanticError("duplicate attribute `prototype'.");
                }
                break;
            case ENCODE:
                switch(functionEncodingType) {
                    case MANUAL:
                        break;
                    case ENCODE:
                        location.reportSemanticError("duplicate attribute `encode'.");
                        break;
                    case DECODE:
                        location.reportSemanticError("`decode' and `encode' attributes cannot be used at the same time.");
                        break;
                    default:
                        break;
                }
                encodingType = ((EncodeAttribute) extensionAttribute).getEncodingType();
                encodingOptions = ((EncodeAttribute) extensionAttribute).getOptions();
                functionEncodingType = ExternalFunctionEncodingType_type.ENCODE;
                break;
            case DECODE:
                switch(functionEncodingType) {
                    case MANUAL:
                        break;
                    case ENCODE:
                        location.reportSemanticError("`decode' and `encode' attributes cannot be used at the same time.");
                        break;
                    case DECODE:
                        location.reportSemanticError("duplicate attribute `decode'.");
                        break;
                    default:
                        break;
                }
                encodingType = ((DecodeAttribute) extensionAttribute).getEncodingType();
                encodingOptions = ((DecodeAttribute) extensionAttribute).getOptions();
                functionEncodingType = ExternalFunctionEncodingType_type.DECODE;
                break;
            case ERRORBEHAVIOR:
                if (errorBehaviorList == null) {
                    errorBehaviorList = ((ErrorBehaviorAttribute) extensionAttribute).getErrrorBehaviorList();
                } else {
                    errorBehaviorList.addAllBehaviors(((ErrorBehaviorAttribute) extensionAttribute).getErrrorBehaviorList());
                }
                break;
            case PRINTING:
                if (printingType == null) {
                    printingType = ((PrintingAttribute) extensionAttribute).getPrintingType();
                } else {
                    location.reportSemanticError("duplicate attribute `printing'.");
                }
                break;
            default:
                break;
        }
    }
}
Also used : AttributeSpecification(org.eclipse.titan.designer.AST.TTCN3.attributes.AttributeSpecification) ArrayList(java.util.ArrayList) SingleWithAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute) ExtensionAttributeAnalyzer(org.eclipse.titan.designer.parsers.extensionattributeparser.ExtensionAttributeAnalyzer) Qualifiers(org.eclipse.titan.designer.AST.TTCN3.attributes.Qualifiers) ExtensionAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.ExtensionAttribute)

Example 2 with ExtensionAttributeAnalyzer

use of org.eclipse.titan.designer.parsers.extensionattributeparser.ExtensionAttributeAnalyzer in project titan.EclipsePlug-ins by eclipse.

the class Def_Function 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 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());
            }
        }
    }
    if (specifications == null) {
        return;
    }
    final List<ExtensionAttribute> attributes = new ArrayList<ExtensionAttribute>();
    for (int i = 0, size = specifications.size(); i < 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, size = attributes.size(); i < size; i++) {
        final ExtensionAttribute extensionAttribute = attributes.get(i);
        if (ExtensionAttribute_type.PROTOTYPE.equals(extensionAttribute.getAttributeType())) {
            final PrototypeAttribute realAttribute = (PrototypeAttribute) extensionAttribute;
            if (EncodingPrototype_type.NONE.equals(prototype)) {
                prototype = realAttribute.getPrototypeType();
            } else {
                realAttribute.getLocation().reportSingularSemanticError("Duplicate attribute `prototype'");
            }
        }
    }
}
Also used : AttributeSpecification(org.eclipse.titan.designer.AST.TTCN3.attributes.AttributeSpecification) PrototypeAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.PrototypeAttribute) ArrayList(java.util.ArrayList) SingleWithAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute) ExtensionAttributeAnalyzer(org.eclipse.titan.designer.parsers.extensionattributeparser.ExtensionAttributeAnalyzer) Qualifiers(org.eclipse.titan.designer.AST.TTCN3.attributes.Qualifiers) ExtensionAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.ExtensionAttribute)

Example 3 with ExtensionAttributeAnalyzer

use of org.eclipse.titan.designer.parsers.extensionattributeparser.ExtensionAttributeAnalyzer in project titan.EclipsePlug-ins by eclipse.

the class Anytype_Type method analyzeExtensionAttributes.

/**
 * Convert and check the anytype attributes applied to the module of this type.
 *
 * @param timestamp
 *                the timestamp of the actual build cycle.
 */
private void analyzeExtensionAttributes(final CompilationTimeStamp timestamp) {
    clear();
    final TTCN3Module myModule = (TTCN3Module) getMyScope().getModuleScope();
    final WithAttributesPath moduleAttributePath = myModule.getAttributePath();
    if (moduleAttributePath == null) {
        return;
    }
    final List<SingleWithAttribute> realAttributes = moduleAttributePath.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);
        }
    }
    final Scope definitionsScope = myModule.getDefinitions();
    ExtensionAttribute extensionAttribute;
    for (int i = 0; i < attributes.size(); i++) {
        extensionAttribute = attributes.get(i);
        if (ExtensionAttribute_type.ANYTYPE.equals(extensionAttribute.getAttributeType())) {
            final AnytypeAttribute anytypeAttribute = (AnytypeAttribute) extensionAttribute;
            for (int j = 0; j < anytypeAttribute.getNofTypes(); j++) {
                final Type tempType = anytypeAttribute.getType(j);
                String fieldName;
                Identifier identifier = null;
                if (Type_type.TYPE_REFERENCED.equals(tempType.getTypetype())) {
                    final Reference reference = ((Referenced_Type) tempType).getReference();
                    identifier = reference.getId();
                    fieldName = identifier.getTtcnName();
                } else {
                    fieldName = tempType.getTypename();
                    identifier = new Identifier(Identifier_type.ID_TTCN, fieldName);
                }
                tempType.setMyScope(definitionsScope);
                addComp(new CompField(identifier, tempType, false, null));
            }
        }
    }
}
Also used : WithAttributesPath(org.eclipse.titan.designer.AST.TTCN3.attributes.WithAttributesPath) TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module) Reference(org.eclipse.titan.designer.AST.Reference) ISubReference(org.eclipse.titan.designer.AST.ISubReference) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) ArraySubReference(org.eclipse.titan.designer.AST.ArraySubReference) ParameterisedSubReference(org.eclipse.titan.designer.AST.ParameterisedSubReference) ArrayList(java.util.ArrayList) SingleWithAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute) AnytypeAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.AnytypeAttribute) ExtensionAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.ExtensionAttribute) AttributeSpecification(org.eclipse.titan.designer.AST.TTCN3.attributes.AttributeSpecification) Attribute_Type(org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute.Attribute_Type) Type(org.eclipse.titan.designer.AST.Type) IType(org.eclipse.titan.designer.AST.IType) Identifier(org.eclipse.titan.designer.AST.Identifier) Scope(org.eclipse.titan.designer.AST.Scope) ExtensionAttributeAnalyzer(org.eclipse.titan.designer.parsers.extensionattributeparser.ExtensionAttributeAnalyzer) Qualifiers(org.eclipse.titan.designer.AST.TTCN3.attributes.Qualifiers)

Example 4 with ExtensionAttributeAnalyzer

use of org.eclipse.titan.designer.parsers.extensionattributeparser.ExtensionAttributeAnalyzer 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");
        }
    }
}
Also used : ArrayList(java.util.ArrayList) SingleWithAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute) ExtensionAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.ExtensionAttribute) ISubReference(org.eclipse.titan.designer.AST.ISubReference) AttributeSpecification(org.eclipse.titan.designer.AST.TTCN3.attributes.AttributeSpecification) ExtensionAttributeAnalyzer(org.eclipse.titan.designer.parsers.extensionattributeparser.ExtensionAttributeAnalyzer) Qualifier(org.eclipse.titan.designer.AST.TTCN3.attributes.Qualifier) Qualifiers(org.eclipse.titan.designer.AST.TTCN3.attributes.Qualifiers)

Example 5 with ExtensionAttributeAnalyzer

use of org.eclipse.titan.designer.parsers.extensionattributeparser.ExtensionAttributeAnalyzer 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;
        }
    }
}
Also used : ModuleVersionAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.ModuleVersionAttribute) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) SingleWithAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute) ExtensionAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.ExtensionAttribute) AttributeSpecification(org.eclipse.titan.designer.AST.TTCN3.attributes.AttributeSpecification) VersionRequirementAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.VersionRequirementAttribute) ProductIdentity(org.eclipse.titan.common.product.ProductIdentity) ExtensionAttributeAnalyzer(org.eclipse.titan.designer.parsers.extensionattributeparser.ExtensionAttributeAnalyzer) TitanVersionAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.TitanVersionAttribute) Qualifiers(org.eclipse.titan.designer.AST.TTCN3.attributes.Qualifiers)

Aggregations

ArrayList (java.util.ArrayList)7 AttributeSpecification (org.eclipse.titan.designer.AST.TTCN3.attributes.AttributeSpecification)7 ExtensionAttribute (org.eclipse.titan.designer.AST.TTCN3.attributes.ExtensionAttribute)7 Qualifiers (org.eclipse.titan.designer.AST.TTCN3.attributes.Qualifiers)7 SingleWithAttribute (org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute)7 ExtensionAttributeAnalyzer (org.eclipse.titan.designer.parsers.extensionattributeparser.ExtensionAttributeAnalyzer)7 ISubReference (org.eclipse.titan.designer.AST.ISubReference)2 IType (org.eclipse.titan.designer.AST.IType)2 TTCN3Module (org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 ProductIdentity (org.eclipse.titan.common.product.ProductIdentity)1 ArraySubReference (org.eclipse.titan.designer.AST.ArraySubReference)1 BridgingNamedNode (org.eclipse.titan.designer.AST.BridgingNamedNode)1 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)1 Identifier (org.eclipse.titan.designer.AST.Identifier)1 ParameterisedSubReference (org.eclipse.titan.designer.AST.ParameterisedSubReference)1 Reference (org.eclipse.titan.designer.AST.Reference)1 Scope (org.eclipse.titan.designer.AST.Scope)1 AnytypeAttribute (org.eclipse.titan.designer.AST.TTCN3.attributes.AnytypeAttribute)1 ExtensionsAttribute (org.eclipse.titan.designer.AST.TTCN3.attributes.ExtensionsAttribute)1