OCL Abstract Syntax Models

Overview

This section defines the classes that make up the Object Command Language (the core part of XOCL). They are defined in the package OCL. The syntax classes are grouped roughly in terms of their basic properties and usage.

The figure below shows classes for atomic expressions. These are simple expressions that do not contain sub-expressions:

Atomic Expressions

Patterns are used in OCL expressions in many places that bindings can opccur. The model of patterns is defined below:

Patterns

Consp is a pair pattern, Varp is a simple variable, Includingp is a set pattern, Objectp is a pattern corresponding to a constructor, Addp is a sequence concatenation or set union pattern, Constp is a constant (where the constant is the result of evaluating an expression), Condp is a guard and Keywordp is a pattern matching objects where the slots are given as keys.

The following example shows how each of the pattern instances occur for a (somewhat unrealistic) example operation:
[1] XMF> [| 
@Operation(x:Integer, // Just bind x (optionally check the type).
10, // Fails if 2nd arg is not 10.
Seq{x,y:Boolean}, // Expect a 2-element sequence.
Seq{a | 8}, // Expect a pair.
XCore::Class(name), // Expect an instance of XCore::Class and bind name.
XCore::Class[name=n], // Expect an instance of XCore::Class and bind n.
z when z->size = 10, // Expect a collection of size 10.
S->including(10), // Expect a collection containing 10. Remove 10 and bind S.
S1 + S2) // Expect a collection, bind S1 and S2 to two distinct halves.
x
end |]
.parameters;
produces the following output:
Seq{
Varp(x,[| Integer |]),
Constp([| 10 |]),
Consp(Varp(x,[| XCore::Element |]),Consp(Varp(y,[| Boolean |]),Constp([| Seq{} |]))),
Consp(Varp(a,[| XCore::Element |]),Constp([| 8 |])),
Objectp[
names = Seq{Class},
class = XCore,
slots = Seq{Varp(name,[| XCore::Element |])}],
Keywordp(XCore,Seq{Class},Seq{Keyp(name,Varp(n,[| XCore::Element |]))}),
Condp(Varp(z,[| XCore::Element |]),[| z->size = 10 |]),
Includingp[
set = Varp(S,[| XCore::Element |]),
element = Constp([| 10 |])],
Addp[
left = Varp(S1,[| XCore::Element |]),
right = Varp(S2,[| XCore::Element |])]}
[1] XMF>
The following diagram shows the abstract syntax of let-expressions:

Let

The following figure shows the abstract syntax of iteration expressions. Both set and sequence expressions are represented as instances of SetExp with the collType set to Set or Seq respectively. A CollExp supports all concrete expressions of the form S->x(a,b,c) and S->x where the arguments to the latter default to the empty sequence. IterExp represents all concrete expressions of the form S->n(x | e) where n is exists, forAll, select, collect or reject.

Iteration

The following figure shows the abstract syntax of operation expressions and the related application of operations:

Ops

Update Expressions

Update Expressions