From: aclement Date: Wed, 28 Feb 2007 13:10:32 +0000 (+0000) Subject: 175806: allow for crumby bytecode incoming X-Git-Tag: V1_5_4rc1~79 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e83cf86b07ea7cf7de0b4f16f8d928c3c94e8e99;p=aspectj.git 175806: allow for crumby bytecode incoming --- diff --git a/bcel-builder/src/org/aspectj/apache/bcel/classfile/LineNumber.java b/bcel-builder/src/org/aspectj/apache/bcel/classfile/LineNumber.java index 06486bc1f..54c9fe330 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/classfile/LineNumber.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/classfile/LineNumber.java @@ -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 M. Dahm * @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 + ")"; } /** diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionList.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionList.java index cf0fb321a..cbf6adf90 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionList.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/InstructionList.java @@ -75,7 +75,7 @@ import java.util.ArrayList; * A list is finally dumped to a byte code array with getByteCode. * - * @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 M. Dahm * @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. diff --git a/bcel-builder/src/org/aspectj/apache/bcel/generic/MethodGen.java b/bcel-builder/src/org/aspectj/apache/bcel/generic/MethodGen.java index e414b94e7..d88f5091a 100644 --- a/bcel-builder/src/org/aspectj/apache/bcel/generic/MethodGen.java +++ b/bcel-builder/src/org/aspectj/apache/bcel/generic/MethodGen.java @@ -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 M. Dahm * @author Patrick C. Beard [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();