1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2007, 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, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, 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 Exp_Tss; use Exp_Tss;
35 with Namet; use Namet;
36 with Snames; use Snames;
37 with Types; use Types;
41 type Attribute_Class_Array is array (Attribute_Id) of Boolean;
42 -- Type used to build attribute classification flag arrays
44 -----------------------------------------
45 -- Implementation Dependent Attributes --
46 -----------------------------------------
48 -- This section describes the implementation dependent attributes
49 -- provided in GNAT, as well as constructing an array of flags
50 -- indicating which attributes these are.
52 Attribute_Impl_Def : Attribute_Class_Array := Attribute_Class_Array'(
58 Attribute_Abort_Signal => True,
59 -- Standard'Abort_Signal (Standard is the only allowed prefix) provides
60 -- the entity for the special exception used to signal task abort or
61 -- asynchronous transfer of control. Normally this attribute should only
62 -- be used in the tasking runtime (it is highly peculiar, and completely
63 -- outside the normal semantics of Ada, for a user program to intercept
64 -- the abort exception).
70 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,
82 -- Used only in conjunction with the Asm subprograms in package
83 -- Machine_Code to construct machine instructions. See documentation
84 -- in package Machine_Code in file s-maccod.ads.
90 Attribute_Asm_Output => True,
91 -- Used only in conjunction with the Asm subprograms in package
92 -- Machine_Code to construct machine instructions. See documentation
93 -- in package Machine_Code in file s-maccod.ads.
99 Attribute_AST_Entry => True,
100 -- E'Ast_Entry, where E is a task entry, yields a value of the
101 -- predefined type System.DEC.AST_Handler, that enables the given
102 -- entry to be called when an AST occurs. If the name to which the
103 -- attribute applies has not been specified with the pragma AST_Entry,
104 -- the attribute returns the value No_Ast_Handler, and no AST occurs.
105 -- If the entry is for a task that is not callable (T'Callable False),
106 -- the exception program error is raised. If an AST occurs for an
107 -- entry of a task that is terminated, the program is erroneous.
109 -- The attribute AST_Entry is supported only in OpenVMS versions
110 -- of GNAT. It will be rejected as illegal in other GNAT versions.
116 Attribute_Bit => True,
117 -- Obj'Bit, where Obj is any object, yields the bit offset within the
118 -- storage unit (byte) that contains the first bit of storage allocated
119 -- for the object. The attribute value is of type Universal_Integer,
120 -- and is always a non-negative number not exceeding the value of
121 -- System.Storage_Unit.
123 -- For an object that is a variable or a constant allocated in a
124 -- register, the value is zero. (The use of this attribute does not
125 -- force the allocation of a variable to memory).
127 -- For an object that is a formal parameter, this attribute applies to
128 -- either the matching actual parameter or to a copy of the matching
131 -- For an access object the value is zero. Note that Obj.all'Bit is
132 -- subject to an Access_Check for the designated object. Similarly
133 -- for a record component X.C'Bit is subject to a discriminant check
134 -- and X(I).Bit and X(I1..I2)'Bit are subject to index checks.
136 -- This attribute is designed to be compatible with the DEC Ada
137 -- definition and implementation of the Bit attribute.
143 Attribute_Code_Address => True,
144 -- The reference subp'Code_Address, where subp is a subprogram entity,
145 -- gives the address of the first generated instruction for the sub-
146 -- program. This is often, but not always the same as the 'Address
147 -- value, which is the address to be used in a call. The differences
148 -- occur in the case of a nested procedure (where Address yields the
149 -- address of the trampoline code used to load the static link), and on
150 -- some systems which use procedure descriptors (in which case Address
151 -- yields the address of the descriptor).
153 -----------------------
154 -- Default_Bit_Order --
155 -----------------------
157 Attribute_Default_Bit_Order => True,
158 -- Standard'Default_Bit_Order (Standard is the only permissible prefix),
159 -- provides the value System.Default_Bit_Order as a Pos value (0 for
160 -- High_Order_First, 1 for Low_Order_First). This is used to construct
161 -- the definition of Default_Bit_Order in package System. This is a
168 Attribute_Elab_Body => True,
169 -- This attribute can only be applied to a program unit name. It returns
170 -- the entity for the corresponding elaboration procedure for elabor-
171 -- ating the body of the referenced unit. This is used in the main
172 -- generated elaboration procedure by the binder, and is not normally
173 -- used in any other context, but there may be specialized situations in
174 -- which it is useful to be able to call this elaboration procedure from
175 -- Ada code, e.g. if it is necessary to do selective reelaboration to
182 Attribute_Elab_Spec => True,
183 -- This attribute can only be applied to a program unit name. It
184 -- returns the entity for the corresponding elaboration procedure
185 -- for elaborating the spec of the referenced unit. This is used
186 -- in the main generated elaboration procedure by the binder, and
187 -- is not normally used in any other context, but there may be
188 -- specialized situations in which it is useful to be able to
189 -- call this elaboration procedure from Ada code, e.g. if it
190 -- is necessary to do selective reelaboration to fix some error.
196 Attribute_Elaborated => True,
197 -- Lunit'Elaborated, where Lunit is a library unit, yields a boolean
198 -- value indicating whether or not the body of the designated library
199 -- unit has been elaborated yet.
205 Attribute_Enum_Rep => True,
206 -- For every enumeration subtype S, S'Enum_Rep denotes a function
207 -- with the following specification:
209 -- function S'Enum_Rep (Arg : S'Base) return universal_integer;
211 -- The function returns the representation value for the given
212 -- enumeration value. This will be equal to the 'Pos value in the
213 -- absence of an enumeration representation clause. This is a static
214 -- attribute (i.e. the result is static if the argument is static).
220 Attribute_Fixed_Value => True,
221 -- For every fixed-point type S, S'Fixed_Value denotes a function
222 -- with the following specification:
224 -- function S'Fixed_Value (Arg : universal_integer) return S;
226 -- The value returned is the fixed-point value V such that
230 -- The effect is thus equivalent to first converting the argument to
231 -- the integer type used to represent S, and then doing an unchecked
232 -- conversion to the fixed-point type. This attribute is primarily
233 -- intended for use in implementation of the input-output functions for
234 -- fixed-point values.
236 -----------------------
237 -- Has_Discriminants --
238 -----------------------
240 Attribute_Has_Discriminants => True,
241 -- Gtyp'Has_Discriminants, where Gtyp is a generic formal type, yields
242 -- a Boolean value indicating whether or not the actual instantiation
243 -- type has discriminants.
249 Attribute_Img => True,
250 -- The 'Img function is defined for any prefix, P, that denotes an
251 -- object of scalar type T. P'Img is equivalent to T'Image (P). This
252 -- is convenient for debugging. For example:
254 -- Put_Line ("X = " & X'Img);
256 -- has the same meaning as the more verbose:
258 -- Put_Line ("X = " & Temperature_Type'Image (X));
260 -- where Temperature_Type is the subtype of the object X.
266 Attribute_Integer_Value => True,
267 -- For every integer type S, S'Integer_Value denotes a function
268 -- with the following specification:
270 -- function S'Integer_Value (Arg : universal_fixed) return S;
272 -- The value returned is the integer value V, such that
274 -- Arg = V * fixed-type'Small
276 -- The effect is thus equivalent to first doing an unchecked convert
277 -- from the fixed-point type to its corresponding implementation type,
278 -- and then converting the result to the target integer type. This
279 -- attribute is primarily intended for use in implementation of the
280 -- standard input-output functions for fixed-point values.
286 Attribute_Machine_Size => True,
287 -- This attribute is identical to the Object_Size attribute. It is
288 -- provided for compatibility with the DEC attribute of this name.
290 -----------------------
291 -- Maximum_Alignment --
292 -----------------------
294 Attribute_Maximum_Alignment => True,
295 -- Standard'Maximum_Alignment (Standard is the only permissible prefix)
296 -- provides the maximum useful alignment value for the target. This
297 -- is a static value that can be used to specify the alignment for an
298 -- object, guaranteeing that it is properly aligned in all cases. The
299 -- time this is useful is when an external object is imported and its
300 -- alignment requirements are unknown. This is a static attribute.
306 Attribute_Mechanism_Code => True,
307 -- function'Mechanism_Code yeilds an integer code for the mechanism
308 -- used for the result of function, and subprogram'Mechanism_Code (n)
309 -- yields the mechanism used for formal parameter number n (a static
310 -- integer value, 1 = first parameter). The code returned is:
312 -- 1 = by copy (value)
314 -- 3 = by descriptor (default descriptor type)
315 -- 4 = by descriptor (UBS unaligned bit string)
316 -- 5 = by descriptor (UBSB aligned bit string with arbitrary bounds)
317 -- 6 = by descriptor (UBA unaligned bit array)
318 -- 7 = by descriptor (S string, also scalar access type parameter)
319 -- 8 = by descriptor (SB string with arbitrary bounds)
320 -- 9 = by descriptor (A contiguous array)
321 -- 10 = by descriptor (NCA non-contiguous array)
327 Attribute_Null_Parameter => True,
328 -- A reference T'Null_Parameter denotes an (imaginary) object of type or
329 -- subtype T allocated at (machine) address zero. The attribute is
330 -- allowed only as the default expression of a formal parameter, or as
331 -- an actual expression of a subporgram call. In either case, the
332 -- subprogram must be imported.
334 -- The identity of the object is represented by the address zero in the
335 -- argument list, independent of the passing mechanism (explicit or
338 -- The reason that this capability is needed is that for a record or
339 -- other composite object passed by reference, there is no other way of
340 -- specifying that a zero address should be passed.
346 Attribute_Object_Size => True,
347 -- Type'Object_Size is the same as Type'Size for all types except
348 -- fixed-point types and discrete types. For fixed-point types and
349 -- discrete types, this attribute gives the size used for default
350 -- allocation of objects and components of the size. See section in
351 -- Einfo ("Handling of type'Size values") for further details.
353 -------------------------
354 -- Passed_By_Reference --
355 -------------------------
357 Attribute_Passed_By_Reference => True,
358 -- T'Passed_By_Reference for any subtype T returns a boolean value that
359 -- is true if the type is normally passed by reference and false if the
360 -- type is normally passed by copy in calls. For scalar types, the
361 -- result is always False and is static. For non-scalar types, the
362 -- result is non-static (since it is computed by Gigi).
368 Attribute_Range_Length => True,
369 -- T'Range_Length for any discrete type T yields the number of values
370 -- represented by the subtype (zero for a null range). The result is
371 -- static for static subtypes. Note that Range_Length applied to the
372 -- index subtype of a one dimensional array always gives the same result
373 -- as Range applied to the array itself. The result is of type universal
380 Attribute_Storage_Unit => True,
381 -- Standard'Storage_Unit (Standard is the only permissible prefix)
382 -- provides the value System.Storage_Unit, and is intended primarily
383 -- for constructing this definition in package System (see note above
384 -- in Default_Bit_Order description). The is a static attribute.
390 Attribute_Stub_Type => True,
391 -- The GNAT implementation of remote access-to-classwide types is
392 -- organised as described in AARM E.4(20.t): a value of an RACW type
393 -- (designating a remote object) is represented as a normal access
394 -- value, pointing to a "stub" object which in turn contains the
395 -- necessary information to contact the designated remote object. A
396 -- call on any dispatching operation of such a stub object does the
397 -- remote call, if necessary, using the information in the stub object
398 -- to locate the target partition, etc.
400 -- For a prefix T that denotes a remote access-to-classwide type,
401 -- T'Stub_Type denotes the type of the corresponding stub objects.
403 -- By construction, the layout of T'Stub_Type is identical to that of
404 -- System.Partition_Interface.RACW_Stub_Type (see implementation notes
405 -- in body of Exp_Dist).
411 Attribute_Target_Name => True,
412 -- Standard'Target_Name yields the string identifying the target for the
413 -- compilation, taken from Sdefault.Target_Name.
419 Attribute_To_Address => True,
420 -- System'To_Address (Address is the only permissible prefix) is a
421 -- function that takes any integer value, and converts it into an
422 -- address value. The semantics is to first convert the integer value to
423 -- type Integer_Address according to normal conversion rules, and then
424 -- to convert this to an address using the same semantics as the
425 -- System.Storage_Elements.To_Address function. The important difference
426 -- is that this is a static attribute so it can be used in
427 -- initializations in preealborate packages.
433 Attribute_Type_Class => True,
434 -- T'Type_Class for any type or subtype T yields the value of the type
435 -- class for the full type of T. If T is a generic formal type, then the
436 -- value is the value for the corresponding actual subtype. The value of
437 -- this attribute is of type System.Aux_DEC.Type_Class, which has the
438 -- following definition:
440 -- type Type_Class is
441 -- (Type_Class_Enumeration,
442 -- Type_Class_Integer,
443 -- Type_Class_Fixed_Point,
444 -- Type_Class_Floating_Point,
446 -- Type_Class_Record,
447 -- Type_Class_Access,
449 -- Type_Class_Address);
451 -- Protected types yield the value Type_Class_Task, which thus applies
452 -- to all concurrent types. This attribute is designed to be compatible
453 -- with the DEC Ada attribute of the same name.
455 -- Note: if pragma Extend_System is used to merge the definitions of
456 -- Aux_DEC into System, then the type Type_Class can be referenced
457 -- as an entity within System, as can its enumeration literals.
463 Attribute_UET_Address => True,
464 -- Unit'UET_Address, where Unit is a program unit, yields the address
465 -- of the unit exception table for the specified unit. This is only
466 -- used in the internal implementation of exception handling. See the
467 -- implementation of unit Ada.Exceptions for details on its use.
469 ------------------------------
470 -- Universal_Literal_String --
471 ------------------------------
473 Attribute_Universal_Literal_String => True,
474 -- The prefix of 'Universal_Literal_String must be a named number. The
475 -- static result is the string consisting of the characters of the
476 -- number as defined in the original source. This allows the user
477 -- program to access the actual text of named numbers without
478 -- intermediate conversions and without the need to enclose the strings
479 -- in quotes (which would preclude their use as numbers). This is used
480 -- internally for the construction of values of the floating-point
481 -- attributes from the file ttypef.ads, but may also be used by user
484 -------------------------
485 -- Unrestricted_Access --
486 -------------------------
488 Attribute_Unrestricted_Access => True,
489 -- The Unrestricted_Access attribute is similar to Access except that
490 -- all accessibility and aliased view checks are omitted. This is very
491 -- much a user-beware attribute. Basically its status is very similar
492 -- to Address, for which it is a desirable replacement where the value
493 -- desired is an access type. In other words, its effect is identical
494 -- to first taking 'Address and then doing an unchecked conversion to
495 -- a desired access type. Note that in GNAT, but not necessarily in
496 -- other implementations, the use of static chains for inner level
497 -- subprograms means that Unrestricted_Access applied to a subprogram
498 -- yields a value that can be called as long as the subprogram is in
499 -- scope (normal Ada 95 accessibility rules restrict this usage).
505 Attribute_VADS_Size => True,
506 -- Typ'VADS_Size yields the Size value typically yielded by some Ada 83
507 -- compilers. The differences between VADS_Size and Size is that for
508 -- scalar types for which no Size has been specified, VADS_Size yields
509 -- the Object_Size rather than the Value_Size. For example, while
510 -- Natural'Size is typically 31, the value of Natural'VADS_Size is 32.
511 -- For all other types, Size and VADS_Size yield the same value.
517 Attribute_Value_Size => True,
518 -- Type'Value_Size is the number of bits required to represent value of
519 -- the given subtype. It is the same as Type'Size, but, unlike Size, may
520 -- be set for non-first subtypes. See section in Einfo ("Handling of
521 -- type'Size values") for further details.
527 Attribute_Word_Size => True,
528 -- Standard'Word_Size (Standard is the only permissible prefix)
529 -- provides the value System.Word_Size, and is intended primarily
530 -- for constructing this definition in package System (see note above
531 -- in Default_Bit_Order description). This is a static attribute.
539 procedure Analyze_Attribute (N : Node_Id);
540 -- Performs bottom up semantic analysis of an attribute. Note that the
541 -- parser has already checked that type returning attributes appear only
542 -- in appropriate contexts (i.e. in subtype marks, or as prefixes for
543 -- other attributes).
545 function Name_Modifies_Prefix (Nam : Name_Id) return Boolean;
546 -- Determine whether the name of an attribute reference modifies the
547 -- contents of its prefix. "Read" is such an attribute.
549 function Requires_Simple_Name_Prefix (Nam : Name_Id) return Boolean;
550 -- Determine whether the name of an attribute reference requires a simple
551 -- name rather than a value as its prefix. Such prefixes do not need to be
552 -- optimized. For instance in the following example:
553 -- I : constant Integer := 5;
554 -- S : constant Integer := I'Size;
555 -- "Size" requires a simple name prefix since "5'Size" does not make
558 procedure Resolve_Attribute (N : Node_Id; Typ : Entity_Id);
559 -- Performs type resolution of attribute. If the attribute yields a
560 -- universal value, mark its type as that of the context. On the other
561 -- hand, if the context itself is universal (as in T'Val (T'Pos (X)), mark
562 -- the type as being the largest type of that class that can be used at
563 -- run-time. This is correct since either the value gets folded (in which
564 -- case it doesn't matter what type of the class we give if, since the
565 -- folding uses universal arithmetic anyway) or it doesn't get folded (in
566 -- which case it is going to be dealt with at runtime, and the largest type
569 function Stream_Attribute_Available
572 Partial_View : Entity_Id := Empty) return Boolean;
573 -- For a limited type Typ, return True iff the given attribute is
574 -- available. For Ada 05, availability is defined by 13.13.2(36/1). For Ada
575 -- 95, an attribute is considered to be available if it has been specified
576 -- using an attribute definition clause for the type, or for its full view,
577 -- or for an ancestor of either. Parameter Partial_View is used only
578 -- internally, when checking for an attribute definition clause that is not
579 -- visible (Ada 95 only).