annotate gcc/ada/doc/gnat_rm/implementation_defined_attributes.rst @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 .. _Implementation_Defined_Attributes:
kono
parents:
diff changeset
2
kono
parents:
diff changeset
3 *********************************
kono
parents:
diff changeset
4 Implementation Defined Attributes
kono
parents:
diff changeset
5 *********************************
kono
parents:
diff changeset
6
kono
parents:
diff changeset
7 Ada defines (throughout the Ada reference manual,
kono
parents:
diff changeset
8 summarized in Annex K),
kono
parents:
diff changeset
9 a set of attributes that provide useful additional functionality in all
kono
parents:
diff changeset
10 areas of the language. These language defined attributes are implemented
kono
parents:
diff changeset
11 in GNAT and work as described in the Ada Reference Manual.
kono
parents:
diff changeset
12
kono
parents:
diff changeset
13 In addition, Ada allows implementations to define additional
kono
parents:
diff changeset
14 attributes whose meaning is defined by the implementation. GNAT provides
kono
parents:
diff changeset
15 a number of these implementation-dependent attributes which can be used
kono
parents:
diff changeset
16 to extend and enhance the functionality of the compiler. This section of
kono
parents:
diff changeset
17 the GNAT reference manual describes these additional attributes. It also
kono
parents:
diff changeset
18 describes additional implementation-dependent features of standard
kono
parents:
diff changeset
19 language-defined attributes.
kono
parents:
diff changeset
20
kono
parents:
diff changeset
21 Note that any program using these attributes may not be portable to
kono
parents:
diff changeset
22 other compilers (although GNAT implements this set of attributes on all
kono
parents:
diff changeset
23 platforms). Therefore if portability to other compilers is an important
kono
parents:
diff changeset
24 consideration, you should minimize the use of these attributes.
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 Attribute Abort_Signal
kono
parents:
diff changeset
27 ======================
kono
parents:
diff changeset
28 .. index:: Abort_Signal
kono
parents:
diff changeset
29
kono
parents:
diff changeset
30 ``Standard'Abort_Signal`` (``Standard`` is the only allowed
kono
parents:
diff changeset
31 prefix) provides the entity for the special exception used to signal
kono
parents:
diff changeset
32 task abort or asynchronous transfer of control. Normally this attribute
kono
parents:
diff changeset
33 should only be used in the tasking runtime (it is highly peculiar, and
kono
parents:
diff changeset
34 completely outside the normal semantics of Ada, for a user program to
kono
parents:
diff changeset
35 intercept the abort exception).
kono
parents:
diff changeset
36
kono
parents:
diff changeset
37 Attribute Address_Size
kono
parents:
diff changeset
38 ======================
kono
parents:
diff changeset
39 .. index:: Size of ``Address``
kono
parents:
diff changeset
40
kono
parents:
diff changeset
41 .. index:: Address_Size
kono
parents:
diff changeset
42
kono
parents:
diff changeset
43 ``Standard'Address_Size`` (``Standard`` is the only allowed
kono
parents:
diff changeset
44 prefix) is a static constant giving the number of bits in an
kono
parents:
diff changeset
45 ``Address``. It is the same value as System.Address'Size,
kono
parents:
diff changeset
46 but has the advantage of being static, while a direct
kono
parents:
diff changeset
47 reference to System.Address'Size is nonstatic because Address
kono
parents:
diff changeset
48 is a private type.
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 Attribute Asm_Input
kono
parents:
diff changeset
51 ===================
kono
parents:
diff changeset
52 .. index:: Asm_Input
kono
parents:
diff changeset
53
kono
parents:
diff changeset
54 The ``Asm_Input`` attribute denotes a function that takes two
kono
parents:
diff changeset
55 parameters. The first is a string, the second is an expression of the
kono
parents:
diff changeset
56 type designated by the prefix. The first (string) argument is required
kono
parents:
diff changeset
57 to be a static expression, and is the constraint for the parameter,
kono
parents:
diff changeset
58 (e.g., what kind of register is required). The second argument is the
kono
parents:
diff changeset
59 value to be used as the input argument. The possible values for the
kono
parents:
diff changeset
60 constant are the same as those used in the RTL, and are dependent on
kono
parents:
diff changeset
61 the configuration file used to built the GCC back end.
kono
parents:
diff changeset
62 :ref:`Machine_Code_Insertions`
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 Attribute Asm_Output
kono
parents:
diff changeset
65 ====================
kono
parents:
diff changeset
66 .. index:: Asm_Output
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 The ``Asm_Output`` attribute denotes a function that takes two
kono
parents:
diff changeset
69 parameters. The first is a string, the second is the name of a variable
kono
parents:
diff changeset
70 of the type designated by the attribute prefix. The first (string)
kono
parents:
diff changeset
71 argument is required to be a static expression and designates the
kono
parents:
diff changeset
72 constraint for the parameter (e.g., what kind of register is
kono
parents:
diff changeset
73 required). The second argument is the variable to be updated with the
kono
parents:
diff changeset
74 result. The possible values for constraint are the same as those used in
kono
parents:
diff changeset
75 the RTL, and are dependent on the configuration file used to build the
kono
parents:
diff changeset
76 GCC back end. If there are no output operands, then this argument may
kono
parents:
diff changeset
77 either be omitted, or explicitly given as ``No_Output_Operands``.
kono
parents:
diff changeset
78 :ref:`Machine_Code_Insertions`
kono
parents:
diff changeset
79
kono
parents:
diff changeset
80 Attribute Atomic_Always_Lock_Free
kono
parents:
diff changeset
81 =================================
kono
parents:
diff changeset
82 .. index:: Atomic_Always_Lock_Free
kono
parents:
diff changeset
83
kono
parents:
diff changeset
84 The prefix of the ``Atomic_Always_Lock_Free`` attribute is a type.
kono
parents:
diff changeset
85 The result is a Boolean value which is True if the type has discriminants,
kono
parents:
diff changeset
86 and False otherwise. The result indicate whether atomic operations are
kono
parents:
diff changeset
87 supported by the target for the given type.
kono
parents:
diff changeset
88
kono
parents:
diff changeset
89 Attribute Bit
kono
parents:
diff changeset
90 =============
kono
parents:
diff changeset
91 .. index:: Bit
kono
parents:
diff changeset
92
kono
parents:
diff changeset
93 ``obj'Bit``, where ``obj`` is any object, yields the bit
kono
parents:
diff changeset
94 offset within the storage unit (byte) that contains the first bit of
kono
parents:
diff changeset
95 storage allocated for the object. The value of this attribute is of the
kono
parents:
diff changeset
96 type *universal_integer*, and is always a non-negative number not
kono
parents:
diff changeset
97 exceeding the value of ``System.Storage_Unit``.
kono
parents:
diff changeset
98
kono
parents:
diff changeset
99 For an object that is a variable or a constant allocated in a register,
kono
parents:
diff changeset
100 the value is zero. (The use of this attribute does not force the
kono
parents:
diff changeset
101 allocation of a variable to memory).
kono
parents:
diff changeset
102
kono
parents:
diff changeset
103 For an object that is a formal parameter, this attribute applies
kono
parents:
diff changeset
104 to either the matching actual parameter or to a copy of the
kono
parents:
diff changeset
105 matching actual parameter.
kono
parents:
diff changeset
106
kono
parents:
diff changeset
107 For an access object the value is zero. Note that
kono
parents:
diff changeset
108 ``obj.all'Bit`` is subject to an ``Access_Check`` for the
kono
parents:
diff changeset
109 designated object. Similarly for a record component
kono
parents:
diff changeset
110 ``X.C'Bit`` is subject to a discriminant check and
kono
parents:
diff changeset
111 ``X(I).Bit`` and ``X(I1..I2)'Bit``
kono
parents:
diff changeset
112 are subject to index checks.
kono
parents:
diff changeset
113
kono
parents:
diff changeset
114 This attribute is designed to be compatible with the DEC Ada 83 definition
kono
parents:
diff changeset
115 and implementation of the ``Bit`` attribute.
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117 Attribute Bit_Position
kono
parents:
diff changeset
118 ======================
kono
parents:
diff changeset
119 .. index:: Bit_Position
kono
parents:
diff changeset
120
kono
parents:
diff changeset
121 ``R.C'Bit_Position``, where ``R`` is a record object and ``C`` is one
kono
parents:
diff changeset
122 of the fields of the record type, yields the bit
kono
parents:
diff changeset
123 offset within the record contains the first bit of
kono
parents:
diff changeset
124 storage allocated for the object. The value of this attribute is of the
kono
parents:
diff changeset
125 type *universal_integer*. The value depends only on the field
kono
parents:
diff changeset
126 ``C`` and is independent of the alignment of
kono
parents:
diff changeset
127 the containing record ``R``.
kono
parents:
diff changeset
128
kono
parents:
diff changeset
129 Attribute Code_Address
kono
parents:
diff changeset
130 ======================
kono
parents:
diff changeset
131 .. index:: Code_Address
kono
parents:
diff changeset
132 .. index:: Subprogram address
kono
parents:
diff changeset
133
kono
parents:
diff changeset
134 .. index:: Address of subprogram code
kono
parents:
diff changeset
135
kono
parents:
diff changeset
136 The ``'Address``
kono
parents:
diff changeset
137 attribute may be applied to subprograms in Ada 95 and Ada 2005, but the
kono
parents:
diff changeset
138 intended effect seems to be to provide
kono
parents:
diff changeset
139 an address value which can be used to call the subprogram by means of
kono
parents:
diff changeset
140 an address clause as in the following example:
kono
parents:
diff changeset
141
kono
parents:
diff changeset
142 .. code-block:: ada
kono
parents:
diff changeset
143
kono
parents:
diff changeset
144 procedure K is ...
kono
parents:
diff changeset
145
kono
parents:
diff changeset
146 procedure L;
kono
parents:
diff changeset
147 for L'Address use K'Address;
kono
parents:
diff changeset
148 pragma Import (Ada, L);
kono
parents:
diff changeset
149
kono
parents:
diff changeset
150
kono
parents:
diff changeset
151 A call to ``L`` is then expected to result in a call to ``K``.
kono
parents:
diff changeset
152 In Ada 83, where there were no access-to-subprogram values, this was
kono
parents:
diff changeset
153 a common work-around for getting the effect of an indirect call.
kono
parents:
diff changeset
154 GNAT implements the above use of ``Address`` and the technique
kono
parents:
diff changeset
155 illustrated by the example code works correctly.
kono
parents:
diff changeset
156
kono
parents:
diff changeset
157 However, for some purposes, it is useful to have the address of the start
kono
parents:
diff changeset
158 of the generated code for the subprogram. On some architectures, this is
kono
parents:
diff changeset
159 not necessarily the same as the ``Address`` value described above.
kono
parents:
diff changeset
160 For example, the ``Address`` value may reference a subprogram
kono
parents:
diff changeset
161 descriptor rather than the subprogram itself.
kono
parents:
diff changeset
162
kono
parents:
diff changeset
163 The ``'Code_Address`` attribute, which can only be applied to
kono
parents:
diff changeset
164 subprogram entities, always returns the address of the start of the
kono
parents:
diff changeset
165 generated code of the specified subprogram, which may or may not be
kono
parents:
diff changeset
166 the same value as is returned by the corresponding ``'Address``
kono
parents:
diff changeset
167 attribute.
kono
parents:
diff changeset
168
kono
parents:
diff changeset
169 Attribute Compiler_Version
kono
parents:
diff changeset
170 ==========================
kono
parents:
diff changeset
171 .. index:: Compiler_Version
kono
parents:
diff changeset
172
kono
parents:
diff changeset
173 ``Standard'Compiler_Version`` (``Standard`` is the only allowed
kono
parents:
diff changeset
174 prefix) yields a static string identifying the version of the compiler
kono
parents:
diff changeset
175 being used to compile the unit containing the attribute reference.
kono
parents:
diff changeset
176
kono
parents:
diff changeset
177 Attribute Constrained
kono
parents:
diff changeset
178 =====================
kono
parents:
diff changeset
179 .. index:: Constrained
kono
parents:
diff changeset
180
kono
parents:
diff changeset
181 In addition to the usage of this attribute in the Ada RM, GNAT
kono
parents:
diff changeset
182 also permits the use of the ``'Constrained`` attribute
kono
parents:
diff changeset
183 in a generic template
kono
parents:
diff changeset
184 for any type, including types without discriminants. The value of this
kono
parents:
diff changeset
185 attribute in the generic instance when applied to a scalar type or a
kono
parents:
diff changeset
186 record type without discriminants is always ``True``. This usage is
kono
parents:
diff changeset
187 compatible with older Ada compilers, including notably DEC Ada.
kono
parents:
diff changeset
188
kono
parents:
diff changeset
189
kono
parents:
diff changeset
190 Attribute Default_Bit_Order
kono
parents:
diff changeset
191 ===========================
kono
parents:
diff changeset
192 .. index:: Big endian
kono
parents:
diff changeset
193
kono
parents:
diff changeset
194 .. index:: Little endian
kono
parents:
diff changeset
195
kono
parents:
diff changeset
196 .. index:: Default_Bit_Order
kono
parents:
diff changeset
197
kono
parents:
diff changeset
198 ``Standard'Default_Bit_Order`` (``Standard`` is the only
kono
parents:
diff changeset
199 permissible prefix), provides the value ``System.Default_Bit_Order``
kono
parents:
diff changeset
200 as a ``Pos`` value (0 for ``High_Order_First``, 1 for
kono
parents:
diff changeset
201 ``Low_Order_First``). This is used to construct the definition of
kono
parents:
diff changeset
202 ``Default_Bit_Order`` in package ``System``.
kono
parents:
diff changeset
203
kono
parents:
diff changeset
204 Attribute Default_Scalar_Storage_Order
kono
parents:
diff changeset
205 ======================================
kono
parents:
diff changeset
206 .. index:: Big endian
kono
parents:
diff changeset
207
kono
parents:
diff changeset
208 .. index:: Little endian
kono
parents:
diff changeset
209
kono
parents:
diff changeset
210 .. index:: Default_Scalar_Storage_Order
kono
parents:
diff changeset
211
kono
parents:
diff changeset
212 ``Standard'Default_Scalar_Storage_Order`` (``Standard`` is the only
kono
parents:
diff changeset
213 permissible prefix), provides the current value of the default scalar storage
kono
parents:
diff changeset
214 order (as specified using pragma ``Default_Scalar_Storage_Order``, or
kono
parents:
diff changeset
215 equal to ``Default_Bit_Order`` if unspecified) as a
kono
parents:
diff changeset
216 ``System.Bit_Order`` value. This is a static attribute.
kono
parents:
diff changeset
217
kono
parents:
diff changeset
218 Attribute Deref
kono
parents:
diff changeset
219 ===============
kono
parents:
diff changeset
220 .. index:: Deref
kono
parents:
diff changeset
221
kono
parents:
diff changeset
222 The attribute ``typ'Deref(expr)`` where ``expr`` is of type ``System.Address`` yields
kono
parents:
diff changeset
223 the variable of type ``typ`` that is located at the given address. It is similar
kono
parents:
diff changeset
224 to ``(totyp (expr).all)``, where ``totyp`` is an unchecked conversion from address to
kono
parents:
diff changeset
225 a named access-to-`typ` type, except that it yields a variable, so it can be
kono
parents:
diff changeset
226 used on the left side of an assignment.
kono
parents:
diff changeset
227
kono
parents:
diff changeset
228 Attribute Descriptor_Size
kono
parents:
diff changeset
229 =========================
kono
parents:
diff changeset
230 .. index:: Descriptor
kono
parents:
diff changeset
231
kono
parents:
diff changeset
232 .. index:: Dope vector
kono
parents:
diff changeset
233
kono
parents:
diff changeset
234 .. index:: Descriptor_Size
kono
parents:
diff changeset
235
kono
parents:
diff changeset
236 Nonstatic attribute ``Descriptor_Size`` returns the size in bits of the
kono
parents:
diff changeset
237 descriptor allocated for a type. The result is non-zero only for unconstrained
kono
parents:
diff changeset
238 array types and the returned value is of type universal integer. In GNAT, an
kono
parents:
diff changeset
239 array descriptor contains bounds information and is located immediately before
kono
parents:
diff changeset
240 the first element of the array.
kono
parents:
diff changeset
241
kono
parents:
diff changeset
242 .. code-block:: ada
kono
parents:
diff changeset
243
kono
parents:
diff changeset
244 type Unconstr_Array is array (Positive range <>) of Boolean;
kono
parents:
diff changeset
245 Put_Line ("Descriptor size = " & Unconstr_Array'Descriptor_Size'Img);
kono
parents:
diff changeset
246
kono
parents:
diff changeset
247
kono
parents:
diff changeset
248 The attribute takes into account any additional padding due to type alignment.
kono
parents:
diff changeset
249 In the example above, the descriptor contains two values of type
kono
parents:
diff changeset
250 ``Positive`` representing the low and high bound. Since ``Positive`` has
kono
parents:
diff changeset
251 a size of 31 bits and an alignment of 4, the descriptor size is ``2 * Positive'Size + 2`` or 64 bits.
kono
parents:
diff changeset
252
kono
parents:
diff changeset
253 Attribute Elaborated
kono
parents:
diff changeset
254 ====================
kono
parents:
diff changeset
255 .. index:: Elaborated
kono
parents:
diff changeset
256
kono
parents:
diff changeset
257 The prefix of the ``'Elaborated`` attribute must be a unit name. The
kono
parents:
diff changeset
258 value is a Boolean which indicates whether or not the given unit has been
kono
parents:
diff changeset
259 elaborated. This attribute is primarily intended for internal use by the
kono
parents:
diff changeset
260 generated code for dynamic elaboration checking, but it can also be used
kono
parents:
diff changeset
261 in user programs. The value will always be True once elaboration of all
kono
parents:
diff changeset
262 units has been completed. An exception is for units which need no
kono
parents:
diff changeset
263 elaboration, the value is always False for such units.
kono
parents:
diff changeset
264
kono
parents:
diff changeset
265 Attribute Elab_Body
kono
parents:
diff changeset
266 ===================
kono
parents:
diff changeset
267 .. index:: Elab_Body
kono
parents:
diff changeset
268
kono
parents:
diff changeset
269 This attribute can only be applied to a program unit name. It returns
kono
parents:
diff changeset
270 the entity for the corresponding elaboration procedure for elaborating
kono
parents:
diff changeset
271 the body of the referenced unit. This is used in the main generated
kono
parents:
diff changeset
272 elaboration procedure by the binder and is not normally used in any
kono
parents:
diff changeset
273 other context. However, there may be specialized situations in which it
kono
parents:
diff changeset
274 is useful to be able to call this elaboration procedure from Ada code,
kono
parents:
diff changeset
275 e.g., if it is necessary to do selective re-elaboration to fix some
kono
parents:
diff changeset
276 error.
kono
parents:
diff changeset
277
kono
parents:
diff changeset
278 Attribute Elab_Spec
kono
parents:
diff changeset
279 ===================
kono
parents:
diff changeset
280 .. index:: Elab_Spec
kono
parents:
diff changeset
281
kono
parents:
diff changeset
282 This attribute can only be applied to a program unit name. It returns
kono
parents:
diff changeset
283 the entity for the corresponding elaboration procedure for elaborating
kono
parents:
diff changeset
284 the spec of the referenced unit. This is used in the main
kono
parents:
diff changeset
285 generated elaboration procedure by the binder and is not normally used
kono
parents:
diff changeset
286 in any other context. However, there may be specialized situations in
kono
parents:
diff changeset
287 which it is useful to be able to call this elaboration procedure from
kono
parents:
diff changeset
288 Ada code, e.g., if it is necessary to do selective re-elaboration to fix
kono
parents:
diff changeset
289 some error.
kono
parents:
diff changeset
290
kono
parents:
diff changeset
291 Attribute Elab_Subp_Body
kono
parents:
diff changeset
292 ========================
kono
parents:
diff changeset
293 .. index:: Elab_Subp_Body
kono
parents:
diff changeset
294
kono
parents:
diff changeset
295 This attribute can only be applied to a library level subprogram
kono
parents:
diff changeset
296 name and is only allowed in CodePeer mode. It returns the entity
kono
parents:
diff changeset
297 for the corresponding elaboration procedure for elaborating the body
kono
parents:
diff changeset
298 of the referenced subprogram unit. This is used in the main generated
kono
parents:
diff changeset
299 elaboration procedure by the binder in CodePeer mode only and is unrecognized
kono
parents:
diff changeset
300 otherwise.
kono
parents:
diff changeset
301
kono
parents:
diff changeset
302 Attribute Emax
kono
parents:
diff changeset
303 ==============
kono
parents:
diff changeset
304 .. index:: Ada 83 attributes
kono
parents:
diff changeset
305
kono
parents:
diff changeset
306 .. index:: Emax
kono
parents:
diff changeset
307
kono
parents:
diff changeset
308 The ``Emax`` attribute is provided for compatibility with Ada 83. See
kono
parents:
diff changeset
309 the Ada 83 reference manual for an exact description of the semantics of
kono
parents:
diff changeset
310 this attribute.
kono
parents:
diff changeset
311
kono
parents:
diff changeset
312 Attribute Enabled
kono
parents:
diff changeset
313 =================
kono
parents:
diff changeset
314 .. index:: Enabled
kono
parents:
diff changeset
315
kono
parents:
diff changeset
316 The ``Enabled`` attribute allows an application program to check at compile
kono
parents:
diff changeset
317 time to see if the designated check is currently enabled. The prefix is a
kono
parents:
diff changeset
318 simple identifier, referencing any predefined check name (other than
kono
parents:
diff changeset
319 ``All_Checks``) or a check name introduced by pragma Check_Name. If
kono
parents:
diff changeset
320 no argument is given for the attribute, the check is for the general state
kono
parents:
diff changeset
321 of the check, if an argument is given, then it is an entity name, and the
kono
parents:
diff changeset
322 check indicates whether an ``Suppress`` or ``Unsuppress`` has been
kono
parents:
diff changeset
323 given naming the entity (if not, then the argument is ignored).
kono
parents:
diff changeset
324
kono
parents:
diff changeset
325 Note that instantiations inherit the check status at the point of the
kono
parents:
diff changeset
326 instantiation, so a useful idiom is to have a library package that
kono
parents:
diff changeset
327 introduces a check name with ``pragma Check_Name``, and then contains
kono
parents:
diff changeset
328 generic packages or subprograms which use the ``Enabled`` attribute
kono
parents:
diff changeset
329 to see if the check is enabled. A user of this package can then issue
kono
parents:
diff changeset
330 a ``pragma Suppress`` or ``pragma Unsuppress`` before instantiating
kono
parents:
diff changeset
331 the package or subprogram, controlling whether the check will be present.
kono
parents:
diff changeset
332
kono
parents:
diff changeset
333 Attribute Enum_Rep
kono
parents:
diff changeset
334 ==================
kono
parents:
diff changeset
335 .. index:: Representation of enums
kono
parents:
diff changeset
336
kono
parents:
diff changeset
337 .. index:: Enum_Rep
kono
parents:
diff changeset
338
kono
parents:
diff changeset
339 For every enumeration subtype ``S``, ``S'Enum_Rep`` denotes a
kono
parents:
diff changeset
340 function with the following spec:
kono
parents:
diff changeset
341
kono
parents:
diff changeset
342 .. code-block:: ada
kono
parents:
diff changeset
343
kono
parents:
diff changeset
344 function S'Enum_Rep (Arg : S'Base) return <Universal_Integer>;
kono
parents:
diff changeset
345
kono
parents:
diff changeset
346
kono
parents:
diff changeset
347 It is also allowable to apply ``Enum_Rep`` directly to an object of an
kono
parents:
diff changeset
348 enumeration type or to a non-overloaded enumeration
kono
parents:
diff changeset
349 literal. In this case ``S'Enum_Rep`` is equivalent to
kono
parents:
diff changeset
350 ``typ'Enum_Rep(S)`` where ``typ`` is the type of the
kono
parents:
diff changeset
351 enumeration literal or object.
kono
parents:
diff changeset
352
kono
parents:
diff changeset
353 The function returns the representation value for the given enumeration
kono
parents:
diff changeset
354 value. This will be equal to value of the ``Pos`` attribute in the
kono
parents:
diff changeset
355 absence of an enumeration representation clause. This is a static
kono
parents:
diff changeset
356 attribute (i.e.,:the result is static if the argument is static).
kono
parents:
diff changeset
357
kono
parents:
diff changeset
358 ``S'Enum_Rep`` can also be used with integer types and objects,
kono
parents:
diff changeset
359 in which case it simply returns the integer value. The reason for this
kono
parents:
diff changeset
360 is to allow it to be used for ``(<>)`` discrete formal arguments in
kono
parents:
diff changeset
361 a generic unit that can be instantiated with either enumeration types
kono
parents:
diff changeset
362 or integer types. Note that if ``Enum_Rep`` is used on a modular
kono
parents:
diff changeset
363 type whose upper bound exceeds the upper bound of the largest signed
kono
parents:
diff changeset
364 integer type, and the argument is a variable, so that the universal
kono
parents:
diff changeset
365 integer calculation is done at run time, then the call to ``Enum_Rep``
kono
parents:
diff changeset
366 may raise ``Constraint_Error``.
kono
parents:
diff changeset
367
kono
parents:
diff changeset
368 Attribute Enum_Val
kono
parents:
diff changeset
369 ==================
kono
parents:
diff changeset
370 .. index:: Representation of enums
kono
parents:
diff changeset
371
kono
parents:
diff changeset
372 .. index:: Enum_Val
kono
parents:
diff changeset
373
kono
parents:
diff changeset
374 For every enumeration subtype ``S``, ``S'Enum_Val`` denotes a
kono
parents:
diff changeset
375 function with the following spec:
kono
parents:
diff changeset
376
kono
parents:
diff changeset
377 .. code-block:: ada
kono
parents:
diff changeset
378
kono
parents:
diff changeset
379 function S'Enum_Val (Arg : <Universal_Integer>) return S'Base;
kono
parents:
diff changeset
380
kono
parents:
diff changeset
381
kono
parents:
diff changeset
382 The function returns the enumeration value whose representation matches the
kono
parents:
diff changeset
383 argument, or raises Constraint_Error if no enumeration literal of the type
kono
parents:
diff changeset
384 has the matching value.
kono
parents:
diff changeset
385 This will be equal to value of the ``Val`` attribute in the
kono
parents:
diff changeset
386 absence of an enumeration representation clause. This is a static
kono
parents:
diff changeset
387 attribute (i.e., the result is static if the argument is static).
kono
parents:
diff changeset
388
kono
parents:
diff changeset
389 Attribute Epsilon
kono
parents:
diff changeset
390 =================
kono
parents:
diff changeset
391 .. index:: Ada 83 attributes
kono
parents:
diff changeset
392
kono
parents:
diff changeset
393 .. index:: Epsilon
kono
parents:
diff changeset
394
kono
parents:
diff changeset
395 The ``Epsilon`` attribute is provided for compatibility with Ada 83. See
kono
parents:
diff changeset
396 the Ada 83 reference manual for an exact description of the semantics of
kono
parents:
diff changeset
397 this attribute.
kono
parents:
diff changeset
398
kono
parents:
diff changeset
399 Attribute Fast_Math
kono
parents:
diff changeset
400 ===================
kono
parents:
diff changeset
401 .. index:: Fast_Math
kono
parents:
diff changeset
402
kono
parents:
diff changeset
403 ``Standard'Fast_Math`` (``Standard`` is the only allowed
kono
parents:
diff changeset
404 prefix) yields a static Boolean value that is True if pragma
kono
parents:
diff changeset
405 ``Fast_Math`` is active, and False otherwise.
kono
parents:
diff changeset
406
kono
parents:
diff changeset
407 Attribute Finalization_Size
kono
parents:
diff changeset
408 ===========================
kono
parents:
diff changeset
409 .. index:: Finalization_Size
kono
parents:
diff changeset
410
kono
parents:
diff changeset
411 The prefix of attribute ``Finalization_Size`` must be an object or
kono
parents:
diff changeset
412 a non-class-wide type. This attribute returns the size of any hidden data
kono
parents:
diff changeset
413 reserved by the compiler to handle finalization-related actions. The type of
kono
parents:
diff changeset
414 the attribute is *universal_integer*.
kono
parents:
diff changeset
415
kono
parents:
diff changeset
416 ``Finalization_Size`` yields a value of zero for a type with no controlled
kono
parents:
diff changeset
417 parts, an object whose type has no controlled parts, or an object of a
kono
parents:
diff changeset
418 class-wide type whose tag denotes a type with no controlled parts.
kono
parents:
diff changeset
419
kono
parents:
diff changeset
420 Note that only heap-allocated objects contain finalization data.
kono
parents:
diff changeset
421
kono
parents:
diff changeset
422 Attribute Fixed_Value
kono
parents:
diff changeset
423 =====================
kono
parents:
diff changeset
424 .. index:: Fixed_Value
kono
parents:
diff changeset
425
kono
parents:
diff changeset
426 For every fixed-point type ``S``, ``S'Fixed_Value`` denotes a
kono
parents:
diff changeset
427 function with the following specification:
kono
parents:
diff changeset
428
kono
parents:
diff changeset
429 .. code-block:: ada
kono
parents:
diff changeset
430
kono
parents:
diff changeset
431 function S'Fixed_Value (Arg : <Universal_Integer>) return S;
kono
parents:
diff changeset
432
kono
parents:
diff changeset
433 The value returned is the fixed-point value ``V`` such that::
kono
parents:
diff changeset
434
kono
parents:
diff changeset
435 V = Arg * S'Small
kono
parents:
diff changeset
436
kono
parents:
diff changeset
437
kono
parents:
diff changeset
438 The effect is thus similar to first converting the argument to the
kono
parents:
diff changeset
439 integer type used to represent ``S``, and then doing an unchecked
kono
parents:
diff changeset
440 conversion to the fixed-point type. The difference is
kono
parents:
diff changeset
441 that there are full range checks, to ensure that the result is in range.
kono
parents:
diff changeset
442 This attribute is primarily intended for use in implementation of the
kono
parents:
diff changeset
443 input-output functions for fixed-point values.
kono
parents:
diff changeset
444
kono
parents:
diff changeset
445 Attribute From_Any
kono
parents:
diff changeset
446 ==================
kono
parents:
diff changeset
447 .. index:: From_Any
kono
parents:
diff changeset
448
kono
parents:
diff changeset
449 This internal attribute is used for the generation of remote subprogram
kono
parents:
diff changeset
450 stubs in the context of the Distributed Systems Annex.
kono
parents:
diff changeset
451
kono
parents:
diff changeset
452 Attribute Has_Access_Values
kono
parents:
diff changeset
453 ===========================
kono
parents:
diff changeset
454 .. index:: Access values, testing for
kono
parents:
diff changeset
455
kono
parents:
diff changeset
456 .. index:: Has_Access_Values
kono
parents:
diff changeset
457
kono
parents:
diff changeset
458 The prefix of the ``Has_Access_Values`` attribute is a type. The result
kono
parents:
diff changeset
459 is a Boolean value which is True if the is an access type, or is a composite
kono
parents:
diff changeset
460 type with a component (at any nesting depth) that is an access type, and is
kono
parents:
diff changeset
461 False otherwise.
kono
parents:
diff changeset
462 The intended use of this attribute is in conjunction with generic
kono
parents:
diff changeset
463 definitions. If the attribute is applied to a generic private type, it
kono
parents:
diff changeset
464 indicates whether or not the corresponding actual type has access values.
kono
parents:
diff changeset
465
kono
parents:
diff changeset
466 Attribute Has_Discriminants
kono
parents:
diff changeset
467 ===========================
kono
parents:
diff changeset
468 .. index:: Discriminants, testing for
kono
parents:
diff changeset
469
kono
parents:
diff changeset
470 .. index:: Has_Discriminants
kono
parents:
diff changeset
471
kono
parents:
diff changeset
472 The prefix of the ``Has_Discriminants`` attribute is a type. The result
kono
parents:
diff changeset
473 is a Boolean value which is True if the type has discriminants, and False
kono
parents:
diff changeset
474 otherwise. The intended use of this attribute is in conjunction with generic
kono
parents:
diff changeset
475 definitions. If the attribute is applied to a generic private type, it
kono
parents:
diff changeset
476 indicates whether or not the corresponding actual type has discriminants.
kono
parents:
diff changeset
477
kono
parents:
diff changeset
478 Attribute Img
kono
parents:
diff changeset
479 =============
kono
parents:
diff changeset
480 .. index:: Img
kono
parents:
diff changeset
481
kono
parents:
diff changeset
482 The ``Img`` attribute differs from ``Image`` in that it is applied
kono
parents:
diff changeset
483 directly to an object, and yields the same result as
kono
parents:
diff changeset
484 ``Image`` for the subtype of the object. This is convenient for
kono
parents:
diff changeset
485 debugging:
kono
parents:
diff changeset
486
kono
parents:
diff changeset
487 .. code-block:: ada
kono
parents:
diff changeset
488
kono
parents:
diff changeset
489 Put_Line ("X = " & X'Img);
kono
parents:
diff changeset
490
kono
parents:
diff changeset
491
kono
parents:
diff changeset
492 has the same meaning as the more verbose:
kono
parents:
diff changeset
493
kono
parents:
diff changeset
494 .. code-block:: ada
kono
parents:
diff changeset
495
kono
parents:
diff changeset
496 Put_Line ("X = " & T'Image (X));
kono
parents:
diff changeset
497
kono
parents:
diff changeset
498 where ``T`` is the (sub)type of the object ``X``.
kono
parents:
diff changeset
499
kono
parents:
diff changeset
500 Note that technically, in analogy to ``Image``,
kono
parents:
diff changeset
501 ``X'Img`` returns a parameterless function
kono
parents:
diff changeset
502 that returns the appropriate string when called. This means that
kono
parents:
diff changeset
503 ``X'Img`` can be renamed as a function-returning-string, or used
kono
parents:
diff changeset
504 in an instantiation as a function parameter.
kono
parents:
diff changeset
505
kono
parents:
diff changeset
506 Attribute Integer_Value
kono
parents:
diff changeset
507 =======================
kono
parents:
diff changeset
508 .. index:: Integer_Value
kono
parents:
diff changeset
509
kono
parents:
diff changeset
510 For every integer type ``S``, ``S'Integer_Value`` denotes a
kono
parents:
diff changeset
511 function with the following spec:
kono
parents:
diff changeset
512
kono
parents:
diff changeset
513 .. code-block:: ada
kono
parents:
diff changeset
514
kono
parents:
diff changeset
515 function S'Integer_Value (Arg : <Universal_Fixed>) return S;
kono
parents:
diff changeset
516
kono
parents:
diff changeset
517 The value returned is the integer value ``V``, such that::
kono
parents:
diff changeset
518
kono
parents:
diff changeset
519 Arg = V * T'Small
kono
parents:
diff changeset
520
kono
parents:
diff changeset
521
kono
parents:
diff changeset
522 where ``T`` is the type of ``Arg``.
kono
parents:
diff changeset
523 The effect is thus similar to first doing an unchecked conversion from
kono
parents:
diff changeset
524 the fixed-point type to its corresponding implementation type, and then
kono
parents:
diff changeset
525 converting the result to the target integer type. The difference is
kono
parents:
diff changeset
526 that there are full range checks, to ensure that the result is in range.
kono
parents:
diff changeset
527 This attribute is primarily intended for use in implementation of the
kono
parents:
diff changeset
528 standard input-output functions for fixed-point values.
kono
parents:
diff changeset
529
kono
parents:
diff changeset
530 Attribute Invalid_Value
kono
parents:
diff changeset
531 =======================
kono
parents:
diff changeset
532 .. index:: Invalid_Value
kono
parents:
diff changeset
533
kono
parents:
diff changeset
534 For every scalar type S, S'Invalid_Value returns an undefined value of the
kono
parents:
diff changeset
535 type. If possible this value is an invalid representation for the type. The
kono
parents:
diff changeset
536 value returned is identical to the value used to initialize an otherwise
kono
parents:
diff changeset
537 uninitialized value of the type if pragma Initialize_Scalars is used,
kono
parents:
diff changeset
538 including the ability to modify the value with the binder -Sxx flag and
kono
parents:
diff changeset
539 relevant environment variables at run time.
kono
parents:
diff changeset
540
kono
parents:
diff changeset
541 Attribute Iterable
kono
parents:
diff changeset
542 ==================
kono
parents:
diff changeset
543 .. index:: Iterable
kono
parents:
diff changeset
544
kono
parents:
diff changeset
545 Equivalent to Aspect Iterable.
kono
parents:
diff changeset
546
kono
parents:
diff changeset
547 Attribute Large
kono
parents:
diff changeset
548 ===============
kono
parents:
diff changeset
549 .. index:: Ada 83 attributes
kono
parents:
diff changeset
550
kono
parents:
diff changeset
551 .. index:: Large
kono
parents:
diff changeset
552
kono
parents:
diff changeset
553 The ``Large`` attribute is provided for compatibility with Ada 83. See
kono
parents:
diff changeset
554 the Ada 83 reference manual for an exact description of the semantics of
kono
parents:
diff changeset
555 this attribute.
kono
parents:
diff changeset
556
kono
parents:
diff changeset
557 Attribute Library_Level
kono
parents:
diff changeset
558 =======================
kono
parents:
diff changeset
559 .. index:: Library_Level
kono
parents:
diff changeset
560
kono
parents:
diff changeset
561 ``P'Library_Level``, where P is an entity name,
kono
parents:
diff changeset
562 returns a Boolean value which is True if the entity is declared
kono
parents:
diff changeset
563 at the library level, and False otherwise. Note that within a
kono
parents:
diff changeset
564 generic instantition, the name of the generic unit denotes the
kono
parents:
diff changeset
565 instance, which means that this attribute can be used to test
kono
parents:
diff changeset
566 if a generic is instantiated at the library level, as shown
kono
parents:
diff changeset
567 in this example:
kono
parents:
diff changeset
568
kono
parents:
diff changeset
569 .. code-block:: ada
kono
parents:
diff changeset
570
kono
parents:
diff changeset
571 generic
kono
parents:
diff changeset
572 ...
kono
parents:
diff changeset
573 package Gen is
kono
parents:
diff changeset
574 pragma Compile_Time_Error
kono
parents:
diff changeset
575 (not Gen'Library_Level,
kono
parents:
diff changeset
576 "Gen can only be instantiated at library level");
kono
parents:
diff changeset
577 ...
kono
parents:
diff changeset
578 end Gen;
kono
parents:
diff changeset
579
kono
parents:
diff changeset
580
kono
parents:
diff changeset
581 Attribute Lock_Free
kono
parents:
diff changeset
582 ===================
kono
parents:
diff changeset
583 .. index:: Lock_Free
kono
parents:
diff changeset
584
kono
parents:
diff changeset
585 ``P'Lock_Free``, where P is a protected object, returns True if a
kono
parents:
diff changeset
586 pragma ``Lock_Free`` applies to P.
kono
parents:
diff changeset
587
kono
parents:
diff changeset
588 Attribute Loop_Entry
kono
parents:
diff changeset
589 ====================
kono
parents:
diff changeset
590 .. index:: Loop_Entry
kono
parents:
diff changeset
591
kono
parents:
diff changeset
592 Syntax::
kono
parents:
diff changeset
593
kono
parents:
diff changeset
594 X'Loop_Entry [(loop_name)]
kono
parents:
diff changeset
595
kono
parents:
diff changeset
596
kono
parents:
diff changeset
597 The ``Loop_Entry`` attribute is used to refer to the value that an
kono
parents:
diff changeset
598 expression had upon entry to a given loop in much the same way that the
kono
parents:
diff changeset
599 ``Old`` attribute in a subprogram postcondition can be used to refer
kono
parents:
diff changeset
600 to the value an expression had upon entry to the subprogram. The
kono
parents:
diff changeset
601 relevant loop is either identified by the given loop name, or it is the
kono
parents:
diff changeset
602 innermost enclosing loop when no loop name is given.
kono
parents:
diff changeset
603
kono
parents:
diff changeset
604 A ``Loop_Entry`` attribute can only occur within a
kono
parents:
diff changeset
605 ``Loop_Variant`` or ``Loop_Invariant`` pragma. A common use of
kono
parents:
diff changeset
606 ``Loop_Entry`` is to compare the current value of objects with their
kono
parents:
diff changeset
607 initial value at loop entry, in a ``Loop_Invariant`` pragma.
kono
parents:
diff changeset
608
kono
parents:
diff changeset
609 The effect of using ``X'Loop_Entry`` is the same as declaring
kono
parents:
diff changeset
610 a constant initialized with the initial value of ``X`` at loop
kono
parents:
diff changeset
611 entry. This copy is not performed if the loop is not entered, or if the
kono
parents:
diff changeset
612 corresponding pragmas are ignored or disabled.
kono
parents:
diff changeset
613
kono
parents:
diff changeset
614 Attribute Machine_Size
kono
parents:
diff changeset
615 ======================
kono
parents:
diff changeset
616 .. index:: Machine_Size
kono
parents:
diff changeset
617
kono
parents:
diff changeset
618 This attribute is identical to the ``Object_Size`` attribute. It is
kono
parents:
diff changeset
619 provided for compatibility with the DEC Ada 83 attribute of this name.
kono
parents:
diff changeset
620
kono
parents:
diff changeset
621 Attribute Mantissa
kono
parents:
diff changeset
622 ==================
kono
parents:
diff changeset
623 .. index:: Ada 83 attributes
kono
parents:
diff changeset
624
kono
parents:
diff changeset
625 .. index:: Mantissa
kono
parents:
diff changeset
626
kono
parents:
diff changeset
627 The ``Mantissa`` attribute is provided for compatibility with Ada 83. See
kono
parents:
diff changeset
628 the Ada 83 reference manual for an exact description of the semantics of
kono
parents:
diff changeset
629 this attribute.
kono
parents:
diff changeset
630
kono
parents:
diff changeset
631 .. _Attribute_Maximum_Alignment:
kono
parents:
diff changeset
632
kono
parents:
diff changeset
633 Attribute Maximum_Alignment
kono
parents:
diff changeset
634 ===========================
kono
parents:
diff changeset
635 .. index:: Alignment, maximum
kono
parents:
diff changeset
636
kono
parents:
diff changeset
637 .. index:: Maximum_Alignment
kono
parents:
diff changeset
638
kono
parents:
diff changeset
639 ``Standard'Maximum_Alignment`` (``Standard`` is the only
kono
parents:
diff changeset
640 permissible prefix) provides the maximum useful alignment value for the
kono
parents:
diff changeset
641 target. This is a static value that can be used to specify the alignment
kono
parents:
diff changeset
642 for an object, guaranteeing that it is properly aligned in all
kono
parents:
diff changeset
643 cases.
kono
parents:
diff changeset
644
kono
parents:
diff changeset
645 Attribute Mechanism_Code
kono
parents:
diff changeset
646 ========================
kono
parents:
diff changeset
647 .. index:: Return values, passing mechanism
kono
parents:
diff changeset
648
kono
parents:
diff changeset
649 .. index:: Parameters, passing mechanism
kono
parents:
diff changeset
650
kono
parents:
diff changeset
651 .. index:: Mechanism_Code
kono
parents:
diff changeset
652
kono
parents:
diff changeset
653 ``func'Mechanism_Code`` yields an integer code for the
kono
parents:
diff changeset
654 mechanism used for the result of function ``func``, and
kono
parents:
diff changeset
655 ``subprog'Mechanism_Code (n)`` yields the mechanism
kono
parents:
diff changeset
656 used for formal parameter number *n* (a static integer value, with 1
kono
parents:
diff changeset
657 meaning the first parameter) of subprogram ``subprog``. The code returned is:
kono
parents:
diff changeset
658
kono
parents:
diff changeset
659
kono
parents:
diff changeset
660
kono
parents:
diff changeset
661 *1*
kono
parents:
diff changeset
662 by copy (value)
kono
parents:
diff changeset
663
kono
parents:
diff changeset
664 *2*
kono
parents:
diff changeset
665 by reference
kono
parents:
diff changeset
666
kono
parents:
diff changeset
667 Attribute Null_Parameter
kono
parents:
diff changeset
668 ========================
kono
parents:
diff changeset
669 .. index:: Zero address, passing
kono
parents:
diff changeset
670
kono
parents:
diff changeset
671 .. index:: Null_Parameter
kono
parents:
diff changeset
672
kono
parents:
diff changeset
673 A reference ``T'Null_Parameter`` denotes an imaginary object of
kono
parents:
diff changeset
674 type or subtype ``T`` allocated at machine address zero. The attribute
kono
parents:
diff changeset
675 is allowed only as the default expression of a formal parameter, or as
kono
parents:
diff changeset
676 an actual expression of a subprogram call. In either case, the
kono
parents:
diff changeset
677 subprogram must be imported.
kono
parents:
diff changeset
678
kono
parents:
diff changeset
679 The identity of the object is represented by the address zero in the
kono
parents:
diff changeset
680 argument list, independent of the passing mechanism (explicit or
kono
parents:
diff changeset
681 default).
kono
parents:
diff changeset
682
kono
parents:
diff changeset
683 This capability is needed to specify that a zero address should be
kono
parents:
diff changeset
684 passed for a record or other composite object passed by reference.
kono
parents:
diff changeset
685 There is no way of indicating this without the ``Null_Parameter``
kono
parents:
diff changeset
686 attribute.
kono
parents:
diff changeset
687
kono
parents:
diff changeset
688 .. _Attribute-Object_Size:
kono
parents:
diff changeset
689
kono
parents:
diff changeset
690 Attribute Object_Size
kono
parents:
diff changeset
691 =====================
kono
parents:
diff changeset
692 .. index:: Size, used for objects
kono
parents:
diff changeset
693
kono
parents:
diff changeset
694 .. index:: Object_Size
kono
parents:
diff changeset
695
kono
parents:
diff changeset
696 The size of an object is not necessarily the same as the size of the type
kono
parents:
diff changeset
697 of an object. This is because by default object sizes are increased to be
kono
parents:
diff changeset
698 a multiple of the alignment of the object. For example,
kono
parents:
diff changeset
699 ``Natural'Size`` is
kono
parents:
diff changeset
700 31, but by default objects of type ``Natural`` will have a size of 32 bits.
kono
parents:
diff changeset
701 Similarly, a record containing an integer and a character:
kono
parents:
diff changeset
702
kono
parents:
diff changeset
703 .. code-block:: ada
kono
parents:
diff changeset
704
kono
parents:
diff changeset
705 type Rec is record
kono
parents:
diff changeset
706 I : Integer;
kono
parents:
diff changeset
707 C : Character;
kono
parents:
diff changeset
708 end record;
kono
parents:
diff changeset
709
kono
parents:
diff changeset
710
kono
parents:
diff changeset
711 will have a size of 40 (that is ``Rec'Size`` will be 40). The
kono
parents:
diff changeset
712 alignment will be 4, because of the
kono
parents:
diff changeset
713 integer field, and so the default size of record objects for this type
kono
parents:
diff changeset
714 will be 64 (8 bytes).
kono
parents:
diff changeset
715
kono
parents:
diff changeset
716 If the alignment of the above record is specified to be 1, then the
kono
parents:
diff changeset
717 object size will be 40 (5 bytes). This is true by default, and also
kono
parents:
diff changeset
718 an object size of 40 can be explicitly specified in this case.
kono
parents:
diff changeset
719
kono
parents:
diff changeset
720 A consequence of this capability is that different object sizes can be
kono
parents:
diff changeset
721 given to subtypes that would otherwise be considered in Ada to be
kono
parents:
diff changeset
722 statically matching. But it makes no sense to consider such subtypes
kono
parents:
diff changeset
723 as statically matching. Consequently, GNAT adds a rule
kono
parents:
diff changeset
724 to the static matching rules that requires object sizes to match.
kono
parents:
diff changeset
725 Consider this example:
kono
parents:
diff changeset
726
kono
parents:
diff changeset
727 .. code-block:: ada
kono
parents:
diff changeset
728
kono
parents:
diff changeset
729 1. procedure BadAVConvert is
kono
parents:
diff changeset
730 2. type R is new Integer;
kono
parents:
diff changeset
731 3. subtype R1 is R range 1 .. 10;
kono
parents:
diff changeset
732 4. subtype R2 is R range 1 .. 10;
kono
parents:
diff changeset
733 5. for R1'Object_Size use 8;
kono
parents:
diff changeset
734 6. for R2'Object_Size use 16;
kono
parents:
diff changeset
735 7. type R1P is access all R1;
kono
parents:
diff changeset
736 8. type R2P is access all R2;
kono
parents:
diff changeset
737 9. R1PV : R1P := new R1'(4);
kono
parents:
diff changeset
738 10. R2PV : R2P;
kono
parents:
diff changeset
739 11. begin
kono
parents:
diff changeset
740 12. R2PV := R2P (R1PV);
kono
parents:
diff changeset
741 |
kono
parents:
diff changeset
742 >>> target designated subtype not compatible with
kono
parents:
diff changeset
743 type "R1" defined at line 3
kono
parents:
diff changeset
744
kono
parents:
diff changeset
745 13. end;
kono
parents:
diff changeset
746
kono
parents:
diff changeset
747
kono
parents:
diff changeset
748 In the absence of lines 5 and 6,
kono
parents:
diff changeset
749 types ``R1`` and ``R2`` statically match and
kono
parents:
diff changeset
750 hence the conversion on line 12 is legal. But since lines 5 and 6
kono
parents:
diff changeset
751 cause the object sizes to differ, GNAT considers that types
kono
parents:
diff changeset
752 ``R1`` and ``R2`` are not statically matching, and line 12
kono
parents:
diff changeset
753 generates the diagnostic shown above.
kono
parents:
diff changeset
754
kono
parents:
diff changeset
755 Similar additional checks are performed in other contexts requiring
kono
parents:
diff changeset
756 statically matching subtypes.
kono
parents:
diff changeset
757
kono
parents:
diff changeset
758 Attribute Old
kono
parents:
diff changeset
759 =============
kono
parents:
diff changeset
760 .. index:: Old
kono
parents:
diff changeset
761
kono
parents:
diff changeset
762 In addition to the usage of ``Old`` defined in the Ada 2012 RM (usage
kono
parents:
diff changeset
763 within ``Post`` aspect), GNAT also permits the use of this attribute
kono
parents:
diff changeset
764 in implementation defined pragmas ``Postcondition``,
kono
parents:
diff changeset
765 ``Contract_Cases`` and ``Test_Case``. Also usages of
kono
parents:
diff changeset
766 ``Old`` which would be illegal according to the Ada 2012 RM
kono
parents:
diff changeset
767 definition are allowed under control of
kono
parents:
diff changeset
768 implementation defined pragma ``Unevaluated_Use_Of_Old``.
kono
parents:
diff changeset
769
kono
parents:
diff changeset
770 Attribute Passed_By_Reference
kono
parents:
diff changeset
771 =============================
kono
parents:
diff changeset
772 .. index:: Parameters, when passed by reference
kono
parents:
diff changeset
773
kono
parents:
diff changeset
774 .. index:: Passed_By_Reference
kono
parents:
diff changeset
775
kono
parents:
diff changeset
776 ``typ'Passed_By_Reference`` for any subtype `typ` returns
kono
parents:
diff changeset
777 a value of type ``Boolean`` value that is ``True`` if the type is
kono
parents:
diff changeset
778 normally passed by reference and ``False`` if the type is normally
kono
parents:
diff changeset
779 passed by copy in calls. For scalar types, the result is always ``False``
kono
parents:
diff changeset
780 and is static. For non-scalar types, the result is nonstatic.
kono
parents:
diff changeset
781
kono
parents:
diff changeset
782 Attribute Pool_Address
kono
parents:
diff changeset
783 ======================
kono
parents:
diff changeset
784 .. index:: Parameters, when passed by reference
kono
parents:
diff changeset
785
kono
parents:
diff changeset
786 .. index:: Pool_Address
kono
parents:
diff changeset
787
kono
parents:
diff changeset
788 ``X'Pool_Address`` for any object ``X`` returns the address
kono
parents:
diff changeset
789 of X within its storage pool. This is the same as
kono
parents:
diff changeset
790 ``X'Address``, except that for an unconstrained array whose
kono
parents:
diff changeset
791 bounds are allocated just before the first component,
kono
parents:
diff changeset
792 ``X'Pool_Address`` returns the address of those bounds,
kono
parents:
diff changeset
793 whereas ``X'Address`` returns the address of the first
kono
parents:
diff changeset
794 component.
kono
parents:
diff changeset
795
kono
parents:
diff changeset
796 Here, we are interpreting 'storage pool' broadly to mean
kono
parents:
diff changeset
797 ``wherever the object is allocated``, which could be a
kono
parents:
diff changeset
798 user-defined storage pool,
kono
parents:
diff changeset
799 the global heap, on the stack, or in a static memory area.
kono
parents:
diff changeset
800 For an object created by ``new``, ``Ptr.all'Pool_Address`` is
kono
parents:
diff changeset
801 what is passed to ``Allocate`` and returned from ``Deallocate``.
kono
parents:
diff changeset
802
kono
parents:
diff changeset
803 Attribute Range_Length
kono
parents:
diff changeset
804 ======================
kono
parents:
diff changeset
805 .. index:: Range_Length
kono
parents:
diff changeset
806
kono
parents:
diff changeset
807 ``typ'Range_Length`` for any discrete type `typ` yields
kono
parents:
diff changeset
808 the number of values represented by the subtype (zero for a null
kono
parents:
diff changeset
809 range). The result is static for static subtypes. ``Range_Length``
kono
parents:
diff changeset
810 applied to the index subtype of a one dimensional array always gives the
kono
parents:
diff changeset
811 same result as ``Length`` applied to the array itself.
kono
parents:
diff changeset
812
kono
parents:
diff changeset
813 Attribute Restriction_Set
kono
parents:
diff changeset
814 =========================
kono
parents:
diff changeset
815 .. index:: Restriction_Set
kono
parents:
diff changeset
816 .. index:: Restrictions
kono
parents:
diff changeset
817
kono
parents:
diff changeset
818 This attribute allows compile time testing of restrictions that
kono
parents:
diff changeset
819 are currently in effect. It is primarily intended for specializing
kono
parents:
diff changeset
820 code in the run-time based on restrictions that are active (e.g.
kono
parents:
diff changeset
821 don't need to save fpt registers if restriction No_Floating_Point
kono
parents:
diff changeset
822 is known to be in effect), but can be used anywhere.
kono
parents:
diff changeset
823
kono
parents:
diff changeset
824 There are two forms:
kono
parents:
diff changeset
825
kono
parents:
diff changeset
826 .. code-block:: ada
kono
parents:
diff changeset
827
kono
parents:
diff changeset
828 System'Restriction_Set (partition_boolean_restriction_NAME)
kono
parents:
diff changeset
829 System'Restriction_Set (No_Dependence => library_unit_NAME);
kono
parents:
diff changeset
830
kono
parents:
diff changeset
831
kono
parents:
diff changeset
832 In the case of the first form, the only restriction names
kono
parents:
diff changeset
833 allowed are parameterless restrictions that are checked
kono
parents:
diff changeset
834 for consistency at bind time. For a complete list see the
kono
parents:
diff changeset
835 subtype ``System.Rident.Partition_Boolean_Restrictions``.
kono
parents:
diff changeset
836
kono
parents:
diff changeset
837 The result returned is True if the restriction is known to
kono
parents:
diff changeset
838 be in effect, and False if the restriction is known not to
kono
parents:
diff changeset
839 be in effect. An important guarantee is that the value of
kono
parents:
diff changeset
840 a Restriction_Set attribute is known to be consistent throughout
kono
parents:
diff changeset
841 all the code of a partition.
kono
parents:
diff changeset
842
kono
parents:
diff changeset
843 This is trivially achieved if the entire partition is compiled
kono
parents:
diff changeset
844 with a consistent set of restriction pragmas. However, the
kono
parents:
diff changeset
845 compilation model does not require this. It is possible to
kono
parents:
diff changeset
846 compile one set of units with one set of pragmas, and another
kono
parents:
diff changeset
847 set of units with another set of pragmas. It is even possible
kono
parents:
diff changeset
848 to compile a spec with one set of pragmas, and then WITH the
kono
parents:
diff changeset
849 same spec with a different set of pragmas. Inconsistencies
kono
parents:
diff changeset
850 in the actual use of the restriction are checked at bind time.
kono
parents:
diff changeset
851
kono
parents:
diff changeset
852 In order to achieve the guarantee of consistency for the
kono
parents:
diff changeset
853 Restriction_Set pragma, we consider that a use of the pragma
kono
parents:
diff changeset
854 that yields False is equivalent to a violation of the
kono
parents:
diff changeset
855 restriction.
kono
parents:
diff changeset
856
kono
parents:
diff changeset
857 So for example if you write
kono
parents:
diff changeset
858
kono
parents:
diff changeset
859 .. code-block:: ada
kono
parents:
diff changeset
860
kono
parents:
diff changeset
861 if System'Restriction_Set (No_Floating_Point) then
kono
parents:
diff changeset
862 ...
kono
parents:
diff changeset
863 else
kono
parents:
diff changeset
864 ...
kono
parents:
diff changeset
865 end if;
kono
parents:
diff changeset
866
kono
parents:
diff changeset
867
kono
parents:
diff changeset
868 And the result is False, so that the else branch is executed,
kono
parents:
diff changeset
869 you can assume that this restriction is not set for any unit
kono
parents:
diff changeset
870 in the partition. This is checked by considering this use of
kono
parents:
diff changeset
871 the restriction pragma to be a violation of the restriction
kono
parents:
diff changeset
872 No_Floating_Point. This means that no other unit can attempt
kono
parents:
diff changeset
873 to set this restriction (if some unit does attempt to set it,
kono
parents:
diff changeset
874 the binder will refuse to bind the partition).
kono
parents:
diff changeset
875
kono
parents:
diff changeset
876 Technical note: The restriction name and the unit name are
kono
parents:
diff changeset
877 intepreted entirely syntactically, as in the corresponding
kono
parents:
diff changeset
878 Restrictions pragma, they are not analyzed semantically,
kono
parents:
diff changeset
879 so they do not have a type.
kono
parents:
diff changeset
880
kono
parents:
diff changeset
881 Attribute Result
kono
parents:
diff changeset
882 ================
kono
parents:
diff changeset
883 .. index:: Result
kono
parents:
diff changeset
884
kono
parents:
diff changeset
885 ``function'Result`` can only be used with in a Postcondition pragma
kono
parents:
diff changeset
886 for a function. The prefix must be the name of the corresponding function. This
kono
parents:
diff changeset
887 is used to refer to the result of the function in the postcondition expression.
kono
parents:
diff changeset
888 For a further discussion of the use of this attribute and examples of its use,
kono
parents:
diff changeset
889 see the description of pragma Postcondition.
kono
parents:
diff changeset
890
kono
parents:
diff changeset
891 Attribute Safe_Emax
kono
parents:
diff changeset
892 ===================
kono
parents:
diff changeset
893 .. index:: Ada 83 attributes
kono
parents:
diff changeset
894
kono
parents:
diff changeset
895 .. index:: Safe_Emax
kono
parents:
diff changeset
896
kono
parents:
diff changeset
897 The ``Safe_Emax`` attribute is provided for compatibility with Ada 83. See
kono
parents:
diff changeset
898 the Ada 83 reference manual for an exact description of the semantics of
kono
parents:
diff changeset
899 this attribute.
kono
parents:
diff changeset
900
kono
parents:
diff changeset
901 Attribute Safe_Large
kono
parents:
diff changeset
902 ====================
kono
parents:
diff changeset
903 .. index:: Ada 83 attributes
kono
parents:
diff changeset
904
kono
parents:
diff changeset
905 .. index:: Safe_Large
kono
parents:
diff changeset
906
kono
parents:
diff changeset
907 The ``Safe_Large`` attribute is provided for compatibility with Ada 83. See
kono
parents:
diff changeset
908 the Ada 83 reference manual for an exact description of the semantics of
kono
parents:
diff changeset
909 this attribute.
kono
parents:
diff changeset
910
kono
parents:
diff changeset
911 Attribute Safe_Small
kono
parents:
diff changeset
912 ====================
kono
parents:
diff changeset
913 .. index:: Ada 83 attributes
kono
parents:
diff changeset
914
kono
parents:
diff changeset
915 .. index:: Safe_Small
kono
parents:
diff changeset
916
kono
parents:
diff changeset
917 The ``Safe_Small`` attribute is provided for compatibility with Ada 83. See
kono
parents:
diff changeset
918 the Ada 83 reference manual for an exact description of the semantics of
kono
parents:
diff changeset
919 this attribute.
kono
parents:
diff changeset
920
kono
parents:
diff changeset
921 .. _Attribute-Scalar_Storage_Order:
kono
parents:
diff changeset
922
kono
parents:
diff changeset
923 Attribute Scalar_Storage_Order
kono
parents:
diff changeset
924 ==============================
kono
parents:
diff changeset
925 .. index:: Endianness
kono
parents:
diff changeset
926
kono
parents:
diff changeset
927 .. index:: Scalar storage order
kono
parents:
diff changeset
928
kono
parents:
diff changeset
929 .. index:: Scalar_Storage_Order
kono
parents:
diff changeset
930
kono
parents:
diff changeset
931 For every array or record type ``S``, the representation attribute
kono
parents:
diff changeset
932 ``Scalar_Storage_Order`` denotes the order in which storage elements
kono
parents:
diff changeset
933 that make up scalar components are ordered within S. The value given must
kono
parents:
diff changeset
934 be a static expression of type System.Bit_Order. The following is an example
kono
parents:
diff changeset
935 of the use of this feature:
kono
parents:
diff changeset
936
kono
parents:
diff changeset
937 .. code-block:: ada
kono
parents:
diff changeset
938
kono
parents:
diff changeset
939 -- Component type definitions
kono
parents:
diff changeset
940
kono
parents:
diff changeset
941 subtype Yr_Type is Natural range 0 .. 127;
kono
parents:
diff changeset
942 subtype Mo_Type is Natural range 1 .. 12;
kono
parents:
diff changeset
943 subtype Da_Type is Natural range 1 .. 31;
kono
parents:
diff changeset
944
kono
parents:
diff changeset
945 -- Record declaration
kono
parents:
diff changeset
946
kono
parents:
diff changeset
947 type Date is record
kono
parents:
diff changeset
948 Years_Since_1980 : Yr_Type;
kono
parents:
diff changeset
949 Month : Mo_Type;
kono
parents:
diff changeset
950 Day_Of_Month : Da_Type;
kono
parents:
diff changeset
951 end record;
kono
parents:
diff changeset
952
kono
parents:
diff changeset
953 -- Record representation clause
kono
parents:
diff changeset
954
kono
parents:
diff changeset
955 for Date use record
kono
parents:
diff changeset
956 Years_Since_1980 at 0 range 0 .. 6;
kono
parents:
diff changeset
957 Month at 0 range 7 .. 10;
kono
parents:
diff changeset
958 Day_Of_Month at 0 range 11 .. 15;
kono
parents:
diff changeset
959 end record;
kono
parents:
diff changeset
960
kono
parents:
diff changeset
961 -- Attribute definition clauses
kono
parents:
diff changeset
962
kono
parents:
diff changeset
963 for Date'Bit_Order use System.High_Order_First;
kono
parents:
diff changeset
964 for Date'Scalar_Storage_Order use System.High_Order_First;
kono
parents:
diff changeset
965 -- If Scalar_Storage_Order is specified, it must be consistent with
kono
parents:
diff changeset
966 -- Bit_Order, so it's best to always define the latter explicitly if
kono
parents:
diff changeset
967 -- the former is used.
kono
parents:
diff changeset
968
kono
parents:
diff changeset
969
kono
parents:
diff changeset
970 Other properties are as for standard representation attribute ``Bit_Order``,
kono
parents:
diff changeset
971 as defined by Ada RM 13.5.3(4). The default is ``System.Default_Bit_Order``.
kono
parents:
diff changeset
972
kono
parents:
diff changeset
973 For a record type ``T``, if ``T'Scalar_Storage_Order`` is
kono
parents:
diff changeset
974 specified explicitly, it shall be equal to ``T'Bit_Order``. Note:
kono
parents:
diff changeset
975 this means that if a ``Scalar_Storage_Order`` attribute definition
kono
parents:
diff changeset
976 clause is not confirming, then the type's ``Bit_Order`` shall be
kono
parents:
diff changeset
977 specified explicitly and set to the same value.
kono
parents:
diff changeset
978
kono
parents:
diff changeset
979 Derived types inherit an explicitly set scalar storage order from their parent
kono
parents:
diff changeset
980 types. This may be overridden for the derived type by giving an explicit scalar
kono
parents:
diff changeset
981 storage order for the derived type. For a record extension, the derived type
kono
parents:
diff changeset
982 must have the same scalar storage order as the parent type.
kono
parents:
diff changeset
983
kono
parents:
diff changeset
984 A component of a record type that is itself a record or an array and that does
kono
parents:
diff changeset
985 not start and end on a byte boundary must have have the same scalar storage
kono
parents:
diff changeset
986 order as the record type. A component of a bit-packed array type that is itself
kono
parents:
diff changeset
987 a record or an array must have the same scalar storage order as the array type.
kono
parents:
diff changeset
988
kono
parents:
diff changeset
989 No component of a type that has an explicit ``Scalar_Storage_Order``
kono
parents:
diff changeset
990 attribute definition may be aliased.
kono
parents:
diff changeset
991
kono
parents:
diff changeset
992 A confirming ``Scalar_Storage_Order`` attribute definition clause (i.e.
kono
parents:
diff changeset
993 with a value equal to ``System.Default_Bit_Order``) has no effect.
kono
parents:
diff changeset
994
kono
parents:
diff changeset
995 If the opposite storage order is specified, then whenever the value of
kono
parents:
diff changeset
996 a scalar component of an object of type ``S`` is read, the storage
kono
parents:
diff changeset
997 elements of the enclosing machine scalar are first reversed (before
kono
parents:
diff changeset
998 retrieving the component value, possibly applying some shift and mask
kono
parents:
diff changeset
999 operatings on the enclosing machine scalar), and the opposite operation
kono
parents:
diff changeset
1000 is done for writes.
kono
parents:
diff changeset
1001
kono
parents:
diff changeset
1002 In that case, the restrictions set forth in 13.5.1(10.3/2) for scalar components
kono
parents:
diff changeset
1003 are relaxed. Instead, the following rules apply:
kono
parents:
diff changeset
1004
kono
parents:
diff changeset
1005 * the underlying storage elements are those at positions
kono
parents:
diff changeset
1006 ``(position + first_bit / storage_element_size) .. (position + (last_bit + storage_element_size - 1) / storage_element_size)``
kono
parents:
diff changeset
1007 * the sequence of underlying storage elements shall have
kono
parents:
diff changeset
1008 a size no greater than the largest machine scalar
kono
parents:
diff changeset
1009 * the enclosing machine scalar is defined as the smallest machine
kono
parents:
diff changeset
1010 scalar starting at a position no greater than
kono
parents:
diff changeset
1011 ``position + first_bit / storage_element_size`` and covering
kono
parents:
diff changeset
1012 storage elements at least up to ``position + (last_bit + storage_element_size - 1) / storage_element_size```
kono
parents:
diff changeset
1013 * the position of the component is interpreted relative to that machine
kono
parents:
diff changeset
1014 scalar.
kono
parents:
diff changeset
1015
kono
parents:
diff changeset
1016 If no scalar storage order is specified for a type (either directly, or by
kono
parents:
diff changeset
1017 inheritance in the case of a derived type), then the default is normally
kono
parents:
diff changeset
1018 the native ordering of the target, but this default can be overridden using
kono
parents:
diff changeset
1019 pragma ``Default_Scalar_Storage_Order``.
kono
parents:
diff changeset
1020
kono
parents:
diff changeset
1021 Note that if a component of ``T`` is itself of a record or array type,
kono
parents:
diff changeset
1022 the specfied ``Scalar_Storage_Order`` does *not* apply to that nested type:
kono
parents:
diff changeset
1023 an explicit attribute definition clause must be provided for the component
kono
parents:
diff changeset
1024 type as well if desired.
kono
parents:
diff changeset
1025
kono
parents:
diff changeset
1026 Note that the scalar storage order only affects the in-memory data
kono
parents:
diff changeset
1027 representation. It has no effect on the representation used by stream
kono
parents:
diff changeset
1028 attributes.
kono
parents:
diff changeset
1029
kono
parents:
diff changeset
1030 .. _Attribute_Simple_Storage_Pool:
kono
parents:
diff changeset
1031
kono
parents:
diff changeset
1032 Attribute Simple_Storage_Pool
kono
parents:
diff changeset
1033 =============================
kono
parents:
diff changeset
1034 .. index:: Storage pool, simple
kono
parents:
diff changeset
1035
kono
parents:
diff changeset
1036 .. index:: Simple storage pool
kono
parents:
diff changeset
1037
kono
parents:
diff changeset
1038 .. index:: Simple_Storage_Pool
kono
parents:
diff changeset
1039
kono
parents:
diff changeset
1040 For every nonformal, nonderived access-to-object type ``Acc``, the
kono
parents:
diff changeset
1041 representation attribute ``Simple_Storage_Pool`` may be specified
kono
parents:
diff changeset
1042 via an attribute_definition_clause (or by specifying the equivalent aspect):
kono
parents:
diff changeset
1043
kono
parents:
diff changeset
1044 .. code-block:: ada
kono
parents:
diff changeset
1045
kono
parents:
diff changeset
1046 My_Pool : My_Simple_Storage_Pool_Type;
kono
parents:
diff changeset
1047
kono
parents:
diff changeset
1048 type Acc is access My_Data_Type;
kono
parents:
diff changeset
1049
kono
parents:
diff changeset
1050 for Acc'Simple_Storage_Pool use My_Pool;
kono
parents:
diff changeset
1051
kono
parents:
diff changeset
1052
kono
parents:
diff changeset
1053
kono
parents:
diff changeset
1054 The name given in an attribute_definition_clause for the
kono
parents:
diff changeset
1055 ``Simple_Storage_Pool`` attribute shall denote a variable of
kono
parents:
diff changeset
1056 a 'simple storage pool type' (see pragma `Simple_Storage_Pool_Type`).
kono
parents:
diff changeset
1057
kono
parents:
diff changeset
1058 The use of this attribute is only allowed for a prefix denoting a type
kono
parents:
diff changeset
1059 for which it has been specified. The type of the attribute is the type
kono
parents:
diff changeset
1060 of the variable specified as the simple storage pool of the access type,
kono
parents:
diff changeset
1061 and the attribute denotes that variable.
kono
parents:
diff changeset
1062
kono
parents:
diff changeset
1063 It is illegal to specify both ``Storage_Pool`` and ``Simple_Storage_Pool``
kono
parents:
diff changeset
1064 for the same access type.
kono
parents:
diff changeset
1065
kono
parents:
diff changeset
1066 If the ``Simple_Storage_Pool`` attribute has been specified for an access
kono
parents:
diff changeset
1067 type, then applying the ``Storage_Pool`` attribute to the type is flagged
kono
parents:
diff changeset
1068 with a warning and its evaluation raises the exception ``Program_Error``.
kono
parents:
diff changeset
1069
kono
parents:
diff changeset
1070 If the Simple_Storage_Pool attribute has been specified for an access
kono
parents:
diff changeset
1071 type ``S``, then the evaluation of the attribute ``S'Storage_Size``
kono
parents:
diff changeset
1072 returns the result of calling ``Storage_Size (S'Simple_Storage_Pool)``,
kono
parents:
diff changeset
1073 which is intended to indicate the number of storage elements reserved for
kono
parents:
diff changeset
1074 the simple storage pool. If the Storage_Size function has not been defined
kono
parents:
diff changeset
1075 for the simple storage pool type, then this attribute returns zero.
kono
parents:
diff changeset
1076
kono
parents:
diff changeset
1077 If an access type ``S`` has a specified simple storage pool of type
kono
parents:
diff changeset
1078 ``SSP``, then the evaluation of an allocator for that access type calls
kono
parents:
diff changeset
1079 the primitive ``Allocate`` procedure for type ``SSP``, passing
kono
parents:
diff changeset
1080 ``S'Simple_Storage_Pool`` as the pool parameter. The detailed
kono
parents:
diff changeset
1081 semantics of such allocators is the same as those defined for allocators
kono
parents:
diff changeset
1082 in section 13.11 of the :title:`Ada Reference Manual`, with the term
kono
parents:
diff changeset
1083 *simple storage pool* substituted for *storage pool*.
kono
parents:
diff changeset
1084
kono
parents:
diff changeset
1085 If an access type ``S`` has a specified simple storage pool of type
kono
parents:
diff changeset
1086 ``SSP``, then a call to an instance of the ``Ada.Unchecked_Deallocation``
kono
parents:
diff changeset
1087 for that access type invokes the primitive ``Deallocate`` procedure
kono
parents:
diff changeset
1088 for type ``SSP``, passing ``S'Simple_Storage_Pool`` as the pool
kono
parents:
diff changeset
1089 parameter. The detailed semantics of such unchecked deallocations is the same
kono
parents:
diff changeset
1090 as defined in section 13.11.2 of the Ada Reference Manual, except that the
kono
parents:
diff changeset
1091 term *simple storage pool* is substituted for *storage pool*.
kono
parents:
diff changeset
1092
kono
parents:
diff changeset
1093 Attribute Small
kono
parents:
diff changeset
1094 ===============
kono
parents:
diff changeset
1095 .. index:: Ada 83 attributes
kono
parents:
diff changeset
1096
kono
parents:
diff changeset
1097 .. index:: Small
kono
parents:
diff changeset
1098
kono
parents:
diff changeset
1099 The ``Small`` attribute is defined in Ada 95 (and Ada 2005) only for
kono
parents:
diff changeset
1100 fixed-point types.
kono
parents:
diff changeset
1101 GNAT also allows this attribute to be applied to floating-point types
kono
parents:
diff changeset
1102 for compatibility with Ada 83. See
kono
parents:
diff changeset
1103 the Ada 83 reference manual for an exact description of the semantics of
kono
parents:
diff changeset
1104 this attribute when applied to floating-point types.
kono
parents:
diff changeset
1105
kono
parents:
diff changeset
1106 Attribute Storage_Unit
kono
parents:
diff changeset
1107 ======================
kono
parents:
diff changeset
1108 .. index:: Storage_Unit
kono
parents:
diff changeset
1109
kono
parents:
diff changeset
1110 ``Standard'Storage_Unit`` (``Standard`` is the only permissible
kono
parents:
diff changeset
1111 prefix) provides the same value as ``System.Storage_Unit``.
kono
parents:
diff changeset
1112
kono
parents:
diff changeset
1113 Attribute Stub_Type
kono
parents:
diff changeset
1114 ===================
kono
parents:
diff changeset
1115 .. index:: Stub_Type
kono
parents:
diff changeset
1116
kono
parents:
diff changeset
1117 The GNAT implementation of remote access-to-classwide types is
kono
parents:
diff changeset
1118 organized as described in AARM section E.4 (20.t): a value of an RACW type
kono
parents:
diff changeset
1119 (designating a remote object) is represented as a normal access
kono
parents:
diff changeset
1120 value, pointing to a "stub" object which in turn contains the
kono
parents:
diff changeset
1121 necessary information to contact the designated remote object. A
kono
parents:
diff changeset
1122 call on any dispatching operation of such a stub object does the
kono
parents:
diff changeset
1123 remote call, if necessary, using the information in the stub object
kono
parents:
diff changeset
1124 to locate the target partition, etc.
kono
parents:
diff changeset
1125
kono
parents:
diff changeset
1126 For a prefix ``T`` that denotes a remote access-to-classwide type,
kono
parents:
diff changeset
1127 ``T'Stub_Type`` denotes the type of the corresponding stub objects.
kono
parents:
diff changeset
1128
kono
parents:
diff changeset
1129 By construction, the layout of ``T'Stub_Type`` is identical to that of
kono
parents:
diff changeset
1130 type ``RACW_Stub_Type`` declared in the internal implementation-defined
kono
parents:
diff changeset
1131 unit ``System.Partition_Interface``. Use of this attribute will create
kono
parents:
diff changeset
1132 an implicit dependency on this unit.
kono
parents:
diff changeset
1133
kono
parents:
diff changeset
1134 Attribute System_Allocator_Alignment
kono
parents:
diff changeset
1135 ====================================
kono
parents:
diff changeset
1136 .. index:: Alignment, allocator
kono
parents:
diff changeset
1137
kono
parents:
diff changeset
1138 .. index:: System_Allocator_Alignment
kono
parents:
diff changeset
1139
kono
parents:
diff changeset
1140 ``Standard'System_Allocator_Alignment`` (``Standard`` is the only
kono
parents:
diff changeset
1141 permissible prefix) provides the observable guaranted to be honored by
kono
parents:
diff changeset
1142 the system allocator (malloc). This is a static value that can be used
kono
parents:
diff changeset
1143 in user storage pools based on malloc either to reject allocation
kono
parents:
diff changeset
1144 with alignment too large or to enable a realignment circuitry if the
kono
parents:
diff changeset
1145 alignment request is larger than this value.
kono
parents:
diff changeset
1146
kono
parents:
diff changeset
1147 Attribute Target_Name
kono
parents:
diff changeset
1148 =====================
kono
parents:
diff changeset
1149 .. index:: Target_Name
kono
parents:
diff changeset
1150
kono
parents:
diff changeset
1151 ``Standard'Target_Name`` (``Standard`` is the only permissible
kono
parents:
diff changeset
1152 prefix) provides a static string value that identifies the target
kono
parents:
diff changeset
1153 for the current compilation. For GCC implementations, this is the
kono
parents:
diff changeset
1154 standard gcc target name without the terminating slash (for
kono
parents:
diff changeset
1155 example, GNAT 5.0 on windows yields "i586-pc-mingw32msv").
kono
parents:
diff changeset
1156
kono
parents:
diff changeset
1157 Attribute To_Address
kono
parents:
diff changeset
1158 ====================
kono
parents:
diff changeset
1159 .. index:: To_Address
kono
parents:
diff changeset
1160
kono
parents:
diff changeset
1161 The ``System'To_Address``
kono
parents:
diff changeset
1162 (``System`` is the only permissible prefix)
kono
parents:
diff changeset
1163 denotes a function identical to
kono
parents:
diff changeset
1164 ``System.Storage_Elements.To_Address`` except that
kono
parents:
diff changeset
1165 it is a static attribute. This means that if its argument is
kono
parents:
diff changeset
1166 a static expression, then the result of the attribute is a
kono
parents:
diff changeset
1167 static expression. This means that such an expression can be
kono
parents:
diff changeset
1168 used in contexts (e.g., preelaborable packages) which require a
kono
parents:
diff changeset
1169 static expression and where the function call could not be used
kono
parents:
diff changeset
1170 (since the function call is always nonstatic, even if its
kono
parents:
diff changeset
1171 argument is static). The argument must be in the range
kono
parents:
diff changeset
1172 -(2**(m-1)) .. 2**m-1, where m is the memory size
kono
parents:
diff changeset
1173 (typically 32 or 64). Negative values are intepreted in a
kono
parents:
diff changeset
1174 modular manner (e.g., -1 means the same as 16#FFFF_FFFF# on
kono
parents:
diff changeset
1175 a 32 bits machine).
kono
parents:
diff changeset
1176
kono
parents:
diff changeset
1177 Attribute To_Any
kono
parents:
diff changeset
1178 ================
kono
parents:
diff changeset
1179 .. index:: To_Any
kono
parents:
diff changeset
1180
kono
parents:
diff changeset
1181 This internal attribute is used for the generation of remote subprogram
kono
parents:
diff changeset
1182 stubs in the context of the Distributed Systems Annex.
kono
parents:
diff changeset
1183
kono
parents:
diff changeset
1184 Attribute Type_Class
kono
parents:
diff changeset
1185 ====================
kono
parents:
diff changeset
1186 .. index:: Type_Class
kono
parents:
diff changeset
1187
kono
parents:
diff changeset
1188 ``typ'Type_Class`` for any type or subtype `typ` yields
kono
parents:
diff changeset
1189 the value of the type class for the full type of `typ`. If
kono
parents:
diff changeset
1190 `typ` is a generic formal type, the value is the value for the
kono
parents:
diff changeset
1191 corresponding actual subtype. The value of this attribute is of type
kono
parents:
diff changeset
1192 ``System.Aux_DEC.Type_Class``, which has the following definition:
kono
parents:
diff changeset
1193
kono
parents:
diff changeset
1194 .. code-block:: ada
kono
parents:
diff changeset
1195
kono
parents:
diff changeset
1196 type Type_Class is
kono
parents:
diff changeset
1197 (Type_Class_Enumeration,
kono
parents:
diff changeset
1198 Type_Class_Integer,
kono
parents:
diff changeset
1199 Type_Class_Fixed_Point,
kono
parents:
diff changeset
1200 Type_Class_Floating_Point,
kono
parents:
diff changeset
1201 Type_Class_Array,
kono
parents:
diff changeset
1202 Type_Class_Record,
kono
parents:
diff changeset
1203 Type_Class_Access,
kono
parents:
diff changeset
1204 Type_Class_Task,
kono
parents:
diff changeset
1205 Type_Class_Address);
kono
parents:
diff changeset
1206
kono
parents:
diff changeset
1207
kono
parents:
diff changeset
1208 Protected types yield the value ``Type_Class_Task``, which thus
kono
parents:
diff changeset
1209 applies to all concurrent types. This attribute is designed to
kono
parents:
diff changeset
1210 be compatible with the DEC Ada 83 attribute of the same name.
kono
parents:
diff changeset
1211
kono
parents:
diff changeset
1212 Attribute Type_Key
kono
parents:
diff changeset
1213 ==================
kono
parents:
diff changeset
1214 .. index:: Type_Key
kono
parents:
diff changeset
1215
kono
parents:
diff changeset
1216 The ``Type_Key`` attribute is applicable to a type or subtype and
kono
parents:
diff changeset
1217 yields a value of type Standard.String containing encoded information
kono
parents:
diff changeset
1218 about the type or subtype. This provides improved compatibility with
kono
parents:
diff changeset
1219 other implementations that support this attribute.
kono
parents:
diff changeset
1220
kono
parents:
diff changeset
1221 Attribute TypeCode
kono
parents:
diff changeset
1222 ==================
kono
parents:
diff changeset
1223 .. index:: TypeCode
kono
parents:
diff changeset
1224
kono
parents:
diff changeset
1225 This internal attribute is used for the generation of remote subprogram
kono
parents:
diff changeset
1226 stubs in the context of the Distributed Systems Annex.
kono
parents:
diff changeset
1227
kono
parents:
diff changeset
1228 Attribute Unconstrained_Array
kono
parents:
diff changeset
1229 =============================
kono
parents:
diff changeset
1230 .. index:: Unconstrained_Array
kono
parents:
diff changeset
1231
kono
parents:
diff changeset
1232 The ``Unconstrained_Array`` attribute can be used with a prefix that
kono
parents:
diff changeset
1233 denotes any type or subtype. It is a static attribute that yields
kono
parents:
diff changeset
1234 ``True`` if the prefix designates an unconstrained array,
kono
parents:
diff changeset
1235 and ``False`` otherwise. In a generic instance, the result is
kono
parents:
diff changeset
1236 still static, and yields the result of applying this test to the
kono
parents:
diff changeset
1237 generic actual.
kono
parents:
diff changeset
1238
kono
parents:
diff changeset
1239 Attribute Universal_Literal_String
kono
parents:
diff changeset
1240 ==================================
kono
parents:
diff changeset
1241 .. index:: Named numbers, representation of
kono
parents:
diff changeset
1242
kono
parents:
diff changeset
1243 .. index:: Universal_Literal_String
kono
parents:
diff changeset
1244
kono
parents:
diff changeset
1245 The prefix of ``Universal_Literal_String`` must be a named
kono
parents:
diff changeset
1246 number. The static result is the string consisting of the characters of
kono
parents:
diff changeset
1247 the number as defined in the original source. This allows the user
kono
parents:
diff changeset
1248 program to access the actual text of named numbers without intermediate
kono
parents:
diff changeset
1249 conversions and without the need to enclose the strings in quotes (which
kono
parents:
diff changeset
1250 would preclude their use as numbers).
kono
parents:
diff changeset
1251
kono
parents:
diff changeset
1252 For example, the following program prints the first 50 digits of pi:
kono
parents:
diff changeset
1253
kono
parents:
diff changeset
1254 .. code-block:: ada
kono
parents:
diff changeset
1255
kono
parents:
diff changeset
1256 with Text_IO; use Text_IO;
kono
parents:
diff changeset
1257 with Ada.Numerics;
kono
parents:
diff changeset
1258 procedure Pi is
kono
parents:
diff changeset
1259 begin
kono
parents:
diff changeset
1260 Put (Ada.Numerics.Pi'Universal_Literal_String);
kono
parents:
diff changeset
1261 end;
kono
parents:
diff changeset
1262
kono
parents:
diff changeset
1263
kono
parents:
diff changeset
1264 Attribute Unrestricted_Access
kono
parents:
diff changeset
1265 =============================
kono
parents:
diff changeset
1266 .. index:: Access, unrestricted
kono
parents:
diff changeset
1267
kono
parents:
diff changeset
1268 .. index:: Unrestricted_Access
kono
parents:
diff changeset
1269
kono
parents:
diff changeset
1270 The ``Unrestricted_Access`` attribute is similar to ``Access``
kono
parents:
diff changeset
1271 except that all accessibility and aliased view checks are omitted. This
kono
parents:
diff changeset
1272 is a user-beware attribute.
kono
parents:
diff changeset
1273
kono
parents:
diff changeset
1274 For objects, it is similar to ``Address``, for which it is a
kono
parents:
diff changeset
1275 desirable replacement where the value desired is an access type.
kono
parents:
diff changeset
1276 In other words, its effect is similar to first applying the
kono
parents:
diff changeset
1277 ``Address`` attribute and then doing an unchecked conversion to a
kono
parents:
diff changeset
1278 desired access type.
kono
parents:
diff changeset
1279
kono
parents:
diff changeset
1280 For subprograms, ``P'Unrestricted_Access`` may be used where
kono
parents:
diff changeset
1281 ``P'Access`` would be illegal, to construct a value of a
kono
parents:
diff changeset
1282 less-nested named access type that designates a more-nested
kono
parents:
diff changeset
1283 subprogram. This value may be used in indirect calls, so long as the
kono
parents:
diff changeset
1284 more-nested subprogram still exists; once the subprogram containing it
kono
parents:
diff changeset
1285 has returned, such calls are erroneous. For example:
kono
parents:
diff changeset
1286
kono
parents:
diff changeset
1287 .. code-block:: ada
kono
parents:
diff changeset
1288
kono
parents:
diff changeset
1289 package body P is
kono
parents:
diff changeset
1290
kono
parents:
diff changeset
1291 type Less_Nested is not null access procedure;
kono
parents:
diff changeset
1292 Global : Less_Nested;
kono
parents:
diff changeset
1293
kono
parents:
diff changeset
1294 procedure P1 is
kono
parents:
diff changeset
1295 begin
kono
parents:
diff changeset
1296 Global.all;
kono
parents:
diff changeset
1297 end P1;
kono
parents:
diff changeset
1298
kono
parents:
diff changeset
1299 procedure P2 is
kono
parents:
diff changeset
1300 Local_Var : Integer;
kono
parents:
diff changeset
1301
kono
parents:
diff changeset
1302 procedure More_Nested is
kono
parents:
diff changeset
1303 begin
kono
parents:
diff changeset
1304 ... Local_Var ...
kono
parents:
diff changeset
1305 end More_Nested;
kono
parents:
diff changeset
1306 begin
kono
parents:
diff changeset
1307 Global := More_Nested'Unrestricted_Access;
kono
parents:
diff changeset
1308 P1;
kono
parents:
diff changeset
1309 end P2;
kono
parents:
diff changeset
1310
kono
parents:
diff changeset
1311 end P;
kono
parents:
diff changeset
1312
kono
parents:
diff changeset
1313
kono
parents:
diff changeset
1314 When P1 is called from P2, the call via Global is OK, but if P1 were
kono
parents:
diff changeset
1315 called after P2 returns, it would be an erroneous use of a dangling
kono
parents:
diff changeset
1316 pointer.
kono
parents:
diff changeset
1317
kono
parents:
diff changeset
1318 For objects, it is possible to use ``Unrestricted_Access`` for any
kono
parents:
diff changeset
1319 type. However, if the result is of an access-to-unconstrained array
kono
parents:
diff changeset
1320 subtype, then the resulting pointer has the same scope as the context
kono
parents:
diff changeset
1321 of the attribute, and must not be returned to some enclosing scope.
kono
parents:
diff changeset
1322 For instance, if a function uses ``Unrestricted_Access`` to create
kono
parents:
diff changeset
1323 an access-to-unconstrained-array and returns that value to the caller,
kono
parents:
diff changeset
1324 the result will involve dangling pointers. In addition, it is only
kono
parents:
diff changeset
1325 valid to create pointers to unconstrained arrays using this attribute
kono
parents:
diff changeset
1326 if the pointer has the normal default 'fat' representation where a
kono
parents:
diff changeset
1327 pointer has two components, one points to the array and one points to
kono
parents:
diff changeset
1328 the bounds. If a size clause is used to force 'thin' representation
kono
parents:
diff changeset
1329 for a pointer to unconstrained where there is only space for a single
kono
parents:
diff changeset
1330 pointer, then the resulting pointer is not usable.
kono
parents:
diff changeset
1331
kono
parents:
diff changeset
1332 In the simple case where a direct use of Unrestricted_Access attempts
kono
parents:
diff changeset
1333 to make a thin pointer for a non-aliased object, the compiler will
kono
parents:
diff changeset
1334 reject the use as illegal, as shown in the following example:
kono
parents:
diff changeset
1335
kono
parents:
diff changeset
1336 .. code-block:: ada
kono
parents:
diff changeset
1337
kono
parents:
diff changeset
1338 with System; use System;
kono
parents:
diff changeset
1339 procedure SliceUA2 is
kono
parents:
diff changeset
1340 type A is access all String;
kono
parents:
diff changeset
1341 for A'Size use Standard'Address_Size;
kono
parents:
diff changeset
1342
kono
parents:
diff changeset
1343 procedure P (Arg : A) is
kono
parents:
diff changeset
1344 begin
kono
parents:
diff changeset
1345 null;
kono
parents:
diff changeset
1346 end P;
kono
parents:
diff changeset
1347
kono
parents:
diff changeset
1348 X : String := "hello world!";
kono
parents:
diff changeset
1349 X2 : aliased String := "hello world!";
kono
parents:
diff changeset
1350
kono
parents:
diff changeset
1351 AV : A := X'Unrestricted_Access; -- ERROR
kono
parents:
diff changeset
1352 |
kono
parents:
diff changeset
1353 >>> illegal use of Unrestricted_Access attribute
kono
parents:
diff changeset
1354 >>> attempt to generate thin pointer to unaliased object
kono
parents:
diff changeset
1355
kono
parents:
diff changeset
1356 begin
kono
parents:
diff changeset
1357 P (X'Unrestricted_Access); -- ERROR
kono
parents:
diff changeset
1358 |
kono
parents:
diff changeset
1359 >>> illegal use of Unrestricted_Access attribute
kono
parents:
diff changeset
1360 >>> attempt to generate thin pointer to unaliased object
kono
parents:
diff changeset
1361
kono
parents:
diff changeset
1362 P (X(7 .. 12)'Unrestricted_Access); -- ERROR
kono
parents:
diff changeset
1363 |
kono
parents:
diff changeset
1364 >>> illegal use of Unrestricted_Access attribute
kono
parents:
diff changeset
1365 >>> attempt to generate thin pointer to unaliased object
kono
parents:
diff changeset
1366
kono
parents:
diff changeset
1367 P (X2'Unrestricted_Access); -- OK
kono
parents:
diff changeset
1368 end;
kono
parents:
diff changeset
1369
kono
parents:
diff changeset
1370
kono
parents:
diff changeset
1371 but other cases cannot be detected by the compiler, and are
kono
parents:
diff changeset
1372 considered to be erroneous. Consider the following example:
kono
parents:
diff changeset
1373
kono
parents:
diff changeset
1374 .. code-block:: ada
kono
parents:
diff changeset
1375
kono
parents:
diff changeset
1376 with System; use System;
kono
parents:
diff changeset
1377 with System; use System;
kono
parents:
diff changeset
1378 procedure SliceUA is
kono
parents:
diff changeset
1379 type AF is access all String;
kono
parents:
diff changeset
1380
kono
parents:
diff changeset
1381 type A is access all String;
kono
parents:
diff changeset
1382 for A'Size use Standard'Address_Size;
kono
parents:
diff changeset
1383
kono
parents:
diff changeset
1384 procedure P (Arg : A) is
kono
parents:
diff changeset
1385 begin
kono
parents:
diff changeset
1386 if Arg'Length /= 6 then
kono
parents:
diff changeset
1387 raise Program_Error;
kono
parents:
diff changeset
1388 end if;
kono
parents:
diff changeset
1389 end P;
kono
parents:
diff changeset
1390
kono
parents:
diff changeset
1391 X : String := "hello world!";
kono
parents:
diff changeset
1392 Y : AF := X (7 .. 12)'Unrestricted_Access;
kono
parents:
diff changeset
1393
kono
parents:
diff changeset
1394 begin
kono
parents:
diff changeset
1395 P (A (Y));
kono
parents:
diff changeset
1396 end;
kono
parents:
diff changeset
1397
kono
parents:
diff changeset
1398
kono
parents:
diff changeset
1399 A normal unconstrained array value
kono
parents:
diff changeset
1400 or a constrained array object marked as aliased has the bounds in memory
kono
parents:
diff changeset
1401 just before the array, so a thin pointer can retrieve both the data and
kono
parents:
diff changeset
1402 the bounds. But in this case, the non-aliased object ``X`` does not have the
kono
parents:
diff changeset
1403 bounds before the string. If the size clause for type ``A``
kono
parents:
diff changeset
1404 were not present, then the pointer
kono
parents:
diff changeset
1405 would be a fat pointer, where one component is a pointer to the bounds,
kono
parents:
diff changeset
1406 and all would be well. But with the size clause present, the conversion from
kono
parents:
diff changeset
1407 fat pointer to thin pointer in the call loses the bounds, and so this
kono
parents:
diff changeset
1408 is erroneous, and the program likely raises a ``Program_Error`` exception.
kono
parents:
diff changeset
1409
kono
parents:
diff changeset
1410 In general, it is advisable to completely
kono
parents:
diff changeset
1411 avoid mixing the use of thin pointers and the use of
kono
parents:
diff changeset
1412 ``Unrestricted_Access`` where the designated type is an
kono
parents:
diff changeset
1413 unconstrained array. The use of thin pointers should be restricted to
kono
parents:
diff changeset
1414 cases of porting legacy code that implicitly assumes the size of pointers,
kono
parents:
diff changeset
1415 and such code should not in any case be using this attribute.
kono
parents:
diff changeset
1416
kono
parents:
diff changeset
1417 Another erroneous situation arises if the attribute is
kono
parents:
diff changeset
1418 applied to a constant. The resulting pointer can be used to access the
kono
parents:
diff changeset
1419 constant, but the effect of trying to modify a constant in this manner
kono
parents:
diff changeset
1420 is not well-defined. Consider this example:
kono
parents:
diff changeset
1421
kono
parents:
diff changeset
1422 .. code-block:: ada
kono
parents:
diff changeset
1423
kono
parents:
diff changeset
1424 P : constant Integer := 4;
kono
parents:
diff changeset
1425 type R is access all Integer;
kono
parents:
diff changeset
1426 RV : R := P'Unrestricted_Access;
kono
parents:
diff changeset
1427 ..
kono
parents:
diff changeset
1428 RV.all := 3;
kono
parents:
diff changeset
1429
kono
parents:
diff changeset
1430
kono
parents:
diff changeset
1431 Here we attempt to modify the constant P from 4 to 3, but the compiler may
kono
parents:
diff changeset
1432 or may not notice this attempt, and subsequent references to P may yield
kono
parents:
diff changeset
1433 either the value 3 or the value 4 or the assignment may blow up if the
kono
parents:
diff changeset
1434 compiler decides to put P in read-only memory. One particular case where
kono
parents:
diff changeset
1435 ``Unrestricted_Access`` can be used in this way is to modify the
kono
parents:
diff changeset
1436 value of an ``in`` parameter:
kono
parents:
diff changeset
1437
kono
parents:
diff changeset
1438 .. code-block:: ada
kono
parents:
diff changeset
1439
kono
parents:
diff changeset
1440 procedure K (S : in String) is
kono
parents:
diff changeset
1441 type R is access all Character;
kono
parents:
diff changeset
1442 RV : R := S (3)'Unrestricted_Access;
kono
parents:
diff changeset
1443 begin
kono
parents:
diff changeset
1444 RV.all := 'a';
kono
parents:
diff changeset
1445 end;
kono
parents:
diff changeset
1446
kono
parents:
diff changeset
1447
kono
parents:
diff changeset
1448 In general this is a risky approach. It may appear to "work" but such uses of
kono
parents:
diff changeset
1449 ``Unrestricted_Access`` are potentially non-portable, even from one version
kono
parents:
diff changeset
1450 of GNAT to another, so are best avoided if possible.
kono
parents:
diff changeset
1451
kono
parents:
diff changeset
1452 Attribute Update
kono
parents:
diff changeset
1453 ================
kono
parents:
diff changeset
1454 .. index:: Update
kono
parents:
diff changeset
1455
kono
parents:
diff changeset
1456 The ``Update`` attribute creates a copy of an array or record value
kono
parents:
diff changeset
1457 with one or more modified components. The syntax is::
kono
parents:
diff changeset
1458
kono
parents:
diff changeset
1459 PREFIX'Update ( RECORD_COMPONENT_ASSOCIATION_LIST )
kono
parents:
diff changeset
1460 PREFIX'Update ( ARRAY_COMPONENT_ASSOCIATION {, ARRAY_COMPONENT_ASSOCIATION } )
kono
parents:
diff changeset
1461 PREFIX'Update ( MULTIDIMENSIONAL_ARRAY_COMPONENT_ASSOCIATION
kono
parents:
diff changeset
1462 {, MULTIDIMENSIONAL_ARRAY_COMPONENT_ASSOCIATION } )
kono
parents:
diff changeset
1463
kono
parents:
diff changeset
1464 MULTIDIMENSIONAL_ARRAY_COMPONENT_ASSOCIATION ::= INDEX_EXPRESSION_LIST_LIST => EXPRESSION
kono
parents:
diff changeset
1465 INDEX_EXPRESSION_LIST_LIST ::= INDEX_EXPRESSION_LIST {| INDEX_EXPRESSION_LIST }
kono
parents:
diff changeset
1466 INDEX_EXPRESSION_LIST ::= ( EXPRESSION {, EXPRESSION } )
kono
parents:
diff changeset
1467
kono
parents:
diff changeset
1468
kono
parents:
diff changeset
1469 where ``PREFIX`` is the name of an array or record object, the
kono
parents:
diff changeset
1470 association list in parentheses does not contain an ``others``
kono
parents:
diff changeset
1471 choice and the box symbol ``<>`` may not appear in any
kono
parents:
diff changeset
1472 expression. The effect is to yield a copy of the array or record value
kono
parents:
diff changeset
1473 which is unchanged apart from the components mentioned in the
kono
parents:
diff changeset
1474 association list, which are changed to the indicated value. The
kono
parents:
diff changeset
1475 original value of the array or record value is not affected. For
kono
parents:
diff changeset
1476 example:
kono
parents:
diff changeset
1477
kono
parents:
diff changeset
1478 .. code-block:: ada
kono
parents:
diff changeset
1479
kono
parents:
diff changeset
1480 type Arr is Array (1 .. 5) of Integer;
kono
parents:
diff changeset
1481 ...
kono
parents:
diff changeset
1482 Avar1 : Arr := (1,2,3,4,5);
kono
parents:
diff changeset
1483 Avar2 : Arr := Avar1'Update (2 => 10, 3 .. 4 => 20);
kono
parents:
diff changeset
1484
kono
parents:
diff changeset
1485
kono
parents:
diff changeset
1486 yields a value for ``Avar2`` of 1,10,20,20,5 with ``Avar1``
kono
parents:
diff changeset
1487 begin unmodified. Similarly:
kono
parents:
diff changeset
1488
kono
parents:
diff changeset
1489 .. code-block:: ada
kono
parents:
diff changeset
1490
kono
parents:
diff changeset
1491 type Rec is A, B, C : Integer;
kono
parents:
diff changeset
1492 ...
kono
parents:
diff changeset
1493 Rvar1 : Rec := (A => 1, B => 2, C => 3);
kono
parents:
diff changeset
1494 Rvar2 : Rec := Rvar1'Update (B => 20);
kono
parents:
diff changeset
1495
kono
parents:
diff changeset
1496
kono
parents:
diff changeset
1497 yields a value for ``Rvar2`` of (A => 1, B => 20, C => 3),
kono
parents:
diff changeset
1498 with ``Rvar1`` being unmodifed.
kono
parents:
diff changeset
1499 Note that the value of the attribute reference is computed
kono
parents:
diff changeset
1500 completely before it is used. This means that if you write:
kono
parents:
diff changeset
1501
kono
parents:
diff changeset
1502 .. code-block:: ada
kono
parents:
diff changeset
1503
kono
parents:
diff changeset
1504 Avar1 := Avar1'Update (1 => 10, 2 => Function_Call);
kono
parents:
diff changeset
1505
kono
parents:
diff changeset
1506
kono
parents:
diff changeset
1507 then the value of ``Avar1`` is not modified if ``Function_Call``
kono
parents:
diff changeset
1508 raises an exception, unlike the effect of a series of direct assignments
kono
parents:
diff changeset
1509 to elements of ``Avar1``. In general this requires that
kono
parents:
diff changeset
1510 two extra complete copies of the object are required, which should be
kono
parents:
diff changeset
1511 kept in mind when considering efficiency.
kono
parents:
diff changeset
1512
kono
parents:
diff changeset
1513 The ``Update`` attribute cannot be applied to prefixes of a limited
kono
parents:
diff changeset
1514 type, and cannot reference discriminants in the case of a record type.
kono
parents:
diff changeset
1515 The accessibility level of an Update attribute result object is defined
kono
parents:
diff changeset
1516 as for an aggregate.
kono
parents:
diff changeset
1517
kono
parents:
diff changeset
1518 In the record case, no component can be mentioned more than once. In
kono
parents:
diff changeset
1519 the array case, two overlapping ranges can appear in the association list,
kono
parents:
diff changeset
1520 in which case the modifications are processed left to right.
kono
parents:
diff changeset
1521
kono
parents:
diff changeset
1522 Multi-dimensional arrays can be modified, as shown by this example:
kono
parents:
diff changeset
1523
kono
parents:
diff changeset
1524 .. code-block:: ada
kono
parents:
diff changeset
1525
kono
parents:
diff changeset
1526 A : array (1 .. 10, 1 .. 10) of Integer;
kono
parents:
diff changeset
1527 ..
kono
parents:
diff changeset
1528 A := A'Update ((1, 2) => 20, (3, 4) => 30);
kono
parents:
diff changeset
1529
kono
parents:
diff changeset
1530
kono
parents:
diff changeset
1531 which changes element (1,2) to 20 and (3,4) to 30.
kono
parents:
diff changeset
1532
kono
parents:
diff changeset
1533 Attribute Valid_Scalars
kono
parents:
diff changeset
1534 =======================
kono
parents:
diff changeset
1535 .. index:: Valid_Scalars
kono
parents:
diff changeset
1536
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1537 The ``'Valid_Scalars`` attribute is intended to make it easier to check the
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1538 validity of scalar subcomponents of composite objects. The attribute is defined
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1539 for any prefix ``P`` which denotes an object. Prefix ``P`` can be any type
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1540 except for tagged private or ``Unchecked_Union`` types. The value of the
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1541 attribute is of type ``Boolean``.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1542
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1543 ``P'Valid_Scalars`` yields ``True`` if and only if the evaluation of
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1544 ``C'Valid`` yields ``True`` for every scalar subcomponent ``C`` of ``P``, or if
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1545 ``P`` has no scalar subcomponents. Attribute ``'Valid_Scalars`` is equivalent
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1546 to attribute ``'Valid`` for scalar types.
111
kono
parents:
diff changeset
1547
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1548 It is not specified in what order the subcomponents are checked, nor whether
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1549 any more are checked after any one of them is determined to be invalid. If the
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1550 prefix ``P`` is of a class-wide type ``T'Class`` (where ``T`` is the associated
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1551 specific type), or if the prefix ``P`` is of a specific tagged type ``T``, then
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1552 only the subcomponents of ``T`` are checked; in other words, components of
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1553 extensions of ``T`` are not checked even if ``T'Class (P)'Tag /= T'Tag``.
111
kono
parents:
diff changeset
1554
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1555 The compiler will issue a warning if it can be determined at compile time that
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1556 the prefix of the attribute has no scalar subcomponents.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1557
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1558 Note: ``Valid_Scalars`` can generate a lot of code, especially in the case of
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1559 a large variant record. If the attribute is called in many places in the same
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1560 program applied to objects of the same type, it can reduce program size to
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1561 write a function with a single use of the attribute, and then call that
111
kono
parents:
diff changeset
1562 function from multiple places.
kono
parents:
diff changeset
1563
kono
parents:
diff changeset
1564 Attribute VADS_Size
kono
parents:
diff changeset
1565 ===================
kono
parents:
diff changeset
1566 .. index:: Size, VADS compatibility
kono
parents:
diff changeset
1567
kono
parents:
diff changeset
1568 .. index:: VADS_Size
kono
parents:
diff changeset
1569
kono
parents:
diff changeset
1570 The ``'VADS_Size`` attribute is intended to make it easier to port
kono
parents:
diff changeset
1571 legacy code which relies on the semantics of ``'Size`` as implemented
kono
parents:
diff changeset
1572 by the VADS Ada 83 compiler. GNAT makes a best effort at duplicating the
kono
parents:
diff changeset
1573 same semantic interpretation. In particular, ``'VADS_Size`` applied
kono
parents:
diff changeset
1574 to a predefined or other primitive type with no Size clause yields the
kono
parents:
diff changeset
1575 Object_Size (for example, ``Natural'Size`` is 32 rather than 31 on
kono
parents:
diff changeset
1576 typical machines). In addition ``'VADS_Size`` applied to an object
kono
parents:
diff changeset
1577 gives the result that would be obtained by applying the attribute to
kono
parents:
diff changeset
1578 the corresponding type.
kono
parents:
diff changeset
1579
kono
parents:
diff changeset
1580 .. _Attribute-Value_Size:
kono
parents:
diff changeset
1581
kono
parents:
diff changeset
1582 Attribute Value_Size
kono
parents:
diff changeset
1583 ====================
kono
parents:
diff changeset
1584 .. index:: Size, setting for not-first subtype
kono
parents:
diff changeset
1585
kono
parents:
diff changeset
1586 .. index:: Value_Size
kono
parents:
diff changeset
1587
kono
parents:
diff changeset
1588 ``type'Value_Size`` is the number of bits required to represent
kono
parents:
diff changeset
1589 a value of the given subtype. It is the same as ``type'Size``,
kono
parents:
diff changeset
1590 but, unlike ``Size``, may be set for non-first subtypes.
kono
parents:
diff changeset
1591
kono
parents:
diff changeset
1592 Attribute Wchar_T_Size
kono
parents:
diff changeset
1593 ======================
kono
parents:
diff changeset
1594 .. index:: Wchar_T_Size
kono
parents:
diff changeset
1595
kono
parents:
diff changeset
1596 ``Standard'Wchar_T_Size`` (``Standard`` is the only permissible
kono
parents:
diff changeset
1597 prefix) provides the size in bits of the C ``wchar_t`` type
kono
parents:
diff changeset
1598 primarily for constructing the definition of this type in
kono
parents:
diff changeset
1599 package ``Interfaces.C``. The result is a static constant.
kono
parents:
diff changeset
1600
kono
parents:
diff changeset
1601 Attribute Word_Size
kono
parents:
diff changeset
1602 ===================
kono
parents:
diff changeset
1603 .. index:: Word_Size
kono
parents:
diff changeset
1604
kono
parents:
diff changeset
1605 ``Standard'Word_Size`` (``Standard`` is the only permissible
kono
parents:
diff changeset
1606 prefix) provides the value ``System.Word_Size``. The result is
kono
parents:
diff changeset
1607 a static constant.
kono
parents:
diff changeset
1608