Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

VIATRA2/GettingStarted/Creating Transformations

< VIATRA2‎ | GettingStarted
Revision as of 14:04, 23 February 2010 by Unnamed Poltroon (Talk) (link updates)

Creating Transformations

GTASM

Since precise model-based systems development is the primary application area of VIATRA2, it necessitates that (i) the model transformations are specified in a mathematically precise way, and (ii) these transformations are automated so that the target mathematical models can be derived fully automatically. For this purpose, VIATRA2 have chosen to integrate two popular, intuitive, yet mathematically precise rule-based specification formalisms [1] , namely, graph transformation (GT) and abstract state machines (ASM) to manipulated graph based models. This combined approach is often called as GTASM.

  • Graph patterns are the basic concept in defining model transformations within VIATRA2. A pattern is a collection of model elements arranged into a certain structure fulfilling additional constraints (as defined by attribute conditions or other patterns). Patterns can be matched on certain model instances
  • Graph transformation (GT) [2] provides a high-level rule and pattern-based manipulation language for graph models. Graph transformation rules can be specified by using a left-hand side -- LHS (or precondition) pattern determining the applicability of the rule, and a right-hand side -- RHS (postcondition) pattern which declaratively specifies the result model after rule application. Elements that are present only in (the image of) the LHS are deleted, elements that are present only in the RHS are created, and other model elements remain unchanged.
  • Complex model transformation can be assembled from elementary graph patterns and graph transformation rules using abstract state machine (ASM) [3] in case of the VIATRA2 framework. ASM provides complex model transformations with all the necessary control structures including the sequencing operators, rule invocation, variable declarations and updates, GT rule invocation etc.

More information on the semantic integration between graph transformation and abstract state machines can be found in [4].

To formulate these constructs VIATRA2 uses its own programming language called VTCL.

The VIATRA2 transformation language

VIATRA2 has its own programming language called VTCL. The VTCL language is a textual syntax to define GTASM program models. Transformations written in VTCL are stored in .vtcl files, and each of them describes a machine of the GTASM formalism. The definition of the control flow of the transformation is similar to the mathematical formalism of Abstract State Machines (ASM), and looks just like a conventional programming language (with a syntax somewhat resembling C); this is extended by the declarative features of Graph Transformation (GT).

Why would you want to write transformations in VTCL, instead of implementing them in a well-known programming environment like Java? First, VTCL has convenient access to the VPM model space, which acts as a common ground between heterogeneous modeling formalisms (although VPM also has a Java API). But more importantly, VTCL is a specialized language tailored to transformation specification, having language constructs for efficiently processing models, such as declarative model queries and even declarative manipulation. Should you still find the capabilities of VTCL limiting, there are ways to plug in arbitrary Java code.

The official page hosts the official (slightly outdated) transformation language specification. This section of the wiki, including the following pages, aims to give an informal, introductory overview of the language. The wiki also contains additional reading material including important usage patterns and more advanced topics.

VTCL basics

The contents of the file form a single GTASM machine, indicated by the machine keyword. The machine declaration is optionally preceded by namespace header to declare a namespace for the machine; the full name of the machine (as seen in the VIATRA2 Model Spaces view) will consist of this namespace, a dot, and the regular name. The other type of header is import, which references a namespace in the metamodel; type names below that namespace can be shortened to their relative qualified names throughout the file.

The procedure/method-like basic execution unit of ASM is the ASM rule. A rule is defined by code blocks introduced by the rule keyword, followed by the rule name, and then an arbitrary number of input (in), output (out), or in-out (inout) parameters enclosed in parentheses and tailed by an equality sign. A machine can have a main rule, which serves as an entry point; it is executed when the user runs the transformation from the GUI (the dialog box will ask for input parameters). The rest of the ASM rules can be invoked by a call instruction in other rules of the same machine, or a different machine (qualifying the rule name by the full name of the called machine).

Declarative model queries are called Graph Patterns. They are defined in code blocks indicated by the pattern (or shareable pattern) keyword, the pattern name, and an arbitrary number of (symbolic) parameters enclosed in parentheses (here, there is no distinction between input and output parameters). The pattern body follows, enclosed in curly braces; it describes constraints that the substituted value of the parameters must fulfill. Sometimes, there are multiple disjunctive pattern bodies separated by or. A match of the pattern is a substitution of each of its parameters (usually to model elements in the model space, less often to other values), such that all constraints are observed in at least one of the disjunctive pattern bodies. Patterns can be incorporated within each other (or a condition expression) using the pattern call feature (find keyword). Additionally, ASM rules can quantify the parameter values universally over all matches of a pattern (forall loop), or existentially just to find one match (choose keyword).

Declarative and semi-declarative model manipulations are called Graph Transformation Rules or GT rules for short. They are defined in code blocks indicated by the gtrule keyword, the GT rule name, an input-output parameter list like the one found at ASM rule declarations, and an equality sign followed by a pair of curly braces enclosing GT rule elements (precondition, postcondition, action). GT rules describe some model manipulation or other effect that is to be executed for matches of a precondition pattern (also known as left-hand-side or LHS). To define this effect, a GT rule contains either a declarative postcondition (right-hand-side or RHS), an imperative action sequence, or both. The precondition is indicated by the keyword precondition, followed either by a pattern call (find keyword) to the precondition pattern, or the inline definition of the precondition pattern. The optional postcondition is defined similarly. The optional imperative action sequence is indicated by the action keyword, followed by a pair of curly braces enclosing a sequence of instructions (similar to seq in ASM rule bodies). A rule application consists of taking a match of the LHS, replace it with the corresponding image of the RHS graph pattern (if any), and executing the action sequence (if any). The quantification syntax (forall, choose) can be used to apply gtrules on all possible or on one single match of the LHS.

As a less common GTASM element, ASM functions are a global associative (key-value) storage, that contributes to the state of the machine (but not to that of the model, i.e. it is not persisted on saving the model space). Keys are tuples of a chosen number of arguments (arity). ASM funtions are defined by the keyword asmfunction, followed by the name of the ASM function, a slash, and the arity. Optionally, the contents can be initialized by an initialization block containing key-value assignments. The contents of the ASM function can be read or written all throughout the machine, as well as from other machines (the ASM function name will have to be qualified with the full name of the defining machine).

VTCL uses C-like comments: // causes the VTCL parser to ignore the whole following line, while a pair of /* and */ ignore anything between them. Annotations (e.g. @incremental or @random) are not comments; they are parsed and may provide special options on how certain elements should be interpreted. Many GTASM elements (most importantly, pattern and GT rule definitions) can be preceded by annotations, marked by a @ and an annotation name, followed by an optional parentheses-enclosed list of key-value pairs.


Example

TODO

ASM rule bodies

In addition to the rule parameters, local variables can be introduced by the let variable = initialValue, variable2 = initialValue2 in block construct, or by quantification. TODO Capital, Types, Undef, ASMFunc (rule body?).

The most common control flow structure to define the body of a rule or a let/in block is the sequence block, delimited by seq { and }. This sequence block, similarly to the curly braces block in many C-like languages, contains semicolon-separated commands that are executed sequentially. Additional control flow elements include the if (condition) action construct for branching, with an optional else otherAction part. The loop construct iterate action repeatedly executes the action as long as it does not fail. Execution can fail by manually executing the instruction fail (typically to terminate a loop), or by an unsuccessful pattern matching (see later). The try action construct masks failures , with an optional else otherAction to execute in case a failure was caught. Finally, skip simply means doing nothing, and the aforementioned call invokes other ASM rules.

The most basic commands include update variable = value, to change variables (or ASM functions), and print/println, to emit textual results / code onto the default tab of the VIATRA2 Textual Output view (or to other tabs or even files). The ASM part of VTCL also contains instructions with direct model space access, the most important ones are the following. ref retrieves a model element by its fully qualified name. new and delete adds and removes model elements (as well as supertypeOf and instanceOf relationships!), respectively. rename changes the name of elements; setFrom and setTo manipulate relations, while move and setValue manipulate entities. Throughout these operations, type references can be shortened to a relative qualified name, by importing the namespace of a metamodel by the import header before the machine declaration.

TODO rule quant

Patterns

TODO find patternName(parameters) clause

GT Rules

TODO

Developing transformations

GUI, etc. TODO

a previous section
Cite error: <ref> tags exist, but no <references/> tag was found

Back to the top