Transformation best practices in VIATRA2

Naming elements

In two words: NAME THEM! It might seem as trivial, but it is one of the most useful techniques for developing and debugging a complex transformation. Note that model elements are automatically named uniquely by the MT framework, but this name doesn't include any information on the actual role of the element. The rename(element,name) function can be used for giving a proper name.

ASM functions

ASM functions provide a non-persistent map to store values. Each ASM function needs to be declared prior to its first use. Initial values can also be set when defining an ASM function.

machine asmFuns {
asmfunction team / 2 {
// Initialization
 (1, "real") = "Casillas";
 (7, "real") = "Raul";
 // Any values are allowed to be used in the untyped version
 (7.1, 6) = 2;
}
asmfunction anotherFun / 1; // An ASM function without initialization
}

The values stored at a certain location of an ASM function can be updated using the update ASM construct: update fun(X) = Y: assigns a new value Y to variable X or ASM function location fun(X).

Usage Tips:

GT-rules and ASM-rules

GT-rules where the tranformation is defined decleratively with pre and postconditions together with some actions is closer to the graph transformation formalism underlying model transformations. However, writing, debugging and reusing GT-rules is burdensome and the performance is lower than when using ASM rules. Still, those who are acquainted with declerative programming may find it easier to create tranformations using GT-rules. Furthermore, MTs built from GT-rules are more usable for intra model transformations if manipulation is more frequent than generation.

On the other hand ASM rules are closer to imperative programming where model manipulation is given as ASM sequences. We advise those who start using VIATRA and model transformations with a fair knowledge of imperative languages to use ASM rules for developing a transformation. Note that ASM rules are also more adventageous for writing inter model transformations as generation has more weight than manipulation.

Control structures

Control structures are used for creating the control flow graph of MT rules. In the following the most usual usecases of these structures are given:

Pattern Composition

Apart from the regular definition of a pattern, several composition techniques can be used for building more complex and better understandable patterns.