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



Download 1.74 Mb.
Page32/62
Date28.01.2017
Size1.74 Mb.
#9041
1   ...   28   29   30   31   32   33   34   35   ...   62

11Standard Model Library


Every modeling environment using Alf must also make available a set of models known as the Alf Standard Model Library. This library consists of the profile ActionLanguage and the model library package Alf::Library. The Alf::Library package contains the subpackages shown in Figure 11 -73.

NOTE. The ActionLanguage profile is not nested within Alf::Library because it may also be useful outside the context of Alf.

Figure 11 73 Alf Standard Model Library Subpackages

The ActionLanguage profile is described in Subclause 11.1. The subpackages of Alf::Library are then described in subsequent subclauses.

11.1ActionLanguage Profile


The ActionLanguage profile contains the single stereotype shown in Figure 11 -74. When applied to a comment, this stereotype indicates that the body of the comment is the textual representation of the element to which the comment is attached, potentially including the representation of other modeling elements contained in the element to which the comment is attached (see Subclause 6.1). The language attribute gives the name of the language in which the comment body text is written, using the same naming conventions as for the language attribute of an opaque behavior.

Figure 11 74 Stereotype TextualRepresentation


11.2Primitive Types


Alf is based on UML 2.4. However, the fUML Foundational Model Library imports the UML 2.3 AuxiliaryTypes::PrimitiveTypes package (see fUML Specification, Subclause 9.2) and the primitive behaviors defined in the Foundational Model Library are based on the UML 2.3 primitive types. Since the Alf Standard Model Library builds on the fUML libarary behaviors (see Subclause 11.3 below), the Alf::Library::PrimitiveTypes package imports the AuxiliaryTypes::PrimitiveTypes package from the UML 2.3 superstructure (see Subclause 17.4 of the OMG UML Superstructure, Version 2.3, formal/2010-05-05), as shown in Figure 11 -73. (It is expected that, in the future, the fUML Foundational Model Library will be updated to use UML 2.4 primitive types, in which case the Alf Standard Model Library may be similarly updated.)

Importing, the UML 2.3 AuxiliaryTypes::PrimitiveTypes package makes the UML primitive types Integer, Boolean, String and UnlimitedNatural available in the Alf::Library::PrimitiveTypes namespace. In addition to the imported types, the Alf PrimitiveTypes package also includes natural and bit string types described in the remainder of this subclause.

To be recognized as primitive types in an fUML execution environment, the types defined in the Alf::Library::PrimitiveTypes package (including imported types) must be registered with any execution locus at which they are to be used (see fUML Specification, Subclause 8.2.1).

11.2.1Natural Type


As shown in Figure 11 -75, the primitive type Natural specializes both Integer and UnlimitedNatural. Natural literals have the type Natural unless they can be determined statically to be of type Integer or UnlimitedNatural from their context of use (see Subclause 7.7.2).

Figure 11 75 Primitive Type Natural


11.2.2Bit String Type


The primitive type BitString represents values that are uninterpreted sequences of bits, each of which has either be set (bit value of 1) or unset (bit value of 0). Alf does not provide direct literals for bit strings, but the standard BitStringFunctions package provides functions for converting integers to bit strings and vice versa.

The length of a bit string is the number of bits in the string. For any conforming implementation, all bit strings must have the same length, but this length may differ between implementations. However, if an implementation limits supported integer values to a finite set (as permitted in Subclause 9.1 of the fUML Specification), the implemented bit string length must be at least long enough to represent the conversion from every supported integer value (positive or negative). If an implementation does not limit supported integer values, then the implemented bit string length must not be smaller than 32.


11.3Primitive Behaviors


As shown in Figure 11 -76, the Alf::Library::PrimitiveBehaviors package has subpackages corresponding to each of the subpackages in the fUML standard FoundationalModelLibrary:: PrimitiveBehaviors package (see fUML Specification, Subclause 9.2) except for the ListFunctions package. Each of these primitive behavior packages imports the primitive functions from the corresponding fUML package, renaming certain functions with aliases so that they have names consistent with the corresponding operators used in the Alf expression syntax. In addition, the Alf PrimitiveBehaviors package also includes the BitString Functions and SequenceFunctions packages.

Figure 11 76 Primitive Behavior Packages

To be usable in an fUML execution environment, implementations of all of the function behaviors in each of the subpackages of the Alf::Library::PrimitiveBehaviors package (including imported behaviors) must be registered with any execution locus at which they are to be used (see fUML Specification, Subclause 8.2.1). These implementations must conform to the specifications for the behaviors they implement, as given in fUML Specification, Subclause 9.2, or in this subclause, as appropriate.

11.3.1Boolean Functions


The Alf::Library::PrimitiveBehaviors::BooleanFunctions package imports all the behaviors contained in the fUML FoundationalModelLibrary::PrimitiveBehaviors:: BooleanFunctions package. Table 11 -8 lists these functions with their Alf aliases, along with their corresponding fUML name. The formal specification for these functions is given in Clause 9.2.1 of the fUML Specification.

Table 11 8 Boolean Functions

Function Signature

fUML Name

Description

'|'(in x: Boolean, in y: Boolean):

Boolean


Or

True if either x or y is true.

'^'(in x: Boolean, in y: Boolean):

Boolean


Xor

True if either x or y is true, but not both.

'&'(in x: Boolean, in y: Boolean):

Boolean


And

True if both x and y are true.

'!'(in x: Boolean): Boolean

Not

True if x is false.

Implies

(in x: Boolean, in y: Boolean):

Boolean


Implies

True if x is false, or if x is true and y is true.

ToString(in x: Boolean): String

ToString

Converts x to a String value.

ToBoolean(in x: String):

Boolean[0..1]



ToBoolean

Converts x to a Boolean value.

11.3.2Integer Functions


The Alf::Library::PrimitiveBehaviors::IntegerFunctions package imports all the behaviors contained in the fUML FoundationalModelLibrary::PrimitiveBehaviors:: IntegerFunctions package. Table 11 -9 lists these functions with their Alf aliases, along with their corresponding fUML name. The formal specification for these functions is given in Clause 9.2.2 of the fUML Specification.

The package also includes the additional ToNatural function, in addition to the functions imported from the fUML IntegerFunctions package. This function converts a string representation of a natural (unsigned) number in any of the forms given in Subclause 7.7.2, as opposed to the ToInteger function which only converts from a decimal string representation (and also allows a sign).



Table 11 9 Integer Functions

Function Signature

fUML Name

Description

Neg(in x: Integer): Integer

Neg

The negative value of x.

Abs(in x: Integer): Integer

Abs

The absolute value of x.

'+'(in x: Integer, in y: Integer):

Integer


+

The value of the addition of x and y.

'-'(in x: Integer, in y: Integer):

Integer


-

The value of the subtraction of x and y.

'*'(in x: Integer, in y: Integer):

Integer


*

The value of the multiplication of x and y.

'/'(in x: Integer, in y: Integer):

Integer[0..1]



Div

The number of times that y fits completely within x.

'%'(in x: Integer, in y: Integer):

Integer


Mod

The result is x modulo y.

Max(in x: Integer, in y: Integer):

Integer


Max

The maximum of x and y.

Min(in x: Integer, in y: Integer):

Integer


Min

The minimum of x and y.

'<'(in x: Integer, in y: Integer):

Boolean


<

True if x is less than y.

'>'(in x: Integer, in y: Integer):

Boolean


>

True if x is greater than y.

'<='(in x: Integer, in y: Integer):

Boolean


<=

True if x is less than or equal to y.

'>='(in x: Integer, in y: Integer):

Boolean


>=

True if x is greater than or equal to y.

ToString(in x: Integer): String

ToString

Converts x to a String value.

ToUnlimitedNatural

(in x: Integer):

UnlimitedNatural[0..1]


ToUnlimitedNatural

Converts x to an UnlimitedNatural value.

ToInteger(in x: String):

Integer[0..1]



ToInteger

Converts x to an Integer value.

ToNatural(in x: String):

Integer[0..1]






Converts x to an Integer value, where x is any legal representation of a natural literal.

11.3.3String Functions


The Alf::Library::PrimitiveBehaviors::StringFunctions package imports all the behaviors contained in the fUML FoundationalModelLibrary::PrimitiveBehaviors:: StringFunctions package. Table 11 -10 lists these functions with their Alf aliases, along with their corresponding fUML name. The formal specification for these functions is given in Clause 9.2.3 of the fUML Specification.

Table 11 10 String Functions

Function Signature

fUML Name

Description

'+'(in x: String, in y: String):

String


Concat

The concatenation of x and y.

Size(in x: String): Integer

Size

The number of characters in x.

Substring

(in x: String,

in lower: Integer,

in upper: Integer):

String[0..1]


Substring

The substring of x starting at character number lower, up to and including character number upper. Character numbers run from 1 to Size(x).

11.3.4UnlimitedNatural Functions


The Alf::Library::PrimitiveBehaviors::UnlimitedNaturalFunctions package imports all the behaviors contained in the fUML FoundationalModelLibrary:: PrimitiveBehaviors::UnlimitedNaturalFunctions package. Table 11 -9 lists these functions with their Alf aliases, along with their corresponding fUML name. The formal specification for these functions is given in Clause 9.2.4 of the fUML Specification.

Table 11 11 UnlimitedNatural Functions

Function Signature

fUML Name

Description

Max

(in x: UnlimitedNatural,

in y: UnlimitedNatural):

UnlimitedNatural



Max

The maximum of x and y.

Min

(in x: UnlimitedNatural,

in y: UnlimitedNatural):

UnlimitedNatural



Min

The minimum of x and y.

'<'

(in x: UnlimitedNatural,

in y: UnlimitedNatural):

Boolean


<

True if x is less than y.

'>'

(in x: UnlimitedNatural,

in y: UnlimitedNatural):

Boolean


>

True if x is greater than y.

'<='

(in x: UnlimitedNatural,

in y: UnlimitedNatural):

Boolean


<=

True if x is less than or equal to y.

'>='

(in x: UnlimitedNatural,

in y: UnlimitedNatural):

Boolean


>=

True if x is greater than or equal to y.

ToString(in x: UnlimitedNatural):

String


ToString

Converts x to a String value.

ToInteger

(in x: UnlimitedNatural):

Integer[0..1]


ToInteger

Converts x to an Integer value.

ToUnlimitedNatural(in x: String):

UnlimitedNatural[0..1]



ToUnlimitedNatural

Converts x to an UnlimitedNatural value.

11.3.5Bit String Functions


The Alf::Library::PrimitiveBehaviors::BitStringFunctions package contains a set of functions used to manipulate bit strings. Table 11 -12 lists a basic set of functions included in the package for constructing and accessing bit strings. Table 11 -13 lists functions corresponding to bit-wise operations for which there is a binary operator syntax.

Table 11 12 Basic Bit String Functions

Function Signature

Description

IsSet(in b: BitString, n: Integer):

Boolean


True if the n-th bit of b is set. Bits are numbered from zero starting with the rightmost bit position. If n is greater than or equal to the length of the bit string, then the result for the leftmost bit is returned.

BitLength(): Integer

The implemented bit string length.

ToBitString(in n: Integer): BitString

The bit string representation of n.

ToInteger(in b: BitString): Integer

The integer represented by the bit string b.

ToHexString(in b: BitString): String

The string representation of b as a hexadecimal numeral.

ToOctalString(in b: BitString): String

The string representation of b as an octal numeral.

There are no literals for bit strings, so the only way to construct a bit string is by using the function toBitString. This function takes an integer value and returns a bit string consisting of the twos-complement binary representation of that value, with the low-order bit being the rightmost bit (bit position 0). If an implementation supports arbitrary integer values, and the twos-complement representation of an integer value is longer than the bit string length for that implementation, then the result of toBitString consists of the low-order bits of the representation, truncated at the implemented bit string length.

Note that, in most cases, it is not necessary to call toBitString explicitly, because such a call is automatically inserted as a result of implicit bit string conversion of an integer value (see Subclause 8.8). The function toInteger performs the inverse conversion from a bit string to an integer value.

Alf provides special operator syntax for unary and binary bit-wise and shift functions on bit strings (see Subclauses 8.x, 8.y and 8.z). This operator syntax is a shorthand for the invocation of the correspondingly named function behaviors given in Table 11 -13. The required behavior of each of these functions is specified as a post-condition on its result, written in the Object Constraint Language (OCL), Version 2.0 (see the OCL Specification). The standard OCL notation is extended to allow calls to the functions isSet and length defined in Table 11 -12.

Table 11 13 Bit-wise Operator Functions

Function Signature

Description

'~'(in b: BitString): BitString

The bit-wise complement of b.

Post:


Sequence{0..BitLength()-1}->

forAll(i |

IsSet(result,i)= not IsSet(b,i)

)


'&'(in b1: BitString, in b2: BitString):

BitString



The bit-wise “and” of b1 and b2.

Post:


Sequence{0..BitLength()-1}->

forAll(i |

isSet(result,i) =

isSet(b1,i) and isSet(b2,i)

)


'^'(in b1: BitString, in b2: BitString):

BitString



The bit-wise “exclusive or” of b1 and b2.

Post:


Sequence{0..BitLength()-1}->

forAll(i |

IsSet(result,i) =

IsSet(b1,i) xor IsSet(b2,i)

)


'|'(in b1: BitString, in b2: BitString):

BitString



The bit-wise “inclusive or” of b1 and b2.

Post:


Sequence{0..BitLength()-1}->

forAll(i |

IsSet(result,i) =

IsSet(b1,i) or IsSet(b2,i)

)


'<<'(in b: BitString, in n: Integer):

BitString



The bit string b shifted n places to the left.

Post:


if n <= 0 then result = b

else


Sequence{0..BitLength()-1}->

forAll(i |

if i < n then

not IsSet(result,i)

else

IsSet(result,i) =



IsSet(b,i-n)

endif


)

endif


'>>'(in b: BitString, in n: Integer):

BitString



The bit string b shifted n places to the right with “sign extension” of the leftmost bit.

Post:


if n <= 0 then result = b

else


Sequence{0..BitLength()-1}->

forAll(i |

if i < BitLength()-n then

IsSet(result,i) =

IsSet(b,i+n)

else


IsSet(result,i) =

IsSet(b,BitLength()-1)

endif

)

endif



'>>>'(in b: BitString, in n: Integer):

BitString



The bit string b shifted n places to the right.

Post:


if n <= 0 then result = b

else


Sequence{0..BitLength()-1}->

forAll(i |

if i < BitLength()-n then

IsSet(result,i) =

IsSet(b,i+n)

else


not IsSet(result,i)

endif


)

endif

11.3.6Sequence Functions


The Alf::Library::PrimitiveBehaviors::SequenceFunctions package contains a set of functions used to manipulate sequences of values. Table 11 -14 lists function behaviors that are included in the SequenceFunctions package. The required behavior of each function is specified as a post-condition on its result, written in the Object Constraint Language (OCL), Version 2.0 (see the OCL Specification). In some cases, a pre-condition is also specified for a function. In this case, if the pre-condition is violated, then the function completes execution, but produces no output value. The result parameters for such functions are specified to have multiplicity 0..1 to allow for this.

Note that all the functions in Table 11 -14 take a sequence as an in parameter and return some result based on that sequence. The CollectionFunctions package also includes a number of behaviors that take a sequence as an inout parameter and make changes to that sequence “in place”. Table 11 -15 listsSince these functions are intended to apply to sequences of any type of value, the function parameters for such sequences and their elements are untyped. This, however, means that, using the normal typing rules, any type information on an input sequence to one of these functions is lost when the function is used, which can be inconvenient.

For example, suppose integerList is a sequence of type Integer and consider the application of the including function to it to define an extended list. Unfortunately, the following is illegal:

let extendedList: Integer[] = _including(integerList, 1); // Type error!

Since the result of the call to including is untyped, it is not assignable to extendedList, which has type Integer. Instead, an explicit cast must be used:

let extendedList: Integer[] = (Integer)_including(integerList, 1); // Legal

To avoid having to do this, the template function behaviors in the CollectionFunctions package (see Subclause 11.5) should generally be used in preference to the primitive behaviors defined in the SequenceFunctions package. Note, however, that these template functions are actually defined in terms of the primitive sequence functions, since only non-template primitive behavior implementations can be registered with the fUML execution locus.

Table 11 14 Sequence Functions

Function Signature

Description

Size

(in seq: any[*] sequence):

Integer


The number of elements in seq.

Post: result = seq->size()



Includes

(in seq: any[*] sequence,

in element: any):

Boolean


True if element is an element of seq, false otherwise.

Post: result = seq->includes(element)



Excludes

(in seq: any[*] sequence,

in element: any):

Boolean


True if element is not an element of seq, false otherwise.

Post: result = seq->excludes(element)



Count

(in seq: any[*] sequence,

in element: any):

Integer


The number of times that element occurs in seq.

Post: result = seq->count(element)



IsEmpty

(in seq: any[*] sequence):

Boolean


True if seq is empty.

Post: result = seq->isEmpty()



NotEmpty

(in seq: any[*] sequence):

Boolean


True if seq is not empty.

Post: result = seq->notEmpty()



IncludesAll

(in seq1: any[*] sequence,


in seq2: any[*] sequence):

Boolean


True if seq1 contains all the elements of seq2, false otherwise.

Post: result = seq1->includesAll(seq2)



ExcludesAll

(in seq1: any[*] sequence,


in seq2: any[*] sequence):

Boolean


True if c1 contains none of the elements of seq2, false otherwise.

Post: result = seq1->excludesAll(seq2)



Equals

(in seq1: any[*] sequence,


in seq2: any[*] sequence):

Boolean


True if seq1 contains the same elements as seq2 in the same order.

Post: result = (seq1=seq2)



At

(in seq: any[*] sequence,

in index: Integer):

any[0..1]



The index-th element of seq.

Pre: index>=1 and index<=seq->size()

Post: result = seq->at(index)


IndexOf

(in seq: any[*],

in element: any):

any[0..1]



The index of element in seq.

Pre: seq->includes(element)

Post: seq->indexOf(element)


First

(in seq: any[*] sequence):

any[0..1]


The first element of seq.

Pre: c->notEmpty()

Post: result = seq->first()


Last

(in seq: any[*] sequence):

any[0..1]


The last element of seq.

Pre: seq->notEmpty()

Post: result = seq->last()


Union

(in seq1: any[*] sequence,


in seq2: any[*] sequence):

any[*] sequence



The sequence consisting of all elements of seq1 followed by all elements of seq2.

Post: result = seq1->union(seq2)



Intersection

(in seq1: any[*] sequence,


in seq2: any[*] sequence):

any[*] sequence



The sequence consisting of all elements of seq1 that are also in seq2.

Post: result = seq1->iterate(

e; s = Sequence{} |

if seq2->excludes(e) then s

else s->append(e) endif)


Difference

(in seq1: any[*] sequence,


in seq2: any[*] sequence nonunique):

any[*] sequence



The sequence consisting of all the elements of seq1 not in seq2.

Post: result = seq1->iterate(

e; s = Sequence{} |

if seq2->includes(e) then s

else s->append(e) endif)


Including

(in seq: any[*] sequence,

in element: any):

any[*]sequence



The sequence consisting of all elements of seq followed by element.

Post: result = seq->including(element)



IncludeAt

(in seq: any[*] sequence,

in index: Integer,
in element: any):

any[*] sequence



The sequence consisting of seq with element inserted at position index.

Post: result =

if index>=1 and index<=seq->size()+1

then


seq->insertAt(index,element)

else


seq

endif


InsertAt

(in seq: any[*] sequence,

in index: Integer,
in element: any):

any[*]sequence



The sequence consisting of seq with element inserted at position index. (This is the same as _includeAt. _insertAt is included for consistency with the similar OCL operation on sequences.)

Post: result =

if index>=1 and index<=seq->size()+1

then


seq->insertAt(index,element)

else


seq

endif


IncludeAllAt

(in seq1: any[*] sequence,

in index: Integer,

in seq2: any[*] sequence:

any[*] sequence


The sequence consisting of seq1 with all elements of seq2 inserted at position index.

Post: result =

if index>=1 and index<=seq->size()+1

then


seq1->subSequence(1,index-1)->

union(seq2)->

union(seq1->subsequence(index,

seq1->size()))

else

seq


endif

Excluding

(in seq: any[*] sequence,

in element: any):

any[*] sequence



The sequence consisting of all elements of seq apart from all occurrences of element.

Post: result = seq->iterate(

e; s = Sequence{} |

if e=element then s

else s->append(e) endif)


ExcludingOne

(in seq: any[*] sequence,

in element: any):

any[*] sequence



The sequence consisting of seq with the first occurrence of element (if any) removed.

Post: result =

if seq->includes(element) then

let index = seq->indexOf(element)

in

seq->subSequence(1,index-1)->



union(seq->

subSequence(index+1,seq->size()))

else

seq


endif

ExcludeAt

(in seq: any[*] sequence,

in index: Integer):

any[*] sequence



The sequence consisting of seq with the index-th element removed.

Post: result =

if index>=1 and index<=c->size then

seq->subSequence(1,index-1)->

union(seq->

subSequence(index+1,seq->size()))

else

seq


endif

Replacing

(in seq: any[*] sequence,

in element: any,

in newElement: any):

any[*] sequence


The sequence consisting of seq with all occurrences of element replaced with newElement.

Post: result->size() = seq->size() and

Sequence{1..seq->size()}->forAll(i |

result->at(i) =

if seq->at(i) = element then

newElement

else

seq->at(i)



endif

ReplacingOne

(in seq: any[*] sequence,

in element: any,

in newElement: any):

any[*] sequence


The sequence consisting of seq with the first occurrence of element (if any) replaced with newElement.

Post: result =

if seq->excludes(element) then seq

else


let index=seq->indexOf(element) in

seq->subSequence(1,index-1)->

union(seq->

subSequence(index,seq->size()))

endif


ReplacingAt

(in seq: any[*] sequence,

in index: Integer,

in element: any):

any[*] sequence


The sequence consisting of seq with the element at position index replaced with the given element.

Pre: index>=1 and index<=seq->size()

Post: result =

seq->subSequence(1,index-1)->

union(seq->

subSequence(index,seq->size()))




Subsequence

(in seq: any[*] sequence,

in lower: Integer,

in upper: Integer):

any[*] sequence


The sub-sequence of seq consisting of the elements at position lower up to and including position upper. If upper is larger than the size of seq, then it is treated as if it was equal to the size.

Pre: lower<=upper

Post: result =

seq->subSequence(lower.max(1),

upper.min(seq->size()))


ToOrderedSet

(in seq: any[*] sequence):

any[*] ordered


The sequence seq with all duplicates removed.

Post:


result = seq->asOrderedSet()


Download 1.74 Mb.

Share with your friends:
1   ...   28   29   30   31   32   33   34   35   ...   62




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

    Main page