[aspectc-user] more on templates

Panu Bloigu panu.bloigu at mbnet.fi
Thu Feb 15 09:51:33 CET 2007


thanks for the explanation. It was quite illuminating! Basically, I 
understood that you said that first all the pcds are searched and added 
to some 'pointcut definition pool'. After that, when the parser sees 
e.g. a function call, it iterates over the pointcut definitions and sees 
if any of them matches the signature of the called function. If such is 
the case, the corresponding code gets inserted and the parser goes about 
it's task without ever knowing the code it is about to see actually 
wasn't there in the first place. Talk about obliviousness! ;-)

On a more serious note, I have a simple follow-up question. If I changed 
the pcd on the line 12 to something like this:

advice execution("void Test::do_before<...>(...)") && args("ClassA*") : around()

it would still work as expected, right? 



Olaf Spinczyk wrote:
> Hi,
> sorry, for the late answer, but I first had to figure out what you actually had
> in mind with your example.
> The problem is indeed quite interesting: Advice code triggers a template
> instantiation, which then should also be affected by other advice. We had a
> similar problem with nested introductions recently: Some introduction matches a
> class that is created by another introduction. Here one might as well ask
> whether the advice order is relevant. The answer is "no".
> I will first explain how the implementation works in the case of nested
> introduction and then describe how the implementation should work in the your
> example.
> The trick is to weave on-the-fly, i.e. while the parser runs, and not
> afterwards, which would be simpler. Whenever the parser comes across a class
> definition it checks, whether some introduction advice matches here. If there
> are introductions, the code is inserted into the token stream. Therefore, an
> introduced nested class will be parsed before we are done with the outer class.
> Here, once again, the inner class will be used to check for more introductions,
> and so on. As you can see, the mechanism does not depend on the advice order.
> With template instances, I could imagine the process as follows: When the parser
> reaches the definition of ClassA::method() or ClassB::method(), it generates the
> necessary code to instantiate the advice from line 6. By inserting this code
> into the token stream, the advice code will be parsed on-the-fly and the
> template instance of do_before will be created. Also on-the-fly the parser will
> notice that the advice from line 12 matches the do_before<ClassA> instance.
> This, once again, triggers the generation of code that instantiates the advice.
> Did you get the idea? The only problem we have to keep in mind on the language
> level is that the code instrumentation at some particular join-point (shadow)
> shall never depend on code that will be parsed in the future (exception: all
> pointcut expressions are parsed during an extra parser run first).
> The short answers to your questions are:
> * the order does not matter
> * the better syntax is "% AClass<...>::%(...)", because <...> matches an
>   arbitrary template argument list, while % matches only a single argument.
> Best regards,
> Olaf
> Panu Bloigu wrote:
>> Hello.
>> I have a question concerning templates. However, this time my question is of
>> theoretical kind since I know the code I'm going to present contains
>> features which are not supported by the current AspectC++ compiler. What I'm
>> asking is that is my code syntactically correct AspectC++ code and should it
>> work if there existed a full implementation of AspectC++ language?
>> I have the following aspect:
>> ======================================================
>>  1: #include <iostream>
>>  2: aspect Test
>>  3: {
>>  4:     pointcut target_methods() = "void ClassA::method()" || "void
>> ClassB::method()";
>>  5:
>>  6:     advice execution(target_methods()) : before()
>>  7:     {
>>  8:         do_before(tjp->that());
>>  9:     }
>> 10:
>> 11:     // Should this work or not?
>> 12:     advice execution("void Test::do_before<ClassA>(ClassA*)") : around()
>> 13:     {
>> 14:         // do something specific to ClassA
>> 15:	}
>> 16:
>> 17:
>> 18:     template<class That> static void do_before(That* that)
>> 19:     {
>> 20:         // do something with 'that';
>> 21:     }
>> 22:  };
>> ======================================================
>> My specific question is that whether the pcd on the line 12 would do what
>> I'm expecting it to do? What I'm especially worried about is the fact that
>> the template is instantiated from within an advice.
>> If the above code would work as such, would it still work if I switched the
>> order of the advices so that the advice beginning on the line 12 would
>> precede the other advice? Does the order matter here?
>> Also, what is the correct pcd syntax for matching all instatiations of a
>> template? Would it be something like "% AClass<...>::%(...)" or "%
>> AClass<%>::%(...)"? Note the '%' sign vs. '...'.
>> Let me emphasise that I know that this does not work with current AspectC++
>> implementation. My questions are purely language-wise.
>> Thanks in advance,
>> Panu.
>> _______________________________________________
>> aspectc-user mailing list
>> aspectc-user at aspectc.org
>> http://www.aspectc.org/mailman/listinfo/aspectc-user

More information about the aspectc-user mailing list