Annotated Ada Reference Manual (Ada 202y Draft 1)Legal Information
Contents   Index   References   Search   Previous   Next 

5.1 Simple and Compound Statements - Sequences of Statements

1/5
{AI12-0119-1} [A statement is either simple or compound. A simple_statement encloses no other statement. A compound_statement can enclose simple_statements and other compound_statements.] A parallel construct is a construct that introduces additional logical threads of control (see Clause 9) without creating a new task. Parallel loops (see 5.5) and parallel_block_statements (see 5.6.1) are parallel constructs.
1.a/5
Term entry: parallel construct — executable construct that defines multiple activities of a single task that can proceed in parallel, via the execution of multiple logical threads of control

Syntax

2/3
{AI05-0179-1} sequence_of_statements ::= statement {statement} {label}
3
statement ::= 
   {labelsimple_statement | {labelcompound_statement
4/2
{AI95-00318-02} simple_statement ::= null_statement
   | assignment_statement | exit_statement
   | goto_statement | procedure_call_statement
   | simple_return_statement | entry_call_statement
   | requeue_statement | delay_statement
   | abort_statement | raise_statement
   | code_statement
5/5
{AI95-00318-02} {AI12-0119-1} compound_statement ::= 
     if_statement | case_statement
   | loop_statement | block_statement
   | extended_return_statement
   | parallel_block_statement
   | accept_statement | select_statement
6
null_statement ::= null;
7
label ::= <<label_statement_identifier>>
8
statement_identifier ::= direct_name
9
The direct_name of a statement_identifier shall be an identifier (not an operator_symbol).

Name Resolution Rules

10
The direct_name of a statement_identifier shall resolve to denote its corresponding implicit declaration (see below).

Legality Rules

11
Distinct identifiers shall be used for all statement_identifiers that appear in the same body, including inner block_statements but excluding inner program units. 

Static Semantics

12
For each statement_identifier, there is an implicit declaration (with the specified identifier) at the end of the declarative_part of the innermost block_statement or body that encloses the statement_identifier. The implicit declarations occur in the same order as the statement_identifiers occur in the source text. If a usage name denotes such an implicit declaration, the entity it denotes is the label, loop_statement, or block_statement with the given statement_identifier.
12.a
Reason: We talk in terms of individual statement_identifiers here rather than in terms of the corresponding statements, since a given statement may have multiple statement_identifiers.
12.b
A block_statement that has no explicit declarative_part has an implicit empty declarative_part, so this rule can safely refer to the declarative_part of a block_statement.
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
The syntax rule for label uses statement_identifier which is a direct_name (not a defining_identifier), because labels are implicitly declared. The same applies to loop and block names. In other words, the label itself is not the defining occurrence; the implicit declaration is.
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/5
{AI05-0299-1} {AI12-0449-1} 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 8.3, so we didn't do it. 
12.1/3
  {AI05-0179-1} If one or more labels end a sequence_of_statements, an implicit null_statement follows the labels before any following constructs.
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
The execution of a null_statement has no effect.
14/2
{AI95-00318-02} A transfer of control is the run-time action of an exit_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
The execution of a sequence_of_statements consists of the execution of the individual statements in succession until the sequence_ is completed.
15.a
Ramification: It could be completed by reaching the end of it, or by a transfer of control. 
16/5
{AI12-0119-1} Within a parallel construct, if a transfer of control out of the construct is initiated by one of the logical threads of control, an attempt is made to cancel all other logical threads of control initiated by the parallel construct. Once all other logical threads of control of the construct either complete or are canceled, the transfer of control occurs. If two or more logical threads of control of the same construct initiate such a transfer of control concurrently, one of them is chosen arbitrarily and the others are canceled.
17/5
{AI12-0119-1} When a logical thread of control is canceled, the cancellation causes it to complete as though it had performed a transfer of control to the point where it would have finished its execution. Such a cancellation is deferred while the logical thread of control is executing within an abort-deferred operation (see 9.8), and may be deferred further, but not past a point where the logical thread initiates a new nested parallel construct or reaches an exception handler that is outside such an abort-deferred operation. 

Bounded (Run-Time) Errors

18/5
{AI12-0119-1} {AI12-0442-1} During the execution of a parallel construct, it is a bounded error to invoke an operation that is potentially blocking (see 9.5). Program_Error is raised if the error is detected by the implementation; otherwise, the execution of the potentially blocking operation can either proceed normally, or it can result in the indefinite blocking of some or all of the logical threads of control making up the current task. 
19/5
NOTE   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. 
19.a
Discussion: Each comment in the following example gives the expanded name associated with an entity declared in the task body: 
19.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

20
Examples of labeled statements: 
21
<<Here>> <<Ici>> <<Aqui>> <<Hier>> null;
22
<<After>> X := 1;

Extensions to Ada 83

22.a
The requeue_statement is new. 

Wording Changes from Ada 83

22.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.
22.c
Completion includes completion caused by a transfer of control, although RM83-5.1(6) did not take this view. 

Extensions to Ada 95

22.d/2
{AI95-00318-02} The extended_return_statement is new (simple_return_statement is merely renamed). 

Extensions to Ada 2005

22.e/3
{AI05-0179-1} A label can end a sequence_of_statements, eliminating the requirement for having an explicit null; statement after an ending label (a common use). 

Extensions to Ada 2012

22.f/5
{AI12-0119-1} The definition of “parallel constructs” and the parallel_block_statement are new. 

Contents   Index   References   Search   Previous   Next 
Ada-Europe Ada 2005 and 2012 Editions sponsored in part by Ada-Europe