[aspectc-user] intercepting flow of execution of the method declared inside aspect

Olaf Spinczyk Olaf.Spinczyk at informatik.uni-erlangen.de
Thu May 27 11:52:01 CEST 2004


Hello Bartosz,

Bartosz Blimke wrote:
> Hi,
> 
> I have been trying instead of calling tjp->proceed() in advice,
> to call the function(which takes an AC::Action argument) inside advice,
> and then call action.trigger() inside this function.
> This works.
> Then I tried to intercept the flow of this function
> I found the problem.
> 
> Problem exists when I try to intercept the flow
> of a method declared inside aspect.
> 
> Here is the simplified example:
> 
> main.cpp
> 
> int main()
> {
> 	return 0;
> }
> 
> aspect.ah
> 
> #ifndef _Aspect_
> #define _Aspect_
> 
> aspect Aspect
> {
> 	void function2()
> 	{
> 	}
> 
> 	advice
> 		execution( "% main(...)" )
> 		|| cflow (execution( "% %function2(...)" ) )
> 	: around()
> 	{
> 		tjp->proceed();
> 	}
> };
> #endif //_Aspect_
> 
> 
> The problem is with cflow (execution( "% %function2(...)" ))  pointcut.
> If I will remove cflow pointcut everything works ok.
> 
> weaving ... .\main.cpp -> Debug\main.cpp
> compiling ... main.cpp
> generating ... Debug/TestAspectProject_LinkOnce.cpp
> compiling ... TestAspectProject_LinkOnce.cpp
> Linking...
> main.obj : error LNK2005: "public: __thiscall `private: static void
> __cdecl Aspect::__action_exec__ZN6Aspect9function2Ev_0(struct AC::Action
> &)'::`3'::Trigger::Trigger(void)"
> (??0Trigger@?2??__action_exec__ZN6Aspect9function2Ev_0 at Aspect@@CAXAAUAction at AC@@@Z at QAE@XZ)
> already defined in TestAspectProject_LinkOnce.obj
> main.obj : error LNK2005: "public: __thiscall `private: static void
> __cdecl Aspect::__action_exec__ZN6Aspect9function2Ev_0(struct AC::Action
> &)'::`3'::Trigger::~Trigger(void)"
> (??1Trigger@?2??__action_exec__ZN6Aspect9function2Ev_0 at Aspect@@CAXAAUAction at AC@@@Z at QAE@XZ)
> already defined in TestAspectProject_LinkOnce.obj
> Debug\TestAspectProject.exe : fatal error LNK1169: one or more multiply
> defined symbols found
> 
> 
> If I will put the function2() outside the aspect
> it throws another errors:
> 
> Aspect.ah(39) : error C2027: use of undefined type 'Aspect'
> Aspect.ah(5) : see declaration of 'Aspect'
> Aspect.ah(39) : error C2065: '__cflow_a0_around_0' : undeclared identifier
> Aspect.ah(42) : error C2027: use of undefined type 'Aspect'
> Aspect.ah(5) : see declaration of 'Aspect'
> Aspect.ah(42) : error C3861: '__cflow_a0_around_0': identifier not found,
> even with argument-dependent lookup
> Compiler failed for main.cpp
> 
> 
> If function2() is declared in main.cpp everything works ok.
> 
> The problem is that I want to call this function
> from advice, so I need it inside the aspect.
> And then I want to intercept the flow of execution
> of this function.
> 
> 
> Bartosz Blimke
> masb at chorwacja.com

it took me some time to understand what you really want. Your second 
(direct) mail clarified that. Probably the pointcut expression is simply 
wrong ...

 > 	advice
 > 		execution( "% main(...)" )
 > 		|| cflow (execution( "% %function2(...)" ) )
 > 	: around()

It seems to me that you mean execution(...) && !cflow(execution("% 
Aspect::function2(...)"). Using "|| cflow(...)" means that ac++ would 
have to generate cflow checks at merely every joinpoint in your system. 
This is probably not what you wanted.

Here is an example of some working AspectC++ code that disables the 
advice for the execution of "func()" when "func()" was called from the 
aspect member function "run()".

=======main.cc=========
#include <stdio.h>

void func () {
   printf ("func\n");
}

int main () {
   func ();
}

====CFlowTest.ah========
#ifndef __CFlowTest_ah__
#define __CFlowTest_ah__

aspect CFlowTest {
   pointcut methods() = execution("% func()");

   void run(AC::Action &action) {
     action.trigger();
   }

   advice methods() && !cflow(execution("% CFlowTest::run(...)")) : 
around () {
     run(tjp->action ());
   }

};

#endif // __CFlowTest_ah__

I hope that this is what you wanted to achieve. Please tell me if I'm wrong.

Olaf

PS: Note that in version 0.9 the match expression "% %f()" can't be used 
to match a function "f" in any scope. The new match expression syntax 
requires to write either "% TheScope::f()" ("f" in the Scope "TheScope") 
or "% ...::f()" ("f" in any scope). A pre-release (0.9pre1) will be 
released soon that allows you to check if your existing code will still 
work with version 0.9.



More information about the aspectc-user mailing list