1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
10 -- Copyright (C) 1992-2002, Free Software Foundation, Inc. --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNAT; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
23 -- GNAT was originally developed by the GNAT team at New York University. --
24 -- Extensive contributions were provided by Ada Core Technologies Inc. --
26 ------------------------------------------------------------------------------
28 -- Attribute handling is isolated in a separate package to ease the addition
29 -- of implementation defined attributes. Logically this processing belongs
30 -- in chapter 4. See Sem_Ch4 for a description of the relation of the
31 -- Analyze and Resolve routines for expression components.
33 -- This spec also documents all GNAT implementation defined pragmas
35 with Snames
; use Snames
;
36 with Types
; use Types
;
40 type Attribute_Class_Array
is array (Attribute_Id
) of Boolean;
41 -- Type used to build attribute classification flag arrays
43 -----------------------------------------
44 -- Implementation Dependent Attributes --
45 -----------------------------------------
47 -- This section describes the implementation dependent attributes
48 -- provided in GNAT, as well as constructing an array of flags
49 -- indicating which attributes these are.
51 Attribute_Impl_Def
: Attribute_Class_Array
:= Attribute_Class_Array
'(
57 Attribute_Abort_Signal => True,
59 -- Standard'Abort_Signal (Standard is the only allowed prefix)
60 -- provides the entity for the special exception used to signal
61 -- task abort or asynchronous transfer of control. Normally this
62 -- attribute should only be used in the tasking runtime (it is
63 -- highly peculiar, and completely outside the normal semantics
64 -- of Ada, for a user program to intercept the abort exception).
70 Attribute_Address_Size => True,
72 -- Standard'Address_Size (Standard is the only allowed prefix) is
73 -- a static constant giving the number of bits in an Address. It
74 -- is used primarily for constructing the definition of Memory_Size
75 -- in package Standard, but may be freely used in user programs.
76 -- This is a static attribute.
82 Attribute_Asm_Input => True,
84 -- Used only in conjunction with the Asm and Asm_Volatile subprograms
85 -- in package Machine_Code to construct machine instructions. See
86 -- documentation in package Machine_Code in file s-maccod.ads.
92 Attribute_Asm_Output => True,
94 -- Used only in conjunction with the Asm and Asm_Volatile subprograms
95 -- in package Machine_Code to construct machine instructions. See
96 -- documentation in package Machine_Code in file s-maccod.ads.
102 Attribute_AST_Entry => True,
104 -- E'Ast_Entry, where E is a task entry, yields a value of the
105 -- predefined type System.DEC.AST_Handler, that enables the given
106 -- entry to be called when an AST occurs. If the name to which the
107 -- attribute applies has not been specified with the pragma AST_Entry,
108 -- the attribute returns the value No_Ast_Handler, and no AST occurs.
109 -- If the entry is for a task that is not callable (T'Callable False),
110 -- the exception program error is raised. If an AST occurs for an
111 -- entry of a task that is terminated, the program is erroneous.
113 -- The attribute AST_Entry is supported only in OpenVMS versions
114 -- of GNAT. It will be rejected as illegal in other GNAT versions.
120 Attribute_Bit => True,
122 -- Obj'Bit, where Obj is any object, yields the bit offset within
123 -- the storage unit (byte) that contains the first bit of storage
124 -- allocated for the object. The value of this attribute is of the
125 -- type Universal_Integer, and is always a non-negative number not
126 -- exceeding the value of System.Storage_Unit.
128 -- For an object that is a variable or a constant allocated in a
129 -- register, the value is zero. (The use of this attribute does not
130 -- force the allocation of a variable to memory).
132 -- For an object that is a formal parameter, this attribute applies
133 -- to either the matching actual parameter or to a copy of the
134 -- matching actual parameter.
136 -- For an access object the value is zero. Note that Obj.all'Bit is
137 -- subject to an Access_Check for the designated object. Similarly
138 -- for a record component X.C'Bit is subject to a discriminant check
139 -- and X(I).Bit and X(I1..I2)'Bit are subject to index checks.
141 -- This attribute is designed to be compatible with the DEC Ada
142 -- definition and implementation of the Bit attribute.
148 Attribute_Code_Address => True,
150 -- subp'Code_Address, where subp is a subprogram entity, gives the
151 -- address of the first generated instruction for a subprogram. This
152 -- is often, but not always the same as the 'Address value
, which
is
153 -- the address to be used in a call. The differences occur in the case
154 -- of a nested procedure (where Address yields the address of the
155 -- trampoline code used to load the static link), and on some systems
156 -- which use procedure descriptors (in which case Address yields the
157 -- address of the descriptor).
159 -----------------------
160 -- Default_Bit_Order --
161 -----------------------
163 Attribute_Default_Bit_Order
=> True,
165 -- Standard'Default_Bit_Order (Standard is the only permissible prefix),
166 -- provides the value System.Default_Bit_Order as a Pos value (0 for
167 -- High_Order_First, 1 for Low_Order_First). This is used to construct
168 -- the definition of Default_Bit_Order in package System. This is a
175 Attribute_Elab_Body
=> True,
177 -- This attribute can only be applied to a program unit name. It
178 -- returns the entity for the corresponding elaboration procedure
179 -- for elaborating the body of the referenced unit. This is used
180 -- in the main generated elaboration procedure by the binder, and
181 -- is not normally used in any other context, but there may be
182 -- specialized situations in which it is useful to be able to
183 -- call this elaboration procedure from Ada code, e.g. if it
184 -- is necessary to do selective reelaboration to fix some error.
190 Attribute_Elab_Spec
=> True,
192 -- This attribute can only be applied to a program unit name. It
193 -- returns the entity for the corresponding elaboration procedure
194 -- for elaborating the spec of the referenced unit. This is used
195 -- in the main generated elaboration procedure by the binder, and
196 -- is not normally used in any other context, but there may be
197 -- specialized situations in which it is useful to be able to
198 -- call this elaboration procedure from Ada code, e.g. if it
199 -- is necessary to do selective reelaboration to fix some error.
205 Attribute_Elaborated
=> True,
207 -- Lunit'Elaborated, where Lunit is a library unit, yields a boolean
208 -- value indicating whether or not the body of the designated library
209 -- unit has been elaborated yet.
215 Attribute_Enum_Rep
=> True,
217 -- For every enumeration subtype S, S'Enum_Rep denotes a function
218 -- with the following specification:
220 -- function S'Enum_Rep (Arg : S'Base) return universal_integer;
222 -- The function returns the representation value for the given
223 -- enumeration value. This will be equal to the 'Pos value in the
224 -- absence of an enumeration representation clause. This is a static
225 -- attribute (i.e. the result is static if the argument is static).
231 Attribute_Fixed_Value
=> True,
233 -- For every fixed-point type S, S'Fixed_Value denotes a function
234 -- with the following specification:
236 -- function S'Fixed_Value (Arg : universal_integer) return S;
238 -- The value returned is the fixed-point value V such that
242 -- The effect is thus equivalent to first converting the argument
243 -- to the integer type used to represent S, and then doing an
244 -- unchecked conversion to the fixed-point type. This attribute is
245 -- primarily intended for use in implementation of the input-output
246 -- functions for fixed-point values.
248 -----------------------
249 -- Has_Discriminants --
250 -----------------------
252 Attribute_Has_Discriminants
=> True,
254 -- Gtyp'Has_Discriminants, where Gtyp is a generic formal type, yields
255 -- a Boolean value indicating whether or not the actual instantiation
256 -- type has discriminants.
262 Attribute_Img
=> True,
264 -- The 'Img function is defined for any prefix, P, that denotes an
265 -- object of scalar type T. P'Img is equivalent to T'Image (P). This
266 -- is convenient for debugging. For example:
268 -- Put_Line ("X = " & X'Img);
270 -- has the same meaning as the more verbose:
272 -- Put_Line ("X = " & Temperature_Type'Image (X));
274 -- where Temperature_Type is the subtype of the object X.
280 Attribute_Integer_Value
=> True,
282 -- For every integer type S, S'Integer_Value denotes a function
283 -- with the following specification:
285 -- function S'Integer_Value (Arg : universal_fixed) return S;
287 -- The value returned is the integer value V, such that
289 -- Arg = V * fixed-type'Small
291 -- The effect is thus equivalent to first doing an unchecked convert
292 -- from the fixed-point type to its corresponding implementation type,
293 -- and then converting the result to the target integer type. This
294 -- attribute is primarily intended for use in implementation of the
295 -- standard input-output functions for fixed-point values.
301 Attribute_Machine_Size
=> True,
303 -- This attribute is identical to the Object_Size attribute. It is
304 -- provided for compatibility with the DEC attribute of this name.
306 -----------------------
307 -- Maximum_Alignment --
308 -----------------------
310 Attribute_Maximum_Alignment
=> True,
312 -- Standard'Maximum_Alignment (Standard is the only permissible prefix)
313 -- provides the maximum useful alignment value for the target. This
314 -- is a static value that can be used to specify the alignment for an
315 -- object, guaranteeing that it is properly aligned in all cases. The
316 -- time this is useful is when an external object is imported and its
317 -- alignment requirements are unknown. This is a static attribute.
323 Attribute_Mechanism_Code
=> True,
325 -- function'Mechanism_Code yeilds an integer code for the mechanism
326 -- used for the result of function, and subprogram'Mechanism_Code (n)
327 -- yields the mechanism used for formal parameter number n (a static
328 -- integer value, 1 = first parameter). The code returned is:
330 -- 1 = by copy (value)
332 -- 3 = by descriptor (default descriptor type)
333 -- 4 = by descriptor (UBS unaligned bit string)
334 -- 5 = by descriptor (UBSB aligned bit string with arbitrary bounds)
335 -- 6 = by descriptor (UBA unaligned bit array)
336 -- 7 = by descriptor (S string, also scalar access type parameter)
337 -- 8 = by descriptor (SB string with arbitrary bounds)
338 -- 9 = by descriptor (A contiguous array)
339 -- 10 = by descriptor (NCA non-contiguous array)
345 Attribute_Null_Parameter
=> True,
347 -- A reference T'Null_Parameter denotes an (imaginary) object of
348 -- type or subtype T allocated at (machine) address zero. The
349 -- attribute is allowed only as the default expression of a formal
350 -- parameter, or as an actual expression of a subporgram call. In
351 -- either case, the subprogram must be imported.
353 -- The identity of the object is represented by the address zero
354 -- in the argument list, independent of the passing mechanism
355 -- (explicit or default).
357 -- The reason that this capability is needed is that for a record
358 -- or other composite object passed by reference, there is no other
359 -- way of specifying that a zero address should be passed.
365 Attribute_Object_Size
=> True,
367 -- Type'Object_Size is the same as Type'Size for all types except
368 -- fixed-point types and discrete types. For fixed-point types and
369 -- discrete types, this attribute gives the size used for default
370 -- allocation of objects and components of the size. See section
371 -- in Einfo ("Handling of type'Size values") for further details.
373 -------------------------
374 -- Passed_By_Reference --
375 -------------------------
377 Attribute_Passed_By_Reference
=> True,
379 -- T'Passed_By_Reference for any subtype T returns a boolean value
380 -- that is true if the type is normally passed by reference and
381 -- false if the type is normally passed by copy in calls. For scalar
382 -- types, the result is always False and is static. For non-scalar
383 -- types, the result is non-static (since it is computed by Gigi).
389 Attribute_Range_Length
=> True,
391 -- T'Range_Length for any discrete type T yields the number of
392 -- values represented by the subtype (zero for a null range). The
393 -- result is static for static subtypes. Note that Range_Length
394 -- applied to the index subtype of a one dimensional array always
395 -- gives the same result as Range applied to the array itself.
396 -- The result is of type universal integer.
402 Attribute_Storage_Unit
=> True,
404 -- Standard'Storage_Unit (Standard is the only permissible prefix)
405 -- provides the value System.Storage_Unit, and is intended primarily
406 -- for constructing this definition in package System (see note above
407 -- in Default_Bit_Order description). The is a static attribute.
413 Attribute_To_Address
=> True,
415 -- System'To_Address (Address is the only permissible prefix)
416 -- is a function that takes any integer value, and converts it into
417 -- an address value. The semantics is to first convert the integer
418 -- value to type Integer_Address according to normal conversion
419 -- rules, and then to convert this to an address using the same
420 -- semantics as the System.Storage_Elements.To_Address function.
421 -- The important difference is that this is a static attribute
422 -- so it can be used in initializations in preealborate packages.
428 Attribute_Type_Class
=> True,
430 -- T'Type_Class for any type or subtype T yields the value of the
431 -- type class for the full type of T. If T is a generic formal type,
432 -- then the value is the value for the corresponding actual subtype.
433 -- The value of this attribute is of type System.Aux_DEC.Type_Class,
434 -- which has the following definition:
436 -- type Type_Class is
437 -- (Type_Class_Enumeration,
438 -- Type_Class_Integer,
439 -- Type_Class_Fixed_Point,
440 -- Type_Class_Floating_Point,
442 -- Type_Class_Record,
443 -- Type_Class_Access,
445 -- Type_Class_Address);
447 -- Protected types yield the value Type_Class_Task, which thus
448 -- applies to all concurrent types. This attribute is designed to
449 -- be compatible with the DEC Ada attribute of the same name.
451 -- Note: if pragma Extend_System is used to merge the definitions of
452 -- Aux_DEC into System, then the type Type_Class can be referenced
453 -- as an entity within System, as can its enumeration literals.
459 Attribute_UET_Address
=> True,
461 -- Unit'UET_Address, where Unit is a program unit, yields the address
462 -- of the unit exception table for the specified unit. This is only
463 -- used in the internal implementation of exception handling. See the
464 -- implementation of unit Ada.Exceptions for details on its use.
466 ------------------------------
467 -- Universal_Literal_String --
468 ------------------------------
470 Attribute_Universal_Literal_String
=> True,
472 -- The prefix of 'Universal_Literal_String must be a named number.
473 -- The static result is the string consisting of the characters of
474 -- the number as defined in the original source. This allows the
475 -- user program to access the actual text of named numbers without
476 -- intermediate conversions and without the need to enclose the
477 -- strings in quotes (which would preclude their use as numbers).
478 -- This is used internally for the construction of values of the
479 -- floating-point attributes from the file ttypef.ads, but may
480 -- also be used by user programs.
482 -------------------------
483 -- Unrestricted_Access --
484 -------------------------
486 Attribute_Unrestricted_Access
=> True,
488 -- The Unrestricted_Access attribute is similar to Access except that
489 -- all accessibility and aliased view checks are omitted. This is very
490 -- much a user-beware attribute. Basically its status is very similar
491 -- to Address, for which it is a desirable replacement where the value
492 -- desired is an access type. In other words, its effect is identical
493 -- to first taking 'Address and then doing an unchecked conversion to
494 -- a desired access type. Note that in GNAT, but not necessarily in
495 -- other implementations, the use of static chains for inner level
496 -- subprograms means that Unrestricted_Access applied to a subprogram
497 -- yields a value that can be called as long as the subprogram is in
498 -- scope (normal Ada 95 accessibility rules restrict this usage).
504 Attribute_VADS_Size
=> True,
506 -- Typ'VADS_Size yields the Size value typically yielded by some
507 -- Ada 83 compilers. The differences between VADS_Size and Size
508 -- is that for scalar types for which no Size has been specified,
509 -- VADS_Size yields the Object_Size rather than the Value_Size.
510 -- For example, while Natural'Size is typically 31, the value of
511 -- Natural'VADS_Size is 32. For all other types, Size and VADS_Size
512 -- yield the same value.
518 Attribute_Value_Size
=> True,
520 -- Type'Value_Size is the number of bits required to represent a
521 -- value of the given subtype. It is the same as Type'Size, but,
522 -- unlike Size, may be set for non-first subtypes. See section
523 -- in Einfo ("Handling of type'Size values") for further details.
529 Attribute_Word_Size
=> True,
531 -- Standard'Word_Size (Standard is the only permissible prefix)
532 -- provides the value System.Word_Size, and is intended primarily
533 -- for constructing this definition in package System (see note above
534 -- in Default_Bit_Order description). This is a static attribute.
542 procedure Analyze_Attribute
(N
: Node_Id
);
543 -- Performs bottom up semantic analysis of an attribute. Note that the
544 -- parser has already checked that type returning attributes appear only
545 -- in appropriate contexts (i.e. in subtype marks, or as prefixes for
546 -- other attributes).
548 procedure Resolve_Attribute
(N
: Node_Id
; Typ
: Entity_Id
);
549 -- Performs type resolution of attribute. If the attribute yields
550 -- a universal value, mark its type as that of the context. On
551 -- the other hand, if the context itself is universal (as in
552 -- T'Val (T'Pos (X)), mark the type as being the largest type of
553 -- that class that can be used at run-time. This is correct since
554 -- either the value gets folded (in which case it doesn't matter
555 -- what type of the class we give if, since the folding uses universal
556 -- arithmetic anyway) or it doesn't get folded (in which case it is
557 -- going to be dealt with at runtime, and the largest type is right).