Ada Reference Manual (Ada 2022)Legal Information
Contents   Index   References   Search   Previous   Next 

2.8 Pragmas

1
A pragma is a compiler directive. There are language-defined pragmas that give instructions for optimization, listing control, etc. An implementation may support additional (implementation-defined) pragmas. 

Syntax

2
pragma ::= 
   pragma identifier [(pragma_argument_association {, pragma_argument_association})];
3/3
pragma_argument_association ::= 
     [pragma_argument_identifier =>] name
   | [pragma_argument_identifier =>] expression
   | pragma_argument_aspect_mark =>  name
   | pragma_argument_aspect_mark =>  expression
4/3
In a pragma, any pragma_argument_associations without a pragma_argument_identifier or pragma_argument_aspect_mark shall precede any associations with a pragma_argument_identifier or pragma_argument_aspect_mark.
5
Pragmas are only allowed at the following places in a program: 
6/5
After a semicolon delimiter, but not within a formal_part, discriminant_part, or declare_expression.
7/3
At any place where the syntax rules allow a construct defined by a syntactic category whose name ends with “declaration”, “item”, “statement”, “clause”, or “alternative”, or one of the syntactic categories variant or exception_handler; but not in place of such a construct if the construct is required, or is part of a list that is required to have at least one such construct.
7.1/3
In place of a statement in a sequence_of_statements.
7.2/3
At any place where a compilation_unit is allowed. 
8
Additional syntax rules and placement restrictions exist for specific pragmas. 
9
The name of a pragma is the identifier following the reserved word pragma. The name or expression of a pragma_argument_association is a pragma argument.
10/3
An identifier specific to a pragma is an identifier or reserved word that is used in a pragma argument with special meaning for that pragma. 

Static Semantics

11
If an implementation does not recognize the name of a pragma, then it has no effect on the semantics of the program. Inside such a pragma, the only rules that apply are the Syntax Rules. 

Dynamic Semantics

12
Any pragma that appears at the place of an executable construct is executed. Unless otherwise specified for a particular pragma, this execution consists of the evaluation of each evaluable pragma argument in an arbitrary order.

Implementation Requirements

13
The implementation shall give a warning message for an unrecognized pragma name. 

Implementation Permissions

14
An implementation may provide implementation-defined pragmas; the name of an implementation-defined pragma shall differ from those of the language-defined pragmas. 
15
An implementation may ignore an unrecognized pragma even if it violates some of the Syntax Rules, if detecting the syntax error is too complex. 

Implementation Advice

16/3
Normally, implementation-defined pragmas should have no semantic effect for error-free programs; that is, if the implementation-defined pragmas in a working program are replaced with unrecognized pragmas, the program should still be legal, and should still have the same semantics.
17
Normally, an implementation should not define pragmas that can make an illegal program legal, except as follows: 
18/3
A pragma used to complete a declaration;
19
A pragma used to configure the environment by adding, removing, or replacing library_items.

Syntax

20
The forms of List, Page, and Optimize pragmas are as follows:
21
  pragma List(identifier);
22
  pragma Page;
23
  pragma Optimize(identifier);
24
Other pragmas are defined throughout this Reference Manual, and are summarized in Annex L

Static Semantics

25
A pragma List takes one of the identifiers On or Off as the single argument. This pragma is allowed anywhere a pragma is allowed. It specifies that listing of the compilation is to be continued or suspended until a List pragma with the opposite argument is given within the same compilation. The pragma itself is always listed if the compiler is producing a listing.
26
A pragma Page is allowed anywhere a pragma is allowed. It specifies that the program text which follows the pragma should start on a new page (if the compiler is currently producing a listing).
27
A pragma Optimize takes one of the identifiers Time, Space, or Off as the single argument. This pragma is allowed anywhere a pragma is allowed, and it applies until the end of the immediately enclosing declarative region, or for a pragma at the place of a compilation_unit, to the end of the compilation. It gives advice to the implementation as to whether time or space is the primary optimization criterion, or that optional optimizations should be turned off. It is implementation defined how this advice is followed.

Examples

28
Examples of pragmas:
29/5
pragma List(Off); -- turn off listing generation
pragma Optimize(Off); -- turn off optional optimizations
pragma Assertion_Policy(Check); -- check assertions
pragma Assert(Exists(File_Name),
              Message => "Nonexistent file"); -- assert file exists

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