Difference between pages "EMF framework for Event-B/Extensibility Issues" and "The Use of Theories in Code Generation"

From Event-B
(Difference between pages)
Jump to navigationJump to search
imported>Colin
 
imported>Andy
 
Line 1: Line 1:
==Some Notes on extensibility related to EMF framework.==
+
== The Theory Plug-in ==
 +
The theory plug-in is used to add mathematical extensions to Rodin. The theories are created, and deployed, and can then be used in any models in the workspace. When dealing with implementation level models, such as in Tasking Event-B, we need to consider how to translate newly added types and operators into code. We have augmented the theory interface with a Translation Rules section. This enables a user to define translation rules that map Event-B formulas to code.
 +
=== Translation Rules===
 +
Figure 1 shows the interface, and some translations rules of the mapping to Ada.
  
===Extensibility in the Rodin Database.===
+
<div id="fig:Translation Rules">
The Rodin database can be extended with new element types by creating new Java classes that follow the pattern of the Event-B ones. This relies on the programmer creating the Java correctly.
+
<br/>
The new elements are then 'registered' via an extension point so that the database knows about them.
+
[[Image:TheoryCGRules.png|center||caption text]]
Attributes can also be added via an extension point.
+
<center>'''Figure 1''': Translation Rules</center>
The database is minimally structured with all elements contained in a 'children' collection. Methods are then provided to simulate a structure by returning all child elements of a particular kind.
+
<br/>
(note that this has the limitation that it is not possible to have two different collections which contain the same kind of element)
+
</div>
  
This approach has the advantage that it can be extended in any way (apart from the limitation noted above). However it is a very implementation-oriented view. That is, it would be nicer if extenders could work at a more model-oriented level and not have to understand (and get right) details about the coding of the database.
+
The translation rules are templates used for pattern matching. The meta-variables are defined and typed, and used in the rules. Event-B expressions and predicates are defined on the left hand side of the rule, and the code to be output (as text) appears on the right hand side of the matching rule.
 
 
EMF provides a more model oriented approach by allowing the extender to create a declarative abstract syntax (a meta-model) from which code is automatically generated. It is often necessary to 'tweak' the code with customisations but the situation is greatly improved.  
 
 
 
===Extensibility of the EMF framework for Event-B===
 
However, extensibility in EMF is currently being investigated.
 
 
 
It is possible to extend models by subclassing their elements and, for example, adding new attributes and collections to this subclass. However, this does not work retrospectively for previously created models. Also, extensions are effectively disjoint since an element cannot simultaneously be an instance of two or more subclasses.
 
 
 
When the Event-B EMF framework was created, we added a meta-class, 'Extension' and a collection, 'extensions' to the base element. The idea was that extenders could subclass this Extension class and thereby add new model features anywhere. This works, but is not very satisfactory for two reasons. Firstly it introduces an unnatural intermediate modelling artefact because the Extension element should really be the same element as its parent. Secondly, once an extension is defined there is no way of limiting who can own it. This means that the extension can be added to every kind of element in the rest of the model including all the new elements in the extension.
 
 
 
Another approach is now under investigation.
 
This is to define the new meta-model including all new element kinds but omitting the containment that attaches it to the existing meta-model. This containment is then defined in an extension point, giving the allowed type of the owner and some EMF details about the properties of the EReference (multiplicity etc.). The core model package will then (via some additional custom code) read all extensions of this extension point and, if any have parent elements in the core package, dynamically extend the core package with a containment to attach the extension meta-model. All Extension plug-ins should also look for relevant extensions of themselves in a similar way.
 
 
 
===Extending Presentation===
 
The Rodin platform already provides an extension point for defining presentation of model elements and attributes. This extension point however, links information to Rodin elements. We require the same information linked to EMF model elements. Of course, EMF elements are synchronised with rodin elements, but this is only updated at save time. Several options exist:
 
 
 
* Replicate the current extension point but linking to EMF models.
 
* Use the existing Rodin extension point mapping to the EMF element via its dynamic synchronisation with rodin elements. It would be necessary to tighten the synchronisation between EMF and Rodin elements so that they are kept in step at all times (see discussion below).
 
* Use the existing Rodin extension point mapping to the EMF element via a static type mapping with rodin elements.
 
* Modify the existing Rodin extension to optionally specify an EMF element type in addition to the Rodin element type.
 
 
 
Question: does the existing Rodin extension point handle multiple collections of the same element type?
 
 
 
===Tighter Synchronisation===
 
TBD
 
 
 
===Instructions for creating an extension===
 
 
 
* Design an EMF meta model (ecore) of your extension's abstract syntax. The model should NOT deal with ownership of the extension (i.e. where the extension is contained in the existing meta-models)
 
* Load and configure the gen model (this should be set for extensible providers) <still under investigation since extending provider would be the container which is defined dynamically now>
 
* Generate the code and edit code
 
* Customise the package initialiser with the code shown below to make your package extensible
 
* Add an extension to define the containment of the extension (the containment will be added dynamically to the meta-model being extended)
 
* Add extensions to declare new kinds of Rodin elements and attributes
 
* Write Java interfaces and classes for each new Rodin element
 
* Add extensions to declare synchronisers to persist your new meta-classes into Rodin elements.
 
* Write Java classes for each synchroniser
 
 
 
[[DynamicContainer|Some notes on an attempt to dynamically add a container to the existing meta-class]]
 

Revision as of 08:38, 15 May 2012

The Theory Plug-in

The theory plug-in is used to add mathematical extensions to Rodin. The theories are created, and deployed, and can then be used in any models in the workspace. When dealing with implementation level models, such as in Tasking Event-B, we need to consider how to translate newly added types and operators into code. We have augmented the theory interface with a Translation Rules section. This enables a user to define translation rules that map Event-B formulas to code.

Translation Rules

Figure 1 shows the interface, and some translations rules of the mapping to Ada.


caption text
Figure 1: Translation Rules


The translation rules are templates used for pattern matching. The meta-variables are defined and typed, and used in the rules. Event-B expressions and predicates are defined on the left hand side of the rule, and the code to be output (as text) appears on the right hand side of the matching rule.