[aspectc-user] How to include files with aspectC++

Mikael Björk mikbj303 at student.liu.se
Tue May 18 11:20:21 CEST 2004


Hi again

I have carefully studied the weaved code and managed
to condense the problem. So I pose a more detailed
question at the end.

> To avoid problems 
> follow 
> these rules:
> 
> 1. Always use include guards in your header files
> 
> 2. Make sure that no header file depends on the
inclusion of other
>    include files. It has to be valid (Aspect)C++
code on its own.
> 

I'm afraid I don't understand rule number two. Do
you mean that no header files should include other
header files (and thus be valid on their own) or do
you mean that if a header file requires something
from another header file, it should include that
file directly (instead of including a third file
which includes the desired header)?

I should point out that the system I'm working on is
written in C, but since the aspect weaver introduces
C++ code, we compile the program with g++.

Now to a condensed description of the problem, first
a number of files (severely cropped):

===============================================
// BufferManagerInterface.h

struct Btable {int stuff};
===============================================
// USMA.ah

#include "hp2pl-w-similarity.h"

aspect USMA
{
  advice "transactionInformation" : int updateWait;
  advice "Btable" : int ID;
};
===============================================
// hp2pl-w-similarity.h

#include "MMCinterface.h"

struct transactionInformation {int stuff};

void initializeThread();
===============================================
// MMCinterface.h

void stuff();
===============================================
// hp2pl-w-similarity.ah

#include "hp2pl-w-similarity.h
#include "MMCinterface.h"

aspect hp2pl-w-similarity.h
{
  initializeThread();
  do-other-stuff-with-MMC-for-example();
};
===============================================

The problem is that USMA is weaved in before BufferManagerInterface.h and USMA.ah includes hp2pl-w-similarity.h.

hp2pl-w-similarity.h in turn includes MMCinterface.h

Unfortunately the aspect hp2pl-w-similarity needs the information in hp2pl-w-similarity.h (and thus includes it), but when hp2pl-w-similarity is weaved into the code right before MMCinterface is included, the function initializeThread() has not been declared yet.

This is the order in which everything occurs in the weaved file (indentation indicates a level of inclusion and I have removed everything which is unreachable due to inclusion guards):

-----------------------------------------------

forward_declaration_stuff_of_USMA;

// USMA.ah

  // hp2pl-w-similarity.h

    // hp2pl-w-similarity.ah

    aspect hp2pl-w-similarity.h
    {
      initializeThread();
      do-other-stuff-with-MMC-for-example();
    };
    // MMCinterface.h

    void stuff();

  struct transactionInformation {int stuff};

  void initializeThread();

aspect USMA
{
  advice "transactionInformation" : int updateWait;
  advice "Btable" : int ID;
};

// BufferManagerInterface.h

struct Btable {int stuff};

-----------------------------------------------

As you can see initializeThread() is used before it is declared. 

Since I do not have knowledge of ac-internals I do not understand why aspect hp2pl-w-similarity is weaved in before MMCinterface.h but not before hp2pl-w-similarity.h. If this was not so, the program would work.

So my question is whether this is a bug or a feature? Is there some way around this problem? (Except for including MMCinterface in USMA.ah)

/Mikael




More information about the aspectc-user mailing list