<
From version < 37.1 >
edited by ssm
on 2016/04/22 16:59
To version < 14.1 >
edited by ssm
on 2016/04/21 17:01
>
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -1,7 +1,7 @@
1 1  {{layout}}
2 2  {{layout-section ac:type="single"}}
3 3  {{layout-cell}}
4 -is 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.
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 6  
7 7  
... ... @@ -13,7 +13,7 @@
13 13  
14 14  == Required Software ==
15 15  
16 -As you're going to develop for KIELER SCCharts, we recommend to use the Oomph setup as described in [[doc:KIELER.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.
16 +As you're going to develop for KIELER SCCharts we recommend to use the semantic Oomph setup as described in [[doc:KIELER.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.
17 17  {{/layout-cell}}
18 18  {{/layout-section}}
19 19  
... ... @@ -96,48 +96,47 @@
96 96  
97 97  To see all class information check //Attributes/Literals// in the Diagram Options on the right.
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 -{{task-list}}
106 -{{task id="1" status="incomplete"}}
107 -(% style="line-height: 1.42857;" %)Answer the following questions
103 +1. Answer the following questions
104 +11. Name the class of the root element of an SCChart
105 +11. How do you describe a superstate in the model?
106 +11. What is a valued object?
107 +11. How do you get the type of an interface variable?
108 +11. Outline the relationship between states, regions, transitions, and valued objects
109 +11. What other metamodels are needed for the SCCharts metamodel and write down which one is needed for what?
110 +1. Write down (on paper, text editor, etc) how the following SCChart models look like
111 +11. Open the wiki page that explains the [[doc:KIELER.Textual SCCharts Language SCT]].
112 +11. Search the //SCChart, Initial State, State, Transition and Immediate Transition //example and ...
113 +111. write down (on paper or text editor, etc) how the model of that SCChart looks like.
114 +111. The user now marks C as final. What has to be changed in the model? What semantic problem do you see?
115 +11. Now, navigate to the //Super State: Strong Abort Transition //example. Write down (on paper) how the model of that SCCharts looks like.
116 +11. And finally a more sophisticated model: Write down the model of ABO (from [[doc:KIELER.Examples]]).
108 108  
109 -1. How do you describe a superstate in the model?
110 -1. Outline the relationship between states, regions, transitions, and valued objects.\\
111 -1. Name the class of the root element of an SCChart.
112 -1. What is a valued object?
113 -1. How do you get the type of an interface variable?
114 -1. What other metamodels are needed for the SCCharts metamodel and write down which one is needed for what?
115 -{{/task}}
116 -
117 -{{task id="2" status="incomplete"}}
118 -Write down (on paper, text editor, etc) how the following SCChart models look like
119 -
120 -1. Open the wiki page that explains the [[doc:KIELER.Textual SCCharts Language SCT]].
121 -1. Search the //SCChart, Initial State, State, Transition and Immediate Transition //example and ...
122 -11. write down (on paper or text editor, etc) how the model of that SCChart looks like.
123 -11. The user now marks C as final. What has to be changed in the model? What semantic problem do you see?
124 -1. Now, navigate to the //Super State: Strong Abort Transition //example. Write down (on paper) how the model of that SCCharts looks like.
125 -1. And finally a more sophisticated model: Write down the model of ABO (from [[doc:KIELER.Examples]]).
126 -{{/task}}
127 -{{/task-list}}
128 -
129 129  
130 130  
131 131  {{info title="KLighD Screenshots"}}
132 -By the way: You can //right-click// on the Diagram View surface and select //Save as image...// to create a screenshot!
121 +By the way: You can //right-click// on the Diagram View surface to select //Save as image...// to create a screenshot!
133 133  {{/info}}
134 134  {{/layout-cell}}
135 135  
136 136  {{layout-cell}}
126 +
127 +
128 +
129 +
137 137  [[image:attach:sccharts_metamodel.png]]
138 138  
139 -[[image:attach:sccharts_metamodel_treeEditor.png]]
132 +
140 140  
134 +
135 +
136 +
137 +
138 +
139 +
141 141  [[image:attach:KLighDSaveAsImage.png]]
142 142  {{/layout-cell}}
143 143  {{/layout-section}}
... ... @@ -144,6 +144,18 @@
144 144  
145 145  {{layout-section ac:type="single"}}
146 146  {{layout-cell}}
146 +
147 +{{/layout-cell}}
148 +{{/layout-section}}
149 +
150 +{{layout-section ac:type="single"}}
151 +{{layout-cell}}
152 +
153 +{{/layout-cell}}
154 +{{/layout-section}}
155 +
156 +{{layout-section ac:type="single"}}
157 +{{layout-cell}}
147 147  = Creating SCCharts Models Programmatically =
148 148  
149 149  == Creating a Test Project ==
... ... @@ -150,7 +150,6 @@
150 150  
151 151  We need a project for testing. Do the following:
152 152  
153 -1. If you used the standard KIELER Oomph installation setup, create a new Working Set named Tutorial in the Package Explorer. Then...
154 154  1. Create a new empty //Plug-In Project//.
155 155  1. Add the project that contains the sccharts metamodel as a dependency of your new project through the //Plugin Manifest Editor//.
156 156  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.
... ... @@ -157,12 +157,12 @@
157 157  
158 158  == Creating a Model ==
159 159  
160 -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:
170 +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:
161 161  
162 162  {{code language="java"}}
163 163  SCChartsFactory sccFactory = SCChartsFactory.eINSTANCE;
164 -State state = sccFactory.createState();
165 -Transition transition = sccFactory.createTransition();
174 +State state = sccFactory .createState();
175 +Transition transition = sccFactory .createTransition();
166 166  {{/code}}
167 167  
168 168  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.
... ... @@ -169,13 +169,13 @@
169 169  
170 170  {{code language="java"}}
171 171  KExpressionsFactory kFactory = KExpressionsFactory.eINSTANCE;
172 -BoolValue boolValue = kFactory.createBoolValue();
182 +BooleanValue boolValue = kFactory.createBooleanValue();
173 173  {{/code}}
174 174  
175 175  For all simple attributes, there are getter and setter methods:
176 176  
177 177  {{code language="java"}}
178 -state.setId("Init");
188 +state.setId("Root");
179 179  boolValue.setValue(true);
180 180  {{/code}}
181 181  
... ... @@ -188,25 +188,15 @@
188 188  List references (multiplicity of > 1) have only a list getter, which is used to manipulate the list:
189 189  
190 190  {{code language="java"}}
191 -state.getOutgoingTransitions().add(transition);
201 +state.outgoingTransitions.add(transition);
192 192  {{/code}}
193 193  
194 -{{info title="Plugin Dependencies"}}
195 -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.
196 -{{/info}}
197 -
198 198  == Saving a Model ==
199 199  
200 200  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:
201 201  
208 +1. Add a dependency to the {{code language="none"}}org.eclipse.emf.ecore.xmi{{/code}} plug-in.
202 202  1. (((
203 -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.
204 -
205 -{{info title="Additional Dependencies"}}
206 -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.
207 -{{/info}}
208 -)))
209 -1. (((
210 210  Use something like the following code to save the model from above:
211 211  
212 212  {{code language="java"}}
... ... @@ -213,10 +213,10 @@
213 213  // Create a resource set.
214 214  ResourceSet resourceSet = new ResourceSetImpl();
215 215  
216 -// Register the resource factory -- only needed for stand-alone!
217 -SctStandaloneSetup.doSetup();
218 -
219 - 
216 +// Register the default resource factory -- only needed for stand-alone!
217 +// this tells EMF to use XML to save the model
218 +resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(
219 + Resource.Factory.Registry.DEFAULT_EXTENSION, new SCTResourceFactoryImpl());
220 220  // Get the URI of the model file.
221 221  URI fileURI = URI.createFileURI(new File("myABO.sct").getAbsolutePath());
222 222  
... ... @@ -234,359 +234,260 @@
234 234   /* error handling */
235 235  }
236 236  {{/code}}
237 -
238 -{{info title="File Extensions"}}
239 -File extensions are important! They define the parser/serializer that EMF uses. Always use the file extension that is defined for a particular model.
240 -{{/info}}
241 241  )))
242 -{{/layout-cell}}
243 -{{/layout-section}}
244 244  
245 -{{layout-section ac:type="two_right_sidebar"}}
246 -{{layout-cell}}
247 247  ==== Model Creation Task ====
248 248  
249 -You are now equipped with the fundamentals you need to create models programmatically. Let's try it:
241 +With these information out of the way, on we go to some model creation:
250 250  
251 -{{task-list}}
252 -{{task id="3" status="incomplete"}}
253 -(% style="line-height: 1.42857;" %)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.
254 -
255 -1. (% style="line-height: 1.42857;" %)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.
243 +1. Programmatically create a valid model of ABO in the {{code language="none"}}main(){{/code}} method.
244 +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.
256 256  1. Execute the main method.
257 -1. (((
258 -(% style="line-height: 1.42857;" %)Inspect your SCT file. (Press F5 to refresh your file view.)
246 +1. Inspect your SCT file.
247 +1. Start your SCChart Editor Eclipse instance and load your SCT file. KLighD should now be able to visualize your ABO correctly.
259 259  
260 -{{note title="Kext Warning"}}
261 -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.
262 -{{/note}}
263 -)))
264 -{{/task}}
249 += Transforming SCCharts =
265 265  
266 -{{task id="4" status="incomplete"}}
267 -Now, create a new Java class and proceed as before to generate a model of ABO in the 
251 +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.
268 268  
269 -{{code language="none"}}
270 -main()
271 -{{/code}}
253 +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.
272 272  
273 - method.
274 -{{/task}}
275 -
276 -{{task id="5" status="incomplete"}}
277 -(% style="line-height: 1.42857;" %)Start your SCChart Editor Eclipse instance and load your SCT file. KLighD should now be able to visualize your ABO correctly.(%%)\\
278 -
279 -1. For this, open tab //Run// and select// Run Configurations...//
280 -1. Create a new //Eclipse Application// and name it appropriately.
281 -1. As product select {{code language="none"}}de.cau.cs.kieler.core.product.product{{/code}}.
282 -1. Click //Run// (or //Debug// if you opened// Debug Configuration...//)
283 -1. Create a new project and add you generated model.
284 -{{/task}}
285 -{{/task-list}}
286 -
287 -
288 -{{/layout-cell}}
289 -
290 -{{layout-cell}}
291 -{{code language="java" title="Root.sct"}}
292 -scchart Root {
293 - initial state Init
294 - --> Init with true;
255 +|(((
256 +{{code}}
257 +scchart ABO_norm_HandleA {
258 + input output bool A;
259 + input output bool B;
260 + output bool O1;
261 + output bool O2;
262 + region HandleA:
263 + initial state WaitA
264 + --> _S immediate with A
265 + --> _Pause immediate;
266 + final state DoneA;
267 + state _S
268 + --> _S2 immediate with / B = true;
269 + state _S2
270 + --> DoneA immediate with / O1 = true;
271 + state _Pause
272 + --> _Depth;
273 + state _Depth
274 + --> _S immediate with A
275 + --> _Pause immediate;
295 295  }
296 296  {{/code}}
278 +)))|(((
279 +[[image:attach:abo_norm_HandleA.png]]
280 +)))|(% colspan="1" %)(% colspan="1" %)
281 +(((
282 +[[image:attach:abo_scg_HandleA.png]]
283 +)))
297 297  
298 -[[image:attach:RunConfiguration.png]]
299 -{{/layout-cell}}
300 -{{/layout-section}}
285 +The next figure depicts the direct mapping from normalized SCCharts to their corresponding SCG.
301 301  
302 -{{layout-section ac:type="two_right_sidebar"}}
303 -{{layout-cell}}
304 -= Model-to-Model Transformations with KiCo =
287 +[[image:attach:sccharts-scg.png]]
305 305  
306 -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.
289 +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,
307 307  
308 -== Creating a new Transformation ==
291 +==== Transformation Task ====
309 309  
310 -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. :)
311 -{{/layout-cell}}
293 +Write a transformation that transforms your normalized version of ABO's HandleA into its corresponding SCG.
312 312  
313 -{{layout-cell}}
314 -[[image:attach:KielerSCTEditor.png]]
315 -{{/layout-cell}}
316 -{{/layout-section}}
317 -
318 -{{layout-section ac:type="two_right_sidebar"}}
319 -{{layout-cell}}
320 -==== Transformation Creation Task ====
321 -
322 -{{task-list}}
323 -{{task id="6" status="incomplete"}}
324 -Create your first transformation...
325 -
326 -1. Create a new project within your tutorial working set as before.
327 -1. Add plugin dependencies to {{code language="none"}}de.cau.cs.kieler.kico{{/code}} and {{code language="none"}}de.cau.cs.kieler.sccharts{{/code}}.
328 -1. Create a new //Xtend class// in you package and name it "DoubleStates" and use {{code language="none"}}AbstractProductionTransformation{{/code}} as superclass.
329 -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.
330 -1. Click on //Add unimplemented methods//.
331 331  1. (((
332 -Now, you should have a class similar to the following one.
296 +**Writing a Model Transformation**
333 333  
334 -{{code language="java"}}
335 -package tutorial.transformation
298 +This time we want you to integrate your transformation into your SCCharts Editor instance. Therefore,...
299 +(% style="color: rgb(51,51,51);line-height: 1.66667;" %)\\
336 336  
337 -import de.cau.cs.kieler.kico.transformation.AbstractProductionTransformation
301 +1. Add a new package 
338 338  
339 -class DoubleStates extends AbstractProductionTransformation {
340 -
341 - override getProducedFeatureId() {
342 - throw new UnsupportedOperationException("TODO: auto-generated method stub")
343 - }
344 -
345 - override getId() {
346 - throw new UnsupportedOperationException("TODO: auto-generated method stub")
347 - }
348 -
349 -}
350 -{{/code}}
303 +{{code language="none"}}
304 +<project>.transformations
305 +{{/code}} to your project.
306 +1. Add an //Xtend Class// to the new package.
307 +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 
351 351  
352 -{{info title="Xtend Infos"}}
353 -* Lines in Xtend code don't have to and with a semicolon.
354 -* We have been explicit about the method's return type, but we could have easily omitted it, letting Xtend infer the return type.
355 -* 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.
356 -* 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.
357 -* 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...
358 -{{/info}}
359 -)))
360 -{{/task}}
309 +{{code language="none"}}
310 +org.eclipse.xtext.xbase.lib, 
311 +{{/code}}you can hover over the error with your mouse and have Eclipse add all libraries required by Xtend to your project.
312 +1.
361 361  
362 -{{task id="7" status="incomplete"}}
363 -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**.
314 +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:
364 364  
365 -{{info title="Programming Guidelines"}}
366 -You should really think about some constants here. You can also look at the sccharts transformation and features constants in the sccharts plugin.
367 -{{/info}}
368 -{{/task}}
369 -{{/task-list}}
370 -{{/layout-cell}}
371 -
372 -{{layout-cell}}
316 +(((
317 +(% class="syntaxhighlighter sh-confluence nogutter java" %)
318 +(((
373 373  
374 -{{/layout-cell}}
375 -{{/layout-section}}
376 376  
377 -{{layout-section ac:type="two_right_sidebar"}}
378 -{{layout-cell}}
379 -{{task-list}}
380 -{{task id="8" status="incomplete"}}
381 -KiCo must know about the new feature and also about your new transformation. 
321 +|(((
322 +(% class="container" title="Hint: double-click to select code" %)
323 +(((
324 +(% class="line number1 index0 alt2" %)
325 +(((
326 +{{code language="none"}}
327 +/**
328 +{{/code}}
329 +)))
382 382  
383 -1. Add a new Xtend class with Feature as superclass. Add all unimplemented methods. Also set** sccharts.doubleStates** as Id.
384 -1. Go to the Extension tab inside your plugin configuration. 
385 -11. Add a new Extension Point de.cau.cs.kieler.kico.feature. Create a new featureClass and point it to your new feature class.
386 -11. Also add a new Extension Point de.cau.cs.kieler.kico.transformation. Create a new productionTransformationClass and point it to your transformation class.
387 -11. 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:
388 -111. editor: {{code language="none"}}de.cau.cs.kieler.sccharts.text.sct.Sct{{/code}}
389 -111. features: sccharts.doubleStates
390 -111. label: Tutorial Compilation
391 -111. priority: 101
392 -111. preferred: (leave it blank)
393 -1. {{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.
394 -{{/task}}
331 +(% class="line number2 index1 alt1" %)
332 +(((
333 +{{code language="none"}}
334
335 +{{/code}}
395 395  
396 -{{task id="9" status="incomplete"}}
397 -If you want to rename your feature in the Compiler Selection (without changing its Id), override the
337 +{{code language="none"}}
338 +* Transforms a given SCCharts program into an SCG.
339 +{{/code}}
340 +)))
398 398  
342 +(% class="line number3 index2 alt2" %)
343 +(((
399 399  {{code language="none"}}
400 -getName
345 + 
401 401  {{/code}}
402 402  
403 - method and return a new name. Rename your feature appropriately.
404 -{{/task}}
405 -{{/task-list}}
406 -{{/layout-cell}}
348 +{{code language="none"}}
349 +*
350 +{{/code}}
351 +)))
407 407  
408 -{{layout-cell}}
409 -[[image:attach:KielerSCTEditorOwnTransformation.png]]
410 -{{/layout-cell}}
411 -{{/layout-section}}
353 +(% class="line number4 index3 alt1" %)
354 +(((
355 +{{code language="none"}}
356 +*/
357 +{{/code}}
358 +)))
412 412  
413 -{{layout-section ac:type="two_right_sidebar"}}
414 -{{layout-cell}}
415 -{{task-list}}
416 -{{task id="10" status="incomplete"}}
417 -Now, fill your transformation with life:
360 +(% class="line number8 index7 alt1" %)
361 +(((
362 +{{code language="none"}}
363 +def SCGraph transform(State rootState) {
364 +{{/code}}
365 +)))
418 418  
419 -1. Inside your transformation class, add a new method with the following signature: {{code language="none"}}def State transform(State rootState, KielerCompilerContext context){{/code}}. This transformation will be executed if the feature is selected in the Compiler Selection.
420 -1. (((
421 -Add thew following body to the function and try to understand the Xtend code. Import unknown class via code assist.
367 +(% class="line number9 index8 alt2" %)
368 +(((
369 +{{code language="none"}}
370 +    
371 +{{/code}}
422 422  
423 -{{code language="java" title="transform"}}
424 - def State transform(State rootState, KielerCompilerContext context) {
425 - val newState = SCChartsFactory.eINSTANCE.createState => [
426 - id = "ololo"
427 - label = "ololo"
428 - ]
373 +{{code language="none"}}
374 +// Create the SCG
375 +{{/code}}
376 +)))
429 429  
430 - rootState.regions.filter(ControlflowRegion).head.states += newState
378 +(% class="line number10 index9 alt1" %)
379 +(((
380 +{{code language="none"}}
381 +    
382 +{{/code}}
431 431  
432 - rootState
433 - }
384 +{{code language="none"}}
385 +val scg = SCGraphFactory::eINSTANCE.createSCGraph()
434 434  {{/code}}
435 435  )))
436 -1. When selecting your transformation, the SCChart gets transformed and looks like the version on the right.
437 -{{/task}}
438 438  
439 -{{task id="11" status="incomplete"}}
440 -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.
441 -{{/task}}
389 +(% class="line number11 index10 alt2" %)
390 +(((
391 +{{code language="none"}}
392 +  
393 +{{/code}}
394 +)))
442 442  
443 -{{task id="12" status="incomplete"}}
444 -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.
396 +(% class="line number12 index11 alt1" %)
397 +(((
398 +{{code language="none"}}
399 +    
400 +{{/code}}
445 445  
446 -{{code language="java" title="Code injection"}}
447 - @Inject
448 - extension SCChartsExtension
402 +{{code language="none"}}
403 +// TODO: Your transformation code
449 449  {{/code}}
405 +)))
450 450  
451 -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}}. There are also several convenient methods for creating model elements so that you don't have to use the factories directly.
407 +(% class="line number13 index12 alt2" %)
408 +(((
409 +{{code language="none"}}
410 +  
411 +{{/code}}
412 +)))
452 452  
453 -{{note title="Extensions Naming Scheme"}}
454 -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.
455 -{{/note}}
456 -{{/task}}
457 -{{/task-list}}
458 -{{/layout-cell}}
414 +(% class="line number14 index13 alt1" %)
415 +(((
416 +{{code language="none"}}
417 +    
418 +{{/code}}
459 459  
460 -{{layout-cell}}
461 -[[image:attach:KielerSCTEditorOwnTransformationOlolo.png]]
462 -{{/layout-cell}}
463 -{{/layout-section}}
420 +{{code language="none"}}
421 +// Return the transformed program
422 +{{/code}}
423 +)))
464 464  
465 -{{layout-section ac:type="two_right_sidebar"}}
466 -{{layout-cell}}
467 -{{task-list}}
468 -{{task id="13" status="incomplete"}}
469 -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.
470 -{{/task}}
471 -{{/task-list}}
425 +(% class="line number15 index14 alt2" %)
426 +(((
427 +{{code language="none"}}
428 +    scg
429 +{{/code}}
430 +)))
472 472  
473 -== The existing Compilation Chain ==
432 +(% class="line number16 index15 alt1" %)
433 +(((
434 +{{code language="none"}}
435 +}
436 +{{/code}}
437 +)))
438 +)))
439 +)))
474 474  
475 -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.
476 -
477 -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!
478 -
479 -//We will add more content to this subsection in the future...//
480 -
481 481  
482 -{{/layout-cell}}
442 +)))
443 +)))
483 483  
484 -{{layout-cell}}
485 -[[image:attach:ABODoubleStates.png]]
486 -
487 -
488 -
489 -
490 -
491 -
492 -{{/layout-cell}}
493 -{{/layout-section}}
494 -
495 -{{layout-section ac:type="single"}}
496 -{{layout-cell}}
497 -= Model-to-Model Transformations between Metamodels =
498 -
499 -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.
500 -
501 -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.
502 -
503 -|(((
504 -{{code}}
505 -scchart ABO_norm_HandleA {
506 - input output bool A;
507 - input output bool B;
508 - output bool O1;
509 - output bool O2;
510 - region HandleA:
511 - initial state WaitA
512 - --> _S immediate with A
513 - --> _Pause immediate;
514 - final state DoneA;
515 - state _S
516 - --> _S2 immediate with / B = true;
517 - state _S2
518 - --> DoneA immediate with / O1 = true;
519 - state _Pause
520 - --> _Depth;
521 - state _Depth
522 - --> _S immediate with A
523 - --> _Pause immediate;
524 -}
525 -{{/code}}
526 -)))|(((
527 -[[image:attach:abo_norm_HandleA.png]]
528 -)))|(% colspan="1" %)(% colspan="1" %)
529 529  (((
530 -[[image:attach:abo_scg_HandleA.png]]
446 +(% class="syntaxhighlighter nogutter java" %)
447 +(((
448 +There's a few points to note here:
531 531  )))
532 -{{/layout-cell}}
533 -{{/layout-section}}
450 +)))
534 534  
535 -{{layout-section ac:type="two_equal"}}
536 -{{layout-cell}}
537 -The next figure depicts the direct mapping from normalized SCCharts to their corresponding SCG.
452 +\\
538 538  
539 -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,
540 -{{/layout-cell}}
454 +1.
455 +1*. Lines in Xtend code don't have to and with a semicolon.
456 +1*. We have been explicit about the method's return type, but we could have easily omitted it, letting Xtend infer the return type.
457 +1*. The keyword 
541 541  
542 -{{layout-cell}}
543 -[[image:attach:sccharts-scg.png]]
544 -{{/layout-cell}}
545 -{{/layout-section}}
459 +{{code language="none"}}
460 +val
461 +{{/code}} declares a constant, while 
546 546  
547 -{{layout-section ac:type="two_right_sidebar"}}
548 -{{layout-cell}}
549 -==== Transformation Creation Task 2 ====
463 +{{code language="none"}}
464 +var
465 +{{/code}} declares a variable. Try to make do with constants where possible.
466 +1*. The methods you call should be declared as 
550 550  
551 -Write a transformation that transforms your normalized version of ABO's HandleA into its corresponding SCG.
468 +{{code language="none"}}
469 +def private
470 +{{/code}} since they are implementation details and shouldn't be called by other classes.
471 +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, 
552 552  
553 -{{task-list}}
554 -{{task id="14" status="incomplete"}}
555 -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.
556 -{{/task}}
557 -
558 -{{task id="15" status="incomplete"}}
559 -Write a transformation that is able to transform 
560 -
561 561  {{code language="none"}}
562 -ABO_norm_HandleA
563 -{{/code}}
474 +def create 
475 +{{/code}}methods might offer a better alternative...
476 +\\
477 +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. 
478 +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.
479 +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.)
480 +\\
481 +)))
482 +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.
483 +1. Check your SCG semantically. Is there anything you could improve/optimize? 
484 +11. Write a second transformation (just as before) and add it to the transformation chain right after the transformation you already added.
485 +11. Optimize the given SCG and compare the result with the previous one.
486 +11. Make sure that the two SCGs are still semantically identical.
564 564  
565 - into its corresponding SCG.
566 -{{/task}}
567 -
568 -{{task id="16" status="incomplete"}}
569 -**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.
570 -{{/task}}
571 -
572 -{{task id="17" status="incomplete"}}
573 -Check your SCG semantically. Is there anything you could improve/optimize? 
574 -
575 -1. Write a second transformation (just as before) and add it to the transformation chain right after the transformation you already added.
576 -1. Optimize the given SCG and compare the result with the previous one.
577 -1. Make sure that the two SCGs are still semantically identical.
578 -{{/task}}
579 -{{/task-list}}
580 -
581 -
582 -
583 583  Congratulations! You finished the SCCharts Development Tutorial. Ask your supervisor for further instructions!
584 584  
585 585  
586 586  {{/layout-cell}}
587 -
588 -{{layout-cell}}
589 -
590 -{{/layout-cell}}
591 591  {{/layout-section}}
592 592  {{/layout}}
Confluence.Code.ConfluencePageClass[0]
Id
... ... @@ -1,1 +1,1 @@
1 -16810391
1 +16810309
URL
... ... @@ -1,1 +1,1 @@
1 -https://rtsys.informatik.uni-kiel.de/confluence//wiki/spaces/TUT/pages/16810391/SCCharts Development
1 +https://rtsys.informatik.uni-kiel.de/confluence//wiki/spaces/TUT/pages/16810309/SCCharts Development