mdahm       2002/11/27 23:36:53

  Modified:    src/java/org/apache/bcel/util BCELFactory.java
                        BCELifier.java
  Log:
  Bug fixes
  
  Revision  Changes    Path
  1.3       +34 -26    jakarta-bcel/src/java/org/apache/bcel/util/BCELFactory.java
  
  Index: BCELFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-bcel/src/java/org/apache/bcel/util/BCELFactory.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- BCELFactory.java  29 Jun 2002 15:14:43 -0000      1.2
  +++ BCELFactory.java  28 Nov 2002 07:36:53 -0000      1.3
  @@ -82,30 +82,32 @@
     private HashMap branch_map = new HashMap(); // Map<Instruction, InstructionHandle>
   
     public void start() {
  -    for(InstructionHandle ih = _mg.getInstructionList().getStart();
  -     ih != null; ih = ih.getNext()) {
  -      Instruction i = ih.getInstruction();
  +    if(!_mg.isAbstract() && !_mg.isNative()) {
  +      for(InstructionHandle ih = _mg.getInstructionList().getStart();
  +       ih != null; ih = ih.getNext()) {
  +     Instruction i = ih.getInstruction();
   
  -      if(i instanceof BranchInstruction) {
  -     branch_map.put(i, ih); // memorize container
  -      }
  -
  -      if(ih.hasTargeters()) {
        if(i instanceof BranchInstruction) {
  -       _out.println("    InstructionHandle ih_" + ih.getPosition() + ";");
  +       branch_map.put(i, ih); // memorize container
  +     }
  +
  +     if(ih.hasTargeters()) {
  +       if(i instanceof BranchInstruction) {
  +         _out.println("    InstructionHandle ih_" + ih.getPosition() + ";");
  +       } else {
  +         _out.print("    InstructionHandle ih_" + ih.getPosition() + " = ");
  +       }
        } else {
  -       _out.print("    InstructionHandle ih_" + ih.getPosition() + " = ");
  +       _out.print("    ");
        }
  -      } else {
  -     _out.print("    ");
  +
  +     if(!visitInstruction(i))
  +       i.accept(this);
         }
   
  -      if(!visitInstruction(i))
  -     i.accept(this);
  +      updateBranchTargets();
  +      updateExceptionHandlers();
       }
  -
  -    updateBranchTargets();
  -    updateExceptionHandlers();
     }
   
     private boolean visitInstruction(Instruction i) {
  @@ -127,8 +129,8 @@
       Type   type   = i.getType(_cp);
   
       if(opcode == Constants.IINC) {
  -    _out.println("il.append(new IINC(" + i.getIndex() + ", " +
  -              ((IINC)i).getIncrement() + "));");
  +      _out.println("il.append(new IINC(" + i.getIndex() + ", " +
  +                ((IINC)i).getIncrement() + "));");
       } else {
         String kind   = (opcode < Constants.ISTORE)? "Load" : "Store";
         _out.println("il.append(_factory.create" + kind + "(" +
  @@ -176,10 +178,16 @@
     }
   
     public void visitAllocationInstruction(AllocationInstruction i) {
  -    CPInstruction in     = (CPInstruction)i;
  -    Type          type   = in.getType(_cp);
  -    short         opcode = in.getOpcode();
  -    int           dim    = 1;
  +    Type type;
  +
  +    if(i instanceof CPInstruction) {
  +      type = ((CPInstruction)i).getType(_cp);
  +    } else {
  +      type = ((NEWARRAY)i).getType();
  +    }
  +
  +    short opcode = ((Instruction)i).getOpcode();
  +    int   dim    = 1;
   
       switch(opcode) {
       case Constants.NEW:
  @@ -192,8 +200,8 @@
   
       case Constants.ANEWARRAY:
       case Constants.NEWARRAY:
  -      _out.println("il.append(_factory.createNewArray(\"" +
  -                BCELifier.printType(type) + ", " + dim + "));");
  +      _out.println("il.append(_factory.createNewArray(" +
  +                BCELifier.printType(type) + ", (short) " + dim + "));");
         break;
   
       default:
  
  
  
  1.3       +5 -1      jakarta-bcel/src/java/org/apache/bcel/util/BCELifier.java
  
  Index: BCELifier.java
  ===================================================================
  RCS file: /home/cvs/jakarta-bcel/src/java/org/apache/bcel/util/BCELifier.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- BCELifier.java    4 Jun 2002 11:16:21 -0000       1.2
  +++ BCELifier.java    28 Nov 2002 07:36:53 -0000      1.3
  @@ -96,6 +96,10 @@
       String package_name = clazz.getPackageName();
       String inter        = Utility.printArray(clazz.getInterfaceNames(),
                                             false, true);
  +    if(!"".equals(package_name)) {
  +      class_name = class_name.substring(package_name.length() + 1);
  +      _out.println("package " + package_name + ";\n");
  +     }
   
       _out.println("import org.apache.bcel.generic.*;");
       _out.println("import org.apache.bcel.classfile.*;");
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to