Extra ATL information Extra ATL information Assigning attributes in - - PowerPoint PPT Presentation

extra atl information extra atl information
SMART_READER_LITE
LIVE PREVIEW

Extra ATL information Extra ATL information Assigning attributes in - - PowerPoint PPT Presentation

Extra ATL information Extra ATL information Assigning attributes in ATL rules: Assigning references g g Three cases: Meta model In/out Meta model Attribute element Model target element generated by current rule pattern


slide-1
SLIDE 1

Extra ATL information

  • Assigning attributes in ATL rules:

Meta model identification Meta model element identification In/out pattern Attribute assignment

rule example1{ from in: MM1!MetaClassA to

  • ut:

MM2!MetaClass1( to

  • ut:

MM2!MetaClass1( attr <- in.attr ) }

/ Faculteit Wiskunde en Informatica

PAGE 0 9-12-2009

Extra ATL information

Assigning references g g

  • Three cases:
  • Model target element generated by current rule
  • Default target model element generated by another rule
  • Non-default target model element generated by another

rule

Extra ATL information

  • Assigning references:

g g

  • Model target element generated by current rule

rule example{ from in: MM1!MetaClass to

  • ut1:

MM2!MetaClass1( RefToMetaClass2 <

  • ut2

RefToMetaClass2 <- out2 ),

  • ut2:

MM2!MetaClass2( ) }

Extra ATL information

  • Assigning references

D f l d l l d b h l

  • Default target model element generated by another rule

rule example1{ from in: MM1!MetaClassA from in: MM1!MetaClassA to

  • ut:

MM2!MetaClass1( RefToMetaClass2 <- in.RefToMetaClassB ) } rule example2{ from in: MM1!MetaClassB to

  • ut:

MM2!MetaClass2( ) }

slide-2
SLIDE 2

Extra ATL information

  • Assigning references

Non defa lt target model element generated b another r le

  • Non-default target model element generated by another rule

rule example1{ from in: MM1!MetaClassA to

  • ut:

MM2!MetaClass1( RefToMetaClassN <- thisModule.resolveTemp(in.RefToMetaClassB, ‘out_n’) ) } rule example2{ from in: MM1!MetaClassB to

  • ut:

MM2!MetaClass1( ),

  • ut n:

MM2!MetaClassN( _ ) }

Extra ATL information

  • Assigning enums

g g

rule example{ from in: MM1!MetaClassB to t MM2!M t Cl 1( to

  • ut:

MM2!MetaClass1( enum <- #”Integer” ) }

  • Quotes are only needed in case of reserved words

Rules

  • Matched rules

rule rule_name{ from in: MM1!MetaClass(<matching condition>) using{<variable definitions>} to

  • ut1:

MM2!MetaClass1( <bindings1> ),

  • ut2:

MM2!MetaClass2( <bindings2> <bindings2> ) do{<imperative block>} }

M t h ll d l l t f t

  • Matches on all model elements of type MM1!MetaClass,

similar to ASF’s traversal functions

ATL matched rules

  • ATL matched rule mechanism provides a mean to

specify the way target model elements must be generated from source model elements.

  • A matched rule enables to specify:
  • A matched rule enables to specify:

1. which source model element must be matched, 2. the number and the type of the generated target model yp g g elements, and 3. the way these target model elements must be initialized from the matched source elements initialized from the matched source elements

/ Faculteit Wiskunde en Informatica

PAGE 7 9-12-2009

slide-3
SLIDE 3

ATL matched rules

  • Each matched rule is identified by its name (rule_name).
  • A matched rule name must be unique within an ATL

transformation.

  • An ATL matched rule is composed of
  • two mandatory sections

− from and to parts.

  • two optional sections:

two optional sections:

− using and do parts.

  • The different variables that may be declared in the scope of a

rule (the source and target pattern elements and the local rule (the source and target pattern elements and the local variables) must have a unique name.

/ Faculteit Wiskunde en Informatica

PAGE 8 9-12-2009

Rules

  • Lazy matched rules

lazy rule rule_name{ from in: MM1!MetaClass using{<variable definitions>} to

  • ut1:

MM2!MetaClass1( <bindings1> ),

  • ut2:

MM2!MetaClass2( <bindings2> <bindings2> ) do{<imperative block>} }

G t t t l t f ll t th l

  • Generates new target elements for every call to the rule
  • Invoked from other rules as follows:

thisModule.rule_name(<model element of type MM1!MetaClass>)

Rules

  • Unique lazy matched rules

unique lazy rule rule_name{ from in: MM1!MetaClass using{<variable definitions>} to

  • ut1:

MM2!MetaClass1( <bindings1> ),

  • ut2:

MM2!MetaClass2( <bindings2> <bindings2> ) do{<imperative block>} }

Al t th t t l t f i

  • Always returns the same target elements for a given

source element, i.e., target elements are generated only

  • nce per source element

Rules

  • Called rules

[entrypoint]? rule rule_name(<parameters>){ using{<variable definitions>} to

  • ut1:

MM2!MetaClass1( <bindings1> ),

  • ut2:

MM2!MetaClass2( <bindings2> <bindings2> ) do{<imperative block>} }

  • For generating target elements from imperative code
  • No from clause
slide-4
SLIDE 4

Called rules

  • Besides matched rules, ATL defines an additional

kind of rules enabling to explicitly generate target model elements from imperative code.

  • Except for the entrypoint called rule this kind of
  • Except for the entrypoint called rule, this kind of

rules must be explicitly called from an ATL imperative block.

/ Faculteit Wiskunde en Informatica

PAGE 12 9-12-2009

Called rules

  • A called rule is identified by its name (rule_name).
  • A called rule name must be unique within an ATL

transformation,

  • must not collide with a helper name
  • a called rule cannot be called "main".
  • A called rule can optionally be declared as the transformation

entrypoint. entrypoint.

  • an ATL transformation can include one entrypoint called rule.
  • it is implicitly invoked at the beginning of the transformation

execution once the module initialization phase has execution, once the module initialization phase has completed.

/ Faculteit Wiskunde en Informatica

PAGE 13 9-12-2009

Called rules

  • A called rule can accept parameters.
  • It is composed of three optional sections:
  • the using,
  • the to and
  • the do sections.
  • Compared to a matched rule, a called rule has no from

Compared to a matched rule, a called rule has no from section, and its to section is optional.

/ Faculteit Wiskunde en Informatica

PAGE 14 9-12-2009

Helpers

  • Helper with context

helper context MM!MetaClass def: helper_name(<parameters>): return_type = let <variable definition> in <expression>;

  • Invocation:

Invocation:

<model element of type MM!MetaClass>.helper_name(<parameters>)

  • The context should never be of a collection type
  • Helper without context

p

helper def: helper_name(<parameters>): return_type = let <variable definition> in <expression>;

  • Invocation:
  • Invocation:

thisModule.helper_name(<parameters>)

  • For OCL functions refer to the ATL user guide
  • For OCL functions refer to the ATL user guide