[go: nahoru, domu]

Jump to content

AspectC++

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by 84.250.223.204 (talk) at 04:40, 19 September 2007. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

AspectC++ is an aspect-oriented extension of C and C++ languages. It is based on source-to-source translation, translating AspectC++ source code to C++. It is available under the GNU GPL, though some extensions specific to Microsoft Windows are only available through pure-systems GmbH.

Aspect-oriented programming allows modularizing cross-cutting concerns in a single module, an aspect. Aspects can modify existing classes, but most commonly they provide 'advice' that runs before, after, or around existing functionality.

For example, if we want to Trace all calls to an API call, rather than inserting 'cerr' or print statements in many places, we can create a single aspect that will accomplish this:

aspect Tracer {
advice call("% %Iter::Reset(...)") : before() {
cerr << "about to call Iter::Reset for " << JoinPoint::signature() << endl;
}
};

The Tracer aspect above will print out a message before any call to %Iter::Reset. The '%Iter' syntax means that it will match all classes that end in Iter.

Each 'matched' location in the source code is call a joinpoint -- the advice is joined to (or advises) that code. AspectC++ provides a joinpoint API to enable accessing this information. For example, the function:

JoinPoint::signature()

returns the name of the method (that matched %Iter::Reset) that is about to be called.

The joinpoint API also provides compile-time type information that can be used within an aspect to access the type of value or arguments and the return type and return value of a method or function.

In addition to the documentation and tutorials at the AspectC++ website (external link below), you can also find articles on Aspect-oriented programming and AspectC++ at past AOSD conferences [1].