[aspectc-user] Automatic #include insertion

arnd-hendrik.mathias at nefkom.net arnd-hendrik.mathias at nefkom.net
Wed Apr 2 01:10:38 CEST 2008


Hi everybody,
i just found some strange behavior of ag++ in concern of include files.

The usual behavior of ag++ is to automatically weave in header files  
of classes used by aspect-woven-in code fragments like:

test.cc:
int main ( int argc, char** argv ) { return 0; }

test.ah
#include <iostream>
aspect Test
{
    advice execution ( "% main ( ... )" ): before ()
    {
       std::cout << "Hello" << endl;
    }
}

where #include <iostream> is inserted into test.cc.

Deviating from this I now found out, that inclusions of header files  
declaring some global objects seem not to be inserted the same way. So  
in the following example the object a is not known by the woven-in  
code fragment:

Note: All .hh and .ah files contain double inclusion avoidance omitted  
here for better overview!

test.hh:
class test {};

test.cc:
int main ( int argc, char** argv ) { return 0; }

a.hh:
extern char a;

a.cc:
#include "a.hh"
char a = 'H';

test.ah:
#include <iostream>
#include "test.hh"
#include "a.hh"

aspect Test1
{
    advice "Test" : slice class
    {
       public : static void test ( void )
       {
          std::cout << "In Test::test ()" << std::endl;
          std::cout << "a = " << a << std::endl;
       };
    };
    advice execution ( "% main ( ... )" ) : before ()
    {
       Test::test ();
    };
};

Here the test.hh include (for the Test class) is inserted  
automatically (can be tested by removing the "a = "... line from the  
aspect) while the a.hh include is not. In this example this leads to  
"error: 'a' was not declared in this scope".

Can anyone confirm this or am I doing something wrong here? Is this  
behavior by a special purpose?
In the given example the consequence was, that I have to add the  
#include line to the test.cc permanently, independently of whether I  
use this aspect or not.
Best regards

Arnd-Hendrik





More information about the aspectc-user mailing list