[aspectc-user] Any way to 'Declare error'

Olaf Spinczyk Olaf.Spinczyk at informatik.uni-erlangen.de
Sun Jan 8 11:20:04 CET 2006


this is a message from Daniel Lohmann, which was automatically discarded 
by mailman, because of a wrong reply address in the mail header. 
Therefore, I post this reply on his behalf.

- Olaf

==>

Hi Mike,

> I also tried another C++ trick, you can declare a template with a name 
> that indicates the issue:
>
>  template <bool> struct DirectCallOf__StartTimer;
>  template <> struct DirectCallOf__StartTimer<true> {};
>
> and then instantiate it in the advice body with the unspecialized 
> (unimplemented) flavor:
>
>   DirectCallOf__StartTimer<false>;
>
> But this doesn't work either, because then the instantiation of 
> DirectCallOf__StartTimer<false> is
> in the Aspect body in the generated C++ code, and the template 
> instantiation fails (as expected), but it fails regardless of whether 
> or not the any code uses the join point since the aspect itself is 
> (correctly) created in the generated code regardless of whether or not 
> its advise is actually 'called' from anywhere that matches the joinpoint.
>  
>
This is because the compiler knows everything to fully instantiate the 
template when parsing the advice body - and so, with accordance to the 
C++ standard, it does. You need just to add another template parameter 
and pass some joinpoint-specific type for it:

template <typename JP, bool> struct DirectCallOf__StartTimer;
template <typename JP> struct DirectCallOf__StartTimer<JP, true> {};

aspect Test {
   advice call("% foo()") : before() {
       DirectCallOf__StartTimer< JoinPoint, false >();
   }
};

void foo() {}

int main() {
   // if uncommented, compile-time error is thrown
   // foo();
}

As the advice code now uses the static joinpoint API, ac++ transform the 
advice code into a template method that is instantiated with the actual 
joinpoint information. If the pointcut does not match any joinpoint, the 
advice template and in turn the DirectCallOf__XXX template is never 
instantiated.



Hope that helps

Daniel



More information about the aspectc-user mailing list