Search in sources :

Example 11 with SingleWithAttribute

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

the class Type method checkDoneAttribute.

@Override
public final /**
 * {@inheritDoc}
 */
void checkDoneAttribute(final CompilationTimeStamp timestamp) {
    hasDone = false;
    if (withAttributesPath == null) {
        return;
    }
    final List<SingleWithAttribute> realAttributes = withAttributesPath.getRealAttributes(timestamp);
    for (int i = 0, size = realAttributes.size(); i < size; i++) {
        final SingleWithAttribute singleAttribute = realAttributes.get(i);
        if (Attribute_Type.Extension_Attribute.equals(singleAttribute.getAttributeType()) && "done".equals(singleAttribute.getAttributeSpecification().getSpecification())) {
            hasDone = true;
        }
    }
}
Also used : SingleWithAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute)

Example 12 with SingleWithAttribute

use of org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute 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;
        }
    }
}
Also used : VariantAttributeAnalyzer(org.eclipse.titan.designer.parsers.variantattributeparser.VariantAttributeAnalyzer) Open_Type(org.eclipse.titan.designer.AST.ASN1.types.Open_Type) RawAST(org.eclipse.titan.designer.AST.TTCN3.attributes.RawAST) ASN1_Set_Seq_Choice_BaseType(org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Seq_Choice_BaseType) ArrayList(java.util.ArrayList) Anytype_Type(org.eclipse.titan.designer.AST.TTCN3.types.Anytype_Type) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TTCN3_Set_Seq_Choice_BaseType(org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Set_Seq_Choice_BaseType) Referenced_Type(org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type)

Example 13 with SingleWithAttribute

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

the class PortTypeBody method checkAttributes.

/**
 * Does the semantic checking of the attributes assigned to the port type having this body.
 *
 * @param timestamp the time stamp of the actual semantic check cycle.
 * @param withAttributesPath the withAttributesPath assigned to the port type.
 */
public void checkAttributes(final CompilationTimeStamp timestamp, final WithAttributesPath withAttributesPath) {
    if (lastTimeAttributesChecked != null && !lastTimeAttributesChecked.isLess(timestamp)) {
        return;
    }
    lastTimeAttributesChecked = lastTimeChecked;
    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>();
                }
                final AttributeSpecification specification = attribute.getAttributeSpecification();
                if (specification.getSpecification() != null) {
                    // there is nothing to parse if specification string is null,
                    // anyway it would cause NPE in ExtensionAttributeAnalyzer.parse()
                    specifications.add(specification);
                }
            }
        }
    }
    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);
        }
    }
    if (attributes.isEmpty()) {
        return;
    }
    // clear the old attributes
    testportType = TestPortAPI_type.TP_REGULAR;
    portType = PortType_type.PT_REGULAR;
    // check the new attributes
    for (int i = 0; i < attributes.size(); i++) {
        final ExtensionAttribute extensionAttribute = attributes.get(i);
        if (ExtensionAttribute_type.PORTTYPE.equals(extensionAttribute.getAttributeType())) {
            final PortTypeAttribute portAttribute = (PortTypeAttribute) extensionAttribute;
            switch(portAttribute.getPortTypeType()) {
                case INTERNAL:
                    switch(testportType) {
                        case TP_REGULAR:
                            break;
                        case TP_INTERNAL:
                            extensionAttribute.getLocation().reportSemanticWarning("Duplicate attribute `internal'");
                            break;
                        case TP_ADDRESS:
                            extensionAttribute.getLocation().reportSemanticError("Attributes `address' and `internal' cannot be used at the same time");
                            break;
                        default:
                            break;
                    }
                    testportType = TestPortAPI_type.TP_INTERNAL;
                    break;
                case ADDRESS:
                    switch(testportType) {
                        case TP_REGULAR:
                            break;
                        case TP_INTERNAL:
                            extensionAttribute.getLocation().reportSemanticError("Attributes `address' and `internal' cannot be used at the same time");
                            break;
                        case TP_ADDRESS:
                            extensionAttribute.getLocation().reportSemanticWarning("Duplicate attribute `address'");
                            break;
                        default:
                            break;
                    }
                    testportType = TestPortAPI_type.TP_ADDRESS;
                    break;
                case PROVIDER:
                    switch(portType) {
                        case PT_REGULAR:
                            break;
                        case PT_PROVIDER:
                            extensionAttribute.getLocation().reportSemanticWarning("Duplicate attribute `provider'");
                            break;
                        case PT_USER:
                            extensionAttribute.getLocation().reportSemanticError("Attributes `user' and `provider' cannot be used at the same time");
                            break;
                        default:
                            break;
                    }
                    addProviderAttribute();
                    break;
                case USER:
                    switch(portType) {
                        case PT_REGULAR:
                            break;
                        case PT_PROVIDER:
                            extensionAttribute.getLocation().reportSemanticError("Attributes `provider' and `user' cannot be used at the same time");
                            break;
                        case PT_USER:
                            extensionAttribute.getLocation().reportSemanticError("Duplicate attribute `user'");
                            break;
                        default:
                            break;
                    }
                    final UserPortTypeAttribute user = (UserPortTypeAttribute) portAttribute;
                    addUserAttribute(user.getReference(), user.getInMappings(), user.getOutMappings());
                    break;
                default:
                    break;
            }
        }
    }
    if (PortType_type.PT_USER.equals(portType)) {
        checkUserAttribute(timestamp);
    } else if (TestPortAPI_type.TP_ADDRESS.equals(testportType)) {
        final TTCN3Module module = (TTCN3Module) myType.getMyScope().getModuleScope();
        if (module.getAddressType(timestamp) == null) {
            location.reportSemanticError(MessageFormat.format("Type `address'' is not defined in module `{0}''", module.getIdentifier().getDisplayName()));
        }
    }
}
Also used : PortTypeAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.PortTypeAttribute) UserPortTypeAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.UserPortTypeAttribute) TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module) 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) ExtensionAttributeAnalyzer(org.eclipse.titan.designer.parsers.extensionattributeparser.ExtensionAttributeAnalyzer) UserPortTypeAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.UserPortTypeAttribute) Qualifiers(org.eclipse.titan.designer.AST.TTCN3.attributes.Qualifiers)

Example 14 with SingleWithAttribute

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

the class ComponentTypeBody method collectExtensionAttributes.

/**
 * Collects the extends extension attributes, from the with attributes assigned to the component type.
 *
 * @param timestamp the timestamp of the actual semantic check cycle
 */
private void collectExtensionAttributes(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);
        }
    }
    if (attributes.isEmpty()) {
        return;
    }
    attrExtendsReferences = new ComponentTypeReferenceList();
    for (int i = 0, size = attributes.size(); i < size; i++) {
        final ExtensionAttribute tempAttribute = attributes.get(i);
        if (ExtensionAttribute_type.EXTENDS.equals(tempAttribute.getAttributeType())) {
            final ExtensionsAttribute extensionsAttribute = (ExtensionsAttribute) tempAttribute;
            for (int j = 0, size2 = extensionsAttribute.getNofTypes(); j < size2; j++) {
                final IType tempType = extensionsAttribute.getType(j);
                if (Type_type.TYPE_REFERENCED.equals(tempType.getTypetype())) {
                    attrExtendsReferences.addReference(((Referenced_Type) tempType).getReference());
                }
            }
        }
    }
    attrExtendsReferences.setFullNameParent(new BridgingNamedNode(this, ".<extends attribute>"));
    attrExtendsReferences.setMyScope(parentScope);
}
Also used : ArrayList(java.util.ArrayList) SingleWithAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute) BridgingNamedNode(org.eclipse.titan.designer.AST.BridgingNamedNode) ExtensionAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.ExtensionAttribute) IType(org.eclipse.titan.designer.AST.IType) AttributeSpecification(org.eclipse.titan.designer.AST.TTCN3.attributes.AttributeSpecification) ExtensionsAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.ExtensionsAttribute) 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