Top Banner
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
27

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.

Dec 26, 2015

Download

Documents

Patrick Cannon
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 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.

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

Page 2: 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.

CHART 2

Graphs

Structured graphical diagram:

nodes

attributes

directed edges

multiplicity, ordered, ….

Apr 18, 2012

attribute

Node Node

attribute

edge 1..*

Page 3: 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.

CHART 3

Graph rules

Pair of graphs:

left-hand-side: matching

right-hand-side: updating

Apr 18, 2012

X

o

X

o

Xp

X

Page 4: 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.

CHART 4

Graph rule application (1)

Apr 18, 2012

X

o

X

o

Xp

X

X

o

X

o

X

o

p

Page 5: 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.

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

Page 6: 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.

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

Page 7: 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.

CHART 7

Observation

Run-time data of an object oriented program:

objects

fields:

references

basic data

Apr 18, 2012

data

Object Object

data

reference

Page 8: 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.

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

Page 9: 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.

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

Page 10: 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.

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.

Page 11: 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.

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

Page 12: 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.

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

Page 13: 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.

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

Page 14: 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.

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

Page 15: 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.

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

Page 16: 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.

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

Page 17: 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.

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

Page 18: 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.

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

Page 19: 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.

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

Page 20: 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.

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

Page 21: 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.

CHART 21

Demo: hashi puzzle

Apr 18, 2012

Page 22: 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.

CHART 22

Demo: hashi puzzle

Apr 18, 2012

Page 23: 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.

CHART 23

Demo: hashi puzzle

Apr 18, 2012

Page 24: 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.

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

Page 25: 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.

CHART 25

Conclusions

RDT allows graph transformation to be embedded in Java: Embed ✓ Non invasive ✓ Geared towards Java programmers ✓ Efficient ≈

Apr 18, 2012

Page 26: 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.

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

Page 27: 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.

CHART 27

Questions

Apr 18, 2012