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
(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.
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
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:
We need a project for testing. Do the following:
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:
SCChartsFactory sccFactory = SCChartsFactory.eINSTANCE; State state = sccFactory.createState(); Transition transition = sccFactory.createTransition(); |
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.
KExpressionsFactory kFactory = KExpressionsFactory.eINSTANCE; BoolValue boolValue = kFactory.createBoolValue(); |
For all simple attributes, there are getter and setter methods:
state.setId("Init"); boolValue.setValue(true); |
Simple references (multiplicity of 1) also have getters and setters:
transition.setTrigger(boolValue); |
List references (multiplicity of > 1) have only a list getter, which is used to manipulate the list:
state.getOutgoingTransitions().add(transition); |
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. |
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 com.google.inject, org.eclipse.core.resources,
and de.cau.cs.kieler.sccharts.text
plug-ins.
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:
// Create a resource set. ResourceSet resourceSet = new ResourceSetImpl(); // Register the resource factory -- only needed for stand-alone! SctStandaloneSetup.doSetup(); // Get the URI of the model file. URI fileURI = URI.createFileURI(new File("myABO.sct").getAbsolutePath()); // Create a resource for this file. Resource resource = resourceSet.createResource(fileURI); // Add the model objects to the contents. resource.getContents().add(myModel); // Save the contents of the resource to the file system. try { resource.save(Collections.EMPTY_MAP); // the map can pass special saving options to the operation } catch (IOException e) { /* error handling */ } |
File extensions are important! They define the parser/serializer that EMF uses. Always use the file extension that is defined for a particular model. |
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,