]> source.dussan.org Git - aspectj.git/commitdiff
more bug fixes
authorjhugunin <jhugunin>
Tue, 17 Dec 2002 03:55:08 +0000 (03:55 +0000)
committerjhugunin <jhugunin>
Tue, 17 Dec 2002 03:55:08 +0000 (03:55 +0000)
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AspectDeclaration.java
org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/compiler/batch/WorkingTestMain.java
weaver/src/org/aspectj/weaver/World.java
weaver/src/org/aspectj/weaver/bcel/BcelCflowStackFieldAdder.java
weaver/src/org/aspectj/weaver/bcel/BcelShadow.java
weaver/src/org/aspectj/weaver/bcel/LazyClassGen.java
weaver/src/org/aspectj/weaver/bcel/LazyMethodGen.java
weaver/src/org/aspectj/weaver/bcel/Range.java
weaver/testdata/AroundArgsDynamicHelloWorld.txt
weaver/testsrc/org/aspectj/weaver/patterns/BindingTestCase.java

index 66e004d002f7914cca75aafb03bc5173bc0b250d..26bf18d8bc7b7a9938eedf090ddb3f3d63ea5296 100644 (file)
@@ -59,7 +59,7 @@ public class AspectDeclaration extends MemberTypeDeclaration {
        }
        
        public void resolve() {
-               if (binding == null || ignoreFurtherInvestigation) {
+               if (binding == null) {
                        ignoreFurtherInvestigation = true;
                        return;
                }
index 6b0cc37856577de8341e551a45b29d9e2fed4e5e..b70be133fe28cafa804bcccb942db3020e7d0980 100644 (file)
@@ -35,6 +35,7 @@ public class WorkingTestMain {
                List args = new ArrayList();
                args.add("-verbose");
                
+               //args.add("-1.3");
                args.add("-d");
                args.add("out");
                
@@ -48,8 +49,8 @@ public class WorkingTestMain {
                //args.add("-aspectpath");
                //args.add("../weaver/testdata/megatrace.jar");
                
-               //args.add("testdata/src1/AroundA1.java");
-               args.add("../tests/new/StrictFPAdvice.java");
+               args.add("testdata/src1/AroundA1.java");
+               //args.add("../tests/new/AroundInnerCalls.java");
                //args.add("-Xlint:error");
                //args.add("testdata/src1/InterType.java");
                //args.add("@" + examplesDir + "tjp/files.lst");
@@ -58,11 +59,12 @@ public class WorkingTestMain {
                CommandTestCase.runCompiler(args, CommandTestCase.NO_ERRORS);
                //CommandTestCase.runCompiler(args, new int[] {11, 14, 18, 32, 43});
                
-               CommandTestCase.printGenerated("../out", "StrictFPAdvice");
-               CommandTestCase.printGenerated("../out", "A");
+//             CommandTestCase.printGenerated("../out", "AdviceOnInheritedMethod");
+//             CommandTestCase.printGenerated("../out", "SuperC");
+//             CommandTestCase.printGenerated("../out", "SubC");
 
                //TestUtil.runMain("out;../bcweaver/testdata/megatrace.jar", "Privileged");
-               TestUtil.runMain("out;../lib/test/testing-client.jar", "StrictFPAdvice");
+               //TestUtil.runMain("out;../lib/test/testing-client.jar", "AroundInnerCalls");
        }
        
        private static String examplesDir = "c:/aspectj/examples/";
index c12acf985202d5ce37e5f8bb499202c4de06ec1b..99f4c6c181ec09ef488a9d821300eef37c1f9956 100644 (file)
@@ -144,7 +144,9 @@ public abstract class World {
     }
 
     protected int getModifiers(Member member) {
-        return resolve(member).getModifiers();
+       ResolvedMember r = resolve(member);
+       if (r == null) throw new BCException("bad resolve of " + member);
+        return r.getModifiers();
     }
 
     protected String[] getParameterNames(Member member) {
index c398cec634ba53b68c29d9ce5b14e07a652c2058..5e3ef466593eaddd2706c4be728e7bdc73ed03fc 100644 (file)
@@ -36,7 +36,7 @@ public class BcelCflowStackFieldAdder extends BcelTypeMunger {
                gen.getConstantPoolGen()).getField();
        gen.addField(f);
 
-               LazyMethodGen clinit = gen.getStaticInitializer();
+               LazyMethodGen clinit = gen.getAjcClinit(); //StaticInitializer();
                InstructionList setup = new InstructionList();
                InstructionFactory fact = gen.getFactory();
 
index 432acd17bbd948184e75c57d926ea48d47d589dd..acc8f96f12ab669565417ef80ea0ed2c82e541d8 100644 (file)
@@ -309,6 +309,13 @@ public class BcelShadow extends Shadow {
             LazyMethodGen enclosingMethod) 
     {
         InstructionList body = enclosingMethod.getBody();
+        InstructionHandle ih = body.getStart();
+        if (ih.getInstruction() instanceof InvokeInstruction) {
+               InvokeInstruction ii = (InvokeInstruction)ih.getInstruction();
+               if (ii.getName(enclosingMethod.getEnclosingClass().getConstantPoolGen()).equals(NameMangler.AJC_CLINIT_NAME)) {
+                       ih = ih.getNext();
+               }
+        }
         BcelShadow s =
             new BcelShadow(
                 world,
@@ -319,7 +326,7 @@ public class BcelShadow extends Shadow {
         ShadowRange r = new ShadowRange(body);
         r.associateWithShadow(s);
         r.associateWithTargets(
-            Range.genStart(body),
+            Range.genStart(body, ih),
             Range.genEnd(body));
         return s;
     }
@@ -654,7 +661,7 @@ public class BcelShadow extends Shadow {
         //???return TypeX.forName(getEnclosingClass().getClassName());      
     }
 
-    public boolean hasRealTarget() {
+    public boolean isTargetDifferentFromThis() {
         return hasTarget() && isExpressionKind();
     }
 
@@ -690,9 +697,9 @@ public class BcelShadow extends Shadow {
         if (!hasTarget()) {
             throw new IllegalStateException("no target");
         }
-        initializeTargetVar();
-        return targetVar;
-    }
+           initializeTargetVar();
+           return targetVar;
+        }
     public Var getArgVar(int i) {
         initializeArgVars();
         return argVars[i];
@@ -700,8 +707,8 @@ public class BcelShadow extends Shadow {
 
     // reflective thisJoinPoint support
     private BcelVar thisJoinPointVar = null;
-    private BcelVar thisJoinPointStaticPartVar = null;  //XXX should be field
-    private BcelVar thisEnclosingJoinPointStaticPartVar = null;  //XXX should be field
+    private BcelVar thisJoinPointStaticPartVar = null;  
+    private BcelVar thisEnclosingJoinPointStaticPartVar = null;  
     
        public final Var getThisJoinPointVar() {
                return getThisJoinPointBcelVar();
@@ -800,6 +807,7 @@ public class BcelShadow extends Shadow {
     private void initializeThisVar() {
         if (thisVar != null) return;
         thisVar = new BcelVar(getThisType().resolve(world), 0);
+        thisVar.setPositionInAroundState(0);
     }
     public void initializeTargetVar() {
        InstructionFactory fact = getFactory();         
@@ -812,14 +820,15 @@ public class BcelShadow extends Shadow {
             TypeX type = getTargetType();
             targetVar = genTempVar(type, "ajc$target");
             range.insert(targetVar.createStore(fact), Range.OutsideBefore); 
+               targetVar.setPositionInAroundState(hasThis() ? 1 : 0);            
         }
-        targetVar.setPositionInAroundState(0);
     }
     public void initializeArgVars() {
         if (argVars != null) return;
        InstructionFactory fact = getFactory();
         int len = getArgCount();
         argVars = new BcelVar[len];
+        int positionOffset = (hasTarget() ? 0 : 1) + (hasThis() ? 0 : 1);
                      
         if (getKind().argsOnStack()) {
             // we move backwards because we're popping off the stack
@@ -828,20 +837,21 @@ public class BcelShadow extends Shadow {
                 BcelVar tmp = genTempVar(type, "ajc$arg" + i);
                 range.insert(tmp.createStore(getFactory()), Range.OutsideBefore);
                 int position = i;
-                if (hasTarget()) position += 1;
+                if (hasTarget()) position += positionOffset;
                 tmp.setPositionInAroundState(position);
                 argVars[i] = tmp;
             }
         } else {
             int index = 0;
             if (hasThis()) index++;
+            
             for (int i = 0; i < len; i++) {
                 TypeX type = getArgType(i); 
                 BcelVar tmp = genTempVar(type, "ajc$arg" + i);
                 range.insert(tmp.createCopyFrom(fact, index), Range.OutsideBefore);
                 argVars[i] = tmp;
                 int position = i;
-                if (hasTarget()) position += 1;
+                if (hasTarget()) position += positionOffset;
                 tmp.setPositionInAroundState(position);
                 index += type.getSize();
             }       
@@ -850,6 +860,7 @@ public class BcelShadow extends Shadow {
     public void initializeForAroundClosure() {
         initializeArgVars();
         if (hasTarget()) initializeTargetVar();
+        if (hasThis()) initializeThisVar();
     }
 
             
@@ -925,6 +936,10 @@ public class BcelShadow extends Shadow {
     }
     
     public void weaveAfterThrowing(BcelAdvice munger, TypeX catchType) {
+       // a good optimization would be not to generate anything here
+       // if the shadow is GUARANTEED empty (i.e., there's NOTHING, not even
+       // a shadow, inside me).
+       if (getRange().getStart().getNext() == getRange().getEnd()) return;
         InstructionFactory fact = getFactory();        
         InstructionList handler = new InstructionList();        
         BcelVar exceptionVar = genTempVar(catchType);
@@ -1352,14 +1367,21 @@ public class BcelShadow extends Shadow {
         }
     }
     
-    // XXX only used for testing
+    // exposed for testing
     InstructionList makeCallToCallback(LazyMethodGen callbackMethod) {
        InstructionFactory fact = getFactory();
         InstructionList callback = new InstructionList();
-        if (targetVar != null) {
+        if (thisVar != null) {
+               callback.append(fact.ALOAD_0); 
+        }
+        if (targetVar != null && targetVar != thisVar) {
             callback.append(BcelRenderer.renderExpr(fact, world, targetVar));
         }
         callback.append(BcelRenderer.renderExprs(fact, world, argVars));
+        // remember to render tjps
+        if (thisJoinPointVar != null) {
+               callback.append(BcelRenderer.renderExpr(fact, world, thisJoinPointVar));
+        }
         callback.append(Utility.createInvoke(fact, callbackMethod));
         return callback;
     }
@@ -1372,13 +1394,20 @@ public class BcelShadow extends Shadow {
         BcelVar arrayVar = genTempVar(TypeX.OBJECTARRAY);
         //final Type objectArrayType = new ArrayType(Type.OBJECT, 1);
         final InstructionList il = new InstructionList();
-        int alen = getArgCount() + (targetVar == null ? 0 : 1) + (thisJoinPointVar == null ? 0 : 1);
+        int alen = getArgCount() + (thisVar == null ? 0 : 1) + 
+                               ((targetVar != null && targetVar != thisVar) ? 1 : 0) + 
+                               (thisJoinPointVar == null ? 0 : 1);
         il.append(Utility.createConstant(fact, alen));
         il.append((Instruction)fact.createNewArray(Type.OBJECT, (short)1));
         arrayVar.appendStore(il, fact);
 
         int stateIndex = 0;     
-        if (targetVar != null) {
+        if (thisVar != null) {
+            arrayVar.appendConvertableArrayStore(il, fact, stateIndex, thisVar);
+                       thisVar.setPositionInAroundState(stateIndex);
+            stateIndex++;
+        }              
+        if (targetVar != null && targetVar != thisVar) {
             arrayVar.appendConvertableArrayStore(il, fact, stateIndex, targetVar);
                        targetVar.setPositionInAroundState(stateIndex);
             stateIndex++;
@@ -1599,7 +1628,10 @@ public class BcelShadow extends Shadow {
     private IntMap makeRemap() {
         IntMap ret = new IntMap(5);
         int reti = 0;
-        if (targetVar != null) {
+               if (thisVar != null) {
+                       ret.put(0, reti++);  // thisVar guaranteed to be 0
+               }
+        if (targetVar != null && targetVar != thisVar) {
             ret.put(targetVar.getSlot(), reti++);
         }            
         for (int i = 0, len = argVars.length; i < len; i++) {
@@ -1613,21 +1645,28 @@ public class BcelShadow extends Shadow {
         // aliases, which we so helpfully put into temps at the beginning of this join 
         // point.
         if (! getKind().argsOnStack()) {
-                   int index = 0;
-               if (hasThis()) { ret.put(0, 0); index++; }
+               int oldi = 0;
+               int newi = 0;
+               // if we're passing in a this and we're not argsOnStack we're always 
+               // passing in a target too
+               if (hasThis()) { ret.put(0, 0); oldi++; newi+=1; }
+               //assert targetVar == thisVar
                for (int i = 0; i < getArgCount(); i++) {
                    TypeX type = getArgType(i); 
-                               ret.put(index, index);
-                   index += type.getSize();
+                               ret.put(oldi, newi);
+                   oldi += type.getSize();
+                   newi += type.getSize();
                }   
         }      
         return ret;
     }
 
     /**
-     * The new method is nonStatic iff we're from nonExpression advice
-     * with an enclosing non-static method.
-     * Otherwise, it's static
+     * The new method always static.
+     * It may take some extra arguments:  this, target.
+     * If it's argsOnStack, then it must take both this/target
+     * If it's argsOnFrame, it shares this and target.
+     * ??? rewrite this to do less array munging, please
      */
     private LazyMethodGen createMethodGen(String newMethodName) {
         Type[] parameterTypes = world.makeBcelTypes(getSignature().getParameterTypes());
@@ -1638,10 +1677,23 @@ public class BcelShadow extends Shadow {
 //            modifiers |= Modifier.STRICT;
 //        }
         modifiers |= Modifier.STATIC;
-        if (hasTarget()) {
+        if (targetVar != null && targetVar != thisVar) {
             TypeX targetType = getTargetType();
+            ResolvedMember resolvedMember = getSignature().resolve(world);
+            if (resolvedMember != null && Modifier.isProtected(resolvedMember.getModifiers()) && 
+               !samePackage(targetType.getPackageName(), getThisType().getPackageName()))
+            {
+               if (!targetType.isAssignableFrom(getThisType(), world)) {
+                       throw new BCException("bad bytecode");
+               }
+               targetType = getThisType();
+            }
             parameterTypes = addType(world.makeBcelType(targetType), parameterTypes);
         }
+        if (thisVar != null) {
+               TypeX thisType = getThisType();
+               parameterTypes = addType(world.makeBcelType(thisType), parameterTypes);
+        }
         
         // We always want to pass down thisJoinPoint in case we have already woven
         // some advice in here.  If we only have a single piece of around advice on a
@@ -1669,6 +1721,13 @@ public class BcelShadow extends Shadow {
 //                TypeX.getNames(getSignature().getExceptions(world)),
                 getEnclosingClass());
     }
+
+       private boolean samePackage(String p1, String p2) {
+               if (p1 == null) return p2 == null;
+               if (p2 == null) return false;
+               return p1.equals(p2);
+       }
+
    
     private Type[] addType(Type type, Type[] types) {
         int len = types.length;
index 0a1861b4746511036b3b79d4e073eb4adcc15aab..b3b4cced868307bb112d3cb566ec53adae478d0e 100644 (file)
@@ -318,6 +318,25 @@ public final class LazyClassGen {
         return clinit;
     }
     
+    public LazyMethodGen getAjcClinit() {
+        for (Iterator i = methodGens.iterator(); i.hasNext();) {
+            LazyMethodGen gen = (LazyMethodGen) i.next();
+                       if (gen.getName().equals(NameMangler.AJC_CLINIT_NAME)) return gen;
+        } 
+        throw new RuntimeException("unimplemented");
+//        LazyMethodGen clinit = new LazyMethodGen(
+//             Modifier.STATIC,
+//             Type.VOID,
+//             "<clinit>",
+//             new Type[0],
+//             CollectionUtil.NO_STRINGS,
+//             this);
+//             clinit.getBody().insert(getFactory().RETURN);
+//        methodGens.add(clinit);
+//        return clinit;
+    }
+    
+    
     
     // reflective thisJoinPoint support
     Map/*BcelShadow, Field*/ tjpFields = new HashMap();
index 63d105e196c4549ef6b41128fe5f2bf14828c9ee..35648dc5f751e3b5cad048107c0cfff3af7b888b 100644 (file)
@@ -700,8 +700,11 @@ public final class LazyMethodGen {
                 if (r instanceof ExceptionRange) {
                     ExceptionRange er = (ExceptionRange) r;
                     if (er.getStart() == ih) {
-                        // order is important, insert handlers in order of start
-                        insertHandler(er, exnList);
+                       //System.err.println("er " + er);
+                       if (!er.isEmpty()){
+                               // order is important, insert handlers in order of start
+                               insertHandler(er, exnList);
+                       }
                     }
                 } else {
                     // we must be a shadow range or something equally useless, 
index 0d6eb21b679138ae7fc29ec7804e0edf7697a634..49df80897fb141fb38c7687950251f7347e1b7e7 100644 (file)
@@ -50,7 +50,9 @@ abstract class Range implements InstructionTargeter {
 
     boolean isEmpty() {
         InstructionHandle ih = start;
+        //System.err.println("  looking for " + end);
         while (ih != end) {
+               //System.err.println("    ih " + ih);
             if (! Range.isRangeHandle(ih)) return false;
             ih = ih.getNext();
         }
index 5ca21c9b51abde9d7a4fe87355a39a99e928a4ed..0c2881392f1cdb1d7775d46a9c11c2a8664d252b 100644 (file)
@@ -68,15 +68,19 @@ public class DynamicHelloWorld extends java.lang.Object implements java.io.Seria
     | |             IFEQ L0
     | |             ALOAD 4
     | |             CHECKCAST java.util.ArrayList
-    | |             BIPUSH 2
+    | |             BIPUSH 3
     | |             ANEWARRAY java.lang.Object
     | |             ASTORE 5
     | |             ALOAD 5
     | |             BIPUSH 0
-    | |             ALOAD 4
+    | |             ALOAD_0
     | |             AASTORE
     | |             ALOAD 5
     | |             BIPUSH 1
+    | |             ALOAD 4
+    | |             AASTORE
+    | |             ALOAD 5
+    | |             BIPUSH 2
     | |             ALOAD_3
     | |             AASTORE
     | |             NEW DynamicHelloWorld$AjcClosure1
@@ -85,9 +89,10 @@ public class DynamicHelloWorld extends java.lang.Object implements java.io.Seria
     | |             INVOKESPECIAL DynamicHelloWorld$AjcClosure1.<init> ([Ljava/lang/Object;)V
     | |             INVOKESTATIC Aspect.ajc_around0 (Ljava/util/ArrayList;Lorg/aspectj/runtime/internal/AroundClosure;)Z
     | |             GOTO L1
-    | |         L0: ALOAD 4
+    | |         L0: ALOAD_0
+    | |             ALOAD 4
     | |             ALOAD_3
-    | |             INVOKESTATIC DynamicHelloWorld.add_aroundBody0 (Ljava/util/List;Ljava/lang/Object;)Z
+    | |             INVOKESTATIC DynamicHelloWorld.add_aroundBody0 (LDynamicHelloWorld;Ljava/util/List;Ljava/lang/Object;)Z
     | |         L1: NOP
     | method-call(boolean java.util.List.add(java.lang.Object))
     |               POP
@@ -99,12 +104,12 @@ public class DynamicHelloWorld extends java.lang.Object implements java.io.Seria
     method-execution(java.lang.String DynamicHelloWorld.doit(java.lang.String, java.util.List))
   end String doit(String, java.util.List)
 
-  static final boolean add_aroundBody0(java.util.List, Object):
-                    ALOAD_0
+  static final boolean add_aroundBody0(DynamicHelloWorld, java.util.List, Object):
                     ALOAD_1
+                    ALOAD_2
                     INVOKEINTERFACE java.util.List.add (Ljava/lang/Object;)Z   (line 21)
                     IRETURN
-  end static final boolean add_aroundBody0(java.util.List, Object)
+  end static final boolean add_aroundBody0(DynamicHelloWorld, java.util.List, Object)
 end public class DynamicHelloWorld
 
 public class DynamicHelloWorld$AjcClosure1 extends org.aspectj.runtime.internal.AroundClosure:
@@ -119,14 +124,18 @@ public class DynamicHelloWorld$AjcClosure1 extends org.aspectj.runtime.internal.
                     ALOAD_0
                     GETFIELD org.aspectj.runtime.internal.AroundClosure.state [Ljava/lang/Object;
                     ASTORE_2
+                    ALOAD_2
+                    BIPUSH 0
+                    AALOAD
+                    CHECKCAST DynamicHelloWorld
                     ALOAD_1
                     BIPUSH 0
                     AALOAD
                     CHECKCAST java.util.List
                     ALOAD_2
-                    BIPUSH 1
+                    BIPUSH 2
                     AALOAD
-                    INVOKESTATIC DynamicHelloWorld.add_aroundBody0 (Ljava/util/List;Ljava/lang/Object;)Z
+                    INVOKESTATIC DynamicHelloWorld.add_aroundBody0 (LDynamicHelloWorld;Ljava/util/List;Ljava/lang/Object;)Z
                     INVOKESTATIC org.aspectj.runtime.internal.Conversions.booleanObject (Z)Ljava/lang/Object;
                     ARETURN
   end public Object run(Object[])
index d1d2b39232e93932dcb79ca1a96d2d6bf3cadb56..d7b598f38802991801732beb0570aa4be4a4f69c 100644 (file)
@@ -23,20 +23,9 @@ import junit.framework.TestCase;
 import org.aspectj.bridge.AbortException;
 import org.aspectj.weaver.*;
 
-/**
- * @author hugunin
- *
- * To change this generated comment edit the template variable "typecomment":
- * Window>Preferences>Java>Templates.
- * To enable and disable the creation of type comments go to
- * Window>Preferences>Java>Code Generation.
- */
 public class BindingTestCase extends TestCase {
 
-       /**
-        * Constructor for ParserTestCase.
-        * @param arg0
-        */
+
        public BindingTestCase(String arg0) {
                super(arg0);
        }
@@ -58,8 +47,12 @@ public class BindingTestCase extends TestCase {
                checkBindings("this(*)", none);
                checkBindings("this(a)", a);
                
-               checkBindings("args(.., a,..,b)", all);
-               checkBindings("args(a,..,b, ..)", all);
+               try {checkBindings("args(.., a,..,b)", all);
+                       //checkBindings("args(a,..,b, ..)", all);
+                       fail("shouldn't be implemented yet");
+               } catch (AbortException ae) {
+                       // not implemented yet
+               }
                
                checkBindings("args(a,..,b)", all);
                checkBindings("args(b)", b);