Presentation is loading. Please wait.

Presentation is loading. Please wait.

CHART: An Approach for Non Invasive Model Transformation IPA Spring Days, April 18 th, 2012 Maarten de Mol 1, Arend Rensink 1, James J. Hunt 2 1 University.

Similar presentations


Presentation on theme: "CHART: An Approach for Non Invasive Model Transformation IPA Spring Days, April 18 th, 2012 Maarten de Mol 1, Arend Rensink 1, James J. Hunt 2 1 University."— Presentation transcript:

1 CHART: An Approach for Non Invasive Model Transformation IPA Spring Days, April 18 th, 2012 Maarten de Mol 1, Arend Rensink 1, James J. Hunt 2 1 University of Twente, Netherlands 2 Aicas GmbH, Karlsruhe, Germany CHART: An Approach for Non Invasive Graph Transformation

2 Graphs  Structured graphical diagram:  nodes  attributes  directed edges  multiplicity, ordered, …. Apr 18, 2012CHART 2 attribute Node attribute edge 1..*

3 Graph rules  Pair of graphs:  left-hand-side: matching  right-hand-side: updating Apr 18, 2012CHART 3 X X o X X o X X p X X

4 Graph rule application (1) Apr 18, 2012CHART 4 X X o X X o X X p X X X X o X X o X X o p

5 Graph rule application (2) Apr 18, 2012CHART 5 X X p X X X X o X X X X o X X X X o X X X X X X p X X X X o X X X X o X X X X o X X X X p p p p

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. 6 CHARTApr 18, 2012

7 Observation  Run-time data of an object oriented program:  objects  fields:  references  basic data 7 CHARTApr 18, 2012 data Object data reference

8 Observation  Run-time data of an object oriented program forms a graph:  objects → nodes  fields:  references → edges  basic data → attributes 8 CHARTApr 18, 2012 attribute Node attribute edge

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. 9 CHARTApr 18, 2012

10 Approach CHARTER Training 10 Rule Driven Transforme r Java Program Graph View Graph Rules Java Rules 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.

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. 11 CHARTApr 18, 2012

12 Example (annotated node) @Node public 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; } } 12 CHARTApr 18, 2012

13 Example (annotated edge, 1) @Node public class Book extends Readable { private final List writtenBy; public List getWrittenBy() { return this.writtenBy; } 13 CHARTApr 18, 2012

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 visitor) throws GraphException; @EdgeSize public int getNrAuthors(); } 14 CHARTApr 18, 2012

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 visitor) throws GraphException { return visitor.apply(getWrittenBy()); }... } 15 CHARTApr 18, 2012

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). 16 CHARTApr 18, 2012

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; } 17 CHARTApr 18, 2012

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; } 18 CHARTApr 18, 2012

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:]); } 19 CHARTApr 18, 2012

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, 2012CHART 20

21 Demo: hashi puzzle Apr 18, 2012CHART 21

22 Demo: hashi puzzle Apr 18, 2012CHART 22

23 Demo: hashi puzzle Apr 18, 2012CHART 23

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, 2012CHART 24

25 Conclusions  RDT allows graph transformation to be embedded in Java:  Embed ✓  Non invasive ✓  Geared towards Java programmers ✓  Efficient ≈ Apr 18, 2012CHART 25

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, 2012CHART 26

27 Questions Apr 18, 2012CHART 27


Download ppt "CHART: An Approach for Non Invasive Model Transformation IPA Spring Days, April 18 th, 2012 Maarten de Mol 1, Arend Rensink 1, James J. Hunt 2 1 University."

Similar presentations


Ads by Google