Beispiel #1
0
        /// <summary>
        /// See <see cref="System.Attribute.Equals"/>.
        /// </summary>
        public override bool Equals(object obj)
        {
            IdlSequenceAttribute other = obj as IdlSequenceAttribute;

            if (other == null)
            {
                return(false);
            }
            return(m_bound == other.m_bound && m_orderNr == other.m_orderNr);
        }
    /**
     * @see parser.IDLParserVisitor#visit(ASTsequence_type, Object)
     * @param data the buildinfo in use for the current scope
     * @return the type container for the IDLSequence type
     */
    public Object visit(ASTsequence_type node, Object data) {
        CheckParameterForBuildInfo(data, node);        
        BuildInfo containerInfo = (BuildInfo) data;
        SimpleNode elemTypeNode = (SimpleNode)node.jjtGetChild(0);
        if (containerInfo.GetContainterType() != null) {
            // inform the type-manager of structs/unions in creation, because
            // recursion using seuqneces is the only allowed recursion for structs/unions
            m_typeManager.PublishTypeForSequenceRecursion(containerInfo.GetContainerSymbol(),
                                                          containerInfo.GetContainterType());
        }
        Debug.WriteLine("determine element type of IDLSequence");
        TypeContainer elemType = (TypeContainer)elemTypeNode.jjtAccept(this, data);
        // disallow further recursive use of union/struct (before next seq recursion)
        m_typeManager.UnpublishTypeForSequenceRecursion();
        if (elemType == null) {
            throw new InvalidIdlException(
                String.Format("sequence element type not defined for {0}",
                              node.GetIdentification()));
        }
        elemType = ReplaceByCustomMappedIfNeeded(elemType);
        // use here the fusioned type as element type; potential unboxing of element type 
        // should be done by users of TypeContainer (if needed)!
        Debug.WriteLine("seq type determined: " + elemType.GetCompactClsType());
        // create CLS array type with the help of GetType(), otherwise not possible
        Type arrayType;
        // because not fully defined types are possible, use module and not assembly to get type from
        Module declModule = elemType.GetCompactClsType().Module;
        arrayType = declModule.GetType(elemType.GetCompactClsType().FullName + "[]"); // not nice, better solution ?        
        Debug.WriteLine("created array type: " + arrayType);
        
        // determin if sequence is bounded or unbounded
        long bound = 0;
        if (node.jjtGetNumChildren() > 1) { 
            // bounded sequnece
            bound = (long) node.jjtGetChild(1).jjtAccept(this, data);
        }

        // determine the needed attributes: IdlSequence is required by the sequence itself; 
        // combine with the attribute from the element type
        // possible are: IdlSequence (for sequence of sequence), ObjectIdlType,
        // WideChar, StringValue
        // invariant: boxed value attribute is not among them, because elem type 
        // is in the compact form        
        AttributeExtCollection elemAttributes = elemType.GetCompactTypeAttrInstances();
        long seqAttrOrderNr = IdlSequenceAttribute.DetermineSequenceAttributeOrderNr(elemAttributes);
        IdlSequenceAttribute seqAttr = new IdlSequenceAttribute(seqAttrOrderNr, bound);
        AttributeExtCollection sequenceAttributes = 
            new AttributeExtCollection(elemAttributes);
        sequenceAttributes = sequenceAttributes.MergeAttribute(seqAttr);
        TypeContainer result = new TypeContainer(arrayType,
                                                 sequenceAttributes );
        return result;
    }