示例#1
0
/* Production 78, chapter 3.4, corba 2.3.1 */
  public void enum_type() {
 /*@bgen(jjtree) enum_type */
  ASTenum_type jjtn000 = new ASTenum_type(this, IDLParserTreeConstants.JJTENUM_TYPE);
  bool jjtc000 = true;
  jjtree.openNodeScope(jjtn000);String ident = "";
    try {
      jj_consume_token(66);
      ident = identifier();
      jj_consume_token(14);
      enumerator();
      while (true) {
        switch ((jj_ntk==-1)?jj_ntk_calc():jj_ntk) {
        case 20:
          ;
          break;
        default:
          jj_la1[67] = jj_gen;
          goto label_21;
          break;
        }
        jj_consume_token(20);
        enumerator();
      }
      label_21: ;
      
      jj_consume_token(15);
    jjtree.closeNodeScope(jjtn000, true);
    jjtc000 = false;
    jjtn000.setIdent(ident);
    Scope currentScope = m_symbolTable.getCurrentScope();
    currentScope.addSymbol(ident);
    } 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(ASTenum_type, Object)
     * @param data the current buildinfo instance
     */
    public Object visit(ASTenum_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
        TypeContainer resultTypeContainer = null;
        if (m_typeManager.CheckSkip(forSymbol)) {
            resultTypeContainer = m_typeManager.GetKnownType(forSymbol);            
        } else {                
            TypeAttributes typeAttrs = TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.Sealed;        
            TypeBuilder enumToCreate = 
                m_typeManager.StartTypeDefinition(forSymbol, typeAttrs,
                                                  typeof(System.Enum), Type.EmptyTypes, false);                                                                                     
        
        	// add value__ field, see DefineEnum method of ModuleBuilder
            enumToCreate.DefineField("value__", typeof(System.Int32), 
                                     FieldAttributes.Public | FieldAttributes.SpecialName | FieldAttributes.RTSpecialName);
        
        	// add enum entries
            for (int i = 0; i < node.jjtGetNumChildren(); i++) {
                String enumeratorId = ((SimpleNodeWithIdent)node.jjtGetChild(i)).getIdent();
                FieldBuilder enumVal = enumToCreate.DefineField(enumeratorId, enumToCreate, 
                	                                            FieldAttributes.Public | FieldAttributes.Static | FieldAttributes.Literal);
                enumVal.SetConstant((System.Int32) i);
            }

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

        // update the symbol values: (do this also, if type is from another assembly)
        for (int i = 0; i < node.jjtGetNumChildren(); i++) {
            String enumeratorId = ((SimpleNodeWithIdent)node.jjtGetChild(i)).getIdent();
            // update symbol with value
            SymbolValue symbol = (SymbolValue)buildInfo.GetBuildScope().getSymbol(enumeratorId);
            object enumVal = Enum.ToObject(resultTypeContainer.GetCompactClsType(), (System.Int32) i);
            symbol.SetValueAsLiteral(new EnumValLiteral(enumVal));
        }

        return resultTypeContainer;
    }