<
From version < 22.1 >
edited by ssm
on 2016/04/22 15:39
To version < 8.1 >
edited by ssm
on 2016/04/21 16:46
>
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -1,12 +1,10 @@
1 1  {{layout}}
2 2  {{layout-section ac:type="single"}}
3 3  {{layout-cell}}
4 +
5 +
4 4  This is a light-weight tutorial for developing 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.
5 5  
6 -
7 -
8 -{{toc/}}
9 -
10 10  = Preliminaries =
11 11  
12 12  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.
... ... @@ -19,8 +19,6 @@
19 19  
20 20  {{layout-section ac:type="three_equal"}}
21 21  {{layout-cell}}
22 -
23 -
24 24  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/>>url:http://rtsys.informatik.uni-kiel.de/~~kieler/updatesite/nightly-openkieler/||rel="nofollow" shape="rect"]]. For this, choose //Install New Software...// in the //Help// tab.
25 25  
26 26  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/>>url:http://rtsys.informatik.uni-kiel.de/~~kieler/updatesite/release_pragmatics_2016-02/||shape="rect"]]. Select the features
... ... @@ -32,16 +32,10 @@
32 32  {{/layout-cell}}
33 33  
34 34  {{layout-cell}}
35 -
36 -
37 37  [[image:attach:InstallEcoreViz.png]]
38 -
39 -
40 40  {{/layout-cell}}
41 41  
42 42  {{layout-cell}}
43 -
44 -
45 45  [[image:attach:InstallKLighDFeatures.png]]
46 46  {{/layout-cell}}
47 47  {{/layout-section}}
... ... @@ -84,57 +84,31 @@
84 84  * **Overview and High-Level Transformations in Detail:**
85 85  (% style="color: rgb(0,0,0);" %)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>>url:http://rtsys.informatik.uni-kiel.de/~~biblio/downloads/papers/report-1311.pdf||shape="rect"]](% style="color: rgb(0,0,0);" %), (%%)[[bib>>url:http://rtsys.informatik.uni-kiel.de/~~biblio/cgi-bin/bibcgi.cgi?key=vonHanxledenDM+13b||shape="rect"]]
86 86  
87 -
88 -{{/layout-cell}}
89 -{{/layout-section}}
90 -
91 -{{layout-section ac:type="two_right_sidebar"}}
92 -{{layout-cell}}
93 93  = The SCCharts Metamodel =
94 94  
95 -Navigate to the {{code language="none"}}models{{/code}} folder of the plugin {{code language="none"}}de.cau.cs.kieler.sccharts{{/code}}. Here, open the {{code language="none"}}sccharts.ecore{{/code}} and right-click on the {{code language="none"}}sccharts.ecore{{/code}} file and select //Visualize Ecore Model//. Since you also installed **EcoreViz** from the OpenKieler Suite, you should now see a graphical representation of the SCCharts metamodel. Every SCChart will be a model of this metamodel.
79 +Navigate to the {{code language="none"}}models{{/code}} folder of the plugin {{code language="none"}}de.cau.cs.kieler.sccharts{{/code}}. Here, open the {{code language="none"}}sccharts.ecore{{/code}} and right-click on the {{code language="none"}}sccharts.ecore{{/code}} file and select //Visualize Ecore Model//. Since you also installed **EcoreViz** from the OpenKieler Suite, you should now see a graphical representation of the SCCharts metamodel. Every SCChart will be a model of this metamodel.
96 96  
97 -To see all class information check //Attributes/Literals// in the Diagram Options on the right.
81 +IMAGE
98 98  
99 -EcoreViz gives you an overview over the selected Ecore diagram. However, Ecore model definitions may depend on other Ecore definitions that are not displayed in the diagram. You can open new diagrams for these Ecore files as described before or use the Ecore tree editor to inspect all classes.
100 -
101 101  Try to understand most parts of the metamodel. You don't have to understand every detail but you should get the idea.
102 102  
103 103  ==== Model Task ====
104 104  
105 -1. Answer the following questions
106 -11. How do you describe a superstate in the model?
107 -11. Outline the relationship between states, regions, transitions, and valued objects.\\
108 -11. Name the class of the root element of an SCChart.
109 -11. What is a valued object?
110 -11. How do you get the type of an interface variable?
111 -11. What other metamodels are needed for the SCCharts metamodel and write down which one is needed for what?
112 -1. Write down (on paper, text editor, etc) how the following SCChart models look like
113 -11. Open the wiki page that explains the [[doc:KIELER.Textual SCCharts Language SCT]].
114 -11. Search the //SCChart, Initial State, State, Transition and Immediate Transition //example and ...
87 +1. (% style="line-height: 20.0px;" %)Answer the following questions
88 +11. (% style="line-height: 20.0px;" %)Name the class of the root element of an SCChart
89 +11. (% style="line-height: 20.0px;" %)How do you describe a superstate in the model?
90 +11. (% style="line-height: 20.0px;" %)What is a valued object?
91 +11. (% style="line-height: 20.0px;" %)How do you get the type of an interface variable?
92 +11. Outline the relationship between states, regions, transitions, and valued objects
93 +11. (% style="line-height: 20.0px;" %)What other metamodels are needed for the SCCharts metamodel and write down which one is needed for what?
94 +1. (% style="line-height: 20.0px;" %)Write down (on paper, text editor, etc) how the following SCChart models look like
95 +11. (% style="line-height: 1.42857;" %)Open the wiki page that explains the [[doc:KIELER.Textual SCCharts Language SCT]].
96 +11. (% style="line-height: 1.4286; line-height: 1.4286" %)Search the (%%)//SCChart, Initial State, State, Transition and Immediate Transition //example and ...
115 115  111. write down (on paper or text editor, etc) how the model of that SCChart looks like.
116 116  111. The user now marks C as final. What has to be changed in the model? What semantic problem do you see?
117 -11. Now, navigate to the //Super State: Strong Abort Transition //example. Write down (on paper) how the model of that SCCharts looks like.
99 +11. (% style="line-height: 1.42857;" %)Now, navigate to the //Super State: Strong Abort Transition //example. Write down (on paper) how the model of that SCCharts looks like.
118 118  11. And finally a more sophisticated model: Write down the model of ABO (from [[doc:KIELER.Examples]]).
119 119  
120 -
121 -
122 -{{info title="KLighD Screenshots"}}
123 -By the way: You can //right-click// on the Diagram View surface and select //Save as image...// to create a screenshot!
124 -{{/info}}
125 -{{/layout-cell}}
126 -
127 -{{layout-cell}}
128 -[[image:attach:sccharts_metamodel.png]]
129 -
130 -[[image:attach:sccharts_metamodel_treeEditor.png]]
131 -
132 -[[image:attach:KLighDSaveAsImage.png]]
133 -{{/layout-cell}}
134 -{{/layout-section}}
135 -
136 -{{layout-section ac:type="single"}}
137 -{{layout-cell}}
138 138  = Creating SCCharts Models Programmatically =
139 139  
140 140  == Creating a Test Project ==
... ... @@ -141,7 +141,6 @@
141 141  
142 142  We need a project for testing. Do the following:
143 143  
144 -1. If you used the standard KIELER Oomph installation setup, create a new Working Set named Tutorial in the Package Explorer. Then...
145 145  1. Create a new empty //Plug-In Project//.
146 146  1. Add the project that contains the sccharts metamodel as a dependency of your new project through the //Plugin Manifest Editor//.
147 147  1. 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.
... ... @@ -148,12 +148,12 @@
148 148  
149 149  == Creating a Model ==
150 150  
151 -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 {{code language="none"}}impl{{/code}} package contains the actual implementation and the {{code language="none"}}util{{/code}} package contains some helper classes. Do not instantiate objects directly by manually calling {{code language="none"}}new{{/code}}. EMF generates a Factory to create new objects. The factory itself uses the singleton pattern to get access to it:
114 +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 {{code language="none"}}impl{{/code}} package contains the actual implementation and the {{code language="none"}}util{{/code}} package contains some helper classes. Do not instantiate objects directly by manually calling {{code language="none"}}new{{/code}}. EMF generates a Factory to create new objects. The factory itself uses the singleton pattern to get access to it:
152 152  
153 153  {{code language="java"}}
154 154  SCChartsFactory sccFactory = SCChartsFactory.eINSTANCE;
155 -State state = sccFactory.createState();
156 -Transition transition = sccFactory.createTransition();
118 +State state = sccFactory .createState();
119 +Transition transition = sccFactory .createTransition();
157 157  {{/code}}
158 158  
159 159  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.
... ... @@ -160,13 +160,13 @@
160 160  
161 161  {{code language="java"}}
162 162  KExpressionsFactory kFactory = KExpressionsFactory.eINSTANCE;
163 -BoolValue boolValue = kFactory.createBoolValue();
126 +BooleanValue boolValue = kFactory.createBooleanValue();
164 164  {{/code}}
165 165  
166 166  For all simple attributes, there are getter and setter methods:
167 167  
168 168  {{code language="java"}}
169 -state.setId("Init");
132 +state.setId("Root");
170 170  boolValue.setValue(true);
171 171  {{/code}}
172 172  
... ... @@ -179,25 +179,15 @@
179 179  List references (multiplicity of > 1) have only a list getter, which is used to manipulate the list:
180 180  
181 181  {{code language="java"}}
182 -state.getOutgoingTransitions().add(transition);
145 +state.outgoingTransitions.add(transition);
183 183  {{/code}}
184 184  
185 -{{info title="Plugin Dependencies"}}
186 -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.
187 -{{/info}}
188 -
189 189  == Saving a Model ==
190 190  
191 191  EMF uses the [[Eclipse Resource concept>>url:http://help.eclipse.org/juno/topic/org.eclipse.platform.doc.isv/guide/resInt.htm?cp=2_0_10||rel="nofollow" shape="rect" class="external-link"]] 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>>url:http://download.eclipse.org/modeling/emf/emf/javadoc/2.8.0/org/eclipse/emf/ecore/xmi/impl/XMIResourceFactoryImpl.html||rel="nofollow" shape="rect" class="external-link"]] to save our models to XML files:
192 192  
152 +1. Add a dependency to the {{code language="none"}}org.eclipse.emf.ecore.xmi{{/code}} plug-in.
193 193  1. (((
194 -Add a dependency to the {{code language="none"}}com.google.inject, org.eclipse.core.resources, {{/code}}and{{code language="none"}} de.cau.cs.kieler.sccharts.text{{/code}} plug-ins.
195 -
196 -{{info title="Additional Dependencies"}}
197 -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.
198 -{{/info}}
199 -)))
200 -1. (((
201 201  Use something like the following code to save the model from above:
202 202  
203 203  {{code language="java"}}
... ... @@ -204,10 +204,10 @@
204 204  // Create a resource set.
205 205  ResourceSet resourceSet = new ResourceSetImpl();
206 206  
207 -// Register the resource factory -- only needed for stand-alone!
208 -SctStandaloneSetup.doSetup();
209 -
210 - 
160 +// Register the default resource factory -- only needed for stand-alone!
161 +// this tells EMF to use XML to save the model
162 +resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(
163 + Resource.Factory.Registry.DEFAULT_EXTENSION, new SCTResourceFactoryImpl());
211 211  // Get the URI of the model file.
212 212  URI fileURI = URI.createFileURI(new File("myABO.sct").getAbsolutePath());
213 213  
... ... @@ -225,297 +225,251 @@
225 225   /* error handling */
226 226  }
227 227  {{/code}}
228 -
229 -{{info title="File Extensions"}}
230 -File extensions are important! They define the parser/serializer that EMF uses. Always use the file extension that is defined for a particular model.
231 -{{/info}}
232 232  )))
233 -{{/layout-cell}}
234 -{{/layout-section}}
235 235  
236 -{{layout-section ac:type="two_right_sidebar"}}
237 -{{layout-cell}}
238 238  ==== Model Creation Task ====
239 239  
240 -You are now equipped with the fundamentals you need to create models programmatically. Let's try it:
185 +With these information out of the way, on we go to some model creation:
241 241  
242 -1. The code fragments listed above do not suffice to create a grammatically correct model. Try to generate a model that corresponds with the serialized model listed on the right side.
243 -11. Run the {{code language="none"}}main(){{/code}} method by right-clicking its class and selecting (% style="line-height: 1.42857;" %)//Run as//(%%) -> (% style="line-height: 1.42857;" %)//Java Application//(%%). Note that this runs your {{code language="none"}}main(){{/code}} method as a simple Java program, not a complete Eclipse application. EMF models can be used in any simple Java context, not just in Eclipse applications.
244 -11. Execute the main method.
245 -11. (((
246 -Inspect your SCT file. (Press F5 to refresh your file view.)
247 -
248 -{{note title="Kext Warning"}}
249 -It is possible that kext generates a Null Pointer Exception when you save your model this way. This is a known issue. We're working on it. Just ignore it for now.
250 -{{/note}}
251 -)))
252 -1. Now, create a new Java class and proceed as before to generate a model of ABO in the {{code language="none"}}main(){{/code}} method.
187 +1. Programmatically create a valid model of ABO in the {{code language="none"}}main(){{/code}} method.
188 +1. Run the {{code language="none"}}main(){{/code}} method by right-clicking its class and selecting //Run as// -> //Java Application//. Note that this runs your {{code language="none"}}main(){{/code}} method as a simple Java program, not a complete Eclipse application. EMF models can be used in any simple Java context, not just in Eclipse applications.
189 +1. Execute the main method.
190 +1. Inspect your SCT file.
253 253  1. Start your SCChart Editor Eclipse instance and load your SCT file. KLighD should now be able to visualize your ABO correctly.
254 -11. For this, open tab //Run// and select// Run Configurations...//
255 -11. Create a new //Eclipse Application// and name it appropriately.
256 -11. As product select {{code language="none"}}de.cau.cs.kieler.core.product.product{{/code}}.
257 -11. Click //Run// (or //Debug// if you opened// Debug Configuration...//)
258 -11. Create a new project and add you generated model.
259 259  
260 -
261 -{{/layout-cell}}
193 += Transforming SCCharts =
262 262  
263 -{{layout-cell}}
264 -{{code language="java" title="Root.sct"}}
265 -scchart Root {
266 - initial state Init
267 - --> Init with true;
195 +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). Both is possible. Just make sure that you know what you're doing.
196 +
197 +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.
198 +
199 +|(((
200 +{{code}}
201 +scchart ABO_norm_HandleA {
202 + input output bool A;
203 + input output bool B;
204 + output bool O1;
205 + output bool O2;
206 + region HandleA:
207 + initial state WaitA
208 + --> _S immediate with A
209 + --> _Pause immediate;
210 + final state DoneA;
211 + state _S
212 + --> _S2 immediate with / B = true;
213 + state _S2
214 + --> DoneA immediate with / O1 = true;
215 + state _Pause
216 + --> _Depth;
217 + state _Depth
218 + --> _S immediate with A
219 + --> _Pause immediate;
268 268  }
269 269  {{/code}}
222 +)))|(((
223 +[[image:attach:abo_norm_HandleA.png]]
224 +)))|(% colspan="1" %)(% colspan="1" %)
225 +(((
226 +[[image:attach:abo_scg_HandleA.png]]
227 +)))
270 270  
271 -[[image:attach:RunConfiguration.png]]
272 -{{/layout-cell}}
273 -{{/layout-section}}
229 +The next figure depicts the direct mapping from normalized SCCharts to their corresponding SCG.
274 274  
275 -{{layout-section ac:type="two_right_sidebar"}}
276 -{{layout-cell}}
277 -= Model-to-Model Transformations with KiCo =
231 +[[image:attach:sccharts-scg.png]]
278 278  
279 -You can use the [[Kieler Compiler>>url:http://rtsys.informatik.uni-kiel.de/confluence/display/KIELER/Kieler+Compiler||shape="rect"]] (KiCo) to handle all the model input/output tasks and concentrate on the actual transformation. If you executed the **Model Creation Task correctly**, you should now have a complete running SCT Editor instance that looks like the one on the right. You should see the //KIELER Compiler Selection// n the lower right part of the working space. Here you can select specific transformations that will be applied to the actual model. Simply select a transformation to test it.
233 +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,
280 280  
281 -== Creating a new Transformation ==
235 +==== Transformation Task ====
282 282  
283 -Now, you're going to write your own transformation with **Xtend** *drumroll*, a programming language that looks very similar to Java, but which adds some very convenient features. Xtend code compiles to Java and and was developed using Xtext. In fact, once you gain experience working with Xtend you will probably appreciate the power of Xtext even more. Xtend is particularly useful to browse & modify EMF models. You get the point... we like it. :)
237 +Write a transformation that transforms your normalized version of ABO's HandleA into its corresponding SCG.
284 284  
285 -
239 +1. (((
240 +**Writing a Model Transformation**
286 286  
287 -==== Transformation Creation Task ====
242 +This time we want you to integrate your transformation into your SCCharts Editor instance. Therefore,...
243 +(% style="color: rgb(51,51,51);line-height: 1.66667;" %)\\
288 288  
289 -1. Therefore, create a new project within your tutorial working set as before.
290 -1. Add plugin dependencies to {{code language="none"}}de.cau.cs.kieler.kico{{/code}} and {{code language="none"}}de.cau.cs.kieler.sccharts{{/code}}.
291 -1. Create a new //Xtend class// in you package and name it "DoubleStates" and use {{code language="none"}}AbstractProductionTransformation{{/code}} as superclass.
292 -1. Here, you can automatically add the missing Xtend files by using the quickfix //Add Xtend lib to class path. //Alternatively you can simply add {{code language="none"}}com.google.guava{{/code}}, {{code language="none"}}org.eclipse.xtext.xbase.lib{{/code}}, {{code language="none"}}org.eclipse.xtend.lib{{/code}}, and {{code language="none"}}org.eclipse.xtend.lib.macro{{/code}} to you plugin dependencies.
293 -1. Click on //Add unimplemented methods//.
294 -1. (((
295 -Now, you should have a class similar to the following one.
245 +1. Add a new package 
296 296  
297 -{{code language="java"}}
298 -package tutorial.transformation
247 +{{code language="none"}}
248 +<project>.transformations
249 +{{/code}} to your project.
250 +1. Add an //Xtend Class// to the new package.
251 +1. If you notice that your new class is marked with an error marker because of a missing dependency of the new plug-in project to 
299 299  
300 -import de.cau.cs.kieler.kico.transformation.AbstractProductionTransformation
253 +{{code language="none"}}
254 +org.eclipse.xtext.xbase.lib, 
255 +{{/code}}you can hover over the error with your mouse and have Eclipse add all libraries required by Xtend to your project.
256 +1.
301 301  
302 -class DoubleStates extends AbstractProductionTransformation {
303 -
304 - override getProducedFeatureId() {
305 - throw new UnsupportedOperationException("TODO: auto-generated method stub")
306 - }
307 -
308 - override getId() {
309 - throw new UnsupportedOperationException("TODO: auto-generated method stub")
310 - }
311 -
312 -}
313 -{{/code}}
258 +Define an entry method for the transformation that takes an SCChart program instance as an argument and returns an SCG {{code language="none"}}Program{{/code}}. You can use the following (incomplete) method as a starting point:
314 314  
315 -{{info title="Xtend Infos"}}
316 -* Lines in Xtend code don't have to and with a semicolon.
317 -* We have been explicit about the method's return type, but we could have easily omitted it, letting Xtend infer the return type.
318 -* The keyword {{code language="none"}}val{{/code}} declares a constant, while {{code language="none"}}var{{/code}} declares a variable. Try to make do with constants where possible.
319 -* The methods you call should be declared as {{code language="none"}}def private{{/code}} since they are implementation details and shouldn't be called by other classes.
320 -* You may be tempted to add a few global variables that hold things like a global input variable or a pointer to the current state. While you could to that, {{code language="none"}}def create {{/code}}methods might offer a better alternative...
321 -{{/info}}
322 -)))
323 -1. (((
324 -As you can see, it is mandatory to add an id for the transformation and another id of the feature that this transformation produces. Name your transformation **tutorial.doubleStates **and the id of feature you want to produce is **sccharts.doubleStates**.
260 +(((
261 +(% class="syntaxhighlighter sh-confluence nogutter java" %)
262 +(((
263 +
325 325  
326 -{{info title="Programming Guidelines"}}
327 -You should really think about some constants here. You can also look at the sccharts transformation and features constants in the sccharts plugin.
328 -{{/info}}
265 +|(((
266 +(% class="container" title="Hint: double-click to select code" %)
267 +(((
268 +(% class="line number1 index0 alt2" %)
269 +(((
270 +{{code language="none"}}
271 +/**
272 +{{/code}}
329 329  )))
330 -1. KiCo must know about the new feature and also about your new transformation. 
331 -11. Add a new Xtend class with Feature as superclass. Add all unimplemented methods. Also set** sccharts.doubleStates** as Id.
332 -11. Go to the Extension tab inside your plugin configuration. 
333 -111. Add a new Extension Point de.cau.cs.kieler.kico.feature. Create a new featureClass and point it to your new feature class.
334 -111. Also add a new Extension Point de.cau.cs.kieler.kico.transformation. Create a new productionTransformationClass and point it to your transformation class.
335 -111. Finally, you have to link your transformation to the SCT Editor. Add the Extension point de.cau.cs.kieler.kico.ui.transformation. Create an editor link and fill in the following values:
336 -1111. editor: de.cau.cs.kieler.sccharts.text.sct.Sct
337 -1111. features: sccharts.doubleStates
338 -1111. label: Tutorial Compilation
339 -1111. priority: 101
340 -1111. preferred: (leave it blank)
341 -11. {{note title="Plugin Tasks"}}In general it is bad to mix non-ui plugins/tasks with ui plugin/tasks because (in the context of KiCo) even if you're not working with an active UI your transformations should work (e.g. a command line compiler). To keep this tutorial simple, you can add this dependency to your plugin nevertheless. However, you shouldn't do this in real products. Always keep the UI separated.{{/note}}If you start your KIELER instance now, you should get a new compilation chain which has only one transformation: yours, which doesn't do anything.
342 -1. If you want to rename your feature in the Compiler Selection (without changing its Id), override the getName method and return a new name. Rename your feature appropriately.
343 -1. Now, fill your transformation with life:
344 -11. Inside your transformation class, add a new method with the following signature: def State transform(State rootState, KielerCompilerContext context). This transformation will be executed if the feature is selected in the Compiler Selection.
345 -11. (((
346 -Add thew following body to the function and try to understand the Xtend code. Import unknown class via code assist.
347 347  
348 -{{code language="java" title="transform"}}
349 - def State transform(State rootState, KielerCompilerContext context) {
350 - val newState = SCChartsFactory.eINSTANCE.createState => [
351 - id = "ololo"
352 - label = "ololo"
353 - ]
275 +(% class="line number2 index1 alt1" %)
276 +(((
277 +{{code language="none"}}
278
279 +{{/code}}
354 354  
355 - rootState.regions.filter(ControlflowRegion).head.states += newState
356 -
357 - rootState
358 - }
281 +{{code language="none"}}
282 +* Transforms a given SCCharts program into an SCG.
359 359  {{/code}}
360 360  )))
361 -11. When selecting your transformation, the SCChart gets transformed and looks like the version on the right.
362 -1. Extend the transformation so that the transition is split up in two and connected via a transient state meaning that the original transformation should point to the new state and a new immediate transformation then points to the original target state. Try it out.
363 -1. (((
364 -Xtend supports extensions that can be used to extend the function set of you classes (i.e. models). Add {{code language="none"}}com.google.inject{{/code}} to the dependencies of your plugin. Now, add the following code fragment to the beginning of your class.
365 365  
366 -{{code language="java" title="Code injection"}}
367 - @Inject
368 - extension SCChartsExtension
286 +(% class="line number3 index2 alt2" %)
287 +(((
288 +{{code language="none"}}
289
369 369  {{/code}}
370 370  
371 -There are several Extensions classes within the KIELER project that extend the functionality of various classes. Basically, there are one or more for each metamodel (e.g. SCCharts, SCG, KExpressions, etc). You don't want to invent the wheel again. Use these methods. For example: there is a method that gives you all contained states of a state in a list: {{code language="none"}}getAllContainedStatesList{{/code}}. You can use it on your {{code language="none"}}rootState{{/code}}: {{code language="none"}}rootState.allContainedStatesList{{/code}}.
292 +{{code language="none"}}
293 +*
294 +{{/code}}
295 +)))
372 372  
373 -{{note title="Extensions Naming Scheme"}}
374 -Extensions are also just classes. You can add your own to improve the structure of your own projects. In KIELER all extensions end with "Extensions"; except SCChartsExtension for legacy reasons. This will be renamed in after the next snapshot to SCChartsExtensions. So, if you're going to add new extensions to the project, please name them accordingly.
375 -{{/note}}
297 +(% class="line number4 index3 alt1" %)
298 +(((
299 +{{code language="none"}}
300 +*/
301 +{{/code}}
376 376  )))
377 -1. Extend your transformation so that it is applied on all states (except the root state). Try your new transformation with ABO. The result should look like the example on the right.
378 378  
379 -== The existing Compilation Chain ==
304 +(% class="line number8 index7 alt1" %)
305 +(((
306 +{{code language="none"}}
307 +def SCGraph transform(State rootState) {
308 +{{/code}}
309 +)))
380 380  
381 -Congratulations. You added and executed your own KiCo transformation. Nevertheless, often you want to extend the existing compilation chain. To do this, you proceed as before but instead of creating your own compilation chain, you must modify the existing chains (e.g. the netlist compilation in de.cau.cs.kieler.sccharts.ui). To add a specific transformation at a specific point in the chain, you must tell KiCo what features are required for the transformation. For that you must override the method getRequiredFeatureIds and return a set with all required features.
311 +(% class="line number9 index8 alt2" %)
312 +(((
313 +{{code language="none"}}
314 +    
315 +{{/code}}
382 382  
383 -Also, if you're developing for the master chain, you should obey the package structure. Look at the sccharts plugins. All features, transformation, extensions, the metamodel, ui elements, etc are separated from each other. You should always do the same!
317 +{{code language="none"}}
318 +// Create the SCG
319 +{{/code}}
320 +)))
384 384  
385 -//We will add more content to this subsection in the future...//
322 +(% class="line number10 index9 alt1" %)
323 +(((
324 +{{code language="none"}}
325 +    
326 +{{/code}}
386 386  
387 -
388 -{{/layout-cell}}
328 +{{code language="none"}}
329 +val scg = SCGraphFactory::eINSTANCE.createSCGraph()
330 +{{/code}}
331 +)))
389 389  
390 -{{layout-cell}}
391 -[[image:attach:KielerSCTEditor.png]]
333 +(% class="line number11 index10 alt2" %)
334 +(((
335 +{{code language="none"}}
336 +  
337 +{{/code}}
338 +)))
392 392  
393 -
340 +(% class="line number12 index11 alt1" %)
341 +(((
342 +{{code language="none"}}
343 +    
344 +{{/code}}
394 394  
395 -
346 +{{code language="none"}}
347 +// TODO: Your transformation code
348 +{{/code}}
349 +)))
396 396  
397 -
351 +(% class="line number13 index12 alt2" %)
352 +(((
353 +{{code language="none"}}
354 +  
355 +{{/code}}
356 +)))
398 398  
399 -
358 +(% class="line number14 index13 alt1" %)
359 +(((
360 +{{code language="none"}}
361 +    
362 +{{/code}}
400 400  
401 -
364 +{{code language="none"}}
365 +// Return the transformed program
366 +{{/code}}
367 +)))
402 402  
403 -
369 +(% class="line number15 index14 alt2" %)
370 +(((
371 +{{code language="none"}}
372 +    scg
373 +{{/code}}
374 +)))
404 404  
405 -
376 +(% class="line number16 index15 alt1" %)
377 +(((
378 +{{code language="none"}}
379 +}
380 +{{/code}}
381 +)))
382 +)))
383 +)))
406 406  
407 407  
386 +)))
387 +)))
408 408  
409 -
410 -
411 -
412 -
413 -
414 -
415 -
416 -
417 -
418 -
419 -
420 -
421 -
422 -
423 -
424 -
425 -
426 -
427 -
428 -
429 -
430 -
431 -
432 -
433 -
434 -
435 -
436 -
437 -
438 -
439 -[[image:attach:KielerSCTEditorOwnTransformation.png]]
440 -
441 -[[image:attach:KielerSCTEditorOwnTransformationOlolo.png]]
442 -
443 -
444 -
445 -
446 -
447 -
448 -
449 -
450 -
451 -
452 -
453 -
454 -
455 -[[image:attach:ABODoubleStates.png]]
456 -{{/layout-cell}}
457 -{{/layout-section}}
458 -
459 -{{layout-section ac:type="single"}}
460 -{{layout-cell}}
461 -= Model-to-Model Transformations between Metamodels =
462 -
463 -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.
464 -
465 -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.
466 -
467 -|(((
468 -{{code}}
469 -scchart ABO_norm_HandleA {
470 - input output bool A;
471 - input output bool B;
472 - output bool O1;
473 - output bool O2;
474 - region HandleA:
475 - initial state WaitA
476 - --> _S immediate with A
477 - --> _Pause immediate;
478 - final state DoneA;
479 - state _S
480 - --> _S2 immediate with / B = true;
481 - state _S2
482 - --> DoneA immediate with / O1 = true;
483 - state _Pause
484 - --> _Depth;
485 - state _Depth
486 - --> _S immediate with A
487 - --> _Pause immediate;
488 -}
489 -{{/code}}
490 -)))|(((
491 -[[image:attach:abo_norm_HandleA.png]]
492 -)))|(% colspan="1" %)(% colspan="1" %)
493 493  (((
494 -[[image:attach:abo_scg_HandleA.png]]
390 +(% class="syntaxhighlighter nogutter java" %)
391 +(((
392 +There's a few points to note here:
495 495  )))
496 -{{/layout-cell}}
497 -{{/layout-section}}
394 +)))
498 498  
499 -{{layout-section ac:type="two_equal"}}
500 -{{layout-cell}}
501 -The next figure depicts the direct mapping from normalized SCCharts to their corresponding SCG.
396 +\\
502 502  
503 -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,
504 -{{/layout-cell}}
398 +1.
399 +1*. Lines in Xtend code don't have to and with a semicolon.
400 +1*. We have been explicit about the method's return type, but we could have easily omitted it, letting Xtend infer the return type.
401 +1*. The keyword 
505 505  
506 -{{layout-cell}}
507 -[[image:attach:sccharts-scg.png]]
508 -{{/layout-cell}}
509 -{{/layout-section}}
403 +{{code language="none"}}
404 +val
405 +{{/code}} declares a constant, while 
510 510  
511 -{{layout-section ac:type="two_right_sidebar"}}
512 -{{layout-cell}}
513 -==== Transformation Creation Task 2 ====
407 +{{code language="none"}}
408 +var
409 +{{/code}} declares a variable. Try to make do with constants where possible.
410 +1*. The methods you call should be declared as 
514 514  
515 -Write a transformation that transforms your normalized version of ABO's HandleA into its corresponding SCG.
412 +{{code language="none"}}
413 +def private
414 +{{/code}} since they are implementation details and shouldn't be called by other classes.
415 +1*. You may be tempted to add a few global variables that hold things like a global input variable or a pointer to the current state. While you could to that, 
516 516  
517 -1. Proceed as before. Create a new plugin (or copy your last one) Make sure, you also add de.cau.cs.kieler.scg to your dependencies.
518 -1. Write a transformation that is able to transform {{code language="none"}}ABO_norm_HandleA{{/code}} into its corresponding SCG.
417 +{{code language="none"}}
418 +def create 
419 +{{/code}}methods might offer a better alternative...
420 +\\
421 +1. Replace the TODO with an transformation code that takes an extended BF program and transforms it into an semantically equivalent BF program that only uses standard BF instructions. 
422 +HINT: Some of the extended BF commands can only be expressed by standard operations if you can write to other cells. Therefore you are allowed to perform side effects on the tape.
423 +1. Open the //Plug-In Manifest Editor// and switch to the Runtime tab. Add the package containing your transformation to the list of exported packages. (You may have to check the //Show non-Java packages// option in the //Exported Packages// dialog to see the package.)
424 +\\
425 +)))
519 519  1. **Verify your generated SCG**. If you added your transformation correctly, the SCG should be displayed automatically as soon as selected. If your SCG looks like the SCG depicted earlier, then everything is fine.
520 520  1. Check your SCG semantically. Is there anything you could improve/optimize? 
521 521  11. Write a second transformation (just as before) and add it to the transformation chain right after the transformation you already added.
... ... @@ -526,9 +526,5 @@
526 526  
527 527  
528 528  {{/layout-cell}}
529 -
530 -{{layout-cell}}
531 -
532 -{{/layout-cell}}
533 533  {{/layout-section}}
534 534  {{/layout}}
Confluence.Code.ConfluencePageClass[0]
Id
... ... @@ -1,1 +1,1 @@
1 -16810374
1 +16810299
URL
... ... @@ -1,1 +1,1 @@
1 -https://rtsys.informatik.uni-kiel.de/confluence//wiki/spaces/TUT/pages/16810374/SCCharts Development
1 +https://rtsys.informatik.uni-kiel.de/confluence//wiki/spaces/TUT/pages/16810299/SCCharts Development