]> source.dussan.org Git - aspectj.git/commitdiff
fixed static calls (semantics preserving and non-crosscutting)
authorehilsdal <ehilsdal>
Fri, 14 Nov 2003 02:30:04 +0000 (02:30 +0000)
committerehilsdal <ehilsdal>
Fri, 14 Nov 2003 02:30:04 +0000 (02:30 +0000)
13 files changed:
weaver/src/org/aspectj/weaver/bcel/BcelCflowStackFieldAdder.java
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java
weaver/src/org/aspectj/weaver/bcel/BcelRenderer.java
weaver/src/org/aspectj/weaver/bcel/BcelShadow.java
weaver/src/org/aspectj/weaver/bcel/BcelTypeMunger.java
weaver/src/org/aspectj/weaver/bcel/BcelVar.java
weaver/src/org/aspectj/weaver/bcel/LazyClassGen.java
weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java
weaver/src/org/aspectj/weaver/bcel/ShadowRange.java
weaver/src/org/aspectj/weaver/bcel/UnwovenClassFile.java
weaver/src/org/aspectj/weaver/bcel/Utility.java
weaver/src/org/aspectj/weaver/patterns/PatternParser.java
weaver/testsrc/org/aspectj/weaver/bcel/MoveInstructionsWeaveTestCase.java

index 79acffa180e6ec1d86fee4151ea949dbe55add3b..bd0f31f0c0f8e06f0dd27a11c63480f4ac9c9b1a 100644 (file)
@@ -47,7 +47,7 @@ public class BcelCflowStackFieldAdder extends BcelTypeMunger {
                InstructionFactory fact = gen.getFactory();
 
                setup.append(fact.createNew(new ObjectType(NameMangler.CFLOW_STACK_TYPE)));
-               setup.append(fact.createDup(1));
+               setup.append(InstructionFactory.createDup(1));
                setup.append(fact.createInvoke(
                        NameMangler.CFLOW_STACK_TYPE, 
                        "<init>", 
index b9ab8bb6a212d1e88ebb5bfcad0d07455afdeca9..51308b4bb5ec61d431d775c226e87348ea83a42c 100644 (file)
@@ -32,6 +32,7 @@ import org.apache.bcel.generic.FieldInstruction;
 import org.apache.bcel.generic.INVOKESPECIAL;
 import org.apache.bcel.generic.IndexedInstruction;
 import org.apache.bcel.generic.Instruction;
+import org.apache.bcel.generic.InstructionConstants;
 import org.apache.bcel.generic.InstructionFactory;
 import org.apache.bcel.generic.InstructionHandle;
 import org.apache.bcel.generic.InstructionList;
@@ -425,7 +426,7 @@ class BcelClassWeaver implements IClassWeaver {
                boolean keepReturns) 
        {
                InstructionList footer = new InstructionList();
-               InstructionHandle end = footer.append(fact.NOP);
+               InstructionHandle end = footer.append(InstructionConstants.NOP);
 
                InstructionList ret = new InstructionList();
                InstructionList sourceList = donor.getBody();
@@ -449,7 +450,10 @@ class BcelClassWeaver implements IClassWeaver {
                                // a computation leak... we're testing this LOTS of times.  Sigh.
                                if (isAcrossClass) {
                                        CPInstruction cpi = (CPInstruction) fresh;
-                                       cpi.setIndex(recipientCpg.addConstant(donorCpg.getConstant(cpi.getIndex()), donorCpg));
+                                       cpi.setIndex(
+                                               recipientCpg.addConstant(
+                                                       donorCpg.getConstant(cpi.getIndex()),
+                                                       donorCpg));
                                }
                        }
                        if (src.getInstruction() == Range.RANGEINSTRUCTION) {
@@ -458,7 +462,8 @@ class BcelClassWeaver implements IClassWeaver {
                                if (keepReturns) {
                                        dest = ret.append(fresh);
                                } else {
-                                       dest = ret.append(fact.createBranchInstruction(Constants.GOTO, end));
+                                       dest = 
+                                               ret.append(InstructionFactory.createBranchInstruction(Constants.GOTO, end));
                                }
                        } else if (fresh instanceof BranchInstruction) {
                                dest = ret.append((BranchInstruction) fresh);
@@ -590,7 +595,7 @@ class BcelClassWeaver implements IClassWeaver {
                // writing ret back to front because we're popping. 
                if (! donor.isStatic()) {
                        int targetSlot = recipient.allocateLocal(Type.OBJECT);
-                       ret.insert(fact.createStore(Type.OBJECT, targetSlot));
+                       ret.insert(InstructionFactory.createStore(Type.OBJECT, targetSlot));
                        frameEnv.put(donorFramePos, targetSlot);
                        donorFramePos += 1;
                }
@@ -598,7 +603,7 @@ class BcelClassWeaver implements IClassWeaver {
                for (int i = 0, len = argTypes.length; i < len; i++) {
                        Type argType = argTypes[i];
                        int argSlot = recipient.allocateLocal(argType);
-                       ret.insert(fact.createStore(argType, argSlot));
+                       ret.insert(InstructionFactory.createStore(argType, argSlot));
                        frameEnv.put(donorFramePos, argSlot);
                        donorFramePos += argType.getSize();
                }
@@ -648,14 +653,19 @@ class BcelClassWeaver implements IClassWeaver {
                InstructionFactory fact = clazz.getFactory();
 
                setup.append(fact.createNew(aspectType));
-               setup.append(fact.createDup(1));
+               setup.append(InstructionFactory.createDup(1));
                setup.append(fact.createInvoke(
                        aspectName, 
                        "<init>", 
                        Type.VOID, 
                        new Type[0], 
                        Constants.INVOKESPECIAL));
-               setup.append(fact.createFieldAccess(aspectName, field.getName(), aspectType, Constants.PUTSTATIC));
+               setup.append(
+                       fact.createFieldAccess(
+                               aspectName,
+                               field.getName(),
+                               aspectType,
+                               Constants.PUTSTATIC));
                clinit.getBody().insert(setup);
     }
 
@@ -728,7 +738,9 @@ class BcelClassWeaver implements IClassWeaver {
                                                        curr,
                                                        ifaceInitSig);
                                        if (match(cexecShadow, shadowAccumulator)) {
-                                               cexecShadow.getRange().getBody().append(cexecShadow.getRange().getStart(), fact.NOP);
+                                               cexecShadow.getRange().getBody().append(
+                                                       cexecShadow.getRange().getStart(),
+                                                       InstructionConstants.NOP);
                                        }
                                        // generate the init jp around it
                                        BcelShadow initShadow =
@@ -776,7 +788,12 @@ class BcelClassWeaver implements IClassWeaver {
                                if (effective == null) {
                                        enclosingShadow = BcelShadow.makeMethodExecution(world, mg);
                                } else if (effective.isWeaveBody()) {
-                                       enclosingShadow = BcelShadow.makeShadowForMethod(world, mg, effective.getShadowKind(), effective.getEffectiveSignature());
+                                       enclosingShadow =
+                                               BcelShadow.makeShadowForMethod(
+                                                       world,
+                                                       mg,
+                                                       effective.getShadowKind(),
+                                                       effective.getEffectiveSignature());
                                } else {
                                        return false;
                                }
@@ -816,7 +833,7 @@ class BcelClassWeaver implements IClassWeaver {
                        ConcreteTypeMunger cmunger = (ConcreteTypeMunger) i.next();
                        NewFieldTypeMunger munger = (NewFieldTypeMunger) cmunger.getMunger();
                        ResolvedMember initMethod = munger.getInitMethod(cmunger.getAspectType());
-                       if (!isStatic) ret.append(fact.ALOAD_0);
+                       if (!isStatic) ret.append(InstructionConstants.ALOAD_0);
                        ret.append(Utility.createInvoke(fact, world, initMethod));
                }
                return ret;
@@ -841,7 +858,7 @@ class BcelClassWeaver implements IClassWeaver {
                                InstructionHandle prevHandle = ih.getPrev();
                                Instruction prevI = prevHandle.getInstruction();
                                if (Utility.isConstantPushInstruction(prevI)) {
-                                       Member field = world.makeFieldSignature(clazz, (FieldInstruction) i);
+                                       Member field = BcelWorld.makeFieldSignature(clazz, (FieldInstruction) i);
                                        ResolvedMember resolvedField = field.resolve(world);
                                        if (resolvedField == null) {
                                                // we can't find the field, so it's not a join point.
@@ -899,16 +916,20 @@ class BcelClassWeaver implements IClassWeaver {
        }
 
 
-       private void matchSetInstruction(LazyMethodGen mg, InstructionHandle ih, BcelShadow enclosingShadow, List shadowAccumulator) {
+       private void matchSetInstruction(
+               LazyMethodGen mg,
+               InstructionHandle ih,
+               BcelShadow enclosingShadow,
+               List shadowAccumulator) {
                FieldInstruction fi = (FieldInstruction) ih.getInstruction();
-               Member field = world.makeFieldSignature(clazz, fi);
+               Member field = BcelWorld.makeFieldSignature(clazz, fi);
                ResolvedMember resolvedField = field.resolve(world);
                if (resolvedField == null) {
                        // we can't find the field, so it's not a join point.
                        return;
-               } else if (Modifier.isFinal(resolvedField.getModifiers()) && 
-                                       Utility.isConstantPushInstruction(ih.getPrev().getInstruction()))
-               {
+               } else if (
+                       Modifier.isFinal(resolvedField.getModifiers())
+                               && Utility.isConstantPushInstruction(ih.getPrev().getInstruction())) {
                        // it's the set of a final constant, so it's
                        // not a join point according to 1.0.6 and 1.1.
                        return;
@@ -916,13 +937,15 @@ class BcelClassWeaver implements IClassWeaver {
                        // sets of synthetics aren't join points in 1.1
                        return;
                } else {
-                       match(BcelShadow.makeFieldSet(world, mg, ih, enclosingShadow), shadowAccumulator);
+                       match(
+                               BcelShadow.makeFieldSet(world, mg, ih, enclosingShadow),
+                               shadowAccumulator);
                }
        }
 
        private void matchGetInstruction(LazyMethodGen mg, InstructionHandle ih, BcelShadow enclosingShadow, List shadowAccumulator) {
                FieldInstruction fi = (FieldInstruction) ih.getInstruction();
-               Member field = world.makeFieldSignature(clazz, fi);
+               Member field = BcelWorld.makeFieldSignature(clazz, fi);
                ResolvedMember resolvedField = field.resolve(world);
                if (resolvedField == null) {
                        // we can't find the field, so it's not a join point.
@@ -944,7 +967,7 @@ class BcelClassWeaver implements IClassWeaver {
                String methodName = invoke.getName(cpg);
                if (methodName.startsWith(NameMangler.PREFIX)) {
                        Member method =
-                               world.makeMethodSignature(clazz, invoke);
+                               BcelWorld.makeMethodSignature(clazz, invoke);
                        ResolvedMember declaredSig = method.resolve(world);
                        //System.err.println(method + ", declaredSig: "  +declaredSig);
                        if (declaredSig == null) return;
@@ -961,7 +984,8 @@ class BcelClassWeaver implements IClassWeaver {
                                                kind, declaredSig),
                                        shadowAccumulator);
                        } else {
-                               AjAttribute.EffectiveSignatureAttribute effectiveSig = declaredSig.getEffectiveSignature();
+                               AjAttribute.EffectiveSignatureAttribute effectiveSig =
+                                       declaredSig.getEffectiveSignature();
                                if (effectiveSig == null) return;
                                //System.err.println("call to inter-type member: " + effectiveSig);
                                if (effectiveSig.isWeaveBody()) return;
index 6642b1fc873c85292733185689ec46b1648ad7b4..f4da0a62a142b9de9cb7c3e8f00866d9eedb1589 100644 (file)
@@ -72,7 +72,7 @@ public class BcelRenderer implements ITestVisitor, IExprVisitor {
         BcelRenderer renderer = new BcelRenderer(fact, world);
         e.accept(renderer);
         InstructionList il = renderer.instructions;
-        il.append(Utility.createConversion(fact, world.makeBcelType(e.getType()), desiredType));
+        il.append(Utility.createConversion(fact, BcelWorld.makeBcelType(e.getType()), desiredType));
         return il;
     }
 
@@ -167,7 +167,7 @@ public class BcelRenderer implements ITestVisitor, IExprVisitor {
     public void visit(Instanceof i) {
         instructions.insert(createJumpBasedOnBooleanOnStack());
         instructions.insert(
-            Utility.createInstanceof(fact, (ReferenceType) world.makeBcelType(i.getType())));
+            Utility.createInstanceof(fact, (ReferenceType) BcelWorld.makeBcelType(i.getType())));
         i.getVar().accept(this);
     }
 
@@ -176,18 +176,18 @@ public class BcelRenderer implements ITestVisitor, IExprVisitor {
         if (sk == fk) {
             // don't bother generating if it doesn't matter
             if (sk != next) {
-                il.insert(fact.createBranchInstruction(Constants.GOTO, sk));
+                il.insert(InstructionFactory.createBranchInstruction(Constants.GOTO, sk));
             }
             return il;
         }
 
         if (fk == next) {
-            il.insert(fact.createBranchInstruction(Constants.IFNE, sk));
+            il.insert(InstructionFactory.createBranchInstruction(Constants.IFNE, sk));
         } else if (sk == next) {
-            il.insert(fact.createBranchInstruction(Constants.IFEQ, fk));
+            il.insert(InstructionFactory.createBranchInstruction(Constants.IFEQ, fk));
         } else {
-            il.insert(fact.createBranchInstruction(Constants.GOTO, sk));
-            il.insert(fact.createBranchInstruction(Constants.IFEQ, fk));
+            il.insert(InstructionFactory.createBranchInstruction(Constants.GOTO, sk));
+            il.insert(InstructionFactory.createBranchInstruction(Constants.IFEQ, fk));
         }
         return il;             
        }
index 3112984d83c656091d86a22bc158dcdea69adf14..9bc3b3fa362a4245fcffa2bf9afbd332950a3108 100644 (file)
@@ -30,6 +30,7 @@ import org.apache.bcel.generic.FieldInstruction;
 import org.apache.bcel.generic.INVOKESPECIAL;
 import org.apache.bcel.generic.INVOKESTATIC;
 import org.apache.bcel.generic.Instruction;
+import org.apache.bcel.generic.InstructionConstants;
 import org.apache.bcel.generic.InstructionFactory;
 import org.apache.bcel.generic.InstructionHandle;
 import org.apache.bcel.generic.InstructionList;
@@ -198,7 +199,7 @@ public class BcelShadow extends Shadow {
                        retargetFrom(newHandle, nextHandle);
                        // add a POP here... we found a NEW w/o a dup or anything else, so
                        // we must be in statement context.
-                       getRange().insert(getFactory().POP, Range.OutsideAfter);
+                       getRange().insert(InstructionConstants.POP, Range.OutsideAfter);
                }
                // assert (dupHandle.getInstruction() instanceof DUP);
 
@@ -235,7 +236,7 @@ public class BcelShadow extends Shadow {
                        ShadowRange range = getRange();
                        InstructionList body = range.getBody();
                        InstructionHandle start = range.getStart();
-                       InstructionHandle freshIh = body.insert(start, getFactory().NOP);
+                       InstructionHandle freshIh = body.insert(start, InstructionConstants.NOP);
                        InstructionTargeter[] targeters = start.getTargeters();
                        for (int i = 0; i < targeters.length; i++) {
                                InstructionTargeter t = targeters[i];
@@ -276,7 +277,7 @@ public class BcelShadow extends Shadow {
                                        Range.InsideBefore);
                        }
                        if (getKind() == ConstructorCall) {
-                               range.insert((Instruction) fact.createDup(1), Range.InsideBefore);
+                               range.insert((Instruction) InstructionFactory.createDup(1), Range.InsideBefore);
                                range.insert(
                                        fact.createNew(
                                                (ObjectType) BcelWorld.makeBcelType(
@@ -353,9 +354,11 @@ public class BcelShadow extends Shadow {
         InstructionHandle clinitStart = body.getStart();
         if (clinitStart.getInstruction() instanceof InvokeInstruction) {
                InvokeInstruction ii = (InvokeInstruction)clinitStart.getInstruction();
-               if (ii.getName(enclosingMethod.getEnclosingClass().getConstantPoolGen()).equals(NameMangler.AJC_PRE_CLINIT_NAME)) {
-                       clinitStart = clinitStart.getNext();
-               }
+                       if (ii
+                               .getName(enclosingMethod.getEnclosingClass().getConstantPoolGen())
+                               .equals(NameMangler.AJC_PRE_CLINIT_NAME)) {
+                               clinitStart = clinitStart.getNext();
+                       }
         }
         
         InstructionHandle clinitEnd = body.getEnd();
@@ -568,9 +571,9 @@ public class BcelShadow extends Shadow {
     {
         final InstructionList body = enclosingMethod.getBody();
         
-        Member sig = world.makeMethodSignature(
-                    enclosingMethod.getEnclosingClass(),
-                    (InvokeInstruction) callHandle.getInstruction());
+        Member sig = BcelWorld.makeMethodSignature(
+                       enclosingMethod.getEnclosingClass(),
+                       (InvokeInstruction) callHandle.getInstruction());
                     
                BcelShadow s = 
                        new BcelShadow(
@@ -599,7 +602,7 @@ public class BcelShadow extends Shadow {
             new BcelShadow(
                 world,
                 MethodCall,
-                world.makeMethodSignature(
+                BcelWorld.makeMethodSignature(
                     enclosingMethod.getEnclosingClass(),
                     (InvokeInstruction) callHandle.getInstruction()),
                 enclosingMethod,
@@ -651,7 +654,7 @@ public class BcelShadow extends Shadow {
             new BcelShadow(
                 world,
                 FieldGet,
-                world.makeFieldSignature(
+                BcelWorld.makeFieldSignature(
                     enclosingMethod.getEnclosingClass(),
                     (FieldInstruction) getHandle.getInstruction()),
                 enclosingMethod,
@@ -676,7 +679,7 @@ public class BcelShadow extends Shadow {
             new BcelShadow(
                 world,
                 FieldSet,
-                world.makeFieldSignature(
+                BcelWorld.makeFieldSignature(
                     enclosingMethod.getEnclosingClass(),
                     (FieldInstruction) setHandle.getInstruction()),
                 enclosingMethod,
@@ -704,10 +707,10 @@ public class BcelShadow extends Shadow {
 
     // ---- type access methods
     private ObjectType getTargetBcelType() {
-        return (ObjectType) world.makeBcelType(getTargetType());
+        return (ObjectType) BcelWorld.makeBcelType(getTargetType());
     }
     private Type getArgBcelType(int arg) {
-        return world.makeBcelType(getArgType(arg));
+        return BcelWorld.makeBcelType(getArgType(arg));
     }
 
     // ---- kinding
@@ -960,7 +963,7 @@ public class BcelShadow extends Shadow {
             retList = new InstructionList(ret);
             afterAdvice = retList.getStart();
         } else /* if (munger.hasDynamicTests()) */ {
-            retList = new InstructionList(fact.NOP);            
+            retList = new InstructionList(InstructionConstants.NOP);            
             afterAdvice = retList.getStart();
 //        } else {
 //             retList = new InstructionList();
@@ -973,11 +976,11 @@ public class BcelShadow extends Shadow {
             TypeX tempVarType = getReturnType();
             if (tempVarType.equals(ResolvedTypeX.VOID)) {
                tempVar = genTempVar(TypeX.OBJECT);
-               advice.append(getFactory().ACONST_NULL);
+               advice.append(InstructionConstants.ACONST_NULL);
                tempVar.appendStore(advice, getFactory());
             } else {
                    tempVar = genTempVar(tempVarType);
-                   advice.append(getFactory().createDup(tempVarType.getSize()));
+                   advice.append(InstructionFactory.createDup(tempVarType.getSize()));
                    tempVar.appendStore(advice, getFactory());
             }
         }
@@ -985,10 +988,15 @@ public class BcelShadow extends Shadow {
 
         if (ret != null) {
             InstructionHandle gotoTarget = advice.getStart();           
-            for (Iterator i = returns.iterator(); i.hasNext(); ) {
-                InstructionHandle ih = (InstructionHandle) i.next();
-                Utility.replaceInstruction(ih, fact.createBranchInstruction(Constants.GOTO, gotoTarget), enclosingMethod);
-            }
+                       for (Iterator i = returns.iterator(); i.hasNext();) {
+                               InstructionHandle ih = (InstructionHandle) i.next();
+                               Utility.replaceInstruction(
+                                       ih,
+                                       InstructionFactory.createBranchInstruction(
+                                               Constants.GOTO,
+                                               gotoTarget),
+                                       enclosingMethod);
+                       }
             range.append(advice);
             range.append(retList);
         } else {
@@ -1012,12 +1020,12 @@ public class BcelShadow extends Shadow {
             exceptionVar.createLoad(fact));
         handler.append(munger.getAdviceInstructions(this, exceptionVar, endHandler.getStart()));
         handler.append(endHandler);
-        handler.append(fact.ATHROW);        
+        handler.append(InstructionConstants.ATHROW);        
         InstructionHandle handlerStart = handler.getStart();
                                     
         if (isFallsThrough()) {
-            InstructionHandle jumpTarget = handler.append(fact.NOP);
-            handler.insert(fact.createBranchInstruction(Constants.GOTO, jumpTarget));
+            InstructionHandle jumpTarget = handler.append(InstructionConstants.NOP);
+            handler.insert(InstructionFactory.createBranchInstruction(Constants.GOTO, jumpTarget));
         }
                InstructionHandle protectedEnd = handler.getStart();
         range.insert(handler, Range.InsideAfter);       
@@ -1042,16 +1050,16 @@ public class BcelShadow extends Shadow {
         exceptionVar.appendStore(handler, fact);
 
                handler.append(fact.createNew(NameMangler.SOFT_EXCEPTION_TYPE));
-               handler.append(fact.createDup(1));   
+               handler.append(InstructionFactory.createDup(1));   
         handler.append(exceptionVar.createLoad(fact));
         handler.append(fact.createInvoke(NameMangler.SOFT_EXCEPTION_TYPE, "<init>", 
                                                Type.VOID, new Type[] { Type.THROWABLE }, Constants.INVOKESPECIAL));  //??? special
-        handler.append(fact.ATHROW);        
+        handler.append(InstructionConstants.ATHROW);        
         InstructionHandle handlerStart = handler.getStart();
                                     
         if (isFallsThrough()) {
             InstructionHandle jumpTarget = range.getEnd();//handler.append(fact.NOP);
-            handler.insert(fact.createBranchInstruction(Constants.GOTO, jumpTarget));
+            handler.insert(InstructionFactory.createBranchInstruction(Constants.GOTO, jumpTarget));
         }
                InstructionHandle protectedEnd = handler.getStart();
         range.insert(handler, Range.InsideAfter);       
@@ -1122,12 +1130,17 @@ public class BcelShadow extends Shadow {
        
                        int alen = cflowStateVars.length;
                        entrySuccessInstructions.append(Utility.createConstant(fact, alen));
-                       entrySuccessInstructions.append((Instruction)fact.createNewArray(Type.OBJECT, (short)1));
+                               entrySuccessInstructions.append(
+                                       (Instruction) fact.createNewArray(Type.OBJECT, (short) 1));
                        arrayVar.appendStore(entrySuccessInstructions, fact);
                 
-                       for (int i = 0; i < alen; i++) {
-                           arrayVar.appendConvertableArrayStore(entrySuccessInstructions, fact, i, cflowStateVars[i]);
-                       }                       
+                               for (int i = 0; i < alen; i++) {
+                                       arrayVar.appendConvertableArrayStore(
+                                               entrySuccessInstructions,
+                                               fact,
+                                               i,
+                                               cflowStateVars[i]);
+                               }               
        
                        entrySuccessInstructions.append(
                                Utility.createGet(fact, cflowStackField));
@@ -1151,18 +1164,31 @@ public class BcelShadow extends Shadow {
                
                // this is the same for both per and non-per
                weaveAfter(new BcelAdvice(null, null, null, 0, 0, 0, null, null) {
-                       public InstructionList getAdviceInstructions(BcelShadow s, BcelVar extraArgVar, InstructionHandle ifNoAdvice) {
-                       InstructionList exitInstructions = new InstructionList(); 
-                       if (munger.hasDynamicTests()) {
-                                testResult.appendLoad(exitInstructions, fact);
-                        exitInstructions.append(fact.createBranchInstruction(Constants.IFEQ, ifNoAdvice));
-                       }
-                       exitInstructions.append(
-                               Utility.createGet(fact, cflowStackField));
-                       exitInstructions.append(
-                               fact.createInvoke(NameMangler.CFLOW_STACK_TYPE, "pop", Type.VOID, new Type[] {}, Constants.INVOKEVIRTUAL));
+                       public InstructionList getAdviceInstructions(
+                               BcelShadow s,
+                               BcelVar extraArgVar,
+                               InstructionHandle ifNoAdvice) {
+                               InstructionList exitInstructions = new InstructionList();
+                               if (munger.hasDynamicTests()) {
+                                       testResult.appendLoad(exitInstructions, fact);
+                                       exitInstructions.append(
+                                               InstructionFactory.createBranchInstruction(
+                                                       Constants.IFEQ,
+                                                       ifNoAdvice));
+                               }
+                               exitInstructions.append(Utility.createGet(fact, cflowStackField));
+                               exitInstructions
+                                       .append(
+                                               fact
+                                               .createInvoke(
+                                                       NameMangler.CFLOW_STACK_TYPE,
+                                                       "pop",
+                                                       Type.VOID,
+                                                       new Type[] {
+                               }, Constants.INVOKEVIRTUAL));
                                return exitInstructions;
-                       }});
+                       }
+               });
 
 
                range.insert(entryInstructions, Range.InsideBefore);
@@ -1269,14 +1295,27 @@ public class BcelShadow extends Shadow {
         
         Type[] adviceParameterTypes = adviceMethod.getArgumentTypes();
         Type[] extractedMethodParameterTypes = extractedMethod.getArgumentTypes();
-               Type[] parameterTypes = new Type[extractedMethodParameterTypes.length + adviceParameterTypes.length + 1];
+               Type[] parameterTypes =
+                       new Type[extractedMethodParameterTypes.length
+                               + adviceParameterTypes.length
+                               + 1];
                int parameterIndex = 0;
-               System.arraycopy(extractedMethodParameterTypes, 0, parameterTypes, parameterIndex, extractedMethodParameterTypes.length);
+               System.arraycopy(
+                       extractedMethodParameterTypes,
+                       0,
+                       parameterTypes,
+                       parameterIndex,
+                       extractedMethodParameterTypes.length);
                parameterIndex += extractedMethodParameterTypes.length;
 
-        parameterTypes[parameterIndex++] =
-               BcelWorld.makeBcelType(adviceMethod.getEnclosingClass().getType());
-               System.arraycopy(adviceParameterTypes, 0, parameterTypes, parameterIndex, adviceParameterTypes.length);
+               parameterTypes[parameterIndex++] =
+                       BcelWorld.makeBcelType(adviceMethod.getEnclosingClass().getType());
+               System.arraycopy(
+                       adviceParameterTypes,
+                       0,
+                       parameterTypes,
+                       parameterIndex,
+                       adviceParameterTypes.length);
 
         LazyMethodGen localAdviceMethod =
                                        new LazyMethodGen(
@@ -1322,17 +1361,21 @@ public class BcelShadow extends Shadow {
                                var.appendLoad(advice, fact);
                        }               
                // ??? we don't actually need to push NULL for the closure if we take care
-                   advice.append(munger.getAdviceArgSetup(this, null, new InstructionList(fact.ACONST_NULL)));
+                       advice.append(
+                               munger.getAdviceArgSetup(
+                                       this,
+                                       null,
+                                       new InstructionList(InstructionConstants.ACONST_NULL)));
                    adviceMethodInvocation =
                        advice.append(
                                Utility.createInvoke(fact, localAdviceMethod)); //(fact, getWorld(), munger.getSignature()));
                        advice.append(
                        Utility.createConversion(
                            getFactory(), 
-                           world.makeBcelType(munger.getSignature().getReturnType()), 
+                           BcelWorld.makeBcelType(munger.getSignature().getReturnType()), 
                            extractedMethod.getReturnType()));
                    if (! isFallsThrough()) {
-                       advice.append(fact.createReturn(extractedMethod.getReturnType()));
+                       advice.append(InstructionFactory.createReturn(extractedMethod.getReturnType()));
                    }
         }
         
@@ -1341,15 +1384,24 @@ public class BcelShadow extends Shadow {
         if (! hasDynamicTest) {
             range.append(advice);
         } else {
-               InstructionList afterThingie = new InstructionList(fact.NOP);
+               InstructionList afterThingie = new InstructionList(InstructionConstants.NOP);
             InstructionList callback = makeCallToCallback(extractedMethod);
-            if (terminatesWithReturn()) {
-                callback.append(fact.createReturn(extractedMethod.getReturnType()));
-            } else {
-               //InstructionHandle endNop = range.insert(fact.NOP, Range.InsideAfter);
-                advice.append(fact.createBranchInstruction(Constants.GOTO, afterThingie.getStart()));
-            }
-            range.append(munger.getTestInstructions(this, advice.getStart(), callback.getStart(), advice.getStart()));
+                       if (terminatesWithReturn()) {
+                               callback.append(
+                                       InstructionFactory.createReturn(extractedMethod.getReturnType()));
+                       } else {
+                               //InstructionHandle endNop = range.insert(fact.NOP, Range.InsideAfter);
+                               advice.append(
+                                       InstructionFactory.createBranchInstruction(
+                                               Constants.GOTO,
+                                               afterThingie.getStart()));
+                       }
+                       range.append(
+                               munger.getTestInstructions(
+                                       this,
+                                       advice.getStart(),
+                                       callback.getStart(),
+                                       advice.getStart()));
             range.append(advice);
             range.append(callback);
             range.append(afterThingie);          
@@ -1369,10 +1421,16 @@ public class BcelShadow extends Shadow {
                        InstructionHandle next = curr.getNext();
                        Instruction inst = curr.getInstruction();
                        if ((inst instanceof INVOKESTATIC)
-                                       && proceedName.equals(((INVOKESTATIC) inst).getMethodName(cpg))) {
-
-                                       
-                               localAdviceMethod.getBody().append(curr, getRedoneProceedCall(fact, extractedMethod, munger, localAdviceMethod, proceedVarList));
+                               && proceedName.equals(((INVOKESTATIC) inst).getMethodName(cpg))) {
+
+                               localAdviceMethod.getBody().append(
+                                       curr,
+                                       getRedoneProceedCall(
+                                               fact,
+                                               extractedMethod,
+                                               munger,
+                                               localAdviceMethod,
+                                               proceedVarList));
                                Utility.deleteInstruction(curr, localAdviceMethod);
                        }
                        curr = next;
@@ -1397,7 +1455,8 @@ public class BcelShadow extends Shadow {
 //             System.out.println(proceedMap + " for " + this);
 //             System.out.println(argVarList);
                
-               ResolvedTypeX[] proceedParamTypes = world.resolve(munger.getSignature().getParameterTypes());
+               ResolvedTypeX[] proceedParamTypes =
+                       world.resolve(munger.getSignature().getParameterTypes());
                // remove this*JoinPoint* as arguments to proceed
                if (munger.getBaseParameterCount()+1 < proceedParamTypes.length) {
                        int len = munger.getBaseParameterCount()+1;
@@ -1491,7 +1550,7 @@ public class BcelShadow extends Shadow {
                        
                        Type[] stateTypes = getSuperConstructorParameterTypes();
                        
-                       returnConversionCode.append(fact.ALOAD_0); // put "this" back on the stack
+                       returnConversionCode.append(InstructionConstants.ALOAD_0); // put "this" back on the stack
                        for (int i = 0, len = stateTypes.length; i < len; i++) {
                                stateTempVar.appendConvertableArrayLoad(
                                        returnConversionCode, 
@@ -1503,11 +1562,12 @@ public class BcelShadow extends Shadow {
                returnConversionCode = 
                    Utility.createConversion(
                        getFactory(), 
-                       world.makeBcelType(munger.getSignature().getReturnType()), 
+                       BcelWorld.makeBcelType(munger.getSignature().getReturnType()), 
                        callbackMethod.getReturnType());
-               if (! isFallsThrough()) {
-                   returnConversionCode.append(fact.createReturn(callbackMethod.getReturnType()));
-               }
+                       if (!isFallsThrough()) {
+                               returnConversionCode.append(
+                                       InstructionFactory.createReturn(callbackMethod.getReturnType()));
+                       }
                }
         
         InstructionList advice = new InstructionList();
@@ -1516,21 +1576,30 @@ public class BcelShadow extends Shadow {
         advice.append(munger.getNonTestAdviceInstructions(this));
         advice.append(returnConversionCode);         
         
-        if (! hasDynamicTest) {
-            range.append(advice);
-        } else {
-            InstructionList callback = makeCallToCallback(callbackMethod);
-            InstructionList postCallback = new InstructionList();
-            if (terminatesWithReturn()) {
-                callback.append(fact.createReturn(callbackMethod.getReturnType()));
-            } else {
-                advice.append(fact.createBranchInstruction(Constants.GOTO, postCallback.append(fact.NOP)));
-            }
-            range.append(munger.getTestInstructions(this, advice.getStart(), callback.getStart(), advice.getStart()));
-            range.append(advice);
-            range.append(callback);   
-            range.append(postCallback);         
-        }
+               if (!hasDynamicTest) {
+                       range.append(advice);
+               } else {
+                       InstructionList callback = makeCallToCallback(callbackMethod);
+                       InstructionList postCallback = new InstructionList();
+                       if (terminatesWithReturn()) {
+                               callback.append(
+                                       InstructionFactory.createReturn(callbackMethod.getReturnType()));
+                       } else {
+                               advice.append(
+                                       InstructionFactory.createBranchInstruction(
+                                               Constants.GOTO,
+                                               postCallback.append(InstructionConstants.NOP)));
+                       }
+                       range.append(
+                               munger.getTestInstructions(
+                                       this,
+                                       advice.getStart(),
+                                       callback.getStart(),
+                                       advice.getStart()));
+                       range.append(advice);
+                       range.append(callback);
+                       range.append(postCallback);
+               }
     }
     
     // exposed for testing
@@ -1538,7 +1607,7 @@ public class BcelShadow extends Shadow {
        InstructionFactory fact = getFactory();
         InstructionList callback = new InstructionList();
         if (thisVar != null) {
-               callback.append(fact.ALOAD_0); 
+               callback.append(InstructionConstants.ALOAD_0); 
         }
         if (targetVar != null && targetVar != thisVar) {
             callback.append(BcelRenderer.renderExpr(fact, world, targetVar));
@@ -1593,7 +1662,7 @@ public class BcelShadow extends Shadow {
         arrayVar.appendLoad(il, fact);
         il.append(Utility.createInvoke(fact, world, constructor));
         if (getKind() == PreInitialization) {
-                       il.append(fact.DUP);
+                       il.append(InstructionConstants.DUP);
                        holder.appendStore(il, fact);
         }
         return il;
@@ -1649,11 +1718,11 @@ public class BcelShadow extends Shadow {
                                                       new String[] {}, 
                                                       closureClass);        
         InstructionList cbody = constructor.getBody();        
-               cbody.append(fact.createLoad(Type.OBJECT, 0));
-               cbody.append(fact.createLoad(objectArrayType, 1));
+               cbody.append(InstructionFactory.createLoad(Type.OBJECT, 0));
+               cbody.append(InstructionFactory.createLoad(objectArrayType, 1));
                cbody.append(fact.createInvoke(superClassName, "<init>", Type.VOID, 
                        new Type[] {objectArrayType}, Constants.INVOKESPECIAL));
-               cbody.append(fact.createReturn(Type.VOID));
+               cbody.append(InstructionFactory.createReturn(Type.VOID));
 
         closureClass.addMethodGen(constructor);
         
@@ -1667,9 +1736,10 @@ public class BcelShadow extends Shadow {
         InstructionList mbody = runMethod.getBody();
         BcelVar proceedVar = new BcelVar(TypeX.OBJECTARRAY.resolve(world), 1);
     //        int proceedVarIndex = 1;
-        BcelVar stateVar = new BcelVar(TypeX.OBJECTARRAY.resolve(world), runMethod.allocateLocal(1));
+               BcelVar stateVar =
+                       new BcelVar(TypeX.OBJECTARRAY.resolve(world), runMethod.allocateLocal(1));
     //        int stateVarIndex = runMethod.allocateLocal(1);
-               mbody.append(fact.createThis());
+               mbody.append(InstructionFactory.createThis());
                mbody.append(fact.createGetField(superClassName, "state", objectArrayType));
         mbody.append(stateVar.createStore(fact));
     //         mbody.append(fact.createStore(objectArrayType, stateVarIndex));
@@ -1697,7 +1767,7 @@ public class BcelShadow extends Shadow {
                        mbody.append(Utility.createSet(
                                fact, 
                                AjcMemberMaker.aroundClosurePreInitializationField()));
-                       mbody.append(fact.ACONST_NULL);
+                       mbody.append(InstructionConstants.ACONST_NULL);
                } else {
                        mbody.append(
                    Utility.createConversion(
@@ -1705,7 +1775,7 @@ public class BcelShadow extends Shadow {
                        callbackMethod.getReturnType(), 
                        Type.OBJECT));
                }
-               mbody.append(fact.createReturn(Type.OBJECT));
+               mbody.append(InstructionFactory.createReturn(Type.OBJECT));
 
                closureClass.addMethodGen(runMethod);
                                
@@ -1769,14 +1839,14 @@ public class BcelShadow extends Shadow {
                        // push object array
                        arrayVar.appendLoad(body, fact);
                        // swap
-                       body.append(fact.SWAP);
+                       body.append(InstructionConstants.SWAP);
                // do object array store.
                        body.append(Utility.createConstant(fact, i));
-                       body.append(fact.SWAP);
-                       body.append(fact.createArrayStore(Type.OBJECT));
+                       body.append(InstructionConstants.SWAP);
+                       body.append(InstructionFactory.createArrayStore(Type.OBJECT));
         }
         arrayVar.appendLoad(body, fact);
-        body.append(fact.ARETURN);
+        body.append(InstructionConstants.ARETURN);
        }
 
        private Type[] getSuperConstructorParameterTypes() {
@@ -1841,7 +1911,7 @@ public class BcelShadow extends Shadow {
      * ??? rewrite this to do less array munging, please
      */
     private LazyMethodGen createMethodGen(String newMethodName) {
-        Type[] parameterTypes = world.makeBcelTypes(getArgTypes()); 
+        Type[] parameterTypes = BcelWorld.makeBcelTypes(getArgTypes()); 
         int modifiers = Modifier.FINAL;
 
         // XXX some bug
@@ -1860,11 +1930,11 @@ public class BcelShadow extends Shadow {
                }
                targetType = getThisType();
             }
-            parameterTypes = addType(world.makeBcelType(targetType), parameterTypes);
+            parameterTypes = addType(BcelWorld.makeBcelType(targetType), parameterTypes);
         }
         if (thisVar != null) {
                TypeX thisType = getThisType();
-               parameterTypes = addType(world.makeBcelType(thisType), parameterTypes);
+               parameterTypes = addType(BcelWorld.makeBcelType(thisType), parameterTypes);
         }
         
         // We always want to pass down thisJoinPoint in case we have already woven
@@ -1883,7 +1953,7 @@ public class BcelShadow extends Shadow {
         return
             new LazyMethodGen(
                 modifiers, 
-                world.makeBcelType(returnType), 
+                BcelWorld.makeBcelType(returnType), 
                 newMethodName,
                 parameterTypes,
                 new String[0],
index 6f57e56bfc7217a5cf377e0988096f44722750bc..4b844428e4e5a8e3b5b648828776f46dbbb19a19 100644 (file)
@@ -19,6 +19,7 @@ import java.util.Set;
 
 import org.apache.bcel.Constants;
 import org.apache.bcel.generic.FieldGen;
+import org.apache.bcel.generic.InstructionConstants;
 import org.apache.bcel.generic.InstructionFactory;
 import org.apache.bcel.generic.InstructionList;
 import org.apache.bcel.generic.Type;
@@ -115,7 +116,8 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
                        } else if (member.getKind() == Member.CONSTRUCTOR) {
                                for (Iterator i = gen.getMethodGens().iterator(); i.hasNext(); ) {
                                        LazyMethodGen m = (LazyMethodGen)i.next();
-                                       if (m.getMemberView() != null && m.getMemberView().getKind() == Member.CONSTRUCTOR) {
+                                       if (m.getMemberView() != null
+                                               && m.getMemberView().getKind() == Member.CONSTRUCTOR) {
                                                // m.getMemberView().equals(member)) {
                                                m.forcePublic();
                                                //return true;
@@ -147,13 +149,13 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
                                field.getName(),
                                BcelWorld.makeBcelType(field.getType()), Constants.GETSTATIC));
                } else {
-                       il.append(fact.ALOAD_0);
+                       il.append(InstructionConstants.ALOAD_0);
                        il.append(fact.createFieldAccess(
                                gen.getClassName(), 
                                field.getName(),
                                BcelWorld.makeBcelType(field.getType()), Constants.GETFIELD));
                }
-               il.append(fact.createReturn(BcelWorld.makeBcelType(field.getType())));
+               il.append(InstructionFactory.createReturn(BcelWorld.makeBcelType(field.getType())));
                mg.getBody().insert(il);
                                
                gen.addMethodGen(mg);
@@ -170,20 +172,20 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
                Type fieldType = BcelWorld.makeBcelType(field.getType());
                
                if (field.isStatic()) {
-                       il.append(fact.createLoad(fieldType, 0));
+                       il.append(InstructionFactory.createLoad(fieldType, 0));
                        il.append(fact.createFieldAccess(
                                gen.getClassName(), 
                                field.getName(),
                                fieldType, Constants.PUTSTATIC));
                } else {
-                       il.append(fact.ALOAD_0);
-                       il.append(fact.createLoad(fieldType, 1));
+                       il.append(InstructionConstants.ALOAD_0);
+                       il.append(InstructionFactory.createLoad(fieldType, 1));
                        il.append(fact.createFieldAccess(
                                gen.getClassName(), 
                                field.getName(),
                                fieldType, Constants.PUTFIELD));
                }
-               il.append(fact.createReturn(Type.VOID));
+               il.append(InstructionFactory.createReturn(Type.VOID));
                mg.getBody().insert(il);
                                
                gen.addMethodGen(mg);
@@ -203,17 +205,17 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
                int pos = 0;
        
                if (!method.isStatic()) {
-                       il.append(fact.ALOAD_0);
+                       il.append(InstructionConstants.ALOAD_0);
                        pos++;
                }
                for (int i = 0, len = paramTypes.length; i < len; i++) {
                        Type paramType = paramTypes[i];
-                       il.append(fact.createLoad(paramType, pos));
+                       il.append(InstructionFactory.createLoad(paramType, pos));
                        pos+=paramType.getSize();
                }
                il.append(Utility.createInvoke(fact, (BcelWorld)aspectType.getWorld(), 
                                method));
-               il.append(fact.createReturn(BcelWorld.makeBcelType(method.getReturnType())));
+               il.append(InstructionFactory.createReturn(BcelWorld.makeBcelType(method.getReturnType())));
 
                mg.getBody().insert(il);
                                
@@ -268,12 +270,12 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
                                gen);
                        InstructionList il = new InstructionList();
                        InstructionFactory fact = gen.getFactory();
-                       il.append(fact.ALOAD_0);
+                       il.append(InstructionConstants.ALOAD_0);
                        il.append(fact.createFieldAccess(
                                gen.getClassName(), 
                                fg.getName(),
                                fieldType, Constants.GETFIELD));
-                       il.append(fact.createReturn(fieldType));
+                       il.append(InstructionFactory.createReturn(fieldType));
                        mg.getBody().insert(il);
                                
                        gen.addMethodGen(mg);
@@ -286,13 +288,13 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
                                new Type[]{fieldType,}, new String[0],
                                gen);
                        InstructionList il1 = new InstructionList();
-                       il1.append(fact.ALOAD_0);
-                       il1.append(fact.createLoad(fieldType, 1));
+                       il1.append(InstructionConstants.ALOAD_0);
+                       il1.append(InstructionFactory.createLoad(fieldType, 1));
                        il1.append(fact.createFieldAccess(
                                gen.getClassName(), 
                                fg.getName(), 
                                fieldType, Constants.PUTFIELD));
-                       il1.append(fact.createReturn(Type.VOID));
+                       il1.append(InstructionFactory.createReturn(Type.VOID));
                        mg1.getBody().insert(il1);
                                
                        gen.addMethodGen(mg1);
@@ -332,17 +334,19 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
                                int pos = 0;
        
                                if (!signature.isStatic()) {
-                                       body.append(fact.createThis());
+                                       body.append(InstructionFactory.createThis());
                                        pos++;
                                }
                                Type[] paramTypes = BcelWorld.makeBcelTypes(introMethod.getParameterTypes());
                                for (int i = 0, len = paramTypes.length; i < len; i++) {
                                        Type paramType = paramTypes[i];
-                                       body.append(fact.createLoad(paramType, pos));
+                                       body.append(InstructionFactory.createLoad(paramType, pos));
                                        pos+=paramType.getSize();
                                }
                                body.append(Utility.createInvoke(fact, weaver.getWorld(), dispatchMethod));
-                               body.append(fact.createReturn(BcelWorld.makeBcelType(introMethod.getReturnType())));
+                               body.append(
+                                       InstructionFactory.createReturn(
+                                               BcelWorld.makeBcelType(introMethod.getReturnType())));
                        } else {
                                //??? this is okay
                                //if (!(mg.getBody() == null)) throw new RuntimeException("bas");
@@ -373,16 +377,16 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
                        int pos = 0;
 
                        if (!introMethod.isStatic()) {
-                               body.append(fact.createThis());
+                               body.append(InstructionFactory.createThis());
                                pos++;
                        }
                        for (int i = 0, len = paramTypes.length; i < len; i++) {
                                Type paramType = paramTypes[i];
-                               body.append(fact.createLoad(paramType, pos));
+                               body.append(InstructionFactory.createLoad(paramType, pos));
                                pos+=paramType.getSize();
                        }
                        body.append(Utility.createInvoke(fact, weaver.getWorld(), dispatchMethod));
-                       body.append(fact.createReturn(returnType));
+                       body.append(InstructionFactory.createReturn(returnType));
                        mg.definingType = onType;
                        
                        weaver.addOrReplaceLazyMethodGen(mg);
@@ -402,16 +406,28 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
        {
                LazyClassGen gen = weaver.getLazyClassGen();
                
-               for (Iterator iter = neededSuperCalls.iterator(); iter.hasNext(); ) {
+               for (Iterator iter = neededSuperCalls.iterator(); iter.hasNext();) {
                        ResolvedMember superMethod = (ResolvedMember) iter.next();
                        if (weaver.addDispatchTarget(superMethod)) {
                                //System.err.println("super type: " + superMethod.getDeclaringType() + ", " + gen.getType());
                                boolean isSuper = !superMethod.getDeclaringType().equals(gen.getType());
                                String dispatchName;
-                               if (isSuper) dispatchName = NameMangler.superDispatchMethod(onType, superMethod.getName());
-                               else dispatchName = NameMangler.protectedDispatchMethod(onType, superMethod.getName());
-                               LazyMethodGen dispatcher = makeDispatcher(gen, dispatchName, superMethod, weaver.getWorld(), isSuper);
-               
+                               if (isSuper)
+                                       dispatchName =
+                                               NameMangler.superDispatchMethod(onType, superMethod.getName());
+                               else
+                                       dispatchName =
+                                               NameMangler.protectedDispatchMethod(
+                                                       onType,
+                                                       superMethod.getName());
+                               LazyMethodGen dispatcher =
+                                       makeDispatcher(
+                                               gen,
+                                               dispatchName,
+                                               superMethod,
+                                               weaver.getWorld(),
+                                               isSuper);
+
                                weaver.addLazyMethodGen(dispatcher);
                        }
                }
@@ -446,28 +462,33 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
                Type[] paramTypes = freshConstructor.getArgumentTypes();
                int frameIndex = 1;
                for (int i = 0, len = declaredParams.length; i < len; i++) {
-                       body.append(fact.createLoad(paramTypes[i], frameIndex));
+                       body.append(InstructionFactory.createLoad(paramTypes[i], frameIndex));
                        frameIndex += paramTypes[i].getSize();
                }
                // do call to pre
-               Member preMethod = AjcMemberMaker.preIntroducedConstructor(aspectType, onType, declaredParams);
+               Member preMethod =
+                       AjcMemberMaker.preIntroducedConstructor(aspectType, onType, declaredParams);
                body.append(Utility.createInvoke(fact, null, preMethod));
                
                // create a local, and store return pre stuff into it.
                int arraySlot = freshConstructor.allocateLocal(1);
-               body.append(fact.createStore(Type.OBJECT, arraySlot));
+               body.append(InstructionFactory.createStore(Type.OBJECT, arraySlot));
                
                // put this on the stack
-               body.append(fact.ALOAD_0);
+               body.append(InstructionConstants.ALOAD_0);
                
                // unpack pre args onto stack
                TypeX[] superParamTypes = explicitConstructor.getParameterTypes();
                
                for (int i = 0, len = superParamTypes.length; i < len; i++) {
-                       body.append(fact.createLoad(Type.OBJECT, arraySlot));
+                       body.append(InstructionFactory.createLoad(Type.OBJECT, arraySlot));
                        body.append(Utility.createConstant(fact, i));
-                       body.append(fact.createArrayLoad(Type.OBJECT));
-                       body.append(Utility.createConversion(fact, Type.OBJECT, BcelWorld.makeBcelType(superParamTypes[i])));
+                       body.append(InstructionFactory.createArrayLoad(Type.OBJECT));
+                       body.append(
+                               Utility.createConversion(
+                                       fact,
+                                       Type.OBJECT,
+                                       BcelWorld.makeBcelType(superParamTypes[i])));
                }
 
                // call super/this
@@ -476,17 +497,22 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
                
                // put this back on the stack
 
-               body.append(fact.ALOAD_0);
+               body.append(InstructionConstants.ALOAD_0);
                
                // unpack params onto stack
-               Member postMethod = AjcMemberMaker.postIntroducedConstructor(aspectType, onType, declaredParams);
+               Member postMethod =
+                       AjcMemberMaker.postIntroducedConstructor(aspectType, onType, declaredParams);
                TypeX[] postParamTypes = postMethod.getParameterTypes();
                
                for (int i = 1, len = postParamTypes.length; i < len; i++) {
-                       body.append(fact.createLoad(Type.OBJECT, arraySlot));
+                       body.append(InstructionFactory.createLoad(Type.OBJECT, arraySlot));
                        body.append(Utility.createConstant(fact, superParamTypes.length + i-1));
-                       body.append(fact.createArrayLoad(Type.OBJECT));
-                       body.append(Utility.createConversion(fact, Type.OBJECT, BcelWorld.makeBcelType(postParamTypes[i])));
+                       body.append(InstructionFactory.createArrayLoad(Type.OBJECT));
+                       body.append(
+                               Utility.createConversion(
+                                       fact,
+                                       Type.OBJECT,
+                                       BcelWorld.makeBcelType(postParamTypes[i])));
                }               
                
                // call post
@@ -494,7 +520,7 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
                
                // don't forget to return!!
                
-               body.append(fact.RETURN);
+               body.append(InstructionConstants.RETURN);
                
                return true;            
        }
@@ -529,11 +555,11 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
                InstructionFactory fact = onGen.getFactory();
                int pos = 0;
                
-               body.append(fact.createThis());
+               body.append(InstructionFactory.createThis());
                pos++;
                for (int i = 0, len = paramTypes.length; i < len; i++) {
                        Type paramType = paramTypes[i];
-                       body.append(fact.createLoad(paramType, pos));
+                       body.append(InstructionFactory.createLoad(paramType, pos));
                        pos+=paramType.getSize();
                }
                if (isSuper) {
@@ -541,7 +567,7 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
                } else {
                        body.append(Utility.createInvoke(fact, world, superMethod));
                }
-               body.append(fact.createReturn(returnType));
+               body.append(InstructionFactory.createReturn(returnType));
 
                return mg;
        }       
@@ -596,13 +622,13 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
                                        fg.getName(),
                                        fieldType, Constants.GETSTATIC));
                        } else {
-                               il.append(fact.ALOAD_0);
+                               il.append(InstructionConstants.ALOAD_0);
                                il.append(fact.createFieldAccess(
                                        gen.getClassName(), 
                                        fg.getName(),
                                        fieldType, Constants.GETFIELD));
                        }
-                       il.append(fact.createReturn(fieldType));
+                       il.append(InstructionFactory.createReturn(fieldType));
                        mg.getBody().insert(il);
                                
                        gen.addMethodGen(mg);
@@ -611,20 +637,20 @@ public class BcelTypeMunger extends ConcreteTypeMunger {
                                        AjcMemberMaker.interFieldInterfaceSetter(field, gen.getType(), aspectType));
                        InstructionList il1 = new InstructionList();
                        if (field.isStatic()) {
-                               il1.append(fact.createLoad(fieldType, 0));
+                               il1.append(InstructionFactory.createLoad(fieldType, 0));
                                il1.append(fact.createFieldAccess(
                                        gen.getClassName(), 
                                        fg.getName(),
                                        fieldType, Constants.PUTSTATIC));
                        } else {
-                               il1.append(fact.ALOAD_0);
-                               il1.append(fact.createLoad(fieldType, 1));
+                               il1.append(InstructionConstants.ALOAD_0);
+                               il1.append(InstructionFactory.createLoad(fieldType, 1));
                                il1.append(fact.createFieldAccess(
                                        gen.getClassName(), 
                                        fg.getName(), 
                                        fieldType, Constants.PUTFIELD));
                        }
-                       il1.append(fact.createReturn(Type.VOID));
+                       il1.append(InstructionFactory.createReturn(Type.VOID));
                        mg1.getBody().insert(il1);
                                
                        gen.addMethodGen(mg1);
index 249bc1de59f4fb06a0fd40e848a977a6cdbb0ed8..d2f1d35f31ff8c6ed59bf3ee6d62c01d57d79e0b 100644 (file)
@@ -40,28 +40,37 @@ public class BcelVar extends Var {
     public int getSlot() { return slot; }
 
     public Instruction createLoad(InstructionFactory fact) {
-        return fact.createLoad(BcelWorld.makeBcelType(getType()), slot);
+               // TODO: remove fact
+        return InstructionFactory.createLoad(BcelWorld.makeBcelType(getType()), slot);
     }
     public Instruction createStore(InstructionFactory fact) {
-        return fact.createStore(BcelWorld.makeBcelType(getType()), slot);
+       // TODO: remove fact
+        return InstructionFactory.createStore(BcelWorld.makeBcelType(getType()), slot);
     }
 
        public void appendStore(InstructionList il, InstructionFactory fact) {
+               // TODO: remove fact
                il.append(createStore(fact));
        }
     public void appendLoad(InstructionList il, InstructionFactory fact) {
+               // TODO: remove fact
         il.append(createLoad(fact));
     }
-    public void appendLoadAndConvert(InstructionList il, InstructionFactory fact, ResolvedTypeX toType) {
-        il.append(createLoad(fact));
-        Utility.appendConversion(il, fact, getType(), toType);
-    }    
+       public void appendLoadAndConvert(
+               InstructionList il,
+               InstructionFactory fact,
+               ResolvedTypeX toType) {
+               il.append(createLoad(fact));
+               Utility.appendConversion(il, fact, getType(), toType);
+       } 
     public void insertLoad(InstructionList il, InstructionFactory fact) {
+               // TODO: remove fact            
         il.insert(createLoad(fact));
     }
     public InstructionList createCopyFrom(InstructionFactory fact, int oldSlot) {
+               // TODO: remove fact
         InstructionList il = new InstructionList();
-        il.append(fact.createLoad(BcelWorld.makeBcelType(getType()), oldSlot));
+        il.append(InstructionFactory.createLoad(BcelWorld.makeBcelType(getType()), oldSlot));
         il.append(createStore(fact));
         return il;
     }
@@ -76,7 +85,7 @@ public class BcelVar extends Var {
         ResolvedTypeX convertFromType = getType().getResolvedComponentType();
         appendLoad(il, fact);
         il.append(Utility.createConstant(fact, index));
-        il.append(fact.createArrayLoad(BcelWorld.makeBcelType(convertFromType)));
+        il.append(InstructionFactory.createArrayLoad(BcelWorld.makeBcelType(convertFromType)));
         Utility.appendConversion(il, fact, convertFromType, convertTo);
     }
 
@@ -91,7 +100,7 @@ public class BcelVar extends Var {
         il.append(Utility.createConstant(fact, index));
         storee.appendLoad(il, fact);
         Utility.appendConversion(il, fact, storee.getType(), convertToType);
-        il.append(fact.createArrayStore(BcelWorld.makeBcelType(convertToType)));
+        il.append(InstructionFactory.createArrayStore(BcelWorld.makeBcelType(convertToType)));
     }
     
     InstructionList createConvertableArrayStore(
index 3efa2831762e5f917eb725f5b9215b3b0a83ff2f..b21460186eb438bc9d65866e5944dd83ddd430ec 100644 (file)
@@ -33,6 +33,7 @@ import org.apache.bcel.classfile.Method;
 import org.apache.bcel.generic.ClassGen;
 import org.apache.bcel.generic.ConstantPoolGen;
 import org.apache.bcel.generic.FieldGen;
+import org.apache.bcel.generic.InstructionConstants;
 import org.apache.bcel.generic.InstructionFactory;
 import org.apache.bcel.generic.InstructionHandle;
 import org.apache.bcel.generic.InstructionList;
@@ -337,7 +338,7 @@ public final class LazyClassGen {
                new Type[0],
                CollectionUtil.NO_STRINGS,
                this);
-               clinit.getBody().insert(getFactory().RETURN);
+               clinit.getBody().insert(InstructionConstants.RETURN);
         methodGens.add(clinit);
         return clinit;
     }
@@ -354,7 +355,7 @@ public final class LazyClassGen {
                new Type[0],
                CollectionUtil.NO_STRINGS,
                this);
-               ajcClinit.getBody().insert(getFactory().RETURN);
+               ajcClinit.getBody().insert(InstructionConstants.RETURN);
         methodGens.add(ajcClinit);
         
         getStaticInitializer().getBody().insert(Utility.createInvoke(getFactory(), ajcClinit));
@@ -405,7 +406,7 @@ public final class LazyClassGen {
        
        // make a new factory
        list.append(fact.createNew(factoryType));
-       list.append(fact.createDup(1));
+       list.append(InstructionFactory.createDup(1));
        
        list.append(new PUSH(getConstantPoolGen(), getFileName()));
        
@@ -421,7 +422,7 @@ public final class LazyClassGen {
                                Type.VOID, new Type[] {Type.STRING, classType},
                                Constants.INVOKESPECIAL));
                                
-       list.append(fact.createStore(factoryType, 0));
+       list.append(InstructionFactory.createStore(factoryType, 0));
        
        List entries = new ArrayList(tjpFields.entrySet());
        Collections.sort(entries, new Comparator() {
@@ -450,13 +451,13 @@ public final class LazyClassGen {
        //ResolvedMember mem = shadow.getSignature().resolve(shadow.getWorld());
        
        // load the factory
-       list.append(fact.createLoad(factoryType, 0));
+       list.append(InstructionFactory.createLoad(factoryType, 0));
        
        // load the kind
        list.append(new PUSH(getConstantPoolGen(), shadow.getKind().getName()));
        
        // create the signature
-       list.append(fact.createLoad(factoryType, 0));
+       list.append(InstructionFactory.createLoad(factoryType, 0));
        list.append(new PUSH(getConstantPoolGen(), sig.getSignatureString(shadow.getWorld())));
        list.append(fact.createInvoke(factoryType.getClassName(), 
                                        sig.getSignatureMakerName(),
index bead0eba35aa4119a29286e73b2b28304629b81b..a6dcb0cc6addcea3beccb46738a205146eb2bee3 100644 (file)
@@ -304,8 +304,7 @@ public final class LazyMethodGen {
        }
 
     public String toShortString() {
-        org.apache.bcel.classfile.Utility util = null; // EVIL!
-        String access = util.accessToString(getAccessFlags());
+        String access = org.apache.bcel.classfile.Utility.accessToString(getAccessFlags());
         
         StringBuffer buf = new StringBuffer();
         
@@ -313,20 +312,29 @@ public final class LazyMethodGen {
             buf.append(access);
             buf.append(" ");
         }
-        buf.append(util.signatureToString(getReturnType().getSignature(), true));
+               buf.append(
+                       org.apache.bcel.classfile.Utility.signatureToString(
+                               getReturnType().getSignature(),
+                               true));
         buf.append(" ");
         buf.append(getName());
         buf.append("(");
-        {
-            int len = argumentTypes.length;
-            if (len > 0) {
-                buf.append(util.signatureToString(argumentTypes[0].getSignature(), true));  
-                for (int i = 1; i < argumentTypes.length; i++) {
-                    buf.append(", ");
-                    buf.append(util.signatureToString(argumentTypes[i].getSignature(), true));
-                }
-            }
-        }
+               {
+                       int len = argumentTypes.length;
+                       if (len > 0) {
+                               buf.append(
+                                       org.apache.bcel.classfile.Utility.signatureToString(
+                                               argumentTypes[0].getSignature(),
+                                               true));
+                               for (int i = 1; i < argumentTypes.length; i++) {
+                                       buf.append(", ");
+                                       buf.append(
+                                               org.apache.bcel.classfile.Utility.signatureToString(
+                                                       argumentTypes[i].getSignature(),
+                                                       true));
+                               }
+                       }
+               }
         buf.append(")");
         
         {
index cf69bea9c1cede0bc5a8e214bb2393ec63b93e61..c8fde4241bd5ef3d81cc83c459a4ce7b587c3fad 100644 (file)
@@ -182,8 +182,7 @@ final class ShadowRange extends Range {
         if (addReturn) {
             // we really should pull this out somewhere...
             ret = freshBody.append(
-                new InstructionFactory(freshMethod.getEnclosingClass().getConstantPoolGen())
-                    .createReturn(freshMethod.getReturnType()));
+                InstructionFactory.createReturn(freshMethod.getReturnType()));
         }
                // and remap all the old targeters of the end handle of the range to the return.
         InstructionTargeter[] ts = end.getTargeters();
index 5c7ce31814126aef9fb9ee7b584265bf1b5b064b..ab446340719e1ea6b167f3eb94340459bcea8ec7 100644 (file)
@@ -56,7 +56,8 @@ public class UnwovenClassFile {
                //XXX this is an important optimization
                if (getBytes() == null) {
                        System.out.println("no bytes for: " + getFilename());
-                       Thread.currentThread().dumpStack();
+                       //Thread.currentThread().dumpStack();
+                       Thread.dumpStack();                     
                }
                return Utility.makeJavaClass(filename, getBytes());
 //             if (javaClass == null) javaClass = Utility.makeJavaClass(filename, getBytes());
index 93c2347bc361b8c84b40d0a887874639befa0211..16527dcc38cb30e073b39e39e2b471663b5d676f 100644 (file)
@@ -71,8 +71,8 @@ public class Utility {
         return fact.createInvoke(
             signature.getDeclaringType().getName(),
             signature.getName(),
-            world.makeBcelType(signature.getReturnType()),
-            world.makeBcelTypes(signature.getParameterTypes()),
+            BcelWorld.makeBcelType(signature.getReturnType()),
+            BcelWorld.makeBcelTypes(signature.getParameterTypes()),
             kind);
        }
     
@@ -206,10 +206,10 @@ public class Utility {
 
         if (toType.equals(ResolvedTypeX.VOID)) {
             // assert fromType.equals(TypeX.OBJECT)
-            il.append(fact.createPop(fromType.getSize()));
+            il.append(InstructionFactory.createPop(fromType.getSize()));
         } else if (fromType.equals(ResolvedTypeX.VOID)) {
             // assert toType.equals(TypeX.OBJECT)
-            il.append(fact.createNull(Type.OBJECT));
+            il.append(InstructionFactory.createNull(Type.OBJECT));
             return;
         } else if (fromType.equals(TypeX.OBJECT)) {
             Type to = BcelWorld.makeBcelType(toType);
@@ -264,14 +264,14 @@ public class Utility {
         if (fromType.equals(toType))
             return il;
         if (toType.equals(Type.VOID)) {
-            il.append(fact.createPop(fromType.getSize()));
+            il.append(InstructionFactory.createPop(fromType.getSize()));
             return il;
         }
 
         if (fromType.equals(Type.VOID)) {
             if (toType instanceof BasicType) 
                 throw new BCException("attempting to cast from void to basic type");
-            il.append(fact.createNull(Type.OBJECT));
+            il.append(InstructionFactory.createNull(Type.OBJECT));
             return il;
         }
 
@@ -449,7 +449,8 @@ public class Utility {
                        }
                                  
                        // Create a new select statement with the new targets array
-                       SWITCH switchStatement = new SWITCH(freshSelect.getMatchs(),targets,freshSelect.getTarget());
+                       SWITCH switchStatement =
+                               new SWITCH(freshSelect.getMatchs(), targets, freshSelect.getTarget());
                        return (Select)switchStatement.getInstruction();        
                } else {
                        return i.copy(); // Use clone for shallow copy...
@@ -521,7 +522,7 @@ public class Utility {
                        Type type = BcelWorld.makeBcelType(typeX);
                        int local = enclosingMethod.allocateLocal(type);
                        
-                       il.append(fact.createStore(type, local));
+                       il.append(InstructionFactory.createStore(type, local));
                        ret[i] = new BcelVar(typeX, local);
                }               
                return ret;
index 20d2e0550d4ffdcacb1e251bdb1817b0bb447488..d2f9b9b0c210132cbd6a36de63c6e1c9d984cf0a 100644 (file)
@@ -657,7 +657,7 @@ public class PatternParser {
                                                                        tokenSource.peek());
                        }
                        if (declaringType.toString().equals("")) {
-                               declaringType = declaringType.ANY;
+                               declaringType = TypePattern.ANY;
                        }
                        }
                }
@@ -699,7 +699,7 @@ public class PatternParser {
            } else {
                name = tryToExtractName(declaringType);
                if (declaringType.toString().equals("")) {
-                       declaringType = declaringType.ANY;
+                       declaringType = TypePattern.ANY;
                }
                }
                SignaturePattern ret = new SignaturePattern(Member.FIELD, modifiers, returnType,
index 2569b1ac7851efa2d1b95dd13c8a0e52632fa62b..4e51ed2ad5ec5b8b9d1b317efd44bbd5f067e953 100644 (file)
@@ -15,6 +15,7 @@ package org.aspectj.weaver.bcel;
 
 import java.io.*;
 
+import org.apache.bcel.generic.InstructionFactory;
 import org.aspectj.weaver.*;
 
 public class MoveInstructionsWeaveTestCase extends WeaveTestCase {
@@ -31,15 +32,18 @@ public class MoveInstructionsWeaveTestCase extends WeaveTestCase {
                super.specializeOn(s);
                 ((BcelShadow) s).initializeForAroundClosure();
             }
-            public void implementOn(Shadow s) {
-                BcelShadow shadow = (BcelShadow) s;
-                LazyMethodGen newMethod = shadow.extractMethod(shadow.getSignature().getExtractableName() + "_extracted");
-                shadow.getRange().append(shadow.makeCallToCallback(newMethod));
+                       public void implementOn(Shadow s) {
+                               BcelShadow shadow = (BcelShadow) s;
+                               LazyMethodGen newMethod =
+                                       shadow.extractMethod(
+                                               shadow.getSignature().getExtractableName() + "_extracted");
+                               shadow.getRange().append(shadow.makeCallToCallback(newMethod));
 
-                if (! shadow.isFallsThrough()) {
-                    shadow.getRange().append(shadow.getFactory().createReturn(newMethod.getReturnType()));
-                }
-            }
+                               if (!shadow.isFallsThrough()) {
+                                       shadow.getRange().append(
+                                               InstructionFactory.createReturn(newMethod.getReturnType()));
+                               }
+                       }
         };
 
         weaveTest("HelloWorld", "ExtractedHelloWorld", p);
@@ -58,7 +62,7 @@ public class MoveInstructionsWeaveTestCase extends WeaveTestCase {
                 shadow.getRange().append(shadow.makeCallToCallback(newMethod));
 
                 if (! shadow.isFallsThrough()) {
-                    shadow.getRange().append(shadow.getFactory().createReturn(newMethod.getReturnType()));
+                    shadow.getRange().append(InstructionFactory.createReturn(newMethod.getReturnType()));
                 }
             }
                };