Page tree
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 17 Next »

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. 

Preliminaries

There's a few things to do before we dive into the tutorial itself. For example, to do Eclipse programming, you will have to get your hands on an Eclipse installation first. Read through the following sections to get ready for the tutorial tasks.

Required Software

As you're going to develop for KIELER SCCharts we recommend to use the semantic Oomph setup as described in Getting Eclipse (Oomph Setup). However, you could also install all componentes by yourself. Please consult the other tutorials if you want to do that. You would need to install the Modeling Tools and the Xtext SDK.

 

Additionally, install the EcoreViz from the Ecore Model Visualization category from the OpenKieler update site: http://rtsys.informatik.uni-kiel.de/~kieler/updatesite/nightly-openkieler/. For this, choose Install New Software... in the Help tab.

Due to the ongoing migration you have to install a workaround for EcoreViz to function. You have to install the KLighD diagram view directly from http://rtsys.informatik.uni-kiel.de/~kieler/updatesite/release_pragmatics_2016-02/. Select the features 

  • KIELER Lightweight Diagrams - Developer Resources and
  • KIELER Lightweight Diagrams Generic Diagram View.

(This step should be obsolete in the near future.)

 

 

 

Recommended Tutorials

We recommend that you have completed the following tutorials before diving into this one (or at least sweep over them). However, this is not a strict requirement.

  1. Eclipse Plug-ins and Extension Points
  2. Eclipse Modeling Framework (EMF)
    1. This tutorial needs the turingmachine.ecore and the controller you've implemented in the EMF tutorial. If you did not complete the EMF tutorial, you may download a working turing machine here... (in the future).
  3. Xtend 2 - Model Transformations

Helpful Tutorials

When developing within the KIELER semantics team, you will most likely be confronted with Xtext and Lightweight Diagrams (KLighD). The following tutorials may be helpful but not required for this tutorial.

  1. Xtext 2 - Creating a Grammar from Scratch
  2. Lightweight Diagrams (KLighD)

Finding Documentation

You can find additional documentation to the aforementioned topics in the corresponding tutorials. If you get stuck with a particular topic, please consult that tutorial. For SCCharts, you should read the SCCharts confluence page in our wiki: SCCharts

As usual, documentation often gets obsolete or wrong if not maintained regularly, so please, if you find missing, misleading, or outdated information, please let us know.

Additionally, the following list will give a short overview over the most important publications:

  • Main paper:
    Reinhard von Hanxleden and Björn Duderstadt and Christian Motika and Steven Smyth and Michael Mendler and Joaquín Aguado and Stephen Mercer and Owen O’Brien. SCCharts: Sequentially Constructive Statecharts for Safety-Critical Applications. In 
    Proc. ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI’14), Edinburgh, UK, June 2014. ACM.  pdftalkbib
  • SLIC Compilation:
    Christian Motika and Steven Smyth and Reinhard von Hanxleden. Compiling SCCharts—A Case-Study on Interactive Model-Based Compilation. In Proceedings of the 6th International Symposium on Leveraging Applications of Formal Methods, Verification and Validation (ISoLA 2014), volume 8802 of LNCS, page 443–462, Corfu, Greece, October 2014.  The original publication is available at http://link.springer.compdfbib
  • Theoretical Foundations:
    Reinhard von Hanxleden and Michael Mendler and Joaquín Aguado and Björn Duderstadt and Insa Fuhrmann and Christian Motika and Stephen Mercer and Owen O’Brien and Partha Roop. Sequentially Constructive Concurrency—A Conservative Extension of the Synchronous Model of Computation. ACM Transactions on Embedded Computing Systems, Special Issue on Applications of Concurrency to System Design, 13(4s):144:1–144:26, July 2014.  pdfbib
  • Overview and High-Level Transformations in Detail:
    Reinhard von Hanxleden and Björn Duderstadt and Christian Motika and Steven Smyth and Michael Mendler and Joaquín Aguado and Stephen Mercer and Owen O’Brien. SCCharts: Sequentially Constructive Statecharts for Safety-Critical Applications. Technical Report 1311, Christian-Albrechts-Universität zu Kiel, Department of Computer Science, December 2013. ISSN 2192-6247.  pdfbib

 

The SCCharts Metamodel

Navigate to the models folder of the plugin de.cau.cs.kieler.sccharts. Here, open the sccharts.ecore and right-click on the sccharts.ecore file and select Visualize Ecore Model. Since you also installed EcoreViz from the OpenKieler Suite, you should now see a graphical representation of the SCCharts metamodel. Every SCChart will be a model of this metamodel. 

To see all class information check Attributes/Literals in the Diagram Options on the right. 

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.

Try to understand most parts of the metamodel. You don't have to understand every detail but you should get the idea.

Model Task

  1. Answer the following questions
    1. How do you describe a superstate in the model?
    2. Outline the relationship between states, regions, transitions, and valued objects.
    3. Name the class of the root element of an SCChart.
    4. What is a valued object?
    5. How do you get the type of an interface variable?
    6. What other metamodels are needed for the SCCharts metamodel and write down which one is needed for what?
  2. Write down (on paper, text editor, etc) how the following SCChart models look like
    1. Open the wiki page that explains the Textual SCCharts Language SCT.
    2. Search the SCChart, Initial State, State, Transition and Immediate Transition example and ...
      1. write down (on paper or text editor, etc) how the model of that SCChart looks like.
      2. The user now marks C as final. What has to be changed in the model? What semantic problem do you see?
    3. Now, navigate to the Super State: Strong Abort Transition example. Write down (on paper) how the model of that SCCharts looks like.
    4. And finally a more sophisticated model: Write down the model of ABO (from Examples).

 

KLighD Screenshots

By the way: You can right-click on the Diagram View surface and select Save as image... to create a screenshot!

Creating SCCharts Models Programmatically 

Creating a Test Project

We need a project for testing. Do the following:

  1. If you used the standard KIELER Oomph installation setup, create a new Working Set named Tutorial in the Package Explorer. Then...
  2. Create a new empty Plug-In Project.
  3. Add the project that contains the sccharts metamodel as a dependency of your new project through the Plugin Manifest Editor.
  4. 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.

Creating a Model

To create a model programmatically you cannot directly use the Java classes generated for the model. Instead, the main package contains interfaces for all of your model object classes. The impl package contains the actual implementation and the util package contains some helper classes. Do not instantiate objects directly by manually calling new. EMF generates a Factory to create new objects. The factory itself uses the singleton pattern to get access to it:

SCChartsFactory sccFactory = SCChartsFactory.eINSTANCE;
State state = sccFactory .createState();
Transition transition = sccFactory .createTransition();

Important: The SCCharts grammar is build on top of several other grammars. Therefore, not all language objects can be found in the SCCharts factory. For example, all expression elements are part of the KExpressions grammar and hence, have their own factory. If you need other factories, don't forget to add the corresponding plugin to your plugin dependency list. 

KExpressionsFactory kFactory = KExpressionsFactory.eINSTANCE;
BoolValue boolValue = kFactory.createBoolValue();

For all simple attributes, there are getter and setter methods:

state.setId("Root");
boolValue.setValue(true);

Simple references (multiplicity of 1) also have getters and setters:

transition.setTrigger(boolValue);

List references (multiplicity of > 1) have only a list getter, which is used to manipulate the list:

state.getOutgoingTransitions().add(transition);

Plugin Dependencies

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.

Saving a Model

EMF uses the Eclipse Resource concept to save models to files and load models from files. It can use different Resource Factories that determine how exactly models are serialized. We will use the XMIResourceFactoryImpl to save our models to XML files:

  1. Add a dependency to the org.eclipse.emf.ecore.xmi plug-in.
  2. Use something like the following code to save the model from above:

    // Create a resource set.
    ResourceSet resourceSet = new ResourceSetImpl();
    
    // Register the default resource factory -- only needed for stand-alone!
    // this tells EMF to use XML to save the model
    resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(
        Resource.Factory.Registry.DEFAULT_EXTENSION, new SCTResourceFactoryImpl());
    // Get the URI of the model file.
    URI fileURI = URI.createFileURI(new File("myABO.sct").getAbsolutePath());
    
    // Create a resource for this file.
    Resource resource = resourceSet.createResource(fileURI);
    
    // Add the model objects to the contents.
    resource.getContents().add(myModel);
    
    // Save the contents of the resource to the file system.
    try
    {
        resource.save(Collections.EMPTY_MAP); // the map can pass special saving options to the operation
    } catch (IOException e) {
        /* error handling */
    }

Model Creation Task

With these information out of the way, on we go to some model creation:

  1. Programmatically create a valid model of ABO in the main() method.
  2. Run the main() method by right-clicking its class and selecting Run as -> Java Application. Note that this runs your main() 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.
  3. Execute the main method.
  4. Inspect your SCT file.
  5. Start your SCChart Editor Eclipse instance and load your SCT file. KLighD should now be able to visualize your ABO correctly.

 

Transforming SCCharts

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.

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.

scchart ABO_norm_HandleA {
  input output bool A;
  input output bool B;
  output bool O1;
  output bool O2;
    region HandleA:
    initial state WaitA
    --> _S immediate with A
    --> _Pause immediate;
    final state DoneA;
    state _S
    --> _S2 immediate with / B = true;
    state _S2
    --> DoneA immediate with / O1 = true;
    state _Pause
    --> _Depth;
    state _Depth
    --> _S immediate with A
    --> _Pause immediate;
}

The next figure depicts the direct mapping from normalized SCCharts to their corresponding SCG.

Inspect the metamodel of the SCGs in plugin de.cau.cs.kieler.scg. SCGs are used for analyses and optimization and include a lot of additional elements. However, for this tutorial it should be sufficient to look at the SCGraph class, its nodes attribute, the important node classes and the controlflow class. Important nodes for this SCG are entry, exit, assignment, conditional, 

Transformation Task

Write a transformation that transforms your normalized version of ABO's HandleA into its corresponding SCG.

  1. Writing a Model Transformation

    This time we want you to integrate your transformation into your SCCharts Editor instance. Therefore,... 

    1. Add a new package <project>.transformations to your project.
    2. Add an Xtend Class to the new package.
    3. 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 org.eclipse.xtext.xbase.lib, you can hover over the error with your mouse and have Eclipse add all libraries required by Xtend to your project.
    4. Define an entry method for the transformation that takes an SCChart program instance as an argument and returns an SCG Program. You can use the following (incomplete) method as a starting point:

       

      /**
       * Transforms a given SCCharts program into an SCG.
       *
      */
      def SCGraph transform(State rootState) {
          // Create the SCG
          val scg = SCGraphFactory::eINSTANCE.createSCGraph()
        
          // TODO: Your transformation code
        
          // Return the transformed program
          scg
      }

       

      There's a few points to note here:


      • Lines in Xtend code don't have to and with a semicolon.
      • We have been explicit about the method's return type, but we could have easily omitted it, letting Xtend infer the return type.
      • The keyword val declares a constant, while var declares a variable. Try to make do with constants where possible.
      • The methods you call should be declared as def private since they are implementation details and shouldn't be called by other classes.
      • 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, def create methods might offer a better alternative...

    5. 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. 
      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.
    6. 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.)

  2. 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. 
  3. Check your SCG semantically. Is there anything you could improve/optimize? 
    1. Write a second transformation (just as before) and add it to the transformation chain right after the transformation you already added. 
    2. Optimize the given SCG and compare the result with the previous one. 
    3. Make sure that the two SCGs are still semantically identical.

Congratulations! You finished the SCCharts Development Tutorial. Ask your supervisor for further instructions!

 

  • No labels