This is a light-weight tutorial for developing transformations/additions for SCCharts in KIELER. It will use Eclipse, EMF, and Xtend and therefore, finishing the corresponding tutorials could prove useful. However, they are not a strict requirement for this tutorial.
There's a few things to do before we dive into the tutorial itself. For example, to do Eclipse programming, you will have to get your hands on an Eclipse installation first. Read through the following sections to get ready for the tutorial tasks.
As you're going to develop for KIELER SCCharts, we recommend to use the Oomph setup as described in Getting Eclipse (Oomph Setup). However, you could also install all componentes by yourself. Please consult the other tutorials if you want to do that. You would need to install the Modeling Tools and the Xtext SDK.
Additionally, install the EcoreViz from the Ecore Model Visualization category from the OpenKieler update site: http://rtsys.informatik.uni-kiel.de/~kieler/updatesite/nightly-openkieler/. For this, choose Install New Software... in the Help tab.
Due to the ongoing migration you have to install a workaround for EcoreViz to function. You have to install the KLighD diagram view directly from http://rtsys.informatik.uni-kiel.de/~kieler/updatesite/release_pragmatics_2016-02/. Select the features
- KIELER Lightweight Diagrams - Developer Resources and
- KIELER Lightweight Diagrams Generic Diagram View.
(This step should be obsolete in the near future.)
We recommend that you have completed the following tutorials before diving into this one (or at least sweep over them). However, this is not a strict requirement.
- Eclipse Plug-ins and Extension Points
- Eclipse Modeling Framework (EMF)
- This tutorial needs the turingmachine.ecore and the controller you've implemented in the EMF tutorial. If you did not complete the EMF tutorial, you may download a working turing machine here... (in the future).
When developing within the KIELER semantics team, you will most likely be confronted with Xtext and Lightweight Diagrams (KLighD). The following tutorials may be helpful but not required for this tutorial.
You can find additional documentation to the aforementioned topics in the corresponding tutorials. If you get stuck with a particular topic, please consult that tutorial. For SCCharts, you should read the SCCharts confluence page in our wiki: SCCharts (pre 1.0)
As usual, documentation often gets obsolete or wrong if not maintained regularly, so please, if you find missing, misleading, or outdated information, please let us know.
Additionally, the following list will give a short overview over the most important publications:
- Main paper:
Reinhard von Hanxleden and Björn Duderstadt and Christian Motika and Steven Smyth and Michael Mendler and Joaquín Aguado and Stephen Mercer and Owen O’Brien. SCCharts: Sequentially Constructive Statecharts for Safety-Critical Applications. In Proc. ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI’14), Edinburgh, UK, June 2014. ACM. pdf, talk, bib
- SLIC Compilation:
Christian Motika and Steven Smyth and Reinhard von Hanxleden. Compiling SCCharts—A Case-Study on Interactive Model-Based Compilation. In Proceedings of the 6th International Symposium on Leveraging Applications of Formal Methods, Verification and Validation (ISoLA 2014), volume 8802 of LNCS, page 443–462, Corfu, Greece, October 2014. The original publication is available at http://link.springer.com. pdf, bib
- Theoretical Foundations:
Reinhard von Hanxleden and Michael Mendler and Joaquín Aguado and Björn Duderstadt and Insa Fuhrmann and Christian Motika and Stephen Mercer and Owen O’Brien and Partha Roop. Sequentially Constructive Concurrency—A Conservative Extension of the Synchronous Model of Computation. ACM Transactions on Embedded Computing Systems, Special Issue on Applications of Concurrency to System Design, 13(4s):144:1–144:26, July 2014. pdf, bib
- Overview and High-Level Transformations in Detail:
Reinhard von Hanxleden and Björn Duderstadt and Christian Motika and Steven Smyth and Michael Mendler and Joaquín Aguado and Stephen Mercer and Owen O’Brien. SCCharts: Sequentially Constructive Statecharts for Safety-Critical Applications. Technical Report 1311, Christian-Albrechts-Universität zu Kiel, Department of Computer Science, December 2013. ISSN 2192-6247. pdf, bib
Creating SCCharts Models Programmatically
Creating a Test Project
We need a project for testing. Do the following:
- If you used the standard KIELER Oomph installation setup, create a new Working Set named Tutorial in the Package Explorer. Then...
- Create a new empty Plug-In Project.
- Add the project that contains the sccharts metamodel as a dependency of your new project through the Plugin Manifest Editor.
- Create a simple Java class that implements a main method. Hint: In a new Java class, simply type main and hit Ctrl+Space. Eclipse content assist will create the method for you.
Creating a Model
To create a model programmatically you cannot directly use the Java classes generated for the model. Instead, the main package contains interfaces for all of your model object classes. The
impl package contains the actual implementation and the
util package contains some helper classes. Do not instantiate objects directly by manually calling
new. EMF generates a Factory to create new objects. The factory itself uses the singleton pattern to get access to it:
Important: The SCCharts grammar is build on top of several other grammars. Therefore, not all language objects can be found in the SCCharts factory. For example, all expression elements are part of the KExpressions grammar and hence, have their own factory. If you need other factories, don't forget to add the corresponding plugin to your plugin dependency list.
For all simple attributes, there are getter and setter methods:
Simple references (multiplicity of 1) also have getters and setters:
List references (multiplicity of > 1) have only a list getter, which is used to manipulate the list:
You may have noticed that is was not necessary to add a dependency for the kexpressions classes. The SCCharts plugin reexports the dependencies of the other EMF metamodels. Look at the plugin.xml in the SCCharts plugin in the dependency tab for more information.
Saving a Model
EMF uses the Eclipse Resource concept to save models to files and load models from files. It can use different Resource Factories that determine how exactly models are serialized. We will use the XMIResourceFactoryImpl to save our models to XML files:
Add a dependency to the
Don't worry. You will be experienced enough to add mandatory dependencies quickly in the future. However, for now just add the dependencies to proceed with the tutorial.
Use something like the following code to save the model from above:
File extensions are important! They define the parser/serializer that EMF uses. Always use the file extension that is defined for a particular model.
Model-to-Model Transformations between Metamodels
Transformations from one model to another may be performed within the same metamodel or from metamodel to a different metamodel. Both methods are used in KIELER and in principle they do not really differ in implementation. Nevertheless, if working within the same metamodel you should keep in mind that you're potentially changing the actual model instead of changing another instance (after copying). When transforming to another metamodel, you're always generating a new model. So there is no in-place transformation. Both is possible. Just make sure that you know what you're doing.
Now, you're going to transform the normalized form of HandleA from ABO to an SCG. The Sequentially Constructive Graph is a control-flow graph which can be seen as another representation of the same program. The SCG of the normalized version of ABO's HandleA is depicted on the right.
The next figure depicts the direct mapping from normalized SCCharts to their corresponding SCG.
Inspect the metamodel of the SCGs in plugin de.cau.cs.kieler.scg. SCGs are used for analyses and optimization and include a lot of additional elements. However, for this tutorial it should be sufficient to look at the SCGraph class, its nodes attribute, the important node classes and the controlflow class. Important nodes for this SCG are entry, exit, assignment, conditional,