[aspectc-user] Aspect templating

Olaf Spinczyk Olaf.Spinczyk at informatik.uni-erlangen.de
Wed May 4 12:01:24 CEST 2005


Hi Manuel,

Manuel Menezes de Sequeira wrote:

> Hi Olav,
>
>> Template aspects are a nice idea. However, aspects are instantiated 
>> implicitly by default and therefore the programmer doesn't have a 
>> chance to pass the template parameter.
>
> Right.  On the other hand, aspect templates could be defined in 
> AspectC++ to have no implicit instantiation.  They would have to be 
> instantiated explicitely.  For instance, something like:
>
>     // file1
>     // No effect unless instantiated explicitelly:
>     template <class T>
>     aspect MakeSingletonOf {
>         ...
>     };
>
>     // file2
>
>     class MyClass {
>         ...
>
>     };
>
>     template aspect MakeSingletonOf<MyClass>; // using C++ explicit
>     template instantiation syntax.
>
> In a sense, this is achievable with abstract aspects.  However, it 
> would be more powerful, since T might be used in a consistent way in 
> several different contexts within the aspect template.
>
> Manuel

I very much sympathize with the idea of aspect templates. However, I 
would object against different instantiation schemes for aspect 
templates and ordinary aspects. This would be confusing for programmers.

We could ...

(A) allow aspect template parameters only for abstract aspects, where a 
derived
    concrete aspect would pass the parameter, and for concrete aspects 
with a
    user-defined instantiation scheme (by implementing aspectof).

(B) no longer support the implicit instantiation (a feature that we simply
    copied from AspectJ without thinking about it very long) anymore. The
    advantage would be that aspect inheritance would no longer have to be
    restricted to abstract aspects, which in my opinion is an artificial 
restriction
    that often circumvents reuse of aspect code.

Here is an example for (B):

--- Foo.h ---
aspect Foo { ... }; // a concrete aspect
---

--- Bar.h ---
#include "Foo.h"
template <typename T> aspect Bar : public Foo { ... }; // a template
---

--- MyFooBar.ah ---
#include "Bar.h"
#include "My.h"
extern Bar<My> myFooBar;  // a global aspect instance
extern Foo myFoo; // another aspect
---

--- MyFooBar.cc ---
#include "MyFooBar.ah"
Bar<My> myFooBar;  // here the storage for the aspect instances is 
statically
Foo myFoo;  // allocated
---

What is your opinion about explicit instantiation?

What do you think about the problem of redundant concepts? A pointcut is 
more powerful than a template parameter, because you can use it to 
parameterize an aspect with sets of classes/functions or other join 
points. Instead of supporting aspect templates we could alternatively 
add a language mechanism that allows one to define a type accordings to 
the value of a poincut, e.g.

aspect X {
  pointcut virtual target_class() = 0;
  typedef typeof(target_class()) T;
  T attribute;
  T func(T);
  advice target_class() : int intro;
};

Any opinions on these issues?

Best regards,

Olaf




More information about the aspectc-user mailing list