1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
11 -- Copyright (C) 1992-2001, Free Software Foundation, Inc. --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
24 -- GNAT was originally developed by the GNAT team at New York University. --
25 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
27 ------------------------------------------------------------------------------
29 with Ada.Characters.Latin_1; use Ada.Characters.Latin_1;
31 with Atree; use Atree;
32 with Checks; use Checks;
33 with Einfo; use Einfo;
34 with Errout; use Errout;
36 with Exp_Tss; use Exp_Tss;
37 with Exp_Util; use Exp_Util;
38 with Expander; use Expander;
39 with Freeze; use Freeze;
40 with Lib.Xref; use Lib.Xref;
41 with Namet; use Namet;
42 with Nlists; use Nlists;
43 with Nmake; use Nmake;
45 with Restrict; use Restrict;
46 with Rtsfind; use Rtsfind;
48 with Sem_Cat; use Sem_Cat;
49 with Sem_Ch6; use Sem_Ch6;
50 with Sem_Ch8; use Sem_Ch8;
51 with Sem_Ch13; use Sem_Ch13;
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 Snames; use Snames;
62 with Stringt; use Stringt;
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;
69 with Widechar; use Widechar;
71 package body Sem_Attr is
73 True_Value : constant Uint := Uint_1;
74 False_Value : constant Uint := Uint_0;
75 -- Synonyms to be used when these constants are used as Boolean values
77 Bad_Attribute : exception;
78 -- Exception raised if an error is detected during attribute processing,
79 -- used so that we can abandon the processing so we don't run into
80 -- trouble with cascaded errors.
82 -- The following array is the list of attributes defined in the Ada 83 RM
84 Attribute_83 : 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 -----------------------
130 -- Local_Subprograms --
131 -----------------------
133 procedure Eval_Attribute (N : Node_Id);
134 -- Performs compile time evaluation of attributes where possible, leaving
135 -- the Is_Static_Expression/Raises_Constraint_Error flags appropriately
136 -- set, and replacing the node with a literal node if the value can be
137 -- computed at compile time. All static attribute references are folded,
138 -- as well as a number of cases of non-static attributes that can always
139 -- be computed at compile time (e.g. floating-point model attributes that
140 -- are applied to non-static subtypes). Of course in such cases, the
141 -- Is_Static_Expression flag will not be set on the resulting literal.
142 -- Note that the only required action of this procedure is to catch the
143 -- static expression cases as described in the RM. Folding of other cases
144 -- is done where convenient, but some additional non-static folding is in
145 -- N_Expand_Attribute_Reference in cases where this is more convenient.
147 function Is_Anonymous_Tagged_Base
151 -- For derived tagged types that constrain parent discriminants we build
152 -- an anonymous unconstrained base type. We need to recognize the relation
153 -- between the two when analyzing an access attribute for a constrained
154 -- component, before the full declaration for Typ has been analyzed, and
155 -- where therefore the prefix of the attribute does not match the enclosing
158 -----------------------
159 -- Analyze_Attribute --
160 -----------------------
162 procedure Analyze_Attribute (N : Node_Id) is
163 Loc : constant Source_Ptr := Sloc (N);
164 Aname : constant Name_Id := Attribute_Name (N);
165 P : constant Node_Id := Prefix (N);
166 Exprs : constant List_Id := Expressions (N);
167 Attr_Id : constant Attribute_Id := Get_Attribute_Id (Aname);
172 -- Type of prefix after analysis
174 P_Base_Type : Entity_Id;
175 -- Base type of prefix after analysis
177 P_Root_Type : Entity_Id;
178 -- Root type of prefix after analysis
180 Unanalyzed : Node_Id;
182 -----------------------
183 -- Local Subprograms --
184 -----------------------
186 procedure Access_Attribute;
187 -- Used for Access, Unchecked_Access, Unrestricted_Access attributes.
188 -- Internally, Id distinguishes which of the three cases is involved.
190 procedure Check_Array_Or_Scalar_Type;
191 -- Common procedure used by First, Last, Range attribute to check
192 -- that the prefix is a constrained array or scalar type, or a name
193 -- of an array object, and that an argument appears only if appropriate
194 -- (i.e. only in the array case).
196 procedure Check_Array_Type;
197 -- Common semantic checks for all array attributes. Checks that the
198 -- prefix is a constrained array type or the name of an array object.
199 -- The error message for non-arrays is specialized appropriately.
201 procedure Check_Asm_Attribute;
202 -- Common semantic checks for Asm_Input and Asm_Output attributes
204 procedure Check_Component;
205 -- Common processing for Bit_Position, First_Bit, Last_Bit, and
206 -- Position. Checks prefix is an appropriate selected component.
208 procedure Check_Decimal_Fixed_Point_Type;
209 -- Check that prefix of attribute N is a decimal fixed-point type
211 procedure Check_Dereference;
212 -- If the prefix of attribute is an object of an access type, then
213 -- introduce an explicit deference, and adjust P_Type accordingly.
215 procedure Check_Discrete_Type;
216 -- Verify that prefix of attribute N is a discrete type
219 -- Check that no attribute arguments are present
221 procedure Check_Either_E0_Or_E1;
222 -- Check that there are zero or one attribute arguments present
225 -- Check that exactly one attribute argument is present
228 -- Check that two attribute arguments are present
230 procedure Check_Enum_Image;
231 -- If the prefix type is an enumeration type, set all its literals
232 -- as referenced, since the image function could possibly end up
233 -- referencing any of the literals indirectly.
235 procedure Check_Enumeration_Type;
236 -- Verify that prefix of attribute N is an enumeration type
238 procedure Check_Fixed_Point_Type;
239 -- Verify that prefix of attribute N is a fixed type
241 procedure Check_Fixed_Point_Type_0;
242 -- Verify that prefix of attribute N is a fixed type and that
243 -- no attribute expressions are present
245 procedure Check_Floating_Point_Type;
246 -- Verify that prefix of attribute N is a float type
248 procedure Check_Floating_Point_Type_0;
249 -- Verify that prefix of attribute N is a float type and that
250 -- no attribute expressions are present
252 procedure Check_Floating_Point_Type_1;
253 -- Verify that prefix of attribute N is a float type and that
254 -- exactly one attribute expression is present
256 procedure Check_Floating_Point_Type_2;
257 -- Verify that prefix of attribute N is a float type and that
258 -- two attribute expressions are present
260 procedure Legal_Formal_Attribute;
261 -- Common processing for attributes Definite, and Has_Discriminants
263 procedure Check_Integer_Type;
264 -- Verify that prefix of attribute N is an integer type
266 procedure Check_Library_Unit;
267 -- Verify that prefix of attribute N is a library unit
269 procedure Check_Not_Incomplete_Type;
270 -- Check that P (the prefix of the attribute) is not an incomplete
271 -- type or a private type for which no full view has been given.
273 procedure Check_Object_Reference (P : Node_Id);
274 -- Check that P (the prefix of the attribute) is an object reference
276 procedure Check_Program_Unit;
277 -- Verify that prefix of attribute N is a program unit
279 procedure Check_Real_Type;
280 -- Verify that prefix of attribute N is fixed or float type
282 procedure Check_Scalar_Type;
283 -- Verify that prefix of attribute N is a scalar type
285 procedure Check_Standard_Prefix;
286 -- Verify that prefix of attribute N is package Standard
288 procedure Check_Stream_Attribute (Nam : Name_Id);
289 -- Validity checking for stream attribute. Nam is the name of the
290 -- corresponding possible defined attribute function (e.g. for the
291 -- Read attribute, Nam will be Name_uRead).
293 procedure Check_Task_Prefix;
294 -- Verify that prefix of attribute N is a task or task type
296 procedure Check_Type;
297 -- Verify that the prefix of attribute N is a type
299 procedure Check_Unit_Name (Nod : Node_Id);
300 -- Check that Nod is of the form of a library unit name, i.e that
301 -- it is an identifier, or a selected component whose prefix is
302 -- itself of the form of a library unit name. Note that this is
303 -- quite different from Check_Program_Unit, since it only checks
304 -- the syntactic form of the name, not the semantic identity. This
305 -- is because it is used with attributes (Elab_Body, Elab_Spec, and
306 -- UET_Address) which can refer to non-visible unit.
308 procedure Error_Attr (Msg : String; Error_Node : Node_Id);
309 pragma No_Return (Error_Attr);
310 -- Posts error using Error_Msg_N at given node, sets type of attribute
311 -- node to Any_Type, and then raises Bad_Attribute to avoid any further
312 -- semantic processing. The message typically contains a % insertion
313 -- character which is replaced by the attribute name.
315 procedure Standard_Attribute (Val : Int);
316 -- Used to process attributes whose prefix is package Standard which
317 -- yield values of type Universal_Integer. The attribute reference
318 -- node is rewritten with an integer literal of the given value.
320 procedure Unexpected_Argument (En : Node_Id);
321 -- Signal unexpected attribute argument (En is the argument)
323 procedure Validate_Non_Static_Attribute_Function_Call;
324 -- Called when processing an attribute that is a function call to a
325 -- non-static function, i.e. an attribute function that either takes
326 -- non-scalar arguments or returns a non-scalar result. Verifies that
327 -- such a call does not appear in a preelaborable context.
329 ----------------------
330 -- Access_Attribute --
331 ----------------------
333 procedure Access_Attribute is
334 Acc_Type : Entity_Id;
339 function Build_Access_Object_Type (DT : Entity_Id) return Entity_Id;
340 -- Build an access-to-object type whose designated type is DT,
341 -- and whose Ekind is appropriate to the attribute type. The
342 -- type that is constructed is returned as the result.
344 procedure Build_Access_Subprogram_Type (P : Node_Id);
345 -- Build an access to subprogram whose designated type is
346 -- the type of the prefix. If prefix is overloaded, so it the
347 -- node itself. The result is stored in Acc_Type.
349 ------------------------------
350 -- Build_Access_Object_Type --
351 ------------------------------
353 function Build_Access_Object_Type (DT : Entity_Id) return Entity_Id is
357 if Aname = Name_Unrestricted_Access then
360 (E_Allocator_Type, Current_Scope, Loc, 'A');
364 (E_Access_Attribute_Type, Current_Scope, Loc, 'A');
367 Set_Etype (Typ, Typ);
368 Init_Size_Align (Typ);
370 Set_Associated_Node_For_Itype (Typ, N);
371 Set_Directly_Designated_Type (Typ, DT);
373 end Build_Access_Object_Type;
375 ----------------------------------
376 -- Build_Access_Subprogram_Type --
377 ----------------------------------
379 procedure Build_Access_Subprogram_Type (P : Node_Id) is
380 Index : Interp_Index;
383 function Get_Kind (E : Entity_Id) return Entity_Kind;
384 -- Distinguish between access to regular and protected
387 function Get_Kind (E : Entity_Id) return Entity_Kind is
389 if Convention (E) = Convention_Protected then
390 return E_Access_Protected_Subprogram_Type;
392 return E_Access_Subprogram_Type;
396 -- Start of processing for Build_Access_Subprogram_Type
399 if not Is_Overloaded (P) then
402 (Get_Kind (Entity (P)), Current_Scope, Loc, 'A');
403 Set_Etype (Acc_Type, Acc_Type);
404 Set_Directly_Designated_Type (Acc_Type, Entity (P));
405 Set_Etype (N, Acc_Type);
408 Get_First_Interp (P, Index, It);
409 Set_Etype (N, Any_Type);
411 while Present (It.Nam) loop
413 if not Is_Intrinsic_Subprogram (It.Nam) then
416 (Get_Kind (It.Nam), Current_Scope, Loc, 'A');
417 Set_Etype (Acc_Type, Acc_Type);
418 Set_Directly_Designated_Type (Acc_Type, It.Nam);
419 Add_One_Interp (N, Acc_Type, Acc_Type);
422 Get_Next_Interp (Index, It);
425 if Etype (N) = Any_Type then
426 Error_Attr ("prefix of % attribute cannot be intrinsic", P);
429 end Build_Access_Subprogram_Type;
431 -- Start of processing for Access_Attribute
436 if Nkind (P) = N_Character_Literal then
438 ("prefix of % attribute cannot be enumeration literal", P);
440 -- In the case of an access to subprogram, use the name of the
441 -- subprogram itself as the designated type. Type-checking in
442 -- this case compares the signatures of the designated types.
444 elsif Is_Entity_Name (P)
445 and then Is_Overloadable (Entity (P))
447 Build_Access_Subprogram_Type (P);
450 -- Component is an operation of a protected type.
452 elsif (Nkind (P) = N_Selected_Component
453 and then Is_Overloadable (Entity (Selector_Name (P))))
455 if Ekind (Entity (Selector_Name (P))) = E_Entry then
456 Error_Attr ("Prefix of % attribute must be subprogram", P);
459 Build_Access_Subprogram_Type (Selector_Name (P));
463 -- Deal with incorrect reference to a type, but note that some
464 -- accesses are allowed (references to the current type instance).
466 if Is_Entity_Name (P) then
467 Scop := Current_Scope;
470 if Is_Type (Typ) then
472 -- OK if we are within the scope of a limited type
473 -- let's mark the component as having per object constraint
475 if Is_Anonymous_Tagged_Base (Scop, Typ) then
483 Q : Node_Id := Parent (N);
487 and then Nkind (Q) /= N_Component_Declaration
492 Set_Has_Per_Object_Constraint (
493 Defining_Identifier (Q), True);
497 if Nkind (P) = N_Expanded_Name then
499 ("current instance prefix must be a direct name", P);
502 -- If a current instance attribute appears within a
503 -- a component constraint it must appear alone; other
504 -- contexts (default expressions, within a task body)
505 -- are not subject to this restriction.
507 if not In_Default_Expression
508 and then not Has_Completion (Scop)
510 Nkind (Parent (N)) /= N_Discriminant_Association
512 Nkind (Parent (N)) /= N_Index_Or_Discriminant_Constraint
515 ("current instance attribute must appear alone", N);
518 -- OK if we are in initialization procedure for the type
519 -- in question, in which case the reference to the type
520 -- is rewritten as a reference to the current object.
522 elsif Ekind (Scop) = E_Procedure
523 and then Chars (Scop) = Name_uInit_Proc
524 and then Etype (First_Formal (Scop)) = Typ
527 Make_Attribute_Reference (Loc,
528 Prefix => Make_Identifier (Loc, Name_uInit),
529 Attribute_Name => Name_Unrestricted_Access));
533 -- OK if a task type, this test needs sharpening up ???
535 elsif Is_Task_Type (Typ) then
538 -- Otherwise we have an error case
541 Error_Attr ("% attribute cannot be applied to type", P);
547 -- If we fall through, we have a normal access to object case.
548 -- Unrestricted_Access is legal wherever an allocator would be
549 -- legal, so its Etype is set to E_Allocator. The expected type
550 -- of the other attributes is a general access type, and therefore
551 -- we label them with E_Access_Attribute_Type.
553 if not Is_Overloaded (P) then
554 Acc_Type := Build_Access_Object_Type (P_Type);
555 Set_Etype (N, Acc_Type);
558 Index : Interp_Index;
562 Set_Etype (N, Any_Type);
563 Get_First_Interp (P, Index, It);
565 while Present (It.Typ) loop
566 Acc_Type := Build_Access_Object_Type (It.Typ);
567 Add_One_Interp (N, Acc_Type, Acc_Type);
568 Get_Next_Interp (Index, It);
573 -- Check for aliased view unless unrestricted case. We allow
574 -- a nonaliased prefix when within an instance because the
575 -- prefix may have been a tagged formal object, which is
576 -- defined to be aliased even when the actual might not be
577 -- (other instance cases will have been caught in the generic).
579 if Aname /= Name_Unrestricted_Access
580 and then not Is_Aliased_View (P)
581 and then not In_Instance
583 Error_Attr ("prefix of % attribute must be aliased", P);
586 end Access_Attribute;
588 --------------------------------
589 -- Check_Array_Or_Scalar_Type --
590 --------------------------------
592 procedure Check_Array_Or_Scalar_Type is
596 -- Dimension number for array attributes.
599 -- Case of string literal or string literal subtype. These cases
600 -- cannot arise from legal Ada code, but the expander is allowed
601 -- to generate them. They require special handling because string
602 -- literal subtypes do not have standard bounds (the whole idea
603 -- of these subtypes is to avoid having to generate the bounds)
605 if Ekind (P_Type) = E_String_Literal_Subtype then
606 Set_Etype (N, Etype (First_Index (P_Base_Type)));
611 elsif Is_Scalar_Type (P_Type) then
615 Error_Attr ("invalid argument in % attribute", E1);
617 Set_Etype (N, P_Base_Type);
621 -- The following is a special test to allow 'First to apply to
622 -- private scalar types if the attribute comes from generated
623 -- code. This occurs in the case of Normalize_Scalars code.
625 elsif Is_Private_Type (P_Type)
626 and then Present (Full_View (P_Type))
627 and then Is_Scalar_Type (Full_View (P_Type))
628 and then not Comes_From_Source (N)
630 Set_Etype (N, Implementation_Base_Type (P_Type));
632 -- Array types other than string literal subtypes handled above
637 -- We know prefix is an array type, or the name of an array
638 -- object, and that the expression, if present, is static
639 -- and within the range of the dimensions of the type.
641 if Is_Array_Type (P_Type) then
642 Index := First_Index (P_Base_Type);
644 else pragma Assert (Is_Access_Type (P_Type));
645 Index := First_Index (Base_Type (Designated_Type (P_Type)));
650 -- First dimension assumed
652 Set_Etype (N, Base_Type (Etype (Index)));
655 D := UI_To_Int (Intval (E1));
657 for J in 1 .. D - 1 loop
661 Set_Etype (N, Base_Type (Etype (Index)));
662 Set_Etype (E1, Standard_Integer);
665 end Check_Array_Or_Scalar_Type;
667 ----------------------
668 -- Check_Array_Type --
669 ----------------------
671 procedure Check_Array_Type is
673 -- Dimension number for array attributes.
676 -- If the type is a string literal type, then this must be generated
677 -- internally, and no further check is required on its legality.
679 if Ekind (P_Type) = E_String_Literal_Subtype then
682 -- If the type is a composite, it is an illegal aggregate, no point
685 elsif P_Type = Any_Composite then
689 -- Normal case of array type or subtype
691 Check_Either_E0_Or_E1;
693 if Is_Array_Type (P_Type) then
694 if not Is_Constrained (P_Type)
695 and then Is_Entity_Name (P)
696 and then Is_Type (Entity (P))
698 -- Note: we do not call Error_Attr here, since we prefer to
699 -- continue, using the relevant index type of the array,
700 -- even though it is unconstrained. This gives better error
701 -- recovery behavior.
703 Error_Msg_Name_1 := Aname;
705 ("prefix for % attribute must be constrained array", P);
708 D := Number_Dimensions (P_Type);
710 elsif Is_Access_Type (P_Type)
711 and then Is_Array_Type (Designated_Type (P_Type))
713 if Is_Entity_Name (P) and then Is_Type (Entity (P)) then
714 Error_Attr ("prefix of % attribute cannot be access type", P);
717 D := Number_Dimensions (Designated_Type (P_Type));
719 -- If there is an implicit dereference, then we must freeze
720 -- the designated type of the access type, since the type of
721 -- the referenced array is this type (see AI95-00106).
723 Freeze_Before (N, Designated_Type (P_Type));
726 if Is_Private_Type (P_Type) then
728 ("prefix for % attribute may not be private type", P);
730 elsif Attr_Id = Attribute_First
732 Attr_Id = Attribute_Last
734 Error_Attr ("invalid prefix for % attribute", P);
737 Error_Attr ("prefix for % attribute must be array", P);
742 Resolve (E1, Any_Integer);
743 Set_Etype (E1, Standard_Integer);
745 if not Is_Static_Expression (E1)
746 or else Raises_Constraint_Error (E1)
748 Error_Attr ("expression for dimension must be static", E1);
750 elsif UI_To_Int (Expr_Value (E1)) > D
751 or else UI_To_Int (Expr_Value (E1)) < 1
753 Error_Attr ("invalid dimension number for array type", E1);
756 end Check_Array_Type;
758 -------------------------
759 -- Check_Asm_Attribute --
760 -------------------------
762 procedure Check_Asm_Attribute is
767 -- Check first argument is static string expression
769 Analyze_And_Resolve (E1, Standard_String);
771 if Etype (E1) = Any_Type then
774 elsif not Is_OK_Static_Expression (E1) then
776 ("constraint argument must be static string expression", E1);
779 -- Check second argument is right type
781 Analyze_And_Resolve (E2, Entity (P));
783 -- Note: that is all we need to do, we don't need to check
784 -- that it appears in a correct context. The Ada type system
785 -- will do that for us.
787 end Check_Asm_Attribute;
789 ---------------------
790 -- Check_Component --
791 ---------------------
793 procedure Check_Component is
797 if Nkind (P) /= N_Selected_Component
799 (Ekind (Entity (Selector_Name (P))) /= E_Component
801 Ekind (Entity (Selector_Name (P))) /= E_Discriminant)
804 ("prefix for % attribute must be selected component", P);
808 ------------------------------------
809 -- Check_Decimal_Fixed_Point_Type --
810 ------------------------------------
812 procedure Check_Decimal_Fixed_Point_Type is
816 if not Is_Decimal_Fixed_Point_Type (P_Type) then
818 ("prefix of % attribute must be decimal type", P);
820 end Check_Decimal_Fixed_Point_Type;
822 -----------------------
823 -- Check_Dereference --
824 -----------------------
826 procedure Check_Dereference is
828 if Is_Object_Reference (P)
829 and then Is_Access_Type (P_Type)
832 Make_Explicit_Dereference (Sloc (P),
833 Prefix => Relocate_Node (P)));
835 Analyze_And_Resolve (P);
838 if P_Type = Any_Type then
842 P_Base_Type := Base_Type (P_Type);
843 P_Root_Type := Root_Type (P_Base_Type);
845 end Check_Dereference;
847 -------------------------
848 -- Check_Discrete_Type --
849 -------------------------
851 procedure Check_Discrete_Type is
855 if not Is_Discrete_Type (P_Type) then
856 Error_Attr ("prefix of % attribute must be discrete type", P);
858 end Check_Discrete_Type;
864 procedure Check_E0 is
867 Unexpected_Argument (E1);
875 procedure Check_E1 is
877 Check_Either_E0_Or_E1;
881 -- Special-case attributes that are functions and that appear as
882 -- the prefix of another attribute. Error is posted on parent.
884 if Nkind (Parent (N)) = N_Attribute_Reference
885 and then (Attribute_Name (Parent (N)) = Name_Address
887 Attribute_Name (Parent (N)) = Name_Code_Address
889 Attribute_Name (Parent (N)) = Name_Access)
891 Error_Msg_Name_1 := Attribute_Name (Parent (N));
892 Error_Msg_N ("illegal prefix for % attribute", Parent (N));
893 Set_Etype (Parent (N), Any_Type);
894 Set_Entity (Parent (N), Any_Type);
898 Error_Attr ("missing argument for % attribute", N);
907 procedure Check_E2 is
910 Error_Attr ("missing arguments for % attribute (2 required)", N);
912 Error_Attr ("missing argument for % attribute (2 required)", N);
916 ---------------------------
917 -- Check_Either_E0_Or_E1 --
918 ---------------------------
920 procedure Check_Either_E0_Or_E1 is
923 Unexpected_Argument (E2);
925 end Check_Either_E0_Or_E1;
927 ----------------------
928 -- Check_Enum_Image --
929 ----------------------
931 procedure Check_Enum_Image is
935 if Is_Enumeration_Type (P_Base_Type) then
936 Lit := First_Literal (P_Base_Type);
937 while Present (Lit) loop
938 Set_Referenced (Lit);
942 end Check_Enum_Image;
944 ----------------------------
945 -- Check_Enumeration_Type --
946 ----------------------------
948 procedure Check_Enumeration_Type is
952 if not Is_Enumeration_Type (P_Type) then
953 Error_Attr ("prefix of % attribute must be enumeration type", P);
955 end Check_Enumeration_Type;
957 ----------------------------
958 -- Check_Fixed_Point_Type --
959 ----------------------------
961 procedure Check_Fixed_Point_Type is
965 if not Is_Fixed_Point_Type (P_Type) then
966 Error_Attr ("prefix of % attribute must be fixed point type", P);
968 end Check_Fixed_Point_Type;
970 ------------------------------
971 -- Check_Fixed_Point_Type_0 --
972 ------------------------------
974 procedure Check_Fixed_Point_Type_0 is
976 Check_Fixed_Point_Type;
978 end Check_Fixed_Point_Type_0;
980 -------------------------------
981 -- Check_Floating_Point_Type --
982 -------------------------------
984 procedure Check_Floating_Point_Type is
988 if not Is_Floating_Point_Type (P_Type) then
989 Error_Attr ("prefix of % attribute must be float type", P);
991 end Check_Floating_Point_Type;
993 ---------------------------------
994 -- Check_Floating_Point_Type_0 --
995 ---------------------------------
997 procedure Check_Floating_Point_Type_0 is
999 Check_Floating_Point_Type;
1001 end Check_Floating_Point_Type_0;
1003 ---------------------------------
1004 -- Check_Floating_Point_Type_1 --
1005 ---------------------------------
1007 procedure Check_Floating_Point_Type_1 is
1009 Check_Floating_Point_Type;
1011 end Check_Floating_Point_Type_1;
1013 ---------------------------------
1014 -- Check_Floating_Point_Type_2 --
1015 ---------------------------------
1017 procedure Check_Floating_Point_Type_2 is
1019 Check_Floating_Point_Type;
1021 end Check_Floating_Point_Type_2;
1023 ------------------------
1024 -- Check_Integer_Type --
1025 ------------------------
1027 procedure Check_Integer_Type is
1031 if not Is_Integer_Type (P_Type) then
1032 Error_Attr ("prefix of % attribute must be integer type", P);
1034 end Check_Integer_Type;
1036 ------------------------
1037 -- Check_Library_Unit --
1038 ------------------------
1040 procedure Check_Library_Unit is
1042 if not Is_Compilation_Unit (Entity (P)) then
1043 Error_Attr ("prefix of % attribute must be library unit", P);
1045 end Check_Library_Unit;
1047 -------------------------------
1048 -- Check_Not_Incomplete_Type --
1049 -------------------------------
1051 procedure Check_Not_Incomplete_Type is
1053 if not Is_Entity_Name (P)
1054 or else not Is_Type (Entity (P))
1055 or else In_Default_Expression
1060 Check_Fully_Declared (P_Type, P);
1062 end Check_Not_Incomplete_Type;
1064 ----------------------------
1065 -- Check_Object_Reference --
1066 ----------------------------
1068 procedure Check_Object_Reference (P : Node_Id) is
1072 -- If we need an object, and we have a prefix that is the name of
1073 -- a function entity, convert it into a function call.
1075 if Is_Entity_Name (P)
1076 and then Ekind (Entity (P)) = E_Function
1078 Rtyp := Etype (Entity (P));
1081 Make_Function_Call (Sloc (P),
1082 Name => Relocate_Node (P)));
1084 Analyze_And_Resolve (P, Rtyp);
1086 -- Otherwise we must have an object reference
1088 elsif not Is_Object_Reference (P) then
1089 Error_Attr ("prefix of % attribute must be object", P);
1091 end Check_Object_Reference;
1093 ------------------------
1094 -- Check_Program_Unit --
1095 ------------------------
1097 procedure Check_Program_Unit is
1099 if Is_Entity_Name (P) then
1101 K : constant Entity_Kind := Ekind (Entity (P));
1102 T : constant Entity_Id := Etype (Entity (P));
1105 if K in Subprogram_Kind
1106 or else K in Task_Kind
1107 or else K in Protected_Kind
1108 or else K = E_Package
1109 or else K in Generic_Unit_Kind
1110 or else (K = E_Variable
1114 Is_Protected_Type (T)))
1121 Error_Attr ("prefix of % attribute must be program unit", P);
1122 end Check_Program_Unit;
1124 ---------------------
1125 -- Check_Real_Type --
1126 ---------------------
1128 procedure Check_Real_Type is
1132 if not Is_Real_Type (P_Type) then
1133 Error_Attr ("prefix of % attribute must be real type", P);
1135 end Check_Real_Type;
1137 -----------------------
1138 -- Check_Scalar_Type --
1139 -----------------------
1141 procedure Check_Scalar_Type is
1145 if not Is_Scalar_Type (P_Type) then
1146 Error_Attr ("prefix of % attribute must be scalar type", P);
1148 end Check_Scalar_Type;
1150 ---------------------------
1151 -- Check_Standard_Prefix --
1152 ---------------------------
1154 procedure Check_Standard_Prefix is
1158 if Nkind (P) /= N_Identifier
1159 or else Chars (P) /= Name_Standard
1161 Error_Attr ("only allowed prefix for % attribute is Standard", P);
1164 end Check_Standard_Prefix;
1166 ----------------------------
1167 -- Check_Stream_Attribute --
1168 ----------------------------
1170 procedure Check_Stream_Attribute (Nam : Name_Id) is
1175 Validate_Non_Static_Attribute_Function_Call;
1177 -- With the exception of 'Input, Stream attributes are procedures,
1178 -- and can only appear at the position of procedure calls. We check
1179 -- for this here, before they are rewritten, to give a more precise
1182 if Nam = Name_uInput then
1185 elsif Is_List_Member (N)
1186 and then Nkind (Parent (N)) /= N_Procedure_Call_Statement
1187 and then Nkind (Parent (N)) /= N_Aggregate
1193 ("invalid context for attribute %, which is a procedure", N);
1197 Btyp := Implementation_Base_Type (P_Type);
1199 -- Stream attributes not allowed on limited types unless the
1200 -- special OK_For_Stream flag is set.
1202 if Is_Limited_Type (P_Type)
1203 and then Comes_From_Source (N)
1204 and then not Present (TSS (Btyp, Nam))
1205 and then No (Get_Rep_Pragma (Btyp, Name_Stream_Convert))
1207 -- Special case the message if we are compiling the stub version
1208 -- of a remote operation. One error on the type is sufficient.
1210 if (Is_Remote_Types (Current_Scope)
1211 or else Is_Remote_Call_Interface (Current_Scope))
1212 and then not Error_Posted (Btyp)
1214 Error_Msg_Node_2 := Current_Scope;
1216 ("limited type& used in& has no stream attributes", P, Btyp);
1217 Set_Error_Posted (Btyp);
1219 elsif not Error_Posted (Btyp) then
1221 ("limited type& has no stream attributes", P, Btyp);
1225 -- Here we must check that the first argument is an access type
1226 -- that is compatible with Ada.Streams.Root_Stream_Type'Class.
1228 Analyze_And_Resolve (E1);
1231 -- Note: the double call to Root_Type here is needed because the
1232 -- root type of a class-wide type is the corresponding type (e.g.
1233 -- X for X'Class, and we really want to go to the root.
1235 if not Is_Access_Type (Etyp)
1236 or else Root_Type (Root_Type (Designated_Type (Etyp))) /=
1237 RTE (RE_Root_Stream_Type)
1240 ("expected access to Ada.Streams.Root_Stream_Type''Class", E1);
1243 -- Check that the second argument is of the right type if there is
1244 -- one (the Input attribute has only one argument so this is skipped)
1246 if Present (E2) then
1250 and then not Is_OK_Variable_For_Out_Formal (E2)
1253 ("second argument of % attribute must be a variable", E2);
1256 Resolve (E2, P_Type);
1258 end Check_Stream_Attribute;
1260 -----------------------
1261 -- Check_Task_Prefix --
1262 -----------------------
1264 procedure Check_Task_Prefix is
1268 if Is_Task_Type (Etype (P))
1269 or else (Is_Access_Type (Etype (P))
1270 and then Is_Task_Type (Designated_Type (Etype (P))))
1272 Resolve (P, Etype (P));
1274 Error_Attr ("prefix of % attribute must be a task", P);
1276 end Check_Task_Prefix;
1282 -- The possibilities are an entity name denoting a type, or an
1283 -- attribute reference that denotes a type (Base or Class). If
1284 -- the type is incomplete, replace it with its full view.
1286 procedure Check_Type is
1288 if not Is_Entity_Name (P)
1289 or else not Is_Type (Entity (P))
1291 Error_Attr ("prefix of % attribute must be a type", P);
1293 elsif Ekind (Entity (P)) = E_Incomplete_Type
1294 and then Present (Full_View (Entity (P)))
1296 P_Type := Full_View (Entity (P));
1297 Set_Entity (P, P_Type);
1301 ---------------------
1302 -- Check_Unit_Name --
1303 ---------------------
1305 procedure Check_Unit_Name (Nod : Node_Id) is
1307 if Nkind (Nod) = N_Identifier then
1310 elsif Nkind (Nod) = N_Selected_Component then
1311 Check_Unit_Name (Prefix (Nod));
1313 if Nkind (Selector_Name (Nod)) = N_Identifier then
1318 Error_Attr ("argument for % attribute must be unit name", P);
1319 end Check_Unit_Name;
1325 procedure Error_Attr (Msg : String; Error_Node : Node_Id) is
1327 Error_Msg_Name_1 := Aname;
1328 Error_Msg_N (Msg, Error_Node);
1329 Set_Etype (N, Any_Type);
1330 Set_Entity (N, Any_Type);
1331 raise Bad_Attribute;
1334 ----------------------------
1335 -- Legal_Formal_Attribute --
1336 ----------------------------
1338 procedure Legal_Formal_Attribute is
1342 if not Is_Entity_Name (P)
1343 or else not Is_Type (Entity (P))
1345 Error_Attr (" prefix of % attribute must be generic type", N);
1347 elsif Is_Generic_Actual_Type (Entity (P))
1352 elsif Is_Generic_Type (Entity (P)) then
1353 if not Is_Indefinite_Subtype (Entity (P)) then
1355 (" prefix of % attribute must be indefinite generic type", N);
1360 (" prefix of % attribute must be indefinite generic type", N);
1363 Set_Etype (N, Standard_Boolean);
1364 end Legal_Formal_Attribute;
1366 ------------------------
1367 -- Standard_Attribute --
1368 ------------------------
1370 procedure Standard_Attribute (Val : Int) is
1372 Check_Standard_Prefix;
1374 Make_Integer_Literal (Loc, Val));
1376 end Standard_Attribute;
1378 -------------------------
1379 -- Unexpected Argument --
1380 -------------------------
1382 procedure Unexpected_Argument (En : Node_Id) is
1384 Error_Attr ("unexpected argument for % attribute", En);
1385 end Unexpected_Argument;
1387 -------------------------------------------------
1388 -- Validate_Non_Static_Attribute_Function_Call --
1389 -------------------------------------------------
1391 -- This function should be moved to Sem_Dist ???
1393 procedure Validate_Non_Static_Attribute_Function_Call is
1395 if In_Preelaborated_Unit
1396 and then not In_Subprogram_Or_Concurrent_Unit
1398 Error_Msg_N ("non-static function call in preelaborated unit", N);
1400 end Validate_Non_Static_Attribute_Function_Call;
1402 -----------------------------------------------
1403 -- Start of Processing for Analyze_Attribute --
1404 -----------------------------------------------
1407 -- Immediate return if unrecognized attribute (already diagnosed
1408 -- by parser, so there is nothing more that we need to do)
1410 if not Is_Attribute_Name (Aname) then
1411 raise Bad_Attribute;
1414 -- Deal with Ada 83 and Features issues
1416 if not Attribute_83 (Attr_Id) then
1417 if Ada_83 and then Comes_From_Source (N) then
1418 Error_Msg_Name_1 := Aname;
1419 Error_Msg_N ("(Ada 83) attribute% is not standard?", N);
1422 if Attribute_Impl_Def (Attr_Id) then
1423 Check_Restriction (No_Implementation_Attributes, N);
1427 -- Remote access to subprogram type access attribute reference needs
1428 -- unanalyzed copy for tree transformation. The analyzed copy is used
1429 -- for its semantic information (whether prefix is a remote subprogram
1430 -- name), the unanalyzed copy is used to construct new subtree rooted
1431 -- with N_aggregate which represents a fat pointer aggregate.
1433 if Aname = Name_Access then
1434 Unanalyzed := Copy_Separate_Tree (N);
1437 -- Analyze prefix and exit if error in analysis. If the prefix is an
1438 -- incomplete type, use full view if available. A special case is
1439 -- that we never analyze the prefix of an Elab_Body or Elab_Spec
1440 -- or UET_Address attribute.
1442 if Aname /= Name_Elab_Body
1444 Aname /= Name_Elab_Spec
1446 Aname /= Name_UET_Address
1449 P_Type := Etype (P);
1451 if Is_Entity_Name (P)
1452 and then Present (Entity (P))
1453 and then Is_Type (Entity (P))
1454 and then Ekind (Entity (P)) = E_Incomplete_Type
1456 P_Type := Get_Full_View (P_Type);
1457 Set_Entity (P, P_Type);
1458 Set_Etype (P, P_Type);
1461 if P_Type = Any_Type then
1462 raise Bad_Attribute;
1465 P_Base_Type := Base_Type (P_Type);
1466 P_Root_Type := Root_Type (P_Base_Type);
1469 -- Analyze expressions that may be present, exiting if an error occurs
1476 E1 := First (Exprs);
1479 -- Check for missing or bad expression (result of previous error)
1481 if No (E1) or else Etype (E1) = Any_Type then
1482 raise Bad_Attribute;
1487 if Present (E2) then
1490 if Etype (E2) = Any_Type then
1491 raise Bad_Attribute;
1494 if Present (Next (E2)) then
1495 Unexpected_Argument (Next (E2));
1500 if Is_Overloaded (P)
1501 and then Aname /= Name_Access
1502 and then Aname /= Name_Address
1503 and then Aname /= Name_Code_Address
1504 and then Aname /= Name_Count
1505 and then Aname /= Name_Unchecked_Access
1507 Error_Attr ("ambiguous prefix for % attribute", P);
1510 -- Remaining processing depends on attribute
1518 when Attribute_Abort_Signal =>
1519 Check_Standard_Prefix;
1521 New_Reference_To (Stand.Abort_Signal, Loc));
1528 when Attribute_Access =>
1535 when Attribute_Address =>
1538 -- Check for some junk cases, where we have to allow the address
1539 -- attribute but it does not make much sense, so at least for now
1540 -- just replace with Null_Address.
1542 -- We also do this if the prefix is a reference to the AST_Entry
1543 -- attribute. If expansion is active, the attribute will be
1544 -- replaced by a function call, and address will work fine and
1545 -- get the proper value, but if expansion is not active, then
1546 -- the check here allows proper semantic analysis of the reference.
1548 -- An Address attribute created by expansion is legal even when it
1549 -- applies to other entity-denoting expressions.
1551 if (Is_Entity_Name (P)) then
1552 if Is_Subprogram (Entity (P))
1553 or else Is_Object (Entity (P))
1554 or else Ekind (Entity (P)) = E_Label
1556 Set_Address_Taken (Entity (P));
1558 elsif (Is_Concurrent_Type (Etype (Entity (P)))
1559 and then Etype (Entity (P)) = Base_Type (Entity (P)))
1560 or else Ekind (Entity (P)) = E_Package
1561 or else Is_Generic_Unit (Entity (P))
1564 New_Occurrence_Of (RTE (RE_Null_Address), Sloc (N)));
1567 Error_Attr ("invalid prefix for % attribute", P);
1570 elsif Nkind (P) = N_Attribute_Reference
1571 and then Attribute_Name (P) = Name_AST_Entry
1574 New_Occurrence_Of (RTE (RE_Null_Address), Sloc (N)));
1576 elsif Is_Object_Reference (P) then
1579 elsif Nkind (P) = N_Selected_Component
1580 and then Is_Subprogram (Entity (Selector_Name (P)))
1584 elsif not Comes_From_Source (N) then
1588 Error_Attr ("invalid prefix for % attribute", P);
1591 Set_Etype (N, RTE (RE_Address));
1597 when Attribute_Address_Size =>
1598 Standard_Attribute (System_Address_Size);
1604 when Attribute_Adjacent =>
1605 Check_Floating_Point_Type_2;
1606 Set_Etype (N, P_Base_Type);
1607 Resolve (E1, P_Base_Type);
1608 Resolve (E2, P_Base_Type);
1614 when Attribute_Aft =>
1615 Check_Fixed_Point_Type_0;
1616 Set_Etype (N, Universal_Integer);
1622 when Attribute_Alignment =>
1624 -- Don't we need more checking here, cf Size ???
1627 Check_Not_Incomplete_Type;
1628 Set_Etype (N, Universal_Integer);
1634 when Attribute_Asm_Input =>
1635 Check_Asm_Attribute;
1636 Set_Etype (N, RTE (RE_Asm_Input_Operand));
1642 when Attribute_Asm_Output =>
1643 Check_Asm_Attribute;
1645 if Etype (E2) = Any_Type then
1648 elsif Aname = Name_Asm_Output then
1649 if not Is_Variable (E2) then
1651 ("second argument for Asm_Output is not variable", E2);
1655 Note_Possible_Modification (E2);
1656 Set_Etype (N, RTE (RE_Asm_Output_Operand));
1662 when Attribute_AST_Entry => AST_Entry : declare
1668 -- Indicates if entry family index is present. Note the coding
1669 -- here handles the entry family case, but in fact it cannot be
1670 -- executed currently, because pragma AST_Entry does not permit
1671 -- the specification of an entry family.
1673 procedure Bad_AST_Entry;
1674 -- Signal a bad AST_Entry pragma
1676 function OK_Entry (E : Entity_Id) return Boolean;
1677 -- Checks that E is of an appropriate entity kind for an entry
1678 -- (i.e. E_Entry if Index is False, or E_Entry_Family if Index
1679 -- is set True for the entry family case). In the True case,
1680 -- makes sure that Is_AST_Entry is set on the entry.
1682 procedure Bad_AST_Entry is
1684 Error_Attr ("prefix for % attribute must be task entry", P);
1687 function OK_Entry (E : Entity_Id) return Boolean is
1692 Result := (Ekind (E) = E_Entry_Family);
1694 Result := (Ekind (E) = E_Entry);
1698 if not Is_AST_Entry (E) then
1699 Error_Msg_Name_2 := Aname;
1701 ("% attribute requires previous % pragma", P);
1708 -- Start of processing for AST_Entry
1714 -- Deal with entry family case
1716 if Nkind (P) = N_Indexed_Component then
1724 Ptyp := Etype (Pref);
1726 if Ptyp = Any_Type or else Error_Posted (Pref) then
1730 -- If the prefix is a selected component whose prefix is of an
1731 -- access type, then introduce an explicit dereference.
1733 if Nkind (Pref) = N_Selected_Component
1734 and then Is_Access_Type (Ptyp)
1737 Make_Explicit_Dereference (Sloc (Pref),
1738 Relocate_Node (Pref)));
1739 Analyze_And_Resolve (Pref, Designated_Type (Ptyp));
1742 -- Prefix can be of the form a.b, where a is a task object
1743 -- and b is one of the entries of the corresponding task type.
1745 if Nkind (Pref) = N_Selected_Component
1746 and then OK_Entry (Entity (Selector_Name (Pref)))
1747 and then Is_Object_Reference (Prefix (Pref))
1748 and then Is_Task_Type (Etype (Prefix (Pref)))
1752 -- Otherwise the prefix must be an entry of a containing task,
1753 -- or of a variable of the enclosing task type.
1756 if Nkind (Pref) = N_Identifier
1757 or else Nkind (Pref) = N_Expanded_Name
1759 Ent := Entity (Pref);
1761 if not OK_Entry (Ent)
1762 or else not In_Open_Scopes (Scope (Ent))
1772 Set_Etype (N, RTE (RE_AST_Handler));
1779 when Attribute_Base => Base : declare
1783 Check_Either_E0_Or_E1;
1787 if Sloc (Typ) = Standard_Location
1788 and then Base_Type (Typ) = Typ
1789 and then Warn_On_Redundant_Constructs
1792 ("?redudant attribute, & is its own base type", N, Typ);
1795 Set_Etype (N, Base_Type (Entity (P)));
1797 -- If we have an expression present, then really this is a conversion
1798 -- and the tree must be reformed. Note that this is one of the cases
1799 -- in which we do a replace rather than a rewrite, because the
1800 -- original tree is junk.
1802 if Present (E1) then
1804 Make_Type_Conversion (Loc,
1806 Make_Attribute_Reference (Loc,
1807 Prefix => Prefix (N),
1808 Attribute_Name => Name_Base),
1809 Expression => Relocate_Node (E1)));
1811 -- E1 may be overloaded, and its interpretations preserved.
1813 Save_Interps (E1, Expression (N));
1816 -- For other cases, set the proper type as the entity of the
1817 -- attribute reference, and then rewrite the node to be an
1818 -- occurrence of the referenced base type. This way, no one
1819 -- else in the compiler has to worry about the base attribute.
1822 Set_Entity (N, Base_Type (Entity (P)));
1824 New_Reference_To (Entity (N), Loc));
1833 when Attribute_Bit => Bit :
1837 if not Is_Object_Reference (P) then
1838 Error_Attr ("prefix for % attribute must be object", P);
1840 -- What about the access object cases ???
1846 Set_Etype (N, Universal_Integer);
1853 when Attribute_Bit_Order => Bit_Order :
1858 if not Is_Record_Type (P_Type) then
1859 Error_Attr ("prefix of % attribute must be record type", P);
1862 if Bytes_Big_Endian xor Reverse_Bit_Order (P_Type) then
1864 New_Occurrence_Of (RTE (RE_High_Order_First), Loc));
1867 New_Occurrence_Of (RTE (RE_Low_Order_First), Loc));
1870 Set_Etype (N, RTE (RE_Bit_Order));
1871 Resolve (N, Etype (N));
1873 -- Reset incorrect indication of staticness
1875 Set_Is_Static_Expression (N, False);
1882 -- Note: in generated code, we can have a Bit_Position attribute
1883 -- applied to a (naked) record component (i.e. the prefix is an
1884 -- identifier that references an E_Component or E_Discriminant
1885 -- entity directly, and this is interpreted as expected by Gigi.
1886 -- The following code will not tolerate such usage, but when the
1887 -- expander creates this special case, it marks it as analyzed
1888 -- immediately and sets an appropriate type.
1890 when Attribute_Bit_Position =>
1892 if Comes_From_Source (N) then
1896 Set_Etype (N, Universal_Integer);
1902 when Attribute_Body_Version =>
1905 Set_Etype (N, RTE (RE_Version_String));
1911 when Attribute_Callable =>
1913 Set_Etype (N, Standard_Boolean);
1920 when Attribute_Caller => Caller : declare
1927 if Nkind (P) = N_Identifier
1928 or else Nkind (P) = N_Expanded_Name
1932 if not Is_Entry (Ent) then
1933 Error_Attr ("invalid entry name", N);
1937 Error_Attr ("invalid entry name", N);
1941 for J in reverse 0 .. Scope_Stack.Last loop
1942 S := Scope_Stack.Table (J).Entity;
1944 if S = Scope (Ent) then
1945 Error_Attr ("Caller must appear in matching accept or body", N);
1951 Set_Etype (N, RTE (RO_AT_Task_ID));
1958 when Attribute_Ceiling =>
1959 Check_Floating_Point_Type_1;
1960 Set_Etype (N, P_Base_Type);
1961 Resolve (E1, P_Base_Type);
1967 when Attribute_Class => Class : declare
1969 Check_Restriction (No_Dispatch, N);
1970 Check_Either_E0_Or_E1;
1972 -- If we have an expression present, then really this is a conversion
1973 -- and the tree must be reformed into a proper conversion. This is a
1974 -- Replace rather than a Rewrite, because the original tree is junk.
1975 -- If expression is overloaded, propagate interpretations to new one.
1977 if Present (E1) then
1979 Make_Type_Conversion (Loc,
1981 Make_Attribute_Reference (Loc,
1982 Prefix => Prefix (N),
1983 Attribute_Name => Name_Class),
1984 Expression => Relocate_Node (E1)));
1986 Save_Interps (E1, Expression (N));
1989 -- Otherwise we just need to find the proper type
2001 when Attribute_Code_Address =>
2004 if Nkind (P) = N_Attribute_Reference
2005 and then (Attribute_Name (P) = Name_Elab_Body
2007 Attribute_Name (P) = Name_Elab_Spec)
2011 elsif not Is_Entity_Name (P)
2012 or else (Ekind (Entity (P)) /= E_Function
2014 Ekind (Entity (P)) /= E_Procedure)
2016 Error_Attr ("invalid prefix for % attribute", P);
2017 Set_Address_Taken (Entity (P));
2020 Set_Etype (N, RTE (RE_Address));
2022 --------------------
2023 -- Component_Size --
2024 --------------------
2026 when Attribute_Component_Size =>
2028 Set_Etype (N, Universal_Integer);
2030 -- Note: unlike other array attributes, unconstrained arrays are OK
2032 if Is_Array_Type (P_Type) and then not Is_Constrained (P_Type) then
2042 when Attribute_Compose =>
2043 Check_Floating_Point_Type_2;
2044 Set_Etype (N, P_Base_Type);
2045 Resolve (E1, P_Base_Type);
2046 Resolve (E2, Any_Integer);
2052 when Attribute_Constrained =>
2054 Set_Etype (N, Standard_Boolean);
2056 -- Case from RM J.4(2) of constrained applied to private type
2058 if Is_Entity_Name (P) and then Is_Type (Entity (P)) then
2060 -- If we are within an instance, the attribute must be legal
2061 -- because it was valid in the generic unit.
2066 -- For sure OK if we have a real private type itself, but must
2067 -- be completed, cannot apply Constrained to incomplete type.
2069 elsif Is_Private_Type (Entity (P)) then
2070 Check_Not_Incomplete_Type;
2075 Check_Object_Reference (P);
2077 -- If N does not come from source, then we allow the
2078 -- the attribute prefix to be of a private type whose
2079 -- full type has discriminants. This occurs in cases
2080 -- involving expanded calls to stream attributes.
2082 if not Comes_From_Source (N) then
2083 P_Type := Underlying_Type (P_Type);
2086 -- Must have discriminants or be an access type designating
2087 -- a type with discriminants. If it is a classwide type is
2088 -- has unknown discriminants.
2090 if Has_Discriminants (P_Type)
2091 or else Has_Unknown_Discriminants (P_Type)
2093 (Is_Access_Type (P_Type)
2094 and then Has_Discriminants (Designated_Type (P_Type)))
2098 -- Also allow an object of a generic type if extensions allowed
2099 -- and allow this for any type at all.
2101 elsif (Is_Generic_Type (P_Type)
2102 or else Is_Generic_Actual_Type (P_Type))
2103 and then Extensions_Allowed
2109 -- Fall through if bad prefix
2112 ("prefix of % attribute must be object of discriminated type", P);
2118 when Attribute_Copy_Sign =>
2119 Check_Floating_Point_Type_2;
2120 Set_Etype (N, P_Base_Type);
2121 Resolve (E1, P_Base_Type);
2122 Resolve (E2, P_Base_Type);
2128 when Attribute_Count => Count :
2137 if Nkind (P) = N_Identifier
2138 or else Nkind (P) = N_Expanded_Name
2142 if Ekind (Ent) /= E_Entry then
2143 Error_Attr ("invalid entry name", N);
2146 elsif Nkind (P) = N_Indexed_Component then
2147 Ent := Entity (Prefix (P));
2149 if Ekind (Ent) /= E_Entry_Family then
2150 Error_Attr ("invalid entry family name", P);
2155 Error_Attr ("invalid entry name", N);
2159 for J in reverse 0 .. Scope_Stack.Last loop
2160 S := Scope_Stack.Table (J).Entity;
2162 if S = Scope (Ent) then
2163 if Nkind (P) = N_Expanded_Name then
2164 Tsk := Entity (Prefix (P));
2166 -- The prefix denotes either the task type, or else a
2167 -- single task whose task type is being analyzed.
2172 or else (not Is_Type (Tsk)
2173 and then Etype (Tsk) = S
2174 and then not (Comes_From_Source (S)))
2179 ("Count must apply to entry of current task", N);
2185 elsif Ekind (Scope (Ent)) in Task_Kind
2186 and then Ekind (S) /= E_Loop
2187 and then Ekind (S) /= E_Block
2188 and then Ekind (S) /= E_Entry
2189 and then Ekind (S) /= E_Entry_Family
2191 Error_Attr ("Count cannot appear in inner unit", N);
2193 elsif Ekind (Scope (Ent)) = E_Protected_Type
2194 and then not Has_Completion (Scope (Ent))
2196 Error_Attr ("attribute % can only be used inside body", N);
2200 if Is_Overloaded (P) then
2202 Index : Interp_Index;
2206 Get_First_Interp (P, Index, It);
2208 while Present (It.Nam) loop
2209 if It.Nam = Ent then
2212 elsif Scope (It.Nam) = Scope (Ent) then
2213 Error_Attr ("ambiguous entry name", N);
2216 -- For now make this into a warning. Will become an
2217 -- error after the 3.15 release.
2220 ("ambiguous name, resolved to entry?", N);
2222 ("\(this will become an error in a later release)?", N);
2225 Get_Next_Interp (Index, It);
2230 Set_Etype (N, Universal_Integer);
2233 -----------------------
2234 -- Default_Bit_Order --
2235 -----------------------
2237 when Attribute_Default_Bit_Order => Default_Bit_Order :
2239 Check_Standard_Prefix;
2242 if Bytes_Big_Endian then
2244 Make_Integer_Literal (Loc, False_Value));
2247 Make_Integer_Literal (Loc, True_Value));
2250 Set_Etype (N, Universal_Integer);
2251 Set_Is_Static_Expression (N);
2252 end Default_Bit_Order;
2258 when Attribute_Definite =>
2259 Legal_Formal_Attribute;
2265 when Attribute_Delta =>
2266 Check_Fixed_Point_Type_0;
2267 Set_Etype (N, Universal_Real);
2273 when Attribute_Denorm =>
2274 Check_Floating_Point_Type_0;
2275 Set_Etype (N, Standard_Boolean);
2281 when Attribute_Digits =>
2285 if not Is_Floating_Point_Type (P_Type)
2286 and then not Is_Decimal_Fixed_Point_Type (P_Type)
2289 ("prefix of % attribute must be float or decimal type", P);
2292 Set_Etype (N, Universal_Integer);
2298 -- Also handles processing for Elab_Spec
2300 when Attribute_Elab_Body | Attribute_Elab_Spec =>
2302 Check_Unit_Name (P);
2303 Set_Etype (N, Standard_Void_Type);
2305 -- We have to manually call the expander in this case to get
2306 -- the necessary expansion (normally attributes that return
2307 -- entities are not expanded).
2315 -- Shares processing with Elab_Body
2321 when Attribute_Elaborated =>
2324 Set_Etype (N, Standard_Boolean);
2330 when Attribute_Emax =>
2331 Check_Floating_Point_Type_0;
2332 Set_Etype (N, Universal_Integer);
2338 when Attribute_Enum_Rep => Enum_Rep : declare
2340 if Present (E1) then
2342 Check_Discrete_Type;
2343 Resolve (E1, P_Base_Type);
2346 if not Is_Entity_Name (P)
2347 or else (not Is_Object (Entity (P))
2349 Ekind (Entity (P)) /= E_Enumeration_Literal)
2352 ("prefix of %attribute must be " &
2353 "discrete type/object or enum literal", P);
2357 Set_Etype (N, Universal_Integer);
2364 when Attribute_Epsilon =>
2365 Check_Floating_Point_Type_0;
2366 Set_Etype (N, Universal_Real);
2372 when Attribute_Exponent =>
2373 Check_Floating_Point_Type_1;
2374 Set_Etype (N, Universal_Integer);
2375 Resolve (E1, P_Base_Type);
2381 when Attribute_External_Tag =>
2385 Set_Etype (N, Standard_String);
2387 if not Is_Tagged_Type (P_Type) then
2388 Error_Attr ("prefix of % attribute must be tagged", P);
2395 when Attribute_First =>
2396 Check_Array_Or_Scalar_Type;
2402 when Attribute_First_Bit =>
2404 Set_Etype (N, Universal_Integer);
2410 when Attribute_Fixed_Value =>
2412 Check_Fixed_Point_Type;
2413 Resolve (E1, Any_Integer);
2414 Set_Etype (N, P_Base_Type);
2420 when Attribute_Floor =>
2421 Check_Floating_Point_Type_1;
2422 Set_Etype (N, P_Base_Type);
2423 Resolve (E1, P_Base_Type);
2429 when Attribute_Fore =>
2430 Check_Fixed_Point_Type_0;
2431 Set_Etype (N, Universal_Integer);
2437 when Attribute_Fraction =>
2438 Check_Floating_Point_Type_1;
2439 Set_Etype (N, P_Base_Type);
2440 Resolve (E1, P_Base_Type);
2442 -----------------------
2443 -- Has_Discriminants --
2444 -----------------------
2446 when Attribute_Has_Discriminants =>
2447 Legal_Formal_Attribute;
2453 when Attribute_Identity =>
2457 if Etype (P) = Standard_Exception_Type then
2458 Set_Etype (N, RTE (RE_Exception_Id));
2460 elsif Is_Task_Type (Etype (P))
2461 or else (Is_Access_Type (Etype (P))
2462 and then Is_Task_Type (Designated_Type (Etype (P))))
2464 Resolve (P, Etype (P));
2465 Set_Etype (N, RTE (RO_AT_Task_ID));
2468 Error_Attr ("prefix of % attribute must be a task or an "
2476 when Attribute_Image => Image :
2478 Set_Etype (N, Standard_String);
2481 if Is_Real_Type (P_Type) then
2482 if Ada_83 and then Comes_From_Source (N) then
2483 Error_Msg_Name_1 := Aname;
2485 ("(Ada 83) % attribute not allowed for real types", N);
2489 if Is_Enumeration_Type (P_Type) then
2490 Check_Restriction (No_Enumeration_Maps, N);
2494 Resolve (E1, P_Base_Type);
2496 Validate_Non_Static_Attribute_Function_Call;
2503 when Attribute_Img => Img :
2505 Set_Etype (N, Standard_String);
2507 if not Is_Scalar_Type (P_Type)
2508 or else (Is_Entity_Name (P) and then Is_Type (Entity (P)))
2511 ("prefix of % attribute must be scalar object name", N);
2521 when Attribute_Input =>
2523 Check_Stream_Attribute (Name_uInput);
2524 Disallow_In_No_Run_Time_Mode (N);
2525 Set_Etype (N, P_Base_Type);
2531 when Attribute_Integer_Value =>
2534 Resolve (E1, Any_Fixed);
2535 Set_Etype (N, P_Base_Type);
2541 when Attribute_Large =>
2544 Set_Etype (N, Universal_Real);
2550 when Attribute_Last =>
2551 Check_Array_Or_Scalar_Type;
2557 when Attribute_Last_Bit =>
2559 Set_Etype (N, Universal_Integer);
2565 when Attribute_Leading_Part =>
2566 Check_Floating_Point_Type_2;
2567 Set_Etype (N, P_Base_Type);
2568 Resolve (E1, P_Base_Type);
2569 Resolve (E2, Any_Integer);
2575 when Attribute_Length =>
2577 Set_Etype (N, Universal_Integer);
2583 when Attribute_Machine =>
2584 Check_Floating_Point_Type_1;
2585 Set_Etype (N, P_Base_Type);
2586 Resolve (E1, P_Base_Type);
2592 when Attribute_Machine_Emax =>
2593 Check_Floating_Point_Type_0;
2594 Set_Etype (N, Universal_Integer);
2600 when Attribute_Machine_Emin =>
2601 Check_Floating_Point_Type_0;
2602 Set_Etype (N, Universal_Integer);
2604 ----------------------
2605 -- Machine_Mantissa --
2606 ----------------------
2608 when Attribute_Machine_Mantissa =>
2609 Check_Floating_Point_Type_0;
2610 Set_Etype (N, Universal_Integer);
2612 -----------------------
2613 -- Machine_Overflows --
2614 -----------------------
2616 when Attribute_Machine_Overflows =>
2619 Set_Etype (N, Standard_Boolean);
2625 when Attribute_Machine_Radix =>
2628 Set_Etype (N, Universal_Integer);
2630 --------------------
2631 -- Machine_Rounds --
2632 --------------------
2634 when Attribute_Machine_Rounds =>
2637 Set_Etype (N, Standard_Boolean);
2643 when Attribute_Machine_Size =>
2646 Check_Not_Incomplete_Type;
2647 Set_Etype (N, Universal_Integer);
2653 when Attribute_Mantissa =>
2656 Set_Etype (N, Universal_Integer);
2662 when Attribute_Max =>
2665 Resolve (E1, P_Base_Type);
2666 Resolve (E2, P_Base_Type);
2667 Set_Etype (N, P_Base_Type);
2669 ----------------------------
2670 -- Max_Interrupt_Priority --
2671 ----------------------------
2673 when Attribute_Max_Interrupt_Priority =>
2678 (Parent (RTE (RE_Max_Interrupt_Priority))))));
2684 when Attribute_Max_Priority =>
2689 (Parent (RTE (RE_Max_Priority))))));
2691 ----------------------------------
2692 -- Max_Size_In_Storage_Elements --
2693 ----------------------------------
2695 when Attribute_Max_Size_In_Storage_Elements =>
2698 Check_Not_Incomplete_Type;
2699 Set_Etype (N, Universal_Integer);
2701 -----------------------
2702 -- Maximum_Alignment --
2703 -----------------------
2705 when Attribute_Maximum_Alignment =>
2706 Standard_Attribute (Ttypes.Maximum_Alignment);
2708 --------------------
2709 -- Mechanism_Code --
2710 --------------------
2712 when Attribute_Mechanism_Code =>
2714 if not Is_Entity_Name (P)
2715 or else not Is_Subprogram (Entity (P))
2717 Error_Attr ("prefix of % attribute must be subprogram", P);
2720 Check_Either_E0_Or_E1;
2722 if Present (E1) then
2723 Resolve (E1, Any_Integer);
2724 Set_Etype (E1, Standard_Integer);
2726 if not Is_Static_Expression (E1) then
2728 ("expression for parameter number must be static", E1);
2730 elsif UI_To_Int (Intval (E1)) > Number_Formals (Entity (P))
2731 or else UI_To_Int (Intval (E1)) < 0
2733 Error_Attr ("invalid parameter number for %attribute", E1);
2737 Set_Etype (N, Universal_Integer);
2743 when Attribute_Min =>
2746 Resolve (E1, P_Base_Type);
2747 Resolve (E2, P_Base_Type);
2748 Set_Etype (N, P_Base_Type);
2754 when Attribute_Model =>
2755 Check_Floating_Point_Type_1;
2756 Set_Etype (N, P_Base_Type);
2757 Resolve (E1, P_Base_Type);
2763 when Attribute_Model_Emin =>
2764 Check_Floating_Point_Type_0;
2765 Set_Etype (N, Universal_Integer);
2771 when Attribute_Model_Epsilon =>
2772 Check_Floating_Point_Type_0;
2773 Set_Etype (N, Universal_Real);
2775 --------------------
2776 -- Model_Mantissa --
2777 --------------------
2779 when Attribute_Model_Mantissa =>
2780 Check_Floating_Point_Type_0;
2781 Set_Etype (N, Universal_Integer);
2787 when Attribute_Model_Small =>
2788 Check_Floating_Point_Type_0;
2789 Set_Etype (N, Universal_Real);
2795 when Attribute_Modulus =>
2799 if not Is_Modular_Integer_Type (P_Type) then
2800 Error_Attr ("prefix of % attribute must be modular type", P);
2803 Set_Etype (N, Universal_Integer);
2805 --------------------
2806 -- Null_Parameter --
2807 --------------------
2809 when Attribute_Null_Parameter => Null_Parameter : declare
2810 Parnt : constant Node_Id := Parent (N);
2811 GParnt : constant Node_Id := Parent (Parnt);
2813 procedure Bad_Null_Parameter (Msg : String);
2814 -- Used if bad Null parameter attribute node is found. Issues
2815 -- given error message, and also sets the type to Any_Type to
2816 -- avoid blowups later on from dealing with a junk node.
2818 procedure Must_Be_Imported (Proc_Ent : Entity_Id);
2819 -- Called to check that Proc_Ent is imported subprogram
2821 ------------------------
2822 -- Bad_Null_Parameter --
2823 ------------------------
2825 procedure Bad_Null_Parameter (Msg : String) is
2827 Error_Msg_N (Msg, N);
2828 Set_Etype (N, Any_Type);
2829 end Bad_Null_Parameter;
2831 ----------------------
2832 -- Must_Be_Imported --
2833 ----------------------
2835 procedure Must_Be_Imported (Proc_Ent : Entity_Id) is
2836 Pent : Entity_Id := Proc_Ent;
2839 while Present (Alias (Pent)) loop
2840 Pent := Alias (Pent);
2843 -- Ignore check if procedure not frozen yet (we will get
2844 -- another chance when the default parameter is reanalyzed)
2846 if not Is_Frozen (Pent) then
2849 elsif not Is_Imported (Pent) then
2851 ("Null_Parameter can only be used with imported subprogram");
2856 end Must_Be_Imported;
2858 -- Start of processing for Null_Parameter
2863 Set_Etype (N, P_Type);
2865 -- Case of attribute used as default expression
2867 if Nkind (Parnt) = N_Parameter_Specification then
2868 Must_Be_Imported (Defining_Entity (GParnt));
2870 -- Case of attribute used as actual for subprogram (positional)
2872 elsif (Nkind (Parnt) = N_Procedure_Call_Statement
2874 Nkind (Parnt) = N_Function_Call)
2875 and then Is_Entity_Name (Name (Parnt))
2877 Must_Be_Imported (Entity (Name (Parnt)));
2879 -- Case of attribute used as actual for subprogram (named)
2881 elsif Nkind (Parnt) = N_Parameter_Association
2882 and then (Nkind (GParnt) = N_Procedure_Call_Statement
2884 Nkind (GParnt) = N_Function_Call)
2885 and then Is_Entity_Name (Name (GParnt))
2887 Must_Be_Imported (Entity (Name (GParnt)));
2889 -- Not an allowed case
2893 ("Null_Parameter must be actual or default parameter");
2902 when Attribute_Object_Size =>
2905 Check_Not_Incomplete_Type;
2906 Set_Etype (N, Universal_Integer);
2912 when Attribute_Output =>
2914 Check_Stream_Attribute (Name_uInput);
2915 Set_Etype (N, Standard_Void_Type);
2916 Disallow_In_No_Run_Time_Mode (N);
2917 Resolve (N, Standard_Void_Type);
2923 when Attribute_Partition_ID =>
2926 if P_Type /= Any_Type then
2927 if not Is_Library_Level_Entity (Entity (P)) then
2929 ("prefix of % attribute must be library-level entity", P);
2931 -- The defining entity of prefix should not be declared inside
2932 -- a Pure unit. RM E.1(8).
2933 -- The Is_Pure flag has been set during declaration.
2935 elsif Is_Entity_Name (P)
2936 and then Is_Pure (Entity (P))
2939 ("prefix of % attribute must not be declared pure", P);
2943 Set_Etype (N, Universal_Integer);
2945 -------------------------
2946 -- Passed_By_Reference --
2947 -------------------------
2949 when Attribute_Passed_By_Reference =>
2952 Set_Etype (N, Standard_Boolean);
2958 when Attribute_Pos =>
2959 Check_Discrete_Type;
2961 Resolve (E1, P_Base_Type);
2962 Set_Etype (N, Universal_Integer);
2968 when Attribute_Position =>
2970 Set_Etype (N, Universal_Integer);
2976 when Attribute_Pred =>
2979 Resolve (E1, P_Base_Type);
2980 Set_Etype (N, P_Base_Type);
2982 -- Nothing to do for real type case
2984 if Is_Real_Type (P_Type) then
2987 -- If not modular type, test for overflow check required
2990 if not Is_Modular_Integer_Type (P_Type)
2991 and then not Range_Checks_Suppressed (P_Base_Type)
2993 Enable_Range_Check (E1);
3001 when Attribute_Range =>
3002 Check_Array_Or_Scalar_Type;
3005 and then Is_Scalar_Type (P_Type)
3006 and then Comes_From_Source (N)
3009 ("(Ada 83) % attribute not allowed for scalar type", P);
3016 when Attribute_Range_Length =>
3017 Check_Discrete_Type;
3018 Set_Etype (N, Universal_Integer);
3024 when Attribute_Read =>
3026 Check_Stream_Attribute (Name_uRead);
3027 Set_Etype (N, Standard_Void_Type);
3028 Resolve (N, Standard_Void_Type);
3029 Disallow_In_No_Run_Time_Mode (N);
3030 Note_Possible_Modification (E2);
3036 when Attribute_Remainder =>
3037 Check_Floating_Point_Type_2;
3038 Set_Etype (N, P_Base_Type);
3039 Resolve (E1, P_Base_Type);
3040 Resolve (E2, P_Base_Type);
3046 when Attribute_Round =>
3048 Check_Decimal_Fixed_Point_Type;
3049 Set_Etype (N, P_Base_Type);
3051 -- Because the context is universal_real (3.5.10(12)) it is a legal
3052 -- context for a universal fixed expression. This is the only
3053 -- attribute whose functional description involves U_R.
3055 if Etype (E1) = Universal_Fixed then
3057 Conv : constant Node_Id := Make_Type_Conversion (Loc,
3058 Subtype_Mark => New_Occurrence_Of (Universal_Real, Loc),
3059 Expression => Relocate_Node (E1));
3067 Resolve (E1, Any_Real);
3073 when Attribute_Rounding =>
3074 Check_Floating_Point_Type_1;
3075 Set_Etype (N, P_Base_Type);
3076 Resolve (E1, P_Base_Type);
3082 when Attribute_Safe_Emax =>
3083 Check_Floating_Point_Type_0;
3084 Set_Etype (N, Universal_Integer);
3090 when Attribute_Safe_First =>
3091 Check_Floating_Point_Type_0;
3092 Set_Etype (N, Universal_Real);
3098 when Attribute_Safe_Large =>
3101 Set_Etype (N, Universal_Real);
3107 when Attribute_Safe_Last =>
3108 Check_Floating_Point_Type_0;
3109 Set_Etype (N, Universal_Real);
3115 when Attribute_Safe_Small =>
3118 Set_Etype (N, Universal_Real);
3124 when Attribute_Scale =>
3126 Check_Decimal_Fixed_Point_Type;
3127 Set_Etype (N, Universal_Integer);
3133 when Attribute_Scaling =>
3134 Check_Floating_Point_Type_2;
3135 Set_Etype (N, P_Base_Type);
3136 Resolve (E1, P_Base_Type);
3142 when Attribute_Signed_Zeros =>
3143 Check_Floating_Point_Type_0;
3144 Set_Etype (N, Standard_Boolean);
3150 when Attribute_Size | Attribute_VADS_Size =>
3153 if Is_Object_Reference (P)
3154 or else (Is_Entity_Name (P)
3155 and then Ekind (Entity (P)) = E_Function)
3157 Check_Object_Reference (P);
3159 elsif Is_Entity_Name (P)
3160 and then Is_Type (Entity (P))
3164 elsif Nkind (P) = N_Type_Conversion
3165 and then not Comes_From_Source (P)
3170 Error_Attr ("invalid prefix for % attribute", P);
3173 Check_Not_Incomplete_Type;
3174 Set_Etype (N, Universal_Integer);
3180 when Attribute_Small =>
3183 Set_Etype (N, Universal_Real);
3189 when Attribute_Storage_Pool =>
3190 if Is_Access_Type (P_Type) then
3193 -- Set appropriate entity
3195 if Present (Associated_Storage_Pool (Root_Type (P_Type))) then
3196 Set_Entity (N, Associated_Storage_Pool (Root_Type (P_Type)));
3198 Set_Entity (N, RTE (RE_Global_Pool_Object));
3201 Set_Etype (N, Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
3203 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
3204 -- Storage_Pool since this attribute is not defined for such
3205 -- types (RM E.2.3(22)).
3207 Validate_Remote_Access_To_Class_Wide_Type (N);
3210 Error_Attr ("prefix of % attribute must be access type", P);
3217 when Attribute_Storage_Size =>
3219 if Is_Task_Type (P_Type) then
3221 Set_Etype (N, Universal_Integer);
3223 elsif Is_Access_Type (P_Type) then
3224 if Is_Entity_Name (P)
3225 and then Is_Type (Entity (P))
3229 Set_Etype (N, Universal_Integer);
3231 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
3232 -- Storage_Size since this attribute is not defined for
3233 -- such types (RM E.2.3(22)).
3235 Validate_Remote_Access_To_Class_Wide_Type (N);
3237 -- The prefix is allowed to be an implicit dereference
3238 -- of an access value designating a task.
3243 Set_Etype (N, Universal_Integer);
3248 ("prefix of % attribute must be access or task type", P);
3255 when Attribute_Storage_Unit =>
3256 Standard_Attribute (Ttypes.System_Storage_Unit);
3262 when Attribute_Succ =>
3265 Resolve (E1, P_Base_Type);
3266 Set_Etype (N, P_Base_Type);
3268 -- Nothing to do for real type case
3270 if Is_Real_Type (P_Type) then
3273 -- If not modular type, test for overflow check required.
3276 if not Is_Modular_Integer_Type (P_Type)
3277 and then not Range_Checks_Suppressed (P_Base_Type)
3279 Enable_Range_Check (E1);
3287 when Attribute_Tag =>
3291 if not Is_Tagged_Type (P_Type) then
3292 Error_Attr ("prefix of % attribute must be tagged", P);
3294 -- Next test does not apply to generated code
3295 -- why not, and what does the illegal reference mean???
3297 elsif Is_Object_Reference (P)
3298 and then not Is_Class_Wide_Type (P_Type)
3299 and then Comes_From_Source (N)
3302 ("% attribute can only be applied to objects of class-wide type",
3306 Set_Etype (N, RTE (RE_Tag));
3312 when Attribute_Terminated =>
3314 Set_Etype (N, Standard_Boolean);
3321 when Attribute_Tick =>
3322 Check_Standard_Prefix;
3324 Make_Real_Literal (Loc,
3325 UR_From_Components (
3326 Num => UI_From_Int (Ttypes.System_Tick_Nanoseconds),
3327 Den => UI_From_Int (9),
3335 when Attribute_To_Address =>
3339 if Nkind (P) /= N_Identifier
3340 or else Chars (P) /= Name_System
3342 Error_Attr ("prefix of %attribute must be System", P);
3345 Generate_Reference (RTE (RE_Address), P);
3346 Analyze_And_Resolve (E1, Any_Integer);
3347 Set_Etype (N, RTE (RE_Address));
3353 when Attribute_Truncation =>
3354 Check_Floating_Point_Type_1;
3355 Resolve (E1, P_Base_Type);
3356 Set_Etype (N, P_Base_Type);
3362 when Attribute_Type_Class =>
3365 Check_Not_Incomplete_Type;
3366 Set_Etype (N, RTE (RE_Type_Class));
3372 when Attribute_UET_Address =>
3374 Check_Unit_Name (P);
3375 Set_Etype (N, RTE (RE_Address));
3377 -----------------------
3378 -- Unbiased_Rounding --
3379 -----------------------
3381 when Attribute_Unbiased_Rounding =>
3382 Check_Floating_Point_Type_1;
3383 Set_Etype (N, P_Base_Type);
3384 Resolve (E1, P_Base_Type);
3386 ----------------------
3387 -- Unchecked_Access --
3388 ----------------------
3390 when Attribute_Unchecked_Access =>
3391 if Comes_From_Source (N) then
3392 Check_Restriction (No_Unchecked_Access, N);
3397 ------------------------------
3398 -- Universal_Literal_String --
3399 ------------------------------
3401 -- This is a GNAT specific attribute whose prefix must be a named
3402 -- number where the expression is either a single numeric literal,
3403 -- or a numeric literal immediately preceded by a minus sign. The
3404 -- result is equivalent to a string literal containing the text of
3405 -- the literal as it appeared in the source program with a possible
3406 -- leading minus sign.
3408 when Attribute_Universal_Literal_String => Universal_Literal_String :
3412 if not Is_Entity_Name (P)
3413 or else Ekind (Entity (P)) not in Named_Kind
3415 Error_Attr ("prefix for % attribute must be named number", P);
3422 Src : Source_Buffer_Ptr;
3425 Expr := Original_Node (Expression (Parent (Entity (P))));
3427 if Nkind (Expr) = N_Op_Minus then
3429 Expr := Original_Node (Right_Opnd (Expr));