[aspectc-user] how to access sliced fields

Olaf Spinczyk os at aspectc.org
Thu May 7 11:49:34 CEST 2009


Hi Steven,

there are two problems here:

1. How to access the object on which the constructor is being executed 
(in the construction advice)?

You can either use the joinpoint API "tjp->that()->init();" or the 
pointcut function 'that':
advice construction(...) && args(...) & that(obj) : after (Heap &obj) { 
... }
If your code has to be generic, only the joinpoint API will work for you.

2. How to avoid include cycles in the generated code?

Introductions can always cause this problem. You can read more about it 
in the ac++ compiler manual. In order to avoid it, move the slice into a 
separate aspect header file and reference the slice by name in your aspect.

If you still have problems, contact me.

Cheers,

Olaf

steven wrote:
> hello folks,
>
> I have a type 'Heap' defined in 'Heap.h' and 'Heap.cpp'.
> I want to weave an instance field 'gc' into 'Heap' that is supposed
> to be initialized in 'Heap's constructor. I defined a slice but I do
> not know how to access a sliced member/ member function in an advice.
>
> How can this be achieved?
>
> #ifndef MARK_SWEEP
> #define MARK_SWEEP
>
> #include "GarbageCollector.h"
>
> aspect MarkSweep{
>    pointcut heapType() = "Heap";
>
>
>    advice heapType():slice class{
>         GarbageCollector* gc;
>         void init(){ gc = new GarbageCollector();}
>    };
>
>    advice construction(heapType()) && args(i): after(int i){
>         //Heap::init(); ??
>     }
> };
>
> #endif
>
>
> regards,
>
> steven
> ------------------------------------------------------------------------
>
> _______________________________________________
> 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