1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2007, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Ada.Characters.Latin_1; use Ada.Characters.Latin_1;
29 with Atree; use Atree;
30 with Casing; use Casing;
31 with Checks; use Checks;
32 with Einfo; use Einfo;
33 with Errout; use Errout;
35 with Exp_Dist; use Exp_Dist;
36 with Exp_Util; use Exp_Util;
37 with Expander; use Expander;
38 with Freeze; use Freeze;
40 with Lib.Xref; use Lib.Xref;
41 with Nlists; use Nlists;
42 with Nmake; use Nmake;
44 with Restrict; use Restrict;
45 with Rident; use Rident;
46 with Rtsfind; use Rtsfind;
47 with Sdefault; use Sdefault;
49 with Sem_Cat; use Sem_Cat;
50 with Sem_Ch6; use Sem_Ch6;
51 with Sem_Ch8; use Sem_Ch8;
52 with Sem_Dist; use Sem_Dist;
53 with Sem_Eval; use Sem_Eval;
54 with Sem_Res; use Sem_Res;
55 with Sem_Type; use Sem_Type;
56 with Sem_Util; use Sem_Util;
57 with Stand; use Stand;
58 with Sinfo; use Sinfo;
59 with Sinput; use Sinput;
60 with Stringt; use Stringt;
62 with Stylesw; use Stylesw;
63 with Targparm; use Targparm;
64 with Ttypes; use Ttypes;
65 with Ttypef; use Ttypef;
66 with Tbuild; use Tbuild;
67 with Uintp; use Uintp;
68 with Urealp; use Urealp;
70 package body Sem_Attr is
72 True_Value : constant Uint := Uint_1;
73 False_Value : constant Uint := Uint_0;
74 -- Synonyms to be used when these constants are used as Boolean values
76 Bad_Attribute : exception;
77 -- Exception raised if an error is detected during attribute processing,
78 -- used so that we can abandon the processing so we don't run into
79 -- trouble with cascaded errors.
81 -- The following array is the list of attributes defined in the Ada 83 RM
82 -- that are not included in Ada 95, but still get recognized in GNAT.
84 Attribute_83 : constant Attribute_Class_Array := Attribute_Class_Array'(
90 Attribute_Constrained |
103 Attribute_Leading_Part |
105 Attribute_Machine_Emax |
106 Attribute_Machine_Emin |
107 Attribute_Machine_Mantissa |
108 Attribute_Machine_Overflows |
109 Attribute_Machine_Radix |
110 Attribute_Machine_Rounds |
116 Attribute_Safe_Emax |
117 Attribute_Safe_Large |
118 Attribute_Safe_Small |
121 Attribute_Storage_Size |
123 Attribute_Terminated |
126 Attribute_Width => True,
129 -- The following array is the list of attributes defined in the Ada 2005
130 -- RM which are not defined in Ada 95. These are recognized in Ada 95 mode,
131 -- but in Ada 95 they are considered to be implementation defined.
133 Attribute_05 : constant Attribute_Class_Array := Attribute_Class_Array'(
134 Attribute_Machine_Rounding |
136 Attribute_Stream_Size |
137 Attribute_Wide_Wide_Width => True,
140 -- The following array contains all attributes that imply a modification
141 -- of their prefixes or result in an access value. Such prefixes can be
142 -- considered as lvalues.
144 Attribute_Name_Implies_Lvalue_Prefix : constant Attribute_Class_Array :=
145 Attribute_Class_Array'(
150 Attribute_Unchecked_Access |
151 Attribute_Unrestricted_Access => True,
154 -----------------------
155 -- Local_Subprograms --
156 -----------------------
158 procedure Eval_Attribute (N : Node_Id);
159 -- Performs compile time evaluation of attributes where possible, leaving
160 -- the Is_Static_Expression/Raises_Constraint_Error flags appropriately
161 -- set, and replacing the node with a literal node if the value can be
162 -- computed at compile time. All static attribute references are folded,
163 -- as well as a number of cases of non-static attributes that can always
164 -- be computed at compile time (e.g. floating-point model attributes that
165 -- are applied to non-static subtypes). Of course in such cases, the
166 -- Is_Static_Expression flag will not be set on the resulting literal.
167 -- Note that the only required action of this procedure is to catch the
168 -- static expression cases as described in the RM. Folding of other cases
169 -- is done where convenient, but some additional non-static folding is in
170 -- N_Expand_Attribute_Reference in cases where this is more convenient.
172 function Is_Anonymous_Tagged_Base
176 -- For derived tagged types that constrain parent discriminants we build
177 -- an anonymous unconstrained base type. We need to recognize the relation
178 -- between the two when analyzing an access attribute for a constrained
179 -- component, before the full declaration for Typ has been analyzed, and
180 -- where therefore the prefix of the attribute does not match the enclosing
183 -----------------------
184 -- Analyze_Attribute --
185 -----------------------
187 procedure Analyze_Attribute (N : Node_Id) is
188 Loc : constant Source_Ptr := Sloc (N);
189 Aname : constant Name_Id := Attribute_Name (N);
190 P : constant Node_Id := Prefix (N);
191 Exprs : constant List_Id := Expressions (N);
192 Attr_Id : constant Attribute_Id := Get_Attribute_Id (Aname);
197 -- Type of prefix after analysis
199 P_Base_Type : Entity_Id;
200 -- Base type of prefix after analysis
202 -----------------------
203 -- Local Subprograms --
204 -----------------------
206 procedure Analyze_Access_Attribute;
207 -- Used for Access, Unchecked_Access, Unrestricted_Access attributes.
208 -- Internally, Id distinguishes which of the three cases is involved.
210 procedure Check_Array_Or_Scalar_Type;
211 -- Common procedure used by First, Last, Range attribute to check
212 -- that the prefix is a constrained array or scalar type, or a name
213 -- of an array object, and that an argument appears only if appropriate
214 -- (i.e. only in the array case).
216 procedure Check_Array_Type;
217 -- Common semantic checks for all array attributes. Checks that the
218 -- prefix is a constrained array type or the name of an array object.
219 -- The error message for non-arrays is specialized appropriately.
221 procedure Check_Asm_Attribute;
222 -- Common semantic checks for Asm_Input and Asm_Output attributes
224 procedure Check_Component;
225 -- Common processing for Bit_Position, First_Bit, Last_Bit, and
226 -- Position. Checks prefix is an appropriate selected component.
228 procedure Check_Decimal_Fixed_Point_Type;
229 -- Check that prefix of attribute N is a decimal fixed-point type
231 procedure Check_Dereference;
232 -- If the prefix of attribute is an object of an access type, then
233 -- introduce an explicit deference, and adjust P_Type accordingly.
235 procedure Check_Discrete_Type;
236 -- Verify that prefix of attribute N is a discrete type
239 -- Check that no attribute arguments are present
241 procedure Check_Either_E0_Or_E1;
242 -- Check that there are zero or one attribute arguments present
245 -- Check that exactly one attribute argument is present
248 -- Check that two attribute arguments are present
250 procedure Check_Enum_Image;
251 -- If the prefix type is an enumeration type, set all its literals
252 -- as referenced, since the image function could possibly end up
253 -- referencing any of the literals indirectly.
255 procedure Check_Fixed_Point_Type;
256 -- Verify that prefix of attribute N is a fixed type
258 procedure Check_Fixed_Point_Type_0;
259 -- Verify that prefix of attribute N is a fixed type and that
260 -- no attribute expressions are present
262 procedure Check_Floating_Point_Type;
263 -- Verify that prefix of attribute N is a float type
265 procedure Check_Floating_Point_Type_0;
266 -- Verify that prefix of attribute N is a float type and that
267 -- no attribute expressions are present
269 procedure Check_Floating_Point_Type_1;
270 -- Verify that prefix of attribute N is a float type and that
271 -- exactly one attribute expression is present
273 procedure Check_Floating_Point_Type_2;
274 -- Verify that prefix of attribute N is a float type and that
275 -- two attribute expressions are present
277 procedure Legal_Formal_Attribute;
278 -- Common processing for attributes Definite, Has_Access_Values,
279 -- and Has_Discriminants
281 procedure Check_Integer_Type;
282 -- Verify that prefix of attribute N is an integer type
284 procedure Check_Library_Unit;
285 -- Verify that prefix of attribute N is a library unit
287 procedure Check_Modular_Integer_Type;
288 -- Verify that prefix of attribute N is a modular integer type
290 procedure Check_Not_Incomplete_Type;
291 -- Check that P (the prefix of the attribute) is not an incomplete
292 -- type or a private type for which no full view has been given.
294 procedure Check_Object_Reference (P : Node_Id);
295 -- Check that P (the prefix of the attribute) is an object reference
297 procedure Check_Program_Unit;
298 -- Verify that prefix of attribute N is a program unit
300 procedure Check_Real_Type;
301 -- Verify that prefix of attribute N is fixed or float type
303 procedure Check_Scalar_Type;
304 -- Verify that prefix of attribute N is a scalar type
306 procedure Check_Standard_Prefix;
307 -- Verify that prefix of attribute N is package Standard
309 procedure Check_Stream_Attribute (Nam : TSS_Name_Type);
310 -- Validity checking for stream attribute. Nam is the TSS name of the
311 -- corresponding possible defined attribute function (e.g. for the
312 -- Read attribute, Nam will be TSS_Stream_Read).
314 procedure Check_Task_Prefix;
315 -- Verify that prefix of attribute N is a task or task type
317 procedure Check_Type;
318 -- Verify that the prefix of attribute N is a type
320 procedure Check_Unit_Name (Nod : Node_Id);
321 -- Check that Nod is of the form of a library unit name, i.e that
322 -- it is an identifier, or a selected component whose prefix is
323 -- itself of the form of a library unit name. Note that this is
324 -- quite different from Check_Program_Unit, since it only checks
325 -- the syntactic form of the name, not the semantic identity. This
326 -- is because it is used with attributes (Elab_Body, Elab_Spec, and
327 -- UET_Address) which can refer to non-visible unit.
329 procedure Error_Attr (Msg : String; Error_Node : Node_Id);
330 pragma No_Return (Error_Attr);
331 procedure Error_Attr;
332 pragma No_Return (Error_Attr);
333 -- Posts error using Error_Msg_N at given node, sets type of attribute
334 -- node to Any_Type, and then raises Bad_Attribute to avoid any further
335 -- semantic processing. The message typically contains a % insertion
336 -- character which is replaced by the attribute name. The call with
337 -- no arguments is used when the caller has already generated the
338 -- required error messages.
340 procedure Error_Attr_P (Msg : String);
341 pragma No_Return (Error_Attr);
342 -- Like Error_Attr, but error is posted at the start of the prefix
344 procedure Standard_Attribute (Val : Int);
345 -- Used to process attributes whose prefix is package Standard which
346 -- yield values of type Universal_Integer. The attribute reference
347 -- node is rewritten with an integer literal of the given value.
349 procedure Unexpected_Argument (En : Node_Id);
350 -- Signal unexpected attribute argument (En is the argument)
352 procedure Validate_Non_Static_Attribute_Function_Call;
353 -- Called when processing an attribute that is a function call to a
354 -- non-static function, i.e. an attribute function that either takes
355 -- non-scalar arguments or returns a non-scalar result. Verifies that
356 -- such a call does not appear in a preelaborable context.
358 ------------------------------
359 -- Analyze_Access_Attribute --
360 ------------------------------
362 procedure Analyze_Access_Attribute is
363 Acc_Type : Entity_Id;
368 function Build_Access_Object_Type (DT : Entity_Id) return Entity_Id;
369 -- Build an access-to-object type whose designated type is DT,
370 -- and whose Ekind is appropriate to the attribute type. The
371 -- type that is constructed is returned as the result.
373 procedure Build_Access_Subprogram_Type (P : Node_Id);
374 -- Build an access to subprogram whose designated type is
375 -- the type of the prefix. If prefix is overloaded, so it the
376 -- node itself. The result is stored in Acc_Type.
378 function OK_Self_Reference return Boolean;
379 -- An access reference whose prefix is a type can legally appear
380 -- within an aggregate, where it is obtained by expansion of
381 -- a defaulted aggregate. The enclosing aggregate that contains
382 -- the self-referenced is flagged so that the self-reference can
383 -- be expanded into a reference to the target object (see exp_aggr).
385 ------------------------------
386 -- Build_Access_Object_Type --
387 ------------------------------
389 function Build_Access_Object_Type (DT : Entity_Id) return Entity_Id is
390 Typ : constant Entity_Id :=
392 (E_Access_Attribute_Type, Current_Scope, Loc, 'A');
394 Set_Etype (Typ, Typ);
395 Init_Size_Align (Typ);
397 Set_Associated_Node_For_Itype (Typ, N);
398 Set_Directly_Designated_Type (Typ, DT);
400 end Build_Access_Object_Type;
402 ----------------------------------
403 -- Build_Access_Subprogram_Type --
404 ----------------------------------
406 procedure Build_Access_Subprogram_Type (P : Node_Id) is
407 Index : Interp_Index;
410 procedure Check_Local_Access (E : Entity_Id);
411 -- Deal with possible access to local subprogram. If we have such
412 -- an access, we set a flag to kill all tracked values on any call
413 -- because this access value may be passed around, and any called
414 -- code might use it to access a local procedure which clobbers a
417 function Get_Kind (E : Entity_Id) return Entity_Kind;
418 -- Distinguish between access to regular/protected subprograms
420 ------------------------
421 -- Check_Local_Access --
422 ------------------------
424 procedure Check_Local_Access (E : Entity_Id) is
426 if not Is_Library_Level_Entity (E) then
427 Set_Suppress_Value_Tracking_On_Call (Current_Scope);
429 end Check_Local_Access;
435 function Get_Kind (E : Entity_Id) return Entity_Kind is
437 if Convention (E) = Convention_Protected then
438 return E_Access_Protected_Subprogram_Type;
440 return E_Access_Subprogram_Type;
444 -- Start of processing for Build_Access_Subprogram_Type
447 -- In the case of an access to subprogram, use the name of the
448 -- subprogram itself as the designated type. Type-checking in
449 -- this case compares the signatures of the designated types.
451 Set_Etype (N, Any_Type);
453 if not Is_Overloaded (P) then
454 Check_Local_Access (Entity (P));
456 if not Is_Intrinsic_Subprogram (Entity (P)) then
459 (Get_Kind (Entity (P)), Current_Scope, Loc, 'A');
460 Set_Etype (Acc_Type, Acc_Type);
461 Set_Directly_Designated_Type (Acc_Type, Entity (P));
462 Set_Etype (N, Acc_Type);
466 Get_First_Interp (P, Index, It);
467 while Present (It.Nam) loop
468 Check_Local_Access (It.Nam);
470 if not Is_Intrinsic_Subprogram (It.Nam) then
473 (Get_Kind (It.Nam), Current_Scope, Loc, 'A');
474 Set_Etype (Acc_Type, Acc_Type);
475 Set_Directly_Designated_Type (Acc_Type, It.Nam);
476 Add_One_Interp (N, Acc_Type, Acc_Type);
479 Get_Next_Interp (Index, It);
483 -- Cannot be applied to intrinsic. Looking at the tests above,
484 -- the only way Etype (N) can still be set to Any_Type is if
485 -- Is_Intrinsic_Subprogram was True for some referenced entity.
487 if Etype (N) = Any_Type then
488 Error_Attr_P ("prefix of % attribute cannot be intrinsic");
490 end Build_Access_Subprogram_Type;
492 ----------------------
493 -- OK_Self_Reference --
494 ----------------------
496 function OK_Self_Reference return Boolean is
503 (Nkind (Par) = N_Component_Association
504 or else Nkind (Par) in N_Subexpr)
506 if Nkind (Par) = N_Aggregate
507 or else Nkind (Par) = N_Extension_Aggregate
509 if Etype (Par) = Typ then
510 Set_Has_Self_Reference (Par);
518 -- No enclosing aggregate, or not a self-reference
521 end OK_Self_Reference;
523 -- Start of processing for Analyze_Access_Attribute
528 if Nkind (P) = N_Character_Literal then
530 ("prefix of % attribute cannot be enumeration literal");
533 -- Case of access to subprogram
535 if Is_Entity_Name (P)
536 and then Is_Overloadable (Entity (P))
538 -- Not allowed for nested subprograms if No_Implicit_Dynamic_Code
539 -- restriction set (since in general a trampoline is required).
541 if not Is_Library_Level_Entity (Entity (P)) then
542 Check_Restriction (No_Implicit_Dynamic_Code, P);
545 if Is_Always_Inlined (Entity (P)) then
547 ("prefix of % attribute cannot be Inline_Always subprogram");
550 if Aname = Name_Unchecked_Access then
551 Error_Attr ("attribute% cannot be applied to a subprogram", P);
554 -- Build the appropriate subprogram type
556 Build_Access_Subprogram_Type (P);
558 -- For unrestricted access, kill current values, since this
559 -- attribute allows a reference to a local subprogram that
560 -- could modify local variables to be passed out of scope
562 if Aname = Name_Unrestricted_Access then
568 -- Component is an operation of a protected type
570 elsif Nkind (P) = N_Selected_Component
571 and then Is_Overloadable (Entity (Selector_Name (P)))
573 if Ekind (Entity (Selector_Name (P))) = E_Entry then
574 Error_Attr_P ("prefix of % attribute must be subprogram");
577 Build_Access_Subprogram_Type (Selector_Name (P));
581 -- Deal with incorrect reference to a type, but note that some
582 -- accesses are allowed: references to the current type instance,
583 -- or in Ada 2005 self-referential pointer in a default-initialized
586 if Is_Entity_Name (P) then
589 -- The reference may appear in an aggregate that has been expanded
590 -- into a loop. Locate scope of type definition, if any.
592 Scop := Current_Scope;
593 while Ekind (Scop) = E_Loop loop
594 Scop := Scope (Scop);
597 if Is_Type (Typ) then
599 -- OK if we are within the scope of a limited type
600 -- let's mark the component as having per object constraint
602 if Is_Anonymous_Tagged_Base (Scop, Typ) then
610 Q : Node_Id := Parent (N);
614 and then Nkind (Q) /= N_Component_Declaration
620 Set_Has_Per_Object_Constraint (
621 Defining_Identifier (Q), True);
625 if Nkind (P) = N_Expanded_Name then
627 ("current instance prefix must be a direct name", P);
630 -- If a current instance attribute appears within a
631 -- a component constraint it must appear alone; other
632 -- contexts (default expressions, within a task body)
633 -- are not subject to this restriction.
635 if not In_Default_Expression
636 and then not Has_Completion (Scop)
638 Nkind (Parent (N)) /= N_Discriminant_Association
640 Nkind (Parent (N)) /= N_Index_Or_Discriminant_Constraint
643 ("current instance attribute must appear alone", N);
646 -- OK if we are in initialization procedure for the type
647 -- in question, in which case the reference to the type
648 -- is rewritten as a reference to the current object.
650 elsif Ekind (Scop) = E_Procedure
651 and then Is_Init_Proc (Scop)
652 and then Etype (First_Formal (Scop)) = Typ
655 Make_Attribute_Reference (Loc,
656 Prefix => Make_Identifier (Loc, Name_uInit),
657 Attribute_Name => Name_Unrestricted_Access));
661 -- OK if a task type, this test needs sharpening up ???
663 elsif Is_Task_Type (Typ) then
666 -- OK if self-reference in an aggregate in Ada 2005, and
667 -- the reference comes from a copied default expression.
669 -- Note that we check legality of self-reference even if the
670 -- expression comes from source, e.g. when a single component
671 -- association in an aggregate has a box association.
673 elsif Ada_Version >= Ada_05
674 and then OK_Self_Reference
678 -- Otherwise we have an error case
681 Error_Attr ("% attribute cannot be applied to type", P);
687 -- If we fall through, we have a normal access to object case.
688 -- Unrestricted_Access is legal wherever an allocator would be
689 -- legal, so its Etype is set to E_Allocator. The expected type
690 -- of the other attributes is a general access type, and therefore
691 -- we label them with E_Access_Attribute_Type.
693 if not Is_Overloaded (P) then
694 Acc_Type := Build_Access_Object_Type (P_Type);
695 Set_Etype (N, Acc_Type);
698 Index : Interp_Index;
701 Set_Etype (N, Any_Type);
702 Get_First_Interp (P, Index, It);
703 while Present (It.Typ) loop
704 Acc_Type := Build_Access_Object_Type (It.Typ);
705 Add_One_Interp (N, Acc_Type, Acc_Type);
706 Get_Next_Interp (Index, It);
711 -- Special cases when prefix is entity name
713 if Is_Entity_Name (P) then
715 -- If we have an access to an object, and the attribute comes from
716 -- source, then set the object as potentially source modified. We
717 -- do this because the resulting access pointer can be used to
718 -- modify the variable, and we might not detect this, leading to
719 -- some junk warnings.
721 Set_Never_Set_In_Source (Entity (P), False);
723 -- Mark entity as address taken, and kill current values
725 Set_Address_Taken (Entity (P));
726 Kill_Current_Values (Entity (P));
729 -- Check for aliased view unless unrestricted case. We allow a
730 -- nonaliased prefix when within an instance because the prefix may
731 -- have been a tagged formal object, which is defined to be aliased
732 -- even when the actual might not be (other instance cases will have
733 -- been caught in the generic). Similarly, within an inlined body we
734 -- know that the attribute is legal in the original subprogram, and
735 -- therefore legal in the expansion.
737 if Aname /= Name_Unrestricted_Access
738 and then not Is_Aliased_View (P)
739 and then not In_Instance
740 and then not In_Inlined_Body
742 Error_Attr_P ("prefix of % attribute must be aliased");
744 end Analyze_Access_Attribute;
746 --------------------------------
747 -- Check_Array_Or_Scalar_Type --
748 --------------------------------
750 procedure Check_Array_Or_Scalar_Type is
754 -- Dimension number for array attributes
757 -- Case of string literal or string literal subtype. These cases
758 -- cannot arise from legal Ada code, but the expander is allowed
759 -- to generate them. They require special handling because string
760 -- literal subtypes do not have standard bounds (the whole idea
761 -- of these subtypes is to avoid having to generate the bounds)
763 if Ekind (P_Type) = E_String_Literal_Subtype then
764 Set_Etype (N, Etype (First_Index (P_Base_Type)));
769 elsif Is_Scalar_Type (P_Type) then
773 Error_Attr ("invalid argument in % attribute", E1);
775 Set_Etype (N, P_Base_Type);
779 -- The following is a special test to allow 'First to apply to
780 -- private scalar types if the attribute comes from generated
781 -- code. This occurs in the case of Normalize_Scalars code.
783 elsif Is_Private_Type (P_Type)
784 and then Present (Full_View (P_Type))
785 and then Is_Scalar_Type (Full_View (P_Type))
786 and then not Comes_From_Source (N)
788 Set_Etype (N, Implementation_Base_Type (P_Type));
790 -- Array types other than string literal subtypes handled above
795 -- We know prefix is an array type, or the name of an array
796 -- object, and that the expression, if present, is static
797 -- and within the range of the dimensions of the type.
799 pragma Assert (Is_Array_Type (P_Type));
800 Index := First_Index (P_Base_Type);
804 -- First dimension assumed
806 Set_Etype (N, Base_Type (Etype (Index)));
809 D := UI_To_Int (Intval (E1));
811 for J in 1 .. D - 1 loop
815 Set_Etype (N, Base_Type (Etype (Index)));
816 Set_Etype (E1, Standard_Integer);
819 end Check_Array_Or_Scalar_Type;
821 ----------------------
822 -- Check_Array_Type --
823 ----------------------
825 procedure Check_Array_Type is
827 -- Dimension number for array attributes
830 -- If the type is a string literal type, then this must be generated
831 -- internally, and no further check is required on its legality.
833 if Ekind (P_Type) = E_String_Literal_Subtype then
836 -- If the type is a composite, it is an illegal aggregate, no point
839 elsif P_Type = Any_Composite then
843 -- Normal case of array type or subtype
845 Check_Either_E0_Or_E1;
848 if Is_Array_Type (P_Type) then
849 if not Is_Constrained (P_Type)
850 and then Is_Entity_Name (P)
851 and then Is_Type (Entity (P))
853 -- Note: we do not call Error_Attr here, since we prefer to
854 -- continue, using the relevant index type of the array,
855 -- even though it is unconstrained. This gives better error
856 -- recovery behavior.
858 Error_Msg_Name_1 := Aname;
860 ("prefix for % attribute must be constrained array", P);
863 D := Number_Dimensions (P_Type);
866 if Is_Private_Type (P_Type) then
867 Error_Attr_P ("prefix for % attribute may not be private type");
869 elsif Is_Access_Type (P_Type)
870 and then Is_Array_Type (Designated_Type (P_Type))
871 and then Is_Entity_Name (P)
872 and then Is_Type (Entity (P))
874 Error_Attr_P ("prefix of % attribute cannot be access type");
876 elsif Attr_Id = Attribute_First
878 Attr_Id = Attribute_Last
880 Error_Attr ("invalid prefix for % attribute", P);
883 Error_Attr_P ("prefix for % attribute must be array");
888 Resolve (E1, Any_Integer);
889 Set_Etype (E1, Standard_Integer);
891 if not Is_Static_Expression (E1)
892 or else Raises_Constraint_Error (E1)
895 ("expression for dimension must be static!", E1);
898 elsif UI_To_Int (Expr_Value (E1)) > D
899 or else UI_To_Int (Expr_Value (E1)) < 1
901 Error_Attr ("invalid dimension number for array type", E1);
905 if (Style_Check and Style_Check_Array_Attribute_Index)
906 and then Comes_From_Source (N)
908 Style.Check_Array_Attribute_Index (N, E1, D);
910 end Check_Array_Type;
912 -------------------------
913 -- Check_Asm_Attribute --
914 -------------------------
916 procedure Check_Asm_Attribute is
921 -- Check first argument is static string expression
923 Analyze_And_Resolve (E1, Standard_String);
925 if Etype (E1) = Any_Type then
928 elsif not Is_OK_Static_Expression (E1) then
930 ("constraint argument must be static string expression!", E1);
934 -- Check second argument is right type
936 Analyze_And_Resolve (E2, Entity (P));
938 -- Note: that is all we need to do, we don't need to check
939 -- that it appears in a correct context. The Ada type system
940 -- will do that for us.
942 end Check_Asm_Attribute;
944 ---------------------
945 -- Check_Component --
946 ---------------------
948 procedure Check_Component is
952 if Nkind (P) /= N_Selected_Component
954 (Ekind (Entity (Selector_Name (P))) /= E_Component
956 Ekind (Entity (Selector_Name (P))) /= E_Discriminant)
958 Error_Attr_P ("prefix for % attribute must be selected component");
962 ------------------------------------
963 -- Check_Decimal_Fixed_Point_Type --
964 ------------------------------------
966 procedure Check_Decimal_Fixed_Point_Type is
970 if not Is_Decimal_Fixed_Point_Type (P_Type) then
971 Error_Attr_P ("prefix of % attribute must be decimal type");
973 end Check_Decimal_Fixed_Point_Type;
975 -----------------------
976 -- Check_Dereference --
977 -----------------------
979 procedure Check_Dereference is
982 -- Case of a subtype mark
984 if Is_Entity_Name (P)
985 and then Is_Type (Entity (P))
990 -- Case of an expression
994 if Is_Access_Type (P_Type) then
996 -- If there is an implicit dereference, then we must freeze
997 -- the designated type of the access type, since the type of
998 -- the referenced array is this type (see AI95-00106).
1000 Freeze_Before (N, Designated_Type (P_Type));
1003 Make_Explicit_Dereference (Sloc (P),
1004 Prefix => Relocate_Node (P)));
1006 Analyze_And_Resolve (P);
1007 P_Type := Etype (P);
1009 if P_Type = Any_Type then
1010 raise Bad_Attribute;
1013 P_Base_Type := Base_Type (P_Type);
1015 end Check_Dereference;
1017 -------------------------
1018 -- Check_Discrete_Type --
1019 -------------------------
1021 procedure Check_Discrete_Type is
1025 if not Is_Discrete_Type (P_Type) then
1026 Error_Attr_P ("prefix of % attribute must be discrete type");
1028 end Check_Discrete_Type;
1034 procedure Check_E0 is
1036 if Present (E1) then
1037 Unexpected_Argument (E1);
1045 procedure Check_E1 is
1047 Check_Either_E0_Or_E1;
1051 -- Special-case attributes that are functions and that appear as
1052 -- the prefix of another attribute. Error is posted on parent.
1054 if Nkind (Parent (N)) = N_Attribute_Reference
1055 and then (Attribute_Name (Parent (N)) = Name_Address
1057 Attribute_Name (Parent (N)) = Name_Code_Address
1059 Attribute_Name (Parent (N)) = Name_Access)
1061 Error_Msg_Name_1 := Attribute_Name (Parent (N));
1062 Error_Msg_N ("illegal prefix for % attribute", Parent (N));
1063 Set_Etype (Parent (N), Any_Type);
1064 Set_Entity (Parent (N), Any_Type);
1065 raise Bad_Attribute;
1068 Error_Attr ("missing argument for % attribute", N);
1077 procedure Check_E2 is
1080 Error_Attr ("missing arguments for % attribute (2 required)", N);
1082 Error_Attr ("missing argument for % attribute (2 required)", N);
1086 ---------------------------
1087 -- Check_Either_E0_Or_E1 --
1088 ---------------------------
1090 procedure Check_Either_E0_Or_E1 is
1092 if Present (E2) then
1093 Unexpected_Argument (E2);
1095 end Check_Either_E0_Or_E1;
1097 ----------------------
1098 -- Check_Enum_Image --
1099 ----------------------
1101 procedure Check_Enum_Image is
1104 if Is_Enumeration_Type (P_Base_Type) then
1105 Lit := First_Literal (P_Base_Type);
1106 while Present (Lit) loop
1107 Set_Referenced (Lit);
1111 end Check_Enum_Image;
1113 ----------------------------
1114 -- Check_Fixed_Point_Type --
1115 ----------------------------
1117 procedure Check_Fixed_Point_Type is
1121 if not Is_Fixed_Point_Type (P_Type) then
1122 Error_Attr_P ("prefix of % attribute must be fixed point type");
1124 end Check_Fixed_Point_Type;
1126 ------------------------------
1127 -- Check_Fixed_Point_Type_0 --
1128 ------------------------------
1130 procedure Check_Fixed_Point_Type_0 is
1132 Check_Fixed_Point_Type;
1134 end Check_Fixed_Point_Type_0;
1136 -------------------------------
1137 -- Check_Floating_Point_Type --
1138 -------------------------------
1140 procedure Check_Floating_Point_Type is
1144 if not Is_Floating_Point_Type (P_Type) then
1145 Error_Attr_P ("prefix of % attribute must be float type");
1147 end Check_Floating_Point_Type;
1149 ---------------------------------
1150 -- Check_Floating_Point_Type_0 --
1151 ---------------------------------
1153 procedure Check_Floating_Point_Type_0 is
1155 Check_Floating_Point_Type;
1157 end Check_Floating_Point_Type_0;
1159 ---------------------------------
1160 -- Check_Floating_Point_Type_1 --
1161 ---------------------------------
1163 procedure Check_Floating_Point_Type_1 is
1165 Check_Floating_Point_Type;
1167 end Check_Floating_Point_Type_1;
1169 ---------------------------------
1170 -- Check_Floating_Point_Type_2 --
1171 ---------------------------------
1173 procedure Check_Floating_Point_Type_2 is
1175 Check_Floating_Point_Type;
1177 end Check_Floating_Point_Type_2;
1179 ------------------------
1180 -- Check_Integer_Type --
1181 ------------------------
1183 procedure Check_Integer_Type is
1187 if not Is_Integer_Type (P_Type) then
1188 Error_Attr_P ("prefix of % attribute must be integer type");
1190 end Check_Integer_Type;
1192 ------------------------
1193 -- Check_Library_Unit --
1194 ------------------------
1196 procedure Check_Library_Unit is
1198 if not Is_Compilation_Unit (Entity (P)) then
1199 Error_Attr_P ("prefix of % attribute must be library unit");
1201 end Check_Library_Unit;
1203 --------------------------------
1204 -- Check_Modular_Integer_Type --
1205 --------------------------------
1207 procedure Check_Modular_Integer_Type is
1211 if not Is_Modular_Integer_Type (P_Type) then
1213 ("prefix of % attribute must be modular integer type");
1215 end Check_Modular_Integer_Type;
1217 -------------------------------
1218 -- Check_Not_Incomplete_Type --
1219 -------------------------------
1221 procedure Check_Not_Incomplete_Type is
1226 -- Ada 2005 (AI-50217, AI-326): If the prefix is an explicit
1227 -- dereference we have to check wrong uses of incomplete types
1228 -- (other wrong uses are checked at their freezing point).
1230 -- Example 1: Limited-with
1232 -- limited with Pkg;
1234 -- type Acc is access Pkg.T;
1236 -- S : Integer := X.all'Size; -- ERROR
1239 -- Example 2: Tagged incomplete
1241 -- type T is tagged;
1242 -- type Acc is access all T;
1244 -- S : constant Integer := X.all'Size; -- ERROR
1245 -- procedure Q (Obj : Integer := X.all'Alignment); -- ERROR
1247 if Ada_Version >= Ada_05
1248 and then Nkind (P) = N_Explicit_Dereference
1251 while Nkind (E) = N_Explicit_Dereference loop
1255 if From_With_Type (Etype (E)) then
1257 ("prefix of % attribute cannot be an incomplete type");
1260 if Is_Access_Type (Etype (E)) then
1261 Typ := Directly_Designated_Type (Etype (E));
1266 if Ekind (Typ) = E_Incomplete_Type
1267 and then No (Full_View (Typ))
1270 ("prefix of % attribute cannot be an incomplete type");
1275 if not Is_Entity_Name (P)
1276 or else not Is_Type (Entity (P))
1277 or else In_Default_Expression
1281 Check_Fully_Declared (P_Type, P);
1283 end Check_Not_Incomplete_Type;
1285 ----------------------------
1286 -- Check_Object_Reference --
1287 ----------------------------
1289 procedure Check_Object_Reference (P : Node_Id) is
1293 -- If we need an object, and we have a prefix that is the name of
1294 -- a function entity, convert it into a function call.
1296 if Is_Entity_Name (P)
1297 and then Ekind (Entity (P)) = E_Function
1299 Rtyp := Etype (Entity (P));
1302 Make_Function_Call (Sloc (P),
1303 Name => Relocate_Node (P)));
1305 Analyze_And_Resolve (P, Rtyp);
1307 -- Otherwise we must have an object reference
1309 elsif not Is_Object_Reference (P) then
1310 Error_Attr_P ("prefix of % attribute must be object");
1312 end Check_Object_Reference;
1314 ------------------------
1315 -- Check_Program_Unit --
1316 ------------------------
1318 procedure Check_Program_Unit is
1320 if Is_Entity_Name (P) then
1322 K : constant Entity_Kind := Ekind (Entity (P));
1323 T : constant Entity_Id := Etype (Entity (P));
1326 if K in Subprogram_Kind
1327 or else K in Task_Kind
1328 or else K in Protected_Kind
1329 or else K = E_Package
1330 or else K in Generic_Unit_Kind
1331 or else (K = E_Variable
1335 Is_Protected_Type (T)))
1342 Error_Attr_P ("prefix of % attribute must be program unit");
1343 end Check_Program_Unit;
1345 ---------------------
1346 -- Check_Real_Type --
1347 ---------------------
1349 procedure Check_Real_Type is
1353 if not Is_Real_Type (P_Type) then
1354 Error_Attr_P ("prefix of % attribute must be real type");
1356 end Check_Real_Type;
1358 -----------------------
1359 -- Check_Scalar_Type --
1360 -----------------------
1362 procedure Check_Scalar_Type is
1366 if not Is_Scalar_Type (P_Type) then
1367 Error_Attr_P ("prefix of % attribute must be scalar type");
1369 end Check_Scalar_Type;
1371 ---------------------------
1372 -- Check_Standard_Prefix --
1373 ---------------------------
1375 procedure Check_Standard_Prefix is
1379 if Nkind (P) /= N_Identifier
1380 or else Chars (P) /= Name_Standard
1382 Error_Attr ("only allowed prefix for % attribute is Standard", P);
1385 end Check_Standard_Prefix;
1387 ----------------------------
1388 -- Check_Stream_Attribute --
1389 ----------------------------
1391 procedure Check_Stream_Attribute (Nam : TSS_Name_Type) is
1396 Validate_Non_Static_Attribute_Function_Call;
1398 -- With the exception of 'Input, Stream attributes are procedures,
1399 -- and can only appear at the position of procedure calls. We check
1400 -- for this here, before they are rewritten, to give a more precise
1403 if Nam = TSS_Stream_Input then
1406 elsif Is_List_Member (N)
1407 and then Nkind (Parent (N)) /= N_Procedure_Call_Statement
1408 and then Nkind (Parent (N)) /= N_Aggregate
1414 ("invalid context for attribute%, which is a procedure", N);
1418 Btyp := Implementation_Base_Type (P_Type);
1420 -- Stream attributes not allowed on limited types unless the
1421 -- attribute reference was generated by the expander (in which
1422 -- case the underlying type will be used, as described in Sinfo),
1423 -- or the attribute was specified explicitly for the type itself
1424 -- or one of its ancestors (taking visibility rules into account if
1425 -- in Ada 2005 mode), or a pragma Stream_Convert applies to Btyp
1426 -- (with no visibility restriction).
1428 if Comes_From_Source (N)
1429 and then not Stream_Attribute_Available (P_Type, Nam)
1430 and then not Has_Rep_Pragma (Btyp, Name_Stream_Convert)
1432 Error_Msg_Name_1 := Aname;
1434 if Is_Limited_Type (P_Type) then
1436 ("limited type& has no% attribute", P, P_Type);
1437 Explain_Limited_Type (P_Type, P);
1440 ("attribute% for type& is not available", P, P_Type);
1444 -- Check for violation of restriction No_Stream_Attributes
1446 if Is_RTE (P_Type, RE_Exception_Id)
1448 Is_RTE (P_Type, RE_Exception_Occurrence)
1450 Check_Restriction (No_Exception_Registration, P);
1453 -- Here we must check that the first argument is an access type
1454 -- that is compatible with Ada.Streams.Root_Stream_Type'Class.
1456 Analyze_And_Resolve (E1);
1459 -- Note: the double call to Root_Type here is needed because the
1460 -- root type of a class-wide type is the corresponding type (e.g.
1461 -- X for X'Class, and we really want to go to the root.)
1463 if not Is_Access_Type (Etyp)
1464 or else Root_Type (Root_Type (Designated_Type (Etyp))) /=
1465 RTE (RE_Root_Stream_Type)
1468 ("expected access to Ada.Streams.Root_Stream_Type''Class", E1);
1471 -- Check that the second argument is of the right type if there is
1472 -- one (the Input attribute has only one argument so this is skipped)
1474 if Present (E2) then
1477 if Nam = TSS_Stream_Read
1478 and then not Is_OK_Variable_For_Out_Formal (E2)
1481 ("second argument of % attribute must be a variable", E2);
1484 Resolve (E2, P_Type);
1486 end Check_Stream_Attribute;
1488 -----------------------
1489 -- Check_Task_Prefix --
1490 -----------------------
1492 procedure Check_Task_Prefix is
1496 -- Ada 2005 (AI-345): Attribute 'Terminated can be applied to
1497 -- task interface class-wide types.
1499 if Is_Task_Type (Etype (P))
1500 or else (Is_Access_Type (Etype (P))
1501 and then Is_Task_Type (Designated_Type (Etype (P))))
1502 or else (Ada_Version >= Ada_05
1503 and then Ekind (Etype (P)) = E_Class_Wide_Type
1504 and then Is_Interface (Etype (P))
1505 and then Is_Task_Interface (Etype (P)))
1510 if Ada_Version >= Ada_05 then
1512 ("prefix of % attribute must be a task or a task " &
1513 "interface class-wide object");
1516 Error_Attr_P ("prefix of % attribute must be a task");
1519 end Check_Task_Prefix;
1525 -- The possibilities are an entity name denoting a type, or an
1526 -- attribute reference that denotes a type (Base or Class). If
1527 -- the type is incomplete, replace it with its full view.
1529 procedure Check_Type is
1531 if not Is_Entity_Name (P)
1532 or else not Is_Type (Entity (P))
1534 Error_Attr_P ("prefix of % attribute must be a type");
1536 elsif Ekind (Entity (P)) = E_Incomplete_Type
1537 and then Present (Full_View (Entity (P)))
1539 P_Type := Full_View (Entity (P));
1540 Set_Entity (P, P_Type);
1544 ---------------------
1545 -- Check_Unit_Name --
1546 ---------------------
1548 procedure Check_Unit_Name (Nod : Node_Id) is
1550 if Nkind (Nod) = N_Identifier then
1553 elsif Nkind (Nod) = N_Selected_Component then
1554 Check_Unit_Name (Prefix (Nod));
1556 if Nkind (Selector_Name (Nod)) = N_Identifier then
1561 Error_Attr ("argument for % attribute must be unit name", P);
1562 end Check_Unit_Name;
1568 procedure Error_Attr is
1570 Set_Etype (N, Any_Type);
1571 Set_Entity (N, Any_Type);
1572 raise Bad_Attribute;
1575 procedure Error_Attr (Msg : String; Error_Node : Node_Id) is
1577 Error_Msg_Name_1 := Aname;
1578 Error_Msg_N (Msg, Error_Node);
1586 procedure Error_Attr_P (Msg : String) is
1588 Error_Msg_Name_1 := Aname;
1589 Error_Msg_F (Msg, P);
1593 ----------------------------
1594 -- Legal_Formal_Attribute --
1595 ----------------------------
1597 procedure Legal_Formal_Attribute is
1601 if not Is_Entity_Name (P)
1602 or else not Is_Type (Entity (P))
1604 Error_Attr_P ("prefix of % attribute must be generic type");
1606 elsif Is_Generic_Actual_Type (Entity (P))
1608 or else In_Inlined_Body
1612 elsif Is_Generic_Type (Entity (P)) then
1613 if not Is_Indefinite_Subtype (Entity (P)) then
1615 ("prefix of % attribute must be indefinite generic type");
1620 ("prefix of % attribute must be indefinite generic type");
1623 Set_Etype (N, Standard_Boolean);
1624 end Legal_Formal_Attribute;
1626 ------------------------
1627 -- Standard_Attribute --
1628 ------------------------
1630 procedure Standard_Attribute (Val : Int) is
1632 Check_Standard_Prefix;
1633 Rewrite (N, Make_Integer_Literal (Loc, Val));
1635 end Standard_Attribute;
1637 -------------------------
1638 -- Unexpected Argument --
1639 -------------------------
1641 procedure Unexpected_Argument (En : Node_Id) is
1643 Error_Attr ("unexpected argument for % attribute", En);
1644 end Unexpected_Argument;
1646 -------------------------------------------------
1647 -- Validate_Non_Static_Attribute_Function_Call --
1648 -------------------------------------------------
1650 -- This function should be moved to Sem_Dist ???
1652 procedure Validate_Non_Static_Attribute_Function_Call is
1654 if In_Preelaborated_Unit
1655 and then not In_Subprogram_Or_Concurrent_Unit
1657 Flag_Non_Static_Expr
1658 ("non-static function call in preelaborated unit!", N);
1660 end Validate_Non_Static_Attribute_Function_Call;
1662 -----------------------------------------------
1663 -- Start of Processing for Analyze_Attribute --
1664 -----------------------------------------------
1667 -- Immediate return if unrecognized attribute (already diagnosed
1668 -- by parser, so there is nothing more that we need to do)
1670 if not Is_Attribute_Name (Aname) then
1671 raise Bad_Attribute;
1674 -- Deal with Ada 83 issues
1676 if Comes_From_Source (N) then
1677 if not Attribute_83 (Attr_Id) then
1678 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
1679 Error_Msg_Name_1 := Aname;
1680 Error_Msg_N ("(Ada 83) attribute% is not standard?", N);
1683 if Attribute_Impl_Def (Attr_Id) then
1684 Check_Restriction (No_Implementation_Attributes, N);
1689 -- Deal with Ada 2005 issues
1691 if Attribute_05 (Attr_Id) and then Ada_Version <= Ada_95 then
1692 Check_Restriction (No_Implementation_Attributes, N);
1695 -- Remote access to subprogram type access attribute reference needs
1696 -- unanalyzed copy for tree transformation. The analyzed copy is used
1697 -- for its semantic information (whether prefix is a remote subprogram
1698 -- name), the unanalyzed copy is used to construct new subtree rooted
1699 -- with N_Aggregate which represents a fat pointer aggregate.
1701 if Aname = Name_Access then
1702 Discard_Node (Copy_Separate_Tree (N));
1705 -- Analyze prefix and exit if error in analysis. If the prefix is an
1706 -- incomplete type, use full view if available. Note that there are
1707 -- some attributes for which we do not analyze the prefix, since the
1708 -- prefix is not a normal name.
1710 if Aname /= Name_Elab_Body
1712 Aname /= Name_Elab_Spec
1714 Aname /= Name_UET_Address
1716 Aname /= Name_Enabled
1719 P_Type := Etype (P);
1721 if Is_Entity_Name (P)
1722 and then Present (Entity (P))
1723 and then Is_Type (Entity (P))
1725 if Ekind (Entity (P)) = E_Incomplete_Type then
1726 P_Type := Get_Full_View (P_Type);
1727 Set_Entity (P, P_Type);
1728 Set_Etype (P, P_Type);
1730 elsif Entity (P) = Current_Scope
1731 and then Is_Record_Type (Entity (P))
1733 -- Use of current instance within the type. Verify that if the
1734 -- attribute appears within a constraint, it yields an access
1735 -- type, other uses are illegal.
1743 and then Nkind (Parent (Par)) /= N_Component_Definition
1745 Par := Parent (Par);
1749 and then Nkind (Par) = N_Subtype_Indication
1751 if Attr_Id /= Attribute_Access
1752 and then Attr_Id /= Attribute_Unchecked_Access
1753 and then Attr_Id /= Attribute_Unrestricted_Access
1756 ("in a constraint the current instance can only"
1757 & " be used with an access attribute", N);
1764 if P_Type = Any_Type then
1765 raise Bad_Attribute;
1768 P_Base_Type := Base_Type (P_Type);
1771 -- Analyze expressions that may be present, exiting if an error occurs
1778 E1 := First (Exprs);
1781 -- Check for missing/bad expression (result of previous error)
1783 if No (E1) or else Etype (E1) = Any_Type then
1784 raise Bad_Attribute;
1789 if Present (E2) then
1792 if Etype (E2) = Any_Type then
1793 raise Bad_Attribute;
1796 if Present (Next (E2)) then
1797 Unexpected_Argument (Next (E2));
1802 -- Ada 2005 (AI-345): Ensure that the compiler gives exactly the current
1803 -- output compiling in Ada 95 mode for the case of ambiguous prefixes.
1805 if Ada_Version < Ada_05
1806 and then Is_Overloaded (P)
1807 and then Aname /= Name_Access
1808 and then Aname /= Name_Address
1809 and then Aname /= Name_Code_Address
1810 and then Aname /= Name_Count
1811 and then Aname /= Name_Unchecked_Access
1813 Error_Attr ("ambiguous prefix for % attribute", P);
1815 elsif Ada_Version >= Ada_05
1816 and then Is_Overloaded (P)
1817 and then Aname /= Name_Access
1818 and then Aname /= Name_Address
1819 and then Aname /= Name_Code_Address
1820 and then Aname /= Name_Unchecked_Access
1822 -- Ada 2005 (AI-345): Since protected and task types have primitive
1823 -- entry wrappers, the attributes Count, Caller and AST_Entry require
1826 if Ada_Version >= Ada_05
1827 and then (Aname = Name_Count
1828 or else Aname = Name_Caller
1829 or else Aname = Name_AST_Entry)
1832 Count : Natural := 0;
1837 Get_First_Interp (P, I, It);
1838 while Present (It.Nam) loop
1839 if Comes_From_Source (It.Nam) then
1845 Get_Next_Interp (I, It);
1849 Error_Attr ("ambiguous prefix for % attribute", P);
1851 Set_Is_Overloaded (P, False);
1856 Error_Attr ("ambiguous prefix for % attribute", P);
1860 -- Remaining processing depends on attribute
1868 when Attribute_Abort_Signal =>
1869 Check_Standard_Prefix;
1871 New_Reference_To (Stand.Abort_Signal, Loc));
1878 when Attribute_Access =>
1879 Analyze_Access_Attribute;
1885 when Attribute_Address =>
1888 -- Check for some junk cases, where we have to allow the address
1889 -- attribute but it does not make much sense, so at least for now
1890 -- just replace with Null_Address.
1892 -- We also do this if the prefix is a reference to the AST_Entry
1893 -- attribute. If expansion is active, the attribute will be
1894 -- replaced by a function call, and address will work fine and
1895 -- get the proper value, but if expansion is not active, then
1896 -- the check here allows proper semantic analysis of the reference.
1898 -- An Address attribute created by expansion is legal even when it
1899 -- applies to other entity-denoting expressions.
1901 if Is_Entity_Name (P) then
1903 Ent : constant Entity_Id := Entity (P);
1906 if Is_Subprogram (Ent) then
1907 if not Is_Library_Level_Entity (Ent) then
1908 Check_Restriction (No_Implicit_Dynamic_Code, P);
1911 Set_Address_Taken (Ent);
1912 Kill_Current_Values (Ent);
1914 -- An Address attribute is accepted when generated by the
1915 -- compiler for dispatching operation, and an error is
1916 -- issued once the subprogram is frozen (to avoid confusing
1917 -- errors about implicit uses of Address in the dispatch
1918 -- table initialization).
1920 if Is_Always_Inlined (Entity (P))
1921 and then Comes_From_Source (P)
1924 ("prefix of % attribute cannot be Inline_Always" &
1928 elsif Is_Object (Ent)
1929 or else Ekind (Ent) = E_Label
1931 Set_Address_Taken (Ent);
1933 -- If we have an address of an object, and the attribute
1934 -- comes from source, then set the object as potentially
1935 -- source modified. We do this because the resulting address
1936 -- can potentially be used to modify the variable and we
1937 -- might not detect this, leading to some junk warnings.
1939 Set_Never_Set_In_Source (Ent, False);
1941 elsif (Is_Concurrent_Type (Etype (Ent))
1942 and then Etype (Ent) = Base_Type (Ent))
1943 or else Ekind (Ent) = E_Package
1944 or else Is_Generic_Unit (Ent)
1947 New_Occurrence_Of (RTE (RE_Null_Address), Sloc (N)));
1950 Error_Attr ("invalid prefix for % attribute", P);
1954 elsif Nkind (P) = N_Attribute_Reference
1955 and then Attribute_Name (P) = Name_AST_Entry
1958 New_Occurrence_Of (RTE (RE_Null_Address), Sloc (N)));
1960 elsif Is_Object_Reference (P) then
1963 elsif Nkind (P) = N_Selected_Component
1964 and then Is_Subprogram (Entity (Selector_Name (P)))
1968 -- What exactly are we allowing here ??? and is this properly
1969 -- documented in the sinfo documentation for this node ???
1971 elsif not Comes_From_Source (N) then
1975 Error_Attr ("invalid prefix for % attribute", P);
1978 Set_Etype (N, RTE (RE_Address));
1984 when Attribute_Address_Size =>
1985 Standard_Attribute (System_Address_Size);
1991 when Attribute_Adjacent =>
1992 Check_Floating_Point_Type_2;
1993 Set_Etype (N, P_Base_Type);
1994 Resolve (E1, P_Base_Type);
1995 Resolve (E2, P_Base_Type);
2001 when Attribute_Aft =>
2002 Check_Fixed_Point_Type_0;
2003 Set_Etype (N, Universal_Integer);
2009 when Attribute_Alignment =>
2011 -- Don't we need more checking here, cf Size ???
2014 Check_Not_Incomplete_Type;
2015 Set_Etype (N, Universal_Integer);
2021 when Attribute_Asm_Input =>
2022 Check_Asm_Attribute;
2023 Set_Etype (N, RTE (RE_Asm_Input_Operand));
2029 when Attribute_Asm_Output =>
2030 Check_Asm_Attribute;
2032 if Etype (E2) = Any_Type then
2035 elsif Aname = Name_Asm_Output then
2036 if not Is_Variable (E2) then
2038 ("second argument for Asm_Output is not variable", E2);
2042 Note_Possible_Modification (E2);
2043 Set_Etype (N, RTE (RE_Asm_Output_Operand));
2049 when Attribute_AST_Entry => AST_Entry : declare
2055 -- Indicates if entry family index is present. Note the coding
2056 -- here handles the entry family case, but in fact it cannot be
2057 -- executed currently, because pragma AST_Entry does not permit
2058 -- the specification of an entry family.
2060 procedure Bad_AST_Entry;
2061 -- Signal a bad AST_Entry pragma
2063 function OK_Entry (E : Entity_Id) return Boolean;
2064 -- Checks that E is of an appropriate entity kind for an entry
2065 -- (i.e. E_Entry if Index is False, or E_Entry_Family if Index
2066 -- is set True for the entry family case). In the True case,
2067 -- makes sure that Is_AST_Entry is set on the entry.
2069 procedure Bad_AST_Entry is
2071 Error_Attr_P ("prefix for % attribute must be task entry");
2074 function OK_Entry (E : Entity_Id) return Boolean is
2079 Result := (Ekind (E) = E_Entry_Family);
2081 Result := (Ekind (E) = E_Entry);
2085 if not Is_AST_Entry (E) then
2086 Error_Msg_Name_2 := Aname;
2087 Error_Attr ("% attribute requires previous % pragma", P);
2094 -- Start of processing for AST_Entry
2100 -- Deal with entry family case
2102 if Nkind (P) = N_Indexed_Component then
2110 Ptyp := Etype (Pref);
2112 if Ptyp = Any_Type or else Error_Posted (Pref) then
2116 -- If the prefix is a selected component whose prefix is of an
2117 -- access type, then introduce an explicit dereference.
2118 -- ??? Could we reuse Check_Dereference here?
2120 if Nkind (Pref) = N_Selected_Component
2121 and then Is_Access_Type (Ptyp)
2124 Make_Explicit_Dereference (Sloc (Pref),
2125 Relocate_Node (Pref)));
2126 Analyze_And_Resolve (Pref, Designated_Type (Ptyp));
2129 -- Prefix can be of the form a.b, where a is a task object
2130 -- and b is one of the entries of the corresponding task type.
2132 if Nkind (Pref) = N_Selected_Component
2133 and then OK_Entry (Entity (Selector_Name (Pref)))
2134 and then Is_Object_Reference (Prefix (Pref))
2135 and then Is_Task_Type (Etype (Prefix (Pref)))
2139 -- Otherwise the prefix must be an entry of a containing task,
2140 -- or of a variable of the enclosing task type.
2143 if Nkind (Pref) = N_Identifier
2144 or else Nkind (Pref) = N_Expanded_Name
2146 Ent := Entity (Pref);
2148 if not OK_Entry (Ent)
2149 or else not In_Open_Scopes (Scope (Ent))
2159 Set_Etype (N, RTE (RE_AST_Handler));
2166 -- Note: when the base attribute appears in the context of a subtype
2167 -- mark, the analysis is done by Sem_Ch8.Find_Type, rather than by
2168 -- the following circuit.
2170 when Attribute_Base => Base : declare
2174 Check_Either_E0_Or_E1;
2178 if Ada_Version >= Ada_95
2179 and then not Is_Scalar_Type (Typ)
2180 and then not Is_Generic_Type (Typ)
2182 Error_Attr_P ("prefix of Base attribute must be scalar type");
2184 elsif Sloc (Typ) = Standard_Location
2185 and then Base_Type (Typ) = Typ
2186 and then Warn_On_Redundant_Constructs
2189 ("?redudant attribute, & is its own base type", N, Typ);
2192 Set_Etype (N, Base_Type (Entity (P)));
2194 -- If we have an expression present, then really this is a conversion
2195 -- and the tree must be reformed. Note that this is one of the cases
2196 -- in which we do a replace rather than a rewrite, because the
2197 -- original tree is junk.
2199 if Present (E1) then
2201 Make_Type_Conversion (Loc,
2203 Make_Attribute_Reference (Loc,
2204 Prefix => Prefix (N),
2205 Attribute_Name => Name_Base),
2206 Expression => Relocate_Node (E1)));
2208 -- E1 may be overloaded, and its interpretations preserved
2210 Save_Interps (E1, Expression (N));
2213 -- For other cases, set the proper type as the entity of the
2214 -- attribute reference, and then rewrite the node to be an
2215 -- occurrence of the referenced base type. This way, no one
2216 -- else in the compiler has to worry about the base attribute.
2219 Set_Entity (N, Base_Type (Entity (P)));
2221 New_Reference_To (Entity (N), Loc));
2230 when Attribute_Bit => Bit :
2234 if not Is_Object_Reference (P) then
2235 Error_Attr_P ("prefix for % attribute must be object");
2237 -- What about the access object cases ???
2243 Set_Etype (N, Universal_Integer);
2250 when Attribute_Bit_Order => Bit_Order :
2255 if not Is_Record_Type (P_Type) then
2256 Error_Attr_P ("prefix of % attribute must be record type");
2259 if Bytes_Big_Endian xor Reverse_Bit_Order (P_Type) then
2261 New_Occurrence_Of (RTE (RE_High_Order_First), Loc));
2264 New_Occurrence_Of (RTE (RE_Low_Order_First), Loc));
2267 Set_Etype (N, RTE (RE_Bit_Order));
2270 -- Reset incorrect indication of staticness
2272 Set_Is_Static_Expression (N, False);
2279 -- Note: in generated code, we can have a Bit_Position attribute
2280 -- applied to a (naked) record component (i.e. the prefix is an
2281 -- identifier that references an E_Component or E_Discriminant
2282 -- entity directly, and this is interpreted as expected by Gigi.
2283 -- The following code will not tolerate such usage, but when the
2284 -- expander creates this special case, it marks it as analyzed
2285 -- immediately and sets an appropriate type.
2287 when Attribute_Bit_Position =>
2288 if Comes_From_Source (N) then
2292 Set_Etype (N, Universal_Integer);
2298 when Attribute_Body_Version =>
2301 Set_Etype (N, RTE (RE_Version_String));
2307 when Attribute_Callable =>
2309 Set_Etype (N, Standard_Boolean);
2316 when Attribute_Caller => Caller : declare
2323 if Nkind (P) = N_Identifier
2324 or else Nkind (P) = N_Expanded_Name
2328 if not Is_Entry (Ent) then
2329 Error_Attr ("invalid entry name", N);
2333 Error_Attr ("invalid entry name", N);
2337 for J in reverse 0 .. Scope_Stack.Last loop
2338 S := Scope_Stack.Table (J).Entity;
2340 if S = Scope (Ent) then
2341 Error_Attr ("Caller must appear in matching accept or body", N);
2347 Set_Etype (N, RTE (RO_AT_Task_Id));
2354 when Attribute_Ceiling =>
2355 Check_Floating_Point_Type_1;
2356 Set_Etype (N, P_Base_Type);
2357 Resolve (E1, P_Base_Type);
2363 when Attribute_Class => Class : declare
2364 P : constant Entity_Id := Prefix (N);
2367 Check_Restriction (No_Dispatch, N);
2368 Check_Either_E0_Or_E1;
2370 -- If we have an expression present, then really this is a conversion
2371 -- and the tree must be reformed into a proper conversion. This is a
2372 -- Replace rather than a Rewrite, because the original tree is junk.
2373 -- If expression is overloaded, propagate interpretations to new one.
2375 if Present (E1) then
2377 Make_Type_Conversion (Loc,
2379 Make_Attribute_Reference (Loc,
2381 Attribute_Name => Name_Class),
2382 Expression => Relocate_Node (E1)));
2384 Save_Interps (E1, Expression (N));
2386 -- Ada 2005 (AI-251): In case of abstract interfaces we have to
2387 -- analyze and resolve the type conversion to generate the code
2388 -- that displaces the reference to the base of the object.
2390 if Is_Interface (Etype (P))
2391 or else Is_Interface (Etype (E1))
2393 Analyze_And_Resolve (N, Etype (P));
2395 -- However, the attribute is a name that occurs in a context
2396 -- that imposes its own type. Leave the result unanalyzed,
2397 -- so that type checking with the context type take place.
2398 -- on the new conversion node, otherwise Resolve is a noop.
2400 Set_Analyzed (N, False);
2406 -- Otherwise we just need to find the proper type
2417 when Attribute_Code_Address =>
2420 if Nkind (P) = N_Attribute_Reference
2421 and then (Attribute_Name (P) = Name_Elab_Body
2423 Attribute_Name (P) = Name_Elab_Spec)
2427 elsif not Is_Entity_Name (P)
2428 or else (Ekind (Entity (P)) /= E_Function
2430 Ekind (Entity (P)) /= E_Procedure)
2432 Error_Attr ("invalid prefix for % attribute", P);
2433 Set_Address_Taken (Entity (P));
2436 Set_Etype (N, RTE (RE_Address));
2438 --------------------
2439 -- Component_Size --
2440 --------------------
2442 when Attribute_Component_Size =>
2444 Set_Etype (N, Universal_Integer);
2446 -- Note: unlike other array attributes, unconstrained arrays are OK
2448 if Is_Array_Type (P_Type) and then not Is_Constrained (P_Type) then
2458 when Attribute_Compose =>
2459 Check_Floating_Point_Type_2;
2460 Set_Etype (N, P_Base_Type);
2461 Resolve (E1, P_Base_Type);
2462 Resolve (E2, Any_Integer);
2468 when Attribute_Constrained =>
2470 Set_Etype (N, Standard_Boolean);
2472 -- Case from RM J.4(2) of constrained applied to private type
2474 if Is_Entity_Name (P) and then Is_Type (Entity (P)) then
2475 Check_Restriction (No_Obsolescent_Features, N);
2477 if Warn_On_Obsolescent_Feature then
2479 ("constrained for private type is an " &
2480 "obsolescent feature (RM J.4)?", N);
2483 -- If we are within an instance, the attribute must be legal
2484 -- because it was valid in the generic unit. Ditto if this is
2485 -- an inlining of a function declared in an instance.
2488 or else In_Inlined_Body
2492 -- For sure OK if we have a real private type itself, but must
2493 -- be completed, cannot apply Constrained to incomplete type.
2495 elsif Is_Private_Type (Entity (P)) then
2497 -- Note: this is one of the Annex J features that does not
2498 -- generate a warning from -gnatwj, since in fact it seems
2499 -- very useful, and is used in the GNAT runtime.
2501 Check_Not_Incomplete_Type;
2505 -- Normal (non-obsolescent case) of application to object of
2506 -- a discriminated type.
2509 Check_Object_Reference (P);
2511 -- If N does not come from source, then we allow the
2512 -- the attribute prefix to be of a private type whose
2513 -- full type has discriminants. This occurs in cases
2514 -- involving expanded calls to stream attributes.
2516 if not Comes_From_Source (N) then
2517 P_Type := Underlying_Type (P_Type);
2520 -- Must have discriminants or be an access type designating
2521 -- a type with discriminants. If it is a classwide type is ???
2522 -- has unknown discriminants.
2524 if Has_Discriminants (P_Type)
2525 or else Has_Unknown_Discriminants (P_Type)
2527 (Is_Access_Type (P_Type)
2528 and then Has_Discriminants (Designated_Type (P_Type)))
2532 -- Also allow an object of a generic type if extensions allowed
2533 -- and allow this for any type at all.
2535 elsif (Is_Generic_Type (P_Type)
2536 or else Is_Generic_Actual_Type (P_Type))
2537 and then Extensions_Allowed
2543 -- Fall through if bad prefix
2546 ("prefix of % attribute must be object of discriminated type");
2552 when Attribute_Copy_Sign =>
2553 Check_Floating_Point_Type_2;
2554 Set_Etype (N, P_Base_Type);
2555 Resolve (E1, P_Base_Type);
2556 Resolve (E2, P_Base_Type);
2562 when Attribute_Count => Count :
2571 if Nkind (P) = N_Identifier
2572 or else Nkind (P) = N_Expanded_Name
2576 if Ekind (Ent) /= E_Entry then
2577 Error_Attr ("invalid entry name", N);
2580 elsif Nkind (P) = N_Indexed_Component then
2581 if not Is_Entity_Name (Prefix (P))
2582 or else No (Entity (Prefix (P)))
2583 or else Ekind (Entity (Prefix (P))) /= E_Entry_Family
2585 if Nkind (Prefix (P)) = N_Selected_Component
2586 and then Present (Entity (Selector_Name (Prefix (P))))
2587 and then Ekind (Entity (Selector_Name (Prefix (P)))) =
2591 ("attribute % must apply to entry of current task", P);
2594 Error_Attr ("invalid entry family name", P);
2599 Ent := Entity (Prefix (P));
2602 elsif Nkind (P) = N_Selected_Component
2603 and then Present (Entity (Selector_Name (P)))
2604 and then Ekind (Entity (Selector_Name (P))) = E_Entry
2607 ("attribute % must apply to entry of current task", P);
2610 Error_Attr ("invalid entry name", N);
2614 for J in reverse 0 .. Scope_Stack.Last loop
2615 S := Scope_Stack.Table (J).Entity;
2617 if S = Scope (Ent) then
2618 if Nkind (P) = N_Expanded_Name then
2619 Tsk := Entity (Prefix (P));
2621 -- The prefix denotes either the task type, or else a
2622 -- single task whose task type is being analyzed.
2627 or else (not Is_Type (Tsk)
2628 and then Etype (Tsk) = S
2629 and then not (Comes_From_Source (S)))
2634 ("Attribute % must apply to entry of current task", N);
2640 elsif Ekind (Scope (Ent)) in Task_Kind
2641 and then Ekind (S) /= E_Loop
2642 and then Ekind (S) /= E_Block
2643 and then Ekind (S) /= E_Entry
2644 and then Ekind (S) /= E_Entry_Family
2646 Error_Attr ("Attribute % cannot appear in inner unit", N);
2648 elsif Ekind (Scope (Ent)) = E_Protected_Type
2649 and then not Has_Completion (Scope (Ent))
2651 Error_Attr ("attribute % can only be used inside body", N);
2655 if Is_Overloaded (P) then
2657 Index : Interp_Index;
2661 Get_First_Interp (P, Index, It);
2663 while Present (It.Nam) loop
2664 if It.Nam = Ent then
2667 -- Ada 2005 (AI-345): Do not consider primitive entry
2668 -- wrappers generated for task or protected types.
2670 elsif Ada_Version >= Ada_05
2671 and then not Comes_From_Source (It.Nam)
2676 Error_Attr ("ambiguous entry name", N);
2679 Get_Next_Interp (Index, It);
2684 Set_Etype (N, Universal_Integer);
2687 -----------------------
2688 -- Default_Bit_Order --
2689 -----------------------
2691 when Attribute_Default_Bit_Order => Default_Bit_Order :
2693 Check_Standard_Prefix;
2696 if Bytes_Big_Endian then
2698 Make_Integer_Literal (Loc, False_Value));
2701 Make_Integer_Literal (Loc, True_Value));
2704 Set_Etype (N, Universal_Integer);
2705 Set_Is_Static_Expression (N);
2706 end Default_Bit_Order;
2712 when Attribute_Definite =>
2713 Legal_Formal_Attribute;
2719 when Attribute_Delta =>
2720 Check_Fixed_Point_Type_0;
2721 Set_Etype (N, Universal_Real);
2727 when Attribute_Denorm =>
2728 Check_Floating_Point_Type_0;
2729 Set_Etype (N, Standard_Boolean);
2735 when Attribute_Digits =>
2739 if not Is_Floating_Point_Type (P_Type)
2740 and then not Is_Decimal_Fixed_Point_Type (P_Type)
2743 ("prefix of % attribute must be float or decimal type");
2746 Set_Etype (N, Universal_Integer);
2752 -- Also handles processing for Elab_Spec
2754 when Attribute_Elab_Body | Attribute_Elab_Spec =>
2756 Check_Unit_Name (P);
2757 Set_Etype (N, Standard_Void_Type);
2759 -- We have to manually call the expander in this case to get
2760 -- the necessary expansion (normally attributes that return
2761 -- entities are not expanded).
2769 -- Shares processing with Elab_Body
2775 when Attribute_Elaborated =>
2778 Set_Etype (N, Standard_Boolean);
2784 when Attribute_Emax =>
2785 Check_Floating_Point_Type_0;
2786 Set_Etype (N, Universal_Integer);
2792 when Attribute_Enabled =>
2793 Check_Either_E0_Or_E1;
2795 if Present (E1) then
2796 if not Is_Entity_Name (E1) or else No (Entity (E1)) then
2797 Error_Msg_N ("entity name expected for Enabled attribute", E1);
2802 if Nkind (P) /= N_Identifier then
2803 Error_Msg_N ("identifier expected (check name)", P);
2805 elsif Get_Check_Id (Chars (P)) = No_Check_Id then
2806 Error_Msg_N ("& is not a recognized check name", P);
2809 Set_Etype (N, Standard_Boolean);
2815 when Attribute_Enum_Rep => Enum_Rep : declare
2817 if Present (E1) then
2819 Check_Discrete_Type;
2820 Resolve (E1, P_Base_Type);
2823 if not Is_Entity_Name (P)
2824 or else (not Is_Object (Entity (P))
2826 Ekind (Entity (P)) /= E_Enumeration_Literal)
2829 ("prefix of %attribute must be " &
2830 "discrete type/object or enum literal");
2834 Set_Etype (N, Universal_Integer);
2841 when Attribute_Epsilon =>
2842 Check_Floating_Point_Type_0;
2843 Set_Etype (N, Universal_Real);
2849 when Attribute_Exponent =>
2850 Check_Floating_Point_Type_1;
2851 Set_Etype (N, Universal_Integer);
2852 Resolve (E1, P_Base_Type);
2858 when Attribute_External_Tag =>
2862 Set_Etype (N, Standard_String);
2864 if not Is_Tagged_Type (P_Type) then
2865 Error_Attr_P ("prefix of % attribute must be tagged");
2872 when Attribute_First =>
2873 Check_Array_Or_Scalar_Type;
2879 when Attribute_First_Bit =>
2881 Set_Etype (N, Universal_Integer);
2887 when Attribute_Fixed_Value =>
2889 Check_Fixed_Point_Type;
2890 Resolve (E1, Any_Integer);
2891 Set_Etype (N, P_Base_Type);
2897 when Attribute_Floor =>
2898 Check_Floating_Point_Type_1;
2899 Set_Etype (N, P_Base_Type);
2900 Resolve (E1, P_Base_Type);
2906 when Attribute_Fore =>
2907 Check_Fixed_Point_Type_0;
2908 Set_Etype (N, Universal_Integer);
2914 when Attribute_Fraction =>
2915 Check_Floating_Point_Type_1;
2916 Set_Etype (N, P_Base_Type);
2917 Resolve (E1, P_Base_Type);
2919 -----------------------
2920 -- Has_Access_Values --
2921 -----------------------
2923 when Attribute_Has_Access_Values =>
2926 Set_Etype (N, Standard_Boolean);
2928 -----------------------
2929 -- Has_Discriminants --
2930 -----------------------
2932 when Attribute_Has_Discriminants =>
2933 Legal_Formal_Attribute;
2939 when Attribute_Identity =>
2943 if Etype (P) = Standard_Exception_Type then
2944 Set_Etype (N, RTE (RE_Exception_Id));
2946 -- Ada 2005 (AI-345): Attribute 'Identity may be applied to
2947 -- task interface class-wide types.
2949 elsif Is_Task_Type (Etype (P))
2950 or else (Is_Access_Type (Etype (P))
2951 and then Is_Task_Type (Designated_Type (Etype (P))))
2952 or else (Ada_Version >= Ada_05
2953 and then Ekind (Etype (P)) = E_Class_Wide_Type
2954 and then Is_Interface (Etype (P))
2955 and then Is_Task_Interface (Etype (P)))
2958 Set_Etype (N, RTE (RO_AT_Task_Id));
2961 if Ada_Version >= Ada_05 then
2963 ("prefix of % attribute must be an exception, a " &
2964 "task or a task interface class-wide object");
2967 ("prefix of % attribute must be a task or an exception");
2975 when Attribute_Image => Image :
2977 Set_Etype (N, Standard_String);
2980 if Is_Real_Type (P_Type) then
2981 if Ada_Version = Ada_83 and then Comes_From_Source (N) then
2982 Error_Msg_Name_1 := Aname;
2984 ("(Ada 83) % attribute not allowed for real types", N);
2988 if Is_Enumeration_Type (P_Type) then
2989 Check_Restriction (No_Enumeration_Maps, N);
2993 Resolve (E1, P_Base_Type);
2995 Validate_Non_Static_Attribute_Function_Call;
3002 when Attribute_Img => Img :
3004 Set_Etype (N, Standard_String);
3006 if not Is_Scalar_Type (P_Type)
3007 or else (Is_Entity_Name (P) and then Is_Type (Entity (P)))
3010 ("prefix of % attribute must be scalar object name");
3020 when Attribute_Input =>
3022 Check_Stream_Attribute (TSS_Stream_Input);
3023 Set_Etype (N, P_Base_Type);
3029 when Attribute_Integer_Value =>
3032 Resolve (E1, Any_Fixed);
3033 Set_Etype (N, P_Base_Type);
3039 when Attribute_Large =>
3042 Set_Etype (N, Universal_Real);
3048 when Attribute_Last =>
3049 Check_Array_Or_Scalar_Type;
3055 when Attribute_Last_Bit =>
3057 Set_Etype (N, Universal_Integer);
3063 when Attribute_Leading_Part =>
3064 Check_Floating_Point_Type_2;
3065 Set_Etype (N, P_Base_Type);
3066 Resolve (E1, P_Base_Type);
3067 Resolve (E2, Any_Integer);
3073 when Attribute_Length =>
3075 Set_Etype (N, Universal_Integer);
3081 when Attribute_Machine =>
3082 Check_Floating_Point_Type_1;
3083 Set_Etype (N, P_Base_Type);
3084 Resolve (E1, P_Base_Type);
3090 when Attribute_Machine_Emax =>
3091 Check_Floating_Point_Type_0;
3092 Set_Etype (N, Universal_Integer);
3098 when Attribute_Machine_Emin =>
3099 Check_Floating_Point_Type_0;
3100 Set_Etype (N, Universal_Integer);
3102 ----------------------
3103 -- Machine_Mantissa --
3104 ----------------------
3106 when Attribute_Machine_Mantissa =>
3107 Check_Floating_Point_Type_0;
3108 Set_Etype (N, Universal_Integer);
3110 -----------------------
3111 -- Machine_Overflows --
3112 -----------------------
3114 when Attribute_Machine_Overflows =>
3117 Set_Etype (N, Standard_Boolean);
3123 when Attribute_Machine_Radix =>
3126 Set_Etype (N, Universal_Integer);
3128 ----------------------
3129 -- Machine_Rounding --
3130 ----------------------
3132 when Attribute_Machine_Rounding =>
3133 Check_Floating_Point_Type_1;
3134 Set_Etype (N, P_Base_Type);
3135 Resolve (E1, P_Base_Type);
3137 --------------------
3138 -- Machine_Rounds --
3139 --------------------
3141 when Attribute_Machine_Rounds =>
3144 Set_Etype (N, Standard_Boolean);
3150 when Attribute_Machine_Size =>
3153 Check_Not_Incomplete_Type;
3154 Set_Etype (N, Universal_Integer);
3160 when Attribute_Mantissa =>
3163 Set_Etype (N, Universal_Integer);
3169 when Attribute_Max =>
3172 Resolve (E1, P_Base_Type);
3173 Resolve (E2, P_Base_Type);
3174 Set_Etype (N, P_Base_Type);
3176 ----------------------------------
3177 -- Max_Size_In_Storage_Elements --
3178 ----------------------------------
3180 when Attribute_Max_Size_In_Storage_Elements =>
3183 Check_Not_Incomplete_Type;
3184 Set_Etype (N, Universal_Integer);
3186 -----------------------
3187 -- Maximum_Alignment --
3188 -----------------------
3190 when Attribute_Maximum_Alignment =>
3191 Standard_Attribute (Ttypes.Maximum_Alignment);
3193 --------------------
3194 -- Mechanism_Code --
3195 --------------------
3197 when Attribute_Mechanism_Code =>
3198 if not Is_Entity_Name (P)
3199 or else not Is_Subprogram (Entity (P))
3201 Error_Attr_P ("prefix of % attribute must be subprogram");
3204 Check_Either_E0_Or_E1;
3206 if Present (E1) then
3207 Resolve (E1, Any_Integer);
3208 Set_Etype (E1, Standard_Integer);
3210 if not Is_Static_Expression (E1) then
3211 Flag_Non_Static_Expr
3212 ("expression for parameter number must be static!", E1);
3215 elsif UI_To_Int (Intval (E1)) > Number_Formals (Entity (P))
3216 or else UI_To_Int (Intval (E1)) < 0
3218 Error_Attr ("invalid parameter number for %attribute", E1);
3222 Set_Etype (N, Universal_Integer);
3228 when Attribute_Min =>
3231 Resolve (E1, P_Base_Type);
3232 Resolve (E2, P_Base_Type);
3233 Set_Etype (N, P_Base_Type);
3239 when Attribute_Mod =>
3241 -- Note: this attribute is only allowed in Ada 2005 mode, but
3242 -- we do not need to test that here, since Mod is only recognized
3243 -- as an attribute name in Ada 2005 mode during the parse.
3246 Check_Modular_Integer_Type;
3247 Resolve (E1, Any_Integer);
3248 Set_Etype (N, P_Base_Type);
3254 when Attribute_Model =>
3255 Check_Floating_Point_Type_1;
3256 Set_Etype (N, P_Base_Type);
3257 Resolve (E1, P_Base_Type);
3263 when Attribute_Model_Emin =>
3264 Check_Floating_Point_Type_0;
3265 Set_Etype (N, Universal_Integer);
3271 when Attribute_Model_Epsilon =>
3272 Check_Floating_Point_Type_0;
3273 Set_Etype (N, Universal_Real);
3275 --------------------
3276 -- Model_Mantissa --
3277 --------------------
3279 when Attribute_Model_Mantissa =>
3280 Check_Floating_Point_Type_0;
3281 Set_Etype (N, Universal_Integer);
3287 when Attribute_Model_Small =>
3288 Check_Floating_Point_Type_0;
3289 Set_Etype (N, Universal_Real);
3295 when Attribute_Modulus =>
3297 Check_Modular_Integer_Type;
3298 Set_Etype (N, Universal_Integer);
3300 --------------------
3301 -- Null_Parameter --
3302 --------------------
3304 when Attribute_Null_Parameter => Null_Parameter : declare
3305 Parnt : constant Node_Id := Parent (N);
3306 GParnt : constant Node_Id := Parent (Parnt);
3308 procedure Bad_Null_Parameter (Msg : String);
3309 -- Used if bad Null parameter attribute node is found. Issues
3310 -- given error message, and also sets the type to Any_Type to
3311 -- avoid blowups later on from dealing with a junk node.
3313 procedure Must_Be_Imported (Proc_Ent : Entity_Id);
3314 -- Called to check that Proc_Ent is imported subprogram
3316 ------------------------
3317 -- Bad_Null_Parameter --
3318 ------------------------
3320 procedure Bad_Null_Parameter (Msg : String) is
3322 Error_Msg_N (Msg, N);
3323 Set_Etype (N, Any_Type);
3324 end Bad_Null_Parameter;
3326 ----------------------
3327 -- Must_Be_Imported --
3328 ----------------------
3330 procedure Must_Be_Imported (Proc_Ent : Entity_Id) is
3331 Pent : Entity_Id := Proc_Ent;
3334 while Present (Alias (Pent)) loop
3335 Pent := Alias (Pent);
3338 -- Ignore check if procedure not frozen yet (we will get
3339 -- another chance when the default parameter is reanalyzed)
3341 if not Is_Frozen (Pent) then
3344 elsif not Is_Imported (Pent) then
3346 ("Null_Parameter can only be used with imported subprogram");
3351 end Must_Be_Imported;
3353 -- Start of processing for Null_Parameter
3358 Set_Etype (N, P_Type);
3360 -- Case of attribute used as default expression
3362 if Nkind (Parnt) = N_Parameter_Specification then
3363 Must_Be_Imported (Defining_Entity (GParnt));
3365 -- Case of attribute used as actual for subprogram (positional)
3367 elsif (Nkind (Parnt) = N_Procedure_Call_Statement
3369 Nkind (Parnt) = N_Function_Call)
3370 and then Is_Entity_Name (Name (Parnt))
3372 Must_Be_Imported (Entity (Name (Parnt)));
3374 -- Case of attribute used as actual for subprogram (named)
3376 elsif Nkind (Parnt) = N_Parameter_Association
3377 and then (Nkind (GParnt) = N_Procedure_Call_Statement
3379 Nkind (GParnt) = N_Function_Call)
3380 and then Is_Entity_Name (Name (GParnt))
3382 Must_Be_Imported (Entity (Name (GParnt)));
3384 -- Not an allowed case
3388 ("Null_Parameter must be actual or default parameter");
3397 when Attribute_Object_Size =>
3400 Check_Not_Incomplete_Type;
3401 Set_Etype (N, Universal_Integer);
3407 when Attribute_Output =>
3409 Check_Stream_Attribute (TSS_Stream_Output);
3410 Set_Etype (N, Standard_Void_Type);
3411 Resolve (N, Standard_Void_Type);
3417 when Attribute_Partition_ID =>
3420 if P_Type /= Any_Type then
3421 if not Is_Library_Level_Entity (Entity (P)) then
3423 ("prefix of % attribute must be library-level entity");
3425 -- The defining entity of prefix should not be declared inside
3426 -- a Pure unit. RM E.1(8).
3427 -- The Is_Pure flag has been set during declaration.
3429 elsif Is_Entity_Name (P)
3430 and then Is_Pure (Entity (P))
3433 ("prefix of % attribute must not be declared pure");
3437 Set_Etype (N, Universal_Integer);
3439 -------------------------
3440 -- Passed_By_Reference --
3441 -------------------------
3443 when Attribute_Passed_By_Reference =>
3446 Set_Etype (N, Standard_Boolean);
3452 when Attribute_Pool_Address =>
3454 Set_Etype (N, RTE (RE_Address));
3460 when Attribute_Pos =>
3461 Check_Discrete_Type;
3463 Resolve (E1, P_Base_Type);
3464 Set_Etype (N, Universal_Integer);
3470 when Attribute_Position =>
3472 Set_Etype (N, Universal_Integer);
3478 when Attribute_Pred =>
3481 Resolve (E1, P_Base_Type);
3482 Set_Etype (N, P_Base_Type);
3484 -- Nothing to do for real type case
3486 if Is_Real_Type (P_Type) then
3489 -- If not modular type, test for overflow check required
3492 if not Is_Modular_Integer_Type (P_Type)
3493 and then not Range_Checks_Suppressed (P_Base_Type)
3495 Enable_Range_Check (E1);
3503 -- Ada 2005 (AI-327): Dynamic ceiling priorities
3505 when Attribute_Priority =>
3506 if Ada_Version < Ada_05 then
3507 Error_Attr ("% attribute is allowed only in Ada 2005 mode", P);
3512 -- The prefix must be a protected object (AARM D.5.2 (2/2))
3516 if Is_Protected_Type (Etype (P))
3517 or else (Is_Access_Type (Etype (P))
3518 and then Is_Protected_Type (Designated_Type (Etype (P))))
3520 Resolve (P, Etype (P));
3522 Error_Attr_P ("prefix of % attribute must be a protected object");
3525 Set_Etype (N, Standard_Integer);
3527 -- Must be called from within a protected procedure or entry of the
3528 -- protected object.
3535 while S /= Etype (P)
3536 and then S /= Standard_Standard
3541 if S = Standard_Standard then
3542 Error_Attr ("the attribute % is only allowed inside protected "
3547 Validate_Non_Static_Attribute_Function_Call;
3553 when Attribute_Range =>
3554 Check_Array_Or_Scalar_Type;
3556 if Ada_Version = Ada_83
3557 and then Is_Scalar_Type (P_Type)
3558 and then Comes_From_Source (N)
3561 ("(Ada 83) % attribute not allowed for scalar type", P);
3568 when Attribute_Range_Length =>
3569 Check_Discrete_Type;
3570 Set_Etype (N, Universal_Integer);
3576 when Attribute_Read =>
3578 Check_Stream_Attribute (TSS_Stream_Read);
3579 Set_Etype (N, Standard_Void_Type);
3580 Resolve (N, Standard_Void_Type);
3581 Note_Possible_Modification (E2);
3587 when Attribute_Remainder =>
3588 Check_Floating_Point_Type_2;
3589 Set_Etype (N, P_Base_Type);
3590 Resolve (E1, P_Base_Type);
3591 Resolve (E2, P_Base_Type);
3597 when Attribute_Round =>
3599 Check_Decimal_Fixed_Point_Type;
3600 Set_Etype (N, P_Base_Type);
3602 -- Because the context is universal_real (3.5.10(12)) it is a legal
3603 -- context for a universal fixed expression. This is the only
3604 -- attribute whose functional description involves U_R.
3606 if Etype (E1) = Universal_Fixed then
3608 Conv : constant Node_Id := Make_Type_Conversion (Loc,
3609 Subtype_Mark => New_Occurrence_Of (Universal_Real, Loc),
3610 Expression => Relocate_Node (E1));
3618 Resolve (E1, Any_Real);
3624 when Attribute_Rounding =>
3625 Check_Floating_Point_Type_1;
3626 Set_Etype (N, P_Base_Type);
3627 Resolve (E1, P_Base_Type);
3633 when Attribute_Safe_Emax =>
3634 Check_Floating_Point_Type_0;
3635 Set_Etype (N, Universal_Integer);
3641 when Attribute_Safe_First =>
3642 Check_Floating_Point_Type_0;
3643 Set_Etype (N, Universal_Real);
3649 when Attribute_Safe_Large =>
3652 Set_Etype (N, Universal_Real);
3658 when Attribute_Safe_Last =>
3659 Check_Floating_Point_Type_0;
3660 Set_Etype (N, Universal_Real);
3666 when Attribute_Safe_Small =>
3669 Set_Etype (N, Universal_Real);
3675 when Attribute_Scale =>
3677 Check_Decimal_Fixed_Point_Type;
3678 Set_Etype (N, Universal_Integer);
3684 when Attribute_Scaling =>
3685 Check_Floating_Point_Type_2;
3686 Set_Etype (N, P_Base_Type);
3687 Resolve (E1, P_Base_Type);
3693 when Attribute_Signed_Zeros =>
3694 Check_Floating_Point_Type_0;
3695 Set_Etype (N, Standard_Boolean);
3701 when Attribute_Size | Attribute_VADS_Size =>
3704 -- If prefix is parameterless function call, rewrite and resolve
3707 if Is_Entity_Name (P)
3708 and then Ekind (Entity (P)) = E_Function
3712 -- Similar processing for a protected function call
3714 elsif Nkind (P) = N_Selected_Component
3715 and then Ekind (Entity (Selector_Name (P))) = E_Function
3720 if Is_Object_Reference (P) then
3721 Check_Object_Reference (P);
3723 elsif Is_Entity_Name (P)
3724 and then (Is_Type (Entity (P))
3725 or else Ekind (Entity (P)) = E_Enumeration_Literal)
3729 elsif Nkind (P) = N_Type_Conversion
3730 and then not Comes_From_Source (P)
3735 Error_Attr_P ("invalid prefix for % attribute");
3738 Check_Not_Incomplete_Type;
3739 Set_Etype (N, Universal_Integer);
3745 when Attribute_Small =>
3748 Set_Etype (N, Universal_Real);
3754 when Attribute_Storage_Pool =>
3755 if Is_Access_Type (P_Type) then
3758 if Ekind (P_Type) = E_Access_Subprogram_Type then
3760 ("cannot use % attribute for access-to-subprogram type");
3763 -- Set appropriate entity
3765 if Present (Associated_Storage_Pool (Root_Type (P_Type))) then
3766 Set_Entity (N, Associated_Storage_Pool (Root_Type (P_Type)));
3768 Set_Entity (N, RTE (RE_Global_Pool_Object));
3771 Set_Etype (N, Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
3773 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
3774 -- Storage_Pool since this attribute is not defined for such
3775 -- types (RM E.2.3(22)).
3777 Validate_Remote_Access_To_Class_Wide_Type (N);
3780 Error_Attr_P ("prefix of % attribute must be access type");
3787 when Attribute_Storage_Size =>
3788 if Is_Task_Type (P_Type) then
3790 Set_Etype (N, Universal_Integer);
3792 elsif Is_Access_Type (P_Type) then
3793 if Ekind (P_Type) = E_Access_Subprogram_Type then
3795 ("cannot use % attribute for access-to-subprogram type");
3798 if Is_Entity_Name (P)
3799 and then Is_Type (Entity (P))
3803 Set_Etype (N, Universal_Integer);
3805 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
3806 -- Storage_Size since this attribute is not defined for
3807 -- such types (RM E.2.3(22)).
3809 Validate_Remote_Access_To_Class_Wide_Type (N);
3811 -- The prefix is allowed to be an implicit dereference
3812 -- of an access value designating a task.
3817 Set_Etype (N, Universal_Integer);
3821 Error_Attr_P ("prefix of % attribute must be access or task type");
3828 when Attribute_Storage_Unit =>
3829 Standard_Attribute (Ttypes.System_Storage_Unit);
3835 when Attribute_Stream_Size =>
3839 if Is_Entity_Name (P)
3840 and then Is_Elementary_Type (Entity (P))
3842 Set_Etype (N, Universal_Integer);
3844 Error_Attr_P ("invalid prefix for % attribute");
3851 when Attribute_Stub_Type =>
3855 if Is_Remote_Access_To_Class_Wide_Type (P_Type) then
3857 New_Occurrence_Of (Corresponding_Stub_Type (P_Type), Loc));
3860 ("prefix of% attribute must be remote access to classwide");
3867 when Attribute_Succ =>
3870 Resolve (E1, P_Base_Type);
3871 Set_Etype (N, P_Base_Type);
3873 -- Nothing to do for real type case
3875 if Is_Real_Type (P_Type) then
3878 -- If not modular type, test for overflow check required
3881 if not Is_Modular_Integer_Type (P_Type)
3882 and then not Range_Checks_Suppressed (P_Base_Type)
3884 Enable_Range_Check (E1);
3892 when Attribute_Tag =>
3896 if not Is_Tagged_Type (P_Type) then
3897 Error_Attr_P ("prefix of % attribute must be tagged");
3899 -- Next test does not apply to generated code
3900 -- why not, and what does the illegal reference mean???
3902 elsif Is_Object_Reference (P)
3903 and then not Is_Class_Wide_Type (P_Type)
3904 and then Comes_From_Source (N)
3907 ("% attribute can only be applied to objects " &
3908 "of class - wide type");
3911 -- The prefix cannot be an incomplete type. However, references
3912 -- to 'Tag can be generated when expanding interface conversions,
3913 -- and this is legal.
3915 if Comes_From_Source (N) then
3916 Check_Not_Incomplete_Type;
3918 Set_Etype (N, RTE (RE_Tag));
3924 when Attribute_Target_Name => Target_Name : declare
3925 TN : constant String := Sdefault.Target_Name.all;
3929 Check_Standard_Prefix;
3934 if TN (TL) = '/' or else TN (TL) = '\' then
3939 Make_String_Literal (Loc,
3940 Strval => TN (TN'First .. TL)));
3941 Analyze_And_Resolve (N, Standard_String);
3948 when Attribute_Terminated =>
3950 Set_Etype (N, Standard_Boolean);
3957 when Attribute_To_Address =>
3961 if Nkind (P) /= N_Identifier
3962 or else Chars (P) /= Name_System
3964 Error_Attr_P ("prefix of %attribute must be System");
3967 Generate_Reference (RTE (RE_Address), P);
3968 Analyze_And_Resolve (E1, Any_Integer);
3969 Set_Etype (N, RTE (RE_Address));
3975 when Attribute_Truncation =>
3976 Check_Floating_Point_Type_1;
3977 Resolve (E1, P_Base_Type);
3978 Set_Etype (N, P_Base_Type);
3984 when Attribute_Type_Class =>
3987 Check_Not_Incomplete_Type;
3988 Set_Etype (N, RTE (RE_Type_Class));
3994 when Attribute_UET_Address =>
3996 Check_Unit_Name (P);
3997 Set_Etype (N, RTE (RE_Address));
3999 -----------------------
4000 -- Unbiased_Rounding --
4001 -----------------------
4003 when Attribute_Unbiased_Rounding =>
4004 Check_Floating_Point_Type_1;
4005 Set_Etype (N, P_Base_Type);
4006 Resolve (E1, P_Base_Type);
4008 ----------------------
4009 -- Unchecked_Access --
4010 ----------------------
4012 when Attribute_Unchecked_Access =>
4013 if Comes_From_Source (N) then
4014 Check_Restriction (No_Unchecked_Access, N);
4017 Analyze_Access_Attribute;
4019 -------------------------
4020 -- Unconstrained_Array --
4021 -------------------------
4023 when Attribute_Unconstrained_Array =>
4026 Check_Not_Incomplete_Type;
4027 Set_Etype (N, Standard_Boolean);
4029 ------------------------------
4030 -- Universal_Literal_String --
4031 ------------------------------
4033 -- This is a GNAT specific attribute whose prefix must be a named
4034 -- number where the expression is either a single numeric literal,
4035 -- or a numeric literal immediately preceded by a minus sign. The
4036 -- result is equivalent to a string literal containing the text of
4037 -- the literal as it appeared in the source program with a possible
4038 -- leading minus sign.
4040 when Attribute_Universal_Literal_String => Universal_Literal_String :
4044 if not Is_Entity_Name (P)
4045 or else Ekind (Entity (P)) not in Named_Kind
4047 Error_Attr_P ("prefix for % attribute must be named number");
4054 Src : Source_Buffer_Ptr;
4057 Expr := Original_Node (Expression (Parent (Entity (P))));
4059 if Nkind (Expr) = N_Op_Minus then
4061 Expr := Original_Node (Right_Opnd (Expr));
4066 if Nkind (Expr) /= N_Integer_Literal
4067 and then Nkind (Expr) /= N_Real_Literal
4070 ("named number for % attribute must be simple literal", N);
4073 -- Build string literal corresponding to source literal text
4078 Store_String_Char (Get_Char_Code ('-'));
4082 Src := Source_Text (Get_Source_File_Index (S));
4084 while Src (S) /= ';' and then Src (S) /= ' ' loop
4085 Store_String_Char (Get_Char_Code (Src (S)));
4089 -- Now we rewrite the attribute with the string literal
4092 Make_String_Literal (Loc, End_String));
4096 end Universal_Literal_String;
4098 -------------------------
4099 -- Unrestricted_Access --
4100 -------------------------
4102 -- This is a GNAT specific attribute which is like Access except that
4103 -- all scope checks and checks for aliased views are omitted.
4105 when Attribute_Unrestricted_Access =>
4106 if Comes_From_Source (N) then
4107 Check_Restriction (No_Unchecked_Access, N);
4110 if Is_Entity_Name (P) then
4111 Set_Address_Taken (Entity (P));
4114 Analyze_Access_Attribute;
4120 when Attribute_Val => Val : declare
4123 Check_Discrete_Type;
4124 Resolve (E1, Any_Integer);
4125 Set_Etype (N, P_Base_Type);
4127 -- Note, we need a range check in general, but we wait for the
4128 -- Resolve call to do this, since we want to let Eval_Attribute
4129 -- have a chance to find an static illegality first!
4136 when Attribute_Valid =>
4139 -- Ignore check for object if we have a 'Valid reference generated
4140 -- by the expanded code, since in some cases valid checks can occur
4141 -- on items that are names, but are not objects (e.g. attributes).
4143 if Comes_From_Source (N) then
4144 Check_Object_Reference (P);
4147 if not Is_Scalar_Type (P_Type) then
4148 Error_Attr_P ("object for % attribute must be of scalar type");
4151 Set_Etype (N, Standard_Boolean);
4157 when Attribute_Value => Value :
4162 -- Case of enumeration type
4164 if Is_Enumeration_Type (P_Type) then
4165 Check_Restriction (No_Enumeration_Maps, N);
4167 -- Mark all enumeration literals as referenced, since the use of
4168 -- the Value attribute can implicitly reference any of the
4169 -- literals of the enumeration base type.
4172 Ent : Entity_Id := First_Literal (P_Base_Type);
4174 while Present (Ent) loop
4175 Set_Referenced (Ent);
4181 -- Set Etype before resolving expression because expansion of
4182 -- expression may require enclosing type. Note that the type
4183 -- returned by 'Value is the base type of the prefix type.
4185 Set_Etype (N, P_Base_Type);
4186 Validate_Non_Static_Attribute_Function_Call;
4193 when Attribute_Value_Size =>
4196 Check_Not_Incomplete_Type;
4197 Set_Etype (N, Universal_Integer);
4203 when Attribute_Version =>
4206 Set_Etype (N, RTE (RE_Version_String));
4212 when Attribute_Wchar_T_Size =>
4213 Standard_Attribute (Interfaces_Wchar_T_Size);
4219 when Attribute_Wide_Image => Wide_Image :
4222 Set_Etype (N, Standard_Wide_String);
4224 Resolve (E1, P_Base_Type);
4225 Validate_Non_Static_Attribute_Function_Call;
4228 ---------------------
4229 -- Wide_Wide_Image --
4230 ---------------------
4232 when Attribute_Wide_Wide_Image => Wide_Wide_Image :
4235 Set_Etype (N, Standard_Wide_Wide_String);
4237 Resolve (E1, P_Base_Type);
4238 Validate_Non_Static_Attribute_Function_Call;
4239 end Wide_Wide_Image;
4245 when Attribute_Wide_Value => Wide_Value :
4250 -- Set Etype before resolving expression because expansion
4251 -- of expression may require enclosing type.
4253 Set_Etype (N, P_Type);
4254 Validate_Non_Static_Attribute_Function_Call;
4257 ---------------------
4258 -- Wide_Wide_Value --
4259 ---------------------
4261 when Attribute_Wide_Wide_Value => Wide_Wide_Value :
4266 -- Set Etype before resolving expression because expansion
4267 -- of expression may require enclosing type.
4269 Set_Etype (N, P_Type);
4270 Validate_Non_Static_Attribute_Function_Call;
4271 end Wide_Wide_Value;
4273 ---------------------
4274 -- Wide_Wide_Width --
4275 ---------------------
4277 when Attribute_Wide_Wide_Width =>
4280 Set_Etype (N, Universal_Integer);
4286 when Attribute_Wide_Width =>
4289 Set_Etype (N, Universal_Integer);
4295 when Attribute_Width =>
4298 Set_Etype (N, Universal_Integer);
4304 when Attribute_Word_Size =>
4305 Standard_Attribute (System_Word_Size);
4311 when Attribute_Write =>
4313 Check_Stream_Attribute (TSS_Stream_Write);
4314 Set_Etype (N, Standard_Void_Type);
4315 Resolve (N, Standard_Void_Type);
4319 -- All errors raise Bad_Attribute, so that we get out before any further
4320 -- damage occurs when an error is detected (for example, if we check for
4321 -- one attribute expression, and the check succeeds, we want to be able
4322 -- to proceed securely assuming that an expression is in fact present.
4324 -- Note: we set the attribute analyzed in this case to prevent any
4325 -- attempt at reanalysis which could generate spurious error msgs.
4328 when Bad_Attribute =>
4330 Set_Etype (N, Any_Type);
4332 end Analyze_Attribute;
4334 --------------------
4335 -- Eval_Attribute --
4336 --------------------
4338 procedure Eval_Attribute (N : Node_Id) is
4339 Loc : constant Source_Ptr := Sloc (N);
4340 Aname : constant Name_Id := Attribute_Name (N);
4341 Id : constant Attribute_Id := Get_Attribute_Id (Aname);
4342 P : constant Node_Id := Prefix (N);
4344 C_Type : constant Entity_Id := Etype (N);
4345 -- The type imposed by the context
4348 -- First expression, or Empty if none
4351 -- Second expression, or Empty if none
4353 P_Entity : Entity_Id;
4354 -- Entity denoted by prefix
4357 -- The type of the prefix
4359 P_Base_Type : Entity_Id;
4360 -- The base type of the prefix type
4362 P_Root_Type : Entity_Id;
4363 -- The root type of the prefix type
4366 -- True if the result is Static. This is set by the general processing
4367 -- to true if the prefix is static, and all expressions are static. It
4368 -- can be reset as processing continues for particular attributes
4370 Lo_Bound, Hi_Bound : Node_Id;
4371 -- Expressions for low and high bounds of type or array index referenced
4372 -- by First, Last, or Length attribute for array, set by Set_Bounds.
4375 -- Constraint error node used if we have an attribute reference has
4376 -- an argument that raises a constraint error. In this case we replace
4377 -- the attribute with a raise constraint_error node. This is important
4378 -- processing, since otherwise gigi might see an attribute which it is
4379 -- unprepared to deal with.
4381 function Aft_Value return Nat;
4382 -- Computes Aft value for current attribute prefix (used by Aft itself
4383 -- and also by Width for computing the Width of a fixed point type).
4385 procedure Check_Expressions;
4386 -- In case where the attribute is not foldable, the expressions, if
4387 -- any, of the attribute, are in a non-static context. This procedure
4388 -- performs the required additional checks.
4390 function Compile_Time_Known_Bounds (Typ : Entity_Id) return Boolean;
4391 -- Determines if the given type has compile time known bounds. Note
4392 -- that we enter the case statement even in cases where the prefix
4393 -- type does NOT have known bounds, so it is important to guard any
4394 -- attempt to evaluate both bounds with a call to this function.
4396 procedure Compile_Time_Known_Attribute (N : Node_Id; Val : Uint);
4397 -- This procedure is called when the attribute N has a non-static
4398 -- but compile time known value given by Val. It includes the
4399 -- necessary checks for out of range values.
4401 procedure Float_Attribute_Universal_Integer
4410 -- This procedure evaluates a float attribute with no arguments that
4411 -- returns a universal integer result. The parameters give the values
4412 -- for the possible floating-point root types. See ttypef for details.
4413 -- The prefix type is a float type (and is thus not a generic type).
4415 procedure Float_Attribute_Universal_Real
4416 (IEEES_Val : String;
4423 AAMPL_Val : String);
4424 -- This procedure evaluates a float attribute with no arguments that
4425 -- returns a universal real result. The parameters give the values
4426 -- required for the possible floating-point root types in string
4427 -- format as real literals with a possible leading minus sign.
4428 -- The prefix type is a float type (and is thus not a generic type).
4430 function Fore_Value return Nat;
4431 -- Computes the Fore value for the current attribute prefix, which is
4432 -- known to be a static fixed-point type. Used by Fore and Width.
4434 function Mantissa return Uint;
4435 -- Returns the Mantissa value for the prefix type
4437 procedure Set_Bounds;
4438 -- Used for First, Last and Length attributes applied to an array or
4439 -- array subtype. Sets the variables Lo_Bound and Hi_Bound to the low
4440 -- and high bound expressions for the index referenced by the attribute
4441 -- designator (i.e. the first index if no expression is present, and
4442 -- the N'th index if the value N is present as an expression). Also
4443 -- used for First and Last of scalar types. Static is reset to False
4444 -- if the type or index type is not statically constrained.
4446 function Statically_Denotes_Entity (N : Node_Id) return Boolean;
4447 -- Verify that the prefix of a potentially static array attribute
4448 -- satisfies the conditions of 4.9 (14).
4454 function Aft_Value return Nat is
4460 Delta_Val := Delta_Value (P_Type);
4461 while Delta_Val < Ureal_Tenth loop
4462 Delta_Val := Delta_Val * Ureal_10;
4463 Result := Result + 1;
4469 -----------------------
4470 -- Check_Expressions --
4471 -----------------------
4473 procedure Check_Expressions is
4477 while Present (E) loop
4478 Check_Non_Static_Context (E);
4481 end Check_Expressions;
4483 ----------------------------------
4484 -- Compile_Time_Known_Attribute --
4485 ----------------------------------
4487 procedure Compile_Time_Known_Attribute (N : Node_Id; Val : Uint) is
4488 T : constant Entity_Id := Etype (N);
4491 Fold_Uint (N, Val, False);
4493 -- Check that result is in bounds of the type if it is static
4495 if Is_In_Range (N, T) then
4498 elsif Is_Out_Of_Range (N, T) then
4499 Apply_Compile_Time_Constraint_Error
4500 (N, "value not in range of}?", CE_Range_Check_Failed);
4502 elsif not Range_Checks_Suppressed (T) then
4503 Enable_Range_Check (N);
4506 Set_Do_Range_Check (N, False);
4508 end Compile_Time_Known_Attribute;
4510 -------------------------------
4511 -- Compile_Time_Known_Bounds --
4512 -------------------------------
4514 function Compile_Time_Known_Bounds (Typ : Entity_Id) return Boolean is
4517 Compile_Time_Known_Value (Type_Low_Bound (Typ))
4519 Compile_Time_Known_Value (Type_High_Bound (Typ));
4520 end Compile_Time_Known_Bounds;
4522 ---------------------------------------
4523 -- Float_Attribute_Universal_Integer --
4524 ---------------------------------------
4526 procedure Float_Attribute_Universal_Integer
4537 Digs : constant Nat := UI_To_Int (Digits_Value (P_Base_Type));
4540 if Vax_Float (P_Base_Type) then
4541 if Digs = VAXFF_Digits then
4543 elsif Digs = VAXDF_Digits then
4545 else pragma Assert (Digs = VAXGF_Digits);
4549 elsif Is_AAMP_Float (P_Base_Type) then
4550 if Digs = AAMPS_Digits then
4552 else pragma Assert (Digs = AAMPL_Digits);
4557 if Digs = IEEES_Digits then
4559 elsif Digs = IEEEL_Digits then
4561 else pragma Assert (Digs = IEEEX_Digits);
4566 Fold_Uint (N, UI_From_Int (Val), True);
4567 end Float_Attribute_Universal_Integer;
4569 ------------------------------------
4570 -- Float_Attribute_Universal_Real --
4571 ------------------------------------
4573 procedure Float_Attribute_Universal_Real
4574 (IEEES_Val : String;
4584 Digs : constant Nat := UI_To_Int (Digits_Value (P_Base_Type));
4587 if Vax_Float (P_Base_Type) then
4588 if Digs = VAXFF_Digits then
4589 Val := Real_Convert (VAXFF_Val);
4590 elsif Digs = VAXDF_Digits then
4591 Val := Real_Convert (VAXDF_Val);
4592 else pragma Assert (Digs = VAXGF_Digits);
4593 Val := Real_Convert (VAXGF_Val);
4596 elsif Is_AAMP_Float (P_Base_Type) then
4597 if Digs = AAMPS_Digits then
4598 Val := Real_Convert (AAMPS_Val);
4599 else pragma Assert (Digs = AAMPL_Digits);
4600 Val := Real_Convert (AAMPL_Val);
4604 if Digs = IEEES_Digits then
4605 Val := Real_Convert (IEEES_Val);
4606 elsif Digs = IEEEL_Digits then
4607 Val := Real_Convert (IEEEL_Val);
4608 else pragma Assert (Digs = IEEEX_Digits);
4609 Val := Real_Convert (IEEEX_Val);
4613 Set_Sloc (Val, Loc);
4615 Set_Is_Static_Expression (N, Static);
4616 Analyze_And_Resolve (N, C_Type);
4617 end Float_Attribute_Universal_Real;
4623 -- Note that the Fore calculation is based on the actual values
4624 -- of the bounds, and does not take into account possible rounding.
4626 function Fore_Value return Nat is
4627 Lo : constant Uint := Expr_Value (Type_Low_Bound (P_Type));
4628 Hi : constant Uint := Expr_Value (Type_High_Bound (P_Type));
4629 Small : constant Ureal := Small_Value (P_Type);
4630 Lo_Real : constant Ureal := Lo * Small;
4631 Hi_Real : constant Ureal := Hi * Small;
4636 -- Bounds are given in terms of small units, so first compute
4637 -- proper values as reals.
4639 T := UR_Max (abs Lo_Real, abs Hi_Real);
4642 -- Loop to compute proper value if more than one digit required
4644 while T >= Ureal_10 loop
4656 -- Table of mantissa values accessed by function Computed using
4659 -- T'Mantissa = integer next above (D * log(10)/log(2)) + 1)
4661 -- where D is T'Digits (RM83 3.5.7)
4663 Mantissa_Value : constant array (Nat range 1 .. 40) of Nat := (
4705 function Mantissa return Uint is
4708 UI_From_Int (Mantissa_Value (UI_To_Int (Digits_Value (P_Type))));
4715 procedure Set_Bounds is
4721 -- For a string literal subtype, we have to construct the bounds.
4722 -- Valid Ada code never applies attributes to string literals, but
4723 -- it is convenient to allow the expander to generate attribute
4724 -- references of this type (e.g. First and Last applied to a string
4727 -- Note that the whole point of the E_String_Literal_Subtype is to
4728 -- avoid this construction of bounds, but the cases in which we
4729 -- have to materialize them are rare enough that we don't worry!
4731 -- The low bound is simply the low bound of the base type. The
4732 -- high bound is computed from the length of the string and this
4735 if Ekind (P_Type) = E_String_Literal_Subtype then
4736 Ityp := Etype (First_Index (Base_Type (P_Type)));
4737 Lo_Bound := Type_Low_Bound (Ityp);
4740 Make_Integer_Literal (Sloc (P),
4742 Expr_Value (Lo_Bound) + String_Literal_Length (P_Type) - 1);
4744 Set_Parent (Hi_Bound, P);
4745 Analyze_And_Resolve (Hi_Bound, Etype (Lo_Bound));
4748 -- For non-array case, just get bounds of scalar type
4750 elsif Is_Scalar_Type (P_Type) then
4753 -- For a fixed-point type, we must freeze to get the attributes
4754 -- of the fixed-point type set now so we can reference them.
4756 if Is_Fixed_Point_Type (P_Type)
4757 and then not Is_Frozen (Base_Type (P_Type))
4758 and then Compile_Time_Known_Value (Type_Low_Bound (P_Type))
4759 and then Compile_Time_Known_Value (Type_High_Bound (P_Type))
4761 Freeze_Fixed_Point_Type (Base_Type (P_Type));
4764 -- For array case, get type of proper index
4770 Ndim := UI_To_Int (Expr_Value (E1));
4773 Indx := First_Index (P_Type);
4774 for J in 1 .. Ndim - 1 loop
4778 -- If no index type, get out (some other error occurred, and
4779 -- we don't have enough information to complete the job!)
4787 Ityp := Etype (Indx);
4790 -- A discrete range in an index constraint is allowed to be a
4791 -- subtype indication. This is syntactically a pain, but should
4792 -- not propagate to the entity for the corresponding index subtype.
4793 -- After checking that the subtype indication is legal, the range
4794 -- of the subtype indication should be transfered to the entity.
4795 -- The attributes for the bounds should remain the simple retrievals
4796 -- that they are now.
4798 Lo_Bound := Type_Low_Bound (Ityp);
4799 Hi_Bound := Type_High_Bound (Ityp);
4801 if not Is_Static_Subtype (Ityp) then
4806 -------------------------------
4807 -- Statically_Denotes_Entity --
4808 -------------------------------
4810 function Statically_Denotes_Entity (N : Node_Id) return Boolean is
4814 if not Is_Entity_Name (N) then
4821 Nkind (Parent (E)) /= N_Object_Renaming_Declaration
4822 or else Statically_Denotes_Entity (Renamed_Object (E));
4823 end Statically_Denotes_Entity;
4825 -- Start of processing for Eval_Attribute
4828 -- Acquire first two expressions (at the moment, no attributes
4829 -- take more than two expressions in any case).
4831 if Present (Expressions (N)) then
4832 E1 := First (Expressions (N));
4839 -- Special processing for Enabled attribute. This attribute has a very
4840 -- special prefix, and the easiest way to avoid lots of special checks
4841 -- to protect this special prefix from causing trouble is to deal with
4842 -- this attribute immediately and be done with it.
4844 if Id = Attribute_Enabled then
4846 -- Evaluate the Enabled attribute
4848 -- We skip evaluation if the expander is not active. This is not just
4849 -- an optimization. It is of key importance that we not rewrite the
4850 -- attribute in a generic template, since we want to pick up the
4851 -- setting of the check in the instance, and testing expander active
4852 -- is as easy way of doing this as any.
4854 if Expander_Active then
4856 C : constant Check_Id := Get_Check_Id (Chars (P));
4861 if C in Predefined_Check_Id then
4862 R := Scope_Suppress (C);
4864 R := Is_Check_Suppressed (Empty, C);
4868 R := Is_Check_Suppressed (Entity (E1), C);
4872 Rewrite (N, New_Occurrence_Of (Standard_False, Loc));
4874 Rewrite (N, New_Occurrence_Of (Standard_True, Loc));
4882 -- Special processing for cases where the prefix is an object. For
4883 -- this purpose, a string literal counts as an object (attributes
4884 -- of string literals can only appear in generated code).
4886 if Is_Object_Reference (P) or else Nkind (P) = N_String_Literal then
4888 -- For Component_Size, the prefix is an array object, and we apply
4889 -- the attribute to the type of the object. This is allowed for
4890 -- both unconstrained and constrained arrays, since the bounds
4891 -- have no influence on the value of this attribute.
4893 if Id = Attribute_Component_Size then
4894 P_Entity := Etype (P);
4896 -- For First and Last, the prefix is an array object, and we apply
4897 -- the attribute to the type of the array, but we need a constrained
4898 -- type for this, so we use the actual subtype if available.
4900 elsif Id = Attribute_First
4904 Id = Attribute_Length
4907 AS : constant Entity_Id := Get_Actual_Subtype_If_Available (P);
4910 if Present (AS) and then Is_Constrained (AS) then
4913 -- If we have an unconstrained type, cannot fold
4921 -- For Size, give size of object if available, otherwise we
4922 -- cannot fold Size.
4924 elsif Id = Attribute_Size then
4925 if Is_Entity_Name (P)
4926 and then Known_Esize (Entity (P))
4928 Compile_Time_Known_Attribute (N, Esize (Entity (P)));
4936 -- For Alignment, give size of object if available, otherwise we
4937 -- cannot fold Alignment.
4939 elsif Id = Attribute_Alignment then
4940 if Is_Entity_Name (P)
4941 and then Known_Alignment (Entity (P))
4943 Fold_Uint (N, Alignment (Entity (P)), False);
4951 -- No other attributes for objects are folded
4958 -- Cases where P is not an object. Cannot do anything if P is
4959 -- not the name of an entity.
4961 elsif not Is_Entity_Name (P) then
4965 -- Otherwise get prefix entity
4968 P_Entity := Entity (P);
4971 -- At this stage P_Entity is the entity to which the attribute
4972 -- is to be applied. This is usually simply the entity of the
4973 -- prefix, except in some cases of attributes for objects, where
4974 -- as described above, we apply the attribute to the object type.
4976 -- First foldable possibility is a scalar or array type (RM 4.9(7))
4977 -- that is not generic (generic types are eliminated by RM 4.9(25)).
4978 -- Note we allow non-static non-generic types at this stage as further
4981 if Is_Type (P_Entity)
4982 and then (Is_Scalar_Type (P_Entity) or Is_Array_Type (P_Entity))
4983 and then (not Is_Generic_Type (P_Entity))
4987 -- Second foldable possibility is an array object (RM 4.9(8))
4989 elsif (Ekind (P_Entity) = E_Variable
4991 Ekind (P_Entity) = E_Constant)
4992 and then Is_Array_Type (Etype (P_Entity))
4993 and then (not Is_Generic_Type (Etype (P_Entity)))
4995 P_Type := Etype (P_Entity);
4997 -- If the entity is an array constant with an unconstrained nominal
4998 -- subtype then get the type from the initial value. If the value has
4999 -- been expanded into assignments, there is no expression and the
5000 -- attribute reference remains dynamic.
5001 -- We could do better here and retrieve the type ???
5003 if Ekind (P_Entity) = E_Constant
5004 and then not Is_Constrained (P_Type)
5006 if No (Constant_Value (P_Entity)) then
5009 P_Type := Etype (Constant_Value (P_Entity));
5013 -- Definite must be folded if the prefix is not a generic type,
5014 -- that is to say if we are within an instantiation. Same processing
5015 -- applies to the GNAT attributes Has_Discriminants, Type_Class,
5016 -- and Unconstrained_Array.
5018 elsif (Id = Attribute_Definite
5020 Id = Attribute_Has_Access_Values
5022 Id = Attribute_Has_Discriminants
5024 Id = Attribute_Type_Class
5026 Id = Attribute_Unconstrained_Array)
5027 and then not Is_Generic_Type (P_Entity)
5031 -- We can fold 'Size applied to a type if the size is known
5032 -- (as happens for a size from an attribute definition clause).
5033 -- At this stage, this can happen only for types (e.g. record
5034 -- types) for which the size is always non-static. We exclude
5035 -- generic types from consideration (since they have bogus
5036 -- sizes set within templates).
5038 elsif Id = Attribute_Size
5039 and then Is_Type (P_Entity)
5040 and then (not Is_Generic_Type (P_Entity))
5041 and then Known_Static_RM_Size (P_Entity)
5043 Compile_Time_Known_Attribute (N, RM_Size (P_Entity));
5046 -- We can fold 'Alignment applied to a type if the alignment is known
5047 -- (as happens for an alignment from an attribute definition clause).
5048 -- At this stage, this can happen only for types (e.g. record
5049 -- types) for which the size is always non-static. We exclude
5050 -- generic types from consideration (since they have bogus
5051 -- sizes set within templates).
5053 elsif Id = Attribute_Alignment
5054 and then Is_Type (P_Entity)
5055 and then (not Is_Generic_Type (P_Entity))
5056 and then Known_Alignment (P_Entity)
5058 Compile_Time_Known_Attribute (N, Alignment (P_Entity));
5061 -- If this is an access attribute that is known to fail accessibility
5062 -- check, rewrite accordingly.
5064 elsif Attribute_Name (N) = Name_Access
5065 and then Raises_Constraint_Error (N)
5068 Make_Raise_Program_Error (Loc,
5069 Reason => PE_Accessibility_Check_Failed));
5070 Set_Etype (N, C_Type);
5073 -- No other cases are foldable (they certainly aren't static, and at
5074 -- the moment we don't try to fold any cases other than these three).
5081 -- If either attribute or the prefix is Any_Type, then propagate
5082 -- Any_Type to the result and don't do anything else at all.
5084 if P_Type = Any_Type
5085 or else (Present (E1) and then Etype (E1) = Any_Type)
5086 or else (Present (E2) and then Etype (E2) = Any_Type)
5088 Set_Etype (N, Any_Type);
5092 -- Scalar subtype case. We have not yet enforced the static requirement
5093 -- of (RM 4.9(7)) and we don't intend to just yet, since there are cases
5094 -- of non-static attribute references (e.g. S'Digits for a non-static
5095 -- floating-point type, which we can compute at compile time).
5097 -- Note: this folding of non-static attributes is not simply a case of
5098 -- optimization. For many of the attributes affected, Gigi cannot handle
5099 -- the attribute and depends on the front end having folded them away.
5101 -- Note: although we don't require staticness at this stage, we do set
5102 -- the Static variable to record the staticness, for easy reference by
5103 -- those attributes where it matters (e.g. Succ and Pred), and also to
5104 -- be used to ensure that non-static folded things are not marked as
5105 -- being static (a check that is done right at the end).
5107 P_Root_Type := Root_Type (P_Type);
5108 P_Base_Type := Base_Type (P_Type);
5110 -- If the root type or base type is generic, then we cannot fold. This
5111 -- test is needed because subtypes of generic types are not always
5112 -- marked as being generic themselves (which seems odd???)
5114 if Is_Generic_Type (P_Root_Type)
5115 or else Is_Generic_Type (P_Base_Type)
5120 if Is_Scalar_Type (P_Type) then
5121 Static := Is_OK_Static_Subtype (P_Type);
5123 -- Array case. We enforce the constrained requirement of (RM 4.9(7-8))
5124 -- since we can't do anything with unconstrained arrays. In addition,
5125 -- only the First, Last and Length attributes are possibly static.
5127 -- Definite, Has_Access_Values, Has_Discriminants, Type_Class, and
5128 -- Unconstrained_Array are again exceptions, because they apply as
5129 -- well to unconstrained types.
5131 -- In addition Component_Size is an exception since it is possibly
5132 -- foldable, even though it is never static, and it does apply to
5133 -- unconstrained arrays. Furthermore, it is essential to fold this
5134 -- in the packed case, since otherwise the value will be incorrect.
5136 elsif Id = Attribute_Definite
5138 Id = Attribute_Has_Access_Values
5140 Id = Attribute_Has_Discriminants
5142 Id = Attribute_Type_Class
5144 Id = Attribute_Unconstrained_Array
5146 Id = Attribute_Component_Size
5151 if not Is_Constrained (P_Type)
5152 or else (Id /= Attribute_First and then
5153 Id /= Attribute_Last and then
5154 Id /= Attribute_Length)
5160 -- The rules in (RM 4.9(7,8)) require a static array, but as in the
5161 -- scalar case, we hold off on enforcing staticness, since there are
5162 -- cases which we can fold at compile time even though they are not
5163 -- static (e.g. 'Length applied to a static index, even though other
5164 -- non-static indexes make the array type non-static). This is only
5165 -- an optimization, but it falls out essentially free, so why not.
5166 -- Again we compute the variable Static for easy reference later
5167 -- (note that no array attributes are static in Ada 83).
5169 Static := Ada_Version >= Ada_95
5170 and then Statically_Denotes_Entity (P);
5176 N := First_Index (P_Type);
5177 while Present (N) loop
5178 Static := Static and then Is_Static_Subtype (Etype (N));
5180 -- If however the index type is generic, attributes cannot
5183 if Is_Generic_Type (Etype (N))
5184 and then Id /= Attribute_Component_Size
5194 -- Check any expressions that are present. Note that these expressions,
5195 -- depending on the particular attribute type, are either part of the
5196 -- attribute designator, or they are arguments in a case where the
5197 -- attribute reference returns a function. In the latter case, the
5198 -- rule in (RM 4.9(22)) applies and in particular requires the type
5199 -- of the expressions to be scalar in order for the attribute to be
5200 -- considered to be static.
5207 while Present (E) loop
5209 -- If expression is not static, then the attribute reference
5210 -- result certainly cannot be static.
5212 if not Is_Static_Expression (E) then
5216 -- If the result is not known at compile time, or is not of
5217 -- a scalar type, then the result is definitely not static,
5218 -- so we can quit now.
5220 if not Compile_Time_Known_Value (E)
5221 or else not Is_Scalar_Type (Etype (E))
5223 -- An odd special case, if this is a Pos attribute, this
5224 -- is where we need to apply a range check since it does
5225 -- not get done anywhere else.
5227 if Id = Attribute_Pos then
5228 if Is_Integer_Type (Etype (E)) then
5229 Apply_Range_Check (E, Etype (N));
5236 -- If the expression raises a constraint error, then so does
5237 -- the attribute reference. We keep going in this case because
5238 -- we are still interested in whether the attribute reference
5239 -- is static even if it is not static.
5241 elsif Raises_Constraint_Error (E) then
5242 Set_Raises_Constraint_Error (N);
5248 if Raises_Constraint_Error (Prefix (N)) then
5253 -- Deal with the case of a static attribute reference that raises
5254 -- constraint error. The Raises_Constraint_Error flag will already
5255 -- have been set, and the Static flag shows whether the attribute
5256 -- reference is static. In any case we certainly can't fold such an
5257 -- attribute reference.
5259 -- Note that the rewriting of the attribute node with the constraint
5260 -- error node is essential in this case, because otherwise Gigi might
5261 -- blow up on one of the attributes it never expects to see.
5263 -- The constraint_error node must have the type imposed by the context,
5264 -- to avoid spurious errors in the enclosing expression.
5266 if Raises_Constraint_Error (N) then
5268 Make_Raise_Constraint_Error (Sloc (N),
5269 Reason => CE_Range_Check_Failed);
5270 Set_Etype (CE_Node, Etype (N));
5271 Set_Raises_Constraint_Error (CE_Node);
5273 Rewrite (N, Relocate_Node (CE_Node));
5274 Set_Is_Static_Expression (N, Static);
5278 -- At this point we have a potentially foldable attribute reference.
5279 -- If Static is set, then the attribute reference definitely obeys
5280 -- the requirements in (RM 4.9(7,8,22)), and it definitely can be
5281 -- folded. If Static is not set, then the attribute may or may not
5282 -- be foldable, and the individual attribute processing routines
5283 -- test Static as required in cases where it makes a difference.
5285 -- In the case where Static is not set, we do know that all the
5286 -- expressions present are at least known at compile time (we
5287 -- assumed above that if this was not the case, then there was
5288 -- no hope of static evaluation). However, we did not require
5289 -- that the bounds of the prefix type be compile time known,
5290 -- let alone static). That's because there are many attributes
5291 -- that can be computed at compile time on non-static subtypes,
5292 -- even though such references are not static expressions.
5300 when Attribute_Adjacent =>
5303 (P_Root_Type, Expr_Value_R (E1), Expr_Value_R (E2)), Static);
5309 when Attribute_Aft =>
5310 Fold_Uint (N, UI_From_Int (Aft_Value), True);
5316 when Attribute_Alignment => Alignment_Block : declare
5317 P_TypeA : constant Entity_Id := Underlying_Type (P_Type);
5320 -- Fold if alignment is set and not otherwise
5322 if Known_Alignment (P_TypeA) then
5323 Fold_Uint (N, Alignment (P_TypeA), Is_Discrete_Type (P_TypeA));
5325 end Alignment_Block;
5331 -- Can only be folded in No_Ast_Handler case
5333 when Attribute_AST_Entry =>
5334 if not Is_AST_Entry (P_Entity) then
5336 New_Occurrence_Of (RTE (RE_No_AST_Handler), Loc));
5345 -- Bit can never be folded
5347 when Attribute_Bit =>
5354 -- Body_version can never be static
5356 when Attribute_Body_Version =>
5363 when Attribute_Ceiling =>
5365 Eval_Fat.Ceiling (P_Root_Type, Expr_Value_R (E1)), Static);
5367 --------------------
5368 -- Component_Size --
5369 --------------------
5371 when Attribute_Component_Size =>
5372 if Known_Static_Component_Size (P_Type) then
5373 Fold_Uint (N, Component_Size (P_Type), False);
5380 when Attribute_Compose =>
5383 (P_Root_Type, Expr_Value_R (E1), Expr_Value (E2)),
5390 -- Constrained is never folded for now, there may be cases that
5391 -- could be handled at compile time. to be looked at later.
5393 when Attribute_Constrained =>
5400 when Attribute_Copy_Sign =>
5403 (P_Root_Type, Expr_Value_R (E1), Expr_Value_R (E2)), Static);
5409 when Attribute_Delta =>
5410 Fold_Ureal (N, Delta_Value (P_Type), True);
5416 when Attribute_Definite =>
5417 Rewrite (N, New_Occurrence_Of (
5418 Boolean_Literals (not Is_Indefinite_Subtype (P_Entity)), Loc));
5419 Analyze_And_Resolve (N, Standard_Boolean);
5425 when Attribute_Denorm =>
5427 (N, UI_From_Int (Boolean'Pos (Denorm_On_Target)), True);
5433 when Attribute_Digits =>
5434 Fold_Uint (N, Digits_Value (P_Type), True);
5440 when Attribute_Emax =>
5442 -- Ada 83 attribute is defined as (RM83 3.5.8)
5444 -- T'Emax = 4 * T'Mantissa
5446 Fold_Uint (N, 4 * Mantissa, True);
5452 when Attribute_Enum_Rep =>
5454 -- For an enumeration type with a non-standard representation use
5455 -- the Enumeration_Rep field of the proper constant. Note that this
5456 -- will not work for types Character/Wide_[Wide-]Character, since no
5457 -- real entities are created for the enumeration literals, but that
5458 -- does not matter since these two types do not have non-standard
5459 -- representations anyway.
5461 if Is_Enumeration_Type (P_Type)
5462 and then Has_Non_Standard_Rep (P_Type)
5464 Fold_Uint (N, Enumeration_Rep (Expr_Value_E (E1)), Static);
5466 -- For enumeration types with standard representations and all
5467 -- other cases (i.e. all integer and modular types), Enum_Rep
5468 -- is equivalent to Pos.
5471 Fold_Uint (N, Expr_Value (E1), Static);
5478 when Attribute_Epsilon =>
5480 -- Ada 83 attribute is defined as (RM83 3.5.8)
5482 -- T'Epsilon = 2.0**(1 - T'Mantissa)
5484 Fold_Ureal (N, Ureal_2 ** (1 - Mantissa), True);
5490 when Attribute_Exponent =>
5492 Eval_Fat.Exponent (P_Root_Type, Expr_Value_R (E1)), Static);
5498 when Attribute_First => First_Attr :
5502 if Compile_Time_Known_Value (Lo_Bound) then
5503 if Is_Real_Type (P_Type) then
5504 Fold_Ureal (N, Expr_Value_R (Lo_Bound), Static);
5506 Fold_Uint (N, Expr_Value (Lo_Bound), Static);
5515 when Attribute_Fixed_Value =>
5522 when Attribute_Floor =>
5524 Eval_Fat.Floor (P_Root_Type, Expr_Value_R (E1)), Static);
5530 when Attribute_Fore =>
5531 if Compile_Time_Known_Bounds (P_Type) then
5532 Fold_Uint (N, UI_From_Int (Fore_Value), Static);
5539 when Attribute_Fraction =>
5541 Eval_Fat.Fraction (P_Root_Type, Expr_Value_R (E1)), Static);
5543 -----------------------
5544 -- Has_Access_Values --
5545 -----------------------
5547 when Attribute_Has_Access_Values =>
5548 Rewrite (N, New_Occurrence_Of
5549 (Boolean_Literals (Has_Access_Values (P_Root_Type)), Loc));
5550 Analyze_And_Resolve (N, Standard_Boolean);
5552 -----------------------
5553 -- Has_Discriminants --
5554 -----------------------
5556 when Attribute_Has_Discriminants =>
5557 Rewrite (N, New_Occurrence_Of (
5558 Boolean_Literals (Has_Discriminants (P_Entity)), Loc));
5559 Analyze_And_Resolve (N, Standard_Boolean);
5565 when Attribute_Identity =>
5572 -- Image is a scalar attribute, but is never static, because it is
5573 -- not a static function (having a non-scalar argument (RM 4.9(22))
5574 -- However, we can constant-fold the image of an enumeration literal
5575 -- if names are available.
5577 when Attribute_Image =>
5578 if Is_Entity_Name (E1)
5579 and then Ekind (Entity (E1)) = E_Enumeration_Literal
5580 and then not Discard_Names (First_Subtype (Etype (E1)))
5581 and then not Global_Discard_Names
5584 Lit : constant Entity_Id := Entity (E1);
5588 Get_Unqualified_Decoded_Name_String (Chars (Lit));
5589 Set_Casing (All_Upper_Case);
5590 Store_String_Chars (Name_Buffer (1 .. Name_Len));
5592 Rewrite (N, Make_String_Literal (Loc, Strval => Str));
5593 Analyze_And_Resolve (N, Standard_String);
5594 Set_Is_Static_Expression (N, False);
5602 -- Img is a scalar attribute, but is never static, because it is
5603 -- not a static function (having a non-scalar argument (RM 4.9(22))
5605 when Attribute_Img =>
5612 when Attribute_Integer_Value =>
5619 when Attribute_Large =>
5621 -- For fixed-point, we use the identity:
5623 -- T'Large = (2.0**T'Mantissa - 1.0) * T'Small
5625 if Is_Fixed_Point_Type (P_Type) then
5627 Make_Op_Multiply (Loc,
5629 Make_Op_Subtract (Loc,
5633 Make_Real_Literal (Loc, Ureal_2),
5635 Make_Attribute_Reference (Loc,
5637 Attribute_Name => Name_Mantissa)),
5638 Right_Opnd => Make_Real_Literal (Loc, Ureal_1)),
5641 Make_Real_Literal (Loc, Small_Value (Entity (P)))));
5643 Analyze_And_Resolve (N, C_Type);
5645 -- Floating-point (Ada 83 compatibility)
5648 -- Ada 83 attribute is defined as (RM83 3.5.8)
5650 -- T'Large = 2.0**T'Emax * (1.0 - 2.0**(-T'Mantissa))
5654 -- T'Emax = 4 * T'Mantissa
5657 Ureal_2 ** (4 * Mantissa) * (Ureal_1 - Ureal_2 ** (-Mantissa)),
5665 when Attribute_Last => Last :
5669 if Compile_Time_Known_Value (Hi_Bound) then
5670 if Is_Real_Type (P_Type) then
5671 Fold_Ureal (N, Expr_Value_R (Hi_Bound), Static);
5673 Fold_Uint (N, Expr_Value (Hi_Bound), Static);
5682 when Attribute_Leading_Part =>
5684 Eval_Fat.Leading_Part
5685 (P_Root_Type, Expr_Value_R (E1), Expr_Value (E2)), Static);
5691 when Attribute_Length => Length : declare
5695 -- In the case of a generic index type, the bounds may
5696 -- appear static but the computation is not meaningful,
5697 -- and may generate a spurious warning.
5699 Ind := First_Index (P_Type);
5701 while Present (Ind) loop
5702 if Is_Generic_Type (Etype (Ind)) then
5711 if Compile_Time_Known_Value (Lo_Bound)
5712 and then Compile_Time_Known_Value (Hi_Bound)
5715 UI_Max (0, 1 + (Expr_Value (Hi_Bound) - Expr_Value (Lo_Bound))),
5724 when Attribute_Machine =>
5727 (P_Root_Type, Expr_Value_R (E1), Eval_Fat.Round, N),
5734 when Attribute_Machine_Emax =>
5735 Float_Attribute_Universal_Integer (
5743 AAMPL_Machine_Emax);
5749 when Attribute_Machine_Emin =>
5750 Float_Attribute_Universal_Integer (
5758 AAMPL_Machine_Emin);
5760 ----------------------
5761 -- Machine_Mantissa --
5762 ----------------------
5764 when Attribute_Machine_Mantissa =>
5765 Float_Attribute_Universal_Integer (
5766 IEEES_Machine_Mantissa,
5767 IEEEL_Machine_Mantissa,
5768 IEEEX_Machine_Mantissa,
5769 VAXFF_Machine_Mantissa,
5770 VAXDF_Machine_Mantissa,
5771 VAXGF_Machine_Mantissa,
5772 AAMPS_Machine_Mantissa,
5773 AAMPL_Machine_Mantissa);
5775 -----------------------
5776 -- Machine_Overflows --
5777 -----------------------
5779 when Attribute_Machine_Overflows =>
5781 -- Always true for fixed-point
5783 if Is_Fixed_Point_Type (P_Type) then
5784 Fold_Uint (N, True_Value, True);
5786 -- Floating point case
5790 UI_From_Int (Boolean'Pos (Machine_Overflows_On_Target)),
5798 when Attribute_Machine_Radix =>
5799 if Is_Fixed_Point_Type (P_Type) then
5800 if Is_Decimal_Fixed_Point_Type (P_Type)
5801 and then Machine_Radix_10 (P_Type)
5803 Fold_Uint (N, Uint_10, True);
5805 Fold_Uint (N, Uint_2, True);
5808 -- All floating-point type always have radix 2
5811 Fold_Uint (N, Uint_2, True);
5814 ----------------------
5815 -- Machine_Rounding --
5816 ----------------------
5818 -- Note: for the folding case, it is fine to treat Machine_Rounding
5819 -- exactly the same way as Rounding, since this is one of the allowed
5820 -- behaviors, and performance is not an issue here. It might be a bit
5821 -- better to give the same result as it would give at run-time, even
5822 -- though the non-determinism is certainly permitted.
5824 when Attribute_Machine_Rounding =>
5826 Eval_Fat.Rounding (P_Root_Type, Expr_Value_R (E1)), Static);
5828 --------------------
5829 -- Machine_Rounds --
5830 --------------------
5832 when Attribute_Machine_Rounds =>
5834 -- Always False for fixed-point
5836 if Is_Fixed_Point_Type (P_Type) then
5837 Fold_Uint (N, False_Value, True);
5839 -- Else yield proper floating-point result
5843 (N, UI_From_Int (Boolean'Pos (Machine_Rounds_On_Target)), True);
5850 -- Note: Machine_Size is identical to Object_Size
5852 when Attribute_Machine_Size => Machine_Size : declare
5853 P_TypeA : constant Entity_Id := Underlying_Type (P_Type);
5856 if Known_Esize (P_TypeA) then
5857 Fold_Uint (N, Esize (P_TypeA), True);
5865 when Attribute_Mantissa =>
5867 -- Fixed-point mantissa
5869 if Is_Fixed_Point_Type (P_Type) then
5871 -- Compile time foldable case
5873 if Compile_Time_Known_Value (Type_Low_Bound (P_Type))
5875 Compile_Time_Known_Value (Type_High_Bound (P_Type))
5877 -- The calculation of the obsolete Ada 83 attribute Mantissa
5878 -- is annoying, because of AI00143, quoted here:
5880 -- !question 84-01-10
5882 -- Consider the model numbers for F:
5884 -- type F is delta 1.0 range -7.0 .. 8.0;
5886 -- The wording requires that F'MANTISSA be the SMALLEST
5887 -- integer number for which each bound of the specified
5888 -- range is either a model number or lies at most small
5889 -- distant from a model number. This means F'MANTISSA
5890 -- is required to be 3 since the range -7.0 .. 7.0 fits
5891 -- in 3 signed bits, and 8 is "at most" 1.0 from a model
5892 -- number, namely, 7. Is this analysis correct? Note that
5893 -- this implies the upper bound of the range is not
5894 -- represented as a model number.
5896 -- !response 84-03-17
5898 -- The analysis is correct. The upper and lower bounds for
5899 -- a fixed point type can lie outside the range of model
5910 LBound := Expr_Value_R (Type_Low_Bound (P_Type));
5911 UBound := Expr_Value_R (Type_High_Bound (P_Type));
5912 Bound := UR_Max (UR_Abs (LBound), UR_Abs (UBound));
5913 Max_Man := UR_Trunc (Bound / Small_Value (P_Type));
5915 -- If the Bound is exactly a model number, i.e. a multiple
5916 -- of Small, then we back it off by one to get the integer
5917 -- value that must be representable.
5919 if Small_Value (P_Type) * Max_Man = Bound then
5920 Max_Man := Max_Man - 1;
5923 -- Now find corresponding size = Mantissa value
5926 while 2 ** Siz < Max_Man loop
5930 Fold_Uint (N, Siz, True);
5934 -- The case of dynamic bounds cannot be evaluated at compile
5935 -- time. Instead we use a runtime routine (see Exp_Attr).
5940 -- Floating-point Mantissa
5943 Fold_Uint (N, Mantissa, True);
5950 when Attribute_Max => Max :
5952 if Is_Real_Type (P_Type) then
5954 (N, UR_Max (Expr_Value_R (E1), Expr_Value_R (E2)), Static);
5956 Fold_Uint (N, UI_Max (Expr_Value (E1), Expr_Value (E2)), Static);
5960 ----------------------------------
5961 -- Max_Size_In_Storage_Elements --
5962 ----------------------------------
5964 -- Max_Size_In_Storage_Elements is simply the Size rounded up to a
5965 -- Storage_Unit boundary. We can fold any cases for which the size
5966 -- is known by the front end.
5968 when Attribute_Max_Size_In_Storage_Elements =>
5969 if Known_Esize (P_Type) then
5971 (Esize (P_Type) + System_Storage_Unit - 1) /
5972 System_Storage_Unit,
5976 --------------------
5977 -- Mechanism_Code --
5978 --------------------
5980 when Attribute_Mechanism_Code =>
5984 Mech : Mechanism_Type;
5988 Mech := Mechanism (P_Entity);
5991 Val := UI_To_Int (Expr_Value (E1));
5993 Formal := First_Formal (P_Entity);
5994 for J in 1 .. Val - 1 loop
5995 Next_Formal (Formal);
5997 Mech := Mechanism (Formal);
6001 Fold_Uint (N, UI_From_Int (Int (-Mech)), True);
6009 when Attribute_Min => Min :
6011 if Is_Real_Type (P_Type) then
6013 (N, UR_Min (Expr_Value_R (E1), Expr_Value_R (E2)), Static);
6016 (N, UI_Min (Expr_Value (E1), Expr_Value (E2)), Static);
6024 when Attribute_Mod =>
6026 (N, UI_Mod (Expr_Value (E1), Modulus (P_Base_Type)), Static);
6032 when Attribute_Model =>
6034 Eval_Fat.Model (P_Root_Type, Expr_Value_R (E1)), Static);
6040 when Attribute_Model_Emin =>
6041 Float_Attribute_Universal_Integer (
6055 when Attribute_Model_Epsilon =>
6056 Float_Attribute_Universal_Real (
6057 IEEES_Model_Epsilon'Universal_Literal_String,
6058 IEEEL_Model_Epsilon'Universal_Literal_String,
6059 IEEEX_Model_Epsilon'Universal_Literal_String,
6060 VAXFF_Model_Epsilon'Universal_Literal_String,
6061 VAXDF_Model_Epsilon'Universal_Literal_String,
6062 VAXGF_Model_Epsilon'Universal_Literal_String,
6063 AAMPS_Model_Epsilon'Universal_Literal_String,
6064 AAMPL_Model_Epsilon'Universal_Literal_String);
6066 --------------------
6067 -- Model_Mantissa --
6068 --------------------
6070 when Attribute_Model_Mantissa =>
6071 Float_Attribute_Universal_Integer (
6072 IEEES_Model_Mantissa,
6073 IEEEL_Model_Mantissa,
6074 IEEEX_Model_Mantissa,
6075 VAXFF_Model_Mantissa,
6076 VAXDF_Model_Mantissa,
6077 VAXGF_Model_Mantissa,
6078 AAMPS_Model_Mantissa,
6079 AAMPL_Model_Mantissa);
6085 when Attribute_Model_Small =>
6086 Float_Attribute_Universal_Real (
6087 IEEES_Model_Small'Universal_Literal_String,
6088 IEEEL_Model_Small'Universal_Literal_String,
6089 IEEEX_Model_Small'Universal_Literal_String,
6090 VAXFF_Model_Small'Universal_Literal_String,
6091 VAXDF_Model_Small'Universal_Literal_String,
6092 VAXGF_Model_Small'Universal_Literal_String,
6093 AAMPS_Model_Small'Universal_Literal_String,
6094 AAMPL_Model_Small'Universal_Literal_String);
6100 when Attribute_Modulus =>
6101 Fold_Uint (N, Modulus (P_Type), True);
6103 --------------------
6104 -- Null_Parameter --
6105 --------------------
6107 -- Cannot fold, we know the value sort of, but the whole point is
6108 -- that there is no way to talk about this imaginary value except
6109 -- by using the attribute, so we leave it the way it is.
6111 when Attribute_Null_Parameter =>
6118 -- The Object_Size attribute for a type returns the Esize of the
6119 -- type and can be folded if this value is known.
6121 when Attribute_Object_Size => Object_Size : declare
6122 P_TypeA : constant Entity_Id := Underlying_Type (P_Type);
6125 if Known_Esize (P_TypeA) then
6126 Fold_Uint (N, Esize (P_TypeA), True);
6130 -------------------------
6131 -- Passed_By_Reference --
6132 -------------------------
6134 -- Scalar types are never passed by reference
6136 when Attribute_Passed_By_Reference =>
6137 Fold_Uint (N, False_Value, True);
6143 when Attribute_Pos =>
6144 Fold_Uint (N, Expr_Value (E1), True);
6150 when Attribute_Pred => Pred :
6152 -- Floating-point case
6154 if Is_Floating_Point_Type (P_Type) then
6156 Eval_Fat.Pred (P_Root_Type, Expr_Value_R (E1)), Static);
6160 elsif Is_Fixed_Point_Type (P_Type) then
6162 Expr_Value_R (E1) - Small_Value (P_Type), True);
6164 -- Modular integer case (wraps)
6166 elsif Is_Modular_Integer_Type (P_Type) then
6167 Fold_Uint (N, (Expr_Value (E1) - 1) mod Modulus (P_Type), Static);
6169 -- Other scalar cases
6172 pragma Assert (Is_Scalar_Type (P_Type));
6174 if Is_Enumeration_Type (P_Type)
6175 and then Expr_Value (E1) =
6176 Expr_Value (Type_Low_Bound (P_Base_Type))
6178 Apply_Compile_Time_Constraint_Error
6179 (N, "Pred of `&''First`",
6180 CE_Overflow_Check_Failed,
6182 Warn => not Static);
6188 Fold_Uint (N, Expr_Value (E1) - 1, Static);
6196 -- No processing required, because by this stage, Range has been
6197 -- replaced by First .. Last, so this branch can never be taken.
6199 when Attribute_Range =>
6200 raise Program_Error;
6206 when Attribute_Range_Length =>
6209 if Compile_Time_Known_Value (Hi_Bound)
6210 and then Compile_Time_Known_Value (Lo_Bound)
6214 (0, Expr_Value (Hi_Bound) - Expr_Value (Lo_Bound) + 1),
6222 when Attribute_Remainder => Remainder : declare
6223 X : constant Ureal := Expr_Value_R (E1);
6224 Y : constant Ureal := Expr_Value_R (E2);
6227 if UR_Is_Zero (Y) then
6228 Apply_Compile_Time_Constraint_Error
6229 (N, "division by zero in Remainder",
6230 CE_Overflow_Check_Failed,
6231 Warn => not Static);
6237 Fold_Ureal (N, Eval_Fat.Remainder (P_Root_Type, X, Y), Static);
6244 when Attribute_Round => Round :
6250 -- First we get the (exact result) in units of small
6252 Sr := Expr_Value_R (E1) / Small_Value (C_Type);
6254 -- Now round that exactly to an integer
6256 Si := UR_To_Uint (Sr);
6258 -- Finally the result is obtained by converting back to real
6260 Fold_Ureal (N, Si * Small_Value (C_Type), Static);
6267 when Attribute_Rounding =>
6269 Eval_Fat.Rounding (P_Root_Type, Expr_Value_R (E1)), Static);
6275 when Attribute_Safe_Emax =>
6276 Float_Attribute_Universal_Integer (
6290 when Attribute_Safe_First =>
6291 Float_Attribute_Universal_Real (
6292 IEEES_Safe_First'Universal_Literal_String,
6293 IEEEL_Safe_First'Universal_Literal_String,
6294 IEEEX_Safe_First'Universal_Literal_String,
6295 VAXFF_Safe_First'Universal_Literal_String,
6296 VAXDF_Safe_First'Universal_Literal_String,
6297 VAXGF_Safe_First'Universal_Literal_String,
6298 AAMPS_Safe_First'Universal_Literal_String,
6299 AAMPL_Safe_First'Universal_Literal_String);
6305 when Attribute_Safe_Large =>
6306 if Is_Fixed_Point_Type (P_Type) then
6308 (N, Expr_Value_R (Type_High_Bound (P_Base_Type)), Static);
6310 Float_Attribute_Universal_Real (
6311 IEEES_Safe_Large'Universal_Literal_String,
6312 IEEEL_Safe_Large'Universal_Literal_String,
6313 IEEEX_Safe_Large'Universal_Literal_String,
6314 VAXFF_Safe_Large'Universal_Literal_String,
6315 VAXDF_Safe_Large'Universal_Literal_String,
6316 VAXGF_Safe_Large'Universal_Literal_String,
6317 AAMPS_Safe_Large'Universal_Literal_String,
6318 AAMPL_Safe_Large'Universal_Literal_String);
6325 when Attribute_Safe_Last =>
6326 Float_Attribute_Universal_Real (
6327 IEEES_Safe_Last'Universal_Literal_String,
6328 IEEEL_Safe_Last'Universal_Literal_String,
6329 IEEEX_Safe_Last'Universal_Literal_String,
6330 VAXFF_Safe_Last'Universal_Literal_String,
6331 VAXDF_Safe_Last'Universal_Literal_String,
6332 VAXGF_Safe_Last'Universal_Literal_String,
6333 AAMPS_Safe_Last'Universal_Literal_String,
6334 AAMPL_Safe_Last'Universal_Literal_String);
6340 when Attribute_Safe_Small =>
6342 -- In Ada 95, the old Ada 83 attribute Safe_Small is redundant
6343 -- for fixed-point, since is the same as Small, but we implement
6344 -- it for backwards compatibility.
6346 if Is_Fixed_Point_Type (P_Type) then
6347 Fold_Ureal (N, Small_Value (P_Type), Static);
6349 -- Ada 83 Safe_Small for floating-point cases
6352 Float_Attribute_Universal_Real (
6353 IEEES_Safe_Small'Universal_Literal_String,
6354 IEEEL_Safe_Small'Universal_Literal_String,
6355 IEEEX_Safe_Small'Universal_Literal_String,
6356 VAXFF_Safe_Small'Universal_Literal_String,
6357 VAXDF_Safe_Small'Universal_Literal_String,
6358 VAXGF_Safe_Small'Universal_Literal_String,
6359 AAMPS_Safe_Small'Universal_Literal_String,
6360 AAMPL_Safe_Small'Universal_Literal_String);
6367 when Attribute_Scale =>
6368 Fold_Uint (N, Scale_Value (P_Type), True);
6374 when Attribute_Scaling =>
6377 (P_Root_Type, Expr_Value_R (E1), Expr_Value (E2)), Static);
6383 when Attribute_Signed_Zeros =>
6385 (N, UI_From_Int (Boolean'Pos (Signed_Zeros_On_Target)), Static);
6391 -- Size attribute returns the RM size. All scalar types can be folded,
6392 -- as well as any types for which the size is known by the front end,
6393 -- including any type for which a size attribute is specified.
6395 when Attribute_Size | Attribute_VADS_Size => Size : declare
6396 P_TypeA : constant Entity_Id := Underlying_Type (P_Type);
6399 if RM_Size (P_TypeA) /= Uint_0 then
6403 if Id = Attribute_VADS_Size or else Use_VADS_Size then
6405 S : constant Node_Id := Size_Clause (P_TypeA);
6408 -- If a size clause applies, then use the size from it.
6409 -- This is one of the rare cases where we can use the
6410 -- Size_Clause field for a subtype when Has_Size_Clause
6411 -- is False. Consider:
6413 -- type x is range 1 .. 64;
6414 -- for x'size use 12;
6415 -- subtype y is x range 0 .. 3;
6417 -- Here y has a size clause inherited from x, but normally
6418 -- it does not apply, and y'size is 2. However, y'VADS_Size
6419 -- is indeed 12 and not 2.
6422 and then Is_OK_Static_Expression (Expression (S))
6424 Fold_Uint (N, Expr_Value (Expression (S)), True);
6426 -- If no size is specified, then we simply use the object
6427 -- size in the VADS_Size case (e.g. Natural'Size is equal
6428 -- to Integer'Size, not one less).
6431 Fold_Uint (N, Esize (P_TypeA), True);
6435 -- Normal case (Size) in which case we want the RM_Size
6440 Static and then Is_Discrete_Type (P_TypeA));
6449 when Attribute_Small =>
6451 -- The floating-point case is present only for Ada 83 compatability.
6452 -- Note that strictly this is an illegal addition, since we are
6453 -- extending an Ada 95 defined attribute, but we anticipate an
6454 -- ARG ruling that will permit this.
6456 if Is_Floating_Point_Type (P_Type) then
6458 -- Ada 83 attribute is defined as (RM83 3.5.8)
6460 -- T'Small = 2.0**(-T'Emax - 1)
6464 -- T'Emax = 4 * T'Mantissa
6466 Fold_Ureal (N, Ureal_2 ** ((-(4 * Mantissa)) - 1), Static);
6468 -- Normal Ada 95 fixed-point case
6471 Fold_Ureal (N, Small_Value (P_Type), True);
6478 when Attribute_Stream_Size =>
6485 when Attribute_Succ => Succ :
6487 -- Floating-point case
6489 if Is_Floating_Point_Type (P_Type) then
6491 Eval_Fat.Succ (P_Root_Type, Expr_Value_R (E1)), Static);
6495 elsif Is_Fixed_Point_Type (P_Type) then
6497 Expr_Value_R (E1) + Small_Value (P_Type), Static);
6499 -- Modular integer case (wraps)
6501 elsif Is_Modular_Integer_Type (P_Type) then
6502 Fold_Uint (N, (Expr_Value (E1) + 1) mod Modulus (P_Type), Static);
6504 -- Other scalar cases
6507 pragma Assert (Is_Scalar_Type (P_Type));
6509 if Is_Enumeration_Type (P_Type)
6510 and then Expr_Value (E1) =
6511 Expr_Value (Type_High_Bound (P_Base_Type))
6513 Apply_Compile_Time_Constraint_Error
6514 (N, "Succ of `&''Last`",
6515 CE_Overflow_Check_Failed,
6517 Warn => not Static);
6522 Fold_Uint (N, Expr_Value (E1) + 1, Static);
6531 when Attribute_Truncation =>
6533 Eval_Fat.Truncation (P_Root_Type, Expr_Value_R (E1)), Static);
6539 when Attribute_Type_Class => Type_Class : declare
6540 Typ : constant Entity_Id := Underlying_Type (P_Base_Type);
6544 if Is_Descendent_Of_Address (Typ) then
6545 Id := RE_Type_Class_Address;
6547 elsif Is_Enumeration_Type (Typ) then
6548 Id := RE_Type_Class_Enumeration;
6550 elsif Is_Integer_Type (Typ) then
6551 Id := RE_Type_Class_Integer;
6553 elsif Is_Fixed_Point_Type (Typ) then
6554 Id := RE_Type_Class_Fixed_Point;
6556 elsif Is_Floating_Point_Type (Typ) then
6557 Id := RE_Type_Class_Floating_Point;
6559 elsif Is_Array_Type (Typ) then
6560 Id := RE_Type_Class_Array;
6562 elsif Is_Record_Type (Typ) then
6563 Id := RE_Type_Class_Record;
6565 elsif Is_Access_Type (Typ) then
6566 Id := RE_Type_Class_Access;
6568 elsif Is_Enumeration_Type (Typ) then
6569 Id := RE_Type_Class_Enumeration;
6571 elsif Is_Task_Type (Typ) then
6572 Id := RE_Type_Class_Task;
6574 -- We treat protected types like task types. It would make more
6575 -- sense to have another enumeration value, but after all the
6576 -- whole point of this feature is to be exactly DEC compatible,
6577 -- and changing the type Type_Clas would not meet this requirement.
6579 elsif Is_Protected_Type (Typ) then
6580 Id := RE_Type_Class_Task;
6582 -- Not clear if there are any other possibilities, but if there
6583 -- are, then we will treat them as the address case.
6586 Id := RE_Type_Class_Address;
6589 Rewrite (N, New_Occurrence_Of (RTE (Id), Loc));
6592 -----------------------
6593 -- Unbiased_Rounding --
6594 -----------------------
6596 when Attribute_Unbiased_Rounding =>
6598 Eval_Fat.Unbiased_Rounding (P_Root_Type, Expr_Value_R (E1)),
6601 -------------------------
6602 -- Unconstrained_Array --
6603 -------------------------
6605 when Attribute_Unconstrained_Array => Unconstrained_Array : declare
6606 Typ : constant Entity_Id := Underlying_Type (P_Type);
6609 Rewrite (N, New_Occurrence_Of (
6611 Is_Array_Type (P_Type)
6612 and then not Is_Constrained (Typ)), Loc));
6614 -- Analyze and resolve as boolean, note that this attribute is
6615 -- a static attribute in GNAT.
6617 Analyze_And_Resolve (N, Standard_Boolean);
6619 end Unconstrained_Array;
6625 -- Processing is shared with Size
6631 when Attribute_Val => Val :
6633 if Expr_Value (E1) < Expr_Value (Type_Low_Bound (P_Base_Type))
6635 Expr_Value (E1) > Expr_Value (Type_High_Bound (P_Base_Type))
6637 Apply_Compile_Time_Constraint_Error
6638 (N, "Val expression out of range",
6639 CE_Range_Check_Failed,
6640 Warn => not Static);
6646 Fold_Uint (N, Expr_Value (E1), Static);
6654 -- The Value_Size attribute for a type returns the RM size of the
6655 -- type. This an always be folded for scalar types, and can also
6656 -- be folded for non-scalar types if the size is set.
6658 when Attribute_Value_Size => Value_Size : declare
6659 P_TypeA : constant Entity_Id := Underlying_Type (P_Type);
6661 if RM_Size (P_TypeA) /= Uint_0 then
6662 Fold_Uint (N, RM_Size (P_TypeA), True);
6670 -- Version can never be static
6672 when Attribute_Version =>
6679 -- Wide_Image is a scalar attribute, but is never static, because it
6680 -- is not a static function (having a non-scalar argument (RM 4.9(22))
6682 when Attribute_Wide_Image =>
6685 ---------------------
6686 -- Wide_Wide_Image --
6687 ---------------------
6689 -- Wide_Wide_Image is a scalar attribute but is never static, because it
6690 -- is not a static function (having a non-scalar argument (RM 4.9(22)).
6692 when Attribute_Wide_Wide_Image =>
6695 ---------------------
6696 -- Wide_Wide_Width --
6697 ---------------------
6699 -- Processing for Wide_Wide_Width is combined with Width
6705 -- Processing for Wide_Width is combined with Width
6711 -- This processing also handles the case of Wide_[Wide_]Width
6713 when Attribute_Width |
6714 Attribute_Wide_Width |
6715 Attribute_Wide_Wide_Width => Width :
6717 if Compile_Time_Known_Bounds (P_Type) then
6719 -- Floating-point types
6721 if Is_Floating_Point_Type (P_Type) then
6723 -- Width is zero for a null range (RM 3.5 (38))
6725 if Expr_Value_R (Type_High_Bound (P_Type)) <
6726 Expr_Value_R (Type_Low_Bound (P_Type))
6728 Fold_Uint (N, Uint_0, True);
6731 -- For floating-point, we have +N.dddE+nnn where length
6732 -- of ddd is determined by type'Digits - 1, but is one
6733 -- if Digits is one (RM 3.5 (33)).
6735 -- nnn is set to 2 for Short_Float and Float (32 bit
6736 -- floats), and 3 for Long_Float and Long_Long_Float.
6737 -- For machines where Long_Long_Float is the IEEE
6738 -- extended precision type, the exponent takes 4 digits.
6742 Int'Max (2, UI_To_Int (Digits_Value (P_Type)));
6745 if Esize (P_Type) <= 32 then
6747 elsif Esize (P_Type) = 64 then
6753 Fold_Uint (N, UI_From_Int (Len), True);
6757 -- Fixed-point types
6759 elsif Is_Fixed_Point_Type (P_Type) then
6761 -- Width is zero for a null range (RM 3.5 (38))
6763 if Expr_Value (Type_High_Bound (P_Type)) <
6764 Expr_Value (Type_Low_Bound (P_Type))
6766 Fold_Uint (N, Uint_0, True);
6768 -- The non-null case depends on the specific real type
6771 -- For fixed-point type width is Fore + 1 + Aft (RM 3.5(34))
6774 (N, UI_From_Int (Fore_Value + 1 + Aft_Value), True);
6781 R : constant Entity_Id := Root_Type (P_Type);
6782 Lo : constant Uint :=
6783 Expr_Value (Type_Low_Bound (P_Type));
6784 Hi : constant Uint :=
6785 Expr_Value (Type_High_Bound (P_Type));
6798 -- Width for types derived from Standard.Character
6799 -- and Standard.Wide_[Wide_]Character.
6801 elsif R = Standard_Character
6802 or else R = Standard_Wide_Character
6803 or else R = Standard_Wide_Wide_Character
6807 -- Set W larger if needed
6809 for J in UI_To_Int (Lo) .. UI_To_Int (Hi) loop
6811 -- All wide characters look like Hex_hhhhhhhh
6817 C := Character'Val (J);
6819 -- Test for all cases where Character'Image
6820 -- yields an image that is longer than three
6821 -- characters. First the cases of Reserved_xxx
6822 -- names (length = 12).
6825 when Reserved_128 | Reserved_129 |
6826 Reserved_132 | Reserved_153
6830 when BS | HT | LF | VT | FF | CR |
6831 SO | SI | EM | FS | GS | RS |
6832 US | RI | MW | ST | PM
6836 when NUL | SOH | STX | ETX | EOT |
6837 ENQ | ACK | BEL | DLE | DC1 |
6838 DC2 | DC3 | DC4 | NAK | SYN |
6839 ETB | CAN | SUB | ESC | DEL |
6840 BPH | NBH | NEL | SSA | ESA |
6841 HTS | HTJ | VTS | PLD | PLU |
6842 SS2 | SS3 | DCS | PU1 | PU2 |
6843 STS | CCH | SPA | EPA | SOS |
6844 SCI | CSI | OSC | APC
6848 when Space .. Tilde |
6849 No_Break_Space .. LC_Y_Diaeresis
6854 W := Int'Max (W, Wt);
6858 -- Width for types derived from Standard.Boolean
6860 elsif R = Standard_Boolean then
6867 -- Width for integer types
6869 elsif Is_Integer_Type (P_Type) then
6870 T := UI_Max (abs Lo, abs Hi);
6878 -- Only remaining possibility is user declared enum type
6881 pragma Assert (Is_Enumeration_Type (P_Type));
6884 L := First_Literal (P_Type);
6886 while Present (L) loop
6888 -- Only pay attention to in range characters
6890 if Lo <= Enumeration_Pos (L)
6891 and then Enumeration_Pos (L) <= Hi
6893 -- For Width case, use decoded name
6895 if Id = Attribute_Width then
6896 Get_Decoded_Name_String (Chars (L));
6897 Wt := Nat (Name_Len);
6899 -- For Wide_[Wide_]Width, use encoded name, and
6900 -- then adjust for the encoding.
6903 Get_Name_String (Chars (L));
6905 -- Character literals are always of length 3
6907 if Name_Buffer (1) = 'Q' then
6910 -- Otherwise loop to adjust for upper/wide chars
6913 Wt := Nat (Name_Len);
6915 for J in 1 .. Name_Len loop
6916 if Name_Buffer (J) = 'U' then
6918 elsif Name_Buffer (J) = 'W' then
6925 W := Int'Max (W, Wt);
6932 Fold_Uint (N, UI_From_Int (W), True);
6938 -- The following attributes can never be folded, and furthermore we
6939 -- should not even have entered the case statement for any of these.
6940 -- Note that in some cases, the values have already been folded as
6941 -- a result of the processing in Analyze_Attribute.
6943 when Attribute_Abort_Signal |
6946 Attribute_Address_Size |
6947 Attribute_Asm_Input |
6948 Attribute_Asm_Output |
6950 Attribute_Bit_Order |
6951 Attribute_Bit_Position |
6952 Attribute_Callable |
6955 Attribute_Code_Address |
6957 Attribute_Default_Bit_Order |
6958 Attribute_Elaborated |
6959 Attribute_Elab_Body |
6960 Attribute_Elab_Spec |
6962 Attribute_External_Tag |
6963 Attribute_First_Bit |
6965 Attribute_Last_Bit |
6966 Attribute_Maximum_Alignment |
6968 Attribute_Partition_ID |
6969 Attribute_Pool_Address |
6970 Attribute_Position |
6971 Attribute_Priority |
6973 Attribute_Storage_Pool |
6974 Attribute_Storage_Size |
6975 Attribute_Storage_Unit |
6976 Attribute_Stub_Type |
6978 Attribute_Target_Name |
6979 Attribute_Terminated |
6980 Attribute_To_Address |
6981 Attribute_UET_Address |
6982 Attribute_Unchecked_Access |
6983 Attribute_Universal_Literal_String |
6984 Attribute_Unrestricted_Access |
6987 Attribute_Wchar_T_Size |
6988 Attribute_Wide_Value |
6989 Attribute_Wide_Wide_Value |
6990 Attribute_Word_Size |
6993 raise Program_Error;
6996 -- At the end of the case, one more check. If we did a static evaluation
6997 -- so that the result is now a literal, then set Is_Static_Expression
6998 -- in the constant only if the prefix type is a static subtype. For
6999 -- non-static subtypes, the folding is still OK, but not static.
7001 -- An exception is the GNAT attribute Constrained_Array which is
7002 -- defined to be a static attribute in all cases.
7004 if Nkind (N) = N_Integer_Literal
7005 or else Nkind (N) = N_Real_Literal
7006 or else Nkind (N) = N_Character_Literal
7007 or else Nkind (N) = N_String_Literal
7008 or else (Is_Entity_Name (N)
7009 and then Ekind (Entity (N)) = E_Enumeration_Literal)
7011 Set_Is_Static_Expression (N, Static);
7013 -- If this is still an attribute reference, then it has not been folded
7014 -- and that means that its expressions are in a non-static context.
7016 elsif Nkind (N) = N_Attribute_Reference then
7019 -- Note: the else case not covered here are odd cases where the
7020 -- processing has transformed the attribute into something other
7021 -- than a constant. Nothing more to do in such cases.
7028 ------------------------------
7029 -- Is_Anonymous_Tagged_Base --
7030 ------------------------------
7032 function Is_Anonymous_Tagged_Base
7039 Anon = Current_Scope
7040 and then Is_Itype (Anon)
7041 and then Associated_Node_For_Itype (Anon) = Parent (Typ);
7042 end Is_Anonymous_Tagged_Base;
7044 --------------------------------
7045 -- Name_Implies_Lvalue_Prefix --
7046 --------------------------------
7048 function Name_Implies_Lvalue_Prefix (Nam : Name_Id) return Boolean is
7049 pragma Assert (Is_Attribute_Name (Nam));
7051 return Attribute_Name_Implies_Lvalue_Prefix (Get_Attribute_Id (Nam));
7052 end Name_Implies_Lvalue_Prefix;
7054 -----------------------
7055 -- Resolve_Attribute --
7056 -----------------------
7058 procedure Resolve_Attribute (N : Node_Id; Typ : Entity_Id) is
7059 Loc : constant Source_Ptr := Sloc (N);
7060 P : constant Node_Id := Prefix (N);
7061 Aname : constant Name_Id := Attribute_Name (N);
7062 Attr_Id : constant Attribute_Id := Get_Attribute_Id (Aname);
7063 Btyp : constant Entity_Id := Base_Type (Typ);
7064 Des_Btyp : Entity_Id;
7065 Index : Interp_Index;
7067 Nom_Subt : Entity_Id;
7069 procedure Accessibility_Message;
7070 -- Error, or warning within an instance, if the static accessibility
7071 -- rules of 3.10.2 are violated.
7073 ---------------------------
7074 -- Accessibility_Message --
7075 ---------------------------
7077 procedure Accessibility_Message is
7078 Indic : Node_Id := Parent (Parent (N));
7081 -- In an instance, this is a runtime check, but one we
7082 -- know will fail, so generate an appropriate warning.
7084 if In_Instance_Body then
7086 ("?non-local pointer cannot point to local object", P);
7088 ("\?Program_Error will be raised at run time", P);
7090 Make_Raise_Program_Error (Loc,
7091 Reason => PE_Accessibility_Check_Failed));
7097 ("non-local pointer cannot point to local object", P);
7099 -- Check for case where we have a missing access definition
7101 if Is_Record_Type (Current_Scope)
7103 (Nkind (Parent (N)) = N_Discriminant_Association
7105 Nkind (Parent (N)) = N_Index_Or_Discriminant_Constraint)
7107 Indic := Parent (Parent (N));
7108 while Present (Indic)
7109 and then Nkind (Indic) /= N_Subtype_Indication
7111 Indic := Parent (Indic);
7114 if Present (Indic) then
7116 ("\use an access definition for" &
7117 " the access discriminant of&",
7118 N, Entity (Subtype_Mark (Indic)));
7122 end Accessibility_Message;
7124 -- Start of processing for Resolve_Attribute
7127 -- If error during analysis, no point in continuing, except for
7128 -- array types, where we get better recovery by using unconstrained
7129 -- indices than nothing at all (see Check_Array_Type).
7132 and then Attr_Id /= Attribute_First
7133 and then Attr_Id /= Attribute_Last
7134 and then Attr_Id /= Attribute_Length
7135 and then Attr_Id /= Attribute_Range
7140 -- If attribute was universal type, reset to actual type
7142 if Etype (N) = Universal_Integer
7143 or else Etype (N) = Universal_Real
7148 -- Remaining processing depends on attribute
7156 -- For access attributes, if the prefix denotes an entity, it is
7157 -- interpreted as a name, never as a call. It may be overloaded,
7158 -- in which case resolution uses the profile of the context type.
7159 -- Otherwise prefix must be resolved.
7161 when Attribute_Access
7162 | Attribute_Unchecked_Access
7163 | Attribute_Unrestricted_Access =>
7165 Access_Attribute : begin
7166 if Is_Variable (P) then
7167 Note_Possible_Modification (P);
7170 if Is_Entity_Name (P) then
7171 if Is_Overloaded (P) then
7172 Get_First_Interp (P, Index, It);
7173 while Present (It.Nam) loop
7174 if Type_Conformant (Designated_Type (Typ), It.Nam) then
7175 Set_Entity (P, It.Nam);
7177 -- The prefix is definitely NOT overloaded anymore at
7178 -- this point, so we reset the Is_Overloaded flag to
7179 -- avoid any confusion when reanalyzing the node.
7181 Set_Is_Overloaded (P, False);
7182 Set_Is_Overloaded (N, False);
7183 Generate_Reference (Entity (P), P);
7187 Get_Next_Interp (Index, It);
7190 -- If Prefix is a subprogram name, it is frozen by this
7193 -- If it is a type, there is nothing to resolve.
7194 -- If it is an object, complete its resolution.
7196 elsif Is_Overloadable (Entity (P)) then
7197 if not In_Default_Expression then
7198 Insert_Actions (N, Freeze_Entity (Entity (P), Loc));
7201 elsif Is_Type (Entity (P)) then
7207 Error_Msg_Name_1 := Aname;
7209 if not Is_Entity_Name (P) then
7212 elsif Is_Overloadable (Entity (P))
7213 and then Is_Abstract_Subprogram (Entity (P))
7215 Error_Msg_F ("prefix of % attribute cannot be abstract", P);
7216 Set_Etype (N, Any_Type);
7218 elsif Convention (Entity (P)) = Convention_Intrinsic then
7219 if Ekind (Entity (P)) = E_Enumeration_Literal then
7221 ("prefix of % attribute cannot be enumeration literal",
7225 ("prefix of % attribute cannot be intrinsic", P);
7228 Set_Etype (N, Any_Type);
7231 -- Assignments, return statements, components of aggregates,
7232 -- generic instantiations will require convention checks if
7233 -- the type is an access to subprogram. Given that there will
7234 -- also be accessibility checks on those, this is where the
7235 -- checks can eventually be centralized ???
7237 if Ekind (Btyp) = E_Access_Subprogram_Type
7239 Ekind (Btyp) = E_Anonymous_Access_Subprogram_Type
7241 Ekind (Btyp) = E_Anonymous_Access_Protected_Subprogram_Type
7243 -- Deal with convention mismatch
7245 if Convention (Btyp) /= Convention (Entity (P)) then
7247 ("subprogram & has wrong convention", P, Entity (P));
7250 ("\does not match convention of access type &",
7253 if not Has_Convention_Pragma (Btyp) then
7255 ("\probable missing pragma Convention for &",
7260 Check_Subtype_Conformant
7261 (New_Id => Entity (P),
7262 Old_Id => Designated_Type (Btyp),
7266 if Attr_Id = Attribute_Unchecked_Access then
7267 Error_Msg_Name_1 := Aname;
7269 ("attribute% cannot be applied to a subprogram", P);
7271 elsif Aname = Name_Unrestricted_Access then
7272 null; -- Nothing to check
7274 -- Check the static accessibility rule of 3.10.2(32).
7275 -- This rule also applies within the private part of an
7276 -- instantiation. This rule does not apply to anonymous
7277 -- access-to-subprogram types (Ada 2005).
7279 elsif Attr_Id = Attribute_Access
7280 and then not In_Instance_Body
7281 and then Subprogram_Access_Level (Entity (P)) >
7282 Type_Access_Level (Btyp)
7283 and then Ekind (Btyp) /=
7284 E_Anonymous_Access_Subprogram_Type
7285 and then Ekind (Btyp) /=
7286 E_Anonymous_Access_Protected_Subprogram_Type
7289 ("subprogram must not be deeper than access type", P);
7291 -- Check the restriction of 3.10.2(32) that disallows the
7292 -- access attribute within a generic body when the ultimate
7293 -- ancestor of the type of the attribute is declared outside
7294 -- of the generic unit and the subprogram is declared within
7295 -- that generic unit. This includes any such attribute that
7296 -- occurs within the body of a generic unit that is a child
7297 -- of the generic unit where the subprogram is declared.
7298 -- The rule also prohibits applying the attibute when the
7299 -- access type is a generic formal access type (since the
7300 -- level of the actual type is not known). This restriction
7301 -- does not apply when the attribute type is an anonymous
7302 -- access-to-subprogram type. Note that this check was
7303 -- revised by AI-229, because the originally Ada 95 rule
7304 -- was too lax. The original rule only applied when the
7305 -- subprogram was declared within the body of the generic,
7306 -- which allowed the possibility of dangling references).
7307 -- The rule was also too strict in some case, in that it
7308 -- didn't permit the access to be declared in the generic
7309 -- spec, whereas the revised rule does (as long as it's not
7312 -- There are a couple of subtleties of the test for applying
7313 -- the check that are worth noting. First, we only apply it
7314 -- when the levels of the subprogram and access type are the
7315 -- same (the case where the subprogram is statically deeper
7316 -- was applied above, and the case where the type is deeper
7317 -- is always safe). Second, we want the check to apply
7318 -- within nested generic bodies and generic child unit
7319 -- bodies, but not to apply to an attribute that appears in
7320 -- the generic unit's specification. This is done by testing
7321 -- that the attribute's innermost enclosing generic body is
7322 -- not the same as the innermost generic body enclosing the
7323 -- generic unit where the subprogram is declared (we don't
7324 -- want the check to apply when the access attribute is in
7325 -- the spec and there's some other generic body enclosing
7326 -- generic). Finally, there's no point applying the check
7327 -- when within an instance, because any violations will have
7328 -- been caught by the compilation of the generic unit.
7330 elsif Attr_Id = Attribute_Access
7331 and then not In_Instance
7332 and then Present (Enclosing_Generic_Unit (Entity (P)))
7333 and then Present (Enclosing_Generic_Body (N))
7334 and then Enclosing_Generic_Body (N) /=
7335 Enclosing_Generic_Body
7336 (Enclosing_Generic_Unit (Entity (P)))
7337 and then Subprogram_Access_Level (Entity (P)) =
7338 Type_Access_Level (Btyp)
7339 and then Ekind (Btyp) /=
7340 E_Anonymous_Access_Subprogram_Type
7341 and then Ekind (Btyp) /=
7342 E_Anonymous_Access_Protected_Subprogram_Type
7344 -- The attribute type's ultimate ancestor must be
7345 -- declared within the same generic unit as the
7346 -- subprogram is declared. The error message is
7347 -- specialized to say "ancestor" for the case where
7348 -- the access type is not its own ancestor, since
7349 -- saying simply "access type" would be very confusing.
7351 if Enclosing_Generic_Unit (Entity (P)) /=
7352 Enclosing_Generic_Unit (Root_Type (Btyp))
7355 ("''Access attribute not allowed in generic body",
7358 if Root_Type (Btyp) = Btyp then
7361 "access type & is declared outside " &
7362 "generic unit (RM 3.10.2(32))", N, Btyp);
7365 ("\because ancestor of " &
7366 "access type & is declared outside " &
7367 "generic unit (RM 3.10.2(32))", N, Btyp);
7371 ("\move ''Access to private part, or " &
7372 "(Ada 2005) use anonymous access type instead of &",
7375 -- If the ultimate ancestor of the attribute's type is
7376 -- a formal type, then the attribute is illegal because
7377 -- the actual type might be declared at a higher level.
7378 -- The error message is specialized to say "ancestor"
7379 -- for the case where the access type is not its own
7380 -- ancestor, since saying simply "access type" would be
7383 elsif Is_Generic_Type (Root_Type (Btyp)) then
7384 if Root_Type (Btyp) = Btyp then
7386 ("access type must not be a generic formal type",
7390 ("ancestor access type must not be a generic " &
7397 -- If this is a renaming, an inherited operation, or a
7398 -- subprogram instance, use the original entity. This may make
7399 -- the node type-inconsistent, so this transformation can only
7400 -- be done if the node will not be reanalyzed. In particular,
7401 -- if it is within a default expression, the transformation
7402 -- must be delayed until the default subprogram is created for
7403 -- it, when the enclosing subprogram is frozen.
7405 if Is_Entity_Name (P)
7406 and then Is_Overloadable (Entity (P))
7407 and then Present (Alias (Entity (P)))
7408 and then Expander_Active
7411 New_Occurrence_Of (Alias (Entity (P)), Sloc (P)));
7414 elsif Nkind (P) = N_Selected_Component
7415 and then Is_Overloadable (Entity (Selector_Name (P)))
7417 -- Protected operation. If operation is overloaded, must
7418 -- disambiguate. Prefix that denotes protected object itself
7419 -- is resolved with its own type.
7421 if Attr_Id = Attribute_Unchecked_Access then
7422 Error_Msg_Name_1 := Aname;
7424 ("attribute% cannot be applied to protected operation", P);
7427 Resolve (Prefix (P));
7428 Generate_Reference (Entity (Selector_Name (P)), P);
7430 elsif Is_Overloaded (P) then
7432 -- Use the designated type of the context to disambiguate
7433 -- Note that this was not strictly conformant to Ada 95,
7434 -- but was the implementation adopted by most Ada 95 compilers.
7435 -- The use of the context type to resolve an Access attribute
7436 -- reference is now mandated in AI-235 for Ada 2005.
7439 Index : Interp_Index;
7443 Get_First_Interp (P, Index, It);
7444 while Present (It.Typ) loop
7445 if Covers (Designated_Type (Typ), It.Typ) then
7446 Resolve (P, It.Typ);
7450 Get_Next_Interp (Index, It);
7457 -- X'Access is illegal if X denotes a constant and the access type
7458 -- is access-to-variable. Same for 'Unchecked_Access. The rule
7459 -- does not apply to 'Unrestricted_Access. If the reference is a
7460 -- default-initialized aggregate component for a self-referential
7461 -- type the reference is legal.
7463 if not (Ekind (Btyp) = E_Access_Subprogram_Type
7464 or else Ekind (Btyp) = E_Anonymous_Access_Subprogram_Type
7465 or else (Is_Record_Type (Btyp)
7467 Present (Corresponding_Remote_Type (Btyp)))
7468 or else Ekind (Btyp) = E_Access_Protected_Subprogram_Type
7469 or else Ekind (Btyp)
7470 = E_Anonymous_Access_Protected_Subprogram_Type
7471 or else Is_Access_Constant (Btyp)
7472 or else Is_Variable (P)
7473 or else Attr_Id = Attribute_Unrestricted_Access)
7475 if Is_Entity_Name (P)
7476 and then Is_Type (Entity (P))
7478 -- Legality of a self-reference through an access
7479 -- attribute has been verified in Analyze_Access_Attribute.
7483 elsif Comes_From_Source (N) then
7484 Error_Msg_F ("access-to-variable designates constant", P);
7488 if (Attr_Id = Attribute_Access
7490 Attr_Id = Attribute_Unchecked_Access)
7491 and then (Ekind (Btyp) = E_General_Access_Type
7492 or else Ekind (Btyp) = E_Anonymous_Access_Type)
7494 -- Ada 2005 (AI-230): Check the accessibility of anonymous
7495 -- access types for stand-alone objects, record and array
7496 -- components, and return objects. For a component definition
7497 -- the level is the same of the enclosing composite type.
7499 if Ada_Version >= Ada_05
7500 and then Is_Local_Anonymous_Access (Btyp)
7501 and then Object_Access_Level (P) > Type_Access_Level (Btyp)
7502 and then Attr_Id = Attribute_Access
7504 -- In an instance, this is a runtime check, but one we
7505 -- know will fail, so generate an appropriate warning.
7507 if In_Instance_Body then
7509 ("?non-local pointer cannot point to local object", P);
7511 ("\?Program_Error will be raised at run time", P);
7513 Make_Raise_Program_Error (Loc,
7514 Reason => PE_Accessibility_Check_Failed));
7519 ("non-local pointer cannot point to local object", P);
7523 if Is_Dependent_Component_Of_Mutable_Object (P) then
7525 ("illegal attribute for discriminant-dependent component",
7529 -- Check static matching rule of 3.10.2(27). Nominal subtype
7530 -- of the prefix must statically match the designated type.
7532 Nom_Subt := Etype (P);
7534 if Is_Constr_Subt_For_U_Nominal (Nom_Subt) then
7535 Nom_Subt := Base_Type (Nom_Subt);
7538 Des_Btyp := Designated_Type (Btyp);
7540 if Ekind (Des_Btyp) = E_Incomplete_Subtype then
7542 -- Ada 2005 (AI-412): Subtypes of incomplete types visible
7543 -- through a limited with clause or regular incomplete
7546 if From_With_Type (Des_Btyp)
7547 and then Present (Non_Limited_View (Des_Btyp))
7549 Des_Btyp := Non_Limited_View (Des_Btyp);
7551 Des_Btyp := Etype (Des_Btyp);
7555 if Is_Tagged_Type (Designated_Type (Typ)) then
7557 -- If the attribute is in the context of an access
7558 -- parameter, then the prefix is allowed to be of the
7559 -- class-wide type (by AI-127).
7561 if Ekind (Typ) = E_Anonymous_Access_Type then
7562 if not Covers (Designated_Type (Typ), Nom_Subt)
7563 and then not Covers (Nom_Subt, Designated_Type (Typ))
7569 Desig := Designated_Type (Typ);
7571 if Is_Class_Wide_Type (Desig) then
7572 Desig := Etype (Desig);
7575 if Is_Anonymous_Tagged_Base (Nom_Subt, Desig) then
7580 ("type of prefix: & not compatible",
7583 ("\with &, the expected designated type",
7584 P, Designated_Type (Typ));
7589 elsif not Covers (Designated_Type (Typ), Nom_Subt)
7591 (not Is_Class_Wide_Type (Designated_Type (Typ))
7592 and then Is_Class_Wide_Type (Nom_Subt))
7595 ("type of prefix: & is not covered", P, Nom_Subt);
7597 ("\by &, the expected designated type" &
7598 " (RM 3.10.2 (27))", P, Designated_Type (Typ));
7601 if Is_Class_Wide_Type (Designated_Type (Typ))
7602 and then Has_Discriminants (Etype (Designated_Type (Typ)))
7603 and then Is_Constrained (Etype (Designated_Type (Typ)))
7604 and then Designated_Type (Typ) /= Nom_Subt
7606 Apply_Discriminant_Check
7607 (N, Etype (Designated_Type (Typ)));
7610 -- Ada 2005 (AI-363): Require static matching when designated
7611 -- type has discriminants and a constrained partial view, since
7612 -- in general objects of such types are mutable, so we can't
7613 -- allow the access value to designate a constrained object
7614 -- (because access values must be assumed to designate mutable
7615 -- objects when designated type does not impose a constraint).
7617 elsif not Subtypes_Statically_Match (Des_Btyp, Nom_Subt)
7619 not (Has_Discriminants (Designated_Type (Typ))
7620 and then not Is_Constrained (Des_Btyp)
7622 (Ada_Version < Ada_05
7624 not Has_Constrained_Partial_View
7625 (Designated_Type (Base_Type (Typ)))))
7628 ("object subtype must statically match "
7629 & "designated subtype", P);
7631 if Is_Entity_Name (P)
7632 and then Is_Array_Type (Designated_Type (Typ))
7635 D : constant Node_Id := Declaration_Node (Entity (P));
7638 Error_Msg_N ("aliased object has explicit bounds?",
7640 Error_Msg_N ("\declare without bounds"
7641 & " (and with explicit initialization)?", D);
7642 Error_Msg_N ("\for use with unconstrained access?", D);
7647 -- Check the static accessibility rule of 3.10.2(28).
7648 -- Note that this check is not performed for the
7649 -- case of an anonymous access type, since the access
7650 -- attribute is always legal in such a context.
7652 if Attr_Id /= Attribute_Unchecked_Access
7653 and then Object_Access_Level (P) > Type_Access_Level (Btyp)
7654 and then Ekind (Btyp) = E_General_Access_Type
7656 Accessibility_Message;
7661 if Ekind (Btyp) = E_Access_Protected_Subprogram_Type
7663 Ekind (Btyp) = E_Anonymous_Access_Protected_Subprogram_Type
7665 if Is_Entity_Name (P)
7666 and then not Is_Protected_Type (Scope (Entity (P)))
7668 Error_Msg_F ("context requires a protected subprogram", P);
7670 -- Check accessibility of protected object against that of the
7671 -- access type, but only on user code, because the expander
7672 -- creates access references for handlers. If the context is an
7673 -- anonymous_access_to_protected, there are no accessibility
7674 -- checks either. Omit check entirely for Unrestricted_Access.
7676 elsif Object_Access_Level (P) > Type_Access_Level (Btyp)
7677 and then Comes_From_Source (N)
7678 and then Ekind (Btyp) = E_Access_Protected_Subprogram_Type
7679 and then Attr_Id /= Attribute_Unrestricted_Access
7681 Accessibility_Message;
7685 elsif (Ekind (Btyp) = E_Access_Subprogram_Type
7687 Ekind (Btyp) = E_Anonymous_Access_Subprogram_Type)
7688 and then Ekind (Etype (N)) = E_Access_Protected_Subprogram_Type
7690 Error_Msg_F ("context requires a non-protected subprogram", P);
7693 -- The context cannot be a pool-specific type, but this is a
7694 -- legality rule, not a resolution rule, so it must be checked
7695 -- separately, after possibly disambiguation (see AI-245).
7697 if Ekind (Btyp) = E_Access_Type
7698 and then Attr_Id /= Attribute_Unrestricted_Access
7700 Wrong_Type (N, Typ);
7703 -- The context may be a constrained access type (however ill-
7704 -- advised such subtypes might be) so in order to generate a
7705 -- constraint check when needed set the type of the attribute
7706 -- reference to the base type of the context.
7708 Set_Etype (N, Btyp);
7710 -- Check for incorrect atomic/volatile reference (RM C.6(12))
7712 if Attr_Id /= Attribute_Unrestricted_Access then
7713 if Is_Atomic_Object (P)
7714 and then not Is_Atomic (Designated_Type (Typ))
7717 ("access to atomic object cannot yield access-to-" &
7718 "non-atomic type", P);
7720 elsif Is_Volatile_Object (P)
7721 and then not Is_Volatile (Designated_Type (Typ))
7724 ("access to volatile object cannot yield access-to-" &
7725 "non-volatile type", P);
7729 if Is_Entity_Name (P) then
7730 Set_Address_Taken (Entity (P));
7732 end Access_Attribute;
7738 -- Deal with resolving the type for Address attribute, overloading
7739 -- is not permitted here, since there is no context to resolve it.
7741 when Attribute_Address | Attribute_Code_Address =>
7742 Address_Attribute : begin
7744 -- To be safe, assume that if the address of a variable is taken,
7745 -- it may be modified via this address, so note modification.
7747 if Is_Variable (P) then
7748 Note_Possible_Modification (P);
7751 if Nkind (P) in N_Subexpr
7752 and then Is_Overloaded (P)
7754 Get_First_Interp (P, Index, It);
7755 Get_Next_Interp (Index, It);
7757 if Present (It.Nam) then
7758 Error_Msg_Name_1 := Aname;
7760 ("prefix of % attribute cannot be overloaded", P);
7764 if not Is_Entity_Name (P)
7765 or else not Is_Overloadable (Entity (P))
7767 if not Is_Task_Type (Etype (P))
7768 or else Nkind (P) = N_Explicit_Dereference
7774 -- If this is the name of a derived subprogram, or that of a
7775 -- generic actual, the address is that of the original entity.
7777 if Is_Entity_Name (P)
7778 and then Is_Overloadable (Entity (P))
7779 and then Present (Alias (Entity (P)))
7782 New_Occurrence_Of (Alias (Entity (P)), Sloc (P)));
7785 if Is_Entity_Name (P) then
7786 Set_Address_Taken (Entity (P));
7788 end Address_Attribute;
7794 -- Prefix of the AST_Entry attribute is an entry name which must
7795 -- not be resolved, since this is definitely not an entry call.
7797 when Attribute_AST_Entry =>
7804 -- Prefix of Body_Version attribute can be a subprogram name which
7805 -- must not be resolved, since this is not a call.
7807 when Attribute_Body_Version =>
7814 -- Prefix of Caller attribute is an entry name which must not
7815 -- be resolved, since this is definitely not an entry call.
7817 when Attribute_Caller =>
7824 -- Shares processing with Address attribute
7830 -- If the prefix of the Count attribute is an entry name it must not
7831 -- be resolved, since this is definitely not an entry call. However,
7832 -- if it is an element of an entry family, the index itself may
7833 -- have to be resolved because it can be a general expression.
7835 when Attribute_Count =>
7836 if Nkind (P) = N_Indexed_Component
7837 and then Is_Entity_Name (Prefix (P))
7840 Indx : constant Node_Id := First (Expressions (P));
7841 Fam : constant Entity_Id := Entity (Prefix (P));
7843 Resolve (Indx, Entry_Index_Type (Fam));
7844 Apply_Range_Check (Indx, Entry_Index_Type (Fam));
7852 -- Prefix of the Elaborated attribute is a subprogram name which
7853 -- must not be resolved, since this is definitely not a call. Note
7854 -- that it is a library unit, so it cannot be overloaded here.
7856 when Attribute_Elaborated =>
7863 -- Prefix of Enabled attribute is a check name, which must be treated
7864 -- specially and not touched by Resolve.
7866 when Attribute_Enabled =>
7869 --------------------
7870 -- Mechanism_Code --
7871 --------------------
7873 -- Prefix of the Mechanism_Code attribute is a function name
7874 -- which must not be resolved. Should we check for overloaded ???
7876 when Attribute_Mechanism_Code =>
7883 -- Most processing is done in sem_dist, after determining the
7884 -- context type. Node is rewritten as a conversion to a runtime call.
7886 when Attribute_Partition_ID =>
7887 Process_Partition_Id (N);
7890 when Attribute_Pool_Address =>
7897 -- We replace the Range attribute node with a range expression
7898 -- whose bounds are the 'First and 'Last attributes applied to the
7899 -- same prefix. The reason that we do this transformation here
7900 -- instead of in the expander is that it simplifies other parts of
7901 -- the semantic analysis which assume that the Range has been
7902 -- replaced; thus it must be done even when in semantic-only mode
7903 -- (note that the RM specifically mentions this equivalence, we
7904 -- take care that the prefix is only evaluated once).
7906 when Attribute_Range => Range_Attribute :
7911 function Check_Discriminated_Prival
7914 -- The range of a private component constrained by a
7915 -- discriminant is rewritten to make the discriminant
7916 -- explicit. This solves some complex visibility problems
7917 -- related to the use of privals.
7919 --------------------------------
7920 -- Check_Discriminated_Prival --
7921 --------------------------------
7923 function Check_Discriminated_Prival
7928 if Is_Entity_Name (N)
7929 and then Ekind (Entity (N)) = E_In_Parameter
7930 and then not Within_Init_Proc
7932 return Make_Identifier (Sloc (N), Chars (Entity (N)));
7934 return Duplicate_Subexpr (N);
7936 end Check_Discriminated_Prival;
7938 -- Start of processing for Range_Attribute
7941 if not Is_Entity_Name (P)
7942 or else not Is_Type (Entity (P))
7947 -- Check whether prefix is (renaming of) private component
7948 -- of protected type.
7950 if Is_Entity_Name (P)
7951 and then Comes_From_Source (N)
7952 and then Is_Array_Type (Etype (P))
7953 and then Number_Dimensions (Etype (P)) = 1
7954 and then (Ekind (Scope (Entity (P))) = E_Protected_Type
7956 Ekind (Scope (Scope (Entity (P)))) =
7960 Check_Discriminated_Prival
7961 (Type_Low_Bound (Etype (First_Index (Etype (P)))));
7964 Check_Discriminated_Prival
7965 (Type_High_Bound (Etype (First_Index (Etype (P)))));
7969 Make_Attribute_Reference (Loc,
7970 Prefix => Duplicate_Subexpr (P),
7971 Attribute_Name => Name_Last,
7972 Expressions => Expressions (N));
7975 Make_Attribute_Reference (Loc,
7977 Attribute_Name => Name_First,
7978 Expressions => Expressions (N));
7981 -- If the original was marked as Must_Not_Freeze (see code
7982 -- in Sem_Ch3.Make_Index), then make sure the rewriting
7983 -- does not freeze either.
7985 if Must_Not_Freeze (N) then
7986 Set_Must_Not_Freeze (HB);
7987 Set_Must_Not_Freeze (LB);
7988 Set_Must_Not_Freeze (Prefix (HB));
7989 Set_Must_Not_Freeze (Prefix (LB));
7992 if Raises_Constraint_Error (Prefix (N)) then
7994 -- Preserve Sloc of prefix in the new bounds, so that
7995 -- the posted warning can be removed if we are within
7996 -- unreachable code.
7998 Set_Sloc (LB, Sloc (Prefix (N)));
7999 Set_Sloc (HB, Sloc (Prefix (N)));
8002 Rewrite (N, Make_Range (Loc, LB, HB));
8003 Analyze_And_Resolve (N, Typ);
8005 -- Normally after resolving attribute nodes, Eval_Attribute
8006 -- is called to do any possible static evaluation of the node.
8007 -- However, here since the Range attribute has just been
8008 -- transformed into a range expression it is no longer an
8009 -- attribute node and therefore the call needs to be avoided
8010 -- and is accomplished by simply returning from the procedure.
8013 end Range_Attribute;
8019 -- Prefix must not be resolved in this case, since it is not a
8020 -- real entity reference. No action of any kind is require!
8022 when Attribute_UET_Address =>
8025 ----------------------
8026 -- Unchecked_Access --
8027 ----------------------
8029 -- Processing is shared with Access
8031 -------------------------
8032 -- Unrestricted_Access --
8033 -------------------------
8035 -- Processing is shared with Access
8041 -- Apply range check. Note that we did not do this during the
8042 -- analysis phase, since we wanted Eval_Attribute to have a
8043 -- chance at finding an illegal out of range value.
8045 when Attribute_Val =>
8047 -- Note that we do our own Eval_Attribute call here rather than
8048 -- use the common one, because we need to do processing after
8049 -- the call, as per above comment.
8053 -- Eval_Attribute may replace the node with a raise CE, or
8054 -- fold it to a constant. Obviously we only apply a scalar
8055 -- range check if this did not happen!
8057 if Nkind (N) = N_Attribute_Reference
8058 and then Attribute_Name (N) = Name_Val
8060 Apply_Scalar_Range_Check (First (Expressions (N)), Btyp);
8069 -- Prefix of Version attribute can be a subprogram name which
8070 -- must not be resolved, since this is not a call.
8072 when Attribute_Version =>
8075 ----------------------
8076 -- Other Attributes --
8077 ----------------------
8079 -- For other attributes, resolve prefix unless it is a type. If
8080 -- the attribute reference itself is a type name ('Base and 'Class)
8081 -- then this is only legal within a task or protected record.
8084 if not Is_Entity_Name (P)
8085 or else not Is_Type (Entity (P))
8090 -- If the attribute reference itself is a type name ('Base,
8091 -- 'Class) then this is only legal within a task or protected
8092 -- record. What is this all about ???
8094 if Is_Entity_Name (N)
8095 and then Is_Type (Entity (N))
8097 if Is_Concurrent_Type (Entity (N))
8098 and then In_Open_Scopes (Entity (P))
8103 ("invalid use of subtype name in expression or call", N);
8107 -- For attributes whose argument may be a string, complete
8108 -- resolution of argument now. This avoids premature expansion
8109 -- (and the creation of transient scopes) before the attribute
8110 -- reference is resolved.
8113 when Attribute_Value =>
8114 Resolve (First (Expressions (N)), Standard_String);
8116 when Attribute_Wide_Value =>
8117 Resolve (First (Expressions (N)), Standard_Wide_String);
8119 when Attribute_Wide_Wide_Value =>
8120 Resolve (First (Expressions (N)), Standard_Wide_Wide_String);
8122 when others => null;
8125 -- If the prefix of the attribute is a class-wide type then it
8126 -- will be expanded into a dispatching call to a predefined
8127 -- primitive. Therefore we must check for potential violation
8128 -- of such restriction.
8130 if Is_Class_Wide_Type (Etype (P)) then
8131 Check_Restriction (No_Dispatching_Calls, N);
8135 -- Normally the Freezing is done by Resolve but sometimes the Prefix
8136 -- is not resolved, in which case the freezing must be done now.
8138 Freeze_Expression (P);
8140 -- Finally perform static evaluation on the attribute reference
8143 end Resolve_Attribute;
8145 --------------------------------
8146 -- Stream_Attribute_Available --
8147 --------------------------------
8149 function Stream_Attribute_Available
8151 Nam : TSS_Name_Type;
8152 Partial_View : Node_Id := Empty) return Boolean
8154 Etyp : Entity_Id := Typ;
8156 -- Start of processing for Stream_Attribute_Available
8159 -- We need some comments in this body ???
8161 if Has_Stream_Attribute_Definition (Typ, Nam) then
8165 if Is_Class_Wide_Type (Typ) then
8166 return not Is_Limited_Type (Typ)
8167 or else Stream_Attribute_Available (Etype (Typ), Nam);
8170 if Nam = TSS_Stream_Input
8171 and then Is_Abstract_Type (Typ)
8172 and then not Is_Class_Wide_Type (Typ)
8177 if not (Is_Limited_Type (Typ)
8178 or else (Present (Partial_View)
8179 and then Is_Limited_Type (Partial_View)))
8184 -- In Ada 2005, Input can invoke Read, and Output can invoke Write
8186 if Nam = TSS_Stream_Input
8187 and then Ada_Version >= Ada_05
8188 and then Stream_Attribute_Available (Etyp, TSS_Stream_Read)
8192 elsif Nam = TSS_Stream_Output
8193 and then Ada_Version >= Ada_05
8194 and then Stream_Attribute_Available (Etyp, TSS_Stream_Write)
8199 -- Case of Read and Write: check for attribute definition clause that
8200 -- applies to an ancestor type.
8202 while Etype (Etyp) /= Etyp loop
8203 Etyp := Etype (Etyp);
8205 if Has_Stream_Attribute_Definition (Etyp, Nam) then
8210 if Ada_Version < Ada_05 then
8212 -- In Ada 95 mode, also consider a non-visible definition
8215 Btyp : constant Entity_Id := Implementation_Base_Type (Typ);
8218 and then Stream_Attribute_Available
8219 (Btyp, Nam, Partial_View => Typ);
8224 end Stream_Attribute_Available;