[aspectc-user] How to include files with aspectC++
Olaf.Spinczyk at informatik.uni-erlangen.de
Mon May 17 15:27:44 CEST 2004
Mikael Björk wrote:
> I'm working on a configurable real-time database which uses aspects to add various features to the database management system, such as concurrency control and quality of service control. The program is spread over a lot of files in many directories.
> Often I encounter compile errors in the weaved code that seems to depend on how and where various header files are included. These are usually solved after some testing by moving include-statements around. On one instance removing an inclusion made it work. Maybe I should point out that all header files are protected by inclusion guards.
> This seems like an impractical solution but I have looked through the documentation and not found any explanations of rules regarding inclusions. So my question is whether there are some kind of rules regarding how things should be included for it to work properly with aspectc++.
You are absolutely right. We need a special manual section on this
rather complicated topic. A few days ago I experimented with an aspect
that used introductions to create a cyclic dependency between classes.
Even for me, with the full knowledge of ac++ internals, this wasn't easy.
As a start I would like to explain the problem why the generation of the
link-once code (acgen.cc) sometimes fails with parse errors in header
files that are also used in other translation units (but with no
problems). This is a typical beginner problem. In acgen.cc translation
unit all classes of your project have to be known. Therefore, the
generated file includes all header files and aspect header files of your
project. The inclusion order is undefined(!). To avoid problems follow
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.
Following these rules might be troublesome in some cases. Therefore, we
are currently investigating new code generation patterns, which would
allow us to get rid of these acgen.cc files if the back-end compiler
comes with the so called COMDAT support (like g++ and MS VC++).
> Also I have looked some a the files which are produced by weaving and noticed that a lot of code introduced by the weaver is duplicated, the same weaver-created class can appear in several places in the resulting file. Is it supposed to be like that or am I doing something wrong while weaving.
> Code snippets to show my problems would be rather long so I omitted them on purpose.
The only duplicated code I am currently aware of is the code defined in
the namespace AC. However, this should only happen in the whole program
transformation mode and is intended because of rule 2 (see above).
More information about the aspectc-user