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