Search in sources :

Example 1 with VariantAttributeAnalyzer

use of org.eclipse.titan.designer.parsers.variantattributeparser.VariantAttributeAnalyzer 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)

Aggregations

ArrayList (java.util.ArrayList)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 ASN1_Set_Seq_Choice_BaseType (org.eclipse.titan.designer.AST.ASN1.types.ASN1_Set_Seq_Choice_BaseType)1 Open_Type (org.eclipse.titan.designer.AST.ASN1.types.Open_Type)1 RawAST (org.eclipse.titan.designer.AST.TTCN3.attributes.RawAST)1 Anytype_Type (org.eclipse.titan.designer.AST.TTCN3.types.Anytype_Type)1 Referenced_Type (org.eclipse.titan.designer.AST.TTCN3.types.Referenced_Type)1 TTCN3_Set_Seq_Choice_BaseType (org.eclipse.titan.designer.AST.TTCN3.types.TTCN3_Set_Seq_Choice_BaseType)1 VariantAttributeAnalyzer (org.eclipse.titan.designer.parsers.variantattributeparser.VariantAttributeAnalyzer)1