You are on page 1of 30

ATL:

Atlas Transformation Language


Reference Manual
- version 0.09 -

2005
by

ATLAS group
LINA & INRIA
Nantes

Content
1

Introduction ....................................................................................................................... 1
QVT................................................................................................................................ 1
ATL and QVT ................................................................................................................ 1
OCL................................................................................................................................ 1
Objectives and Rationale................................................................................................ 1
2
Grammar............................................................................................................................ 1
2.1 Context-Free Grammar .................................................................................................. 1
2.2 Grammar Notation.......................................................................................................... 2
3
Lexical Structure ............................................................................................................... 2
3.1 Encoding......................................................................................................................... 2
3.2 Lexical Translations ....................................................................................................... 3
3.3 Unicode Escapes ............................................................................................................ 3
3.4 Line Terminators ............................................................................................................ 3
3.5 Input Elements and Tokens ............................................................................................ 4
3.6 White Space.................................................................................................................... 4
3.7 Comments....................................................................................................................... 4
3.8 Identifiers ....................................................................................................................... 4
3.9 Keywords ....................................................................................................................... 5
3.10 Separators ....................................................................................................................... 6
3.11 Operators ........................................................................................................................ 6
3.12 Infix Operators ............................................................................................................... 6
4
Data Model........................................................................................................................ 7
4.1 OclAny ........................................................................................................................... 7
4.2 Model Elements.............................................................................................................. 7
4.3 Primitive Types .............................................................................................................. 8
4.3.1
The Boolean Type .................................................................................................. 8
4.3.2
The String Type...................................................................................................... 9
4.3.3
Numeric Types ....................................................................................................... 9
4.4 Collections.................................................................................................................... 11
4.4.1
Set......................................................................................................................... 12
4.4.2
OrderedSet............................................................................................................ 13
4.4.3
Bag ....................................................................................................................... 14
4.4.4
Sequence............................................................................................................... 15
4.4.5
Iterator Expressions.............................................................................................. 16
4.5 Tuples ........................................................................................................................... 18
4.6 Enumerations................................................................................................................ 18
5
ATL Programs................................................................................................................. 18
5.1 Modules........................................................................................................................ 18
5.1.1
Header Section ..................................................................................................... 19
5.1.2
Import Section ...................................................................................................... 19
5.2 Queries ......................................................................................................................... 19
5.3 Libraries ....................................................................................................................... 19
6
OCL Expressions............................................................................................................. 20
6.1 The If Expression ......................................................................................................... 20
1.1
1.2
1.3
1.4

6.2 The Let Expression....................................................................................................... 20


7
Helpers ............................................................................................................................ 20
8
Declarative Rules ............................................................................................................ 21
9
Imperative Constructs ..................................................................................................... 22
10 Execution Semantics ....................................................................................................... 22
I.
References ....................................................................................................................... 24

ATL User Manual

1 Introduction
ATL, the Atlas Transformation Language, is the ATLAS INRIA & LINA research group
answer to the OMG MOF [5][6] /QVT RFP [6]. It is a model transformation language
specified both as a metamodel and as a textual concrete syntax. It is a hybrid of declarative
and imperative. The preferred style of transformation writing is declarative, which means
simple mappings can be expressed simply. However, imperative constructs are provided so
that some mappings too complex to be declaratively handled can still be specified. An ATL
transformation program is composed of rules that define how source model elements are
matched and navigated to create and initialize the elements of the target models.

1.1 QVT
QVT is an acronym for Query, View and Transformation. This is how they are described in
QVT RFP [6]:
Queries take as input a model, and select specific elements from that model.
Views are models that are derived from other models.
Transformations take as input a model and update it or create a new model.

1.2 ATL and QVT


ATL supports QVT queries, QVT views and QVT transformations. Nevertheless, there are
some minor differences. ATL programs perform queries and transformations. Since views are
models and ATL programs take models as input and, in general, produce models as output,
views are a specific case of the input or of the output of ATL programs.
There are two kinds of executable ATL programs, namely modules and queries. Modules
transform models to models while queries do models to text transformations. Finally, ATL
supports libraries which allow defining repetitive pieces of code in one place.

1.3 OCL
ATL is based on OCL [7], the Object Constraint Language. ATL supports OCL expressions
(see chapter 6) and it has a type model (see chapter 4) that is very similar to the one of OCL.

1.4 Objectives and Rationale


The objective of ATL is a transformation language that on the one hand is close to the
standards and on the other hand very powerful and easy to use. A rich set of tools has been
built for ATL development [1] under Eclipse.
The Java Language Specification [3] is a good and well-known example of a language
specification. For this reason, the specification in this ATL Reference Manual is based on it. It
contains a similar document structure and uses the same context-free grammar.

2 Grammar
To describe ATL, an EBNF-like context-free grammar has been chosen.

2.1 Context-Free Grammar


Context-free grammars are a common way to describe computer languages. Context-free
grammars consist of production rules. These have an abstract symbol called a nonterminal on
their left-hand side. On their right hand side they have a sequence of nonterminal and terminal
symbols defining the syntax of the left-hand side nonterminal.

Page 1

ATL Reference Manual

2.2 Grammar Notation


Nonterminal and terminal symbols are shown in fixed width. Furthermore, nonterminal
symbols are shown in italic. The declaration of the nonterminal on the right-hand side is
introduced by the name of the nonterminal and followed by a semicolon. One or more
alternative right-hand sides then follow on succeeding lines to define the content of the
nonterminal.
This example defines an if-expression:
IfExpression :
if ( Expression ) then Expression else Expression endif

An if-expression consists of an if-then-else-endif structure. The if is followed by a


Boolean expression. The then and the else introduce each an expression. The else-part is
not optional.
The words one of introduce alternatives:
BooleanLiteral : one of
true false

which is shorthand for:


BooleanLiteral :
true
false

Left-side terminals or nonterminals can be declared optional with the opt keyword.
Input :
InputElementsopt

The above means that an input may consist of input elements but an input may also be empty.
If a line is too short, the content can be split on several lines. While alternatives start at the
same indention, split lines have additional indention.
TargetPatternElement :
Identifier : MetamodelClassPath ( Assignements )
Identifier : distinctopt MetamodelClassPath
foreach (Identifier in Identifier ) ( Assignements )
The definition contains two alternatives starting with the nonterminal identifier. The second left side alternative
is split on two lines.

3 Lexical Structure
3.1 Encoding
ATL programs are written using the Unicode character set. Except for comments, identifiers,
and the contents of character and string literals, all input elements in an ATL program are
formed only from ASCII characters (or Unicode escapes which result in ASCII characters).
Information about the Unicode encoding standard can be found in the Unicode Standard [9].
ASCII characters are the first 128 characters of the Unicode character encoding.
Page 2

ATL Reference Manual

3.2 Lexical Translations


The lexical translation of an ATL program in the form of a raw Unicode character stream can
be summarized in three steps:
1. A first translation step transforms the Unicode escapes in the raw stream of Unicode
(in general ASCII) characters to the corresponding Unicode characters.
2. A second translation step takes the result of step 1 and translates it into a stream of
input characters and line terminators.
3. A third translation step takes the result of step two and translates it into a sequence of
input elements. After discarding comments and white spaces the result comprises the
tokens that are the terminal symbols of the syntactic grammar.

3.3 Unicode Escapes


Implementations first recognize Unicode escapes in their input, translating the ASCII
characters \u followed by four hexadecimal digits to the Unicode character with the indicated
hexadecimal value, and passing all other characters unchanged. This translation step results in
a sequence of Unicode input characters:
UnicodeInputCharacter :
UnicodeEscape
RawInputCharacter
UnicodeEscape :
\ UnicodeMarker HexDigit HexDigit HexDigit HexDigit
\ any Unicode character
UnicodeMarker :
u
UnicodeMarker u
RawInputCharacter :
any Unicode character but not
HexDigit : one of
0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F

The \, the u, and hexadecimal digits are all ASCII characters.


For example, \u2297 is the Unicode encoding of the character " " and \n is the encoding
of the CR character (carriage return).

3.4 Line Terminators


For the second lexical translation step line terminators and input characters have to be
identified. This is how they are defined:
LineTerminator :
the ASCII LF character, also known as "newline"
the ASCII CR character, also known as "return"
the ASCII CR character followed by the ASCII LF character
InputCharacter :
UnicodeInputCharacter but not CR or LF

Page 3

ATL Reference Manual

3.5 Input Elements and Tokens


Very important for the lexical translation are input elements, and tokens. An input element
can be a white space, a comment or a token. Tokens represent the terminal symbols of the
syntactic grammar (e.g. keywords, identifiers, literals and operators).
Input :
InputElementsopt
InputElements :
InputElement
InputElements InputElement
InputElement :
WhiteSpace
Comment
Token
Token :
Identifier
Keyword
Literal
Separator
Operator

3.6 White Space


A white space is defined as ASCII space, horizontal tab, form feed characters, or as line
terminator.
WhiteSpace :
the ASCII SP character, also known as "space"
the ASCII HT character, also known as "horizontal tab"
the ASCII FF character, also known as "form feed"
LineTerminator

3.7 Comments
Comments start with two consecutive hyphens and end with the line terminator.
Comment :
-- CharactersInLineopt LineTerminator
CharactersInLine :
InputCharacter
CharactersInLine InputCharacter

3.8 Identifiers
Please note that OCL identifiers are defined as String and String as a chain of characters
which is not restricted to specific characters. myVariable is a possible name for an identifier
as much as 4any-thing2:) (a mix of signs, digits and letters).
Identifiers are unlimited sequences of specific Unicode characters and are defined as follows:
Identifier :
IdentifierChars but not Keyword, BooleanLiteral or NullLiteral
UnicodeInputCharacters

Page 4

ATL Reference Manual

UnicodeInputCharacters :
UnicodeInputCharacter
UnicodeInputCharacter UnicodeInputCharacters
IdentifierChars :
LetterOrDigit
IdentifierChars LetterOrDigit
Letter :
any Unicode character between a and z or A and Z
LetterOrDigit :
any Letter or any Unicode character between 0 and 9

Examples of identifiers are:


String
myVariable
MAX_VALUE
isLetterOrDigit
i
-
\n

The usage of inverted commas allows overwriting operators:


query TestOperatorDefinition = '123'."-"(2);
helper context String def: "-"(i : Integer) : String =
self.substring(1,self.size() - i);

Identifier declarations with chains of Unicode input characters containing none identifier
characters have to be put in double inverted commas (similar rules apply to keywords).
However, what has not yet been specified (and this applies only to chains of Unicode input
characters containing none identifier characters and not to keywords) is that when identifiers
are used (and not declared) in the program double inverted commas are not necessary. Thus
the following code is also possible:
query TestOperatorDefinition = '123' - 2;
helper context String def: "-"(i : Integer) : String =
self.substring(1,self.size() - i);

For the declaration of overloaded operators inverted commas are obligatory.

3.9 Keywords
The following words are ATL keywords:
Keyword : one of
not
module
def
to
do
let

and
create
context
mapsTo
if
library

or
from
rule
distinct
then
query

Page 5

xor
uses
using
foreach
else
for

implies
helper
derived
in
endif

ATL Reference Manual

3.10 Separators
The following nine ASCII characters are the separators (punctuators):
Separator : one of
(
)
.

3.11 Operators
Operators can be used by the ASCII
Operator:
UnaryOperator
BinaryOperator

The following tokens are basic operators. They are formed from ASCII characters:
UnaryOperator : one of
+
BinaryOperator
=
+
div

: one of
>
<
*
mod

not

<=
/

>=
&

!=
|

OperatorExpression :
UnaryOperator Expression
Expression . UnaryOperator ()
Expression BinaryOperator Expression
Expression . BinaryOperator ( Expression )

The operators are listed in precedence order with the highest precedence at the top of the
table:
Priority of operators
precedence
@pre
brackets, dot and arrows
[] () {} . <unary
+ - not
multiplicative
*/%
additive
+if-clause
if-then-else-endif
relational
< <= > >=
equality
= <>
logical AND
and
logical OR and XOR
or xor
logical implies
implies

3.12 Infix Operators


As in OCL, ATL has allows the use of infix operators. The binary operators +, -, *. /,
<, >, <> <= >= can be used in an expression as ordinary infix operators or in
operation-like expressions.

Page 6

ATL Reference Manual


The following infix operator expression:
a + b

is equivalent to the operation-like expression:


a.+( b )

4 Data Model
ATL is a strongly typed language since every expression has a type that is known at compile
time.
The ATL type model is very similar to the OCL type model; in particular what concerns the
primitive types, the model elements and the collection types

4.1 OclAny
An important superclass of the OCL type system is OclAny from which, among others,
OclModelElement, OclType, Real, Boolean and String inherit.
OclAny = OclAny : Boolean
Returns true if the objects are the same, otherwise false.
OclAny <> OclAny : Boolean
Returns false if the objects are the same, otherwise true.
OclAny oclIsNew : Boolean
Returns true if the object is newly created (i.e. didnt exist at precondition time), otherwise
false.
OclAny oclIsTypeOf( OclType ) : Boolean
Returns true if the object is of the OclType specified, otherwise false.
OclAny oclIsKindOf( OclType ) : Boolean
Returns true if the objects conforms to the OclType specified (thus also to any of its
subclasses), otherwise false.
OclType allInstances : Set
Returns all instances of a type (that are in a given source model).
OclAny oclIsUndefined : Boolean
Returns true if the object is void (void is represnted by OclVoid), otherwise false.

4.2 Model Elements


Model Element Types are defined by the corresponding source and target metamodels. ATL
has an abstraction layer that allows adapting to different metametamodels via corresponding
adaptors.
In ATL it is not allowed to presume the execution order (namely the order of creation of
model elements of the target model) since this is a decision of the ATL implementation and a
matter of optimization. This means that model elements of the target models are not allowed
to be used on the right hand side of assertions.
Page 7

ATL Reference Manual

OclModelElement = OclModelElement : Boolean


Returns true if the model elements are the same, otherwise false.
OclModelElement <> OclModelElement : Boolean
Returns false if the model elements are the same, otherwise true.

4.3 Primitive Types


The primitive types of ATL correspond to the OCL primitive types, namely to Boolean,
String, Integer and Real. Integer and Real are numeric types.
In OCL primitive types are only vaguely specified leaving space for different
implementations (e.g. there is no precision of the limits of numeric types). The ATL language
specification does not intend to be more restrictive than OCL but at the same time gives an
indication about the current implementation.
These are the primitive types in ATL:
PrimitiveType :
Boolean
String
NumericType

In OCL there is no numeric type. The ATL numeric type and the ATL Real correspond to
OCL Real. Numeric type has only been used to facilitate the specification of ATL.

4.3.1 The Boolean Type


The Boolean type has two values, true and false. A Boolean literal is defined as follows:
BooleanLiteral : one of
true false

Boolean has the following operations:


BooleanOperation: one of
and
or
xor
not

implies

Boolean expressions determine the control flow in if-expressions.


Boolean and Boolean : Boolean
True if both boolean values are true, otherwise false.
Boolean or Boolean : Boolean
True if at least one boolean value is true, otherwise false.
Boolean xor Boolean : Boolean
True if exactly one boolean value is true, otherwise false.
not Boolean : Boolean
True if the boolean value is false, otherwise false.
Boolean implies Boolean : Boolean
False if the first boolean value is true and the second false, otherwise true.
Page 8

ATL Reference Manual

4.3.2 The String Type


Strings are chains of characters. String literals are defined as follows:
StringLiteral :
' StringCharactersopt '
StringCharacters :
StringCharacter
StringCharacters StringCharacter
StringCharacter :
InputCharacter but not ' or \
EscapeSequence

The following are examples of string literals:


''
'\''
'A String'
'This is a \n' +
'two-line String'

-------

the empty String


a string containing '
a string containing 8 characters
actually a string-valued constant
expression, formed from two String
literals

String has the following operations:


StringOperation : one of
concat()
size()
toReal()

substring()

String concat( String ) : String


The concatenation of the two String values.
String size() : Integer
The number of characters in the String.
String substring( Integer , Integer ) : String
The Substring between the two Integers.
String toInteger() : Integer
The Integer value that is coded in the String.
String toReal() : Integer
The Real value that is coded in the String.

4.3.3 Numeric Types


ATL has two numeric types, namely Integer and Real.
NumericType :
Integer
Real

Numeric types have the following operations:


NumericOperation : one of

Page 9

toInteger()

ATL Reference Manual


*
+
/
div() sin() cos() floor()
max() min() abs() sum() mod() round()

The ATL language does not specify numeric limits. The limits depend on the
implementation. The current implementation for Integer and Real is based on Java [3] and
thus has the same limits as the corresponding Java types which are java.lang.Integer and
java.lang.Double.
NumericType * NumericType : NumericType
The multiplication of two numeric values.
NumericType + NumericType : NumericType
The addition of two numeric values.
NumericType - NumericType : NumericType
The substraction of two numeric values.
- NumericType : NumericType
The negative numeric value.
NumericType / NumericType : NumericType
NumericType.div( NumericType ) : NumericType
The division of two numeric values.
NumericType.sin() : NumericType
The sinus of a numeric value.
NumericType.cos() : NumericType
The cosinus of a numeric value.
NumericType.floor() : NumericType
The largest numeric value which is less or equal than the numeric value.
NumericType.max( NumericType ) : NumericType
The maximum of the two numeric values.
NumericType.min( NumericType ) : NumericType
The minimum of the two numeric values.
NumericType.cos() : NumericType
The absolute numeric value.
Collection.sum(): NumericType
The sum of all numeric values.
NumericType.mod( NumericType ) : NumericType
The result of modulo of the first numeric value with the second.
NumericType.round() : Integer
The Integer value that is closet to the numeric value. Halve values are rounded up.
Page 10

ATL Reference Manual

4.3.3.1 Integer
An Integer is a whole number. Integer literal examples are 2 and 123. Integer is the
supertype of Real.
Integer has the operations:
IntegerOperation : one of
NumericOperation

4.3.3.2 Real
A Real is a number that may have a fractional part, an exponent, and a type suffix. Examples
of Reals are 5e5f and -3.12.
Real has the operations:
IntegerOperation : one of
IntegerOperation

4.4 Collections
Collection is the abstract superclass of Set, OrderedSet, Bag and Sequence.

Set is a collection without duplicates. Set has no order.


OrderedSet is a collection without duplicates. OrderedSet has an order.
Bag is a collection in which duplicates are allowed. Bag has no order.
Sequence is a collection in which duplicates are allowed. Sequence has an order.

Collections contain zero to n expressions.


CollectionElements :
0to1CollectionElements
2toNCollectionElements
0to1CollectionElements :
Expressionopt
2toNCollectionElements :
Expression , Expression
Expression , 2toNCollectionElements

Collection literals are defined as follows:


SetLiteral :
Set { CollectionElements }
OrderedSetLiteral :
OrderedSet { CollectionElements }
BagLiteral :
Bag { CollectionElements }
SequenceLiteral :
Sequence { CollectionElements }

Examples of collections are:


Page 11

ATL Reference Manual

Sequence{ 1, 2, 3, 4, 5, 6, 7, 8 }
Sequence{ 1..(4 + 4) }
Sequence{ 1..8 }

All three sequence expressions are semantically identical.


Collection has the following operations:
Collection.size() : Integer
The number of elements in the collection.
Collection.includes( Object ) : Boolean
The information of whether an object is part of a collection.
Collection.excludes( Object ) : Boolean
The information of whether an object is not part of a collection.
Collection.count( Object ) : Integer
The number of times that object occurs in the collection.
Collection.includesAll( Collection ) : Boolean
The information of whether all objects of a given collection are part of a specific collection.
Collection.excludesAll( Collection ) : Boolean
The information of whether none of the objects of a given collection are part of a specific
collection.
Collection.isEmpty() : Boolean
The information if a collection is empty.
Collection.notEmpty() : Boolean
The information if a collection is not empty.

4.4.1 Set
Set inherits all collection operations. Additionally, set has the following set specific
operations:
Set.union( Set ) : Set
The union of the first and the second set.
Set.union( Bag ) : Bag
The union of the set and the first bag.
Set = Set : Boolean
Tests if the sets contain the same elements and if this is true it returns true.
Set.intersection( Set ) : Set
The intersection of the first and the second set.
Set. intersection( Bag ) : Bag
Page 12

ATL Reference Manual


The intersection of the set and the first bag.
Set - Set : Set
Returns a set with those elements of the first set that are not in the second.
Set including( Object ) : Set
Adds the object to the set.
Set excluding( Object ) : Set
Removes the object from the set.
Set symmetricDifference( Set ) : Set
Returns a set with all those set elements that are in exactly one of the sets (an not in both).
Set count( Object ) : Integer
The number of occurrences of object in the set (because of the set characteristic possible
results are 0 and 1, but not a number greater than 1).
Set flatten() : Set
If the elements of the set are not collections the set will be returned unmodified. If the
elements in the set are collections, the returned set will directly contain all elements of those
collections.
Set asSet() : Set
Returns the set unmodified.
Set asOrderedSet() : OrderedSet
Casts the set to an ordered set.
Set asSequence() : Sequence
Casts the set to a sequence.
Set asBag() : Bag
Casts the set to a bag.

4.4.2 OrderedSet
Ordered set inherits all collection operations. Additionally, ordered set has the following
ordered set specific operations:
OrderedSet append( Object ) : OrderedSet
Appends the object at the end of the ordered set.
OrderedSet prepend( Object ) : OrderedSet
Inserts the object at the first place of the ordered set.
OrderedSet insertAt( Integer, Object ) : OrderedSet
Inserts the object at the place indicated by the Integer value in the ordered set.
OrderedSet subOrderedSet ( Integer, Integer ) : OrderedSet
All elements starting at the first Integer value and including the second Integer value.
Page 13

ATL Reference Manual

OrderedSet at( Integer ) : Object


Returns the object at the position indicated by the Integer value in the ordered set.
OrderedSet indexOf( Object ) : Integer
Returns the position of the object in the ordered set.
OrderedSet first( Integer ) : Object
Returns the first object of the ordered set.
OrderedSet last( Integer ) : Object
Returns the last object of the ordered set.

4.4.3 Bag
Bag inherits all collection operations. Additionally, bag has the following bag specific
operations:
Bag.union( Bag ) : Bag
The union of the first and the second bag.
Bag.union( Set ) : Bag
The union of the set and the first bag.
Bag = Bag : Boolean
Tests if the bags contain the same elements the same number of times and if this is true, it
returns true.
Bag.intersection( Bag ) : Bag
The intersection of the first and the second bag.
Bag. intersection( Set ) : Set
The intersection of the bag and the first set.
Bag including( Object ) : Bag
Adds the object to the bag.
Bag excluding( Object ) : Bag
Removes all occurrences of the given object from the bag.
Bag count( Object ) : Integer
The number of occurrences of object in the bag.
Bag flatten() : Bag
If the elements of the bag are not collections the bag will be returned unmodified. If the
elements in the bag are collections, the returned bag will directly contain all elements of those
collections.
Bag asSet() : Set
Casts the bag to a set. This removes all duplicates.

Page 14

ATL Reference Manual


Bag asOrderedSet() : Sequence
Casts the bag to an ordered set (undefined order). This removes all duplicates.
Bag asSequence() : Sequence
Casts the bag to a sequence (undefined order).
Bag asBag() : Bag
Returns the bag unmodified.

4.4.4 Sequence
Sequence inherits all collection operations. Additionally, sequence has the following sequence
specific operations:
Sequence count( Object ) : Integer
The number of occurrences of object in the Sequence.
Sequence = Sequence : Boolean
Tests if the sequences contain the same elements in the same order and if this is true, it returns
true.
Sequence.union( Sequence ) : Sequence
Appends the second sequence to the first sequence.
Sequence flatten() : Sequence
If the elements of the sequence are not collections the sequence will be returned unmodified.
If the elements in the sequence are collections, the returned sequence will directly contain all
elements of those collections.
Sequence append( Object ) : Sequence
Appends the object at the end of the sequence.
Sequence prepend( Object ) : Sequence
Inserts the object at the first place of the sequence.
Sequence insertAt( Integer, Object ) : Sequence
Inserts the object at the place indicated by the Integer value in the sequence.
Sequence subSequence ( Integer, Integer ) : Sequence
All elements starting at the first Integer value and including the second Integer value.
Sequence at( Integer ) : Object
Returns the object at the position indicated by the Integer value in the sequence.
Sequence indexOf( Object ) : Integer
Returns the position of the object in the sequence.
Sequence first( Integer ) : Object
Returns the first object of the sequence.
Sequence last( Integer ) : Object
Page 15

ATL Reference Manual


Returns the last object of the sequence.
Sequence including( Object ) : Sequence
Adds the object to the sequence.
Sequence excluding( Object ) : Sequence
Removes all occurrences of the given object from the sequence.
Sequence asSet() : Set
Casts the sequence to a set. This removes all duplicates.
Sequence asOrderedSet() : Sequence
Casts the sequence to an ordered set. This removes all duplicates.
Sequence asSequence() : Sequence
Returns the sequence unmodified.
Sequence asBag() : Bag
Casts the sequence to a bag.

4.4.5 Iterator Expressions


ATL supports OCL iterator expressions. Iterator expressions consist of a source, a body,
iterator(s), and a result.

4.4.5.1 Collection
There is a rich set of iterator expressions defined on collection.
exists
If body evaluates to true for at least one element in the source collection, the exists expression
returns true, otherwise false.
forAll
If body evaluates to true for at all elements in the source collection, the forAll expression
returns true, otherwise false.
isUnique
If body expression evaluates for each element in the source collection a different value, the
isUnique expression returns true, otherwise false.
any
Returns any element in the source collection for which body evaluates to true.
one
If body evaluates to true for exactly one element in the source collection, the one expression
returns true, otherwise false.
collect
The collect expression returns the collection of elements which results from applying body to
every member of the source set. The result is flattened.
Page 16

ATL Reference Manual

4.4.5.2 Set
Set allows the iterator expressions defined on collection and additionally it defined some set
specific ones.
select
The subset of set for which the body evaluates to true.
reject
The subset of set for which the body evaluates to false.
collectNested
Returns the bag of elements which results from applying body to every member of the source
set.
sortedBy
Returns the Set as an ordered set, lower values go first. The elements of the set must be
comparable with<.

4.4.5.3 Bag
Bag allows the iterator expressions defined on collection and additionally it defined some bag
specific ones.
select
The subset of bag for which the body evaluates to true.
reject
The subset of bag for which the body evaluates to false.
collectNested
Returns the bag of elements which results from applying body to every member of the source
bag.
sortedBy
Returns the bag as a sequence with lower values first. The elements of the bag must be
comparable with<.

4.4.5.4 Sequence
Sequence allows the iterator expressions defined on collection and additionally it defined
some sequence specific ones.
Bag allows the iterator expressions defined on collection and additionally it defined some bag
specific ones.
select
The subset of sequence for which the body evaluates to true.
reject
The subset of sequence for which the body evaluates to false.
collectNested
Page 17

ATL Reference Manual


Returns the sequence of elements which results from applying body to every member of the
source bag.
sortedBy
Returns the sequence with lower values first. The elements of the sequence must be
comparable with<.

4.5 Tuples
Tuples are known from mathematics and database theory. An n-tuple is a composite with n
elements.
TupleLiteral :
Tuple { TupleElements }
TupleElements :
TupeElementopt
TupeElements , TupeElement
TupleElement :
Identifier = Expression

An example of an ATL tuple literal is:


Tuple {
x = 1,
y = 2,
z = 3 }

4.6 Enumerations
In ATL programs model enumerations are defined by the source and target metamodels.
Enumerations cannot be defined in ATL programs themselves.

5 ATL Programs
ATL has three different types of programming units, namely modules, queries and libraries.
Modules transform models to models while queries do model to text transformations.
Libraries serve to define repetitive pieces of code in one place. In contrast to queries and
modules, libraries are not executable on their own.

5.1 Modules
The primary intention of ATL is model to model transformation and thus modules are the
most common ATL programs. A module consists of a header section and in some cases of an
import section. These are followed by zero to n helpers and rules. Best programming practice
is to write the all helpers before the rules, but this is not obligatory.
Module :
HeaderSection ImportSectionopt RulesAndHelpers
RulesAndHelpers :
RulesAndHelpersopt Helperopt
RulesAndHelpersopt Ruleopt

Page 18

ATL Reference Manual

5.1.1 Header Section


A header declares the name of the module trough an identifier. The header starts with the
word module and ends with a semicolon.
HeaderSection :
module Identifier ;

Please note that the identifier should/must correspond to the modules file name.

5.1.2 Import Section


The import section declares what libraries are to be imported.
ImportSection :
uses Libraries;
Libraries :
0to1Libraries
2toNLibraries
0to1Libraries :
Identifieropt
2toNLibraries :
Identifier , Identifier
Identifier , 2toNLibraries

5.2 Queries
Queries allow to analyse models and to calculate an output that is not necessarily a model.
This makes them very useful to generate text or code from a model.
Query :
query Identifier = Expression ; Helpers ImportSection
query Identifier = Expression ; ImportSection Helpers
Helpers :
Helperopt Helpersopt

5.3 Libraries
Libraries are reusable program units that can be called from modules or from queries.
Library :
library Identifier; ImportSection Helpers
Helpers :
Helperopt Helpersopt

It is important to mention that if a module imports a library this has to be declared in the
import section and in the configuration.

Page 19

ATL Reference Manual

6 OCL Expressions
OCL [7], the Object Constraint Language, is an OMG standard to express constraints. In ATL
programs OCL expressions are omnipresent which is why they are simply referred to as
expressions. They are used within declarative rules, helpers and queries.
Expression :
any literal
Identifier
IfExpressoin
LetExpression
OperatorExpression

If-expressions have a return value and are thus expressions. The same applies to letexpressions.

6.1 The If Expression


Just as other languages, ATL has also an if-expression.
IfExpression :
if ( Expression ) then Expression else Expression endif

An if-expression consists of an if-then-else-endif structure. The if is followed by a


Boolean expression which determines whether the then or the else part will be executed.
The then and the else introduce each an expression. The else-part is not optional. The
type of the result of the if-expression depends on the then and on the else part. In general,
the then and the else part should return the same result type.

6.2 The Let Expression


A very convenient way to declare variables is the let-expression. A let-expression can be used
with primitive types or with collection types.
Let-expressions or more precisely let-variables (the variables defined by the let-expressions)
are very helpful when debugging in order to check the value of an expression.
The let expression is defined as follows:
LetExpression :
let VariableName : PrimitiveType = Expression in Expression
let VariableName : CollectionType = Expression in Expression
VariableName :
Identifier

VariableName declares the name of the let-variable. The let-variable is of the type specified
(primitive type or collection). It is attributed the value of the first expression. The Letexpression returns the value of the second expression. The visibility and the lifetime of the
let-variable are restricted to the second expression.

7 Helpers
Helpers can be used to define (global) variables and functions. Helper functions are OCL
expressions. They can call each other (recursion is possible) or they can be called from within
rules. In general, they serve to define repetitive pieces of code in one place.
Page 20

ATL Reference Manual


The notion of the term context is similar to OCL and it may be compared to an input
parameter of a method. A context variable is specified with the help of the ATL path
expression (MetamodleElementPath) and is accessible via the self variable. If no context is
specified, the module itself is taken as context.
Helper :
HelperVariable
HelperFunction
HelperVariable :
helper def: Identifier = Expression ;
HelperFunction :
helper Contextopt def: Identifier () = Expression ;
Context :
context MetamodelClassPath

8 Declarative Rules
Rules describe the transformation from a source model to a target model by relating
metamodels. Each rule contains a unique name. It is introduced by the keyword rule that is
followed by the rules name. Its implementation is surrounded by curly brackets.
Rule :
rule { from SourcePattern to TargetPattern }
rule { from SourcePattern using { UsingExp } to TargetPattern }
SourcePattern :
Identifier : MetamodelClassPath ( Filter )
Filter :
Expression
UsingExp :
UsingElement
UsingElement UsingExp
UsingElement :
Identifier : Identifier = Expression ;
TargetPattern :
TargetPatternElement
TargetPatternElement , TargetPattern
TargetPatternElement :
Identifier : MetamodelClassPath ( Assignements )
Identifier : distinct MetamodelClassPath
foreach (Identifier in Identifier )
( Assignements )
Assignements :
Assignementopt
Assignement , Assignements
Assignement :
LeftSideElement = RightSideElement

Page 21

ATL Reference Manual

LeftSideElement :
Identifier
RightSideElement :
Expression

With using one can define variables for the scope of the rule. Each time the rule is matched
the variables will be recalculated. The using variable (usually a Sequence) can be reused to
define complex target pattern elements with the distinct and the foreach keywords but
also in the context of an assertion. Complex target pattern elements can create a variable
number of output elements, which is different form simple target pattern elements (without
distinct and foreach ) which create only one target element.
An example for a more advanced rule with using has been taken from the geometrical
transformation example explained in [2]. Here it is merely used to illustrate the syntax:
rule Point {
from
point :
DXF1!Point
using {
c : GeoTrans!GeoTransfo = let g : GeoTrans!GeoTransfo =
GeoTrans!GeoTransfo->
allInstances()->
select(t|
t.subGeoTransfos->
size() = 0 )->first()
in g;
}
to
out : DXF2!Point (
name <- point.name,
x <- thisModule.doCommands( point,
point.getPoint(), c ).x,
y <- thisModule.doCommands( point,
point.getPoint(), c ).y,
z <- thisModule.doCommands( point,
point.getPoint(), c ).z
)
}

9 Imperative Constructs
to be written later

10 Execution Semantics
Executing an ATL transformation model requires several steps. If the model is given in
textual format, it is first parsed and transformed to a model defined using the ATL metamodel. This model is then statically checked for semantic errors against the ATL metamodel
and source and target meta-models. The next step can either be an interpretation or a
compilation followed by an execution. In both cases, the application of an ATL
transformation follows the semantics described in this section.
If there is a called rule marked as entrypoint (only one is allowed) it is executed first. This
rule can call any number of called rules until it reaches its end. Then, the matched rules are
Page 22

ATL Reference Manual


executed. In a first time, the output elements are instantiated. For each rule, every
combination of elements matching the types of its source pattern is tried and checked against
its filter. It the latter returns true, a pattern has just been recognized and the rule is matched
for a specific set of elements.
Each time a declarative rule is matched, its target elements are instantiated. This is simply
done by instantiating each element of its target pattern. A run-time link between the rule, the
recognized and newly generated elements is created. This link associates one output element
to each input element, which becomes the default element for implicit target-from-source
resolution. A given source element cannot participate to more than one source pattern,
otherwise a runtime error occurs. As a matter of fact, this cannot be statically detected in the
general case; some filters would have to be checked for not being simultaneously true. In a
second time, the bindings are applied to initialize every output element. Depending on the
type and multiplicity of the property to be set, different actions can be done:
If the type is primitive (String, Integer, Boolean, Double) and the multiplicity has an
upper bound of 1, the result of the evaluation of the right part is simply used to set the
property (which is an Attribute).
If the type is complex (a Class of the meta-model) and the multiplicitys upper bound
equals 1, the right operand of the binding must evaluate to a model element of one of
the source models (navigation over target elements being prohibited).The value, which
will be used to set the property, cannot be this model element, which is not in the same
model as the propertys owner. However, at this point, a link might exist between this
source element and some target elements, if it belongs to a matched subgraph of a rule
(the same or another). If it does not, there is an execution error because the binding
cannot properly initialize the property. If it does, however, the default element,
associated to this source element by the run-time link, is used to set the property. If
another element is explicitly specified, it is used in place of the default one. This is the
target-from-source resolution algorithm.
If the upper bound of the multiplicity is greater than 1, there are two possibilities:
o The right operand of the binding evaluates to a single element (primitive or
complex), which type matches the type of the property (otherwise, it would
have been statically plotted as a semantic error). This element is added to the
collection of elements of the property.
o The right operand evaluates to an OCL Collection of elements (primitive or
complex), which types match the type of the property. The size must match the
multiplicity, or there is an execution warning (an imperative section can
correct this). Every element is added to the collection of elements of the
property.
In a third time, the imperative blocks of the matched rules are executed. Eventually and
provided it exists, the called rule marked as endpoint is executed.
Please note:
A called rule containing a target pattern is not executed as matched rule. The target elements
are simply created and initialized before the execution of the imperative block, but are not
automatically linked to any source element.

Page 23

ATL User Manual

I. References
[1] Allilaire, F., Idrissi, T. ADT: Eclipse Development Tools for ATL. EWMDA-2, September 2004, Kent,
http://www.cs.kent.ac.uk/projects/kmf/mdaworkshop/
[2] ATLAS Group, ATL Transformation Example: Geometrical Transformations. 2005
[3] Gosling, J., Joy, B., Steele, G., Bracha, G.: The Java Language Specification, Second Edition. Addison Wesley, 2000
[4] IBM, Eclipse project, EMF Documentation. http://www.eclipse.org/emf/
[5] OMG/MOF Meta Object Facility (MOF) Specification. OMG document AD/97-08-14, September 1997.
http://www.omg.org
[6] OMG/RFP/QVT MOF 2.0 Query/Views/Transformations RFP. OMG document AD/2002-04-10.
http://www.omg.org
[7] OMG UML 2.0 OCL Specification. OMG document AD/03-01-07 2003
[8] OMG/XMI XML Model Interchange (XMI) OMG document AD/98-10-05, October 1998.
http://www.omg.org
[9] The Unicode Consortium. The Unicode Standard, Version 4.0.0, defined by: The Unicode Standard, Version
4.0, Boston, MA, Addison-Wesley, ISBN 0-321-18578-1, 2003

Page 24

You might also like