* gcc.dg/store-motion-fgcse-sm.c (dg-final): Cleanup
[official-gcc.git] / gcc / ada / sem_attr.ads
blobc2652211b21ef43f1450d18867972d6b6f85f0ad
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S E M _ A T T R --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 1992-2014, Free Software Foundation, Inc. --
10 -- --
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 3, 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. --
17 -- --
18 -- You should have received a copy of the GNU General Public License along --
19 -- with this program; see file COPYING3. If not see --
20 -- <http://www.gnu.org/licenses/>. --
21 -- --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 -- --
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;
39 package Sem_Attr is
41 -----------------------------------------
42 -- Implementation Dependent Attributes --
43 -----------------------------------------
45 -- This section describes the implementation dependent attributes
46 -- provided in GNAT, as well as constructing an array of flags
47 -- indicating which attributes these are.
49 Attribute_Impl_Def : Attribute_Class_Array := Attribute_Class_Array'(
51 ------------------
52 -- Abort_Signal --
53 ------------------
55 Attribute_Abort_Signal => True,
56 -- Standard'Abort_Signal (Standard is the only allowed prefix) provides
57 -- the entity for the special exception used to signal task abort or
58 -- asynchronous transfer of control. Normally this attribute should only
59 -- be used in the tasking runtime (it is highly peculiar, and completely
60 -- outside the normal semantics of Ada, for a user program to intercept
61 -- the abort exception).
63 ------------------
64 -- Address_Size --
65 ------------------
67 Attribute_Address_Size => True,
68 -- Standard'Address_Size (Standard is the only allowed prefix) is
69 -- a static constant giving the number of bits in an Address. It
70 -- is used primarily for constructing the definition of Memory_Size
71 -- in package Standard, but may be freely used in user programs.
72 -- This is a static attribute.
74 ---------------
75 -- Asm_Input --
76 ---------------
78 Attribute_Asm_Input => True,
79 -- Used only in conjunction with the Asm subprograms in package
80 -- Machine_Code to construct machine instructions. See documentation
81 -- in package Machine_Code in file s-maccod.ads.
83 ----------------
84 -- Asm_Output --
85 ----------------
87 Attribute_Asm_Output => True,
88 -- Used only in conjunction with the Asm subprograms in package
89 -- Machine_Code to construct machine instructions. See documentation
90 -- in package Machine_Code in file s-maccod.ads.
92 ---------
93 -- Bit --
94 ---------
96 Attribute_Bit => True,
97 -- Obj'Bit, where Obj is any object, yields the bit offset within the
98 -- storage unit (byte) that contains the first bit of storage allocated
99 -- for the object. The attribute value is of type Universal_Integer,
100 -- and is always a non-negative number not exceeding the value of
101 -- System.Storage_Unit.
103 -- For an object that is a variable or a constant allocated in a
104 -- register, the value is zero. (The use of this attribute does not
105 -- force the allocation of a variable to memory).
107 -- For an object that is a formal parameter, this attribute applies to
108 -- either the matching actual parameter or to a copy of the matching
109 -- actual parameter.
111 -- For an access object the value is zero. Note that Obj.all'Bit is
112 -- subject to an Access_Check for the designated object. Similarly
113 -- for a record component X.C'Bit is subject to a discriminant check
114 -- and X(I).Bit and X(I1..I2)'Bit are subject to index checks.
116 -- This attribute is designed to be compatible with the DEC Ada
117 -- definition and implementation of the Bit attribute.
119 ------------------
120 -- Code_Address --
121 ------------------
123 Attribute_Code_Address => True,
124 -- The reference subp'Code_Address, where subp is a subprogram entity,
125 -- gives the address of the first generated instruction for the sub-
126 -- program. This is often, but not always the same as the 'Address
127 -- value, which is the address to be used in a call. The differences
128 -- occur in the case of a nested procedure (where Address yields the
129 -- address of the trampoline code used to load the static link), and on
130 -- some systems which use procedure descriptors (in which case Address
131 -- yields the address of the descriptor).
133 -----------------------
134 -- Default_Bit_Order --
135 -----------------------
137 Attribute_Default_Bit_Order => True,
138 -- Standard'Default_Bit_Order (Standard is the only permissible prefix)
139 -- provides the value System.Default_Bit_Order as a Pos value (0 for
140 -- High_Order_First, 1 for Low_Order_First). This is used to construct
141 -- the definition of Default_Bit_Order in package System. This is a
142 -- static attribute.
144 ----------------------------------
145 -- Default_Scalar_Storage_Order --
146 ----------------------------------
148 Attribute_Default_Scalar_Storage_Order => True,
149 -- Standard'Default_Scalar_Storage_Order (Standard is the
150 -- only permissible prefix) provides the current value of the
151 -- default scalar storage order (as specified using pragma
152 -- Default_Scalar_Storage_Order, or equal to Default_Bit_Order if
153 -- unspecified) as a System.Bit_Order value. This is a static attribute.
155 ---------------
156 -- Elab_Body --
157 ---------------
159 Attribute_Elab_Body => True,
160 -- This attribute can only be applied to a program unit name. It
161 -- returns the entity for the corresponding elaboration procedure for
162 -- elaborating the body of the referenced unit. This is used in the main
163 -- generated elaboration procedure by the binder, and is not normally
164 -- used in any other context, but there may be specialized situations in
165 -- which it is useful to be able to call this elaboration procedure from
166 -- Ada code, e.g. if it is necessary to do selective reelaboration to
167 -- fix some error.
169 --------------------
170 -- Elab_Subp_Body --
171 --------------------
173 Attribute_Elab_Subp_Body => True,
174 -- This attribute can only be applied to a library level subprogram
175 -- name and is only relevant in CodePeer mode. It returns the entity
176 -- for the corresponding elaboration procedure for elaborating the body
177 -- of the referenced subprogram unit. This is used in the main generated
178 -- elaboration procedure by the binder in CodePeer mode only.
180 ---------------
181 -- Elab_Spec --
182 ---------------
184 Attribute_Elab_Spec => True,
185 -- This attribute can only be applied to a program unit name. It
186 -- returns the entity for the corresponding elaboration procedure for
187 -- elaborating the spec of the referenced unit. This is used in the main
188 -- generated elaboration procedure by the binder, and is not normally
189 -- used in any other context, but there may be specialized situations in
190 -- which it is useful to be able to call this elaboration procedure from
191 -- Ada code, e.g. if it is necessary to do selective reelaboration to
192 -- fix some error.
194 ----------------
195 -- Elaborated --
196 ----------------
198 Attribute_Elaborated => True,
199 -- Lunit'Elaborated, where Lunit is a library unit, yields a boolean
200 -- value indicating whether or not the body of the designated library
201 -- unit has been elaborated yet.
203 --------------
204 -- Enum_Rep --
205 --------------
207 Attribute_Enum_Rep => True,
208 -- For every enumeration subtype S, S'Enum_Rep denotes a function
209 -- with the following specification:
211 -- function S'Enum_Rep (Arg : S'Base) return universal_integer;
213 -- The function returns the representation value for the given
214 -- enumeration value. This will be equal to the 'Pos value in the
215 -- absence of an enumeration representation clause. This is a static
216 -- attribute (i.e. the result is static if the argument is static).
218 --------------
219 -- Enum_Val --
220 --------------
222 Attribute_Enum_Val => True,
223 -- For every enumeration subtype S, S'Enum_Val denotes a function with
224 -- the following specification:
226 -- function S'Enum_Val (Arg : universal_integer) return S'Base;
228 -- This function performs the inverse transformation to Enum_Rep. Given
229 -- a representation value for the type, it returns the corresponding
230 -- enumeration value. Constraint_Error is raised if no value of the
231 -- enumeration type corresponds to the given integer value.
233 -----------------
234 -- Fixed_Value --
235 -----------------
237 Attribute_Fixed_Value => True,
238 -- For every fixed-point type S, S'Fixed_Value denotes a function
239 -- with the following specification:
241 -- function S'Fixed_Value (Arg : universal_integer) return S;
243 -- The value returned is the fixed-point value V such that
245 -- V = Arg * S'Small
247 -- The effect is thus equivalent to first converting the argument to
248 -- the integer type used to represent S, and then doing an unchecked
249 -- conversion to the fixed-point type. This attribute is primarily
250 -- intended for use in implementation of the input-output functions
251 -- for fixed-point values.
253 -----------------------
254 -- Has_Discriminants --
255 -----------------------
257 Attribute_Has_Discriminants => True,
258 -- Gtyp'Has_Discriminants, where Gtyp is a generic formal type, yields
259 -- a Boolean value indicating whether or not the actual instantiation
260 -- type has discriminants.
262 ---------
263 -- Img --
264 ---------
266 Attribute_Img => True,
267 -- The 'Img function is defined for any prefix, P, that denotes an
268 -- object of scalar type T. P'Img is equivalent to T'Image (P). This
269 -- is convenient for debugging. For example:
271 -- Put_Line ("X = " & X'Img);
273 -- has the same meaning as the more verbose:
275 -- Put_Line ("X = " & Temperature_Type'Image (X));
277 -- where Temperature_Type is the subtype of the object X.
279 -------------------
280 -- Integer_Value --
281 -------------------
283 Attribute_Integer_Value => True,
284 -- For every integer type S, S'Integer_Value denotes a function
285 -- with the following specification:
287 -- function S'Integer_Value (Arg : universal_fixed) return S;
289 -- The value returned is the integer value V, such that
291 -- Arg = V * fixed-type'Small
293 -- The effect is thus equivalent to first doing an unchecked convert
294 -- from the fixed-point type to its corresponding implementation type,
295 -- and then converting the result to the target integer type. This
296 -- attribute is primarily intended for use in implementation of the
297 -- standard input-output functions for fixed-point values.
299 Attribute_Invalid_Value => True,
300 -- For every scalar type, S'Invalid_Value designates an undefined value
301 -- of the type. If possible this value is an invalid value, and in fact
302 -- is identical to the value that would be set if Initialize_Scalars
303 -- mode were in effect (including the behavior of its value on
304 -- environment variables or binder switches). The intended use is to
305 -- set a value where initialization is required (e.g. as a result of the
306 -- coding standards in use), but logically no initialization is needed,
307 -- and the value should never be accessed.
309 Attribute_Loop_Entry => True,
310 -- For every object of a non-limited type, S'Loop_Entry [(Loop_Name)]
311 -- denotes the constant value of prefix S at the point of entry into the
312 -- related loop. The type of the attribute is the type of the prefix.
314 ------------------
315 -- Machine_Size --
316 ------------------
318 Attribute_Machine_Size => True,
319 -- This attribute is identical to the Object_Size attribute. It is
320 -- provided for compatibility with the DEC attribute of this name.
322 -----------------------
323 -- Maximum_Alignment --
324 -----------------------
326 Attribute_Maximum_Alignment => True,
327 -- Standard'Maximum_Alignment (Standard is the only permissible prefix)
328 -- provides the maximum useful alignment value for the target. This is a
329 -- static value that can be used to specify the alignment for an object,
330 -- guaranteeing that it is properly aligned in all cases. The time this
331 -- is useful is when an external object is imported and its alignment
332 -- requirements are unknown. This is a static attribute.
334 --------------------
335 -- Mechanism_Code --
336 --------------------
338 Attribute_Mechanism_Code => True,
339 -- function'Mechanism_Code yields an integer code for the mechanism
340 -- used for the result of function, and subprogram'Mechanism_Code (n)
341 -- yields the mechanism used for formal parameter number n (a static
342 -- integer value, 1 = first parameter). The code returned is:
344 -- 1 = by copy (value)
345 -- 2 = by reference
346 -- 3 = by descriptor (default descriptor type)
347 -- 4 = by descriptor (UBS unaligned bit string)
348 -- 5 = by descriptor (UBSB aligned bit string with arbitrary bounds)
349 -- 6 = by descriptor (UBA unaligned bit array)
350 -- 7 = by descriptor (S string, also scalar access type parameter)
351 -- 8 = by descriptor (SB string with arbitrary bounds)
352 -- 9 = by descriptor (A contiguous array)
353 -- 10 = by descriptor (NCA non-contiguous array)
355 --------------------
356 -- Null_Parameter --
357 --------------------
359 Attribute_Null_Parameter => True,
360 -- A reference T'Null_Parameter denotes an (imaginary) object of type
361 -- or subtype T allocated at (machine) address zero. The attribute is
362 -- allowed only as the default expression of a formal parameter, or
363 -- as an actual expression of a subprogram call. In either case, the
364 -- subprogram must be imported.
366 -- The identity of the object is represented by the address zero in
367 -- the argument list, independent of the passing mechanism (explicit
368 -- or default).
370 -- The reason that this capability is needed is that for a record or
371 -- other composite object passed by reference, there is no other way
372 -- of specifying that a zero address should be passed.
374 -----------------
375 -- Object_Size --
376 -----------------
378 Attribute_Object_Size => True,
379 -- Type'Object_Size is the same as Type'Size for all types except
380 -- fixed-point types and discrete types. For fixed-point types and
381 -- discrete types, this attribute gives the size used for default
382 -- allocation of objects and components of the size. See section in
383 -- Einfo ("Handling of type'Size values") for further details.
385 -------------------------
386 -- Passed_By_Reference --
387 -------------------------
389 Attribute_Passed_By_Reference => True,
390 -- T'Passed_By_Reference for any subtype T returns a boolean value that
391 -- is true if the type is normally passed by reference and false if the
392 -- type is normally passed by copy in calls. For scalar types, the
393 -- result is always False and is static. For non-scalar types, the
394 -- result is non-static (since it is computed by Gigi).
396 ------------------
397 -- Range_Length --
398 ------------------
400 Attribute_Range_Length => True,
401 -- T'Range_Length for any discrete type T yields the number of values
402 -- represented by the subtype (zero for a null range). The result is
403 -- static for static subtypes. Note that Range_Length applied to the
404 -- index subtype of a one dimensional array always gives the same result
405 -- as Range applied to the array itself. The result is of type universal
406 -- integer.
408 ---------
409 -- Ref --
410 ---------
412 Attribute_Ref => True,
413 -- System.Address'Ref (Address is the only permissible prefix) is
414 -- equivalent to System'To_Address, provided for compatibility with
415 -- other compilers.
417 ------------------
418 -- Storage_Unit --
419 ------------------
421 Attribute_Storage_Unit => True,
422 -- Standard'Storage_Unit (Standard is the only permissible prefix)
423 -- provides the value System.Storage_Unit, and is intended primarily
424 -- for constructing this definition in package System (see note above
425 -- in Default_Bit_Order description). The is a static attribute.
427 ---------------
428 -- Stub_Type --
429 ---------------
431 Attribute_Stub_Type => True,
432 -- The GNAT implementation of remote access-to-classwide types is
433 -- organised as described in AARM E.4(20.t): a value of an RACW type
434 -- (designating a remote object) is represented as a normal access
435 -- value, pointing to a "stub" object which in turn contains the
436 -- necessary information to contact the designated remote object. A
437 -- call on any dispatching operation of such a stub object does the
438 -- remote call, if necessary, using the information in the stub object
439 -- to locate the target partition, etc.
441 -- For a prefix T that denotes a remote access-to-classwide type,
442 -- T'Stub_Type denotes the type of the corresponding stub objects.
444 -- By construction, the layout of T'Stub_Type is identical to that of
445 -- System.Partition_Interface.RACW_Stub_Type (see implementation notes
446 -- in body of Exp_Dist).
448 -----------------
449 -- Target_Name --
450 -----------------
452 Attribute_Target_Name => True,
453 -- Standard'Target_Name yields the string identifying the target for the
454 -- compilation, taken from Sdefault.Target_Name.
456 ----------------
457 -- To_Address --
458 ----------------
460 Attribute_To_Address => True,
461 -- System'To_Address (System is the only permissible prefix) is a
462 -- function that takes any integer value, and converts it into an
463 -- address value. The semantics is to first convert the integer value to
464 -- type Integer_Address according to normal conversion rules, and then
465 -- to convert this to an address using the same semantics as the
466 -- System.Storage_Elements.To_Address function. The important difference
467 -- is that this is a static attribute so it can be used in
468 -- initializations in preelaborate packages.
470 ----------------
471 -- Type_Class --
472 ----------------
474 Attribute_Type_Class => True,
475 -- T'Type_Class for any type or subtype T yields the value of the type
476 -- class for the full type of T. If T is a generic formal type, then the
477 -- value is the value for the corresponding actual subtype. The value of
478 -- this attribute is of type System.Aux_DEC.Type_Class, which has the
479 -- following definition:
481 -- type Type_Class is
482 -- (Type_Class_Enumeration,
483 -- Type_Class_Integer,
484 -- Type_Class_Fixed_Point,
485 -- Type_Class_Floating_Point,
486 -- Type_Class_Array,
487 -- Type_Class_Record,
488 -- Type_Class_Access,
489 -- Type_Class_Task,
490 -- Type_Class_Address);
492 -- Protected types yield the value Type_Class_Task, which thus applies
493 -- to all concurrent types. This attribute is designed to be compatible
494 -- with the DEC Ada attribute of the same name.
496 -- Note: if pragma Extend_System is used to merge the definitions of
497 -- Aux_DEC into System, then the type Type_Class can be referenced
498 -- as an entity within System, as can its enumeration literals.
500 -----------------
501 -- UET_Address --
502 -----------------
504 Attribute_UET_Address => True,
505 -- Unit'UET_Address, where Unit is a program unit, yields the address
506 -- of the unit exception table for the specified unit. This is only
507 -- used in the internal implementation of exception handling. See the
508 -- implementation of unit Ada.Exceptions for details on its use.
510 ------------------------------
511 -- Universal_Literal_String --
512 ------------------------------
514 Attribute_Universal_Literal_String => True,
515 -- The prefix of 'Universal_Literal_String must be a named number.
516 -- The static result is the string consisting of the characters of
517 -- the number as defined in the original source. This allows the
518 -- user program to access the actual text of named numbers without
519 -- intermediate conversions and without the need to enclose the
520 -- strings in quotes (which would preclude their use as numbers).
522 -------------------------
523 -- Unrestricted_Access --
524 -------------------------
526 Attribute_Unrestricted_Access => True,
527 -- The Unrestricted_Access attribute is similar to Access except that
528 -- all accessibility and aliased view checks are omitted. This is very
529 -- much a user-beware attribute. Basically its status is very similar
530 -- to Address, for which it is a desirable replacement where the value
531 -- desired is an access type. In other words, its effect is identical
532 -- to first taking 'Address and then doing an unchecked conversion to
533 -- a desired access type. Note that in GNAT, but not necessarily in
534 -- other implementations, the use of static chains for inner level
535 -- subprograms means that Unrestricted_Access applied to a subprogram
536 -- yields a value that can be called as long as the subprogram is in
537 -- scope (normal Ada 95 accessibility rules restrict this usage).
539 ---------------
540 -- VADS_Size --
541 ---------------
543 Attribute_VADS_Size => True,
544 -- Typ'VADS_Size yields the Size value typically yielded by some Ada 83
545 -- compilers. The differences between VADS_Size and Size is that for
546 -- scalar types for which no Size has been specified, VADS_Size yields
547 -- the Object_Size rather than the Value_Size. For example, while
548 -- Natural'Size is typically 31, the value of Natural'VADS_Size is 32.
549 -- For all other types, Size and VADS_Size yield the same value.
551 -------------------
552 -- Valid_Scalars --
553 -------------------
555 Attribute_Valid_Scalars => True,
556 -- Obj'Valid_Scalars can be applied to any object. The result depends
557 -- on the type of the object:
559 -- For a scalar type, the result is the same as obj'Valid
561 -- For an array object, the result is True if the result of applying
562 -- Valid_Scalars to every component is True. For an empty array the
563 -- result is True.
565 -- For a record object, the result is True if the result of applying
566 -- Valid_Scalars to every component is True. For class-wide types,
567 -- only the components of the base type are checked. For variant
568 -- records, only the components actually present are checked. The
569 -- discriminants, if any, are also checked. If there are no components
570 -- or discriminants, the result is True.
572 -- For any other type that has discriminants, the result is True if
573 -- the result of applying Valid_Scalars to each discriminant is True.
575 -- For all other types, the result is always True
577 -- A warning is given for a trivially True result, when the attribute
578 -- is applied to an object that is not of scalar, array, or record
579 -- type, or in the composite case if no scalar subcomponents exist. For
580 -- a variant record, the warning is given only if none of the variants
581 -- have scalar subcomponents. In addition, the warning is suppressed
582 -- for private types, or generic formal types in an instance.
584 ----------------
585 -- Value_Size --
586 ----------------
588 Attribute_Value_Size => True,
589 -- Type'Value_Size is the number of bits required to represent value of
590 -- the given subtype. It is the same as Type'Size, but, unlike Size, may
591 -- be set for non-first subtypes. See section in Einfo ("Handling of
592 -- type'Size values") for further details.
594 ---------------
595 -- Word_Size --
596 ---------------
598 Attribute_Word_Size => True,
599 -- Standard'Word_Size (Standard is the only permissible prefix)
600 -- provides the value System.Word_Size, and is intended primarily
601 -- for constructing this definition in package System (see note above
602 -- in Default_Bit_Order description). This is a static attribute.
604 others => False);
606 -----------------
607 -- Subprograms --
608 -----------------
610 procedure Analyze_Attribute (N : Node_Id);
611 -- Performs bottom up semantic analysis of an attribute. Note that the
612 -- parser has already checked that type returning attributes appear only
613 -- in appropriate contexts (i.e. in subtype marks, or as prefixes for
614 -- other attributes).
616 function Name_Implies_Lvalue_Prefix (Nam : Name_Id) return Boolean;
617 -- Determine whether the name of an attribute reference categorizes its
618 -- prefix as an lvalue. The following attributes fall under this bracket
619 -- by directly or indirectly modifying their prefixes.
620 -- Access
621 -- Address
622 -- Input
623 -- Read
624 -- Unchecked_Access
625 -- Unrestricted_Access
627 procedure Resolve_Attribute (N : Node_Id; Typ : Entity_Id);
628 -- Performs type resolution of attribute. If the attribute yields a
629 -- universal value, mark its type as that of the context. On the other
630 -- hand, if the context itself is universal (as in T'Val (T'Pos (X)), mark
631 -- the type as being the largest type of that class that can be used at
632 -- run-time. This is correct since either the value gets folded (in which
633 -- case it doesn't matter what type of the class we give if, since the
634 -- folding uses universal arithmetic anyway) or it doesn't get folded (in
635 -- which case it is going to be dealt with at runtime, and the largest type
636 -- is right).
638 function Stream_Attribute_Available
639 (Typ : Entity_Id;
640 Nam : TSS_Name_Type;
641 Partial_View : Entity_Id := Empty) return Boolean;
642 -- For a limited type Typ, return True if and only if the given attribute
643 -- is available. For Ada 2005, availability is defined by 13.13.2(36/1).
644 -- For Ada 95, an attribute is considered to be available if it has been
645 -- specified using an attribute definition clause for the type, or for its
646 -- full view, or for an ancestor of either. Parameter Partial_View is used
647 -- only internally, when checking for an attribute definition clause that
648 -- is not visible (Ada 95 only).
650 end Sem_Attr;