[aspectc-user] Problem with slice struct

Olaf Spinczyk Olaf.Spinczyk at informatik.uni-erlangen.de
Mon Jun 19 09:19:51 CEST 2006


Hello Carsten,

ac++ supports the introduction of non-inline members. However, the 
syntax is different: The implementation of 'baz()' should be a member of 
the slice and not a non-declared member of the target class. With your 
syntax it would only be possible to introduce 'baz' into 'Bar' and not 
into any class that is matched by the pointcut expression in your advice 
declaration.

This is how to do it correctly:

class Bar {}; // 'public:' is not necessary here. The accessability is
               // determined by the accessibility of the member in the
               // slice, which is 'public' in your case
...
slice struct MyIntros {      // a slice is a class/struct fragment
   void baz();                // The syntax is like the template syntax,
};                           // except for the fact that 'slice' is used
                              // instead of 'template<...>'
slice void MyIntros::baz () { ... }

aspect Foo {
   advice "Bar" : slice MyIntros; // a 'slice reference' => MyIntros
                                  // shall be merged into "Bar"
                                  // Note: don't use
                                  // 'slice struct MyIntros;' here!
};

There is one restriction for the introduction of non-inline functions 
into classes that I should tell you in advance: ac++ has to be able to 
find a suitable .cc/.cpp file for the introduction. This is done by 
checking if the target class is either defined in such a file or if it 
has at least one member that is defined in a .cpp/.cc file (non-inline 
member function or non-const static attribute). If such member does not 
exist, e.g. the target class only has inline member functions, the 
weaver will terminate with an error message.

A smarter solution is going to be implemented based on the knowledge 
save in the project repository file in the future.

Best regards,

Olaf


Carsten V. Munk wrote:
> 
> foo.cc:
> 
> class Bar
> {
>        public:
> };
> 
> aspect Foo
> {
>        public:
>        advice "Bar" : slice struct
>        {
>                void baz();
>        };
> };
> 
> void Bar::baz()
> {
>        int i;
>        i += 2;
> }
> 
> stskeeps at ns1 [~/test]# ag++ -v9 -k -c foo.cc
> *
> *
> * AG++ Configuration:
> *   Create puma.config: 1
> *   Aspect C++ weaver:  ac++
> *   C++ compiler:       g++
> *   Files:               foo.cc
> *   Options (G++):       -v -c -I"."
> *   Options (AC++):      -v9 -k -p.
> *   Options (total):     -v9 -v -k -c foo.cc -I"." -p.
> *   Weave: 1 Compile: 1 Link: 0
> *
> *
> * Generating Puma configuration file
>  - Parsing output of g++ compiler
>  - Executing: "g++"  -v -c -I"." -E -dM -v -x c++ "/dev/null" 2>.err.out 
> 1>.std.out
>  - Exit: Success
>  - removing temporary file: .std.out
>  - removing temporary file: .err.out
>  - Writing puma configuration file
> * Weaving
>  - Executing: "ac++" --config "puma.config"  -v9 -k -p. -c "foo.cc" -o 
> "foo.acc"
> * Running ac++ 1.0pre3
> * Handling Translation Unit `foo.cc'.
>  - Path "foo.cc"
>  - Inserting namespace AC
>  - Parsing ...
> foo.cc:16: error: `baz' is not a member of `Bar'
>  - Aborting
> error: Execution failed: "ac++" --config "puma.config"  -v9 -k -p. -c 
> "foo.cc" -o "foo.acc"
>  - Exitcode: 256 (should be 0 )
> 
> Isn't it a bit awkward only to be able introduce methods that are 
> inline, in classes?
> 
> 
> /Carsten Munk
> 
> _______________________________________________
> 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