/**
     * @see parser.IDLParserVisitor#visit(ASTcasex, Object)
     */
    public Object visit(ASTcasex node, Object data) {
        if (!(data is UnionBuildInfo)) {
            throw new InternalCompilerException("invalid parameter in visit ASTswitch_body");
        }
        UnionBuildInfo buildInfo = (UnionBuildInfo)data;
        // REFACTORING possiblity: replace direct use of values by using the Literals
        // case node consists of one or more case-labels followed by an element spec
        // collect the data for this switch-case
        object[] discriminatorValues = CollectDiscriminatorValuesForCase(node, 
                                                                         buildInfo.GetGenerationHelper().DiscriminatorType, 
                                                                         buildInfo);
        
        ASTelement_spec elemSpec = (ASTelement_spec)node.jjtGetChild(node.jjtGetNumChildren() - 1);
        ASTtype_spec typeSpecNode = (ASTtype_spec)elemSpec.jjtGetChild(0);
        TypeContainer elemType = (TypeContainer)typeSpecNode.jjtAccept(this, buildInfo);
        if (elemType == null) {
            throw new InvalidIdlException(
                String.Format("union elem type not defined for {0}",
                              node.GetIdentification()));
        }
        elemType = ReplaceByCustomMappedIfNeeded(elemType);
        Node elemDecl = elemSpec.jjtGetChild(1);
        string elemDeclIdent = 
                DetermineTypeAndNameForDeclarator((ASTdeclarator)elemDecl, data,
                                                  ref elemType);
        // generate the methods/field for this switch-case
        buildInfo.GetGenerationHelper().GenerateSwitchCase(elemType, elemDeclIdent, discriminatorValues);

        return null;
    }
Exemplo n.º 2
0
/* Production 75, chapter 3.4, corba 2.3.1 (renamed case -> casex, because case is a keyword in java) */
  public void casex() {
 /*@bgen(jjtree) casex */
  ASTcasex jjtn000 = new ASTcasex(this, IDLParserTreeConstants.JJTCASEX);
  bool jjtc000 = true;
  jjtree.openNodeScope(jjtn000);
    try {
      while (true) {
        case_label();
        switch ((jj_ntk==-1)?jj_ntk_calc():jj_ntk) {
        case 64:
        case 65:
          ;
          break;
        default:
          jj_la1[65] = jj_gen;
          goto label_20;
          break;
        }
      }
      label_20: ;
      
      element_spec();
      jj_consume_token(12);
    } catch (Exception jjte000) {
    if (jjtc000) {
      jjtree.clearNodeScope(jjtn000);
      jjtc000 = false;
    } else {
      jjtree.popNode();
    }
  {if (true) throw ;}
    } finally {
    if (jjtc000) {
      jjtree.closeNodeScope(jjtn000, true);
    }
    }
  }
 /// <summary>helper methods to collect discriminator values for casex node; checks if const-type is ok</summary>
 private object[] CollectDiscriminatorValuesForCase(ASTcasex node, TypeContainer discrType,
                                                    BuildInfo unionInfo) {
     object[] result = new object[node.jjtGetNumChildren() - 1];
     for (int i = 0; i < node.jjtGetNumChildren() - 1; i++) {
         if (!((ASTcase_label)node.jjtGetChild(i)).isDefault()) {
             Literal litVal = ((Literal)node.jjtGetChild(i).jjtAccept(this, unionInfo));
             if (litVal == null) {
                 throw new InvalidIdlException(
                     String.Format("invalid {0}, discrimitator value for case not retrievable",
                                   node.GetIdentification()));
             }                
             // check if val ok ...
             CheckDiscrValAssignableToDiscrType(litVal, discrType);
             result[i] = litVal.GetValue();
         } else {
             // default case
             result[i] = UnionGenerationHelper.DefaultCaseDiscriminator;
         }
     }
     return result;
 }