1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2008, 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 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. 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 COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Ada
.Characters
.Latin_1
; use Ada
.Characters
.Latin_1
;
28 with Atree
; use Atree
;
29 with Casing
; use Casing
;
30 with Checks
; use Checks
;
31 with Einfo
; use Einfo
;
32 with Errout
; use Errout
;
34 with Exp_Dist
; use Exp_Dist
;
35 with Exp_Util
; use Exp_Util
;
36 with Expander
; use Expander
;
37 with Freeze
; use Freeze
;
38 with Itypes
; use Itypes
;
40 with Lib
.Xref
; use Lib
.Xref
;
41 with Nlists
; use Nlists
;
42 with Nmake
; use Nmake
;
44 with Restrict
; use Restrict
;
45 with Rident
; use Rident
;
46 with Rtsfind
; use Rtsfind
;
47 with Sdefault
; use Sdefault
;
49 with Sem_Cat
; use Sem_Cat
;
50 with Sem_Ch6
; use Sem_Ch6
;
51 with Sem_Ch8
; use Sem_Ch8
;
52 with Sem_Dist
; use Sem_Dist
;
53 with Sem_Eval
; use Sem_Eval
;
54 with Sem_Res
; use Sem_Res
;
55 with Sem_Type
; use Sem_Type
;
56 with Sem_Util
; use Sem_Util
;
57 with Stand
; use Stand
;
58 with Sinfo
; use Sinfo
;
59 with Sinput
; use Sinput
;
60 with Stringt
; use Stringt
;
62 with Stylesw
; use Stylesw
;
63 with Targparm
; use Targparm
;
64 with Ttypes
; use Ttypes
;
65 with Ttypef
; use Ttypef
;
66 with Tbuild
; use Tbuild
;
67 with Uintp
; use Uintp
;
68 with Urealp
; use Urealp
;
70 package body Sem_Attr
is
72 True_Value
: constant Uint
:= Uint_1
;
73 False_Value
: constant Uint
:= Uint_0
;
74 -- Synonyms to be used when these constants are used as Boolean values
76 Bad_Attribute
: exception;
77 -- Exception raised if an error is detected during attribute processing,
78 -- used so that we can abandon the processing so we don't run into
79 -- trouble with cascaded errors.
81 -- The following array is the list of attributes defined in the Ada 83 RM
82 -- that are not included in Ada 95, but still get recognized in GNAT.
84 Attribute_83
: constant Attribute_Class_Array
:= Attribute_Class_Array
'(
90 Attribute_Constrained |
103 Attribute_Leading_Part |
105 Attribute_Machine_Emax |
106 Attribute_Machine_Emin |
107 Attribute_Machine_Mantissa |
108 Attribute_Machine_Overflows |
109 Attribute_Machine_Radix |
110 Attribute_Machine_Rounds |
116 Attribute_Safe_Emax |
117 Attribute_Safe_Large |
118 Attribute_Safe_Small |
121 Attribute_Storage_Size |
123 Attribute_Terminated |
126 Attribute_Width => True,
129 -- The following array is the list of attributes defined in the Ada 2005
130 -- RM which are not defined in Ada 95. These are recognized in Ada 95 mode,
131 -- but in Ada 95 they are considered to be implementation defined.
133 Attribute_05 : constant Attribute_Class_Array := Attribute_Class_Array'(
134 Attribute_Machine_Rounding |
136 Attribute_Stream_Size |
137 Attribute_Wide_Wide_Width
=> True,
140 -- The following array contains all attributes that imply a modification
141 -- of their prefixes or result in an access value. Such prefixes can be
142 -- considered as lvalues.
144 Attribute_Name_Implies_Lvalue_Prefix
: constant Attribute_Class_Array
:=
145 Attribute_Class_Array
'(
150 Attribute_Unchecked_Access |
151 Attribute_Unrestricted_Access => True,
154 -----------------------
155 -- Local_Subprograms --
156 -----------------------
158 procedure Eval_Attribute (N : Node_Id);
159 -- Performs compile time evaluation of attributes where possible, leaving
160 -- the Is_Static_Expression/Raises_Constraint_Error flags appropriately
161 -- set, and replacing the node with a literal node if the value can be
162 -- computed at compile time. All static attribute references are folded,
163 -- as well as a number of cases of non-static attributes that can always
164 -- be computed at compile time (e.g. floating-point model attributes that
165 -- are applied to non-static subtypes). Of course in such cases, the
166 -- Is_Static_Expression flag will not be set on the resulting literal.
167 -- Note that the only required action of this procedure is to catch the
168 -- static expression cases as described in the RM. Folding of other cases
169 -- is done where convenient, but some additional non-static folding is in
170 -- N_Expand_Attribute_Reference in cases where this is more convenient.
172 function Is_Anonymous_Tagged_Base
176 -- For derived tagged types that constrain parent discriminants we build
177 -- an anonymous unconstrained base type. We need to recognize the relation
178 -- between the two when analyzing an access attribute for a constrained
179 -- component, before the full declaration for Typ has been analyzed, and
180 -- where therefore the prefix of the attribute does not match the enclosing
183 -----------------------
184 -- Analyze_Attribute --
185 -----------------------
187 procedure Analyze_Attribute (N : Node_Id) is
188 Loc : constant Source_Ptr := Sloc (N);
189 Aname : constant Name_Id := Attribute_Name (N);
190 P : constant Node_Id := Prefix (N);
191 Exprs : constant List_Id := Expressions (N);
192 Attr_Id : constant Attribute_Id := Get_Attribute_Id (Aname);
197 -- Type of prefix after analysis
199 P_Base_Type : Entity_Id;
200 -- Base type of prefix after analysis
202 -----------------------
203 -- Local Subprograms --
204 -----------------------
206 procedure Analyze_Access_Attribute;
207 -- Used for Access, Unchecked_Access, Unrestricted_Access attributes.
208 -- Internally, Id distinguishes which of the three cases is involved.
210 procedure Check_Array_Or_Scalar_Type;
211 -- Common procedure used by First, Last, Range attribute to check
212 -- that the prefix is a constrained array or scalar type, or a name
213 -- of an array object, and that an argument appears only if appropriate
214 -- (i.e. only in the array case).
216 procedure Check_Array_Type;
217 -- Common semantic checks for all array attributes. Checks that the
218 -- prefix is a constrained array type or the name of an array object.
219 -- The error message for non-arrays is specialized appropriately.
221 procedure Check_Asm_Attribute;
222 -- Common semantic checks for Asm_Input and Asm_Output attributes
224 procedure Check_Component;
225 -- Common processing for Bit_Position, First_Bit, Last_Bit, and
226 -- Position. Checks prefix is an appropriate selected component.
228 procedure Check_Decimal_Fixed_Point_Type;
229 -- Check that prefix of attribute N is a decimal fixed-point type
231 procedure Check_Dereference;
232 -- If the prefix of attribute is an object of an access type, then
233 -- introduce an explicit deference, and adjust P_Type accordingly.
235 procedure Check_Discrete_Type;
236 -- Verify that prefix of attribute N is a discrete type
239 -- Check that no attribute arguments are present
241 procedure Check_Either_E0_Or_E1;
242 -- Check that there are zero or one attribute arguments present
245 -- Check that exactly one attribute argument is present
248 -- Check that two attribute arguments are present
250 procedure Check_Enum_Image;
251 -- If the prefix type is an enumeration type, set all its literals
252 -- as referenced, since the image function could possibly end up
253 -- referencing any of the literals indirectly. Same for Enum_Val.
255 procedure Check_Fixed_Point_Type;
256 -- Verify that prefix of attribute N is a fixed type
258 procedure Check_Fixed_Point_Type_0;
259 -- Verify that prefix of attribute N is a fixed type and that
260 -- no attribute expressions are present
262 procedure Check_Floating_Point_Type;
263 -- Verify that prefix of attribute N is a float type
265 procedure Check_Floating_Point_Type_0;
266 -- Verify that prefix of attribute N is a float type and that
267 -- no attribute expressions are present
269 procedure Check_Floating_Point_Type_1;
270 -- Verify that prefix of attribute N is a float type and that
271 -- exactly one attribute expression is present
273 procedure Check_Floating_Point_Type_2;
274 -- Verify that prefix of attribute N is a float type and that
275 -- two attribute expressions are present
277 procedure Legal_Formal_Attribute;
278 -- Common processing for attributes Definite and Has_Discriminants.
279 -- Checks that prefix is generic indefinite formal type.
281 procedure Check_Integer_Type;
282 -- Verify that prefix of attribute N is an integer type
284 procedure Check_Library_Unit;
285 -- Verify that prefix of attribute N is a library unit
287 procedure Check_Modular_Integer_Type;
288 -- Verify that prefix of attribute N is a modular integer type
290 procedure Check_Not_CPP_Type;
291 -- Check that P (the prefix of the attribute) is not an CPP type
292 -- for which no Ada predefined primitive is available.
294 procedure Check_Not_Incomplete_Type;
295 -- Check that P (the prefix of the attribute) is not an incomplete
296 -- type or a private type for which no full view has been given.
298 procedure Check_Object_Reference (P : Node_Id);
299 -- Check that P (the prefix of the attribute) is an object reference
301 procedure Check_Program_Unit;
302 -- Verify that prefix of attribute N is a program unit
304 procedure Check_Real_Type;
305 -- Verify that prefix of attribute N is fixed or float type
307 procedure Check_Scalar_Type;
308 -- Verify that prefix of attribute N is a scalar type
310 procedure Check_Standard_Prefix;
311 -- Verify that prefix of attribute N is package Standard
313 procedure Check_Stream_Attribute (Nam : TSS_Name_Type);
314 -- Validity checking for stream attribute. Nam is the TSS name of the
315 -- corresponding possible defined attribute function (e.g. for the
316 -- Read attribute, Nam will be TSS_Stream_Read).
318 procedure Check_Task_Prefix;
319 -- Verify that prefix of attribute N is a task or task type
321 procedure Check_Type;
322 -- Verify that the prefix of attribute N is a type
324 procedure Check_Unit_Name (Nod : Node_Id);
325 -- Check that Nod is of the form of a library unit name, i.e that
326 -- it is an identifier, or a selected component whose prefix is
327 -- itself of the form of a library unit name. Note that this is
328 -- quite different from Check_Program_Unit, since it only checks
329 -- the syntactic form of the name, not the semantic identity. This
330 -- is because it is used with attributes (Elab_Body, Elab_Spec, and
331 -- UET_Address) which can refer to non-visible unit.
333 procedure Error_Attr (Msg : String; Error_Node : Node_Id);
334 pragma No_Return (Error_Attr);
335 procedure Error_Attr;
336 pragma No_Return (Error_Attr);
337 -- Posts error using Error_Msg_N at given node, sets type of attribute
338 -- node to Any_Type, and then raises Bad_Attribute to avoid any further
339 -- semantic processing. The message typically contains a % insertion
340 -- character which is replaced by the attribute name. The call with
341 -- no arguments is used when the caller has already generated the
342 -- required error messages.
344 procedure Error_Attr_P (Msg : String);
345 pragma No_Return (Error_Attr);
346 -- Like Error_Attr, but error is posted at the start of the prefix
348 procedure Standard_Attribute (Val : Int);
349 -- Used to process attributes whose prefix is package Standard which
350 -- yield values of type Universal_Integer. The attribute reference
351 -- node is rewritten with an integer literal of the given value.
353 procedure Unexpected_Argument (En : Node_Id);
354 -- Signal unexpected attribute argument (En is the argument)
356 procedure Validate_Non_Static_Attribute_Function_Call;
357 -- Called when processing an attribute that is a function call to a
358 -- non-static function, i.e. an attribute function that either takes
359 -- non-scalar arguments or returns a non-scalar result. Verifies that
360 -- such a call does not appear in a preelaborable context.
362 ------------------------------
363 -- Analyze_Access_Attribute --
364 ------------------------------
366 procedure Analyze_Access_Attribute is
367 Acc_Type : Entity_Id;
372 function Build_Access_Object_Type (DT : Entity_Id) return Entity_Id;
373 -- Build an access-to-object type whose designated type is DT,
374 -- and whose Ekind is appropriate to the attribute type. The
375 -- type that is constructed is returned as the result.
377 procedure Build_Access_Subprogram_Type (P : Node_Id);
378 -- Build an access to subprogram whose designated type is the type of
379 -- the prefix. If prefix is overloaded, so is the node itself. The
380 -- result is stored in Acc_Type.
382 function OK_Self_Reference return Boolean;
383 -- An access reference whose prefix is a type can legally appear
384 -- within an aggregate, where it is obtained by expansion of
385 -- a defaulted aggregate. The enclosing aggregate that contains
386 -- the self-referenced is flagged so that the self-reference can
387 -- be expanded into a reference to the target object (see exp_aggr).
389 ------------------------------
390 -- Build_Access_Object_Type --
391 ------------------------------
393 function Build_Access_Object_Type (DT : Entity_Id) return Entity_Id is
394 Typ : constant Entity_Id :=
396 (E_Access_Attribute_Type, Current_Scope, Loc, 'A
');
398 Set_Etype (Typ, Typ);
400 Set_Associated_Node_For_Itype (Typ, N);
401 Set_Directly_Designated_Type (Typ, DT);
403 end Build_Access_Object_Type;
405 ----------------------------------
406 -- Build_Access_Subprogram_Type --
407 ----------------------------------
409 procedure Build_Access_Subprogram_Type (P : Node_Id) is
410 Index : Interp_Index;
413 procedure Check_Local_Access (E : Entity_Id);
414 -- Deal with possible access to local subprogram. If we have such
415 -- an access, we set a flag to kill all tracked values on any call
416 -- because this access value may be passed around, and any called
417 -- code might use it to access a local procedure which clobbers a
420 function Get_Kind (E : Entity_Id) return Entity_Kind;
421 -- Distinguish between access to regular/protected subprograms
423 ------------------------
424 -- Check_Local_Access --
425 ------------------------
427 procedure Check_Local_Access (E : Entity_Id) is
429 if not Is_Library_Level_Entity (E) then
430 Set_Suppress_Value_Tracking_On_Call (Current_Scope);
432 end Check_Local_Access;
438 function Get_Kind (E : Entity_Id) return Entity_Kind is
440 if Convention (E) = Convention_Protected then
441 return E_Access_Protected_Subprogram_Type;
443 return E_Access_Subprogram_Type;
447 -- Start of processing for Build_Access_Subprogram_Type
450 -- In the case of an access to subprogram, use the name of the
451 -- subprogram itself as the designated type. Type-checking in
452 -- this case compares the signatures of the designated types.
454 -- Note: This fragment of the tree is temporarily malformed
455 -- because the correct tree requires an E_Subprogram_Type entity
456 -- as the designated type. In most cases this designated type is
457 -- later overridden by the semantics with the type imposed by the
458 -- context during the resolution phase. In the specific case of
459 -- the expression Address!(Prim'Unrestricted_Access), used to
460 -- initialize slots of dispatch tables, this work will be done by
461 -- the expander (see Exp_Aggr).
463 -- The reason to temporarily add this kind of node to the tree
464 -- instead of a proper E_Subprogram_Type itype, is the following:
465 -- in case of errors found in the source file we report better
466 -- error messages. For example, instead of generating the
469 -- "expected access to subprogram with profile
470 -- defined at line X"
472 -- we currently generate:
474 -- "expected access to function Z defined at line X"
476 Set_Etype (N, Any_Type);
478 if not Is_Overloaded (P) then
479 Check_Local_Access (Entity (P));
481 if not Is_Intrinsic_Subprogram (Entity (P)) then
482 Acc_Type := Create_Itype (Get_Kind (Entity (P)), N);
483 Set_Is_Public (Acc_Type, False);
484 Set_Etype (Acc_Type, Acc_Type);
485 Set_Convention (Acc_Type, Convention (Entity (P)));
486 Set_Directly_Designated_Type (Acc_Type, Entity (P));
487 Set_Etype (N, Acc_Type);
488 Freeze_Before (N, Acc_Type);
492 Get_First_Interp (P, Index, It);
493 while Present (It.Nam) loop
494 Check_Local_Access (It.Nam);
496 if not Is_Intrinsic_Subprogram (It.Nam) then
497 Acc_Type := Create_Itype (Get_Kind (It.Nam), N);
498 Set_Is_Public (Acc_Type, False);
499 Set_Etype (Acc_Type, Acc_Type);
500 Set_Convention (Acc_Type, Convention (It.Nam));
501 Set_Directly_Designated_Type (Acc_Type, It.Nam);
502 Add_One_Interp (N, Acc_Type, Acc_Type);
503 Freeze_Before (N, Acc_Type);
506 Get_Next_Interp (Index, It);
510 -- Cannot be applied to intrinsic. Looking at the tests above,
511 -- the only way Etype (N) can still be set to Any_Type is if
512 -- Is_Intrinsic_Subprogram was True for some referenced entity.
514 if Etype (N) = Any_Type then
515 Error_Attr_P ("prefix of % attribute cannot be intrinsic");
517 end Build_Access_Subprogram_Type;
519 ----------------------
520 -- OK_Self_Reference --
521 ----------------------
523 function OK_Self_Reference return Boolean is
530 (Nkind (Par) = N_Component_Association
531 or else Nkind (Par) in N_Subexpr)
533 if Nkind_In (Par, N_Aggregate, N_Extension_Aggregate) then
534 if Etype (Par) = Typ then
535 Set_Has_Self_Reference (Par);
543 -- No enclosing aggregate, or not a self-reference
546 end OK_Self_Reference;
548 -- Start of processing for Analyze_Access_Attribute
553 if Nkind (P) = N_Character_Literal then
555 ("prefix of % attribute cannot be enumeration literal");
558 -- Case of access to subprogram
560 if Is_Entity_Name (P)
561 and then Is_Overloadable (Entity (P))
563 if Has_Pragma_Inline_Always (Entity (P)) then
565 ("prefix of % attribute cannot be Inline_Always subprogram");
568 if Aname = Name_Unchecked_Access then
569 Error_Attr ("attribute% cannot be applied to a subprogram", P);
572 -- Build the appropriate subprogram type
574 Build_Access_Subprogram_Type (P);
576 -- For unrestricted access, kill current values, since this
577 -- attribute allows a reference to a local subprogram that
578 -- could modify local variables to be passed out of scope
580 if Aname = Name_Unrestricted_Access then
582 -- Do not kill values on nodes initializing dispatch tables
583 -- slots. The construct Prim_Ptr!(Prim'Unrestricted_Access)
584 -- is currently generated by the expander only for this
585 -- purpose. Done to keep the quality of warnings currently
586 -- generated by the compiler (otherwise any declaration of
587 -- a tagged type cleans constant indications from its scope).
589 if Nkind (Parent (N)) = N_Unchecked_Type_Conversion
590 and then (Etype (Parent (N)) = RTE (RE_Prim_Ptr)
592 Etype (Parent (N)) = RTE (RE_Size_Ptr))
593 and then Is_Dispatching_Operation
594 (Directly_Designated_Type (Etype (N)))
604 -- Component is an operation of a protected type
606 elsif Nkind (P) = N_Selected_Component
607 and then Is_Overloadable (Entity (Selector_Name (P)))
609 if Ekind (Entity (Selector_Name (P))) = E_Entry then
610 Error_Attr_P ("prefix of % attribute must be subprogram");
613 Build_Access_Subprogram_Type (Selector_Name (P));
617 -- Deal with incorrect reference to a type, but note that some
618 -- accesses are allowed: references to the current type instance,
619 -- or in Ada 2005 self-referential pointer in a default-initialized
622 if Is_Entity_Name (P) then
625 -- The reference may appear in an aggregate that has been expanded
626 -- into a loop. Locate scope of type definition, if any.
628 Scop := Current_Scope;
629 while Ekind (Scop) = E_Loop loop
630 Scop := Scope (Scop);
633 if Is_Type (Typ) then
635 -- OK if we are within the scope of a limited type
636 -- let's mark the component as having per object constraint
638 if Is_Anonymous_Tagged_Base (Scop, Typ) then
646 Q : Node_Id := Parent (N);
650 and then Nkind (Q) /= N_Component_Declaration
656 Set_Has_Per_Object_Constraint (
657 Defining_Identifier (Q), True);
661 if Nkind (P) = N_Expanded_Name then
663 ("current instance prefix must be a direct name", P);
666 -- If a current instance attribute appears in a component
667 -- constraint it must appear alone; other contexts (spec-
668 -- expressions, within a task body) are not subject to this
671 if not In_Spec_Expression
672 and then not Has_Completion (Scop)
674 Nkind_In (Parent (N), N_Discriminant_Association,
675 N_Index_Or_Discriminant_Constraint)
678 ("current instance attribute must appear alone", N);
681 -- OK if we are in initialization procedure for the type
682 -- in question, in which case the reference to the type
683 -- is rewritten as a reference to the current object.
685 elsif Ekind (Scop) = E_Procedure
686 and then Is_Init_Proc (Scop)
687 and then Etype (First_Formal (Scop)) = Typ
690 Make_Attribute_Reference (Loc,
691 Prefix => Make_Identifier (Loc, Name_uInit),
692 Attribute_Name => Name_Unrestricted_Access));
696 -- OK if a task type, this test needs sharpening up ???
698 elsif Is_Task_Type (Typ) then
701 -- OK if self-reference in an aggregate in Ada 2005, and
702 -- the reference comes from a copied default expression.
704 -- Note that we check legality of self-reference even if the
705 -- expression comes from source, e.g. when a single component
706 -- association in an aggregate has a box association.
708 elsif Ada_Version >= Ada_05
709 and then OK_Self_Reference
713 -- Otherwise we have an error case
716 Error_Attr ("% attribute cannot be applied to type", P);
722 -- If we fall through, we have a normal access to object case.
723 -- Unrestricted_Access is legal wherever an allocator would be
724 -- legal, so its Etype is set to E_Allocator. The expected type
725 -- of the other attributes is a general access type, and therefore
726 -- we label them with E_Access_Attribute_Type.
728 if not Is_Overloaded (P) then
729 Acc_Type := Build_Access_Object_Type (P_Type);
730 Set_Etype (N, Acc_Type);
733 Index : Interp_Index;
736 Set_Etype (N, Any_Type);
737 Get_First_Interp (P, Index, It);
738 while Present (It.Typ) loop
739 Acc_Type := Build_Access_Object_Type (It.Typ);
740 Add_One_Interp (N, Acc_Type, Acc_Type);
741 Get_Next_Interp (Index, It);
746 -- Special cases when we can find a prefix that is an entity name
755 if Is_Entity_Name (PP) then
758 -- If we have an access to an object, and the attribute
759 -- comes from source, then set the object as potentially
760 -- source modified. We do this because the resulting access
761 -- pointer can be used to modify the variable, and we might
762 -- not detect this, leading to some junk warnings.
764 Set_Never_Set_In_Source (Ent, False);
766 -- Mark entity as address taken, and kill current values
768 Set_Address_Taken (Ent);
769 Kill_Current_Values (Ent);
772 elsif Nkind_In (PP, N_Selected_Component,
783 -- Check for aliased view unless unrestricted case. We allow a
784 -- nonaliased prefix when within an instance because the prefix may
785 -- have been a tagged formal object, which is defined to be aliased
786 -- even when the actual might not be (other instance cases will have
787 -- been caught in the generic). Similarly, within an inlined body we
788 -- know that the attribute is legal in the original subprogram, and
789 -- therefore legal in the expansion.
791 if Aname /= Name_Unrestricted_Access
792 and then not Is_Aliased_View (P)
793 and then not In_Instance
794 and then not In_Inlined_Body
796 Error_Attr_P ("prefix of % attribute must be aliased");
798 end Analyze_Access_Attribute;
800 --------------------------------
801 -- Check_Array_Or_Scalar_Type --
802 --------------------------------
804 procedure Check_Array_Or_Scalar_Type is
808 -- Dimension number for array attributes
811 -- Case of string literal or string literal subtype. These cases
812 -- cannot arise from legal Ada code, but the expander is allowed
813 -- to generate them. They require special handling because string
814 -- literal subtypes do not have standard bounds (the whole idea
815 -- of these subtypes is to avoid having to generate the bounds)
817 if Ekind (P_Type) = E_String_Literal_Subtype then
818 Set_Etype (N, Etype (First_Index (P_Base_Type)));
823 elsif Is_Scalar_Type (P_Type) then
827 Error_Attr ("invalid argument in % attribute", E1);
829 Set_Etype (N, P_Base_Type);
833 -- The following is a special test to allow 'First to apply to
834 -- private scalar types if the attribute comes from generated
835 -- code. This occurs in the case of Normalize_Scalars code.
837 elsif Is_Private_Type
(P_Type
)
838 and then Present
(Full_View
(P_Type
))
839 and then Is_Scalar_Type
(Full_View
(P_Type
))
840 and then not Comes_From_Source
(N
)
842 Set_Etype
(N
, Implementation_Base_Type
(P_Type
));
844 -- Array types other than string literal subtypes handled above
849 -- We know prefix is an array type, or the name of an array
850 -- object, and that the expression, if present, is static
851 -- and within the range of the dimensions of the type.
853 pragma Assert
(Is_Array_Type
(P_Type
));
854 Index
:= First_Index
(P_Base_Type
);
858 -- First dimension assumed
860 Set_Etype
(N
, Base_Type
(Etype
(Index
)));
863 D
:= UI_To_Int
(Intval
(E1
));
865 for J
in 1 .. D
- 1 loop
869 Set_Etype
(N
, Base_Type
(Etype
(Index
)));
870 Set_Etype
(E1
, Standard_Integer
);
873 end Check_Array_Or_Scalar_Type
;
875 ----------------------
876 -- Check_Array_Type --
877 ----------------------
879 procedure Check_Array_Type
is
881 -- Dimension number for array attributes
884 -- If the type is a string literal type, then this must be generated
885 -- internally, and no further check is required on its legality.
887 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
890 -- If the type is a composite, it is an illegal aggregate, no point
893 elsif P_Type
= Any_Composite
then
897 -- Normal case of array type or subtype
899 Check_Either_E0_Or_E1
;
902 if Is_Array_Type
(P_Type
) then
903 if not Is_Constrained
(P_Type
)
904 and then Is_Entity_Name
(P
)
905 and then Is_Type
(Entity
(P
))
907 -- Note: we do not call Error_Attr here, since we prefer to
908 -- continue, using the relevant index type of the array,
909 -- even though it is unconstrained. This gives better error
910 -- recovery behavior.
912 Error_Msg_Name_1
:= Aname
;
914 ("prefix for % attribute must be constrained array", P
);
917 D
:= Number_Dimensions
(P_Type
);
920 if Is_Private_Type
(P_Type
) then
921 Error_Attr_P
("prefix for % attribute may not be private type");
923 elsif Is_Access_Type
(P_Type
)
924 and then Is_Array_Type
(Designated_Type
(P_Type
))
925 and then Is_Entity_Name
(P
)
926 and then Is_Type
(Entity
(P
))
928 Error_Attr_P
("prefix of % attribute cannot be access type");
930 elsif Attr_Id
= Attribute_First
932 Attr_Id
= Attribute_Last
934 Error_Attr
("invalid prefix for % attribute", P
);
937 Error_Attr_P
("prefix for % attribute must be array");
942 Resolve
(E1
, Any_Integer
);
943 Set_Etype
(E1
, Standard_Integer
);
945 if not Is_Static_Expression
(E1
)
946 or else Raises_Constraint_Error
(E1
)
949 ("expression for dimension must be static!", E1
);
952 elsif UI_To_Int
(Expr_Value
(E1
)) > D
953 or else UI_To_Int
(Expr_Value
(E1
)) < 1
955 Error_Attr
("invalid dimension number for array type", E1
);
959 if (Style_Check
and Style_Check_Array_Attribute_Index
)
960 and then Comes_From_Source
(N
)
962 Style
.Check_Array_Attribute_Index
(N
, E1
, D
);
964 end Check_Array_Type
;
966 -------------------------
967 -- Check_Asm_Attribute --
968 -------------------------
970 procedure Check_Asm_Attribute
is
975 -- Check first argument is static string expression
977 Analyze_And_Resolve
(E1
, Standard_String
);
979 if Etype
(E1
) = Any_Type
then
982 elsif not Is_OK_Static_Expression
(E1
) then
984 ("constraint argument must be static string expression!", E1
);
988 -- Check second argument is right type
990 Analyze_And_Resolve
(E2
, Entity
(P
));
992 -- Note: that is all we need to do, we don't need to check
993 -- that it appears in a correct context. The Ada type system
994 -- will do that for us.
996 end Check_Asm_Attribute
;
998 ---------------------
999 -- Check_Component --
1000 ---------------------
1002 procedure Check_Component
is
1006 if Nkind
(P
) /= N_Selected_Component
1008 (Ekind
(Entity
(Selector_Name
(P
))) /= E_Component
1010 Ekind
(Entity
(Selector_Name
(P
))) /= E_Discriminant
)
1012 Error_Attr_P
("prefix for % attribute must be selected component");
1014 end Check_Component
;
1016 ------------------------------------
1017 -- Check_Decimal_Fixed_Point_Type --
1018 ------------------------------------
1020 procedure Check_Decimal_Fixed_Point_Type
is
1024 if not Is_Decimal_Fixed_Point_Type
(P_Type
) then
1025 Error_Attr_P
("prefix of % attribute must be decimal type");
1027 end Check_Decimal_Fixed_Point_Type
;
1029 -----------------------
1030 -- Check_Dereference --
1031 -----------------------
1033 procedure Check_Dereference
is
1036 -- Case of a subtype mark
1038 if Is_Entity_Name
(P
)
1039 and then Is_Type
(Entity
(P
))
1044 -- Case of an expression
1048 if Is_Access_Type
(P_Type
) then
1050 -- If there is an implicit dereference, then we must freeze
1051 -- the designated type of the access type, since the type of
1052 -- the referenced array is this type (see AI95-00106).
1054 Freeze_Before
(N
, Designated_Type
(P_Type
));
1057 Make_Explicit_Dereference
(Sloc
(P
),
1058 Prefix
=> Relocate_Node
(P
)));
1060 Analyze_And_Resolve
(P
);
1061 P_Type
:= Etype
(P
);
1063 if P_Type
= Any_Type
then
1064 raise Bad_Attribute
;
1067 P_Base_Type
:= Base_Type
(P_Type
);
1069 end Check_Dereference
;
1071 -------------------------
1072 -- Check_Discrete_Type --
1073 -------------------------
1075 procedure Check_Discrete_Type
is
1079 if not Is_Discrete_Type
(P_Type
) then
1080 Error_Attr_P
("prefix of % attribute must be discrete type");
1082 end Check_Discrete_Type
;
1088 procedure Check_E0
is
1090 if Present
(E1
) then
1091 Unexpected_Argument
(E1
);
1099 procedure Check_E1
is
1101 Check_Either_E0_Or_E1
;
1105 -- Special-case attributes that are functions and that appear as
1106 -- the prefix of another attribute. Error is posted on parent.
1108 if Nkind
(Parent
(N
)) = N_Attribute_Reference
1109 and then (Attribute_Name
(Parent
(N
)) = Name_Address
1111 Attribute_Name
(Parent
(N
)) = Name_Code_Address
1113 Attribute_Name
(Parent
(N
)) = Name_Access
)
1115 Error_Msg_Name_1
:= Attribute_Name
(Parent
(N
));
1116 Error_Msg_N
("illegal prefix for % attribute", Parent
(N
));
1117 Set_Etype
(Parent
(N
), Any_Type
);
1118 Set_Entity
(Parent
(N
), Any_Type
);
1119 raise Bad_Attribute
;
1122 Error_Attr
("missing argument for % attribute", N
);
1131 procedure Check_E2
is
1134 Error_Attr
("missing arguments for % attribute (2 required)", N
);
1136 Error_Attr
("missing argument for % attribute (2 required)", N
);
1140 ---------------------------
1141 -- Check_Either_E0_Or_E1 --
1142 ---------------------------
1144 procedure Check_Either_E0_Or_E1
is
1146 if Present
(E2
) then
1147 Unexpected_Argument
(E2
);
1149 end Check_Either_E0_Or_E1
;
1151 ----------------------
1152 -- Check_Enum_Image --
1153 ----------------------
1155 procedure Check_Enum_Image
is
1158 if Is_Enumeration_Type
(P_Base_Type
) then
1159 Lit
:= First_Literal
(P_Base_Type
);
1160 while Present
(Lit
) loop
1161 Set_Referenced
(Lit
);
1165 end Check_Enum_Image
;
1167 ----------------------------
1168 -- Check_Fixed_Point_Type --
1169 ----------------------------
1171 procedure Check_Fixed_Point_Type
is
1175 if not Is_Fixed_Point_Type
(P_Type
) then
1176 Error_Attr_P
("prefix of % attribute must be fixed point type");
1178 end Check_Fixed_Point_Type
;
1180 ------------------------------
1181 -- Check_Fixed_Point_Type_0 --
1182 ------------------------------
1184 procedure Check_Fixed_Point_Type_0
is
1186 Check_Fixed_Point_Type
;
1188 end Check_Fixed_Point_Type_0
;
1190 -------------------------------
1191 -- Check_Floating_Point_Type --
1192 -------------------------------
1194 procedure Check_Floating_Point_Type
is
1198 if not Is_Floating_Point_Type
(P_Type
) then
1199 Error_Attr_P
("prefix of % attribute must be float type");
1201 end Check_Floating_Point_Type
;
1203 ---------------------------------
1204 -- Check_Floating_Point_Type_0 --
1205 ---------------------------------
1207 procedure Check_Floating_Point_Type_0
is
1209 Check_Floating_Point_Type
;
1211 end Check_Floating_Point_Type_0
;
1213 ---------------------------------
1214 -- Check_Floating_Point_Type_1 --
1215 ---------------------------------
1217 procedure Check_Floating_Point_Type_1
is
1219 Check_Floating_Point_Type
;
1221 end Check_Floating_Point_Type_1
;
1223 ---------------------------------
1224 -- Check_Floating_Point_Type_2 --
1225 ---------------------------------
1227 procedure Check_Floating_Point_Type_2
is
1229 Check_Floating_Point_Type
;
1231 end Check_Floating_Point_Type_2
;
1233 ------------------------
1234 -- Check_Integer_Type --
1235 ------------------------
1237 procedure Check_Integer_Type
is
1241 if not Is_Integer_Type
(P_Type
) then
1242 Error_Attr_P
("prefix of % attribute must be integer type");
1244 end Check_Integer_Type
;
1246 ------------------------
1247 -- Check_Library_Unit --
1248 ------------------------
1250 procedure Check_Library_Unit
is
1252 if not Is_Compilation_Unit
(Entity
(P
)) then
1253 Error_Attr_P
("prefix of % attribute must be library unit");
1255 end Check_Library_Unit
;
1257 --------------------------------
1258 -- Check_Modular_Integer_Type --
1259 --------------------------------
1261 procedure Check_Modular_Integer_Type
is
1265 if not Is_Modular_Integer_Type
(P_Type
) then
1267 ("prefix of % attribute must be modular integer type");
1269 end Check_Modular_Integer_Type
;
1271 ------------------------
1272 -- Check_Not_CPP_Type --
1273 ------------------------
1275 procedure Check_Not_CPP_Type
is
1277 if Is_Tagged_Type
(Etype
(P
))
1278 and then Convention
(Etype
(P
)) = Convention_CPP
1279 and then Is_CPP_Class
(Root_Type
(Etype
(P
)))
1282 ("invalid use of % attribute with 'C'P'P tagged type");
1284 end Check_Not_CPP_Type
;
1286 -------------------------------
1287 -- Check_Not_Incomplete_Type --
1288 -------------------------------
1290 procedure Check_Not_Incomplete_Type
is
1295 -- Ada 2005 (AI-50217, AI-326): If the prefix is an explicit
1296 -- dereference we have to check wrong uses of incomplete types
1297 -- (other wrong uses are checked at their freezing point).
1299 -- Example 1: Limited-with
1301 -- limited with Pkg;
1303 -- type Acc is access Pkg.T;
1305 -- S : Integer := X.all'Size; -- ERROR
1308 -- Example 2: Tagged incomplete
1310 -- type T is tagged;
1311 -- type Acc is access all T;
1313 -- S : constant Integer := X.all'Size; -- ERROR
1314 -- procedure Q (Obj : Integer := X.all'Alignment); -- ERROR
1316 if Ada_Version
>= Ada_05
1317 and then Nkind
(P
) = N_Explicit_Dereference
1320 while Nkind
(E
) = N_Explicit_Dereference
loop
1324 if From_With_Type
(Etype
(E
)) then
1326 ("prefix of % attribute cannot be an incomplete type");
1329 if Is_Access_Type
(Etype
(E
)) then
1330 Typ
:= Directly_Designated_Type
(Etype
(E
));
1335 if Ekind
(Typ
) = E_Incomplete_Type
1336 and then No
(Full_View
(Typ
))
1339 ("prefix of % attribute cannot be an incomplete type");
1344 if not Is_Entity_Name
(P
)
1345 or else not Is_Type
(Entity
(P
))
1346 or else In_Spec_Expression
1350 Check_Fully_Declared
(P_Type
, P
);
1352 end Check_Not_Incomplete_Type
;
1354 ----------------------------
1355 -- Check_Object_Reference --
1356 ----------------------------
1358 procedure Check_Object_Reference
(P
: Node_Id
) is
1362 -- If we need an object, and we have a prefix that is the name of
1363 -- a function entity, convert it into a function call.
1365 if Is_Entity_Name
(P
)
1366 and then Ekind
(Entity
(P
)) = E_Function
1368 Rtyp
:= Etype
(Entity
(P
));
1371 Make_Function_Call
(Sloc
(P
),
1372 Name
=> Relocate_Node
(P
)));
1374 Analyze_And_Resolve
(P
, Rtyp
);
1376 -- Otherwise we must have an object reference
1378 elsif not Is_Object_Reference
(P
) then
1379 Error_Attr_P
("prefix of % attribute must be object");
1381 end Check_Object_Reference
;
1383 ------------------------
1384 -- Check_Program_Unit --
1385 ------------------------
1387 procedure Check_Program_Unit
is
1389 if Is_Entity_Name
(P
) then
1391 K
: constant Entity_Kind
:= Ekind
(Entity
(P
));
1392 T
: constant Entity_Id
:= Etype
(Entity
(P
));
1395 if K
in Subprogram_Kind
1396 or else K
in Task_Kind
1397 or else K
in Protected_Kind
1398 or else K
= E_Package
1399 or else K
in Generic_Unit_Kind
1400 or else (K
= E_Variable
1404 Is_Protected_Type
(T
)))
1411 Error_Attr_P
("prefix of % attribute must be program unit");
1412 end Check_Program_Unit
;
1414 ---------------------
1415 -- Check_Real_Type --
1416 ---------------------
1418 procedure Check_Real_Type
is
1422 if not Is_Real_Type
(P_Type
) then
1423 Error_Attr_P
("prefix of % attribute must be real type");
1425 end Check_Real_Type
;
1427 -----------------------
1428 -- Check_Scalar_Type --
1429 -----------------------
1431 procedure Check_Scalar_Type
is
1435 if not Is_Scalar_Type
(P_Type
) then
1436 Error_Attr_P
("prefix of % attribute must be scalar type");
1438 end Check_Scalar_Type
;
1440 ---------------------------
1441 -- Check_Standard_Prefix --
1442 ---------------------------
1444 procedure Check_Standard_Prefix
is
1448 if Nkind
(P
) /= N_Identifier
1449 or else Chars
(P
) /= Name_Standard
1451 Error_Attr
("only allowed prefix for % attribute is Standard", P
);
1453 end Check_Standard_Prefix
;
1455 ----------------------------
1456 -- Check_Stream_Attribute --
1457 ----------------------------
1459 procedure Check_Stream_Attribute
(Nam
: TSS_Name_Type
) is
1463 In_Shared_Var_Procs
: Boolean;
1464 -- True when compiling the body of System.Shared_Storage.
1465 -- Shared_Var_Procs. For this runtime package (always compiled in
1466 -- GNAT mode), we allow stream attributes references for limited
1467 -- types for the case where shared passive objects are implemented
1468 -- using stream attributes, which is the default in GNAT's persistent
1469 -- storage implementation.
1472 Validate_Non_Static_Attribute_Function_Call
;
1474 -- With the exception of 'Input, Stream attributes are procedures,
1475 -- and can only appear at the position of procedure calls. We check
1476 -- for this here, before they are rewritten, to give a more precise
1479 if Nam
= TSS_Stream_Input
then
1482 elsif Is_List_Member
(N
)
1483 and then not Nkind_In
(Parent
(N
), N_Procedure_Call_Statement
,
1490 ("invalid context for attribute%, which is a procedure", N
);
1494 Btyp
:= Implementation_Base_Type
(P_Type
);
1496 -- Stream attributes not allowed on limited types unless the
1497 -- attribute reference was generated by the expander (in which
1498 -- case the underlying type will be used, as described in Sinfo),
1499 -- or the attribute was specified explicitly for the type itself
1500 -- or one of its ancestors (taking visibility rules into account if
1501 -- in Ada 2005 mode), or a pragma Stream_Convert applies to Btyp
1502 -- (with no visibility restriction).
1505 Gen_Body
: constant Node_Id
:= Enclosing_Generic_Body
(N
);
1507 if Present
(Gen_Body
) then
1508 In_Shared_Var_Procs
:=
1509 Is_RTE
(Corresponding_Spec
(Gen_Body
), RE_Shared_Var_Procs
);
1511 In_Shared_Var_Procs
:= False;
1515 if (Comes_From_Source
(N
)
1516 and then not (In_Shared_Var_Procs
or In_Instance
))
1517 and then not Stream_Attribute_Available
(P_Type
, Nam
)
1518 and then not Has_Rep_Pragma
(Btyp
, Name_Stream_Convert
)
1520 Error_Msg_Name_1
:= Aname
;
1522 if Is_Limited_Type
(P_Type
) then
1524 ("limited type& has no% attribute", P
, P_Type
);
1525 Explain_Limited_Type
(P_Type
, P
);
1528 ("attribute% for type& is not available", P
, P_Type
);
1532 -- Check for violation of restriction No_Stream_Attributes
1534 if Is_RTE
(P_Type
, RE_Exception_Id
)
1536 Is_RTE
(P_Type
, RE_Exception_Occurrence
)
1538 Check_Restriction
(No_Exception_Registration
, P
);
1541 -- Here we must check that the first argument is an access type
1542 -- that is compatible with Ada.Streams.Root_Stream_Type'Class.
1544 Analyze_And_Resolve
(E1
);
1547 -- Note: the double call to Root_Type here is needed because the
1548 -- root type of a class-wide type is the corresponding type (e.g.
1549 -- X for X'Class, and we really want to go to the root.)
1551 if not Is_Access_Type
(Etyp
)
1552 or else Root_Type
(Root_Type
(Designated_Type
(Etyp
))) /=
1553 RTE
(RE_Root_Stream_Type
)
1556 ("expected access to Ada.Streams.Root_Stream_Type''Class", E1
);
1559 -- Check that the second argument is of the right type if there is
1560 -- one (the Input attribute has only one argument so this is skipped)
1562 if Present
(E2
) then
1565 if Nam
= TSS_Stream_Read
1566 and then not Is_OK_Variable_For_Out_Formal
(E2
)
1569 ("second argument of % attribute must be a variable", E2
);
1572 Resolve
(E2
, P_Type
);
1576 end Check_Stream_Attribute
;
1578 -----------------------
1579 -- Check_Task_Prefix --
1580 -----------------------
1582 procedure Check_Task_Prefix
is
1586 -- Ada 2005 (AI-345): Attribute 'Terminated can be applied to
1587 -- task interface class-wide types.
1589 if Is_Task_Type
(Etype
(P
))
1590 or else (Is_Access_Type
(Etype
(P
))
1591 and then Is_Task_Type
(Designated_Type
(Etype
(P
))))
1592 or else (Ada_Version
>= Ada_05
1593 and then Ekind
(Etype
(P
)) = E_Class_Wide_Type
1594 and then Is_Interface
(Etype
(P
))
1595 and then Is_Task_Interface
(Etype
(P
)))
1600 if Ada_Version
>= Ada_05
then
1602 ("prefix of % attribute must be a task or a task " &
1603 "interface class-wide object");
1606 Error_Attr_P
("prefix of % attribute must be a task");
1609 end Check_Task_Prefix
;
1615 -- The possibilities are an entity name denoting a type, or an
1616 -- attribute reference that denotes a type (Base or Class). If
1617 -- the type is incomplete, replace it with its full view.
1619 procedure Check_Type
is
1621 if not Is_Entity_Name
(P
)
1622 or else not Is_Type
(Entity
(P
))
1624 Error_Attr_P
("prefix of % attribute must be a type");
1626 elsif Ekind
(Entity
(P
)) = E_Incomplete_Type
1627 and then Present
(Full_View
(Entity
(P
)))
1629 P_Type
:= Full_View
(Entity
(P
));
1630 Set_Entity
(P
, P_Type
);
1634 ---------------------
1635 -- Check_Unit_Name --
1636 ---------------------
1638 procedure Check_Unit_Name
(Nod
: Node_Id
) is
1640 if Nkind
(Nod
) = N_Identifier
then
1643 elsif Nkind
(Nod
) = N_Selected_Component
then
1644 Check_Unit_Name
(Prefix
(Nod
));
1646 if Nkind
(Selector_Name
(Nod
)) = N_Identifier
then
1651 Error_Attr
("argument for % attribute must be unit name", P
);
1652 end Check_Unit_Name
;
1658 procedure Error_Attr
is
1660 Set_Etype
(N
, Any_Type
);
1661 Set_Entity
(N
, Any_Type
);
1662 raise Bad_Attribute
;
1665 procedure Error_Attr
(Msg
: String; Error_Node
: Node_Id
) is
1667 Error_Msg_Name_1
:= Aname
;
1668 Error_Msg_N
(Msg
, Error_Node
);
1676 procedure Error_Attr_P
(Msg
: String) is
1678 Error_Msg_Name_1
:= Aname
;
1679 Error_Msg_F
(Msg
, P
);
1683 ----------------------------
1684 -- Legal_Formal_Attribute --
1685 ----------------------------
1687 procedure Legal_Formal_Attribute
is
1691 if not Is_Entity_Name
(P
)
1692 or else not Is_Type
(Entity
(P
))
1694 Error_Attr_P
("prefix of % attribute must be generic type");
1696 elsif Is_Generic_Actual_Type
(Entity
(P
))
1698 or else In_Inlined_Body
1702 elsif Is_Generic_Type
(Entity
(P
)) then
1703 if not Is_Indefinite_Subtype
(Entity
(P
)) then
1705 ("prefix of % attribute must be indefinite generic type");
1710 ("prefix of % attribute must be indefinite generic type");
1713 Set_Etype
(N
, Standard_Boolean
);
1714 end Legal_Formal_Attribute
;
1716 ------------------------
1717 -- Standard_Attribute --
1718 ------------------------
1720 procedure Standard_Attribute
(Val
: Int
) is
1722 Check_Standard_Prefix
;
1723 Rewrite
(N
, Make_Integer_Literal
(Loc
, Val
));
1725 end Standard_Attribute
;
1727 -------------------------
1728 -- Unexpected Argument --
1729 -------------------------
1731 procedure Unexpected_Argument
(En
: Node_Id
) is
1733 Error_Attr
("unexpected argument for % attribute", En
);
1734 end Unexpected_Argument
;
1736 -------------------------------------------------
1737 -- Validate_Non_Static_Attribute_Function_Call --
1738 -------------------------------------------------
1740 -- This function should be moved to Sem_Dist ???
1742 procedure Validate_Non_Static_Attribute_Function_Call
is
1744 if In_Preelaborated_Unit
1745 and then not In_Subprogram_Or_Concurrent_Unit
1747 Flag_Non_Static_Expr
1748 ("non-static function call in preelaborated unit!", N
);
1750 end Validate_Non_Static_Attribute_Function_Call
;
1752 -----------------------------------------------
1753 -- Start of Processing for Analyze_Attribute --
1754 -----------------------------------------------
1757 -- Immediate return if unrecognized attribute (already diagnosed
1758 -- by parser, so there is nothing more that we need to do)
1760 if not Is_Attribute_Name
(Aname
) then
1761 raise Bad_Attribute
;
1764 -- Deal with Ada 83 issues
1766 if Comes_From_Source
(N
) then
1767 if not Attribute_83
(Attr_Id
) then
1768 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
1769 Error_Msg_Name_1
:= Aname
;
1770 Error_Msg_N
("(Ada 83) attribute% is not standard?", N
);
1773 if Attribute_Impl_Def
(Attr_Id
) then
1774 Check_Restriction
(No_Implementation_Attributes
, N
);
1779 -- Deal with Ada 2005 issues
1781 if Attribute_05
(Attr_Id
) and then Ada_Version
<= Ada_95
then
1782 Check_Restriction
(No_Implementation_Attributes
, N
);
1785 -- Remote access to subprogram type access attribute reference needs
1786 -- unanalyzed copy for tree transformation. The analyzed copy is used
1787 -- for its semantic information (whether prefix is a remote subprogram
1788 -- name), the unanalyzed copy is used to construct new subtree rooted
1789 -- with N_Aggregate which represents a fat pointer aggregate.
1791 if Aname
= Name_Access
then
1792 Discard_Node
(Copy_Separate_Tree
(N
));
1795 -- Analyze prefix and exit if error in analysis. If the prefix is an
1796 -- incomplete type, use full view if available. Note that there are
1797 -- some attributes for which we do not analyze the prefix, since the
1798 -- prefix is not a normal name.
1800 if Aname
/= Name_Elab_Body
1802 Aname
/= Name_Elab_Spec
1804 Aname
/= Name_UET_Address
1806 Aname
/= Name_Enabled
1809 P_Type
:= Etype
(P
);
1811 if Is_Entity_Name
(P
)
1812 and then Present
(Entity
(P
))
1813 and then Is_Type
(Entity
(P
))
1815 if Ekind
(Entity
(P
)) = E_Incomplete_Type
then
1816 P_Type
:= Get_Full_View
(P_Type
);
1817 Set_Entity
(P
, P_Type
);
1818 Set_Etype
(P
, P_Type
);
1820 elsif Entity
(P
) = Current_Scope
1821 and then Is_Record_Type
(Entity
(P
))
1823 -- Use of current instance within the type. Verify that if the
1824 -- attribute appears within a constraint, it yields an access
1825 -- type, other uses are illegal.
1833 and then Nkind
(Parent
(Par
)) /= N_Component_Definition
1835 Par
:= Parent
(Par
);
1839 and then Nkind
(Par
) = N_Subtype_Indication
1841 if Attr_Id
/= Attribute_Access
1842 and then Attr_Id
/= Attribute_Unchecked_Access
1843 and then Attr_Id
/= Attribute_Unrestricted_Access
1846 ("in a constraint the current instance can only"
1847 & " be used with an access attribute", N
);
1854 if P_Type
= Any_Type
then
1855 raise Bad_Attribute
;
1858 P_Base_Type
:= Base_Type
(P_Type
);
1861 -- Analyze expressions that may be present, exiting if an error occurs
1868 E1
:= First
(Exprs
);
1871 -- Check for missing/bad expression (result of previous error)
1873 if No
(E1
) or else Etype
(E1
) = Any_Type
then
1874 raise Bad_Attribute
;
1879 if Present
(E2
) then
1882 if Etype
(E2
) = Any_Type
then
1883 raise Bad_Attribute
;
1886 if Present
(Next
(E2
)) then
1887 Unexpected_Argument
(Next
(E2
));
1892 -- Ada 2005 (AI-345): Ensure that the compiler gives exactly the current
1893 -- output compiling in Ada 95 mode for the case of ambiguous prefixes.
1895 if Ada_Version
< Ada_05
1896 and then Is_Overloaded
(P
)
1897 and then Aname
/= Name_Access
1898 and then Aname
/= Name_Address
1899 and then Aname
/= Name_Code_Address
1900 and then Aname
/= Name_Count
1901 and then Aname
/= Name_Unchecked_Access
1903 Error_Attr
("ambiguous prefix for % attribute", P
);
1905 elsif Ada_Version
>= Ada_05
1906 and then Is_Overloaded
(P
)
1907 and then Aname
/= Name_Access
1908 and then Aname
/= Name_Address
1909 and then Aname
/= Name_Code_Address
1910 and then Aname
/= Name_Result
1911 and then Aname
/= Name_Unchecked_Access
1913 -- Ada 2005 (AI-345): Since protected and task types have primitive
1914 -- entry wrappers, the attributes Count, Caller and AST_Entry require
1917 if Aname
= Name_Count
1918 or else Aname
= Name_Caller
1919 or else Aname
= Name_AST_Entry
1922 Count
: Natural := 0;
1927 Get_First_Interp
(P
, I
, It
);
1928 while Present
(It
.Nam
) loop
1929 if Comes_From_Source
(It
.Nam
) then
1935 Get_Next_Interp
(I
, It
);
1939 Error_Attr
("ambiguous prefix for % attribute", P
);
1941 Set_Is_Overloaded
(P
, False);
1946 Error_Attr
("ambiguous prefix for % attribute", P
);
1950 -- Remaining processing depends on attribute
1958 when Attribute_Abort_Signal
=>
1959 Check_Standard_Prefix
;
1961 New_Reference_To
(Stand
.Abort_Signal
, Loc
));
1968 when Attribute_Access
=>
1969 Analyze_Access_Attribute
;
1975 when Attribute_Address
=>
1978 -- Check for some junk cases, where we have to allow the address
1979 -- attribute but it does not make much sense, so at least for now
1980 -- just replace with Null_Address.
1982 -- We also do this if the prefix is a reference to the AST_Entry
1983 -- attribute. If expansion is active, the attribute will be
1984 -- replaced by a function call, and address will work fine and
1985 -- get the proper value, but if expansion is not active, then
1986 -- the check here allows proper semantic analysis of the reference.
1988 -- An Address attribute created by expansion is legal even when it
1989 -- applies to other entity-denoting expressions.
1991 if Is_Entity_Name
(P
) then
1993 Ent
: constant Entity_Id
:= Entity
(P
);
1996 if Is_Subprogram
(Ent
) then
1997 Set_Address_Taken
(Ent
);
1998 Kill_Current_Values
(Ent
);
2000 -- An Address attribute is accepted when generated by the
2001 -- compiler for dispatching operation, and an error is
2002 -- issued once the subprogram is frozen (to avoid confusing
2003 -- errors about implicit uses of Address in the dispatch
2004 -- table initialization).
2006 if Has_Pragma_Inline_Always
(Entity
(P
))
2007 and then Comes_From_Source
(P
)
2010 ("prefix of % attribute cannot be Inline_Always" &
2014 elsif Is_Object
(Ent
)
2015 or else Ekind
(Ent
) = E_Label
2017 Set_Address_Taken
(Ent
);
2019 -- If we have an address of an object, and the attribute
2020 -- comes from source, then set the object as potentially
2021 -- source modified. We do this because the resulting address
2022 -- can potentially be used to modify the variable and we
2023 -- might not detect this, leading to some junk warnings.
2025 Set_Never_Set_In_Source
(Ent
, False);
2027 elsif (Is_Concurrent_Type
(Etype
(Ent
))
2028 and then Etype
(Ent
) = Base_Type
(Ent
))
2029 or else Ekind
(Ent
) = E_Package
2030 or else Is_Generic_Unit
(Ent
)
2033 New_Occurrence_Of
(RTE
(RE_Null_Address
), Sloc
(N
)));
2036 Error_Attr
("invalid prefix for % attribute", P
);
2040 elsif Nkind
(P
) = N_Attribute_Reference
2041 and then Attribute_Name
(P
) = Name_AST_Entry
2044 New_Occurrence_Of
(RTE
(RE_Null_Address
), Sloc
(N
)));
2046 elsif Is_Object_Reference
(P
) then
2049 elsif Nkind
(P
) = N_Selected_Component
2050 and then Is_Subprogram
(Entity
(Selector_Name
(P
)))
2054 -- What exactly are we allowing here ??? and is this properly
2055 -- documented in the sinfo documentation for this node ???
2057 elsif not Comes_From_Source
(N
) then
2061 Error_Attr
("invalid prefix for % attribute", P
);
2064 Set_Etype
(N
, RTE
(RE_Address
));
2070 when Attribute_Address_Size
=>
2071 Standard_Attribute
(System_Address_Size
);
2077 when Attribute_Adjacent
=>
2078 Check_Floating_Point_Type_2
;
2079 Set_Etype
(N
, P_Base_Type
);
2080 Resolve
(E1
, P_Base_Type
);
2081 Resolve
(E2
, P_Base_Type
);
2087 when Attribute_Aft
=>
2088 Check_Fixed_Point_Type_0
;
2089 Set_Etype
(N
, Universal_Integer
);
2095 when Attribute_Alignment
=>
2097 -- Don't we need more checking here, cf Size ???
2100 Check_Not_Incomplete_Type
;
2102 Set_Etype
(N
, Universal_Integer
);
2108 when Attribute_Asm_Input
=>
2109 Check_Asm_Attribute
;
2110 Set_Etype
(N
, RTE
(RE_Asm_Input_Operand
));
2116 when Attribute_Asm_Output
=>
2117 Check_Asm_Attribute
;
2119 if Etype
(E2
) = Any_Type
then
2122 elsif Aname
= Name_Asm_Output
then
2123 if not Is_Variable
(E2
) then
2125 ("second argument for Asm_Output is not variable", E2
);
2129 Note_Possible_Modification
(E2
, Sure
=> True);
2130 Set_Etype
(N
, RTE
(RE_Asm_Output_Operand
));
2136 when Attribute_AST_Entry
=> AST_Entry
: declare
2142 -- Indicates if entry family index is present. Note the coding
2143 -- here handles the entry family case, but in fact it cannot be
2144 -- executed currently, because pragma AST_Entry does not permit
2145 -- the specification of an entry family.
2147 procedure Bad_AST_Entry
;
2148 -- Signal a bad AST_Entry pragma
2150 function OK_Entry
(E
: Entity_Id
) return Boolean;
2151 -- Checks that E is of an appropriate entity kind for an entry
2152 -- (i.e. E_Entry if Index is False, or E_Entry_Family if Index
2153 -- is set True for the entry family case). In the True case,
2154 -- makes sure that Is_AST_Entry is set on the entry.
2160 procedure Bad_AST_Entry
is
2162 Error_Attr_P
("prefix for % attribute must be task entry");
2169 function OK_Entry
(E
: Entity_Id
) return Boolean is
2174 Result
:= (Ekind
(E
) = E_Entry_Family
);
2176 Result
:= (Ekind
(E
) = E_Entry
);
2180 if not Is_AST_Entry
(E
) then
2181 Error_Msg_Name_2
:= Aname
;
2182 Error_Attr
("% attribute requires previous % pragma", P
);
2189 -- Start of processing for AST_Entry
2195 -- Deal with entry family case
2197 if Nkind
(P
) = N_Indexed_Component
then
2205 Ptyp
:= Etype
(Pref
);
2207 if Ptyp
= Any_Type
or else Error_Posted
(Pref
) then
2211 -- If the prefix is a selected component whose prefix is of an
2212 -- access type, then introduce an explicit dereference.
2213 -- ??? Could we reuse Check_Dereference here?
2215 if Nkind
(Pref
) = N_Selected_Component
2216 and then Is_Access_Type
(Ptyp
)
2219 Make_Explicit_Dereference
(Sloc
(Pref
),
2220 Relocate_Node
(Pref
)));
2221 Analyze_And_Resolve
(Pref
, Designated_Type
(Ptyp
));
2224 -- Prefix can be of the form a.b, where a is a task object
2225 -- and b is one of the entries of the corresponding task type.
2227 if Nkind
(Pref
) = N_Selected_Component
2228 and then OK_Entry
(Entity
(Selector_Name
(Pref
)))
2229 and then Is_Object_Reference
(Prefix
(Pref
))
2230 and then Is_Task_Type
(Etype
(Prefix
(Pref
)))
2234 -- Otherwise the prefix must be an entry of a containing task,
2235 -- or of a variable of the enclosing task type.
2238 if Nkind_In
(Pref
, N_Identifier
, N_Expanded_Name
) then
2239 Ent
:= Entity
(Pref
);
2241 if not OK_Entry
(Ent
)
2242 or else not In_Open_Scopes
(Scope
(Ent
))
2252 Set_Etype
(N
, RTE
(RE_AST_Handler
));
2259 -- Note: when the base attribute appears in the context of a subtype
2260 -- mark, the analysis is done by Sem_Ch8.Find_Type, rather than by
2261 -- the following circuit.
2263 when Attribute_Base
=> Base
: declare
2271 if Ada_Version
>= Ada_95
2272 and then not Is_Scalar_Type
(Typ
)
2273 and then not Is_Generic_Type
(Typ
)
2275 Error_Attr_P
("prefix of Base attribute must be scalar type");
2277 elsif Sloc
(Typ
) = Standard_Location
2278 and then Base_Type
(Typ
) = Typ
2279 and then Warn_On_Redundant_Constructs
2282 ("?redundant attribute, & is its own base type", N
, Typ
);
2285 Set_Etype
(N
, Base_Type
(Entity
(P
)));
2286 Set_Entity
(N
, Base_Type
(Entity
(P
)));
2287 Rewrite
(N
, New_Reference_To
(Entity
(N
), Loc
));
2295 when Attribute_Bit
=> Bit
:
2299 if not Is_Object_Reference
(P
) then
2300 Error_Attr_P
("prefix for % attribute must be object");
2302 -- What about the access object cases ???
2308 Set_Etype
(N
, Universal_Integer
);
2315 when Attribute_Bit_Order
=> Bit_Order
:
2320 if not Is_Record_Type
(P_Type
) then
2321 Error_Attr_P
("prefix of % attribute must be record type");
2324 if Bytes_Big_Endian
xor Reverse_Bit_Order
(P_Type
) then
2326 New_Occurrence_Of
(RTE
(RE_High_Order_First
), Loc
));
2329 New_Occurrence_Of
(RTE
(RE_Low_Order_First
), Loc
));
2332 Set_Etype
(N
, RTE
(RE_Bit_Order
));
2335 -- Reset incorrect indication of staticness
2337 Set_Is_Static_Expression
(N
, False);
2344 -- Note: in generated code, we can have a Bit_Position attribute
2345 -- applied to a (naked) record component (i.e. the prefix is an
2346 -- identifier that references an E_Component or E_Discriminant
2347 -- entity directly, and this is interpreted as expected by Gigi.
2348 -- The following code will not tolerate such usage, but when the
2349 -- expander creates this special case, it marks it as analyzed
2350 -- immediately and sets an appropriate type.
2352 when Attribute_Bit_Position
=>
2353 if Comes_From_Source
(N
) then
2357 Set_Etype
(N
, Universal_Integer
);
2363 when Attribute_Body_Version
=>
2366 Set_Etype
(N
, RTE
(RE_Version_String
));
2372 when Attribute_Callable
=>
2374 Set_Etype
(N
, Standard_Boolean
);
2381 when Attribute_Caller
=> Caller
: declare
2388 if Nkind_In
(P
, N_Identifier
, N_Expanded_Name
) then
2391 if not Is_Entry
(Ent
) then
2392 Error_Attr
("invalid entry name", N
);
2396 Error_Attr
("invalid entry name", N
);
2400 for J
in reverse 0 .. Scope_Stack
.Last
loop
2401 S
:= Scope_Stack
.Table
(J
).Entity
;
2403 if S
= Scope
(Ent
) then
2404 Error_Attr
("Caller must appear in matching accept or body", N
);
2410 Set_Etype
(N
, RTE
(RO_AT_Task_Id
));
2417 when Attribute_Ceiling
=>
2418 Check_Floating_Point_Type_1
;
2419 Set_Etype
(N
, P_Base_Type
);
2420 Resolve
(E1
, P_Base_Type
);
2426 when Attribute_Class
=>
2427 Check_Restriction
(No_Dispatch
, N
);
2435 when Attribute_Code_Address
=>
2438 if Nkind
(P
) = N_Attribute_Reference
2439 and then (Attribute_Name
(P
) = Name_Elab_Body
2441 Attribute_Name
(P
) = Name_Elab_Spec
)
2445 elsif not Is_Entity_Name
(P
)
2446 or else (Ekind
(Entity
(P
)) /= E_Function
2448 Ekind
(Entity
(P
)) /= E_Procedure
)
2450 Error_Attr
("invalid prefix for % attribute", P
);
2451 Set_Address_Taken
(Entity
(P
));
2454 Set_Etype
(N
, RTE
(RE_Address
));
2456 --------------------
2457 -- Component_Size --
2458 --------------------
2460 when Attribute_Component_Size
=>
2462 Set_Etype
(N
, Universal_Integer
);
2464 -- Note: unlike other array attributes, unconstrained arrays are OK
2466 if Is_Array_Type
(P_Type
) and then not Is_Constrained
(P_Type
) then
2476 when Attribute_Compose
=>
2477 Check_Floating_Point_Type_2
;
2478 Set_Etype
(N
, P_Base_Type
);
2479 Resolve
(E1
, P_Base_Type
);
2480 Resolve
(E2
, Any_Integer
);
2486 when Attribute_Constrained
=>
2488 Set_Etype
(N
, Standard_Boolean
);
2490 -- Case from RM J.4(2) of constrained applied to private type
2492 if Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)) then
2493 Check_Restriction
(No_Obsolescent_Features
, N
);
2495 if Warn_On_Obsolescent_Feature
then
2497 ("constrained for private type is an " &
2498 "obsolescent feature (RM J.4)?", N
);
2501 -- If we are within an instance, the attribute must be legal
2502 -- because it was valid in the generic unit. Ditto if this is
2503 -- an inlining of a function declared in an instance.
2506 or else In_Inlined_Body
2510 -- For sure OK if we have a real private type itself, but must
2511 -- be completed, cannot apply Constrained to incomplete type.
2513 elsif Is_Private_Type
(Entity
(P
)) then
2515 -- Note: this is one of the Annex J features that does not
2516 -- generate a warning from -gnatwj, since in fact it seems
2517 -- very useful, and is used in the GNAT runtime.
2519 Check_Not_Incomplete_Type
;
2523 -- Normal (non-obsolescent case) of application to object of
2524 -- a discriminated type.
2527 Check_Object_Reference
(P
);
2529 -- If N does not come from source, then we allow the
2530 -- the attribute prefix to be of a private type whose
2531 -- full type has discriminants. This occurs in cases
2532 -- involving expanded calls to stream attributes.
2534 if not Comes_From_Source
(N
) then
2535 P_Type
:= Underlying_Type
(P_Type
);
2538 -- Must have discriminants or be an access type designating
2539 -- a type with discriminants. If it is a classwide type is ???
2540 -- has unknown discriminants.
2542 if Has_Discriminants
(P_Type
)
2543 or else Has_Unknown_Discriminants
(P_Type
)
2545 (Is_Access_Type
(P_Type
)
2546 and then Has_Discriminants
(Designated_Type
(P_Type
)))
2550 -- Also allow an object of a generic type if extensions allowed
2551 -- and allow this for any type at all.
2553 elsif (Is_Generic_Type
(P_Type
)
2554 or else Is_Generic_Actual_Type
(P_Type
))
2555 and then Extensions_Allowed
2561 -- Fall through if bad prefix
2564 ("prefix of % attribute must be object of discriminated type");
2570 when Attribute_Copy_Sign
=>
2571 Check_Floating_Point_Type_2
;
2572 Set_Etype
(N
, P_Base_Type
);
2573 Resolve
(E1
, P_Base_Type
);
2574 Resolve
(E2
, P_Base_Type
);
2580 when Attribute_Count
=> Count
:
2589 if Nkind_In
(P
, N_Identifier
, N_Expanded_Name
) then
2592 if Ekind
(Ent
) /= E_Entry
then
2593 Error_Attr
("invalid entry name", N
);
2596 elsif Nkind
(P
) = N_Indexed_Component
then
2597 if not Is_Entity_Name
(Prefix
(P
))
2598 or else No
(Entity
(Prefix
(P
)))
2599 or else Ekind
(Entity
(Prefix
(P
))) /= E_Entry_Family
2601 if Nkind
(Prefix
(P
)) = N_Selected_Component
2602 and then Present
(Entity
(Selector_Name
(Prefix
(P
))))
2603 and then Ekind
(Entity
(Selector_Name
(Prefix
(P
)))) =
2607 ("attribute % must apply to entry of current task", P
);
2610 Error_Attr
("invalid entry family name", P
);
2615 Ent
:= Entity
(Prefix
(P
));
2618 elsif Nkind
(P
) = N_Selected_Component
2619 and then Present
(Entity
(Selector_Name
(P
)))
2620 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Entry
2623 ("attribute % must apply to entry of current task", P
);
2626 Error_Attr
("invalid entry name", N
);
2630 for J
in reverse 0 .. Scope_Stack
.Last
loop
2631 S
:= Scope_Stack
.Table
(J
).Entity
;
2633 if S
= Scope
(Ent
) then
2634 if Nkind
(P
) = N_Expanded_Name
then
2635 Tsk
:= Entity
(Prefix
(P
));
2637 -- The prefix denotes either the task type, or else a
2638 -- single task whose task type is being analyzed.
2643 or else (not Is_Type
(Tsk
)
2644 and then Etype
(Tsk
) = S
2645 and then not (Comes_From_Source
(S
)))
2650 ("Attribute % must apply to entry of current task", N
);
2656 elsif Ekind
(Scope
(Ent
)) in Task_Kind
2657 and then Ekind
(S
) /= E_Loop
2658 and then Ekind
(S
) /= E_Block
2659 and then Ekind
(S
) /= E_Entry
2660 and then Ekind
(S
) /= E_Entry_Family
2662 Error_Attr
("Attribute % cannot appear in inner unit", N
);
2664 elsif Ekind
(Scope
(Ent
)) = E_Protected_Type
2665 and then not Has_Completion
(Scope
(Ent
))
2667 Error_Attr
("attribute % can only be used inside body", N
);
2671 if Is_Overloaded
(P
) then
2673 Index
: Interp_Index
;
2677 Get_First_Interp
(P
, Index
, It
);
2679 while Present
(It
.Nam
) loop
2680 if It
.Nam
= Ent
then
2683 -- Ada 2005 (AI-345): Do not consider primitive entry
2684 -- wrappers generated for task or protected types.
2686 elsif Ada_Version
>= Ada_05
2687 and then not Comes_From_Source
(It
.Nam
)
2692 Error_Attr
("ambiguous entry name", N
);
2695 Get_Next_Interp
(Index
, It
);
2700 Set_Etype
(N
, Universal_Integer
);
2703 -----------------------
2704 -- Default_Bit_Order --
2705 -----------------------
2707 when Attribute_Default_Bit_Order
=> Default_Bit_Order
:
2709 Check_Standard_Prefix
;
2711 if Bytes_Big_Endian
then
2713 Make_Integer_Literal
(Loc
, False_Value
));
2716 Make_Integer_Literal
(Loc
, True_Value
));
2719 Set_Etype
(N
, Universal_Integer
);
2720 Set_Is_Static_Expression
(N
);
2721 end Default_Bit_Order
;
2727 when Attribute_Definite
=>
2728 Legal_Formal_Attribute
;
2734 when Attribute_Delta
=>
2735 Check_Fixed_Point_Type_0
;
2736 Set_Etype
(N
, Universal_Real
);
2742 when Attribute_Denorm
=>
2743 Check_Floating_Point_Type_0
;
2744 Set_Etype
(N
, Standard_Boolean
);
2750 when Attribute_Digits
=>
2754 if not Is_Floating_Point_Type
(P_Type
)
2755 and then not Is_Decimal_Fixed_Point_Type
(P_Type
)
2758 ("prefix of % attribute must be float or decimal type");
2761 Set_Etype
(N
, Universal_Integer
);
2767 -- Also handles processing for Elab_Spec
2769 when Attribute_Elab_Body | Attribute_Elab_Spec
=>
2771 Check_Unit_Name
(P
);
2772 Set_Etype
(N
, Standard_Void_Type
);
2774 -- We have to manually call the expander in this case to get
2775 -- the necessary expansion (normally attributes that return
2776 -- entities are not expanded).
2784 -- Shares processing with Elab_Body
2790 when Attribute_Elaborated
=>
2793 Set_Etype
(N
, Standard_Boolean
);
2799 when Attribute_Emax
=>
2800 Check_Floating_Point_Type_0
;
2801 Set_Etype
(N
, Universal_Integer
);
2807 when Attribute_Enabled
=>
2808 Check_Either_E0_Or_E1
;
2810 if Present
(E1
) then
2811 if not Is_Entity_Name
(E1
) or else No
(Entity
(E1
)) then
2812 Error_Msg_N
("entity name expected for Enabled attribute", E1
);
2817 if Nkind
(P
) /= N_Identifier
then
2818 Error_Msg_N
("identifier expected (check name)", P
);
2819 elsif Get_Check_Id
(Chars
(P
)) = No_Check_Id
then
2820 Error_Msg_N
("& is not a recognized check name", P
);
2823 Set_Etype
(N
, Standard_Boolean
);
2829 when Attribute_Enum_Rep
=> Enum_Rep
: declare
2831 if Present
(E1
) then
2833 Check_Discrete_Type
;
2834 Resolve
(E1
, P_Base_Type
);
2837 if not Is_Entity_Name
(P
)
2838 or else (not Is_Object
(Entity
(P
))
2840 Ekind
(Entity
(P
)) /= E_Enumeration_Literal
)
2843 ("prefix of %attribute must be " &
2844 "discrete type/object or enum literal");
2848 Set_Etype
(N
, Universal_Integer
);
2855 when Attribute_Enum_Val
=> Enum_Val
: begin
2859 if not Is_Enumeration_Type
(P_Type
) then
2860 Error_Attr_P
("prefix of % attribute must be enumeration type");
2863 -- If the enumeration type has a standard representation, the effect
2864 -- is the same as 'Val, so rewrite the attribute as a 'Val.
2866 if not Has_Non_Standard_Rep
(P_Base_Type
) then
2868 Make_Attribute_Reference
(Loc
,
2869 Prefix
=> Relocate_Node
(Prefix
(N
)),
2870 Attribute_Name
=> Name_Val
,
2871 Expressions
=> New_List
(Relocate_Node
(E1
))));
2872 Analyze_And_Resolve
(N
, P_Base_Type
);
2874 -- Non-standard representation case (enumeration with holes)
2878 Resolve
(E1
, Any_Integer
);
2879 Set_Etype
(N
, P_Base_Type
);
2887 when Attribute_Epsilon
=>
2888 Check_Floating_Point_Type_0
;
2889 Set_Etype
(N
, Universal_Real
);
2895 when Attribute_Exponent
=>
2896 Check_Floating_Point_Type_1
;
2897 Set_Etype
(N
, Universal_Integer
);
2898 Resolve
(E1
, P_Base_Type
);
2904 when Attribute_External_Tag
=>
2908 Set_Etype
(N
, Standard_String
);
2910 if not Is_Tagged_Type
(P_Type
) then
2911 Error_Attr_P
("prefix of % attribute must be tagged");
2918 when Attribute_Fast_Math
=>
2919 Check_Standard_Prefix
;
2921 if Opt
.Fast_Math
then
2922 Rewrite
(N
, New_Occurrence_Of
(Standard_True
, Loc
));
2924 Rewrite
(N
, New_Occurrence_Of
(Standard_False
, Loc
));
2931 when Attribute_First
=>
2932 Check_Array_Or_Scalar_Type
;
2938 when Attribute_First_Bit
=>
2940 Set_Etype
(N
, Universal_Integer
);
2946 when Attribute_Fixed_Value
=>
2948 Check_Fixed_Point_Type
;
2949 Resolve
(E1
, Any_Integer
);
2950 Set_Etype
(N
, P_Base_Type
);
2956 when Attribute_Floor
=>
2957 Check_Floating_Point_Type_1
;
2958 Set_Etype
(N
, P_Base_Type
);
2959 Resolve
(E1
, P_Base_Type
);
2965 when Attribute_Fore
=>
2966 Check_Fixed_Point_Type_0
;
2967 Set_Etype
(N
, Universal_Integer
);
2973 when Attribute_Fraction
=>
2974 Check_Floating_Point_Type_1
;
2975 Set_Etype
(N
, P_Base_Type
);
2976 Resolve
(E1
, P_Base_Type
);
2978 -----------------------
2979 -- Has_Access_Values --
2980 -----------------------
2982 when Attribute_Has_Access_Values
=>
2985 Set_Etype
(N
, Standard_Boolean
);
2987 -----------------------
2988 -- Has_Tagged_Values --
2989 -----------------------
2991 when Attribute_Has_Tagged_Values
=>
2994 Set_Etype
(N
, Standard_Boolean
);
2996 -----------------------
2997 -- Has_Discriminants --
2998 -----------------------
3000 when Attribute_Has_Discriminants
=>
3001 Legal_Formal_Attribute
;
3007 when Attribute_Identity
=>
3011 if Etype
(P
) = Standard_Exception_Type
then
3012 Set_Etype
(N
, RTE
(RE_Exception_Id
));
3014 -- Ada 2005 (AI-345): Attribute 'Identity may be applied to
3015 -- task interface class-wide types.
3017 elsif Is_Task_Type
(Etype
(P
))
3018 or else (Is_Access_Type
(Etype
(P
))
3019 and then Is_Task_Type
(Designated_Type
(Etype
(P
))))
3020 or else (Ada_Version
>= Ada_05
3021 and then Ekind
(Etype
(P
)) = E_Class_Wide_Type
3022 and then Is_Interface
(Etype
(P
))
3023 and then Is_Task_Interface
(Etype
(P
)))
3026 Set_Etype
(N
, RTE
(RO_AT_Task_Id
));
3029 if Ada_Version
>= Ada_05
then
3031 ("prefix of % attribute must be an exception, a " &
3032 "task or a task interface class-wide object");
3035 ("prefix of % attribute must be a task or an exception");
3043 when Attribute_Image
=> Image
:
3045 Set_Etype
(N
, Standard_String
);
3048 if Is_Real_Type
(P_Type
) then
3049 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
3050 Error_Msg_Name_1
:= Aname
;
3052 ("(Ada 83) % attribute not allowed for real types", N
);
3056 if Is_Enumeration_Type
(P_Type
) then
3057 Check_Restriction
(No_Enumeration_Maps
, N
);
3061 Resolve
(E1
, P_Base_Type
);
3063 Validate_Non_Static_Attribute_Function_Call
;
3070 when Attribute_Img
=> Img
:
3073 Set_Etype
(N
, Standard_String
);
3075 if not Is_Scalar_Type
(P_Type
)
3076 or else (Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)))
3079 ("prefix of % attribute must be scalar object name");
3089 when Attribute_Input
=>
3091 Check_Stream_Attribute
(TSS_Stream_Input
);
3092 Set_Etype
(N
, P_Base_Type
);
3098 when Attribute_Integer_Value
=>
3101 Resolve
(E1
, Any_Fixed
);
3103 -- Signal an error if argument type is not a specific fixed-point
3104 -- subtype. An error has been signalled already if the argument
3105 -- was not of a fixed-point type.
3107 if Etype
(E1
) = Any_Fixed
and then not Error_Posted
(E1
) then
3108 Error_Attr
("argument of % must be of a fixed-point type", E1
);
3111 Set_Etype
(N
, P_Base_Type
);
3117 when Attribute_Invalid_Value
=>
3120 Set_Etype
(N
, P_Base_Type
);
3121 Invalid_Value_Used
:= True;
3127 when Attribute_Large
=>
3130 Set_Etype
(N
, Universal_Real
);
3136 when Attribute_Last
=>
3137 Check_Array_Or_Scalar_Type
;
3143 when Attribute_Last_Bit
=>
3145 Set_Etype
(N
, Universal_Integer
);
3151 when Attribute_Leading_Part
=>
3152 Check_Floating_Point_Type_2
;
3153 Set_Etype
(N
, P_Base_Type
);
3154 Resolve
(E1
, P_Base_Type
);
3155 Resolve
(E2
, Any_Integer
);
3161 when Attribute_Length
=>
3163 Set_Etype
(N
, Universal_Integer
);
3169 when Attribute_Machine
=>
3170 Check_Floating_Point_Type_1
;
3171 Set_Etype
(N
, P_Base_Type
);
3172 Resolve
(E1
, P_Base_Type
);
3178 when Attribute_Machine_Emax
=>
3179 Check_Floating_Point_Type_0
;
3180 Set_Etype
(N
, Universal_Integer
);
3186 when Attribute_Machine_Emin
=>
3187 Check_Floating_Point_Type_0
;
3188 Set_Etype
(N
, Universal_Integer
);
3190 ----------------------
3191 -- Machine_Mantissa --
3192 ----------------------
3194 when Attribute_Machine_Mantissa
=>
3195 Check_Floating_Point_Type_0
;
3196 Set_Etype
(N
, Universal_Integer
);
3198 -----------------------
3199 -- Machine_Overflows --
3200 -----------------------
3202 when Attribute_Machine_Overflows
=>
3205 Set_Etype
(N
, Standard_Boolean
);
3211 when Attribute_Machine_Radix
=>
3214 Set_Etype
(N
, Universal_Integer
);
3216 ----------------------
3217 -- Machine_Rounding --
3218 ----------------------
3220 when Attribute_Machine_Rounding
=>
3221 Check_Floating_Point_Type_1
;
3222 Set_Etype
(N
, P_Base_Type
);
3223 Resolve
(E1
, P_Base_Type
);
3225 --------------------
3226 -- Machine_Rounds --
3227 --------------------
3229 when Attribute_Machine_Rounds
=>
3232 Set_Etype
(N
, Standard_Boolean
);
3238 when Attribute_Machine_Size
=>
3241 Check_Not_Incomplete_Type
;
3242 Set_Etype
(N
, Universal_Integer
);
3248 when Attribute_Mantissa
=>
3251 Set_Etype
(N
, Universal_Integer
);
3257 when Attribute_Max
=>
3260 Resolve
(E1
, P_Base_Type
);
3261 Resolve
(E2
, P_Base_Type
);
3262 Set_Etype
(N
, P_Base_Type
);
3264 ----------------------------------
3265 -- Max_Size_In_Storage_Elements --
3266 ----------------------------------
3268 when Attribute_Max_Size_In_Storage_Elements
=>
3271 Check_Not_Incomplete_Type
;
3272 Set_Etype
(N
, Universal_Integer
);
3274 -----------------------
3275 -- Maximum_Alignment --
3276 -----------------------
3278 when Attribute_Maximum_Alignment
=>
3279 Standard_Attribute
(Ttypes
.Maximum_Alignment
);
3281 --------------------
3282 -- Mechanism_Code --
3283 --------------------
3285 when Attribute_Mechanism_Code
=>
3286 if not Is_Entity_Name
(P
)
3287 or else not Is_Subprogram
(Entity
(P
))
3289 Error_Attr_P
("prefix of % attribute must be subprogram");
3292 Check_Either_E0_Or_E1
;
3294 if Present
(E1
) then
3295 Resolve
(E1
, Any_Integer
);
3296 Set_Etype
(E1
, Standard_Integer
);
3298 if not Is_Static_Expression
(E1
) then
3299 Flag_Non_Static_Expr
3300 ("expression for parameter number must be static!", E1
);
3303 elsif UI_To_Int
(Intval
(E1
)) > Number_Formals
(Entity
(P
))
3304 or else UI_To_Int
(Intval
(E1
)) < 0
3306 Error_Attr
("invalid parameter number for %attribute", E1
);
3310 Set_Etype
(N
, Universal_Integer
);
3316 when Attribute_Min
=>
3319 Resolve
(E1
, P_Base_Type
);
3320 Resolve
(E2
, P_Base_Type
);
3321 Set_Etype
(N
, P_Base_Type
);
3327 when Attribute_Mod
=>
3329 -- Note: this attribute is only allowed in Ada 2005 mode, but
3330 -- we do not need to test that here, since Mod is only recognized
3331 -- as an attribute name in Ada 2005 mode during the parse.
3334 Check_Modular_Integer_Type
;
3335 Resolve
(E1
, Any_Integer
);
3336 Set_Etype
(N
, P_Base_Type
);
3342 when Attribute_Model
=>
3343 Check_Floating_Point_Type_1
;
3344 Set_Etype
(N
, P_Base_Type
);
3345 Resolve
(E1
, P_Base_Type
);
3351 when Attribute_Model_Emin
=>
3352 Check_Floating_Point_Type_0
;
3353 Set_Etype
(N
, Universal_Integer
);
3359 when Attribute_Model_Epsilon
=>
3360 Check_Floating_Point_Type_0
;
3361 Set_Etype
(N
, Universal_Real
);
3363 --------------------
3364 -- Model_Mantissa --
3365 --------------------
3367 when Attribute_Model_Mantissa
=>
3368 Check_Floating_Point_Type_0
;
3369 Set_Etype
(N
, Universal_Integer
);
3375 when Attribute_Model_Small
=>
3376 Check_Floating_Point_Type_0
;
3377 Set_Etype
(N
, Universal_Real
);
3383 when Attribute_Modulus
=>
3385 Check_Modular_Integer_Type
;
3386 Set_Etype
(N
, Universal_Integer
);
3388 --------------------
3389 -- Null_Parameter --
3390 --------------------
3392 when Attribute_Null_Parameter
=> Null_Parameter
: declare
3393 Parnt
: constant Node_Id
:= Parent
(N
);
3394 GParnt
: constant Node_Id
:= Parent
(Parnt
);
3396 procedure Bad_Null_Parameter
(Msg
: String);
3397 -- Used if bad Null parameter attribute node is found. Issues
3398 -- given error message, and also sets the type to Any_Type to
3399 -- avoid blowups later on from dealing with a junk node.
3401 procedure Must_Be_Imported
(Proc_Ent
: Entity_Id
);
3402 -- Called to check that Proc_Ent is imported subprogram
3404 ------------------------
3405 -- Bad_Null_Parameter --
3406 ------------------------
3408 procedure Bad_Null_Parameter
(Msg
: String) is
3410 Error_Msg_N
(Msg
, N
);
3411 Set_Etype
(N
, Any_Type
);
3412 end Bad_Null_Parameter
;
3414 ----------------------
3415 -- Must_Be_Imported --
3416 ----------------------
3418 procedure Must_Be_Imported
(Proc_Ent
: Entity_Id
) is
3419 Pent
: Entity_Id
:= Proc_Ent
;
3422 while Present
(Alias
(Pent
)) loop
3423 Pent
:= Alias
(Pent
);
3426 -- Ignore check if procedure not frozen yet (we will get
3427 -- another chance when the default parameter is reanalyzed)
3429 if not Is_Frozen
(Pent
) then
3432 elsif not Is_Imported
(Pent
) then
3434 ("Null_Parameter can only be used with imported subprogram");
3439 end Must_Be_Imported
;
3441 -- Start of processing for Null_Parameter
3446 Set_Etype
(N
, P_Type
);
3448 -- Case of attribute used as default expression
3450 if Nkind
(Parnt
) = N_Parameter_Specification
then
3451 Must_Be_Imported
(Defining_Entity
(GParnt
));
3453 -- Case of attribute used as actual for subprogram (positional)
3455 elsif Nkind_In
(Parnt
, N_Procedure_Call_Statement
,
3457 and then Is_Entity_Name
(Name
(Parnt
))
3459 Must_Be_Imported
(Entity
(Name
(Parnt
)));
3461 -- Case of attribute used as actual for subprogram (named)
3463 elsif Nkind
(Parnt
) = N_Parameter_Association
3464 and then Nkind_In
(GParnt
, N_Procedure_Call_Statement
,
3466 and then Is_Entity_Name
(Name
(GParnt
))
3468 Must_Be_Imported
(Entity
(Name
(GParnt
)));
3470 -- Not an allowed case
3474 ("Null_Parameter must be actual or default parameter");
3482 when Attribute_Object_Size
=>
3485 Check_Not_Incomplete_Type
;
3486 Set_Etype
(N
, Universal_Integer
);
3492 when Attribute_Old
=>
3494 Set_Etype
(N
, P_Type
);
3496 if No
(Current_Subprogram
) then
3497 Error_Attr
("attribute % can only appear within subprogram", N
);
3500 if Is_Limited_Type
(P_Type
) then
3501 Error_Attr
("attribute % cannot apply to limited objects", P
);
3504 if Is_Entity_Name
(P
)
3505 and then Is_Constant_Object
(Entity
(P
))
3508 ("?attribute Old applied to constant has no effect", P
);
3511 -- Check that the expression does not refer to local entities
3513 Check_Local
: declare
3514 Subp
: Entity_Id
:= Current_Subprogram
;
3516 function Process
(N
: Node_Id
) return Traverse_Result
;
3517 -- Check that N does not contain references to local variables
3518 -- or other local entities of Subp.
3524 function Process
(N
: Node_Id
) return Traverse_Result
is
3526 if Is_Entity_Name
(N
)
3527 and then not Is_Formal
(Entity
(N
))
3528 and then Enclosing_Subprogram
(Entity
(N
)) = Subp
3530 Error_Msg_Node_1
:= Entity
(N
);
3532 ("attribute % cannot refer to local variable&", N
);
3538 procedure Check_No_Local
is new Traverse_Proc
;
3540 -- Start of processing for Check_Local
3545 if In_Parameter_Specification
(P
) then
3547 -- We have additional restrictions on using 'Old in parameter
3550 if Present
(Enclosing_Subprogram
(Current_Subprogram
)) then
3552 -- Check that there is no reference to the enclosing
3553 -- subprogram local variables. Otherwise, we might end
3554 -- up being called from the enclosing subprogram and thus
3555 -- using 'Old on a local variable which is not defined
3558 Subp
:= Enclosing_Subprogram
(Current_Subprogram
);
3562 -- We must prevent default expression of library-level
3563 -- subprogram from using 'Old, as the subprogram may be
3564 -- used in elaboration code for which there is no enclosing
3568 ("attribute % can only appear within subprogram", N
);
3577 when Attribute_Output
=>
3579 Check_Stream_Attribute
(TSS_Stream_Output
);
3580 Set_Etype
(N
, Standard_Void_Type
);
3581 Resolve
(N
, Standard_Void_Type
);
3587 when Attribute_Partition_ID
=> Partition_Id
:
3591 if P_Type
/= Any_Type
then
3592 if not Is_Library_Level_Entity
(Entity
(P
)) then
3594 ("prefix of % attribute must be library-level entity");
3596 -- The defining entity of prefix should not be declared inside a
3597 -- Pure unit. RM E.1(8). Is_Pure was set during declaration.
3599 elsif Is_Entity_Name
(P
)
3600 and then Is_Pure
(Entity
(P
))
3603 ("prefix of % attribute must not be declared pure");
3607 Set_Etype
(N
, Universal_Integer
);
3610 -------------------------
3611 -- Passed_By_Reference --
3612 -------------------------
3614 when Attribute_Passed_By_Reference
=>
3617 Set_Etype
(N
, Standard_Boolean
);
3623 when Attribute_Pool_Address
=>
3625 Set_Etype
(N
, RTE
(RE_Address
));
3631 when Attribute_Pos
=>
3632 Check_Discrete_Type
;
3634 Resolve
(E1
, P_Base_Type
);
3635 Set_Etype
(N
, Universal_Integer
);
3641 when Attribute_Position
=>
3643 Set_Etype
(N
, Universal_Integer
);
3649 when Attribute_Pred
=>
3652 Resolve
(E1
, P_Base_Type
);
3653 Set_Etype
(N
, P_Base_Type
);
3655 -- Nothing to do for real type case
3657 if Is_Real_Type
(P_Type
) then
3660 -- If not modular type, test for overflow check required
3663 if not Is_Modular_Integer_Type
(P_Type
)
3664 and then not Range_Checks_Suppressed
(P_Base_Type
)
3666 Enable_Range_Check
(E1
);
3674 -- Ada 2005 (AI-327): Dynamic ceiling priorities
3676 when Attribute_Priority
=>
3677 if Ada_Version
< Ada_05
then
3678 Error_Attr
("% attribute is allowed only in Ada 2005 mode", P
);
3683 -- The prefix must be a protected object (AARM D.5.2 (2/2))
3687 if Is_Protected_Type
(Etype
(P
))
3688 or else (Is_Access_Type
(Etype
(P
))
3689 and then Is_Protected_Type
(Designated_Type
(Etype
(P
))))
3691 Resolve
(P
, Etype
(P
));
3693 Error_Attr_P
("prefix of % attribute must be a protected object");
3696 Set_Etype
(N
, Standard_Integer
);
3698 -- Must be called from within a protected procedure or entry of the
3699 -- protected object.
3706 while S
/= Etype
(P
)
3707 and then S
/= Standard_Standard
3712 if S
= Standard_Standard
then
3713 Error_Attr
("the attribute % is only allowed inside protected "
3718 Validate_Non_Static_Attribute_Function_Call
;
3724 when Attribute_Range
=>
3725 Check_Array_Or_Scalar_Type
;
3727 if Ada_Version
= Ada_83
3728 and then Is_Scalar_Type
(P_Type
)
3729 and then Comes_From_Source
(N
)
3732 ("(Ada 83) % attribute not allowed for scalar type", P
);
3739 when Attribute_Result
=> Result
: declare
3740 CS
: constant Entity_Id
:= Current_Scope
;
3741 PS
: constant Entity_Id
:= Scope
(CS
);
3744 -- If we are in the scope of a function and in Spec_Expression mode,
3745 -- this is likely the prescan of the postcondition pragma, and we
3746 -- just set the proper type. If there is an error it will be caught
3747 -- when the real Analyze call is done.
3749 if Ekind
(CS
) = E_Function
3750 and then In_Spec_Expression
3754 if Chars
(CS
) /= Chars
(P
) then
3756 ("incorrect prefix for % attribute, expected &", P
, CS
);
3760 Set_Etype
(N
, Etype
(CS
));
3762 -- If several functions with that name are visible,
3763 -- the intended one is the current scope.
3765 if Is_Overloaded
(P
) then
3767 Set_Is_Overloaded
(P
, False);
3770 -- Body case, where we must be inside a generated _Postcondition
3771 -- procedure, or the attribute use is definitely misplaced.
3773 elsif Chars
(CS
) = Name_uPostconditions
3774 and then Ekind
(PS
) = E_Function
3778 if Nkind
(P
) /= N_Identifier
3779 or else Chars
(P
) /= Chars
(PS
)
3782 ("incorrect prefix for % attribute, expected &", P
, PS
);
3787 Make_Identifier
(Sloc
(N
),
3788 Chars
=> Name_uResult
));
3789 Analyze_And_Resolve
(N
, Etype
(PS
));
3793 ("% attribute can only appear in function Postcondition pragma",
3802 when Attribute_Range_Length
=>
3804 Check_Discrete_Type
;
3805 Set_Etype
(N
, Universal_Integer
);
3811 when Attribute_Read
=>
3813 Check_Stream_Attribute
(TSS_Stream_Read
);
3814 Set_Etype
(N
, Standard_Void_Type
);
3815 Resolve
(N
, Standard_Void_Type
);
3816 Note_Possible_Modification
(E2
, Sure
=> True);
3822 when Attribute_Remainder
=>
3823 Check_Floating_Point_Type_2
;
3824 Set_Etype
(N
, P_Base_Type
);
3825 Resolve
(E1
, P_Base_Type
);
3826 Resolve
(E2
, P_Base_Type
);
3832 when Attribute_Round
=>
3834 Check_Decimal_Fixed_Point_Type
;
3835 Set_Etype
(N
, P_Base_Type
);
3837 -- Because the context is universal_real (3.5.10(12)) it is a legal
3838 -- context for a universal fixed expression. This is the only
3839 -- attribute whose functional description involves U_R.
3841 if Etype
(E1
) = Universal_Fixed
then
3843 Conv
: constant Node_Id
:= Make_Type_Conversion
(Loc
,
3844 Subtype_Mark
=> New_Occurrence_Of
(Universal_Real
, Loc
),
3845 Expression
=> Relocate_Node
(E1
));
3853 Resolve
(E1
, Any_Real
);
3859 when Attribute_Rounding
=>
3860 Check_Floating_Point_Type_1
;
3861 Set_Etype
(N
, P_Base_Type
);
3862 Resolve
(E1
, P_Base_Type
);
3868 when Attribute_Safe_Emax
=>
3869 Check_Floating_Point_Type_0
;
3870 Set_Etype
(N
, Universal_Integer
);
3876 when Attribute_Safe_First
=>
3877 Check_Floating_Point_Type_0
;
3878 Set_Etype
(N
, Universal_Real
);
3884 when Attribute_Safe_Large
=>
3887 Set_Etype
(N
, Universal_Real
);
3893 when Attribute_Safe_Last
=>
3894 Check_Floating_Point_Type_0
;
3895 Set_Etype
(N
, Universal_Real
);
3901 when Attribute_Safe_Small
=>
3904 Set_Etype
(N
, Universal_Real
);
3910 when Attribute_Scale
=>
3912 Check_Decimal_Fixed_Point_Type
;
3913 Set_Etype
(N
, Universal_Integer
);
3919 when Attribute_Scaling
=>
3920 Check_Floating_Point_Type_2
;
3921 Set_Etype
(N
, P_Base_Type
);
3922 Resolve
(E1
, P_Base_Type
);
3928 when Attribute_Signed_Zeros
=>
3929 Check_Floating_Point_Type_0
;
3930 Set_Etype
(N
, Standard_Boolean
);
3936 when Attribute_Size | Attribute_VADS_Size
=> Size
:
3940 -- If prefix is parameterless function call, rewrite and resolve
3943 if Is_Entity_Name
(P
)
3944 and then Ekind
(Entity
(P
)) = E_Function
3948 -- Similar processing for a protected function call
3950 elsif Nkind
(P
) = N_Selected_Component
3951 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Function
3956 if Is_Object_Reference
(P
) then
3957 Check_Object_Reference
(P
);
3959 elsif Is_Entity_Name
(P
)
3960 and then (Is_Type
(Entity
(P
))
3961 or else Ekind
(Entity
(P
)) = E_Enumeration_Literal
)
3965 elsif Nkind
(P
) = N_Type_Conversion
3966 and then not Comes_From_Source
(P
)
3971 Error_Attr_P
("invalid prefix for % attribute");
3974 Check_Not_Incomplete_Type
;
3976 Set_Etype
(N
, Universal_Integer
);
3983 when Attribute_Small
=>
3986 Set_Etype
(N
, Universal_Real
);
3992 when Attribute_Storage_Pool
=> Storage_Pool
:
3996 if Is_Access_Type
(P_Type
) then
3997 if Ekind
(P_Type
) = E_Access_Subprogram_Type
then
3999 ("cannot use % attribute for access-to-subprogram type");
4002 -- Set appropriate entity
4004 if Present
(Associated_Storage_Pool
(Root_Type
(P_Type
))) then
4005 Set_Entity
(N
, Associated_Storage_Pool
(Root_Type
(P_Type
)));
4007 Set_Entity
(N
, RTE
(RE_Global_Pool_Object
));
4010 Set_Etype
(N
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
4012 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
4013 -- Storage_Pool since this attribute is not defined for such
4014 -- types (RM E.2.3(22)).
4016 Validate_Remote_Access_To_Class_Wide_Type
(N
);
4019 Error_Attr_P
("prefix of % attribute must be access type");
4027 when Attribute_Storage_Size
=> Storage_Size
:
4031 if Is_Task_Type
(P_Type
) then
4032 Set_Etype
(N
, Universal_Integer
);
4034 elsif Is_Access_Type
(P_Type
) then
4035 if Ekind
(P_Type
) = E_Access_Subprogram_Type
then
4037 ("cannot use % attribute for access-to-subprogram type");
4040 if Is_Entity_Name
(P
)
4041 and then Is_Type
(Entity
(P
))
4044 Set_Etype
(N
, Universal_Integer
);
4046 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
4047 -- Storage_Size since this attribute is not defined for
4048 -- such types (RM E.2.3(22)).
4050 Validate_Remote_Access_To_Class_Wide_Type
(N
);
4052 -- The prefix is allowed to be an implicit dereference
4053 -- of an access value designating a task.
4057 Set_Etype
(N
, Universal_Integer
);
4061 Error_Attr_P
("prefix of % attribute must be access or task type");
4069 when Attribute_Storage_Unit
=>
4070 Standard_Attribute
(Ttypes
.System_Storage_Unit
);
4076 when Attribute_Stream_Size
=>
4080 if Is_Entity_Name
(P
)
4081 and then Is_Elementary_Type
(Entity
(P
))
4083 Set_Etype
(N
, Universal_Integer
);
4085 Error_Attr_P
("invalid prefix for % attribute");
4092 when Attribute_Stub_Type
=>
4096 if Is_Remote_Access_To_Class_Wide_Type
(P_Type
) then
4098 New_Occurrence_Of
(Corresponding_Stub_Type
(P_Type
), Loc
));
4101 ("prefix of% attribute must be remote access to classwide");
4108 when Attribute_Succ
=>
4111 Resolve
(E1
, P_Base_Type
);
4112 Set_Etype
(N
, P_Base_Type
);
4114 -- Nothing to do for real type case
4116 if Is_Real_Type
(P_Type
) then
4119 -- If not modular type, test for overflow check required
4122 if not Is_Modular_Integer_Type
(P_Type
)
4123 and then not Range_Checks_Suppressed
(P_Base_Type
)
4125 Enable_Range_Check
(E1
);
4133 when Attribute_Tag
=> Tag
:
4138 if not Is_Tagged_Type
(P_Type
) then
4139 Error_Attr_P
("prefix of % attribute must be tagged");
4141 -- Next test does not apply to generated code
4142 -- why not, and what does the illegal reference mean???
4144 elsif Is_Object_Reference
(P
)
4145 and then not Is_Class_Wide_Type
(P_Type
)
4146 and then Comes_From_Source
(N
)
4149 ("% attribute can only be applied to objects " &
4150 "of class - wide type");
4153 -- The prefix cannot be an incomplete type. However, references
4154 -- to 'Tag can be generated when expanding interface conversions,
4155 -- and this is legal.
4157 if Comes_From_Source
(N
) then
4158 Check_Not_Incomplete_Type
;
4161 -- Set appropriate type
4163 Set_Etype
(N
, RTE
(RE_Tag
));
4170 when Attribute_Target_Name
=> Target_Name
: declare
4171 TN
: constant String := Sdefault
.Target_Name
.all;
4175 Check_Standard_Prefix
;
4179 if TN
(TL
) = '/' or else TN
(TL
) = '\' then
4184 Make_String_Literal
(Loc
,
4185 Strval
=> TN
(TN
'First .. TL
)));
4186 Analyze_And_Resolve
(N
, Standard_String
);
4193 when Attribute_Terminated
=>
4195 Set_Etype
(N
, Standard_Boolean
);
4202 when Attribute_To_Address
=>
4206 if Nkind
(P
) /= N_Identifier
4207 or else Chars
(P
) /= Name_System
4209 Error_Attr_P
("prefix of %attribute must be System");
4212 Generate_Reference
(RTE
(RE_Address
), P
);
4213 Analyze_And_Resolve
(E1
, Any_Integer
);
4214 Set_Etype
(N
, RTE
(RE_Address
));
4220 when Attribute_Truncation
=>
4221 Check_Floating_Point_Type_1
;
4222 Resolve
(E1
, P_Base_Type
);
4223 Set_Etype
(N
, P_Base_Type
);
4229 when Attribute_Type_Class
=>
4232 Check_Not_Incomplete_Type
;
4233 Set_Etype
(N
, RTE
(RE_Type_Class
));
4239 when Attribute_UET_Address
=>
4241 Check_Unit_Name
(P
);
4242 Set_Etype
(N
, RTE
(RE_Address
));
4244 -----------------------
4245 -- Unbiased_Rounding --
4246 -----------------------
4248 when Attribute_Unbiased_Rounding
=>
4249 Check_Floating_Point_Type_1
;
4250 Set_Etype
(N
, P_Base_Type
);
4251 Resolve
(E1
, P_Base_Type
);
4253 ----------------------
4254 -- Unchecked_Access --
4255 ----------------------
4257 when Attribute_Unchecked_Access
=>
4258 if Comes_From_Source
(N
) then
4259 Check_Restriction
(No_Unchecked_Access
, N
);
4262 Analyze_Access_Attribute
;
4264 -------------------------
4265 -- Unconstrained_Array --
4266 -------------------------
4268 when Attribute_Unconstrained_Array
=>
4271 Check_Not_Incomplete_Type
;
4272 Set_Etype
(N
, Standard_Boolean
);
4274 ------------------------------
4275 -- Universal_Literal_String --
4276 ------------------------------
4278 -- This is a GNAT specific attribute whose prefix must be a named
4279 -- number where the expression is either a single numeric literal,
4280 -- or a numeric literal immediately preceded by a minus sign. The
4281 -- result is equivalent to a string literal containing the text of
4282 -- the literal as it appeared in the source program with a possible
4283 -- leading minus sign.
4285 when Attribute_Universal_Literal_String
=> Universal_Literal_String
:
4289 if not Is_Entity_Name
(P
)
4290 or else Ekind
(Entity
(P
)) not in Named_Kind
4292 Error_Attr_P
("prefix for % attribute must be named number");
4299 Src
: Source_Buffer_Ptr
;
4302 Expr
:= Original_Node
(Expression
(Parent
(Entity
(P
))));
4304 if Nkind
(Expr
) = N_Op_Minus
then
4306 Expr
:= Original_Node
(Right_Opnd
(Expr
));
4311 if not Nkind_In
(Expr
, N_Integer_Literal
, N_Real_Literal
) then
4313 ("named number for % attribute must be simple literal", N
);
4316 -- Build string literal corresponding to source literal text
4321 Store_String_Char
(Get_Char_Code
('-'));
4325 Src
:= Source_Text
(Get_Source_File_Index
(S
));
4327 while Src
(S
) /= ';' and then Src
(S
) /= ' ' loop
4328 Store_String_Char
(Get_Char_Code
(Src
(S
)));
4332 -- Now we rewrite the attribute with the string literal
4335 Make_String_Literal
(Loc
, End_String
));
4339 end Universal_Literal_String
;
4341 -------------------------
4342 -- Unrestricted_Access --
4343 -------------------------
4345 -- This is a GNAT specific attribute which is like Access except that
4346 -- all scope checks and checks for aliased views are omitted.
4348 when Attribute_Unrestricted_Access
=>
4349 if Comes_From_Source
(N
) then
4350 Check_Restriction
(No_Unchecked_Access
, N
);
4353 if Is_Entity_Name
(P
) then
4354 Set_Address_Taken
(Entity
(P
));
4357 Analyze_Access_Attribute
;
4363 when Attribute_Val
=> Val
: declare
4366 Check_Discrete_Type
;
4367 Resolve
(E1
, Any_Integer
);
4368 Set_Etype
(N
, P_Base_Type
);
4370 -- Note, we need a range check in general, but we wait for the
4371 -- Resolve call to do this, since we want to let Eval_Attribute
4372 -- have a chance to find an static illegality first!
4379 when Attribute_Valid
=>
4382 -- Ignore check for object if we have a 'Valid reference generated
4383 -- by the expanded code, since in some cases valid checks can occur
4384 -- on items that are names, but are not objects (e.g. attributes).
4386 if Comes_From_Source
(N
) then
4387 Check_Object_Reference
(P
);
4390 if not Is_Scalar_Type
(P_Type
) then
4391 Error_Attr_P
("object for % attribute must be of scalar type");
4394 Set_Etype
(N
, Standard_Boolean
);
4400 when Attribute_Value
=> Value
:
4405 -- Case of enumeration type
4407 if Is_Enumeration_Type
(P_Type
) then
4408 Check_Restriction
(No_Enumeration_Maps
, N
);
4410 -- Mark all enumeration literals as referenced, since the use of
4411 -- the Value attribute can implicitly reference any of the
4412 -- literals of the enumeration base type.
4415 Ent
: Entity_Id
:= First_Literal
(P_Base_Type
);
4417 while Present
(Ent
) loop
4418 Set_Referenced
(Ent
);
4424 -- Set Etype before resolving expression because expansion of
4425 -- expression may require enclosing type. Note that the type
4426 -- returned by 'Value is the base type of the prefix type.
4428 Set_Etype
(N
, P_Base_Type
);
4429 Validate_Non_Static_Attribute_Function_Call
;
4436 when Attribute_Value_Size
=>
4439 Check_Not_Incomplete_Type
;
4440 Set_Etype
(N
, Universal_Integer
);
4446 when Attribute_Version
=>
4449 Set_Etype
(N
, RTE
(RE_Version_String
));
4455 when Attribute_Wchar_T_Size
=>
4456 Standard_Attribute
(Interfaces_Wchar_T_Size
);
4462 when Attribute_Wide_Image
=> Wide_Image
:
4465 Set_Etype
(N
, Standard_Wide_String
);
4467 Resolve
(E1
, P_Base_Type
);
4468 Validate_Non_Static_Attribute_Function_Call
;
4471 ---------------------
4472 -- Wide_Wide_Image --
4473 ---------------------
4475 when Attribute_Wide_Wide_Image
=> Wide_Wide_Image
:
4478 Set_Etype
(N
, Standard_Wide_Wide_String
);
4480 Resolve
(E1
, P_Base_Type
);
4481 Validate_Non_Static_Attribute_Function_Call
;
4482 end Wide_Wide_Image
;
4488 when Attribute_Wide_Value
=> Wide_Value
:
4493 -- Set Etype before resolving expression because expansion
4494 -- of expression may require enclosing type.
4496 Set_Etype
(N
, P_Type
);
4497 Validate_Non_Static_Attribute_Function_Call
;
4500 ---------------------
4501 -- Wide_Wide_Value --
4502 ---------------------
4504 when Attribute_Wide_Wide_Value
=> Wide_Wide_Value
:
4509 -- Set Etype before resolving expression because expansion
4510 -- of expression may require enclosing type.
4512 Set_Etype
(N
, P_Type
);
4513 Validate_Non_Static_Attribute_Function_Call
;
4514 end Wide_Wide_Value
;
4516 ---------------------
4517 -- Wide_Wide_Width --
4518 ---------------------
4520 when Attribute_Wide_Wide_Width
=>
4523 Set_Etype
(N
, Universal_Integer
);
4529 when Attribute_Wide_Width
=>
4532 Set_Etype
(N
, Universal_Integer
);
4538 when Attribute_Width
=>
4541 Set_Etype
(N
, Universal_Integer
);
4547 when Attribute_Word_Size
=>
4548 Standard_Attribute
(System_Word_Size
);
4554 when Attribute_Write
=>
4556 Check_Stream_Attribute
(TSS_Stream_Write
);
4557 Set_Etype
(N
, Standard_Void_Type
);
4558 Resolve
(N
, Standard_Void_Type
);
4562 -- All errors raise Bad_Attribute, so that we get out before any further
4563 -- damage occurs when an error is detected (for example, if we check for
4564 -- one attribute expression, and the check succeeds, we want to be able
4565 -- to proceed securely assuming that an expression is in fact present.
4567 -- Note: we set the attribute analyzed in this case to prevent any
4568 -- attempt at reanalysis which could generate spurious error msgs.
4571 when Bad_Attribute
=>
4573 Set_Etype
(N
, Any_Type
);
4575 end Analyze_Attribute
;
4577 --------------------
4578 -- Eval_Attribute --
4579 --------------------
4581 procedure Eval_Attribute
(N
: Node_Id
) is
4582 Loc
: constant Source_Ptr
:= Sloc
(N
);
4583 Aname
: constant Name_Id
:= Attribute_Name
(N
);
4584 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Aname
);
4585 P
: constant Node_Id
:= Prefix
(N
);
4587 C_Type
: constant Entity_Id
:= Etype
(N
);
4588 -- The type imposed by the context
4591 -- First expression, or Empty if none
4594 -- Second expression, or Empty if none
4596 P_Entity
: Entity_Id
;
4597 -- Entity denoted by prefix
4600 -- The type of the prefix
4602 P_Base_Type
: Entity_Id
;
4603 -- The base type of the prefix type
4605 P_Root_Type
: Entity_Id
;
4606 -- The root type of the prefix type
4609 -- True if the result is Static. This is set by the general processing
4610 -- to true if the prefix is static, and all expressions are static. It
4611 -- can be reset as processing continues for particular attributes
4613 Lo_Bound
, Hi_Bound
: Node_Id
;
4614 -- Expressions for low and high bounds of type or array index referenced
4615 -- by First, Last, or Length attribute for array, set by Set_Bounds.
4618 -- Constraint error node used if we have an attribute reference has
4619 -- an argument that raises a constraint error. In this case we replace
4620 -- the attribute with a raise constraint_error node. This is important
4621 -- processing, since otherwise gigi might see an attribute which it is
4622 -- unprepared to deal with.
4624 function Aft_Value
return Nat
;
4625 -- Computes Aft value for current attribute prefix (used by Aft itself
4626 -- and also by Width for computing the Width of a fixed point type).
4628 procedure Check_Expressions
;
4629 -- In case where the attribute is not foldable, the expressions, if
4630 -- any, of the attribute, are in a non-static context. This procedure
4631 -- performs the required additional checks.
4633 function Compile_Time_Known_Bounds
(Typ
: Entity_Id
) return Boolean;
4634 -- Determines if the given type has compile time known bounds. Note
4635 -- that we enter the case statement even in cases where the prefix
4636 -- type does NOT have known bounds, so it is important to guard any
4637 -- attempt to evaluate both bounds with a call to this function.
4639 procedure Compile_Time_Known_Attribute
(N
: Node_Id
; Val
: Uint
);
4640 -- This procedure is called when the attribute N has a non-static
4641 -- but compile time known value given by Val. It includes the
4642 -- necessary checks for out of range values.
4644 procedure Float_Attribute_Universal_Integer
4653 -- This procedure evaluates a float attribute with no arguments that
4654 -- returns a universal integer result. The parameters give the values
4655 -- for the possible floating-point root types. See ttypef for details.
4656 -- The prefix type is a float type (and is thus not a generic type).
4658 procedure Float_Attribute_Universal_Real
4659 (IEEES_Val
: String;
4666 AAMPL_Val
: String);
4667 -- This procedure evaluates a float attribute with no arguments that
4668 -- returns a universal real result. The parameters give the values
4669 -- required for the possible floating-point root types in string
4670 -- format as real literals with a possible leading minus sign.
4671 -- The prefix type is a float type (and is thus not a generic type).
4673 function Fore_Value
return Nat
;
4674 -- Computes the Fore value for the current attribute prefix, which is
4675 -- known to be a static fixed-point type. Used by Fore and Width.
4677 function Mantissa
return Uint
;
4678 -- Returns the Mantissa value for the prefix type
4680 procedure Set_Bounds
;
4681 -- Used for First, Last and Length attributes applied to an array or
4682 -- array subtype. Sets the variables Lo_Bound and Hi_Bound to the low
4683 -- and high bound expressions for the index referenced by the attribute
4684 -- designator (i.e. the first index if no expression is present, and
4685 -- the N'th index if the value N is present as an expression). Also
4686 -- used for First and Last of scalar types. Static is reset to False
4687 -- if the type or index type is not statically constrained.
4689 function Statically_Denotes_Entity
(N
: Node_Id
) return Boolean;
4690 -- Verify that the prefix of a potentially static array attribute
4691 -- satisfies the conditions of 4.9 (14).
4697 function Aft_Value
return Nat
is
4703 Delta_Val
:= Delta_Value
(P_Type
);
4704 while Delta_Val
< Ureal_Tenth
loop
4705 Delta_Val
:= Delta_Val
* Ureal_10
;
4706 Result
:= Result
+ 1;
4712 -----------------------
4713 -- Check_Expressions --
4714 -----------------------
4716 procedure Check_Expressions
is
4720 while Present
(E
) loop
4721 Check_Non_Static_Context
(E
);
4724 end Check_Expressions
;
4726 ----------------------------------
4727 -- Compile_Time_Known_Attribute --
4728 ----------------------------------
4730 procedure Compile_Time_Known_Attribute
(N
: Node_Id
; Val
: Uint
) is
4731 T
: constant Entity_Id
:= Etype
(N
);
4734 Fold_Uint
(N
, Val
, False);
4736 -- Check that result is in bounds of the type if it is static
4738 if Is_In_Range
(N
, T
) then
4741 elsif Is_Out_Of_Range
(N
, T
) then
4742 Apply_Compile_Time_Constraint_Error
4743 (N
, "value not in range of}?", CE_Range_Check_Failed
);
4745 elsif not Range_Checks_Suppressed
(T
) then
4746 Enable_Range_Check
(N
);
4749 Set_Do_Range_Check
(N
, False);
4751 end Compile_Time_Known_Attribute
;
4753 -------------------------------
4754 -- Compile_Time_Known_Bounds --
4755 -------------------------------
4757 function Compile_Time_Known_Bounds
(Typ
: Entity_Id
) return Boolean is
4760 Compile_Time_Known_Value
(Type_Low_Bound
(Typ
))
4762 Compile_Time_Known_Value
(Type_High_Bound
(Typ
));
4763 end Compile_Time_Known_Bounds
;
4765 ---------------------------------------
4766 -- Float_Attribute_Universal_Integer --
4767 ---------------------------------------
4769 procedure Float_Attribute_Universal_Integer
4780 Digs
: constant Nat
:= UI_To_Int
(Digits_Value
(P_Base_Type
));
4783 if Vax_Float
(P_Base_Type
) then
4784 if Digs
= VAXFF_Digits
then
4786 elsif Digs
= VAXDF_Digits
then
4788 else pragma Assert
(Digs
= VAXGF_Digits
);
4792 elsif Is_AAMP_Float
(P_Base_Type
) then
4793 if Digs
= AAMPS_Digits
then
4795 else pragma Assert
(Digs
= AAMPL_Digits
);
4800 if Digs
= IEEES_Digits
then
4802 elsif Digs
= IEEEL_Digits
then
4804 else pragma Assert
(Digs
= IEEEX_Digits
);
4809 Fold_Uint
(N
, UI_From_Int
(Val
), True);
4810 end Float_Attribute_Universal_Integer
;
4812 ------------------------------------
4813 -- Float_Attribute_Universal_Real --
4814 ------------------------------------
4816 procedure Float_Attribute_Universal_Real
4817 (IEEES_Val
: String;
4827 Digs
: constant Nat
:= UI_To_Int
(Digits_Value
(P_Base_Type
));
4830 if Vax_Float
(P_Base_Type
) then
4831 if Digs
= VAXFF_Digits
then
4832 Val
:= Real_Convert
(VAXFF_Val
);
4833 elsif Digs
= VAXDF_Digits
then
4834 Val
:= Real_Convert
(VAXDF_Val
);
4835 else pragma Assert
(Digs
= VAXGF_Digits
);
4836 Val
:= Real_Convert
(VAXGF_Val
);
4839 elsif Is_AAMP_Float
(P_Base_Type
) then
4840 if Digs
= AAMPS_Digits
then
4841 Val
:= Real_Convert
(AAMPS_Val
);
4842 else pragma Assert
(Digs
= AAMPL_Digits
);
4843 Val
:= Real_Convert
(AAMPL_Val
);
4847 if Digs
= IEEES_Digits
then
4848 Val
:= Real_Convert
(IEEES_Val
);
4849 elsif Digs
= IEEEL_Digits
then
4850 Val
:= Real_Convert
(IEEEL_Val
);
4851 else pragma Assert
(Digs
= IEEEX_Digits
);
4852 Val
:= Real_Convert
(IEEEX_Val
);
4856 Set_Sloc
(Val
, Loc
);
4858 Set_Is_Static_Expression
(N
, Static
);
4859 Analyze_And_Resolve
(N
, C_Type
);
4860 end Float_Attribute_Universal_Real
;
4866 -- Note that the Fore calculation is based on the actual values
4867 -- of the bounds, and does not take into account possible rounding.
4869 function Fore_Value
return Nat
is
4870 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(P_Type
));
4871 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(P_Type
));
4872 Small
: constant Ureal
:= Small_Value
(P_Type
);
4873 Lo_Real
: constant Ureal
:= Lo
* Small
;
4874 Hi_Real
: constant Ureal
:= Hi
* Small
;
4879 -- Bounds are given in terms of small units, so first compute
4880 -- proper values as reals.
4882 T
:= UR_Max
(abs Lo_Real
, abs Hi_Real
);
4885 -- Loop to compute proper value if more than one digit required
4887 while T
>= Ureal_10
loop
4899 -- Table of mantissa values accessed by function Computed using
4902 -- T'Mantissa = integer next above (D * log(10)/log(2)) + 1)
4904 -- where D is T'Digits (RM83 3.5.7)
4906 Mantissa_Value
: constant array (Nat
range 1 .. 40) of Nat
:= (
4948 function Mantissa
return Uint
is
4951 UI_From_Int
(Mantissa_Value
(UI_To_Int
(Digits_Value
(P_Type
))));
4958 procedure Set_Bounds
is
4964 -- For a string literal subtype, we have to construct the bounds.
4965 -- Valid Ada code never applies attributes to string literals, but
4966 -- it is convenient to allow the expander to generate attribute
4967 -- references of this type (e.g. First and Last applied to a string
4970 -- Note that the whole point of the E_String_Literal_Subtype is to
4971 -- avoid this construction of bounds, but the cases in which we
4972 -- have to materialize them are rare enough that we don't worry!
4974 -- The low bound is simply the low bound of the base type. The
4975 -- high bound is computed from the length of the string and this
4978 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
4979 Ityp
:= Etype
(First_Index
(Base_Type
(P_Type
)));
4980 Lo_Bound
:= Type_Low_Bound
(Ityp
);
4983 Make_Integer_Literal
(Sloc
(P
),
4985 Expr_Value
(Lo_Bound
) + String_Literal_Length
(P_Type
) - 1);
4987 Set_Parent
(Hi_Bound
, P
);
4988 Analyze_And_Resolve
(Hi_Bound
, Etype
(Lo_Bound
));
4991 -- For non-array case, just get bounds of scalar type
4993 elsif Is_Scalar_Type
(P_Type
) then
4996 -- For a fixed-point type, we must freeze to get the attributes
4997 -- of the fixed-point type set now so we can reference them.
4999 if Is_Fixed_Point_Type
(P_Type
)
5000 and then not Is_Frozen
(Base_Type
(P_Type
))
5001 and then Compile_Time_Known_Value
(Type_Low_Bound
(P_Type
))
5002 and then Compile_Time_Known_Value
(Type_High_Bound
(P_Type
))
5004 Freeze_Fixed_Point_Type
(Base_Type
(P_Type
));
5007 -- For array case, get type of proper index
5013 Ndim
:= UI_To_Int
(Expr_Value
(E1
));
5016 Indx
:= First_Index
(P_Type
);
5017 for J
in 1 .. Ndim
- 1 loop
5021 -- If no index type, get out (some other error occurred, and
5022 -- we don't have enough information to complete the job!)
5030 Ityp
:= Etype
(Indx
);
5033 -- A discrete range in an index constraint is allowed to be a
5034 -- subtype indication. This is syntactically a pain, but should
5035 -- not propagate to the entity for the corresponding index subtype.
5036 -- After checking that the subtype indication is legal, the range
5037 -- of the subtype indication should be transfered to the entity.
5038 -- The attributes for the bounds should remain the simple retrievals
5039 -- that they are now.
5041 Lo_Bound
:= Type_Low_Bound
(Ityp
);
5042 Hi_Bound
:= Type_High_Bound
(Ityp
);
5044 if not Is_Static_Subtype
(Ityp
) then
5049 -------------------------------
5050 -- Statically_Denotes_Entity --
5051 -------------------------------
5053 function Statically_Denotes_Entity
(N
: Node_Id
) return Boolean is
5057 if not Is_Entity_Name
(N
) then
5064 Nkind
(Parent
(E
)) /= N_Object_Renaming_Declaration
5065 or else Statically_Denotes_Entity
(Renamed_Object
(E
));
5066 end Statically_Denotes_Entity
;
5068 -- Start of processing for Eval_Attribute
5071 -- Acquire first two expressions (at the moment, no attributes
5072 -- take more than two expressions in any case).
5074 if Present
(Expressions
(N
)) then
5075 E1
:= First
(Expressions
(N
));
5082 -- Special processing for Enabled attribute. This attribute has a very
5083 -- special prefix, and the easiest way to avoid lots of special checks
5084 -- to protect this special prefix from causing trouble is to deal with
5085 -- this attribute immediately and be done with it.
5087 if Id
= Attribute_Enabled
then
5089 -- Evaluate the Enabled attribute
5091 -- We skip evaluation if the expander is not active. This is not just
5092 -- an optimization. It is of key importance that we not rewrite the
5093 -- attribute in a generic template, since we want to pick up the
5094 -- setting of the check in the instance, and testing expander active
5095 -- is as easy way of doing this as any.
5097 if Expander_Active
then
5099 C
: constant Check_Id
:= Get_Check_Id
(Chars
(P
));
5104 if C
in Predefined_Check_Id
then
5105 R
:= Scope_Suppress
(C
);
5107 R
:= Is_Check_Suppressed
(Empty
, C
);
5111 R
:= Is_Check_Suppressed
(Entity
(E1
), C
);
5115 Rewrite
(N
, New_Occurrence_Of
(Standard_False
, Loc
));
5117 Rewrite
(N
, New_Occurrence_Of
(Standard_True
, Loc
));
5125 -- Special processing for cases where the prefix is an object. For
5126 -- this purpose, a string literal counts as an object (attributes
5127 -- of string literals can only appear in generated code).
5129 if Is_Object_Reference
(P
) or else Nkind
(P
) = N_String_Literal
then
5131 -- For Component_Size, the prefix is an array object, and we apply
5132 -- the attribute to the type of the object. This is allowed for
5133 -- both unconstrained and constrained arrays, since the bounds
5134 -- have no influence on the value of this attribute.
5136 if Id
= Attribute_Component_Size
then
5137 P_Entity
:= Etype
(P
);
5139 -- For First and Last, the prefix is an array object, and we apply
5140 -- the attribute to the type of the array, but we need a constrained
5141 -- type for this, so we use the actual subtype if available.
5143 elsif Id
= Attribute_First
5147 Id
= Attribute_Length
5150 AS
: constant Entity_Id
:= Get_Actual_Subtype_If_Available
(P
);
5153 if Present
(AS
) and then Is_Constrained
(AS
) then
5156 -- If we have an unconstrained type, cannot fold
5164 -- For Size, give size of object if available, otherwise we
5165 -- cannot fold Size.
5167 elsif Id
= Attribute_Size
then
5168 if Is_Entity_Name
(P
)
5169 and then Known_Esize
(Entity
(P
))
5171 Compile_Time_Known_Attribute
(N
, Esize
(Entity
(P
)));
5179 -- For Alignment, give size of object if available, otherwise we
5180 -- cannot fold Alignment.
5182 elsif Id
= Attribute_Alignment
then
5183 if Is_Entity_Name
(P
)
5184 and then Known_Alignment
(Entity
(P
))
5186 Fold_Uint
(N
, Alignment
(Entity
(P
)), False);
5194 -- No other attributes for objects are folded
5201 -- Cases where P is not an object. Cannot do anything if P is
5202 -- not the name of an entity.
5204 elsif not Is_Entity_Name
(P
) then
5208 -- Otherwise get prefix entity
5211 P_Entity
:= Entity
(P
);
5214 -- At this stage P_Entity is the entity to which the attribute
5215 -- is to be applied. This is usually simply the entity of the
5216 -- prefix, except in some cases of attributes for objects, where
5217 -- as described above, we apply the attribute to the object type.
5219 -- First foldable possibility is a scalar or array type (RM 4.9(7))
5220 -- that is not generic (generic types are eliminated by RM 4.9(25)).
5221 -- Note we allow non-static non-generic types at this stage as further
5224 if Is_Type
(P_Entity
)
5225 and then (Is_Scalar_Type
(P_Entity
) or Is_Array_Type
(P_Entity
))
5226 and then (not Is_Generic_Type
(P_Entity
))
5230 -- Second foldable possibility is an array object (RM 4.9(8))
5232 elsif (Ekind
(P_Entity
) = E_Variable
5234 Ekind
(P_Entity
) = E_Constant
)
5235 and then Is_Array_Type
(Etype
(P_Entity
))
5236 and then (not Is_Generic_Type
(Etype
(P_Entity
)))
5238 P_Type
:= Etype
(P_Entity
);
5240 -- If the entity is an array constant with an unconstrained nominal
5241 -- subtype then get the type from the initial value. If the value has
5242 -- been expanded into assignments, there is no expression and the
5243 -- attribute reference remains dynamic.
5245 -- We could do better here and retrieve the type ???
5247 if Ekind
(P_Entity
) = E_Constant
5248 and then not Is_Constrained
(P_Type
)
5250 if No
(Constant_Value
(P_Entity
)) then
5253 P_Type
:= Etype
(Constant_Value
(P_Entity
));
5257 -- Definite must be folded if the prefix is not a generic type,
5258 -- that is to say if we are within an instantiation. Same processing
5259 -- applies to the GNAT attributes Has_Discriminants, Type_Class,
5260 -- Has_Tagged_Value, and Unconstrained_Array.
5262 elsif (Id
= Attribute_Definite
5264 Id
= Attribute_Has_Access_Values
5266 Id
= Attribute_Has_Discriminants
5268 Id
= Attribute_Has_Tagged_Values
5270 Id
= Attribute_Type_Class
5272 Id
= Attribute_Unconstrained_Array
)
5273 and then not Is_Generic_Type
(P_Entity
)
5277 -- We can fold 'Size applied to a type if the size is known (as happens
5278 -- for a size from an attribute definition clause). At this stage, this
5279 -- can happen only for types (e.g. record types) for which the size is
5280 -- always non-static. We exclude generic types from consideration (since
5281 -- they have bogus sizes set within templates).
5283 elsif Id
= Attribute_Size
5284 and then Is_Type
(P_Entity
)
5285 and then (not Is_Generic_Type
(P_Entity
))
5286 and then Known_Static_RM_Size
(P_Entity
)
5288 Compile_Time_Known_Attribute
(N
, RM_Size
(P_Entity
));
5291 -- We can fold 'Alignment applied to a type if the alignment is known
5292 -- (as happens for an alignment from an attribute definition clause).
5293 -- At this stage, this can happen only for types (e.g. record
5294 -- types) for which the size is always non-static. We exclude
5295 -- generic types from consideration (since they have bogus
5296 -- sizes set within templates).
5298 elsif Id
= Attribute_Alignment
5299 and then Is_Type
(P_Entity
)
5300 and then (not Is_Generic_Type
(P_Entity
))
5301 and then Known_Alignment
(P_Entity
)
5303 Compile_Time_Known_Attribute
(N
, Alignment
(P_Entity
));
5306 -- If this is an access attribute that is known to fail accessibility
5307 -- check, rewrite accordingly.
5309 elsif Attribute_Name
(N
) = Name_Access
5310 and then Raises_Constraint_Error
(N
)
5313 Make_Raise_Program_Error
(Loc
,
5314 Reason
=> PE_Accessibility_Check_Failed
));
5315 Set_Etype
(N
, C_Type
);
5318 -- No other cases are foldable (they certainly aren't static, and at
5319 -- the moment we don't try to fold any cases other than these three).
5326 -- If either attribute or the prefix is Any_Type, then propagate
5327 -- Any_Type to the result and don't do anything else at all.
5329 if P_Type
= Any_Type
5330 or else (Present
(E1
) and then Etype
(E1
) = Any_Type
)
5331 or else (Present
(E2
) and then Etype
(E2
) = Any_Type
)
5333 Set_Etype
(N
, Any_Type
);
5337 -- Scalar subtype case. We have not yet enforced the static requirement
5338 -- of (RM 4.9(7)) and we don't intend to just yet, since there are cases
5339 -- of non-static attribute references (e.g. S'Digits for a non-static
5340 -- floating-point type, which we can compute at compile time).
5342 -- Note: this folding of non-static attributes is not simply a case of
5343 -- optimization. For many of the attributes affected, Gigi cannot handle
5344 -- the attribute and depends on the front end having folded them away.
5346 -- Note: although we don't require staticness at this stage, we do set
5347 -- the Static variable to record the staticness, for easy reference by
5348 -- those attributes where it matters (e.g. Succ and Pred), and also to
5349 -- be used to ensure that non-static folded things are not marked as
5350 -- being static (a check that is done right at the end).
5352 P_Root_Type
:= Root_Type
(P_Type
);
5353 P_Base_Type
:= Base_Type
(P_Type
);
5355 -- If the root type or base type is generic, then we cannot fold. This
5356 -- test is needed because subtypes of generic types are not always
5357 -- marked as being generic themselves (which seems odd???)
5359 if Is_Generic_Type
(P_Root_Type
)
5360 or else Is_Generic_Type
(P_Base_Type
)
5365 if Is_Scalar_Type
(P_Type
) then
5366 Static
:= Is_OK_Static_Subtype
(P_Type
);
5368 -- Array case. We enforce the constrained requirement of (RM 4.9(7-8))
5369 -- since we can't do anything with unconstrained arrays. In addition,
5370 -- only the First, Last and Length attributes are possibly static.
5372 -- Definite, Has_Access_Values, Has_Discriminants, Has_Tagged_Values,
5373 -- Type_Class, and Unconstrained_Array are again exceptions, because
5374 -- they apply as well to unconstrained types.
5376 -- In addition Component_Size is an exception since it is possibly
5377 -- foldable, even though it is never static, and it does apply to
5378 -- unconstrained arrays. Furthermore, it is essential to fold this
5379 -- in the packed case, since otherwise the value will be incorrect.
5381 elsif Id
= Attribute_Definite
5383 Id
= Attribute_Has_Access_Values
5385 Id
= Attribute_Has_Discriminants
5387 Id
= Attribute_Has_Tagged_Values
5389 Id
= Attribute_Type_Class
5391 Id
= Attribute_Unconstrained_Array
5393 Id
= Attribute_Component_Size
5398 if not Is_Constrained
(P_Type
)
5399 or else (Id
/= Attribute_First
and then
5400 Id
/= Attribute_Last
and then
5401 Id
/= Attribute_Length
)
5407 -- The rules in (RM 4.9(7,8)) require a static array, but as in the
5408 -- scalar case, we hold off on enforcing staticness, since there are
5409 -- cases which we can fold at compile time even though they are not
5410 -- static (e.g. 'Length applied to a static index, even though other
5411 -- non-static indexes make the array type non-static). This is only
5412 -- an optimization, but it falls out essentially free, so why not.
5413 -- Again we compute the variable Static for easy reference later
5414 -- (note that no array attributes are static in Ada 83).
5416 Static
:= Ada_Version
>= Ada_95
5417 and then Statically_Denotes_Entity
(P
);
5423 N
:= First_Index
(P_Type
);
5424 while Present
(N
) loop
5425 Static
:= Static
and then Is_Static_Subtype
(Etype
(N
));
5427 -- If however the index type is generic, attributes cannot
5430 if Is_Generic_Type
(Etype
(N
))
5431 and then Id
/= Attribute_Component_Size
5441 -- Check any expressions that are present. Note that these expressions,
5442 -- depending on the particular attribute type, are either part of the
5443 -- attribute designator, or they are arguments in a case where the
5444 -- attribute reference returns a function. In the latter case, the
5445 -- rule in (RM 4.9(22)) applies and in particular requires the type
5446 -- of the expressions to be scalar in order for the attribute to be
5447 -- considered to be static.
5454 while Present
(E
) loop
5456 -- If expression is not static, then the attribute reference
5457 -- result certainly cannot be static.
5459 if not Is_Static_Expression
(E
) then
5463 -- If the result is not known at compile time, or is not of
5464 -- a scalar type, then the result is definitely not static,
5465 -- so we can quit now.
5467 if not Compile_Time_Known_Value
(E
)
5468 or else not Is_Scalar_Type
(Etype
(E
))
5470 -- An odd special case, if this is a Pos attribute, this
5471 -- is where we need to apply a range check since it does
5472 -- not get done anywhere else.
5474 if Id
= Attribute_Pos
then
5475 if Is_Integer_Type
(Etype
(E
)) then
5476 Apply_Range_Check
(E
, Etype
(N
));
5483 -- If the expression raises a constraint error, then so does
5484 -- the attribute reference. We keep going in this case because
5485 -- we are still interested in whether the attribute reference
5486 -- is static even if it is not static.
5488 elsif Raises_Constraint_Error
(E
) then
5489 Set_Raises_Constraint_Error
(N
);
5495 if Raises_Constraint_Error
(Prefix
(N
)) then
5500 -- Deal with the case of a static attribute reference that raises
5501 -- constraint error. The Raises_Constraint_Error flag will already
5502 -- have been set, and the Static flag shows whether the attribute
5503 -- reference is static. In any case we certainly can't fold such an
5504 -- attribute reference.
5506 -- Note that the rewriting of the attribute node with the constraint
5507 -- error node is essential in this case, because otherwise Gigi might
5508 -- blow up on one of the attributes it never expects to see.
5510 -- The constraint_error node must have the type imposed by the context,
5511 -- to avoid spurious errors in the enclosing expression.
5513 if Raises_Constraint_Error
(N
) then
5515 Make_Raise_Constraint_Error
(Sloc
(N
),
5516 Reason
=> CE_Range_Check_Failed
);
5517 Set_Etype
(CE_Node
, Etype
(N
));
5518 Set_Raises_Constraint_Error
(CE_Node
);
5520 Rewrite
(N
, Relocate_Node
(CE_Node
));
5521 Set_Is_Static_Expression
(N
, Static
);
5525 -- At this point we have a potentially foldable attribute reference.
5526 -- If Static is set, then the attribute reference definitely obeys
5527 -- the requirements in (RM 4.9(7,8,22)), and it definitely can be
5528 -- folded. If Static is not set, then the attribute may or may not
5529 -- be foldable, and the individual attribute processing routines
5530 -- test Static as required in cases where it makes a difference.
5532 -- In the case where Static is not set, we do know that all the
5533 -- expressions present are at least known at compile time (we
5534 -- assumed above that if this was not the case, then there was
5535 -- no hope of static evaluation). However, we did not require
5536 -- that the bounds of the prefix type be compile time known,
5537 -- let alone static). That's because there are many attributes
5538 -- that can be computed at compile time on non-static subtypes,
5539 -- even though such references are not static expressions.
5547 when Attribute_Adjacent
=>
5550 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
5556 when Attribute_Aft
=>
5557 Fold_Uint
(N
, UI_From_Int
(Aft_Value
), True);
5563 when Attribute_Alignment
=> Alignment_Block
: declare
5564 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
5567 -- Fold if alignment is set and not otherwise
5569 if Known_Alignment
(P_TypeA
) then
5570 Fold_Uint
(N
, Alignment
(P_TypeA
), Is_Discrete_Type
(P_TypeA
));
5572 end Alignment_Block
;
5578 -- Can only be folded in No_Ast_Handler case
5580 when Attribute_AST_Entry
=>
5581 if not Is_AST_Entry
(P_Entity
) then
5583 New_Occurrence_Of
(RTE
(RE_No_AST_Handler
), Loc
));
5592 -- Bit can never be folded
5594 when Attribute_Bit
=>
5601 -- Body_version can never be static
5603 when Attribute_Body_Version
=>
5610 when Attribute_Ceiling
=>
5612 Eval_Fat
.Ceiling
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
5614 --------------------
5615 -- Component_Size --
5616 --------------------
5618 when Attribute_Component_Size
=>
5619 if Known_Static_Component_Size
(P_Type
) then
5620 Fold_Uint
(N
, Component_Size
(P_Type
), False);
5627 when Attribute_Compose
=>
5630 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)),
5637 -- Constrained is never folded for now, there may be cases that
5638 -- could be handled at compile time. To be looked at later.
5640 when Attribute_Constrained
=>
5647 when Attribute_Copy_Sign
=>
5650 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
5656 when Attribute_Delta
=>
5657 Fold_Ureal
(N
, Delta_Value
(P_Type
), True);
5663 when Attribute_Definite
=>
5664 Rewrite
(N
, New_Occurrence_Of
(
5665 Boolean_Literals
(not Is_Indefinite_Subtype
(P_Entity
)), Loc
));
5666 Analyze_And_Resolve
(N
, Standard_Boolean
);
5672 when Attribute_Denorm
=>
5674 (N
, UI_From_Int
(Boolean'Pos (Denorm_On_Target
)), True);
5680 when Attribute_Digits
=>
5681 Fold_Uint
(N
, Digits_Value
(P_Type
), True);
5687 when Attribute_Emax
=>
5689 -- Ada 83 attribute is defined as (RM83 3.5.8)
5691 -- T'Emax = 4 * T'Mantissa
5693 Fold_Uint
(N
, 4 * Mantissa
, True);
5699 when Attribute_Enum_Rep
=>
5701 -- For an enumeration type with a non-standard representation use
5702 -- the Enumeration_Rep field of the proper constant. Note that this
5703 -- will not work for types Character/Wide_[Wide-]Character, since no
5704 -- real entities are created for the enumeration literals, but that
5705 -- does not matter since these two types do not have non-standard
5706 -- representations anyway.
5708 if Is_Enumeration_Type
(P_Type
)
5709 and then Has_Non_Standard_Rep
(P_Type
)
5711 Fold_Uint
(N
, Enumeration_Rep
(Expr_Value_E
(E1
)), Static
);
5713 -- For enumeration types with standard representations and all
5714 -- other cases (i.e. all integer and modular types), Enum_Rep
5715 -- is equivalent to Pos.
5718 Fold_Uint
(N
, Expr_Value
(E1
), Static
);
5725 when Attribute_Enum_Val
=> Enum_Val
: declare
5729 -- We have something like Enum_Type'Enum_Val (23), so search for a
5730 -- corresponding value in the list of Enum_Rep values for the type.
5732 Lit
:= First_Literal
(P_Base_Type
);
5734 if Enumeration_Rep
(Lit
) = Expr_Value
(E1
) then
5735 Fold_Uint
(N
, Enumeration_Pos
(Lit
), Static
);
5742 Apply_Compile_Time_Constraint_Error
5743 (N
, "no representation value matches",
5744 CE_Range_Check_Failed
,
5745 Warn
=> not Static
);
5755 when Attribute_Epsilon
=>
5757 -- Ada 83 attribute is defined as (RM83 3.5.8)
5759 -- T'Epsilon = 2.0**(1 - T'Mantissa)
5761 Fold_Ureal
(N
, Ureal_2
** (1 - Mantissa
), True);
5767 when Attribute_Exponent
=>
5769 Eval_Fat
.Exponent
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
5775 when Attribute_First
=> First_Attr
:
5779 if Compile_Time_Known_Value
(Lo_Bound
) then
5780 if Is_Real_Type
(P_Type
) then
5781 Fold_Ureal
(N
, Expr_Value_R
(Lo_Bound
), Static
);
5783 Fold_Uint
(N
, Expr_Value
(Lo_Bound
), Static
);
5792 when Attribute_Fixed_Value
=>
5799 when Attribute_Floor
=>
5801 Eval_Fat
.Floor
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
5807 when Attribute_Fore
=>
5808 if Compile_Time_Known_Bounds
(P_Type
) then
5809 Fold_Uint
(N
, UI_From_Int
(Fore_Value
), Static
);
5816 when Attribute_Fraction
=>
5818 Eval_Fat
.Fraction
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
5820 -----------------------
5821 -- Has_Access_Values --
5822 -----------------------
5824 when Attribute_Has_Access_Values
=>
5825 Rewrite
(N
, New_Occurrence_Of
5826 (Boolean_Literals
(Has_Access_Values
(P_Root_Type
)), Loc
));
5827 Analyze_And_Resolve
(N
, Standard_Boolean
);
5829 -----------------------
5830 -- Has_Discriminants --
5831 -----------------------
5833 when Attribute_Has_Discriminants
=>
5834 Rewrite
(N
, New_Occurrence_Of
(
5835 Boolean_Literals
(Has_Discriminants
(P_Entity
)), Loc
));
5836 Analyze_And_Resolve
(N
, Standard_Boolean
);
5838 -----------------------
5839 -- Has_Tagged_Values --
5840 -----------------------
5842 when Attribute_Has_Tagged_Values
=>
5843 Rewrite
(N
, New_Occurrence_Of
5844 (Boolean_Literals
(Has_Tagged_Component
(P_Root_Type
)), Loc
));
5845 Analyze_And_Resolve
(N
, Standard_Boolean
);
5851 when Attribute_Identity
=>
5858 -- Image is a scalar attribute, but is never static, because it is
5859 -- not a static function (having a non-scalar argument (RM 4.9(22))
5860 -- However, we can constant-fold the image of an enumeration literal
5861 -- if names are available.
5863 when Attribute_Image
=>
5864 if Is_Entity_Name
(E1
)
5865 and then Ekind
(Entity
(E1
)) = E_Enumeration_Literal
5866 and then not Discard_Names
(First_Subtype
(Etype
(E1
)))
5867 and then not Global_Discard_Names
5870 Lit
: constant Entity_Id
:= Entity
(E1
);
5874 Get_Unqualified_Decoded_Name_String
(Chars
(Lit
));
5875 Set_Casing
(All_Upper_Case
);
5876 Store_String_Chars
(Name_Buffer
(1 .. Name_Len
));
5878 Rewrite
(N
, Make_String_Literal
(Loc
, Strval
=> Str
));
5879 Analyze_And_Resolve
(N
, Standard_String
);
5880 Set_Is_Static_Expression
(N
, False);
5888 -- Img is a scalar attribute, but is never static, because it is
5889 -- not a static function (having a non-scalar argument (RM 4.9(22))
5891 when Attribute_Img
=>
5898 -- We never try to fold Integer_Value (though perhaps we could???)
5900 when Attribute_Integer_Value
=>
5907 -- Invalid_Value is a scalar attribute that is never static, because
5908 -- the value is by design out of range.
5910 when Attribute_Invalid_Value
=>
5917 when Attribute_Large
=>
5919 -- For fixed-point, we use the identity:
5921 -- T'Large = (2.0**T'Mantissa - 1.0) * T'Small
5923 if Is_Fixed_Point_Type
(P_Type
) then
5925 Make_Op_Multiply
(Loc
,
5927 Make_Op_Subtract
(Loc
,
5931 Make_Real_Literal
(Loc
, Ureal_2
),
5933 Make_Attribute_Reference
(Loc
,
5935 Attribute_Name
=> Name_Mantissa
)),
5936 Right_Opnd
=> Make_Real_Literal
(Loc
, Ureal_1
)),
5939 Make_Real_Literal
(Loc
, Small_Value
(Entity
(P
)))));
5941 Analyze_And_Resolve
(N
, C_Type
);
5943 -- Floating-point (Ada 83 compatibility)
5946 -- Ada 83 attribute is defined as (RM83 3.5.8)
5948 -- T'Large = 2.0**T'Emax * (1.0 - 2.0**(-T'Mantissa))
5952 -- T'Emax = 4 * T'Mantissa
5955 Ureal_2
** (4 * Mantissa
) * (Ureal_1
- Ureal_2
** (-Mantissa
)),
5963 when Attribute_Last
=> Last
:
5967 if Compile_Time_Known_Value
(Hi_Bound
) then
5968 if Is_Real_Type
(P_Type
) then
5969 Fold_Ureal
(N
, Expr_Value_R
(Hi_Bound
), Static
);
5971 Fold_Uint
(N
, Expr_Value
(Hi_Bound
), Static
);
5980 when Attribute_Leading_Part
=>
5982 Eval_Fat
.Leading_Part
5983 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)), Static
);
5989 when Attribute_Length
=> Length
: declare
5993 -- In the case of a generic index type, the bounds may
5994 -- appear static but the computation is not meaningful,
5995 -- and may generate a spurious warning.
5997 Ind
:= First_Index
(P_Type
);
5999 while Present
(Ind
) loop
6000 if Is_Generic_Type
(Etype
(Ind
)) then
6009 if Compile_Time_Known_Value
(Lo_Bound
)
6010 and then Compile_Time_Known_Value
(Hi_Bound
)
6013 UI_Max
(0, 1 + (Expr_Value
(Hi_Bound
) - Expr_Value
(Lo_Bound
))),
6022 when Attribute_Machine
=>
6025 (P_Root_Type
, Expr_Value_R
(E1
), Eval_Fat
.Round
, N
),
6032 when Attribute_Machine_Emax
=>
6033 Float_Attribute_Universal_Integer
(
6041 AAMPL_Machine_Emax
);
6047 when Attribute_Machine_Emin
=>
6048 Float_Attribute_Universal_Integer
(
6056 AAMPL_Machine_Emin
);
6058 ----------------------
6059 -- Machine_Mantissa --
6060 ----------------------
6062 when Attribute_Machine_Mantissa
=>
6063 Float_Attribute_Universal_Integer
(
6064 IEEES_Machine_Mantissa
,
6065 IEEEL_Machine_Mantissa
,
6066 IEEEX_Machine_Mantissa
,
6067 VAXFF_Machine_Mantissa
,
6068 VAXDF_Machine_Mantissa
,
6069 VAXGF_Machine_Mantissa
,
6070 AAMPS_Machine_Mantissa
,
6071 AAMPL_Machine_Mantissa
);
6073 -----------------------
6074 -- Machine_Overflows --
6075 -----------------------
6077 when Attribute_Machine_Overflows
=>
6079 -- Always true for fixed-point
6081 if Is_Fixed_Point_Type
(P_Type
) then
6082 Fold_Uint
(N
, True_Value
, True);
6084 -- Floating point case
6088 UI_From_Int
(Boolean'Pos (Machine_Overflows_On_Target
)),
6096 when Attribute_Machine_Radix
=>
6097 if Is_Fixed_Point_Type
(P_Type
) then
6098 if Is_Decimal_Fixed_Point_Type
(P_Type
)
6099 and then Machine_Radix_10
(P_Type
)
6101 Fold_Uint
(N
, Uint_10
, True);
6103 Fold_Uint
(N
, Uint_2
, True);
6106 -- All floating-point type always have radix 2
6109 Fold_Uint
(N
, Uint_2
, True);
6112 ----------------------
6113 -- Machine_Rounding --
6114 ----------------------
6116 -- Note: for the folding case, it is fine to treat Machine_Rounding
6117 -- exactly the same way as Rounding, since this is one of the allowed
6118 -- behaviors, and performance is not an issue here. It might be a bit
6119 -- better to give the same result as it would give at run-time, even
6120 -- though the non-determinism is certainly permitted.
6122 when Attribute_Machine_Rounding
=>
6124 Eval_Fat
.Rounding
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
6126 --------------------
6127 -- Machine_Rounds --
6128 --------------------
6130 when Attribute_Machine_Rounds
=>
6132 -- Always False for fixed-point
6134 if Is_Fixed_Point_Type
(P_Type
) then
6135 Fold_Uint
(N
, False_Value
, True);
6137 -- Else yield proper floating-point result
6141 (N
, UI_From_Int
(Boolean'Pos (Machine_Rounds_On_Target
)), True);
6148 -- Note: Machine_Size is identical to Object_Size
6150 when Attribute_Machine_Size
=> Machine_Size
: declare
6151 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
6154 if Known_Esize
(P_TypeA
) then
6155 Fold_Uint
(N
, Esize
(P_TypeA
), True);
6163 when Attribute_Mantissa
=>
6165 -- Fixed-point mantissa
6167 if Is_Fixed_Point_Type
(P_Type
) then
6169 -- Compile time foldable case
6171 if Compile_Time_Known_Value
(Type_Low_Bound
(P_Type
))
6173 Compile_Time_Known_Value
(Type_High_Bound
(P_Type
))
6175 -- The calculation of the obsolete Ada 83 attribute Mantissa
6176 -- is annoying, because of AI00143, quoted here:
6178 -- !question 84-01-10
6180 -- Consider the model numbers for F:
6182 -- type F is delta 1.0 range -7.0 .. 8.0;
6184 -- The wording requires that F'MANTISSA be the SMALLEST
6185 -- integer number for which each bound of the specified
6186 -- range is either a model number or lies at most small
6187 -- distant from a model number. This means F'MANTISSA
6188 -- is required to be 3 since the range -7.0 .. 7.0 fits
6189 -- in 3 signed bits, and 8 is "at most" 1.0 from a model
6190 -- number, namely, 7. Is this analysis correct? Note that
6191 -- this implies the upper bound of the range is not
6192 -- represented as a model number.
6194 -- !response 84-03-17
6196 -- The analysis is correct. The upper and lower bounds for
6197 -- a fixed point type can lie outside the range of model
6208 LBound
:= Expr_Value_R
(Type_Low_Bound
(P_Type
));
6209 UBound
:= Expr_Value_R
(Type_High_Bound
(P_Type
));
6210 Bound
:= UR_Max
(UR_Abs
(LBound
), UR_Abs
(UBound
));
6211 Max_Man
:= UR_Trunc
(Bound
/ Small_Value
(P_Type
));
6213 -- If the Bound is exactly a model number, i.e. a multiple
6214 -- of Small, then we back it off by one to get the integer
6215 -- value that must be representable.
6217 if Small_Value
(P_Type
) * Max_Man
= Bound
then
6218 Max_Man
:= Max_Man
- 1;
6221 -- Now find corresponding size = Mantissa value
6224 while 2 ** Siz
< Max_Man
loop
6228 Fold_Uint
(N
, Siz
, True);
6232 -- The case of dynamic bounds cannot be evaluated at compile
6233 -- time. Instead we use a runtime routine (see Exp_Attr).
6238 -- Floating-point Mantissa
6241 Fold_Uint
(N
, Mantissa
, True);
6248 when Attribute_Max
=> Max
:
6250 if Is_Real_Type
(P_Type
) then
6252 (N
, UR_Max
(Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
6254 Fold_Uint
(N
, UI_Max
(Expr_Value
(E1
), Expr_Value
(E2
)), Static
);
6258 ----------------------------------
6259 -- Max_Size_In_Storage_Elements --
6260 ----------------------------------
6262 -- Max_Size_In_Storage_Elements is simply the Size rounded up to a
6263 -- Storage_Unit boundary. We can fold any cases for which the size
6264 -- is known by the front end.
6266 when Attribute_Max_Size_In_Storage_Elements
=>
6267 if Known_Esize
(P_Type
) then
6269 (Esize
(P_Type
) + System_Storage_Unit
- 1) /
6270 System_Storage_Unit
,
6274 --------------------
6275 -- Mechanism_Code --
6276 --------------------
6278 when Attribute_Mechanism_Code
=>
6282 Mech
: Mechanism_Type
;
6286 Mech
:= Mechanism
(P_Entity
);
6289 Val
:= UI_To_Int
(Expr_Value
(E1
));
6291 Formal
:= First_Formal
(P_Entity
);
6292 for J
in 1 .. Val
- 1 loop
6293 Next_Formal
(Formal
);
6295 Mech
:= Mechanism
(Formal
);
6299 Fold_Uint
(N
, UI_From_Int
(Int
(-Mech
)), True);
6307 when Attribute_Min
=> Min
:
6309 if Is_Real_Type
(P_Type
) then
6311 (N
, UR_Min
(Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
6314 (N
, UI_Min
(Expr_Value
(E1
), Expr_Value
(E2
)), Static
);
6322 when Attribute_Mod
=>
6324 (N
, UI_Mod
(Expr_Value
(E1
), Modulus
(P_Base_Type
)), Static
);
6330 when Attribute_Model
=>
6332 Eval_Fat
.Model
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
6338 when Attribute_Model_Emin
=>
6339 Float_Attribute_Universal_Integer
(
6353 when Attribute_Model_Epsilon
=>
6354 Float_Attribute_Universal_Real
(
6355 IEEES_Model_Epsilon
'Universal_Literal_String,
6356 IEEEL_Model_Epsilon
'Universal_Literal_String,
6357 IEEEX_Model_Epsilon
'Universal_Literal_String,
6358 VAXFF_Model_Epsilon
'Universal_Literal_String,
6359 VAXDF_Model_Epsilon
'Universal_Literal_String,
6360 VAXGF_Model_Epsilon
'Universal_Literal_String,
6361 AAMPS_Model_Epsilon
'Universal_Literal_String,
6362 AAMPL_Model_Epsilon
'Universal_Literal_String);
6364 --------------------
6365 -- Model_Mantissa --
6366 --------------------
6368 when Attribute_Model_Mantissa
=>
6369 Float_Attribute_Universal_Integer
(
6370 IEEES_Model_Mantissa
,
6371 IEEEL_Model_Mantissa
,
6372 IEEEX_Model_Mantissa
,
6373 VAXFF_Model_Mantissa
,
6374 VAXDF_Model_Mantissa
,
6375 VAXGF_Model_Mantissa
,
6376 AAMPS_Model_Mantissa
,
6377 AAMPL_Model_Mantissa
);
6383 when Attribute_Model_Small
=>
6384 Float_Attribute_Universal_Real
(
6385 IEEES_Model_Small
'Universal_Literal_String,
6386 IEEEL_Model_Small
'Universal_Literal_String,
6387 IEEEX_Model_Small
'Universal_Literal_String,
6388 VAXFF_Model_Small
'Universal_Literal_String,
6389 VAXDF_Model_Small
'Universal_Literal_String,
6390 VAXGF_Model_Small
'Universal_Literal_String,
6391 AAMPS_Model_Small
'Universal_Literal_String,
6392 AAMPL_Model_Small
'Universal_Literal_String);
6398 when Attribute_Modulus
=>
6399 Fold_Uint
(N
, Modulus
(P_Type
), True);
6401 --------------------
6402 -- Null_Parameter --
6403 --------------------
6405 -- Cannot fold, we know the value sort of, but the whole point is
6406 -- that there is no way to talk about this imaginary value except
6407 -- by using the attribute, so we leave it the way it is.
6409 when Attribute_Null_Parameter
=>
6416 -- The Object_Size attribute for a type returns the Esize of the
6417 -- type and can be folded if this value is known.
6419 when Attribute_Object_Size
=> Object_Size
: declare
6420 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
6423 if Known_Esize
(P_TypeA
) then
6424 Fold_Uint
(N
, Esize
(P_TypeA
), True);
6428 -------------------------
6429 -- Passed_By_Reference --
6430 -------------------------
6432 -- Scalar types are never passed by reference
6434 when Attribute_Passed_By_Reference
=>
6435 Fold_Uint
(N
, False_Value
, True);
6441 when Attribute_Pos
=>
6442 Fold_Uint
(N
, Expr_Value
(E1
), True);
6448 when Attribute_Pred
=> Pred
:
6450 -- Floating-point case
6452 if Is_Floating_Point_Type
(P_Type
) then
6454 Eval_Fat
.Pred
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
6458 elsif Is_Fixed_Point_Type
(P_Type
) then
6460 Expr_Value_R
(E1
) - Small_Value
(P_Type
), True);
6462 -- Modular integer case (wraps)
6464 elsif Is_Modular_Integer_Type
(P_Type
) then
6465 Fold_Uint
(N
, (Expr_Value
(E1
) - 1) mod Modulus
(P_Type
), Static
);
6467 -- Other scalar cases
6470 pragma Assert
(Is_Scalar_Type
(P_Type
));
6472 if Is_Enumeration_Type
(P_Type
)
6473 and then Expr_Value
(E1
) =
6474 Expr_Value
(Type_Low_Bound
(P_Base_Type
))
6476 Apply_Compile_Time_Constraint_Error
6477 (N
, "Pred of `&''First`",
6478 CE_Overflow_Check_Failed
,
6480 Warn
=> not Static
);
6486 Fold_Uint
(N
, Expr_Value
(E1
) - 1, Static
);
6494 -- No processing required, because by this stage, Range has been
6495 -- replaced by First .. Last, so this branch can never be taken.
6497 when Attribute_Range
=>
6498 raise Program_Error
;
6504 when Attribute_Range_Length
=>
6507 if Compile_Time_Known_Value
(Hi_Bound
)
6508 and then Compile_Time_Known_Value
(Lo_Bound
)
6512 (0, Expr_Value
(Hi_Bound
) - Expr_Value
(Lo_Bound
) + 1),
6520 when Attribute_Remainder
=> Remainder
: declare
6521 X
: constant Ureal
:= Expr_Value_R
(E1
);
6522 Y
: constant Ureal
:= Expr_Value_R
(E2
);
6525 if UR_Is_Zero
(Y
) then
6526 Apply_Compile_Time_Constraint_Error
6527 (N
, "division by zero in Remainder",
6528 CE_Overflow_Check_Failed
,
6529 Warn
=> not Static
);
6535 Fold_Ureal
(N
, Eval_Fat
.Remainder
(P_Root_Type
, X
, Y
), Static
);
6542 when Attribute_Round
=> Round
:
6548 -- First we get the (exact result) in units of small
6550 Sr
:= Expr_Value_R
(E1
) / Small_Value
(C_Type
);
6552 -- Now round that exactly to an integer
6554 Si
:= UR_To_Uint
(Sr
);
6556 -- Finally the result is obtained by converting back to real
6558 Fold_Ureal
(N
, Si
* Small_Value
(C_Type
), Static
);
6565 when Attribute_Rounding
=>
6567 Eval_Fat
.Rounding
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
6573 when Attribute_Safe_Emax
=>
6574 Float_Attribute_Universal_Integer
(
6588 when Attribute_Safe_First
=>
6589 Float_Attribute_Universal_Real
(
6590 IEEES_Safe_First
'Universal_Literal_String,
6591 IEEEL_Safe_First
'Universal_Literal_String,
6592 IEEEX_Safe_First
'Universal_Literal_String,
6593 VAXFF_Safe_First
'Universal_Literal_String,
6594 VAXDF_Safe_First
'Universal_Literal_String,
6595 VAXGF_Safe_First
'Universal_Literal_String,
6596 AAMPS_Safe_First
'Universal_Literal_String,
6597 AAMPL_Safe_First
'Universal_Literal_String);
6603 when Attribute_Safe_Large
=>
6604 if Is_Fixed_Point_Type
(P_Type
) then
6606 (N
, Expr_Value_R
(Type_High_Bound
(P_Base_Type
)), Static
);
6608 Float_Attribute_Universal_Real
(
6609 IEEES_Safe_Large
'Universal_Literal_String,
6610 IEEEL_Safe_Large
'Universal_Literal_String,
6611 IEEEX_Safe_Large
'Universal_Literal_String,
6612 VAXFF_Safe_Large
'Universal_Literal_String,
6613 VAXDF_Safe_Large
'Universal_Literal_String,
6614 VAXGF_Safe_Large
'Universal_Literal_String,
6615 AAMPS_Safe_Large
'Universal_Literal_String,
6616 AAMPL_Safe_Large
'Universal_Literal_String);
6623 when Attribute_Safe_Last
=>
6624 Float_Attribute_Universal_Real
(
6625 IEEES_Safe_Last
'Universal_Literal_String,
6626 IEEEL_Safe_Last
'Universal_Literal_String,
6627 IEEEX_Safe_Last
'Universal_Literal_String,
6628 VAXFF_Safe_Last
'Universal_Literal_String,
6629 VAXDF_Safe_Last
'Universal_Literal_String,
6630 VAXGF_Safe_Last
'Universal_Literal_String,
6631 AAMPS_Safe_Last
'Universal_Literal_String,
6632 AAMPL_Safe_Last
'Universal_Literal_String);
6638 when Attribute_Safe_Small
=>
6640 -- In Ada 95, the old Ada 83 attribute Safe_Small is redundant
6641 -- for fixed-point, since is the same as Small, but we implement
6642 -- it for backwards compatibility.
6644 if Is_Fixed_Point_Type
(P_Type
) then
6645 Fold_Ureal
(N
, Small_Value
(P_Type
), Static
);
6647 -- Ada 83 Safe_Small for floating-point cases
6650 Float_Attribute_Universal_Real
(
6651 IEEES_Safe_Small
'Universal_Literal_String,
6652 IEEEL_Safe_Small
'Universal_Literal_String,
6653 IEEEX_Safe_Small
'Universal_Literal_String,
6654 VAXFF_Safe_Small
'Universal_Literal_String,
6655 VAXDF_Safe_Small
'Universal_Literal_String,
6656 VAXGF_Safe_Small
'Universal_Literal_String,
6657 AAMPS_Safe_Small
'Universal_Literal_String,
6658 AAMPL_Safe_Small
'Universal_Literal_String);
6665 when Attribute_Scale
=>
6666 Fold_Uint
(N
, Scale_Value
(P_Type
), True);
6672 when Attribute_Scaling
=>
6675 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)), Static
);
6681 when Attribute_Signed_Zeros
=>
6683 (N
, UI_From_Int
(Boolean'Pos (Signed_Zeros_On_Target
)), Static
);
6689 -- Size attribute returns the RM size. All scalar types can be folded,
6690 -- as well as any types for which the size is known by the front end,
6691 -- including any type for which a size attribute is specified.
6693 when Attribute_Size | Attribute_VADS_Size
=> Size
: declare
6694 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
6697 if RM_Size
(P_TypeA
) /= Uint_0
then
6701 if Id
= Attribute_VADS_Size
or else Use_VADS_Size
then
6703 S
: constant Node_Id
:= Size_Clause
(P_TypeA
);
6706 -- If a size clause applies, then use the size from it.
6707 -- This is one of the rare cases where we can use the
6708 -- Size_Clause field for a subtype when Has_Size_Clause
6709 -- is False. Consider:
6711 -- type x is range 1 .. 64;
6712 -- for x'size use 12;
6713 -- subtype y is x range 0 .. 3;
6715 -- Here y has a size clause inherited from x, but normally
6716 -- it does not apply, and y'size is 2. However, y'VADS_Size
6717 -- is indeed 12 and not 2.
6720 and then Is_OK_Static_Expression
(Expression
(S
))
6722 Fold_Uint
(N
, Expr_Value
(Expression
(S
)), True);
6724 -- If no size is specified, then we simply use the object
6725 -- size in the VADS_Size case (e.g. Natural'Size is equal
6726 -- to Integer'Size, not one less).
6729 Fold_Uint
(N
, Esize
(P_TypeA
), True);
6733 -- Normal case (Size) in which case we want the RM_Size
6738 Static
and then Is_Discrete_Type
(P_TypeA
));
6747 when Attribute_Small
=>
6749 -- The floating-point case is present only for Ada 83 compatibility.
6750 -- Note that strictly this is an illegal addition, since we are
6751 -- extending an Ada 95 defined attribute, but we anticipate an
6752 -- ARG ruling that will permit this.
6754 if Is_Floating_Point_Type
(P_Type
) then
6756 -- Ada 83 attribute is defined as (RM83 3.5.8)
6758 -- T'Small = 2.0**(-T'Emax - 1)
6762 -- T'Emax = 4 * T'Mantissa
6764 Fold_Ureal
(N
, Ureal_2
** ((-(4 * Mantissa
)) - 1), Static
);
6766 -- Normal Ada 95 fixed-point case
6769 Fold_Ureal
(N
, Small_Value
(P_Type
), True);
6776 when Attribute_Stream_Size
=>
6783 when Attribute_Succ
=> Succ
:
6785 -- Floating-point case
6787 if Is_Floating_Point_Type
(P_Type
) then
6789 Eval_Fat
.Succ
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
6793 elsif Is_Fixed_Point_Type
(P_Type
) then
6795 Expr_Value_R
(E1
) + Small_Value
(P_Type
), Static
);
6797 -- Modular integer case (wraps)
6799 elsif Is_Modular_Integer_Type
(P_Type
) then
6800 Fold_Uint
(N
, (Expr_Value
(E1
) + 1) mod Modulus
(P_Type
), Static
);
6802 -- Other scalar cases
6805 pragma Assert
(Is_Scalar_Type
(P_Type
));
6807 if Is_Enumeration_Type
(P_Type
)
6808 and then Expr_Value
(E1
) =
6809 Expr_Value
(Type_High_Bound
(P_Base_Type
))
6811 Apply_Compile_Time_Constraint_Error
6812 (N
, "Succ of `&''Last`",
6813 CE_Overflow_Check_Failed
,
6815 Warn
=> not Static
);
6820 Fold_Uint
(N
, Expr_Value
(E1
) + 1, Static
);
6829 when Attribute_Truncation
=>
6831 Eval_Fat
.Truncation
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
6837 when Attribute_Type_Class
=> Type_Class
: declare
6838 Typ
: constant Entity_Id
:= Underlying_Type
(P_Base_Type
);
6842 if Is_Descendent_Of_Address
(Typ
) then
6843 Id
:= RE_Type_Class_Address
;
6845 elsif Is_Enumeration_Type
(Typ
) then
6846 Id
:= RE_Type_Class_Enumeration
;
6848 elsif Is_Integer_Type
(Typ
) then
6849 Id
:= RE_Type_Class_Integer
;
6851 elsif Is_Fixed_Point_Type
(Typ
) then
6852 Id
:= RE_Type_Class_Fixed_Point
;
6854 elsif Is_Floating_Point_Type
(Typ
) then
6855 Id
:= RE_Type_Class_Floating_Point
;
6857 elsif Is_Array_Type
(Typ
) then
6858 Id
:= RE_Type_Class_Array
;
6860 elsif Is_Record_Type
(Typ
) then
6861 Id
:= RE_Type_Class_Record
;
6863 elsif Is_Access_Type
(Typ
) then
6864 Id
:= RE_Type_Class_Access
;
6866 elsif Is_Enumeration_Type
(Typ
) then
6867 Id
:= RE_Type_Class_Enumeration
;
6869 elsif Is_Task_Type
(Typ
) then
6870 Id
:= RE_Type_Class_Task
;
6872 -- We treat protected types like task types. It would make more
6873 -- sense to have another enumeration value, but after all the
6874 -- whole point of this feature is to be exactly DEC compatible,
6875 -- and changing the type Type_Class would not meet this requirement.
6877 elsif Is_Protected_Type
(Typ
) then
6878 Id
:= RE_Type_Class_Task
;
6880 -- Not clear if there are any other possibilities, but if there
6881 -- are, then we will treat them as the address case.
6884 Id
:= RE_Type_Class_Address
;
6887 Rewrite
(N
, New_Occurrence_Of
(RTE
(Id
), Loc
));
6890 -----------------------
6891 -- Unbiased_Rounding --
6892 -----------------------
6894 when Attribute_Unbiased_Rounding
=>
6896 Eval_Fat
.Unbiased_Rounding
(P_Root_Type
, Expr_Value_R
(E1
)),
6899 -------------------------
6900 -- Unconstrained_Array --
6901 -------------------------
6903 when Attribute_Unconstrained_Array
=> Unconstrained_Array
: declare
6904 Typ
: constant Entity_Id
:= Underlying_Type
(P_Type
);
6907 Rewrite
(N
, New_Occurrence_Of
(
6909 Is_Array_Type
(P_Type
)
6910 and then not Is_Constrained
(Typ
)), Loc
));
6912 -- Analyze and resolve as boolean, note that this attribute is
6913 -- a static attribute in GNAT.
6915 Analyze_And_Resolve
(N
, Standard_Boolean
);
6917 end Unconstrained_Array
;
6923 -- Processing is shared with Size
6929 when Attribute_Val
=> Val
:
6931 if Expr_Value
(E1
) < Expr_Value
(Type_Low_Bound
(P_Base_Type
))
6933 Expr_Value
(E1
) > Expr_Value
(Type_High_Bound
(P_Base_Type
))
6935 Apply_Compile_Time_Constraint_Error
6936 (N
, "Val expression out of range",
6937 CE_Range_Check_Failed
,
6938 Warn
=> not Static
);
6944 Fold_Uint
(N
, Expr_Value
(E1
), Static
);
6952 -- The Value_Size attribute for a type returns the RM size of the
6953 -- type. This an always be folded for scalar types, and can also
6954 -- be folded for non-scalar types if the size is set.
6956 when Attribute_Value_Size
=> Value_Size
: declare
6957 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
6959 if RM_Size
(P_TypeA
) /= Uint_0
then
6960 Fold_Uint
(N
, RM_Size
(P_TypeA
), True);
6968 -- Version can never be static
6970 when Attribute_Version
=>
6977 -- Wide_Image is a scalar attribute, but is never static, because it
6978 -- is not a static function (having a non-scalar argument (RM 4.9(22))
6980 when Attribute_Wide_Image
=>
6983 ---------------------
6984 -- Wide_Wide_Image --
6985 ---------------------
6987 -- Wide_Wide_Image is a scalar attribute but is never static, because it
6988 -- is not a static function (having a non-scalar argument (RM 4.9(22)).
6990 when Attribute_Wide_Wide_Image
=>
6993 ---------------------
6994 -- Wide_Wide_Width --
6995 ---------------------
6997 -- Processing for Wide_Wide_Width is combined with Width
7003 -- Processing for Wide_Width is combined with Width
7009 -- This processing also handles the case of Wide_[Wide_]Width
7011 when Attribute_Width |
7012 Attribute_Wide_Width |
7013 Attribute_Wide_Wide_Width
=> Width
:
7015 if Compile_Time_Known_Bounds
(P_Type
) then
7017 -- Floating-point types
7019 if Is_Floating_Point_Type
(P_Type
) then
7021 -- Width is zero for a null range (RM 3.5 (38))
7023 if Expr_Value_R
(Type_High_Bound
(P_Type
)) <
7024 Expr_Value_R
(Type_Low_Bound
(P_Type
))
7026 Fold_Uint
(N
, Uint_0
, True);
7029 -- For floating-point, we have +N.dddE+nnn where length
7030 -- of ddd is determined by type'Digits - 1, but is one
7031 -- if Digits is one (RM 3.5 (33)).
7033 -- nnn is set to 2 for Short_Float and Float (32 bit
7034 -- floats), and 3 for Long_Float and Long_Long_Float.
7035 -- For machines where Long_Long_Float is the IEEE
7036 -- extended precision type, the exponent takes 4 digits.
7040 Int
'Max (2, UI_To_Int
(Digits_Value
(P_Type
)));
7043 if Esize
(P_Type
) <= 32 then
7045 elsif Esize
(P_Type
) = 64 then
7051 Fold_Uint
(N
, UI_From_Int
(Len
), True);
7055 -- Fixed-point types
7057 elsif Is_Fixed_Point_Type
(P_Type
) then
7059 -- Width is zero for a null range (RM 3.5 (38))
7061 if Expr_Value
(Type_High_Bound
(P_Type
)) <
7062 Expr_Value
(Type_Low_Bound
(P_Type
))
7064 Fold_Uint
(N
, Uint_0
, True);
7066 -- The non-null case depends on the specific real type
7069 -- For fixed-point type width is Fore + 1 + Aft (RM 3.5(34))
7072 (N
, UI_From_Int
(Fore_Value
+ 1 + Aft_Value
), True);
7079 R
: constant Entity_Id
:= Root_Type
(P_Type
);
7080 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(P_Type
));
7081 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(P_Type
));
7094 -- Width for types derived from Standard.Character
7095 -- and Standard.Wide_[Wide_]Character.
7097 elsif Is_Standard_Character_Type
(P_Type
) then
7100 -- Set W larger if needed
7102 for J
in UI_To_Int
(Lo
) .. UI_To_Int
(Hi
) loop
7104 -- All wide characters look like Hex_hhhhhhhh
7110 C
:= Character'Val (J
);
7112 -- Test for all cases where Character'Image
7113 -- yields an image that is longer than three
7114 -- characters. First the cases of Reserved_xxx
7115 -- names (length = 12).
7118 when Reserved_128 | Reserved_129 |
7119 Reserved_132 | Reserved_153
7123 when BS | HT | LF | VT | FF | CR |
7124 SO | SI | EM | FS | GS | RS |
7125 US | RI | MW | ST | PM
7129 when NUL | SOH | STX | ETX | EOT |
7130 ENQ | ACK | BEL | DLE | DC1 |
7131 DC2 | DC3 | DC4 | NAK | SYN |
7132 ETB | CAN | SUB | ESC | DEL |
7133 BPH | NBH | NEL | SSA | ESA |
7134 HTS | HTJ | VTS | PLD | PLU |
7135 SS2 | SS3 | DCS | PU1 | PU2 |
7136 STS | CCH | SPA | EPA | SOS |
7137 SCI | CSI | OSC | APC
7141 when Space
.. Tilde |
7142 No_Break_Space
.. LC_Y_Diaeresis
7147 W
:= Int
'Max (W
, Wt
);
7151 -- Width for types derived from Standard.Boolean
7153 elsif R
= Standard_Boolean
then
7160 -- Width for integer types
7162 elsif Is_Integer_Type
(P_Type
) then
7163 T
:= UI_Max
(abs Lo
, abs Hi
);
7171 -- Only remaining possibility is user declared enum type
7174 pragma Assert
(Is_Enumeration_Type
(P_Type
));
7177 L
:= First_Literal
(P_Type
);
7179 while Present
(L
) loop
7181 -- Only pay attention to in range characters
7183 if Lo
<= Enumeration_Pos
(L
)
7184 and then Enumeration_Pos
(L
) <= Hi
7186 -- For Width case, use decoded name
7188 if Id
= Attribute_Width
then
7189 Get_Decoded_Name_String
(Chars
(L
));
7190 Wt
:= Nat
(Name_Len
);
7192 -- For Wide_[Wide_]Width, use encoded name, and
7193 -- then adjust for the encoding.
7196 Get_Name_String
(Chars
(L
));
7198 -- Character literals are always of length 3
7200 if Name_Buffer
(1) = 'Q' then
7203 -- Otherwise loop to adjust for upper/wide chars
7206 Wt
:= Nat
(Name_Len
);
7208 for J
in 1 .. Name_Len
loop
7209 if Name_Buffer
(J
) = 'U' then
7211 elsif Name_Buffer
(J
) = 'W' then
7218 W
:= Int
'Max (W
, Wt
);
7225 Fold_Uint
(N
, UI_From_Int
(W
), True);
7231 -- The following attributes can never be folded, and furthermore we
7232 -- should not even have entered the case statement for any of these.
7233 -- Note that in some cases, the values have already been folded as
7234 -- a result of the processing in Analyze_Attribute.
7236 when Attribute_Abort_Signal |
7239 Attribute_Address_Size |
7240 Attribute_Asm_Input |
7241 Attribute_Asm_Output |
7243 Attribute_Bit_Order |
7244 Attribute_Bit_Position |
7245 Attribute_Callable |
7248 Attribute_Code_Address |
7250 Attribute_Default_Bit_Order |
7251 Attribute_Elaborated |
7252 Attribute_Elab_Body |
7253 Attribute_Elab_Spec |
7255 Attribute_External_Tag |
7256 Attribute_Fast_Math |
7257 Attribute_First_Bit |
7259 Attribute_Last_Bit |
7260 Attribute_Maximum_Alignment |
7263 Attribute_Partition_ID |
7264 Attribute_Pool_Address |
7265 Attribute_Position |
7266 Attribute_Priority |
7269 Attribute_Storage_Pool |
7270 Attribute_Storage_Size |
7271 Attribute_Storage_Unit |
7272 Attribute_Stub_Type |
7274 Attribute_Target_Name |
7275 Attribute_Terminated |
7276 Attribute_To_Address |
7277 Attribute_UET_Address |
7278 Attribute_Unchecked_Access |
7279 Attribute_Universal_Literal_String |
7280 Attribute_Unrestricted_Access |
7283 Attribute_Wchar_T_Size |
7284 Attribute_Wide_Value |
7285 Attribute_Wide_Wide_Value |
7286 Attribute_Word_Size |
7289 raise Program_Error
;
7292 -- At the end of the case, one more check. If we did a static evaluation
7293 -- so that the result is now a literal, then set Is_Static_Expression
7294 -- in the constant only if the prefix type is a static subtype. For
7295 -- non-static subtypes, the folding is still OK, but not static.
7297 -- An exception is the GNAT attribute Constrained_Array which is
7298 -- defined to be a static attribute in all cases.
7300 if Nkind_In
(N
, N_Integer_Literal
,
7302 N_Character_Literal
,
7304 or else (Is_Entity_Name
(N
)
7305 and then Ekind
(Entity
(N
)) = E_Enumeration_Literal
)
7307 Set_Is_Static_Expression
(N
, Static
);
7309 -- If this is still an attribute reference, then it has not been folded
7310 -- and that means that its expressions are in a non-static context.
7312 elsif Nkind
(N
) = N_Attribute_Reference
then
7315 -- Note: the else case not covered here are odd cases where the
7316 -- processing has transformed the attribute into something other
7317 -- than a constant. Nothing more to do in such cases.
7324 ------------------------------
7325 -- Is_Anonymous_Tagged_Base --
7326 ------------------------------
7328 function Is_Anonymous_Tagged_Base
7335 Anon
= Current_Scope
7336 and then Is_Itype
(Anon
)
7337 and then Associated_Node_For_Itype
(Anon
) = Parent
(Typ
);
7338 end Is_Anonymous_Tagged_Base
;
7340 --------------------------------
7341 -- Name_Implies_Lvalue_Prefix --
7342 --------------------------------
7344 function Name_Implies_Lvalue_Prefix
(Nam
: Name_Id
) return Boolean is
7345 pragma Assert
(Is_Attribute_Name
(Nam
));
7347 return Attribute_Name_Implies_Lvalue_Prefix
(Get_Attribute_Id
(Nam
));
7348 end Name_Implies_Lvalue_Prefix
;
7350 -----------------------
7351 -- Resolve_Attribute --
7352 -----------------------
7354 procedure Resolve_Attribute
(N
: Node_Id
; Typ
: Entity_Id
) is
7355 Loc
: constant Source_Ptr
:= Sloc
(N
);
7356 P
: constant Node_Id
:= Prefix
(N
);
7357 Aname
: constant Name_Id
:= Attribute_Name
(N
);
7358 Attr_Id
: constant Attribute_Id
:= Get_Attribute_Id
(Aname
);
7359 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
7360 Des_Btyp
: Entity_Id
;
7361 Index
: Interp_Index
;
7363 Nom_Subt
: Entity_Id
;
7365 procedure Accessibility_Message
;
7366 -- Error, or warning within an instance, if the static accessibility
7367 -- rules of 3.10.2 are violated.
7369 ---------------------------
7370 -- Accessibility_Message --
7371 ---------------------------
7373 procedure Accessibility_Message
is
7374 Indic
: Node_Id
:= Parent
(Parent
(N
));
7377 -- In an instance, this is a runtime check, but one we
7378 -- know will fail, so generate an appropriate warning.
7380 if In_Instance_Body
then
7382 ("?non-local pointer cannot point to local object", P
);
7384 ("\?Program_Error will be raised at run time", P
);
7386 Make_Raise_Program_Error
(Loc
,
7387 Reason
=> PE_Accessibility_Check_Failed
));
7393 ("non-local pointer cannot point to local object", P
);
7395 -- Check for case where we have a missing access definition
7397 if Is_Record_Type
(Current_Scope
)
7399 Nkind_In
(Parent
(N
), N_Discriminant_Association
,
7400 N_Index_Or_Discriminant_Constraint
)
7402 Indic
:= Parent
(Parent
(N
));
7403 while Present
(Indic
)
7404 and then Nkind
(Indic
) /= N_Subtype_Indication
7406 Indic
:= Parent
(Indic
);
7409 if Present
(Indic
) then
7411 ("\use an access definition for" &
7412 " the access discriminant of&",
7413 N
, Entity
(Subtype_Mark
(Indic
)));
7417 end Accessibility_Message
;
7419 -- Start of processing for Resolve_Attribute
7422 -- If error during analysis, no point in continuing, except for
7423 -- array types, where we get better recovery by using unconstrained
7424 -- indices than nothing at all (see Check_Array_Type).
7427 and then Attr_Id
/= Attribute_First
7428 and then Attr_Id
/= Attribute_Last
7429 and then Attr_Id
/= Attribute_Length
7430 and then Attr_Id
/= Attribute_Range
7435 -- If attribute was universal type, reset to actual type
7437 if Etype
(N
) = Universal_Integer
7438 or else Etype
(N
) = Universal_Real
7443 -- Remaining processing depends on attribute
7451 -- For access attributes, if the prefix denotes an entity, it is
7452 -- interpreted as a name, never as a call. It may be overloaded,
7453 -- in which case resolution uses the profile of the context type.
7454 -- Otherwise prefix must be resolved.
7456 when Attribute_Access
7457 | Attribute_Unchecked_Access
7458 | Attribute_Unrestricted_Access
=>
7462 if Is_Variable
(P
) then
7463 Note_Possible_Modification
(P
, Sure
=> False);
7466 if Is_Entity_Name
(P
) then
7467 if Is_Overloaded
(P
) then
7468 Get_First_Interp
(P
, Index
, It
);
7469 while Present
(It
.Nam
) loop
7470 if Type_Conformant
(Designated_Type
(Typ
), It
.Nam
) then
7471 Set_Entity
(P
, It
.Nam
);
7473 -- The prefix is definitely NOT overloaded anymore at
7474 -- this point, so we reset the Is_Overloaded flag to
7475 -- avoid any confusion when reanalyzing the node.
7477 Set_Is_Overloaded
(P
, False);
7478 Set_Is_Overloaded
(N
, False);
7479 Generate_Reference
(Entity
(P
), P
);
7483 Get_Next_Interp
(Index
, It
);
7486 -- If Prefix is a subprogram name, it is frozen by this
7489 -- If it is a type, there is nothing to resolve.
7490 -- If it is an object, complete its resolution.
7492 elsif Is_Overloadable
(Entity
(P
)) then
7494 -- Avoid insertion of freeze actions in spec expression mode
7496 if not In_Spec_Expression
then
7497 Insert_Actions
(N
, Freeze_Entity
(Entity
(P
), Loc
));
7500 elsif Is_Type
(Entity
(P
)) then
7506 Error_Msg_Name_1
:= Aname
;
7508 if not Is_Entity_Name
(P
) then
7511 elsif Is_Overloadable
(Entity
(P
))
7512 and then Is_Abstract_Subprogram
(Entity
(P
))
7514 Error_Msg_F
("prefix of % attribute cannot be abstract", P
);
7515 Set_Etype
(N
, Any_Type
);
7517 elsif Convention
(Entity
(P
)) = Convention_Intrinsic
then
7518 if Ekind
(Entity
(P
)) = E_Enumeration_Literal
then
7520 ("prefix of % attribute cannot be enumeration literal",
7524 ("prefix of % attribute cannot be intrinsic", P
);
7527 Set_Etype
(N
, Any_Type
);
7530 -- Assignments, return statements, components of aggregates,
7531 -- generic instantiations will require convention checks if
7532 -- the type is an access to subprogram. Given that there will
7533 -- also be accessibility checks on those, this is where the
7534 -- checks can eventually be centralized ???
7536 if Ekind
(Btyp
) = E_Access_Subprogram_Type
7538 Ekind
(Btyp
) = E_Anonymous_Access_Subprogram_Type
7540 Ekind
(Btyp
) = E_Anonymous_Access_Protected_Subprogram_Type
7542 -- Deal with convention mismatch
7544 if Convention
(Btyp
) /= Convention
(Entity
(P
)) then
7546 ("subprogram & has wrong convention", P
, Entity
(P
));
7549 ("\does not match convention of access type &",
7552 if not Has_Convention_Pragma
(Btyp
) then
7554 ("\probable missing pragma Convention for &",
7559 Check_Subtype_Conformant
7560 (New_Id
=> Entity
(P
),
7561 Old_Id
=> Designated_Type
(Btyp
),
7565 if Attr_Id
= Attribute_Unchecked_Access
then
7566 Error_Msg_Name_1
:= Aname
;
7568 ("attribute% cannot be applied to a subprogram", P
);
7570 elsif Aname
= Name_Unrestricted_Access
then
7571 null; -- Nothing to check
7573 -- Check the static accessibility rule of 3.10.2(32).
7574 -- This rule also applies within the private part of an
7575 -- instantiation. This rule does not apply to anonymous
7576 -- access-to-subprogram types (Ada 2005).
7578 elsif Attr_Id
= Attribute_Access
7579 and then not In_Instance_Body
7580 and then Subprogram_Access_Level
(Entity
(P
)) >
7581 Type_Access_Level
(Btyp
)
7582 and then Ekind
(Btyp
) /=
7583 E_Anonymous_Access_Subprogram_Type
7584 and then Ekind
(Btyp
) /=
7585 E_Anonymous_Access_Protected_Subprogram_Type
7588 ("subprogram must not be deeper than access type", P
);
7590 -- Check the restriction of 3.10.2(32) that disallows the
7591 -- access attribute within a generic body when the ultimate
7592 -- ancestor of the type of the attribute is declared outside
7593 -- of the generic unit and the subprogram is declared within
7594 -- that generic unit. This includes any such attribute that
7595 -- occurs within the body of a generic unit that is a child
7596 -- of the generic unit where the subprogram is declared.
7597 -- The rule also prohibits applying the attribute when the
7598 -- access type is a generic formal access type (since the
7599 -- level of the actual type is not known). This restriction
7600 -- does not apply when the attribute type is an anonymous
7601 -- access-to-subprogram type. Note that this check was
7602 -- revised by AI-229, because the originally Ada 95 rule
7603 -- was too lax. The original rule only applied when the
7604 -- subprogram was declared within the body of the generic,
7605 -- which allowed the possibility of dangling references).
7606 -- The rule was also too strict in some case, in that it
7607 -- didn't permit the access to be declared in the generic
7608 -- spec, whereas the revised rule does (as long as it's not
7611 -- There are a couple of subtleties of the test for applying
7612 -- the check that are worth noting. First, we only apply it
7613 -- when the levels of the subprogram and access type are the
7614 -- same (the case where the subprogram is statically deeper
7615 -- was applied above, and the case where the type is deeper
7616 -- is always safe). Second, we want the check to apply
7617 -- within nested generic bodies and generic child unit
7618 -- bodies, but not to apply to an attribute that appears in
7619 -- the generic unit's specification. This is done by testing
7620 -- that the attribute's innermost enclosing generic body is
7621 -- not the same as the innermost generic body enclosing the
7622 -- generic unit where the subprogram is declared (we don't
7623 -- want the check to apply when the access attribute is in
7624 -- the spec and there's some other generic body enclosing
7625 -- generic). Finally, there's no point applying the check
7626 -- when within an instance, because any violations will have
7627 -- been caught by the compilation of the generic unit.
7629 elsif Attr_Id
= Attribute_Access
7630 and then not In_Instance
7631 and then Present
(Enclosing_Generic_Unit
(Entity
(P
)))
7632 and then Present
(Enclosing_Generic_Body
(N
))
7633 and then Enclosing_Generic_Body
(N
) /=
7634 Enclosing_Generic_Body
7635 (Enclosing_Generic_Unit
(Entity
(P
)))
7636 and then Subprogram_Access_Level
(Entity
(P
)) =
7637 Type_Access_Level
(Btyp
)
7638 and then Ekind
(Btyp
) /=
7639 E_Anonymous_Access_Subprogram_Type
7640 and then Ekind
(Btyp
) /=
7641 E_Anonymous_Access_Protected_Subprogram_Type
7643 -- The attribute type's ultimate ancestor must be
7644 -- declared within the same generic unit as the
7645 -- subprogram is declared. The error message is
7646 -- specialized to say "ancestor" for the case where
7647 -- the access type is not its own ancestor, since
7648 -- saying simply "access type" would be very confusing.
7650 if Enclosing_Generic_Unit
(Entity
(P
)) /=
7651 Enclosing_Generic_Unit
(Root_Type
(Btyp
))
7654 ("''Access attribute not allowed in generic body",
7657 if Root_Type
(Btyp
) = Btyp
then
7660 "access type & is declared outside " &
7661 "generic unit (RM 3.10.2(32))", N
, Btyp
);
7664 ("\because ancestor of " &
7665 "access type & is declared outside " &
7666 "generic unit (RM 3.10.2(32))", N
, Btyp
);
7670 ("\move ''Access to private part, or " &
7671 "(Ada 2005) use anonymous access type instead of &",
7674 -- If the ultimate ancestor of the attribute's type is
7675 -- a formal type, then the attribute is illegal because
7676 -- the actual type might be declared at a higher level.
7677 -- The error message is specialized to say "ancestor"
7678 -- for the case where the access type is not its own
7679 -- ancestor, since saying simply "access type" would be
7682 elsif Is_Generic_Type
(Root_Type
(Btyp
)) then
7683 if Root_Type
(Btyp
) = Btyp
then
7685 ("access type must not be a generic formal type",
7689 ("ancestor access type must not be a generic " &
7696 -- If this is a renaming, an inherited operation, or a
7697 -- subprogram instance, use the original entity. This may make
7698 -- the node type-inconsistent, so this transformation can only
7699 -- be done if the node will not be reanalyzed. In particular,
7700 -- if it is within a default expression, the transformation
7701 -- must be delayed until the default subprogram is created for
7702 -- it, when the enclosing subprogram is frozen.
7704 if Is_Entity_Name
(P
)
7705 and then Is_Overloadable
(Entity
(P
))
7706 and then Present
(Alias
(Entity
(P
)))
7707 and then Expander_Active
7710 New_Occurrence_Of
(Alias
(Entity
(P
)), Sloc
(P
)));
7713 elsif Nkind
(P
) = N_Selected_Component
7714 and then Is_Overloadable
(Entity
(Selector_Name
(P
)))
7716 -- Protected operation. If operation is overloaded, must
7717 -- disambiguate. Prefix that denotes protected object itself
7718 -- is resolved with its own type.
7720 if Attr_Id
= Attribute_Unchecked_Access
then
7721 Error_Msg_Name_1
:= Aname
;
7723 ("attribute% cannot be applied to protected operation", P
);
7726 Resolve
(Prefix
(P
));
7727 Generate_Reference
(Entity
(Selector_Name
(P
)), P
);
7729 elsif Is_Overloaded
(P
) then
7731 -- Use the designated type of the context to disambiguate
7732 -- Note that this was not strictly conformant to Ada 95,
7733 -- but was the implementation adopted by most Ada 95 compilers.
7734 -- The use of the context type to resolve an Access attribute
7735 -- reference is now mandated in AI-235 for Ada 2005.
7738 Index
: Interp_Index
;
7742 Get_First_Interp
(P
, Index
, It
);
7743 while Present
(It
.Typ
) loop
7744 if Covers
(Designated_Type
(Typ
), It
.Typ
) then
7745 Resolve
(P
, It
.Typ
);
7749 Get_Next_Interp
(Index
, It
);
7756 -- X'Access is illegal if X denotes a constant and the access type
7757 -- is access-to-variable. Same for 'Unchecked_Access. The rule
7758 -- does not apply to 'Unrestricted_Access. If the reference is a
7759 -- default-initialized aggregate component for a self-referential
7760 -- type the reference is legal.
7762 if not (Ekind
(Btyp
) = E_Access_Subprogram_Type
7763 or else Ekind
(Btyp
) = E_Anonymous_Access_Subprogram_Type
7764 or else (Is_Record_Type
(Btyp
)
7766 Present
(Corresponding_Remote_Type
(Btyp
)))
7767 or else Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
7768 or else Ekind
(Btyp
)
7769 = E_Anonymous_Access_Protected_Subprogram_Type
7770 or else Is_Access_Constant
(Btyp
)
7771 or else Is_Variable
(P
)
7772 or else Attr_Id
= Attribute_Unrestricted_Access
)
7774 if Is_Entity_Name
(P
)
7775 and then Is_Type
(Entity
(P
))
7777 -- Legality of a self-reference through an access
7778 -- attribute has been verified in Analyze_Access_Attribute.
7782 elsif Comes_From_Source
(N
) then
7783 Error_Msg_F
("access-to-variable designates constant", P
);
7787 Des_Btyp
:= Designated_Type
(Btyp
);
7789 if Ada_Version
>= Ada_05
7790 and then Is_Incomplete_Type
(Des_Btyp
)
7792 -- Ada 2005 (AI-412): If the (sub)type is a limited view of an
7793 -- imported entity, and the non-limited view is visible, make
7794 -- use of it. If it is an incomplete subtype, use the base type
7797 if From_With_Type
(Des_Btyp
)
7798 and then Present
(Non_Limited_View
(Des_Btyp
))
7800 Des_Btyp
:= Non_Limited_View
(Des_Btyp
);
7802 elsif Ekind
(Des_Btyp
) = E_Incomplete_Subtype
then
7803 Des_Btyp
:= Etype
(Des_Btyp
);
7807 if (Attr_Id
= Attribute_Access
7809 Attr_Id
= Attribute_Unchecked_Access
)
7810 and then (Ekind
(Btyp
) = E_General_Access_Type
7811 or else Ekind
(Btyp
) = E_Anonymous_Access_Type
)
7813 -- Ada 2005 (AI-230): Check the accessibility of anonymous
7814 -- access types for stand-alone objects, record and array
7815 -- components, and return objects. For a component definition
7816 -- the level is the same of the enclosing composite type.
7818 if Ada_Version
>= Ada_05
7819 and then Is_Local_Anonymous_Access
(Btyp
)
7820 and then Object_Access_Level
(P
) > Type_Access_Level
(Btyp
)
7821 and then Attr_Id
= Attribute_Access
7823 -- In an instance, this is a runtime check, but one we
7824 -- know will fail, so generate an appropriate warning.
7826 if In_Instance_Body
then
7828 ("?non-local pointer cannot point to local object", P
);
7830 ("\?Program_Error will be raised at run time", P
);
7832 Make_Raise_Program_Error
(Loc
,
7833 Reason
=> PE_Accessibility_Check_Failed
));
7838 ("non-local pointer cannot point to local object", P
);
7842 if Is_Dependent_Component_Of_Mutable_Object
(P
) then
7844 ("illegal attribute for discriminant-dependent component",
7848 -- Check static matching rule of 3.10.2(27). Nominal subtype
7849 -- of the prefix must statically match the designated type.
7851 Nom_Subt
:= Etype
(P
);
7853 if Is_Constr_Subt_For_U_Nominal
(Nom_Subt
) then
7854 Nom_Subt
:= Base_Type
(Nom_Subt
);
7857 if Is_Tagged_Type
(Designated_Type
(Typ
)) then
7859 -- If the attribute is in the context of an access
7860 -- parameter, then the prefix is allowed to be of the
7861 -- class-wide type (by AI-127).
7863 if Ekind
(Typ
) = E_Anonymous_Access_Type
then
7864 if not Covers
(Designated_Type
(Typ
), Nom_Subt
)
7865 and then not Covers
(Nom_Subt
, Designated_Type
(Typ
))
7871 Desig
:= Designated_Type
(Typ
);
7873 if Is_Class_Wide_Type
(Desig
) then
7874 Desig
:= Etype
(Desig
);
7877 if Is_Anonymous_Tagged_Base
(Nom_Subt
, Desig
) then
7882 ("type of prefix: & not compatible",
7885 ("\with &, the expected designated type",
7886 P
, Designated_Type
(Typ
));
7891 elsif not Covers
(Designated_Type
(Typ
), Nom_Subt
)
7893 (not Is_Class_Wide_Type
(Designated_Type
(Typ
))
7894 and then Is_Class_Wide_Type
(Nom_Subt
))
7897 ("type of prefix: & is not covered", P
, Nom_Subt
);
7899 ("\by &, the expected designated type" &
7900 " (RM 3.10.2 (27))", P
, Designated_Type
(Typ
));
7903 if Is_Class_Wide_Type
(Designated_Type
(Typ
))
7904 and then Has_Discriminants
(Etype
(Designated_Type
(Typ
)))
7905 and then Is_Constrained
(Etype
(Designated_Type
(Typ
)))
7906 and then Designated_Type
(Typ
) /= Nom_Subt
7908 Apply_Discriminant_Check
7909 (N
, Etype
(Designated_Type
(Typ
)));
7912 -- Ada 2005 (AI-363): Require static matching when designated
7913 -- type has discriminants and a constrained partial view, since
7914 -- in general objects of such types are mutable, so we can't
7915 -- allow the access value to designate a constrained object
7916 -- (because access values must be assumed to designate mutable
7917 -- objects when designated type does not impose a constraint).
7919 elsif Subtypes_Statically_Match
(Des_Btyp
, Nom_Subt
) then
7922 elsif Has_Discriminants
(Designated_Type
(Typ
))
7923 and then not Is_Constrained
(Des_Btyp
)
7925 (Ada_Version
< Ada_05
7927 not Has_Constrained_Partial_View
7928 (Designated_Type
(Base_Type
(Typ
))))
7934 ("object subtype must statically match "
7935 & "designated subtype", P
);
7937 if Is_Entity_Name
(P
)
7938 and then Is_Array_Type
(Designated_Type
(Typ
))
7941 D
: constant Node_Id
:= Declaration_Node
(Entity
(P
));
7944 Error_Msg_N
("aliased object has explicit bounds?",
7946 Error_Msg_N
("\declare without bounds"
7947 & " (and with explicit initialization)?", D
);
7948 Error_Msg_N
("\for use with unconstrained access?", D
);
7953 -- Check the static accessibility rule of 3.10.2(28).
7954 -- Note that this check is not performed for the
7955 -- case of an anonymous access type, since the access
7956 -- attribute is always legal in such a context.
7958 if Attr_Id
/= Attribute_Unchecked_Access
7959 and then Object_Access_Level
(P
) > Type_Access_Level
(Btyp
)
7960 and then Ekind
(Btyp
) = E_General_Access_Type
7962 Accessibility_Message
;
7967 if Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
7969 Ekind
(Btyp
) = E_Anonymous_Access_Protected_Subprogram_Type
7971 if Is_Entity_Name
(P
)
7972 and then not Is_Protected_Type
(Scope
(Entity
(P
)))
7974 Error_Msg_F
("context requires a protected subprogram", P
);
7976 -- Check accessibility of protected object against that of the
7977 -- access type, but only on user code, because the expander
7978 -- creates access references for handlers. If the context is an
7979 -- anonymous_access_to_protected, there are no accessibility
7980 -- checks either. Omit check entirely for Unrestricted_Access.
7982 elsif Object_Access_Level
(P
) > Type_Access_Level
(Btyp
)
7983 and then Comes_From_Source
(N
)
7984 and then Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
7985 and then Attr_Id
/= Attribute_Unrestricted_Access
7987 Accessibility_Message
;
7991 elsif (Ekind
(Btyp
) = E_Access_Subprogram_Type
7993 Ekind
(Btyp
) = E_Anonymous_Access_Subprogram_Type
)
7994 and then Ekind
(Etype
(N
)) = E_Access_Protected_Subprogram_Type
7996 Error_Msg_F
("context requires a non-protected subprogram", P
);
7999 -- The context cannot be a pool-specific type, but this is a
8000 -- legality rule, not a resolution rule, so it must be checked
8001 -- separately, after possibly disambiguation (see AI-245).
8003 if Ekind
(Btyp
) = E_Access_Type
8004 and then Attr_Id
/= Attribute_Unrestricted_Access
8006 Wrong_Type
(N
, Typ
);
8009 -- The context may be a constrained access type (however ill-
8010 -- advised such subtypes might be) so in order to generate a
8011 -- constraint check when needed set the type of the attribute
8012 -- reference to the base type of the context.
8014 Set_Etype
(N
, Btyp
);
8016 -- Check for incorrect atomic/volatile reference (RM C.6(12))
8018 if Attr_Id
/= Attribute_Unrestricted_Access
then
8019 if Is_Atomic_Object
(P
)
8020 and then not Is_Atomic
(Designated_Type
(Typ
))
8023 ("access to atomic object cannot yield access-to-" &
8024 "non-atomic type", P
);
8026 elsif Is_Volatile_Object
(P
)
8027 and then not Is_Volatile
(Designated_Type
(Typ
))
8030 ("access to volatile object cannot yield access-to-" &
8031 "non-volatile type", P
);
8035 if Is_Entity_Name
(P
) then
8036 Set_Address_Taken
(Entity
(P
));
8038 end Access_Attribute
;
8044 -- Deal with resolving the type for Address attribute, overloading
8045 -- is not permitted here, since there is no context to resolve it.
8047 when Attribute_Address | Attribute_Code_Address
=>
8048 Address_Attribute
: begin
8050 -- To be safe, assume that if the address of a variable is taken,
8051 -- it may be modified via this address, so note modification.
8053 if Is_Variable
(P
) then
8054 Note_Possible_Modification
(P
, Sure
=> False);
8057 if Nkind
(P
) in N_Subexpr
8058 and then Is_Overloaded
(P
)
8060 Get_First_Interp
(P
, Index
, It
);
8061 Get_Next_Interp
(Index
, It
);
8063 if Present
(It
.Nam
) then
8064 Error_Msg_Name_1
:= Aname
;
8066 ("prefix of % attribute cannot be overloaded", P
);
8070 if not Is_Entity_Name
(P
)
8071 or else not Is_Overloadable
(Entity
(P
))
8073 if not Is_Task_Type
(Etype
(P
))
8074 or else Nkind
(P
) = N_Explicit_Dereference
8080 -- If this is the name of a derived subprogram, or that of a
8081 -- generic actual, the address is that of the original entity.
8083 if Is_Entity_Name
(P
)
8084 and then Is_Overloadable
(Entity
(P
))
8085 and then Present
(Alias
(Entity
(P
)))
8088 New_Occurrence_Of
(Alias
(Entity
(P
)), Sloc
(P
)));
8091 if Is_Entity_Name
(P
) then
8092 Set_Address_Taken
(Entity
(P
));
8095 if Nkind
(P
) = N_Slice
then
8097 -- Arr (X .. Y)'address is identical to Arr (X)'address,
8098 -- even if the array is packed and the slice itself is not
8099 -- addressable. Transform the prefix into an indexed component.
8101 -- Note that the transformation is safe only if we know that
8102 -- the slice is non-null. That is because a null slice can have
8103 -- an out of bounds index value.
8105 -- Right now, gigi blows up if given 'Address on a slice as a
8106 -- result of some incorrect freeze nodes generated by the front
8107 -- end, and this covers up that bug in one case, but the bug is
8108 -- likely still there in the cases not handled by this code ???
8110 -- It's not clear what 'Address *should* return for a null
8111 -- slice with out of bounds indexes, this might be worth an ARG
8114 -- One approach would be to do a length check unconditionally,
8115 -- and then do the transformation below unconditionally, but
8116 -- analyze with checks off, avoiding the problem of the out of
8117 -- bounds index. This approach would interpret the address of
8118 -- an out of bounds null slice as being the address where the
8119 -- array element would be if there was one, which is probably
8120 -- as reasonable an interpretation as any ???
8123 Loc
: constant Source_Ptr
:= Sloc
(P
);
8124 D
: constant Node_Id
:= Discrete_Range
(P
);
8128 if Is_Entity_Name
(D
)
8131 (Type_Low_Bound
(Entity
(D
)),
8132 Type_High_Bound
(Entity
(D
)))
8135 Make_Attribute_Reference
(Loc
,
8136 Prefix
=> (New_Occurrence_Of
(Entity
(D
), Loc
)),
8137 Attribute_Name
=> Name_First
);
8139 elsif Nkind
(D
) = N_Range
8140 and then Not_Null_Range
(Low_Bound
(D
), High_Bound
(D
))
8142 Lo
:= Low_Bound
(D
);
8148 if Present
(Lo
) then
8150 Make_Indexed_Component
(Loc
,
8151 Prefix
=> Relocate_Node
(Prefix
(P
)),
8152 Expressions
=> New_List
(Lo
)));
8154 Analyze_And_Resolve
(P
);
8158 end Address_Attribute
;
8164 -- Prefix of the AST_Entry attribute is an entry name which must
8165 -- not be resolved, since this is definitely not an entry call.
8167 when Attribute_AST_Entry
=>
8174 -- Prefix of Body_Version attribute can be a subprogram name which
8175 -- must not be resolved, since this is not a call.
8177 when Attribute_Body_Version
=>
8184 -- Prefix of Caller attribute is an entry name which must not
8185 -- be resolved, since this is definitely not an entry call.
8187 when Attribute_Caller
=>
8194 -- Shares processing with Address attribute
8200 -- If the prefix of the Count attribute is an entry name it must not
8201 -- be resolved, since this is definitely not an entry call. However,
8202 -- if it is an element of an entry family, the index itself may
8203 -- have to be resolved because it can be a general expression.
8205 when Attribute_Count
=>
8206 if Nkind
(P
) = N_Indexed_Component
8207 and then Is_Entity_Name
(Prefix
(P
))
8210 Indx
: constant Node_Id
:= First
(Expressions
(P
));
8211 Fam
: constant Entity_Id
:= Entity
(Prefix
(P
));
8213 Resolve
(Indx
, Entry_Index_Type
(Fam
));
8214 Apply_Range_Check
(Indx
, Entry_Index_Type
(Fam
));
8222 -- Prefix of the Elaborated attribute is a subprogram name which
8223 -- must not be resolved, since this is definitely not a call. Note
8224 -- that it is a library unit, so it cannot be overloaded here.
8226 when Attribute_Elaborated
=>
8233 -- Prefix of Enabled attribute is a check name, which must be treated
8234 -- specially and not touched by Resolve.
8236 when Attribute_Enabled
=>
8239 --------------------
8240 -- Mechanism_Code --
8241 --------------------
8243 -- Prefix of the Mechanism_Code attribute is a function name
8244 -- which must not be resolved. Should we check for overloaded ???
8246 when Attribute_Mechanism_Code
=>
8253 -- Most processing is done in sem_dist, after determining the
8254 -- context type. Node is rewritten as a conversion to a runtime call.
8256 when Attribute_Partition_ID
=>
8257 Process_Partition_Id
(N
);
8264 when Attribute_Pool_Address
=>
8271 -- We replace the Range attribute node with a range expression
8272 -- whose bounds are the 'First and 'Last attributes applied to the
8273 -- same prefix. The reason that we do this transformation here
8274 -- instead of in the expander is that it simplifies other parts of
8275 -- the semantic analysis which assume that the Range has been
8276 -- replaced; thus it must be done even when in semantic-only mode
8277 -- (note that the RM specifically mentions this equivalence, we
8278 -- take care that the prefix is only evaluated once).
8280 when Attribute_Range
=> Range_Attribute
:
8286 if not Is_Entity_Name
(P
)
8287 or else not Is_Type
(Entity
(P
))
8293 Make_Attribute_Reference
(Loc
,
8295 Duplicate_Subexpr
(P
, Name_Req
=> True),
8296 Attribute_Name
=> Name_Last
,
8297 Expressions
=> Expressions
(N
));
8300 Make_Attribute_Reference
(Loc
,
8302 Attribute_Name
=> Name_First
,
8303 Expressions
=> Expressions
(N
));
8305 -- If the original was marked as Must_Not_Freeze (see code
8306 -- in Sem_Ch3.Make_Index), then make sure the rewriting
8307 -- does not freeze either.
8309 if Must_Not_Freeze
(N
) then
8310 Set_Must_Not_Freeze
(HB
);
8311 Set_Must_Not_Freeze
(LB
);
8312 Set_Must_Not_Freeze
(Prefix
(HB
));
8313 Set_Must_Not_Freeze
(Prefix
(LB
));
8316 if Raises_Constraint_Error
(Prefix
(N
)) then
8318 -- Preserve Sloc of prefix in the new bounds, so that
8319 -- the posted warning can be removed if we are within
8320 -- unreachable code.
8322 Set_Sloc
(LB
, Sloc
(Prefix
(N
)));
8323 Set_Sloc
(HB
, Sloc
(Prefix
(N
)));
8326 Rewrite
(N
, Make_Range
(Loc
, LB
, HB
));
8327 Analyze_And_Resolve
(N
, Typ
);
8329 -- Normally after resolving attribute nodes, Eval_Attribute
8330 -- is called to do any possible static evaluation of the node.
8331 -- However, here since the Range attribute has just been
8332 -- transformed into a range expression it is no longer an
8333 -- attribute node and therefore the call needs to be avoided
8334 -- and is accomplished by simply returning from the procedure.
8337 end Range_Attribute
;
8343 -- We will only come here during the prescan of a spec expression
8344 -- containing a Result attribute. In that case the proper Etype has
8345 -- already been set, and nothing more needs to be done here.
8347 when Attribute_Result
=>
8354 -- Prefix must not be resolved in this case, since it is not a
8355 -- real entity reference. No action of any kind is require!
8357 when Attribute_UET_Address
=>
8360 ----------------------
8361 -- Unchecked_Access --
8362 ----------------------
8364 -- Processing is shared with Access
8366 -------------------------
8367 -- Unrestricted_Access --
8368 -------------------------
8370 -- Processing is shared with Access
8376 -- Apply range check. Note that we did not do this during the
8377 -- analysis phase, since we wanted Eval_Attribute to have a
8378 -- chance at finding an illegal out of range value.
8380 when Attribute_Val
=>
8382 -- Note that we do our own Eval_Attribute call here rather than
8383 -- use the common one, because we need to do processing after
8384 -- the call, as per above comment.
8388 -- Eval_Attribute may replace the node with a raise CE, or
8389 -- fold it to a constant. Obviously we only apply a scalar
8390 -- range check if this did not happen!
8392 if Nkind
(N
) = N_Attribute_Reference
8393 and then Attribute_Name
(N
) = Name_Val
8395 Apply_Scalar_Range_Check
(First
(Expressions
(N
)), Btyp
);
8404 -- Prefix of Version attribute can be a subprogram name which
8405 -- must not be resolved, since this is not a call.
8407 when Attribute_Version
=>
8410 ----------------------
8411 -- Other Attributes --
8412 ----------------------
8414 -- For other attributes, resolve prefix unless it is a type. If
8415 -- the attribute reference itself is a type name ('Base and 'Class)
8416 -- then this is only legal within a task or protected record.
8419 if not Is_Entity_Name
(P
)
8420 or else not Is_Type
(Entity
(P
))
8425 -- If the attribute reference itself is a type name ('Base,
8426 -- 'Class) then this is only legal within a task or protected
8427 -- record. What is this all about ???
8429 if Is_Entity_Name
(N
)
8430 and then Is_Type
(Entity
(N
))
8432 if Is_Concurrent_Type
(Entity
(N
))
8433 and then In_Open_Scopes
(Entity
(P
))
8438 ("invalid use of subtype name in expression or call", N
);
8442 -- For attributes whose argument may be a string, complete
8443 -- resolution of argument now. This avoids premature expansion
8444 -- (and the creation of transient scopes) before the attribute
8445 -- reference is resolved.
8448 when Attribute_Value
=>
8449 Resolve
(First
(Expressions
(N
)), Standard_String
);
8451 when Attribute_Wide_Value
=>
8452 Resolve
(First
(Expressions
(N
)), Standard_Wide_String
);
8454 when Attribute_Wide_Wide_Value
=>
8455 Resolve
(First
(Expressions
(N
)), Standard_Wide_Wide_String
);
8457 when others => null;
8460 -- If the prefix of the attribute is a class-wide type then it
8461 -- will be expanded into a dispatching call to a predefined
8462 -- primitive. Therefore we must check for potential violation
8463 -- of such restriction.
8465 if Is_Class_Wide_Type
(Etype
(P
)) then
8466 Check_Restriction
(No_Dispatching_Calls
, N
);
8470 -- Normally the Freezing is done by Resolve but sometimes the Prefix
8471 -- is not resolved, in which case the freezing must be done now.
8473 Freeze_Expression
(P
);
8475 -- Finally perform static evaluation on the attribute reference
8478 end Resolve_Attribute
;
8480 --------------------------------
8481 -- Stream_Attribute_Available --
8482 --------------------------------
8484 function Stream_Attribute_Available
8486 Nam
: TSS_Name_Type
;
8487 Partial_View
: Node_Id
:= Empty
) return Boolean
8489 Etyp
: Entity_Id
:= Typ
;
8491 -- Start of processing for Stream_Attribute_Available
8494 -- We need some comments in this body ???
8496 if Has_Stream_Attribute_Definition
(Typ
, Nam
) then
8500 if Is_Class_Wide_Type
(Typ
) then
8501 return not Is_Limited_Type
(Typ
)
8502 or else Stream_Attribute_Available
(Etype
(Typ
), Nam
);
8505 if Nam
= TSS_Stream_Input
8506 and then Is_Abstract_Type
(Typ
)
8507 and then not Is_Class_Wide_Type
(Typ
)
8512 if not (Is_Limited_Type
(Typ
)
8513 or else (Present
(Partial_View
)
8514 and then Is_Limited_Type
(Partial_View
)))
8519 -- In Ada 2005, Input can invoke Read, and Output can invoke Write
8521 if Nam
= TSS_Stream_Input
8522 and then Ada_Version
>= Ada_05
8523 and then Stream_Attribute_Available
(Etyp
, TSS_Stream_Read
)
8527 elsif Nam
= TSS_Stream_Output
8528 and then Ada_Version
>= Ada_05
8529 and then Stream_Attribute_Available
(Etyp
, TSS_Stream_Write
)
8534 -- Case of Read and Write: check for attribute definition clause that
8535 -- applies to an ancestor type.
8537 while Etype
(Etyp
) /= Etyp
loop
8538 Etyp
:= Etype
(Etyp
);
8540 if Has_Stream_Attribute_Definition
(Etyp
, Nam
) then
8545 if Ada_Version
< Ada_05
then
8547 -- In Ada 95 mode, also consider a non-visible definition
8550 Btyp
: constant Entity_Id
:= Implementation_Base_Type
(Typ
);
8553 and then Stream_Attribute_Available
8554 (Btyp
, Nam
, Partial_View
=> Typ
);
8559 end Stream_Attribute_Available
;