Chapter 9 Generation Reference Guide (GTL)
Templates are instantiated through a process called translation. Translation is done in a well-defined scope and consists in substituting the variables by their corresponding values in the scope. All templates are defined with respect to metamodel classes, they are considered special type properties that take on the result of their translation as value.
A scope is a context for evaluating a template, it comprises the active object and local variables. At any given point during translation, only one object is active; it is the object which the template is applied onto. In a translation scope, all metamodel attributes and collections defined on the active object metaclass and its parents are visible, as well as the corresponding extended attributes and templates. When the translation engine starts evaluating a template, a new translation scope is created.
For more information on object collections, see "Associations and collections" in the "PowerDesigner Public Metamodel" chapter.
Whenever a scope is created it is the current translation scope, the old translation scope being the outer scope for the current translation scope
Whenever a scope is exited its outer scope is restored as the current translation scope
For more information on the outer scope, see the "Defining variables" section.
New scopes may be created during evaluation of a template that forces the active object to change. For example, the foreach_item
macro that allows for iteration on collections defines a new scope, as well as the foreach_line
macro. The outer scope is restored when leaving the block.
For more information on both macros, see the "foreach_item macro", and the "section foreach_line macro" sections.
Nested scopes form a hierarchy that can be viewed as a tree, the top level scope being the root.
The following example shows the scope mechanism using a Class template:
Copyright (C) 2005. Sybase Inc. All rights reserved. |