CS代写 Week 7: Model-to-Model transformation – a better transformation pipeline

Week 7: Model-to-Model transformation – a better transformation pipeline
Dr Steffen Zschaler

Goals for today

Copyright By PowCoder代写 加微信 powcoder

Today we will look at ways of building more complex code generation
– How can we build more complicated transformations effectively and in a maintainable fashion? – Larger abstraction gap, optimisations, …
– What else can we do with our models?
28/02/2020 (c) King’s College London 2

An example problem

Constant folding in Turtle programs
Remember, we introduced expressions in Turtle programs?
– Actually, these are always constant values
– Because we’re not allowing variables to change values
28/02/2020 (c) King’s College London 4

Constant folding in Turtle programs
Remember, we introduced expressions in Turtle programs?
– Actually, these are always constant values
– Because we’re not allowing variables to change values
– Constant folding
– When an expression can be evaluated at “compile” time, do so – Improves efficiency of generated code
28/02/2020 (c) King’s College London 4

Constant folding in Turtle programs
Remember, we introduced expressions in Turtle programs?
– Actually, these are always constant values
– Because we’re not allowing variables to change values
– Constant folding
– When an expression can be evaluated at “compile” time, do so – Improves efficiency of generated code
– Rules of constant folding:
1. Literals remain literals
2. Expressions that have only constant sub-expressions are pre-calculated and replaced by the
resulting literal
3. Rinse and repeat until no more changes are made
– (Typically traverse the expression tree bottom up for efficiency)
28/02/2020 (c) King’s College London 4

In your pairs
– Extend your code generator to implement constant folding for all expressions
– Aim to build a reasonably modular implementation – remember you can use dispatch methods
You have 15 minutes
Download last step as tag DSML_v16_expression_types from the Turtles repository linked from KEATS
28/02/2020 (c) King’s College London 5

Maintainability?
This was actually the easy case:
– All expressions are always constant – variables can never change value – What if we added support for changing variable values?
– Maybe we want functions, too?
– Folding involves executing a series of commands at compile time…
What would it take to change our code generator to support this functionality?
How about if we also want to…
– … remove unnecessary pen move commands (e.g., sequences of pen up or pen down)? – … combine sequences of move or turn commands?
– Discuss in your pairs
You have 5 minutes
28/02/2020 (c) King’s College London 8

Complex code generators considered evil
This wasn’t really a good idea!
– Too much logic in the code generator
– Templates become difficult to understand
– Difficult to test generation and transformation logic independently
– Logic becomes difficult to maintain
– It gets easy to produce code that’s syntactically / semantically wrong
– Breaks single-responsibility principle
– That’s why compilers are built in passes: a sequence of transformation stages
28/02/2020 (c) King’s College London 10

Multi-stage code generation
Modelling Language
instance of
instance of
“Model to text transformation”
instance of
Text (aka program)
28/02/2020 (c) King’s College London
Generation Template
Programming Language

Multi-stage code generation
Modelling Language
instance of
instance of
instance of
Text (aka program)
28/02/2020 (c) King’s College London
Generation Template
Programming Language

Multi-stage code generation
Modelling Language
Modelling Language 2
Generation Template
Programming Language
instance of
instance of
instance of
instance of
Text (aka program)
Intermediary Model
28/02/2020 (c) King’s College London

Multi-stage code generation
Transformation Specification
Modelling Language
Modelling Language 2
Generation Template
Programming Language
instance of instance of instance of Model
“Model to model transformation”
instance of
instance of
Text (aka program)
Intermediary Model
28/02/2020 (c) King’s College London

Specifying M2M Transformations
Model-to-Model (M2M) Transformations
– Transform abstract syntax to abstract syntax – One or more input models
– One or more output models
Can be specified using
– Any GPL programming language
– Often referred to as imperative transformation specification – E.g., Xtend, Java
– A specialised transformation language
– Declarative: triple graph grammars, QVT-R (OMG standard)
– Imperative: QVT-O, Epsilon Object Language (EOL)
– Hybrid: ATLAS Transformation Language (ATL), Epsilon Transformation Language (ETL) ,
graph transformation (e.g., Henshin)
28/02/2020 (c) King’s College London 12

Approaches to transformation specification Imperative Declarative Hybrid
28/02/2020 (c) King’s College London

Approaches to transformation specification
Imperative
– Often in GPL language
Declarative
– Specialised language
– Specialised language
28/02/2020 (c) King’s College London

Approaches to transformation specification
Imperative
– Often in GPL language
– Methods implement creation
process of target model
Declarative
– Specialised language
– Rules describe relationship
between source and target
– Specialised language
– Rules describe relationship
between source and target
28/02/2020 (c) King’s College London

Approaches to transformation specification
Imperative
– Often in GPL language
– Methods implement creation
process of target model
– Creation of new model
– Setting of values
– Tracing and cross-references
– Scheduling of transformation
Declarative
– Specialised language
– Rules describe relationship
between source and target
– Without saying how one is
constructed from other
– Purely algebraic specification – Can be limiting at times
– Specialised language
– Rules describe relationship
between source and target
– Include imperative code for
setting values and cross-links – Mixed specification
– Can lead to more intuitive
28/02/2020 (c) King’s College London

Approaches to transformation specification
Imperative
– Often in GPL language
– Methods implement creation
process of target model
– Creation of new model
– Setting of values
– Tracing and cross-references
– Scheduling of transformation
– Easily integrated into other code
Declarative
– Specialised language
– Rules describe relationship
between source and target
– Without saying how one is
constructed from other
– Purely algebraic specification – Can be limiting at times
– Needs execution infrastructure
– Specialised language
– Rules describe relationship
between source and target
– Include imperative code for
setting values and cross-links – Mixed specification
– Can lead to more intuitive
– Needs execution infrastructure
28/02/2020 (c) King’s College London

Approaches to transformation specification
Imperative
– Often in GPL language
– Methods implement creation
process of target model
– Creation of new model
– Setting of values
– Tracing and cross-references
– Scheduling of transformation
– Easily integrated into other code
– Leaves everything to developer
Declarative
– Specialised language
– Rules describe relationship
between source and target
– Without saying how one is
constructed from other
– Purely algebraic specification – Can be limiting at times
– Needs execution infrastructure – Scheduling and updates
automatically determined
– Specialised language
– Rules describe relationship
between source and target
– Include imperative code for
setting values and cross-links – Mixed specification
– Can lead to more intuitive
– Needs execution infrastructure
– Scheduling automatically determined
28/02/2020 (c) King’s College London

Approaches to transformation specification
Imperative
– Often in GPL language
– Methods implement creation
process of target model
– Creation of new model
– Setting of values
– Tracing and cross-references
– Scheduling of transformation
– Easily integrated into other code
– Leaves everything to developer
– Can only create target model 28/02/2020 (c) King’s College London
Declarative
– Specialised language
– Rules describe relationship
between source and target
– Without saying how one is
constructed from other
– Purely algebraic specification – Can be limiting at times
– Needs execution infrastructure – Scheduling and updates
automatically determined
– Synchronise source and target
models, potentially both ways
– Specialised language
– Rules describe relationship
between source and target
– Include imperative code for
setting values and cross-links – Mixed specification
– Can lead to more intuitive
– Needs execution infrastructure
– Scheduling automatically determined
– Can only create target model

Approaches to transformation specification
Imperative
– Often in GPL language
– Methods implement creation
process of target model
– Creation of new model
– Setting of values
– Tracing and cross-references
– Scheduling of transformation
– Easily integrated into other code
– Leaves everything to developer
– Can only create target model
– No validation support
28/02/2020 (c) King’s College London
Declarative Hybrid
– Specialised language
– Rules describe relationship
between source and target
– Without saying how one is
constructed from other
– Purely algebraic specification – Can be limiting at times
– Needs execution infrastructure – Scheduling and updates
automatically determined
– Synchronise source and target
models, potentially both ways – Can be formally validated
– Specialised language
– Rules describe relationship
between source and target
– Include imperative code for
setting values and cross-links – Mixed specification
– Can lead to more intuitive
– Needs execution infrastructure
– Scheduling automatically determined
– Can only create target model
– Can be validated, full formal validation more difficult 13

ETL, an example hybrid transformation language
Epsilon Transformation Language
– A rule-based, hybrid transformation language – Developed at the University of York
– Part of the Eclipse approach to modelling
28/02/2020 (c) King’s College London 14

ETL, an example hybrid transformation language
Epsilon Transformation Language
– A rule-based, hybrid transformation language – Developed at the University of York
– Part of the Eclipse approach to modelling
Structure of an ETL transformation specification
– Each describes how one type of model element is translated into another
28/02/2020 (c) King’s College London 14

ETL, an example hybrid transformation language
Epsilon Transformation Language
– A rule-based, hybrid transformation language – Developed at the University of York
– Part of the Eclipse approach to modelling
Structure of an ETL transformation specification
– Each describes how one type of model element is translated into another
Declarative header: source and target model- element types
Control matching with @greedy annotation
28/02/2020 (c) King’s College London 14

ETL, an example hybrid transformation language
Epsilon Transformation Language
– A rule-based, hybrid transformation language – Developed at the University of York
– Part of the Eclipse approach to modelling
Structure of an ETL transformation specification
– Each describes how one type of model element is translated into another
28/02/2020 (c) King’s College London 14
Transform all instances of the Vote meta-class…

ETL, an example hybrid transformation language
Epsilon Transformation Language
– A rule-based, hybrid transformation language – Developed at the University of York
– Part of the Eclipse approach to modelling
Structure of an ETL transformation specification
…in the TVApp model.
– Each describes how one type of model element is translated into another
28/02/2020 (c) King’s College London 14

ETL, an example hybrid transformation language
Epsilon Transformation Language
– A rule-based, hybrid transformation language – Developed at the University of York
– Part of the Eclipse approach to modelling
Structure of an ETL transformation specification
– Each describes how one type of model element is translated into another
28/02/2020 (c) King’s College London 14
Imperative body: what to do when the rule is applied to transform a model element

ETL, an example hybrid transformation language
Epsilon Transformation Language
– A rule-based, hybrid transformation language – Developed at the University of York
– Part of the Eclipse approach to modelling
Structure of an ETL transformation specification
– Each describes how one type of model element is translated into another
28/02/2020 (c) King’s College London
Can use partial transformation results in rule body, using equivalent(), equivalents(), ::=

ETL, an example hybrid transformation language
Epsilon Transformation Language
– A rule-based, hybrid transformation language – Developed at the University of York
Invocation order of rules (scheduling) automatically determined
– Part of the Eclipse approach to modelling
Control with @lazy and @primary annotations
Structure of an ETL transformation specification
– Each describes how one type of model element is translated into another
– Implicit scheduling
28/02/2020 (c) King’s College London 14

ETL, an example hybrid transformation language
Epsilon Transformation Language
– A rule-based, hybrid transformation language – Developed at the University of York
– Part of the Eclipse approach to modelling
Structure of an ETL transformation specification
– Each describes how one type of model element is translated into another
– Implicit scheduling
ETL transformations are “out-place” transformations
– They produce a new model from an existing one – Rather than changing the existing model directly
28/02/2020 (c) King’s College London 14

Creating and running ETL transformations
The practicalities…
– ETL transformations are specified in .etl files
– Create using the usual wizard
28/02/2020 (c) King’s College London 15

Creating and running ETL transformations
The practicalities…
– ETL transformations are specified in .etl files
– Create using the usual wizard
28/02/2020 (c) King’s College London 15

Creating and running ETL transformations
The practicalities…
– ETL transformations are specified in .etl files
– Create using the usual wizard
– Creates an editor with syntax highlighting and code
completions
– Not an Xtext editor, so some of the code completion
works slightly differently
28/02/2020 (c) King’s College London 15

Creating and running ETL transformations
The practicalities…
Selecting transform from the code-completion will create a rule – ETL transformations are specified in .etl files
template. Typing rul and hitting Ctrl+Space, annoyingly, won’t. – Create using the usual wizard
– Creates an editor with syntax highlighting and code completions
– Not an Xtext editor, so some of the code completion works slightly differently
28/02/2020 (c) King’s College London 15

Creating and running ETL transformations
The practicalities…
– ETL transformations are specified in .etl files
– Create using the usual wizard
– Creates an editor with syntax highlighting and code
completions
– Not an Xtext editor, so some of the code completion
works slightly differently
– Run your transformation from a launch configuration
– Right-click and choose “Run As/Run configurations…”
– Create a new “ETL Transformation” configuration – The source should be your .etl file
28/02/2020 (c) King’s College London 15

Creating and running ETL transformations
The practicalities…
– ETL transformations are specified in .etl files
– Create using the usual wizard
– Creates an editor with syntax highlighting and code
completions
– Not an Xtext editor, so some of the code completion
works slightly differently
– Run your transformation from a launch configuration
– Right-click and choose “Run As/Run configurations…”
– Create a new “ETL Transformation” configuration – The source should be your .etl file
– Under “Models” add the models to be transformed from and to
28/02/2020 (c) King’s College London 15

Creating and running ETL transformations
The practicalities…
– ETL transformations arEepsiploencisfuiepdpoirnts.metodlelfliilnegsplatforms other than
EMF. For this course, we stick with EMF models.
– Create using the usual wizard
– Creates an editor with syntax highlighting and code
completions
– Not an Xtext editor, so some of the code completion
works slightly differently
– Run your transformation from a launch configuration
– Right-click and choose “Run As/Run configurations…”
– Create a new “ETL Transformation” configuration – The source should be your .etl file
– Under “Models” add the models to be transformed from and to
28/02/2020 (c) King’s College London 15

Creating and running ETL transformations
The practicalities…
– ETL transformations are specified in .etl files
– Create using the usual wizard
– Creates an editor with syntax highlighting and code
completions
– Not an Xtext editor, so some of the code completion
works slightly differently
– Run your transformation from a launch configuration
– Right-click and choose “Run As/Run configurations…”
– Create a new “ETL Transformation” configuration – The source should be your .etl file
– Under “Models” add the models to be transformed from and to
28/02/2020 (c) King’s College London 15

Creating and running ETL transformations
This is how the model will be identified inside your transformation. When referencing a meta-class in your transformation, use Source!ClassName
The practicalities…
to refer to meta-class ClassName in model Source.
– ETL transformations are specified in .etl files
– Create using the usual wizard
– Creates an editor with syntax highlighting and code
completions
– Not an Xtext editor, so some of the code completion
works slightly differently
– Run your transformation from a launch configuration
– Right-click and choose “Run As/Run configurations…”
– Create a new “ETL Transformation” configuration – The source should be your .etl file
– Under “Models” add the models to be transformed from and to
28/02/2020 (c) King’s College London 15

Creating and running ETL transformations
The practicalities…
– ETL transformations are specified in .etl files
– Create using the usual wizard
– Creates an editor with syntax highlighting and code
completions
– Not an Xtext editor, so some of the code completion
works slightly differently
Browse the workspace to find an existing model file (for input models). The metamodels section will be filled automatically.
– Create a new “ETL Transformation” configuration – The source should be your .etl file
– Under “Models” add the models to be transformed from and to
– Run your transformation from a launch configuration
– Right-click and choose “Run As/Run configurations…”
28/02/2020 (c) King’s College London 15

Creating and running ETL transformations
The practicalities…
– ETL transformations are specified in .etl files
– Create using the usual wizard
– Creates an editor with syntax highlighting and code
completions
– Not an Xtext editor, so some of the code completion
works slightly differently
– Run your transformation from a launch configuration
– Right-click and choose “Run As/Run
configurations…”
– Create a new “ETL Transformation” configuration
– The source should be your .etl file
– Under “Models” add the models to be transformed
from and to
Select read-on-load for input models. Select store on disposal for output models.
28/02/2020 (c) King’s College London 15

In your pairs
– Create an ETL transformation:
– Takes a TurtleProgram as input

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com