]> source.dussan.org Git - aspectj.git/commitdiff
175806: allow for crumby bytecode incoming
authoraclement <aclement>
Wed, 28 Feb 2007 13:10:32 +0000 (13:10 +0000)
committeraclement <aclement>
Wed, 28 Feb 2007 13:10:32 +0000 (13:10 +0000)
bcel-builder/src/org/aspectj/apache/bcel/classfile/LineNumber.java
bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionList.java
bcel-builder/src/org/aspectj/apache/bcel/generic/MethodGen.java

index 06486bc1fddfaf01712ce8ecaf7970be14323eaa..54c9fe3300ff38830fc1f0d2e9eb421721b53354 100644 (file)
@@ -64,7 +64,7 @@ import java.io.Serializable;
  * the source that corresponds to a relative address in the byte code. This
  * is used for debugging purposes.
  *
- * @version $Id: LineNumber.java,v 1.3 2004/11/19 16:45:18 aclement Exp $
+ * @version $Id: LineNumber.java,v 1.4 2007/02/28 13:10:32 aclement Exp $
  * @author  <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
  * @see     LineNumberTable
  */
@@ -150,7 +150,7 @@ public final class LineNumber implements Cloneable, Node, Serializable {
    * @return String representation
    */ 
   public final String toString() {
-    return "LineNumber(" + start_pc + ", " + line_number + ")";
+    return "LineNumber(pc=" + start_pc + ", line=" + line_number + ")";
   }    
 
   /**
index cf0fb321a4d92a781ef79942001191e48d0cc79e..cbf6adf90d266ac8d43431d4c3ef4177161a0970 100644 (file)
@@ -75,7 +75,7 @@ import java.util.ArrayList;
  * A list is finally dumped to a byte code array with <a
  * href="#getByteCode()">getByteCode</a>.
  *
- * @version $Id: InstructionList.java,v 1.4 2006/05/12 08:17:43 aclement Exp $
+ * @version $Id: InstructionList.java,v 1.5 2007/02/28 13:10:32 aclement Exp $
  * @author  <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
  * @see     Instruction
  * @see     InstructionHandle
@@ -122,6 +122,9 @@ public class InstructionList implements Serializable {
    */
   public boolean isEmpty() { return start == null; } // && end == null
 
+  public static InstructionHandle findHandle(InstructionHandle[] ihs,int[] pos,int count,int target) {
+         return findHandle(ihs,pos,count,target,false);
+  }
   /**
    * Find the target instruction (handle) that corresponds to the given target
    * position (byte code offset).
@@ -133,7 +136,7 @@ public class InstructionList implements Serializable {
    * @return target position's instruction handle if available
    */
   public static InstructionHandle findHandle(InstructionHandle[] ihs,
-                                            int[] pos, int count,int target) {
+                                            int[] pos, int count,int target,boolean returnClosestIfNoExactMatch) {
     int l=0, r = count - 1;
     
     // Do a binary search since the pos array is ordered
@@ -146,6 +149,10 @@ public class InstructionList implements Serializable {
       else                  l=i+1; // target > j
     } while(l <= r);
 
+    if (returnClosestIfNoExactMatch) {
+       i = (l+r)/2; if (i<0) i=0;
+       return ihs[i];
+    }
     return null;
   }
 
@@ -165,10 +172,14 @@ public class InstructionList implements Serializable {
   public InstructionHandle[] getInstructionsAsArray() {
          return getInstructionHandles();
   }
-  
+
   public InstructionHandle findHandle(int pos,InstructionHandle[] instructionArray) {
          return findHandle(instructionArray,byte_positions,length,pos);
   }
+  
+  public InstructionHandle findHandle(int pos,InstructionHandle[] instructionArray,boolean useClosestApproximationIfNoExactFound) {
+         return findHandle(instructionArray,byte_positions,length,pos,useClosestApproximationIfNoExactFound);
+  }
 
   /**
    * Initialize instruction list from byte array.
index e414b94e7335a8b52aa1adc7dd45dbfa2475c4de..d88f5091a6cc525555b9fc3ff4afd149992d579a 100644 (file)
@@ -86,7 +86,7 @@ import org.aspectj.apache.bcel.generic.annotation.AnnotationGen;
  * use the `removeNOPs' method to get rid off them.
  * The resulting method object can be obtained via the `getMethod()' method.
  *
- * @version $Id: MethodGen.java,v 1.7 2006/02/21 10:49:15 aclement Exp $
+ * @version $Id: MethodGen.java,v 1.8 2007/02/28 13:10:32 aclement Exp $
  * @author  <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
  * @author  <A HREF="http://www.vmeng.com/beard">Patrick C. Beard</A> [setMaxStack()]
  * @see     InstructionList
@@ -275,17 +275,16 @@ public class MethodGen extends FieldGenOrMethodGen {
                                                        int lnum = l.getLineNumber();
                                                        if (lnum>highestLineNumber) highestLineNumber=lnum;
                                                        LineNumberTag lt = new LineNumberTag(lnum);
-                                                       il.findHandle(l.getStartPC(),arrayOfInstructions).addTargeter(lt);
+                                                       il.findHandle(l.getStartPC(),arrayOfInstructions,true).addTargeter(lt);
                                                }
                                        } else {
                                                for (int k = 0; k < ln.length; k++) {
                                                        LineNumber l = ln[k];
-                                                       addLineNumber(il.findHandle(l.getStartPC(),arrayOfInstructions),
+                                                       addLineNumber(il.findHandle(l.getStartPC(),arrayOfInstructions,true),
                                                                        l.getLineNumber());
                                                }
                                        }
                                } else if (a instanceof LocalVariableTable) {
-                                       
                                        // Lets have a go at creating Tags directly
                                        if (useTags) {
                                                LocalVariable[] lv = ((LocalVariableTable) a).getLocalVariableTable();
@@ -294,7 +293,7 @@ public class MethodGen extends FieldGenOrMethodGen {
                                                        LocalVariable l = lv[k];
                                                        Type t = Type.getType(l.getSignature());
                                                        LocalVariableTag lvt = new LocalVariableTag(t,l.getSignature(),l.getName(),l.getIndex(),l.getStartPC());
-                                                       InstructionHandle start = il.findHandle(l.getStartPC(), arrayOfInstructions);
+                                                       InstructionHandle start = il.findHandle(l.getStartPC(), arrayOfInstructions,true);
                                                        byte b = t.getType();
                                                        if (b!= Constants.T_ADDRESS) {
                                                                int increment = t.getSize();