* gnat_rm.texi, gnat_ugn.texi, doc: Documentation updates and clean ups
[official-gcc.git] / gcc / ada / doc / gnat_rm / implementation_defined_aspects.rst
blob5599a81413ae2ada46084b734b9d0a90e2646731
1 .. _Implementation_Defined_Aspects:
3 ******************************
4 Implementation Defined Aspects
5 ******************************
7 Ada defines (throughout the Ada 2012 reference manual, summarized
8 in Annex K) a set of aspects that can be specified for certain entities.
9 These language defined aspects are implemented in GNAT in Ada 2012 mode
10 and work as described in the Ada 2012 Reference Manual.
12 In addition, Ada 2012 allows implementations to define additional aspects
13 whose meaning is defined by the implementation.  GNAT provides
14 a number of these implementation-defined aspects which can be used
15 to extend and enhance the functionality of the compiler.  This section of
16 the GNAT reference manual describes these additional aspects.
18 Note that any program using these aspects may not be portable to
19 other compilers (although GNAT implements this set of aspects on all
20 platforms).  Therefore if portability to other compilers is an important
21 consideration, you should minimize the use of these aspects.
23 Note that for many of these aspects, the effect is essentially similar
24 to the use of a pragma or attribute specification with the same name
25 applied to the entity. For example, if we write:
28 .. code-block:: ada
30   type R is range 1 .. 100
31     with Value_Size => 10;
34 then the effect is the same as:
36 .. code-block:: ada
38   type R is range 1 .. 100;
39   for R'Value_Size use 10;
42 and if we write:
44 .. code-block:: ada
46   type R is new Integer
47     with Shared => True;
50 then the effect is the same as:
52 .. code-block:: ada
54   type R is new Integer;
55   pragma Shared (R);
58 In the documentation below, such cases are simply marked
59 as being boolean aspects equivalent to the corresponding pragma
60 or attribute definition clause.
62 Aspect Abstract_State
63 =====================
65 .. index:: Abstract_State
67 This aspect is equivalent to pragma `Abstract_State`.
69 Annotate
70 ========
71 .. index:: Annotate
73 There are three forms of this aspect (where ID is an identifier,
74 and ARG is a general expression).
78 *Annotate => ID*
79   Equivalent to `pragma Annotate (ID, Entity => Name);`
82 *Annotate => (ID)*
83   Equivalent to `pragma Annotate (ID, Entity => Name);`
86 *Annotate => (ID ,ID {, ARG})*
87   Equivalent to `pragma Annotate (ID, ID {, ARG}, Entity => Name);`
89 Aspect Async_Readers
90 ====================
91 .. index:: Async_Readers
93 This boolean aspect is equivalent to pragma `Async_Readers`.
95 Aspect Async_Writers
96 ====================
97 .. index:: Async_Writers
99 This boolean aspect is equivalent to pragma `Async_Writers`.
101 Aspect Contract_Cases
102 =====================
103 .. index:: Contract_Cases
105 This aspect is equivalent to pragma `Contract_Cases`, the sequence
106 of clauses being enclosed in parentheses so that syntactically it is an
107 aggregate.
109 Aspect Depends
110 ==============
111 .. index:: Depends
113 This aspect is equivalent to pragma `Depends`.
115 Aspect Dimension
116 ================
117 .. index:: Dimension
119 The `Dimension` aspect is used to specify the dimensions of a given
120 subtype of a dimensioned numeric type. The aspect also specifies a symbol
121 used when doing formatted output of dimensioned quantities. The syntax is::
123   with Dimension =>
124     ([Symbol =>] SYMBOL, DIMENSION_VALUE {, DIMENSION_Value})
126   SYMBOL ::= STRING_LITERAL | CHARACTER_LITERAL
128   DIMENSION_VALUE ::=
129     RATIONAL
130   | others               => RATIONAL
131   | DISCRETE_CHOICE_LIST => RATIONAL
133   RATIONAL ::= [-] NUMERIC_LITERAL [/ NUMERIC_LITERAL]
136 This aspect can only be applied to a subtype whose parent type has
137 a `Dimension_Systen` aspect. The aspect must specify values for
138 all dimensions of the system. The rational values are the powers of the
139 corresponding dimensions that are used by the compiler to verify that
140 physical (numeric) computations are dimensionally consistent. For example,
141 the computation of a force must result in dimensions (L => 1, M => 1, T => -2).
142 For further examples of the usage
143 of this aspect, see package `System.Dim.Mks`.
144 Note that when the dimensioned type is an integer type, then any
145 dimension value must be an integer literal.
147 Aspect Dimension_System
148 =======================
149 .. index:: Dimension_System
151 The `Dimension_System` aspect is used to define a system of
152 dimensions that will be used in subsequent subtype declarations with
153 `Dimension` aspects that reference this system. The syntax is::
155   with Dimension_System => (DIMENSION {, DIMENSION});
157   DIMENSION ::= ([Unit_Name   =>] IDENTIFIER,
158                  [Unit_Symbol =>] SYMBOL,
159                  [Dim_Symbol  =>] SYMBOL)
161   SYMBOL ::= CHARACTER_LITERAL | STRING_LITERAL
164 This aspect is applied to a type, which must be a numeric derived type
165 (typically a floating-point type), that
166 will represent values within the dimension system. Each `DIMENSION`
167 corresponds to one particular dimension. A maximum of 7 dimensions may
168 be specified. `Unit_Name` is the name of the dimension (for example
169 `Meter`). `Unit_Symbol` is the shorthand used for quantities
170 of this dimension (for example `m` for `Meter`).
171 `Dim_Symbol` gives
172 the identification within the dimension system (typically this is a
173 single letter, e.g. `L` standing for length for unit name `Meter`).
174 The `Unit_Symbol` is used in formatted output of dimensioned quantities.
175 The `Dim_Symbol` is used in error messages when numeric operations have
176 inconsistent dimensions.
178 GNAT provides the standard definition of the International MKS system in
179 the run-time package `System.Dim.Mks`. You can easily define
180 similar packages for cgs units or British units, and define conversion factors
181 between values in different systems. The MKS system is characterized by the
182 following aspect:
184 .. code-block:: ada
186      type Mks_Type is new Long_Long_Float with
187        Dimension_System => (
188          (Unit_Name => Meter,    Unit_Symbol => 'm',   Dim_Symbol => 'L'),
189          (Unit_Name => Kilogram, Unit_Symbol => "kg",  Dim_Symbol => 'M'),
190          (Unit_Name => Second,   Unit_Symbol => 's',   Dim_Symbol => 'T'),
191          (Unit_Name => Ampere,   Unit_Symbol => 'A',   Dim_Symbol => 'I'),
192          (Unit_Name => Kelvin,   Unit_Symbol => 'K',   Dim_Symbol => '@'),
193          (Unit_Name => Mole,     Unit_Symbol => "mol", Dim_Symbol => 'N'),
194          (Unit_Name => Candela,  Unit_Symbol => "cd",  Dim_Symbol => 'J'));
197 Note that in the above type definition, we use the `at` symbol (``@``) to
198 represent a theta character (avoiding the use of extended Latin-1
199 characters in this context).
201 See section 'Performing Dimensionality Analysis in GNAT' in the GNAT Users
202 Guide for detailed examples of use of the dimension system.
204 Aspect Disable_Controlled
205 =========================
206 .. index:: Disable_Controlled
208 The aspect  `Disable_Controlled` is defined for controlled record types. If
209 active, this aspect causes suppression of all related calls to `Initialize`,
210 `Adjust`, and `Finalize`. The intended use is for conditional compilation,
211 where for example you might want a record to be controlled or not depending on
212 whether some run-time check is enabled or suppressed.
214 Aspect Effective_Reads
215 ======================
216 .. index:: Effective_Reads
218 This aspect is equivalent to pragma `Effective_Reads`.
220 Aspect Effective_Writes
221 =======================
222 .. index:: Effective_Writes
224 This aspect is equivalent to pragma `Effective_Writes`.
226 Aspect Favor_Top_Level
227 ======================
228 .. index:: Favor_Top_Level
230 This boolean aspect is equivalent to pragma `Favor_Top_Level`.
232 Aspect Global
233 =============
234 .. index:: Global
236 This aspect is equivalent to pragma `Global`.
238 Aspect Initial_Condition
239 ========================
240 .. index:: Initial_Condition
242 This aspect is equivalent to pragma `Initial_Condition`.
244 Aspect Initializes
245 ==================
246 .. index:: Initializes
248 This aspect is equivalent to pragma `Initializes`.
250 Aspect Inline_Always
251 ====================
252 .. index:: Inline_Always
254 This boolean aspect is equivalent to pragma `Inline_Always`.
256 Aspect Invariant
257 ================
258 .. index:: Invariant
260 This aspect is equivalent to pragma `Invariant`. It is a
261 synonym for the language defined aspect `Type_Invariant` except
262 that it is separately controllable using pragma `Assertion_Policy`.
264 Aspect Invariant'Class
265 ======================
266 .. index:: Invariant'Class
268 This aspect is equivalent to pragma `Type_Invariant_Class`. It is a
269 synonym for the language defined aspect `Type_Invariant'Class` except
270 that it is separately controllable using pragma `Assertion_Policy`.
272 Aspect Iterable
273 ===============
274 .. index:: Iterable
276 This aspect provides a light-weight mechanism for loops and quantified
277 expressions over container types, without the overhead imposed by the tampering
278 checks of standard Ada 2012 iterators. The value of the aspect is an aggregate
279 with four named components: `First`, `Next`, `Has_Element`, and `Element` (the
280 last one being optional). When only 3 components are specified, only the
281 `for .. in` form of iteration over cursors is available. When all 4 components
282 are specified, both this form and the `for .. of` form of iteration over
283 elements are available. The following is a typical example of use:
285 .. code-block:: ada
287   type List is private with
288       Iterable => (First        => First_Cursor,
289                    Next         => Advance,
290                    Has_Element  => Cursor_Has_Element,
291                   [Element      => Get_Element]);
293 * The value denoted by `First` must denote a primitive operation of the
294   container type that returns a `Cursor`, which must a be a type declared in
295   the container package or visible from it. For example:
297 .. code-block:: ada
299   function First_Cursor (Cont : Container) return Cursor;
301 * The value of `Next` is a primitive operation of the container type that takes
302   both a container and a cursor and yields a cursor. For example:
304 .. code-block:: ada
306   function Advance (Cont : Container; Position : Cursor) return Cursor;
308 * The value of `Has_Element` is a primitive operation of the container type
309   that takes both a container and a cursor and yields a boolean. For example:
311 .. code-block:: ada
313   function Cursor_Has_Element (Cont : Container; Position : Cursor) return Boolean;
315 * The value of `Element` is a primitive operation of the container type that
316   takes both a container and a cursor and yields an `Element_Type`, which must
317   be a type declared in the container package or visible from it. For example:
319 .. code-block:: ada
321   function Get_Element (Cont : Container; Position : Cursor) return Element_Type;
323 This aspect is used in the GNAT-defined formal container packages.
325 Aspect Linker_Section
326 =====================
327 .. index:: Linker_Section
329 This aspect is equivalent to an `Linker_Section` pragma.
331 Aspect Lock_Free
332 ================
333 .. index:: Lock_Free
335 This boolean aspect is equivalent to pragma `Lock_Free`.
337 Aspect No_Elaboration_Code_All
338 ==============================
339 .. index:: No_Elaboration_Code_All
341 This aspect is equivalent to a `pragma No_Elaboration_Code_All`
342 statement for a program unit.
344 Aspect No_Tagged_Streams
345 ========================
346 .. index:: No_Tagged_Streams
348 This aspect is equivalent to a `pragma No_Tagged_Streams` with an
349 argument specifying a root tagged type (thus this aspect can only be
350 applied to such a type).
352 Aspect Object_Size
353 ==================
354 .. index:: Object_Size
356 This aspect is equivalent to an `Object_Size` attribute definition
357 clause.
359 Aspect Obsolescent
360 ==================
361 .. index:: Obsolsecent
363 This aspect is equivalent to an `Obsolescent` pragma. Note that the
364 evaluation of this aspect happens at the point of occurrence, it is not
365 delayed until the freeze point.
367 Aspect Part_Of
368 ==============
369 .. index:: Part_Of
371 This aspect is equivalent to pragma `Part_Of`.
373 Aspect Persistent_BSS
374 =====================
375 .. index:: Persistent_BSS
377 This boolean aspect is equivalent to pragma `Persistent_BSS`.
379 Aspect Predicate
380 ================
381 .. index:: Predicate
383 This aspect is equivalent to pragma `Predicate`. It is thus
384 similar to the language defined aspects `Dynamic_Predicate`
385 and `Static_Predicate` except that whether the resulting
386 predicate is static or dynamic is controlled by the form of the
387 expression. It is also separately controllable using pragma
388 `Assertion_Policy`.
390 Aspect Pure_Function
391 ====================
392 .. index:: Pure_Function
394 This boolean aspect is equivalent to pragma `Pure_Function`.
396 Aspect Refined_Depends
397 ======================
398 .. index:: Refined_Depends
400 This aspect is equivalent to pragma `Refined_Depends`.
402 Aspect Refined_Global
403 =====================
404 .. index:: Refined_Global
406 This aspect is equivalent to pragma `Refined_Global`.
408 Aspect Refined_Post
409 ===================
410 .. index:: Refined_Post
412 This aspect is equivalent to pragma `Refined_Post`.
414 Aspect Refined_State
415 ====================
416 .. index:: Refined_State
418 This aspect is equivalent to pragma `Refined_State`.
420 Aspect Remote_Access_Type
421 =========================
422 .. index:: Remote_Access_Type
424 This aspect is equivalent to pragma `Remote_Access_Type`.
426 Aspect Scalar_Storage_Order
427 ===========================
428 .. index:: Scalar_Storage_Order
430 This aspect is equivalent to a `Scalar_Storage_Order`
431 attribute definition clause.
433 Aspect Shared
434 =============
435 .. index:: Shared
437 This boolean aspect is equivalent to pragma `Shared`,
438 and is thus a synonym for aspect `Atomic`.
440 Aspect Simple_Storage_Pool
441 ==========================
442 .. index:: Simple_Storage_Pool
444 This aspect is equivalent to a `Simple_Storage_Pool`
445 attribute definition clause.
447 Aspect Simple_Storage_Pool_Type
448 ===============================
449 .. index:: Simple_Storage_Pool_Type
451 This boolean aspect is equivalent to pragma `Simple_Storage_Pool_Type`.
453 Aspect SPARK_Mode
454 =================
455 .. index:: SPARK_Mode
457 This aspect is equivalent to pragma `SPARK_Mode` and
458 may be specified for either or both of the specification and body
459 of a subprogram or package.
461 Aspect Suppress_Debug_Info
462 ==========================
463 .. index:: Suppress_Debug_Info
465 This boolean aspect is equivalent to pragma `Suppress_Debug_Info`.
467 Aspect Suppress_Initialization
468 ==============================
469 .. index:: Suppress_Initialization
471 This boolean aspect is equivalent to pragma `Suppress_Initialization`.
473 Aspect Test_Case
474 ================
475 .. index:: Test_Case
477 This aspect is equivalent to pragma `Test_Case`.
479 Aspect Thread_Local_Storage
480 ===========================
481 .. index:: Thread_Local_Storage
483 This boolean aspect is equivalent to pragma `Thread_Local_Storage`.
485 Aspect Universal_Aliasing
486 =========================
487 .. index:: Universal_Aliasing
489 This boolean aspect is equivalent to pragma `Universal_Aliasing`.
491 Aspect Universal_Data
492 =====================
493 .. index:: Universal_Data
495 This aspect is equivalent to pragma `Universal_Data`.
497 Aspect Unmodified
498 =================
499 .. index:: Unmodified
501 This boolean aspect is equivalent to pragma `Unmodified`.
503 Aspect Unreferenced
504 ===================
505 .. index:: Unreferenced
507 This boolean aspect is equivalent to pragma `Unreferenced`. Note that
508 in the case of formal parameters, it is not permitted to have aspects for
509 a formal parameter, so in this case the pragma form must be used.
511 Aspect Unreferenced_Objects
512 ===========================
513 .. index:: Unreferenced_Objects
515 This boolean aspect is equivalent to pragma `Unreferenced_Objects`.
517 Aspect Value_Size
518 =================
519 .. index:: Value_Size
521 This aspect is equivalent to a `Value_Size`
522 attribute definition clause.
524 Aspect Volatile_Full_Access
525 ===========================
526 .. index:: Volatile_Full_Access
528 This boolean aspect is equivalent to pragma `Volatile_Full_Access`.
530 Aspect Warnings
531 ===============
532 .. index:: Warnings
534 This aspect is equivalent to the two argument form of pragma `Warnings`,
535 where the first argument is `ON` or `OFF` and the second argument
536 is the entity.