1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2003, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 -- Attribute handling is isolated in a separate package to ease the addition
28 -- of implementation defined attributes. Logically this processing belongs
29 -- in chapter 4. See Sem_Ch4 for a description of the relation of the
30 -- Analyze and Resolve routines for expression components.
32 -- This spec also documents all GNAT implementation defined pragmas
34 with Snames
; use Snames
;
35 with Types
; use Types
;
39 type Attribute_Class_Array
is array (Attribute_Id
) of Boolean;
40 -- Type used to build attribute classification flag arrays
42 -----------------------------------------
43 -- Implementation Dependent Attributes --
44 -----------------------------------------
46 -- This section describes the implementation dependent attributes
47 -- provided in GNAT, as well as constructing an array of flags
48 -- indicating which attributes these are.
50 Attribute_Impl_Def
: Attribute_Class_Array
:= Attribute_Class_Array
'(
56 Attribute_Abort_Signal => True,
58 -- Standard'Abort_Signal (Standard is the only allowed prefix)
59 -- provides the entity for the special exception used to signal
60 -- task abort or asynchronous transfer of control. Normally this
61 -- attribute should only be used in the tasking runtime (it is
62 -- highly peculiar, and completely outside the normal semantics
63 -- of Ada, for a user program to intercept the abort exception).
69 Attribute_Address_Size => True,
71 -- Standard'Address_Size (Standard is the only allowed prefix) is
72 -- a static constant giving the number of bits in an Address. It
73 -- is used primarily for constructing the definition of Memory_Size
74 -- in package Standard, but may be freely used in user programs.
75 -- This is a static attribute.
81 Attribute_Asm_Input => True,
83 -- Used only in conjunction with the Asm and Asm_Volatile subprograms
84 -- in package Machine_Code to construct machine instructions. See
85 -- documentation in package Machine_Code in file s-maccod.ads.
91 Attribute_Asm_Output => True,
93 -- Used only in conjunction with the Asm and Asm_Volatile subprograms
94 -- in package Machine_Code to construct machine instructions. See
95 -- documentation in package Machine_Code in file s-maccod.ads.
101 Attribute_AST_Entry => True,
103 -- E'Ast_Entry, where E is a task entry, yields a value of the
104 -- predefined type System.DEC.AST_Handler, that enables the given
105 -- entry to be called when an AST occurs. If the name to which the
106 -- attribute applies has not been specified with the pragma AST_Entry,
107 -- the attribute returns the value No_Ast_Handler, and no AST occurs.
108 -- If the entry is for a task that is not callable (T'Callable False),
109 -- the exception program error is raised. If an AST occurs for an
110 -- entry of a task that is terminated, the program is erroneous.
112 -- The attribute AST_Entry is supported only in OpenVMS versions
113 -- of GNAT. It will be rejected as illegal in other GNAT versions.
119 Attribute_Bit => True,
121 -- Obj'Bit, where Obj is any object, yields the bit offset within
122 -- the storage unit (byte) that contains the first bit of storage
123 -- allocated for the object. The value of this attribute is of the
124 -- type Universal_Integer, and is always a non-negative number not
125 -- exceeding the value of System.Storage_Unit.
127 -- For an object that is a variable or a constant allocated in a
128 -- register, the value is zero. (The use of this attribute does not
129 -- force the allocation of a variable to memory).
131 -- For an object that is a formal parameter, this attribute applies
132 -- to either the matching actual parameter or to a copy of the
133 -- matching actual parameter.
135 -- For an access object the value is zero. Note that Obj.all'Bit is
136 -- subject to an Access_Check for the designated object. Similarly
137 -- for a record component X.C'Bit is subject to a discriminant check
138 -- and X(I).Bit and X(I1..I2)'Bit are subject to index checks.
140 -- This attribute is designed to be compatible with the DEC Ada
141 -- definition and implementation of the Bit attribute.
147 Attribute_Code_Address => True,
149 -- subp'Code_Address, where subp is a subprogram entity, gives the
150 -- address of the first generated instruction for a subprogram. This
151 -- is often, but not always the same as the 'Address value
, which
is
152 -- the address to be used in a call. The differences occur in the case
153 -- of a nested procedure (where Address yields the address of the
154 -- trampoline code used to load the static link), and on some systems
155 -- which use procedure descriptors (in which case Address yields the
156 -- address of the descriptor).
158 -----------------------
159 -- Default_Bit_Order --
160 -----------------------
162 Attribute_Default_Bit_Order
=> True,
164 -- Standard'Default_Bit_Order (Standard is the only permissible prefix),
165 -- provides the value System.Default_Bit_Order as a Pos value (0 for
166 -- High_Order_First, 1 for Low_Order_First). This is used to construct
167 -- the definition of Default_Bit_Order in package System. This is a
174 Attribute_Elab_Body
=> True,
176 -- This attribute can only be applied to a program unit name. It
177 -- returns the entity for the corresponding elaboration procedure
178 -- for elaborating the body of the referenced unit. This is used
179 -- in the main generated elaboration procedure by the binder, and
180 -- is not normally used in any other context, but there may be
181 -- specialized situations in which it is useful to be able to
182 -- call this elaboration procedure from Ada code, e.g. if it
183 -- is necessary to do selective reelaboration to fix some error.
189 Attribute_Elab_Spec
=> True,
191 -- This attribute can only be applied to a program unit name. It
192 -- returns the entity for the corresponding elaboration procedure
193 -- for elaborating the spec of the referenced unit. This is used
194 -- in the main generated elaboration procedure by the binder, and
195 -- is not normally used in any other context, but there may be
196 -- specialized situations in which it is useful to be able to
197 -- call this elaboration procedure from Ada code, e.g. if it
198 -- is necessary to do selective reelaboration to fix some error.
204 Attribute_Elaborated
=> True,
206 -- Lunit'Elaborated, where Lunit is a library unit, yields a boolean
207 -- value indicating whether or not the body of the designated library
208 -- unit has been elaborated yet.
214 Attribute_Enum_Rep
=> True,
216 -- For every enumeration subtype S, S'Enum_Rep denotes a function
217 -- with the following specification:
219 -- function S'Enum_Rep (Arg : S'Base) return universal_integer;
221 -- The function returns the representation value for the given
222 -- enumeration value. This will be equal to the 'Pos value in the
223 -- absence of an enumeration representation clause. This is a static
224 -- attribute (i.e. the result is static if the argument is static).
230 Attribute_Fixed_Value
=> True,
232 -- For every fixed-point type S, S'Fixed_Value denotes a function
233 -- with the following specification:
235 -- function S'Fixed_Value (Arg : universal_integer) return S;
237 -- The value returned is the fixed-point value V such that
241 -- The effect is thus equivalent to first converting the argument
242 -- to the integer type used to represent S, and then doing an
243 -- unchecked conversion to the fixed-point type. This attribute is
244 -- primarily intended for use in implementation of the input-output
245 -- functions for fixed-point values.
247 -----------------------
248 -- Has_Discriminants --
249 -----------------------
251 Attribute_Has_Discriminants
=> True,
253 -- Gtyp'Has_Discriminants, where Gtyp is a generic formal type, yields
254 -- a Boolean value indicating whether or not the actual instantiation
255 -- type has discriminants.
261 Attribute_Img
=> True,
263 -- The 'Img function is defined for any prefix, P, that denotes an
264 -- object of scalar type T. P'Img is equivalent to T'Image (P). This
265 -- is convenient for debugging. For example:
267 -- Put_Line ("X = " & X'Img);
269 -- has the same meaning as the more verbose:
271 -- Put_Line ("X = " & Temperature_Type'Image (X));
273 -- where Temperature_Type is the subtype of the object X.
279 Attribute_Integer_Value
=> True,
281 -- For every integer type S, S'Integer_Value denotes a function
282 -- with the following specification:
284 -- function S'Integer_Value (Arg : universal_fixed) return S;
286 -- The value returned is the integer value V, such that
288 -- Arg = V * fixed-type'Small
290 -- The effect is thus equivalent to first doing an unchecked convert
291 -- from the fixed-point type to its corresponding implementation type,
292 -- and then converting the result to the target integer type. This
293 -- attribute is primarily intended for use in implementation of the
294 -- standard input-output functions for fixed-point values.
300 Attribute_Machine_Size
=> True,
302 -- This attribute is identical to the Object_Size attribute. It is
303 -- provided for compatibility with the DEC attribute of this name.
305 -----------------------
306 -- Maximum_Alignment --
307 -----------------------
309 Attribute_Maximum_Alignment
=> True,
311 -- Standard'Maximum_Alignment (Standard is the only permissible prefix)
312 -- provides the maximum useful alignment value for the target. This
313 -- is a static value that can be used to specify the alignment for an
314 -- object, guaranteeing that it is properly aligned in all cases. The
315 -- time this is useful is when an external object is imported and its
316 -- alignment requirements are unknown. This is a static attribute.
322 Attribute_Mechanism_Code
=> True,
324 -- function'Mechanism_Code yeilds an integer code for the mechanism
325 -- used for the result of function, and subprogram'Mechanism_Code (n)
326 -- yields the mechanism used for formal parameter number n (a static
327 -- integer value, 1 = first parameter). The code returned is:
329 -- 1 = by copy (value)
331 -- 3 = by descriptor (default descriptor type)
332 -- 4 = by descriptor (UBS unaligned bit string)
333 -- 5 = by descriptor (UBSB aligned bit string with arbitrary bounds)
334 -- 6 = by descriptor (UBA unaligned bit array)
335 -- 7 = by descriptor (S string, also scalar access type parameter)
336 -- 8 = by descriptor (SB string with arbitrary bounds)
337 -- 9 = by descriptor (A contiguous array)
338 -- 10 = by descriptor (NCA non-contiguous array)
344 Attribute_Null_Parameter
=> True,
346 -- A reference T'Null_Parameter denotes an (imaginary) object of
347 -- type or subtype T allocated at (machine) address zero. The
348 -- attribute is allowed only as the default expression of a formal
349 -- parameter, or as an actual expression of a subporgram call. In
350 -- either case, the subprogram must be imported.
352 -- The identity of the object is represented by the address zero
353 -- in the argument list, independent of the passing mechanism
354 -- (explicit or default).
356 -- The reason that this capability is needed is that for a record
357 -- or other composite object passed by reference, there is no other
358 -- way of specifying that a zero address should be passed.
364 Attribute_Object_Size
=> True,
366 -- Type'Object_Size is the same as Type'Size for all types except
367 -- fixed-point types and discrete types. For fixed-point types and
368 -- discrete types, this attribute gives the size used for default
369 -- allocation of objects and components of the size. See section
370 -- in Einfo ("Handling of type'Size values") for further details.
372 -------------------------
373 -- Passed_By_Reference --
374 -------------------------
376 Attribute_Passed_By_Reference
=> True,
378 -- T'Passed_By_Reference for any subtype T returns a boolean value
379 -- that is true if the type is normally passed by reference and
380 -- false if the type is normally passed by copy in calls. For scalar
381 -- types, the result is always False and is static. For non-scalar
382 -- types, the result is non-static (since it is computed by Gigi).
388 Attribute_Range_Length
=> True,
390 -- T'Range_Length for any discrete type T yields the number of
391 -- values represented by the subtype (zero for a null range). The
392 -- result is static for static subtypes. Note that Range_Length
393 -- applied to the index subtype of a one dimensional array always
394 -- gives the same result as Range applied to the array itself.
395 -- The result is of type universal integer.
401 Attribute_Storage_Unit
=> True,
403 -- Standard'Storage_Unit (Standard is the only permissible prefix)
404 -- provides the value System.Storage_Unit, and is intended primarily
405 -- for constructing this definition in package System (see note above
406 -- in Default_Bit_Order description). The is a static attribute.
412 Attribute_Target_Name
=> True,
414 -- Standard'Target_Name yields the string identifying the target
415 -- for the compilation, taken from Sdefault.Target_Name.
421 Attribute_To_Address
=> True,
423 -- System'To_Address (Address is the only permissible prefix)
424 -- is a function that takes any integer value, and converts it into
425 -- an address value. The semantics is to first convert the integer
426 -- value to type Integer_Address according to normal conversion
427 -- rules, and then to convert this to an address using the same
428 -- semantics as the System.Storage_Elements.To_Address function.
429 -- The important difference is that this is a static attribute
430 -- so it can be used in initializations in preealborate packages.
436 Attribute_Type_Class
=> True,
438 -- T'Type_Class for any type or subtype T yields the value of the
439 -- type class for the full type of T. If T is a generic formal type,
440 -- then the value is the value for the corresponding actual subtype.
441 -- The value of this attribute is of type System.Aux_DEC.Type_Class,
442 -- which has the following definition:
444 -- type Type_Class is
445 -- (Type_Class_Enumeration,
446 -- Type_Class_Integer,
447 -- Type_Class_Fixed_Point,
448 -- Type_Class_Floating_Point,
450 -- Type_Class_Record,
451 -- Type_Class_Access,
453 -- Type_Class_Address);
455 -- Protected types yield the value Type_Class_Task, which thus
456 -- applies to all concurrent types. This attribute is designed to
457 -- be compatible with the DEC Ada attribute of the same name.
459 -- Note: if pragma Extend_System is used to merge the definitions of
460 -- Aux_DEC into System, then the type Type_Class can be referenced
461 -- as an entity within System, as can its enumeration literals.
467 Attribute_UET_Address
=> True,
469 -- Unit'UET_Address, where Unit is a program unit, yields the address
470 -- of the unit exception table for the specified unit. This is only
471 -- used in the internal implementation of exception handling. See the
472 -- implementation of unit Ada.Exceptions for details on its use.
474 ------------------------------
475 -- Universal_Literal_String --
476 ------------------------------
478 Attribute_Universal_Literal_String
=> True,
480 -- The prefix of 'Universal_Literal_String must be a named number.
481 -- The static result is the string consisting of the characters of
482 -- the number as defined in the original source. This allows the
483 -- user program to access the actual text of named numbers without
484 -- intermediate conversions and without the need to enclose the
485 -- strings in quotes (which would preclude their use as numbers).
486 -- This is used internally for the construction of values of the
487 -- floating-point attributes from the file ttypef.ads, but may
488 -- also be used by user programs.
490 -------------------------
491 -- Unrestricted_Access --
492 -------------------------
494 Attribute_Unrestricted_Access
=> True,
496 -- The Unrestricted_Access attribute is similar to Access except that
497 -- all accessibility and aliased view checks are omitted. This is very
498 -- much a user-beware attribute. Basically its status is very similar
499 -- to Address, for which it is a desirable replacement where the value
500 -- desired is an access type. In other words, its effect is identical
501 -- to first taking 'Address and then doing an unchecked conversion to
502 -- a desired access type. Note that in GNAT, but not necessarily in
503 -- other implementations, the use of static chains for inner level
504 -- subprograms means that Unrestricted_Access applied to a subprogram
505 -- yields a value that can be called as long as the subprogram is in
506 -- scope (normal Ada 95 accessibility rules restrict this usage).
512 Attribute_VADS_Size
=> True,
514 -- Typ'VADS_Size yields the Size value typically yielded by some
515 -- Ada 83 compilers. The differences between VADS_Size and Size
516 -- is that for scalar types for which no Size has been specified,
517 -- VADS_Size yields the Object_Size rather than the Value_Size.
518 -- For example, while Natural'Size is typically 31, the value of
519 -- Natural'VADS_Size is 32. For all other types, Size and VADS_Size
520 -- yield the same value.
526 Attribute_Value_Size
=> True,
528 -- Type'Value_Size is the number of bits required to represent a
529 -- value of the given subtype. It is the same as Type'Size, but,
530 -- unlike Size, may be set for non-first subtypes. See section
531 -- in Einfo ("Handling of type'Size values") for further details.
537 Attribute_Word_Size
=> True,
539 -- Standard'Word_Size (Standard is the only permissible prefix)
540 -- provides the value System.Word_Size, and is intended primarily
541 -- for constructing this definition in package System (see note above
542 -- in Default_Bit_Order description). This is a static attribute.
550 procedure Analyze_Attribute
(N
: Node_Id
);
551 -- Performs bottom up semantic analysis of an attribute. Note that the
552 -- parser has already checked that type returning attributes appear only
553 -- in appropriate contexts (i.e. in subtype marks, or as prefixes for
554 -- other attributes).
556 procedure Resolve_Attribute
(N
: Node_Id
; Typ
: Entity_Id
);
557 -- Performs type resolution of attribute. If the attribute yields
558 -- a universal value, mark its type as that of the context. On
559 -- the other hand, if the context itself is universal (as in
560 -- T'Val (T'Pos (X)), mark the type as being the largest type of
561 -- that class that can be used at run-time. This is correct since
562 -- either the value gets folded (in which case it doesn't matter
563 -- what type of the class we give if, since the folding uses universal
564 -- arithmetic anyway) or it doesn't get folded (in which case it is
565 -- going to be dealt with at runtime, and the largest type is right).