[aspectc-user] more on templates

Olaf Spinczyk Olaf.Spinczyk at informatik.uni-erlangen.de
Wed Feb 14 15:07:24 CET 2007


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

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,


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