Upload
patrick-cannon
View
219
Download
0
Embed Size (px)
Citation preview
CHART: An Approach for Non InvasiveModel Transformation
IPA Spring Days, April 18th, 2012
Maarten de Mol1, Arend Rensink1, James J. Hunt2
1 University of Twente, Netherlands
2 Aicas GmbH, Karlsruhe, Germany
CHART: An Approach for Non InvasiveGraph Transformation
CHART 2
Graphs
Structured graphical diagram:
nodes
attributes
directed edges
multiplicity, ordered, ….
Apr 18, 2012
attribute
Node Node
attribute
edge 1..*
CHART 3
Graph rules
Pair of graphs:
left-hand-side: matching
right-hand-side: updating
Apr 18, 2012
X
o
X
o
Xp
X
CHART 4
Graph rule application (1)
Apr 18, 2012
X
o
X
o
Xp
X
X
o
X
o
X
o
p
CHART 5
Graph rule application (2)
Apr 18, 2012
X
p X
X
o
X
X
o X
X
o
X
X
X p X
X
o
X X
o X
X
o
X
X
p p
p p
CHART 6
Overview
Idea: embed graph transformation in Java.
Our approach:
custom annotation language
custom transformation language (CHART)
custom compiler (RDT)
Demo: hashi puzzle.
User experiences.
Conclusions.
Apr 18, 2012
CHART 7
Observation
Run-time data of an object oriented program:
objects
fields:
references
basic data
Apr 18, 2012
data
Object Object
data
reference
CHART 8
Observation
Run-time data of an object oriented program forms a graph:
objects → nodes
fields:
references → edges
basic data → attributes
Apr 18, 2012
attribute
Node Node
attribute
edge
CHART 9
Idea
Use graph transformation to express manipulation of Java data.
Compile graph transformation to Java code.
Benefits:
Java: General purpose programming language.
GT: Special purpose transformation language.
Requirements:
Embed: arbitrarily mix Java code and GT code.
Non invasive: user code does not have to be modified.
Geared towards Java programmers: intended users.
Efficient: little or no performance loss compared to Java.
Apr 18, 2012
Approach
CHA
RTE
R
Trai
ning
10
Rule Driven Transformer
JavaProgram
GraphView
GraphRules
JavaRules RDT
annotate
compile
refer to
Extended Java Program
Start point: Java program with OO data.
Step 1: build graph view.
Step 2: write graph rules.
Step 3: compile rules into Java.
End point: extended Java program.
CHART 11
Step 1: build graph view
Purpose of graph view:
Select relevant data structures.
Provide additional meta information.
Custom annotation language.
How should the graph rules manipulate data?
Rely on user provided manipulation methods.
Nodes: create, delete, match, visit all.
Fields: add, remove, get one, set one, visit all, clear, replace, get
size, membership, get index.
Manipulate single elements only.
Implementation can choose collection type freely.
Apr 18, 2012
CHART 12
Example (annotated node)@Nodepublic class Author {
private final String name; public Author(String name) { this.name = name; }
@NodeCreate(inits = {“name”}) public static Author create(String name) { return new Author(name);
}
@AttributeGet public String getName() { return this.name; }}
Apr 18, 2012
CHART 13
Example (annotated edge, 1)@Nodepublic class Book extends Readable {
private final List<Author> writtenBy;
public List<Author> getWrittenBy() { return this.writtenBy; }}
Apr 18, 2012
CHART 14
Example (annotated edge, 2)@Edge(target = Author.class, isOrdered = true)public interface WrittenBy {
@EdgeAdd public void addAuthor(int index, Author author);
@EdgeGet public Author getAuthor(int index);
@EdgeVisit public GraphVisitor.CONTINUE visitAuthors( GraphVisitor<Author> visitor) throws GraphException;
@EdgeSize public int getNrAuthors();
}
Apr 18, 2012
CHART 15
Example (annotated edge, 3)public class Book implements WrittenBy {
...
@Override public Author getAuthor(int index) { return getWrittenBy().get(index); }
@Override public GraphVisitor.CONTINUE visitAuthors( GraphVisitor<Author> visitor) throws GraphException { return visitor.apply(getWrittenBy()); }
...
}
Apr 18, 2012
CHART 16
Step 2: write graph rules.
Custom transformation language: CHART.
Mix of graph transformation and Java.
Graph transformation influence:
Rule based.
Rule format: match -> update -> sequence.
Declarative matching (LHS of rule).
Simultaneous updating (RHS of rule).> sequence.
Java influence:
Textual Java-like syntax.
Imperative control structure (sequence block).
Apr 18, 2012
CHART 17
Example (rule, 1)rule Author{} findRich(int price) { Author{} authors; match (authors) { foreach (Author author : authors) { Comic comic; author elementof comic.writtenBy; comic.price > price; } } return authors;}
Apr 18, 2012
CHART 18
Example (rule, 2)rule void addPicture(Comic comic, Picture picture) {
int old_price;
match () { comic.price > 1; } update let { Comic new_comic = new Comic(); } in { new_comic.contains = comic.contains + [picture];
new_comic.price = comic.price; new_comic.writtenBy = comic.writtenBy; comic.price = comic.price – 1; old_price = comic.price; }
return old_price;}
Apr 18, 2012
CHART 19
Example (rule, 3)rule void addPictures(Comic comic, Picture[] pictures) { sequence { if (pictures.size > 0) { try { addPicture(comic, pictures[0]); addPictures(comic, pictures[1:]); } } }}
Apr 18, 2012
CHART 20
Step 3: compile graph rules.
RDT:
Rule Driven Transformer.
Written in Java.
Steps:
Analyze annotations (reflection).
Parse rules into internal representation (Antlr).
Optimize.
Produce code.
Apr 18, 2012
CHART 21
Demo: hashi puzzle
Apr 18, 2012
CHART 22
Demo: hashi puzzle
Apr 18, 2012
CHART 23
Demo: hashi puzzle
Apr 18, 2012
CHART 24
Experiences
Technology has been applied successfully in CHARTER project:
Aicas (JamaicaVM).
Atego (ArtisanStudio).
Chalmers (KeY).
Observations of Aicas:
More concise: reported 5-10 times less lines of code.
Easier to maintain and adapt.
Easy to experiment with different algorithms.
No efficiency loss.
With respect to old Java algorithm.
Apr 18, 2012
CHART 25
Conclusions
RDT allows graph transformation to be embedded in Java: Embed ✓ Non invasive ✓ Geared towards Java programmers ✓ Efficient ≈
Apr 18, 2012
CHART 26
Conclusions
RDT allows graph transformation to be embedded in Java: Embed ✓ Non invasive ✓ (requires ‘gluing code’)
Geared towards Java programmers ✓ Efficient ✓ (more experiments needed)
Apr 18, 2012
CHART 27
Questions
Apr 18, 2012