Implementing an OCL 2.0 Compiler for ... - ResearchGate
Implementing an OCL 2.0 Compiler for ... - ResearchGate
Implementing an OCL 2.0 Compiler for ... - ResearchGate
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
source code. CodeDom has m<strong>an</strong>y adv<strong>an</strong>tages, <strong>for</strong> example, it supports the code<br />
generation <strong>for</strong> m<strong>an</strong>y l<strong>an</strong>guages, <strong>an</strong>d syntax checking in the generated source code<br />
c<strong>an</strong> be avoided, since CodeDom ensures that it is be syntactically correct in all<br />
cases.<br />
<strong>OCL</strong> constraints c<strong>an</strong> be of five base types: Initial Values, Derivation Rules,<br />
Invari<strong>an</strong>ts, Virtual Attribute or Operation Definitions <strong>an</strong>d OperationConstraints.<br />
The current implementation of the <strong>OCL</strong> compiler h<strong>an</strong>dles only the invari<strong>an</strong>t types<br />
in the code generation, because only this type of constraints c<strong>an</strong> be used to<br />
validate a static model (a model that c<strong>an</strong> not ch<strong>an</strong>ge its state). The non-invari<strong>an</strong>t<br />
types are sem<strong>an</strong>tically <strong>an</strong>alyzed, only the code generation steps does not compile<br />
them into source code.<br />
The generated source code should support the operation of the <strong>OCL</strong>-based types<br />
defined in the <strong>OCL</strong> specification. This me<strong>an</strong>s that either the generated source code<br />
should contain the operation logic, or a class library is required with the base<br />
classes, <strong>an</strong>d the source code inst<strong>an</strong>tiate the classes <strong>an</strong>d use them. The first solution<br />
is neither eleg<strong>an</strong>t, nor efficient, thus, VMTS uses the second solution. The<br />
compiler already has classes <strong>for</strong> the base types (recall the type in<strong>for</strong>mation<br />
checking part of the sem<strong>an</strong>tic step). These classes are extended with the necessary<br />
operations <strong>an</strong>d they are used in the implementation. Using theses classes the<br />
operations contained by the constraints c<strong>an</strong> easily be expressed in the C#<br />
l<strong>an</strong>guage. While the version of C# used in development does not support class<br />
templates, the implementation of the collection types is more complex, th<strong>an</strong> it<br />
would be with generics.<br />
The tr<strong>an</strong>s<strong>for</strong>mation of the syntax tree to the CodeDom tree is easy, because each<br />
node type has <strong>an</strong> appropriate code sequence i.e. CodeDom tree br<strong>an</strong>ch. Packages<br />
are tr<strong>an</strong>s<strong>for</strong>med to namespaces, contexts are realized with classes, <strong>an</strong>d constraint<br />
expression as public methods. Contexts have a self attribute that is used the same<br />
way as in the <strong>OCL</strong> expressions; this attribute is initialized in the constructor of the<br />
class. To h<strong>an</strong>dle the invari<strong>an</strong>ts simply, the context class has always a method<br />
(checkInvari<strong>an</strong>ts) that calls the methods of the invari<strong>an</strong>ts one after the other.<br />
There is only one decision left that deserves word in the Syntax tree to CodeDom<br />
tr<strong>an</strong>s<strong>for</strong>mation. The OclExpression c<strong>an</strong> be tr<strong>an</strong>s<strong>for</strong>med either to classes, methods,<br />
or simple code expressions. The simpler the generated CodeDom tree is, the faster<br />
the binary executer will be. If there is a separated class <strong>for</strong> every OclExpression,<br />
then the source code is well separated, easy-to-read, but it contains a lot of<br />
redund<strong>an</strong>cy. If the OclExpressions are h<strong>an</strong>dled as simple code expressions, then<br />
source code is very small, but neither user-friendly, nor easy to debug. There<strong>for</strong>e<br />
in VMTS the <strong>OCL</strong>Expressions are tr<strong>an</strong>slated as methods. This decision facilitate<br />
the code generation <strong>for</strong> complex OclExpressions like iterators.<br />
The source code generation based on a CodeDom tree is a simple function call,<br />
<strong>an</strong>d the .NET technology offers also functions to compile <strong>an</strong>d build the<br />
constructed source code.