Search in sources :

Example 1 with MultipleWithAttributes

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

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

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

the class Def_Type method setWithAttributes.

@Override
public /**
 * {@inheritDoc}
 */
void setWithAttributes(final MultipleWithAttributes attributes) {
    if (type == null) {
        return;
    }
    if (withAttributesPath == null) {
        withAttributesPath = new WithAttributesPath();
        type.setAttributeParentPath(withAttributesPath);
    }
    type.setWithAttributes(attributes);
}
Also used : WithAttributesPath(org.eclipse.titan.designer.AST.TTCN3.attributes.WithAttributesPath)

Example 4 with MultipleWithAttributes

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

the class Definition method checkErroneousAttributes.

protected void checkErroneousAttributes(final CompilationTimeStamp timestamp) {
    erroneousAttributes = null;
    if (withAttributesPath != null) {
        final MultipleWithAttributes attribs = withAttributesPath.getAttributes();
        if (attribs == null) {
            return;
        }
        for (int i = 0; i < attribs.getNofElements(); i++) {
            final SingleWithAttribute actualAttribute = attribs.getAttribute(i);
            if (actualAttribute.getAttributeType() == Attribute_Type.Erroneous_Attribute) {
                final int nofQualifiers = (actualAttribute.getQualifiers() == null) ? 0 : actualAttribute.getQualifiers().getNofQualifiers();
                final List<IType> referencedTypeArray = new ArrayList<IType>(nofQualifiers);
                final List<ArrayList<Integer>> subrefsArrayArray = new ArrayList<ArrayList<Integer>>(nofQualifiers);
                final List<ArrayList<IType>> typeArrayArray = new ArrayList<ArrayList<IType>>(nofQualifiers);
                if (nofQualifiers == 0) {
                    actualAttribute.getLocation().reportSemanticError("At least one qualifier must be specified for the `erroneous' attribute");
                } else {
                    // existing fields
                    for (int qi = 0; qi < nofQualifiers; qi++) {
                        final Qualifier actualQualifier = actualAttribute.getQualifiers().getQualifierByIndex(qi);
                        final IType definitionType = getType(timestamp);
                        // construct a reference
                        final Reference reference = new Reference(null);
                        reference.addSubReference(new FieldSubReference(identifier));
                        for (int ri = 0; ri < actualQualifier.getNofSubReferences(); ri++) {
                            reference.addSubReference(actualQualifier.getSubReferenceByIndex(ri));
                        }
                        reference.setLocation(actualQualifier.getLocation());
                        reference.setMyScope(getMyScope());
                        IType fieldType = definitionType.getFieldType(timestamp, reference, 1, Expected_Value_type.EXPECTED_CONSTANT, false);
                        ArrayList<Integer> subrefsArray = null;
                        ArrayList<IType> typeArray = null;
                        if (fieldType != null) {
                            subrefsArray = new ArrayList<Integer>();
                            typeArray = new ArrayList<IType>();
                            final boolean validIndexes = definitionType.getSubrefsAsArray(timestamp, reference, 1, subrefsArray, typeArray);
                            if (!validIndexes) {
                                fieldType = null;
                                subrefsArray = null;
                                typeArray = null;
                            }
                            if (reference.refersToStringElement()) {
                                actualQualifier.getLocation().reportSemanticError("Reference to a string element cannot be used in this context");
                                fieldType = null;
                                subrefsArray = null;
                                typeArray = null;
                            }
                        }
                        referencedTypeArray.add(fieldType);
                        subrefsArrayArray.add(subrefsArray);
                        typeArrayArray.add(typeArray);
                    }
                }
                // parse the attr. spec.
                final ErroneousAttributeSpecification errAttributeSpecification = parseErrAttrSpecString(actualAttribute.getAttributeSpecification());
                if (errAttributeSpecification != null) {
                    if (erroneousAttributes == null) {
                        erroneousAttributes = new ErroneousAttributes(getType(timestamp));
                    }
                    erroneousAttributes.addSpecification(errAttributeSpecification);
                    errAttributeSpecification.check(timestamp, getMyScope());
                    // err.attr.spec. pairs
                    for (int qi = 0; qi < nofQualifiers; qi++) {
                        if (referencedTypeArray.get(qi) != null && errAttributeSpecification.getIndicator() != Indicator_Type.Invalid_Indicator) {
                            final Qualifier actualQualifier = actualAttribute.getQualifiers().getQualifierByIndex(qi);
                            erroneousAttributes.addFieldErr(actualQualifier, errAttributeSpecification, subrefsArrayArray.get(qi), typeArrayArray.get(qi));
                        }
                    }
                }
            }
        }
        if (erroneousAttributes != null) {
            erroneousAttributes.check(timestamp);
        }
    }
}
Also used : ErroneousAttributeSpecification(org.eclipse.titan.designer.AST.TTCN3.attributes.ErroneousAttributeSpecification) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) FieldSubReference(org.eclipse.titan.designer.AST.FieldSubReference) Reference(org.eclipse.titan.designer.AST.Reference) ArrayList(java.util.ArrayList) ErroneousAttributes(org.eclipse.titan.designer.AST.TTCN3.attributes.ErroneousAttributes) SingleWithAttribute(org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute) MultipleWithAttributes(org.eclipse.titan.designer.AST.TTCN3.attributes.MultipleWithAttributes) IType(org.eclipse.titan.designer.AST.IType) Qualifier(org.eclipse.titan.designer.AST.TTCN3.attributes.Qualifier)

Example 5 with MultipleWithAttributes

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

MultipleWithAttributes (org.eclipse.titan.designer.AST.TTCN3.attributes.MultipleWithAttributes)4 SingleWithAttribute (org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute)4 ArrayList (java.util.ArrayList)3 Qualifier (org.eclipse.titan.designer.AST.TTCN3.attributes.Qualifier)3 WithAttributesPath (org.eclipse.titan.designer.AST.TTCN3.attributes.WithAttributesPath)3 Qualifiers (org.eclipse.titan.designer.AST.TTCN3.attributes.Qualifiers)2 Def_Type (org.eclipse.titan.designer.AST.TTCN3.definitions.Def_Type)2 Group (org.eclipse.titan.designer.AST.TTCN3.definitions.Group)2 TTCN3Module (org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module)2 FieldSubReference (org.eclipse.titan.designer.AST.FieldSubReference)1 IType (org.eclipse.titan.designer.AST.IType)1 Reference (org.eclipse.titan.designer.AST.Reference)1 ErroneousAttributeSpecification (org.eclipse.titan.designer.AST.TTCN3.attributes.ErroneousAttributeSpecification)1 ErroneousAttributes (org.eclipse.titan.designer.AST.TTCN3.attributes.ErroneousAttributes)1 Attribute_Modifier_type (org.eclipse.titan.designer.AST.TTCN3.attributes.SingleWithAttribute.Attribute_Modifier_type)1