Aspect Oriented Programming with DMS

The DMS Software Reengineering Toolkit is an ideal tool for implementing aspect-weavers.

Aspect-oriented programming is a means for independently specifying and maintaining solutions to problems (typically locking, synchronization ...) that "cut across" a large application, and "weaving" those solutions into the application to achieve the application with correspondingly solved problems. The independent code solutions are called "aspects" and are coded in a specialized minilanguage. The idea is to keep the the aspects unentangled from the application code from the developers' point of view, to enable separate maintainability and understandability.

To use aspects, one must have an application code in some language, a set of aspects, and in practice, a weaving engine. Each aspect specifies places in the code where it is relevant, called "pointcuts", and "advice" to be carried out at those places, that will solve problem addressed by the aspect. Often the advice is code to be inserted near the identified pointcuts. The weaving engine combines aspects with the application by locating the pointcuts, and executing the advice. Weaving may be done at runtime with some additional overhead, or more ideally at compile-time.

What is not easy is finding a class of problem/solutions that can be solved this way for a particular language and domain, deciding how to encode those aspects, and implementing a practical weaving engine that understands how to read the aspects, read the application code, find the pointcuts, carry out the advice, and emit the resulting code.

The most well-known aspect-solution is called AspectJ, which implements these capabilities for Java with a compile-time weaver. A special purpose weaver was implemented (not with DMS) that understands the entire Java language. For AspectJ, pointcuts are generally method call sites designated with a kind of regular expression, and advice is cast as Java code fragments. The AspectJ weaver finds the designated method calls, and inserts the "advice" before, after, or around the designated calls. This tool has been implemented over a number of years.

If one wishes to use aspects for other languages, one must find or build weavers for those languages. The AspectJ experience shows building weavers is decidedly nontrivial. One must have a full language parser, an aspect parser, a mechanism to interpret the pointcuts to decide where in the parsed code the advice will apply, and machinery to execute the advice, and then re-emit the revised code for compilation/execution. Experimental compile-time weavers have been built (again, not with DMS) for C (AspectC) and C++ (AspectC++). AspectC++ has been under development for a number of years also, but still isn't ready for prime-time. Given the complexity of C++, this is hardly a surprise.

The notion of compile-time weaving is just a special case of program transformation; aspects spell out how to transform code. This makes the DMS Software Reengineering Toolkit an ideal engine on which to construct weavers. DMS not only has the built-in machinery to parse, transform, and unparse, but it also has robust front ends for many languages to which aspects might apply, including C, Java, C++, and many other languages as well. By amortizing the cost of strong infrastructure over many program transformation tasks, DMS makes it relatively straightforward to define aspect readers and to apply the corresponding transforms. Click here to see a movie showing aspect weaving for ObjectPascal using DMS by the University of Alabama at Birmingham. In contrast to AspectC++, this required an extremely modest effort; in fairness, it too is incomplete.

Semantic Designs is presently building special purpose aspect weavers using DMS to carry out large-scale component reengineering tasks for C++. SD is willing to discuss building custom weavers to meet your needs.

We observe just briefly the synergy of DMS's machinery for refactoring tasks.

For more information: info@semanticdesigns.com    Follow us at Twitter: @SemanticDesigns

Aspect-oriented Programming
with DMS