Search in sources :

Example 1 with Attribute_Modifier_type

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

Aggregations

ArrayList (java.util.ArrayList)1 MultipleWithAttributes (org.eclipse.titan.designer.AST.TTCN3.attributes.MultipleWithAttributes)1 Qualifier (org.eclipse.titan.designer.AST.TTCN3.attributes.Qualifier)1 Qualifiers (org.eclipse.titan.designer.AST.TTCN3.attributes.Qualifiers)1 SingleWithAttribute (org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute)1 Attribute_Modifier_type (org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute.Attribute_Modifier_type)1 WithAttributesPath (org.eclipse.titan.designer.AST.TTCN3.attributes.WithAttributesPath)1 Def_Type (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type)1 Group (org.eclipse.titan.designer.AST.TTCN3.definitions.Group)1 TTCN3Module (org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module)1