1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2004, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Ada.Characters.Latin_1; use Ada.Characters.Latin_1;
29 with Atree; use Atree;
30 with Checks; use Checks;
31 with Einfo; use Einfo;
32 with Errout; use Errout;
34 with Exp_Tss; use Exp_Tss;
35 with Exp_Util; use Exp_Util;
36 with Expander; use Expander;
37 with Freeze; use Freeze;
39 with Lib.Xref; use Lib.Xref;
40 with Namet; use Namet;
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 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 : 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 -----------------------
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 -----------------------
178 -- Local Subprograms --
179 -----------------------
181 procedure Analyze_Access_Attribute;
182 -- Used for Access, Unchecked_Access, Unrestricted_Access attributes.
183 -- Internally, Id distinguishes which of the three cases is involved.
185 procedure Check_Array_Or_Scalar_Type;
186 -- Common procedure used by First, Last, Range attribute to check
187 -- that the prefix is a constrained array or scalar type, or a name
188 -- of an array object, and that an argument appears only if appropriate
189 -- (i.e. only in the array case).
191 procedure Check_Array_Type;
192 -- Common semantic checks for all array attributes. Checks that the
193 -- prefix is a constrained array type or the name of an array object.
194 -- The error message for non-arrays is specialized appropriately.
196 procedure Check_Asm_Attribute;
197 -- Common semantic checks for Asm_Input and Asm_Output attributes
199 procedure Check_Component;
200 -- Common processing for Bit_Position, First_Bit, Last_Bit, and
201 -- Position. Checks prefix is an appropriate selected component.
203 procedure Check_Decimal_Fixed_Point_Type;
204 -- Check that prefix of attribute N is a decimal fixed-point type
206 procedure Check_Dereference;
207 -- If the prefix of attribute is an object of an access type, then
208 -- introduce an explicit deference, and adjust P_Type accordingly.
210 procedure Check_Discrete_Type;
211 -- Verify that prefix of attribute N is a discrete type
214 -- Check that no attribute arguments are present
216 procedure Check_Either_E0_Or_E1;
217 -- Check that there are zero or one attribute arguments present
220 -- Check that exactly one attribute argument is present
223 -- Check that two attribute arguments are present
225 procedure Check_Enum_Image;
226 -- If the prefix type is an enumeration type, set all its literals
227 -- as referenced, since the image function could possibly end up
228 -- referencing any of the literals indirectly.
230 procedure Check_Fixed_Point_Type;
231 -- Verify that prefix of attribute N is a fixed type
233 procedure Check_Fixed_Point_Type_0;
234 -- Verify that prefix of attribute N is a fixed type and that
235 -- no attribute expressions are present
237 procedure Check_Floating_Point_Type;
238 -- Verify that prefix of attribute N is a float type
240 procedure Check_Floating_Point_Type_0;
241 -- Verify that prefix of attribute N is a float type and that
242 -- no attribute expressions are present
244 procedure Check_Floating_Point_Type_1;
245 -- Verify that prefix of attribute N is a float type and that
246 -- exactly one attribute expression is present
248 procedure Check_Floating_Point_Type_2;
249 -- Verify that prefix of attribute N is a float type and that
250 -- two attribute expressions are present
252 procedure Legal_Formal_Attribute;
253 -- Common processing for attributes Definite, Has_Access_Values,
254 -- and Has_Discriminants
256 procedure Check_Integer_Type;
257 -- Verify that prefix of attribute N is an integer type
259 procedure Check_Library_Unit;
260 -- Verify that prefix of attribute N is a library unit
262 procedure Check_Not_Incomplete_Type;
263 -- Check that P (the prefix of the attribute) is not an incomplete
264 -- type or a private type for which no full view has been given.
266 procedure Check_Object_Reference (P : Node_Id);
267 -- Check that P (the prefix of the attribute) is an object reference
269 procedure Check_Program_Unit;
270 -- Verify that prefix of attribute N is a program unit
272 procedure Check_Real_Type;
273 -- Verify that prefix of attribute N is fixed or float type
275 procedure Check_Scalar_Type;
276 -- Verify that prefix of attribute N is a scalar type
278 procedure Check_Standard_Prefix;
279 -- Verify that prefix of attribute N is package Standard
281 procedure Check_Stream_Attribute (Nam : TSS_Name_Type);
282 -- Validity checking for stream attribute. Nam is the TSS name of the
283 -- corresponding possible defined attribute function (e.g. for the
284 -- Read attribute, Nam will be TSS_Stream_Read).
286 procedure Check_Task_Prefix;
287 -- Verify that prefix of attribute N is a task or task type
289 procedure Check_Type;
290 -- Verify that the prefix of attribute N is a type
292 procedure Check_Unit_Name (Nod : Node_Id);
293 -- Check that Nod is of the form of a library unit name, i.e that
294 -- it is an identifier, or a selected component whose prefix is
295 -- itself of the form of a library unit name. Note that this is
296 -- quite different from Check_Program_Unit, since it only checks
297 -- the syntactic form of the name, not the semantic identity. This
298 -- is because it is used with attributes (Elab_Body, Elab_Spec, and
299 -- UET_Address) which can refer to non-visible unit.
301 procedure Error_Attr (Msg : String; Error_Node : Node_Id);
302 pragma No_Return (Error_Attr);
303 procedure Error_Attr;
304 pragma No_Return (Error_Attr);
305 -- Posts error using Error_Msg_N at given node, sets type of attribute
306 -- node to Any_Type, and then raises Bad_Attribute to avoid any further
307 -- semantic processing. The message typically contains a % insertion
308 -- character which is replaced by the attribute name. The call with
309 -- no arguments is used when the caller has already generated the
310 -- required error messages.
312 procedure Standard_Attribute (Val : Int);
313 -- Used to process attributes whose prefix is package Standard which
314 -- yield values of type Universal_Integer. The attribute reference
315 -- node is rewritten with an integer literal of the given value.
317 procedure Unexpected_Argument (En : Node_Id);
318 -- Signal unexpected attribute argument (En is the argument)
320 procedure Validate_Non_Static_Attribute_Function_Call;
321 -- Called when processing an attribute that is a function call to a
322 -- non-static function, i.e. an attribute function that either takes
323 -- non-scalar arguments or returns a non-scalar result. Verifies that
324 -- such a call does not appear in a preelaborable context.
326 ------------------------------
327 -- Analyze_Access_Attribute --
328 ------------------------------
330 procedure Analyze_Access_Attribute is
331 Acc_Type : Entity_Id;
336 function Build_Access_Object_Type (DT : Entity_Id) return Entity_Id;
337 -- Build an access-to-object type whose designated type is DT,
338 -- and whose Ekind is appropriate to the attribute type. The
339 -- type that is constructed is returned as the result.
341 procedure Build_Access_Subprogram_Type (P : Node_Id);
342 -- Build an access to subprogram whose designated type is
343 -- the type of the prefix. If prefix is overloaded, so it the
344 -- node itself. The result is stored in Acc_Type.
346 ------------------------------
347 -- Build_Access_Object_Type --
348 ------------------------------
350 function Build_Access_Object_Type (DT : Entity_Id) return Entity_Id is
354 if Aname = Name_Unrestricted_Access then
357 (E_Allocator_Type, Current_Scope, Loc, 'A');
361 (E_Access_Attribute_Type, Current_Scope, Loc, 'A');
364 Set_Etype (Typ, Typ);
365 Init_Size_Align (Typ);
367 Set_Associated_Node_For_Itype (Typ, N);
368 Set_Directly_Designated_Type (Typ, DT);
370 end Build_Access_Object_Type;
372 ----------------------------------
373 -- Build_Access_Subprogram_Type --
374 ----------------------------------
376 procedure Build_Access_Subprogram_Type (P : Node_Id) is
377 Index : Interp_Index;
380 function Get_Kind (E : Entity_Id) return Entity_Kind;
381 -- Distinguish between access to regular and protected
388 function Get_Kind (E : Entity_Id) return Entity_Kind is
390 if Convention (E) = Convention_Protected then
391 return E_Access_Protected_Subprogram_Type;
393 return E_Access_Subprogram_Type;
397 -- Start of processing for Build_Access_Subprogram_Type
400 -- In the case of an access to subprogram, use the name of the
401 -- subprogram itself as the designated type. Type-checking in
402 -- this case compares the signatures of the designated types.
404 if not Is_Overloaded (P) then
407 (Get_Kind (Entity (P)), Current_Scope, Loc, 'A');
408 Set_Etype (Acc_Type, Acc_Type);
409 Set_Directly_Designated_Type (Acc_Type, Entity (P));
410 Set_Etype (N, Acc_Type);
413 Get_First_Interp (P, Index, It);
414 Set_Etype (N, Any_Type);
416 while Present (It.Nam) loop
417 if not Is_Intrinsic_Subprogram (It.Nam) then
420 (Get_Kind (It.Nam), Current_Scope, Loc, 'A');
421 Set_Etype (Acc_Type, Acc_Type);
422 Set_Directly_Designated_Type (Acc_Type, It.Nam);
423 Add_One_Interp (N, Acc_Type, Acc_Type);
426 Get_Next_Interp (Index, It);
429 if Etype (N) = Any_Type then
430 Error_Attr ("prefix of % attribute cannot be intrinsic", P);
433 end Build_Access_Subprogram_Type;
435 -- Start of processing for Analyze_Access_Attribute
440 if Nkind (P) = N_Character_Literal then
442 ("prefix of % attribute cannot be enumeration literal", P);
445 -- Case of access to subprogram
447 if Is_Entity_Name (P)
448 and then Is_Overloadable (Entity (P))
450 -- Not allowed for nested subprograms if No_Implicit_Dynamic_Code
451 -- restriction set (since in general a trampoline is required).
453 if not Is_Library_Level_Entity (Entity (P)) then
454 Check_Restriction (No_Implicit_Dynamic_Code, P);
457 -- Build the appropriate subprogram type
459 Build_Access_Subprogram_Type (P);
461 -- For unrestricted access, kill current values, since this
462 -- attribute allows a reference to a local subprogram that
463 -- could modify local variables to be passed out of scope
465 if Aname = Name_Unrestricted_Access then
471 -- Component is an operation of a protected type
473 elsif Nkind (P) = N_Selected_Component
474 and then Is_Overloadable (Entity (Selector_Name (P)))
476 if Ekind (Entity (Selector_Name (P))) = E_Entry then
477 Error_Attr ("prefix of % attribute must be subprogram", P);
480 Build_Access_Subprogram_Type (Selector_Name (P));
484 -- Deal with incorrect reference to a type, but note that some
485 -- accesses are allowed (references to the current type instance).
487 if Is_Entity_Name (P) then
488 Scop := Current_Scope;
491 if Is_Type (Typ) then
493 -- OK if we are within the scope of a limited type
494 -- let's mark the component as having per object constraint
496 if Is_Anonymous_Tagged_Base (Scop, Typ) then
504 Q : Node_Id := Parent (N);
508 and then Nkind (Q) /= N_Component_Declaration
513 Set_Has_Per_Object_Constraint (
514 Defining_Identifier (Q), True);
518 if Nkind (P) = N_Expanded_Name then
520 ("current instance prefix must be a direct name", P);
523 -- If a current instance attribute appears within a
524 -- a component constraint it must appear alone; other
525 -- contexts (default expressions, within a task body)
526 -- are not subject to this restriction.
528 if not In_Default_Expression
529 and then not Has_Completion (Scop)
531 Nkind (Parent (N)) /= N_Discriminant_Association
533 Nkind (Parent (N)) /= N_Index_Or_Discriminant_Constraint
536 ("current instance attribute must appear alone", N);
539 -- OK if we are in initialization procedure for the type
540 -- in question, in which case the reference to the type
541 -- is rewritten as a reference to the current object.
543 elsif Ekind (Scop) = E_Procedure
544 and then Is_Init_Proc (Scop)
545 and then Etype (First_Formal (Scop)) = Typ
548 Make_Attribute_Reference (Loc,
549 Prefix => Make_Identifier (Loc, Name_uInit),
550 Attribute_Name => Name_Unrestricted_Access));
554 -- OK if a task type, this test needs sharpening up ???
556 elsif Is_Task_Type (Typ) then
559 -- Otherwise we have an error case
562 Error_Attr ("% attribute cannot be applied to type", P);
568 -- If we fall through, we have a normal access to object case.
569 -- Unrestricted_Access is legal wherever an allocator would be
570 -- legal, so its Etype is set to E_Allocator. The expected type
571 -- of the other attributes is a general access type, and therefore
572 -- we label them with E_Access_Attribute_Type.
574 if not Is_Overloaded (P) then
575 Acc_Type := Build_Access_Object_Type (P_Type);
576 Set_Etype (N, Acc_Type);
579 Index : Interp_Index;
583 Set_Etype (N, Any_Type);
584 Get_First_Interp (P, Index, It);
586 while Present (It.Typ) loop
587 Acc_Type := Build_Access_Object_Type (It.Typ);
588 Add_One_Interp (N, Acc_Type, Acc_Type);
589 Get_Next_Interp (Index, It);
594 -- If we have an access to an object, and the attribute comes
595 -- from source, then set the object as potentially source modified.
596 -- We do this because the resulting access pointer can be used to
597 -- modify the variable, and we might not detect this, leading to
598 -- some junk warnings.
600 if Is_Entity_Name (P) then
601 Set_Never_Set_In_Source (Entity (P), False);
604 -- Check for aliased view unless unrestricted case. We allow
605 -- a nonaliased prefix when within an instance because the
606 -- prefix may have been a tagged formal object, which is
607 -- defined to be aliased even when the actual might not be
608 -- (other instance cases will have been caught in the generic).
609 -- Similarly, within an inlined body we know that the attribute
610 -- is legal in the original subprogram, and therefore legal in
613 if Aname /= Name_Unrestricted_Access
614 and then not Is_Aliased_View (P)
615 and then not In_Instance
616 and then not In_Inlined_Body
618 Error_Attr ("prefix of % attribute must be aliased", P);
620 end Analyze_Access_Attribute;
622 --------------------------------
623 -- Check_Array_Or_Scalar_Type --
624 --------------------------------
626 procedure Check_Array_Or_Scalar_Type is
630 -- Dimension number for array attributes.
633 -- Case of string literal or string literal subtype. These cases
634 -- cannot arise from legal Ada code, but the expander is allowed
635 -- to generate them. They require special handling because string
636 -- literal subtypes do not have standard bounds (the whole idea
637 -- of these subtypes is to avoid having to generate the bounds)
639 if Ekind (P_Type) = E_String_Literal_Subtype then
640 Set_Etype (N, Etype (First_Index (P_Base_Type)));
645 elsif Is_Scalar_Type (P_Type) then
649 Error_Attr ("invalid argument in % attribute", E1);
651 Set_Etype (N, P_Base_Type);
655 -- The following is a special test to allow 'First to apply to
656 -- private scalar types if the attribute comes from generated
657 -- code. This occurs in the case of Normalize_Scalars code.
659 elsif Is_Private_Type (P_Type)
660 and then Present (Full_View (P_Type))
661 and then Is_Scalar_Type (Full_View (P_Type))
662 and then not Comes_From_Source (N)
664 Set_Etype (N, Implementation_Base_Type (P_Type));
666 -- Array types other than string literal subtypes handled above
671 -- We know prefix is an array type, or the name of an array
672 -- object, and that the expression, if present, is static
673 -- and within the range of the dimensions of the type.
675 pragma Assert (Is_Array_Type (P_Type));
676 Index := First_Index (P_Base_Type);
680 -- First dimension assumed
682 Set_Etype (N, Base_Type (Etype (Index)));
685 D := UI_To_Int (Intval (E1));
687 for J in 1 .. D - 1 loop
691 Set_Etype (N, Base_Type (Etype (Index)));
692 Set_Etype (E1, Standard_Integer);
695 end Check_Array_Or_Scalar_Type;
697 ----------------------
698 -- Check_Array_Type --
699 ----------------------
701 procedure Check_Array_Type is
703 -- Dimension number for array attributes.
706 -- If the type is a string literal type, then this must be generated
707 -- internally, and no further check is required on its legality.
709 if Ekind (P_Type) = E_String_Literal_Subtype then
712 -- If the type is a composite, it is an illegal aggregate, no point
715 elsif P_Type = Any_Composite then
719 -- Normal case of array type or subtype
721 Check_Either_E0_Or_E1;
724 if Is_Array_Type (P_Type) then
725 if not Is_Constrained (P_Type)
726 and then Is_Entity_Name (P)
727 and then Is_Type (Entity (P))
729 -- Note: we do not call Error_Attr here, since we prefer to
730 -- continue, using the relevant index type of the array,
731 -- even though it is unconstrained. This gives better error
732 -- recovery behavior.
734 Error_Msg_Name_1 := Aname;
736 ("prefix for % attribute must be constrained array", P);
739 D := Number_Dimensions (P_Type);
742 if Is_Private_Type (P_Type) then
744 ("prefix for % attribute may not be private type", P);
746 elsif Is_Access_Type (P_Type)
747 and then Is_Array_Type (Designated_Type (P_Type))
748 and then Is_Entity_Name (P)
749 and then Is_Type (Entity (P))
751 Error_Attr ("prefix of % attribute cannot be access type", P);
753 elsif Attr_Id = Attribute_First
755 Attr_Id = Attribute_Last
757 Error_Attr ("invalid prefix for % attribute", P);
760 Error_Attr ("prefix for % attribute must be array", P);
765 Resolve (E1, Any_Integer);
766 Set_Etype (E1, Standard_Integer);
768 if not Is_Static_Expression (E1)
769 or else Raises_Constraint_Error (E1)
772 ("expression for dimension must be static!", E1);
775 elsif UI_To_Int (Expr_Value (E1)) > D
776 or else UI_To_Int (Expr_Value (E1)) < 1
778 Error_Attr ("invalid dimension number for array type", E1);
781 end Check_Array_Type;
783 -------------------------
784 -- Check_Asm_Attribute --
785 -------------------------
787 procedure Check_Asm_Attribute is
792 -- Check first argument is static string expression
794 Analyze_And_Resolve (E1, Standard_String);
796 if Etype (E1) = Any_Type then
799 elsif not Is_OK_Static_Expression (E1) then
801 ("constraint argument must be static string expression!", E1);
805 -- Check second argument is right type
807 Analyze_And_Resolve (E2, Entity (P));
809 -- Note: that is all we need to do, we don't need to check
810 -- that it appears in a correct context. The Ada type system
811 -- will do that for us.
813 end Check_Asm_Attribute;
815 ---------------------
816 -- Check_Component --
817 ---------------------
819 procedure Check_Component is
823 if Nkind (P) /= N_Selected_Component
825 (Ekind (Entity (Selector_Name (P))) /= E_Component
827 Ekind (Entity (Selector_Name (P))) /= E_Discriminant)
830 ("prefix for % attribute must be selected component", P);
834 ------------------------------------
835 -- Check_Decimal_Fixed_Point_Type --
836 ------------------------------------
838 procedure Check_Decimal_Fixed_Point_Type is
842 if not Is_Decimal_Fixed_Point_Type (P_Type) then
844 ("prefix of % attribute must be decimal type", P);
846 end Check_Decimal_Fixed_Point_Type;
848 -----------------------
849 -- Check_Dereference --
850 -----------------------
852 procedure Check_Dereference is
855 -- Case of a subtype mark
857 if Is_Entity_Name (P)
858 and then Is_Type (Entity (P))
863 -- Case of an expression
867 if Is_Access_Type (P_Type) then
869 -- If there is an implicit dereference, then we must freeze
870 -- the designated type of the access type, since the type of
871 -- the referenced array is this type (see AI95-00106).
873 Freeze_Before (N, Designated_Type (P_Type));
876 Make_Explicit_Dereference (Sloc (P),
877 Prefix => Relocate_Node (P)));
879 Analyze_And_Resolve (P);
882 if P_Type = Any_Type then
886 P_Base_Type := Base_Type (P_Type);
888 end Check_Dereference;
890 -------------------------
891 -- Check_Discrete_Type --
892 -------------------------
894 procedure Check_Discrete_Type is
898 if not Is_Discrete_Type (P_Type) then
899 Error_Attr ("prefix of % attribute must be discrete type", P);
901 end Check_Discrete_Type;
907 procedure Check_E0 is
910 Unexpected_Argument (E1);
918 procedure Check_E1 is
920 Check_Either_E0_Or_E1;
924 -- Special-case attributes that are functions and that appear as
925 -- the prefix of another attribute. Error is posted on parent.
927 if Nkind (Parent (N)) = N_Attribute_Reference
928 and then (Attribute_Name (Parent (N)) = Name_Address
930 Attribute_Name (Parent (N)) = Name_Code_Address
932 Attribute_Name (Parent (N)) = Name_Access)
934 Error_Msg_Name_1 := Attribute_Name (Parent (N));
935 Error_Msg_N ("illegal prefix for % attribute", Parent (N));
936 Set_Etype (Parent (N), Any_Type);
937 Set_Entity (Parent (N), Any_Type);
941 Error_Attr ("missing argument for % attribute", N);
950 procedure Check_E2 is
953 Error_Attr ("missing arguments for % attribute (2 required)", N);
955 Error_Attr ("missing argument for % attribute (2 required)", N);
959 ---------------------------
960 -- Check_Either_E0_Or_E1 --
961 ---------------------------
963 procedure Check_Either_E0_Or_E1 is
966 Unexpected_Argument (E2);
968 end Check_Either_E0_Or_E1;
970 ----------------------
971 -- Check_Enum_Image --
972 ----------------------
974 procedure Check_Enum_Image is
978 if Is_Enumeration_Type (P_Base_Type) then
979 Lit := First_Literal (P_Base_Type);
980 while Present (Lit) loop
981 Set_Referenced (Lit);
985 end Check_Enum_Image;
987 ----------------------------
988 -- Check_Fixed_Point_Type --
989 ----------------------------
991 procedure Check_Fixed_Point_Type is
995 if not Is_Fixed_Point_Type (P_Type) then
996 Error_Attr ("prefix of % attribute must be fixed point type", P);
998 end Check_Fixed_Point_Type;
1000 ------------------------------
1001 -- Check_Fixed_Point_Type_0 --
1002 ------------------------------
1004 procedure Check_Fixed_Point_Type_0 is
1006 Check_Fixed_Point_Type;
1008 end Check_Fixed_Point_Type_0;
1010 -------------------------------
1011 -- Check_Floating_Point_Type --
1012 -------------------------------
1014 procedure Check_Floating_Point_Type is
1018 if not Is_Floating_Point_Type (P_Type) then
1019 Error_Attr ("prefix of % attribute must be float type", P);
1021 end Check_Floating_Point_Type;
1023 ---------------------------------
1024 -- Check_Floating_Point_Type_0 --
1025 ---------------------------------
1027 procedure Check_Floating_Point_Type_0 is
1029 Check_Floating_Point_Type;
1031 end Check_Floating_Point_Type_0;
1033 ---------------------------------
1034 -- Check_Floating_Point_Type_1 --
1035 ---------------------------------
1037 procedure Check_Floating_Point_Type_1 is
1039 Check_Floating_Point_Type;
1041 end Check_Floating_Point_Type_1;
1043 ---------------------------------
1044 -- Check_Floating_Point_Type_2 --
1045 ---------------------------------
1047 procedure Check_Floating_Point_Type_2 is
1049 Check_Floating_Point_Type;
1051 end Check_Floating_Point_Type_2;
1053 ------------------------
1054 -- Check_Integer_Type --
1055 ------------------------
1057 procedure Check_Integer_Type is
1061 if not Is_Integer_Type (P_Type) then
1062 Error_Attr ("prefix of % attribute must be integer type", P);
1064 end Check_Integer_Type;
1066 ------------------------
1067 -- Check_Library_Unit --
1068 ------------------------
1070 procedure Check_Library_Unit is
1072 if not Is_Compilation_Unit (Entity (P)) then
1073 Error_Attr ("prefix of % attribute must be library unit", P);
1075 end Check_Library_Unit;
1077 -------------------------------
1078 -- Check_Not_Incomplete_Type --
1079 -------------------------------
1081 procedure Check_Not_Incomplete_Type is
1083 if not Is_Entity_Name (P)
1084 or else not Is_Type (Entity (P))
1085 or else In_Default_Expression
1090 Check_Fully_Declared (P_Type, P);
1092 end Check_Not_Incomplete_Type;
1094 ----------------------------
1095 -- Check_Object_Reference --
1096 ----------------------------
1098 procedure Check_Object_Reference (P : Node_Id) is
1102 -- If we need an object, and we have a prefix that is the name of
1103 -- a function entity, convert it into a function call.
1105 if Is_Entity_Name (P)
1106 and then Ekind (Entity (P)) = E_Function
1108 Rtyp := Etype (Entity (P));
1111 Make_Function_Call (Sloc (P),
1112 Name => Relocate_Node (P)));
1114 Analyze_And_Resolve (P, Rtyp);
1116 -- Otherwise we must have an object reference
1118 elsif not Is_Object_Reference (P) then
1119 Error_Attr ("prefix of % attribute must be object", P);
1121 end Check_Object_Reference;
1123 ------------------------
1124 -- Check_Program_Unit --
1125 ------------------------
1127 procedure Check_Program_Unit is
1129 if Is_Entity_Name (P) then
1131 K : constant Entity_Kind := Ekind (Entity (P));
1132 T : constant Entity_Id := Etype (Entity (P));
1135 if K in Subprogram_Kind
1136 or else K in Task_Kind
1137 or else K in Protected_Kind
1138 or else K = E_Package
1139 or else K in Generic_Unit_Kind
1140 or else (K = E_Variable
1144 Is_Protected_Type (T)))
1151 Error_Attr ("prefix of % attribute must be program unit", P);
1152 end Check_Program_Unit;
1154 ---------------------
1155 -- Check_Real_Type --
1156 ---------------------
1158 procedure Check_Real_Type is
1162 if not Is_Real_Type (P_Type) then
1163 Error_Attr ("prefix of % attribute must be real type", P);
1165 end Check_Real_Type;
1167 -----------------------
1168 -- Check_Scalar_Type --
1169 -----------------------
1171 procedure Check_Scalar_Type is
1175 if not Is_Scalar_Type (P_Type) then
1176 Error_Attr ("prefix of % attribute must be scalar type", P);
1178 end Check_Scalar_Type;
1180 ---------------------------
1181 -- Check_Standard_Prefix --
1182 ---------------------------
1184 procedure Check_Standard_Prefix is
1188 if Nkind (P) /= N_Identifier
1189 or else Chars (P) /= Name_Standard
1191 Error_Attr ("only allowed prefix for % attribute is Standard", P);
1194 end Check_Standard_Prefix;
1196 ----------------------------
1197 -- Check_Stream_Attribute --
1198 ----------------------------
1200 procedure Check_Stream_Attribute (Nam : TSS_Name_Type) is
1205 Validate_Non_Static_Attribute_Function_Call;
1207 -- With the exception of 'Input, Stream attributes are procedures,
1208 -- and can only appear at the position of procedure calls. We check
1209 -- for this here, before they are rewritten, to give a more precise
1212 if Nam = TSS_Stream_Input then
1215 elsif Is_List_Member (N)
1216 and then Nkind (Parent (N)) /= N_Procedure_Call_Statement
1217 and then Nkind (Parent (N)) /= N_Aggregate
1223 ("invalid context for attribute%, which is a procedure", N);
1227 Btyp := Implementation_Base_Type (P_Type);
1229 -- Stream attributes not allowed on limited types unless the
1230 -- special OK_For_Stream flag is set.
1232 if Is_Limited_Type (P_Type)
1233 and then Comes_From_Source (N)
1234 and then not Present (TSS (Btyp, Nam))
1235 and then No (Get_Rep_Pragma (Btyp, Name_Stream_Convert))
1237 Error_Msg_Name_1 := Aname;
1239 ("limited type& has no% attribute", P, Btyp);
1240 Explain_Limited_Type (P_Type, P);
1243 -- Check for violation of restriction No_Stream_Attributes
1245 if Is_RTE (P_Type, RE_Exception_Id)
1247 Is_RTE (P_Type, RE_Exception_Occurrence)
1249 Check_Restriction (No_Exception_Registration, P);
1252 -- Here we must check that the first argument is an access type
1253 -- that is compatible with Ada.Streams.Root_Stream_Type'Class.
1255 Analyze_And_Resolve (E1);
1258 -- Note: the double call to Root_Type here is needed because the
1259 -- root type of a class-wide type is the corresponding type (e.g.
1260 -- X for X'Class, and we really want to go to the root.
1262 if not Is_Access_Type (Etyp)
1263 or else Root_Type (Root_Type (Designated_Type (Etyp))) /=
1264 RTE (RE_Root_Stream_Type)
1267 ("expected access to Ada.Streams.Root_Stream_Type''Class", E1);
1270 -- Check that the second argument is of the right type if there is
1271 -- one (the Input attribute has only one argument so this is skipped)
1273 if Present (E2) then
1276 if Nam = TSS_Stream_Read
1277 and then not Is_OK_Variable_For_Out_Formal (E2)
1280 ("second argument of % attribute must be a variable", E2);
1283 Resolve (E2, P_Type);
1285 end Check_Stream_Attribute;
1287 -----------------------
1288 -- Check_Task_Prefix --
1289 -----------------------
1291 procedure Check_Task_Prefix is
1295 if Is_Task_Type (Etype (P))
1296 or else (Is_Access_Type (Etype (P))
1297 and then Is_Task_Type (Designated_Type (Etype (P))))
1301 Error_Attr ("prefix of % attribute must be a task", P);
1303 end Check_Task_Prefix;
1309 -- The possibilities are an entity name denoting a type, or an
1310 -- attribute reference that denotes a type (Base or Class). If
1311 -- the type is incomplete, replace it with its full view.
1313 procedure Check_Type is
1315 if not Is_Entity_Name (P)
1316 or else not Is_Type (Entity (P))
1318 Error_Attr ("prefix of % attribute must be a type", P);
1320 elsif Ekind (Entity (P)) = E_Incomplete_Type
1321 and then Present (Full_View (Entity (P)))
1323 P_Type := Full_View (Entity (P));
1324 Set_Entity (P, P_Type);
1328 ---------------------
1329 -- Check_Unit_Name --
1330 ---------------------
1332 procedure Check_Unit_Name (Nod : Node_Id) is
1334 if Nkind (Nod) = N_Identifier then
1337 elsif Nkind (Nod) = N_Selected_Component then
1338 Check_Unit_Name (Prefix (Nod));
1340 if Nkind (Selector_Name (Nod)) = N_Identifier then
1345 Error_Attr ("argument for % attribute must be unit name", P);
1346 end Check_Unit_Name;
1352 procedure Error_Attr is
1354 Set_Etype (N, Any_Type);
1355 Set_Entity (N, Any_Type);
1356 raise Bad_Attribute;
1359 procedure Error_Attr (Msg : String; Error_Node : Node_Id) is
1361 Error_Msg_Name_1 := Aname;
1362 Error_Msg_N (Msg, Error_Node);
1366 ----------------------------
1367 -- Legal_Formal_Attribute --
1368 ----------------------------
1370 procedure Legal_Formal_Attribute is
1374 if not Is_Entity_Name (P)
1375 or else not Is_Type (Entity (P))
1377 Error_Attr ("prefix of % attribute must be generic type", N);
1379 elsif Is_Generic_Actual_Type (Entity (P))
1381 or else In_Inlined_Body
1385 elsif Is_Generic_Type (Entity (P)) then
1386 if not Is_Indefinite_Subtype (Entity (P)) then
1388 ("prefix of % attribute must be indefinite generic type", N);
1393 ("prefix of % attribute must be indefinite generic type", N);
1396 Set_Etype (N, Standard_Boolean);
1397 end Legal_Formal_Attribute;
1399 ------------------------
1400 -- Standard_Attribute --
1401 ------------------------
1403 procedure Standard_Attribute (Val : Int) is
1405 Check_Standard_Prefix;
1407 -- First a special check (more like a kludge really). For GNAT5
1408 -- on Windows, the alignments in GCC are severely mixed up. In
1409 -- particular, we have a situation where the maximum alignment
1410 -- that GCC thinks is possible is greater than the guaranteed
1411 -- alignment at run-time. That causes many problems. As a partial
1412 -- cure for this situation, we force a value of 4 for the maximum
1413 -- alignment attribute on this target. This still does not solve
1414 -- all problems, but it helps.
1416 -- A further (even more horrible) dimension to this kludge is now
1417 -- installed. There are two uses for Maximum_Alignment, one is to
1418 -- determine the maximum guaranteed alignment, that's the one we
1419 -- want the kludge to yield as 4. The other use is to maximally
1420 -- align objects, we can't use 4 here, since for example, long
1421 -- long integer has an alignment of 8, so we will get errors.
1423 -- It is of course impossible to determine which use the programmer
1424 -- has in mind, but an approximation for now is to disconnect the
1425 -- kludge if the attribute appears in an alignment clause.
1427 -- To be removed if GCC ever gets its act together here ???
1429 Alignment_Kludge : declare
1432 function On_X86 return Boolean;
1433 -- Determine if target is x86 (ia32), return True if so
1439 function On_X86 return Boolean is
1440 T : constant String := Sdefault.Target_Name.all;
1443 -- There is no clean way to check this. That's not surprising,
1444 -- the front end should not be doing this kind of test ???. The
1445 -- way we do it is test for either "86" or "pentium" being in
1446 -- the string for the target name.
1448 for J in T'First .. T'Last - 1 loop
1449 if T (J .. J + 1) = "86"
1450 or else (J <= T'Last - 6
1451 and then T (J .. J + 6) = "pentium")
1461 if Aname = Name_Maximum_Alignment and then On_X86 then
1464 while Nkind (P) in N_Subexpr loop
1468 if Nkind (P) /= N_Attribute_Definition_Clause
1469 or else Chars (P) /= Name_Alignment
1471 Rewrite (N, Make_Integer_Literal (Loc, 4));
1476 end Alignment_Kludge;
1478 -- Normally we get the value from gcc ???
1480 Rewrite (N, Make_Integer_Literal (Loc, Val));
1482 end Standard_Attribute;
1484 -------------------------
1485 -- Unexpected Argument --
1486 -------------------------
1488 procedure Unexpected_Argument (En : Node_Id) is
1490 Error_Attr ("unexpected argument for % attribute", En);
1491 end Unexpected_Argument;
1493 -------------------------------------------------
1494 -- Validate_Non_Static_Attribute_Function_Call --
1495 -------------------------------------------------
1497 -- This function should be moved to Sem_Dist ???
1499 procedure Validate_Non_Static_Attribute_Function_Call is
1501 if In_Preelaborated_Unit
1502 and then not In_Subprogram_Or_Concurrent_Unit
1504 Flag_Non_Static_Expr
1505 ("non-static function call in preelaborated unit!", N);
1507 end Validate_Non_Static_Attribute_Function_Call;
1509 -----------------------------------------------
1510 -- Start of Processing for Analyze_Attribute --
1511 -----------------------------------------------
1514 -- Immediate return if unrecognized attribute (already diagnosed
1515 -- by parser, so there is nothing more that we need to do)
1517 if not Is_Attribute_Name (Aname) then
1518 raise Bad_Attribute;
1521 -- Deal with Ada 83 and Features issues
1523 if Comes_From_Source (N) then
1524 if not Attribute_83 (Attr_Id) then
1525 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
1526 Error_Msg_Name_1 := Aname;
1527 Error_Msg_N ("(Ada 83) attribute% is not standard?", N);
1530 if Attribute_Impl_Def (Attr_Id) then
1531 Check_Restriction (No_Implementation_Attributes, N);
1536 -- Remote access to subprogram type access attribute reference needs
1537 -- unanalyzed copy for tree transformation. The analyzed copy is used
1538 -- for its semantic information (whether prefix is a remote subprogram
1539 -- name), the unanalyzed copy is used to construct new subtree rooted
1540 -- with N_aggregate which represents a fat pointer aggregate.
1542 if Aname = Name_Access then
1543 Discard_Node (Copy_Separate_Tree (N));
1546 -- Analyze prefix and exit if error in analysis. If the prefix is an
1547 -- incomplete type, use full view if available. A special case is
1548 -- that we never analyze the prefix of an Elab_Body or Elab_Spec
1549 -- or UET_Address attribute.
1551 if Aname /= Name_Elab_Body
1553 Aname /= Name_Elab_Spec
1555 Aname /= Name_UET_Address
1558 P_Type := Etype (P);
1560 if Is_Entity_Name (P)
1561 and then Present (Entity (P))
1562 and then Is_Type (Entity (P))
1563 and then Ekind (Entity (P)) = E_Incomplete_Type
1565 P_Type := Get_Full_View (P_Type);
1566 Set_Entity (P, P_Type);
1567 Set_Etype (P, P_Type);
1570 if P_Type = Any_Type then
1571 raise Bad_Attribute;
1574 P_Base_Type := Base_Type (P_Type);
1577 -- Analyze expressions that may be present, exiting if an error occurs
1584 E1 := First (Exprs);
1587 -- Check for missing or bad expression (result of previous error)
1589 if No (E1) or else Etype (E1) = Any_Type then
1590 raise Bad_Attribute;
1595 if Present (E2) then
1598 if Etype (E2) = Any_Type then
1599 raise Bad_Attribute;
1602 if Present (Next (E2)) then
1603 Unexpected_Argument (Next (E2));
1608 if Is_Overloaded (P)
1609 and then Aname /= Name_Access
1610 and then Aname /= Name_Address
1611 and then Aname /= Name_Code_Address
1612 and then Aname /= Name_Count
1613 and then Aname /= Name_Unchecked_Access
1615 Error_Attr ("ambiguous prefix for % attribute", P);
1618 -- Remaining processing depends on attribute
1626 when Attribute_Abort_Signal =>
1627 Check_Standard_Prefix;
1629 New_Reference_To (Stand.Abort_Signal, Loc));
1636 when Attribute_Access =>
1637 Analyze_Access_Attribute;
1643 when Attribute_Address =>
1646 -- Check for some junk cases, where we have to allow the address
1647 -- attribute but it does not make much sense, so at least for now
1648 -- just replace with Null_Address.
1650 -- We also do this if the prefix is a reference to the AST_Entry
1651 -- attribute. If expansion is active, the attribute will be
1652 -- replaced by a function call, and address will work fine and
1653 -- get the proper value, but if expansion is not active, then
1654 -- the check here allows proper semantic analysis of the reference.
1656 -- An Address attribute created by expansion is legal even when it
1657 -- applies to other entity-denoting expressions.
1659 if Is_Entity_Name (P) then
1661 Ent : constant Entity_Id := Entity (P);
1664 if Is_Subprogram (Ent) then
1665 if not Is_Library_Level_Entity (Ent) then
1666 Check_Restriction (No_Implicit_Dynamic_Code, P);
1669 Set_Address_Taken (Ent);
1671 elsif Is_Object (Ent)
1672 or else Ekind (Ent) = E_Label
1674 Set_Address_Taken (Ent);
1676 -- If we have an address of an object, and the attribute
1677 -- comes from source, then set the object as potentially
1678 -- source modified. We do this because the resulting address
1679 -- can potentially be used to modify the variable and we
1680 -- might not detect this, leading to some junk warnings.
1682 Set_Never_Set_In_Source (Ent, False);
1684 elsif (Is_Concurrent_Type (Etype (Ent))
1685 and then Etype (Ent) = Base_Type (Ent))
1686 or else Ekind (Ent) = E_Package
1687 or else Is_Generic_Unit (Ent)
1690 New_Occurrence_Of (RTE (RE_Null_Address), Sloc (N)));
1693 Error_Attr ("invalid prefix for % attribute", P);
1697 elsif Nkind (P) = N_Attribute_Reference
1698 and then Attribute_Name (P) = Name_AST_Entry
1701 New_Occurrence_Of (RTE (RE_Null_Address), Sloc (N)));
1703 elsif Is_Object_Reference (P) then
1706 elsif Nkind (P) = N_Selected_Component
1707 and then Is_Subprogram (Entity (Selector_Name (P)))
1711 -- What exactly are we allowing here ??? and is this properly
1712 -- documented in the sinfo documentation for this node ???
1714 elsif not Comes_From_Source (N) then
1718 Error_Attr ("invalid prefix for % attribute", P);
1721 Set_Etype (N, RTE (RE_Address));
1727 when Attribute_Address_Size =>
1728 Standard_Attribute (System_Address_Size);
1734 when Attribute_Adjacent =>
1735 Check_Floating_Point_Type_2;
1736 Set_Etype (N, P_Base_Type);
1737 Resolve (E1, P_Base_Type);
1738 Resolve (E2, P_Base_Type);
1744 when Attribute_Aft =>
1745 Check_Fixed_Point_Type_0;
1746 Set_Etype (N, Universal_Integer);
1752 when Attribute_Alignment =>
1754 -- Don't we need more checking here, cf Size ???
1757 Check_Not_Incomplete_Type;
1758 Set_Etype (N, Universal_Integer);
1764 when Attribute_Asm_Input =>
1765 Check_Asm_Attribute;
1766 Set_Etype (N, RTE (RE_Asm_Input_Operand));
1772 when Attribute_Asm_Output =>
1773 Check_Asm_Attribute;
1775 if Etype (E2) = Any_Type then
1778 elsif Aname = Name_Asm_Output then
1779 if not Is_Variable (E2) then
1781 ("second argument for Asm_Output is not variable", E2);
1785 Note_Possible_Modification (E2);
1786 Set_Etype (N, RTE (RE_Asm_Output_Operand));
1792 when Attribute_AST_Entry => AST_Entry : declare
1798 -- Indicates if entry family index is present. Note the coding
1799 -- here handles the entry family case, but in fact it cannot be
1800 -- executed currently, because pragma AST_Entry does not permit
1801 -- the specification of an entry family.
1803 procedure Bad_AST_Entry;
1804 -- Signal a bad AST_Entry pragma
1806 function OK_Entry (E : Entity_Id) return Boolean;
1807 -- Checks that E is of an appropriate entity kind for an entry
1808 -- (i.e. E_Entry if Index is False, or E_Entry_Family if Index
1809 -- is set True for the entry family case). In the True case,
1810 -- makes sure that Is_AST_Entry is set on the entry.
1812 procedure Bad_AST_Entry is
1814 Error_Attr ("prefix for % attribute must be task entry", P);
1817 function OK_Entry (E : Entity_Id) return Boolean is
1822 Result := (Ekind (E) = E_Entry_Family);
1824 Result := (Ekind (E) = E_Entry);
1828 if not Is_AST_Entry (E) then
1829 Error_Msg_Name_2 := Aname;
1831 ("% attribute requires previous % pragma", P);
1838 -- Start of processing for AST_Entry
1844 -- Deal with entry family case
1846 if Nkind (P) = N_Indexed_Component then
1854 Ptyp := Etype (Pref);
1856 if Ptyp = Any_Type or else Error_Posted (Pref) then
1860 -- If the prefix is a selected component whose prefix is of an
1861 -- access type, then introduce an explicit dereference.
1862 -- ??? Could we reuse Check_Dereference here?
1864 if Nkind (Pref) = N_Selected_Component
1865 and then Is_Access_Type (Ptyp)
1868 Make_Explicit_Dereference (Sloc (Pref),
1869 Relocate_Node (Pref)));
1870 Analyze_And_Resolve (Pref, Designated_Type (Ptyp));
1873 -- Prefix can be of the form a.b, where a is a task object
1874 -- and b is one of the entries of the corresponding task type.
1876 if Nkind (Pref) = N_Selected_Component
1877 and then OK_Entry (Entity (Selector_Name (Pref)))
1878 and then Is_Object_Reference (Prefix (Pref))
1879 and then Is_Task_Type (Etype (Prefix (Pref)))
1883 -- Otherwise the prefix must be an entry of a containing task,
1884 -- or of a variable of the enclosing task type.
1887 if Nkind (Pref) = N_Identifier
1888 or else Nkind (Pref) = N_Expanded_Name
1890 Ent := Entity (Pref);
1892 if not OK_Entry (Ent)
1893 or else not In_Open_Scopes (Scope (Ent))
1903 Set_Etype (N, RTE (RE_AST_Handler));
1910 -- Note: when the base attribute appears in the context of a subtype
1911 -- mark, the analysis is done by Sem_Ch8.Find_Type, rather than by
1912 -- the following circuit.
1914 when Attribute_Base => Base : declare
1918 Check_Either_E0_Or_E1;
1922 if Ada_Version >= Ada_95
1923 and then not Is_Scalar_Type (Typ)
1924 and then not Is_Generic_Type (Typ)
1926 Error_Msg_N ("prefix of Base attribute must be scalar type", N);
1928 elsif Sloc (Typ) = Standard_Location
1929 and then Base_Type (Typ) = Typ
1930 and then Warn_On_Redundant_Constructs
1933 ("?redudant attribute, & is its own base type", N, Typ);
1936 Set_Etype (N, Base_Type (Entity (P)));
1938 -- If we have an expression present, then really this is a conversion
1939 -- and the tree must be reformed. Note that this is one of the cases
1940 -- in which we do a replace rather than a rewrite, because the
1941 -- original tree is junk.
1943 if Present (E1) then
1945 Make_Type_Conversion (Loc,
1947 Make_Attribute_Reference (Loc,
1948 Prefix => Prefix (N),
1949 Attribute_Name => Name_Base),
1950 Expression => Relocate_Node (E1)));
1952 -- E1 may be overloaded, and its interpretations preserved.
1954 Save_Interps (E1, Expression (N));
1957 -- For other cases, set the proper type as the entity of the
1958 -- attribute reference, and then rewrite the node to be an
1959 -- occurrence of the referenced base type. This way, no one
1960 -- else in the compiler has to worry about the base attribute.
1963 Set_Entity (N, Base_Type (Entity (P)));
1965 New_Reference_To (Entity (N), Loc));
1974 when Attribute_Bit => Bit :
1978 if not Is_Object_Reference (P) then
1979 Error_Attr ("prefix for % attribute must be object", P);
1981 -- What about the access object cases ???
1987 Set_Etype (N, Universal_Integer);
1994 when Attribute_Bit_Order => Bit_Order :
1999 if not Is_Record_Type (P_Type) then
2000 Error_Attr ("prefix of % attribute must be record type", P);
2003 if Bytes_Big_Endian xor Reverse_Bit_Order (P_Type) then
2005 New_Occurrence_Of (RTE (RE_High_Order_First), Loc));
2008 New_Occurrence_Of (RTE (RE_Low_Order_First), Loc));
2011 Set_Etype (N, RTE (RE_Bit_Order));
2014 -- Reset incorrect indication of staticness
2016 Set_Is_Static_Expression (N, False);
2023 -- Note: in generated code, we can have a Bit_Position attribute
2024 -- applied to a (naked) record component (i.e. the prefix is an
2025 -- identifier that references an E_Component or E_Discriminant
2026 -- entity directly, and this is interpreted as expected by Gigi.
2027 -- The following code will not tolerate such usage, but when the
2028 -- expander creates this special case, it marks it as analyzed
2029 -- immediately and sets an appropriate type.
2031 when Attribute_Bit_Position =>
2033 if Comes_From_Source (N) then
2037 Set_Etype (N, Universal_Integer);
2043 when Attribute_Body_Version =>
2046 Set_Etype (N, RTE (RE_Version_String));
2052 when Attribute_Callable =>
2054 Set_Etype (N, Standard_Boolean);
2061 when Attribute_Caller => Caller : declare
2068 if Nkind (P) = N_Identifier
2069 or else Nkind (P) = N_Expanded_Name
2073 if not Is_Entry (Ent) then
2074 Error_Attr ("invalid entry name", N);
2078 Error_Attr ("invalid entry name", N);
2082 for J in reverse 0 .. Scope_Stack.Last loop
2083 S := Scope_Stack.Table (J).Entity;
2085 if S = Scope (Ent) then
2086 Error_Attr ("Caller must appear in matching accept or body", N);
2092 Set_Etype (N, RTE (RO_AT_Task_Id));
2099 when Attribute_Ceiling =>
2100 Check_Floating_Point_Type_1;
2101 Set_Etype (N, P_Base_Type);
2102 Resolve (E1, P_Base_Type);
2108 when Attribute_Class => Class : declare
2110 Check_Restriction (No_Dispatch, N);
2111 Check_Either_E0_Or_E1;
2113 -- If we have an expression present, then really this is a conversion
2114 -- and the tree must be reformed into a proper conversion. This is a
2115 -- Replace rather than a Rewrite, because the original tree is junk.
2116 -- If expression is overloaded, propagate interpretations to new one.
2118 if Present (E1) then
2120 Make_Type_Conversion (Loc,
2122 Make_Attribute_Reference (Loc,
2123 Prefix => Prefix (N),
2124 Attribute_Name => Name_Class),
2125 Expression => Relocate_Node (E1)));
2127 Save_Interps (E1, Expression (N));
2130 -- Otherwise we just need to find the proper type
2142 when Attribute_Code_Address =>
2145 if Nkind (P) = N_Attribute_Reference
2146 and then (Attribute_Name (P) = Name_Elab_Body
2148 Attribute_Name (P) = Name_Elab_Spec)
2152 elsif not Is_Entity_Name (P)
2153 or else (Ekind (Entity (P)) /= E_Function
2155 Ekind (Entity (P)) /= E_Procedure)
2157 Error_Attr ("invalid prefix for % attribute", P);
2158 Set_Address_Taken (Entity (P));
2161 Set_Etype (N, RTE (RE_Address));
2163 --------------------
2164 -- Component_Size --
2165 --------------------
2167 when Attribute_Component_Size =>
2169 Set_Etype (N, Universal_Integer);
2171 -- Note: unlike other array attributes, unconstrained arrays are OK
2173 if Is_Array_Type (P_Type) and then not Is_Constrained (P_Type) then
2183 when Attribute_Compose =>
2184 Check_Floating_Point_Type_2;
2185 Set_Etype (N, P_Base_Type);
2186 Resolve (E1, P_Base_Type);
2187 Resolve (E2, Any_Integer);
2193 when Attribute_Constrained =>
2195 Set_Etype (N, Standard_Boolean);
2197 -- Case from RM J.4(2) of constrained applied to private type
2199 if Is_Entity_Name (P) and then Is_Type (Entity (P)) then
2201 -- If we are within an instance, the attribute must be legal
2202 -- because it was valid in the generic unit. Ditto if this is
2203 -- an inlining of a function declared in an instance.
2206 or else In_Inlined_Body
2210 -- For sure OK if we have a real private type itself, but must
2211 -- be completed, cannot apply Constrained to incomplete type.
2213 elsif Is_Private_Type (Entity (P)) then
2215 -- Note: this is one of the Annex J features that does not
2216 -- generate a warning from -gnatwj, since in fact it seems
2217 -- very useful, and is used in the GNAT runtime.
2219 Check_Not_Incomplete_Type;
2223 -- Normal (non-obsolescent case) of application to object of
2224 -- a discriminated type.
2227 Check_Object_Reference (P);
2229 -- If N does not come from source, then we allow the
2230 -- the attribute prefix to be of a private type whose
2231 -- full type has discriminants. This occurs in cases
2232 -- involving expanded calls to stream attributes.
2234 if not Comes_From_Source (N) then
2235 P_Type := Underlying_Type (P_Type);
2238 -- Must have discriminants or be an access type designating
2239 -- a type with discriminants. If it is a classwide type is
2240 -- has unknown discriminants.
2242 if Has_Discriminants (P_Type)
2243 or else Has_Unknown_Discriminants (P_Type)
2245 (Is_Access_Type (P_Type)
2246 and then Has_Discriminants (Designated_Type (P_Type)))
2250 -- Also allow an object of a generic type if extensions allowed
2251 -- and allow this for any type at all.
2253 elsif (Is_Generic_Type (P_Type)
2254 or else Is_Generic_Actual_Type (P_Type))
2255 and then Extensions_Allowed
2261 -- Fall through if bad prefix
2264 ("prefix of % attribute must be object of discriminated type", P);
2270 when Attribute_Copy_Sign =>
2271 Check_Floating_Point_Type_2;
2272 Set_Etype (N, P_Base_Type);
2273 Resolve (E1, P_Base_Type);
2274 Resolve (E2, P_Base_Type);
2280 when Attribute_Count => Count :
2289 if Nkind (P) = N_Identifier
2290 or else Nkind (P) = N_Expanded_Name
2294 if Ekind (Ent) /= E_Entry then
2295 Error_Attr ("invalid entry name", N);
2298 elsif Nkind (P) = N_Indexed_Component then
2299 if not Is_Entity_Name (Prefix (P))
2300 or else No (Entity (Prefix (P)))
2301 or else Ekind (Entity (Prefix (P))) /= E_Entry_Family
2303 if Nkind (Prefix (P)) = N_Selected_Component
2304 and then Present (Entity (Selector_Name (Prefix (P))))
2305 and then Ekind (Entity (Selector_Name (Prefix (P)))) =
2309 ("attribute % must apply to entry of current task", P);
2312 Error_Attr ("invalid entry family name", P);
2317 Ent := Entity (Prefix (P));
2320 elsif Nkind (P) = N_Selected_Component
2321 and then Present (Entity (Selector_Name (P)))
2322 and then Ekind (Entity (Selector_Name (P))) = E_Entry
2325 ("attribute % must apply to entry of current task", P);
2328 Error_Attr ("invalid entry name", N);
2332 for J in reverse 0 .. Scope_Stack.Last loop
2333 S := Scope_Stack.Table (J).Entity;
2335 if S = Scope (Ent) then
2336 if Nkind (P) = N_Expanded_Name then
2337 Tsk := Entity (Prefix (P));
2339 -- The prefix denotes either the task type, or else a
2340 -- single task whose task type is being analyzed.
2345 or else (not Is_Type (Tsk)
2346 and then Etype (Tsk) = S
2347 and then not (Comes_From_Source (S)))
2352 ("Attribute % must apply to entry of current task", N);
2358 elsif Ekind (Scope (Ent)) in Task_Kind
2359 and then Ekind (S) /= E_Loop
2360 and then Ekind (S) /= E_Block
2361 and then Ekind (S) /= E_Entry
2362 and then Ekind (S) /= E_Entry_Family
2364 Error_Attr ("Attribute % cannot appear in inner unit", N);
2366 elsif Ekind (Scope (Ent)) = E_Protected_Type
2367 and then not Has_Completion (Scope (Ent))
2369 Error_Attr ("attribute % can only be used inside body", N);
2373 if Is_Overloaded (P) then
2375 Index : Interp_Index;
2379 Get_First_Interp (P, Index, It);
2381 while Present (It.Nam) loop
2382 if It.Nam = Ent then
2386 Error_Attr ("ambiguous entry name", N);
2389 Get_Next_Interp (Index, It);
2394 Set_Etype (N, Universal_Integer);
2397 -----------------------
2398 -- Default_Bit_Order --
2399 -----------------------
2401 when Attribute_Default_Bit_Order => Default_Bit_Order :
2403 Check_Standard_Prefix;
2406 if Bytes_Big_Endian then
2408 Make_Integer_Literal (Loc, False_Value));
2411 Make_Integer_Literal (Loc, True_Value));
2414 Set_Etype (N, Universal_Integer);
2415 Set_Is_Static_Expression (N);
2416 end Default_Bit_Order;
2422 when Attribute_Definite =>
2423 Legal_Formal_Attribute;
2429 when Attribute_Delta =>
2430 Check_Fixed_Point_Type_0;
2431 Set_Etype (N, Universal_Real);
2437 when Attribute_Denorm =>
2438 Check_Floating_Point_Type_0;
2439 Set_Etype (N, Standard_Boolean);
2445 when Attribute_Digits =>
2449 if not Is_Floating_Point_Type (P_Type)
2450 and then not Is_Decimal_Fixed_Point_Type (P_Type)
2453 ("prefix of % attribute must be float or decimal type", P);
2456 Set_Etype (N, Universal_Integer);
2462 -- Also handles processing for Elab_Spec
2464 when Attribute_Elab_Body | Attribute_Elab_Spec =>
2466 Check_Unit_Name (P);
2467 Set_Etype (N, Standard_Void_Type);
2469 -- We have to manually call the expander in this case to get
2470 -- the necessary expansion (normally attributes that return
2471 -- entities are not expanded).
2479 -- Shares processing with Elab_Body
2485 when Attribute_Elaborated =>
2488 Set_Etype (N, Standard_Boolean);
2494 when Attribute_Emax =>
2495 Check_Floating_Point_Type_0;
2496 Set_Etype (N, Universal_Integer);
2502 when Attribute_Enum_Rep => Enum_Rep : declare
2504 if Present (E1) then
2506 Check_Discrete_Type;
2507 Resolve (E1, P_Base_Type);
2510 if not Is_Entity_Name (P)
2511 or else (not Is_Object (Entity (P))
2513 Ekind (Entity (P)) /= E_Enumeration_Literal)
2516 ("prefix of %attribute must be " &
2517 "discrete type/object or enum literal", P);
2521 Set_Etype (N, Universal_Integer);
2528 when Attribute_Epsilon =>
2529 Check_Floating_Point_Type_0;
2530 Set_Etype (N, Universal_Real);
2536 when Attribute_Exponent =>
2537 Check_Floating_Point_Type_1;
2538 Set_Etype (N, Universal_Integer);
2539 Resolve (E1, P_Base_Type);
2545 when Attribute_External_Tag =>
2549 Set_Etype (N, Standard_String);
2551 if not Is_Tagged_Type (P_Type) then
2552 Error_Attr ("prefix of % attribute must be tagged", P);
2559 when Attribute_First =>
2560 Check_Array_Or_Scalar_Type;
2566 when Attribute_First_Bit =>
2568 Set_Etype (N, Universal_Integer);
2574 when Attribute_Fixed_Value =>
2576 Check_Fixed_Point_Type;
2577 Resolve (E1, Any_Integer);
2578 Set_Etype (N, P_Base_Type);
2584 when Attribute_Floor =>
2585 Check_Floating_Point_Type_1;
2586 Set_Etype (N, P_Base_Type);
2587 Resolve (E1, P_Base_Type);
2593 when Attribute_Fore =>
2594 Check_Fixed_Point_Type_0;
2595 Set_Etype (N, Universal_Integer);
2601 when Attribute_Fraction =>
2602 Check_Floating_Point_Type_1;
2603 Set_Etype (N, P_Base_Type);
2604 Resolve (E1, P_Base_Type);
2606 -----------------------
2607 -- Has_Access_Values --
2608 -----------------------
2610 when Attribute_Has_Access_Values =>
2613 Set_Etype (N, Standard_Boolean);
2615 -----------------------
2616 -- Has_Discriminants --
2617 -----------------------
2619 when Attribute_Has_Discriminants =>
2620 Legal_Formal_Attribute;
2626 when Attribute_Identity =>
2630 if Etype (P) = Standard_Exception_Type then
2631 Set_Etype (N, RTE (RE_Exception_Id));
2633 elsif Is_Task_Type (Etype (P))
2634 or else (Is_Access_Type (Etype (P))
2635 and then Is_Task_Type (Designated_Type (Etype (P))))
2638 Set_Etype (N, RTE (RO_AT_Task_Id));
2641 Error_Attr ("prefix of % attribute must be a task or an "
2649 when Attribute_Image => Image :
2651 Set_Etype (N, Standard_String);
2654 if Is_Real_Type (P_Type) then
2655 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
2656 Error_Msg_Name_1 := Aname;
2658 ("(Ada 83) % attribute not allowed for real types", N);
2662 if Is_Enumeration_Type (P_Type) then
2663 Check_Restriction (No_Enumeration_Maps, N);
2667 Resolve (E1, P_Base_Type);
2669 Validate_Non_Static_Attribute_Function_Call;
2676 when Attribute_Img => Img :
2678 Set_Etype (N, Standard_String);
2680 if not Is_Scalar_Type (P_Type)
2681 or else (Is_Entity_Name (P) and then Is_Type (Entity (P)))
2684 ("prefix of % attribute must be scalar object name", N);
2694 when Attribute_Input =>
2696 Check_Stream_Attribute (TSS_Stream_Input);
2697 Set_Etype (N, P_Base_Type);
2703 when Attribute_Integer_Value =>
2706 Resolve (E1, Any_Fixed);
2707 Set_Etype (N, P_Base_Type);
2713 when Attribute_Large =>
2716 Set_Etype (N, Universal_Real);
2722 when Attribute_Last =>
2723 Check_Array_Or_Scalar_Type;
2729 when Attribute_Last_Bit =>
2731 Set_Etype (N, Universal_Integer);
2737 when Attribute_Leading_Part =>
2738 Check_Floating_Point_Type_2;
2739 Set_Etype (N, P_Base_Type);
2740 Resolve (E1, P_Base_Type);
2741 Resolve (E2, Any_Integer);
2747 when Attribute_Length =>
2749 Set_Etype (N, Universal_Integer);
2755 when Attribute_Machine =>
2756 Check_Floating_Point_Type_1;
2757 Set_Etype (N, P_Base_Type);
2758 Resolve (E1, P_Base_Type);
2764 when Attribute_Machine_Emax =>
2765 Check_Floating_Point_Type_0;
2766 Set_Etype (N, Universal_Integer);
2772 when Attribute_Machine_Emin =>
2773 Check_Floating_Point_Type_0;
2774 Set_Etype (N, Universal_Integer);
2776 ----------------------
2777 -- Machine_Mantissa --
2778 ----------------------
2780 when Attribute_Machine_Mantissa =>
2781 Check_Floating_Point_Type_0;
2782 Set_Etype (N, Universal_Integer);
2784 -----------------------
2785 -- Machine_Overflows --
2786 -----------------------
2788 when Attribute_Machine_Overflows =>
2791 Set_Etype (N, Standard_Boolean);
2797 when Attribute_Machine_Radix =>
2800 Set_Etype (N, Universal_Integer);
2802 --------------------
2803 -- Machine_Rounds --
2804 --------------------
2806 when Attribute_Machine_Rounds =>
2809 Set_Etype (N, Standard_Boolean);
2815 when Attribute_Machine_Size =>
2818 Check_Not_Incomplete_Type;
2819 Set_Etype (N, Universal_Integer);
2825 when Attribute_Mantissa =>
2828 Set_Etype (N, Universal_Integer);
2834 when Attribute_Max =>
2837 Resolve (E1, P_Base_Type);
2838 Resolve (E2, P_Base_Type);
2839 Set_Etype (N, P_Base_Type);
2841 ----------------------------------
2842 -- Max_Size_In_Storage_Elements --
2843 ----------------------------------
2845 when Attribute_Max_Size_In_Storage_Elements =>
2848 Check_Not_Incomplete_Type;
2849 Set_Etype (N, Universal_Integer);
2851 -----------------------
2852 -- Maximum_Alignment --
2853 -----------------------
2855 when Attribute_Maximum_Alignment =>
2856 Standard_Attribute (Ttypes.Maximum_Alignment);
2858 --------------------
2859 -- Mechanism_Code --
2860 --------------------
2862 when Attribute_Mechanism_Code =>
2863 if not Is_Entity_Name (P)
2864 or else not Is_Subprogram (Entity (P))
2866 Error_Attr ("prefix of % attribute must be subprogram", P);
2869 Check_Either_E0_Or_E1;
2871 if Present (E1) then
2872 Resolve (E1, Any_Integer);
2873 Set_Etype (E1, Standard_Integer);
2875 if not Is_Static_Expression (E1) then
2876 Flag_Non_Static_Expr
2877 ("expression for parameter number must be static!", E1);
2880 elsif UI_To_Int (Intval (E1)) > Number_Formals (Entity (P))
2881 or else UI_To_Int (Intval (E1)) < 0
2883 Error_Attr ("invalid parameter number for %attribute", E1);
2887 Set_Etype (N, Universal_Integer);
2893 when Attribute_Min =>
2896 Resolve (E1, P_Base_Type);
2897 Resolve (E2, P_Base_Type);
2898 Set_Etype (N, P_Base_Type);
2904 when Attribute_Model =>
2905 Check_Floating_Point_Type_1;
2906 Set_Etype (N, P_Base_Type);
2907 Resolve (E1, P_Base_Type);
2913 when Attribute_Model_Emin =>
2914 Check_Floating_Point_Type_0;
2915 Set_Etype (N, Universal_Integer);
2921 when Attribute_Model_Epsilon =>
2922 Check_Floating_Point_Type_0;
2923 Set_Etype (N, Universal_Real);
2925 --------------------
2926 -- Model_Mantissa --
2927 --------------------
2929 when Attribute_Model_Mantissa =>
2930 Check_Floating_Point_Type_0;
2931 Set_Etype (N, Universal_Integer);
2937 when Attribute_Model_Small =>
2938 Check_Floating_Point_Type_0;
2939 Set_Etype (N, Universal_Real);
2945 when Attribute_Modulus =>
2949 if not Is_Modular_Integer_Type (P_Type) then
2950 Error_Attr ("prefix of % attribute must be modular type", P);
2953 Set_Etype (N, Universal_Integer);
2955 --------------------
2956 -- Null_Parameter --
2957 --------------------
2959 when Attribute_Null_Parameter => Null_Parameter : declare
2960 Parnt : constant Node_Id := Parent (N);
2961 GParnt : constant Node_Id := Parent (Parnt);
2963 procedure Bad_Null_Parameter (Msg : String);
2964 -- Used if bad Null parameter attribute node is found. Issues
2965 -- given error message, and also sets the type to Any_Type to
2966 -- avoid blowups later on from dealing with a junk node.
2968 procedure Must_Be_Imported (Proc_Ent : Entity_Id);
2969 -- Called to check that Proc_Ent is imported subprogram
2971 ------------------------
2972 -- Bad_Null_Parameter --
2973 ------------------------
2975 procedure Bad_Null_Parameter (Msg : String) is
2977 Error_Msg_N (Msg, N);
2978 Set_Etype (N, Any_Type);
2979 end Bad_Null_Parameter;
2981 ----------------------
2982 -- Must_Be_Imported --
2983 ----------------------
2985 procedure Must_Be_Imported (Proc_Ent : Entity_Id) is
2986 Pent : Entity_Id := Proc_Ent;
2989 while Present (Alias (Pent)) loop
2990 Pent := Alias (Pent);
2993 -- Ignore check if procedure not frozen yet (we will get
2994 -- another chance when the default parameter is reanalyzed)
2996 if not Is_Frozen (Pent) then
2999 elsif not Is_Imported (Pent) then
3001 ("Null_Parameter can only be used with imported subprogram");
3006 end Must_Be_Imported;
3008 -- Start of processing for Null_Parameter
3013 Set_Etype (N, P_Type);
3015 -- Case of attribute used as default expression
3017 if Nkind (Parnt) = N_Parameter_Specification then
3018 Must_Be_Imported (Defining_Entity (GParnt));
3020 -- Case of attribute used as actual for subprogram (positional)
3022 elsif (Nkind (Parnt) = N_Procedure_Call_Statement
3024 Nkind (Parnt) = N_Function_Call)
3025 and then Is_Entity_Name (Name (Parnt))
3027 Must_Be_Imported (Entity (Name (Parnt)));
3029 -- Case of attribute used as actual for subprogram (named)
3031 elsif Nkind (Parnt) = N_Parameter_Association
3032 and then (Nkind (GParnt) = N_Procedure_Call_Statement
3034 Nkind (GParnt) = N_Function_Call)
3035 and then Is_Entity_Name (Name (GParnt))
3037 Must_Be_Imported (Entity (Name (GParnt)));
3039 -- Not an allowed case
3043 ("Null_Parameter must be actual or default parameter");
3052 when Attribute_Object_Size =>
3055 Check_Not_Incomplete_Type;
3056 Set_Etype (N, Universal_Integer);
3062 when Attribute_Output =>
3064 Check_Stream_Attribute (TSS_Stream_Output);
3065 Set_Etype (N, Standard_Void_Type);
3066 Resolve (N, Standard_Void_Type);
3072 when Attribute_Partition_ID =>
3075 if P_Type /= Any_Type then
3076 if not Is_Library_Level_Entity (Entity (P)) then
3078 ("prefix of % attribute must be library-level entity", P);
3080 -- The defining entity of prefix should not be declared inside
3081 -- a Pure unit. RM E.1(8).
3082 -- The Is_Pure flag has been set during declaration.
3084 elsif Is_Entity_Name (P)
3085 and then Is_Pure (Entity (P))
3088 ("prefix of % attribute must not be declared pure", P);
3092 Set_Etype (N, Universal_Integer);
3094 -------------------------
3095 -- Passed_By_Reference --
3096 -------------------------
3098 when Attribute_Passed_By_Reference =>
3101 Set_Etype (N, Standard_Boolean);
3107 when Attribute_Pool_Address =>
3109 Set_Etype (N, RTE (RE_Address));
3115 when Attribute_Pos =>
3116 Check_Discrete_Type;
3118 Resolve (E1, P_Base_Type);
3119 Set_Etype (N, Universal_Integer);
3125 when Attribute_Position =>
3127 Set_Etype (N, Universal_Integer);
3133 when Attribute_Pred =>
3136 Resolve (E1, P_Base_Type);
3137 Set_Etype (N, P_Base_Type);
3139 -- Nothing to do for real type case
3141 if Is_Real_Type (P_Type) then
3144 -- If not modular type, test for overflow check required
3147 if not Is_Modular_Integer_Type (P_Type)
3148 and then not Range_Checks_Suppressed (P_Base_Type)
3150 Enable_Range_Check (E1);
3158 when Attribute_Range =>
3159 Check_Array_Or_Scalar_Type;
3161 if Ada_Version = Ada_83
3162 and then Is_Scalar_Type (P_Type)
3163 and then Comes_From_Source (N)
3166 ("(Ada 83) % attribute not allowed for scalar type", P);
3173 when Attribute_Range_Length =>
3174 Check_Discrete_Type;
3175 Set_Etype (N, Universal_Integer);
3181 when Attribute_Read =>
3183 Check_Stream_Attribute (TSS_Stream_Read);
3184 Set_Etype (N, Standard_Void_Type);
3185 Resolve (N, Standard_Void_Type);
3186 Note_Possible_Modification (E2);
3192 when Attribute_Remainder =>
3193 Check_Floating_Point_Type_2;
3194 Set_Etype (N, P_Base_Type);
3195 Resolve (E1, P_Base_Type);
3196 Resolve (E2, P_Base_Type);
3202 when Attribute_Round =>
3204 Check_Decimal_Fixed_Point_Type;
3205 Set_Etype (N, P_Base_Type);
3207 -- Because the context is universal_real (3.5.10(12)) it is a legal
3208 -- context for a universal fixed expression. This is the only
3209 -- attribute whose functional description involves U_R.
3211 if Etype (E1) = Universal_Fixed then
3213 Conv : constant Node_Id := Make_Type_Conversion (Loc,
3214 Subtype_Mark => New_Occurrence_Of (Universal_Real, Loc),
3215 Expression => Relocate_Node (E1));
3223 Resolve (E1, Any_Real);
3229 when Attribute_Rounding =>
3230 Check_Floating_Point_Type_1;
3231 Set_Etype (N, P_Base_Type);
3232 Resolve (E1, P_Base_Type);
3238 when Attribute_Safe_Emax =>
3239 Check_Floating_Point_Type_0;
3240 Set_Etype (N, Universal_Integer);
3246 when Attribute_Safe_First =>
3247 Check_Floating_Point_Type_0;
3248 Set_Etype (N, Universal_Real);
3254 when Attribute_Safe_Large =>
3257 Set_Etype (N, Universal_Real);
3263 when Attribute_Safe_Last =>
3264 Check_Floating_Point_Type_0;
3265 Set_Etype (N, Universal_Real);
3271 when Attribute_Safe_Small =>
3274 Set_Etype (N, Universal_Real);
3280 when Attribute_Scale =>
3282 Check_Decimal_Fixed_Point_Type;
3283 Set_Etype (N, Universal_Integer);
3289 when Attribute_Scaling =>
3290 Check_Floating_Point_Type_2;
3291 Set_Etype (N, P_Base_Type);
3292 Resolve (E1, P_Base_Type);
3298 when Attribute_Signed_Zeros =>
3299 Check_Floating_Point_Type_0;
3300 Set_Etype (N, Standard_Boolean);
3306 when Attribute_Size | Attribute_VADS_Size =>
3309 -- If prefix is parameterless function call, rewrite and resolve
3312 if Is_Entity_Name (P)
3313 and then Ekind (Entity (P)) = E_Function
3317 -- Similar processing for a protected function call
3319 elsif Nkind (P) = N_Selected_Component
3320 and then Ekind (Entity (Selector_Name (P))) = E_Function
3325 if Is_Object_Reference (P) then
3326 Check_Object_Reference (P);
3328 elsif Is_Entity_Name (P)
3329 and then Is_Type (Entity (P))
3333 elsif Nkind (P) = N_Type_Conversion
3334 and then not Comes_From_Source (P)
3339 Error_Attr ("invalid prefix for % attribute", P);
3342 Check_Not_Incomplete_Type;
3343 Set_Etype (N, Universal_Integer);
3349 when Attribute_Small =>
3352 Set_Etype (N, Universal_Real);
3358 when Attribute_Storage_Pool =>
3359 if Is_Access_Type (P_Type) then
3362 -- Set appropriate entity
3364 if Present (Associated_Storage_Pool (Root_Type (P_Type))) then
3365 Set_Entity (N, Associated_Storage_Pool (Root_Type (P_Type)));
3367 Set_Entity (N, RTE (RE_Global_Pool_Object));
3370 Set_Etype (N, Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
3372 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
3373 -- Storage_Pool since this attribute is not defined for such
3374 -- types (RM E.2.3(22)).
3376 Validate_Remote_Access_To_Class_Wide_Type (N);
3379 Error_Attr ("prefix of % attribute must be access type", P);
3386 when Attribute_Storage_Size =>
3388 if Is_Task_Type (P_Type) then
3390 Set_Etype (N, Universal_Integer);
3392 elsif Is_Access_Type (P_Type) then
3393 if Is_Entity_Name (P)
3394 and then Is_Type (Entity (P))
3398 Set_Etype (N, Universal_Integer);
3400 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
3401 -- Storage_Size since this attribute is not defined for
3402 -- such types (RM E.2.3(22)).
3404 Validate_Remote_Access_To_Class_Wide_Type (N);
3406 -- The prefix is allowed to be an implicit dereference
3407 -- of an access value designating a task.
3412 Set_Etype (N, Universal_Integer);
3417 ("prefix of % attribute must be access or task type", P);
3424 when Attribute_Storage_Unit =>
3425 Standard_Attribute (Ttypes.System_Storage_Unit);
3431 when Attribute_Succ =>
3434 Resolve (E1, P_Base_Type);
3435 Set_Etype (N, P_Base_Type);
3437 -- Nothing to do for real type case
3439 if Is_Real_Type (P_Type) then
3442 -- If not modular type, test for overflow check required.
3445 if not Is_Modular_Integer_Type (P_Type)
3446 and then not Range_Checks_Suppressed (P_Base_Type)
3448 Enable_Range_Check (E1);
3456 when Attribute_Tag =>
3460 if not Is_Tagged_Type (P_Type) then
3461 Error_Attr ("prefix of % attribute must be tagged", P);
3463 -- Next test does not apply to generated code
3464 -- why not, and what does the illegal reference mean???
3466 elsif Is_Object_Reference (P)
3467 and then not Is_Class_Wide_Type (P_Type)
3468 and then Comes_From_Source (N)
3471 ("% attribute can only be applied to objects of class-wide type",
3475 Set_Etype (N, RTE (RE_Tag));
3481 when Attribute_Target_Name => Target_Name : declare
3482 TN : constant String := Sdefault.Target_Name.all;
3483 TL : Integer := TN'Last;
3486 Check_Standard_Prefix;
3490 if TN (TL) = '/' or else TN (TL) = '\' then
3494 Store_String_Chars (TN (TN'First .. TL));
3497 Make_String_Literal (Loc,
3498 Strval => End_String));
3499 Analyze_And_Resolve (N, Standard_String);
3506 when Attribute_Terminated =>
3508 Set_Etype (N, Standard_Boolean);
3515 when Attribute_To_Address =>
3519 if Nkind (P) /= N_Identifier
3520 or else Chars (P) /= Name_System
3522 Error_Attr ("prefix of %attribute must be System", P);
3525 Generate_Reference (RTE (RE_Address), P);
3526 Analyze_And_Resolve (E1, Any_Integer);
3527 Set_Etype (N, RTE (RE_Address));
3533 when Attribute_Truncation =>
3534 Check_Floating_Point_Type_1;
3535 Resolve (E1, P_Base_Type);
3536 Set_Etype (N, P_Base_Type);
3542 when Attribute_Type_Class =>
3545 Check_Not_Incomplete_Type;
3546 Set_Etype (N, RTE (RE_Type_Class));
3552 when Attribute_UET_Address =>
3554 Check_Unit_Name (P);
3555 Set_Etype (N, RTE (RE_Address));
3557 -----------------------
3558 -- Unbiased_Rounding --
3559 -----------------------
3561 when Attribute_Unbiased_Rounding =>
3562 Check_Floating_Point_Type_1;
3563 Set_Etype (N, P_Base_Type);
3564 Resolve (E1, P_Base_Type);
3566 ----------------------
3567 -- Unchecked_Access --
3568 ----------------------
3570 when Attribute_Unchecked_Access =>
3571 if Comes_From_Source (N) then
3572 Check_Restriction (No_Unchecked_Access, N);
3575 Analyze_Access_Attribute;
3577 -------------------------
3578 -- Unconstrained_Array --
3579 -------------------------
3581 when Attribute_Unconstrained_Array =>
3584 Check_Not_Incomplete_Type;
3585 Set_Etype (N, Standard_Boolean);
3587 ------------------------------
3588 -- Universal_Literal_String --
3589 ------------------------------
3591 -- This is a GNAT specific attribute whose prefix must be a named
3592 -- number where the expression is either a single numeric literal,
3593 -- or a numeric literal immediately preceded by a minus sign. The
3594 -- result is equivalent to a string literal containing the text of
3595 -- the literal as it appeared in the source program with a possible
3596 -- leading minus sign.
3598 when Attribute_Universal_Literal_String => Universal_Literal_String :
3602 if not Is_Entity_Name (P)
3603 or else Ekind (Entity (P)) not in Named_Kind
3605 Error_Attr ("prefix for % attribute must be named number", P);
3612 Src : Source_Buffer_Ptr;
3615 Expr := Original_Node (Expression (Parent (Entity (P))));
3617 if Nkind (Expr) = N_Op_Minus then
3619 Expr := Original_Node (Right_Opnd (Expr));
3624 if Nkind (Expr) /= N_Integer_Literal
3625 and then Nkind (Expr) /= N_Real_Literal
3628 ("named number for % attribute must be simple literal", N);
3631 -- Build string literal corresponding to source literal text
3636 Store_String_Char (Get_Char_Code ('-'));
3640 Src := Source_Text (Get_Source_File_Index (S));
3642 while Src (S) /= ';' and then Src (S) /= ' ' loop
3643 Store_String_Char (Get_Char_Code (Src (S)));
3647 -- Now we rewrite the attribute with the string literal
3650 Make_String_Literal (Loc, End_String));
3654 end Universal_Literal_String;
3656 -------------------------
3657 -- Unrestricted_Access --
3658 -------------------------
3660 -- This is a GNAT specific attribute which is like Access except that
3661 -- all scope checks and checks for aliased views are omitted.
3663 when Attribute_Unrestricted_Access =>
3664 if Comes_From_Source (N) then
3665 Check_Restriction (No_Unchecked_Access, N);
3668 if Is_Entity_Name (P) then
3669 Set_Address_Taken (Entity (P));
3672 Analyze_Access_Attribute;
3678 when Attribute_Val => Val : declare
3681 Check_Discrete_Type;
3682 Resolve (E1, Any_Integer);
3683 Set_Etype (N, P_Base_Type);
3685 -- Note, we need a range check in general, but we wait for the
3686 -- Resolve call to do this, since we want to let Eval_Attribute
3687 -- have a chance to find an static illegality first!
3694 when Attribute_Valid =>
3697 -- Ignore check for object if we have a 'Valid reference generated
3698 -- by the expanded code, since in some cases valid checks can occur
3699 -- on items that are names, but are not objects (e.g. attributes).
3701 if Comes_From_Source (N) then
3702 Check_Object_Reference (P);
3705 if not Is_Scalar_Type (P_Type) then
3706 Error_Attr ("object for % attribute must be of scalar type", P);
3709 Set_Etype (N, Standard_Boolean);
3715 when Attribute_Value => Value :
3720 if Is_Enumeration_Type (P_Type) then
3721 Check_Restriction (No_Enumeration_Maps, N);
3724 -- Set Etype before resolving expression because expansion of
3725 -- expression may require enclosing type. Note that the type
3726 -- returned by 'Value is the base type of the prefix type.
3728 Set_Etype (N, P_Base_Type);
3729 Validate_Non_Static_Attribute_Function_Call;
3736 when Attribute_Value_Size =>
3739 Check_Not_Incomplete_Type;
3740 Set_Etype (N, Universal_Integer);
3746 when Attribute_Version =>
3749 Set_Etype (N, RTE (RE_Version_String));
3755 when Attribute_Wchar_T_Size =>
3756 Standard_Attribute (Interfaces_Wchar_T_Size);
3762 when Attribute_Wide_Image => Wide_Image :
3765 Set_Etype (N, Standard_Wide_String);
3767 Resolve (E1, P_Base_Type);
3768 Validate_Non_Static_Attribute_Function_Call;
3775 when Attribute_Wide_Value => Wide_Value :
3780 -- Set Etype before resolving expression because expansion
3781 -- of expression may require enclosing type.
3783 Set_Etype (N, P_Type);
3784 Validate_Non_Static_Attribute_Function_Call;
3791 when Attribute_Wide_Width =>
3794 Set_Etype (N, Universal_Integer);
3800 when Attribute_Width =>
3803 Set_Etype (N, Universal_Integer);
3809 when Attribute_Word_Size =>
3810 Standard_Attribute (System_Word_Size);
3816 when Attribute_Write =>
3818 Check_Stream_Attribute (TSS_Stream_Write);
3819 Set_Etype (N, Standard_Void_Type);
3820 Resolve (N, Standard_Void_Type);
3824 -- All errors raise Bad_Attribute, so that we get out before any further
3825 -- damage occurs when an error is detected (for example, if we check for
3826 -- one attribute expression, and the check succeeds, we want to be able
3827 -- to proceed securely assuming that an expression is in fact present.
3829 -- Note: we set the attribute analyzed in this case to prevent any
3830 -- attempt at reanalysis which could generate spurious error msgs.
3833 when Bad_Attribute =>
3835 Set_Etype (N, Any_Type);
3837 end Analyze_Attribute;
3839 --------------------
3840 -- Eval_Attribute --
3841 --------------------
3843 procedure Eval_Attribute (N : Node_Id) is
3844 Loc : constant Source_Ptr := Sloc (N);
3845 Aname : constant Name_Id := Attribute_Name (N);
3846 Id : constant Attribute_Id := Get_Attribute_Id (Aname);
3847 P : constant Node_Id := Prefix (N);
3849 C_Type : constant Entity_Id := Etype (N);
3850 -- The type imposed by the context.
3853 -- First expression, or Empty if none
3856 -- Second expression, or Empty if none
3858 P_Entity : Entity_Id;
3859 -- Entity denoted by prefix
3862 -- The type of the prefix
3864 P_Base_Type : Entity_Id;
3865 -- The base type of the prefix type
3867 P_Root_Type : Entity_Id;
3868 -- The root type of the prefix type
3871 -- True if the result is Static. This is set by the general processing
3872 -- to true if the prefix is static, and all expressions are static. It
3873 -- can be reset as processing continues for particular attributes
3875 Lo_Bound, Hi_Bound : Node_Id;
3876 -- Expressions for low and high bounds of type or array index referenced
3877 -- by First, Last, or Length attribute for array, set by Set_Bounds.
3880 -- Constraint error node used if we have an attribute reference has
3881 -- an argument that raises a constraint error. In this case we replace
3882 -- the attribute with a raise constraint_error node. This is important
3883 -- processing, since otherwise gigi might see an attribute which it is
3884 -- unprepared to deal with.
3886 function Aft_Value return Nat;
3887 -- Computes Aft value for current attribute prefix (used by Aft itself
3888 -- and also by Width for computing the Width of a fixed point type).
3890 procedure Check_Expressions;
3891 -- In case where the attribute is not foldable, the expressions, if
3892 -- any, of the attribute, are in a non-static context. This procedure
3893 -- performs the required additional checks.
3895 function Compile_Time_Known_Bounds (Typ : Entity_Id) return Boolean;
3896 -- Determines if the given type has compile time known bounds. Note
3897 -- that we enter the case statement even in cases where the prefix
3898 -- type does NOT have known bounds, so it is important to guard any
3899 -- attempt to evaluate both bounds with a call to this function.
3901 procedure Compile_Time_Known_Attribute (N : Node_Id; Val : Uint);
3902 -- This procedure is called when the attribute N has a non-static
3903 -- but compile time known value given by Val. It includes the
3904 -- necessary checks for out of range values.
3906 procedure Float_Attribute_Universal_Integer
3915 -- This procedure evaluates a float attribute with no arguments that
3916 -- returns a universal integer result. The parameters give the values
3917 -- for the possible floating-point root types. See ttypef for details.
3918 -- The prefix type is a float type (and is thus not a generic type).
3920 procedure Float_Attribute_Universal_Real
3921 (IEEES_Val : String;
3928 AAMPL_Val : String);
3929 -- This procedure evaluates a float attribute with no arguments that
3930 -- returns a universal real result. The parameters give the values
3931 -- required for the possible floating-point root types in string
3932 -- format as real literals with a possible leading minus sign.
3933 -- The prefix type is a float type (and is thus not a generic type).
3935 function Fore_Value return Nat;
3936 -- Computes the Fore value for the current attribute prefix, which is
3937 -- known to be a static fixed-point type. Used by Fore and Width.
3939 function Mantissa return Uint;
3940 -- Returns the Mantissa value for the prefix type
3942 procedure Set_Bounds;
3943 -- Used for First, Last and Length attributes applied to an array or
3944 -- array subtype. Sets the variables Lo_Bound and Hi_Bound to the low
3945 -- and high bound expressions for the index referenced by the attribute
3946 -- designator (i.e. the first index if no expression is present, and
3947 -- the N'th index if the value N is present as an expression). Also
3948 -- used for First and Last of scalar types. Static is reset to False
3949 -- if the type or index type is not statically constrained.
3955 function Aft_Value return Nat is
3961 Delta_Val := Delta_Value (P_Type);
3963 while Delta_Val < Ureal_Tenth loop
3964 Delta_Val := Delta_Val * Ureal_10;
3965 Result := Result + 1;
3971 -----------------------
3972 -- Check_Expressions --
3973 -----------------------
3975 procedure Check_Expressions is
3979 while Present (E) loop
3980 Check_Non_Static_Context (E);
3983 end Check_Expressions;
3985 ----------------------------------
3986 -- Compile_Time_Known_Attribute --
3987 ----------------------------------
3989 procedure Compile_Time_Known_Attribute (N : Node_Id; Val : Uint) is
3990 T : constant Entity_Id := Etype (N);
3993 Fold_Uint (N, Val, False);
3995 -- Check that result is in bounds of the type if it is static
3997 if Is_In_Range (N, T) then
4000 elsif Is_Out_Of_Range (N, T) then
4001 Apply_Compile_Time_Constraint_Error
4002 (N, "value not in range of}?", CE_Range_Check_Failed);
4004 elsif not Range_Checks_Suppressed (T) then
4005 Enable_Range_Check (N);
4008 Set_Do_Range_Check (N, False);
4010 end Compile_Time_Known_Attribute;
4012 -------------------------------
4013 -- Compile_Time_Known_Bounds --
4014 -------------------------------
4016 function Compile_Time_Known_Bounds (Typ : Entity_Id) return Boolean is
4019 Compile_Time_Known_Value (Type_Low_Bound (Typ))
4021 Compile_Time_Known_Value (Type_High_Bound (Typ));
4022 end Compile_Time_Known_Bounds;
4024 ---------------------------------------
4025 -- Float_Attribute_Universal_Integer --
4026 ---------------------------------------
4028 procedure Float_Attribute_Universal_Integer
4039 Digs : constant Nat := UI_To_Int (Digits_Value (P_Base_Type));
4042 if Vax_Float (P_Base_Type) then
4043 if Digs = VAXFF_Digits then
4045 elsif Digs = VAXDF_Digits then
4047 else pragma Assert (Digs = VAXGF_Digits);
4051 elsif Is_AAMP_Float (P_Base_Type) then
4052 if Digs = AAMPS_Digits then
4054 else pragma Assert (Digs = AAMPL_Digits);
4059 if Digs = IEEES_Digits then
4061 elsif Digs = IEEEL_Digits then
4063 else pragma Assert (Digs = IEEEX_Digits);
4068 Fold_Uint (N, UI_From_Int (Val), True);
4069 end Float_Attribute_Universal_Integer;
4071 ------------------------------------
4072 -- Float_Attribute_Universal_Real --
4073 ------------------------------------
4075 procedure Float_Attribute_Universal_Real
4076 (IEEES_Val : String;
4086 Digs : constant Nat := UI_To_Int (Digits_Value (P_Base_Type));
4089 if Vax_Float (P_Base_Type) then
4090 if Digs = VAXFF_Digits then
4091 Val := Real_Convert (VAXFF_Val);
4092 elsif Digs = VAXDF_Digits then
4093 Val := Real_Convert (VAXDF_Val);
4094 else pragma Assert (Digs = VAXGF_Digits);
4095 Val := Real_Convert (VAXGF_Val);
4098 elsif Is_AAMP_Float (P_Base_Type) then
4099 if Digs = AAMPS_Digits then
4100 Val := Real_Convert (AAMPS_Val);
4101 else pragma Assert (Digs = AAMPL_Digits);
4102 Val := Real_Convert (AAMPL_Val);
4106 if Digs = IEEES_Digits then
4107 Val := Real_Convert (IEEES_Val);
4108 elsif Digs = IEEEL_Digits then
4109 Val := Real_Convert (IEEEL_Val);
4110 else pragma Assert (Digs = IEEEX_Digits);
4111 Val := Real_Convert (IEEEX_Val);
4115 Set_Sloc (Val, Loc);
4117 Set_Is_Static_Expression (N, Static);
4118 Analyze_And_Resolve (N, C_Type);
4119 end Float_Attribute_Universal_Real;
4125 -- Note that the Fore calculation is based on the actual values
4126 -- of the bounds, and does not take into account possible rounding.
4128 function Fore_Value return Nat is
4129 Lo : constant Uint := Expr_Value (Type_Low_Bound (P_Type));
4130 Hi : constant Uint := Expr_Value (Type_High_Bound (P_Type));
4131 Small : constant Ureal := Small_Value (P_Type);
4132 Lo_Real : constant Ureal := Lo * Small;
4133 Hi_Real : constant Ureal := Hi * Small;
4138 -- Bounds are given in terms of small units, so first compute
4139 -- proper values as reals.
4141 T := UR_Max (abs Lo_Real, abs Hi_Real);
4144 -- Loop to compute proper value if more than one digit required
4146 while T >= Ureal_10 loop
4158 -- Table of mantissa values accessed by function Computed using
4161 -- T'Mantissa = integer next above (D * log(10)/log(2)) + 1)
4163 -- where D is T'Digits (RM83 3.5.7)
4165 Mantissa_Value : constant array (Nat range 1 .. 40) of Nat := (
4207 function Mantissa return Uint is
4210 UI_From_Int (Mantissa_Value (UI_To_Int (Digits_Value (P_Type))));
4217 procedure Set_Bounds is
4223 -- For a string literal subtype, we have to construct the bounds.
4224 -- Valid Ada code never applies attributes to string literals, but
4225 -- it is convenient to allow the expander to generate attribute
4226 -- references of this type (e.g. First and Last applied to a string
4229 -- Note that the whole point of the E_String_Literal_Subtype is to
4230 -- avoid this construction of bounds, but the cases in which we
4231 -- have to materialize them are rare enough that we don't worry!
4233 -- The low bound is simply the low bound of the base type. The
4234 -- high bound is computed from the length of the string and this
4237 if Ekind (P_Type) = E_String_Literal_Subtype then
4238 Ityp := Etype (First_Index (Base_Type (P_Type)));
4239 Lo_Bound := Type_Low_Bound (Ityp);
4242 Make_Integer_Literal (Sloc (P),
4244 Expr_Value (Lo_Bound) + String_Literal_Length (P_Type) - 1);
4246 Set_Parent (Hi_Bound, P);
4247 Analyze_And_Resolve (Hi_Bound, Etype (Lo_Bound));
4250 -- For non-array case, just get bounds of scalar type
4252 elsif Is_Scalar_Type (P_Type) then
4255 -- For a fixed-point type, we must freeze to get the attributes
4256 -- of the fixed-point type set now so we can reference them.
4258 if Is_Fixed_Point_Type (P_Type)
4259 and then not Is_Frozen (Base_Type (P_Type))
4260 and then Compile_Time_Known_Value (Type_Low_Bound (P_Type))
4261 and then Compile_Time_Known_Value (Type_High_Bound (P_Type))
4263 Freeze_Fixed_Point_Type (Base_Type (P_Type));
4266 -- For array case, get type of proper index
4272 Ndim := UI_To_Int (Expr_Value (E1));
4275 Indx := First_Index (P_Type);
4276 for J in 1 .. Ndim - 1 loop
4280 -- If no index type, get out (some other error occurred, and
4281 -- we don't have enough information to complete the job!)
4289 Ityp := Etype (Indx);
4292 -- A discrete range in an index constraint is allowed to be a
4293 -- subtype indication. This is syntactically a pain, but should
4294 -- not propagate to the entity for the corresponding index subtype.
4295 -- After checking that the subtype indication is legal, the range
4296 -- of the subtype indication should be transfered to the entity.
4297 -- The attributes for the bounds should remain the simple retrievals
4298 -- that they are now.
4300 Lo_Bound := Type_Low_Bound (Ityp);
4301 Hi_Bound := Type_High_Bound (Ityp);
4303 if not Is_Static_Subtype (Ityp) then
4308 -- Start of processing for Eval_Attribute
4311 -- Acquire first two expressions (at the moment, no attributes
4312 -- take more than two expressions in any case).
4314 if Present (Expressions (N)) then
4315 E1 := First (Expressions (N));
4322 -- Special processing for cases where the prefix is an object. For
4323 -- this purpose, a string literal counts as an object (attributes
4324 -- of string literals can only appear in generated code).
4326 if Is_Object_Reference (P) or else Nkind (P) = N_String_Literal then
4328 -- For Component_Size, the prefix is an array object, and we apply
4329 -- the attribute to the type of the object. This is allowed for
4330 -- both unconstrained and constrained arrays, since the bounds
4331 -- have no influence on the value of this attribute.
4333 if Id = Attribute_Component_Size then
4334 P_Entity := Etype (P);
4336 -- For First and Last, the prefix is an array object, and we apply
4337 -- the attribute to the type of the array, but we need a constrained
4338 -- type for this, so we use the actual subtype if available.
4340 elsif Id = Attribute_First
4344 Id = Attribute_Length
4347 AS : constant Entity_Id := Get_Actual_Subtype_If_Available (P);
4350 if Present (AS) and then Is_Constrained (AS) then
4353 -- If we have an unconstrained type, cannot fold
4361 -- For Size, give size of object if available, otherwise we
4362 -- cannot fold Size.
4364 elsif Id = Attribute_Size then
4365 if Is_Entity_Name (P)
4366 and then Known_Esize (Entity (P))
4368 Compile_Time_Known_Attribute (N, Esize (Entity (P)));
4376 -- For Alignment, give size of object if available, otherwise we
4377 -- cannot fold Alignment.
4379 elsif Id = Attribute_Alignment then
4380 if Is_Entity_Name (P)
4381 and then Known_Alignment (Entity (P))
4383 Fold_Uint (N, Alignment (Entity (P)), False);
4391 -- No other attributes for objects are folded
4398 -- Cases where P is not an object. Cannot do anything if P is
4399 -- not the name of an entity.
4401 elsif not Is_Entity_Name (P) then
4405 -- Otherwise get prefix entity
4408 P_Entity := Entity (P);
4411 -- At this stage P_Entity is the entity to which the attribute
4412 -- is to be applied. This is usually simply the entity of the
4413 -- prefix, except in some cases of attributes for objects, where
4414 -- as described above, we apply the attribute to the object type.
4416 -- First foldable possibility is a scalar or array type (RM 4.9(7))
4417 -- that is not generic (generic types are eliminated by RM 4.9(25)).
4418 -- Note we allow non-static non-generic types at this stage as further
4421 if Is_Type (P_Entity)
4422 and then (Is_Scalar_Type (P_Entity) or Is_Array_Type (P_Entity))
4423 and then (not Is_Generic_Type (P_Entity))
4427 -- Second foldable possibility is an array object (RM 4.9(8))
4429 elsif (Ekind (P_Entity) = E_Variable
4431 Ekind (P_Entity) = E_Constant)
4432 and then Is_Array_Type (Etype (P_Entity))
4433 and then (not Is_Generic_Type (Etype (P_Entity)))
4435 P_Type := Etype (P_Entity);
4437 -- If the entity is an array constant with an unconstrained
4438 -- nominal subtype then get the type from the initial value.
4439 -- If the value has been expanded into assignments, the expression
4440 -- is not present and the attribute reference remains dynamic.
4441 -- We could do better here and retrieve the type ???
4443 if Ekind (P_Entity) = E_Constant
4444 and then not Is_Constrained (P_Type)
4446 if No (Constant_Value (P_Entity)) then
4449 P_Type := Etype (Constant_Value (P_Entity));
4453 -- Definite must be folded if the prefix is not a generic type,
4454 -- that is to say if we are within an instantiation. Same processing
4455 -- applies to the GNAT attributes Has_Discriminants, Type_Class,
4456 -- and Unconstrained_Array.
4458 elsif (Id = Attribute_Definite
4460 Id = Attribute_Has_Access_Values
4462 Id = Attribute_Has_Discriminants
4464 Id = Attribute_Type_Class
4466 Id = Attribute_Unconstrained_Array)
4467 and then not Is_Generic_Type (P_Entity)
4471 -- We can fold 'Size applied to a type if the size is known
4472 -- (as happens for a size from an attribute definition clause).
4473 -- At this stage, this can happen only for types (e.g. record
4474 -- types) for which the size is always non-static. We exclude
4475 -- generic types from consideration (since they have bogus
4476 -- sizes set within templates).
4478 elsif Id = Attribute_Size
4479 and then Is_Type (P_Entity)
4480 and then (not Is_Generic_Type (P_Entity))
4481 and then Known_Static_RM_Size (P_Entity)
4483 Compile_Time_Known_Attribute (N, RM_Size (P_Entity));
4486 -- We can fold 'Alignment applied to a type if the alignment is known
4487 -- (as happens for an alignment from an attribute definition clause).
4488 -- At this stage, this can happen only for types (e.g. record
4489 -- types) for which the size is always non-static. We exclude
4490 -- generic types from consideration (since they have bogus
4491 -- sizes set within templates).
4493 elsif Id = Attribute_Alignment
4494 and then Is_Type (P_Entity)
4495 and then (not Is_Generic_Type (P_Entity))
4496 and then Known_Alignment (P_Entity)
4498 Compile_Time_Known_Attribute (N, Alignment (P_Entity));
4501 -- If this is an access attribute that is known to fail accessibility
4502 -- check, rewrite accordingly.
4504 elsif Attribute_Name (N) = Name_Access
4505 and then Raises_Constraint_Error (N)
4508 Make_Raise_Program_Error (Loc,
4509 Reason => PE_Accessibility_Check_Failed));
4510 Set_Etype (N, C_Type);
4513 -- No other cases are foldable (they certainly aren't static, and at
4514 -- the moment we don't try to fold any cases other than these three).
4521 -- If either attribute or the prefix is Any_Type, then propagate
4522 -- Any_Type to the result and don't do anything else at all.
4524 if P_Type = Any_Type
4525 or else (Present (E1) and then Etype (E1) = Any_Type)
4526 or else (Present (E2) and then Etype (E2) = Any_Type)
4528 Set_Etype (N, Any_Type);
4532 -- Scalar subtype case. We have not yet enforced the static requirement
4533 -- of (RM 4.9(7)) and we don't intend to just yet, since there are cases
4534 -- of non-static attribute references (e.g. S'Digits for a non-static
4535 -- floating-point type, which we can compute at compile time).
4537 -- Note: this folding of non-static attributes is not simply a case of
4538 -- optimization. For many of the attributes affected, Gigi cannot handle
4539 -- the attribute and depends on the front end having folded them away.
4541 -- Note: although we don't require staticness at this stage, we do set
4542 -- the Static variable to record the staticness, for easy reference by
4543 -- those attributes where it matters (e.g. Succ and Pred), and also to
4544 -- be used to ensure that non-static folded things are not marked as
4545 -- being static (a check that is done right at the end).
4547 P_Root_Type := Root_Type (P_Type);
4548 P_Base_Type := Base_Type (P_Type);
4550 -- If the root type or base type is generic, then we cannot fold. This
4551 -- test is needed because subtypes of generic types are not always
4552 -- marked as being generic themselves (which seems odd???)
4554 if Is_Generic_Type (P_Root_Type)
4555 or else Is_Generic_Type (P_Base_Type)
4560 if Is_Scalar_Type (P_Type) then
4561 Static := Is_OK_Static_Subtype (P_Type);
4563 -- Array case. We enforce the constrained requirement of (RM 4.9(7-8))
4564 -- since we can't do anything with unconstrained arrays. In addition,
4565 -- only the First, Last and Length attributes are possibly static.
4566 -- In addition Component_Size is possibly foldable, even though it
4567 -- can never be static.
4569 -- Definite, Has_Access_Values, Has_Discriminants, Type_Class, and
4570 -- Unconstrained_Array are again exceptions, because they apply as
4571 -- well to unconstrained types.
4573 elsif Id = Attribute_Definite
4575 Id = Attribute_Has_Access_Values
4577 Id = Attribute_Has_Discriminants
4579 Id = Attribute_Type_Class
4581 Id = Attribute_Unconstrained_Array
4586 if not Is_Constrained (P_Type)
4587 or else (Id /= Attribute_Component_Size and then
4588 Id /= Attribute_First and then
4589 Id /= Attribute_Last and then
4590 Id /= Attribute_Length)
4596 -- The rules in (RM 4.9(7,8)) require a static array, but as in the
4597 -- scalar case, we hold off on enforcing staticness, since there are
4598 -- cases which we can fold at compile time even though they are not
4599 -- static (e.g. 'Length applied to a static index, even though other
4600 -- non-static indexes make the array type non-static). This is only
4601 -- an optimization, but it falls out essentially free, so why not.
4602 -- Again we compute the variable Static for easy reference later
4603 -- (note that no array attributes are static in Ada 83).
4605 Static := Ada_Version >= Ada_95;
4611 N := First_Index (P_Type);
4612 while Present (N) loop
4613 Static := Static and then Is_Static_Subtype (Etype (N));
4615 -- If however the index type is generic, attributes cannot
4618 if Is_Generic_Type (Etype (N))
4619 and then Id /= Attribute_Component_Size
4629 -- Check any expressions that are present. Note that these expressions,
4630 -- depending on the particular attribute type, are either part of the
4631 -- attribute designator, or they are arguments in a case where the
4632 -- attribute reference returns a function. In the latter case, the
4633 -- rule in (RM 4.9(22)) applies and in particular requires the type
4634 -- of the expressions to be scalar in order for the attribute to be
4635 -- considered to be static.
4642 while Present (E) loop
4644 -- If expression is not static, then the attribute reference
4645 -- result certainly cannot be static.
4647 if not Is_Static_Expression (E) then
4651 -- If the result is not known at compile time, or is not of
4652 -- a scalar type, then the result is definitely not static,
4653 -- so we can quit now.
4655 if not Compile_Time_Known_Value (E)
4656 or else not Is_Scalar_Type (Etype (E))
4658 -- An odd special case, if this is a Pos attribute, this
4659 -- is where we need to apply a range check since it does
4660 -- not get done anywhere else.
4662 if Id = Attribute_Pos then
4663 if Is_Integer_Type (Etype (E)) then
4664 Apply_Range_Check (E, Etype (N));
4671 -- If the expression raises a constraint error, then so does
4672 -- the attribute reference. We keep going in this case because
4673 -- we are still interested in whether the attribute reference
4674 -- is static even if it is not static.
4676 elsif Raises_Constraint_Error (E) then
4677 Set_Raises_Constraint_Error (N);
4683 if Raises_Constraint_Error (Prefix (N)) then
4688 -- Deal with the case of a static attribute reference that raises
4689 -- constraint error. The Raises_Constraint_Error flag will already
4690 -- have been set, and the Static flag shows whether the attribute
4691 -- reference is static. In any case we certainly can't fold such an
4692 -- attribute reference.
4694 -- Note that the rewriting of the attribute node with the constraint
4695 -- error node is essential in this case, because otherwise Gigi might
4696 -- blow up on one of the attributes it never expects to see.
4698 -- The constraint_error node must have the type imposed by the context,
4699 -- to avoid spurious errors in the enclosing expression.
4701 if Raises_Constraint_Error (N) then
4703 Make_Raise_Constraint_Error (Sloc (N),
4704 Reason => CE_Range_Check_Failed);
4705 Set_Etype (CE_Node, Etype (N));
4706 Set_Raises_Constraint_Error (CE_Node);
4708 Rewrite (N, Relocate_Node (CE_Node));
4709 Set_Is_Static_Expression (N, Static);
4713 -- At this point we have a potentially foldable attribute reference.
4714 -- If Static is set, then the attribute reference definitely obeys
4715 -- the requirements in (RM 4.9(7,8,22)), and it definitely can be
4716 -- folded. If Static is not set, then the attribute may or may not
4717 -- be foldable, and the individual attribute processing routines
4718 -- test Static as required in cases where it makes a difference.
4720 -- In the case where Static is not set, we do know that all the
4721 -- expressions present are at least known at compile time (we
4722 -- assumed above that if this was not the case, then there was
4723 -- no hope of static evaluation). However, we did not require
4724 -- that the bounds of the prefix type be compile time known,
4725 -- let alone static). That's because there are many attributes
4726 -- that can be computed at compile time on non-static subtypes,
4727 -- even though such references are not static expressions.
4735 when Attribute_Adjacent =>
4738 (P_Root_Type, Expr_Value_R (E1), Expr_Value_R (E2)), Static);
4744 when Attribute_Aft =>
4745 Fold_Uint (N, UI_From_Int (Aft_Value), True);
4751 when Attribute_Alignment => Alignment_Block : declare
4752 P_TypeA : constant Entity_Id := Underlying_Type (P_Type);
4755 -- Fold if alignment is set and not otherwise
4757 if Known_Alignment (P_TypeA) then
4758 Fold_Uint (N, Alignment (P_TypeA), Is_Discrete_Type (P_TypeA));
4760 end Alignment_Block;
4766 -- Can only be folded in No_Ast_Handler case
4768 when Attribute_AST_Entry =>
4769 if not Is_AST_Entry (P_Entity) then
4771 New_Occurrence_Of (RTE (RE_No_AST_Handler), Loc));
4780 -- Bit can never be folded
4782 when Attribute_Bit =>
4789 -- Body_version can never be static
4791 when Attribute_Body_Version =>
4798 when Attribute_Ceiling =>
4800 Eval_Fat.Ceiling (P_Root_Type, Expr_Value_R (E1)), Static);
4802 --------------------
4803 -- Component_Size --
4804 --------------------
4806 when Attribute_Component_Size =>
4807 if Known_Static_Component_Size (P_Type) then
4808 Fold_Uint (N, Component_Size (P_Type), False);
4815 when Attribute_Compose =>
4818 (P_Root_Type, Expr_Value_R (E1), Expr_Value (E2)),
4825 -- Constrained is never folded for now, there may be cases that
4826 -- could be handled at compile time. to be looked at later.
4828 when Attribute_Constrained =>
4835 when Attribute_Copy_Sign =>
4838 (P_Root_Type, Expr_Value_R (E1), Expr_Value_R (E2)), Static);
4844 when Attribute_Delta =>
4845 Fold_Ureal (N, Delta_Value (P_Type), True);
4851 when Attribute_Definite =>
4852 Rewrite (N, New_Occurrence_Of (
4853 Boolean_Literals (not Is_Indefinite_Subtype (P_Entity)), Loc));
4854 Analyze_And_Resolve (N, Standard_Boolean);
4860 when Attribute_Denorm =>
4862 (N, UI_From_Int (Boolean'Pos (Denorm_On_Target)), True);
4868 when Attribute_Digits =>
4869 Fold_Uint (N, Digits_Value (P_Type), True);
4875 when Attribute_Emax =>
4877 -- Ada 83 attribute is defined as (RM83 3.5.8)
4879 -- T'Emax = 4 * T'Mantissa
4881 Fold_Uint (N, 4 * Mantissa, True);
4887 when Attribute_Enum_Rep =>
4889 -- For an enumeration type with a non-standard representation
4890 -- use the Enumeration_Rep field of the proper constant. Note
4891 -- that this would not work for types Character/Wide_Character,
4892 -- since no real entities are created for the enumeration
4893 -- literals, but that does not matter since these two types
4894 -- do not have non-standard representations anyway.
4896 if Is_Enumeration_Type (P_Type)
4897 and then Has_Non_Standard_Rep (P_Type)
4899 Fold_Uint (N, Enumeration_Rep (Expr_Value_E (E1)), Static);
4901 -- For enumeration types with standard representations and all
4902 -- other cases (i.e. all integer and modular types), Enum_Rep
4903 -- is equivalent to Pos.
4906 Fold_Uint (N, Expr_Value (E1), Static);
4913 when Attribute_Epsilon =>
4915 -- Ada 83 attribute is defined as (RM83 3.5.8)
4917 -- T'Epsilon = 2.0**(1 - T'Mantissa)
4919 Fold_Ureal (N, Ureal_2 ** (1 - Mantissa), True);
4925 when Attribute_Exponent =>
4927 Eval_Fat.Exponent (P_Root_Type, Expr_Value_R (E1)), Static);
4933 when Attribute_First => First_Attr :
4937 if Compile_Time_Known_Value (Lo_Bound) then
4938 if Is_Real_Type (P_Type) then
4939 Fold_Ureal (N, Expr_Value_R (Lo_Bound), Static);
4941 Fold_Uint (N, Expr_Value (Lo_Bound), Static);
4950 when Attribute_Fixed_Value =>
4957 when Attribute_Floor =>
4959 Eval_Fat.Floor (P_Root_Type, Expr_Value_R (E1)), Static);
4965 when Attribute_Fore =>
4966 if Compile_Time_Known_Bounds (P_Type) then
4967 Fold_Uint (N, UI_From_Int (Fore_Value), Static);
4974 when Attribute_Fraction =>
4976 Eval_Fat.Fraction (P_Root_Type, Expr_Value_R (E1)), Static);
4978 -----------------------
4979 -- Has_Access_Values --
4980 -----------------------
4982 when Attribute_Has_Access_Values =>
4983 Rewrite (N, New_Occurrence_Of
4984 (Boolean_Literals (Has_Access_Values (P_Root_Type)), Loc));
4985 Analyze_And_Resolve (N, Standard_Boolean);
4987 -----------------------
4988 -- Has_Discriminants --
4989 -----------------------
4991 when Attribute_Has_Discriminants =>
4992 Rewrite (N, New_Occurrence_Of (
4993 Boolean_Literals (Has_Discriminants (P_Entity)), Loc));
4994 Analyze_And_Resolve (N, Standard_Boolean);
5000 when Attribute_Identity =>
5007 -- Image is a scalar attribute, but is never static, because it is
5008 -- not a static function (having a non-scalar argument (RM 4.9(22))
5010 when Attribute_Image =>
5017 -- Img is a scalar attribute, but is never static, because it is
5018 -- not a static function (having a non-scalar argument (RM 4.9(22))
5020 when Attribute_Img =>
5027 when Attribute_Integer_Value =>
5034 when Attribute_Large =>
5036 -- For fixed-point, we use the identity:
5038 -- T'Large = (2.0**T'Mantissa - 1.0) * T'Small
5040 if Is_Fixed_Point_Type (P_Type) then
5042 Make_Op_Multiply (Loc,
5044 Make_Op_Subtract (Loc,
5048 Make_Real_Literal (Loc, Ureal_2),
5050 Make_Attribute_Reference (Loc,
5052 Attribute_Name => Name_Mantissa)),
5053 Right_Opnd => Make_Real_Literal (Loc, Ureal_1)),
5056 Make_Real_Literal (Loc, Small_Value (Entity (P)))));
5058 Analyze_And_Resolve (N, C_Type);
5060 -- Floating-point (Ada 83 compatibility)
5063 -- Ada 83 attribute is defined as (RM83 3.5.8)
5065 -- T'Large = 2.0**T'Emax * (1.0 - 2.0**(-T'Mantissa))
5069 -- T'Emax = 4 * T'Mantissa
5072 Ureal_2 ** (4 * Mantissa) * (Ureal_1 - Ureal_2 ** (-Mantissa)),
5080 when Attribute_Last => Last :
5084 if Compile_Time_Known_Value (Hi_Bound) then
5085 if Is_Real_Type (P_Type) then
5086 Fold_Ureal (N, Expr_Value_R (Hi_Bound), Static);
5088 Fold_Uint (N, Expr_Value (Hi_Bound), Static);
5097 when Attribute_Leading_Part =>
5099 Eval_Fat.Leading_Part
5100 (P_Root_Type, Expr_Value_R (E1), Expr_Value (E2)), Static);
5106 when Attribute_Length => Length : declare
5110 -- In the case of a generic index type, the bounds may
5111 -- appear static but the computation is not meaningful,
5112 -- and may generate a spurious warning.
5114 Ind := First_Index (P_Type);
5116 while Present (Ind) loop
5117 if Is_Generic_Type (Etype (Ind)) then
5126 if Compile_Time_Known_Value (Lo_Bound)
5127 and then Compile_Time_Known_Value (Hi_Bound)
5130 UI_Max (0, 1 + (Expr_Value (Hi_Bound) - Expr_Value (Lo_Bound))),
5139 when Attribute_Machine =>
5142 (P_Root_Type, Expr_Value_R (E1), Eval_Fat.Round, N),
5149 when Attribute_Machine_Emax =>
5150 Float_Attribute_Universal_Integer (
5158 AAMPL_Machine_Emax);
5164 when Attribute_Machine_Emin =>
5165 Float_Attribute_Universal_Integer (
5173 AAMPL_Machine_Emin);
5175 ----------------------
5176 -- Machine_Mantissa --
5177 ----------------------
5179 when Attribute_Machine_Mantissa =>
5180 Float_Attribute_Universal_Integer (
5181 IEEES_Machine_Mantissa,
5182 IEEEL_Machine_Mantissa,
5183 IEEEX_Machine_Mantissa,
5184 VAXFF_Machine_Mantissa,
5185 VAXDF_Machine_Mantissa,
5186 VAXGF_Machine_Mantissa,
5187 AAMPS_Machine_Mantissa,
5188 AAMPL_Machine_Mantissa);
5190 -----------------------
5191 -- Machine_Overflows --
5192 -----------------------
5194 when Attribute_Machine_Overflows =>
5196 -- Always true for fixed-point
5198 if Is_Fixed_Point_Type (P_Type) then
5199 Fold_Uint (N, True_Value, True);
5201 -- Floating point case
5205 UI_From_Int (Boolean'Pos (Machine_Overflows_On_Target)),
5213 when Attribute_Machine_Radix =>
5214 if Is_Fixed_Point_Type (P_Type) then
5215 if Is_Decimal_Fixed_Point_Type (P_Type)
5216 and then Machine_Radix_10 (P_Type)
5218 Fold_Uint (N, Uint_10, True);
5220 Fold_Uint (N, Uint_2, True);
5223 -- All floating-point type always have radix 2
5226 Fold_Uint (N, Uint_2, True);
5229 --------------------
5230 -- Machine_Rounds --
5231 --------------------
5233 when Attribute_Machine_Rounds =>
5235 -- Always False for fixed-point
5237 if Is_Fixed_Point_Type (P_Type) then
5238 Fold_Uint (N, False_Value, True);
5240 -- Else yield proper floating-point result
5244 (N, UI_From_Int (Boolean'Pos (Machine_Rounds_On_Target)), True);
5251 -- Note: Machine_Size is identical to Object_Size
5253 when Attribute_Machine_Size => Machine_Size : declare
5254 P_TypeA : constant Entity_Id := Underlying_Type (P_Type);
5257 if Known_Esize (P_TypeA) then
5258 Fold_Uint (N, Esize (P_TypeA), True);
5266 when Attribute_Mantissa =>
5268 -- Fixed-point mantissa
5270 if Is_Fixed_Point_Type (P_Type) then
5272 -- Compile time foldable case
5274 if Compile_Time_Known_Value (Type_Low_Bound (P_Type))
5276 Compile_Time_Known_Value (Type_High_Bound (P_Type))
5278 -- The calculation of the obsolete Ada 83 attribute Mantissa
5279 -- is annoying, because of AI00143, quoted here:
5281 -- !question 84-01-10
5283 -- Consider the model numbers for F:
5285 -- type F is delta 1.0 range -7.0 .. 8.0;
5287 -- The wording requires that F'MANTISSA be the SMALLEST
5288 -- integer number for which each bound of the specified
5289 -- range is either a model number or lies at most small
5290 -- distant from a model number. This means F'MANTISSA
5291 -- is required to be 3 since the range -7.0 .. 7.0 fits
5292 -- in 3 signed bits, and 8 is "at most" 1.0 from a model
5293 -- number, namely, 7. Is this analysis correct? Note that
5294 -- this implies the upper bound of the range is not
5295 -- represented as a model number.
5297 -- !response 84-03-17
5299 -- The analysis is correct. The upper and lower bounds for
5300 -- a fixed point type can lie outside the range of model
5311 LBound := Expr_Value_R (Type_Low_Bound (P_Type));
5312 UBound := Expr_Value_R (Type_High_Bound (P_Type));
5313 Bound := UR_Max (UR_Abs (LBound), UR_Abs (UBound));
5314 Max_Man := UR_Trunc (Bound / Small_Value (P_Type));
5316 -- If the Bound is exactly a model number, i.e. a multiple
5317 -- of Small, then we back it off by one to get the integer
5318 -- value that must be representable.
5320 if Small_Value (P_Type) * Max_Man = Bound then
5321 Max_Man := Max_Man - 1;
5324 -- Now find corresponding size = Mantissa value
5327 while 2 ** Siz < Max_Man loop
5331 Fold_Uint (N, Siz, True);
5335 -- The case of dynamic bounds cannot be evaluated at compile
5336 -- time. Instead we use a runtime routine (see Exp_Attr).
5341 -- Floating-point Mantissa
5344 Fold_Uint (N, Mantissa, True);
5351 when Attribute_Max => Max :
5353 if Is_Real_Type (P_Type) then
5355 (N, UR_Max (Expr_Value_R (E1), Expr_Value_R (E2)), Static);
5357 Fold_Uint (N, UI_Max (Expr_Value (E1), Expr_Value (E2)), Static);
5361 ----------------------------------
5362 -- Max_Size_In_Storage_Elements --
5363 ----------------------------------
5365 -- Max_Size_In_Storage_Elements is simply the Size rounded up to a
5366 -- Storage_Unit boundary. We can fold any cases for which the size
5367 -- is known by the front end.
5369 when Attribute_Max_Size_In_Storage_Elements =>
5370 if Known_Esize (P_Type) then
5372 (Esize (P_Type) + System_Storage_Unit - 1) /
5373 System_Storage_Unit,
5377 --------------------
5378 -- Mechanism_Code --
5379 --------------------
5381 when Attribute_Mechanism_Code =>
5385 Mech : Mechanism_Type;
5389 Mech := Mechanism (P_Entity);
5392 Val := UI_To_Int (Expr_Value (E1));
5394 Formal := First_Formal (P_Entity);
5395 for J in 1 .. Val - 1 loop
5396 Next_Formal (Formal);
5398 Mech := Mechanism (Formal);
5402 Fold_Uint (N, UI_From_Int (Int (-Mech)), True);
5410 when Attribute_Min => Min :
5412 if Is_Real_Type (P_Type) then
5414 (N, UR_Min (Expr_Value_R (E1), Expr_Value_R (E2)), Static);
5416 Fold_Uint (N, UI_Min (Expr_Value (E1), Expr_Value (E2)), Static);
5424 when Attribute_Model =>
5426 Eval_Fat.Model (P_Root_Type, Expr_Value_R (E1)), Static);
5432 when Attribute_Model_Emin =>
5433 Float_Attribute_Universal_Integer (
5447 when Attribute_Model_Epsilon =>
5448 Float_Attribute_Universal_Real (
5449 IEEES_Model_Epsilon'Universal_Literal_String,
5450 IEEEL_Model_Epsilon'Universal_Literal_String,
5451 IEEEX_Model_Epsilon'Universal_Literal_String,
5452 VAXFF_Model_Epsilon'Universal_Literal_String,
5453 VAXDF_Model_Epsilon'Universal_Literal_String,
5454 VAXGF_Model_Epsilon'Universal_Literal_String,
5455 AAMPS_Model_Epsilon'Universal_Literal_String,
5456 AAMPL_Model_Epsilon'Universal_Literal_String);
5458 --------------------
5459 -- Model_Mantissa --
5460 --------------------
5462 when Attribute_Model_Mantissa =>
5463 Float_Attribute_Universal_Integer (
5464 IEEES_Model_Mantissa,
5465 IEEEL_Model_Mantissa,
5466 IEEEX_Model_Mantissa,
5467 VAXFF_Model_Mantissa,
5468 VAXDF_Model_Mantissa,
5469 VAXGF_Model_Mantissa,
5470 AAMPS_Model_Mantissa,
5471 AAMPL_Model_Mantissa);
5477 when Attribute_Model_Small =>
5478 Float_Attribute_Universal_Real (
5479 IEEES_Model_Small'Universal_Literal_String,
5480 IEEEL_Model_Small'Universal_Literal_String,
5481 IEEEX_Model_Small'Universal_Literal_String,
5482 VAXFF_Model_Small'Universal_Literal_String,
5483 VAXDF_Model_Small'Universal_Literal_String,
5484 VAXGF_Model_Small'Universal_Literal_String,
5485 AAMPS_Model_Small'Universal_Literal_String,
5486 AAMPL_Model_Small'Universal_Literal_String);
5492 when Attribute_Modulus =>
5493 Fold_Uint (N, Modulus (P_Type), True);
5495 --------------------
5496 -- Null_Parameter --
5497 --------------------
5499 -- Cannot fold, we know the value sort of, but the whole point is
5500 -- that there is no way to talk about this imaginary value except
5501 -- by using the attribute, so we leave it the way it is.
5503 when Attribute_Null_Parameter =>
5510 -- The Object_Size attribute for a type returns the Esize of the
5511 -- type and can be folded if this value is known.
5513 when Attribute_Object_Size => Object_Size : declare
5514 P_TypeA : constant Entity_Id := Underlying_Type (P_Type);
5517 if Known_Esize (P_TypeA) then
5518 Fold_Uint (N, Esize (P_TypeA), True);
5522 -------------------------
5523 -- Passed_By_Reference --
5524 -------------------------
5526 -- Scalar types are never passed by reference
5528 when Attribute_Passed_By_Reference =>
5529 Fold_Uint (N, False_Value, True);
5535 when Attribute_Pos =>
5536 Fold_Uint (N, Expr_Value (E1), True);
5542 when Attribute_Pred => Pred :
5544 -- Floating-point case
5546 if Is_Floating_Point_Type (P_Type) then
5548 Eval_Fat.Pred (P_Root_Type, Expr_Value_R (E1)), Static);
5552 elsif Is_Fixed_Point_Type (P_Type) then
5554 Expr_Value_R (E1) - Small_Value (P_Type), True);
5556 -- Modular integer case (wraps)
5558 elsif Is_Modular_Integer_Type (P_Type) then
5559 Fold_Uint (N, (Expr_Value (E1) - 1) mod Modulus (P_Type), Static);
5561 -- Other scalar cases
5564 pragma Assert (Is_Scalar_Type (P_Type));
5566 if Is_Enumeration_Type (P_Type)
5567 and then Expr_Value (E1) =
5568 Expr_Value (Type_Low_Bound (P_Base_Type))
5570 Apply_Compile_Time_Constraint_Error
5571 (N, "Pred of `&''First`",
5572 CE_Overflow_Check_Failed,
5574 Warn => not Static);
5580 Fold_Uint (N, Expr_Value (E1) - 1, Static);
5588 -- No processing required, because by this stage, Range has been
5589 -- replaced by First .. Last, so this branch can never be taken.
5591 when Attribute_Range =>
5592 raise Program_Error;
5598 when Attribute_Range_Length =>
5601 if Compile_Time_Known_Value (Hi_Bound)
5602 and then Compile_Time_Known_Value (Lo_Bound)
5606 (0, Expr_Value (Hi_Bound) - Expr_Value (Lo_Bound) + 1),
5614 when Attribute_Remainder =>
5617 (P_Root_Type, Expr_Value_R (E1), Expr_Value_R (E2)),
5624 when Attribute_Round => Round :
5630 -- First we get the (exact result) in units of small
5632 Sr := Expr_Value_R (E1) / Small_Value (C_Type);
5634 -- Now round that exactly to an integer
5636 Si := UR_To_Uint (Sr);
5638 -- Finally the result is obtained by converting back to real
5640 Fold_Ureal (N, Si * Small_Value (C_Type), Static);
5647 when Attribute_Rounding =>
5649 Eval_Fat.Rounding (P_Root_Type, Expr_Value_R (E1)), Static);
5655 when Attribute_Safe_Emax =>
5656 Float_Attribute_Universal_Integer (
5670 when Attribute_Safe_First =>
5671 Float_Attribute_Universal_Real (
5672 IEEES_Safe_First'Universal_Literal_String,
5673 IEEEL_Safe_First'Universal_Literal_String,
5674 IEEEX_Safe_First'Universal_Literal_String,
5675 VAXFF_Safe_First'Universal_Literal_String,
5676 VAXDF_Safe_First'Universal_Literal_String,
5677 VAXGF_Safe_First'Universal_Literal_String,
5678 AAMPS_Safe_First'Universal_Literal_String,
5679 AAMPL_Safe_First'Universal_Literal_String);
5685 when Attribute_Safe_Large =>
5686 if Is_Fixed_Point_Type (P_Type) then
5688 (N, Expr_Value_R (Type_High_Bound (P_Base_Type)), Static);
5690 Float_Attribute_Universal_Real (
5691 IEEES_Safe_Large'Universal_Literal_String,
5692 IEEEL_Safe_Large'Universal_Literal_String,
5693 IEEEX_Safe_Large'Universal_Literal_String,
5694 VAXFF_Safe_Large'Universal_Literal_String,
5695 VAXDF_Safe_Large'Universal_Literal_String,
5696 VAXGF_Safe_Large'Universal_Literal_String,
5697 AAMPS_Safe_Large'Universal_Literal_String,
5698 AAMPL_Safe_Large'Universal_Literal_String);
5705 when Attribute_Safe_Last =>
5706 Float_Attribute_Universal_Real (
5707 IEEES_Safe_Last'Universal_Literal_String,
5708 IEEEL_Safe_Last'Universal_Literal_String,
5709 IEEEX_Safe_Last'Universal_Literal_String,
5710 VAXFF_Safe_Last'Universal_Literal_String,
5711 VAXDF_Safe_Last'Universal_Literal_String,
5712 VAXGF_Safe_Last'Universal_Literal_String,
5713 AAMPS_Safe_Last'Universal_Literal_String,
5714 AAMPL_Safe_Last'Universal_Literal_String);
5720 when Attribute_Safe_Small =>
5722 -- In Ada 95, the old Ada 83 attribute Safe_Small is redundant
5723 -- for fixed-point, since is the same as Small, but we implement
5724 -- it for backwards compatibility.
5726 if Is_Fixed_Point_Type (P_Type) then
5727 Fold_Ureal (N, Small_Value (P_Type), Static);
5729 -- Ada 83 Safe_Small for floating-point cases
5732 Float_Attribute_Universal_Real (
5733 IEEES_Safe_Small'Universal_Literal_String,
5734 IEEEL_Safe_Small'Universal_Literal_String,
5735 IEEEX_Safe_Small'Universal_Literal_String,
5736 VAXFF_Safe_Small'Universal_Literal_String,
5737 VAXDF_Safe_Small'Universal_Literal_String,
5738 VAXGF_Safe_Small'Universal_Literal_String,
5739 AAMPS_Safe_Small'Universal_Literal_String,
5740 AAMPL_Safe_Small'Universal_Literal_String);
5747 when Attribute_Scale =>
5748 Fold_Uint (N, Scale_Value (P_Type), True);
5754 when Attribute_Scaling =>
5757 (P_Root_Type, Expr_Value_R (E1), Expr_Value (E2)), Static);
5763 when Attribute_Signed_Zeros =>
5765 (N, UI_From_Int (Boolean'Pos (Signed_Zeros_On_Target)), Static);
5771 -- Size attribute returns the RM size. All scalar types can be folded,
5772 -- as well as any types for which the size is known by the front end,
5773 -- including any type for which a size attribute is specified.
5775 when Attribute_Size | Attribute_VADS_Size => Size : declare
5776 P_TypeA : constant Entity_Id := Underlying_Type (P_Type);
5779 if RM_Size (P_TypeA) /= Uint_0 then
5783 if Id = Attribute_VADS_Size or else Use_VADS_Size then
5785 S : constant Node_Id := Size_Clause (P_TypeA);
5788 -- If a size clause applies, then use the size from it.
5789 -- This is one of the rare cases where we can use the
5790 -- Size_Clause field for a subtype when Has_Size_Clause
5791 -- is False. Consider:
5793 -- type x is range 1 .. 64; g
5794 -- for x'size use 12;
5795 -- subtype y is x range 0 .. 3;
5797 -- Here y has a size clause inherited from x, but normally
5798 -- it does not apply, and y'size is 2. However, y'VADS_Size
5799 -- is indeed 12 and not 2.
5802 and then Is_OK_Static_Expression (Expression (S))
5804 Fold_Uint (N, Expr_Value (Expression (S)), True);
5806 -- If no size is specified, then we simply use the object
5807 -- size in the VADS_Size case (e.g. Natural'Size is equal
5808 -- to Integer'Size, not one less).
5811 Fold_Uint (N, Esize (P_TypeA), True);
5815 -- Normal case (Size) in which case we want the RM_Size
5820 Static and then Is_Discrete_Type (P_TypeA));
5829 when Attribute_Small =>
5831 -- The floating-point case is present only for Ada 83 compatability.
5832 -- Note that strictly this is an illegal addition, since we are
5833 -- extending an Ada 95 defined attribute, but we anticipate an
5834 -- ARG ruling that will permit this.
5836 if Is_Floating_Point_Type (P_Type) then
5838 -- Ada 83 attribute is defined as (RM83 3.5.8)
5840 -- T'Small = 2.0**(-T'Emax - 1)
5844 -- T'Emax = 4 * T'Mantissa
5846 Fold_Ureal (N, Ureal_2 ** ((-(4 * Mantissa)) - 1), Static);
5848 -- Normal Ada 95 fixed-point case
5851 Fold_Ureal (N, Small_Value (P_Type), True);
5858 when Attribute_Succ => Succ :
5860 -- Floating-point case
5862 if Is_Floating_Point_Type (P_Type) then
5864 Eval_Fat.Succ (P_Root_Type, Expr_Value_R (E1)), Static);
5868 elsif Is_Fixed_Point_Type (P_Type) then
5870 Expr_Value_R (E1) + Small_Value (P_Type), Static);
5872 -- Modular integer case (wraps)
5874 elsif Is_Modular_Integer_Type (P_Type) then
5875 Fold_Uint (N, (Expr_Value (E1) + 1) mod Modulus (P_Type), Static);
5877 -- Other scalar cases
5880 pragma Assert (Is_Scalar_Type (P_Type));
5882 if Is_Enumeration_Type (P_Type)
5883 and then Expr_Value (E1) =
5884 Expr_Value (Type_High_Bound (P_Base_Type))
5886 Apply_Compile_Time_Constraint_Error
5887 (N, "Succ of `&''Last`",
5888 CE_Overflow_Check_Failed,
5890 Warn => not Static);
5895 Fold_Uint (N, Expr_Value (E1) + 1, Static);
5904 when Attribute_Truncation =>
5906 Eval_Fat.Truncation (P_Root_Type, Expr_Value_R (E1)), Static);
5912 when Attribute_Type_Class => Type_Class : declare
5913 Typ : constant Entity_Id := Underlying_Type (P_Base_Type);
5917 if Is_Descendent_Of_Address (Typ) then
5918 Id := RE_Type_Class_Address;
5920 elsif Is_Enumeration_Type (Typ) then
5921 Id := RE_Type_Class_Enumeration;
5923 elsif Is_Integer_Type (Typ) then
5924 Id := RE_Type_Class_Integer;
5926 elsif Is_Fixed_Point_Type (Typ) then
5927 Id := RE_Type_Class_Fixed_Point;
5929 elsif Is_Floating_Point_Type (Typ) then
5930 Id := RE_Type_Class_Floating_Point;
5932 elsif Is_Array_Type (Typ) then
5933 Id := RE_Type_Class_Array;
5935 elsif Is_Record_Type (Typ) then
5936 Id := RE_Type_Class_Record;
5938 elsif Is_Access_Type (Typ) then
5939 Id := RE_Type_Class_Access;
5941 elsif Is_Enumeration_Type (Typ) then
5942 Id := RE_Type_Class_Enumeration;
5944 elsif Is_Task_Type (Typ) then
5945 Id := RE_Type_Class_Task;
5947 -- We treat protected types like task types. It would make more
5948 -- sense to have another enumeration value, but after all the
5949 -- whole point of this feature is to be exactly DEC compatible,
5950 -- and changing the type Type_Clas would not meet this requirement.
5952 elsif Is_Protected_Type (Typ) then
5953 Id := RE_Type_Class_Task;
5955 -- Not clear if there are any other possibilities, but if there
5956 -- are, then we will treat them as the address case.
5959 Id := RE_Type_Class_Address;
5962 Rewrite (N, New_Occurrence_Of (RTE (Id), Loc));
5966 -----------------------
5967 -- Unbiased_Rounding --
5968 -----------------------
5970 when Attribute_Unbiased_Rounding =>
5972 Eval_Fat.Unbiased_Rounding (P_Root_Type, Expr_Value_R (E1)),
5975 -------------------------
5976 -- Unconstrained_Array --
5977 -------------------------
5979 when Attribute_Unconstrained_Array => Unconstrained_Array : declare
5980 Typ : constant Entity_Id := Underlying_Type (P_Type);
5983 Rewrite (N, New_Occurrence_Of (
5985 Is_Array_Type (P_Type)
5986 and then not Is_Constrained (Typ)), Loc));
5988 -- Analyze and resolve as boolean, note that this attribute is
5989 -- a static attribute in GNAT.
5991 Analyze_And_Resolve (N, Standard_Boolean);
5993 end Unconstrained_Array;
5999 -- Processing is shared with Size
6005 when Attribute_Val => Val :
6007 if Expr_Value (E1) < Expr_Value (Type_Low_Bound (P_Base_Type))
6009 Expr_Value (E1) > Expr_Value (Type_High_Bound (P_Base_Type))
6011 Apply_Compile_Time_Constraint_Error
6012 (N, "Val expression out of range",
6013 CE_Range_Check_Failed,
6014 Warn => not Static);
6020 Fold_Uint (N, Expr_Value (E1), Static);
6028 -- The Value_Size attribute for a type returns the RM size of the
6029 -- type. This an always be folded for scalar types, and can also
6030 -- be folded for non-scalar types if the size is set.
6032 when Attribute_Value_Size => Value_Size : declare
6033 P_TypeA : constant Entity_Id := Underlying_Type (P_Type);
6036 if RM_Size (P_TypeA) /= Uint_0 then
6037 Fold_Uint (N, RM_Size (P_TypeA), True);
6046 -- Version can never be static
6048 when Attribute_Version =>
6055 -- Wide_Image is a scalar attribute, but is never static, because it
6056 -- is not a static function (having a non-scalar argument (RM 4.9(22))
6058 when Attribute_Wide_Image =>
6065 -- Processing for Wide_Width is combined with Width
6071 -- This processing also handles the case of Wide_Width
6073 when Attribute_Width | Attribute_Wide_Width => Width :
6075 if Compile_Time_Known_Bounds (P_Type) then
6077 -- Floating-point types
6079 if Is_Floating_Point_Type (P_Type) then
6081 -- Width is zero for a null range (RM 3.5 (38))
6083 if Expr_Value_R (Type_High_Bound (P_Type)) <
6084 Expr_Value_R (Type_Low_Bound (P_Type))
6086 Fold_Uint (N, Uint_0, True);
6089 -- For floating-point, we have +N.dddE+nnn where length
6090 -- of ddd is determined by type'Digits - 1, but is one
6091 -- if Digits is one (RM 3.5 (33)).
6093 -- nnn is set to 2 for Short_Float and Float (32 bit
6094 -- floats), and 3 for Long_Float and Long_Long_Float.
6095 -- This is not quite right, but is good enough.
6099 Int'Max (2, UI_To_Int (Digits_Value (P_Type)));
6102 if Esize (P_Type) <= 32 then
6108 Fold_Uint (N, UI_From_Int (Len), True);
6112 -- Fixed-point types
6114 elsif Is_Fixed_Point_Type (P_Type) then
6116 -- Width is zero for a null range (RM 3.5 (38))
6118 if Expr_Value (Type_High_Bound (P_Type)) <
6119 Expr_Value (Type_Low_Bound (P_Type))
6121 Fold_Uint (N, Uint_0, True);
6123 -- The non-null case depends on the specific real type
6126 -- For fixed-point type width is Fore + 1 + Aft (RM 3.5(34))
6129 (N, UI_From_Int (Fore_Value + 1 + Aft_Value), True);
6136 R : constant Entity_Id := Root_Type (P_Type);
6137 Lo : constant Uint :=
6138 Expr_Value (Type_Low_Bound (P_Type));
6139 Hi : constant Uint :=
6140 Expr_Value (Type_High_Bound (P_Type));
6153 -- Width for types derived from Standard.Character
6154 -- and Standard.Wide_Character.
6156 elsif R = Standard_Character
6157 or else R = Standard_Wide_Character
6161 -- Set W larger if needed
6163 for J in UI_To_Int (Lo) .. UI_To_Int (Hi) loop
6165 -- Assume all wide-character escape sequences are
6166 -- same length, so we can quit when we reach one.
6169 if Id = Attribute_Wide_Width then
6170 W := Int'Max (W, 3);
6173 W := Int'Max (W, Length_Wide);
6178 C := Character'Val (J);
6180 -- Test for all cases where Character'Image
6181 -- yields an image that is longer than three
6182 -- characters. First the cases of Reserved_xxx
6183 -- names (length = 12).
6186 when Reserved_128 | Reserved_129 |
6187 Reserved_132 | Reserved_153
6191 when BS | HT | LF | VT | FF | CR |
6192 SO | SI | EM | FS | GS | RS |
6193 US | RI | MW | ST | PM
6197 when NUL | SOH | STX | ETX | EOT |
6198 ENQ | ACK | BEL | DLE | DC1 |
6199 DC2 | DC3 | DC4 | NAK | SYN |
6200 ETB | CAN | SUB | ESC | DEL |
6201 BPH | NBH | NEL | SSA | ESA |
6202 HTS | HTJ | VTS | PLD | PLU |
6203 SS2 | SS3 | DCS | PU1 | PU2 |
6204 STS | CCH | SPA | EPA | SOS |
6205 SCI | CSI | OSC | APC
6209 when Space .. Tilde |
6210 No_Break_Space .. LC_Y_Diaeresis
6215 W := Int'Max (W, Wt);
6219 -- Width for types derived from Standard.Boolean
6221 elsif R = Standard_Boolean then
6228 -- Width for integer types
6230 elsif Is_Integer_Type (P_Type) then
6231 T := UI_Max (abs Lo, abs Hi);
6239 -- Only remaining possibility is user declared enum type
6242 pragma Assert (Is_Enumeration_Type (P_Type));
6245 L := First_Literal (P_Type);
6247 while Present (L) loop
6249 -- Only pay attention to in range characters
6251 if Lo <= Enumeration_Pos (L)
6252 and then Enumeration_Pos (L) <= Hi
6254 -- For Width case, use decoded name
6256 if Id = Attribute_Width then
6257 Get_Decoded_Name_String (Chars (L));
6258 Wt := Nat (Name_Len);
6260 -- For Wide_Width, use encoded name, and then
6261 -- adjust for the encoding.
6264 Get_Name_String (Chars (L));
6266 -- Character literals are always of length 3
6268 if Name_Buffer (1) = 'Q' then
6271 -- Otherwise loop to adjust for upper/wide chars
6274 Wt := Nat (Name_Len);
6276 for J in 1 .. Name_Len loop
6277 if Name_Buffer (J) = 'U' then
6279 elsif Name_Buffer (J) = 'W' then
6286 W := Int'Max (W, Wt);
6293 Fold_Uint (N, UI_From_Int (W), True);
6299 -- The following attributes can never be folded, and furthermore we
6300 -- should not even have entered the case statement for any of these.
6301 -- Note that in some cases, the values have already been folded as
6302 -- a result of the processing in Analyze_Attribute.
6304 when Attribute_Abort_Signal |
6307 Attribute_Address_Size |
6308 Attribute_Asm_Input |
6309 Attribute_Asm_Output |
6311 Attribute_Bit_Order |
6312 Attribute_Bit_Position |
6313 Attribute_Callable |
6316 Attribute_Code_Address |
6318 Attribute_Default_Bit_Order |
6319 Attribute_Elaborated |
6320 Attribute_Elab_Body |
6321 Attribute_Elab_Spec |
6322 Attribute_External_Tag |
6323 Attribute_First_Bit |
6325 Attribute_Last_Bit |
6326 Attribute_Maximum_Alignment |
6328 Attribute_Partition_ID |
6329 Attribute_Pool_Address |
6330 Attribute_Position |
6332 Attribute_Storage_Pool |
6333 Attribute_Storage_Size |
6334 Attribute_Storage_Unit |
6336 Attribute_Target_Name |
6337 Attribute_Terminated |
6338 Attribute_To_Address |
6339 Attribute_UET_Address |
6340 Attribute_Unchecked_Access |
6341 Attribute_Universal_Literal_String |
6342 Attribute_Unrestricted_Access |
6345 Attribute_Wchar_T_Size |
6346 Attribute_Wide_Value |
6347 Attribute_Word_Size |
6350 raise Program_Error;
6354 -- At the end of the case, one more check. If we did a static evaluation
6355 -- so that the result is now a literal, then set Is_Static_Expression
6356 -- in the constant only if the prefix type is a static subtype. For
6357 -- non-static subtypes, the folding is still OK, but not static.
6359 -- An exception is the GNAT attribute Constrained_Array which is
6360 -- defined to be a static attribute in all cases.
6362 if Nkind (N) = N_Integer_Literal
6363 or else Nkind (N) = N_Real_Literal
6364 or else Nkind (N) = N_Character_Literal
6365 or else Nkind (N) = N_String_Literal
6366 or else (Is_Entity_Name (N)
6367 and then Ekind (Entity (N)) = E_Enumeration_Literal)
6369 Set_Is_Static_Expression (N, Static);
6371 -- If this is still an attribute reference, then it has not been folded
6372 -- and that means that its expressions are in a non-static context.
6374 elsif Nkind (N) = N_Attribute_Reference then
6377 -- Note: the else case not covered here are odd cases where the
6378 -- processing has transformed the attribute into something other
6379 -- than a constant. Nothing more to do in such cases.
6387 ------------------------------
6388 -- Is_Anonymous_Tagged_Base --
6389 ------------------------------
6391 function Is_Anonymous_Tagged_Base
6398 Anon = Current_Scope
6399 and then Is_Itype (Anon)
6400 and then Associated_Node_For_Itype (Anon) = Parent (Typ);
6401 end Is_Anonymous_Tagged_Base;
6403 -----------------------
6404 -- Resolve_Attribute --
6405 -----------------------
6407 procedure Resolve_Attribute (N : Node_Id; Typ : Entity_Id) is
6408 Loc : constant Source_Ptr := Sloc (N);
6409 P : constant Node_Id := Prefix (N);
6410 Aname : constant Name_Id := Attribute_Name (N);
6411 Attr_Id : constant Attribute_Id := Get_Attribute_Id (Aname);
6412 Btyp : constant Entity_Id := Base_Type (Typ);
6413 Index : Interp_Index;
6415 Nom_Subt : Entity_Id;
6418 -- If error during analysis, no point in continuing, except for
6419 -- array types, where we get better recovery by using unconstrained
6420 -- indices than nothing at all (see Check_Array_Type).
6423 and then Attr_Id /= Attribute_First
6424 and then Attr_Id /= Attribute_Last
6425 and then Attr_Id /= Attribute_Length
6426 and then Attr_Id /= Attribute_Range
6431 -- If attribute was universal type, reset to actual type
6433 if Etype (N) = Universal_Integer
6434 or else Etype (N) = Universal_Real
6439 -- Remaining processing depends on attribute
6447 -- For access attributes, if the prefix denotes an entity, it is
6448 -- interpreted as a name, never as a call. It may be overloaded,
6449 -- in which case resolution uses the profile of the context type.
6450 -- Otherwise prefix must be resolved.
6452 when Attribute_Access
6453 | Attribute_Unchecked_Access
6454 | Attribute_Unrestricted_Access =>
6456 if Is_Variable (P) then
6457 Note_Possible_Modification (P);
6460 if Is_Entity_Name (P) then
6461 if Is_Overloaded (P) then
6462 Get_First_Interp (P, Index, It);
6464 while Present (It.Nam) loop
6466 if Type_Conformant (Designated_Type (Typ), It.Nam) then
6467 Set_Entity (P, It.Nam);
6469 -- The prefix is definitely NOT overloaded anymore
6470 -- at this point, so we reset the Is_Overloaded
6471 -- flag to avoid any confusion when reanalyzing
6474 Set_Is_Overloaded (P, False);
6475 Generate_Reference (Entity (P), P);
6479 Get_Next_Interp (Index, It);
6482 -- If it is a subprogram name or a type, there is nothing
6485 elsif not Is_Overloadable (Entity (P))
6486 and then not Is_Type (Entity (P))
6491 Error_Msg_Name_1 := Aname;
6493 if not Is_Entity_Name (P) then
6496 elsif Is_Abstract (Entity (P))
6497 and then Is_Overloadable (Entity (P))
6499 Error_Msg_N ("prefix of % attribute cannot be abstract", P);
6500 Set_Etype (N, Any_Type);
6502 elsif Convention (Entity (P)) = Convention_Intrinsic then
6503 if Ekind (Entity (P)) = E_Enumeration_Literal then
6505 ("prefix of % attribute cannot be enumeration literal",
6509 ("prefix of % attribute cannot be intrinsic", P);
6512 Set_Etype (N, Any_Type);
6514 elsif Is_Thread_Body (Entity (P)) then
6516 ("prefix of % attribute cannot be a thread body", P);
6519 -- Assignments, return statements, components of aggregates,
6520 -- generic instantiations will require convention checks if
6521 -- the type is an access to subprogram. Given that there will
6522 -- also be accessibility checks on those, this is where the
6523 -- checks can eventually be centralized ???
6525 if Ekind (Btyp) = E_Access_Subprogram_Type
6527 Ekind (Btyp) = E_Anonymous_Access_Subprogram_Type
6529 Ekind (Btyp) = E_Anonymous_Access_Protected_Subprogram_Type
6531 if Convention (Btyp) /= Convention (Entity (P)) then
6533 ("subprogram has invalid convention for context", P);
6536 Check_Subtype_Conformant
6537 (New_Id => Entity (P),
6538 Old_Id => Designated_Type (Btyp),
6542 if Attr_Id = Attribute_Unchecked_Access then
6543 Error_Msg_Name_1 := Aname;
6545 ("attribute% cannot be applied to a subprogram", P);
6547 elsif Aname = Name_Unrestricted_Access then
6548 null; -- Nothing to check
6550 -- Check the static accessibility rule of 3.10.2(32)
6551 -- In an instance body, if subprogram and type are both
6552 -- local, other rules prevent dangling references, and no
6553 -- warning is needed.
6555 elsif Attr_Id = Attribute_Access
6556 and then Subprogram_Access_Level (Entity (P)) >
6557 Type_Access_Level (Btyp)
6558 and then Ekind (Btyp) /=
6559 E_Anonymous_Access_Subprogram_Type
6560 and then Ekind (Btyp) /=
6561 E_Anonymous_Access_Protected_Subprogram_Type
6563 if not In_Instance_Body then
6565 ("subprogram must not be deeper than access type",
6568 elsif Scope (Entity (P)) /= Scope (Btyp) then
6570 ("subprogram must not be deeper than access type?",
6573 ("Constraint_Error will be raised ?", P);
6574 Set_Raises_Constraint_Error (N);
6577 -- Check the restriction of 3.10.2(32) that disallows
6578 -- the type of the access attribute to be declared
6579 -- outside a generic body when the subprogram is declared
6580 -- within that generic body.
6582 elsif Present (Enclosing_Generic_Body (Entity (P)))
6583 and then Enclosing_Generic_Body (Entity (P)) /=
6584 Enclosing_Generic_Body (Btyp)
6587 ("access type must not be outside generic body", P);
6591 -- If this is a renaming, an inherited operation, or a
6592 -- subprogram instance, use the original entity.
6594 if Is_Entity_Name (P)
6595 and then Is_Overloadable (Entity (P))
6596 and then Present (Alias (Entity (P)))
6599 New_Occurrence_Of (Alias (Entity (P)), Sloc (P)));
6602 elsif Nkind (P) = N_Selected_Component
6603 and then Is_Overloadable (Entity (Selector_Name (P)))
6605 -- Protected operation. If operation is overloaded, must
6606 -- disambiguate. Prefix that denotes protected object itself
6607 -- is resolved with its own type.
6609 if Attr_Id = Attribute_Unchecked_Access then
6610 Error_Msg_Name_1 := Aname;
6612 ("attribute% cannot be applied to protected operation", P);
6615 Resolve (Prefix (P));
6616 Generate_Reference (Entity (Selector_Name (P)), P);
6618 elsif Is_Overloaded (P) then
6620 -- Use the designated type of the context to disambiguate
6623 Index : Interp_Index;
6626 Get_First_Interp (P, Index, It);
6628 while Present (It.Typ) loop
6629 if Covers (Designated_Type (Typ), It.Typ) then
6630 Resolve (P, It.Typ);
6634 Get_Next_Interp (Index, It);
6641 -- X'Access is illegal if X denotes a constant and the access
6642 -- type is access-to-variable. Same for 'Unchecked_Access.
6643 -- The rule does not apply to 'Unrestricted_Access.
6645 if not (Ekind (Btyp) = E_Access_Subprogram_Type
6646 or else Ekind (Btyp) = E_Anonymous_Access_Subprogram_Type
6647 or else (Is_Record_Type (Btyp) and then
6648 Present (Corresponding_Remote_Type (Btyp)))
6649 or else Ekind (Btyp) = E_Access_Protected_Subprogram_Type
6650 or else Ekind (Btyp)
6651 = E_Anonymous_Access_Protected_Subprogram_Type
6652 or else Is_Access_Constant (Btyp)
6653 or else Is_Variable (P)
6654 or else Attr_Id = Attribute_Unrestricted_Access)
6656 if Comes_From_Source (N) then
6657 Error_Msg_N ("access-to-variable designates constant", P);
6661 if (Attr_Id = Attribute_Access
6663 Attr_Id = Attribute_Unchecked_Access)
6664 and then (Ekind (Btyp) = E_General_Access_Type
6665 or else Ekind (Btyp) = E_Anonymous_Access_Type)
6667 -- Ada 2005 (AI-230): Check the accessibility of anonymous
6668 -- access types in record and array components. For a
6669 -- component definition the level is the same of the
6670 -- enclosing composite type.
6672 if Ada_Version >= Ada_05
6673 and then Ekind (Btyp) = E_Anonymous_Access_Type
6674 and then (Is_Array_Type (Scope (Btyp))
6675 or else Ekind (Scope (Btyp)) = E_Record_Type)
6676 and then Object_Access_Level (P) > Type_Access_Level (Btyp)
6678 -- In an instance, this is a runtime check, but one we
6679 -- know will fail, so generate an appropriate warning.
6681 if In_Instance_Body then
6683 ("?non-local pointer cannot point to local object", P);
6685 ("?Program_Error will be raised at run time", P);
6687 Make_Raise_Program_Error (Loc,
6688 Reason => PE_Accessibility_Check_Failed));
6692 ("non-local pointer cannot point to local object", P);
6696 if Is_Dependent_Component_Of_Mutable_Object (P) then
6698 ("illegal attribute for discriminant-dependent component",
6702 -- Check the static matching rule of 3.10.2(27). The
6703 -- nominal subtype of the prefix must statically
6704 -- match the designated type.
6706 Nom_Subt := Etype (P);
6708 if Is_Constr_Subt_For_U_Nominal (Nom_Subt) then
6709 Nom_Subt := Etype (Nom_Subt);
6712 if Is_Tagged_Type (Designated_Type (Typ)) then
6714 -- If the attribute is in the context of an access
6715 -- parameter, then the prefix is allowed to be of
6716 -- the class-wide type (by AI-127).
6718 if Ekind (Typ) = E_Anonymous_Access_Type then
6719 if not Covers (Designated_Type (Typ), Nom_Subt)
6720 and then not Covers (Nom_Subt, Designated_Type (Typ))
6726 Desig := Designated_Type (Typ);
6728 if Is_Class_Wide_Type (Desig) then
6729 Desig := Etype (Desig);
6732 if Is_Anonymous_Tagged_Base (Nom_Subt, Desig) then
6737 ("type of prefix: & not compatible",
6740 ("\with &, the expected designated type",
6741 P, Designated_Type (Typ));
6746 elsif not Covers (Designated_Type (Typ), Nom_Subt)
6748 (not Is_Class_Wide_Type (Designated_Type (Typ))
6749 and then Is_Class_Wide_Type (Nom_Subt))
6752 ("type of prefix: & is not covered", P, Nom_Subt);
6754 ("\by &, the expected designated type" &
6755 " ('R'M 3.10.2 (27))", P, Designated_Type (Typ));
6758 if Is_Class_Wide_Type (Designated_Type (Typ))
6759 and then Has_Discriminants (Etype (Designated_Type (Typ)))
6760 and then Is_Constrained (Etype (Designated_Type (Typ)))
6761 and then Designated_Type (Typ) /= Nom_Subt
6763 Apply_Discriminant_Check
6764 (N, Etype (Designated_Type (Typ)));
6767 elsif not Subtypes_Statically_Match
6768 (Designated_Type (Base_Type (Typ)), Nom_Subt)
6770 not (Has_Discriminants (Designated_Type (Typ))
6773 (Designated_Type (Base_Type (Typ))))
6776 ("object subtype must statically match "
6777 & "designated subtype", P);
6779 if Is_Entity_Name (P)
6780 and then Is_Array_Type (Designated_Type (Typ))
6784 D : constant Node_Id := Declaration_Node (Entity (P));
6787 Error_Msg_N ("aliased object has explicit bounds?",
6789 Error_Msg_N ("\declare without bounds"
6790 & " (and with explicit initialization)?", D);
6791 Error_Msg_N ("\for use with unconstrained access?", D);
6796 -- Check the static accessibility rule of 3.10.2(28).
6797 -- Note that this check is not performed for the
6798 -- case of an anonymous access type, since the access
6799 -- attribute is always legal in such a context.
6801 if Attr_Id /= Attribute_Unchecked_Access
6802 and then Object_Access_Level (P) > Type_Access_Level (Btyp)
6803 and then Ekind (Btyp) = E_General_Access_Type
6805 -- In an instance, this is a runtime check, but one we
6806 -- know will fail, so generate an appropriate warning.
6808 if In_Instance_Body then
6810 ("?non-local pointer cannot point to local object", P);
6812 ("?Program_Error will be raised at run time", P);
6814 Make_Raise_Program_Error (Loc,
6815 Reason => PE_Accessibility_Check_Failed));
6821 ("non-local pointer cannot point to local object", P);
6823 if Is_Record_Type (Current_Scope)
6824 and then (Nkind (Parent (N)) =
6825 N_Discriminant_Association
6827 Nkind (Parent (N)) =
6828 N_Index_Or_Discriminant_Constraint)
6831 Indic : Node_Id := Parent (Parent (N));
6834 while Present (Indic)
6835 and then Nkind (Indic) /= N_Subtype_Indication
6837 Indic := Parent (Indic);
6840 if Present (Indic) then
6842 ("\use an access definition for" &
6843 " the access discriminant of&", N,
6844 Entity (Subtype_Mark (Indic)));
6852 if (Ekind (Btyp) = E_Access_Protected_Subprogram_Type
6854 Ekind (Btyp) = E_Anonymous_Access_Protected_Subprogram_Type)
6855 and then Is_Entity_Name (P)
6856 and then not Is_Protected_Type (Scope (Entity (P)))
6858 Error_Msg_N ("context requires a protected subprogram", P);
6860 elsif (Ekind (Btyp) = E_Access_Subprogram_Type
6862 Ekind (Btyp) = E_Anonymous_Access_Subprogram_Type)
6863 and then Ekind (Etype (N)) = E_Access_Protected_Subprogram_Type
6865 Error_Msg_N ("context requires a non-protected subprogram", P);
6868 -- The context cannot be a pool-specific type, but this is a
6869 -- legality rule, not a resolution rule, so it must be checked
6870 -- separately, after possibly disambiguation (see AI-245).
6872 if Ekind (Btyp) = E_Access_Type
6873 and then Attr_Id /= Attribute_Unrestricted_Access
6875 Wrong_Type (N, Typ);
6880 -- Check for incorrect atomic/volatile reference (RM C.6(12))
6882 if Attr_Id /= Attribute_Unrestricted_Access then
6883 if Is_Atomic_Object (P)
6884 and then not Is_Atomic (Designated_Type (Typ))
6887 ("access to atomic object cannot yield access-to-" &
6888 "non-atomic type", P);
6890 elsif Is_Volatile_Object (P)
6891 and then not Is_Volatile (Designated_Type (Typ))
6894 ("access to volatile object cannot yield access-to-" &
6895 "non-volatile type", P);
6903 -- Deal with resolving the type for Address attribute, overloading
6904 -- is not permitted here, since there is no context to resolve it.
6906 when Attribute_Address | Attribute_Code_Address =>
6908 -- To be safe, assume that if the address of a variable is taken,
6909 -- it may be modified via this address, so note modification.
6911 if Is_Variable (P) then
6912 Note_Possible_Modification (P);
6915 if Nkind (P) in N_Subexpr
6916 and then Is_Overloaded (P)
6918 Get_First_Interp (P, Index, It);
6919 Get_Next_Interp (Index, It);
6921 if Present (It.Nam) then
6922 Error_Msg_Name_1 := Aname;
6924 ("prefix of % attribute cannot be overloaded", N);
6929 if not Is_Entity_Name (P)
6930 or else not Is_Overloadable (Entity (P))
6932 if not Is_Task_Type (Etype (P))
6933 or else Nkind (P) = N_Explicit_Dereference
6939 -- If this is the name of a derived subprogram, or that of a
6940 -- generic actual, the address is that of the original entity.
6942 if Is_Entity_Name (P)
6943 and then Is_Overloadable (Entity (P))
6944 and then Present (Alias (Entity (P)))
6947 New_Occurrence_Of (Alias (Entity (P)), Sloc (P)));
6954 -- Prefix of the AST_Entry attribute is an entry name which must
6955 -- not be resolved, since this is definitely not an entry call.
6957 when Attribute_AST_Entry =>
6964 -- Prefix of Body_Version attribute can be a subprogram name which
6965 -- must not be resolved, since this is not a call.
6967 when Attribute_Body_Version =>
6974 -- Prefix of Caller attribute is an entry name which must not
6975 -- be resolved, since this is definitely not an entry call.
6977 when Attribute_Caller =>
6984 -- Shares processing with Address attribute
6990 -- If the prefix of the Count attribute is an entry name it must not
6991 -- be resolved, since this is definitely not an entry call. However,
6992 -- if it is an element of an entry family, the index itself may
6993 -- have to be resolved because it can be a general expression.
6995 when Attribute_Count =>
6996 if Nkind (P) = N_Indexed_Component
6997 and then Is_Entity_Name (Prefix (P))
7000 Indx : constant Node_Id := First (Expressions (P));
7001 Fam : constant Entity_Id := Entity (Prefix (P));
7003 Resolve (Indx, Entry_Index_Type (Fam));
7004 Apply_Range_Check (Indx, Entry_Index_Type (Fam));
7012 -- Prefix of the Elaborated attribute is a subprogram name which
7013 -- must not be resolved, since this is definitely not a call. Note
7014 -- that it is a library unit, so it cannot be overloaded here.
7016 when Attribute_Elaborated =>
7019 --------------------
7020 -- Mechanism_Code --
7021 --------------------
7023 -- Prefix of the Mechanism_Code attribute is a function name
7024 -- which must not be resolved. Should we check for overloaded ???
7026 when Attribute_Mechanism_Code =>
7033 -- Most processing is done in sem_dist, after determining the
7034 -- context type. Node is rewritten as a conversion to a runtime call.
7036 when Attribute_Partition_ID =>
7037 Process_Partition_Id (N);
7040 when Attribute_Pool_Address =>
7047 -- We replace the Range attribute node with a range expression
7048 -- whose bounds are the 'First and 'Last attributes applied to the
7049 -- same prefix. The reason that we do this transformation here
7050 -- instead of in the expander is that it simplifies other parts of
7051 -- the semantic analysis which assume that the Range has been
7052 -- replaced; thus it must be done even when in semantic-only mode
7053 -- (note that the RM specifically mentions this equivalence, we
7054 -- take care that the prefix is only evaluated once).
7056 when Attribute_Range => Range_Attribute :
7061 function Check_Discriminated_Prival
7064 -- The range of a private component constrained by a
7065 -- discriminant is rewritten to make the discriminant
7066 -- explicit. This solves some complex visibility problems
7067 -- related to the use of privals.
7069 --------------------------------
7070 -- Check_Discriminated_Prival --
7071 --------------------------------
7073 function Check_Discriminated_Prival
7078 if Is_Entity_Name (N)
7079 and then Ekind (Entity (N)) = E_In_Parameter
7080 and then not Within_Init_Proc
7082 return Make_Identifier (Sloc (N), Chars (Entity (N)));
7084 return Duplicate_Subexpr (N);
7086 end Check_Discriminated_Prival;
7088 -- Start of processing for Range_Attribute
7091 if not Is_Entity_Name (P)
7092 or else not Is_Type (Entity (P))
7097 -- Check whether prefix is (renaming of) private component
7098 -- of protected type.
7100 if Is_Entity_Name (P)
7101 and then Comes_From_Source (N)
7102 and then Is_Array_Type (Etype (P))
7103 and then Number_Dimensions (Etype (P)) = 1
7104 and then (Ekind (Scope (Entity (P))) = E_Protected_Type
7106 Ekind (Scope (Scope (Entity (P)))) =
7110 Check_Discriminated_Prival
7111 (Type_Low_Bound (Etype (First_Index (Etype (P)))));
7114 Check_Discriminated_Prival
7115 (Type_High_Bound (Etype (First_Index (Etype (P)))));
7119 Make_Attribute_Reference (Loc,
7120 Prefix => Duplicate_Subexpr (P),
7121 Attribute_Name => Name_Last,
7122 Expressions => Expressions (N));
7125 Make_Attribute_Reference (Loc,
7127 Attribute_Name => Name_First,
7128 Expressions => Expressions (N));
7131 -- If the original was marked as Must_Not_Freeze (see code
7132 -- in Sem_Ch3.Make_Index), then make sure the rewriting
7133 -- does not freeze either.
7135 if Must_Not_Freeze (N) then
7136 Set_Must_Not_Freeze (HB);
7137 Set_Must_Not_Freeze (LB);
7138 Set_Must_Not_Freeze (Prefix (HB));
7139 Set_Must_Not_Freeze (Prefix (LB));
7142 if Raises_Constraint_Error (Prefix (N)) then
7144 -- Preserve Sloc of prefix in the new bounds, so that
7145 -- the posted warning can be removed if we are within
7146 -- unreachable code.
7148 Set_Sloc (LB, Sloc (Prefix (N)));
7149 Set_Sloc (HB, Sloc (Prefix (N)));
7152 Rewrite (N, Make_Range (Loc, LB, HB));
7153 Analyze_And_Resolve (N, Typ);
7155 -- Normally after resolving attribute nodes, Eval_Attribute
7156 -- is called to do any possible static evaluation of the node.
7157 -- However, here since the Range attribute has just been
7158 -- transformed into a range expression it is no longer an
7159 -- attribute node and therefore the call needs to be avoided
7160 -- and is accomplished by simply returning from the procedure.
7163 end Range_Attribute;
7169 -- Prefix must not be resolved in this case, since it is not a
7170 -- real entity reference. No action of any kind is require!
7172 when Attribute_UET_Address =>
7175 ----------------------
7176 -- Unchecked_Access --
7177 ----------------------
7179 -- Processing is shared with Access
7181 -------------------------
7182 -- Unrestricted_Access --
7183 -------------------------
7185 -- Processing is shared with Access
7191 -- Apply range check. Note that we did not do this during the
7192 -- analysis phase, since we wanted Eval_Attribute to have a
7193 -- chance at finding an illegal out of range value.
7195 when Attribute_Val =>
7197 -- Note that we do our own Eval_Attribute call here rather than
7198 -- use the common one, because we need to do processing after
7199 -- the call, as per above comment.
7203 -- Eval_Attribute may replace the node with a raise CE, or
7204 -- fold it to a constant. Obviously we only apply a scalar
7205 -- range check if this did not happen!
7207 if Nkind (N) = N_Attribute_Reference
7208 and then Attribute_Name (N) = Name_Val
7210 Apply_Scalar_Range_Check (First (Expressions (N)), Btyp);
7219 -- Prefix of Version attribute can be a subprogram name which
7220 -- must not be resolved, since this is not a call.
7222 when Attribute_Version =>
7225 ----------------------
7226 -- Other Attributes --
7227 ----------------------
7229 -- For other attributes, resolve prefix unless it is a type. If
7230 -- the attribute reference itself is a type name ('Base and 'Class)
7231 -- then this is only legal within a task or protected record.
7234 if not Is_Entity_Name (P)
7235 or else not Is_Type (Entity (P))
7240 -- If the attribute reference itself is a type name ('Base,
7241 -- 'Class) then this is only legal within a task or protected
7242 -- record. What is this all about ???
7244 if Is_Entity_Name (N)
7245 and then Is_Type (Entity (N))
7247 if Is_Concurrent_Type (Entity (N))
7248 and then In_Open_Scopes (Entity (P))
7253 ("invalid use of subtype name in expression or call", N);
7257 -- For attributes whose argument may be a string, complete
7258 -- resolution of argument now. This avoids premature expansion
7259 -- (and the creation of transient scopes) before the attribute
7260 -- reference is resolved.
7263 when Attribute_Value =>
7264 Resolve (First (Expressions (N)), Standard_String);
7266 when Attribute_Wide_Value =>
7267 Resolve (First (Expressions (N)), Standard_Wide_String);
7269 when others => null;
7273 -- Normally the Freezing is done by Resolve but sometimes the Prefix
7274 -- is not resolved, in which case the freezing must be done now.
7276 Freeze_Expression (P);
7278 -- Finally perform static evaluation on the attribute reference
7281 end Resolve_Attribute;