[aspectc-user] Aspects inheritance problem ?
Olaf Spinczyk
Olaf.Spinczyk at informatik.uni-erlangen.de
Fri May 28 13:28:41 CEST 2004
Hello Bartosz,
Bartosz Blimke wrote:
> Hi,
>
> According to the Olaf's advice for workaround
> for problem about intercepting cflow() of a aspect method,
> I've been trying to implement this solution,
> and I found next problem.
>
> Here is the source code:
>
> main.cpp
> ---------
> #include <stdio.h>
>
> void func () {
> printf ("func\n");
> }
>
> int main () {
> func ();
> return 0;
> }
> ---------
>
> Aspect.ah
> -----------
> #ifndef __Aspect_ah__
> #define __Aspect_ah__
>
>
>
> aspect Aspect {
>
> void run(AC::Action &action);
>
> pointcut virtual methods() = 0;
>
> advice methods() && !cflow(execution("% Aspect::run(...)")) :
> around () {
> run(tjp->action ());
> }
>
> };
>
> #endif // __Aspect_ah__
> ----------
>
>
> Aspect.cpp
> -----------
> #include "Aspect.ah"
>
> void Aspect::run(AC::Action &action)
> {
> action.trigger();
> }
> -------------
>
> DerivedAspect.ah
> -----------
> #ifndef _DerivedAspect_ah_
> #define _DerivedAspect_ah_
>
> #include "Aspect.ah"
>
> aspect DerivedAspect : public Aspect
> {
> pointcut methods() = execution("% func()");
>
> pointcut virtual methods2() = 0;
>
> void run2(AC::Action &action);
> };
>
> #endif //_DerivedAspect_ah_
> ------------
>
>
> DerivedAspect.cpp
> -----------
> #include "DerivedAspect.ah"
>
>
> void DerivedAspect::run2(AC::Action &action)
> {
> action.trigger();
> }
> ------------
>
> FinalAspect.ah
> -------------
> #ifndef _FinalAspect_ah_
> #define _FinalAspect_ah_
>
> #include "DerivedAspect.ah"
>
> aspect FinalAspect : public DerivedAspect
> {
> pointcut methods() = execution("% func()");
>
> pointcut methods2() = execution("% func()");
>
> };
>
> #endif
> ---------------
>
>
> When I try to compile this code I have:
>
> Compiling...
> weaving ... .\DerivedAspect.cpp -> Debug\DerivedAspect.cpp
> compiling ... DerivedAspect.cpp
> FinalAspect.ah(2) : error C2504: 'DerivedAspect' : base class undefined
> Compiler failed for DerivedAspect.cpp
>
>
> I should add that this is only code to show the problem,
> without any special funcionality.
>
> I have no idea how to solve the problem,
> have I done something wrong, or the weaver doesn't generate
> correct code ?
>
>
> Greets,
>
> Bartek
This problem is the same as the one described by Mikael Björk a few days
ago on this list. It has to do with ac++'s difficult task to bring
everything in a C++ program into a linear order where everything is
defined before it is used.
After several lengthy mails I exchanged with Mikael we found out that
(the current) ac++ has a code generation problem which can only be
avoided if the programmer obeys this rule:
Never include a file in an aspect header that includes another file
which is affected by the aspect. Directly including an affected file
is allowed.
In your case FinalAspect.ah includes Aspect.ah indirectly and affects
it, because of the advice for the run function.
Obeying this rule is inconvenient in many situations. Therefore, we
started a discussion about better code generation patterns. However,
changing things in this area has consequences which are very difficult
to predict. So we will need some time.
I hope that you are now (after reading this rule) able to find a
workaround. If that doesn't help, contact me directly.
Best regards,
Olaf
More information about the aspectc-user
mailing list