[aspectc-user] advice "Foo": struct Bar{}; advice "Foo": static Bar member;

Olaf Spinczyk Olaf.Spinczyk at informatik.uni-erlangen.de
Sat Feb 18 11:50:21 CET 2006


Hi Szczepan,

your example reveals one of many weaknesses of the current introduction 
mechanism. The problem is that in the line "advice "Foo": Bar 
IntroduceStructAndStaticMember::member;" the identifier "Bar" is looked 
up in the global scope. However, the struct was introduced into "Foo". 
Therefore it is not found. -> Syntax Error (I know, the error message 
should be better!)

The problem is that there is no way to access the target type with 
introduced code. To solve this problem we have a join point API for 
introduced code in mind, but this is not implemented yet.

In order to find the aspect, to which non-inline introduction code 
belongs, the name of the introduced element is qualified with the aspect 
name ("IntroduceStructAndStaticMember::member"). When the target 
specific code is generated this name is replaced by the target class 
name. Note that not all name qualifiers <aspect>:: are replace by 
<target-class>::. Only the qualifier of the element name. This is 
necessary to allow introduced code to access elements defined in the 
aspect scope.

I know that this mechanism is not very intuitive. This the reason why 
I'm currently reimplementing the introduction mechanism (see the roadmap 
at aspectc.org). Until this is finished you can only use the following 
workaround:

---
aspect IntroduceStructAndStaticMember
{
public:
   struct Bar {};
   advice "Foo": typedef IntroduceStructAndStaticMember::Bar Bar;
   advice "Foo": static Bar member;
};

advice "Foo": IntroduceStructAndStaticMember::Bar 
IntroduceStructAndStaticMember::member;

class Foo {};
---

Note that the class Foo has to be defined after the aspect. You can 
achieve that by putting the aspect into a separate aspect header file. 
Now Bar is defined as a nested struct in the aspect. This is referenced 
by the non-inline introduction code for "member". In order to allow 
other parts of the system to access Bar like a nested struct in Foo, I 
added the typedef introduction.

I hope this helps you, until we come up with a better solution.

Best regards,

Olaf


Szczepan Hołyszewski wrote:
> Hello,
>
> I cannot introduce a nested struct, and then a static member which is
> an instance of the introduced nested struct. Is this illegal? I
> suspect a bug because the error message is somewhat vague. I am not
> certain however that my non-inline intro syntax is OK so please check
> me:
>
> --main.cc------------------------------------------------
>
> class Foo {};
>
> aspect IntroduceStructAndStaticMember
> {
> public:
>    advice "Foo": struct Bar {};
>    advice "Foo": static Bar member;
> };
>
> //is this the right way?
>
> advice "Foo": Bar IntroduceStructAndStaticMember::member;
>
> --from Eclipse console (newlines doubled)--------------------------
>
> "c:/eclipse/plugins/org.aspectc.compiler.win32_0.9.92/AC/ag++.exe" 
> --c_compiler
> mingw32-g++ --keep_acc -r repo.acp -p .. -c ../main.cc --Xcompiler -o
> main.o -D_useAC -O0 -g3 -Wall -fmessage-length=0 -I..
>
> <anonymous unit>:1: error: invalid declaration near token `Foo'
>
> error: Execution failed:
> ""c:/eclipse/plugins/org.aspectc.compiler.win32_0.9.92/AC/ac++" --config
> "puma.config" -rrepo.acp -p".." -D_useAC -I".." -c "../main.cc" -o
> "main.acc""
>
> --end of Eclipse console-------------------------------------------
>
> The error message seems to be:
>
> <anonymous unit>:1: error: invalid declaration near token `Foo'
>
> The woven file main.acc is not created.
>
> Any ideas? If this is an AC bug then I will file it at bugzilla.
>
> Thanks in advance,
> Szczepan Holyszewski
> _______________________________________________
> 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