5.1 Simple and Compound Statements - Sequences of Statements
1
Syntax
2/3
3
4/2
5/2
6
7
8
9
Name Resolution Rules
10
Legality Rules
11
Static Semantics
12
12.a
12.b
12.c
The scope of a declaration starts at the place
of the declaration itself (see
8.2). In the
case of a label, loop, or block name, it follows from this rule that
the scope of the implicit declaration starts before the first explicit
occurrence of the corresponding name, since this occurrence is either
in a statement label, a
loop_statement,
a
block_statement,
or a
goto_statement.
An implicit declaration in a
block_statement
may hide a declaration given in an outer program unit or
block_statement
(according to the usual rules of hiding explained in
8.3).
12.d
12.e
We cannot consider
the
label
to be a defining occurrence. An example that can tell the difference
is this:
12.f
declare
-- Label Foo is implicitly declared here.
begin
for Foo in ... loop
...
<<Foo>> -- Illegal.
...
end loop;
end;
12.g
The label in this example is hidden from itself
by the loop parameter with the same name; the example is illegal. We
considered creating a new syntactic category name, separate from
direct_name
and
selector_name,
for use in the case of statement labels. However, that would confuse
the rules in Section 8, so we didn't do it.
12.1/3
12.g.1/3
Reason: The semantics
of a goto_statement
is defined in terms of the statement having (following) that label. Thus
we ensure that every label has a following statement, which might be
implicit.
Dynamic Semantics
13
14/2
{
AI95-00318-02}
A
transfer of control is the run-time action
of an
exit_statement,
return statement return_statement,
goto_statement,
or
requeue_statement,
selection of a
terminate_alternative,
raising of an exception, or an abort, which causes the next action performed
to be one other than what would normally be expected from the other rules
of the language. [As explained in
7.6.1,
a transfer of control can cause the execution of constructs to be completed
and then left, which may trigger finalization.]
15
15.a
Ramification: It could be completed by
reaching the end of it, or by a transfer of control.
16
1 A
statement_identifier
that appears immediately within the declarative region of a named
loop_statement
or an
accept_statement
is nevertheless implicitly declared immediately within the declarative
region of the innermost enclosing body or
block_statement;
in other words, the expanded name for a named statement is not affected
by whether the statement occurs inside or outside a named loop or an
accept_statement
— only nesting within
block_statements
is relevant to the form of its expanded name.
16.a
Discussion:
Each comment in the following example gives the expanded name associated
with an entity declared in the task body:
16.b
task body Compute is
Sum : Integer := 0; -- Compute.Sum
begin
Outer: -- Compute.Outer
for I in 1..10 loop -- Compute.Outer.I
Blk: -- Compute.Blk
declare
Sum : Integer := 0; -- Compute.Blk.Sum
begin
accept Ent(I : out Integer; J : in Integer) do
-- Compute.Ent.I, Compute.Ent.J
Compute.Ent.I := Compute.Outer.I;
Inner: -- Compute.Blk.Inner
for J in 1..10 loop
-- Compute.Blk.Inner.J
Sum := Sum + Compute.Blk.Inner.J * Compute.Ent.J;
end loop Inner;
end Ent;
Compute.Sum := Compute.Sum + Compute.Blk.Sum;
end Blk;
end loop Outer;
Record_Result(Sum);
end Compute;
Examples
17
Examples of labeled
statements:
18
<<Here>> <<Ici>> <<Aqui>> <<Hier>> null;
19
<<After>> X := 1;
Extensions to Ada 83
19.a
Wording Changes from Ada 83
19.b
We define the syntactic category
statement_identifier
to simplify the description. It is used for labels, loop names, and block
names. We define the entity associated with the implicit declarations
of statement names.
19.c
Completion includes completion caused by a transfer
of control, although RM83-5.1(6) did not take this view.
Extensions to Ada 95
19.d/2
Extensions to Ada 2005
19.e/3
Ada 2005 and 2012 Editions sponsored in part by Ada-Europe