Ejemplo n.º 1
0
    /**
     * @see parser.IDLParserVisitor#visit(ASTstruct_type, Object)
      * @param data expected is an instance of BuildInfo
     * if ((BuildInfo)data).getContainerType() is null, than an independant type-decl is created, else
     * the type delcaration is added to the Type in creation
     * @return the TypeContainer for the constructed type
     */
    public Object visit(ASTstruct_type node, Object data) {
        CheckParameterForBuildInfo(data, node);
        BuildInfo buildInfo = (BuildInfo) data;
        Symbol forSymbol = buildInfo.GetBuildScope().getSymbol(node.getIdent());
        // check if type is known from a previous run over a parse tree --> if so: skip
        // not needed to check if struct is a nested types, because parent type should already be skipped 
        // --> code generation for all nested types skipped too
        if (m_typeManager.CheckSkip(forSymbol)) { 
            return m_typeManager.GetKnownType(forSymbol);
        }
        
        // layout-sequential causes problem, if member of array type is not fully defined (TypeLoadException) -> use autolayout instead
        TypeAttributes typeAttrs = TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.Serializable | TypeAttributes.BeforeFieldInit | 
                                   /* TypeAttributes.SequentialLayout | */ TypeAttributes.Sealed;
        
        TypeBuilder structToCreate = m_typeManager.StartTypeDefinition(forSymbol,
                                                                       typeAttrs,
                                                                       typeof(System.ValueType), new System.Type[] { typeof(IIdlEntity) }, false);
        BuildInfo thisTypeInfo = new BuildInfo(buildInfo.GetBuildScope().getChildScope(forSymbol.getSymbolName()), 
                                               structToCreate,
                                               forSymbol);

        // add fileds and a constructor, which assigns the fields
        IList members = (IList)node.jjtGetChild(0).jjtAccept(this, thisTypeInfo); // accept the member list
        AddStructConstructor(structToCreate, members);        
        AddExplicitSerializationOrder(structToCreate, members);

        // add type specific attributes
        structToCreate.SetCustomAttribute(new IdlStructAttribute().CreateAttributeBuilder());
        m_ilEmitHelper.AddSerializableAttribute(structToCreate);
        
        // create the type
        Type resultType = m_typeManager.EndTypeDefinition(forSymbol);
        return new TypeContainer(resultType);
    }