| 1 |
.. role:: switch(samp) |
| 2 |
|
| 3 |
.. _Implementation_Defined_Pragmas: |
| 4 |
|
| 5 |
****************************** |
| 6 |
Implementation Defined Pragmas |
| 7 |
****************************** |
| 8 |
|
| 9 |
Ada defines a set of pragmas that can be used to supply additional |
| 10 |
information to the compiler. These language defined pragmas are |
| 11 |
implemented in GNAT and work as described in the Ada Reference Manual. |
| 12 |
|
| 13 |
In addition, Ada allows implementations to define additional pragmas |
| 14 |
whose meaning is defined by the implementation. GNAT provides a number |
| 15 |
of these implementation-defined pragmas, which can be used to extend |
| 16 |
and enhance the functionality of the compiler. This section of the GNAT |
| 17 |
Reference Manual describes these additional pragmas. |
| 18 |
|
| 19 |
Note that any program using these pragmas might not be portable to other |
| 20 |
compilers (although GNAT implements this set of pragmas on all |
| 21 |
platforms). Therefore if portability to other compilers is an important |
| 22 |
consideration, the use of these pragmas should be minimized. |
| 23 |
|
| 24 |
Pragma Abort_Defer |
| 25 |
================== |
| 26 |
|
| 27 |
.. index:: Deferring aborts |
| 28 |
|
| 29 |
Syntax: |
| 30 |
|
| 31 |
.. code-block:: ada |
| 32 |
|
| 33 |
pragma Abort_Defer; |
| 34 |
|
| 35 |
|
| 36 |
This pragma must appear at the start of the statement sequence of a |
| 37 |
handled sequence of statements (right after the ``begin``). It has |
| 38 |
the effect of deferring aborts for the sequence of statements (but not |
| 39 |
for the declarations or handlers, if any, associated with this statement |
| 40 |
sequence). This can also be useful for adding a polling point in Ada code, |
| 41 |
where asynchronous abort of tasks is checked when leaving the statement |
| 42 |
sequence, and is lighter than, for example, using ``delay 0.0;``, since with |
| 43 |
zero-cost exception handling, propagating exceptions (implicitly used to |
| 44 |
implement task abort) cannot be done reliably in an asynchronous way. |
| 45 |
|
| 46 |
An example of usage would be: |
| 47 |
|
| 48 |
.. code-block:: ada |
| 49 |
|
| 50 |
-- Add a polling point to check for task aborts |
| 51 |
|
| 52 |
begin |
| 53 |
pragma Abort_Defer; |
| 54 |
end; |
| 55 |
|
| 56 |
.. _Pragma-Abstract_State: |
| 57 |
|
| 58 |
Pragma Abstract_State |
| 59 |
===================== |
| 60 |
|
| 61 |
Syntax: |
| 62 |
|
| 63 |
.. code-block:: ada |
| 64 |
|
| 65 |
pragma Abstract_State (ABSTRACT_STATE_LIST); |
| 66 |
|
| 67 |
ABSTRACT_STATE_LIST ::= |
| 68 |
null |
| 69 |
| STATE_NAME_WITH_OPTIONS |
| 70 |
| (STATE_NAME_WITH_OPTIONS {, STATE_NAME_WITH_OPTIONS} ) |
| 71 |
|
| 72 |
STATE_NAME_WITH_OPTIONS ::= |
| 73 |
STATE_NAME |
| 74 |
| (STATE_NAME with OPTION_LIST) |
| 75 |
|
| 76 |
OPTION_LIST ::= OPTION {, OPTION} |
| 77 |
|
| 78 |
OPTION ::= |
| 79 |
SIMPLE_OPTION |
| 80 |
| NAME_VALUE_OPTION |
| 81 |
|
| 82 |
SIMPLE_OPTION ::= Ghost | Synchronous |
| 83 |
|
| 84 |
NAME_VALUE_OPTION ::= |
| 85 |
Part_Of => ABSTRACT_STATE |
| 86 |
| External [=> EXTERNAL_PROPERTY_LIST] |
| 87 |
|
| 88 |
EXTERNAL_PROPERTY_LIST ::= |
| 89 |
EXTERNAL_PROPERTY |
| 90 |
| (EXTERNAL_PROPERTY {, EXTERNAL_PROPERTY} ) |
| 91 |
|
| 92 |
EXTERNAL_PROPERTY ::= |
| 93 |
Async_Readers [=> static_boolean_EXPRESSION] |
| 94 |
| Async_Writers [=> static_boolean_EXPRESSION] |
| 95 |
| Effective_Reads [=> static_boolean_EXPRESSION] |
| 96 |
| Effective_Writes [=> static_boolean_EXPRESSION] |
| 97 |
others => static_boolean_EXPRESSION |
| 98 |
|
| 99 |
STATE_NAME ::= defining_identifier |
| 100 |
|
| 101 |
ABSTRACT_STATE ::= name |
| 102 |
|
| 103 |
For the semantics of this pragma, see the entry for aspect ``Abstract_State`` in |
| 104 |
the SPARK 2014 Reference Manual, section 7.1.4. |
| 105 |
|
| 106 |
Pragma Ada_83 |
| 107 |
============= |
| 108 |
|
| 109 |
Syntax: |
| 110 |
|
| 111 |
.. code-block:: ada |
| 112 |
|
| 113 |
pragma Ada_83; |
| 114 |
|
| 115 |
|
| 116 |
A configuration pragma that establishes Ada 83 mode for the unit to |
| 117 |
which it applies, regardless of the mode set by the command line |
| 118 |
switches. In Ada 83 mode, GNAT attempts to be as compatible with |
| 119 |
the syntax and semantics of Ada 83, as defined in the original Ada |
| 120 |
83 Reference Manual as possible. In particular, the keywords added by Ada 95 |
| 121 |
and Ada 2005 are not recognized, optional package bodies are allowed, |
| 122 |
and generics may name types with unknown discriminants without using |
| 123 |
the ``(<>)`` notation. In addition, some but not all of the additional |
| 124 |
restrictions of Ada 83 are enforced. |
| 125 |
|
| 126 |
Ada 83 mode is intended for two purposes. Firstly, it allows existing |
| 127 |
Ada 83 code to be compiled and adapted to GNAT with less effort. |
| 128 |
Secondly, it aids in keeping code backwards compatible with Ada 83. |
| 129 |
However, there is no guarantee that code that is processed correctly |
| 130 |
by GNAT in Ada 83 mode will in fact compile and execute with an Ada |
| 131 |
83 compiler, since GNAT does not enforce all the additional checks |
| 132 |
required by Ada 83. |
| 133 |
|
| 134 |
Pragma Ada_95 |
| 135 |
============= |
| 136 |
|
| 137 |
Syntax: |
| 138 |
|
| 139 |
.. code-block:: ada |
| 140 |
|
| 141 |
pragma Ada_95; |
| 142 |
|
| 143 |
|
| 144 |
A configuration pragma that establishes Ada 95 mode for the unit to which |
| 145 |
it applies, regardless of the mode set by the command line switches. |
| 146 |
This mode is set automatically for the ``Ada`` and ``System`` |
| 147 |
packages and their children, so you need not specify it in these |
| 148 |
contexts. This pragma is useful when writing a reusable component that |
| 149 |
itself uses Ada 95 features, but which is intended to be usable from |
| 150 |
either Ada 83 or Ada 95 programs. |
| 151 |
|
| 152 |
Pragma Ada_05 |
| 153 |
============= |
| 154 |
|
| 155 |
Syntax: |
| 156 |
|
| 157 |
.. code-block:: ada |
| 158 |
|
| 159 |
pragma Ada_05; |
| 160 |
pragma Ada_05 (local_NAME); |
| 161 |
|
| 162 |
|
| 163 |
A configuration pragma that establishes Ada 2005 mode for the unit to which |
| 164 |
it applies, regardless of the mode set by the command line switches. |
| 165 |
This pragma is useful when writing a reusable component that |
| 166 |
itself uses Ada 2005 features, but which is intended to be usable from |
| 167 |
either Ada 83 or Ada 95 programs. |
| 168 |
|
| 169 |
The one argument form (which is not a configuration pragma) |
| 170 |
is used for managing the transition from |
| 171 |
Ada 95 to Ada 2005 in the run-time library. If an entity is marked |
| 172 |
as Ada_2005 only, then referencing the entity in Ada_83 or Ada_95 |
| 173 |
mode will generate a warning. In addition, in Ada_83 or Ada_95 |
| 174 |
mode, a preference rule is established which does not choose |
| 175 |
such an entity unless it is unambiguously specified. This avoids |
| 176 |
extra subprograms marked this way from generating ambiguities in |
| 177 |
otherwise legal pre-Ada_2005 programs. The one argument form is |
| 178 |
intended for exclusive use in the GNAT run-time library. |
| 179 |
|
| 180 |
Pragma Ada_2005 |
| 181 |
=============== |
| 182 |
|
| 183 |
Syntax: |
| 184 |
|
| 185 |
.. code-block:: ada |
| 186 |
|
| 187 |
pragma Ada_2005; |
| 188 |
|
| 189 |
|
| 190 |
This configuration pragma is a synonym for pragma Ada_05 and has the |
| 191 |
same syntax and effect. |
| 192 |
|
| 193 |
Pragma Ada_12 |
| 194 |
============= |
| 195 |
|
| 196 |
Syntax: |
| 197 |
|
| 198 |
.. code-block:: ada |
| 199 |
|
| 200 |
pragma Ada_12; |
| 201 |
pragma Ada_12 (local_NAME); |
| 202 |
|
| 203 |
|
| 204 |
A configuration pragma that establishes Ada 2012 mode for the unit to which |
| 205 |
it applies, regardless of the mode set by the command line switches. |
| 206 |
This mode is set automatically for the ``Ada`` and ``System`` |
| 207 |
packages and their children, so you need not specify it in these |
| 208 |
contexts. This pragma is useful when writing a reusable component that |
| 209 |
itself uses Ada 2012 features, but which is intended to be usable from |
| 210 |
Ada 83, Ada 95, or Ada 2005 programs. |
| 211 |
|
| 212 |
The one argument form, which is not a configuration pragma, |
| 213 |
is used for managing the transition from Ada |
| 214 |
2005 to Ada 2012 in the run-time library. If an entity is marked |
| 215 |
as Ada_2012 only, then referencing the entity in any pre-Ada_2012 |
| 216 |
mode will generate a warning. In addition, in any pre-Ada_2012 |
| 217 |
mode, a preference rule is established which does not choose |
| 218 |
such an entity unless it is unambiguously specified. This avoids |
| 219 |
extra subprograms marked this way from generating ambiguities in |
| 220 |
otherwise legal pre-Ada_2012 programs. The one argument form is |
| 221 |
intended for exclusive use in the GNAT run-time library. |
| 222 |
|
| 223 |
Pragma Ada_2012 |
| 224 |
=============== |
| 225 |
|
| 226 |
Syntax: |
| 227 |
|
| 228 |
.. code-block:: ada |
| 229 |
|
| 230 |
pragma Ada_2012; |
| 231 |
|
| 232 |
|
| 233 |
This configuration pragma is a synonym for pragma Ada_12 and has the |
| 234 |
same syntax and effect. |
| 235 |
|
| 236 |
Pragma Ada_2022 |
| 237 |
=============== |
| 238 |
|
| 239 |
Syntax: |
| 240 |
|
| 241 |
.. code-block:: ada |
| 242 |
|
| 243 |
pragma Ada_2022; |
| 244 |
pragma Ada_2022 (local_NAME); |
| 245 |
|
| 246 |
|
| 247 |
A configuration pragma that establishes Ada 2022 mode for the unit to which |
| 248 |
it applies, regardless of the mode set by the command line switches. |
| 249 |
This mode is set automatically for the ``Ada`` and ``System`` |
| 250 |
packages and their children, so you need not specify it in these |
| 251 |
contexts. This pragma is useful when writing a reusable component that |
| 252 |
itself uses Ada 2022 features, but which is intended to be usable from |
| 253 |
Ada 83, Ada 95, Ada 2005 or Ada 2012 programs. |
| 254 |
|
| 255 |
The one argument form, which is not a configuration pragma, |
| 256 |
is used for managing the transition from Ada |
| 257 |
2012 to Ada 2022 in the run-time library. If an entity is marked |
| 258 |
as Ada_2022 only, then referencing the entity in any pre-Ada_2022 |
| 259 |
mode will generate a warning. In addition, in any pre-Ada_2012 |
| 260 |
mode, a preference rule is established which does not choose |
| 261 |
such an entity unless it is unambiguously specified. This avoids |
| 262 |
extra subprograms marked this way from generating ambiguities in |
| 263 |
otherwise legal pre-Ada_2022 programs. The one argument form is |
| 264 |
intended for exclusive use in the GNAT run-time library. |
| 265 |
|
| 266 |
Pragma Aggregate_Individually_Assign |
| 267 |
==================================== |
| 268 |
|
| 269 |
Syntax: |
| 270 |
|
| 271 |
.. code-block:: ada |
| 272 |
|
| 273 |
pragma Aggregate_Individually_Assign; |
| 274 |
|
| 275 |
Where possible, GNAT will store the binary representation of a record aggregate |
| 276 |
in memory for space and performance reasons. This configuration pragma changes |
| 277 |
this behavior so that record aggregates are instead always converted into |
| 278 |
individual assignment statements. |
| 279 |
|
| 280 |
|
| 281 |
Pragma Allow_Integer_Address |
| 282 |
============================ |
| 283 |
|
| 284 |
Syntax: |
| 285 |
|
| 286 |
.. code-block:: ada |
| 287 |
|
| 288 |
pragma Allow_Integer_Address; |
| 289 |
|
| 290 |
|
| 291 |
In almost all versions of GNAT, ``System.Address`` is a private |
| 292 |
type in accordance with the implementation advice in the RM. This |
| 293 |
means that integer values, |
| 294 |
in particular integer literals, are not allowed as address values. |
| 295 |
If the configuration pragma |
| 296 |
``Allow_Integer_Address`` is given, then integer expressions may |
| 297 |
be used anywhere a value of type ``System.Address`` is required. |
| 298 |
The effect is to introduce an implicit unchecked conversion from the |
| 299 |
integer value to type ``System.Address``. The reverse case of using |
| 300 |
an address where an integer type is required is handled analogously. |
| 301 |
The following example compiles without errors: |
| 302 |
|
| 303 |
|
| 304 |
.. code-block:: ada |
| 305 |
|
| 306 |
pragma Allow_Integer_Address; |
| 307 |
with System; use System; |
| 308 |
package AddrAsInt is |
| 309 |
X : Integer; |
| 310 |
Y : Integer; |
| 311 |
for X'Address use 16#1240#; |
| 312 |
for Y use at 16#3230#; |
| 313 |
m : Address := 16#4000#; |
| 314 |
n : constant Address := 4000; |
| 315 |
p : constant Address := Address (X + Y); |
| 316 |
v : Integer := y'Address; |
| 317 |
w : constant Integer := Integer (Y'Address); |
| 318 |
type R is new integer; |
| 319 |
RR : R := 1000; |
| 320 |
Z : Integer; |
| 321 |
for Z'Address use RR; |
| 322 |
end AddrAsInt; |
| 323 |
|
| 324 |
|
| 325 |
Note that pragma ``Allow_Integer_Address`` is ignored if ``System.Address`` |
| 326 |
is not a private type. In implementations of ``GNAT`` where |
| 327 |
System.Address is a visible integer type, |
| 328 |
this pragma serves no purpose but is ignored |
| 329 |
rather than rejected to allow common sets of sources to be used |
| 330 |
in the two situations. |
| 331 |
|
| 332 |
.. _Pragma-Annotate: |
| 333 |
|
| 334 |
Pragma Annotate |
| 335 |
=============== |
| 336 |
|
| 337 |
Syntax:: |
| 338 |
|
| 339 |
pragma Annotate (IDENTIFIER [, IDENTIFIER {, ARG}] [, entity => local_NAME]); |
| 340 |
|
| 341 |
ARG ::= NAME | EXPRESSION |
| 342 |
|
| 343 |
|
| 344 |
This pragma is used to annotate programs. IDENTIFIER identifies |
| 345 |
the type of annotation. GNAT verifies that it is an identifier, but does |
| 346 |
not otherwise analyze it. The second optional identifier is also left |
| 347 |
unanalyzed, and by convention is used to control the action of the tool to |
| 348 |
which the annotation is addressed. The remaining ARG arguments |
| 349 |
can be either string literals or more generally expressions. |
| 350 |
String literals (and concatenations of string literals) are assumed to be |
| 351 |
either of type |
| 352 |
``Standard.String`` or else ``Wide_String`` or ``Wide_Wide_String`` |
| 353 |
depending on the character literals they contain. |
| 354 |
All other kinds of arguments are analyzed as expressions, and must be |
| 355 |
unambiguous. The last argument if present must have the identifier |
| 356 |
``Entity`` and GNAT verifies that a local name is given. |
| 357 |
|
| 358 |
The analyzed pragma is retained in the tree, but not otherwise processed |
| 359 |
by any part of the GNAT compiler, except to generate corresponding note |
| 360 |
lines in the generated ALI file. For the format of these note lines, see |
| 361 |
the compiler source file lib-writ.ads. This pragma is intended for use by |
| 362 |
external tools, including ASIS. The use of pragma Annotate does not |
| 363 |
affect the compilation process in any way. This pragma may be used as |
| 364 |
a configuration pragma. |
| 365 |
|
| 366 |
Pragma Assert |
| 367 |
============= |
| 368 |
|
| 369 |
Syntax:: |
| 370 |
|
| 371 |
pragma Assert ( |
| 372 |
boolean_EXPRESSION |
| 373 |
[, string_EXPRESSION]); |
| 374 |
|
| 375 |
|
| 376 |
The effect of this pragma depends on whether the corresponding command |
| 377 |
line switch is set to activate assertions. The pragma expands into code |
| 378 |
equivalent to the following: |
| 379 |
|
| 380 |
.. code-block:: ada |
| 381 |
|
| 382 |
if assertions-enabled then |
| 383 |
if not boolean_EXPRESSION then |
| 384 |
System.Assertions.Raise_Assert_Failure |
| 385 |
(string_EXPRESSION); |
| 386 |
end if; |
| 387 |
end if; |
| 388 |
|
| 389 |
|
| 390 |
The string argument, if given, is the message that will be associated |
| 391 |
with the exception occurrence if the exception is raised. If no second |
| 392 |
argument is given, the default message is ``file``:``nnn``, |
| 393 |
where ``file`` is the name of the source file containing the assert, |
| 394 |
and ``nnn`` is the line number of the assert. |
| 395 |
|
| 396 |
Note that, as with the ``if`` statement to which it is equivalent, the |
| 397 |
type of the expression is either ``Standard.Boolean``, or any type derived |
| 398 |
from this standard type. |
| 399 |
|
| 400 |
Assert checks can be either checked or ignored. By default they are ignored. |
| 401 |
They will be checked if either the command line switch *-gnata* is |
| 402 |
used, or if an ``Assertion_Policy`` or ``Check_Policy`` pragma is used |
| 403 |
to enable ``Assert_Checks``. |
| 404 |
|
| 405 |
If assertions are ignored, then there |
| 406 |
is no run-time effect (and in particular, any side effects from the |
| 407 |
expression will not occur at run time). (The expression is still |
| 408 |
analyzed at compile time, and may cause types to be frozen if they are |
| 409 |
mentioned here for the first time). |
| 410 |
|
| 411 |
If assertions are checked, then the given expression is tested, and if |
| 412 |
it is ``False`` then ``System.Assertions.Raise_Assert_Failure`` is called |
| 413 |
which results in the raising of ``Assert_Failure`` with the given message. |
| 414 |
|
| 415 |
You should generally avoid side effects in the expression arguments of |
| 416 |
this pragma, because these side effects will turn on and off with the |
| 417 |
setting of the assertions mode, resulting in assertions that have an |
| 418 |
effect on the program. However, the expressions are analyzed for |
| 419 |
semantic correctness whether or not assertions are enabled, so turning |
| 420 |
assertions on and off cannot affect the legality of a program. |
| 421 |
|
| 422 |
Note that the implementation defined policy ``DISABLE``, given in a |
| 423 |
pragma ``Assertion_Policy``, can be used to suppress this semantic analysis. |
| 424 |
|
| 425 |
Note: this is a standard language-defined pragma in versions |
| 426 |
of Ada from 2005 on. In GNAT, it is implemented in all versions |
| 427 |
of Ada, and the DISABLE policy is an implementation-defined |
| 428 |
addition. |
| 429 |
|
| 430 |
Pragma Assert_And_Cut |
| 431 |
===================== |
| 432 |
|
| 433 |
Syntax:: |
| 434 |
|
| 435 |
pragma Assert_And_Cut ( |
| 436 |
boolean_EXPRESSION |
| 437 |
[, string_EXPRESSION]); |
| 438 |
|
| 439 |
|
| 440 |
The effect of this pragma is identical to that of pragma ``Assert``, |
| 441 |
except that in an ``Assertion_Policy`` pragma, the identifier |
| 442 |
``Assert_And_Cut`` is used to control whether it is ignored or checked |
| 443 |
(or disabled). |
| 444 |
|
| 445 |
The intention is that this be used within a subprogram when the |
| 446 |
given test expresion sums up all the work done so far in the |
| 447 |
subprogram, so that the rest of the subprogram can be verified |
| 448 |
(informally or formally) using only the entry preconditions, |
| 449 |
and the expression in this pragma. This allows dividing up |
| 450 |
a subprogram into sections for the purposes of testing or |
| 451 |
formal verification. The pragma also serves as useful |
| 452 |
documentation. |
| 453 |
|
| 454 |
Pragma Assertion_Policy |
| 455 |
======================= |
| 456 |
|
| 457 |
Syntax:: |
| 458 |
|
| 459 |
pragma Assertion_Policy (CHECK | DISABLE | IGNORE | SUPPRESSIBLE); |
| 460 |
|
| 461 |
pragma Assertion_Policy ( |
| 462 |
ASSERTION_KIND => POLICY_IDENTIFIER |
| 463 |
{, ASSERTION_KIND => POLICY_IDENTIFIER}); |
| 464 |
|
| 465 |
ASSERTION_KIND ::= RM_ASSERTION_KIND | ID_ASSERTION_KIND |
| 466 |
|
| 467 |
RM_ASSERTION_KIND ::= Assert | |
| 468 |
Static_Predicate | |
| 469 |
Dynamic_Predicate | |
| 470 |
Pre | |
| 471 |
Pre'Class | |
| 472 |
Post | |
| 473 |
Post'Class | |
| 474 |
Type_Invariant | |
| 475 |
Type_Invariant'Class | |
| 476 |
Default_Initial_Condition |
| 477 |
|
| 478 |
ID_ASSERTION_KIND ::= Assertions | |
| 479 |
Assert_And_Cut | |
| 480 |
Assume | |
| 481 |
Contract_Cases | |
| 482 |
Debug | |
| 483 |
Ghost | |
| 484 |
Initial_Condition | |
| 485 |
Invariant | |
| 486 |
Invariant'Class | |
| 487 |
Loop_Invariant | |
| 488 |
Loop_Variant | |
| 489 |
Postcondition | |
| 490 |
Precondition | |
| 491 |
Predicate | |
| 492 |
Refined_Post | |
| 493 |
Statement_Assertions | |
| 494 |
Subprogram_Variant |
| 495 |
|
| 496 |
POLICY_IDENTIFIER ::= Check | Disable | Ignore | Suppressible |
| 497 |
|
| 498 |
|
| 499 |
This is a standard Ada 2012 pragma that is available as an |
| 500 |
implementation-defined pragma in earlier versions of Ada. |
| 501 |
The assertion kinds ``RM_ASSERTION_KIND`` are those defined in |
| 502 |
the Ada standard. The assertion kinds ``ID_ASSERTION_KIND`` |
| 503 |
are implementation defined additions recognized by the GNAT compiler. |
| 504 |
|
| 505 |
The pragma applies in both cases to pragmas and aspects with matching |
| 506 |
names, e.g. ``Pre`` applies to the Pre aspect, and ``Precondition`` |
| 507 |
applies to both the ``Precondition`` pragma |
| 508 |
and the aspect ``Precondition``. Note that the identifiers for |
| 509 |
pragmas Pre_Class and Post_Class are Pre'Class and Post'Class (not |
| 510 |
Pre_Class and Post_Class), since these pragmas are intended to be |
| 511 |
identical to the corresponding aspects. |
| 512 |
|
| 513 |
If the policy is ``CHECK``, then assertions are enabled, i.e. |
| 514 |
the corresponding pragma or aspect is activated. |
| 515 |
If the policy is ``IGNORE``, then assertions are ignored, i.e. |
| 516 |
the corresponding pragma or aspect is deactivated. |
| 517 |
This pragma overrides the effect of the *-gnata* switch on the |
| 518 |
command line. |
| 519 |
If the policy is ``SUPPRESSIBLE``, then assertions are enabled by default, |
| 520 |
however, if the *-gnatp* switch is specified all assertions are ignored. |
| 521 |
|
| 522 |
The implementation defined policy ``DISABLE`` is like |
| 523 |
``IGNORE`` except that it completely disables semantic |
| 524 |
checking of the corresponding pragma or aspect. This is |
| 525 |
useful when the pragma or aspect argument references subprograms |
| 526 |
in a with'ed package which is replaced by a dummy package |
| 527 |
for the final build. |
| 528 |
|
| 529 |
The implementation defined assertion kind ``Assertions`` applies to all |
| 530 |
assertion kinds. The form with no assertion kind given implies this |
| 531 |
choice, so it applies to all assertion kinds (RM defined, and |
| 532 |
implementation defined). |
| 533 |
|
| 534 |
The implementation defined assertion kind ``Statement_Assertions`` |
| 535 |
applies to ``Assert``, ``Assert_And_Cut``, |
| 536 |
``Assume``, ``Loop_Invariant``, and ``Loop_Variant``. |
| 537 |
|
| 538 |
Pragma Assume |
| 539 |
============= |
| 540 |
|
| 541 |
Syntax: |
| 542 |
|
| 543 |
:: |
| 544 |
|
| 545 |
pragma Assume ( |
| 546 |
boolean_EXPRESSION |
| 547 |
[, string_EXPRESSION]); |
| 548 |
|
| 549 |
|
| 550 |
The effect of this pragma is identical to that of pragma ``Assert``, |
| 551 |
except that in an ``Assertion_Policy`` pragma, the identifier |
| 552 |
``Assume`` is used to control whether it is ignored or checked |
| 553 |
(or disabled). |
| 554 |
|
| 555 |
The intention is that this be used for assumptions about the |
| 556 |
external environment. So you cannot expect to verify formally |
| 557 |
or informally that the condition is met, this must be |
| 558 |
established by examining things outside the program itself. |
| 559 |
For example, we may have code that depends on the size of |
| 560 |
``Long_Long_Integer`` being at least 64. So we could write: |
| 561 |
|
| 562 |
.. code-block:: ada |
| 563 |
|
| 564 |
pragma Assume (Long_Long_Integer'Size >= 64); |
| 565 |
|
| 566 |
|
| 567 |
This assumption cannot be proved from the program itself, |
| 568 |
but it acts as a useful run-time check that the assumption |
| 569 |
is met, and documents the need to ensure that it is met by |
| 570 |
reference to information outside the program. |
| 571 |
|
| 572 |
Pragma Assume_No_Invalid_Values |
| 573 |
=============================== |
| 574 |
.. index:: Invalid representations |
| 575 |
|
| 576 |
.. index:: Invalid values |
| 577 |
|
| 578 |
Syntax: |
| 579 |
|
| 580 |
.. code-block:: ada |
| 581 |
|
| 582 |
pragma Assume_No_Invalid_Values (On | Off); |
| 583 |
|
| 584 |
|
| 585 |
This is a configuration pragma that controls the assumptions made by the |
| 586 |
compiler about the occurrence of invalid representations (invalid values) |
| 587 |
in the code. |
| 588 |
|
| 589 |
The default behavior (corresponding to an Off argument for this pragma), is |
| 590 |
to assume that values may in general be invalid unless the compiler can |
| 591 |
prove they are valid. Consider the following example: |
| 592 |
|
| 593 |
.. code-block:: ada |
| 594 |
|
| 595 |
V1 : Integer range 1 .. 10; |
| 596 |
V2 : Integer range 11 .. 20; |
| 597 |
... |
| 598 |
for J in V2 .. V1 loop |
| 599 |
... |
| 600 |
end loop; |
| 601 |
|
| 602 |
|
| 603 |
if V1 and V2 have valid values, then the loop is known at compile |
| 604 |
time not to execute since the lower bound must be greater than the |
| 605 |
upper bound. However in default mode, no such assumption is made, |
| 606 |
and the loop may execute. If ``Assume_No_Invalid_Values (On)`` |
| 607 |
is given, the compiler will assume that any occurrence of a variable |
| 608 |
other than in an explicit ``'Valid`` test always has a valid |
| 609 |
value, and the loop above will be optimized away. |
| 610 |
|
| 611 |
The use of ``Assume_No_Invalid_Values (On)`` is appropriate if |
| 612 |
you know your code is free of uninitialized variables and other |
| 613 |
possible sources of invalid representations, and may result in |
| 614 |
more efficient code. A program that accesses an invalid representation |
| 615 |
with this pragma in effect is erroneous, so no guarantees can be made |
| 616 |
about its behavior. |
| 617 |
|
| 618 |
It is peculiar though permissible to use this pragma in conjunction |
| 619 |
with validity checking (-gnatVa). In such cases, accessing invalid |
| 620 |
values will generally give an exception, though formally the program |
| 621 |
is erroneous so there are no guarantees that this will always be the |
| 622 |
case, and it is recommended that these two options not be used together. |
| 623 |
|
| 624 |
.. _Pragma-Async_Readers: |
| 625 |
|
| 626 |
Pragma Async_Readers |
| 627 |
==================== |
| 628 |
|
| 629 |
Syntax: |
| 630 |
|
| 631 |
.. code-block:: ada |
| 632 |
|
| 633 |
pragma Async_Readers [ (static_boolean_EXPRESSION) ]; |
| 634 |
|
| 635 |
For the semantics of this pragma, see the entry for aspect ``Async_Readers`` in |
| 636 |
the SPARK 2014 Reference Manual, section 7.1.2. |
| 637 |
|
| 638 |
.. _Pragma-Async_Writers: |
| 639 |
|
| 640 |
Pragma Async_Writers |
| 641 |
==================== |
| 642 |
|
| 643 |
Syntax: |
| 644 |
|
| 645 |
.. code-block:: ada |
| 646 |
|
| 647 |
pragma Async_Writers [ (static_boolean_EXPRESSION) ]; |
| 648 |
|
| 649 |
For the semantics of this pragma, see the entry for aspect ``Async_Writers`` in |
| 650 |
the SPARK 2014 Reference Manual, section 7.1.2. |
| 651 |
|
| 652 |
Pragma Attribute_Definition |
| 653 |
=========================== |
| 654 |
|
| 655 |
Syntax: |
| 656 |
|
| 657 |
:: |
| 658 |
|
| 659 |
pragma Attribute_Definition |
| 660 |
([Attribute =>] ATTRIBUTE_DESIGNATOR, |
| 661 |
[Entity =>] LOCAL_NAME, |
| 662 |
[Expression =>] EXPRESSION | NAME); |
| 663 |
|
| 664 |
|
| 665 |
If ``Attribute`` is a known attribute name, this pragma is equivalent to |
| 666 |
the attribute definition clause: |
| 667 |
|
| 668 |
|
| 669 |
.. code-block:: ada |
| 670 |
|
| 671 |
for Entity'Attribute use Expression; |
| 672 |
|
| 673 |
|
| 674 |
If ``Attribute`` is not a recognized attribute name, the pragma is |
| 675 |
ignored, and a warning is emitted. This allows source |
| 676 |
code to be written that takes advantage of some new attribute, while remaining |
| 677 |
compilable with earlier compilers. |
| 678 |
|
| 679 |
Pragma C_Pass_By_Copy |
| 680 |
===================== |
| 681 |
.. index:: Passing by copy |
| 682 |
|
| 683 |
|
| 684 |
Syntax: |
| 685 |
|
| 686 |
:: |
| 687 |
|
| 688 |
pragma C_Pass_By_Copy |
| 689 |
([Max_Size =>] static_integer_EXPRESSION); |
| 690 |
|
| 691 |
|
| 692 |
Normally the default mechanism for passing C convention records to C |
| 693 |
convention subprograms is to pass them by reference, as suggested by RM |
| 694 |
B.3(69). Use the configuration pragma ``C_Pass_By_Copy`` to change |
| 695 |
this default, by requiring that record formal parameters be passed by |
| 696 |
copy if all of the following conditions are met: |
| 697 |
|
| 698 |
* |
| 699 |
The size of the record type does not exceed the value specified for |
| 700 |
``Max_Size``. |
| 701 |
* |
| 702 |
The record type has ``Convention C``. |
| 703 |
* |
| 704 |
The formal parameter has this record type, and the subprogram has a |
| 705 |
foreign (non-Ada) convention. |
| 706 |
|
| 707 |
If these conditions are met the argument is passed by copy; i.e., in a |
| 708 |
manner consistent with what C expects if the corresponding formal in the |
| 709 |
C prototype is a struct (rather than a pointer to a struct). |
| 710 |
|
| 711 |
You can also pass records by copy by specifying the convention |
| 712 |
``C_Pass_By_Copy`` for the record type, or by using the extended |
| 713 |
``Import`` and ``Export`` pragmas, which allow specification of |
| 714 |
passing mechanisms on a parameter by parameter basis. |
| 715 |
|
| 716 |
Pragma Check |
| 717 |
============ |
| 718 |
.. index:: Assertions |
| 719 |
|
| 720 |
.. index:: Named assertions |
| 721 |
|
| 722 |
|
| 723 |
Syntax: |
| 724 |
|
| 725 |
:: |
| 726 |
|
| 727 |
pragma Check ( |
| 728 |
[Name =>] CHECK_KIND, |
| 729 |
[Check =>] Boolean_EXPRESSION |
| 730 |
[, [Message =>] string_EXPRESSION] ); |
| 731 |
|
| 732 |
CHECK_KIND ::= IDENTIFIER | |
| 733 |
Pre'Class | |
| 734 |
Post'Class | |
| 735 |
Type_Invariant'Class | |
| 736 |
Invariant'Class |
| 737 |
|
| 738 |
|
| 739 |
This pragma is similar to the predefined pragma ``Assert`` except that an |
| 740 |
extra identifier argument is present. In conjunction with pragma |
| 741 |
``Check_Policy``, this can be used to define groups of assertions that can |
| 742 |
be independently controlled. The identifier ``Assertion`` is special, it |
| 743 |
refers to the normal set of pragma ``Assert`` statements. |
| 744 |
|
| 745 |
Checks introduced by this pragma are normally deactivated by default. They can |
| 746 |
be activated either by the command line option *-gnata*, which turns on |
| 747 |
all checks, or individually controlled using pragma ``Check_Policy``. |
| 748 |
|
| 749 |
The identifiers ``Assertions`` and ``Statement_Assertions`` are not |
| 750 |
permitted as check kinds, since this would cause confusion with the use |
| 751 |
of these identifiers in ``Assertion_Policy`` and ``Check_Policy`` |
| 752 |
pragmas, where they are used to refer to sets of assertions. |
| 753 |
|
| 754 |
Pragma Check_Float_Overflow |
| 755 |
=========================== |
| 756 |
.. index:: Floating-point overflow |
| 757 |
|
| 758 |
|
| 759 |
Syntax: |
| 760 |
|
| 761 |
.. code-block:: ada |
| 762 |
|
| 763 |
pragma Check_Float_Overflow; |
| 764 |
|
| 765 |
|
| 766 |
In Ada, the predefined floating-point types (``Short_Float``, |
| 767 |
``Float``, ``Long_Float``, ``Long_Long_Float``) are |
| 768 |
defined to be *unconstrained*. This means that even though each |
| 769 |
has a well-defined base range, an operation that delivers a result |
| 770 |
outside this base range is not required to raise an exception. |
| 771 |
This implementation permission accommodates the notion |
| 772 |
of infinities in IEEE floating-point, and corresponds to the |
| 773 |
efficient execution mode on most machines. GNAT will not raise |
| 774 |
overflow exceptions on these machines; instead it will generate |
| 775 |
infinities and NaN's as defined in the IEEE standard. |
| 776 |
|
| 777 |
Generating infinities, although efficient, is not always desirable. |
| 778 |
Often the preferable approach is to check for overflow, even at the |
| 779 |
(perhaps considerable) expense of run-time performance. |
| 780 |
This can be accomplished by defining your own constrained floating-point subtypes -- i.e., by supplying explicit |
| 781 |
range constraints -- and indeed such a subtype |
| 782 |
can have the same base range as its base type. For example: |
| 783 |
|
| 784 |
|
| 785 |
.. code-block:: ada |
| 786 |
|
| 787 |
subtype My_Float is Float range Float'Range; |
| 788 |
|
| 789 |
|
| 790 |
Here ``My_Float`` has the same range as |
| 791 |
``Float`` but is constrained, so operations on |
| 792 |
``My_Float`` values will be checked for overflow |
| 793 |
against this range. |
| 794 |
|
| 795 |
This style will achieve the desired goal, but |
| 796 |
it is often more convenient to be able to simply use |
| 797 |
the standard predefined floating-point types as long |
| 798 |
as overflow checking could be guaranteed. |
| 799 |
The ``Check_Float_Overflow`` |
| 800 |
configuration pragma achieves this effect. If a unit is compiled |
| 801 |
subject to this configuration pragma, then all operations |
| 802 |
on predefined floating-point types including operations on |
| 803 |
base types of these floating-point types will be treated as |
| 804 |
though those types were constrained, and overflow checks |
| 805 |
will be generated. The ``Constraint_Error`` |
| 806 |
exception is raised if the result is out of range. |
| 807 |
|
| 808 |
This mode can also be set by use of the compiler |
| 809 |
switch *-gnateF*. |
| 810 |
|
| 811 |
Pragma Check_Name |
| 812 |
================= |
| 813 |
.. index:: Defining check names |
| 814 |
|
| 815 |
.. index:: Check names, defining |
| 816 |
|
| 817 |
|
| 818 |
Syntax: |
| 819 |
|
| 820 |
.. code-block:: ada |
| 821 |
|
| 822 |
pragma Check_Name (check_name_IDENTIFIER); |
| 823 |
|
| 824 |
|
| 825 |
This is a configuration pragma that defines a new implementation |
| 826 |
defined check name (unless IDENTIFIER matches one of the predefined |
| 827 |
check names, in which case the pragma has no effect). Check names |
| 828 |
are global to a partition, so if two or more configuration pragmas |
| 829 |
are present in a partition mentioning the same name, only one new |
| 830 |
check name is introduced. |
| 831 |
|
| 832 |
An implementation defined check name introduced with this pragma may |
| 833 |
be used in only three contexts: ``pragma Suppress``, |
| 834 |
``pragma Unsuppress``, |
| 835 |
and as the prefix of a ``Check_Name'Enabled`` attribute reference. For |
| 836 |
any of these three cases, the check name must be visible. A check |
| 837 |
name is visible if it is in the configuration pragmas applying to |
| 838 |
the current unit, or if it appears at the start of any unit that |
| 839 |
is part of the dependency set of the current unit (e.g., units that |
| 840 |
are mentioned in ``with`` clauses). |
| 841 |
|
| 842 |
Check names introduced by this pragma are subject to control by compiler |
| 843 |
switches (in particular -gnatp) in the usual manner. |
| 844 |
|
| 845 |
Pragma Check_Policy |
| 846 |
=================== |
| 847 |
.. index:: Controlling assertions |
| 848 |
|
| 849 |
.. index:: Assertions, control |
| 850 |
|
| 851 |
.. index:: Check pragma control |
| 852 |
|
| 853 |
.. index:: Named assertions |
| 854 |
|
| 855 |
|
| 856 |
Syntax: |
| 857 |
|
| 858 |
:: |
| 859 |
|
| 860 |
pragma Check_Policy |
| 861 |
([Name =>] CHECK_KIND, |
| 862 |
[Policy =>] POLICY_IDENTIFIER); |
| 863 |
|
| 864 |
pragma Check_Policy ( |
| 865 |
CHECK_KIND => POLICY_IDENTIFIER |
| 866 |
{, CHECK_KIND => POLICY_IDENTIFIER}); |
| 867 |
|
| 868 |
ASSERTION_KIND ::= RM_ASSERTION_KIND | ID_ASSERTION_KIND |
| 869 |
|
| 870 |
CHECK_KIND ::= IDENTIFIER | |
| 871 |
Pre'Class | |
| 872 |
Post'Class | |
| 873 |
Type_Invariant'Class | |
| 874 |
Invariant'Class |
| 875 |
|
| 876 |
The identifiers Name and Policy are not allowed as CHECK_KIND values. This |
| 877 |
avoids confusion between the two possible syntax forms for this pragma. |
| 878 |
|
| 879 |
POLICY_IDENTIFIER ::= ON | OFF | CHECK | DISABLE | IGNORE |
| 880 |
|
| 881 |
|
| 882 |
This pragma is used to set the checking policy for assertions (specified |
| 883 |
by aspects or pragmas), the ``Debug`` pragma, or additional checks |
| 884 |
to be checked using the ``Check`` pragma. It may appear either as |
| 885 |
a configuration pragma, or within a declarative part of package. In the |
| 886 |
latter case, it applies from the point where it appears to the end of |
| 887 |
the declarative region (like pragma ``Suppress``). |
| 888 |
|
| 889 |
The ``Check_Policy`` pragma is similar to the |
| 890 |
predefined ``Assertion_Policy`` pragma, |
| 891 |
and if the check kind corresponds to one of the assertion kinds that |
| 892 |
are allowed by ``Assertion_Policy``, then the effect is identical. |
| 893 |
|
| 894 |
If the first argument is Debug, then the policy applies to Debug pragmas, |
| 895 |
disabling their effect if the policy is ``OFF``, ``DISABLE``, or |
| 896 |
``IGNORE``, and allowing them to execute with normal semantics if |
| 897 |
the policy is ``ON`` or ``CHECK``. In addition if the policy is |
| 898 |
``DISABLE``, then the procedure call in ``Debug`` pragmas will |
| 899 |
be totally ignored and not analyzed semantically. |
| 900 |
|
| 901 |
Finally the first argument may be some other identifier than the above |
| 902 |
possibilities, in which case it controls a set of named assertions |
| 903 |
that can be checked using pragma ``Check``. For example, if the pragma: |
| 904 |
|
| 905 |
|
| 906 |
.. code-block:: ada |
| 907 |
|
| 908 |
pragma Check_Policy (Critical_Error, OFF); |
| 909 |
|
| 910 |
|
| 911 |
is given, then subsequent ``Check`` pragmas whose first argument is also |
| 912 |
``Critical_Error`` will be disabled. |
| 913 |
|
| 914 |
The check policy is ``OFF`` to turn off corresponding checks, and ``ON`` |
| 915 |
to turn on corresponding checks. The default for a set of checks for which no |
| 916 |
``Check_Policy`` is given is ``OFF`` unless the compiler switch |
| 917 |
*-gnata* is given, which turns on all checks by default. |
| 918 |
|
| 919 |
The check policy settings ``CHECK`` and ``IGNORE`` are recognized |
| 920 |
as synonyms for ``ON`` and ``OFF``. These synonyms are provided for |
| 921 |
compatibility with the standard ``Assertion_Policy`` pragma. The check |
| 922 |
policy setting ``DISABLE`` causes the second argument of a corresponding |
| 923 |
``Check`` pragma to be completely ignored and not analyzed. |
| 924 |
|
| 925 |
Pragma Comment |
| 926 |
============== |
| 927 |
|
| 928 |
Syntax: |
| 929 |
|
| 930 |
|
| 931 |
.. code-block:: ada |
| 932 |
|
| 933 |
pragma Comment (static_string_EXPRESSION); |
| 934 |
|
| 935 |
|
| 936 |
This is almost identical in effect to pragma ``Ident``. It allows the |
| 937 |
placement of a comment into the object file and hence into the |
| 938 |
executable file if the operating system permits such usage. The |
| 939 |
difference is that ``Comment``, unlike ``Ident``, has |
| 940 |
no limitations on placement of the pragma (it can be placed |
| 941 |
anywhere in the main source unit), and if more than one pragma |
| 942 |
is used, all comments are retained. |
| 943 |
|
| 944 |
Pragma Common_Object |
| 945 |
==================== |
| 946 |
|
| 947 |
Syntax: |
| 948 |
|
| 949 |
|
| 950 |
:: |
| 951 |
|
| 952 |
pragma Common_Object ( |
| 953 |
[Internal =>] LOCAL_NAME |
| 954 |
[, [External =>] EXTERNAL_SYMBOL] |
| 955 |
[, [Size =>] EXTERNAL_SYMBOL] ); |
| 956 |
|
| 957 |
EXTERNAL_SYMBOL ::= |
| 958 |
IDENTIFIER |
| 959 |
| static_string_EXPRESSION |
| 960 |
|
| 961 |
|
| 962 |
This pragma enables the shared use of variables stored in overlaid |
| 963 |
linker areas corresponding to the use of ``COMMON`` |
| 964 |
in Fortran. The single |
| 965 |
object ``LOCAL_NAME`` is assigned to the area designated by |
| 966 |
the ``External`` argument. |
| 967 |
You may define a record to correspond to a series |
| 968 |
of fields. The ``Size`` argument |
| 969 |
is syntax checked in GNAT, but otherwise ignored. |
| 970 |
|
| 971 |
``Common_Object`` is not supported on all platforms. If no |
| 972 |
support is available, then the code generator will issue a message |
| 973 |
indicating that the necessary attribute for implementation of this |
| 974 |
pragma is not available. |
| 975 |
|
| 976 |
.. _Compile_Time_Error: |
| 977 |
|
| 978 |
Pragma Compile_Time_Error |
| 979 |
========================= |
| 980 |
|
| 981 |
Syntax: |
| 982 |
|
| 983 |
|
| 984 |
.. code-block:: ada |
| 985 |
|
| 986 |
pragma Compile_Time_Error |
| 987 |
(boolean_EXPRESSION, static_string_EXPRESSION); |
| 988 |
|
| 989 |
|
| 990 |
This pragma can be used to generate additional compile time |
| 991 |
error messages. It |
| 992 |
is particularly useful in generics, where errors can be issued for |
| 993 |
specific problematic instantiations. The first parameter is a boolean |
| 994 |
expression. The pragma ensures that the value of an expression |
| 995 |
is known at compile time, and has the value False. The set of expressions |
| 996 |
whose values are known at compile time includes all static boolean |
| 997 |
expressions, and also other values which the compiler can determine |
| 998 |
at compile time (e.g., the size of a record type set by an explicit |
| 999 |
size representation clause, or the value of a variable which was |
| 1000 |
initialized to a constant and is known not to have been modified). |
| 1001 |
If these conditions are not met, an error message is generated using |
| 1002 |
the value given as the second argument. This string value may contain |
| 1003 |
embedded ASCII.LF characters to break the message into multiple lines. |
| 1004 |
|
| 1005 |
Pragma Compile_Time_Warning |
| 1006 |
=========================== |
| 1007 |
|
| 1008 |
Syntax: |
| 1009 |
|
| 1010 |
|
| 1011 |
.. code-block:: ada |
| 1012 |
|
| 1013 |
pragma Compile_Time_Warning |
| 1014 |
(boolean_EXPRESSION, static_string_EXPRESSION); |
| 1015 |
|
| 1016 |
|
| 1017 |
Same as pragma Compile_Time_Error, except a warning is issued instead |
| 1018 |
of an error message. If switch *-gnatw_C* is used, a warning is only issued |
| 1019 |
if the value of the expression is known to be True at compile time, not when |
| 1020 |
the value of the expression is not known at compile time. |
| 1021 |
Note that if this pragma is used in a package that |
| 1022 |
is with'ed by a client, the client will get the warning even though it |
| 1023 |
is issued by a with'ed package (normally warnings in with'ed units are |
| 1024 |
suppressed, but this is a special exception to that rule). |
| 1025 |
|
| 1026 |
One typical use is within a generic where compile time known characteristics |
| 1027 |
of formal parameters are tested, and warnings given appropriately. Another use |
| 1028 |
with a first parameter of True is to warn a client about use of a package, |
| 1029 |
for example that it is not fully implemented. |
| 1030 |
|
| 1031 |
In previous versions of the compiler, combining *-gnatwe* with |
| 1032 |
Compile_Time_Warning resulted in a fatal error. Now the compiler always emits |
| 1033 |
a warning. You can use :ref:`Compile_Time_Error` to force the generation of |
| 1034 |
an error. |
| 1035 |
|
| 1036 |
Pragma Complete_Representation |
| 1037 |
============================== |
| 1038 |
|
| 1039 |
Syntax: |
| 1040 |
|
| 1041 |
|
| 1042 |
.. code-block:: ada |
| 1043 |
|
| 1044 |
pragma Complete_Representation; |
| 1045 |
|
| 1046 |
|
| 1047 |
This pragma must appear immediately within a record representation |
| 1048 |
clause. Typical placements are before the first component clause |
| 1049 |
or after the last component clause. The effect is to give an error |
| 1050 |
message if any component is missing a component clause. This pragma |
| 1051 |
may be used to ensure that a record representation clause is |
| 1052 |
complete, and that this invariant is maintained if fields are |
| 1053 |
added to the record in the future. |
| 1054 |
|
| 1055 |
Pragma Complex_Representation |
| 1056 |
============================= |
| 1057 |
|
| 1058 |
Syntax: |
| 1059 |
|
| 1060 |
|
| 1061 |
:: |
| 1062 |
|
| 1063 |
pragma Complex_Representation |
| 1064 |
([Entity =>] LOCAL_NAME); |
| 1065 |
|
| 1066 |
|
| 1067 |
The ``Entity`` argument must be the name of a record type which has |
| 1068 |
two fields of the same floating-point type. The effect of this pragma is |
| 1069 |
to force gcc to use the special internal complex representation form for |
| 1070 |
this record, which may be more efficient. Note that this may result in |
| 1071 |
the code for this type not conforming to standard ABI (application |
| 1072 |
binary interface) requirements for the handling of record types. For |
| 1073 |
example, in some environments, there is a requirement for passing |
| 1074 |
records by pointer, and the use of this pragma may result in passing |
| 1075 |
this type in floating-point registers. |
| 1076 |
|
| 1077 |
Pragma Component_Alignment |
| 1078 |
========================== |
| 1079 |
.. index:: Alignments of components |
| 1080 |
.. index:: Pragma Component_Alignment |
| 1081 |
|
| 1082 |
|
| 1083 |
Syntax: |
| 1084 |
|
| 1085 |
:: |
| 1086 |
|
| 1087 |
pragma Component_Alignment ( |
| 1088 |
[Form =>] ALIGNMENT_CHOICE |
| 1089 |
[, [Name =>] type_LOCAL_NAME]); |
| 1090 |
|
| 1091 |
ALIGNMENT_CHOICE ::= |
| 1092 |
Component_Size |
| 1093 |
| Component_Size_4 |
| 1094 |
| Storage_Unit |
| 1095 |
| Default |
| 1096 |
|
| 1097 |
|
| 1098 |
Specifies the alignment of components in array or record types. |
| 1099 |
The meaning of the ``Form`` argument is as follows: |
| 1100 |
|
| 1101 |
|
| 1102 |
.. index:: Component_Size (in pragma Component_Alignment) |
| 1103 |
|
| 1104 |
*Component_Size* |
| 1105 |
Aligns scalar components and subcomponents of the array or record type |
| 1106 |
on boundaries appropriate to their inherent size (naturally |
| 1107 |
aligned). For example, 1-byte components are aligned on byte boundaries, |
| 1108 |
2-byte integer components are aligned on 2-byte boundaries, 4-byte |
| 1109 |
integer components are aligned on 4-byte boundaries and so on. These |
| 1110 |
alignment rules correspond to the normal rules for C compilers on all |
| 1111 |
machines except the VAX. |
| 1112 |
|
| 1113 |
.. index:: Component_Size_4 (in pragma Component_Alignment) |
| 1114 |
|
| 1115 |
*Component_Size_4* |
| 1116 |
Naturally aligns components with a size of four or fewer |
| 1117 |
bytes. Components that are larger than 4 bytes are placed on the next |
| 1118 |
4-byte boundary. |
| 1119 |
|
| 1120 |
.. index:: Storage_Unit (in pragma Component_Alignment) |
| 1121 |
|
| 1122 |
*Storage_Unit* |
| 1123 |
Specifies that array or record components are byte aligned, i.e., |
| 1124 |
aligned on boundaries determined by the value of the constant |
| 1125 |
``System.Storage_Unit``. |
| 1126 |
|
| 1127 |
.. index:: Default (in pragma Component_Alignment) |
| 1128 |
|
| 1129 |
*Default* |
| 1130 |
Specifies that array or record components are aligned on default |
| 1131 |
boundaries, appropriate to the underlying hardware or operating system or |
| 1132 |
both. The ``Default`` choice is the same as ``Component_Size`` (natural |
| 1133 |
alignment). |
| 1134 |
|
| 1135 |
If the ``Name`` parameter is present, ``type_LOCAL_NAME`` must |
| 1136 |
refer to a local record or array type, and the specified alignment |
| 1137 |
choice applies to the specified type. The use of |
| 1138 |
``Component_Alignment`` together with a pragma ``Pack`` causes the |
| 1139 |
``Component_Alignment`` pragma to be ignored. The use of |
| 1140 |
``Component_Alignment`` together with a record representation clause |
| 1141 |
is only effective for fields not specified by the representation clause. |
| 1142 |
|
| 1143 |
If the ``Name`` parameter is absent, the pragma can be used as either |
| 1144 |
a configuration pragma, in which case it applies to one or more units in |
| 1145 |
accordance with the normal rules for configuration pragmas, or it can be |
| 1146 |
used within a declarative part, in which case it applies to types that |
| 1147 |
are declared within this declarative part, or within any nested scope |
| 1148 |
within this declarative part. In either case it specifies the alignment |
| 1149 |
to be applied to any record or array type which has otherwise standard |
| 1150 |
representation. |
| 1151 |
|
| 1152 |
If the alignment for a record or array type is not specified (using |
| 1153 |
pragma ``Pack``, pragma ``Component_Alignment``, or a record rep |
| 1154 |
clause), the GNAT uses the default alignment as described previously. |
| 1155 |
|
| 1156 |
.. _Pragma-Constant_After_Elaboration: |
| 1157 |
|
| 1158 |
Pragma Constant_After_Elaboration |
| 1159 |
================================= |
| 1160 |
|
| 1161 |
Syntax: |
| 1162 |
|
| 1163 |
.. code-block:: ada |
| 1164 |
|
| 1165 |
pragma Constant_After_Elaboration [ (static_boolean_EXPRESSION) ]; |
| 1166 |
|
| 1167 |
For the semantics of this pragma, see the entry for aspect |
| 1168 |
``Constant_After_Elaboration`` in the SPARK 2014 Reference Manual, section 3.3.1. |
| 1169 |
|
| 1170 |
.. _Pragma-Contract_Cases: |
| 1171 |
|
| 1172 |
Pragma Contract_Cases |
| 1173 |
===================== |
| 1174 |
.. index:: Contract cases |
| 1175 |
|
| 1176 |
Syntax: |
| 1177 |
|
| 1178 |
.. code-block:: ada |
| 1179 |
|
| 1180 |
pragma Contract_Cases (CONTRACT_CASE {, CONTRACT_CASE}); |
| 1181 |
|
| 1182 |
CONTRACT_CASE ::= CASE_GUARD => CONSEQUENCE |
| 1183 |
|
| 1184 |
CASE_GUARD ::= boolean_EXPRESSION | others |
| 1185 |
|
| 1186 |
CONSEQUENCE ::= boolean_EXPRESSION |
| 1187 |
|
| 1188 |
The ``Contract_Cases`` pragma allows defining fine-grain specifications |
| 1189 |
that can complement or replace the contract given by a precondition and a |
| 1190 |
postcondition. Additionally, the ``Contract_Cases`` pragma can be used |
| 1191 |
by testing and formal verification tools. The compiler checks its validity and, |
| 1192 |
depending on the assertion policy at the point of declaration of the pragma, |
| 1193 |
it may insert a check in the executable. For code generation, the contract |
| 1194 |
cases |
| 1195 |
|
| 1196 |
|
| 1197 |
.. code-block:: ada |
| 1198 |
|
| 1199 |
pragma Contract_Cases ( |
| 1200 |
Cond1 => Pred1, |
| 1201 |
Cond2 => Pred2); |
| 1202 |
|
| 1203 |
|
| 1204 |
are equivalent to |
| 1205 |
|
| 1206 |
|
| 1207 |
.. code-block:: ada |
| 1208 |
|
| 1209 |
C1 : constant Boolean := Cond1; -- evaluated at subprogram entry |
| 1210 |
C2 : constant Boolean := Cond2; -- evaluated at subprogram entry |
| 1211 |
pragma Precondition ((C1 and not C2) or (C2 and not C1)); |
| 1212 |
pragma Postcondition (if C1 then Pred1); |
| 1213 |
pragma Postcondition (if C2 then Pred2); |
| 1214 |
|
| 1215 |
|
| 1216 |
The precondition ensures that one and only one of the case guards is |
| 1217 |
satisfied on entry to the subprogram. |
| 1218 |
The postcondition ensures that for the case guard that was True on entry, |
| 1219 |
the corresponding consequence is True on exit. Other consequence expressions |
| 1220 |
are not evaluated. |
| 1221 |
|
| 1222 |
A precondition ``P`` and postcondition ``Q`` can also be |
| 1223 |
expressed as contract cases: |
| 1224 |
|
| 1225 |
.. code-block:: ada |
| 1226 |
|
| 1227 |
pragma Contract_Cases (P => Q); |
| 1228 |
|
| 1229 |
|
| 1230 |
The placement and visibility rules for ``Contract_Cases`` pragmas are |
| 1231 |
identical to those described for preconditions and postconditions. |
| 1232 |
|
| 1233 |
The compiler checks that boolean expressions given in case guards and |
| 1234 |
consequences are valid, where the rules for case guards are the same as |
| 1235 |
the rule for an expression in ``Precondition`` and the rules for |
| 1236 |
consequences are the same as the rule for an expression in |
| 1237 |
``Postcondition``. In particular, attributes ``'Old`` and |
| 1238 |
``'Result`` can only be used within consequence expressions. |
| 1239 |
The case guard for the last contract case may be ``others``, to denote |
| 1240 |
any case not captured by the previous cases. The |
| 1241 |
following is an example of use within a package spec: |
| 1242 |
|
| 1243 |
|
| 1244 |
.. code-block:: ada |
| 1245 |
|
| 1246 |
package Math_Functions is |
| 1247 |
... |
| 1248 |
function Sqrt (Arg : Float) return Float; |
| 1249 |
pragma Contract_Cases (((Arg in 0.0 .. 99.0) => Sqrt'Result < 10.0, |
| 1250 |
Arg >= 100.0 => Sqrt'Result >= 10.0, |
| 1251 |
others => Sqrt'Result = 0.0)); |
| 1252 |
... |
| 1253 |
end Math_Functions; |
| 1254 |
|
| 1255 |
|
| 1256 |
The meaning of contract cases is that only one case should apply at each |
| 1257 |
call, as determined by the corresponding case guard evaluating to True, |
| 1258 |
and that the consequence for this case should hold when the subprogram |
| 1259 |
returns. |
| 1260 |
|
| 1261 |
Pragma Convention_Identifier |
| 1262 |
============================ |
| 1263 |
.. index:: Conventions, synonyms |
| 1264 |
|
| 1265 |
Syntax: |
| 1266 |
|
| 1267 |
|
| 1268 |
:: |
| 1269 |
|
| 1270 |
pragma Convention_Identifier ( |
| 1271 |
[Name =>] IDENTIFIER, |
| 1272 |
[Convention =>] convention_IDENTIFIER); |
| 1273 |
|
| 1274 |
|
| 1275 |
This pragma provides a mechanism for supplying synonyms for existing |
| 1276 |
convention identifiers. The ``Name`` identifier can subsequently |
| 1277 |
be used as a synonym for the given convention in other pragmas (including |
| 1278 |
for example pragma ``Import`` or another ``Convention_Identifier`` |
| 1279 |
pragma). As an example of the use of this, suppose you had legacy code |
| 1280 |
which used Fortran77 as the identifier for Fortran. Then the pragma: |
| 1281 |
|
| 1282 |
|
| 1283 |
.. code-block:: ada |
| 1284 |
|
| 1285 |
pragma Convention_Identifier (Fortran77, Fortran); |
| 1286 |
|
| 1287 |
|
| 1288 |
would allow the use of the convention identifier ``Fortran77`` in |
| 1289 |
subsequent code, avoiding the need to modify the sources. As another |
| 1290 |
example, you could use this to parameterize convention requirements |
| 1291 |
according to systems. Suppose you needed to use ``Stdcall`` on |
| 1292 |
windows systems, and ``C`` on some other system, then you could |
| 1293 |
define a convention identifier ``Library`` and use a single |
| 1294 |
``Convention_Identifier`` pragma to specify which convention |
| 1295 |
would be used system-wide. |
| 1296 |
|
| 1297 |
Pragma CPP_Class |
| 1298 |
================ |
| 1299 |
.. index:: Interfacing with C++ |
| 1300 |
|
| 1301 |
Syntax: |
| 1302 |
|
| 1303 |
|
| 1304 |
:: |
| 1305 |
|
| 1306 |
pragma CPP_Class ([Entity =>] LOCAL_NAME); |
| 1307 |
|
| 1308 |
|
| 1309 |
The argument denotes an entity in the current declarative region that is |
| 1310 |
declared as a record type. It indicates that the type corresponds to an |
| 1311 |
externally declared C++ class type, and is to be laid out the same way |
| 1312 |
that C++ would lay out the type. If the C++ class has virtual primitives |
| 1313 |
then the record must be declared as a tagged record type. |
| 1314 |
|
| 1315 |
Types for which ``CPP_Class`` is specified do not have assignment or |
| 1316 |
equality operators defined (such operations can be imported or declared |
| 1317 |
as subprograms as required). Initialization is allowed only by constructor |
| 1318 |
functions (see pragma ``CPP_Constructor``). Such types are implicitly |
| 1319 |
limited if not explicitly declared as limited or derived from a limited |
| 1320 |
type, and an error is issued in that case. |
| 1321 |
|
| 1322 |
See :ref:`Interfacing_to_C++` for related information. |
| 1323 |
|
| 1324 |
Note: Pragma ``CPP_Class`` is currently obsolete. It is supported |
| 1325 |
for backward compatibility but its functionality is available |
| 1326 |
using pragma ``Import`` with ``Convention`` = ``CPP``. |
| 1327 |
|
| 1328 |
Pragma CPP_Constructor |
| 1329 |
====================== |
| 1330 |
.. index:: Interfacing with C++ |
| 1331 |
|
| 1332 |
|
| 1333 |
Syntax: |
| 1334 |
|
| 1335 |
|
| 1336 |
:: |
| 1337 |
|
| 1338 |
pragma CPP_Constructor ([Entity =>] LOCAL_NAME |
| 1339 |
[, [External_Name =>] static_string_EXPRESSION ] |
| 1340 |
[, [Link_Name =>] static_string_EXPRESSION ]); |
| 1341 |
|
| 1342 |
|
| 1343 |
This pragma identifies an imported function (imported in the usual way |
| 1344 |
with pragma ``Import``) as corresponding to a C++ constructor. If |
| 1345 |
``External_Name`` and ``Link_Name`` are not specified then the |
| 1346 |
``Entity`` argument is a name that must have been previously mentioned |
| 1347 |
in a pragma ``Import`` with ``Convention`` = ``CPP``. Such name |
| 1348 |
must be of one of the following forms: |
| 1349 |
|
| 1350 |
* |
| 1351 |
**function** ``Fname`` **return** T` |
| 1352 |
|
| 1353 |
* |
| 1354 |
**function** ``Fname`` **return** T'Class |
| 1355 |
|
| 1356 |
* |
| 1357 |
**function** ``Fname`` (...) **return** T` |
| 1358 |
|
| 1359 |
* |
| 1360 |
**function** ``Fname`` (...) **return** T'Class |
| 1361 |
|
| 1362 |
where ``T`` is a limited record type imported from C++ with pragma |
| 1363 |
``Import`` and ``Convention`` = ``CPP``. |
| 1364 |
|
| 1365 |
The first two forms import the default constructor, used when an object |
| 1366 |
of type ``T`` is created on the Ada side with no explicit constructor. |
| 1367 |
The latter two forms cover all the non-default constructors of the type. |
| 1368 |
See the GNAT User's Guide for details. |
| 1369 |
|
| 1370 |
If no constructors are imported, it is impossible to create any objects |
| 1371 |
on the Ada side and the type is implicitly declared abstract. |
| 1372 |
|
| 1373 |
Pragma ``CPP_Constructor`` is intended primarily for automatic generation |
| 1374 |
using an automatic binding generator tool (such as the :switch:`-fdump-ada-spec` |
| 1375 |
GCC switch). |
| 1376 |
See :ref:`Interfacing_to_C++` for more related information. |
| 1377 |
|
| 1378 |
Note: The use of functions returning class-wide types for constructors is |
| 1379 |
currently obsolete. They are supported for backward compatibility. The |
| 1380 |
use of functions returning the type T leave the Ada sources more clear |
| 1381 |
because the imported C++ constructors always return an object of type T; |
| 1382 |
that is, they never return an object whose type is a descendant of type T. |
| 1383 |
|
| 1384 |
Pragma CPP_Virtual |
| 1385 |
================== |
| 1386 |
.. index:: Interfacing to C++ |
| 1387 |
|
| 1388 |
|
| 1389 |
This pragma is now obsolete and, other than generating a warning if warnings |
| 1390 |
on obsolescent features are enabled, is completely ignored. |
| 1391 |
It is retained for compatibility |
| 1392 |
purposes. It used to be required to ensure compatibility with C++, but |
| 1393 |
is no longer required for that purpose because GNAT generates |
| 1394 |
the same object layout as the G++ compiler by default. |
| 1395 |
|
| 1396 |
See :ref:`Interfacing_to_C++` for related information. |
| 1397 |
|
| 1398 |
Pragma CPP_Vtable |
| 1399 |
================= |
| 1400 |
.. index:: Interfacing with C++ |
| 1401 |
|
| 1402 |
|
| 1403 |
This pragma is now obsolete and, other than generating a warning if warnings |
| 1404 |
on obsolescent features are enabled, is completely ignored. |
| 1405 |
It used to be required to ensure compatibility with C++, but |
| 1406 |
is no longer required for that purpose because GNAT generates |
| 1407 |
the same object layout as the G++ compiler by default. |
| 1408 |
|
| 1409 |
See :ref:`Interfacing_to_C++` for related information. |
| 1410 |
|
| 1411 |
Pragma CPU |
| 1412 |
========== |
| 1413 |
|
| 1414 |
Syntax: |
| 1415 |
|
| 1416 |
|
| 1417 |
.. code-block:: ada |
| 1418 |
|
| 1419 |
pragma CPU (EXPRESSION); |
| 1420 |
|
| 1421 |
|
| 1422 |
This pragma is standard in Ada 2012, but is available in all earlier |
| 1423 |
versions of Ada as an implementation-defined pragma. |
| 1424 |
See Ada 2012 Reference Manual for details. |
| 1425 |
|
| 1426 |
Pragma Deadline_Floor |
| 1427 |
===================== |
| 1428 |
|
| 1429 |
Syntax: |
| 1430 |
|
| 1431 |
|
| 1432 |
.. code-block:: ada |
| 1433 |
|
| 1434 |
pragma Deadline_Floor (time_span_EXPRESSION); |
| 1435 |
|
| 1436 |
|
| 1437 |
This pragma applies only to protected types and specifies the floor |
| 1438 |
deadline inherited by a task when the task enters a protected object. |
| 1439 |
It is effective only when the EDF scheduling policy is used. |
| 1440 |
|
| 1441 |
Pragma Debug |
| 1442 |
============ |
| 1443 |
|
| 1444 |
Syntax: |
| 1445 |
|
| 1446 |
|
| 1447 |
:: |
| 1448 |
|
| 1449 |
pragma Debug ([CONDITION, ]PROCEDURE_CALL_WITHOUT_SEMICOLON); |
| 1450 |
|
| 1451 |
PROCEDURE_CALL_WITHOUT_SEMICOLON ::= |
| 1452 |
PROCEDURE_NAME |
| 1453 |
| PROCEDURE_PREFIX ACTUAL_PARAMETER_PART |
| 1454 |
|
| 1455 |
|
| 1456 |
The procedure call argument has the syntactic form of an expression, meeting |
| 1457 |
the syntactic requirements for pragmas. |
| 1458 |
|
| 1459 |
If debug pragmas are not enabled or if the condition is present and evaluates |
| 1460 |
to False, this pragma has no effect. If debug pragmas are enabled, the |
| 1461 |
semantics of the pragma is exactly equivalent to the procedure call statement |
| 1462 |
corresponding to the argument with a terminating semicolon. Pragmas are |
| 1463 |
permitted in sequences of declarations, so you can use pragma ``Debug`` to |
| 1464 |
intersperse calls to debug procedures in the middle of declarations. Debug |
| 1465 |
pragmas can be enabled either by use of the command line switch *-gnata* |
| 1466 |
or by use of the pragma ``Check_Policy`` with a first argument of |
| 1467 |
``Debug``. |
| 1468 |
|
| 1469 |
Pragma Debug_Policy |
| 1470 |
=================== |
| 1471 |
|
| 1472 |
Syntax: |
| 1473 |
|
| 1474 |
|
| 1475 |
.. code-block:: ada |
| 1476 |
|
| 1477 |
pragma Debug_Policy (CHECK | DISABLE | IGNORE | ON | OFF); |
| 1478 |
|
| 1479 |
|
| 1480 |
This pragma is equivalent to a corresponding ``Check_Policy`` pragma |
| 1481 |
with a first argument of ``Debug``. It is retained for historical |
| 1482 |
compatibility reasons. |
| 1483 |
|
| 1484 |
.. _Pragma-Default_Initial_Condition: |
| 1485 |
|
| 1486 |
Pragma Default_Initial_Condition |
| 1487 |
================================ |
| 1488 |
|
| 1489 |
Syntax: |
| 1490 |
|
| 1491 |
.. code-block:: ada |
| 1492 |
|
| 1493 |
pragma Default_Initial_Condition [ (null | boolean_EXPRESSION) ]; |
| 1494 |
|
| 1495 |
For the semantics of this pragma, see the entry for aspect |
| 1496 |
``Default_Initial_Condition`` in the SPARK 2014 Reference Manual, section 7.3.3. |
| 1497 |
|
| 1498 |
Pragma Default_Scalar_Storage_Order |
| 1499 |
=================================== |
| 1500 |
.. index:: Default_Scalar_Storage_Order |
| 1501 |
|
| 1502 |
.. index:: Scalar_Storage_Order |
| 1503 |
|
| 1504 |
|
| 1505 |
Syntax: |
| 1506 |
|
| 1507 |
|
| 1508 |
.. code-block:: ada |
| 1509 |
|
| 1510 |
pragma Default_Scalar_Storage_Order (High_Order_First | Low_Order_First); |
| 1511 |
|
| 1512 |
|
| 1513 |
Normally if no explicit ``Scalar_Storage_Order`` is given for a record |
| 1514 |
type or array type, then the scalar storage order defaults to the ordinary |
| 1515 |
default for the target. But this default may be overridden using this pragma. |
| 1516 |
The pragma may appear as a configuration pragma, or locally within a package |
| 1517 |
spec or declarative part. In the latter case, it applies to all subsequent |
| 1518 |
types declared within that package spec or declarative part. |
| 1519 |
|
| 1520 |
The following example shows the use of this pragma: |
| 1521 |
|
| 1522 |
|
| 1523 |
.. code-block:: ada |
| 1524 |
|
| 1525 |
pragma Default_Scalar_Storage_Order (High_Order_First); |
| 1526 |
with System; use System; |
| 1527 |
package DSSO1 is |
| 1528 |
type H1 is record |
| 1529 |
a : Integer; |
| 1530 |
end record; |
| 1531 |
|
| 1532 |
type L2 is record |
| 1533 |
a : Integer; |
| 1534 |
end record; |
| 1535 |
for L2'Scalar_Storage_Order use Low_Order_First; |
| 1536 |
|
| 1537 |
type L2a is new L2; |
| 1538 |
|
| 1539 |
package Inner is |
| 1540 |
type H3 is record |
| 1541 |
a : Integer; |
| 1542 |
end record; |
| 1543 |
|
| 1544 |
pragma Default_Scalar_Storage_Order (Low_Order_First); |
| 1545 |
|
| 1546 |
type L4 is record |
| 1547 |
a : Integer; |
| 1548 |
end record; |
| 1549 |
end Inner; |
| 1550 |
|
| 1551 |
type H4a is new Inner.L4; |
| 1552 |
|
| 1553 |
type H5 is record |
| 1554 |
a : Integer; |
| 1555 |
end record; |
| 1556 |
end DSSO1; |
| 1557 |
|
| 1558 |
|
| 1559 |
In this example record types with names starting with *L* have `Low_Order_First` scalar |
| 1560 |
storage order, and record types with names starting with *H* have ``High_Order_First``. |
| 1561 |
Note that in the case of ``H4a``, the order is not inherited |
| 1562 |
from the parent type. Only an explicitly set ``Scalar_Storage_Order`` |
| 1563 |
gets inherited on type derivation. |
| 1564 |
|
| 1565 |
If this pragma is used as a configuration pragma which appears within a |
| 1566 |
configuration pragma file (as opposed to appearing explicitly at the start |
| 1567 |
of a single unit), then the binder will require that all units in a partition |
| 1568 |
be compiled in a similar manner, other than run-time units, which are not |
| 1569 |
affected by this pragma. Note that the use of this form is discouraged because |
| 1570 |
it may significantly degrade the run-time performance of the software, instead |
| 1571 |
the default scalar storage order ought to be changed only on a local basis. |
| 1572 |
|
| 1573 |
Pragma Default_Storage_Pool |
| 1574 |
=========================== |
| 1575 |
.. index:: Default_Storage_Pool |
| 1576 |
|
| 1577 |
|
| 1578 |
Syntax: |
| 1579 |
|
| 1580 |
|
| 1581 |
.. code-block:: ada |
| 1582 |
|
| 1583 |
pragma Default_Storage_Pool (storage_pool_NAME | null); |
| 1584 |
|
| 1585 |
|
| 1586 |
This pragma is standard in Ada 2012, but is available in all earlier |
| 1587 |
versions of Ada as an implementation-defined pragma. |
| 1588 |
See Ada 2012 Reference Manual for details. |
| 1589 |
|
| 1590 |
.. _Pragma-Depends: |
| 1591 |
|
| 1592 |
Pragma Depends |
| 1593 |
============== |
| 1594 |
|
| 1595 |
Syntax: |
| 1596 |
|
| 1597 |
.. code-block:: ada |
| 1598 |
|
| 1599 |
pragma Depends (DEPENDENCY_RELATION); |
| 1600 |
|
| 1601 |
DEPENDENCY_RELATION ::= |
| 1602 |
null |
| 1603 |
| (DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE}) |
| 1604 |
|
| 1605 |
DEPENDENCY_CLAUSE ::= |
| 1606 |
OUTPUT_LIST =>[+] INPUT_LIST |
| 1607 |
| NULL_DEPENDENCY_CLAUSE |
| 1608 |
|
| 1609 |
NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST |
| 1610 |
|
| 1611 |
OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT}) |
| 1612 |
|
| 1613 |
INPUT_LIST ::= null | INPUT | (INPUT {, INPUT}) |
| 1614 |
|
| 1615 |
OUTPUT ::= NAME | FUNCTION_RESULT |
| 1616 |
INPUT ::= NAME |
| 1617 |
|
| 1618 |
where FUNCTION_RESULT is a function Result attribute_reference |
| 1619 |
|
| 1620 |
For the semantics of this pragma, see the entry for aspect ``Depends`` in the |
| 1621 |
SPARK 2014 Reference Manual, section 6.1.5. |
| 1622 |
|
| 1623 |
Pragma Detect_Blocking |
| 1624 |
====================== |
| 1625 |
|
| 1626 |
Syntax: |
| 1627 |
|
| 1628 |
.. code-block:: ada |
| 1629 |
|
| 1630 |
pragma Detect_Blocking; |
| 1631 |
|
| 1632 |
|
| 1633 |
This is a standard pragma in Ada 2005, that is available in all earlier |
| 1634 |
versions of Ada as an implementation-defined pragma. |
| 1635 |
|
| 1636 |
This is a configuration pragma that forces the detection of potentially |
| 1637 |
blocking operations within a protected operation, and to raise Program_Error |
| 1638 |
if that happens. |
| 1639 |
|
| 1640 |
Pragma Disable_Atomic_Synchronization |
| 1641 |
===================================== |
| 1642 |
|
| 1643 |
.. index:: Atomic Synchronization |
| 1644 |
|
| 1645 |
Syntax: |
| 1646 |
|
| 1647 |
:: |
| 1648 |
|
| 1649 |
pragma Disable_Atomic_Synchronization [(Entity)]; |
| 1650 |
|
| 1651 |
|
| 1652 |
Ada requires that accesses (reads or writes) of an atomic variable be |
| 1653 |
regarded as synchronization points in the case of multiple tasks. |
| 1654 |
Particularly in the case of multi-processors this may require special |
| 1655 |
handling, e.g. the generation of memory barriers. This capability may |
| 1656 |
be turned off using this pragma in cases where it is known not to be |
| 1657 |
required. |
| 1658 |
|
| 1659 |
The placement and scope rules for this pragma are the same as those |
| 1660 |
for ``pragma Suppress``. In particular it can be used as a |
| 1661 |
configuration pragma, or in a declaration sequence where it applies |
| 1662 |
till the end of the scope. If an ``Entity`` argument is present, |
| 1663 |
the action applies only to that entity. |
| 1664 |
|
| 1665 |
Pragma Dispatching_Domain |
| 1666 |
========================= |
| 1667 |
|
| 1668 |
Syntax: |
| 1669 |
|
| 1670 |
|
| 1671 |
.. code-block:: ada |
| 1672 |
|
| 1673 |
pragma Dispatching_Domain (EXPRESSION); |
| 1674 |
|
| 1675 |
|
| 1676 |
This pragma is standard in Ada 2012, but is available in all earlier |
| 1677 |
versions of Ada as an implementation-defined pragma. |
| 1678 |
See Ada 2012 Reference Manual for details. |
| 1679 |
|
| 1680 |
.. _Pragma-Effective_Reads: |
| 1681 |
|
| 1682 |
Pragma Effective_Reads |
| 1683 |
====================== |
| 1684 |
|
| 1685 |
Syntax: |
| 1686 |
|
| 1687 |
.. code-block:: ada |
| 1688 |
|
| 1689 |
pragma Effective_Reads [ (static_boolean_EXPRESSION) ]; |
| 1690 |
|
| 1691 |
For the semantics of this pragma, see the entry for aspect ``Effective_Reads`` in |
| 1692 |
the SPARK 2014 Reference Manual, section 7.1.2. |
| 1693 |
|
| 1694 |
.. _Pragma-Effective_Writes: |
| 1695 |
|
| 1696 |
Pragma Effective_Writes |
| 1697 |
======================= |
| 1698 |
|
| 1699 |
Syntax: |
| 1700 |
|
| 1701 |
.. code-block:: ada |
| 1702 |
|
| 1703 |
pragma Effective_Writes [ (static_boolean_EXPRESSION) ]; |
| 1704 |
|
| 1705 |
For the semantics of this pragma, see the entry for aspect ``Effective_Writes`` |
| 1706 |
in the SPARK 2014 Reference Manual, section 7.1.2. |
| 1707 |
|
| 1708 |
Pragma Elaboration_Checks |
| 1709 |
========================= |
| 1710 |
.. index:: Elaboration control |
| 1711 |
|
| 1712 |
|
| 1713 |
Syntax: |
| 1714 |
|
| 1715 |
|
| 1716 |
.. code-block:: ada |
| 1717 |
|
| 1718 |
pragma Elaboration_Checks (Dynamic | Static); |
| 1719 |
|
| 1720 |
|
| 1721 |
This is a configuration pragma which specifies the elaboration model to be |
| 1722 |
used during compilation. For more information on the elaboration models of |
| 1723 |
GNAT, consult the chapter on elaboration order handling in the *GNAT User's |
| 1724 |
Guide*. |
| 1725 |
|
| 1726 |
The pragma may appear in the following contexts: |
| 1727 |
|
| 1728 |
* Configuration pragmas file |
| 1729 |
|
| 1730 |
* Prior to the context clauses of a compilation unit's initial declaration |
| 1731 |
|
| 1732 |
Any other placement of the pragma will result in a warning and the effects of |
| 1733 |
the offending pragma will be ignored. |
| 1734 |
|
| 1735 |
If the pragma argument is ``Dynamic``, then the dynamic elaboration model is in |
| 1736 |
effect. If the pragma argument is ``Static``, then the static elaboration model |
| 1737 |
is in effect. |
| 1738 |
|
| 1739 |
Pragma Eliminate |
| 1740 |
================ |
| 1741 |
.. index:: Elimination of unused subprograms |
| 1742 |
|
| 1743 |
|
| 1744 |
Syntax: |
| 1745 |
|
| 1746 |
|
| 1747 |
:: |
| 1748 |
|
| 1749 |
pragma Eliminate ( |
| 1750 |
[ Unit_Name => ] IDENTIFIER | SELECTED_COMPONENT , |
| 1751 |
[ Entity => ] IDENTIFIER | |
| 1752 |
SELECTED_COMPONENT | |
| 1753 |
STRING_LITERAL |
| 1754 |
[, Source_Location => SOURCE_TRACE ] ); |
| 1755 |
|
| 1756 |
SOURCE_TRACE ::= STRING_LITERAL |
| 1757 |
|
| 1758 |
|
| 1759 |
This pragma indicates that the given entity is not used in the program to be |
| 1760 |
compiled and built, thus allowing the compiler to |
| 1761 |
eliminate the code or data associated with the named entity. Any reference to |
| 1762 |
an eliminated entity causes a compile-time or link-time error. |
| 1763 |
|
| 1764 |
The pragma has the following semantics, where ``U`` is the unit specified by |
| 1765 |
the ``Unit_Name`` argument and ``E`` is the entity specified by the ``Entity`` |
| 1766 |
argument: |
| 1767 |
|
| 1768 |
* ``E`` must be a subprogram that is explicitly declared either: |
| 1769 |
|
| 1770 |
* Within ``U``, or |
| 1771 |
* Within a generic package that is instantiated in ``U``, or |
| 1772 |
* As an instance of generic subprogram instantiated in ``U``. |
| 1773 |
|
| 1774 |
Otherwise the pragma is ignored. |
| 1775 |
|
| 1776 |
* If ``E`` is overloaded within ``U`` then, in the absence of a |
| 1777 |
``Source_Location`` argument, all overloadings are eliminated. |
| 1778 |
* If ``E`` is overloaded within ``U`` and only some overloadings |
| 1779 |
are to be eliminated, then each overloading to be eliminated |
| 1780 |
must be specified in a corresponding pragma ``Eliminate`` |
| 1781 |
with a ``Source_Location`` argument identifying the line where the |
| 1782 |
declaration appears, as described below. |
| 1783 |
* If ``E`` is declared as the result of a generic instantiation, then |
| 1784 |
a ``Source_Location`` argument is needed, as described below. |
| 1785 |
|
| 1786 |
Pragma ``Eliminate`` allows a program to be compiled in a system-independent |
| 1787 |
manner, so that unused entities are eliminated but without |
| 1788 |
needing to modify the source text. Normally the required set of |
| 1789 |
``Eliminate`` pragmas is constructed automatically using the ``gnatelim`` tool. |
| 1790 |
|
| 1791 |
Any source file change that removes, splits, or |
| 1792 |
adds lines may make the set of ``Eliminate`` pragmas invalid because their |
| 1793 |
``Source_Location`` argument values may get out of date. |
| 1794 |
|
| 1795 |
Pragma ``Eliminate`` may be used where the referenced entity is a dispatching |
| 1796 |
operation. In this case all the subprograms to which the given operation can |
| 1797 |
dispatch are considered to be unused (are never called as a result of a direct |
| 1798 |
or a dispatching call). |
| 1799 |
|
| 1800 |
The string literal given for the source location specifies the line number |
| 1801 |
of the declaration of the entity, using the following syntax for ``SOURCE_TRACE``: |
| 1802 |
|
| 1803 |
:: |
| 1804 |
|
| 1805 |
SOURCE_TRACE ::= SOURCE_REFERENCE [ LBRACKET SOURCE_TRACE RBRACKET ] |
| 1806 |
|
| 1807 |
LBRACKET ::= '[' |
| 1808 |
RBRACKET ::= ']' |
| 1809 |
|
| 1810 |
SOURCE_REFERENCE ::= FILE_NAME : LINE_NUMBER |
| 1811 |
|
| 1812 |
LINE_NUMBER ::= DIGIT {DIGIT} |
| 1813 |
|
| 1814 |
|
| 1815 |
Spaces around the colon in a ``SOURCE_REFERENCE`` are optional. |
| 1816 |
|
| 1817 |
The source trace that is given as the ``Source_Location`` must obey the |
| 1818 |
following rules (or else the pragma is ignored), where ``U`` is |
| 1819 |
the unit ``U`` specified by the ``Unit_Name`` argument and ``E`` is the |
| 1820 |
subprogram specified by the ``Entity`` argument: |
| 1821 |
|
| 1822 |
* ``FILE_NAME`` is the short name (with no directory |
| 1823 |
information) of the Ada source file for ``U``, using the required syntax |
| 1824 |
for the underlying file system (e.g. case is significant if the underlying |
| 1825 |
operating system is case sensitive). |
| 1826 |
If ``U`` is a package and ``E`` is a subprogram declared in the package |
| 1827 |
specification and its full declaration appears in the package body, |
| 1828 |
then the relevant source file is the one for the package specification; |
| 1829 |
analogously if ``U`` is a generic package. |
| 1830 |
|
| 1831 |
* If ``E`` is not declared in a generic instantiation (this includes |
| 1832 |
generic subprogram instances), the source trace includes only one source |
| 1833 |
line reference. ``LINE_NUMBER`` gives the line number of the occurrence |
| 1834 |
of the declaration of ``E`` within the source file (as a decimal literal |
| 1835 |
without an exponent or point). |
| 1836 |
|
| 1837 |
* If ``E`` is declared by a generic instantiation, its source trace |
| 1838 |
(from left to right) starts with the source location of the |
| 1839 |
declaration of ``E`` in the generic unit and ends with the source |
| 1840 |
location of the instantiation, given in square brackets. This approach is |
| 1841 |
applied recursively with nested instantiations: the rightmost (nested |
| 1842 |
most deeply in square brackets) element of the source trace is the location |
| 1843 |
of the outermost instantiation, and the leftmost element (that is, outside |
| 1844 |
of any square brackets) is the location of the declaration of ``E`` in |
| 1845 |
the generic unit. |
| 1846 |
|
| 1847 |
Examples: |
| 1848 |
|
| 1849 |
.. code-block:: ada |
| 1850 |
|
| 1851 |
pragma Eliminate (Pkg0, Proc); |
| 1852 |
-- Eliminate (all overloadings of) Proc in Pkg0 |
| 1853 |
|
| 1854 |
pragma Eliminate (Pkg1, Proc, |
| 1855 |
Source_Location => "pkg1.ads:8"); |
| 1856 |
-- Eliminate overloading of Proc at line 8 in pkg1.ads |
| 1857 |
|
| 1858 |
-- Assume the following file contents: |
| 1859 |
-- gen_pkg.ads |
| 1860 |
-- 1: generic |
| 1861 |
-- 2: type T is private; |
| 1862 |
-- 3: package Gen_Pkg is |
| 1863 |
-- 4: procedure Proc(N : T); |
| 1864 |
-- ... ... |
| 1865 |
-- ... end Gen_Pkg; |
| 1866 |
-- |
| 1867 |
-- q.adb |
| 1868 |
-- 1: with Gen_Pkg; |
| 1869 |
-- 2: procedure Q is |
| 1870 |
-- 3: package Inst_Pkg is new Gen_Pkg(Integer); |
| 1871 |
-- ... -- No calls on Inst_Pkg.Proc |
| 1872 |
-- ... end Q; |
| 1873 |
|
| 1874 |
-- The following pragma eliminates Inst_Pkg.Proc from Q |
| 1875 |
pragma Eliminate (Q, Proc, |
| 1876 |
Source_Location => "gen_pkg.ads:4[q.adb:3]"); |
| 1877 |
|
| 1878 |
|
| 1879 |
|
| 1880 |
Pragma Enable_Atomic_Synchronization |
| 1881 |
==================================== |
| 1882 |
.. index:: Atomic Synchronization |
| 1883 |
|
| 1884 |
|
| 1885 |
Syntax: |
| 1886 |
|
| 1887 |
|
| 1888 |
:: |
| 1889 |
|
| 1890 |
pragma Enable_Atomic_Synchronization [(Entity)]; |
| 1891 |
|
| 1892 |
|
| 1893 |
Ada requires that accesses (reads or writes) of an atomic variable be |
| 1894 |
regarded as synchronization points in the case of multiple tasks. |
| 1895 |
Particularly in the case of multi-processors this may require special |
| 1896 |
handling, e.g. the generation of memory barriers. This synchronization |
| 1897 |
is performed by default, but can be turned off using |
| 1898 |
``pragma Disable_Atomic_Synchronization``. The |
| 1899 |
``Enable_Atomic_Synchronization`` pragma can be used to turn |
| 1900 |
it back on. |
| 1901 |
|
| 1902 |
The placement and scope rules for this pragma are the same as those |
| 1903 |
for ``pragma Unsuppress``. In particular it can be used as a |
| 1904 |
configuration pragma, or in a declaration sequence where it applies |
| 1905 |
till the end of the scope. If an ``Entity`` argument is present, |
| 1906 |
the action applies only to that entity. |
| 1907 |
|
| 1908 |
Pragma Export_Function |
| 1909 |
====================== |
| 1910 |
.. index:: Argument passing mechanisms |
| 1911 |
|
| 1912 |
|
| 1913 |
Syntax: |
| 1914 |
|
| 1915 |
|
| 1916 |
:: |
| 1917 |
|
| 1918 |
pragma Export_Function ( |
| 1919 |
[Internal =>] LOCAL_NAME |
| 1920 |
[, [External =>] EXTERNAL_SYMBOL] |
| 1921 |
[, [Parameter_Types =>] PARAMETER_TYPES] |
| 1922 |
[, [Result_Type =>] result_SUBTYPE_MARK] |
| 1923 |
[, [Mechanism =>] MECHANISM] |
| 1924 |
[, [Result_Mechanism =>] MECHANISM_NAME]); |
| 1925 |
|
| 1926 |
EXTERNAL_SYMBOL ::= |
| 1927 |
IDENTIFIER |
| 1928 |
| static_string_EXPRESSION |
| 1929 |
| "" |
| 1930 |
|
| 1931 |
PARAMETER_TYPES ::= |
| 1932 |
null |
| 1933 |
| TYPE_DESIGNATOR {, TYPE_DESIGNATOR} |
| 1934 |
|
| 1935 |
TYPE_DESIGNATOR ::= |
| 1936 |
subtype_NAME |
| 1937 |
| subtype_Name ' Access |
| 1938 |
|
| 1939 |
MECHANISM ::= |
| 1940 |
MECHANISM_NAME |
| 1941 |
| (MECHANISM_ASSOCIATION {, MECHANISM_ASSOCIATION}) |
| 1942 |
|
| 1943 |
MECHANISM_ASSOCIATION ::= |
| 1944 |
[formal_parameter_NAME =>] MECHANISM_NAME |
| 1945 |
|
| 1946 |
MECHANISM_NAME ::= Value | Reference |
| 1947 |
|
| 1948 |
|
| 1949 |
Use this pragma to make a function externally callable and optionally |
| 1950 |
provide information on mechanisms to be used for passing parameter and |
| 1951 |
result values. We recommend, for the purposes of improving portability, |
| 1952 |
this pragma always be used in conjunction with a separate pragma |
| 1953 |
``Export``, which must precede the pragma ``Export_Function``. |
| 1954 |
GNAT does not require a separate pragma ``Export``, but if none is |
| 1955 |
present, ``Convention Ada`` is assumed, which is usually |
| 1956 |
not what is wanted, so it is usually appropriate to use this |
| 1957 |
pragma in conjunction with a ``Export`` or ``Convention`` |
| 1958 |
pragma that specifies the desired foreign convention. |
| 1959 |
Pragma ``Export_Function`` |
| 1960 |
(and ``Export``, if present) must appear in the same declarative |
| 1961 |
region as the function to which they apply. |
| 1962 |
|
| 1963 |
The ``internal_name`` must uniquely designate the function to which the |
| 1964 |
pragma applies. If more than one function name exists of this name in |
| 1965 |
the declarative part you must use the ``Parameter_Types`` and |
| 1966 |
``Result_Type`` parameters to achieve the required |
| 1967 |
unique designation. The `subtype_mark`\ s in these parameters must |
| 1968 |
exactly match the subtypes in the corresponding function specification, |
| 1969 |
using positional notation to match parameters with subtype marks. |
| 1970 |
The form with an ``'Access`` attribute can be used to match an |
| 1971 |
anonymous access parameter. |
| 1972 |
|
| 1973 |
.. index:: Suppressing external name |
| 1974 |
|
| 1975 |
Special treatment is given if the EXTERNAL is an explicit null |
| 1976 |
string or a static string expressions that evaluates to the null |
| 1977 |
string. In this case, no external name is generated. This form |
| 1978 |
still allows the specification of parameter mechanisms. |
| 1979 |
|
| 1980 |
Pragma Export_Object |
| 1981 |
==================== |
| 1982 |
|
| 1983 |
Syntax: |
| 1984 |
|
| 1985 |
|
| 1986 |
:: |
| 1987 |
|
| 1988 |
pragma Export_Object ( |
| 1989 |
[Internal =>] LOCAL_NAME |
| 1990 |
[, [External =>] EXTERNAL_SYMBOL] |
| 1991 |
[, [Size =>] EXTERNAL_SYMBOL]); |
| 1992 |
|
| 1993 |
EXTERNAL_SYMBOL ::= |
| 1994 |
IDENTIFIER |
| 1995 |
| static_string_EXPRESSION |
| 1996 |
|
| 1997 |
|
| 1998 |
This pragma designates an object as exported, and apart from the |
| 1999 |
extended rules for external symbols, is identical in effect to the use of |
| 2000 |
the normal ``Export`` pragma applied to an object. You may use a |
| 2001 |
separate Export pragma (and you probably should from the point of view |
| 2002 |
of portability), but it is not required. ``Size`` is syntax checked, |
| 2003 |
but otherwise ignored by GNAT. |
| 2004 |
|
| 2005 |
Pragma Export_Procedure |
| 2006 |
======================= |
| 2007 |
|
| 2008 |
Syntax: |
| 2009 |
|
| 2010 |
|
| 2011 |
:: |
| 2012 |
|
| 2013 |
pragma Export_Procedure ( |
| 2014 |
[Internal =>] LOCAL_NAME |
| 2015 |
[, [External =>] EXTERNAL_SYMBOL] |
| 2016 |
[, [Parameter_Types =>] PARAMETER_TYPES] |
| 2017 |
[, [Mechanism =>] MECHANISM]); |
| 2018 |
|
| 2019 |
EXTERNAL_SYMBOL ::= |
| 2020 |
IDENTIFIER |
| 2021 |
| static_string_EXPRESSION |
| 2022 |
| "" |
| 2023 |
|
| 2024 |
PARAMETER_TYPES ::= |
| 2025 |
null |
| 2026 |
| TYPE_DESIGNATOR {, TYPE_DESIGNATOR} |
| 2027 |
|
| 2028 |
TYPE_DESIGNATOR ::= |
| 2029 |
subtype_NAME |
| 2030 |
| subtype_Name ' Access |
| 2031 |
|
| 2032 |
MECHANISM ::= |
| 2033 |
MECHANISM_NAME |
| 2034 |
| (MECHANISM_ASSOCIATION {, MECHANISM_ASSOCIATION}) |
| 2035 |
|
| 2036 |
MECHANISM_ASSOCIATION ::= |
| 2037 |
[formal_parameter_NAME =>] MECHANISM_NAME |
| 2038 |
|
| 2039 |
MECHANISM_NAME ::= Value | Reference |
| 2040 |
|
| 2041 |
|
| 2042 |
This pragma is identical to ``Export_Function`` except that it |
| 2043 |
applies to a procedure rather than a function and the parameters |
| 2044 |
``Result_Type`` and ``Result_Mechanism`` are not permitted. |
| 2045 |
GNAT does not require a separate pragma ``Export``, but if none is |
| 2046 |
present, ``Convention Ada`` is assumed, which is usually |
| 2047 |
not what is wanted, so it is usually appropriate to use this |
| 2048 |
pragma in conjunction with a ``Export`` or ``Convention`` |
| 2049 |
pragma that specifies the desired foreign convention. |
| 2050 |
|
| 2051 |
.. index:: Suppressing external name |
| 2052 |
|
| 2053 |
Special treatment is given if the EXTERNAL is an explicit null |
| 2054 |
string or a static string expressions that evaluates to the null |
| 2055 |
string. In this case, no external name is generated. This form |
| 2056 |
still allows the specification of parameter mechanisms. |
| 2057 |
|
| 2058 |
Pragma Export_Valued_Procedure |
| 2059 |
============================== |
| 2060 |
|
| 2061 |
Syntax: |
| 2062 |
|
| 2063 |
|
| 2064 |
:: |
| 2065 |
|
| 2066 |
pragma Export_Valued_Procedure ( |
| 2067 |
[Internal =>] LOCAL_NAME |
| 2068 |
[, [External =>] EXTERNAL_SYMBOL] |
| 2069 |
[, [Parameter_Types =>] PARAMETER_TYPES] |
| 2070 |
[, [Mechanism =>] MECHANISM]); |
| 2071 |
|
| 2072 |
EXTERNAL_SYMBOL ::= |
| 2073 |
IDENTIFIER |
| 2074 |
| static_string_EXPRESSION |
| 2075 |
| "" |
| 2076 |
|
| 2077 |
PARAMETER_TYPES ::= |
| 2078 |
null |
| 2079 |
| TYPE_DESIGNATOR {, TYPE_DESIGNATOR} |
| 2080 |
|
| 2081 |
TYPE_DESIGNATOR ::= |
| 2082 |
subtype_NAME |
| 2083 |
| subtype_Name ' Access |
| 2084 |
|
| 2085 |
MECHANISM ::= |
| 2086 |
MECHANISM_NAME |
| 2087 |
| (MECHANISM_ASSOCIATION {, MECHANISM_ASSOCIATION}) |
| 2088 |
|
| 2089 |
MECHANISM_ASSOCIATION ::= |
| 2090 |
[formal_parameter_NAME =>] MECHANISM_NAME |
| 2091 |
|
| 2092 |
MECHANISM_NAME ::= Value | Reference |
| 2093 |
|
| 2094 |
|
| 2095 |
This pragma is identical to ``Export_Procedure`` except that the |
| 2096 |
first parameter of ``LOCAL_NAME``, which must be present, must be of |
| 2097 |
mode ``out``, and externally the subprogram is treated as a function |
| 2098 |
with this parameter as the result of the function. GNAT provides for |
| 2099 |
this capability to allow the use of ``out`` and ``in out`` |
| 2100 |
parameters in interfacing to external functions (which are not permitted |
| 2101 |
in Ada functions). |
| 2102 |
GNAT does not require a separate pragma ``Export``, but if none is |
| 2103 |
present, ``Convention Ada`` is assumed, which is almost certainly |
| 2104 |
not what is wanted since the whole point of this pragma is to interface |
| 2105 |
with foreign language functions, so it is usually appropriate to use this |
| 2106 |
pragma in conjunction with a ``Export`` or ``Convention`` |
| 2107 |
pragma that specifies the desired foreign convention. |
| 2108 |
|
| 2109 |
.. index:: Suppressing external name |
| 2110 |
|
| 2111 |
Special treatment is given if the EXTERNAL is an explicit null |
| 2112 |
string or a static string expressions that evaluates to the null |
| 2113 |
string. In this case, no external name is generated. This form |
| 2114 |
still allows the specification of parameter mechanisms. |
| 2115 |
|
| 2116 |
Pragma Extend_System |
| 2117 |
==================== |
| 2118 |
.. index:: System, extending |
| 2119 |
|
| 2120 |
.. index:: DEC Ada 83 |
| 2121 |
|
| 2122 |
|
| 2123 |
Syntax: |
| 2124 |
|
| 2125 |
|
| 2126 |
:: |
| 2127 |
|
| 2128 |
pragma Extend_System ([Name =>] IDENTIFIER); |
| 2129 |
|
| 2130 |
|
| 2131 |
This pragma is used to provide backwards compatibility with other |
| 2132 |
implementations that extend the facilities of package ``System``. In |
| 2133 |
GNAT, ``System`` contains only the definitions that are present in |
| 2134 |
the Ada RM. However, other implementations, notably the DEC Ada 83 |
| 2135 |
implementation, provide many extensions to package ``System``. |
| 2136 |
|
| 2137 |
For each such implementation accommodated by this pragma, GNAT provides a |
| 2138 |
package :samp:`Aux_{xxx}`, e.g., ``Aux_DEC`` for the DEC Ada 83 |
| 2139 |
implementation, which provides the required additional definitions. You |
| 2140 |
can use this package in two ways. You can ``with`` it in the normal |
| 2141 |
way and access entities either by selection or using a ``use`` |
| 2142 |
clause. In this case no special processing is required. |
| 2143 |
|
| 2144 |
However, if existing code contains references such as |
| 2145 |
:samp:`System.{xxx}` where *xxx* is an entity in the extended |
| 2146 |
definitions provided in package ``System``, you may use this pragma |
| 2147 |
to extend visibility in ``System`` in a non-standard way that |
| 2148 |
provides greater compatibility with the existing code. Pragma |
| 2149 |
``Extend_System`` is a configuration pragma whose single argument is |
| 2150 |
the name of the package containing the extended definition |
| 2151 |
(e.g., ``Aux_DEC`` for the DEC Ada case). A unit compiled under |
| 2152 |
control of this pragma will be processed using special visibility |
| 2153 |
processing that looks in package :samp:`System.Aux_{xxx}` where |
| 2154 |
:samp:`Aux_{xxx}` is the pragma argument for any entity referenced in |
| 2155 |
package ``System``, but not found in package ``System``. |
| 2156 |
|
| 2157 |
You can use this pragma either to access a predefined ``System`` |
| 2158 |
extension supplied with the compiler, for example ``Aux_DEC`` or |
| 2159 |
you can construct your own extension unit following the above |
| 2160 |
definition. Note that such a package is a child of ``System`` |
| 2161 |
and thus is considered part of the implementation. |
| 2162 |
To compile it you will have to use the *-gnatg* switch |
| 2163 |
for compiling System units, as explained in the |
| 2164 |
GNAT User's Guide. |
| 2165 |
|
| 2166 |
Pragma Extensions_Allowed |
| 2167 |
========================= |
| 2168 |
.. index:: Ada Extensions |
| 2169 |
|
| 2170 |
.. index:: GNAT Extensions |
| 2171 |
|
| 2172 |
|
| 2173 |
Syntax: |
| 2174 |
|
| 2175 |
.. code-block:: ada |
| 2176 |
|
| 2177 |
pragma Extensions_Allowed (On | Off | All); |
| 2178 |
|
| 2179 |
|
| 2180 |
This configuration pragma enables (via the "On" or "All" argument) or disables |
| 2181 |
(via the "Off" argument) the implementation extension mode; the pragma takes |
| 2182 |
precedence over the *-gnatX* and *-gnatX0* command switches. |
| 2183 |
|
| 2184 |
If an argument of "All" is specified, the latest version of the Ada language |
| 2185 |
is implemented (currently Ada 2022) and, in addition, a number |
| 2186 |
of GNAT specific extensions are recognized. These extensions are listed |
| 2187 |
below. An argument of "On" has the same effect except that only |
| 2188 |
some, not all, of the listed extensions are enabled; those extensions |
| 2189 |
are identified below. |
| 2190 |
|
| 2191 |
* Constrained attribute for generic objects |
| 2192 |
|
| 2193 |
The ``Constrained`` attribute is permitted for objects of |
| 2194 |
generic types. The result indicates if the corresponding actual |
| 2195 |
is constrained. |
| 2196 |
|
| 2197 |
* ``Static`` aspect on intrinsic functions |
| 2198 |
|
| 2199 |
The Ada 202x ``Static`` aspect can be specified on Intrinsic imported |
| 2200 |
functions and the compiler will evaluate some of these intrinsic statically, |
| 2201 |
in particular the ``Shift_Left`` and ``Shift_Right`` intrinsics. |
| 2202 |
|
| 2203 |
An Extensions_Allowed pragma argument of "On" enables this extension. |
| 2204 |
|
| 2205 |
* ``[]`` aggregates |
| 2206 |
|
| 2207 |
This new aggregate syntax for arrays and containers is provided under -gnatX |
| 2208 |
to experiment and confirm this new language syntax. |
| 2209 |
|
| 2210 |
* Additional ``when`` constructs |
| 2211 |
|
| 2212 |
In addition to the ``exit when CONDITION`` control structure, several |
| 2213 |
additional constructs are allowed following this format. Including |
| 2214 |
``return when CONDITION``, ``goto when CONDITION``, and |
| 2215 |
``raise [with EXCEPTION_MESSAGE] when CONDITION.`` |
| 2216 |
|
| 2217 |
Some examples: |
| 2218 |
|
| 2219 |
.. code-block:: ada |
| 2220 |
|
| 2221 |
return Result when Variable > 10; |
| 2222 |
|
| 2223 |
raise Program_Error with "Element is null" when Element = null; |
| 2224 |
|
| 2225 |
goto End_Of_Subprogram when Variable = -1; |
| 2226 |
|
| 2227 |
* Casing on composite values (aka pattern matching) |
| 2228 |
|
| 2229 |
The selector for a case statement may be of a composite type, subject to |
| 2230 |
some restrictions (described below). Aggregate syntax is used for choices |
| 2231 |
of such a case statement; however, in cases where a "normal" aggregate would |
| 2232 |
require a discrete value, a discrete subtype may be used instead; box |
| 2233 |
notation can also be used to match all values. |
| 2234 |
|
| 2235 |
Consider this example: |
| 2236 |
|
| 2237 |
.. code-block:: ada |
| 2238 |
|
| 2239 |
type Rec is record |
| 2240 |
F1, F2 : Integer; |
| 2241 |
end record; |
| 2242 |
|
| 2243 |
procedure Caser_1 (X : Rec) is |
| 2244 |
begin |
| 2245 |
case X is |
| 2246 |
when (F1 => Positive, F2 => Positive) => |
| 2247 |
Do_This; |
| 2248 |
when (F1 => Natural, F2 => <>) | (F1 => <>, F2 => Natural) => |
| 2249 |
Do_That; |
| 2250 |
when others => |
| 2251 |
Do_The_Other_Thing; |
| 2252 |
end case; |
| 2253 |
end Caser_1; |
| 2254 |
|
| 2255 |
If Caser_1 is called and both components of X are positive, then |
| 2256 |
Do_This will be called; otherwise, if either component is nonnegative |
| 2257 |
then Do_That will be called; otherwise, Do_The_Other_Thing will be called. |
| 2258 |
|
| 2259 |
If the set of values that match the choice(s) of an earlier alternative |
| 2260 |
overlaps the corresponding set of a later alternative, then the first |
| 2261 |
set shall be a proper subset of the second (and the later alternative |
| 2262 |
will not be executed if the earlier alternative "matches"). All possible |
| 2263 |
values of the composite type shall be covered. The composite type of the |
| 2264 |
selector shall be an array or record type that is neither limited |
| 2265 |
class-wide. Currently, a "when others =>" case choice is required; it is |
| 2266 |
intended that this requirement will be relaxed at some point. |
| 2267 |
|
| 2268 |
If a subcomponent's subtype does not meet certain restrictions, then |
| 2269 |
the only value that can be specified for that subcomponent in a case |
| 2270 |
choice expression is a "box" component association (which matches all |
| 2271 |
possible values for the subcomponent). This restriction applies if |
| 2272 |
|
| 2273 |
- the component subtype is not a record, array, or discrete type; or |
| 2274 |
|
| 2275 |
- the component subtype is subject to a non-static constraint or |
| 2276 |
has a predicate; or |
| 2277 |
|
| 2278 |
- the component type is an enumeration type that is subject to an |
| 2279 |
enumeration representation clause; or |
| 2280 |
|
| 2281 |
- the component type is a multidimensional array type or an |
| 2282 |
array type with a nonstatic index subtype. |
| 2283 |
|
| 2284 |
Support for casing on arrays (and on records that contain arrays) is |
| 2285 |
currently subject to some restrictions. Non-positional |
| 2286 |
array aggregates are not supported as (or within) case choices. Likewise |
| 2287 |
for array type and subtype names. The current implementation exceeds |
| 2288 |
compile-time capacity limits in some annoyingly common scenarios; the |
| 2289 |
message generated in such cases is usually "Capacity exceeded in compiling |
| 2290 |
case statement with composite selector type". |
| 2291 |
|
| 2292 |
In addition, pattern bindings are supported. This is a mechanism |
| 2293 |
for binding a name to a component of a matching value for use within |
| 2294 |
an alternative of a case statement. For a component association |
| 2295 |
that occurs within a case choice, the expression may be followed by |
| 2296 |
"is <identifier>". In the special case of a "box" component association, |
| 2297 |
the identifier may instead be provided within the box. Either of these |
| 2298 |
indicates that the given identifer denotes (a constant view of) the matching |
| 2299 |
subcomponent of the case selector. Binding is not yet supported for arrays |
| 2300 |
or subcomponents thereof. |
| 2301 |
|
| 2302 |
Consider this example (which uses type Rec from the previous example): |
| 2303 |
|
| 2304 |
.. code-block:: ada |
| 2305 |
|
| 2306 |
procedure Caser_2 (X : Rec) is |
| 2307 |
begin |
| 2308 |
case X is |
| 2309 |
when (F1 => Positive is Abc, F2 => Positive) => |
| 2310 |
Do_This (Abc) |
| 2311 |
when (F1 => Natural is N1, F2 => <N2>) | |
| 2312 |
(F1 => <N2>, F2 => Natural is N1) => |
| 2313 |
Do_That (Param_1 => N1, Param_2 => N2); |
| 2314 |
when others => |
| 2315 |
Do_The_Other_Thing; |
| 2316 |
end case; |
| 2317 |
end Caser_2; |
| 2318 |
|
| 2319 |
This example is the same as the previous one with respect to |
| 2320 |
determining whether Do_This, Do_That, or Do_The_Other_Thing will |
| 2321 |
be called. But for this version, Do_This takes a parameter and Do_That |
| 2322 |
takes two parameters. If Do_This is called, the actual parameter in the |
| 2323 |
call will be X.F1. |
| 2324 |
|
| 2325 |
If Do_That is called, the situation is more complex because there are two |
| 2326 |
choices for that alternative. If Do_That is called because the first choice |
| 2327 |
matched (i.e., because X.F1 is nonnegative and either X.F1 or X.F2 is zero |
| 2328 |
or negative), then the actual parameters of the call will be (in order) |
| 2329 |
X.F1 and X.F2. If Do_That is called because the second choice matched (and |
| 2330 |
the first one did not), then the actual parameters will be reversed. |
| 2331 |
|
| 2332 |
Within the choice list for single alternative, each choice must |
| 2333 |
define the same set of bindings and the component subtypes for |
| 2334 |
for a given identifer must all statically match. Currently, the case |
| 2335 |
of a binding for a nondiscrete component is not implemented. |
| 2336 |
|
| 2337 |
An Extensions_Allowed pragma argument of "On" enables this extension. |
| 2338 |
|
| 2339 |
* Fixed lower bounds for array types and subtypes |
| 2340 |
|
| 2341 |
Unconstrained array types and subtypes can be specified with a lower bound |
| 2342 |
that is fixed to a certain value, by writing an index range that uses the |
| 2343 |
syntax "<lower-bound-expression> .. <>". This guarantees that all objects |
| 2344 |
of the type or subtype will have the specified lower bound. |
| 2345 |
|
| 2346 |
For example, a matrix type with fixed lower bounds of zero for each |
| 2347 |
dimension can be declared by the following: |
| 2348 |
|
| 2349 |
.. code-block:: ada |
| 2350 |
|
| 2351 |
type Matrix is |
| 2352 |
array (Natural range 0 .. <>, Natural range 0 .. <>) of Integer; |
| 2353 |
|
| 2354 |
Objects of type Matrix declared with an index constraint must have index |
| 2355 |
ranges starting at zero: |
| 2356 |
|
| 2357 |
.. code-block:: ada |
| 2358 |
|
| 2359 |
M1 : Matrix (0 .. 9, 0 .. 19); |
| 2360 |
M2 : Matrix (2 .. 11, 3 .. 22); -- Warning about bounds; will raise CE |
| 2361 |
|
| 2362 |
Similarly, a subtype of String can be declared that specifies the lower |
| 2363 |
bound of objects of that subtype to be 1: |
| 2364 |
|
| 2365 |
.. code-block:: ada |
| 2366 |
|
| 2367 |
subtype String_1 is String (1 .. <>); |
| 2368 |
|
| 2369 |
If a string slice is passed to a formal of subtype String_1 in a call to |
| 2370 |
a subprogram S, the slice's bounds will "slide" so that the lower bound |
| 2371 |
is 1. Within S, the lower bound of the formal is known to be 1, so, unlike |
| 2372 |
a normal unconstrained String formal, there is no need to worry about |
| 2373 |
accounting for other possible lower-bound values. Sliding of bounds also |
| 2374 |
occurs in other contexts, such as for object declarations with an |
| 2375 |
unconstrained subtype with fixed lower bound, as well as in subtype |
| 2376 |
conversions. |
| 2377 |
|
| 2378 |
Use of this feature increases safety by simplifying code, and can also |
| 2379 |
improve the efficiency of indexing operations, since the compiler statically |
| 2380 |
knows the lower bound of unconstrained array formals when the formal's |
| 2381 |
subtype has index ranges with static fixed lower bounds. |
| 2382 |
|
| 2383 |
An Extensions_Allowed pragma argument of "On" enables this extension. |
| 2384 |
|
| 2385 |
* Prefixed-view notation for calls to primitive subprograms of untagged types |
| 2386 |
|
| 2387 |
Since Ada 2005, calls to primitive subprograms of a tagged type that |
| 2388 |
have a "prefixed view" (see RM 4.1.3(9.2)) have been allowed to be |
| 2389 |
written using the form of a selected_component, with the first actual |
| 2390 |
parameter given as the prefix and the name of the subprogram as a |
| 2391 |
selector. This prefixed-view notation for calls is extended so as to |
| 2392 |
also allow such syntax for calls to primitive subprograms of untagged |
| 2393 |
types. The primitives of an untagged type T that have a prefixed view |
| 2394 |
are those where the first formal parameter of the subprogram either |
| 2395 |
is of type T or is an anonymous access parameter whose designated type |
| 2396 |
is T. For a type that has a component that happens to have the same |
| 2397 |
simple name as one of the type's primitive subprograms, where the |
| 2398 |
component is visible at the point of a selected_component using that |
| 2399 |
name, preference is given to the component in a selected_component |
| 2400 |
(as is currently the case for tagged types with such component names). |
| 2401 |
|
| 2402 |
An Extensions_Allowed pragma argument of "On" enables this extension. |
| 2403 |
|
| 2404 |
* Expression defaults for generic formal functions |
| 2405 |
|
| 2406 |
The declaration of a generic formal function is allowed to specify |
| 2407 |
an expression as a default, using the syntax of an expression function. |
| 2408 |
|
| 2409 |
Here is an example of this feature: |
| 2410 |
|
| 2411 |
.. code-block:: ada |
| 2412 |
|
| 2413 |
generic |
| 2414 |
type T is private; |
| 2415 |
with function Copy (Item : T) return T is (Item); -- Defaults to Item |
| 2416 |
package Stacks is |
| 2417 |
|
| 2418 |
type Stack is limited private; |
| 2419 |
|
| 2420 |
procedure Push (S : in out Stack; X : T); -- Calls Copy on X |
| 2421 |
|
| 2422 |
function Pop (S : in out Stack) return T; -- Calls Copy to return item |
| 2423 |
|
| 2424 |
private |
| 2425 |
-- ... |
| 2426 |
end Stacks; |
| 2427 |
|
| 2428 |
.. _Pragma-Extensions_Visible: |
| 2429 |
|
| 2430 |
Pragma Extensions_Visible |
| 2431 |
========================= |
| 2432 |
|
| 2433 |
Syntax: |
| 2434 |
|
| 2435 |
.. code-block:: ada |
| 2436 |
|
| 2437 |
pragma Extensions_Visible [ (static_boolean_EXPRESSION) ]; |
| 2438 |
|
| 2439 |
For the semantics of this pragma, see the entry for aspect ``Extensions_Visible`` |
| 2440 |
in the SPARK 2014 Reference Manual, section 6.1.7. |
| 2441 |
|
| 2442 |
Pragma External |
| 2443 |
=============== |
| 2444 |
|
| 2445 |
Syntax: |
| 2446 |
|
| 2447 |
|
| 2448 |
:: |
| 2449 |
|
| 2450 |
pragma External ( |
| 2451 |
[ Convention =>] convention_IDENTIFIER, |
| 2452 |
[ Entity =>] LOCAL_NAME |
| 2453 |
[, [External_Name =>] static_string_EXPRESSION ] |
| 2454 |
[, [Link_Name =>] static_string_EXPRESSION ]); |
| 2455 |
|
| 2456 |
|
| 2457 |
This pragma is identical in syntax and semantics to pragma |
| 2458 |
``Export`` as defined in the Ada Reference Manual. It is |
| 2459 |
provided for compatibility with some Ada 83 compilers that |
| 2460 |
used this pragma for exactly the same purposes as pragma |
| 2461 |
``Export`` before the latter was standardized. |
| 2462 |
|
| 2463 |
Pragma External_Name_Casing |
| 2464 |
=========================== |
| 2465 |
.. index:: Dec Ada 83 casing compatibility |
| 2466 |
|
| 2467 |
.. index:: External Names, casing |
| 2468 |
|
| 2469 |
.. index:: Casing of External names |
| 2470 |
|
| 2471 |
|
| 2472 |
Syntax: |
| 2473 |
|
| 2474 |
|
| 2475 |
:: |
| 2476 |
|
| 2477 |
pragma External_Name_Casing ( |
| 2478 |
Uppercase | Lowercase |
| 2479 |
[, Uppercase | Lowercase | As_Is]); |
| 2480 |
|
| 2481 |
|
| 2482 |
This pragma provides control over the casing of external names associated |
| 2483 |
with Import and Export pragmas. There are two cases to consider: |
| 2484 |
|
| 2485 |
|
| 2486 |
|
| 2487 |
* Implicit external names |
| 2488 |
|
| 2489 |
Implicit external names are derived from identifiers. The most common case |
| 2490 |
arises when a standard Ada Import or Export pragma is used with only two |
| 2491 |
arguments, as in: |
| 2492 |
|
| 2493 |
.. code-block:: ada |
| 2494 |
|
| 2495 |
pragma Import (C, C_Routine); |
| 2496 |
|
| 2497 |
Since Ada is a case-insensitive language, the spelling of the identifier in |
| 2498 |
the Ada source program does not provide any information on the desired |
| 2499 |
casing of the external name, and so a convention is needed. In GNAT the |
| 2500 |
default treatment is that such names are converted to all lower case |
| 2501 |
letters. This corresponds to the normal C style in many environments. |
| 2502 |
The first argument of pragma ``External_Name_Casing`` can be used to |
| 2503 |
control this treatment. If ``Uppercase`` is specified, then the name |
| 2504 |
will be forced to all uppercase letters. If ``Lowercase`` is specified, |
| 2505 |
then the normal default of all lower case letters will be used. |
| 2506 |
|
| 2507 |
This same implicit treatment is also used in the case of extended DEC Ada 83 |
| 2508 |
compatible Import and Export pragmas where an external name is explicitly |
| 2509 |
specified using an identifier rather than a string. |
| 2510 |
|
| 2511 |
|
| 2512 |
* Explicit external names |
| 2513 |
|
| 2514 |
Explicit external names are given as string literals. The most common case |
| 2515 |
arises when a standard Ada Import or Export pragma is used with three |
| 2516 |
arguments, as in: |
| 2517 |
|
| 2518 |
.. code-block:: ada |
| 2519 |
|
| 2520 |
pragma Import (C, C_Routine, "C_routine"); |
| 2521 |
|
| 2522 |
In this case, the string literal normally provides the exact casing required |
| 2523 |
for the external name. The second argument of pragma |
| 2524 |
``External_Name_Casing`` may be used to modify this behavior. |
| 2525 |
If ``Uppercase`` is specified, then the name |
| 2526 |
will be forced to all uppercase letters. If ``Lowercase`` is specified, |
| 2527 |
then the name will be forced to all lowercase letters. A specification of |
| 2528 |
``As_Is`` provides the normal default behavior in which the casing is |
| 2529 |
taken from the string provided. |
| 2530 |
|
| 2531 |
This pragma may appear anywhere that a pragma is valid. In particular, it |
| 2532 |
can be used as a configuration pragma in the :file:`gnat.adc` file, in which |
| 2533 |
case it applies to all subsequent compilations, or it can be used as a program |
| 2534 |
unit pragma, in which case it only applies to the current unit, or it can |
| 2535 |
be used more locally to control individual Import/Export pragmas. |
| 2536 |
|
| 2537 |
It was primarily intended for use with OpenVMS systems, where many |
| 2538 |
compilers convert all symbols to upper case by default. For interfacing to |
| 2539 |
such compilers (e.g., the DEC C compiler), it may be convenient to use |
| 2540 |
the pragma: |
| 2541 |
|
| 2542 |
.. code-block:: ada |
| 2543 |
|
| 2544 |
pragma External_Name_Casing (Uppercase, Uppercase); |
| 2545 |
|
| 2546 |
|
| 2547 |
to enforce the upper casing of all external symbols. |
| 2548 |
|
| 2549 |
Pragma Fast_Math |
| 2550 |
================ |
| 2551 |
|
| 2552 |
Syntax: |
| 2553 |
|
| 2554 |
|
| 2555 |
.. code-block:: ada |
| 2556 |
|
| 2557 |
pragma Fast_Math; |
| 2558 |
|
| 2559 |
|
| 2560 |
This is a configuration pragma which activates a mode in which speed is |
| 2561 |
considered more important for floating-point operations than absolutely |
| 2562 |
accurate adherence to the requirements of the standard. Currently the |
| 2563 |
following operations are affected: |
| 2564 |
|
| 2565 |
|
| 2566 |
|
| 2567 |
*Complex Multiplication* |
| 2568 |
The normal simple formula for complex multiplication can result in intermediate |
| 2569 |
overflows for numbers near the end of the range. The Ada standard requires that |
| 2570 |
this situation be detected and corrected by scaling, but in Fast_Math mode such |
| 2571 |
cases will simply result in overflow. Note that to take advantage of this you |
| 2572 |
must instantiate your own version of ``Ada.Numerics.Generic_Complex_Types`` |
| 2573 |
under control of the pragma, rather than use the preinstantiated versions. |
| 2574 |
|
| 2575 |
.. _Pragma-Favor_Top_Level: |
| 2576 |
|
| 2577 |
Pragma Favor_Top_Level |
| 2578 |
====================== |
| 2579 |
|
| 2580 |
Syntax: |
| 2581 |
|
| 2582 |
|
| 2583 |
.. code-block:: ada |
| 2584 |
|
| 2585 |
pragma Favor_Top_Level (type_NAME); |
| 2586 |
|
| 2587 |
|
| 2588 |
The argument of pragma ``Favor_Top_Level`` must be a named access-to-subprogram |
| 2589 |
type. This pragma is an efficiency hint to the compiler, regarding the use of |
| 2590 |
``'Access`` or ``'Unrestricted_Access`` on nested (non-library-level) subprograms. |
| 2591 |
The pragma means that nested subprograms are not used with this type, or are |
| 2592 |
rare, so that the generated code should be efficient in the top-level case. |
| 2593 |
When this pragma is used, dynamically generated trampolines may be used on some |
| 2594 |
targets for nested subprograms. See restriction ``No_Implicit_Dynamic_Code``. |
| 2595 |
|
| 2596 |
Pragma Finalize_Storage_Only |
| 2597 |
============================ |
| 2598 |
|
| 2599 |
Syntax: |
| 2600 |
|
| 2601 |
|
| 2602 |
.. code-block:: ada |
| 2603 |
|
| 2604 |
pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME); |
| 2605 |
|
| 2606 |
|
| 2607 |
The argument of pragma ``Finalize_Storage_Only`` must denote a local type which |
| 2608 |
is derived from ``Ada.Finalization.Controlled`` or ``Limited_Controlled``. The |
| 2609 |
pragma suppresses the call to ``Finalize`` for declared library-level objects |
| 2610 |
of the argument type. This is mostly useful for types where finalization is |
| 2611 |
only used to deal with storage reclamation since in most environments it is |
| 2612 |
not necessary to reclaim memory just before terminating execution, hence the |
| 2613 |
name. Note that this pragma does not suppress Finalize calls for library-level |
| 2614 |
heap-allocated objects (see pragma ``No_Heap_Finalization``). |
| 2615 |
|
| 2616 |
Pragma Float_Representation |
| 2617 |
=========================== |
| 2618 |
|
| 2619 |
Syntax:: |
| 2620 |
|
| 2621 |
pragma Float_Representation (FLOAT_REP[, float_type_LOCAL_NAME]); |
| 2622 |
|
| 2623 |
FLOAT_REP ::= VAX_Float | IEEE_Float |
| 2624 |
|
| 2625 |
|
| 2626 |
In the one argument form, this pragma is a configuration pragma which |
| 2627 |
allows control over the internal representation chosen for the predefined |
| 2628 |
floating point types declared in the packages ``Standard`` and |
| 2629 |
``System``. This pragma is only provided for compatibility and has no effect. |
| 2630 |
|
| 2631 |
The two argument form specifies the representation to be used for |
| 2632 |
the specified floating-point type. The argument must |
| 2633 |
be ``IEEE_Float`` to specify the use of IEEE format, as follows: |
| 2634 |
|
| 2635 |
* |
| 2636 |
For a digits value of 6, 32-bit IEEE short format will be used. |
| 2637 |
* |
| 2638 |
For a digits value of 15, 64-bit IEEE long format will be used. |
| 2639 |
* |
| 2640 |
No other value of digits is permitted. |
| 2641 |
|
| 2642 |
.. _Pragma-Ghost: |
| 2643 |
|
| 2644 |
Pragma Ghost |
| 2645 |
============ |
| 2646 |
|
| 2647 |
Syntax: |
| 2648 |
|
| 2649 |
.. code-block:: ada |
| 2650 |
|
| 2651 |
pragma Ghost [ (static_boolean_EXPRESSION) ]; |
| 2652 |
|
| 2653 |
For the semantics of this pragma, see the entry for aspect ``Ghost`` in the SPARK |
| 2654 |
2014 Reference Manual, section 6.9. |
| 2655 |
|
| 2656 |
.. _Pragma-Global: |
| 2657 |
|
| 2658 |
Pragma Global |
| 2659 |
============= |
| 2660 |
|
| 2661 |
Syntax: |
| 2662 |
|
| 2663 |
.. code-block:: ada |
| 2664 |
|
| 2665 |
pragma Global (GLOBAL_SPECIFICATION); |
| 2666 |
|
| 2667 |
GLOBAL_SPECIFICATION ::= |
| 2668 |
null |
| 2669 |
| (GLOBAL_LIST) |
| 2670 |
| (MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST}) |
| 2671 |
|
| 2672 |
MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST |
| 2673 |
|
| 2674 |
MODE_SELECTOR ::= In_Out | Input | Output | Proof_In |
| 2675 |
GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM}) |
| 2676 |
GLOBAL_ITEM ::= NAME |
| 2677 |
|
| 2678 |
For the semantics of this pragma, see the entry for aspect ``Global`` in the |
| 2679 |
SPARK 2014 Reference Manual, section 6.1.4. |
| 2680 |
|
| 2681 |
Pragma Ident |
| 2682 |
============ |
| 2683 |
|
| 2684 |
Syntax: |
| 2685 |
|
| 2686 |
|
| 2687 |
.. code-block:: ada |
| 2688 |
|
| 2689 |
pragma Ident (static_string_EXPRESSION); |
| 2690 |
|
| 2691 |
|
| 2692 |
This pragma is identical in effect to pragma ``Comment``. It is provided |
| 2693 |
for compatibility with other Ada compilers providing this pragma. |
| 2694 |
|
| 2695 |
Pragma Ignore_Pragma |
| 2696 |
==================== |
| 2697 |
|
| 2698 |
Syntax: |
| 2699 |
|
| 2700 |
|
| 2701 |
.. code-block:: ada |
| 2702 |
|
| 2703 |
pragma Ignore_Pragma (pragma_IDENTIFIER); |
| 2704 |
|
| 2705 |
This is a configuration pragma |
| 2706 |
that takes a single argument that is a simple identifier. Any subsequent |
| 2707 |
use of a pragma whose pragma identifier matches this argument will be |
| 2708 |
silently ignored. This may be useful when legacy code or code intended |
| 2709 |
for compilation with some other compiler contains pragmas that match the |
| 2710 |
name, but not the exact implementation, of a GNAT pragma. The use of this |
| 2711 |
pragma allows such pragmas to be ignored, which may be useful in CodePeer |
| 2712 |
mode, or during porting of legacy code. |
| 2713 |
|
| 2714 |
Pragma Implementation_Defined |
| 2715 |
============================= |
| 2716 |
|
| 2717 |
Syntax: |
| 2718 |
|
| 2719 |
|
| 2720 |
.. code-block:: ada |
| 2721 |
|
| 2722 |
pragma Implementation_Defined (local_NAME); |
| 2723 |
|
| 2724 |
|
| 2725 |
This pragma marks a previously declared entity as implementation-defined. |
| 2726 |
For an overloaded entity, applies to the most recent homonym. |
| 2727 |
|
| 2728 |
|
| 2729 |
.. code-block:: ada |
| 2730 |
|
| 2731 |
pragma Implementation_Defined; |
| 2732 |
|
| 2733 |
|
| 2734 |
The form with no arguments appears anywhere within a scope, most |
| 2735 |
typically a package spec, and indicates that all entities that are |
| 2736 |
defined within the package spec are Implementation_Defined. |
| 2737 |
|
| 2738 |
This pragma is used within the GNAT runtime library to identify |
| 2739 |
implementation-defined entities introduced in language-defined units, |
| 2740 |
for the purpose of implementing the No_Implementation_Identifiers |
| 2741 |
restriction. |
| 2742 |
|
| 2743 |
Pragma Implemented |
| 2744 |
================== |
| 2745 |
|
| 2746 |
Syntax: |
| 2747 |
|
| 2748 |
|
| 2749 |
:: |
| 2750 |
|
| 2751 |
pragma Implemented (procedure_LOCAL_NAME, implementation_kind); |
| 2752 |
|
| 2753 |
implementation_kind ::= By_Entry | By_Protected_Procedure | By_Any |
| 2754 |
|
| 2755 |
|
| 2756 |
This is an Ada 2012 representation pragma which applies to protected, task |
| 2757 |
and synchronized interface primitives. The use of pragma Implemented provides |
| 2758 |
a way to impose a static requirement on the overriding operation by adhering |
| 2759 |
to one of the three implementation kinds: entry, protected procedure or any of |
| 2760 |
the above. This pragma is available in all earlier versions of Ada as an |
| 2761 |
implementation-defined pragma. |
| 2762 |
|
| 2763 |
|
| 2764 |
.. code-block:: ada |
| 2765 |
|
| 2766 |
type Synch_Iface is synchronized interface; |
| 2767 |
procedure Prim_Op (Obj : in out Iface) is abstract; |
| 2768 |
pragma Implemented (Prim_Op, By_Protected_Procedure); |
| 2769 |
|
| 2770 |
protected type Prot_1 is new Synch_Iface with |
| 2771 |
procedure Prim_Op; -- Legal |
| 2772 |
end Prot_1; |
| 2773 |
|
| 2774 |
protected type Prot_2 is new Synch_Iface with |
| 2775 |
entry Prim_Op; -- Illegal |
| 2776 |
end Prot_2; |
| 2777 |
|
| 2778 |
task type Task_Typ is new Synch_Iface with |
| 2779 |
entry Prim_Op; -- Illegal |
| 2780 |
end Task_Typ; |
| 2781 |
|
| 2782 |
|
| 2783 |
When applied to the procedure_or_entry_NAME of a requeue statement, pragma |
| 2784 |
Implemented determines the runtime behavior of the requeue. Implementation kind |
| 2785 |
By_Entry guarantees that the action of requeueing will proceed from an entry to |
| 2786 |
another entry. Implementation kind By_Protected_Procedure transforms the |
| 2787 |
requeue into a dispatching call, thus eliminating the chance of blocking. Kind |
| 2788 |
By_Any shares the behavior of By_Entry and By_Protected_Procedure depending on |
| 2789 |
the target's overriding subprogram kind. |
| 2790 |
|
| 2791 |
Pragma Implicit_Packing |
| 2792 |
======================= |
| 2793 |
.. index:: Rational Profile |
| 2794 |
|
| 2795 |
Syntax: |
| 2796 |
|
| 2797 |
|
| 2798 |
.. code-block:: ada |
| 2799 |
|
| 2800 |
pragma Implicit_Packing; |
| 2801 |
|
| 2802 |
|
| 2803 |
This is a configuration pragma that requests implicit packing for packed |
| 2804 |
arrays for which a size clause is given but no explicit pragma Pack or |
| 2805 |
specification of Component_Size is present. It also applies to records |
| 2806 |
where no record representation clause is present. Consider this example: |
| 2807 |
|
| 2808 |
|
| 2809 |
.. code-block:: ada |
| 2810 |
|
| 2811 |
type R is array (0 .. 7) of Boolean; |
| 2812 |
for R'Size use 8; |
| 2813 |
|
| 2814 |
|
| 2815 |
In accordance with the recommendation in the RM (RM 13.3(53)), a Size clause |
| 2816 |
does not change the layout of a composite object. So the Size clause in the |
| 2817 |
above example is normally rejected, since the default layout of the array uses |
| 2818 |
8-bit components, and thus the array requires a minimum of 64 bits. |
| 2819 |
|
| 2820 |
If this declaration is compiled in a region of code covered by an occurrence |
| 2821 |
of the configuration pragma Implicit_Packing, then the Size clause in this |
| 2822 |
and similar examples will cause implicit packing and thus be accepted. For |
| 2823 |
this implicit packing to occur, the type in question must be an array of small |
| 2824 |
components whose size is known at compile time, and the Size clause must |
| 2825 |
specify the exact size that corresponds to the number of elements in the array |
| 2826 |
multiplied by the size in bits of the component type (both single and |
| 2827 |
multi-dimensioned arrays can be controlled with this pragma). |
| 2828 |
|
| 2829 |
.. index:: Array packing |
| 2830 |
|
| 2831 |
Similarly, the following example shows the use in the record case |
| 2832 |
|
| 2833 |
|
| 2834 |
.. code-block:: ada |
| 2835 |
|
| 2836 |
type r is record |
| 2837 |
a, b, c, d, e, f, g, h : boolean; |
| 2838 |
chr : character; |
| 2839 |
end record; |
| 2840 |
for r'size use 16; |
| 2841 |
|
| 2842 |
|
| 2843 |
Without a pragma Pack, each Boolean field requires 8 bits, so the |
| 2844 |
minimum size is 72 bits, but with a pragma Pack, 16 bits would be |
| 2845 |
sufficient. The use of pragma Implicit_Packing allows this record |
| 2846 |
declaration to compile without an explicit pragma Pack. |
| 2847 |
|
| 2848 |
Pragma Import_Function |
| 2849 |
====================== |
| 2850 |
|
| 2851 |
Syntax: |
| 2852 |
|
| 2853 |
|
| 2854 |
:: |
| 2855 |
|
| 2856 |
pragma Import_Function ( |
| 2857 |
[Internal =>] LOCAL_NAME, |
| 2858 |
[, [External =>] EXTERNAL_SYMBOL] |
| 2859 |
[, [Parameter_Types =>] PARAMETER_TYPES] |
| 2860 |
[, [Result_Type =>] SUBTYPE_MARK] |
| 2861 |
[, [Mechanism =>] MECHANISM] |
| 2862 |
[, [Result_Mechanism =>] MECHANISM_NAME]); |
| 2863 |
|
| 2864 |
EXTERNAL_SYMBOL ::= |
| 2865 |
IDENTIFIER |
| 2866 |
| static_string_EXPRESSION |
| 2867 |
|
| 2868 |
PARAMETER_TYPES ::= |
| 2869 |
null |
| 2870 |
| TYPE_DESIGNATOR {, TYPE_DESIGNATOR} |
| 2871 |
|
| 2872 |
TYPE_DESIGNATOR ::= |
| 2873 |
subtype_NAME |
| 2874 |
| subtype_Name ' Access |
| 2875 |
|
| 2876 |
MECHANISM ::= |
| 2877 |
MECHANISM_NAME |
| 2878 |
| (MECHANISM_ASSOCIATION {, MECHANISM_ASSOCIATION}) |
| 2879 |
|
| 2880 |
MECHANISM_ASSOCIATION ::= |
| 2881 |
[formal_parameter_NAME =>] MECHANISM_NAME |
| 2882 |
|
| 2883 |
MECHANISM_NAME ::= |
| 2884 |
Value |
| 2885 |
| Reference |
| 2886 |
|
| 2887 |
|
| 2888 |
This pragma is used in conjunction with a pragma ``Import`` to |
| 2889 |
specify additional information for an imported function. The pragma |
| 2890 |
``Import`` (or equivalent pragma ``Interface``) must precede the |
| 2891 |
``Import_Function`` pragma and both must appear in the same |
| 2892 |
declarative part as the function specification. |
| 2893 |
|
| 2894 |
The ``Internal`` argument must uniquely designate |
| 2895 |
the function to which the |
| 2896 |
pragma applies. If more than one function name exists of this name in |
| 2897 |
the declarative part you must use the ``Parameter_Types`` and |
| 2898 |
``Result_Type`` parameters to achieve the required unique |
| 2899 |
designation. Subtype marks in these parameters must exactly match the |
| 2900 |
subtypes in the corresponding function specification, using positional |
| 2901 |
notation to match parameters with subtype marks. |
| 2902 |
The form with an ``'Access`` attribute can be used to match an |
| 2903 |
anonymous access parameter. |
| 2904 |
|
| 2905 |
You may optionally use the ``Mechanism`` and ``Result_Mechanism`` |
| 2906 |
parameters to specify passing mechanisms for the |
| 2907 |
parameters and result. If you specify a single mechanism name, it |
| 2908 |
applies to all parameters. Otherwise you may specify a mechanism on a |
| 2909 |
parameter by parameter basis using either positional or named |
| 2910 |
notation. If the mechanism is not specified, the default mechanism |
| 2911 |
is used. |
| 2912 |
|
| 2913 |
Pragma Import_Object |
| 2914 |
==================== |
| 2915 |
|
| 2916 |
Syntax: |
| 2917 |
|
| 2918 |
|
| 2919 |
:: |
| 2920 |
|
| 2921 |
pragma Import_Object ( |
| 2922 |
[Internal =>] LOCAL_NAME |
| 2923 |
[, [External =>] EXTERNAL_SYMBOL] |
| 2924 |
[, [Size =>] EXTERNAL_SYMBOL]); |
| 2925 |
|
| 2926 |
EXTERNAL_SYMBOL ::= |
| 2927 |
IDENTIFIER |
| 2928 |
| static_string_EXPRESSION |
| 2929 |
|
| 2930 |
|
| 2931 |
This pragma designates an object as imported, and apart from the |
| 2932 |
extended rules for external symbols, is identical in effect to the use of |
| 2933 |
the normal ``Import`` pragma applied to an object. Unlike the |
| 2934 |
subprogram case, you need not use a separate ``Import`` pragma, |
| 2935 |
although you may do so (and probably should do so from a portability |
| 2936 |
point of view). ``size`` is syntax checked, but otherwise ignored by |
| 2937 |
GNAT. |
| 2938 |
|
| 2939 |
Pragma Import_Procedure |
| 2940 |
======================= |
| 2941 |
|
| 2942 |
Syntax: |
| 2943 |
|
| 2944 |
|
| 2945 |
:: |
| 2946 |
|
| 2947 |
pragma Import_Procedure ( |
| 2948 |
[Internal =>] LOCAL_NAME |
| 2949 |
[, [External =>] EXTERNAL_SYMBOL] |
| 2950 |
[, [Parameter_Types =>] PARAMETER_TYPES] |
| 2951 |
[, [Mechanism =>] MECHANISM]); |
| 2952 |
|
| 2953 |
EXTERNAL_SYMBOL ::= |
| 2954 |
IDENTIFIER |
| 2955 |
| static_string_EXPRESSION |
| 2956 |
|
| 2957 |
PARAMETER_TYPES ::= |
| 2958 |
null |
| 2959 |
| TYPE_DESIGNATOR {, TYPE_DESIGNATOR} |
| 2960 |
|
| 2961 |
TYPE_DESIGNATOR ::= |
| 2962 |
subtype_NAME |
| 2963 |
| subtype_Name ' Access |
| 2964 |
|
| 2965 |
MECHANISM ::= |
| 2966 |
MECHANISM_NAME |
| 2967 |
| (MECHANISM_ASSOCIATION {, MECHANISM_ASSOCIATION}) |
| 2968 |
|
| 2969 |
MECHANISM_ASSOCIATION ::= |
| 2970 |
[formal_parameter_NAME =>] MECHANISM_NAME |
| 2971 |
|
| 2972 |
MECHANISM_NAME ::= Value | Reference |
| 2973 |
|
| 2974 |
|
| 2975 |
This pragma is identical to ``Import_Function`` except that it |
| 2976 |
applies to a procedure rather than a function and the parameters |
| 2977 |
``Result_Type`` and ``Result_Mechanism`` are not permitted. |
| 2978 |
|
| 2979 |
Pragma Import_Valued_Procedure |
| 2980 |
============================== |
| 2981 |
|
| 2982 |
Syntax: |
| 2983 |
|
| 2984 |
|
| 2985 |
:: |
| 2986 |
|
| 2987 |
pragma Import_Valued_Procedure ( |
| 2988 |
[Internal =>] LOCAL_NAME |
| 2989 |
[, [External =>] EXTERNAL_SYMBOL] |
| 2990 |
[, [Parameter_Types =>] PARAMETER_TYPES] |
| 2991 |
[, [Mechanism =>] MECHANISM]); |
| 2992 |
|
| 2993 |
EXTERNAL_SYMBOL ::= |
| 2994 |
IDENTIFIER |
| 2995 |
| static_string_EXPRESSION |
| 2996 |
|
| 2997 |
PARAMETER_TYPES ::= |
| 2998 |
null |
| 2999 |
| TYPE_DESIGNATOR {, TYPE_DESIGNATOR} |
| 3000 |
|
| 3001 |
TYPE_DESIGNATOR ::= |
| 3002 |
subtype_NAME |
| 3003 |
| subtype_Name ' Access |
| 3004 |
|
| 3005 |
MECHANISM ::= |
| 3006 |
MECHANISM_NAME |
| 3007 |
| (MECHANISM_ASSOCIATION {, MECHANISM_ASSOCIATION}) |
| 3008 |
|
| 3009 |
MECHANISM_ASSOCIATION ::= |
| 3010 |
[formal_parameter_NAME =>] MECHANISM_NAME |
| 3011 |
|
| 3012 |
MECHANISM_NAME ::= Value | Reference |
| 3013 |
|
| 3014 |
|
| 3015 |
This pragma is identical to ``Import_Procedure`` except that the |
| 3016 |
first parameter of ``LOCAL_NAME``, which must be present, must be of |
| 3017 |
mode ``out``, and externally the subprogram is treated as a function |
| 3018 |
with this parameter as the result of the function. The purpose of this |
| 3019 |
capability is to allow the use of ``out`` and ``in out`` |
| 3020 |
parameters in interfacing to external functions (which are not permitted |
| 3021 |
in Ada functions). You may optionally use the ``Mechanism`` |
| 3022 |
parameters to specify passing mechanisms for the parameters. |
| 3023 |
If you specify a single mechanism name, it applies to all parameters. |
| 3024 |
Otherwise you may specify a mechanism on a parameter by parameter |
| 3025 |
basis using either positional or named notation. If the mechanism is not |
| 3026 |
specified, the default mechanism is used. |
| 3027 |
|
| 3028 |
Note that it is important to use this pragma in conjunction with a separate |
| 3029 |
pragma Import that specifies the desired convention, since otherwise the |
| 3030 |
default convention is Ada, which is almost certainly not what is required. |
| 3031 |
|
| 3032 |
Pragma Independent |
| 3033 |
================== |
| 3034 |
|
| 3035 |
Syntax: |
| 3036 |
|
| 3037 |
|
| 3038 |
.. code-block:: ada |
| 3039 |
|
| 3040 |
pragma Independent (Local_NAME); |
| 3041 |
|
| 3042 |
|
| 3043 |
This pragma is standard in Ada 2012 mode (which also provides an aspect |
| 3044 |
of the same name). It is also available as an implementation-defined |
| 3045 |
pragma in all earlier versions. It specifies that the |
| 3046 |
designated object or all objects of the designated type must be |
| 3047 |
independently addressable. This means that separate tasks can safely |
| 3048 |
manipulate such objects. For example, if two components of a record are |
| 3049 |
independent, then two separate tasks may access these two components. |
| 3050 |
This may place |
| 3051 |
constraints on the representation of the object (for instance prohibiting |
| 3052 |
tight packing). |
| 3053 |
|
| 3054 |
Pragma Independent_Components |
| 3055 |
============================= |
| 3056 |
|
| 3057 |
Syntax: |
| 3058 |
|
| 3059 |
|
| 3060 |
.. code-block:: ada |
| 3061 |
|
| 3062 |
pragma Independent_Components (Local_NAME); |
| 3063 |
|
| 3064 |
|
| 3065 |
This pragma is standard in Ada 2012 mode (which also provides an aspect |
| 3066 |
of the same name). It is also available as an implementation-defined |
| 3067 |
pragma in all earlier versions. It specifies that the components of the |
| 3068 |
designated object, or the components of each object of the designated |
| 3069 |
type, must be |
| 3070 |
independently addressable. This means that separate tasks can safely |
| 3071 |
manipulate separate components in the composite object. This may place |
| 3072 |
constraints on the representation of the object (for instance prohibiting |
| 3073 |
tight packing). |
| 3074 |
|
| 3075 |
.. _Pragma-Initial_Condition: |
| 3076 |
|
| 3077 |
Pragma Initial_Condition |
| 3078 |
======================== |
| 3079 |
|
| 3080 |
Syntax: |
| 3081 |
|
| 3082 |
.. code-block:: ada |
| 3083 |
|
| 3084 |
pragma Initial_Condition (boolean_EXPRESSION); |
| 3085 |
|
| 3086 |
For the semantics of this pragma, see the entry for aspect ``Initial_Condition`` |
| 3087 |
in the SPARK 2014 Reference Manual, section 7.1.6. |
| 3088 |
|
| 3089 |
Pragma Initialize_Scalars |
| 3090 |
========================= |
| 3091 |
.. index:: debugging with Initialize_Scalars |
| 3092 |
|
| 3093 |
Syntax: |
| 3094 |
|
| 3095 |
|
| 3096 |
.. code-block:: ada |
| 3097 |
|
| 3098 |
pragma Initialize_Scalars |
| 3099 |
[ ( TYPE_VALUE_PAIR {, TYPE_VALUE_PAIR} ) ]; |
| 3100 |
|
| 3101 |
TYPE_VALUE_PAIR ::= |
| 3102 |
SCALAR_TYPE => static_EXPRESSION |
| 3103 |
|
| 3104 |
SCALAR_TYPE := |
| 3105 |
Short_Float |
| 3106 |
| Float |
| 3107 |
| Long_Float |
| 3108 |
| Long_Long_Flat |
| 3109 |
| Signed_8 |
| 3110 |
| Signed_16 |
| 3111 |
| Signed_32 |
| 3112 |
| Signed_64 |
| 3113 |
| Unsigned_8 |
| 3114 |
| Unsigned_16 |
| 3115 |
| Unsigned_32 |
| 3116 |
| Unsigned_64 |
| 3117 |
|
| 3118 |
|
| 3119 |
This pragma is similar to ``Normalize_Scalars`` conceptually but has two |
| 3120 |
important differences. |
| 3121 |
|
| 3122 |
First, there is no requirement for the pragma to be used uniformly in all units |
| 3123 |
of a partition. In particular, it is fine to use this just for some or all of |
| 3124 |
the application units of a partition, without needing to recompile the run-time |
| 3125 |
library. In the case where some units are compiled with the pragma, and some |
| 3126 |
without, then a declaration of a variable where the type is defined in package |
| 3127 |
Standard or is locally declared will always be subject to initialization, as |
| 3128 |
will any declaration of a scalar variable. For composite variables, whether the |
| 3129 |
variable is initialized may also depend on whether the package in which the |
| 3130 |
type of the variable is declared is compiled with the pragma. |
| 3131 |
|
| 3132 |
The other important difference is that the programmer can control the value |
| 3133 |
used for initializing scalar objects. This effect can be achieved in several |
| 3134 |
different ways: |
| 3135 |
|
| 3136 |
* At compile time, the programmer can specify the invalid value for a |
| 3137 |
particular family of scalar types using the optional arguments of the pragma. |
| 3138 |
|
| 3139 |
The compile-time approach is intended to optimize the generated code for the |
| 3140 |
pragma, by possibly using fast operations such as ``memset``. Note that such |
| 3141 |
optimizations require using values where the bytes all have the same binary |
| 3142 |
representation. |
| 3143 |
|
| 3144 |
* At bind time, the programmer has several options: |
| 3145 |
|
| 3146 |
* Initialization with invalid values (similar to Normalize_Scalars, though |
| 3147 |
for Initialize_Scalars it is not always possible to determine the invalid |
| 3148 |
values in complex cases like signed component fields with nonstandard |
| 3149 |
sizes). |
| 3150 |
|
| 3151 |
* Initialization with high values. |
| 3152 |
|
| 3153 |
* Initialization with low values. |
| 3154 |
|
| 3155 |
* Initialization with a specific bit pattern. |
| 3156 |
|
| 3157 |
See the GNAT User's Guide for binder options for specifying these cases. |
| 3158 |
|
| 3159 |
The bind-time approach is intended to provide fast turnaround for testing |
| 3160 |
with different values, without having to recompile the program. |
| 3161 |
|
| 3162 |
* At execution time, the programmer can specify the invalid values using an |
| 3163 |
environment variable. See the GNAT User's Guide for details. |
| 3164 |
|
| 3165 |
The execution-time approach is intended to provide fast turnaround for |
| 3166 |
testing with different values, without having to recompile and rebind the |
| 3167 |
program. |
| 3168 |
|
| 3169 |
Note that pragma ``Initialize_Scalars`` is particularly useful in conjunction |
| 3170 |
with the enhanced validity checking that is now provided in GNAT, which checks |
| 3171 |
for invalid values under more conditions. Using this feature (see description |
| 3172 |
of the *-gnatV* flag in the GNAT User's Guide) in conjunction with pragma |
| 3173 |
``Initialize_Scalars`` provides a powerful new tool to assist in the detection |
| 3174 |
of problems caused by uninitialized variables. |
| 3175 |
|
| 3176 |
Note: the use of ``Initialize_Scalars`` has a fairly extensive effect on the |
| 3177 |
generated code. This may cause your code to be substantially larger. It may |
| 3178 |
also cause an increase in the amount of stack required, so it is probably a |
| 3179 |
good idea to turn on stack checking (see description of stack checking in the |
| 3180 |
GNAT User's Guide) when using this pragma. |
| 3181 |
|
| 3182 |
.. _Pragma-Initializes: |
| 3183 |
|
| 3184 |
Pragma Initializes |
| 3185 |
================== |
| 3186 |
|
| 3187 |
Syntax: |
| 3188 |
|
| 3189 |
.. code-block:: ada |
| 3190 |
|
| 3191 |
pragma Initializes (INITIALIZATION_LIST); |
| 3192 |
|
| 3193 |
INITIALIZATION_LIST ::= |
| 3194 |
null |
| 3195 |
| (INITIALIZATION_ITEM {, INITIALIZATION_ITEM}) |
| 3196 |
|
| 3197 |
INITIALIZATION_ITEM ::= name [=> INPUT_LIST] |
| 3198 |
|
| 3199 |
INPUT_LIST ::= |
| 3200 |
null |
| 3201 |
| INPUT |
| 3202 |
| (INPUT {, INPUT}) |
| 3203 |
|
| 3204 |
INPUT ::= name |
| 3205 |
|
| 3206 |
For the semantics of this pragma, see the entry for aspect ``Initializes`` in the |
| 3207 |
SPARK 2014 Reference Manual, section 7.1.5. |
| 3208 |
|
| 3209 |
.. _Pragma-Inline_Always: |
| 3210 |
|
| 3211 |
Pragma Inline_Always |
| 3212 |
==================== |
| 3213 |
|
| 3214 |
Syntax: |
| 3215 |
|
| 3216 |
|
| 3217 |
:: |
| 3218 |
|
| 3219 |
pragma Inline_Always (NAME [, NAME]); |
| 3220 |
|
| 3221 |
|
| 3222 |
Similar to pragma ``Inline`` except that inlining is unconditional. |
| 3223 |
Inline_Always instructs the compiler to inline every direct call to the |
| 3224 |
subprogram or else to emit a compilation error, independently of any |
| 3225 |
option, in particular *-gnatn* or *-gnatN* or the optimization level. |
| 3226 |
It is an error to take the address or access of ``NAME``. It is also an error to |
| 3227 |
apply this pragma to a primitive operation of a tagged type. Thanks to such |
| 3228 |
restrictions, the compiler is allowed to remove the out-of-line body of ``NAME``. |
| 3229 |
|
| 3230 |
Pragma Inline_Generic |
| 3231 |
===================== |
| 3232 |
|
| 3233 |
Syntax: |
| 3234 |
|
| 3235 |
|
| 3236 |
:: |
| 3237 |
|
| 3238 |
pragma Inline_Generic (GNAME {, GNAME}); |
| 3239 |
|
| 3240 |
GNAME ::= generic_unit_NAME | generic_instance_NAME |
| 3241 |
|
| 3242 |
|
| 3243 |
This pragma is provided for compatibility with Dec Ada 83. It has |
| 3244 |
no effect in GNAT (which always inlines generics), other |
| 3245 |
than to check that the given names are all names of generic units or |
| 3246 |
generic instances. |
| 3247 |
|
| 3248 |
Pragma Interface |
| 3249 |
================ |
| 3250 |
|
| 3251 |
Syntax: |
| 3252 |
|
| 3253 |
|
| 3254 |
:: |
| 3255 |
|
| 3256 |
pragma Interface ( |
| 3257 |
[Convention =>] convention_identifier, |
| 3258 |
[Entity =>] local_NAME |
| 3259 |
[, [External_Name =>] static_string_expression] |
| 3260 |
[, [Link_Name =>] static_string_expression]); |
| 3261 |
|
| 3262 |
|
| 3263 |
This pragma is identical in syntax and semantics to |
| 3264 |
the standard Ada pragma ``Import``. It is provided for compatibility |
| 3265 |
with Ada 83. The definition is upwards compatible both with pragma |
| 3266 |
``Interface`` as defined in the Ada 83 Reference Manual, and also |
| 3267 |
with some extended implementations of this pragma in certain Ada 83 |
| 3268 |
implementations. The only difference between pragma ``Interface`` |
| 3269 |
and pragma ``Import`` is that there is special circuitry to allow |
| 3270 |
both pragmas to appear for the same subprogram entity (normally it |
| 3271 |
is illegal to have multiple ``Import`` pragmas). This is useful in |
| 3272 |
maintaining Ada 83/Ada 95 compatibility and is compatible with other |
| 3273 |
Ada 83 compilers. |
| 3274 |
|
| 3275 |
Pragma Interface_Name |
| 3276 |
===================== |
| 3277 |
|
| 3278 |
Syntax: |
| 3279 |
|
| 3280 |
|
| 3281 |
:: |
| 3282 |
|
| 3283 |
pragma Interface_Name ( |
| 3284 |
[Entity =>] LOCAL_NAME |
| 3285 |
[, [External_Name =>] static_string_EXPRESSION] |
| 3286 |
[, [Link_Name =>] static_string_EXPRESSION]); |
| 3287 |
|
| 3288 |
|
| 3289 |
This pragma provides an alternative way of specifying the interface name |
| 3290 |
for an interfaced subprogram, and is provided for compatibility with Ada |
| 3291 |
83 compilers that use the pragma for this purpose. You must provide at |
| 3292 |
least one of ``External_Name`` or ``Link_Name``. |
| 3293 |
|
| 3294 |
Pragma Interrupt_Handler |
| 3295 |
======================== |
| 3296 |
|
| 3297 |
Syntax: |
| 3298 |
|
| 3299 |
|
| 3300 |
.. code-block:: ada |
| 3301 |
|
| 3302 |
pragma Interrupt_Handler (procedure_LOCAL_NAME); |
| 3303 |
|
| 3304 |
|
| 3305 |
This program unit pragma is supported for parameterless protected procedures |
| 3306 |
as described in Annex C of the Ada Reference Manual. |
| 3307 |
|
| 3308 |
Pragma Interrupt_State |
| 3309 |
====================== |
| 3310 |
|
| 3311 |
Syntax: |
| 3312 |
|
| 3313 |
|
| 3314 |
:: |
| 3315 |
|
| 3316 |
pragma Interrupt_State |
| 3317 |
([Name =>] value, |
| 3318 |
[State =>] SYSTEM | RUNTIME | USER); |
| 3319 |
|
| 3320 |
|
| 3321 |
Normally certain interrupts are reserved to the implementation. Any attempt |
| 3322 |
to attach an interrupt causes Program_Error to be raised, as described in |
| 3323 |
RM C.3.2(22). A typical example is the ``SIGINT`` interrupt used in |
| 3324 |
many systems for an :kbd:`Ctrl-C` interrupt. Normally this interrupt is |
| 3325 |
reserved to the implementation, so that :kbd:`Ctrl-C` can be used to |
| 3326 |
interrupt execution. Additionally, signals such as ``SIGSEGV``, |
| 3327 |
``SIGABRT``, ``SIGFPE`` and ``SIGILL`` are often mapped to specific |
| 3328 |
Ada exceptions, or used to implement run-time functions such as the |
| 3329 |
``abort`` statement and stack overflow checking. |
| 3330 |
|
| 3331 |
Pragma ``Interrupt_State`` provides a general mechanism for overriding |
| 3332 |
such uses of interrupts. It subsumes the functionality of pragma |
| 3333 |
``Unreserve_All_Interrupts``. Pragma ``Interrupt_State`` is not |
| 3334 |
available on Windows. On all other platforms than VxWorks, |
| 3335 |
it applies to signals; on VxWorks, it applies to vectored hardware interrupts |
| 3336 |
and may be used to mark interrupts required by the board support package |
| 3337 |
as reserved. |
| 3338 |
|
| 3339 |
Interrupts can be in one of three states: |
| 3340 |
|
| 3341 |
* System |
| 3342 |
|
| 3343 |
The interrupt is reserved (no Ada handler can be installed), and the |
| 3344 |
Ada run-time may not install a handler. As a result you are guaranteed |
| 3345 |
standard system default action if this interrupt is raised. This also allows |
| 3346 |
installing a low level handler via C APIs such as sigaction(), outside |
| 3347 |
of Ada control. |
| 3348 |
|
| 3349 |
* Runtime |
| 3350 |
|
| 3351 |
The interrupt is reserved (no Ada handler can be installed). The run time |
| 3352 |
is allowed to install a handler for internal control purposes, but is |
| 3353 |
not required to do so. |
| 3354 |
|
| 3355 |
* User |
| 3356 |
|
| 3357 |
The interrupt is unreserved. The user may install an Ada handler via |
| 3358 |
Ada.Interrupts and pragma Interrupt_Handler or Attach_Handler to provide |
| 3359 |
some other action. |
| 3360 |
|
| 3361 |
These states are the allowed values of the ``State`` parameter of the |
| 3362 |
pragma. The ``Name`` parameter is a value of the type |
| 3363 |
``Ada.Interrupts.Interrupt_ID``. Typically, it is a name declared in |
| 3364 |
``Ada.Interrupts.Names``. |
| 3365 |
|
| 3366 |
This is a configuration pragma, and the binder will check that there |
| 3367 |
are no inconsistencies between different units in a partition in how a |
| 3368 |
given interrupt is specified. It may appear anywhere a pragma is legal. |
| 3369 |
|
| 3370 |
The effect is to move the interrupt to the specified state. |
| 3371 |
|
| 3372 |
By declaring interrupts to be SYSTEM, you guarantee the standard system |
| 3373 |
action, such as a core dump. |
| 3374 |
|
| 3375 |
By declaring interrupts to be USER, you guarantee that you can install |
| 3376 |
a handler. |
| 3377 |
|
| 3378 |
Note that certain signals on many operating systems cannot be caught and |
| 3379 |
handled by applications. In such cases, the pragma is ignored. See the |
| 3380 |
operating system documentation, or the value of the array ``Reserved`` |
| 3381 |
declared in the spec of package ``System.OS_Interface``. |
| 3382 |
|
| 3383 |
Overriding the default state of signals used by the Ada runtime may interfere |
| 3384 |
with an application's runtime behavior in the cases of the synchronous signals, |
| 3385 |
and in the case of the signal used to implement the ``abort`` statement. |
| 3386 |
|
| 3387 |
.. _Pragma-Invariant: |
| 3388 |
|
| 3389 |
Pragma Invariant |
| 3390 |
================ |
| 3391 |
|
| 3392 |
Syntax: |
| 3393 |
|
| 3394 |
|
| 3395 |
:: |
| 3396 |
|
| 3397 |
pragma Invariant |
| 3398 |
([Entity =>] private_type_LOCAL_NAME, |
| 3399 |
[Check =>] EXPRESSION |
| 3400 |
[,[Message =>] String_Expression]); |
| 3401 |
|
| 3402 |
|
| 3403 |
This pragma provides exactly the same capabilities as the Type_Invariant aspect |
| 3404 |
defined in AI05-0146-1, and in the Ada 2012 Reference Manual. The |
| 3405 |
Type_Invariant aspect is fully implemented in Ada 2012 mode, but since it |
| 3406 |
requires the use of the aspect syntax, which is not available except in 2012 |
| 3407 |
mode, it is not possible to use the Type_Invariant aspect in earlier versions |
| 3408 |
of Ada. However the Invariant pragma may be used in any version of Ada. Also |
| 3409 |
note that the aspect Invariant is a synonym in GNAT for the aspect |
| 3410 |
Type_Invariant, but there is no pragma Type_Invariant. |
| 3411 |
|
| 3412 |
The pragma must appear within the visible part of the package specification, |
| 3413 |
after the type to which its Entity argument appears. As with the Invariant |
| 3414 |
aspect, the Check expression is not analyzed until the end of the visible |
| 3415 |
part of the package, so it may contain forward references. The Message |
| 3416 |
argument, if present, provides the exception message used if the invariant |
| 3417 |
is violated. If no Message parameter is provided, a default message that |
| 3418 |
identifies the line on which the pragma appears is used. |
| 3419 |
|
| 3420 |
It is permissible to have multiple Invariants for the same type entity, in |
| 3421 |
which case they are and'ed together. It is permissible to use this pragma |
| 3422 |
in Ada 2012 mode, but you cannot have both an invariant aspect and an |
| 3423 |
invariant pragma for the same entity. |
| 3424 |
|
| 3425 |
For further details on the use of this pragma, see the Ada 2012 documentation |
| 3426 |
of the Type_Invariant aspect. |
| 3427 |
|
| 3428 |
Pragma Keep_Names |
| 3429 |
================= |
| 3430 |
|
| 3431 |
Syntax: |
| 3432 |
|
| 3433 |
|
| 3434 |
:: |
| 3435 |
|
| 3436 |
pragma Keep_Names ([On =>] enumeration_first_subtype_LOCAL_NAME); |
| 3437 |
|
| 3438 |
|
| 3439 |
The ``LOCAL_NAME`` argument |
| 3440 |
must refer to an enumeration first subtype |
| 3441 |
in the current declarative part. The effect is to retain the enumeration |
| 3442 |
literal names for use by ``Image`` and ``Value`` even if a global |
| 3443 |
``Discard_Names`` pragma applies. This is useful when you want to |
| 3444 |
generally suppress enumeration literal names and for example you therefore |
| 3445 |
use a ``Discard_Names`` pragma in the :file:`gnat.adc` file, but you |
| 3446 |
want to retain the names for specific enumeration types. |
| 3447 |
|
| 3448 |
Pragma License |
| 3449 |
============== |
| 3450 |
.. index:: License checking |
| 3451 |
|
| 3452 |
Syntax: |
| 3453 |
|
| 3454 |
|
| 3455 |
.. code-block:: ada |
| 3456 |
|
| 3457 |
pragma License (Unrestricted | GPL | Modified_GPL | Restricted); |
| 3458 |
|
| 3459 |
|
| 3460 |
This pragma is provided to allow automated checking for appropriate license |
| 3461 |
conditions with respect to the standard and modified GPL. A pragma |
| 3462 |
``License``, which is a configuration pragma that typically appears at |
| 3463 |
the start of a source file or in a separate :file:`gnat.adc` file, specifies |
| 3464 |
the licensing conditions of a unit as follows: |
| 3465 |
|
| 3466 |
* Unrestricted |
| 3467 |
This is used for a unit that can be freely used with no license restrictions. |
| 3468 |
Examples of such units are public domain units, and units from the Ada |
| 3469 |
Reference Manual. |
| 3470 |
|
| 3471 |
* GPL |
| 3472 |
This is used for a unit that is licensed under the unmodified GPL, and which |
| 3473 |
therefore cannot be ``with``\ ed by a restricted unit. |
| 3474 |
|
| 3475 |
* Modified_GPL |
| 3476 |
This is used for a unit licensed under the GNAT modified GPL that includes |
| 3477 |
a special exception paragraph that specifically permits the inclusion of |
| 3478 |
the unit in programs without requiring the entire program to be released |
| 3479 |
under the GPL. |
| 3480 |
|
| 3481 |
* Restricted |
| 3482 |
This is used for a unit that is restricted in that it is not permitted to |
| 3483 |
depend on units that are licensed under the GPL. Typical examples are |
| 3484 |
proprietary code that is to be released under more restrictive license |
| 3485 |
conditions. Note that restricted units are permitted to ``with`` units |
| 3486 |
which are licensed under the modified GPL (this is the whole point of the |
| 3487 |
modified GPL). |
| 3488 |
|
| 3489 |
|
| 3490 |
Normally a unit with no ``License`` pragma is considered to have an |
| 3491 |
unknown license, and no checking is done. However, standard GNAT headers |
| 3492 |
are recognized, and license information is derived from them as follows. |
| 3493 |
|
| 3494 |
A GNAT license header starts with a line containing 78 hyphens. The following |
| 3495 |
comment text is searched for the appearance of any of the following strings. |
| 3496 |
|
| 3497 |
If the string 'GNU General Public License' is found, then the unit is assumed |
| 3498 |
to have GPL license, unless the string 'As a special exception' follows, in |
| 3499 |
which case the license is assumed to be modified GPL. |
| 3500 |
|
| 3501 |
If one of the strings |
| 3502 |
'This specification is adapted from the Ada Semantic Interface' or |
| 3503 |
'This specification is derived from the Ada Reference Manual' is found |
| 3504 |
then the unit is assumed to be unrestricted. |
| 3505 |
|
| 3506 |
These default actions means that a program with a restricted license pragma |
| 3507 |
will automatically get warnings if a GPL unit is inappropriately |
| 3508 |
``with``\ ed. For example, the program: |
| 3509 |
|
| 3510 |
.. code-block:: ada |
| 3511 |
|
| 3512 |
with Sem_Ch3; |
| 3513 |
with GNAT.Sockets; |
| 3514 |
procedure Secret_Stuff is |
| 3515 |
... |
| 3516 |
end Secret_Stuff |
| 3517 |
|
| 3518 |
|
| 3519 |
if compiled with pragma ``License`` (``Restricted``) in a |
| 3520 |
:file:`gnat.adc` file will generate the warning:: |
| 3521 |
|
| 3522 |
1. with Sem_Ch3; |
| 3523 |
| |
| 3524 |
>>> license of withed unit "Sem_Ch3" is incompatible |
| 3525 |
|
| 3526 |
2. with GNAT.Sockets; |
| 3527 |
3. procedure Secret_Stuff is |
| 3528 |
|
| 3529 |
|
| 3530 |
Here we get a warning on ``Sem_Ch3`` since it is part of the GNAT |
| 3531 |
compiler and is licensed under the |
| 3532 |
GPL, but no warning for ``GNAT.Sockets`` which is part of the GNAT |
| 3533 |
run time, and is therefore licensed under the modified GPL. |
| 3534 |
|
| 3535 |
Pragma Link_With |
| 3536 |
================ |
| 3537 |
|
| 3538 |
Syntax: |
| 3539 |
|
| 3540 |
|
| 3541 |
:: |
| 3542 |
|
| 3543 |
pragma Link_With (static_string_EXPRESSION {,static_string_EXPRESSION}); |
| 3544 |
|
| 3545 |
|
| 3546 |
This pragma is provided for compatibility with certain Ada 83 compilers. |
| 3547 |
It has exactly the same effect as pragma ``Linker_Options`` except |
| 3548 |
that spaces occurring within one of the string expressions are treated |
| 3549 |
as separators. For example, in the following case: |
| 3550 |
|
| 3551 |
.. code-block:: ada |
| 3552 |
|
| 3553 |
pragma Link_With ("-labc -ldef"); |
| 3554 |
|
| 3555 |
|
| 3556 |
results in passing the strings ``-labc`` and ``-ldef`` as two |
| 3557 |
separate arguments to the linker. In addition pragma Link_With allows |
| 3558 |
multiple arguments, with the same effect as successive pragmas. |
| 3559 |
|
| 3560 |
Pragma Linker_Alias |
| 3561 |
=================== |
| 3562 |
|
| 3563 |
Syntax: |
| 3564 |
|
| 3565 |
|
| 3566 |
:: |
| 3567 |
|
| 3568 |
pragma Linker_Alias ( |
| 3569 |
[Entity =>] LOCAL_NAME, |
| 3570 |
[Target =>] static_string_EXPRESSION); |
| 3571 |
|
| 3572 |
|
| 3573 |
``LOCAL_NAME`` must refer to an object that is declared at the library |
| 3574 |
level. This pragma establishes the given entity as a linker alias for the |
| 3575 |
given target. It is equivalent to ``__attribute__((alias))`` in GNU C |
| 3576 |
and causes ``LOCAL_NAME`` to be emitted as an alias for the symbol |
| 3577 |
``static_string_EXPRESSION`` in the object file, that is to say no space |
| 3578 |
is reserved for ``LOCAL_NAME`` by the assembler and it will be resolved |
| 3579 |
to the same address as ``static_string_EXPRESSION`` by the linker. |
| 3580 |
|
| 3581 |
The actual linker name for the target must be used (e.g., the fully |
| 3582 |
encoded name with qualification in Ada, or the mangled name in C++), |
| 3583 |
or it must be declared using the C convention with ``pragma Import`` |
| 3584 |
or ``pragma Export``. |
| 3585 |
|
| 3586 |
Not all target machines support this pragma. On some of them it is accepted |
| 3587 |
only if ``pragma Weak_External`` has been applied to ``LOCAL_NAME``. |
| 3588 |
|
| 3589 |
|
| 3590 |
.. code-block:: ada |
| 3591 |
|
| 3592 |
-- Example of the use of pragma Linker_Alias |
| 3593 |
|
| 3594 |
package p is |
| 3595 |
i : Integer := 1; |
| 3596 |
pragma Export (C, i); |
| 3597 |
|
| 3598 |
new_name_for_i : Integer; |
| 3599 |
pragma Linker_Alias (new_name_for_i, "i"); |
| 3600 |
end p; |
| 3601 |
|
| 3602 |
|
| 3603 |
Pragma Linker_Constructor |
| 3604 |
========================= |
| 3605 |
|
| 3606 |
Syntax: |
| 3607 |
|
| 3608 |
|
| 3609 |
.. code-block:: ada |
| 3610 |
|
| 3611 |
pragma Linker_Constructor (procedure_LOCAL_NAME); |
| 3612 |
|
| 3613 |
|
| 3614 |
``procedure_LOCAL_NAME`` must refer to a parameterless procedure that |
| 3615 |
is declared at the library level. A procedure to which this pragma is |
| 3616 |
applied will be treated as an initialization routine by the linker. |
| 3617 |
It is equivalent to ``__attribute__((constructor))`` in GNU C and |
| 3618 |
causes ``procedure_LOCAL_NAME`` to be invoked before the entry point |
| 3619 |
of the executable is called (or immediately after the shared library is |
| 3620 |
loaded if the procedure is linked in a shared library), in particular |
| 3621 |
before the Ada run-time environment is set up. |
| 3622 |
|
| 3623 |
Because of these specific contexts, the set of operations such a procedure |
| 3624 |
can perform is very limited and the type of objects it can manipulate is |
| 3625 |
essentially restricted to the elementary types. In particular, it must only |
| 3626 |
contain code to which pragma Restrictions (No_Elaboration_Code) applies. |
| 3627 |
|
| 3628 |
This pragma is used by GNAT to implement auto-initialization of shared Stand |
| 3629 |
Alone Libraries, which provides a related capability without the restrictions |
| 3630 |
listed above. Where possible, the use of Stand Alone Libraries is preferable |
| 3631 |
to the use of this pragma. |
| 3632 |
|
| 3633 |
Pragma Linker_Destructor |
| 3634 |
======================== |
| 3635 |
|
| 3636 |
Syntax: |
| 3637 |
|
| 3638 |
|
| 3639 |
.. code-block:: ada |
| 3640 |
|
| 3641 |
pragma Linker_Destructor (procedure_LOCAL_NAME); |
| 3642 |
|
| 3643 |
|
| 3644 |
``procedure_LOCAL_NAME`` must refer to a parameterless procedure that |
| 3645 |
is declared at the library level. A procedure to which this pragma is |
| 3646 |
applied will be treated as a finalization routine by the linker. |
| 3647 |
It is equivalent to ``__attribute__((destructor))`` in GNU C and |
| 3648 |
causes ``procedure_LOCAL_NAME`` to be invoked after the entry point |
| 3649 |
of the executable has exited (or immediately before the shared library |
| 3650 |
is unloaded if the procedure is linked in a shared library), in particular |
| 3651 |
after the Ada run-time environment is shut down. |
| 3652 |
|
| 3653 |
See ``pragma Linker_Constructor`` for the set of restrictions that apply |
| 3654 |
because of these specific contexts. |
| 3655 |
|
| 3656 |
.. _Pragma-Linker_Section: |
| 3657 |
|
| 3658 |
Pragma Linker_Section |
| 3659 |
===================== |
| 3660 |
|
| 3661 |
Syntax: |
| 3662 |
|
| 3663 |
|
| 3664 |
:: |
| 3665 |
|
| 3666 |
pragma Linker_Section ( |
| 3667 |
[Entity =>] LOCAL_NAME, |
| 3668 |
[Section =>] static_string_EXPRESSION); |
| 3669 |
|
| 3670 |
|
| 3671 |
``LOCAL_NAME`` must refer to an object, type, or subprogram that is |
| 3672 |
declared at the library level. This pragma specifies the name of the |
| 3673 |
linker section for the given entity. It is equivalent to |
| 3674 |
``__attribute__((section))`` in GNU C and causes ``LOCAL_NAME`` to |
| 3675 |
be placed in the ``static_string_EXPRESSION`` section of the |
| 3676 |
executable (assuming the linker doesn't rename the section). |
| 3677 |
GNAT also provides an implementation defined aspect of the same name. |
| 3678 |
|
| 3679 |
In the case of specifying this aspect for a type, the effect is to |
| 3680 |
specify the corresponding section for all library-level objects of |
| 3681 |
the type that do not have an explicit linker section set. Note that |
| 3682 |
this only applies to whole objects, not to components of composite objects. |
| 3683 |
|
| 3684 |
In the case of a subprogram, the linker section applies to all previously |
| 3685 |
declared matching overloaded subprograms in the current declarative part |
| 3686 |
which do not already have a linker section assigned. The linker section |
| 3687 |
aspect is useful in this case for specifying different linker sections |
| 3688 |
for different elements of such an overloaded set. |
| 3689 |
|
| 3690 |
Note that an empty string specifies that no linker section is specified. |
| 3691 |
This is not quite the same as omitting the pragma or aspect, since it |
| 3692 |
can be used to specify that one element of an overloaded set of subprograms |
| 3693 |
has the default linker section, or that one object of a type for which a |
| 3694 |
linker section is specified should has the default linker section. |
| 3695 |
|
| 3696 |
The compiler normally places library-level entities in standard sections |
| 3697 |
depending on the class: procedures and functions generally go in the |
| 3698 |
``.text`` section, initialized variables in the ``.data`` section |
| 3699 |
and uninitialized variables in the ``.bss`` section. |
| 3700 |
|
| 3701 |
Other, special sections may exist on given target machines to map special |
| 3702 |
hardware, for example I/O ports or flash memory. This pragma is a means to |
| 3703 |
defer the final layout of the executable to the linker, thus fully working |
| 3704 |
at the symbolic level with the compiler. |
| 3705 |
|
| 3706 |
Some file formats do not support arbitrary sections so not all target |
| 3707 |
machines support this pragma. The use of this pragma may cause a program |
| 3708 |
execution to be erroneous if it is used to place an entity into an |
| 3709 |
inappropriate section (e.g., a modified variable into the ``.text`` |
| 3710 |
section). See also ``pragma Persistent_BSS``. |
| 3711 |
|
| 3712 |
|
| 3713 |
.. code-block:: ada |
| 3714 |
|
| 3715 |
-- Example of the use of pragma Linker_Section |
| 3716 |
|
| 3717 |
package IO_Card is |
| 3718 |
Port_A : Integer; |
| 3719 |
pragma Volatile (Port_A); |
| 3720 |
pragma Linker_Section (Port_A, ".bss.port_a"); |
| 3721 |
|
| 3722 |
Port_B : Integer; |
| 3723 |
pragma Volatile (Port_B); |
| 3724 |
pragma Linker_Section (Port_B, ".bss.port_b"); |
| 3725 |
|
| 3726 |
type Port_Type is new Integer with Linker_Section => ".bss"; |
| 3727 |
PA : Port_Type with Linker_Section => ".bss.PA"; |
| 3728 |
PB : Port_Type; -- ends up in linker section ".bss" |
| 3729 |
|
| 3730 |
procedure Q with Linker_Section => "Qsection"; |
| 3731 |
end IO_Card; |
| 3732 |
|
| 3733 |
.. _Pragma-Lock_Free: |
| 3734 |
|
| 3735 |
Pragma Lock_Free |
| 3736 |
================ |
| 3737 |
|
| 3738 |
Syntax: |
| 3739 |
This pragma may be specified for protected types or objects. It specifies that |
| 3740 |
the implementation of protected operations must be implemented without locks. |
| 3741 |
Compilation fails if the compiler cannot generate lock-free code for the |
| 3742 |
operations. |
| 3743 |
|
| 3744 |
The current conditions required to support this pragma are: |
| 3745 |
|
| 3746 |
* Protected type declarations may not contain entries |
| 3747 |
* Protected subprogram declarations may not have nonelementary parameters |
| 3748 |
|
| 3749 |
In addition, each protected subprogram body must satisfy: |
| 3750 |
|
| 3751 |
* May reference only one protected component |
| 3752 |
* May not reference nonconstant entities outside the protected subprogram |
| 3753 |
scope |
| 3754 |
* May not contain address representation items, allocators, or quantified |
| 3755 |
expressions |
| 3756 |
* May not contain delay, goto, loop, or procedure-call statements |
| 3757 |
* May not contain exported and imported entities |
| 3758 |
* May not dereferenced access values |
| 3759 |
* Function calls and attribute references must be static |
| 3760 |
|
| 3761 |
If the Lock_Free aspect is specified to be True for a protected unit |
| 3762 |
and the Ceiling_Locking locking policy is in effect, then the run-time |
| 3763 |
actions associated with the Ceiling_Locking locking policy (described in |
| 3764 |
Ada RM D.3) are not performed when a protected operation of the protected |
| 3765 |
unit is executed. |
| 3766 |
|
| 3767 |
Pragma Loop_Invariant |
| 3768 |
===================== |
| 3769 |
|
| 3770 |
Syntax: |
| 3771 |
|
| 3772 |
|
| 3773 |
.. code-block:: ada |
| 3774 |
|
| 3775 |
pragma Loop_Invariant ( boolean_EXPRESSION ); |
| 3776 |
|
| 3777 |
|
| 3778 |
The effect of this pragma is similar to that of pragma ``Assert``, |
| 3779 |
except that in an ``Assertion_Policy`` pragma, the identifier |
| 3780 |
``Loop_Invariant`` is used to control whether it is ignored or checked |
| 3781 |
(or disabled). |
| 3782 |
|
| 3783 |
``Loop_Invariant`` can only appear as one of the items in the sequence |
| 3784 |
of statements of a loop body, or nested inside block statements that |
| 3785 |
appear in the sequence of statements of a loop body. |
| 3786 |
The intention is that it be used to |
| 3787 |
represent a "loop invariant" assertion, i.e. something that is true each |
| 3788 |
time through the loop, and which can be used to show that the loop is |
| 3789 |
achieving its purpose. |
| 3790 |
|
| 3791 |
Multiple ``Loop_Invariant`` and ``Loop_Variant`` pragmas that |
| 3792 |
apply to the same loop should be grouped in the same sequence of |
| 3793 |
statements. |
| 3794 |
|
| 3795 |
To aid in writing such invariants, the special attribute ``Loop_Entry`` |
| 3796 |
may be used to refer to the value of an expression on entry to the loop. This |
| 3797 |
attribute can only be used within the expression of a ``Loop_Invariant`` |
| 3798 |
pragma. For full details, see documentation of attribute ``Loop_Entry``. |
| 3799 |
|
| 3800 |
Pragma Loop_Optimize |
| 3801 |
==================== |
| 3802 |
|
| 3803 |
Syntax: |
| 3804 |
|
| 3805 |
|
| 3806 |
:: |
| 3807 |
|
| 3808 |
pragma Loop_Optimize (OPTIMIZATION_HINT {, OPTIMIZATION_HINT}); |
| 3809 |
|
| 3810 |
OPTIMIZATION_HINT ::= Ivdep | No_Unroll | Unroll | No_Vector | Vector |
| 3811 |
|
| 3812 |
|
| 3813 |
This pragma must appear immediately within a loop statement. It allows the |
| 3814 |
programmer to specify optimization hints for the enclosing loop. The hints |
| 3815 |
are not mutually exclusive and can be freely mixed, but not all combinations |
| 3816 |
will yield a sensible outcome. |
| 3817 |
|
| 3818 |
There are five supported optimization hints for a loop: |
| 3819 |
|
| 3820 |
* Ivdep |
| 3821 |
|
| 3822 |
The programmer asserts that there are no loop-carried dependencies |
| 3823 |
which would prevent consecutive iterations of the loop from being |
| 3824 |
executed simultaneously. |
| 3825 |
|
| 3826 |
* No_Unroll |
| 3827 |
|
| 3828 |
The loop must not be unrolled. This is a strong hint: the compiler will not |
| 3829 |
unroll a loop marked with this hint. |
| 3830 |
|
| 3831 |
* Unroll |
| 3832 |
|
| 3833 |
The loop should be unrolled. This is a weak hint: the compiler will try to |
| 3834 |
apply unrolling to this loop preferably to other optimizations, notably |
| 3835 |
vectorization, but there is no guarantee that the loop will be unrolled. |
| 3836 |
|
| 3837 |
* No_Vector |
| 3838 |
|
| 3839 |
The loop must not be vectorized. This is a strong hint: the compiler will not |
| 3840 |
vectorize a loop marked with this hint. |
| 3841 |
|
| 3842 |
* Vector |
| 3843 |
|
| 3844 |
The loop should be vectorized. This is a weak hint: the compiler will try to |
| 3845 |
apply vectorization to this loop preferably to other optimizations, notably |
| 3846 |
unrolling, but there is no guarantee that the loop will be vectorized. |
| 3847 |
|
| 3848 |
|
| 3849 |
These hints do not remove the need to pass the appropriate switches to the |
| 3850 |
compiler in order to enable the relevant optimizations, that is to say |
| 3851 |
*-funroll-loops* for unrolling and *-ftree-vectorize* for |
| 3852 |
vectorization. |
| 3853 |
|
| 3854 |
Pragma Loop_Variant |
| 3855 |
=================== |
| 3856 |
|
| 3857 |
Syntax: |
| 3858 |
|
| 3859 |
|
| 3860 |
:: |
| 3861 |
|
| 3862 |
pragma Loop_Variant ( LOOP_VARIANT_ITEM {, LOOP_VARIANT_ITEM } ); |
| 3863 |
LOOP_VARIANT_ITEM ::= CHANGE_DIRECTION => discrete_EXPRESSION |
| 3864 |
CHANGE_DIRECTION ::= Increases | Decreases |
| 3865 |
|
| 3866 |
|
| 3867 |
``Loop_Variant`` can only appear as one of the items in the sequence |
| 3868 |
of statements of a loop body, or nested inside block statements that |
| 3869 |
appear in the sequence of statements of a loop body. |
| 3870 |
It allows the specification of quantities which must always |
| 3871 |
decrease or increase in successive iterations of the loop. In its simplest |
| 3872 |
form, just one expression is specified, whose value must increase or decrease |
| 3873 |
on each iteration of the loop. |
| 3874 |
|
| 3875 |
In a more complex form, multiple arguments can be given which are interpreted |
| 3876 |
in a nesting lexicographic manner. For example: |
| 3877 |
|
| 3878 |
.. code-block:: ada |
| 3879 |
|
| 3880 |
pragma Loop_Variant (Increases => X, Decreases => Y); |
| 3881 |
|
| 3882 |
|
| 3883 |
specifies that each time through the loop either X increases, or X stays |
| 3884 |
the same and Y decreases. A ``Loop_Variant`` pragma ensures that the |
| 3885 |
loop is making progress. It can be useful in helping to show informally |
| 3886 |
or prove formally that the loop always terminates. |
| 3887 |
|
| 3888 |
``Loop_Variant`` is an assertion whose effect can be controlled using |
| 3889 |
an ``Assertion_Policy`` with a check name of ``Loop_Variant``. The |
| 3890 |
policy can be ``Check`` to enable the loop variant check, ``Ignore`` |
| 3891 |
to ignore the check (in which case the pragma has no effect on the program), |
| 3892 |
or ``Disable`` in which case the pragma is not even checked for correct |
| 3893 |
syntax. |
| 3894 |
|
| 3895 |
Multiple ``Loop_Invariant`` and ``Loop_Variant`` pragmas that |
| 3896 |
apply to the same loop should be grouped in the same sequence of |
| 3897 |
statements. |
| 3898 |
|
| 3899 |
The ``Loop_Entry`` attribute may be used within the expressions of the |
| 3900 |
``Loop_Variant`` pragma to refer to values on entry to the loop. |
| 3901 |
|
| 3902 |
Pragma Machine_Attribute |
| 3903 |
======================== |
| 3904 |
|
| 3905 |
Syntax: |
| 3906 |
|
| 3907 |
|
| 3908 |
:: |
| 3909 |
|
| 3910 |
pragma Machine_Attribute ( |
| 3911 |
[Entity =>] LOCAL_NAME, |
| 3912 |
[Attribute_Name =>] static_string_EXPRESSION |
| 3913 |
[, [Info =>] static_EXPRESSION {, static_EXPRESSION}] ); |
| 3914 |
|
| 3915 |
|
| 3916 |
Machine-dependent attributes can be specified for types and/or |
| 3917 |
declarations. This pragma is semantically equivalent to |
| 3918 |
:samp:`__attribute__(({attribute_name}))` (if ``info`` is not |
| 3919 |
specified) or :samp:`__attribute__(({attribute_name(info})))` |
| 3920 |
or :samp:`__attribute__(({attribute_name(info,...})))` in GNU C, |
| 3921 |
where *attribute_name* is recognized by the compiler middle-end |
| 3922 |
or the ``TARGET_ATTRIBUTE_TABLE`` machine specific macro. Note |
| 3923 |
that a string literal for the optional parameter ``info`` or the |
| 3924 |
following ones is transformed by default into an identifier, |
| 3925 |
which may make this pragma unusable for some attributes. |
| 3926 |
For further information see :title:`GNU Compiler Collection (GCC) Internals`. |
| 3927 |
|
| 3928 |
Pragma Main |
| 3929 |
=========== |
| 3930 |
|
| 3931 |
Syntax:: |
| 3932 |
|
| 3933 |
pragma Main |
| 3934 |
(MAIN_OPTION [, MAIN_OPTION]); |
| 3935 |
|
| 3936 |
MAIN_OPTION ::= |
| 3937 |
[Stack_Size =>] static_integer_EXPRESSION |
| 3938 |
| [Task_Stack_Size_Default =>] static_integer_EXPRESSION |
| 3939 |
| [Time_Slicing_Enabled =>] static_boolean_EXPRESSION |
| 3940 |
|
| 3941 |
|
| 3942 |
This pragma is provided for compatibility with OpenVMS VAX Systems. It has |
| 3943 |
no effect in GNAT, other than being syntax checked. |
| 3944 |
|
| 3945 |
Pragma Main_Storage |
| 3946 |
=================== |
| 3947 |
|
| 3948 |
Syntax:: |
| 3949 |
|
| 3950 |
pragma Main_Storage |
| 3951 |
(MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]); |
| 3952 |
|
| 3953 |
MAIN_STORAGE_OPTION ::= |
| 3954 |
[WORKING_STORAGE =>] static_SIMPLE_EXPRESSION |
| 3955 |
| [TOP_GUARD =>] static_SIMPLE_EXPRESSION |
| 3956 |
|
| 3957 |
|
| 3958 |
This pragma is provided for compatibility with OpenVMS VAX Systems. It has |
| 3959 |
no effect in GNAT, other than being syntax checked. |
| 3960 |
|
| 3961 |
.. _Pragma-Max_Queue_Length: |
| 3962 |
|
| 3963 |
Pragma Max_Queue_Length |
| 3964 |
======================= |
| 3965 |
|
| 3966 |
Syntax:: |
| 3967 |
|
| 3968 |
pragma Max_Entry_Queue (static_integer_EXPRESSION); |
| 3969 |
|
| 3970 |
|
| 3971 |
This pragma is used to specify the maximum callers per entry queue for |
| 3972 |
individual protected entries and entry families. It accepts a single |
| 3973 |
integer (-1 or more) as a parameter and must appear after the declaration of an |
| 3974 |
entry. |
| 3975 |
|
| 3976 |
A value of -1 represents no additional restriction on queue length. |
| 3977 |
|
| 3978 |
Pragma No_Body |
| 3979 |
============== |
| 3980 |
|
| 3981 |
Syntax: |
| 3982 |
|
| 3983 |
|
| 3984 |
.. code-block:: ada |
| 3985 |
|
| 3986 |
pragma No_Body; |
| 3987 |
|
| 3988 |
|
| 3989 |
There are a number of cases in which a package spec does not require a body, |
| 3990 |
and in fact a body is not permitted. GNAT will not permit the spec to be |
| 3991 |
compiled if there is a body around. The pragma No_Body allows you to provide |
| 3992 |
a body file, even in a case where no body is allowed. The body file must |
| 3993 |
contain only comments and a single No_Body pragma. This is recognized by |
| 3994 |
the compiler as indicating that no body is logically present. |
| 3995 |
|
| 3996 |
This is particularly useful during maintenance when a package is modified in |
| 3997 |
such a way that a body needed before is no longer needed. The provision of a |
| 3998 |
dummy body with a No_Body pragma ensures that there is no interference from |
| 3999 |
earlier versions of the package body. |
| 4000 |
|
| 4001 |
.. _Pragma-No_Caching: |
| 4002 |
|
| 4003 |
Pragma No_Caching |
| 4004 |
================= |
| 4005 |
|
| 4006 |
Syntax: |
| 4007 |
|
| 4008 |
.. code-block:: ada |
| 4009 |
|
| 4010 |
pragma No_Caching [ (static_boolean_EXPRESSION) ]; |
| 4011 |
|
| 4012 |
For the semantics of this pragma, see the entry for aspect ``No_Caching`` in |
| 4013 |
the SPARK 2014 Reference Manual, section 7.1.2. |
| 4014 |
|
| 4015 |
Pragma No_Component_Reordering |
| 4016 |
============================== |
| 4017 |
|
| 4018 |
Syntax: |
| 4019 |
|
| 4020 |
|
| 4021 |
:: |
| 4022 |
|
| 4023 |
pragma No_Component_Reordering [([Entity =>] type_LOCAL_NAME)]; |
| 4024 |
|
| 4025 |
|
| 4026 |
``type_LOCAL_NAME`` must refer to a record type declaration in the current |
| 4027 |
declarative part. The effect is to preclude any reordering of components |
| 4028 |
for the layout of the record, i.e. the record is laid out by the compiler |
| 4029 |
in the order in which the components are declared textually. The form with |
| 4030 |
no argument is a configuration pragma which applies to all record types |
| 4031 |
declared in units to which the pragma applies and there is a requirement |
| 4032 |
that this pragma be used consistently within a partition. |
| 4033 |
|
| 4034 |
.. _Pragma-No_Elaboration_Code_All: |
| 4035 |
|
| 4036 |
Pragma No_Elaboration_Code_All |
| 4037 |
============================== |
| 4038 |
|
| 4039 |
Syntax: |
| 4040 |
|
| 4041 |
|
| 4042 |
:: |
| 4043 |
|
| 4044 |
pragma No_Elaboration_Code_All [(program_unit_NAME)]; |
| 4045 |
|
| 4046 |
|
| 4047 |
This is a program unit pragma (there is also an equivalent aspect of the |
| 4048 |
same name) that establishes the restriction ``No_Elaboration_Code`` for |
| 4049 |
the current unit and any extended main source units (body and subunits). |
| 4050 |
It also has the effect of enforcing a transitive application of this |
| 4051 |
aspect, so that if any unit is implicitly or explicitly with'ed by the |
| 4052 |
current unit, it must also have the No_Elaboration_Code_All aspect set. |
| 4053 |
It may be applied to package or subprogram specs or their generic versions. |
| 4054 |
|
| 4055 |
Pragma No_Heap_Finalization |
| 4056 |
=========================== |
| 4057 |
|
| 4058 |
Syntax: |
| 4059 |
|
| 4060 |
|
| 4061 |
:: |
| 4062 |
|
| 4063 |
pragma No_Heap_Finalization [ (first_subtype_LOCAL_NAME) ]; |
| 4064 |
|
| 4065 |
|
| 4066 |
Pragma ``No_Heap_Finalization`` may be used as a configuration pragma or as a |
| 4067 |
type-specific pragma. |
| 4068 |
|
| 4069 |
In its configuration form, the pragma must appear within a configuration file |
| 4070 |
such as gnat.adc, without an argument. The pragma suppresses the call to |
| 4071 |
``Finalize`` for heap-allocated objects created through library-level named |
| 4072 |
access-to-object types in cases where the designated type requires finalization |
| 4073 |
actions. |
| 4074 |
|
| 4075 |
In its type-specific form, the argument of the pragma must denote a |
| 4076 |
library-level named access-to-object type. The pragma suppresses the call to |
| 4077 |
``Finalize`` for heap-allocated objects created through the specific access type |
| 4078 |
in cases where the designated type requires finalization actions. |
| 4079 |
|
| 4080 |
It is still possible to finalize such heap-allocated objects by explicitly |
| 4081 |
deallocating them. |
| 4082 |
|
| 4083 |
A library-level named access-to-object type declared within a generic unit will |
| 4084 |
lose its ``No_Heap_Finalization`` pragma when the corresponding instance does not |
| 4085 |
appear at the library level. |
| 4086 |
|
| 4087 |
.. _Pragma-No_Inline: |
| 4088 |
|
| 4089 |
Pragma No_Inline |
| 4090 |
================ |
| 4091 |
|
| 4092 |
Syntax: |
| 4093 |
|
| 4094 |
|
| 4095 |
:: |
| 4096 |
|
| 4097 |
pragma No_Inline (NAME {, NAME}); |
| 4098 |
|
| 4099 |
|
| 4100 |
This pragma suppresses inlining for the callable entity or the instances of |
| 4101 |
the generic subprogram designated by ``NAME``, including inlining that |
| 4102 |
results from the use of pragma ``Inline``. This pragma is always active, |
| 4103 |
in particular it is not subject to the use of option *-gnatn* or |
| 4104 |
*-gnatN*. It is illegal to specify both pragma ``No_Inline`` and |
| 4105 |
pragma ``Inline_Always`` for the same ``NAME``. |
| 4106 |
|
| 4107 |
Pragma No_Return |
| 4108 |
================ |
| 4109 |
|
| 4110 |
Syntax: |
| 4111 |
|
| 4112 |
|
| 4113 |
:: |
| 4114 |
|
| 4115 |
pragma No_Return (procedure_LOCAL_NAME {, procedure_LOCAL_NAME}); |
| 4116 |
|
| 4117 |
|
| 4118 |
Each ``procedure_LOCAL_NAME`` argument must refer to one or more procedure |
| 4119 |
declarations in the current declarative part. A procedure to which this |
| 4120 |
pragma is applied may not contain any explicit ``return`` statements. |
| 4121 |
In addition, if the procedure contains any implicit returns from falling |
| 4122 |
off the end of a statement sequence, then execution of that implicit |
| 4123 |
return will cause Program_Error to be raised. |
| 4124 |
|
| 4125 |
One use of this pragma is to identify procedures whose only purpose is to raise |
| 4126 |
an exception. Another use of this pragma is to suppress incorrect warnings |
| 4127 |
about missing returns in functions, where the last statement of a function |
| 4128 |
statement sequence is a call to such a procedure. |
| 4129 |
|
| 4130 |
Note that in Ada 2005 mode, this pragma is part of the language. It is |
| 4131 |
available in all earlier versions of Ada as an implementation-defined |
| 4132 |
pragma. |
| 4133 |
|
| 4134 |
Pragma No_Strict_Aliasing |
| 4135 |
========================= |
| 4136 |
|
| 4137 |
Syntax: |
| 4138 |
|
| 4139 |
|
| 4140 |
:: |
| 4141 |
|
| 4142 |
pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)]; |
| 4143 |
|
| 4144 |
|
| 4145 |
``type_LOCAL_NAME`` must refer to an access type |
| 4146 |
declaration in the current declarative part. The effect is to inhibit |
| 4147 |
strict aliasing optimization for the given type. The form with no |
| 4148 |
arguments is a configuration pragma which applies to all access types |
| 4149 |
declared in units to which the pragma applies. For a detailed |
| 4150 |
description of the strict aliasing optimization, and the situations |
| 4151 |
in which it must be suppressed, see the section on Optimization and Strict Aliasing |
| 4152 |
in the :title:`GNAT User's Guide`. |
| 4153 |
|
| 4154 |
This pragma currently has no effects on access to unconstrained array types. |
| 4155 |
|
| 4156 |
.. _Pragma-No_Tagged_Streams: |
| 4157 |
|
| 4158 |
Pragma No_Tagged_Streams |
| 4159 |
======================== |
| 4160 |
|
| 4161 |
Syntax: |
| 4162 |
|
| 4163 |
|
| 4164 |
:: |
| 4165 |
|
| 4166 |
pragma No_Tagged_Streams [([Entity =>] tagged_type_LOCAL_NAME)]; |
| 4167 |
|
| 4168 |
|
| 4169 |
Normally when a tagged type is introduced using a full type declaration, |
| 4170 |
part of the processing includes generating stream access routines to be |
| 4171 |
used by stream attributes referencing the type (or one of its subtypes |
| 4172 |
or derived types). This can involve the generation of significant amounts |
| 4173 |
of code which is wasted space if stream routines are not needed for the |
| 4174 |
type in question. |
| 4175 |
|
| 4176 |
The ``No_Tagged_Streams`` pragma causes the generation of these stream |
| 4177 |
routines to be skipped, and any attempt to use stream operations on |
| 4178 |
types subject to this pragma will be statically rejected as illegal. |
| 4179 |
|
| 4180 |
There are two forms of the pragma. The form with no arguments must appear |
| 4181 |
in a declarative sequence or in the declarations of a package spec. This |
| 4182 |
pragma affects all subsequent root tagged types declared in the declaration |
| 4183 |
sequence, and specifies that no stream routines be generated. The form with |
| 4184 |
an argument (for which there is also a corresponding aspect) specifies a |
| 4185 |
single root tagged type for which stream routines are not to be generated. |
| 4186 |
|
| 4187 |
Once the pragma has been given for a particular root tagged type, all subtypes |
| 4188 |
and derived types of this type inherit the pragma automatically, so the effect |
| 4189 |
applies to a complete hierarchy (this is necessary to deal with the class-wide |
| 4190 |
dispatching versions of the stream routines). |
| 4191 |
|
| 4192 |
When pragmas ``Discard_Names`` and ``No_Tagged_Streams`` are simultaneously |
| 4193 |
applied to a tagged type its Expanded_Name and External_Tag are initialized |
| 4194 |
with empty strings. This is useful to avoid exposing entity names at binary |
| 4195 |
level but has a negative impact on the debuggability of tagged types. |
| 4196 |
|
| 4197 |
Pragma Normalize_Scalars |
| 4198 |
======================== |
| 4199 |
|
| 4200 |
Syntax: |
| 4201 |
|
| 4202 |
|
| 4203 |
.. code-block:: ada |
| 4204 |
|
| 4205 |
pragma Normalize_Scalars; |
| 4206 |
|
| 4207 |
|
| 4208 |
This is a language defined pragma which is fully implemented in GNAT. The |
| 4209 |
effect is to cause all scalar objects that are not otherwise initialized |
| 4210 |
to be initialized. The initial values are implementation dependent and |
| 4211 |
are as follows: |
| 4212 |
|
| 4213 |
|
| 4214 |
|
| 4215 |
*Standard.Character* |
| 4216 |
Objects whose root type is Standard.Character are initialized to |
| 4217 |
Character'Last unless the subtype range excludes NUL (in which case |
| 4218 |
NUL is used). This choice will always generate an invalid value if |
| 4219 |
one exists. |
| 4220 |
|
| 4221 |
|
| 4222 |
*Standard.Wide_Character* |
| 4223 |
Objects whose root type is Standard.Wide_Character are initialized to |
| 4224 |
Wide_Character'Last unless the subtype range excludes NUL (in which case |
| 4225 |
NUL is used). This choice will always generate an invalid value if |
| 4226 |
one exists. |
| 4227 |
|
| 4228 |
|
| 4229 |
*Standard.Wide_Wide_Character* |
| 4230 |
Objects whose root type is Standard.Wide_Wide_Character are initialized to |
| 4231 |
the invalid value 16#FFFF_FFFF# unless the subtype range excludes NUL (in |
| 4232 |
which case NUL is used). This choice will always generate an invalid value if |
| 4233 |
one exists. |
| 4234 |
|
| 4235 |
|
| 4236 |
*Integer types* |
| 4237 |
Objects of an integer type are treated differently depending on whether |
| 4238 |
negative values are present in the subtype. If no negative values are |
| 4239 |
present, then all one bits is used as the initial value except in the |
| 4240 |
special case where zero is excluded from the subtype, in which case |
| 4241 |
all zero bits are used. This choice will always generate an invalid |
| 4242 |
value if one exists. |
| 4243 |
|
| 4244 |
For subtypes with negative values present, the largest negative number |
| 4245 |
is used, except in the unusual case where this largest negative number |
| 4246 |
is in the subtype, and the largest positive number is not, in which case |
| 4247 |
the largest positive value is used. This choice will always generate |
| 4248 |
an invalid value if one exists. |
| 4249 |
|
| 4250 |
|
| 4251 |
*Floating-Point Types* |
| 4252 |
Objects of all floating-point types are initialized to all 1-bits. For |
| 4253 |
standard IEEE format, this corresponds to a NaN (not a number) which is |
| 4254 |
indeed an invalid value. |
| 4255 |
|
| 4256 |
|
| 4257 |
*Fixed-Point Types* |
| 4258 |
Objects of all fixed-point types are treated as described above for integers, |
| 4259 |
with the rules applying to the underlying integer value used to represent |
| 4260 |
the fixed-point value. |
| 4261 |
|
| 4262 |
|
| 4263 |
*Modular types* |
| 4264 |
Objects of a modular type are initialized to all one bits, except in |
| 4265 |
the special case where zero is excluded from the subtype, in which |
| 4266 |
case all zero bits are used. This choice will always generate an |
| 4267 |
invalid value if one exists. |
| 4268 |
|
| 4269 |
|
| 4270 |
*Enumeration types* |
| 4271 |
Objects of an enumeration type are initialized to all one-bits, i.e., to |
| 4272 |
the value ``2 ** typ'Size - 1`` unless the subtype excludes the literal |
| 4273 |
whose Pos value is zero, in which case a code of zero is used. This choice |
| 4274 |
will always generate an invalid value if one exists. |
| 4275 |
|
| 4276 |
.. _Pragma_Obsolescent: |
| 4277 |
|
| 4278 |
Pragma Obsolescent |
| 4279 |
================== |
| 4280 |
|
| 4281 |
Syntax: |
| 4282 |
|
| 4283 |
|
| 4284 |
:: |
| 4285 |
|
| 4286 |
pragma Obsolescent; |
| 4287 |
|
| 4288 |
pragma Obsolescent ( |
| 4289 |
[Message =>] static_string_EXPRESSION |
| 4290 |
[,[Version =>] Ada_05]); |
| 4291 |
|
| 4292 |
pragma Obsolescent ( |
| 4293 |
[Entity =>] NAME |
| 4294 |
[,[Message =>] static_string_EXPRESSION |
| 4295 |
[,[Version =>] Ada_05]]); |
| 4296 |
|
| 4297 |
|
| 4298 |
This pragma can occur immediately following a declaration of an entity, |
| 4299 |
including the case of a record component. If no Entity argument is present, |
| 4300 |
then this declaration is the one to which the pragma applies. If an Entity |
| 4301 |
parameter is present, it must either match the name of the entity in this |
| 4302 |
declaration, or alternatively, the pragma can immediately follow an enumeration |
| 4303 |
type declaration, where the Entity argument names one of the enumeration |
| 4304 |
literals. |
| 4305 |
|
| 4306 |
This pragma is used to indicate that the named entity |
| 4307 |
is considered obsolescent and should not be used. Typically this is |
| 4308 |
used when an API must be modified by eventually removing or modifying |
| 4309 |
existing subprograms or other entities. The pragma can be used at an |
| 4310 |
intermediate stage when the entity is still present, but will be |
| 4311 |
removed later. |
| 4312 |
|
| 4313 |
The effect of this pragma is to output a warning message on a reference to |
| 4314 |
an entity thus marked that the subprogram is obsolescent if the appropriate |
| 4315 |
warning option in the compiler is activated. If the ``Message`` parameter is |
| 4316 |
present, then a second warning message is given containing this text. In |
| 4317 |
addition, a reference to the entity is considered to be a violation of pragma |
| 4318 |
``Restrictions (No_Obsolescent_Features)``. |
| 4319 |
|
| 4320 |
This pragma can also be used as a program unit pragma for a package, |
| 4321 |
in which case the entity name is the name of the package, and the |
| 4322 |
pragma indicates that the entire package is considered |
| 4323 |
obsolescent. In this case a client ``with``\ ing such a package |
| 4324 |
violates the restriction, and the ``with`` clause is |
| 4325 |
flagged with warnings if the warning option is set. |
| 4326 |
|
| 4327 |
If the ``Version`` parameter is present (which must be exactly |
| 4328 |
the identifier ``Ada_05``, no other argument is allowed), then the |
| 4329 |
indication of obsolescence applies only when compiling in Ada 2005 |
| 4330 |
mode. This is primarily intended for dealing with the situations |
| 4331 |
in the predefined library where subprograms or packages |
| 4332 |
have become defined as obsolescent in Ada 2005 |
| 4333 |
(e.g., in ``Ada.Characters.Handling``), but may be used anywhere. |
| 4334 |
|
| 4335 |
The following examples show typical uses of this pragma: |
| 4336 |
|
| 4337 |
|
| 4338 |
.. code-block:: ada |
| 4339 |
|
| 4340 |
package p is |
| 4341 |
pragma Obsolescent (p, Message => "use pp instead of p"); |
| 4342 |
end p; |
| 4343 |
|
| 4344 |
package q is |
| 4345 |
procedure q2; |
| 4346 |
pragma Obsolescent ("use q2new instead"); |
| 4347 |
|
| 4348 |
type R is new integer; |
| 4349 |
pragma Obsolescent |
| 4350 |
(Entity => R, |
| 4351 |
Message => "use RR in Ada 2005", |
| 4352 |
Version => Ada_05); |
| 4353 |
|
| 4354 |
type M is record |
| 4355 |
F1 : Integer; |
| 4356 |
F2 : Integer; |
| 4357 |
pragma Obsolescent; |
| 4358 |
F3 : Integer; |
| 4359 |
end record; |
| 4360 |
|
| 4361 |
type E is (a, bc, 'd', quack); |
| 4362 |
pragma Obsolescent (Entity => bc) |
| 4363 |
pragma Obsolescent (Entity => 'd') |
| 4364 |
|
| 4365 |
function "+" |
| 4366 |
(a, b : character) return character; |
| 4367 |
pragma Obsolescent (Entity => "+"); |
| 4368 |
end; |
| 4369 |
|
| 4370 |
|
| 4371 |
Note that, as for all pragmas, if you use a pragma argument identifier, |
| 4372 |
then all subsequent parameters must also use a pragma argument identifier. |
| 4373 |
So if you specify ``Entity =>`` for the ``Entity`` argument, and a ``Message`` |
| 4374 |
argument is present, it must be preceded by ``Message =>``. |
| 4375 |
|
| 4376 |
Pragma Optimize_Alignment |
| 4377 |
========================= |
| 4378 |
.. index:: Alignment, default settings |
| 4379 |
|
| 4380 |
Syntax: |
| 4381 |
|
| 4382 |
|
| 4383 |
.. code-block:: ada |
| 4384 |
|
| 4385 |
pragma Optimize_Alignment (TIME | SPACE | OFF); |
| 4386 |
|
| 4387 |
|
| 4388 |
This is a configuration pragma which affects the choice of default alignments |
| 4389 |
for types and objects where no alignment is explicitly specified. There is a |
| 4390 |
time/space trade-off in the selection of these values. Large alignments result |
| 4391 |
in more efficient code, at the expense of larger data space, since sizes have |
| 4392 |
to be increased to match these alignments. Smaller alignments save space, but |
| 4393 |
the access code is slower. The normal choice of default alignments for types |
| 4394 |
and individual alignment promotions for objects (which is what you get if you |
| 4395 |
do not use this pragma, or if you use an argument of OFF), tries to balance |
| 4396 |
these two requirements. |
| 4397 |
|
| 4398 |
Specifying SPACE causes smaller default alignments to be chosen in two cases. |
| 4399 |
First any packed record is given an alignment of 1. Second, if a size is given |
| 4400 |
for the type, then the alignment is chosen to avoid increasing this size. For |
| 4401 |
example, consider: |
| 4402 |
|
| 4403 |
|
| 4404 |
.. code-block:: ada |
| 4405 |
|
| 4406 |
type R is record |
| 4407 |
X : Integer; |
| 4408 |
Y : Character; |
| 4409 |
end record; |
| 4410 |
|
| 4411 |
for R'Size use 5*8; |
| 4412 |
|
| 4413 |
|
| 4414 |
In the default mode, this type gets an alignment of 4, so that access to the |
| 4415 |
Integer field X are efficient. But this means that objects of the type end up |
| 4416 |
with a size of 8 bytes. This is a valid choice, since sizes of objects are |
| 4417 |
allowed to be bigger than the size of the type, but it can waste space if for |
| 4418 |
example fields of type R appear in an enclosing record. If the above type is |
| 4419 |
compiled in ``Optimize_Alignment (Space)`` mode, the alignment is set to 1. |
| 4420 |
|
| 4421 |
However, there is one case in which SPACE is ignored. If a variable length |
| 4422 |
record (that is a discriminated record with a component which is an array |
| 4423 |
whose length depends on a discriminant), has a pragma Pack, then it is not |
| 4424 |
in general possible to set the alignment of such a record to one, so the |
| 4425 |
pragma is ignored in this case (with a warning). |
| 4426 |
|
| 4427 |
Specifying SPACE also disables alignment promotions for standalone objects, |
| 4428 |
which occur when the compiler increases the alignment of a specific object |
| 4429 |
without changing the alignment of its type. |
| 4430 |
|
| 4431 |
Specifying SPACE also disables component reordering in unpacked record types, |
| 4432 |
which can result in larger sizes in order to meet alignment requirements. |
| 4433 |
|
| 4434 |
Specifying TIME causes larger default alignments to be chosen in the case of |
| 4435 |
small types with sizes that are not a power of 2. For example, consider: |
| 4436 |
|
| 4437 |
|
| 4438 |
.. code-block:: ada |
| 4439 |
|
| 4440 |
type R is record |
| 4441 |
A : Character; |
| 4442 |
B : Character; |
| 4443 |
C : Boolean; |
| 4444 |
end record; |
| 4445 |
|
| 4446 |
pragma Pack (R); |
| 4447 |
for R'Size use 17; |
| 4448 |
|
| 4449 |
|
| 4450 |
The default alignment for this record is normally 1, but if this type is |
| 4451 |
compiled in ``Optimize_Alignment (Time)`` mode, then the alignment is set |
| 4452 |
to 4, which wastes space for objects of the type, since they are now 4 bytes |
| 4453 |
long, but results in more efficient access when the whole record is referenced. |
| 4454 |
|
| 4455 |
As noted above, this is a configuration pragma, and there is a requirement |
| 4456 |
that all units in a partition be compiled with a consistent setting of the |
| 4457 |
optimization setting. This would normally be achieved by use of a configuration |
| 4458 |
pragma file containing the appropriate setting. The exception to this rule is |
| 4459 |
that units with an explicit configuration pragma in the same file as the source |
| 4460 |
unit are excluded from the consistency check, as are all predefined units. The |
| 4461 |
latter are compiled by default in pragma Optimize_Alignment (Off) mode if no |
| 4462 |
pragma appears at the start of the file. |
| 4463 |
|
| 4464 |
Pragma Ordered |
| 4465 |
============== |
| 4466 |
|
| 4467 |
Syntax: |
| 4468 |
|
| 4469 |
|
| 4470 |
.. code-block:: ada |
| 4471 |
|
| 4472 |
pragma Ordered (enumeration_first_subtype_LOCAL_NAME); |
| 4473 |
|
| 4474 |
|
| 4475 |
Most enumeration types are from a conceptual point of view unordered. |
| 4476 |
For example, consider: |
| 4477 |
|
| 4478 |
|
| 4479 |
.. code-block:: ada |
| 4480 |
|
| 4481 |
type Color is (Red, Blue, Green, Yellow); |
| 4482 |
|
| 4483 |
|
| 4484 |
By Ada semantics ``Blue > Red`` and ``Green > Blue``, |
| 4485 |
but really these relations make no sense; the enumeration type merely |
| 4486 |
specifies a set of possible colors, and the order is unimportant. |
| 4487 |
|
| 4488 |
For unordered enumeration types, it is generally a good idea if |
| 4489 |
clients avoid comparisons (other than equality or inequality) and |
| 4490 |
explicit ranges. (A *client* is a unit where the type is referenced, |
| 4491 |
other than the unit where the type is declared, its body, and its subunits.) |
| 4492 |
For example, if code buried in some client says: |
| 4493 |
|
| 4494 |
|
| 4495 |
.. code-block:: ada |
| 4496 |
|
| 4497 |
if Current_Color < Yellow then ... |
| 4498 |
if Current_Color in Blue .. Green then ... |
| 4499 |
|
| 4500 |
|
| 4501 |
then the client code is relying on the order, which is undesirable. |
| 4502 |
It makes the code hard to read and creates maintenance difficulties if |
| 4503 |
entries have to be added to the enumeration type. Instead, |
| 4504 |
the code in the client should list the possibilities, or an |
| 4505 |
appropriate subtype should be declared in the unit that declares |
| 4506 |
the original enumeration type. E.g., the following subtype could |
| 4507 |
be declared along with the type ``Color``: |
| 4508 |
|
| 4509 |
|
| 4510 |
.. code-block:: ada |
| 4511 |
|
| 4512 |
subtype RBG is Color range Red .. Green; |
| 4513 |
|
| 4514 |
|
| 4515 |
and then the client could write: |
| 4516 |
|
| 4517 |
|
| 4518 |
.. code-block:: ada |
| 4519 |
|
| 4520 |
if Current_Color in RBG then ... |
| 4521 |
if Current_Color = Blue or Current_Color = Green then ... |
| 4522 |
|
| 4523 |
|
| 4524 |
However, some enumeration types are legitimately ordered from a conceptual |
| 4525 |
point of view. For example, if you declare: |
| 4526 |
|
| 4527 |
|
| 4528 |
.. code-block:: ada |
| 4529 |
|
| 4530 |
type Day is (Mon, Tue, Wed, Thu, Fri, Sat, Sun); |
| 4531 |
|
| 4532 |
|
| 4533 |
then the ordering imposed by the language is reasonable, and |
| 4534 |
clients can depend on it, writing for example: |
| 4535 |
|
| 4536 |
|
| 4537 |
.. code-block:: ada |
| 4538 |
|
| 4539 |
if D in Mon .. Fri then ... |
| 4540 |
if D < Wed then ... |
| 4541 |
|
| 4542 |
|
| 4543 |
The pragma *Ordered* is provided to mark enumeration types that |
| 4544 |
are conceptually ordered, alerting the reader that clients may depend |
| 4545 |
on the ordering. GNAT provides a pragma to mark enumerations as ordered |
| 4546 |
rather than one to mark them as unordered, since in our experience, |
| 4547 |
the great majority of enumeration types are conceptually unordered. |
| 4548 |
|
| 4549 |
The types ``Boolean``, ``Character``, ``Wide_Character``, |
| 4550 |
and ``Wide_Wide_Character`` |
| 4551 |
are considered to be ordered types, so each is declared with a |
| 4552 |
pragma ``Ordered`` in package ``Standard``. |
| 4553 |
|
| 4554 |
Normally pragma ``Ordered`` serves only as documentation and a guide for |
| 4555 |
coding standards, but GNAT provides a warning switch *-gnatw.u* that |
| 4556 |
requests warnings for inappropriate uses (comparisons and explicit |
| 4557 |
subranges) for unordered types. If this switch is used, then any |
| 4558 |
enumeration type not marked with pragma ``Ordered`` will be considered |
| 4559 |
as unordered, and will generate warnings for inappropriate uses. |
| 4560 |
|
| 4561 |
Note that generic types are not considered ordered or unordered (since the |
| 4562 |
template can be instantiated for both cases), so we never generate warnings |
| 4563 |
for the case of generic enumerated types. |
| 4564 |
|
| 4565 |
For additional information please refer to the description of the |
| 4566 |
*-gnatw.u* switch in the GNAT User's Guide. |
| 4567 |
|
| 4568 |
Pragma Overflow_Mode |
| 4569 |
==================== |
| 4570 |
|
| 4571 |
Syntax: |
| 4572 |
|
| 4573 |
|
| 4574 |
:: |
| 4575 |
|
| 4576 |
pragma Overflow_Mode |
| 4577 |
( [General =>] MODE |
| 4578 |
[,[Assertions =>] MODE]); |
| 4579 |
|
| 4580 |
MODE ::= STRICT | MINIMIZED | ELIMINATED |
| 4581 |
|
| 4582 |
|
| 4583 |
This pragma sets the current overflow mode to the given setting. For details |
| 4584 |
of the meaning of these modes, please refer to the |
| 4585 |
'Overflow Check Handling in GNAT' appendix in the |
| 4586 |
GNAT User's Guide. If only the ``General`` parameter is present, |
| 4587 |
the given mode applies to all expressions. If both parameters are present, |
| 4588 |
the ``General`` mode applies to expressions outside assertions, and |
| 4589 |
the ``Eliminated`` mode applies to expressions within assertions. |
| 4590 |
|
| 4591 |
The case of the ``MODE`` parameter is ignored, |
| 4592 |
so ``MINIMIZED``, ``Minimized`` and |
| 4593 |
``minimized`` all have the same effect. |
| 4594 |
|
| 4595 |
The ``Overflow_Mode`` pragma has the same scoping and placement |
| 4596 |
rules as pragma ``Suppress``, so it can occur either as a |
| 4597 |
configuration pragma, specifying a default for the whole |
| 4598 |
program, or in a declarative scope, where it applies to the |
| 4599 |
remaining declarations and statements in that scope. |
| 4600 |
|
| 4601 |
The pragma ``Suppress (Overflow_Check)`` suppresses |
| 4602 |
overflow checking, but does not affect the overflow mode. |
| 4603 |
|
| 4604 |
The pragma ``Unsuppress (Overflow_Check)`` unsuppresses (enables) |
| 4605 |
overflow checking, but does not affect the overflow mode. |
| 4606 |
|
| 4607 |
Pragma Overriding_Renamings |
| 4608 |
=========================== |
| 4609 |
.. index:: Rational profile |
| 4610 |
|
| 4611 |
.. index:: Rational compatibility |
| 4612 |
|
| 4613 |
Syntax: |
| 4614 |
|
| 4615 |
|
| 4616 |
.. code-block:: ada |
| 4617 |
|
| 4618 |
pragma Overriding_Renamings; |
| 4619 |
|
| 4620 |
|
| 4621 |
This is a GNAT configuration pragma to simplify porting |
| 4622 |
legacy code accepted by the Rational |
| 4623 |
Ada compiler. In the presence of this pragma, a renaming declaration that |
| 4624 |
renames an inherited operation declared in the same scope is legal if selected |
| 4625 |
notation is used as in: |
| 4626 |
|
| 4627 |
|
| 4628 |
.. code-block:: ada |
| 4629 |
|
| 4630 |
pragma Overriding_Renamings; |
| 4631 |
... |
| 4632 |
package R is |
| 4633 |
function F (..); |
| 4634 |
... |
| 4635 |
function F (..) renames R.F; |
| 4636 |
end R; |
| 4637 |
|
| 4638 |
|
| 4639 |
even though |
| 4640 |
RM 8.3 (15) stipulates that an overridden operation is not visible within the |
| 4641 |
declaration of the overriding operation. |
| 4642 |
|
| 4643 |
.. _Pragma-Part_Of: |
| 4644 |
|
| 4645 |
Pragma Part_Of |
| 4646 |
============== |
| 4647 |
|
| 4648 |
Syntax: |
| 4649 |
|
| 4650 |
.. code-block:: ada |
| 4651 |
|
| 4652 |
pragma Part_Of (ABSTRACT_STATE); |
| 4653 |
|
| 4654 |
ABSTRACT_STATE ::= NAME |
| 4655 |
|
| 4656 |
For the semantics of this pragma, see the entry for aspect ``Part_Of`` in the |
| 4657 |
SPARK 2014 Reference Manual, section 7.2.6. |
| 4658 |
|
| 4659 |
Pragma Partition_Elaboration_Policy |
| 4660 |
=================================== |
| 4661 |
|
| 4662 |
Syntax: |
| 4663 |
|
| 4664 |
|
| 4665 |
:: |
| 4666 |
|
| 4667 |
pragma Partition_Elaboration_Policy (POLICY_IDENTIFIER); |
| 4668 |
|
| 4669 |
POLICY_IDENTIFIER ::= Concurrent | Sequential |
| 4670 |
|
| 4671 |
|
| 4672 |
This pragma is standard in Ada 2005, but is available in all earlier |
| 4673 |
versions of Ada as an implementation-defined pragma. |
| 4674 |
See Ada 2012 Reference Manual for details. |
| 4675 |
|
| 4676 |
Pragma Passive |
| 4677 |
============== |
| 4678 |
|
| 4679 |
Syntax: |
| 4680 |
|
| 4681 |
|
| 4682 |
:: |
| 4683 |
|
| 4684 |
pragma Passive [(Semaphore | No)]; |
| 4685 |
|
| 4686 |
|
| 4687 |
Syntax checked, but otherwise ignored by GNAT. This is recognized for |
| 4688 |
compatibility with DEC Ada 83 implementations, where it is used within a |
| 4689 |
task definition to request that a task be made passive. If the argument |
| 4690 |
``Semaphore`` is present, or the argument is omitted, then DEC Ada 83 |
| 4691 |
treats the pragma as an assertion that the containing task is passive |
| 4692 |
and that optimization of context switch with this task is permitted and |
| 4693 |
desired. If the argument ``No`` is present, the task must not be |
| 4694 |
optimized. GNAT does not attempt to optimize any tasks in this manner |
| 4695 |
(since protected objects are available in place of passive tasks). |
| 4696 |
|
| 4697 |
For more information on the subject of passive tasks, see the section |
| 4698 |
'Passive Task Optimization' in the GNAT Users Guide. |
| 4699 |
|
| 4700 |
.. _Pragma-Persistent_BSS: |
| 4701 |
|
| 4702 |
Pragma Persistent_BSS |
| 4703 |
===================== |
| 4704 |
|
| 4705 |
Syntax: |
| 4706 |
|
| 4707 |
|
| 4708 |
:: |
| 4709 |
|
| 4710 |
pragma Persistent_BSS [(LOCAL_NAME)] |
| 4711 |
|
| 4712 |
|
| 4713 |
This pragma allows selected objects to be placed in the ``.persistent_bss`` |
| 4714 |
section. On some targets the linker and loader provide for special |
| 4715 |
treatment of this section, allowing a program to be reloaded without |
| 4716 |
affecting the contents of this data (hence the name persistent). |
| 4717 |
|
| 4718 |
There are two forms of usage. If an argument is given, it must be the |
| 4719 |
local name of a library-level object, with no explicit initialization |
| 4720 |
and whose type is potentially persistent. If no argument is given, then |
| 4721 |
the pragma is a configuration pragma, and applies to all library-level |
| 4722 |
objects with no explicit initialization of potentially persistent types. |
| 4723 |
|
| 4724 |
A potentially persistent type is a scalar type, or an untagged, |
| 4725 |
non-discriminated record, all of whose components have no explicit |
| 4726 |
initialization and are themselves of a potentially persistent type, |
| 4727 |
or an array, all of whose constraints are static, and whose component |
| 4728 |
type is potentially persistent. |
| 4729 |
|
| 4730 |
If this pragma is used on a target where this feature is not supported, |
| 4731 |
then the pragma will be ignored. See also ``pragma Linker_Section``. |
| 4732 |
|
| 4733 |
Pragma Post |
| 4734 |
=========== |
| 4735 |
.. index:: Post |
| 4736 |
|
| 4737 |
.. index:: Checks, postconditions |
| 4738 |
|
| 4739 |
|
| 4740 |
Syntax: |
| 4741 |
|
| 4742 |
|
| 4743 |
.. code-block:: ada |
| 4744 |
|
| 4745 |
pragma Post (Boolean_Expression); |
| 4746 |
|
| 4747 |
|
| 4748 |
The ``Post`` pragma is intended to be an exact replacement for |
| 4749 |
the language-defined |
| 4750 |
``Post`` aspect, and shares its restrictions and semantics. |
| 4751 |
It must appear either immediately following the corresponding |
| 4752 |
subprogram declaration (only other pragmas may intervene), or |
| 4753 |
if there is no separate subprogram declaration, then it can |
| 4754 |
appear at the start of the declarations in a subprogram body |
| 4755 |
(preceded only by other pragmas). |
| 4756 |
|
| 4757 |
Pragma Postcondition |
| 4758 |
==================== |
| 4759 |
.. index:: Postcondition |
| 4760 |
|
| 4761 |
.. index:: Checks, postconditions |
| 4762 |
|
| 4763 |
|
| 4764 |
Syntax: |
| 4765 |
|
| 4766 |
|
| 4767 |
:: |
| 4768 |
|
| 4769 |
pragma Postcondition ( |
| 4770 |
[Check =>] Boolean_Expression |
| 4771 |
[,[Message =>] String_Expression]); |
| 4772 |
|
| 4773 |
|
| 4774 |
The ``Postcondition`` pragma allows specification of automatic |
| 4775 |
postcondition checks for subprograms. These checks are similar to |
| 4776 |
assertions, but are automatically inserted just prior to the return |
| 4777 |
statements of the subprogram with which they are associated (including |
| 4778 |
implicit returns at the end of procedure bodies and associated |
| 4779 |
exception handlers). |
| 4780 |
|
| 4781 |
In addition, the boolean expression which is the condition which |
| 4782 |
must be true may contain references to function'Result in the case |
| 4783 |
of a function to refer to the returned value. |
| 4784 |
|
| 4785 |
``Postcondition`` pragmas may appear either immediately following the |
| 4786 |
(separate) declaration of a subprogram, or at the start of the |
| 4787 |
declarations of a subprogram body. Only other pragmas may intervene |
| 4788 |
(that is appear between the subprogram declaration and its |
| 4789 |
postconditions, or appear before the postcondition in the |
| 4790 |
declaration sequence in a subprogram body). In the case of a |
| 4791 |
postcondition appearing after a subprogram declaration, the |
| 4792 |
formal arguments of the subprogram are visible, and can be |
| 4793 |
referenced in the postcondition expressions. |
| 4794 |
|
| 4795 |
The postconditions are collected and automatically tested just |
| 4796 |
before any return (implicit or explicit) in the subprogram body. |
| 4797 |
A postcondition is only recognized if postconditions are active |
| 4798 |
at the time the pragma is encountered. The compiler switch *gnata* |
| 4799 |
turns on all postconditions by default, and pragma ``Check_Policy`` |
| 4800 |
with an identifier of ``Postcondition`` can also be used to |
| 4801 |
control whether postconditions are active. |
| 4802 |
|
| 4803 |
The general approach is that postconditions are placed in the spec |
| 4804 |
if they represent functional aspects which make sense to the client. |
| 4805 |
For example we might have: |
| 4806 |
|
| 4807 |
|
| 4808 |
.. code-block:: ada |
| 4809 |
|
| 4810 |
function Direction return Integer; |
| 4811 |
pragma Postcondition |
| 4812 |
(Direction'Result = +1 |
| 4813 |
or else |
| 4814 |
Direction'Result = -1); |
| 4815 |
|
| 4816 |
|
| 4817 |
which serves to document that the result must be +1 or -1, and |
| 4818 |
will test that this is the case at run time if postcondition |
| 4819 |
checking is active. |
| 4820 |
|
| 4821 |
Postconditions within the subprogram body can be used to |
| 4822 |
check that some internal aspect of the implementation, |
| 4823 |
not visible to the client, is operating as expected. |
| 4824 |
For instance if a square root routine keeps an internal |
| 4825 |
counter of the number of times it is called, then we |
| 4826 |
might have the following postcondition: |
| 4827 |
|
| 4828 |
|
| 4829 |
.. code-block:: ada |
| 4830 |
|
| 4831 |
Sqrt_Calls : Natural := 0; |
| 4832 |
|
| 4833 |
function Sqrt (Arg : Float) return Float is |
| 4834 |
pragma Postcondition |
| 4835 |
(Sqrt_Calls = Sqrt_Calls'Old + 1); |
| 4836 |
... |
| 4837 |
end Sqrt |
| 4838 |
|
| 4839 |
|
| 4840 |
As this example, shows, the use of the ``Old`` attribute |
| 4841 |
is often useful in postconditions to refer to the state on |
| 4842 |
entry to the subprogram. |
| 4843 |
|
| 4844 |
Note that postconditions are only checked on normal returns |
| 4845 |
from the subprogram. If an abnormal return results from |
| 4846 |
raising an exception, then the postconditions are not checked. |
| 4847 |
|
| 4848 |
If a postcondition fails, then the exception |
| 4849 |
``System.Assertions.Assert_Failure`` is raised. If |
| 4850 |
a message argument was supplied, then the given string |
| 4851 |
will be used as the exception message. If no message |
| 4852 |
argument was supplied, then the default message has |
| 4853 |
the form "Postcondition failed at file_name:line". The |
| 4854 |
exception is raised in the context of the subprogram |
| 4855 |
body, so it is possible to catch postcondition failures |
| 4856 |
within the subprogram body itself. |
| 4857 |
|
| 4858 |
Within a package spec, normal visibility rules |
| 4859 |
in Ada would prevent forward references within a |
| 4860 |
postcondition pragma to functions defined later in |
| 4861 |
the same package. This would introduce undesirable |
| 4862 |
ordering constraints. To avoid this problem, all |
| 4863 |
postcondition pragmas are analyzed at the end of |
| 4864 |
the package spec, allowing forward references. |
| 4865 |
|
| 4866 |
The following example shows that this even allows |
| 4867 |
mutually recursive postconditions as in: |
| 4868 |
|
| 4869 |
|
| 4870 |
.. code-block:: ada |
| 4871 |
|
| 4872 |
package Parity_Functions is |
| 4873 |
function Odd (X : Natural) return Boolean; |
| 4874 |
pragma Postcondition |
| 4875 |
(Odd'Result = |
| 4876 |
(x = 1 |
| 4877 |
or else |
| 4878 |
(x /= 0 and then Even (X - 1)))); |
| 4879 |
|
| 4880 |
function Even (X : Natural) return Boolean; |
| 4881 |
pragma Postcondition |
| 4882 |
(Even'Result = |
| 4883 |
(x = 0 |
| 4884 |
or else |
| 4885 |
(x /= 1 and then Odd (X - 1)))); |
| 4886 |
|
| 4887 |
end Parity_Functions; |
| 4888 |
|
| 4889 |
|
| 4890 |
There are no restrictions on the complexity or form of |
| 4891 |
conditions used within ``Postcondition`` pragmas. |
| 4892 |
The following example shows that it is even possible |
| 4893 |
to verify performance behavior. |
| 4894 |
|
| 4895 |
|
| 4896 |
.. code-block:: ada |
| 4897 |
|
| 4898 |
package Sort is |
| 4899 |
|
| 4900 |
Performance : constant Float; |
| 4901 |
-- Performance constant set by implementation |
| 4902 |
-- to match target architecture behavior. |
| 4903 |
|
| 4904 |
procedure Treesort (Arg : String); |
| 4905 |
-- Sorts characters of argument using N*logN sort |
| 4906 |
pragma Postcondition |
| 4907 |
(Float (Clock - Clock'Old) <= |
| 4908 |
Float (Arg'Length) * |
| 4909 |
log (Float (Arg'Length)) * |
| 4910 |
Performance); |
| 4911 |
end Sort; |
| 4912 |
|
| 4913 |
|
| 4914 |
Note: postcondition pragmas associated with subprograms that are |
| 4915 |
marked as Inline_Always, or those marked as Inline with front-end |
| 4916 |
inlining (-gnatN option set) are accepted and legality-checked |
| 4917 |
by the compiler, but are ignored at run-time even if postcondition |
| 4918 |
checking is enabled. |
| 4919 |
|
| 4920 |
Note that pragma ``Postcondition`` differs from the language-defined |
| 4921 |
``Post`` aspect (and corresponding ``Post`` pragma) in allowing |
| 4922 |
multiple occurrences, allowing occurences in the body even if there |
| 4923 |
is a separate spec, and allowing a second string parameter, and the |
| 4924 |
use of the pragma identifier ``Check``. Historically, pragma |
| 4925 |
``Postcondition`` was implemented prior to the development of |
| 4926 |
Ada 2012, and has been retained in its original form for |
| 4927 |
compatibility purposes. |
| 4928 |
|
| 4929 |
Pragma Post_Class |
| 4930 |
================= |
| 4931 |
.. index:: Post |
| 4932 |
|
| 4933 |
.. index:: Checks, postconditions |
| 4934 |
|
| 4935 |
|
| 4936 |
Syntax: |
| 4937 |
|
| 4938 |
|
| 4939 |
.. code-block:: ada |
| 4940 |
|
| 4941 |
pragma Post_Class (Boolean_Expression); |
| 4942 |
|
| 4943 |
|
| 4944 |
The ``Post_Class`` pragma is intended to be an exact replacement for |
| 4945 |
the language-defined |
| 4946 |
``Post'Class`` aspect, and shares its restrictions and semantics. |
| 4947 |
It must appear either immediately following the corresponding |
| 4948 |
subprogram declaration (only other pragmas may intervene), or |
| 4949 |
if there is no separate subprogram declaration, then it can |
| 4950 |
appear at the start of the declarations in a subprogram body |
| 4951 |
(preceded only by other pragmas). |
| 4952 |
|
| 4953 |
Note: This pragma is called ``Post_Class`` rather than |
| 4954 |
``Post'Class`` because the latter would not be strictly |
| 4955 |
conforming to the allowed syntax for pragmas. The motivation |
| 4956 |
for providing pragmas equivalent to the aspects is to allow a program |
| 4957 |
to be written using the pragmas, and then compiled if necessary |
| 4958 |
using an Ada compiler that does not recognize the pragmas or |
| 4959 |
aspects, but is prepared to ignore the pragmas. The assertion |
| 4960 |
policy that controls this pragma is ``Post'Class``, not |
| 4961 |
``Post_Class``. |
| 4962 |
|
| 4963 |
Pragma Pre |
| 4964 |
========== |
| 4965 |
.. index:: Pre |
| 4966 |
|
| 4967 |
.. index:: Checks, preconditions |
| 4968 |
|
| 4969 |
|
| 4970 |
Syntax: |
| 4971 |
|
| 4972 |
|
| 4973 |
.. code-block:: ada |
| 4974 |
|
| 4975 |
pragma Pre (Boolean_Expression); |
| 4976 |
|
| 4977 |
|
| 4978 |
The ``Pre`` pragma is intended to be an exact replacement for |
| 4979 |
the language-defined |
| 4980 |
``Pre`` aspect, and shares its restrictions and semantics. |
| 4981 |
It must appear either immediately following the corresponding |
| 4982 |
subprogram declaration (only other pragmas may intervene), or |
| 4983 |
if there is no separate subprogram declaration, then it can |
| 4984 |
appear at the start of the declarations in a subprogram body |
| 4985 |
(preceded only by other pragmas). |
| 4986 |
|
| 4987 |
Pragma Precondition |
| 4988 |
=================== |
| 4989 |
.. index:: Preconditions |
| 4990 |
|
| 4991 |
.. index:: Checks, preconditions |
| 4992 |
|
| 4993 |
|
| 4994 |
Syntax: |
| 4995 |
|
| 4996 |
|
| 4997 |
:: |
| 4998 |
|
| 4999 |
pragma Precondition ( |
| 5000 |
[Check =>] Boolean_Expression |
| 5001 |
[,[Message =>] String_Expression]); |
| 5002 |
|
| 5003 |
|
| 5004 |
The ``Precondition`` pragma is similar to ``Postcondition`` |
| 5005 |
except that the corresponding checks take place immediately upon |
| 5006 |
entry to the subprogram, and if a precondition fails, the exception |
| 5007 |
is raised in the context of the caller, and the attribute 'Result |
| 5008 |
cannot be used within the precondition expression. |
| 5009 |
|
| 5010 |
Otherwise, the placement and visibility rules are identical to those |
| 5011 |
described for postconditions. The following is an example of use |
| 5012 |
within a package spec: |
| 5013 |
|
| 5014 |
|
| 5015 |
.. code-block:: ada |
| 5016 |
|
| 5017 |
package Math_Functions is |
| 5018 |
... |
| 5019 |
function Sqrt (Arg : Float) return Float; |
| 5020 |
pragma Precondition (Arg >= 0.0) |
| 5021 |
... |
| 5022 |
end Math_Functions; |
| 5023 |
|
| 5024 |
|
| 5025 |
``Precondition`` pragmas may appear either immediately following the |
| 5026 |
(separate) declaration of a subprogram, or at the start of the |
| 5027 |
declarations of a subprogram body. Only other pragmas may intervene |
| 5028 |
(that is appear between the subprogram declaration and its |
| 5029 |
postconditions, or appear before the postcondition in the |
| 5030 |
declaration sequence in a subprogram body). |
| 5031 |
|
| 5032 |
Note: precondition pragmas associated with subprograms that are |
| 5033 |
marked as Inline_Always, or those marked as Inline with front-end |
| 5034 |
inlining (-gnatN option set) are accepted and legality-checked |
| 5035 |
by the compiler, but are ignored at run-time even if precondition |
| 5036 |
checking is enabled. |
| 5037 |
|
| 5038 |
Note that pragma ``Precondition`` differs from the language-defined |
| 5039 |
``Pre`` aspect (and corresponding ``Pre`` pragma) in allowing |
| 5040 |
multiple occurrences, allowing occurences in the body even if there |
| 5041 |
is a separate spec, and allowing a second string parameter, and the |
| 5042 |
use of the pragma identifier ``Check``. Historically, pragma |
| 5043 |
``Precondition`` was implemented prior to the development of |
| 5044 |
Ada 2012, and has been retained in its original form for |
| 5045 |
compatibility purposes. |
| 5046 |
|
| 5047 |
.. _Pragma-Predicate: |
| 5048 |
|
| 5049 |
Pragma Predicate |
| 5050 |
================ |
| 5051 |
|
| 5052 |
Syntax: |
| 5053 |
|
| 5054 |
|
| 5055 |
:: |
| 5056 |
|
| 5057 |
pragma Predicate |
| 5058 |
([Entity =>] type_LOCAL_NAME, |
| 5059 |
[Check =>] EXPRESSION); |
| 5060 |
|
| 5061 |
|
| 5062 |
This pragma (available in all versions of Ada in GNAT) encompasses both |
| 5063 |
the ``Static_Predicate`` and ``Dynamic_Predicate`` aspects in |
| 5064 |
Ada 2012. A predicate is regarded as static if it has an allowed form |
| 5065 |
for ``Static_Predicate`` and is otherwise treated as a |
| 5066 |
``Dynamic_Predicate``. Otherwise, predicates specified by this |
| 5067 |
pragma behave exactly as described in the Ada 2012 reference manual. |
| 5068 |
For example, if we have |
| 5069 |
|
| 5070 |
|
| 5071 |
.. code-block:: ada |
| 5072 |
|
| 5073 |
type R is range 1 .. 10; |
| 5074 |
subtype S is R; |
| 5075 |
pragma Predicate (Entity => S, Check => S not in 4 .. 6); |
| 5076 |
subtype Q is R |
| 5077 |
pragma Predicate (Entity => Q, Check => F(Q) or G(Q)); |
| 5078 |
|
| 5079 |
|
| 5080 |
the effect is identical to the following Ada 2012 code: |
| 5081 |
|
| 5082 |
|
| 5083 |
.. code-block:: ada |
| 5084 |
|
| 5085 |
type R is range 1 .. 10; |
| 5086 |
subtype S is R with |
| 5087 |
Static_Predicate => S not in 4 .. 6; |
| 5088 |
subtype Q is R with |
| 5089 |
Dynamic_Predicate => F(Q) or G(Q); |
| 5090 |
|
| 5091 |
|
| 5092 |
Note that there are no pragmas ``Dynamic_Predicate`` |
| 5093 |
or ``Static_Predicate``. That is |
| 5094 |
because these pragmas would affect legality and semantics of |
| 5095 |
the program and thus do not have a neutral effect if ignored. |
| 5096 |
The motivation behind providing pragmas equivalent to |
| 5097 |
corresponding aspects is to allow a program to be written |
| 5098 |
using the pragmas, and then compiled with a compiler that |
| 5099 |
will ignore the pragmas. That doesn't work in the case of |
| 5100 |
static and dynamic predicates, since if the corresponding |
| 5101 |
pragmas are ignored, then the behavior of the program is |
| 5102 |
fundamentally changed (for example a membership test |
| 5103 |
``A in B`` would not take into account a predicate |
| 5104 |
defined for subtype B). When following this approach, the |
| 5105 |
use of predicates should be avoided. |
| 5106 |
|
| 5107 |
Pragma Predicate_Failure |
| 5108 |
======================== |
| 5109 |
|
| 5110 |
Syntax: |
| 5111 |
|
| 5112 |
|
| 5113 |
:: |
| 5114 |
|
| 5115 |
pragma Predicate_Failure |
| 5116 |
([Entity =>] type_LOCAL_NAME, |
| 5117 |
[Message =>] String_Expression); |
| 5118 |
|
| 5119 |
|
| 5120 |
The ``Predicate_Failure`` pragma is intended to be an exact replacement for |
| 5121 |
the language-defined |
| 5122 |
``Predicate_Failure`` aspect, and shares its restrictions and semantics. |
| 5123 |
|
| 5124 |
Pragma Preelaborable_Initialization |
| 5125 |
=================================== |
| 5126 |
|
| 5127 |
Syntax: |
| 5128 |
|
| 5129 |
|
| 5130 |
.. code-block:: ada |
| 5131 |
|
| 5132 |
pragma Preelaborable_Initialization (DIRECT_NAME); |
| 5133 |
|
| 5134 |
|
| 5135 |
This pragma is standard in Ada 2005, but is available in all earlier |
| 5136 |
versions of Ada as an implementation-defined pragma. |
| 5137 |
See Ada 2012 Reference Manual for details. |
| 5138 |
|
| 5139 |
Pragma Prefix_Exception_Messages |
| 5140 |
================================ |
| 5141 |
.. index:: Prefix_Exception_Messages |
| 5142 |
|
| 5143 |
.. index:: exception |
| 5144 |
|
| 5145 |
.. index:: Exception_Message |
| 5146 |
|
| 5147 |
|
| 5148 |
Syntax: |
| 5149 |
|
| 5150 |
|
| 5151 |
.. code-block:: ada |
| 5152 |
|
| 5153 |
pragma Prefix_Exception_Messages; |
| 5154 |
|
| 5155 |
|
| 5156 |
This is an implementation-defined configuration pragma that affects the |
| 5157 |
behavior of raise statements with a message given as a static string |
| 5158 |
constant (typically a string literal). In such cases, the string will |
| 5159 |
be automatically prefixed by the name of the enclosing entity (giving |
| 5160 |
the package and subprogram containing the raise statement). This helps |
| 5161 |
to identify where messages are coming from, and this mode is automatic |
| 5162 |
for the run-time library. |
| 5163 |
|
| 5164 |
The pragma has no effect if the message is computed with an expression other |
| 5165 |
than a static string constant, since the assumption in this case is that |
| 5166 |
the program computes exactly the string it wants. If you still want the |
| 5167 |
prefixing in this case, you can always call |
| 5168 |
``GNAT.Source_Info.Enclosing_Entity`` and prepend the string manually. |
| 5169 |
|
| 5170 |
Pragma Pre_Class |
| 5171 |
================ |
| 5172 |
.. index:: Pre_Class |
| 5173 |
|
| 5174 |
.. index:: Checks, preconditions |
| 5175 |
|
| 5176 |
|
| 5177 |
Syntax: |
| 5178 |
|
| 5179 |
|
| 5180 |
.. code-block:: ada |
| 5181 |
|
| 5182 |
pragma Pre_Class (Boolean_Expression); |
| 5183 |
|
| 5184 |
|
| 5185 |
The ``Pre_Class`` pragma is intended to be an exact replacement for |
| 5186 |
the language-defined |
| 5187 |
``Pre'Class`` aspect, and shares its restrictions and semantics. |
| 5188 |
It must appear either immediately following the corresponding |
| 5189 |
subprogram declaration (only other pragmas may intervene), or |
| 5190 |
if there is no separate subprogram declaration, then it can |
| 5191 |
appear at the start of the declarations in a subprogram body |
| 5192 |
(preceded only by other pragmas). |
| 5193 |
|
| 5194 |
Note: This pragma is called ``Pre_Class`` rather than |
| 5195 |
``Pre'Class`` because the latter would not be strictly |
| 5196 |
conforming to the allowed syntax for pragmas. The motivation |
| 5197 |
for providing pragmas equivalent to the aspects is to allow a program |
| 5198 |
to be written using the pragmas, and then compiled if necessary |
| 5199 |
using an Ada compiler that does not recognize the pragmas or |
| 5200 |
aspects, but is prepared to ignore the pragmas. The assertion |
| 5201 |
policy that controls this pragma is ``Pre'Class``, not |
| 5202 |
``Pre_Class``. |
| 5203 |
|
| 5204 |
Pragma Priority_Specific_Dispatching |
| 5205 |
==================================== |
| 5206 |
|
| 5207 |
Syntax: |
| 5208 |
|
| 5209 |
|
| 5210 |
:: |
| 5211 |
|
| 5212 |
pragma Priority_Specific_Dispatching ( |
| 5213 |
POLICY_IDENTIFIER, |
| 5214 |
first_priority_EXPRESSION, |
| 5215 |
last_priority_EXPRESSION) |
| 5216 |
|
| 5217 |
POLICY_IDENTIFIER ::= |
| 5218 |
EDF_Across_Priorities | |
| 5219 |
FIFO_Within_Priorities | |
| 5220 |
Non_Preemptive_Within_Priorities | |
| 5221 |
Round_Robin_Within_Priorities |
| 5222 |
|
| 5223 |
|
| 5224 |
This pragma is standard in Ada 2005, but is available in all earlier |
| 5225 |
versions of Ada as an implementation-defined pragma. |
| 5226 |
See Ada 2012 Reference Manual for details. |
| 5227 |
|
| 5228 |
Pragma Profile |
| 5229 |
============== |
| 5230 |
|
| 5231 |
Syntax: |
| 5232 |
|
| 5233 |
|
| 5234 |
.. code-block:: ada |
| 5235 |
|
| 5236 |
pragma Profile (Ravenscar | Restricted | Rational | Jorvik | |
| 5237 |
GNAT_Extended_Ravenscar | GNAT_Ravenscar_EDF ); |
| 5238 |
|
| 5239 |
|
| 5240 |
This pragma is standard in Ada 2005, but is available in all earlier |
| 5241 |
versions of Ada as an implementation-defined pragma. This is a |
| 5242 |
configuration pragma that establishes a set of configuration pragmas |
| 5243 |
that depend on the argument. ``Ravenscar`` is standard in Ada 2005. |
| 5244 |
``Jorvik`` is standard in Ada 202x. |
| 5245 |
The other possibilities (``Restricted``, ``Rational``, |
| 5246 |
``GNAT_Extended_Ravenscar``, ``GNAT_Ravenscar_EDF``) |
| 5247 |
are implementation-defined. ``GNAT_Extended_Ravenscar`` is an alias for ``Jorvik``. |
| 5248 |
|
| 5249 |
The set of configuration pragmas is defined in the following sections. |
| 5250 |
|
| 5251 |
|
| 5252 |
* Pragma Profile (Ravenscar) |
| 5253 |
|
| 5254 |
The ``Ravenscar`` profile is standard in Ada 2005, |
| 5255 |
but is available in all earlier |
| 5256 |
versions of Ada as an implementation-defined pragma. This profile |
| 5257 |
establishes the following set of configuration pragmas: |
| 5258 |
|
| 5259 |
* ``Task_Dispatching_Policy (FIFO_Within_Priorities)`` |
| 5260 |
|
| 5261 |
[RM D.2.2] Tasks are dispatched following a preemptive |
| 5262 |
priority-ordered scheduling policy. |
| 5263 |
|
| 5264 |
|
| 5265 |
* ``Locking_Policy (Ceiling_Locking)`` |
| 5266 |
|
| 5267 |
[RM D.3] While tasks and interrupts execute a protected action, they inherit |
| 5268 |
the ceiling priority of the corresponding protected object. |
| 5269 |
|
| 5270 |
|
| 5271 |
* ``Detect_Blocking`` |
| 5272 |
|
| 5273 |
This pragma forces the detection of potentially blocking operations within a |
| 5274 |
protected operation, and to raise Program_Error if that happens. |
| 5275 |
|
| 5276 |
plus the following set of restrictions: |
| 5277 |
|
| 5278 |
* ``Max_Entry_Queue_Length => 1`` |
| 5279 |
|
| 5280 |
No task can be queued on a protected entry. |
| 5281 |
|
| 5282 |
* ``Max_Protected_Entries => 1`` |
| 5283 |
|
| 5284 |
* ``Max_Task_Entries => 0`` |
| 5285 |
|
| 5286 |
No rendezvous statements are allowed. |
| 5287 |
|
| 5288 |
* ``No_Abort_Statements`` |
| 5289 |
|
| 5290 |
* ``No_Dynamic_Attachment`` |
| 5291 |
|
| 5292 |
* ``No_Dynamic_Priorities`` |
| 5293 |
|
| 5294 |
* ``No_Implicit_Heap_Allocations`` |
| 5295 |
|
| 5296 |
* ``No_Local_Protected_Objects`` |
| 5297 |
|
| 5298 |
* ``No_Local_Timing_Events`` |
| 5299 |
|
| 5300 |
* ``No_Protected_Type_Allocators`` |
| 5301 |
|
| 5302 |
* ``No_Relative_Delay`` |
| 5303 |
|
| 5304 |
* ``No_Requeue_Statements`` |
| 5305 |
|
| 5306 |
* ``No_Select_Statements`` |
| 5307 |
|
| 5308 |
* ``No_Specific_Termination_Handlers`` |
| 5309 |
|
| 5310 |
* ``No_Task_Allocators`` |
| 5311 |
|
| 5312 |
* ``No_Task_Hierarchy`` |
| 5313 |
|
| 5314 |
* ``No_Task_Termination`` |
| 5315 |
|
| 5316 |
* ``Simple_Barriers`` |
| 5317 |
|
| 5318 |
The Ravenscar profile also includes the following restrictions that specify |
| 5319 |
that there are no semantic dependencies on the corresponding predefined |
| 5320 |
packages: |
| 5321 |
|
| 5322 |
* ``No_Dependence => Ada.Asynchronous_Task_Control`` |
| 5323 |
|
| 5324 |
* ``No_Dependence => Ada.Calendar`` |
| 5325 |
|
| 5326 |
* ``No_Dependence => Ada.Execution_Time.Group_Budget`` |
| 5327 |
|
| 5328 |
* ``No_Dependence => Ada.Execution_Time.Timers`` |
| 5329 |
|
| 5330 |
* ``No_Dependence => Ada.Task_Attributes`` |
| 5331 |
|
| 5332 |
* ``No_Dependence => System.Multiprocessors.Dispatching_Domains`` |
| 5333 |
|
| 5334 |
This set of configuration pragmas and restrictions correspond to the |
| 5335 |
definition of the 'Ravenscar Profile' for limited tasking, devised and |
| 5336 |
published by the :title:`International Real-Time Ada Workshop, 1997`. |
| 5337 |
A description is also available at |
| 5338 |
`http://www-users.cs.york.ac.uk/~burns/ravenscar.ps <http://www-users.cs.york.ac.uk/~burns/ravenscar.ps>`_. |
| 5339 |
|
| 5340 |
The original definition of the profile was revised at subsequent IRTAW |
| 5341 |
meetings. It has been included in the ISO |
| 5342 |
:title:`Guide for the Use of the Ada Programming Language in High Integrity Systems`, |
| 5343 |
and was made part of the Ada 2005 standard. |
| 5344 |
The formal definition given by |
| 5345 |
the Ada Rapporteur Group (ARG) can be found in two Ada Issues (AI-249 and |
| 5346 |
AI-305) available at |
| 5347 |
`http://www.ada-auth.org/cgi-bin/cvsweb.cgi/ais/ai-00249.txt <http://www.ada-auth.org/cgi-bin/cvsweb.cgi/ais/ai-00249.txt>`_ and |
| 5348 |
`http://www.ada-auth.org/cgi-bin/cvsweb.cgi/ais/ai-00305.txt <http://www.ada-auth.org/cgi-bin/cvsweb.cgi/ais/ai-00305.txt>`_. |
| 5349 |
|
| 5350 |
The above set is a superset of the restrictions provided by pragma |
| 5351 |
``Profile (Restricted)``, it includes six additional restrictions |
| 5352 |
(``Simple_Barriers``, ``No_Select_Statements``, |
| 5353 |
``No_Calendar``, ``No_Implicit_Heap_Allocations``, |
| 5354 |
``No_Relative_Delay`` and ``No_Task_Termination``). This means |
| 5355 |
that pragma ``Profile (Ravenscar)``, like the pragma |
| 5356 |
``Profile (Restricted)``, |
| 5357 |
automatically causes the use of a simplified, |
| 5358 |
more efficient version of the tasking run-time library. |
| 5359 |
|
| 5360 |
* Pragma Profile (Jorvik) |
| 5361 |
|
| 5362 |
``Jorvik`` is the new profile added to the Ada 202x draft standard, |
| 5363 |
previously implemented under the name ``GNAT_Extended_Ravenscar``. |
| 5364 |
|
| 5365 |
The ``No_Implicit_Heap_Allocations`` restriction has been replaced |
| 5366 |
by ``No_Implicit_Task_Allocations`` and |
| 5367 |
``No_Implicit_Protected_Object_Allocations``. |
| 5368 |
|
| 5369 |
The ``Simple_Barriers`` restriction has been replaced by |
| 5370 |
``Pure_Barriers``. |
| 5371 |
|
| 5372 |
The ``Max_Protected_Entries``, ``Max_Entry_Queue_Length``, and |
| 5373 |
``No_Relative_Delay`` restrictions have been removed. |
| 5374 |
|
| 5375 |
Details on the rationale for ``Jorvik`` and implications for use may be |
| 5376 |
found in :title:`A New Ravenscar-Based Profile` by P. Rogers, J. Ruiz, |
| 5377 |
T. Gingold and P. Bernardi, in :title:`Reliable Software Technologies -- |
| 5378 |
Ada Europe 2017`, Springer-Verlag Lecture Notes in Computer Science, |
| 5379 |
Number 10300. |
| 5380 |
|
| 5381 |
|
| 5382 |
* Pragma Profile (GNAT_Ravenscar_EDF) |
| 5383 |
|
| 5384 |
This profile corresponds to the Ravenscar profile but using |
| 5385 |
EDF_Across_Priority as the Task_Scheduling_Policy. |
| 5386 |
|
| 5387 |
* Pragma Profile (Restricted) |
| 5388 |
|
| 5389 |
This profile corresponds to the GNAT restricted run time. It |
| 5390 |
establishes the following set of restrictions: |
| 5391 |
|
| 5392 |
* ``No_Abort_Statements`` |
| 5393 |
* ``No_Entry_Queue`` |
| 5394 |
* ``No_Task_Hierarchy`` |
| 5395 |
* ``No_Task_Allocators`` |
| 5396 |
* ``No_Dynamic_Priorities`` |
| 5397 |
* ``No_Terminate_Alternatives`` |
| 5398 |
* ``No_Dynamic_Attachment`` |
| 5399 |
* ``No_Protected_Type_Allocators`` |
| 5400 |
* ``No_Local_Protected_Objects`` |
| 5401 |
* ``No_Requeue_Statements`` |
| 5402 |
* ``No_Task_Attributes_Package`` |
| 5403 |
* ``Max_Asynchronous_Select_Nesting = 0`` |
| 5404 |
* ``Max_Task_Entries = 0`` |
| 5405 |
* ``Max_Protected_Entries = 1`` |
| 5406 |
* ``Max_Select_Alternatives = 0`` |
| 5407 |
|
| 5408 |
This set of restrictions causes the automatic selection of a simplified |
| 5409 |
version of the run time that provides improved performance for the |
| 5410 |
limited set of tasking functionality permitted by this set of restrictions. |
| 5411 |
|
| 5412 |
* Pragma Profile (Rational) |
| 5413 |
|
| 5414 |
The Rational profile is intended to facilitate porting legacy code that |
| 5415 |
compiles with the Rational APEX compiler, even when the code includes non- |
| 5416 |
conforming Ada constructs. The profile enables the following three pragmas: |
| 5417 |
|
| 5418 |
* ``pragma Implicit_Packing`` |
| 5419 |
* ``pragma Overriding_Renamings`` |
| 5420 |
* ``pragma Use_VADS_Size`` |
| 5421 |
|
| 5422 |
|
| 5423 |
Pragma Profile_Warnings |
| 5424 |
======================= |
| 5425 |
|
| 5426 |
Syntax: |
| 5427 |
|
| 5428 |
|
| 5429 |
.. code-block:: ada |
| 5430 |
|
| 5431 |
pragma Profile_Warnings (Ravenscar | Restricted | Rational); |
| 5432 |
|
| 5433 |
|
| 5434 |
This is an implementation-defined pragma that is similar in |
| 5435 |
effect to ``pragma Profile`` except that instead of |
| 5436 |
generating ``Restrictions`` pragmas, it generates |
| 5437 |
``Restriction_Warnings`` pragmas. The result is that |
| 5438 |
violations of the profile generate warning messages instead |
| 5439 |
of error messages. |
| 5440 |
|
| 5441 |
Pragma Propagate_Exceptions |
| 5442 |
=========================== |
| 5443 |
.. index:: Interfacing to C++ |
| 5444 |
|
| 5445 |
|
| 5446 |
Syntax: |
| 5447 |
|
| 5448 |
|
| 5449 |
.. code-block:: ada |
| 5450 |
|
| 5451 |
pragma Propagate_Exceptions; |
| 5452 |
|
| 5453 |
|
| 5454 |
This pragma is now obsolete and, other than generating a warning if warnings |
| 5455 |
on obsolescent features are enabled, is ignored. |
| 5456 |
It is retained for compatibility |
| 5457 |
purposes. It used to be used in connection with optimization of |
| 5458 |
a now-obsolete mechanism for implementation of exceptions. |
| 5459 |
|
| 5460 |
Pragma Provide_Shift_Operators |
| 5461 |
============================== |
| 5462 |
.. index:: Shift operators |
| 5463 |
|
| 5464 |
|
| 5465 |
Syntax: |
| 5466 |
|
| 5467 |
|
| 5468 |
.. code-block:: ada |
| 5469 |
|
| 5470 |
pragma Provide_Shift_Operators (integer_first_subtype_LOCAL_NAME); |
| 5471 |
|
| 5472 |
|
| 5473 |
This pragma can be applied to a first subtype local name that specifies |
| 5474 |
either an unsigned or signed type. It has the effect of providing the |
| 5475 |
five shift operators (Shift_Left, Shift_Right, Shift_Right_Arithmetic, |
| 5476 |
Rotate_Left and Rotate_Right) for the given type. It is similar to |
| 5477 |
including the function declarations for these five operators, together |
| 5478 |
with the pragma Import (Intrinsic, ...) statements. |
| 5479 |
|
| 5480 |
Pragma Psect_Object |
| 5481 |
=================== |
| 5482 |
|
| 5483 |
Syntax: |
| 5484 |
|
| 5485 |
|
| 5486 |
:: |
| 5487 |
|
| 5488 |
pragma Psect_Object ( |
| 5489 |
[Internal =>] LOCAL_NAME, |
| 5490 |
[, [External =>] EXTERNAL_SYMBOL] |
| 5491 |
[, [Size =>] EXTERNAL_SYMBOL]); |
| 5492 |
|
| 5493 |
EXTERNAL_SYMBOL ::= |
| 5494 |
IDENTIFIER |
| 5495 |
| static_string_EXPRESSION |
| 5496 |
|
| 5497 |
|
| 5498 |
This pragma is identical in effect to pragma ``Common_Object``. |
| 5499 |
|
| 5500 |
.. _Pragma-Pure_Function: |
| 5501 |
|
| 5502 |
Pragma Pure_Function |
| 5503 |
==================== |
| 5504 |
|
| 5505 |
Syntax: |
| 5506 |
|
| 5507 |
|
| 5508 |
:: |
| 5509 |
|
| 5510 |
pragma Pure_Function ([Entity =>] function_LOCAL_NAME); |
| 5511 |
|
| 5512 |
|
| 5513 |
This pragma appears in the same declarative part as a function |
| 5514 |
declaration (or a set of function declarations if more than one |
| 5515 |
overloaded declaration exists, in which case the pragma applies |
| 5516 |
to all entities). It specifies that the function ``Entity`` is |
| 5517 |
to be considered pure for the purposes of code generation. This means |
| 5518 |
that the compiler can assume that there are no side effects, and |
| 5519 |
in particular that two identical calls produce the same result in |
| 5520 |
the same context. It also means that the function can be used in |
| 5521 |
an address clause. |
| 5522 |
|
| 5523 |
Note that, quite deliberately, there are no static checks to try |
| 5524 |
to ensure that this promise is met, so ``Pure_Function`` can be used |
| 5525 |
with functions that are conceptually pure, even if they do modify |
| 5526 |
global variables. For example, a square root function that is |
| 5527 |
instrumented to count the number of times it is called is still |
| 5528 |
conceptually pure, and can still be optimized, even though it |
| 5529 |
modifies a global variable (the count). Memo functions are another |
| 5530 |
example (where a table of previous calls is kept and consulted to |
| 5531 |
avoid re-computation). |
| 5532 |
|
| 5533 |
Note also that the normal rules excluding optimization of subprograms |
| 5534 |
in pure units (when parameter types are descended from System.Address, |
| 5535 |
or when the full view of a parameter type is limited), do not apply |
| 5536 |
for the Pure_Function case. If you explicitly specify Pure_Function, |
| 5537 |
the compiler may optimize away calls with identical arguments, and |
| 5538 |
if that results in unexpected behavior, the proper action is not to |
| 5539 |
use the pragma for subprograms that are not (conceptually) pure. |
| 5540 |
|
| 5541 |
Note: Most functions in a ``Pure`` package are automatically pure, and |
| 5542 |
there is no need to use pragma ``Pure_Function`` for such functions. One |
| 5543 |
exception is any function that has at least one formal of type |
| 5544 |
``System.Address`` or a type derived from it. Such functions are not |
| 5545 |
considered pure by default, since the compiler assumes that the |
| 5546 |
``Address`` parameter may be functioning as a pointer and that the |
| 5547 |
referenced data may change even if the address value does not. |
| 5548 |
Similarly, imported functions are not considered to be pure by default, |
| 5549 |
since there is no way of checking that they are in fact pure. The use |
| 5550 |
of pragma ``Pure_Function`` for such a function will override these default |
| 5551 |
assumption, and cause the compiler to treat a designated subprogram as pure |
| 5552 |
in these cases. |
| 5553 |
|
| 5554 |
Note: If pragma ``Pure_Function`` is applied to a renamed function, it |
| 5555 |
applies to the underlying renamed function. This can be used to |
| 5556 |
disambiguate cases of overloading where some but not all functions |
| 5557 |
in a set of overloaded functions are to be designated as pure. |
| 5558 |
|
| 5559 |
If pragma ``Pure_Function`` is applied to a library-level function, the |
| 5560 |
function is also considered pure from an optimization point of view, but the |
| 5561 |
unit is not a Pure unit in the categorization sense. So for example, a function |
| 5562 |
thus marked is free to ``with`` non-pure units. |
| 5563 |
|
| 5564 |
Pragma Rational |
| 5565 |
=============== |
| 5566 |
|
| 5567 |
Syntax: |
| 5568 |
|
| 5569 |
|
| 5570 |
.. code-block:: ada |
| 5571 |
|
| 5572 |
pragma Rational; |
| 5573 |
|
| 5574 |
|
| 5575 |
This pragma is considered obsolescent, but is retained for |
| 5576 |
compatibility purposes. It is equivalent to: |
| 5577 |
|
| 5578 |
|
| 5579 |
.. code-block:: ada |
| 5580 |
|
| 5581 |
pragma Profile (Rational); |
| 5582 |
|
| 5583 |
|
| 5584 |
Pragma Ravenscar |
| 5585 |
================ |
| 5586 |
|
| 5587 |
Syntax: |
| 5588 |
|
| 5589 |
|
| 5590 |
.. code-block:: ada |
| 5591 |
|
| 5592 |
pragma Ravenscar; |
| 5593 |
|
| 5594 |
|
| 5595 |
This pragma is considered obsolescent, but is retained for |
| 5596 |
compatibility purposes. It is equivalent to: |
| 5597 |
|
| 5598 |
|
| 5599 |
.. code-block:: ada |
| 5600 |
|
| 5601 |
pragma Profile (Ravenscar); |
| 5602 |
|
| 5603 |
|
| 5604 |
which is the preferred method of setting the ``Ravenscar`` profile. |
| 5605 |
|
| 5606 |
.. _Pragma-Refined_Depends: |
| 5607 |
|
| 5608 |
Pragma Refined_Depends |
| 5609 |
====================== |
| 5610 |
|
| 5611 |
Syntax: |
| 5612 |
|
| 5613 |
.. code-block:: ada |
| 5614 |
|
| 5615 |
pragma Refined_Depends (DEPENDENCY_RELATION); |
| 5616 |
|
| 5617 |
DEPENDENCY_RELATION ::= |
| 5618 |
null |
| 5619 |
| (DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE}) |
| 5620 |
|
| 5621 |
DEPENDENCY_CLAUSE ::= |
| 5622 |
OUTPUT_LIST =>[+] INPUT_LIST |
| 5623 |
| NULL_DEPENDENCY_CLAUSE |
| 5624 |
|
| 5625 |
NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST |
| 5626 |
|
| 5627 |
OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT}) |
| 5628 |
|
| 5629 |
INPUT_LIST ::= null | INPUT | (INPUT {, INPUT}) |
| 5630 |
|
| 5631 |
OUTPUT ::= NAME | FUNCTION_RESULT |
| 5632 |
INPUT ::= NAME |
| 5633 |
|
| 5634 |
where FUNCTION_RESULT is a function Result attribute_reference |
| 5635 |
|
| 5636 |
For the semantics of this pragma, see the entry for aspect ``Refined_Depends`` in |
| 5637 |
the SPARK 2014 Reference Manual, section 6.1.5. |
| 5638 |
|
| 5639 |
.. _Pragma-Refined_Global: |
| 5640 |
|
| 5641 |
Pragma Refined_Global |
| 5642 |
===================== |
| 5643 |
|
| 5644 |
Syntax: |
| 5645 |
|
| 5646 |
.. code-block:: ada |
| 5647 |
|
| 5648 |
pragma Refined_Global (GLOBAL_SPECIFICATION); |
| 5649 |
|
| 5650 |
GLOBAL_SPECIFICATION ::= |
| 5651 |
null |
| 5652 |
| (GLOBAL_LIST) |
| 5653 |
| (MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST}) |
| 5654 |
|
| 5655 |
MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST |
| 5656 |
|
| 5657 |
MODE_SELECTOR ::= In_Out | Input | Output | Proof_In |
| 5658 |
GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM}) |
| 5659 |
GLOBAL_ITEM ::= NAME |
| 5660 |
|
| 5661 |
For the semantics of this pragma, see the entry for aspect ``Refined_Global`` in |
| 5662 |
the SPARK 2014 Reference Manual, section 6.1.4. |
| 5663 |
|
| 5664 |
.. _Pragma-Refined_Post: |
| 5665 |
|
| 5666 |
Pragma Refined_Post |
| 5667 |
=================== |
| 5668 |
|
| 5669 |
Syntax: |
| 5670 |
|
| 5671 |
.. code-block:: ada |
| 5672 |
|
| 5673 |
pragma Refined_Post (boolean_EXPRESSION); |
| 5674 |
|
| 5675 |
For the semantics of this pragma, see the entry for aspect ``Refined_Post`` in |
| 5676 |
the SPARK 2014 Reference Manual, section 7.2.7. |
| 5677 |
|
| 5678 |
.. _Pragma-Refined_State: |
| 5679 |
|
| 5680 |
Pragma Refined_State |
| 5681 |
==================== |
| 5682 |
|
| 5683 |
Syntax: |
| 5684 |
|
| 5685 |
.. code-block:: ada |
| 5686 |
|
| 5687 |
pragma Refined_State (REFINEMENT_LIST); |
| 5688 |
|
| 5689 |
REFINEMENT_LIST ::= |
| 5690 |
(REFINEMENT_CLAUSE {, REFINEMENT_CLAUSE}) |
| 5691 |
|
| 5692 |
REFINEMENT_CLAUSE ::= state_NAME => CONSTITUENT_LIST |
| 5693 |
|
| 5694 |
CONSTITUENT_LIST ::= |
| 5695 |
null |
| 5696 |
| CONSTITUENT |
| 5697 |
| (CONSTITUENT {, CONSTITUENT}) |
| 5698 |
|
| 5699 |
CONSTITUENT ::= object_NAME | state_NAME |
| 5700 |
|
| 5701 |
For the semantics of this pragma, see the entry for aspect ``Refined_State`` in |
| 5702 |
the SPARK 2014 Reference Manual, section 7.2.2. |
| 5703 |
|
| 5704 |
Pragma Relative_Deadline |
| 5705 |
======================== |
| 5706 |
|
| 5707 |
Syntax: |
| 5708 |
|
| 5709 |
|
| 5710 |
.. code-block:: ada |
| 5711 |
|
| 5712 |
pragma Relative_Deadline (time_span_EXPRESSION); |
| 5713 |
|
| 5714 |
|
| 5715 |
This pragma is standard in Ada 2005, but is available in all earlier |
| 5716 |
versions of Ada as an implementation-defined pragma. |
| 5717 |
See Ada 2012 Reference Manual for details. |
| 5718 |
|
| 5719 |
.. _Pragma-Remote_Access_Type: |
| 5720 |
|
| 5721 |
Pragma Remote_Access_Type |
| 5722 |
========================= |
| 5723 |
|
| 5724 |
Syntax: |
| 5725 |
|
| 5726 |
|
| 5727 |
:: |
| 5728 |
|
| 5729 |
pragma Remote_Access_Type ([Entity =>] formal_access_type_LOCAL_NAME); |
| 5730 |
|
| 5731 |
|
| 5732 |
This pragma appears in the formal part of a generic declaration. |
| 5733 |
It specifies an exception to the RM rule from E.2.2(17/2), which forbids |
| 5734 |
the use of a remote access to class-wide type as actual for a formal |
| 5735 |
access type. |
| 5736 |
|
| 5737 |
When this pragma applies to a formal access type ``Entity``, that |
| 5738 |
type is treated as a remote access to class-wide type in the generic. |
| 5739 |
It must be a formal general access type, and its designated type must |
| 5740 |
be the class-wide type of a formal tagged limited private type from the |
| 5741 |
same generic declaration. |
| 5742 |
|
| 5743 |
In the generic unit, the formal type is subject to all restrictions |
| 5744 |
pertaining to remote access to class-wide types. At instantiation, the |
| 5745 |
actual type must be a remote access to class-wide type. |
| 5746 |
|
| 5747 |
Pragma Rename_Pragma |
| 5748 |
============================ |
| 5749 |
.. index:: Pragmas, synonyms |
| 5750 |
|
| 5751 |
Syntax: |
| 5752 |
|
| 5753 |
|
| 5754 |
:: |
| 5755 |
|
| 5756 |
pragma Rename_Pragma ( |
| 5757 |
[New_Name =>] IDENTIFIER, |
| 5758 |
[Renamed =>] pragma_IDENTIFIER); |
| 5759 |
|
| 5760 |
This pragma provides a mechanism for supplying new names for existing |
| 5761 |
pragmas. The ``New_Name`` identifier can subsequently be used as a synonym for |
| 5762 |
the Renamed pragma. For example, suppose you have code that was originally |
| 5763 |
developed on a compiler that supports Inline_Only as an implementation defined |
| 5764 |
pragma. And suppose the semantics of pragma Inline_Only are identical to (or at |
| 5765 |
least very similar to) the GNAT implementation defined pragma |
| 5766 |
Inline_Always. You could globally replace Inline_Only with Inline_Always. |
| 5767 |
|
| 5768 |
However, to avoid that source modification, you could instead add a |
| 5769 |
configuration pragma: |
| 5770 |
|
| 5771 |
.. code-block:: ada |
| 5772 |
|
| 5773 |
pragma Rename_Pragma ( |
| 5774 |
New_Name => Inline_Only, |
| 5775 |
Renamed => Inline_Always); |
| 5776 |
|
| 5777 |
|
| 5778 |
Then GNAT will treat "pragma Inline_Only ..." as if you had written |
| 5779 |
"pragma Inline_Always ...". |
| 5780 |
|
| 5781 |
Pragma Inline_Only will not necessarily mean the same thing as the other Ada |
| 5782 |
compiler; it's up to you to make sure the semantics are close enough. |
| 5783 |
|
| 5784 |
Pragma Restricted_Run_Time |
| 5785 |
========================== |
| 5786 |
|
| 5787 |
Syntax: |
| 5788 |
|
| 5789 |
|
| 5790 |
.. code-block:: ada |
| 5791 |
|
| 5792 |
pragma Restricted_Run_Time; |
| 5793 |
|
| 5794 |
|
| 5795 |
This pragma is considered obsolescent, but is retained for |
| 5796 |
compatibility purposes. It is equivalent to: |
| 5797 |
|
| 5798 |
|
| 5799 |
.. code-block:: ada |
| 5800 |
|
| 5801 |
pragma Profile (Restricted); |
| 5802 |
|
| 5803 |
|
| 5804 |
which is the preferred method of setting the restricted run time |
| 5805 |
profile. |
| 5806 |
|
| 5807 |
Pragma Restriction_Warnings |
| 5808 |
=========================== |
| 5809 |
|
| 5810 |
Syntax: |
| 5811 |
|
| 5812 |
|
| 5813 |
:: |
| 5814 |
|
| 5815 |
pragma Restriction_Warnings |
| 5816 |
(restriction_IDENTIFIER {, restriction_IDENTIFIER}); |
| 5817 |
|
| 5818 |
|
| 5819 |
This pragma allows a series of restriction identifiers to be |
| 5820 |
specified (the list of allowed identifiers is the same as for |
| 5821 |
pragma ``Restrictions``). For each of these identifiers |
| 5822 |
the compiler checks for violations of the restriction, but |
| 5823 |
generates a warning message rather than an error message |
| 5824 |
if the restriction is violated. |
| 5825 |
|
| 5826 |
One use of this is in situations where you want to know |
| 5827 |
about violations of a restriction, but you want to ignore some of |
| 5828 |
these violations. Consider this example, where you want to set |
| 5829 |
Ada_95 mode and enable style checks, but you want to know about |
| 5830 |
any other use of implementation pragmas: |
| 5831 |
|
| 5832 |
|
| 5833 |
.. code-block:: ada |
| 5834 |
|
| 5835 |
pragma Restriction_Warnings (No_Implementation_Pragmas); |
| 5836 |
pragma Warnings (Off, "violation of No_Implementation_Pragmas"); |
| 5837 |
pragma Ada_95; |
| 5838 |
pragma Style_Checks ("2bfhkM160"); |
| 5839 |
pragma Warnings (On, "violation of No_Implementation_Pragmas"); |
| 5840 |
|
| 5841 |
|
| 5842 |
By including the above lines in a configuration pragmas file, |
| 5843 |
the Ada_95 and Style_Checks pragmas are accepted without |
| 5844 |
generating a warning, but any other use of implementation |
| 5845 |
defined pragmas will cause a warning to be generated. |
| 5846 |
|
| 5847 |
Pragma Reviewable |
| 5848 |
================= |
| 5849 |
|
| 5850 |
Syntax: |
| 5851 |
|
| 5852 |
|
| 5853 |
.. code-block:: ada |
| 5854 |
|
| 5855 |
pragma Reviewable; |
| 5856 |
|
| 5857 |
|
| 5858 |
This pragma is an RM-defined standard pragma, but has no effect on the |
| 5859 |
program being compiled, or on the code generated for the program. |
| 5860 |
|
| 5861 |
To obtain the required output specified in RM H.3.1, the compiler must be |
| 5862 |
run with various special switches as follows: |
| 5863 |
|
| 5864 |
* *Where compiler-generated run-time checks remain* |
| 5865 |
|
| 5866 |
The switch *-gnatGL* |
| 5867 |
may be used to list the expanded code in pseudo-Ada form. |
| 5868 |
Runtime checks show up in the listing either as explicit |
| 5869 |
checks or operators marked with {} to indicate a check is present. |
| 5870 |
|
| 5871 |
|
| 5872 |
* *An identification of known exceptions at compile time* |
| 5873 |
|
| 5874 |
If the program is compiled with *-gnatwa*, |
| 5875 |
the compiler warning messages will indicate all cases where the compiler |
| 5876 |
detects that an exception is certain to occur at run time. |
| 5877 |
|
| 5878 |
|
| 5879 |
* *Possible reads of uninitialized variables* |
| 5880 |
|
| 5881 |
The compiler warns of many such cases, but its output is incomplete. |
| 5882 |
|
| 5883 |
.. only:: PRO or GPL |
| 5884 |
|
| 5885 |
The CodePeer analysis tool |
| 5886 |
may be used to obtain a comprehensive list of all |
| 5887 |
possible points at which uninitialized data may be read. |
| 5888 |
|
| 5889 |
.. only:: FSF |
| 5890 |
|
| 5891 |
A supplemental static analysis tool |
| 5892 |
may be used to obtain a comprehensive list of all |
| 5893 |
possible points at which uninitialized data may be read. |
| 5894 |
|
| 5895 |
|
| 5896 |
* *Where run-time support routines are implicitly invoked* |
| 5897 |
|
| 5898 |
In the output from *-gnatGL*, |
| 5899 |
run-time calls are explicitly listed as calls to the relevant |
| 5900 |
run-time routine. |
| 5901 |
|
| 5902 |
|
| 5903 |
* *Object code listing* |
| 5904 |
|
| 5905 |
This may be obtained either by using the *-S* switch, |
| 5906 |
or the objdump utility. |
| 5907 |
|
| 5908 |
|
| 5909 |
* *Constructs known to be erroneous at compile time* |
| 5910 |
|
| 5911 |
These are identified by warnings issued by the compiler (use *-gnatwa*). |
| 5912 |
|
| 5913 |
|
| 5914 |
* *Stack usage information* |
| 5915 |
|
| 5916 |
Static stack usage data (maximum per-subprogram) can be obtained via the |
| 5917 |
*-fstack-usage* switch to the compiler. |
| 5918 |
Dynamic stack usage data (per task) can be obtained via the *-u* switch |
| 5919 |
to gnatbind |
| 5920 |
|
| 5921 |
.. only:: PRO or GPL |
| 5922 |
|
| 5923 |
The gnatstack utility |
| 5924 |
can be used to provide additional information on stack usage. |
| 5925 |
|
| 5926 |
|
| 5927 |
* *Object code listing of entire partition* |
| 5928 |
|
| 5929 |
This can be obtained by compiling the partition with *-S*, |
| 5930 |
or by applying objdump |
| 5931 |
to all the object files that are part of the partition. |
| 5932 |
|
| 5933 |
|
| 5934 |
* *A description of the run-time model* |
| 5935 |
|
| 5936 |
The full sources of the run-time are available, and the documentation of |
| 5937 |
these routines describes how these run-time routines interface to the |
| 5938 |
underlying operating system facilities. |
| 5939 |
|
| 5940 |
|
| 5941 |
* *Control and data-flow information* |
| 5942 |
|
| 5943 |
.. only:: PRO or GPL |
| 5944 |
|
| 5945 |
The CodePeer tool |
| 5946 |
may be used to obtain complete control and data-flow information, as well as |
| 5947 |
comprehensive messages identifying possible problems based on this |
| 5948 |
information. |
| 5949 |
|
| 5950 |
.. only:: FSF |
| 5951 |
|
| 5952 |
A supplemental static analysis tool |
| 5953 |
may be used to obtain complete control and data-flow information, as well as |
| 5954 |
comprehensive messages identifying possible problems based on this |
| 5955 |
information. |
| 5956 |
|
| 5957 |
.. _Pragma-Secondary_Stack_Size: |
| 5958 |
|
| 5959 |
Pragma Secondary_Stack_Size |
| 5960 |
=========================== |
| 5961 |
|
| 5962 |
Syntax: |
| 5963 |
|
| 5964 |
.. code-block:: ada |
| 5965 |
|
| 5966 |
pragma Secondary_Stack_Size (integer_EXPRESSION); |
| 5967 |
|
| 5968 |
This pragma appears within the task definition of a single task declaration |
| 5969 |
or a task type declaration (like pragma ``Storage_Size``) and applies to all |
| 5970 |
task objects of that type. The argument specifies the size of the secondary |
| 5971 |
stack to be used by these task objects, and must be of an integer type. The |
| 5972 |
secondary stack is used to handle functions that return a variable-sized |
| 5973 |
result, for example a function returning an unconstrained String. |
| 5974 |
|
| 5975 |
Note this pragma only applies to targets using fixed secondary stacks, like |
| 5976 |
VxWorks 653 and bare board targets, where a fixed block for the |
| 5977 |
secondary stack is allocated from the primary stack of the task. By default, |
| 5978 |
these targets assign a percentage of the primary stack for the secondary stack, |
| 5979 |
as defined by ``System.Parameter.Sec_Stack_Percentage``. With this pragma, |
| 5980 |
an ``integer_EXPRESSION`` of bytes is assigned from the primary stack instead. |
| 5981 |
|
| 5982 |
For most targets, the pragma does not apply as the secondary stack grows on |
| 5983 |
demand: allocated as a chain of blocks in the heap. The default size of these |
| 5984 |
blocks can be modified via the :switch:`-D` binder option as described in |
| 5985 |
:title:`GNAT User's Guide`. |
| 5986 |
|
| 5987 |
Note that no check is made to see if the secondary stack can fit inside the |
| 5988 |
primary stack. |
| 5989 |
|
| 5990 |
Note the pragma cannot appear when the restriction ``No_Secondary_Stack`` |
| 5991 |
is in effect. |
| 5992 |
|
| 5993 |
Pragma Share_Generic |
| 5994 |
==================== |
| 5995 |
|
| 5996 |
Syntax: |
| 5997 |
|
| 5998 |
|
| 5999 |
:: |
| 6000 |
|
| 6001 |
pragma Share_Generic (GNAME {, GNAME}); |
| 6002 |
|
| 6003 |
GNAME ::= generic_unit_NAME | generic_instance_NAME |
| 6004 |
|
| 6005 |
|
| 6006 |
This pragma is provided for compatibility with Dec Ada 83. It has |
| 6007 |
no effect in GNAT (which does not implement shared generics), other |
| 6008 |
than to check that the given names are all names of generic units or |
| 6009 |
generic instances. |
| 6010 |
|
| 6011 |
.. _Pragma-Shared: |
| 6012 |
|
| 6013 |
Pragma Shared |
| 6014 |
============= |
| 6015 |
|
| 6016 |
This pragma is provided for compatibility with Ada 83. The syntax and |
| 6017 |
semantics are identical to pragma Atomic. |
| 6018 |
|
| 6019 |
Pragma Short_Circuit_And_Or |
| 6020 |
=========================== |
| 6021 |
|
| 6022 |
Syntax: |
| 6023 |
|
| 6024 |
|
| 6025 |
.. code-block:: ada |
| 6026 |
|
| 6027 |
pragma Short_Circuit_And_Or; |
| 6028 |
|
| 6029 |
|
| 6030 |
This configuration pragma causes any occurrence of the AND operator applied to |
| 6031 |
operands of type Standard.Boolean to be short-circuited (i.e. the AND operator |
| 6032 |
is treated as if it were AND THEN). Or is similarly treated as OR ELSE. This |
| 6033 |
may be useful in the context of certification protocols requiring the use of |
| 6034 |
short-circuited logical operators. If this configuration pragma occurs locally |
| 6035 |
within the file being compiled, it applies only to the file being compiled. |
| 6036 |
There is no requirement that all units in a partition use this option. |
| 6037 |
|
| 6038 |
Pragma Short_Descriptors |
| 6039 |
======================== |
| 6040 |
|
| 6041 |
Syntax: |
| 6042 |
|
| 6043 |
|
| 6044 |
.. code-block:: ada |
| 6045 |
|
| 6046 |
pragma Short_Descriptors; |
| 6047 |
|
| 6048 |
|
| 6049 |
This pragma is provided for compatibility with other Ada implementations. It |
| 6050 |
is recognized but ignored by all current versions of GNAT. |
| 6051 |
|
| 6052 |
.. _Pragma-Simple_Storage_Pool_Type: |
| 6053 |
|
| 6054 |
Pragma Simple_Storage_Pool_Type |
| 6055 |
=============================== |
| 6056 |
.. index:: Storage pool, simple |
| 6057 |
|
| 6058 |
.. index:: Simple storage pool |
| 6059 |
|
| 6060 |
Syntax: |
| 6061 |
|
| 6062 |
|
| 6063 |
.. code-block:: ada |
| 6064 |
|
| 6065 |
pragma Simple_Storage_Pool_Type (type_LOCAL_NAME); |
| 6066 |
|
| 6067 |
|
| 6068 |
A type can be established as a 'simple storage pool type' by applying |
| 6069 |
the representation pragma ``Simple_Storage_Pool_Type`` to the type. |
| 6070 |
A type named in the pragma must be a library-level immutably limited record |
| 6071 |
type or limited tagged type declared immediately within a package declaration. |
| 6072 |
The type can also be a limited private type whose full type is allowed as |
| 6073 |
a simple storage pool type. |
| 6074 |
|
| 6075 |
For a simple storage pool type ``SSP``, nonabstract primitive subprograms |
| 6076 |
``Allocate``, ``Deallocate``, and ``Storage_Size`` can be declared that |
| 6077 |
are subtype conformant with the following subprogram declarations: |
| 6078 |
|
| 6079 |
|
| 6080 |
.. code-block:: ada |
| 6081 |
|
| 6082 |
procedure Allocate |
| 6083 |
(Pool : in out SSP; |
| 6084 |
Storage_Address : out System.Address; |
| 6085 |
Size_In_Storage_Elements : System.Storage_Elements.Storage_Count; |
| 6086 |
Alignment : System.Storage_Elements.Storage_Count); |
| 6087 |
|
| 6088 |
procedure Deallocate |
| 6089 |
(Pool : in out SSP; |
| 6090 |
Storage_Address : System.Address; |
| 6091 |
Size_In_Storage_Elements : System.Storage_Elements.Storage_Count; |
| 6092 |
Alignment : System.Storage_Elements.Storage_Count); |
| 6093 |
|
| 6094 |
function Storage_Size (Pool : SSP) |
| 6095 |
return System.Storage_Elements.Storage_Count; |
| 6096 |
|
| 6097 |
|
| 6098 |
Procedure ``Allocate`` must be declared, whereas ``Deallocate`` and |
| 6099 |
``Storage_Size`` are optional. If ``Deallocate`` is not declared, then |
| 6100 |
applying an unchecked deallocation has no effect other than to set its actual |
| 6101 |
parameter to null. If ``Storage_Size`` is not declared, then the |
| 6102 |
``Storage_Size`` attribute applied to an access type associated with |
| 6103 |
a pool object of type SSP returns zero. Additional operations can be declared |
| 6104 |
for a simple storage pool type (such as for supporting a mark/release |
| 6105 |
storage-management discipline). |
| 6106 |
|
| 6107 |
An object of a simple storage pool type can be associated with an access |
| 6108 |
type by specifying the attribute |
| 6109 |
:ref:`Simple_Storage_Pool <Attribute_Simple_Storage_Pool>`. For example: |
| 6110 |
|
| 6111 |
|
| 6112 |
.. code-block:: ada |
| 6113 |
|
| 6114 |
My_Pool : My_Simple_Storage_Pool_Type; |
| 6115 |
|
| 6116 |
type Acc is access My_Data_Type; |
| 6117 |
|
| 6118 |
for Acc'Simple_Storage_Pool use My_Pool; |
| 6119 |
|
| 6120 |
|
| 6121 |
|
| 6122 |
See attribute :ref:`Simple_Storage_Pool <Attribute_Simple_Storage_Pool>` |
| 6123 |
for further details. |
| 6124 |
|
| 6125 |
.. _Pragma_Source_File_Name: |
| 6126 |
|
| 6127 |
Pragma Source_File_Name |
| 6128 |
======================= |
| 6129 |
|
| 6130 |
Syntax: |
| 6131 |
|
| 6132 |
|
| 6133 |
:: |
| 6134 |
|
| 6135 |
pragma Source_File_Name ( |
| 6136 |
[Unit_Name =>] unit_NAME, |
| 6137 |
Spec_File_Name => STRING_LITERAL, |
| 6138 |
[Index => INTEGER_LITERAL]); |
| 6139 |
|
| 6140 |
pragma Source_File_Name ( |
| 6141 |
[Unit_Name =>] unit_NAME, |
| 6142 |
Body_File_Name => STRING_LITERAL, |
| 6143 |
[Index => INTEGER_LITERAL]); |
| 6144 |
|
| 6145 |
|
| 6146 |
Use this to override the normal naming convention. It is a configuration |
| 6147 |
pragma, and so has the usual applicability of configuration pragmas |
| 6148 |
(i.e., it applies to either an entire partition, or to all units in a |
| 6149 |
compilation, or to a single unit, depending on how it is used). |
| 6150 |
``unit_name`` is mapped to ``file_name_literal``. The identifier for |
| 6151 |
the second argument is required, and indicates whether this is the file |
| 6152 |
name for the spec or for the body. |
| 6153 |
|
| 6154 |
The optional Index argument should be used when a file contains multiple |
| 6155 |
units, and when you do not want to use ``gnatchop`` to separate then |
| 6156 |
into multiple files (which is the recommended procedure to limit the |
| 6157 |
number of recompilations that are needed when some sources change). |
| 6158 |
For instance, if the source file :file:`source.ada` contains |
| 6159 |
|
| 6160 |
|
| 6161 |
.. code-block:: ada |
| 6162 |
|
| 6163 |
package B is |
| 6164 |
... |
| 6165 |
end B; |
| 6166 |
|
| 6167 |
with B; |
| 6168 |
procedure A is |
| 6169 |
begin |
| 6170 |
.. |
| 6171 |
end A; |
| 6172 |
|
| 6173 |
|
| 6174 |
you could use the following configuration pragmas: |
| 6175 |
|
| 6176 |
|
| 6177 |
.. code-block:: ada |
| 6178 |
|
| 6179 |
pragma Source_File_Name |
| 6180 |
(B, Spec_File_Name => "source.ada", Index => 1); |
| 6181 |
pragma Source_File_Name |
| 6182 |
(A, Body_File_Name => "source.ada", Index => 2); |
| 6183 |
|
| 6184 |
|
| 6185 |
Note that the ``gnatname`` utility can also be used to generate those |
| 6186 |
configuration pragmas. |
| 6187 |
|
| 6188 |
Another form of the ``Source_File_Name`` pragma allows |
| 6189 |
the specification of patterns defining alternative file naming schemes |
| 6190 |
to apply to all files. |
| 6191 |
|
| 6192 |
|
| 6193 |
:: |
| 6194 |
|
| 6195 |
pragma Source_File_Name |
| 6196 |
( [Spec_File_Name =>] STRING_LITERAL |
| 6197 |
[,[Casing =>] CASING_SPEC] |
| 6198 |
[,[Dot_Replacement =>] STRING_LITERAL]); |
| 6199 |
|
| 6200 |
pragma Source_File_Name |
| 6201 |
( [Body_File_Name =>] STRING_LITERAL |
| 6202 |
[,[Casing =>] CASING_SPEC] |
| 6203 |
[,[Dot_Replacement =>] STRING_LITERAL]); |
| 6204 |
|
| 6205 |
pragma Source_File_Name |
| 6206 |
( [Subunit_File_Name =>] STRING_LITERAL |
| 6207 |
[,[Casing =>] CASING_SPEC] |
| 6208 |
[,[Dot_Replacement =>] STRING_LITERAL]); |
| 6209 |
|
| 6210 |
CASING_SPEC ::= Lowercase | Uppercase | Mixedcase |
| 6211 |
|
| 6212 |
|
| 6213 |
The first argument is a pattern that contains a single asterisk indicating |
| 6214 |
the point at which the unit name is to be inserted in the pattern string |
| 6215 |
to form the file name. The second argument is optional. If present it |
| 6216 |
specifies the casing of the unit name in the resulting file name string. |
| 6217 |
The default is lower case. Finally the third argument allows for systematic |
| 6218 |
replacement of any dots in the unit name by the specified string literal. |
| 6219 |
|
| 6220 |
Note that Source_File_Name pragmas should not be used if you are using |
| 6221 |
project files. The reason for this rule is that the project manager is not |
| 6222 |
aware of these pragmas, and so other tools that use the project file would not |
| 6223 |
be aware of the intended naming conventions. If you are using project files, |
| 6224 |
file naming is controlled by Source_File_Name_Project pragmas, which are |
| 6225 |
usually supplied automatically by the project manager. A pragma |
| 6226 |
Source_File_Name cannot appear after a :ref:`Pragma_Source_File_Name_Project`. |
| 6227 |
|
| 6228 |
For more details on the use of the ``Source_File_Name`` pragma, see the |
| 6229 |
sections on `Using Other File Names` and `Alternative File Naming Schemes` |
| 6230 |
in the :title:`GNAT User's Guide`. |
| 6231 |
|
| 6232 |
.. _Pragma_Source_File_Name_Project: |
| 6233 |
|
| 6234 |
Pragma Source_File_Name_Project |
| 6235 |
=============================== |
| 6236 |
|
| 6237 |
This pragma has the same syntax and semantics as pragma Source_File_Name. |
| 6238 |
It is only allowed as a stand-alone configuration pragma. |
| 6239 |
It cannot appear after a :ref:`Pragma_Source_File_Name`, and |
| 6240 |
most importantly, once pragma Source_File_Name_Project appears, |
| 6241 |
no further Source_File_Name pragmas are allowed. |
| 6242 |
|
| 6243 |
The intention is that Source_File_Name_Project pragmas are always |
| 6244 |
generated by the Project Manager in a manner consistent with the naming |
| 6245 |
specified in a project file, and when naming is controlled in this manner, |
| 6246 |
it is not permissible to attempt to modify this naming scheme using |
| 6247 |
Source_File_Name or Source_File_Name_Project pragmas (which would not be |
| 6248 |
known to the project manager). |
| 6249 |
|
| 6250 |
Pragma Source_Reference |
| 6251 |
======================= |
| 6252 |
|
| 6253 |
Syntax: |
| 6254 |
|
| 6255 |
|
| 6256 |
.. code-block:: ada |
| 6257 |
|
| 6258 |
pragma Source_Reference (INTEGER_LITERAL, STRING_LITERAL); |
| 6259 |
|
| 6260 |
|
| 6261 |
This pragma must appear as the first line of a source file. |
| 6262 |
``integer_literal`` is the logical line number of the line following |
| 6263 |
the pragma line (for use in error messages and debugging |
| 6264 |
information). ``string_literal`` is a static string constant that |
| 6265 |
specifies the file name to be used in error messages and debugging |
| 6266 |
information. This is most notably used for the output of ``gnatchop`` |
| 6267 |
with the *-r* switch, to make sure that the original unchopped |
| 6268 |
source file is the one referred to. |
| 6269 |
|
| 6270 |
The second argument must be a string literal, it cannot be a static |
| 6271 |
string expression other than a string literal. This is because its value |
| 6272 |
is needed for error messages issued by all phases of the compiler. |
| 6273 |
|
| 6274 |
.. _Pragma-SPARK_Mode: |
| 6275 |
|
| 6276 |
Pragma SPARK_Mode |
| 6277 |
================= |
| 6278 |
|
| 6279 |
Syntax: |
| 6280 |
|
| 6281 |
|
| 6282 |
:: |
| 6283 |
|
| 6284 |
pragma SPARK_Mode [(On | Off)] ; |
| 6285 |
|
| 6286 |
|
| 6287 |
In general a program can have some parts that are in SPARK 2014 (and |
| 6288 |
follow all the rules in the SPARK Reference Manual), and some parts |
| 6289 |
that are full Ada 2012. |
| 6290 |
|
| 6291 |
The SPARK_Mode pragma is used to identify which parts are in SPARK |
| 6292 |
2014 (by default programs are in full Ada). The SPARK_Mode pragma can |
| 6293 |
be used in the following places: |
| 6294 |
|
| 6295 |
|
| 6296 |
* |
| 6297 |
As a configuration pragma, in which case it sets the default mode for |
| 6298 |
all units compiled with this pragma. |
| 6299 |
|
| 6300 |
* |
| 6301 |
Immediately following a library-level subprogram spec |
| 6302 |
|
| 6303 |
* |
| 6304 |
Immediately within a library-level package body |
| 6305 |
|
| 6306 |
* |
| 6307 |
Immediately following the ``private`` keyword of a library-level |
| 6308 |
package spec |
| 6309 |
|
| 6310 |
* |
| 6311 |
Immediately following the ``begin`` keyword of a library-level |
| 6312 |
package body |
| 6313 |
|
| 6314 |
* |
| 6315 |
Immediately within a library-level subprogram body |
| 6316 |
|
| 6317 |
|
| 6318 |
Normally a subprogram or package spec/body inherits the current mode |
| 6319 |
that is active at the point it is declared. But this can be overridden |
| 6320 |
by pragma within the spec or body as above. |
| 6321 |
|
| 6322 |
The basic consistency rule is that you can't turn SPARK_Mode back |
| 6323 |
``On``, once you have explicitly (with a pragma) turned if |
| 6324 |
``Off``. So the following rules apply: |
| 6325 |
|
| 6326 |
If a subprogram spec has SPARK_Mode ``Off``, then the body must |
| 6327 |
also have SPARK_Mode ``Off``. |
| 6328 |
|
| 6329 |
For a package, we have four parts: |
| 6330 |
|
| 6331 |
* |
| 6332 |
the package public declarations |
| 6333 |
* |
| 6334 |
the package private part |
| 6335 |
* |
| 6336 |
the body of the package |
| 6337 |
* |
| 6338 |
the elaboration code after ``begin`` |
| 6339 |
|
| 6340 |
For a package, the rule is that if you explicitly turn SPARK_Mode |
| 6341 |
``Off`` for any part, then all the following parts must have |
| 6342 |
SPARK_Mode ``Off``. Note that this may require repeating a pragma |
| 6343 |
SPARK_Mode (``Off``) in the body. For example, if we have a |
| 6344 |
configuration pragma SPARK_Mode (``On``) that turns the mode on by |
| 6345 |
default everywhere, and one particular package spec has pragma |
| 6346 |
SPARK_Mode (``Off``), then that pragma will need to be repeated in |
| 6347 |
the package body. |
| 6348 |
|
| 6349 |
Pragma Static_Elaboration_Desired |
| 6350 |
================================= |
| 6351 |
|
| 6352 |
Syntax: |
| 6353 |
|
| 6354 |
|
| 6355 |
.. code-block:: ada |
| 6356 |
|
| 6357 |
pragma Static_Elaboration_Desired; |
| 6358 |
|
| 6359 |
|
| 6360 |
This pragma is used to indicate that the compiler should attempt to initialize |
| 6361 |
statically the objects declared in the library unit to which the pragma applies, |
| 6362 |
when these objects are initialized (explicitly or implicitly) by an aggregate. |
| 6363 |
In the absence of this pragma, aggregates in object declarations are expanded |
| 6364 |
into assignments and loops, even when the aggregate components are static |
| 6365 |
constants. When the aggregate is present the compiler builds a static expression |
| 6366 |
that requires no run-time code, so that the initialized object can be placed in |
| 6367 |
read-only data space. If the components are not static, or the aggregate has |
| 6368 |
more that 100 components, the compiler emits a warning that the pragma cannot |
| 6369 |
be obeyed. (See also the restriction No_Implicit_Loops, which supports static |
| 6370 |
construction of larger aggregates with static components that include an others |
| 6371 |
choice.) |
| 6372 |
|
| 6373 |
Pragma Stream_Convert |
| 6374 |
===================== |
| 6375 |
|
| 6376 |
Syntax: |
| 6377 |
|
| 6378 |
|
| 6379 |
:: |
| 6380 |
|
| 6381 |
pragma Stream_Convert ( |
| 6382 |
[Entity =>] type_LOCAL_NAME, |
| 6383 |
[Read =>] function_NAME, |
| 6384 |
[Write =>] function_NAME); |
| 6385 |
|
| 6386 |
|
| 6387 |
This pragma provides an efficient way of providing user-defined stream |
| 6388 |
attributes. Not only is it simpler to use than specifying the attributes |
| 6389 |
directly, but more importantly, it allows the specification to be made in such |
| 6390 |
a way that the predefined unit Ada.Streams is not loaded unless it is actually |
| 6391 |
needed (i.e. unless the stream attributes are actually used); the use of |
| 6392 |
the Stream_Convert pragma adds no overhead at all, unless the stream |
| 6393 |
attributes are actually used on the designated type. |
| 6394 |
|
| 6395 |
The first argument specifies the type for which stream functions are |
| 6396 |
provided. The second parameter provides a function used to read values |
| 6397 |
of this type. It must name a function whose argument type may be any |
| 6398 |
subtype, and whose returned type must be the type given as the first |
| 6399 |
argument to the pragma. |
| 6400 |
|
| 6401 |
The meaning of the ``Read`` parameter is that if a stream attribute directly |
| 6402 |
or indirectly specifies reading of the type given as the first parameter, |
| 6403 |
then a value of the type given as the argument to the Read function is |
| 6404 |
read from the stream, and then the Read function is used to convert this |
| 6405 |
to the required target type. |
| 6406 |
|
| 6407 |
Similarly the ``Write`` parameter specifies how to treat write attributes |
| 6408 |
that directly or indirectly apply to the type given as the first parameter. |
| 6409 |
It must have an input parameter of the type specified by the first parameter, |
| 6410 |
and the return type must be the same as the input type of the Read function. |
| 6411 |
The effect is to first call the Write function to convert to the given stream |
| 6412 |
type, and then write the result type to the stream. |
| 6413 |
|
| 6414 |
The Read and Write functions must not be overloaded subprograms. If necessary |
| 6415 |
renamings can be supplied to meet this requirement. |
| 6416 |
The usage of this attribute is best illustrated by a simple example, taken |
| 6417 |
from the GNAT implementation of package Ada.Strings.Unbounded: |
| 6418 |
|
| 6419 |
|
| 6420 |
.. code-block:: ada |
| 6421 |
|
| 6422 |
function To_Unbounded (S : String) return Unbounded_String |
| 6423 |
renames To_Unbounded_String; |
| 6424 |
|
| 6425 |
pragma Stream_Convert |
| 6426 |
(Unbounded_String, To_Unbounded, To_String); |
| 6427 |
|
| 6428 |
|
| 6429 |
The specifications of the referenced functions, as given in the Ada |
| 6430 |
Reference Manual are: |
| 6431 |
|
| 6432 |
|
| 6433 |
.. code-block:: ada |
| 6434 |
|
| 6435 |
function To_Unbounded_String (Source : String) |
| 6436 |
return Unbounded_String; |
| 6437 |
|
| 6438 |
function To_String (Source : Unbounded_String) |
| 6439 |
return String; |
| 6440 |
|
| 6441 |
|
| 6442 |
The effect is that if the value of an unbounded string is written to a stream, |
| 6443 |
then the representation of the item in the stream is in the same format that |
| 6444 |
would be used for ``Standard.String'Output``, and this same representation |
| 6445 |
is expected when a value of this type is read from the stream. Note that the |
| 6446 |
value written always includes the bounds, even for Unbounded_String'Write, |
| 6447 |
since Unbounded_String is not an array type. |
| 6448 |
|
| 6449 |
Note that the ``Stream_Convert`` pragma is not effective in the case of |
| 6450 |
a derived type of a non-limited tagged type. If such a type is specified then |
| 6451 |
the pragma is silently ignored, and the default implementation of the stream |
| 6452 |
attributes is used instead. |
| 6453 |
|
| 6454 |
Pragma Style_Checks |
| 6455 |
=================== |
| 6456 |
|
| 6457 |
Syntax: |
| 6458 |
|
| 6459 |
|
| 6460 |
:: |
| 6461 |
|
| 6462 |
pragma Style_Checks (string_LITERAL | ALL_CHECKS | |
| 6463 |
On | Off [, LOCAL_NAME]); |
| 6464 |
|
| 6465 |
|
| 6466 |
This pragma is used in conjunction with compiler switches to control the |
| 6467 |
built in style checking provided by GNAT. The compiler switches, if set, |
| 6468 |
provide an initial setting for the switches, and this pragma may be used |
| 6469 |
to modify these settings, or the settings may be provided entirely by |
| 6470 |
the use of the pragma. This pragma can be used anywhere that a pragma |
| 6471 |
is legal, including use as a configuration pragma (including use in |
| 6472 |
the :file:`gnat.adc` file). |
| 6473 |
|
| 6474 |
The form with a string literal specifies which style options are to be |
| 6475 |
activated. These are additive, so they apply in addition to any previously |
| 6476 |
set style check options. The codes for the options are the same as those |
| 6477 |
used in the *-gnaty* switch to *gcc* or *gnatmake*. |
| 6478 |
For example the following two methods can be used to enable |
| 6479 |
layout checking: |
| 6480 |
|
| 6481 |
* |
| 6482 |
|
| 6483 |
:: |
| 6484 |
|
| 6485 |
pragma Style_Checks ("l"); |
| 6486 |
|
| 6487 |
|
| 6488 |
* |
| 6489 |
|
| 6490 |
:: |
| 6491 |
|
| 6492 |
gcc -c -gnatyl ... |
| 6493 |
|
| 6494 |
|
| 6495 |
The form ``ALL_CHECKS`` activates all standard checks (its use is equivalent |
| 6496 |
to the use of the :switch:`gnaty` switch with no options. |
| 6497 |
See the :title:`GNAT User's Guide` for details.) |
| 6498 |
|
| 6499 |
Note: the behavior is slightly different in GNAT mode (:switch:`-gnatg` used). |
| 6500 |
In this case, ``ALL_CHECKS`` implies the standard set of GNAT mode style check |
| 6501 |
options (i.e. equivalent to :switch:`-gnatyg`). |
| 6502 |
|
| 6503 |
The forms with ``Off`` and ``On`` |
| 6504 |
can be used to temporarily disable style checks |
| 6505 |
as shown in the following example: |
| 6506 |
|
| 6507 |
|
| 6508 |
.. code-block:: ada |
| 6509 |
|
| 6510 |
pragma Style_Checks ("k"); -- requires keywords in lower case |
| 6511 |
pragma Style_Checks (Off); -- turn off style checks |
| 6512 |
NULL; -- this will not generate an error message |
| 6513 |
pragma Style_Checks (On); -- turn style checks back on |
| 6514 |
NULL; -- this will generate an error message |
| 6515 |
|
| 6516 |
|
| 6517 |
Finally the two argument form is allowed only if the first argument is |
| 6518 |
``On`` or ``Off``. The effect is to turn of semantic style checks |
| 6519 |
for the specified entity, as shown in the following example: |
| 6520 |
|
| 6521 |
|
| 6522 |
.. code-block:: ada |
| 6523 |
|
| 6524 |
pragma Style_Checks ("r"); -- require consistency of identifier casing |
| 6525 |
Arg : Integer; |
| 6526 |
Rf1 : Integer := ARG; -- incorrect, wrong case |
| 6527 |
pragma Style_Checks (Off, Arg); |
| 6528 |
Rf2 : Integer := ARG; -- OK, no error |
| 6529 |
|
| 6530 |
|
| 6531 |
Pragma Subtitle |
| 6532 |
=============== |
| 6533 |
|
| 6534 |
Syntax: |
| 6535 |
|
| 6536 |
|
| 6537 |
:: |
| 6538 |
|
| 6539 |
pragma Subtitle ([Subtitle =>] STRING_LITERAL); |
| 6540 |
|
| 6541 |
|
| 6542 |
This pragma is recognized for compatibility with other Ada compilers |
| 6543 |
but is ignored by GNAT. |
| 6544 |
|
| 6545 |
Pragma Suppress |
| 6546 |
=============== |
| 6547 |
|
| 6548 |
Syntax: |
| 6549 |
|
| 6550 |
|
| 6551 |
:: |
| 6552 |
|
| 6553 |
pragma Suppress (Identifier [, [On =>] Name]); |
| 6554 |
|
| 6555 |
|
| 6556 |
This is a standard pragma, and supports all the check names required in |
| 6557 |
the RM. It is included here because GNAT recognizes some additional check |
| 6558 |
names that are implementation defined (as permitted by the RM): |
| 6559 |
|
| 6560 |
|
| 6561 |
* |
| 6562 |
``Alignment_Check`` can be used to suppress alignment checks |
| 6563 |
on addresses used in address clauses. Such checks can also be suppressed |
| 6564 |
by suppressing range checks, but the specific use of ``Alignment_Check`` |
| 6565 |
allows suppression of alignment checks without suppressing other range checks. |
| 6566 |
Note that ``Alignment_Check`` is suppressed by default on machines (such as |
| 6567 |
the x86) with non-strict alignment. |
| 6568 |
|
| 6569 |
* |
| 6570 |
``Atomic_Synchronization`` can be used to suppress the special memory |
| 6571 |
synchronization instructions that are normally generated for access to |
| 6572 |
``Atomic`` variables to ensure correct synchronization between tasks |
| 6573 |
that use such variables for synchronization purposes. |
| 6574 |
|
| 6575 |
* |
| 6576 |
``Duplicated_Tag_Check`` Can be used to suppress the check that is generated |
| 6577 |
for a duplicated tag value when a tagged type is declared. |
| 6578 |
|
| 6579 |
* |
| 6580 |
``Container_Checks`` Can be used to suppress all checks within Ada.Containers |
| 6581 |
and instances of its children, including Tampering_Check. |
| 6582 |
|
| 6583 |
* |
| 6584 |
``Tampering_Check`` Can be used to suppress tampering check in the containers. |
| 6585 |
|
| 6586 |
* |
| 6587 |
``Predicate_Check`` can be used to control whether predicate checks are |
| 6588 |
active. It is applicable only to predicates for which the policy is |
| 6589 |
``Check``. Unlike ``Assertion_Policy``, which determines if a given |
| 6590 |
predicate is ignored or checked for the whole program, the use of |
| 6591 |
``Suppress`` and ``Unsuppress`` with this check name allows a given |
| 6592 |
predicate to be turned on and off at specific points in the program. |
| 6593 |
|
| 6594 |
* |
| 6595 |
``Validity_Check`` can be used specifically to control validity checks. |
| 6596 |
If ``Suppress`` is used to suppress validity checks, then no validity |
| 6597 |
checks are performed, including those specified by the appropriate compiler |
| 6598 |
switch or the ``Validity_Checks`` pragma. |
| 6599 |
|
| 6600 |
* |
| 6601 |
Additional check names previously introduced by use of the ``Check_Name`` |
| 6602 |
pragma are also allowed. |
| 6603 |
|
| 6604 |
|
| 6605 |
Note that pragma Suppress gives the compiler permission to omit |
| 6606 |
checks, but does not require the compiler to omit checks. The compiler |
| 6607 |
will generate checks if they are essentially free, even when they are |
| 6608 |
suppressed. In particular, if the compiler can prove that a certain |
| 6609 |
check will necessarily fail, it will generate code to do an |
| 6610 |
unconditional 'raise', even if checks are suppressed. The compiler |
| 6611 |
warns in this case. |
| 6612 |
|
| 6613 |
Of course, run-time checks are omitted whenever the compiler can prove |
| 6614 |
that they will not fail, whether or not checks are suppressed. |
| 6615 |
|
| 6616 |
Pragma Suppress_All |
| 6617 |
=================== |
| 6618 |
|
| 6619 |
Syntax: |
| 6620 |
|
| 6621 |
|
| 6622 |
.. code-block:: ada |
| 6623 |
|
| 6624 |
pragma Suppress_All; |
| 6625 |
|
| 6626 |
|
| 6627 |
This pragma can appear anywhere within a unit. |
| 6628 |
The effect is to apply ``Suppress (All_Checks)`` to the unit |
| 6629 |
in which it appears. This pragma is implemented for compatibility with DEC |
| 6630 |
Ada 83 usage where it appears at the end of a unit, and for compatibility |
| 6631 |
with Rational Ada, where it appears as a program unit pragma. |
| 6632 |
The use of the standard Ada pragma ``Suppress (All_Checks)`` |
| 6633 |
as a normal configuration pragma is the preferred usage in GNAT. |
| 6634 |
|
| 6635 |
.. _Pragma-Suppress_Debug_Info: |
| 6636 |
|
| 6637 |
Pragma Suppress_Debug_Info |
| 6638 |
========================== |
| 6639 |
|
| 6640 |
Syntax: |
| 6641 |
|
| 6642 |
|
| 6643 |
:: |
| 6644 |
|
| 6645 |
pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME); |
| 6646 |
|
| 6647 |
|
| 6648 |
This pragma can be used to suppress generation of debug information |
| 6649 |
for the specified entity. It is intended primarily for use in debugging |
| 6650 |
the debugger, and navigating around debugger problems. |
| 6651 |
|
| 6652 |
Pragma Suppress_Exception_Locations |
| 6653 |
=================================== |
| 6654 |
|
| 6655 |
Syntax: |
| 6656 |
|
| 6657 |
|
| 6658 |
.. code-block:: ada |
| 6659 |
|
| 6660 |
pragma Suppress_Exception_Locations; |
| 6661 |
|
| 6662 |
|
| 6663 |
In normal mode, a raise statement for an exception by default generates |
| 6664 |
an exception message giving the file name and line number for the location |
| 6665 |
of the raise. This is useful for debugging and logging purposes, but this |
| 6666 |
entails extra space for the strings for the messages. The configuration |
| 6667 |
pragma ``Suppress_Exception_Locations`` can be used to suppress the |
| 6668 |
generation of these strings, with the result that space is saved, but the |
| 6669 |
exception message for such raises is null. This configuration pragma may |
| 6670 |
appear in a global configuration pragma file, or in a specific unit as |
| 6671 |
usual. It is not required that this pragma be used consistently within |
| 6672 |
a partition, so it is fine to have some units within a partition compiled |
| 6673 |
with this pragma and others compiled in normal mode without it. |
| 6674 |
|
| 6675 |
.. _Pragma-Suppress_Initialization: |
| 6676 |
|
| 6677 |
Pragma Suppress_Initialization |
| 6678 |
============================== |
| 6679 |
.. index:: Suppressing initialization |
| 6680 |
|
| 6681 |
.. index:: Initialization, suppression of |
| 6682 |
|
| 6683 |
Syntax: |
| 6684 |
|
| 6685 |
|
| 6686 |
:: |
| 6687 |
|
| 6688 |
pragma Suppress_Initialization ([Entity =>] variable_or_subtype_Name); |
| 6689 |
|
| 6690 |
|
| 6691 |
Here variable_or_subtype_Name is the name introduced by a type declaration |
| 6692 |
or subtype declaration or the name of a variable introduced by an |
| 6693 |
object declaration. |
| 6694 |
|
| 6695 |
In the case of a type or subtype |
| 6696 |
this pragma suppresses any implicit or explicit initialization |
| 6697 |
for all variables of the given type or subtype, |
| 6698 |
including initialization resulting from the use of pragmas |
| 6699 |
Normalize_Scalars or Initialize_Scalars. |
| 6700 |
|
| 6701 |
This is considered a representation item, so it cannot be given after |
| 6702 |
the type is frozen. It applies to all subsequent object declarations, |
| 6703 |
and also any allocator that creates objects of the type. |
| 6704 |
|
| 6705 |
If the pragma is given for the first subtype, then it is considered |
| 6706 |
to apply to the base type and all its subtypes. If the pragma is given |
| 6707 |
for other than a first subtype, then it applies only to the given subtype. |
| 6708 |
The pragma may not be given after the type is frozen. |
| 6709 |
|
| 6710 |
Note that this includes eliminating initialization of discriminants |
| 6711 |
for discriminated types, and tags for tagged types. In these cases, |
| 6712 |
you will have to use some non-portable mechanism (e.g. address |
| 6713 |
overlays or unchecked conversion) to achieve required initialization |
| 6714 |
of these fields before accessing any object of the corresponding type. |
| 6715 |
|
| 6716 |
For the variable case, implicit initialization for the named variable |
| 6717 |
is suppressed, just as though its subtype had been given in a pragma |
| 6718 |
Suppress_Initialization, as described above. |
| 6719 |
|
| 6720 |
Pragma Task_Name |
| 6721 |
================ |
| 6722 |
|
| 6723 |
Syntax |
| 6724 |
|
| 6725 |
|
| 6726 |
.. code-block:: ada |
| 6727 |
|
| 6728 |
pragma Task_Name (string_EXPRESSION); |
| 6729 |
|
| 6730 |
|
| 6731 |
This pragma appears within a task definition (like pragma |
| 6732 |
``Priority``) and applies to the task in which it appears. The |
| 6733 |
argument must be of type String, and provides a name to be used for |
| 6734 |
the task instance when the task is created. Note that this expression |
| 6735 |
is not required to be static, and in particular, it can contain |
| 6736 |
references to task discriminants. This facility can be used to |
| 6737 |
provide different names for different tasks as they are created, |
| 6738 |
as illustrated in the example below. |
| 6739 |
|
| 6740 |
The task name is recorded internally in the run-time structures |
| 6741 |
and is accessible to tools like the debugger. In addition the |
| 6742 |
routine ``Ada.Task_Identification.Image`` will return this |
| 6743 |
string, with a unique task address appended. |
| 6744 |
|
| 6745 |
|
| 6746 |
.. code-block:: ada |
| 6747 |
|
| 6748 |
-- Example of the use of pragma Task_Name |
| 6749 |
|
| 6750 |
with Ada.Task_Identification; |
| 6751 |
use Ada.Task_Identification; |
| 6752 |
with Text_IO; use Text_IO; |
| 6753 |
procedure t3 is |
| 6754 |
|
| 6755 |
type Astring is access String; |
| 6756 |
|
| 6757 |
task type Task_Typ (Name : access String) is |
| 6758 |
pragma Task_Name (Name.all); |
| 6759 |
end Task_Typ; |
| 6760 |
|
| 6761 |
task body Task_Typ is |
| 6762 |
Nam : constant String := Image (Current_Task); |
| 6763 |
begin |
| 6764 |
Put_Line ("-->" & Nam (1 .. 14) & "<--"); |
| 6765 |
end Task_Typ; |
| 6766 |
|
| 6767 |
type Ptr_Task is access Task_Typ; |
| 6768 |
Task_Var : Ptr_Task; |
| 6769 |
|
| 6770 |
begin |
| 6771 |
Task_Var := |
| 6772 |
new Task_Typ (new String'("This is task 1")); |
| 6773 |
Task_Var := |
| 6774 |
new Task_Typ (new String'("This is task 2")); |
| 6775 |
end; |
| 6776 |
|
| 6777 |
|
| 6778 |
Pragma Task_Storage |
| 6779 |
=================== |
| 6780 |
Syntax: |
| 6781 |
|
| 6782 |
|
| 6783 |
:: |
| 6784 |
|
| 6785 |
pragma Task_Storage ( |
| 6786 |
[Task_Type =>] LOCAL_NAME, |
| 6787 |
[Top_Guard =>] static_integer_EXPRESSION); |
| 6788 |
|
| 6789 |
|
| 6790 |
This pragma specifies the length of the guard area for tasks. The guard |
| 6791 |
area is an additional storage area allocated to a task. A value of zero |
| 6792 |
means that either no guard area is created or a minimal guard area is |
| 6793 |
created, depending on the target. This pragma can appear anywhere a |
| 6794 |
``Storage_Size`` attribute definition clause is allowed for a task |
| 6795 |
type. |
| 6796 |
|
| 6797 |
.. _Pragma-Test_Case: |
| 6798 |
|
| 6799 |
Pragma Test_Case |
| 6800 |
================ |
| 6801 |
.. index:: Test cases |
| 6802 |
|
| 6803 |
|
| 6804 |
Syntax: |
| 6805 |
|
| 6806 |
|
| 6807 |
:: |
| 6808 |
|
| 6809 |
pragma Test_Case ( |
| 6810 |
[Name =>] static_string_Expression |
| 6811 |
,[Mode =>] (Nominal | Robustness) |
| 6812 |
[, Requires => Boolean_Expression] |
| 6813 |
[, Ensures => Boolean_Expression]); |
| 6814 |
|
| 6815 |
|
| 6816 |
The ``Test_Case`` pragma allows defining fine-grain specifications |
| 6817 |
for use by testing tools. |
| 6818 |
The compiler checks the validity of the ``Test_Case`` pragma, but its |
| 6819 |
presence does not lead to any modification of the code generated by the |
| 6820 |
compiler. |
| 6821 |
|
| 6822 |
``Test_Case`` pragmas may only appear immediately following the |
| 6823 |
(separate) declaration of a subprogram in a package declaration, inside |
| 6824 |
a package spec unit. Only other pragmas may intervene (that is appear |
| 6825 |
between the subprogram declaration and a test case). |
| 6826 |
|
| 6827 |
The compiler checks that boolean expressions given in ``Requires`` and |
| 6828 |
``Ensures`` are valid, where the rules for ``Requires`` are the |
| 6829 |
same as the rule for an expression in ``Precondition`` and the rules |
| 6830 |
for ``Ensures`` are the same as the rule for an expression in |
| 6831 |
``Postcondition``. In particular, attributes ``'Old`` and |
| 6832 |
``'Result`` can only be used within the ``Ensures`` |
| 6833 |
expression. The following is an example of use within a package spec: |
| 6834 |
|
| 6835 |
|
| 6836 |
.. code-block:: ada |
| 6837 |
|
| 6838 |
package Math_Functions is |
| 6839 |
... |
| 6840 |
function Sqrt (Arg : Float) return Float; |
| 6841 |
pragma Test_Case (Name => "Test 1", |
| 6842 |
Mode => Nominal, |
| 6843 |
Requires => Arg < 10000.0, |
| 6844 |
Ensures => Sqrt'Result < 10.0); |
| 6845 |
... |
| 6846 |
end Math_Functions; |
| 6847 |
|
| 6848 |
|
| 6849 |
The meaning of a test case is that there is at least one context where |
| 6850 |
``Requires`` holds such that, if the associated subprogram is executed in |
| 6851 |
that context, then ``Ensures`` holds when the subprogram returns. |
| 6852 |
Mode ``Nominal`` indicates that the input context should also satisfy the |
| 6853 |
precondition of the subprogram, and the output context should also satisfy its |
| 6854 |
postcondition. Mode ``Robustness`` indicates that the precondition and |
| 6855 |
postcondition of the subprogram should be ignored for this test case. |
| 6856 |
|
| 6857 |
.. _Pragma-Thread_Local_Storage: |
| 6858 |
|
| 6859 |
Pragma Thread_Local_Storage |
| 6860 |
=========================== |
| 6861 |
.. index:: Task specific storage |
| 6862 |
|
| 6863 |
.. index:: TLS (Thread Local Storage) |
| 6864 |
|
| 6865 |
.. index:: Task_Attributes |
| 6866 |
|
| 6867 |
Syntax: |
| 6868 |
|
| 6869 |
|
| 6870 |
:: |
| 6871 |
|
| 6872 |
pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME); |
| 6873 |
|
| 6874 |
|
| 6875 |
This pragma specifies that the specified entity, which must be |
| 6876 |
a variable declared in a library-level package, is to be marked as |
| 6877 |
"Thread Local Storage" (``TLS``). On systems supporting this (which |
| 6878 |
include Windows, Solaris, GNU/Linux, and VxWorks), this causes each |
| 6879 |
thread (and hence each Ada task) to see a distinct copy of the variable. |
| 6880 |
|
| 6881 |
The variable must not have default initialization, and if there is |
| 6882 |
an explicit initialization, it must be either ``null`` for an |
| 6883 |
access variable, a static expression for a scalar variable, or a fully |
| 6884 |
static aggregate for a composite type, that is to say, an aggregate all |
| 6885 |
of whose components are static, and which does not include packed or |
| 6886 |
discriminated components. |
| 6887 |
|
| 6888 |
This provides a low-level mechanism similar to that provided by |
| 6889 |
the ``Ada.Task_Attributes`` package, but much more efficient |
| 6890 |
and is also useful in writing interface code that will interact |
| 6891 |
with foreign threads. |
| 6892 |
|
| 6893 |
If this pragma is used on a system where ``TLS`` is not supported, |
| 6894 |
then an error message will be generated and the program will be rejected. |
| 6895 |
|
| 6896 |
Pragma Time_Slice |
| 6897 |
================= |
| 6898 |
|
| 6899 |
Syntax: |
| 6900 |
|
| 6901 |
|
| 6902 |
.. code-block:: ada |
| 6903 |
|
| 6904 |
pragma Time_Slice (static_duration_EXPRESSION); |
| 6905 |
|
| 6906 |
|
| 6907 |
For implementations of GNAT on operating systems where it is possible |
| 6908 |
to supply a time slice value, this pragma may be used for this purpose. |
| 6909 |
It is ignored if it is used in a system that does not allow this control, |
| 6910 |
or if it appears in other than the main program unit. |
| 6911 |
|
| 6912 |
Pragma Title |
| 6913 |
============ |
| 6914 |
|
| 6915 |
Syntax: |
| 6916 |
|
| 6917 |
|
| 6918 |
:: |
| 6919 |
|
| 6920 |
pragma Title (TITLING_OPTION [, TITLING OPTION]); |
| 6921 |
|
| 6922 |
TITLING_OPTION ::= |
| 6923 |
[Title =>] STRING_LITERAL, |
| 6924 |
| [Subtitle =>] STRING_LITERAL |
| 6925 |
|
| 6926 |
|
| 6927 |
Syntax checked but otherwise ignored by GNAT. This is a listing control |
| 6928 |
pragma used in DEC Ada 83 implementations to provide a title and/or |
| 6929 |
subtitle for the program listing. The program listing generated by GNAT |
| 6930 |
does not have titles or subtitles. |
| 6931 |
|
| 6932 |
Unlike other pragmas, the full flexibility of named notation is allowed |
| 6933 |
for this pragma, i.e., the parameters may be given in any order if named |
| 6934 |
notation is used, and named and positional notation can be mixed |
| 6935 |
following the normal rules for procedure calls in Ada. |
| 6936 |
|
| 6937 |
Pragma Type_Invariant |
| 6938 |
===================== |
| 6939 |
|
| 6940 |
Syntax: |
| 6941 |
|
| 6942 |
|
| 6943 |
:: |
| 6944 |
|
| 6945 |
pragma Type_Invariant |
| 6946 |
([Entity =>] type_LOCAL_NAME, |
| 6947 |
[Check =>] EXPRESSION); |
| 6948 |
|
| 6949 |
|
| 6950 |
The ``Type_Invariant`` pragma is intended to be an exact |
| 6951 |
replacement for the language-defined ``Type_Invariant`` |
| 6952 |
aspect, and shares its restrictions and semantics. It differs |
| 6953 |
from the language defined ``Invariant`` pragma in that it |
| 6954 |
does not permit a string parameter, and it is |
| 6955 |
controlled by the assertion identifier ``Type_Invariant`` |
| 6956 |
rather than ``Invariant``. |
| 6957 |
|
| 6958 |
.. _Pragma-Type_Invariant_Class: |
| 6959 |
|
| 6960 |
Pragma Type_Invariant_Class |
| 6961 |
=========================== |
| 6962 |
|
| 6963 |
Syntax: |
| 6964 |
|
| 6965 |
|
| 6966 |
:: |
| 6967 |
|
| 6968 |
pragma Type_Invariant_Class |
| 6969 |
([Entity =>] type_LOCAL_NAME, |
| 6970 |
[Check =>] EXPRESSION); |
| 6971 |
|
| 6972 |
|
| 6973 |
The ``Type_Invariant_Class`` pragma is intended to be an exact |
| 6974 |
replacement for the language-defined ``Type_Invariant'Class`` |
| 6975 |
aspect, and shares its restrictions and semantics. |
| 6976 |
|
| 6977 |
Note: This pragma is called ``Type_Invariant_Class`` rather than |
| 6978 |
``Type_Invariant'Class`` because the latter would not be strictly |
| 6979 |
conforming to the allowed syntax for pragmas. The motivation |
| 6980 |
for providing pragmas equivalent to the aspects is to allow a program |
| 6981 |
to be written using the pragmas, and then compiled if necessary |
| 6982 |
using an Ada compiler that does not recognize the pragmas or |
| 6983 |
aspects, but is prepared to ignore the pragmas. The assertion |
| 6984 |
policy that controls this pragma is ``Type_Invariant'Class``, |
| 6985 |
not ``Type_Invariant_Class``. |
| 6986 |
|
| 6987 |
Pragma Unchecked_Union |
| 6988 |
====================== |
| 6989 |
.. index:: Unions in C |
| 6990 |
|
| 6991 |
|
| 6992 |
Syntax: |
| 6993 |
|
| 6994 |
|
| 6995 |
.. code-block:: ada |
| 6996 |
|
| 6997 |
pragma Unchecked_Union (first_subtype_LOCAL_NAME); |
| 6998 |
|
| 6999 |
|
| 7000 |
This pragma is used to specify a representation of a record type that is |
| 7001 |
equivalent to a C union. It was introduced as a GNAT implementation defined |
| 7002 |
pragma in the GNAT Ada 95 mode. Ada 2005 includes an extended version of this |
| 7003 |
pragma, making it language defined, and GNAT fully implements this extended |
| 7004 |
version in all language modes (Ada 83, Ada 95, and Ada 2005). For full |
| 7005 |
details, consult the Ada 2012 Reference Manual, section B.3.3. |
| 7006 |
|
| 7007 |
Pragma Unevaluated_Use_Of_Old |
| 7008 |
============================= |
| 7009 |
.. index:: Attribute Old |
| 7010 |
|
| 7011 |
.. index:: Attribute Loop_Entry |
| 7012 |
|
| 7013 |
.. index:: Unevaluated_Use_Of_Old |
| 7014 |
|
| 7015 |
|
| 7016 |
Syntax: |
| 7017 |
|
| 7018 |
|
| 7019 |
.. code-block:: ada |
| 7020 |
|
| 7021 |
pragma Unevaluated_Use_Of_Old (Error | Warn | Allow); |
| 7022 |
|
| 7023 |
|
| 7024 |
This pragma controls the processing of attributes Old and Loop_Entry. |
| 7025 |
If either of these attributes is used in a potentially unevaluated |
| 7026 |
expression (e.g. the then or else parts of an if expression), then |
| 7027 |
normally this usage is considered illegal if the prefix of the attribute |
| 7028 |
is other than an entity name. The language requires this |
| 7029 |
behavior for Old, and GNAT copies the same rule for Loop_Entry. |
| 7030 |
|
| 7031 |
The reason for this rule is that otherwise, we can have a situation |
| 7032 |
where we save the Old value, and this results in an exception, even |
| 7033 |
though we might not evaluate the attribute. Consider this example: |
| 7034 |
|
| 7035 |
|
| 7036 |
.. code-block:: ada |
| 7037 |
|
| 7038 |
package UnevalOld is |
| 7039 |
K : Character; |
| 7040 |
procedure U (A : String; C : Boolean) -- ERROR |
| 7041 |
with Post => (if C then A(1)'Old = K else True); |
| 7042 |
end; |
| 7043 |
|
| 7044 |
|
| 7045 |
If procedure U is called with a string with a lower bound of 2, and |
| 7046 |
C false, then an exception would be raised trying to evaluate A(1) |
| 7047 |
on entry even though the value would not be actually used. |
| 7048 |
|
| 7049 |
Although the rule guarantees against this possibility, it is sometimes |
| 7050 |
too restrictive. For example if we know that the string has a lower |
| 7051 |
bound of 1, then we will never raise an exception. |
| 7052 |
The pragma ``Unevaluated_Use_Of_Old`` can be |
| 7053 |
used to modify this behavior. If the argument is ``Error`` then an |
| 7054 |
error is given (this is the default RM behavior). If the argument is |
| 7055 |
``Warn`` then the usage is allowed as legal but with a warning |
| 7056 |
that an exception might be raised. If the argument is ``Allow`` |
| 7057 |
then the usage is allowed as legal without generating a warning. |
| 7058 |
|
| 7059 |
This pragma may appear as a configuration pragma, or in a declarative |
| 7060 |
part or package specification. In the latter case it applies to |
| 7061 |
uses up to the end of the corresponding statement sequence or |
| 7062 |
sequence of package declarations. |
| 7063 |
|
| 7064 |
Pragma Unimplemented_Unit |
| 7065 |
========================= |
| 7066 |
|
| 7067 |
Syntax: |
| 7068 |
|
| 7069 |
|
| 7070 |
.. code-block:: ada |
| 7071 |
|
| 7072 |
pragma Unimplemented_Unit; |
| 7073 |
|
| 7074 |
|
| 7075 |
If this pragma occurs in a unit that is processed by the compiler, GNAT |
| 7076 |
aborts with the message :samp:`xxx not implemented`, where |
| 7077 |
``xxx`` is the name of the current compilation unit. This pragma is |
| 7078 |
intended to allow the compiler to handle unimplemented library units in |
| 7079 |
a clean manner. |
| 7080 |
|
| 7081 |
The abort only happens if code is being generated. Thus you can use |
| 7082 |
specs of unimplemented packages in syntax or semantic checking mode. |
| 7083 |
|
| 7084 |
.. _Pragma-Universal_Aliasing: |
| 7085 |
|
| 7086 |
Pragma Universal_Aliasing |
| 7087 |
========================= |
| 7088 |
|
| 7089 |
Syntax: |
| 7090 |
|
| 7091 |
|
| 7092 |
:: |
| 7093 |
|
| 7094 |
pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)]; |
| 7095 |
|
| 7096 |
|
| 7097 |
``type_LOCAL_NAME`` must refer to a type declaration in the current |
| 7098 |
declarative part. The effect is to inhibit strict type-based aliasing |
| 7099 |
optimization for the given type. In other words, the effect is as though |
| 7100 |
access types designating this type were subject to pragma No_Strict_Aliasing. |
| 7101 |
For a detailed description of the strict aliasing optimization, and the |
| 7102 |
situations in which it must be suppressed, see the section on |
| 7103 |
``Optimization and Strict Aliasing`` in the :title:`GNAT User's Guide`. |
| 7104 |
|
| 7105 |
.. _Pragma-Unmodified: |
| 7106 |
|
| 7107 |
Pragma Unmodified |
| 7108 |
================= |
| 7109 |
.. index:: Warnings, unmodified |
| 7110 |
|
| 7111 |
Syntax: |
| 7112 |
|
| 7113 |
|
| 7114 |
:: |
| 7115 |
|
| 7116 |
pragma Unmodified (LOCAL_NAME {, LOCAL_NAME}); |
| 7117 |
|
| 7118 |
|
| 7119 |
This pragma signals that the assignable entities (variables, |
| 7120 |
``out`` parameters, ``in out`` parameters) whose names are listed are |
| 7121 |
deliberately not assigned in the current source unit. This |
| 7122 |
suppresses warnings about the |
| 7123 |
entities being referenced but not assigned, and in addition a warning will be |
| 7124 |
generated if one of these entities is in fact assigned in the |
| 7125 |
same unit as the pragma (or in the corresponding body, or one |
| 7126 |
of its subunits). |
| 7127 |
|
| 7128 |
This is particularly useful for clearly signaling that a particular |
| 7129 |
parameter is not modified, even though the spec suggests that it might |
| 7130 |
be. |
| 7131 |
|
| 7132 |
For the variable case, warnings are never given for unreferenced variables |
| 7133 |
whose name contains one of the substrings |
| 7134 |
``DISCARD, DUMMY, IGNORE, JUNK, UNUSE, TMP, TEMP`` in any casing. Such names |
| 7135 |
are typically to be used in cases where such warnings are expected. |
| 7136 |
Thus it is never necessary to use ``pragma Unmodified`` for such |
| 7137 |
variables, though it is harmless to do so. |
| 7138 |
|
| 7139 |
.. _Pragma-Unreferenced: |
| 7140 |
|
| 7141 |
Pragma Unreferenced |
| 7142 |
=================== |
| 7143 |
.. index:: Warnings, unreferenced |
| 7144 |
|
| 7145 |
Syntax: |
| 7146 |
|
| 7147 |
|
| 7148 |
:: |
| 7149 |
|
| 7150 |
pragma Unreferenced (LOCAL_NAME {, LOCAL_NAME}); |
| 7151 |
pragma Unreferenced (library_unit_NAME {, library_unit_NAME}); |
| 7152 |
|
| 7153 |
|
| 7154 |
This pragma signals that the entities whose names are listed are |
| 7155 |
deliberately not referenced in the current source unit after the |
| 7156 |
occurrence of the pragma. This |
| 7157 |
suppresses warnings about the |
| 7158 |
entities being unreferenced, and in addition a warning will be |
| 7159 |
generated if one of these entities is in fact subsequently referenced in the |
| 7160 |
same unit as the pragma (or in the corresponding body, or one |
| 7161 |
of its subunits). |
| 7162 |
|
| 7163 |
This is particularly useful for clearly signaling that a particular |
| 7164 |
parameter is not referenced in some particular subprogram implementation |
| 7165 |
and that this is deliberate. It can also be useful in the case of |
| 7166 |
objects declared only for their initialization or finalization side |
| 7167 |
effects. |
| 7168 |
|
| 7169 |
If ``LOCAL_NAME`` identifies more than one matching homonym in the |
| 7170 |
current scope, then the entity most recently declared is the one to which |
| 7171 |
the pragma applies. Note that in the case of accept formals, the pragma |
| 7172 |
Unreferenced may appear immediately after the keyword ``do`` which |
| 7173 |
allows the indication of whether or not accept formals are referenced |
| 7174 |
or not to be given individually for each accept statement. |
| 7175 |
|
| 7176 |
The left hand side of an assignment does not count as a reference for the |
| 7177 |
purpose of this pragma. Thus it is fine to assign to an entity for which |
| 7178 |
pragma Unreferenced is given. However, use of an entity as an actual for |
| 7179 |
an out parameter does count as a reference unless warnings for unread output |
| 7180 |
parameters are enabled via :switch:`-gnatw.o`. |
| 7181 |
|
| 7182 |
Note that if a warning is desired for all calls to a given subprogram, |
| 7183 |
regardless of whether they occur in the same unit as the subprogram |
| 7184 |
declaration, then this pragma should not be used (calls from another |
| 7185 |
unit would not be flagged); pragma Obsolescent can be used instead |
| 7186 |
for this purpose, see :ref:`Pragma_Obsolescent`. |
| 7187 |
|
| 7188 |
The second form of pragma ``Unreferenced`` is used within a context |
| 7189 |
clause. In this case the arguments must be unit names of units previously |
| 7190 |
mentioned in ``with`` clauses (similar to the usage of pragma |
| 7191 |
``Elaborate_All``). The effect is to suppress warnings about unreferenced |
| 7192 |
units and unreferenced entities within these units. |
| 7193 |
|
| 7194 |
For the variable case, warnings are never given for unreferenced variables |
| 7195 |
whose name contains one of the substrings |
| 7196 |
``DISCARD, DUMMY, IGNORE, JUNK, UNUSED`` in any casing. Such names |
| 7197 |
are typically to be used in cases where such warnings are expected. |
| 7198 |
Thus it is never necessary to use ``pragma Unreferenced`` for such |
| 7199 |
variables, though it is harmless to do so. |
| 7200 |
|
| 7201 |
.. _Pragma-Unreferenced_Objects: |
| 7202 |
|
| 7203 |
Pragma Unreferenced_Objects |
| 7204 |
=========================== |
| 7205 |
.. index:: Warnings, unreferenced |
| 7206 |
|
| 7207 |
Syntax: |
| 7208 |
|
| 7209 |
|
| 7210 |
:: |
| 7211 |
|
| 7212 |
pragma Unreferenced_Objects (local_subtype_NAME {, local_subtype_NAME}); |
| 7213 |
|
| 7214 |
|
| 7215 |
This pragma signals that for the types or subtypes whose names are |
| 7216 |
listed, objects which are declared with one of these types or subtypes may |
| 7217 |
not be referenced, and if no references appear, no warnings are given. |
| 7218 |
|
| 7219 |
This is particularly useful for objects which are declared solely for their |
| 7220 |
initialization and finalization effect. Such variables are sometimes referred |
| 7221 |
to as RAII variables (Resource Acquisition Is Initialization). Using this |
| 7222 |
pragma on the relevant type (most typically a limited controlled type), the |
| 7223 |
compiler will automatically suppress unwanted warnings about these variables |
| 7224 |
not being referenced. |
| 7225 |
|
| 7226 |
Pragma Unreserve_All_Interrupts |
| 7227 |
=============================== |
| 7228 |
|
| 7229 |
Syntax: |
| 7230 |
|
| 7231 |
|
| 7232 |
.. code-block:: ada |
| 7233 |
|
| 7234 |
pragma Unreserve_All_Interrupts; |
| 7235 |
|
| 7236 |
|
| 7237 |
Normally certain interrupts are reserved to the implementation. Any attempt |
| 7238 |
to attach an interrupt causes Program_Error to be raised, as described in |
| 7239 |
RM C.3.2(22). A typical example is the ``SIGINT`` interrupt used in |
| 7240 |
many systems for a :kbd:`Ctrl-C` interrupt. Normally this interrupt is |
| 7241 |
reserved to the implementation, so that :kbd:`Ctrl-C` can be used to |
| 7242 |
interrupt execution. |
| 7243 |
|
| 7244 |
If the pragma ``Unreserve_All_Interrupts`` appears anywhere in any unit in |
| 7245 |
a program, then all such interrupts are unreserved. This allows the |
| 7246 |
program to handle these interrupts, but disables their standard |
| 7247 |
functions. For example, if this pragma is used, then pressing |
| 7248 |
:kbd:`Ctrl-C` will not automatically interrupt execution. However, |
| 7249 |
a program can then handle the ``SIGINT`` interrupt as it chooses. |
| 7250 |
|
| 7251 |
For a full list of the interrupts handled in a specific implementation, |
| 7252 |
see the source code for the spec of ``Ada.Interrupts.Names`` in |
| 7253 |
file :file:`a-intnam.ads`. This is a target dependent file that contains the |
| 7254 |
list of interrupts recognized for a given target. The documentation in |
| 7255 |
this file also specifies what interrupts are affected by the use of |
| 7256 |
the ``Unreserve_All_Interrupts`` pragma. |
| 7257 |
|
| 7258 |
For a more general facility for controlling what interrupts can be |
| 7259 |
handled, see pragma ``Interrupt_State``, which subsumes the functionality |
| 7260 |
of the ``Unreserve_All_Interrupts`` pragma. |
| 7261 |
|
| 7262 |
Pragma Unsuppress |
| 7263 |
================= |
| 7264 |
|
| 7265 |
Syntax: |
| 7266 |
|
| 7267 |
|
| 7268 |
:: |
| 7269 |
|
| 7270 |
pragma Unsuppress (IDENTIFIER [, [On =>] NAME]); |
| 7271 |
|
| 7272 |
|
| 7273 |
This pragma undoes the effect of a previous pragma ``Suppress``. If |
| 7274 |
there is no corresponding pragma ``Suppress`` in effect, it has no |
| 7275 |
effect. The range of the effect is the same as for pragma |
| 7276 |
``Suppress``. The meaning of the arguments is identical to that used |
| 7277 |
in pragma ``Suppress``. |
| 7278 |
|
| 7279 |
One important application is to ensure that checks are on in cases where |
| 7280 |
code depends on the checks for its correct functioning, so that the code |
| 7281 |
will compile correctly even if the compiler switches are set to suppress |
| 7282 |
checks. For example, in a program that depends on external names of tagged |
| 7283 |
types and wants to ensure that the duplicated tag check occurs even if all |
| 7284 |
run-time checks are suppressed by a compiler switch, the following |
| 7285 |
configuration pragma will ensure this test is not suppressed: |
| 7286 |
|
| 7287 |
|
| 7288 |
.. code-block:: ada |
| 7289 |
|
| 7290 |
pragma Unsuppress (Duplicated_Tag_Check); |
| 7291 |
|
| 7292 |
|
| 7293 |
This pragma is standard in Ada 2005. It is available in all earlier versions |
| 7294 |
of Ada as an implementation-defined pragma. |
| 7295 |
|
| 7296 |
Note that in addition to the checks defined in the Ada RM, GNAT recognizes a |
| 7297 |
number of implementation-defined check names. See the description of pragma |
| 7298 |
``Suppress`` for full details. |
| 7299 |
|
| 7300 |
.. _Pragma-Unused: |
| 7301 |
|
| 7302 |
Pragma Unused |
| 7303 |
============= |
| 7304 |
.. index:: Warnings, unused |
| 7305 |
|
| 7306 |
Syntax: |
| 7307 |
|
| 7308 |
|
| 7309 |
:: |
| 7310 |
|
| 7311 |
pragma Unused (LOCAL_NAME {, LOCAL_NAME}); |
| 7312 |
|
| 7313 |
|
| 7314 |
This pragma signals that the assignable entities (variables, |
| 7315 |
``out`` parameters, and ``in out`` parameters) whose names are listed |
| 7316 |
deliberately do not get assigned or referenced in the current source unit |
| 7317 |
after the occurrence of the pragma in the current source unit. This |
| 7318 |
suppresses warnings about the entities that are unreferenced and/or not |
| 7319 |
assigned, and, in addition, a warning will be generated if one of these |
| 7320 |
entities gets assigned or subsequently referenced in the same unit as the |
| 7321 |
pragma (in the corresponding body or one of its subunits). |
| 7322 |
|
| 7323 |
This is particularly useful for clearly signaling that a particular |
| 7324 |
parameter is not modified or referenced, even though the spec suggests |
| 7325 |
that it might be. |
| 7326 |
|
| 7327 |
For the variable case, warnings are never given for unreferenced |
| 7328 |
variables whose name contains one of the substrings |
| 7329 |
``DISCARD, DUMMY, IGNORE, JUNK, UNUSED`` in any casing. Such names |
| 7330 |
are typically to be used in cases where such warnings are expected. |
| 7331 |
Thus it is never necessary to use ``pragma Unused`` for such |
| 7332 |
variables, though it is harmless to do so. |
| 7333 |
|
| 7334 |
Pragma Use_VADS_Size |
| 7335 |
==================== |
| 7336 |
.. index:: Size, VADS compatibility |
| 7337 |
|
| 7338 |
.. index:: Rational profile |
| 7339 |
|
| 7340 |
|
| 7341 |
Syntax: |
| 7342 |
|
| 7343 |
|
| 7344 |
.. code-block:: ada |
| 7345 |
|
| 7346 |
pragma Use_VADS_Size; |
| 7347 |
|
| 7348 |
|
| 7349 |
This is a configuration pragma. In a unit to which it applies, any use |
| 7350 |
of the 'Size attribute is automatically interpreted as a use of the |
| 7351 |
'VADS_Size attribute. Note that this may result in incorrect semantic |
| 7352 |
processing of valid Ada 95 or Ada 2005 programs. This is intended to aid in |
| 7353 |
the handling of existing code which depends on the interpretation of Size |
| 7354 |
as implemented in the VADS compiler. See description of the VADS_Size |
| 7355 |
attribute for further details. |
| 7356 |
|
| 7357 |
Pragma Validity_Checks |
| 7358 |
====================== |
| 7359 |
|
| 7360 |
Syntax: |
| 7361 |
|
| 7362 |
|
| 7363 |
.. code-block:: ada |
| 7364 |
|
| 7365 |
pragma Validity_Checks (string_LITERAL | ALL_CHECKS | On | Off); |
| 7366 |
|
| 7367 |
|
| 7368 |
This pragma is used in conjunction with compiler switches to control the |
| 7369 |
built-in validity checking provided by GNAT. The compiler switches, if set |
| 7370 |
provide an initial setting for the switches, and this pragma may be used |
| 7371 |
to modify these settings, or the settings may be provided entirely by |
| 7372 |
the use of the pragma. This pragma can be used anywhere that a pragma |
| 7373 |
is legal, including use as a configuration pragma (including use in |
| 7374 |
the :file:`gnat.adc` file). |
| 7375 |
|
| 7376 |
The form with a string literal specifies which validity options are to be |
| 7377 |
activated. The validity checks are first set to include only the default |
| 7378 |
reference manual settings, and then a string of letters in the string |
| 7379 |
specifies the exact set of options required. The form of this string |
| 7380 |
is exactly as described for the *-gnatVx* compiler switch (see the |
| 7381 |
GNAT User's Guide for details). For example the following two |
| 7382 |
methods can be used to enable validity checking for mode ``in`` and |
| 7383 |
``in out`` subprogram parameters: |
| 7384 |
|
| 7385 |
* |
| 7386 |
|
| 7387 |
.. code-block:: ada |
| 7388 |
|
| 7389 |
pragma Validity_Checks ("im"); |
| 7390 |
|
| 7391 |
|
| 7392 |
* |
| 7393 |
|
| 7394 |
.. code-block:: sh |
| 7395 |
|
| 7396 |
$ gcc -c -gnatVim ... |
| 7397 |
|
| 7398 |
|
| 7399 |
The form ALL_CHECKS activates all standard checks (its use is equivalent |
| 7400 |
to the use of the :switch:`gnatVa` switch). |
| 7401 |
|
| 7402 |
The forms with ``Off`` and ``On`` can be used to temporarily disable |
| 7403 |
validity checks as shown in the following example: |
| 7404 |
|
| 7405 |
|
| 7406 |
.. code-block:: ada |
| 7407 |
|
| 7408 |
pragma Validity_Checks ("c"); -- validity checks for copies |
| 7409 |
pragma Validity_Checks (Off); -- turn off validity checks |
| 7410 |
A := B; -- B will not be validity checked |
| 7411 |
pragma Validity_Checks (On); -- turn validity checks back on |
| 7412 |
A := C; -- C will be validity checked |
| 7413 |
|
| 7414 |
.. _Pragma-Volatile: |
| 7415 |
|
| 7416 |
Pragma Volatile |
| 7417 |
=============== |
| 7418 |
|
| 7419 |
Syntax: |
| 7420 |
|
| 7421 |
|
| 7422 |
.. code-block:: ada |
| 7423 |
|
| 7424 |
pragma Volatile (LOCAL_NAME); |
| 7425 |
|
| 7426 |
|
| 7427 |
This pragma is defined by the Ada Reference Manual, and the GNAT |
| 7428 |
implementation is fully conformant with this definition. The reason it |
| 7429 |
is mentioned in this section is that a pragma of the same name was supplied |
| 7430 |
in some Ada 83 compilers, including DEC Ada 83. The Ada 95 / Ada 2005 |
| 7431 |
implementation of pragma Volatile is upwards compatible with the |
| 7432 |
implementation in DEC Ada 83. |
| 7433 |
|
| 7434 |
.. _Pragma-Volatile_Full_Access: |
| 7435 |
|
| 7436 |
Pragma Volatile_Full_Access |
| 7437 |
=========================== |
| 7438 |
|
| 7439 |
Syntax: |
| 7440 |
|
| 7441 |
|
| 7442 |
.. code-block:: ada |
| 7443 |
|
| 7444 |
pragma Volatile_Full_Access (LOCAL_NAME); |
| 7445 |
|
| 7446 |
|
| 7447 |
This is similar in effect to pragma Volatile, except that any reference to the |
| 7448 |
object is guaranteed to be done only with instructions that read or write all |
| 7449 |
the bits of the object. Furthermore, if the object is of a composite type, |
| 7450 |
then any reference to a subcomponent of the object is guaranteed to read |
| 7451 |
and/or write all the bits of the object. |
| 7452 |
|
| 7453 |
The intention is that this be suitable for use with memory-mapped I/O devices |
| 7454 |
on some machines. Note that there are two important respects in which this is |
| 7455 |
different from ``pragma Atomic``. First a reference to a ``Volatile_Full_Access`` |
| 7456 |
object is not a sequential action in the RM 9.10 sense and, therefore, does |
| 7457 |
not create a synchronization point. Second, in the case of ``pragma Atomic``, |
| 7458 |
there is no guarantee that all the bits will be accessed if the reference |
| 7459 |
is not to the whole object; the compiler is allowed (and generally will) |
| 7460 |
access only part of the object in this case. |
| 7461 |
|
| 7462 |
.. _Pragma-Volatile_Function: |
| 7463 |
|
| 7464 |
Pragma Volatile_Function |
| 7465 |
======================== |
| 7466 |
|
| 7467 |
Syntax: |
| 7468 |
|
| 7469 |
.. code-block:: ada |
| 7470 |
|
| 7471 |
pragma Volatile_Function [ (static_boolean_EXPRESSION) ]; |
| 7472 |
|
| 7473 |
For the semantics of this pragma, see the entry for aspect ``Volatile_Function`` |
| 7474 |
in the SPARK 2014 Reference Manual, section 7.1.2. |
| 7475 |
|
| 7476 |
Pragma Warning_As_Error |
| 7477 |
======================= |
| 7478 |
|
| 7479 |
Syntax: |
| 7480 |
|
| 7481 |
|
| 7482 |
.. code-block:: ada |
| 7483 |
|
| 7484 |
pragma Warning_As_Error (static_string_EXPRESSION); |
| 7485 |
|
| 7486 |
|
| 7487 |
This configuration pragma allows the programmer to specify a set |
| 7488 |
of warnings that will be treated as errors. Any warning that |
| 7489 |
matches the pattern given by the pragma argument will be treated |
| 7490 |
as an error. This gives more precise control than -gnatwe, |
| 7491 |
which treats warnings as errors. |
| 7492 |
|
| 7493 |
This pragma can apply to regular warnings (messages enabled by -gnatw) |
| 7494 |
and to style warnings (messages that start with "(style)", |
| 7495 |
enabled by -gnaty). |
| 7496 |
|
| 7497 |
The pattern may contain asterisks, which match zero or more characters |
| 7498 |
in the message. For example, you can use ``pragma Warning_As_Error |
| 7499 |
("bits of*unused")`` to treat the warning message ``warning: 960 bits of |
| 7500 |
"a" unused`` as an error. All characters other than asterisk are treated |
| 7501 |
as literal characters in the match. The match is case insensitive; for |
| 7502 |
example XYZ matches xyz. |
| 7503 |
|
| 7504 |
Note that the pattern matches if it occurs anywhere within the warning |
| 7505 |
message string (it is not necessary to put an asterisk at the start and |
| 7506 |
the end of the message, since this is implied). |
| 7507 |
|
| 7508 |
Another possibility for the static_string_EXPRESSION which works whether |
| 7509 |
or not error tags are enabled (*-gnatw.d*) is to use a single |
| 7510 |
*-gnatw* tag string, enclosed in brackets, |
| 7511 |
as shown in the example below, to treat one category of warnings as errors. |
| 7512 |
Note that if you want to treat multiple categories of warnings as errors, |
| 7513 |
you can use multiple pragma Warning_As_Error. |
| 7514 |
|
| 7515 |
The above use of patterns to match the message applies only to warning |
| 7516 |
messages generated by the front end. This pragma can also be applied to |
| 7517 |
warnings provided by the back end and mentioned in :ref:`Pragma_Warnings`. |
| 7518 |
By using a single full *-Wxxx* switch in the pragma, such warnings |
| 7519 |
can also be treated as errors. |
| 7520 |
|
| 7521 |
The pragma can appear either in a global configuration pragma file |
| 7522 |
(e.g. :file:`gnat.adc`), or at the start of a file. Given a global |
| 7523 |
configuration pragma file containing: |
| 7524 |
|
| 7525 |
|
| 7526 |
.. code-block:: ada |
| 7527 |
|
| 7528 |
pragma Warning_As_Error ("[-gnatwj]"); |
| 7529 |
|
| 7530 |
|
| 7531 |
which will treat all obsolescent feature warnings as errors, the |
| 7532 |
following program compiles as shown (compile options here are |
| 7533 |
*-gnatwa.d -gnatl -gnatj55*). |
| 7534 |
|
| 7535 |
|
| 7536 |
:: |
| 7537 |
|
| 7538 |
1. pragma Warning_As_Error ("*never assigned*"); |
| 7539 |
2. function Warnerr return String is |
| 7540 |
3. X : Integer; |
| 7541 |
| |
| 7542 |
>>> error: variable "X" is never read and |
| 7543 |
never assigned [-gnatwv] [warning-as-error] |
| 7544 |
|
| 7545 |
4. Y : Integer; |
| 7546 |
| |
| 7547 |
>>> warning: variable "Y" is assigned but |
| 7548 |
never read [-gnatwu] |
| 7549 |
|
| 7550 |
5. begin |
| 7551 |
6. Y := 0; |
| 7552 |
7. return %ABC%; |
| 7553 |
| |
| 7554 |
>>> error: use of "%" is an obsolescent |
| 7555 |
feature (RM J.2(4)), use """ instead |
| 7556 |
[-gnatwj] [warning-as-error] |
| 7557 |
|
| 7558 |
8. end; |
| 7559 |
|
| 7560 |
8 lines: No errors, 3 warnings (2 treated as errors) |
| 7561 |
|
| 7562 |
|
| 7563 |
Note that this pragma does not affect the set of warnings issued in |
| 7564 |
any way, it merely changes the effect of a matching warning if one |
| 7565 |
is produced as a result of other warnings options. As shown in this |
| 7566 |
example, if the pragma results in a warning being treated as an error, |
| 7567 |
the tag is changed from "warning:" to "error:" and the string |
| 7568 |
"[warning-as-error]" is appended to the end of the message. |
| 7569 |
|
| 7570 |
.. _Pragma_Warnings: |
| 7571 |
|
| 7572 |
Pragma Warnings |
| 7573 |
=============== |
| 7574 |
|
| 7575 |
Syntax: |
| 7576 |
|
| 7577 |
|
| 7578 |
.. code-block:: ada |
| 7579 |
|
| 7580 |
pragma Warnings ([TOOL_NAME,] DETAILS [, REASON]); |
| 7581 |
|
| 7582 |
DETAILS ::= On | Off |
| 7583 |
DETAILS ::= On | Off, local_NAME |
| 7584 |
DETAILS ::= static_string_EXPRESSION |
| 7585 |
DETAILS ::= On | Off, static_string_EXPRESSION |
| 7586 |
|
| 7587 |
TOOL_NAME ::= GNAT | GNATprove |
| 7588 |
|
| 7589 |
REASON ::= Reason => STRING_LITERAL {& STRING_LITERAL} |
| 7590 |
|
| 7591 |
Note: in Ada 83 mode, a string literal may be used in place of a static string |
| 7592 |
expression (which does not exist in Ada 83). |
| 7593 |
|
| 7594 |
Note if the second argument of ``DETAILS`` is a ``local_NAME`` then the |
| 7595 |
second form is always understood. If the intention is to use |
| 7596 |
the fourth form, then you can write ``NAME & ""`` to force the |
| 7597 |
interpretation as a *static_string_EXPRESSION*. |
| 7598 |
|
| 7599 |
Note: if the first argument is a valid ``TOOL_NAME``, it will be interpreted |
| 7600 |
that way. The use of the ``TOOL_NAME`` argument is relevant only to users |
| 7601 |
of SPARK and GNATprove, see last part of this section for details. |
| 7602 |
|
| 7603 |
Normally warnings are enabled, with the output being controlled by |
| 7604 |
the command line switch. Warnings (``Off``) turns off generation of |
| 7605 |
warnings until a Warnings (``On``) is encountered or the end of the |
| 7606 |
current unit. If generation of warnings is turned off using this |
| 7607 |
pragma, then some or all of the warning messages are suppressed, |
| 7608 |
regardless of the setting of the command line switches. |
| 7609 |
|
| 7610 |
The ``Reason`` parameter may optionally appear as the last argument |
| 7611 |
in any of the forms of this pragma. It is intended purely for the |
| 7612 |
purposes of documenting the reason for the ``Warnings`` pragma. |
| 7613 |
The compiler will check that the argument is a static string but |
| 7614 |
otherwise ignore this argument. Other tools may provide specialized |
| 7615 |
processing for this string. |
| 7616 |
|
| 7617 |
The form with a single argument (or two arguments if Reason present), |
| 7618 |
where the first argument is ``ON`` or ``OFF`` |
| 7619 |
may be used as a configuration pragma. |
| 7620 |
|
| 7621 |
If the ``LOCAL_NAME`` parameter is present, warnings are suppressed for |
| 7622 |
the specified entity. This suppression is effective from the point where |
| 7623 |
it occurs till the end of the extended scope of the variable (similar to |
| 7624 |
the scope of ``Suppress``). This form cannot be used as a configuration |
| 7625 |
pragma. |
| 7626 |
|
| 7627 |
In the case where the first argument is other than ``ON`` or |
| 7628 |
``OFF``, |
| 7629 |
the third form with a single static_string_EXPRESSION argument (and possible |
| 7630 |
reason) provides more precise |
| 7631 |
control over which warnings are active. The string is a list of letters |
| 7632 |
specifying which warnings are to be activated and which deactivated. The |
| 7633 |
code for these letters is the same as the string used in the command |
| 7634 |
line switch controlling warnings. For a brief summary, use the gnatmake |
| 7635 |
command with no arguments, which will generate usage information containing |
| 7636 |
the list of warnings switches supported. For |
| 7637 |
full details see the section on ``Warning Message Control`` in the |
| 7638 |
:title:`GNAT User's Guide`. |
| 7639 |
This form can also be used as a configuration pragma. |
| 7640 |
|
| 7641 |
The warnings controlled by the :switch:`-gnatw` switch are generated by the |
| 7642 |
front end of the compiler. The GCC back end can provide additional warnings |
| 7643 |
and they are controlled by the :switch:`-W` switch. Such warnings can be |
| 7644 |
identified by the appearance of a string of the form ``[-W{xxx}]`` in the |
| 7645 |
message which designates the :switch:`-W{xxx}` switch that controls the message. |
| 7646 |
The form with a single *static_string_EXPRESSION* argument also works for these |
| 7647 |
warnings, but the string must be a single full :switch:`-W{xxx}` switch in this |
| 7648 |
case. The above reference lists a few examples of these additional warnings. |
| 7649 |
|
| 7650 |
The specified warnings will be in effect until the end of the program |
| 7651 |
or another pragma ``Warnings`` is encountered. The effect of the pragma is |
| 7652 |
cumulative. Initially the set of warnings is the standard default set |
| 7653 |
as possibly modified by compiler switches. Then each pragma Warning |
| 7654 |
modifies this set of warnings as specified. This form of the pragma may |
| 7655 |
also be used as a configuration pragma. |
| 7656 |
|
| 7657 |
The fourth form, with an ``On|Off`` parameter and a string, is used to |
| 7658 |
control individual messages, based on their text. The string argument |
| 7659 |
is a pattern that is used to match against the text of individual |
| 7660 |
warning messages (not including the initial "warning: " tag). |
| 7661 |
|
| 7662 |
The pattern may contain asterisks, which match zero or more characters in |
| 7663 |
the message. For example, you can use |
| 7664 |
``pragma Warnings (Off, "bits of*unused")`` to suppress the warning |
| 7665 |
message ``warning: 960 bits of "a" unused``. No other regular |
| 7666 |
expression notations are permitted. All characters other than asterisk in |
| 7667 |
these three specific cases are treated as literal characters in the match. |
| 7668 |
The match is case insensitive, for example XYZ matches xyz. |
| 7669 |
|
| 7670 |
Note that the pattern matches if it occurs anywhere within the warning |
| 7671 |
message string (it is not necessary to put an asterisk at the start and |
| 7672 |
the end of the message, since this is implied). |
| 7673 |
|
| 7674 |
The above use of patterns to match the message applies only to warning |
| 7675 |
messages generated by the front end. This form of the pragma with a string |
| 7676 |
argument can also be used to control warnings provided by the back end and |
| 7677 |
mentioned above. By using a single full :switch:`-W{xxx}` switch in the pragma, |
| 7678 |
such warnings can be turned on and off. |
| 7679 |
|
| 7680 |
There are two ways to use the pragma in this form. The OFF form can be used |
| 7681 |
as a configuration pragma. The effect is to suppress all warnings (if any) |
| 7682 |
that match the pattern string throughout the compilation (or match the |
| 7683 |
-W switch in the back end case). |
| 7684 |
|
| 7685 |
The second usage is to suppress a warning locally, and in this case, two |
| 7686 |
pragmas must appear in sequence: |
| 7687 |
|
| 7688 |
|
| 7689 |
.. code-block:: ada |
| 7690 |
|
| 7691 |
pragma Warnings (Off, Pattern); |
| 7692 |
... code where given warning is to be suppressed |
| 7693 |
pragma Warnings (On, Pattern); |
| 7694 |
|
| 7695 |
|
| 7696 |
In this usage, the pattern string must match in the Off and On |
| 7697 |
pragmas, and (if *-gnatw.w* is given) at least one matching |
| 7698 |
warning must be suppressed. |
| 7699 |
|
| 7700 |
Note: if the ON form is not found, then the effect of the OFF form extends |
| 7701 |
until the end of the file (pragma Warnings is purely textual, so its effect |
| 7702 |
does not stop at the end of the enclosing scope). |
| 7703 |
|
| 7704 |
Note: to write a string that will match any warning, use the string |
| 7705 |
``"***"``. It will not work to use a single asterisk or two |
| 7706 |
asterisks since this looks like an operator name. This form with three |
| 7707 |
asterisks is similar in effect to specifying ``pragma Warnings (Off)`` except (if :switch:`-gnatw.w` is given) that a matching |
| 7708 |
``pragma Warnings (On, "***")`` will be required. This can be |
| 7709 |
helpful in avoiding forgetting to turn warnings back on. |
| 7710 |
|
| 7711 |
Note: the debug flag :switch:`-gnatd.i` can be |
| 7712 |
used to cause the compiler to entirely ignore all WARNINGS pragmas. This can |
| 7713 |
be useful in checking whether obsolete pragmas in existing programs are hiding |
| 7714 |
real problems. |
| 7715 |
|
| 7716 |
Note: pragma Warnings does not affect the processing of style messages. See |
| 7717 |
separate entry for pragma Style_Checks for control of style messages. |
| 7718 |
|
| 7719 |
Users of the formal verification tool GNATprove for the SPARK subset of Ada may |
| 7720 |
use the version of the pragma with a ``TOOL_NAME`` parameter. |
| 7721 |
|
| 7722 |
If present, ``TOOL_NAME`` is the name of a tool, currently either ``GNAT`` for the |
| 7723 |
compiler or ``GNATprove`` for the formal verification tool. A given tool only |
| 7724 |
takes into account pragma Warnings that do not specify a tool name, or that |
| 7725 |
specify the matching tool name. This makes it possible to disable warnings |
| 7726 |
selectively for each tool, and as a consequence to detect useless pragma |
| 7727 |
Warnings with switch :switch:`-gnatw.w`. |
| 7728 |
|
| 7729 |
Pragma Weak_External |
| 7730 |
==================== |
| 7731 |
|
| 7732 |
Syntax: |
| 7733 |
|
| 7734 |
|
| 7735 |
.. code-block:: ada |
| 7736 |
|
| 7737 |
pragma Weak_External ([Entity =>] LOCAL_NAME); |
| 7738 |
|
| 7739 |
|
| 7740 |
``LOCAL_NAME`` must refer to an object that is declared at the library |
| 7741 |
level. This pragma specifies that the given entity should be marked as a |
| 7742 |
weak symbol for the linker. It is equivalent to ``__attribute__((weak))`` |
| 7743 |
in GNU C and causes ``LOCAL_NAME`` to be emitted as a weak symbol instead |
| 7744 |
of a regular symbol, that is to say a symbol that does not have to be |
| 7745 |
resolved by the linker if used in conjunction with a pragma Import. |
| 7746 |
|
| 7747 |
When a weak symbol is not resolved by the linker, its address is set to |
| 7748 |
zero. This is useful in writing interfaces to external modules that may |
| 7749 |
or may not be linked in the final executable, for example depending on |
| 7750 |
configuration settings. |
| 7751 |
|
| 7752 |
If a program references at run time an entity to which this pragma has been |
| 7753 |
applied, and the corresponding symbol was not resolved at link time, then |
| 7754 |
the execution of the program is erroneous. It is not erroneous to take the |
| 7755 |
Address of such an entity, for example to guard potential references, |
| 7756 |
as shown in the example below. |
| 7757 |
|
| 7758 |
Some file formats do not support weak symbols so not all target machines |
| 7759 |
support this pragma. |
| 7760 |
|
| 7761 |
|
| 7762 |
.. code-block:: ada |
| 7763 |
|
| 7764 |
-- Example of the use of pragma Weak_External |
| 7765 |
|
| 7766 |
package External_Module is |
| 7767 |
key : Integer; |
| 7768 |
pragma Import (C, key); |
| 7769 |
pragma Weak_External (key); |
| 7770 |
function Present return boolean; |
| 7771 |
end External_Module; |
| 7772 |
|
| 7773 |
with System; use System; |
| 7774 |
package body External_Module is |
| 7775 |
function Present return boolean is |
| 7776 |
begin |
| 7777 |
return key'Address /= System.Null_Address; |
| 7778 |
end Present; |
| 7779 |
end External_Module; |
| 7780 |
|
| 7781 |
|
| 7782 |
Pragma Wide_Character_Encoding |
| 7783 |
============================== |
| 7784 |
|
| 7785 |
Syntax: |
| 7786 |
|
| 7787 |
|
| 7788 |
.. code-block:: ada |
| 7789 |
|
| 7790 |
pragma Wide_Character_Encoding (IDENTIFIER | CHARACTER_LITERAL); |
| 7791 |
|
| 7792 |
|
| 7793 |
This pragma specifies the wide character encoding to be used in program |
| 7794 |
source text appearing subsequently. It is a configuration pragma, but may |
| 7795 |
also be used at any point that a pragma is allowed, and it is permissible |
| 7796 |
to have more than one such pragma in a file, allowing multiple encodings |
| 7797 |
to appear within the same file. |
| 7798 |
|
| 7799 |
However, note that the pragma cannot immediately precede the relevant |
| 7800 |
wide character, because then the previous encoding will still be in |
| 7801 |
effect, causing "illegal character" errors. |
| 7802 |
|
| 7803 |
The argument can be an identifier or a character literal. In the identifier |
| 7804 |
case, it is one of ``HEX``, ``UPPER``, ``SHIFT_JIS``, |
| 7805 |
``EUC``, ``UTF8``, or ``BRACKETS``. In the character literal |
| 7806 |
case it is correspondingly one of the characters :kbd:`h`, :kbd:`u`, |
| 7807 |
:kbd:`s`, :kbd:`e`, :kbd:`8`, or :kbd:`b`. |
| 7808 |
|
| 7809 |
Note that when the pragma is used within a file, it affects only the |
| 7810 |
encoding within that file, and does not affect withed units, specs, |
| 7811 |
or subunits. |