Title: Aspect Weaving with Graph Rewriting
1Aspect Weaving with Graph Rewriting
- Uwe Aßmann
- Andreas Ludwig
- Universität Karlsruhe
- Institut für Programmstrukturen
2Overview
- Aspect Oriented Programming (AOP)
- Graph Rewrite Systems (GRS)
- Categories of GRS-based Weaving
- Generation of Aspect Weavers
- Conclusion
3Aspect-Oriented Programming
- Motivation Separation of Concerns
- Technique Integration by Weaving
- Examples for Aspects
- Synchronization
- Communication
- Instrumentalization
4Problem
- AOP aims at different problem domains...
- ... weaving requires different techniques.
- Weavers can become as complicated as
- fully fledged compilers.
5Idea
- 1) We need a uniform and formal technique to
- classify and specify AOP weavers.
- 2) Programs are edge-colored graphs...
- Describe aspect weaving as graph-rewriting.
6Classes of AOP Systems
- Script-based AOP (e.g. RG )
- aspects are modification rules
- Language-based AOP (e.g. AspectJ )
- aspects are specialized languages
- Rewriting-based AOP
- rewriting rules combine aspect fragments
7GRS - Basics
Rewrite Rule
Derivation
Host Graph
Redex
8Component Aspect Graphs
9AOP as GRS
- Join Point ? Redex in Component Graph
- Aspect Fragment ? Redex in Aspect Graph
- Aspect Composer ? Graph Rewrite Rule
- Weave Operation ? Direct Derivation
- Weaver ? Graph Rewrite System with
- a set of aspect composers,
- a component graph, and
- a set of aspect graphs (context-sensitive rules).
10Example
- Task prepend statements to method entries
class ClassDeclaration (nameName)
class ClassDeclaration (nameName)
aspectStatement Statement (placename)
aspectStatement Statement (placename)
methods
methods
method MethodDeclaration
method MethodDeclaration
entry
11Example (2)
methods
entry
methods
methods
entry
methods
methods
12Benefits
- Uniform specification allows a classification of
aspect weaving systems. - Certain classes of rewrite systems guarantee
- termination
- confluence ( deterministic results)
13Category I Aspect-Relating Rules
- Edge-addition rewrite system (EARS)
- always congruent ( terminating confluent)
- weaving operation becomes a function
- Ideal for simple property aspects
- e.g. persistency, synchronization, ...
14Category IIAspect-Additive Rules
- Exhaustive rewriting system (XGRS)
- does not modify the redex
- always congruent ( terminating confluent)
- Ideal for orthogonal aspect code
- e.g. Adaptive Programming
15Category IIIComponent-Modifying Rules
- Exchange parts of components.
- Confluence and termination are not guaranteed.
- Indeterminism is acceptable if all normal forms
are semantically equivalent.
16Special CategoryAspects in Rules
- Aspect fragments are part of the right-hand
sides. - Similar to script-based AOP.
- Ideal for aspects with finite variability.
17Special CategoryComponent-Modifying Rules
- Intra-component rules
- rewrite the component graph only
- resemble standard code motion optimizations
- Ideal for optimizing aspect weavers.
- e.g. RG
18Comparison
System
terminating
deterministic
aspect graph
Aspect Fragment Matching
Aspect-relating
yes
yes
yes
Aspect-additive
if exhaustive
yes
yes
Component-modifying
if exhaustive
usually not
yes
Aspects in Rules
depends
depends
no
Intra-Component
depends
depends
no
19Aspect Weaving is similar toProgram Optimization
- Graph rewriting can express many program
optimizations uniformly Aßm96. - Optimizations transform programs.
- Weavers transform programs.
- Claim
- Graph rewriting can express many aspect weavings
uniformly.
20Generating Tools from Rewrite Specification
Program data weaving rules
Optimix
Component Code
generates
Weaver
Aspect Code
generates
Program
21Conclusion
- GRS provide a uniform and formal way to specify
and classify aspect weavings. - Tool support for weavers.
- Open question
- How much of AOP can be covered by this approach?
22Rewriting or Meta-Programming
- Graph-rewriting rules are declarative.
- The component and aspect graphs are
(meta-)models of the program. - The derivations can also be implemented
explicitely by meta-programming.