UNFINISHED CONTENT The rules applicable to the different forms of name and expression, and to their evaluation, are given in this section. Names
can denote declared entities, whether declared explicitly or implicitly
(see 3.1). Names
can also denote objects or subprograms designated by access values; the
results of type_conversions
or function_calls;
subcomponents and slices of objects and values; protected subprograms,
single entries, entry families, and entries in families of entries. Finally,
names can
denote attributes of any of the foregoing.
Syntax2
name ::=
direct_name | explicit_dereference | indexed_component | slice | selected_component | attribute_reference | type_conversion | function_call | character_literal 3
4
5
6
7/2
Certain forms of name
(indexed_components,
selected_components,
slices,
and attribute_references)
include a prefix
that is either itself a name
that denotes some related entity, or an implicit_dereference
of an access value that designates some related entity. 14
Examples of direct
names:
15
Pi -- the direct name of a number (see 3.3.2)
Limit -- the direct name of a constant (see 3.3.1) Count -- the direct name of a scalar variable (see 3.3.1) Board -- the direct name of an array variable (see 3.6.1) Matrix -- the direct name of a type (see 3.6) Random -- the direct name of a function (see 6.1) Error -- the direct name of an exception (see 11.1) 16
Examples of dereferences:
17
Next_Car.all -- explicit dereference denoting the object designated by -- the access variable Next_Car (see 3.10.1) Next_Car.Owner -- selected component with implicit dereference; -- same as Next_Car.all.Owner Examples of indexed
components:
9
My_Schedule(Sat) -- a component of a one-dimensional array (see 3.6.1) Page(10) -- a component of a one-dimensional array (see 3.6) Board(M, J + 1) -- a component of a two-dimensional array (see 3.6.1) Page(10)(20) -- a component of a component (see 3.6) Request(Medium) -- an entry in a family of entries (see 9.1) Next_Frame(L)(M, N) -- a component of a function call (see 6.1) Examples of slices:
11
Stars(1 .. 15) -- a slice of 15 characters (see 3.6.3) Page(10 .. 10 + Size) -- a slice of 1 + Size components (see 3.6) Page(L)(A .. B) -- a slice of the array Page(L) (see 3.6) Stars(1 .. 0) -- a null slice (see 3.6.3) My_Schedule(Weekday) -- bounds given by subtype (see 3.6.1 and 3.5.1) Stars(5 .. 15)(K) -- same as Stars(K) (see 3.6.3) -- provided that K is in 5 .. 15 Examples of selected
components:
17/2
Tomorrow.Month -- a record component (see 3.8)
Next_Car.Owner -- a record component (see 3.10.1) Next_Car.Owner.Age -- a record component (see 3.10.1) -- the previous two lines involve implicit dereferences Writer.Unit -- a record component (a discriminant) (see 3.8.1) Min_Cell(H).Value -- a record component of the result (see 6.1) -- of the function call Min_Cell(H) Cashier.Append -- a prefixed view of a procedure (see 3.9.4) Control.Seize -- an entry of a protected object (see 9.4) Pool(K).Write -- an entry of the task Pool(K) (see 9.4) 18
Examples of expanded
names:
19
Key_Manager."<" -- an operator of the visible part of a package (see 7.3.1)
Dot_Product.Sum -- a variable declared in a function body (see 6.1) Buffer.Pool -- a variable declared in a protected unit (see 9.11) Buffer.Read -- an entry of a protected unit (see 9.11) Swap.Temp -- a variable declared in a block statement (see 5.6) Standard.Boolean -- the name of a predefined type (see A.1) 15
Examples of attributes:
16
Color'First -- minimum value of the enumeration type Color (see 3.5.1) Rainbow'Base'First -- same as Color'First (see 3.5.1) Real'Digits -- precision of the type Real (see 3.5.7) Board'Last(2) -- upper bound of the second dimension of Board (see 3.6.1) Board'Range(1) -- index range of the first dimension of Board (see 3.6.1) Pool(K)'Terminated -- True if task Pool(K) is terminated (see 9.1) Date'Size -- number of bits for records of type Date (see 3.8) Message'Address -- address of the record variable Message (see 3.7.1) Examples of literals:
14
3.14159_26536 -- a real literal 1_345 -- an integer literal 'A' -- a character literal "Some Text" -- a string literal AggregatesExample of a record
aggregate with positional associations:
23
(4, July, 1776) -- see 3.8
24
Examples of record
aggregates with named associations:
25
(Day => 4, Month => July, Year => 1776)
(Month => July, Day => 4, Year => 1776) 26
(Disk, Closed, Track => 5, Cylinder => 12) -- see 3.8.1
(Unit => Disk, Status => Closed, Cylinder => 9, Track => 1) 27/2
Examples of component
associations with several choices:
28
(Value => 0, Succ|Pred => new Cell'(0, null, null)) -- see 3.10.1
29
-- The allocator is evaluated twice: Succ and Pred designate different cells
29.1/2
(Value => 0, Succ|Pred => <>) -- see 3.10.1
29.2/2
-- Succ and Pred will be set to null
30
31
Expression'(null record)
Literal'(Value => 0.0) Painted_Point'(0.0, Pi/2.0, Paint => Red) 11
Examples of extension
aggregates (for types defined in 3.9.1):
12
Painted_Point'(Point with Red)
(Point'(P) with Paint => Black) 13
(Expression with Left => 1.2, Right => 3.4) Addition'(Binop with null record) -- presuming Binop is of type Binary_Operation Examples of array
aggregates with positional associations:
34
(7, 9, 5, 1, 3, 2, 4, 8, 6, 0)
Table'(5, 8, 4, 1, others => 0) -- see 3.6 35
Examples of array
aggregates with named associations:
36
(1 .. 5 => (1 .. 8 => 0.0)) -- two-dimensional
(1 .. N => new Cell) -- N new cells, in particular for N = 0 37
Table'(2 | 4 | 10 => 1, others => 0)
Schedule'(Mon .. Fri => True, others => False) -- see 3.6 Schedule'(Wed | Sun => False, others => True) Vector'(1 => 2.5) -- single-component vector 38
Examples of two-dimensional
array aggregates:
39
-- Three aggregates for the same value of subtype Matrix(1..2,1..3) (see 3.6):
40
((1.1, 1.2, 1.3), (2.1, 2.2, 2.3))
(1 => (1.1, 1.2, 1.3), 2 => (2.1, 2.2, 2.3)) (1 => (1 => 1.1, 2 => 1.2, 3 => 1.3), 2 => (1 => 2.1, 2 => 2.2, 3 => 2.3)) 41
Examples of aggregates
as initial values:
42
A : Table := (7, 9, 5, 1, 3, 2, 4, 8, 6, 0); -- A(1)=7, A(10)=0
B : Table := (2 | 4 | 10 => 1, others => 0); -- B(1)=0, B(10)=1 C : constant Matrix := (1 .. 5 => (1 .. 8 => 0.0)); -- C'Last(1)=5, C'Last(2)=8 43
D : Bit_Vector(M .. N) := (M .. N => True); -- see 3.6
E : Bit_Vector(M .. N) := (others => True); F : String(1 .. 1) := (1 => 'F'); -- a one component aggregate: same as "F" 44/2
Example of an array
aggregate with defaulted others choice and with an applicable index constraint
provided by an enclosing record aggregate:
45/2
Buffer'(Size => 50, Pos => 1, Value => String'('x', others => <>)) -- see 3.7 Examples of primaries: 13
4.0 -- real literal
Pi -- named number (1 .. 10 => 0) -- array aggregate Sum -- variable Integer'Last -- attribute Sine(X) -- function call Color'(Blue) -- qualified expression Real(M*N) -- conversion (Line_Count + 10) -- parenthesized expression 14
Examples of expressions:
15/2
Volume -- primary not Destroyed -- factor 2*Line_Count -- term -4.0 -- simple expression -4.0 + A -- simple expression B**2 - 4.0*A*C -- simple expression R*Sin(θ)*Cos(φ) -- simple expression Password(1 .. 3) = "Bwv" -- relation Count in Small_Int -- relation Count not in Small_Int -- relation Index = 0 or Item_Hit -- expression (Cold and Sunny) or Warm -- expression (parentheses are required) A**(B**C) -- expression (parentheses are required) Examples of precedence:
16
not Sunny or Warm -- same as (not Sunny) or Warm
X > 4.0 and Y > 0.0 -- same as (X > 4.0) and (Y > 0.0) 17
-4.0*A**2 -- same as –(4.0 * (A**2)) abs(1 + A) + B -- same as (abs (1 + A)) + B Y**(-3) -- parentheses are necessary A / B * C -- same as (A/B)*C A + (B + C) -- evaluate B + C before adding it to A Examples of logical
operators:
12
Sunny or Warm
Filter(1 .. 10) and Filter(15 .. 24) -- see 3.6.1 13
Examples of short-circuit
control forms:
14
Next_Car.Owner /= null and then Next_Car.Owner.Age > 25 -- see 3.10.1 N = 0 or else A(N) = Hit_Value Examples of expressions
involving relational operators and membership tests:
36
X /= Y
37
"" < "A" and "A" < "Aa" -- True
"Aa" < "B" and "A" < "A " -- True 38
My_Car = null -- true if My_Car has been set to null (see 3.10.1)
My_Car = Your_Car -- true if we both share the same car My_Car.all = Your_Car.all -- true if the two cars are identical 39
N not in 1 .. 10 -- range membership test Today in Mon .. Fri -- range membership test Today in Weekday -- subtype membership test (see 3.5.1) Archive in Disk_Unit -- subtype membership test (see 3.8.1) Tree.all in Addition'Class -- class membership test (see 3.9.1) 1
The
binary adding operators + (addition) and – (subtraction) are predefined
for every specific numeric type T with their conventional meaning.
They have the following specifications:
2
function "+"(Left, Right : T) return T
function "-"(Left, Right : T) return T 3
The
concatenation operators & are predefined for every nonlimited, one-dimensional
array type T with component type C. They have the following
specifications:
4
function "&"(Left : T; Right : T) return T function "&"(Left : T; Right : C) return T function "&"(Left : C; Right : T) return T function "&"(Left : C; Right : C) return T Examples of expressions
involving binary adding operators:
13
Z + 0.1 -- Z has to be of a real type
14
"A" & "BCD" -- concatenation of two string literals 'A' & "BCD" -- concatenation of a character literal and a string literal 'A' & 'A' -- concatenation of two character literals The unary adding operators + (identity) and – (negation) are predefined for every specific numeric type T with their conventional meaning. They have the following specifications: 2
function "+"(Right : T) return T
function "-"(Right : T) return T NOTES
3
15 For modular integer types, the unary adding operator –, when given a nonzero operand, returns the result of subtracting the value of the operand from the modulus; for a zero operand, the result is zero. Got to 4.5.5 Multiplying Operators |