Ad/2010-08-01 Concrete Syntax for a uml action Language for Foundational uml (Alf) Second Revised Submission



Download 1.74 Mb.
Page6/62
Date28.01.2017
Size1.74 Mb.
#9041
1   2   3   4   5   6   7   8   9   ...   62

6.2Templates


Templates, defined in Subclause 17.5 of the UML Superstructure, are not included in the fUML subset. Nevertheless, Alf text may be used as snippets within the context of a wider model that is a template. Since template parameters are tied to parameterable elements that are used as regular model elements within the context of the template model (see UML Superstructure, Subclause 17.5.1), Alf text may refer to these elements in the usual way.

However, templates are particularly useful for modeling parameterized types, and they are, in fact, used in this way in the CollectionClasses model in the Alf Standard Model Library (see Subclause 11.6). But Alf text that uses types that are instantiations of such templates still needs to be mapped to fUML in order to provide its formal semantics. This requires a way to define the semantics of template binding in terms of constructs available in the fUML subset.

According to the UML Superstructure specification (Subclause 17.5.2 TemplateableElement, under Semantics), “The semantics of a [template] binding relationship is equivalent to the model elements that would result from copying the contents of the template into the bound element, replacing any elements exposed as a template parameter with the corresponding element(s) specified as actual parameters in this binding.” This section also states that “In a canonical model a bound element does not explicitly contain the model elements implied by expanding the templates it binds to, since those expansions are regarded as derived.” However, by actually carrying out the expansion, one can obtain an equivalent model that does not explicitly refer to the original template or the binding of its parameters. (This is analogous to the way other forms of derivation in the UML abstract syntax model are handled in fUML—see fUML Specification, Subclause 8.1.)

In order to make the explicit copy semantics of template binding more precise, an equivalent bound element may be constructed for any element with a template binding by the following steps.



  1. Copy the template associated with the template signature that is the target of the template binding. For the present purposes, a copy of a model element is an instance of the same metaclass as the original model element that has the same values as the original element for all non-composite properties (owned attributes and association ends) and copies (in the same sense) of the values from the original element for all composite properties.

  2. If the copy specializes any elements that are templates, then redirect the generalization relationships to equivalent bound elements for the general elements, using the same template binding. If the copy is an operation that has an associated method that is also a template, then replace that method with an equivalent bound element using the same template binding.

NOTE. The UML Superstructure does not address the issue of methods of template operations. However, it is necessary for the method of a template operation to also be a template, presumably with the same template parameters as the operation. In particular, operation template parameters are typically used to parameterize the types of operation parameters, but the method of an operation does not directly reference the parameters of the operation that specifies it. Rather, the method has its own parameter list, which must match that of the operation (see UML Superstructure, Subclause 13.3.2). The types of the method parameters would thus need to be separately templated to match the template parameterization of the operation.

  1. For each element owned directly or indirectly by the copy, replace any reference to the parametered element of a template parameter of the copy with a reference to the actual element associated with the parameter in the template binding (if any). If an actual element has a template binding itself, then reference the equivalent bound element.

  2. Remove all template parameters that are referenced in the template binding from the template signature of the copy. If this would remove all template parameters from the template signature, then remove the template signature entirely.

The syntax for template binding in Alf is defined in Subclause 8.2. Only a limited set of template bindings may be so notated in Alf. Specifically:

  • The binding must specify an actual element for every template parameter of the template.

  • The element being bound must not have template parameters of its own.

Thus, the equivalent bound element (as defined above) for a template binding notated in Alf will always be a directly usable non-template element. However, in this context, it is important that two identical template bindings be considered to result in the same element. Otherwise, every template binding would lead to a separate instantiation of the template, even if the bindings were equivalent, which would have undesirable consequences.

For example, a set of integers may be notated in Alf as Set, using the standard template collection class Set and the standard primitive type Integer. If each occurrence in a model of the Alf text “Set” resulted in a different equivalent bound element, then an object created using one such occurrence would not be type compatible with, say, a formal parameter of an operation whose type is given by another such occurrence. Clearly this is not desirable.

Therefore, the template bindings within a model must be replaced as a whole using the following steps.


  1. Partition the set of all elements with template bindings in the model into disjoint subsets of elements with identical bindings. Two template bindings are considered identical if they have the same set of parameter substitutions. Two parameter substitutions are considered to be the same if they reference the same formal parameter and actual element.

NOTE. The sameness of parameter substitutions is determined by the elements referenced, regardless of the names that may be used to reference those elements in the Alf text for a template binding. That is, the use of unqualified names, qualified names or aliases is irrelevant to the determination of whether two template bindings are identical, so long as corresponding names resolve to the same element.

  1. For each subset, create a single equivalent bound element (as defined above), starting with any one member of the subset.

  2. Replace any reference to any element in the model with a template binding with a reference to the equivalent bound element for its subset.

In order to simplify the identification of equivalent bound elements after the above substitutions are carried out, Alf defines a standard naming convention for such elements, constructed as follows.

  1. Take the fully qualified name of each actual element in the template binding and replace all “::” separators with “$” characters. If the actual element is itself a template binding, then use the name of the equivalent bound element.

  2. Concatenate the modified names, separated by “_” (one underscore), and prepended and postpended with “__” (two underscores).

  3. Concatenate “$$”, the name of the target template of the template binding and the argument name list from 2 to produce the standard name of the equivalent bound element.

For example, the standard name for the equivalent bound element for Set is

$$Set__UML$AuxiliaryConstructs$PrimitiveTypes$Integer__

Note that the qualified name for an element is determined by its owning namespace. Therefore, even though the name “Integer” resolves in Alf to “Alf::Library::PrimitiveTypes:: Integer”, this element is just an import of “UML::AuxiliaryTypes::PrimitiveTypes:: Integer” (see Subclause 11.2), and it is the latter qualified name that is used.

Since the initial copy of the template model element also copies the reference to the namespace of the original template, the equivalent bound element is considered to be added to that namespace. A modeling environment must disallow any user-created element in a namespace with template elements with a name that would conflict with a standard equivalent bound element name created as defined above.



NOTE. The concept of equivalent bound elements defined above is intended to provide a specification of the semantics of template instantiation compatible with execution semantics that are defined only on the fUML subset. It is not required that a conforming implementation actually physically generate equivalent bound elements in order to execute Alf text, particularly if that implementation semantically conforms through interpretive or translational execution (see Subclause 2.2). However, an implementation that conforms through compilative execution must produce a UML model conforming to the fUML subset, in which case the implementation would, in fact, need to replace templates and bindings with equivalent elements as described here (or similar elements with an equivalent effect, as discussed in Subclause 2.2).


Download 1.74 Mb.

Share with your friends:
1   2   3   4   5   6   7   8   9   ...   62




The database is protected by copyright ©ininet.org 2024
send message

    Main page