Search in sources :

Example 16 with WithAttributesPath

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

the class Def_Const method check.

@Override
public /**
 * {@inheritDoc}
 */
void check(final CompilationTimeStamp timestamp, final IReferenceChain refChain) {
    if (lastTimeChecked != null && !lastTimeChecked.isLess(timestamp)) {
        return;
    }
    lastTimeChecked = timestamp;
    isUsed = false;
    if (getMyScope() instanceof ComponentTypeBody) {
        NamingConventionHelper.checkConvention(PreferenceConstants.REPORTNAMINGCONVENTION_COMPONENT_CONSTANT, identifier, this);
    } else if (isLocal()) {
        NamingConventionHelper.checkConvention(PreferenceConstants.REPORTNAMINGCONVENTION_LOCAL_CONSTANT, identifier, this);
    } else {
        NamingConventionHelper.checkConvention(PreferenceConstants.REPORTNAMINGCONVENTION_GLOBAL_CONSTANT, identifier, this);
    }
    NamingConventionHelper.checkNameContents(identifier, getMyScope().getModuleScope().getIdentifier(), getDescription());
    if (type == null) {
        return;
    }
    T3Doc.check(this.getCommentLocation(), KIND, this.type.getTypetype());
    type.setGenName("_T_", getGenName());
    type.check(timestamp);
    if (withAttributesPath != null) {
        withAttributesPath.checkGlobalAttributes(timestamp, true);
        withAttributesPath.checkAttributes(timestamp, type.getTypeRefdLast(timestamp).getTypetype());
    }
    if (value == null) {
        return;
    }
    value.setMyGovernor(type);
    final IValue temporalValue = type.checkThisValueRef(timestamp, value);
    final IType lastType = type.getTypeRefdLast(timestamp);
    switch(lastType.getTypetype()) {
        case TYPE_PORT:
            location.reportSemanticError(MessageFormat.format(PORTNOTALLOWED, lastType.getFullName()));
            break;
        case TYPE_SIGNATURE:
            location.reportSemanticError(MessageFormat.format(SIGNATURENOTALLOWED, lastType.getFullName()));
            break;
        default:
            break;
    }
    type.checkThisValue(timestamp, temporalValue, null, new ValueCheckingOptions(Expected_Value_type.EXPECTED_CONSTANT, true, false, true, hasImplicitOmitAttribute(timestamp), false));
    checkErroneousAttributes(timestamp);
    final IReferenceChain chain = ReferenceChain.getInstance(IReferenceChain.CIRCULARREFERENCE, true);
    chain.add(this);
    temporalValue.checkRecursions(timestamp, chain);
    chain.release();
    // value.setGenNamePrefix("const_");//currently does not need the prefix
    value.setGenNameRecursive(getGenName());
    value.setCodeSection(CodeSectionType.CS_PRE_INIT);
}
Also used : ComponentTypeBody(org.eclipse.titan.designer.AST.TTCN3.types.ComponentTypeBody) IValue(org.eclipse.titan.designer.AST.IValue) IReferenceChain(org.eclipse.titan.designer.AST.IReferenceChain) ValueCheckingOptions(org.eclipse.titan.designer.AST.IType.ValueCheckingOptions) IType(org.eclipse.titan.designer.AST.IType)

Example 17 with WithAttributesPath

use of org.eclipse.titan.designer.AST.TTCN3.attributes.WithAttributesPath 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;
    }
}
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) Attribute_Modifier_type(org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute.Attribute_Modifier_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 18 with WithAttributesPath

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

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

use of org.eclipse.titan.designer.AST.TTCN3.attributes.WithAttributesPath 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)11 ArrayList (java.util.ArrayList)8 IType (org.eclipse.titan.designer.AST.IType)8 Qualifiers (org.eclipse.titan.designer.AST.TTCN3.attributes.Qualifiers)7 AttributeSpecification (org.eclipse.titan.designer.AST.TTCN3.attributes.AttributeSpecification)5 ExtensionAttribute (org.eclipse.titan.designer.AST.TTCN3.attributes.ExtensionAttribute)5 ExtensionAttributeAnalyzer (org.eclipse.titan.designer.parsers.extensionattributeparser.ExtensionAttributeAnalyzer)5 MultipleWithAttributes (org.eclipse.titan.designer.AST.TTCN3.attributes.MultipleWithAttributes)4 Qualifier (org.eclipse.titan.designer.AST.TTCN3.attributes.Qualifier)4 WithAttributesPath (org.eclipse.titan.designer.AST.TTCN3.attributes.WithAttributesPath)4 TTCN3Module (org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module)4 IReferenceChain (org.eclipse.titan.designer.AST.IReferenceChain)3 IValue (org.eclipse.titan.designer.AST.IValue)3 ITTCN3Template (org.eclipse.titan.designer.AST.TTCN3.templates.ITTCN3Template)3 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)2 ISubReference (org.eclipse.titan.designer.AST.ISubReference)2 ValueCheckingOptions (org.eclipse.titan.designer.AST.IType.ValueCheckingOptions)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