]> source.dussan.org Git - aspectj.git/commitdiff
Fix for Bugzilla Bug 74952: before,after !(cflow(within(Trace*))) prints nothing
authoraclement <aclement>
Thu, 21 Oct 2004 12:55:49 +0000 (12:55 +0000)
committeraclement <aclement>
Thu, 21 Oct 2004 12:55:49 +0000 (12:55 +0000)
tests/bugs/WhatsGoingOn.java [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc121/Ajc121Tests.java
tests/src/org/aspectj/systemtest/ajc121/ajc121-tests.xml
weaver/src/org/aspectj/weaver/bcel/BcelShadow.java

diff --git a/tests/bugs/WhatsGoingOn.java b/tests/bugs/WhatsGoingOn.java
new file mode 100644 (file)
index 0000000..1838bc4
--- /dev/null
@@ -0,0 +1,151 @@
+public class WhatsGoingOn {
+    static public void main (String [] args) { }
+}
+
+aspect TraceClass {
+    static private int level = 0;
+
+    static private void offset() {
+        for (int i = 0; i < level; ++i)  System.err.print("  ");
+    }
+
+    pointcut pc() : 
+        !cflow(within(Trace*))
+//        !(within(Trace*) || cflowbelow(within(Trace*)))
+        ;
+    before () : pc() {
+        offset();
+        System.err.println("-> " + thisJoinPoint);
+        ++level;
+    }
+    after  () : pc() {
+        --level;
+        offset();
+        System.err.println("<- " + thisJoinPoint);
+    }
+} 
+
+aspect TraceTrace {
+
+    static private int level = 0;
+
+    static private void offset() {
+        for (int i = 0; i < level; ++i)         System.err.print("  ");
+    }
+    
+    pointcut pc() : within(TraceClass);
+    before () : pc() {
+        offset();
+        System.err.println("=> " + thisJoinPoint);
+        ++level;
+    }
+    after  () : pc() {
+        --level;
+        offset();
+        System.err.println("<= " + thisJoinPoint);
+    }
+}
+
+//Expected output:
+//"=> staticinitialization(TraceClass.<clinit>)\n"+
+//"  => set(int TraceClass.level)\n"+
+//"  <= set(int TraceClass.level)\n"+
+//"  => preinitialization(TraceClass())\n"+
+//"  <= preinitialization(TraceClass())\n"+
+//"  => initialization(TraceClass())\n"+
+//"    => execution(TraceClass())\n"+
+//"    <= execution(TraceClass())\n"+
+//"  <= initialization(TraceClass())\n"+
+//"<= staticinitialization(TraceClass.<clinit>)\n"+
+//"=> execution(ADVICE: void TraceClass.ajc$before$TraceClass$1$346234(JoinPoint))\n"+
+//"  => call(void TraceClass.offset())\n"+
+//"    => execution(void TraceClass.offset())\n"+
+//"      => get(int TraceClass.level)\n"+
+//"      <= get(int TraceClass.level)\n"+
+//"    <= execution(void TraceClass.offset())\n"+
+//"  <= call(void TraceClass.offset())\n"+
+//"  => get(PrintStream java.lang.System.err)\n"+
+//"  <= get(PrintStream java.lang.System.err)\n"+
+//"  => call(java.lang.StringBuffer(String))\n"+
+//"  <= call(java.lang.StringBuffer(String))\n"+
+//"  => call(StringBuffer java.lang.StringBuffer.append(Object))\n"+
+//"  <= call(StringBuffer java.lang.StringBuffer.append(Object))\n"+
+//"  => call(String java.lang.StringBuffer.toString())\n"+
+//"  <= call(String java.lang.StringBuffer.toString())\n"+
+//"  => call(void java.io.PrintStream.println(String))\n"+
+//"-> staticinitialization(WhatsGoingOn.<clinit>)\n"+
+//"  <= call(void java.io.PrintStream.println(String))\n"+
+//"  => get(int TraceClass.level)\n"+
+//"  <= get(int TraceClass.level)\n"+
+//"  => set(int TraceClass.level)\n"+
+//"  <= set(int TraceClass.level)\n"+
+//"<= execution(ADVICE: void TraceClass.ajc$before$TraceClass$1$346234(JoinPoint))\n"+
+//"=> execution(ADVICE: void TraceClass.ajc$after$TraceClass$2$346234(JoinPoint))\n"+
+//"  => get(int TraceClass.level)\n"+
+//"  <= get(int TraceClass.level)\n"+
+//"  => set(int TraceClass.level)\n"+
+//"  <= set(int TraceClass.level)\n"+
+//"  => call(void TraceClass.offset())\n"+
+//"    => execution(void TraceClass.offset())\n"+
+//"      => get(int TraceClass.level)\n"+
+//"      <= get(int TraceClass.level)\n"+
+//"    <= execution(void TraceClass.offset())\n"+
+//"  <= call(void TraceClass.offset())\n"+
+//"  => get(PrintStream java.lang.System.err)\n"+
+//"  <= get(PrintStream java.lang.System.err)\n"+
+//"  => call(java.lang.StringBuffer(String))\n"+
+//"  <= call(java.lang.StringBuffer(String))\n"+
+//"  => call(StringBuffer java.lang.StringBuffer.append(Object))\n"+
+//"  <= call(StringBuffer java.lang.StringBuffer.append(Object))\n"+
+//"  => call(String java.lang.StringBuffer.toString())\n"+
+//"  <= call(String java.lang.StringBuffer.toString())\n"+
+//"  => call(void java.io.PrintStream.println(String))\n"+
+//"<- staticinitialization(WhatsGoingOn.<clinit>)\n"+
+//"  <= call(void java.io.PrintStream.println(String))\n"+
+//"<= execution(ADVICE: void TraceClass.ajc$after$TraceClass$2$346234(JoinPoint))\n"+
+//"=> execution(ADVICE: void TraceClass.ajc$before$TraceClass$1$346234(JoinPoint))\n"+
+//"  => call(void TraceClass.offset())\n"+
+//"    => execution(void TraceClass.offset())\n"+
+//"      => get(int TraceClass.level)\n"+
+//"      <= get(int TraceClass.level)\n"+
+//"    <= execution(void TraceClass.offset())\n"+
+//"  <= call(void TraceClass.offset())\n"+
+//"  => get(PrintStream java.lang.System.err)\n"+
+//"  <= get(PrintStream java.lang.System.err)\n"+
+//"  => call(java.lang.StringBuffer(String))\n"+
+//"  <= call(java.lang.StringBuffer(String))\n"+
+//"  => call(StringBuffer java.lang.StringBuffer.append(Object))\n"+
+//"  <= call(StringBuffer java.lang.StringBuffer.append(Object))\n"+
+//"  => call(String java.lang.StringBuffer.toString())\n"+
+//"  <= call(String java.lang.StringBuffer.toString())\n"+
+//"  => call(void java.io.PrintStream.println(String))\n"+
+//"-> execution(void WhatsGoingOn.main(String[]))\n"+
+//"  <= call(void java.io.PrintStream.println(String))\n"+
+//"  => get(int TraceClass.level)\n"+
+//"  <= get(int TraceClass.level)\n"+
+//"  => set(int TraceClass.level)\n"+
+//"  <= set(int TraceClass.level)\n"+
+//"<= execution(ADVICE: void TraceClass.ajc$before$TraceClass$1$346234(JoinPoint))\n"+
+//"=> execution(ADVICE: void TraceClass.ajc$after$TraceClass$2$346234(JoinPoint))\n"+
+//"  => get(int TraceClass.level)\n"+
+//"  <= get(int TraceClass.level)\n"+
+//"  => set(int TraceClass.level)\n"+
+//"  <= set(int TraceClass.level)\n"+
+//"  => call(void TraceClass.offset())\n"+
+//"    => execution(void TraceClass.offset())\n"+
+//"      => get(int TraceClass.level)\n"+
+//"      <= get(int TraceClass.level)\n"+
+//"    <= execution(void TraceClass.offset())\n"+
+//"  <= call(void TraceClass.offset())\n"+
+//"  => get(PrintStream java.lang.System.err)\n"+
+//"  <= get(PrintStream java.lang.System.err)\n"+
+//"  => call(java.lang.StringBuffer(String))\n"+
+//"  <= call(java.lang.StringBuffer(String))\n"+
+//"  => call(StringBuffer java.lang.StringBuffer.append(Object))\n"+
+//"  <= call(StringBuffer java.lang.StringBuffer.append(Object))\n"+
+//"  => call(String java.lang.StringBuffer.toString())\n"+
+//"  <= call(String java.lang.StringBuffer.toString())\n"+
+//"  => call(void java.io.PrintStream.println(String))\n"+
+//"<- execution(void WhatsGoingOn.main(String[]))\n"+
+//"  <= call(void java.io.PrintStream.println(String))\n"+
+//"<= execution(ADVICE: void TraceClass.ajc$after$TraceClass$2$346234(JoinPoint))\n");
\ No newline at end of file
index 6e86caaccc1785b8948fc04d3a69e137f9a0ee72..1926ea38e77af77a4ab6be458f0b145c79626ae4 100644 (file)
@@ -20,6 +20,9 @@ import org.aspectj.testing.XMLBasedAjcTestCase;
 
 public class Ajc121Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
 
+
+
+         
   public static Test suite() {
     return XMLBasedAjcTestCase.loadSuite(Ajc121Tests.class);
   }
@@ -337,5 +340,24 @@ public class Ajc121Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
   public void test064() {
        runTest("Anonymous classes unaware of introductions into abstract classes");
   }
+  
+  private int countLines(String s) {
+    int lines = 0;
+    int idx = 0;
+    while (s.indexOf("\n",idx)!=-1) {
+       lines++;
+       idx = s.indexOf("\n",idx)+1;
+    }
+    return lines;
+  }
+  
+  public void test065() {
+       runTest("before,after not (cflow(within(Trace*))) prints nothing");
+       String s = getLastRunResult().getStdErr();
+       int lines = countLines(s);
+       assertTrue("The actual output does not match the expected output.  Expected 102 lines but got "+
+                          lines+" lines.  Actual output =\n"+s,lines==102);
+       // IF YOU WANT TO SEE THE EXPECTED OUTPUT, LOOK IN THE TEST PROGRAM bugs/WhatsGoingOn.java
+  }
 
 }
\ No newline at end of file
index 2ec496b3579cc84b9382be18d3e73f0d954505a9..77d52f3dc91fa408912f09f72fac829d5e2b0fbf 100644 (file)
         <compile files="ConcreteClassA.java"/>
         <run class="ConcreteClassA"/>
     </ajc-test>
+    
+    <ajc-test dir="bugs" pr="74952" title="before,after not (cflow(within(Trace*))) prints nothing">
+        <compile files="WhatsGoingOn.java"/>
+        <run class="WhatsGoingOn"/>
+    </ajc-test>
index cbabd9e1c0c3f1f7fc4c475cb19b2b8e6f2a33ac..c08fc485c4db2547eb4b2a4d3e501a54cd2d060b 100644 (file)
@@ -240,6 +240,9 @@ public class BcelShadow extends Shadow {
                if (getKind() == ConstructorCall) {
                        deleteNewAndDup();
                        initializeArgVars();
+               } else if (getKind() == PreInitialization) { // pr74952
+                       ShadowRange range = getRange();
+                       range.insert(InstructionConstants.NOP,Range.InsideAfter); 
                } else if (getKind() == ExceptionHandler) {
                        
                        ShadowRange range = getRange();
@@ -1259,6 +1262,18 @@ public class BcelShadow extends Shadow {
             retList = new InstructionList(ret);
             afterAdvice = retList.getStart();
         } else /* if (munger.hasDynamicTests()) */ {
+               /*
+                * 
+ 27:  getstatic       #72; //Field ajc$cflowCounter$0:Lorg/aspectj/runtime/internal/CFlowCounter;
+ 30:  invokevirtual   #87; //Method org/aspectj/runtime/internal/CFlowCounter.dec:()V
+ 33:  aload   6
+ 35:  athrow
+ 36:  nop
+ 37:  getstatic       #72; //Field ajc$cflowCounter$0:Lorg/aspectj/runtime/internal/CFlowCounter;
+ 40:  invokevirtual   #87; //Method org/aspectj/runtime/internal/CFlowCounter.dec:()V
+ 43:  d2i
+ 44:  invokespecial   #23; //Method java/lang/Object."<init>":()V
+                */
             retList = new InstructionList(InstructionConstants.NOP);            
             afterAdvice = retList.getStart();
 //        } else {
@@ -1295,7 +1310,7 @@ public class BcelShadow extends Shadow {
                        }
             range.append(advice);
             range.append(retList);
-        } else {
+        } else {            
             range.append(advice);
             range.append(retList);
         }
@@ -1449,7 +1464,7 @@ public class BcelShadow extends Shadow {
                                if (cflowStateVars.length == 0) {
                                        // This should be getting managed by a counter - lets make sure.
                                        if (!cflowField.getType().getName().endsWith("CFlowCounter")) 
-                                               throw new RuntimeException("Oncorrectly attempting counter operation on stacked cflow");
+                                               throw new RuntimeException("Incorrectly attempting counter operation on stacked cflow");
                                        entrySuccessInstructions.append(
                                                Utility.createGet(fact, cflowField));
                                        //arrayVar.appendLoad(entrySuccessInstructions, fact);
@@ -1487,7 +1502,6 @@ public class BcelShadow extends Shadow {
                                munger.getTestInstructions(this, entrySuccessInstructions.getStart(), 
                                                                        range.getRealStart(), 
                                                                        entrySuccessInstructions.getStart());
-                                               
                        entryInstructions.append(testInstructions);
                        entryInstructions.append(entrySuccessInstructions);
                }