An increment expression is one that uses the increment operator ++. A decrement expression is one that uses the decrement operator --. Either of these operators may be used in either a prefix form, in which the operator appears before the the operand expression, or a postfix form, in which the operator appears after the operand expression.
Examples
Postfix Form
count++
size--
total[i]++
Prefix Form
++count
--numberWaiting[queueIndex]
Syntax
IncrementOrDecrementExpression(e: IncrementOrDecrementExpression)
= PostfixExpression(e)
| PrefixExpression(e) (e.isPrefix=true)
PostfixExpression(e: IncrementOrDecrementExpression)
= LeftHandSide(e.operand) AffixOperator(e.operator)
PrefixExpression(e: IncrementOrDecrementExpression)
= AffixOperator(e.operator) LeftHandSide(e.operand)
AffixOperator(op: String)
= "++"(op) | "--"(op)
Figure 8 25 Increment and Decrement Expressions
Cross References
-
Expression see Subclause 8.1
-
LeftHandSide see Subclause 8.8
Semantics
The operand expression for an increment or decrement expression must conform to the syntax and static semantics for the left hand side of an assignment (see Subclause 8.8). It must have type Integer and multiplicity upper bound of 1. The increment or decrement expression has type Integer, the same multiplicity lower bound as its operand expression and a multiplicity upper bound of 1.
The effect of an increment or decrement expression is to increment (++) or decrement (--) the value of its operand and then reassigns the result to the operand. If the operator is used as a postfix, then the value of the expression is the value of its operand before it is reassigned. If the operator is used as a prefix, the value of the expression is the values of its operand after it is reassigned.
For example, if the local name a has the value 5, then both a++ and ++a assign the value 6 to a. However the value of the expression a++ itself is 5, while the value of ++a is 6.
8.5.1Overview
A unary expression is an expression with a single operand expression and an operator that performs some action on the values produced by the operand. Unary operators include numeric unary operators, Boolean negation and isolation. Cast expressions, which filter a sequence of values based on type, are also considered unary expressions in terms of concrete syntax, even though their “operator” is given by a type name, not a fixed symbol.
The static and execution semantics of each kind of unary expression are discussed further in subsequent subclauses.
Syntax
UnaryExpression(e: Expression)
= PrimaryExpression(e)
| IncrementOrDecrementExpression(e)
| BooleanUnaryExpression(e)
| BitStringUnaryExpression(e)
| NumericUnaryExpression(e)
| CastExpression(e)
| IsolationExpression(e)
Figure 8 26 Base Abstract Syntax for Unary Expressions
Cross References
-
Expression see Subclause 8.1
-
PrimaryExpression see Subclause 8.3.1
-
IncrementOrDecrementExpression see Subclause 8.4
-
BooleanUnaryExpression see Subclause 8.5.2
-
NumericUnaryExpression see Subclause 8.5.4
-
CastExpression see Subclause 8.5.5
-
IsolationExpression see Subclause 8.5.6
8.5.2Boolean Unary Expressions
A Boolean unary expression is a unary expression whose operator acts on and produces Boolean values. The only Boolean unary operator is the negation operator !.
Examples
!isActive
!this.running
Syntax
BooleanUnaryExpression(e: BooleanUnaryExpression)
= "!"(e.operator) UnaryExpression(e.operand)
Figure 8 27 Abstract Syntax of Boolean Unary Expressions
Cross References
-
UnaryExpression see Subclause 8.5.1
Semantics
A Boolean unary expression must have an operand expression with type Boolean and a multiplicity upper bound of 1. The Boolean unary expression has type Boolean, the same multiplicity lower bound as its operand expression and a multiplicity upper bound of 1.
The functionality of the Boolean negation operator is the same as an application of the Alf library BooleanFunctions::'!' function (see Subclause 11.3.1) with the operand expression as its argument. If the operand is true, the result is false. If the operand is false, the result is true.
8.5.3BitString Unary Expressions
A BitString unary expression is a unary expression whose operator acts on a bit string (or an integer convertible to a bit string) and produces a bit string. The only BitString unary operator is the bit-wise complement operator ~.
Examples
~registerContext
~memory.getByte(address)
Syntax
BitStringUnaryExpression(e: BitStringUnaryExpression)
= "~"(e.operator) UnaryExpression(e.operand)
Figure 8 28 Abstract Syntax of BitString Unary Expressions
Semantics
A BitString unary expression must have an operand expression with type BitString or Integer and a multiplicity upper bound of 1. The BitString unary expression has type BitString, the same multiplicity lower bound as its operand expression and a multiplicity upper bound of 1. If the operand is an integer, then it is first converted to a bit string by applying the library BitStringFunctions::ToBitString function (see Subclause 11.3.5).
The functionality of the BitString bit-wise complement operator is the same as an application of the Alf library BitStringFunctions::'~' function (see Subclause 11.3.5) with the operand expression as its argument. The result is a bit string that has a bit set (value 1) in each bit position in which the operand bit string had its bit unset (value 0) and a bit unset (value 0) in each bit position in which the operand bit string had its bit set (value 1).
8.5.4Numeric Unary Expressions
A numeric unary expression is a unary expression that acts on and produces numeric values. The numeric unary operators are + and -.
Examples
+1234
-42
+(a*b)
-absoluteValue
Syntax
NumericUnaryExpression(e: NumericUnaryExpression)
= NumericUnaryOperator(e.operator) UnaryExpression(e.operand)
NumericUnaryOperator(op: String)
= "+"(op) | "-"(op)
Figure 8 29 Abstract Syntax of Numeric Unary Expressions
Cross References
-
UnaryExpression see Subclause 8.5.1
Semantics
A numeric unary expression must have an operand expression with type Integer and a multiplicity upper bound of 1. A numeric unary expression has type Integer, the same multiplicity lower bound as its operand expression and a multiplicity upper bound of 1.
The unary plus operator does not change its operand value, while the unary minus operator negates it. The unary minus operator has the same functionality as application of the Alf library IntegerFunctions::Neg function (see Subclause 11.3.2), with the operand expression as the argument.
NOTE. While the unary plus operator does not have any mathematical effect on its operand, it can be used as a way to effectively denote an Integer literal value. For example the literal “1234” has the type Natural (see Subclause 7.7.2) and could be either an Integer or an UnlimitedNatural value. However the expression “+1234” is unambiguously an Integer.
8.5.5Cast Expressions
A cast expression is used to filter the values of its operand expression to those of a given type. The type is named within parenthesizes and prefixes the operand expression as an effective unary operator.
Examples
(fUML::Syntax::Activity)this.getTypes()
(Person)invoice.payingParty
(any)this
Syntax
CastExpression(e: CastExpression)
= "(" TypeName(e.typeName) ")" NonNumericUnaryExpression(e.operand)
NonNumericUnaryExpression(e: Expression)
= PrimaryExpression(e)
| PostfixExpression(e)
| BooleanUnaryExpression(e)
| BitStringUnaryExpression(e)
| CastExpression(e)
| IsolationExpression(e)
Figure 8 30 Abstract Syntax of Cast Expressions
Cross References
-
Expression see Subclause 8.1
-
TypeName see Subclause 8.2
-
QualifiedName see Subclause 8.2
-
PrimaryExpression see Subclause 8.3.1
-
TypeName see Subclause 8.3.15
-
PostfixExpression see Subclause 8.4
-
BooleanUnaryExpression see Subclause 8.5.2
-
IsolationExpression see Subclause 8.5.6
Semantics
Unless the type name in a cast expression is the keyword any, the cast expression has the given type (see also Subclause 8.2 on type names). If the type name is any, then the cast expression is untyped. If the type name is a qualified name, then it must resolve to a classifier, which must not be a template, though it may be a binding of a template classifier.
A cast expression is evaluated by first evaluating its operand expression, producing a sequence of values. Any values of the operand expression whose dynamic type does not conform to the type of the cast expression are filtered out, so that all result values of the cast expression are of the given type. If the cast expression is untyped, then no values are filtered out.
For example, the cast expression
(Integer)any[]{1,"banana",2}
evaluates to
Integer[]{1,2}
NOTE. The library type Natural is a subtype of Integer and UnlimitedNatural. This means that natural literals of type Natural (see Subclause 7.7.2) can be cast to Integer or UnlimitedNatural. Thus, (Integer)2 is the Integer value 2, while (UnlimitedNatural)2 is the UnlimitedNatural value 2.
The multiplicity lower bound of a cast expression is 0 and the upper bound is the same as that of the operand expression.
8.5.6Isolation Expressions
An isolation expression is a unary expression with the isolation operator $.
NOTE. The isolation expression notation is not available at the minimum conformance level (see Subclause 2.1).
Examples
$this.monitor.getActiveSensor().getReading()
Syntax
IsolationExpression(e: IsolationExpression)
= "$"(e.operator) UnaryExpression(e.operand)
Figure 8 31 Abstract Syntax of Isolation Expressoins
Cross References
-
UnaryExpression see Subclause 8.5.1
Semantics
The isolation operator indicates that its operand expression should be evaluated in isolation, similarly to the use of the @isolated annotation for a statement (see Subclause 9.2). That is, during the evaluation of the operand expression, no object accessed as part of the evaluation of the expression or as the result of a synchronous invocation from the expression may be modified by any action that is not executed as part of the operand expression or as the result of a synchronous invocation from that expression.
NOTE. See Subclause 8.5.3.1 of the fUML Specification for a complete discussion of the semantics of isolation.
An isolation expression has the type and multiplicity of its operand expression.
Share with your friends: |