[aspectc-user] cflowbelow

Olaf Spinczyk Olaf.Spinczyk at informatik.uni-erlangen.de
Tue May 25 15:10:03 CEST 2004


Hello,

Bartosz Blimke wrote:
> Hi,
> 
> I'm trying to intercept the top level execution of function
> for example for some recursive function, I want to intercept
> only the instance of the function in the bottom of the stack.
> 
> for this in AspectJ I would use:
> 
> pointcut myPointcut = execution("% myFunction(...)");
> 
> pointcut topLevelExecutionOfFunction() =
>                myPointcut() && !cflowbelow(myPointcut());
> 
> In AspectC++ there is only cflow()
> 
> Are there some plans to insert cflowbelow into AspectC++ or
> maybe you know some other trick to deal with my problem ?
> 
> Bartosz Blimke
> masb at chorwacja.com

one way to 'simulate' cflowbelow is shown in the following example:

---
#include <stdio.h>

aspect FirstFac {
   int _recursions;
public:
   FirstFac () { _recursions = 0; }
   advice execution ("int fac(int)") : around () {
     if (_recursions == 0)
       printf ("first execution of fac()\n");
     _recursions++;
     tjp->proceed ();
     _recursions--;
   }
};

int fac (int n);

int main () {
   printf ("factorial of %d is %d\n", 5, fac (5));
}

int fac (int n) {
   if (n == 1)
     return 1;
   else
     return n * fac (n-1);
}
---

If you compile and execute it, the result is ...

first execution of fac()
factorial of 5 is 120

Note that this implementation is not thread-safe. However, the current 
cflow implementation is not thread-safe, too. You can make this 
implementation thread-safe by putting the aspect instance into 
thread-local memory. The concrete implementation depends on your 
thread-library/OS.

We'll probably integrate cflowbelow into AspectC++ quite soon.

Best regards,

Olaf



More information about the aspectc-user mailing list