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
-
... ... @@ -274,23 +274,17 @@ 274 274 275 275 {{layout-section ac:type="two_right_sidebar"}} 276 276 {{layout-cell}} 277 -= Model-to-Model Transformation swith KiCo =277 += Model-to-Model Transformation with KiCo = 278 278 279 -You can use the 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. 280 280 281 281 == Creating a new Transformation == 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. :) 284 -{{/layout-cell}} 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. :) 285 285 286 -{{layout-cell}} 287 287 288 -{{/layout-cell}} 289 -{{/layout-section}} 290 290 291 -{{layout-section ac:type="two_right_sidebar"}} 292 -{{layout-cell}} 293 -==== Transformation Creation Task ==== 287 +Transformation Creation Task 294 294 295 295 1. Therefore, create a new project within your tutorial working set as before. 296 296 1. Add plugin dependencies to {{code language="none"}}de.cau.cs.kieler.kico{{/code}} and {{code language="none"}}de.cau.cs.kieler.sccharts{{/code}}. ... ... @@ -317,14 +317,6 @@ 317 317 318 318 } 319 319 {{/code}} 320 - 321 -{{info title="Xtend Infos"}} 322 -* Lines in Xtend code don't have to and with a semicolon. 323 -* We have been explicit about the method's return type, but we could have easily omitted it, letting Xtend infer the return type. 324 -* 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. 325 -* 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. 326 -* 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... 327 -{{/info}} 328 328 ))) 329 329 1. ((( 330 330 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**. ... ... @@ -334,7 +334,7 @@ 334 334 {{/info}} 335 335 ))) 336 336 1. KiCo must know about the new feature and also about your new transformation. 337 -11. Add a new Xtend class with Feature as superclass. Add all unimplemented methods. Also set **sccharts.doubleStates**as Id.323 +11. Add a new Xtend class with Feature as superclass. Add all unimplemented methods. Also set sccharts.doubleStates as Id. 338 338 11. Go to the Extension tab inside your plugin configuration. 339 339 111. Add a new Extension Point de.cau.cs.kieler.kico.feature. Create a new featureClass and point it to your new feature class. 340 340 111. Also add a new Extension Point de.cau.cs.kieler.kico.transformation. Create a new productionTransformationClass and point it to your transformation class. ... ... @@ -344,71 +344,70 @@ 344 344 1111. label: Tutorial Compilation 345 345 1111. priority: 101 346 346 1111. preferred: (leave it blank) 347 -11. {{note title="Plugin Tasks"}}In general it is bad to mix non-ui plugins/tasks with ui plugin/tasks because (in the context ofKiCo) even ifyou'renot working with an active UI your transformations should work (e.g.acommand line compiler). To keepthistutorial simple,youcan add this dependency to yourplugin nevertheless. However, you shouldn't do this in real products. Always keep the UI separated.{{/note}}If you start yourKIELER instance now, you should get a new compilation chain which has only one transformation: yours, which doesn't do anything.333 +11. 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. 348 348 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. 349 -1. Now, fill your transformation with life: 350 -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. 351 -11. ((( 352 -Add thew following body to the function and try to understand the Xtend code. Import unknown class via code assist. 353 353 354 -{{code language="java" title="transform"}} 355 - def State transform(State rootState, KielerCompilerContext context) { 356 - val newState = SCChartsFactory.eINSTANCE.createState => [ 357 - id = "ololo" 358 - label = "ololo" 359 - ] 336 + 337 +{{/layout-cell}} 360 360 361 - rootState.regions.filter(ControlflowRegion).head.states += newState 339 +{{layout-cell}} 340 +[[image:attach:KielerSCTEditor.png]] 362 362 363 - rootState 364 - } 365 -{{/code}} 366 -))) 367 -11. When selecting your transformation, the SCChart gets transformed and looks like the version on the right. 368 -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. 369 -1. ((( 370 -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. 342 + 371 371 372 -{{code language="java" title="Code injection"}} 373 - @Inject 374 - extension SCChartsExtension 375 -{{/code}} 344 + 376 376 377 - Thereare 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.346 + 378 378 379 -{{note title="Extensions Naming Scheme"}} 380 -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. 381 -{{/note}} 382 -))) 383 -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. 348 + 384 384 385 - ==The existing Compilation Chain ==350 + 386 386 387 - 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.352 + 388 388 389 - 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!354 + 390 390 391 - //Wewill add more content to this subsection in the future...//356 + 392 392 393 393 394 -{{/layout-cell}} 395 395 396 -{{layout-cell}} 397 -[[image:attach:KielerSCTEditor.png]] 360 + 398 398 399 - [[image:attach:KielerSCTEditorOwnTransformation.png]]362 + 400 400 401 - [[image:attach:KielerSCTEditorOwnTransformationOlolo.png]]364 + 402 402 403 -[[image:attach:ABODoubleStates.png]] 366 + 367 + 368 + 369 + 370 + 371 + 372 + 373 + 374 + 375 + 376 + 377 + 378 + 379 + 380 + 381 + 382 + 383 + 384 + 385 + 386 + 387 + 388 +[[image:attach:KielerSCTEditorOwnTransformation.png]] 404 404 {{/layout-cell}} 405 405 {{/layout-section}} 406 406 407 407 {{layout-section ac:type="single"}} 408 408 {{layout-cell}} 409 -= Model-to-ModelTransformationsbetween Metamodels =394 += Transforming SCCharts = 410 410 411 -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.396 +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. 412 412 413 413 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. 414 414 ... ... @@ -441,29 +441,204 @@ 441 441 ((( 442 442 [[image:attach:abo_scg_HandleA.png]] 443 443 ))) 444 -{{/layout-cell}} 445 -{{/layout-section}} 446 446 447 -{{layout-section ac:type="two_equal"}} 448 -{{layout-cell}} 449 449 The next figure depicts the direct mapping from normalized SCCharts to their corresponding SCG. 450 450 451 -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, 452 -{{/layout-cell}} 453 - 454 -{{layout-cell}} 455 455 [[image:attach:sccharts-scg.png]] 456 -{{/layout-cell}} 457 -{{/layout-section}} 458 458 459 -{{layout-section ac:type="two_right_sidebar"}} 460 -{{layout-cell}} 461 -==== Transformation Creation Task 2 ==== 434 +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, 462 462 436 +==== Transformation Task ==== 437 + 463 463 Write a transformation that transforms your normalized version of ABO's HandleA into its corresponding SCG. 464 464 465 -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. 466 -1. Write a transformation that is able to transform {{code language="none"}}ABO_norm_HandleA{{/code}} into its corresponding SCG. 440 +1. ((( 441 +**Writing a Model Transformation** 442 + 443 +This time we want you to integrate your transformation into your SCCharts Editor instance. Therefore,... 444 +(% style="color: rgb(51,51,51);line-height: 1.66667;" %)\\ 445 + 446 +1. Add a new package 447 + 448 +{{code language="none"}} 449 +<project>.transformations 450 +{{/code}} to your project. 451 +1. Add an //Xtend Class// to the new package. 452 +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 453 + 454 +{{code language="none"}} 455 +org.eclipse.xtext.xbase.lib, 456 +{{/code}}you can hover over the error with your mouse and have Eclipse add all libraries required by Xtend to your project. 457 +1. 458 + 459 +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: 460 + 461 +((( 462 +(% class="syntaxhighlighter sh-confluence nogutter java" %) 463 +((( 464 + 465 + 466 +|((( 467 +(% class="container" title="Hint: double-click to select code" %) 468 +((( 469 +(% class="line number1 index0 alt2" %) 470 +((( 471 +{{code language="none"}} 472 +/** 473 +{{/code}} 474 +))) 475 + 476 +(% class="line number2 index1 alt1" %) 477 +((( 478 +{{code language="none"}} 479 + 480 +{{/code}} 481 + 482 +{{code language="none"}} 483 +* Transforms a given SCCharts program into an SCG. 484 +{{/code}} 485 +))) 486 + 487 +(% class="line number3 index2 alt2" %) 488 +((( 489 +{{code language="none"}} 490 + 491 +{{/code}} 492 + 493 +{{code language="none"}} 494 +* 495 +{{/code}} 496 +))) 497 + 498 +(% class="line number4 index3 alt1" %) 499 +((( 500 +{{code language="none"}} 501 +*/ 502 +{{/code}} 503 +))) 504 + 505 +(% class="line number8 index7 alt1" %) 506 +((( 507 +{{code language="none"}} 508 +def SCGraph transform(State rootState) { 509 +{{/code}} 510 +))) 511 + 512 +(% class="line number9 index8 alt2" %) 513 +((( 514 +{{code language="none"}} 515 + 516 +{{/code}} 517 + 518 +{{code language="none"}} 519 +// Create the SCG 520 +{{/code}} 521 +))) 522 + 523 +(% class="line number10 index9 alt1" %) 524 +((( 525 +{{code language="none"}} 526 + 527 +{{/code}} 528 + 529 +{{code language="none"}} 530 +val scg = SCGraphFactory::eINSTANCE.createSCGraph() 531 +{{/code}} 532 +))) 533 + 534 +(% class="line number11 index10 alt2" %) 535 +((( 536 +{{code language="none"}} 537 + 538 +{{/code}} 539 +))) 540 + 541 +(% class="line number12 index11 alt1" %) 542 +((( 543 +{{code language="none"}} 544 + 545 +{{/code}} 546 + 547 +{{code language="none"}} 548 +// TODO: Your transformation code 549 +{{/code}} 550 +))) 551 + 552 +(% class="line number13 index12 alt2" %) 553 +((( 554 +{{code language="none"}} 555 + 556 +{{/code}} 557 +))) 558 + 559 +(% class="line number14 index13 alt1" %) 560 +((( 561 +{{code language="none"}} 562 + 563 +{{/code}} 564 + 565 +{{code language="none"}} 566 +// Return the transformed program 567 +{{/code}} 568 +))) 569 + 570 +(% class="line number15 index14 alt2" %) 571 +((( 572 +{{code language="none"}} 573 + scg 574 +{{/code}} 575 +))) 576 + 577 +(% class="line number16 index15 alt1" %) 578 +((( 579 +{{code language="none"}} 580 +} 581 +{{/code}} 582 +))) 583 +))) 584 +))) 585 + 586 + 587 +))) 588 +))) 589 + 590 +((( 591 +(% class="syntaxhighlighter nogutter java" %) 592 +((( 593 +There's a few points to note here: 594 +))) 595 +))) 596 + 597 +\\ 598 + 599 +1. 600 +1*. Lines in Xtend code don't have to and with a semicolon. 601 +1*. We have been explicit about the method's return type, but we could have easily omitted it, letting Xtend infer the return type. 602 +1*. The keyword 603 + 604 +{{code language="none"}} 605 +val 606 +{{/code}} declares a constant, while 607 + 608 +{{code language="none"}} 609 +var 610 +{{/code}} declares a variable. Try to make do with constants where possible. 611 +1*. The methods you call should be declared as 612 + 613 +{{code language="none"}} 614 +def private 615 +{{/code}} since they are implementation details and shouldn't be called by other classes. 616 +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, 617 + 618 +{{code language="none"}} 619 +def create 620 +{{/code}}methods might offer a better alternative... 621 +\\ 622 +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. 623 +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. 624 +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.) 625 +\\ 626 +))) 467 467 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. 468 468 1. Check your SCG semantically. Is there anything you could improve/optimize? 469 469 11. Write a second transformation (just as before) and add it to the transformation chain right after the transformation you already added. ... ... @@ -474,9 +474,5 @@ 474 474 475 475 476 476 {{/layout-cell}} 477 - 478 -{{layout-cell}} 479 - 480 -{{/layout-cell}} 481 481 {{/layout-section}} 482 482 {{/layout}}
- Confluence.Code.ConfluencePageClass[0]
-
- Id
-
... ... @@ -1,1 +1,1 @@ 1 -168103 781 +16810368 - URL
-
... ... @@ -1,1 +1,1 @@ 1 -https://rtsys.informatik.uni-kiel.de/confluence//wiki/spaces/TUT/pages/168103 78/SCCharts Development1 +https://rtsys.informatik.uni-kiel.de/confluence//wiki/spaces/TUT/pages/16810368/SCCharts Development