Search in sources :

Example 1 with SingleWithAttribute

use of org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute in project titan.EclipsePlug-ins by eclipse.

the class Type method checkVariants.

/**
 * Checks the type's variant attributes (when using the new codec handling).
 */
public void checkVariants(final CompilationTimeStamp timestamp) {
    if (isAsn() || 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) {
        // process all global variants, not just the closest group
        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.Variant_Attribute) {
                checkThisVariant(timestamp, singleWithAttribute, true);
            }
        }
    }
    // check local variant attributes second, so they overwrite global ones if they
    // conflict with each other
    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.Variant_Attribute) {
                    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("Variant attribute is ignored, because it refers to a type from a different type definition");
                                } else {
                                    type.checkThisVariant(timestamp, singleWithAttribute, false);
                                }
                            }
                        }
                    } else {
                        checkThisVariant(timestamp, singleWithAttribute, false);
                    }
                }
            }
        }
    }
    // check the coding attributes set by the variants
    final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    checkCodingAttributes(timestamp, chain);
    chain.release();
}
Also used : WithAttributesPath(org.eclipse.titan.designer.AST.TTCN3.attributes.WithAttributesPath) Group(org.eclipse.titan.designer.AST.TTCN3.definitions.Group) Def_Type(org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type) ArrayList(java.util.ArrayList) SingleWithAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute) MultipleWithAttributes(org.eclipse.titan.designer.AST.TTCN3.attributes.MultipleWithAttributes) Qualifier(org.eclipse.titan.designer.AST.TTCN3.attributes.Qualifier) Qualifiers(org.eclipse.titan.designer.AST.TTCN3.attributes.Qualifiers) TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module)

Example 2 with SingleWithAttribute

use of org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute in project titan.EclipsePlug-ins by eclipse.

the class Type method hasVariantAttributes.

@Override
public final /**
 * {@inheritDoc}
 */
boolean hasVariantAttributes(final CompilationTimeStamp timestamp) {
    if (withAttributesPath == null) {
        return false;
    }
    final List<SingleWithAttribute> realAttributes = withAttributesPath.getRealAttributes(timestamp);
    for (int i = 0; i < realAttributes.size(); i++) {
        if (SingleWithAttribute.Attribute_Type.Variant_Attribute.equals(realAttributes.get(i).getAttributeType())) {
            return true;
        }
    }
    final MultipleWithAttributes localAttributes = withAttributesPath.getAttributes();
    if (localAttributes == null) {
        return false;
    }
    for (int i = 0; i < localAttributes.getNofElements(); i++) {
        final SingleWithAttribute tempSingle = localAttributes.getAttribute(i);
        if (Attribute_Type.Variant_Attribute.equals(tempSingle.getAttributeType())) {
            return true;
        }
    }
    return false;
}
Also used : SingleWithAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute) MultipleWithAttributes(org.eclipse.titan.designer.AST.TTCN3.attributes.MultipleWithAttributes)

Example 3 with SingleWithAttribute

use of org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute 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 4 with SingleWithAttribute

use of org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute 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 5 with SingleWithAttribute

use of org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute 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)

Aggregations

SingleWithAttribute (org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute)13 ArrayList (java.util.ArrayList)11 Qualifiers (org.eclipse.titan.designer.AST.TTCN3.attributes.Qualifiers)9 AttributeSpecification (org.eclipse.titan.designer.AST.TTCN3.attributes.AttributeSpecification)7 ExtensionAttribute (org.eclipse.titan.designer.AST.TTCN3.attributes.ExtensionAttribute)7 ExtensionAttributeAnalyzer (org.eclipse.titan.designer.parsers.extensionattributeparser.ExtensionAttributeAnalyzer)7 MultipleWithAttributes (org.eclipse.titan.designer.AST.TTCN3.attributes.MultipleWithAttributes)4 Qualifier (org.eclipse.titan.designer.AST.TTCN3.attributes.Qualifier)4 TTCN3Module (org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module)4 IType (org.eclipse.titan.designer.AST.IType)3 WithAttributesPath (org.eclipse.titan.designer.AST.TTCN3.attributes.WithAttributesPath)3 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)2 ISubReference (org.eclipse.titan.designer.AST.ISubReference)2 Reference (org.eclipse.titan.designer.AST.Reference)2 Def_Type (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type)2 Group (org.eclipse.titan.designer.AST.TTCN3.definitions.Group)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 ProductIdentity (org.eclipse.titan.common.product.ProductIdentity)1 ASN1_Set_Seq_Choice_BaseType (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Seq_Choice_BaseType)1