示例#1
0
/* Production 69, chapter 3.4, corba 2.3.1 */
  public void struct_type() {
 /*@bgen(jjtree) struct_type */
  ASTstruct_type jjtn000 = new ASTstruct_type(this, IDLParserTreeConstants.JJTSTRUCT_TYPE);
  bool jjtc000 = true;
  jjtree.openNodeScope(jjtn000);String ident = "";
    try {
      jj_consume_token(61);
      ident = identifier();
    // recursive definition using a sequence is permitted --> publish symbol already here
    Scope currentScope = m_symbolTable.getCurrentScope();
    currentScope.addSymbol(ident);
    jjtn000.setIdent(ident);
    m_symbolTable.openScope(ident, true); // open a scope for type declaration inside the struct

      jj_consume_token(14);
      member_list();
      jj_consume_token(15);
                          jjtree.closeNodeScope(jjtn000, true);
                          jjtc000 = false;
    m_symbolTable.closeScope();
    } catch (Exception jjte000) {
    if (jjtc000) {
      jjtree.clearNodeScope(jjtn000);
      jjtc000 = false;
    } else {
      jjtree.popNode();
    }
  {if (true) throw ;}
    } finally {
    if (jjtc000) {
      jjtree.closeNodeScope(jjtn000, true);
    }
    }
  }
    /**
     * @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);
    }