1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2005 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 Checks
; use Checks
;
31 with Einfo
; use Einfo
;
32 with Errout
; use Errout
;
34 with Exp_Util
; use Exp_Util
;
35 with Expander
; use Expander
;
36 with Freeze
; use Freeze
;
38 with Lib
.Xref
; use Lib
.Xref
;
39 with Namet
; use Namet
;
40 with Nlists
; use Nlists
;
41 with Nmake
; use Nmake
;
43 with Restrict
; use Restrict
;
44 with Rident
; use Rident
;
45 with Rtsfind
; use Rtsfind
;
46 with Sdefault
; use Sdefault
;
48 with Sem_Cat
; use Sem_Cat
;
49 with Sem_Ch6
; use Sem_Ch6
;
50 with Sem_Ch8
; use Sem_Ch8
;
51 with Sem_Dist
; use Sem_Dist
;
52 with Sem_Eval
; use Sem_Eval
;
53 with Sem_Res
; use Sem_Res
;
54 with Sem_Type
; use Sem_Type
;
55 with Sem_Util
; use Sem_Util
;
56 with Stand
; use Stand
;
57 with Sinfo
; use Sinfo
;
58 with Sinput
; use Sinput
;
60 with Stringt
; use Stringt
;
61 with Targparm
; use Targparm
;
62 with Ttypes
; use Ttypes
;
63 with Ttypef
; use Ttypef
;
64 with Tbuild
; use Tbuild
;
65 with Uintp
; use Uintp
;
66 with Urealp
; use Urealp
;
68 package body Sem_Attr
is
70 True_Value
: constant Uint
:= Uint_1
;
71 False_Value
: constant Uint
:= Uint_0
;
72 -- Synonyms to be used when these constants are used as Boolean values
74 Bad_Attribute
: exception;
75 -- Exception raised if an error is detected during attribute processing,
76 -- used so that we can abandon the processing so we don't run into
77 -- trouble with cascaded errors.
79 -- The following array is the list of attributes defined in the Ada 83 RM
81 Attribute_83
: constant Attribute_Class_Array
:= Attribute_Class_Array
'(
87 Attribute_Constrained |
100 Attribute_Leading_Part |
102 Attribute_Machine_Emax |
103 Attribute_Machine_Emin |
104 Attribute_Machine_Mantissa |
105 Attribute_Machine_Overflows |
106 Attribute_Machine_Radix |
107 Attribute_Machine_Rounds |
113 Attribute_Safe_Emax |
114 Attribute_Safe_Large |
115 Attribute_Safe_Small |
118 Attribute_Storage_Size |
120 Attribute_Terminated |
123 Attribute_Width => True,
126 -----------------------
127 -- Local_Subprograms --
128 -----------------------
130 procedure Eval_Attribute (N : Node_Id);
131 -- Performs compile time evaluation of attributes where possible, leaving
132 -- the Is_Static_Expression/Raises_Constraint_Error flags appropriately
133 -- set, and replacing the node with a literal node if the value can be
134 -- computed at compile time. All static attribute references are folded,
135 -- as well as a number of cases of non-static attributes that can always
136 -- be computed at compile time (e.g. floating-point model attributes that
137 -- are applied to non-static subtypes). Of course in such cases, the
138 -- Is_Static_Expression flag will not be set on the resulting literal.
139 -- Note that the only required action of this procedure is to catch the
140 -- static expression cases as described in the RM. Folding of other cases
141 -- is done where convenient, but some additional non-static folding is in
142 -- N_Expand_Attribute_Reference in cases where this is more convenient.
144 function Is_Anonymous_Tagged_Base
148 -- For derived tagged types that constrain parent discriminants we build
149 -- an anonymous unconstrained base type. We need to recognize the relation
150 -- between the two when analyzing an access attribute for a constrained
151 -- component, before the full declaration for Typ has been analyzed, and
152 -- where therefore the prefix of the attribute does not match the enclosing
155 -----------------------
156 -- Analyze_Attribute --
157 -----------------------
159 procedure Analyze_Attribute (N : Node_Id) is
160 Loc : constant Source_Ptr := Sloc (N);
161 Aname : constant Name_Id := Attribute_Name (N);
162 P : constant Node_Id := Prefix (N);
163 Exprs : constant List_Id := Expressions (N);
164 Attr_Id : constant Attribute_Id := Get_Attribute_Id (Aname);
169 -- Type of prefix after analysis
171 P_Base_Type : Entity_Id;
172 -- Base type of prefix after analysis
174 -----------------------
175 -- Local Subprograms --
176 -----------------------
178 procedure Analyze_Access_Attribute;
179 -- Used for Access, Unchecked_Access, Unrestricted_Access attributes.
180 -- Internally, Id distinguishes which of the three cases is involved.
182 procedure Check_Array_Or_Scalar_Type;
183 -- Common procedure used by First, Last, Range attribute to check
184 -- that the prefix is a constrained array or scalar type, or a name
185 -- of an array object, and that an argument appears only if appropriate
186 -- (i.e. only in the array case).
188 procedure Check_Array_Type;
189 -- Common semantic checks for all array attributes. Checks that the
190 -- prefix is a constrained array type or the name of an array object.
191 -- The error message for non-arrays is specialized appropriately.
193 procedure Check_Asm_Attribute;
194 -- Common semantic checks for Asm_Input and Asm_Output attributes
196 procedure Check_Component;
197 -- Common processing for Bit_Position, First_Bit, Last_Bit, and
198 -- Position. Checks prefix is an appropriate selected component.
200 procedure Check_Decimal_Fixed_Point_Type;
201 -- Check that prefix of attribute N is a decimal fixed-point type
203 procedure Check_Dereference;
204 -- If the prefix of attribute is an object of an access type, then
205 -- introduce an explicit deference, and adjust P_Type accordingly.
207 procedure Check_Discrete_Type;
208 -- Verify that prefix of attribute N is a discrete type
211 -- Check that no attribute arguments are present
213 procedure Check_Either_E0_Or_E1;
214 -- Check that there are zero or one attribute arguments present
217 -- Check that exactly one attribute argument is present
220 -- Check that two attribute arguments are present
222 procedure Check_Enum_Image;
223 -- If the prefix type is an enumeration type, set all its literals
224 -- as referenced, since the image function could possibly end up
225 -- referencing any of the literals indirectly.
227 procedure Check_Fixed_Point_Type;
228 -- Verify that prefix of attribute N is a fixed type
230 procedure Check_Fixed_Point_Type_0;
231 -- Verify that prefix of attribute N is a fixed type and that
232 -- no attribute expressions are present
234 procedure Check_Floating_Point_Type;
235 -- Verify that prefix of attribute N is a float type
237 procedure Check_Floating_Point_Type_0;
238 -- Verify that prefix of attribute N is a float type and that
239 -- no attribute expressions are present
241 procedure Check_Floating_Point_Type_1;
242 -- Verify that prefix of attribute N is a float type and that
243 -- exactly one attribute expression is present
245 procedure Check_Floating_Point_Type_2;
246 -- Verify that prefix of attribute N is a float type and that
247 -- two attribute expressions are present
249 procedure Legal_Formal_Attribute;
250 -- Common processing for attributes Definite, Has_Access_Values,
251 -- and Has_Discriminants
253 procedure Check_Integer_Type;
254 -- Verify that prefix of attribute N is an integer type
256 procedure Check_Library_Unit;
257 -- Verify that prefix of attribute N is a library unit
259 procedure Check_Modular_Integer_Type;
260 -- Verify that prefix of attribute N is a modular integer type
262 procedure Check_Not_Incomplete_Type;
263 -- Check that P (the prefix of the attribute) is not an incomplete
264 -- type or a private type for which no full view has been given.
266 procedure Check_Object_Reference (P : Node_Id);
267 -- Check that P (the prefix of the attribute) is an object reference
269 procedure Check_Program_Unit;
270 -- Verify that prefix of attribute N is a program unit
272 procedure Check_Real_Type;
273 -- Verify that prefix of attribute N is fixed or float type
275 procedure Check_Scalar_Type;
276 -- Verify that prefix of attribute N is a scalar type
278 procedure Check_Standard_Prefix;
279 -- Verify that prefix of attribute N is package Standard
281 procedure Check_Stream_Attribute (Nam : TSS_Name_Type);
282 -- Validity checking for stream attribute. Nam is the TSS name of the
283 -- corresponding possible defined attribute function (e.g. for the
284 -- Read attribute, Nam will be TSS_Stream_Read).
286 procedure Check_Task_Prefix;
287 -- Verify that prefix of attribute N is a task or task type
289 procedure Check_Type;
290 -- Verify that the prefix of attribute N is a type
292 procedure Check_Unit_Name (Nod : Node_Id);
293 -- Check that Nod is of the form of a library unit name, i.e that
294 -- it is an identifier, or a selected component whose prefix is
295 -- itself of the form of a library unit name. Note that this is
296 -- quite different from Check_Program_Unit, since it only checks
297 -- the syntactic form of the name, not the semantic identity. This
298 -- is because it is used with attributes (Elab_Body, Elab_Spec, and
299 -- UET_Address) which can refer to non-visible unit.
301 procedure Error_Attr (Msg : String; Error_Node : Node_Id);
302 pragma No_Return (Error_Attr);
303 procedure Error_Attr;
304 pragma No_Return (Error_Attr);
305 -- Posts error using Error_Msg_N at given node, sets type of attribute
306 -- node to Any_Type, and then raises Bad_Attribute to avoid any further
307 -- semantic processing. The message typically contains a % insertion
308 -- character which is replaced by the attribute name. The call with
309 -- no arguments is used when the caller has already generated the
310 -- required error messages.
312 procedure Standard_Attribute (Val : Int);
313 -- Used to process attributes whose prefix is package Standard which
314 -- yield values of type Universal_Integer. The attribute reference
315 -- node is rewritten with an integer literal of the given value.
317 procedure Unexpected_Argument (En : Node_Id);
318 -- Signal unexpected attribute argument (En is the argument)
320 procedure Validate_Non_Static_Attribute_Function_Call;
321 -- Called when processing an attribute that is a function call to a
322 -- non-static function, i.e. an attribute function that either takes
323 -- non-scalar arguments or returns a non-scalar result. Verifies that
324 -- such a call does not appear in a preelaborable context.
326 ------------------------------
327 -- Analyze_Access_Attribute --
328 ------------------------------
330 procedure Analyze_Access_Attribute is
331 Acc_Type : Entity_Id;
336 function Build_Access_Object_Type (DT : Entity_Id) return Entity_Id;
337 -- Build an access-to-object type whose designated type is DT,
338 -- and whose Ekind is appropriate to the attribute type. The
339 -- type that is constructed is returned as the result.
341 procedure Build_Access_Subprogram_Type (P : Node_Id);
342 -- Build an access to subprogram whose designated type is
343 -- the type of the prefix. If prefix is overloaded, so it the
344 -- node itself. The result is stored in Acc_Type.
346 ------------------------------
347 -- Build_Access_Object_Type --
348 ------------------------------
350 function Build_Access_Object_Type (DT : Entity_Id) return Entity_Id is
354 if Aname = Name_Unrestricted_Access then
357 (E_Allocator_Type, Current_Scope, Loc, 'A
');
361 (E_Access_Attribute_Type, Current_Scope, Loc, 'A
');
364 Set_Etype (Typ, Typ);
365 Init_Size_Align (Typ);
367 Set_Associated_Node_For_Itype (Typ, N);
368 Set_Directly_Designated_Type (Typ, DT);
370 end Build_Access_Object_Type;
372 ----------------------------------
373 -- Build_Access_Subprogram_Type --
374 ----------------------------------
376 procedure Build_Access_Subprogram_Type (P : Node_Id) is
377 Index : Interp_Index;
380 function Get_Kind (E : Entity_Id) return Entity_Kind;
381 -- Distinguish between access to regular/protected subprograms
387 function Get_Kind (E : Entity_Id) return Entity_Kind is
389 if Convention (E) = Convention_Protected then
390 return E_Access_Protected_Subprogram_Type;
392 return E_Access_Subprogram_Type;
396 -- Start of processing for Build_Access_Subprogram_Type
399 -- In the case of an access to subprogram, use the name of the
400 -- subprogram itself as the designated type. Type-checking in
401 -- this case compares the signatures of the designated types.
403 Set_Etype (N, Any_Type);
405 if not Is_Overloaded (P) then
406 if not Is_Intrinsic_Subprogram (Entity (P)) then
409 (Get_Kind (Entity (P)), Current_Scope, Loc, 'A
');
410 Set_Etype (Acc_Type, Acc_Type);
411 Set_Directly_Designated_Type (Acc_Type, Entity (P));
412 Set_Etype (N, Acc_Type);
416 Get_First_Interp (P, Index, It);
417 while Present (It.Nam) loop
418 if not Is_Intrinsic_Subprogram (It.Nam) then
421 (Get_Kind (It.Nam), Current_Scope, Loc, 'A
');
422 Set_Etype (Acc_Type, Acc_Type);
423 Set_Directly_Designated_Type (Acc_Type, It.Nam);
424 Add_One_Interp (N, Acc_Type, Acc_Type);
427 Get_Next_Interp (Index, It);
431 if Etype (N) = Any_Type then
432 Error_Attr ("prefix of % attribute cannot be intrinsic", P);
434 end Build_Access_Subprogram_Type;
436 -- Start of processing for Analyze_Access_Attribute
441 if Nkind (P) = N_Character_Literal then
443 ("prefix of % attribute cannot be enumeration literal", P);
446 -- Case of access to subprogram
448 if Is_Entity_Name (P)
449 and then Is_Overloadable (Entity (P))
451 -- Not allowed for nested subprograms if No_Implicit_Dynamic_Code
452 -- restriction set (since in general a trampoline is required).
454 if not Is_Library_Level_Entity (Entity (P)) then
455 Check_Restriction (No_Implicit_Dynamic_Code, P);
458 if Is_Always_Inlined (Entity (P)) then
460 ("prefix of % attribute cannot be Inline_Always subprogram",
464 -- Build the appropriate subprogram type
466 Build_Access_Subprogram_Type (P);
468 -- For unrestricted access, kill current values, since this
469 -- attribute allows a reference to a local subprogram that
470 -- could modify local variables to be passed out of scope
472 if Aname = Name_Unrestricted_Access then
478 -- Component is an operation of a protected type
480 elsif Nkind (P) = N_Selected_Component
481 and then Is_Overloadable (Entity (Selector_Name (P)))
483 if Ekind (Entity (Selector_Name (P))) = E_Entry then
484 Error_Attr ("prefix of % attribute must be subprogram", P);
487 Build_Access_Subprogram_Type (Selector_Name (P));
491 -- Deal with incorrect reference to a type, but note that some
492 -- accesses are allowed (references to the current type instance).
494 if Is_Entity_Name (P) then
495 Scop := Current_Scope;
498 if Is_Type (Typ) then
500 -- OK if we are within the scope of a limited type
501 -- let's mark the component as having per object constraint
503 if Is_Anonymous_Tagged_Base (Scop, Typ) then
511 Q : Node_Id := Parent (N);
515 and then Nkind (Q) /= N_Component_Declaration
520 Set_Has_Per_Object_Constraint (
521 Defining_Identifier (Q), True);
525 if Nkind (P) = N_Expanded_Name then
527 ("current instance prefix must be a direct name", P);
530 -- If a current instance attribute appears within a
531 -- a component constraint it must appear alone; other
532 -- contexts (default expressions, within a task body)
533 -- are not subject to this restriction.
535 if not In_Default_Expression
536 and then not Has_Completion (Scop)
538 Nkind (Parent (N)) /= N_Discriminant_Association
540 Nkind (Parent (N)) /= N_Index_Or_Discriminant_Constraint
543 ("current instance attribute must appear alone", N);
546 -- OK if we are in initialization procedure for the type
547 -- in question, in which case the reference to the type
548 -- is rewritten as a reference to the current object.
550 elsif Ekind (Scop) = E_Procedure
551 and then Is_Init_Proc (Scop)
552 and then Etype (First_Formal (Scop)) = Typ
555 Make_Attribute_Reference (Loc,
556 Prefix => Make_Identifier (Loc, Name_uInit),
557 Attribute_Name => Name_Unrestricted_Access));
561 -- OK if a task type, this test needs sharpening up ???
563 elsif Is_Task_Type (Typ) then
566 -- Otherwise we have an error case
569 Error_Attr ("% attribute cannot be applied to type", P);
575 -- If we fall through, we have a normal access to object case.
576 -- Unrestricted_Access is legal wherever an allocator would be
577 -- legal, so its Etype is set to E_Allocator. The expected type
578 -- of the other attributes is a general access type, and therefore
579 -- we label them with E_Access_Attribute_Type.
581 if not Is_Overloaded (P) then
582 Acc_Type := Build_Access_Object_Type (P_Type);
583 Set_Etype (N, Acc_Type);
586 Index : Interp_Index;
590 Set_Etype (N, Any_Type);
591 Get_First_Interp (P, Index, It);
593 while Present (It.Typ) loop
594 Acc_Type := Build_Access_Object_Type (It.Typ);
595 Add_One_Interp (N, Acc_Type, Acc_Type);
596 Get_Next_Interp (Index, It);
601 -- If we have an access to an object, and the attribute comes
602 -- from source, then set the object as potentially source modified.
603 -- We do this because the resulting access pointer can be used to
604 -- modify the variable, and we might not detect this, leading to
605 -- some junk warnings.
607 if Is_Entity_Name (P) then
608 Set_Never_Set_In_Source (Entity (P), False);
611 -- Check for aliased view unless unrestricted case. We allow
612 -- a nonaliased prefix when within an instance because the
613 -- prefix may have been a tagged formal object, which is
614 -- defined to be aliased even when the actual might not be
615 -- (other instance cases will have been caught in the generic).
616 -- Similarly, within an inlined body we know that the attribute
617 -- is legal in the original subprogram, and therefore legal in
620 if Aname /= Name_Unrestricted_Access
621 and then not Is_Aliased_View (P)
622 and then not In_Instance
623 and then not In_Inlined_Body
625 Error_Attr ("prefix of % attribute must be aliased", P);
627 end Analyze_Access_Attribute;
629 --------------------------------
630 -- Check_Array_Or_Scalar_Type --
631 --------------------------------
633 procedure Check_Array_Or_Scalar_Type is
637 -- Dimension number for array attributes
640 -- Case of string literal or string literal subtype. These cases
641 -- cannot arise from legal Ada code, but the expander is allowed
642 -- to generate them. They require special handling because string
643 -- literal subtypes do not have standard bounds (the whole idea
644 -- of these subtypes is to avoid having to generate the bounds)
646 if Ekind (P_Type) = E_String_Literal_Subtype then
647 Set_Etype (N, Etype (First_Index (P_Base_Type)));
652 elsif Is_Scalar_Type (P_Type) then
656 Error_Attr ("invalid argument in % attribute", E1);
658 Set_Etype (N, P_Base_Type);
662 -- The following is a special test to allow 'First to apply to
663 -- private scalar types if the attribute comes from generated
664 -- code. This occurs in the case of Normalize_Scalars code.
666 elsif Is_Private_Type
(P_Type
)
667 and then Present
(Full_View
(P_Type
))
668 and then Is_Scalar_Type
(Full_View
(P_Type
))
669 and then not Comes_From_Source
(N
)
671 Set_Etype
(N
, Implementation_Base_Type
(P_Type
));
673 -- Array types other than string literal subtypes handled above
678 -- We know prefix is an array type, or the name of an array
679 -- object, and that the expression, if present, is static
680 -- and within the range of the dimensions of the type.
682 pragma Assert
(Is_Array_Type
(P_Type
));
683 Index
:= First_Index
(P_Base_Type
);
687 -- First dimension assumed
689 Set_Etype
(N
, Base_Type
(Etype
(Index
)));
692 D
:= UI_To_Int
(Intval
(E1
));
694 for J
in 1 .. D
- 1 loop
698 Set_Etype
(N
, Base_Type
(Etype
(Index
)));
699 Set_Etype
(E1
, Standard_Integer
);
702 end Check_Array_Or_Scalar_Type
;
704 ----------------------
705 -- Check_Array_Type --
706 ----------------------
708 procedure Check_Array_Type
is
710 -- Dimension number for array attributes
713 -- If the type is a string literal type, then this must be generated
714 -- internally, and no further check is required on its legality.
716 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
719 -- If the type is a composite, it is an illegal aggregate, no point
722 elsif P_Type
= Any_Composite
then
726 -- Normal case of array type or subtype
728 Check_Either_E0_Or_E1
;
731 if Is_Array_Type
(P_Type
) then
732 if not Is_Constrained
(P_Type
)
733 and then Is_Entity_Name
(P
)
734 and then Is_Type
(Entity
(P
))
736 -- Note: we do not call Error_Attr here, since we prefer to
737 -- continue, using the relevant index type of the array,
738 -- even though it is unconstrained. This gives better error
739 -- recovery behavior.
741 Error_Msg_Name_1
:= Aname
;
743 ("prefix for % attribute must be constrained array", P
);
746 D
:= Number_Dimensions
(P_Type
);
749 if Is_Private_Type
(P_Type
) then
751 ("prefix for % attribute may not be private type", P
);
753 elsif Is_Access_Type
(P_Type
)
754 and then Is_Array_Type
(Designated_Type
(P_Type
))
755 and then Is_Entity_Name
(P
)
756 and then Is_Type
(Entity
(P
))
758 Error_Attr
("prefix of % attribute cannot be access type", P
);
760 elsif Attr_Id
= Attribute_First
762 Attr_Id
= Attribute_Last
764 Error_Attr
("invalid prefix for % attribute", P
);
767 Error_Attr
("prefix for % attribute must be array", P
);
772 Resolve
(E1
, Any_Integer
);
773 Set_Etype
(E1
, Standard_Integer
);
775 if not Is_Static_Expression
(E1
)
776 or else Raises_Constraint_Error
(E1
)
779 ("expression for dimension must be static!", E1
);
782 elsif UI_To_Int
(Expr_Value
(E1
)) > D
783 or else UI_To_Int
(Expr_Value
(E1
)) < 1
785 Error_Attr
("invalid dimension number for array type", E1
);
788 end Check_Array_Type
;
790 -------------------------
791 -- Check_Asm_Attribute --
792 -------------------------
794 procedure Check_Asm_Attribute
is
799 -- Check first argument is static string expression
801 Analyze_And_Resolve
(E1
, Standard_String
);
803 if Etype
(E1
) = Any_Type
then
806 elsif not Is_OK_Static_Expression
(E1
) then
808 ("constraint argument must be static string expression!", E1
);
812 -- Check second argument is right type
814 Analyze_And_Resolve
(E2
, Entity
(P
));
816 -- Note: that is all we need to do, we don't need to check
817 -- that it appears in a correct context. The Ada type system
818 -- will do that for us.
820 end Check_Asm_Attribute
;
822 ---------------------
823 -- Check_Component --
824 ---------------------
826 procedure Check_Component
is
830 if Nkind
(P
) /= N_Selected_Component
832 (Ekind
(Entity
(Selector_Name
(P
))) /= E_Component
834 Ekind
(Entity
(Selector_Name
(P
))) /= E_Discriminant
)
837 ("prefix for % attribute must be selected component", P
);
841 ------------------------------------
842 -- Check_Decimal_Fixed_Point_Type --
843 ------------------------------------
845 procedure Check_Decimal_Fixed_Point_Type
is
849 if not Is_Decimal_Fixed_Point_Type
(P_Type
) then
851 ("prefix of % attribute must be decimal type", P
);
853 end Check_Decimal_Fixed_Point_Type
;
855 -----------------------
856 -- Check_Dereference --
857 -----------------------
859 procedure Check_Dereference
is
862 -- Case of a subtype mark
864 if Is_Entity_Name
(P
)
865 and then Is_Type
(Entity
(P
))
870 -- Case of an expression
874 if Is_Access_Type
(P_Type
) then
876 -- If there is an implicit dereference, then we must freeze
877 -- the designated type of the access type, since the type of
878 -- the referenced array is this type (see AI95-00106).
880 Freeze_Before
(N
, Designated_Type
(P_Type
));
883 Make_Explicit_Dereference
(Sloc
(P
),
884 Prefix
=> Relocate_Node
(P
)));
886 Analyze_And_Resolve
(P
);
889 if P_Type
= Any_Type
then
893 P_Base_Type
:= Base_Type
(P_Type
);
895 end Check_Dereference
;
897 -------------------------
898 -- Check_Discrete_Type --
899 -------------------------
901 procedure Check_Discrete_Type
is
905 if not Is_Discrete_Type
(P_Type
) then
906 Error_Attr
("prefix of % attribute must be discrete type", P
);
908 end Check_Discrete_Type
;
914 procedure Check_E0
is
917 Unexpected_Argument
(E1
);
925 procedure Check_E1
is
927 Check_Either_E0_Or_E1
;
931 -- Special-case attributes that are functions and that appear as
932 -- the prefix of another attribute. Error is posted on parent.
934 if Nkind
(Parent
(N
)) = N_Attribute_Reference
935 and then (Attribute_Name
(Parent
(N
)) = Name_Address
937 Attribute_Name
(Parent
(N
)) = Name_Code_Address
939 Attribute_Name
(Parent
(N
)) = Name_Access
)
941 Error_Msg_Name_1
:= Attribute_Name
(Parent
(N
));
942 Error_Msg_N
("illegal prefix for % attribute", Parent
(N
));
943 Set_Etype
(Parent
(N
), Any_Type
);
944 Set_Entity
(Parent
(N
), Any_Type
);
948 Error_Attr
("missing argument for % attribute", N
);
957 procedure Check_E2
is
960 Error_Attr
("missing arguments for % attribute (2 required)", N
);
962 Error_Attr
("missing argument for % attribute (2 required)", N
);
966 ---------------------------
967 -- Check_Either_E0_Or_E1 --
968 ---------------------------
970 procedure Check_Either_E0_Or_E1
is
973 Unexpected_Argument
(E2
);
975 end Check_Either_E0_Or_E1
;
977 ----------------------
978 -- Check_Enum_Image --
979 ----------------------
981 procedure Check_Enum_Image
is
985 if Is_Enumeration_Type
(P_Base_Type
) then
986 Lit
:= First_Literal
(P_Base_Type
);
987 while Present
(Lit
) loop
988 Set_Referenced
(Lit
);
992 end Check_Enum_Image
;
994 ----------------------------
995 -- Check_Fixed_Point_Type --
996 ----------------------------
998 procedure Check_Fixed_Point_Type
is
1002 if not Is_Fixed_Point_Type
(P_Type
) then
1003 Error_Attr
("prefix of % attribute must be fixed point type", P
);
1005 end Check_Fixed_Point_Type
;
1007 ------------------------------
1008 -- Check_Fixed_Point_Type_0 --
1009 ------------------------------
1011 procedure Check_Fixed_Point_Type_0
is
1013 Check_Fixed_Point_Type
;
1015 end Check_Fixed_Point_Type_0
;
1017 -------------------------------
1018 -- Check_Floating_Point_Type --
1019 -------------------------------
1021 procedure Check_Floating_Point_Type
is
1025 if not Is_Floating_Point_Type
(P_Type
) then
1026 Error_Attr
("prefix of % attribute must be float type", P
);
1028 end Check_Floating_Point_Type
;
1030 ---------------------------------
1031 -- Check_Floating_Point_Type_0 --
1032 ---------------------------------
1034 procedure Check_Floating_Point_Type_0
is
1036 Check_Floating_Point_Type
;
1038 end Check_Floating_Point_Type_0
;
1040 ---------------------------------
1041 -- Check_Floating_Point_Type_1 --
1042 ---------------------------------
1044 procedure Check_Floating_Point_Type_1
is
1046 Check_Floating_Point_Type
;
1048 end Check_Floating_Point_Type_1
;
1050 ---------------------------------
1051 -- Check_Floating_Point_Type_2 --
1052 ---------------------------------
1054 procedure Check_Floating_Point_Type_2
is
1056 Check_Floating_Point_Type
;
1058 end Check_Floating_Point_Type_2
;
1060 ------------------------
1061 -- Check_Integer_Type --
1062 ------------------------
1064 procedure Check_Integer_Type
is
1068 if not Is_Integer_Type
(P_Type
) then
1069 Error_Attr
("prefix of % attribute must be integer type", P
);
1071 end Check_Integer_Type
;
1073 ------------------------
1074 -- Check_Library_Unit --
1075 ------------------------
1077 procedure Check_Library_Unit
is
1079 if not Is_Compilation_Unit
(Entity
(P
)) then
1080 Error_Attr
("prefix of % attribute must be library unit", P
);
1082 end Check_Library_Unit
;
1084 --------------------------------
1085 -- Check_Modular_Integer_Type --
1086 --------------------------------
1088 procedure Check_Modular_Integer_Type
is
1092 if not Is_Modular_Integer_Type
(P_Type
) then
1094 ("prefix of % attribute must be modular integer type", P
);
1096 end Check_Modular_Integer_Type
;
1098 -------------------------------
1099 -- Check_Not_Incomplete_Type --
1100 -------------------------------
1102 procedure Check_Not_Incomplete_Type
is
1107 -- Ada 2005 (AI-50217, AI-326): If the prefix is an explicit
1108 -- dereference we have to check wrong uses of incomplete types
1109 -- (other wrong uses are checked at their freezing point).
1111 -- Example 1: Limited-with
1113 -- limited with Pkg;
1115 -- type Acc is access Pkg.T;
1117 -- S : Integer := X.all'Size; -- ERROR
1120 -- Example 2: Tagged incomplete
1122 -- type T is tagged;
1123 -- type Acc is access all T;
1125 -- S : constant Integer := X.all'Size; -- ERROR
1126 -- procedure Q (Obj : Integer := X.all'Alignment); -- ERROR
1128 if Ada_Version
>= Ada_05
1129 and then Nkind
(P
) = N_Explicit_Dereference
1132 while Nkind
(E
) = N_Explicit_Dereference
loop
1136 if From_With_Type
(Etype
(E
)) then
1138 ("prefix of % attribute cannot be an incomplete type", P
);
1141 if Is_Access_Type
(Etype
(E
)) then
1142 Typ
:= Directly_Designated_Type
(Etype
(E
));
1147 if Ekind
(Typ
) = E_Incomplete_Type
1148 and then not Present
(Full_View
(Typ
))
1151 ("prefix of % attribute cannot be an incomplete type", P
);
1156 if not Is_Entity_Name
(P
)
1157 or else not Is_Type
(Entity
(P
))
1158 or else In_Default_Expression
1162 Check_Fully_Declared
(P_Type
, P
);
1164 end Check_Not_Incomplete_Type
;
1166 ----------------------------
1167 -- Check_Object_Reference --
1168 ----------------------------
1170 procedure Check_Object_Reference
(P
: Node_Id
) is
1174 -- If we need an object, and we have a prefix that is the name of
1175 -- a function entity, convert it into a function call.
1177 if Is_Entity_Name
(P
)
1178 and then Ekind
(Entity
(P
)) = E_Function
1180 Rtyp
:= Etype
(Entity
(P
));
1183 Make_Function_Call
(Sloc
(P
),
1184 Name
=> Relocate_Node
(P
)));
1186 Analyze_And_Resolve
(P
, Rtyp
);
1188 -- Otherwise we must have an object reference
1190 elsif not Is_Object_Reference
(P
) then
1191 Error_Attr
("prefix of % attribute must be object", P
);
1193 end Check_Object_Reference
;
1195 ------------------------
1196 -- Check_Program_Unit --
1197 ------------------------
1199 procedure Check_Program_Unit
is
1201 if Is_Entity_Name
(P
) then
1203 K
: constant Entity_Kind
:= Ekind
(Entity
(P
));
1204 T
: constant Entity_Id
:= Etype
(Entity
(P
));
1207 if K
in Subprogram_Kind
1208 or else K
in Task_Kind
1209 or else K
in Protected_Kind
1210 or else K
= E_Package
1211 or else K
in Generic_Unit_Kind
1212 or else (K
= E_Variable
1216 Is_Protected_Type
(T
)))
1223 Error_Attr
("prefix of % attribute must be program unit", P
);
1224 end Check_Program_Unit
;
1226 ---------------------
1227 -- Check_Real_Type --
1228 ---------------------
1230 procedure Check_Real_Type
is
1234 if not Is_Real_Type
(P_Type
) then
1235 Error_Attr
("prefix of % attribute must be real type", P
);
1237 end Check_Real_Type
;
1239 -----------------------
1240 -- Check_Scalar_Type --
1241 -----------------------
1243 procedure Check_Scalar_Type
is
1247 if not Is_Scalar_Type
(P_Type
) then
1248 Error_Attr
("prefix of % attribute must be scalar type", P
);
1250 end Check_Scalar_Type
;
1252 ---------------------------
1253 -- Check_Standard_Prefix --
1254 ---------------------------
1256 procedure Check_Standard_Prefix
is
1260 if Nkind
(P
) /= N_Identifier
1261 or else Chars
(P
) /= Name_Standard
1263 Error_Attr
("only allowed prefix for % attribute is Standard", P
);
1266 end Check_Standard_Prefix
;
1268 ----------------------------
1269 -- Check_Stream_Attribute --
1270 ----------------------------
1272 procedure Check_Stream_Attribute
(Nam
: TSS_Name_Type
) is
1276 Validate_Non_Static_Attribute_Function_Call
;
1278 -- With the exception of 'Input, Stream attributes are procedures,
1279 -- and can only appear at the position of procedure calls. We check
1280 -- for this here, before they are rewritten, to give a more precise
1283 if Nam
= TSS_Stream_Input
then
1286 elsif Is_List_Member
(N
)
1287 and then Nkind
(Parent
(N
)) /= N_Procedure_Call_Statement
1288 and then Nkind
(Parent
(N
)) /= N_Aggregate
1294 ("invalid context for attribute%, which is a procedure", N
);
1298 Btyp
:= Implementation_Base_Type
(P_Type
);
1300 -- Stream attributes not allowed on limited types unless the
1301 -- attribute reference was generated by the expander (in which
1302 -- case the underlying type will be used, as described in Sinfo),
1303 -- or the attribute was specified explicitly for the type itself
1304 -- or one of its ancestors (taking visibility rules into account if
1305 -- in Ada 2005 mode), or a pragma Stream_Convert applies to Btyp
1306 -- (with no visibility restriction).
1308 if Comes_From_Source
(N
)
1309 and then not Stream_Attribute_Available
(P_Type
, Nam
)
1310 and then not Has_Rep_Pragma
(Btyp
, Name_Stream_Convert
)
1312 Error_Msg_Name_1
:= Aname
;
1314 if Is_Limited_Type
(P_Type
) then
1316 ("limited type& has no% attribute", P
, P_Type
);
1317 Explain_Limited_Type
(P_Type
, P
);
1320 ("attribute% for type& is not available", P
, P_Type
);
1324 -- Check for violation of restriction No_Stream_Attributes
1326 if Is_RTE
(P_Type
, RE_Exception_Id
)
1328 Is_RTE
(P_Type
, RE_Exception_Occurrence
)
1330 Check_Restriction
(No_Exception_Registration
, P
);
1333 -- Here we must check that the first argument is an access type
1334 -- that is compatible with Ada.Streams.Root_Stream_Type'Class.
1336 Analyze_And_Resolve
(E1
);
1339 -- Note: the double call to Root_Type here is needed because the
1340 -- root type of a class-wide type is the corresponding type (e.g.
1341 -- X for X'Class, and we really want to go to the root.
1343 if not Is_Access_Type
(Etyp
)
1344 or else Root_Type
(Root_Type
(Designated_Type
(Etyp
))) /=
1345 RTE
(RE_Root_Stream_Type
)
1348 ("expected access to Ada.Streams.Root_Stream_Type''Class", E1
);
1351 -- Check that the second argument is of the right type if there is
1352 -- one (the Input attribute has only one argument so this is skipped)
1354 if Present
(E2
) then
1357 if Nam
= TSS_Stream_Read
1358 and then not Is_OK_Variable_For_Out_Formal
(E2
)
1361 ("second argument of % attribute must be a variable", E2
);
1364 Resolve
(E2
, P_Type
);
1366 end Check_Stream_Attribute
;
1368 -----------------------
1369 -- Check_Task_Prefix --
1370 -----------------------
1372 procedure Check_Task_Prefix
is
1376 if Is_Task_Type
(Etype
(P
))
1377 or else (Is_Access_Type
(Etype
(P
))
1378 and then Is_Task_Type
(Designated_Type
(Etype
(P
))))
1382 Error_Attr
("prefix of % attribute must be a task", P
);
1384 end Check_Task_Prefix
;
1390 -- The possibilities are an entity name denoting a type, or an
1391 -- attribute reference that denotes a type (Base or Class). If
1392 -- the type is incomplete, replace it with its full view.
1394 procedure Check_Type
is
1396 if not Is_Entity_Name
(P
)
1397 or else not Is_Type
(Entity
(P
))
1399 Error_Attr
("prefix of % attribute must be a type", P
);
1401 elsif Ekind
(Entity
(P
)) = E_Incomplete_Type
1402 and then Present
(Full_View
(Entity
(P
)))
1404 P_Type
:= Full_View
(Entity
(P
));
1405 Set_Entity
(P
, P_Type
);
1409 ---------------------
1410 -- Check_Unit_Name --
1411 ---------------------
1413 procedure Check_Unit_Name
(Nod
: Node_Id
) is
1415 if Nkind
(Nod
) = N_Identifier
then
1418 elsif Nkind
(Nod
) = N_Selected_Component
then
1419 Check_Unit_Name
(Prefix
(Nod
));
1421 if Nkind
(Selector_Name
(Nod
)) = N_Identifier
then
1426 Error_Attr
("argument for % attribute must be unit name", P
);
1427 end Check_Unit_Name
;
1433 procedure Error_Attr
is
1435 Set_Etype
(N
, Any_Type
);
1436 Set_Entity
(N
, Any_Type
);
1437 raise Bad_Attribute
;
1440 procedure Error_Attr
(Msg
: String; Error_Node
: Node_Id
) is
1442 Error_Msg_Name_1
:= Aname
;
1443 Error_Msg_N
(Msg
, Error_Node
);
1447 ----------------------------
1448 -- Legal_Formal_Attribute --
1449 ----------------------------
1451 procedure Legal_Formal_Attribute
is
1455 if not Is_Entity_Name
(P
)
1456 or else not Is_Type
(Entity
(P
))
1458 Error_Attr
("prefix of % attribute must be generic type", N
);
1460 elsif Is_Generic_Actual_Type
(Entity
(P
))
1462 or else In_Inlined_Body
1466 elsif Is_Generic_Type
(Entity
(P
)) then
1467 if not Is_Indefinite_Subtype
(Entity
(P
)) then
1469 ("prefix of % attribute must be indefinite generic type", N
);
1474 ("prefix of % attribute must be indefinite generic type", N
);
1477 Set_Etype
(N
, Standard_Boolean
);
1478 end Legal_Formal_Attribute
;
1480 ------------------------
1481 -- Standard_Attribute --
1482 ------------------------
1484 procedure Standard_Attribute
(Val
: Int
) is
1486 Check_Standard_Prefix
;
1488 -- First a special check (more like a kludge really). For GNAT5
1489 -- on Windows, the alignments in GCC are severely mixed up. In
1490 -- particular, we have a situation where the maximum alignment
1491 -- that GCC thinks is possible is greater than the guaranteed
1492 -- alignment at run-time. That causes many problems. As a partial
1493 -- cure for this situation, we force a value of 4 for the maximum
1494 -- alignment attribute on this target. This still does not solve
1495 -- all problems, but it helps.
1497 -- A further (even more horrible) dimension to this kludge is now
1498 -- installed. There are two uses for Maximum_Alignment, one is to
1499 -- determine the maximum guaranteed alignment, that's the one we
1500 -- want the kludge to yield as 4. The other use is to maximally
1501 -- align objects, we can't use 4 here, since for example, long
1502 -- long integer has an alignment of 8, so we will get errors.
1504 -- It is of course impossible to determine which use the programmer
1505 -- has in mind, but an approximation for now is to disconnect the
1506 -- kludge if the attribute appears in an alignment clause.
1508 -- To be removed if GCC ever gets its act together here ???
1510 Alignment_Kludge
: declare
1513 function On_X86
return Boolean;
1514 -- Determine if target is x86 (ia32), return True if so
1520 function On_X86
return Boolean is
1521 T
: constant String := Sdefault
.Target_Name
.all;
1524 -- There is no clean way to check this. That's not surprising,
1525 -- the front end should not be doing this kind of test ???. The
1526 -- way we do it is test for either "86" or "pentium" being in
1527 -- the string for the target name. However, we need to exclude
1528 -- x86_64 for this check.
1530 for J
in T
'First .. T
'Last - 1 loop
1531 if (T
(J
.. J
+ 1) = "86"
1534 or else T
(J
+ 2 .. J
+ 4) /= "_64"))
1535 or else (J
<= T
'Last - 6
1536 and then T
(J
.. J
+ 6) = "pentium")
1546 if Aname
= Name_Maximum_Alignment
and then On_X86
then
1549 while Nkind
(P
) in N_Subexpr
loop
1553 if Nkind
(P
) /= N_Attribute_Definition_Clause
1554 or else Chars
(P
) /= Name_Alignment
1556 Rewrite
(N
, Make_Integer_Literal
(Loc
, 4));
1561 end Alignment_Kludge
;
1563 -- Normally we get the value from gcc ???
1565 Rewrite
(N
, Make_Integer_Literal
(Loc
, Val
));
1567 end Standard_Attribute
;
1569 -------------------------
1570 -- Unexpected Argument --
1571 -------------------------
1573 procedure Unexpected_Argument
(En
: Node_Id
) is
1575 Error_Attr
("unexpected argument for % attribute", En
);
1576 end Unexpected_Argument
;
1578 -------------------------------------------------
1579 -- Validate_Non_Static_Attribute_Function_Call --
1580 -------------------------------------------------
1582 -- This function should be moved to Sem_Dist ???
1584 procedure Validate_Non_Static_Attribute_Function_Call
is
1586 if In_Preelaborated_Unit
1587 and then not In_Subprogram_Or_Concurrent_Unit
1589 Flag_Non_Static_Expr
1590 ("non-static function call in preelaborated unit!", N
);
1592 end Validate_Non_Static_Attribute_Function_Call
;
1594 -----------------------------------------------
1595 -- Start of Processing for Analyze_Attribute --
1596 -----------------------------------------------
1599 -- Immediate return if unrecognized attribute (already diagnosed
1600 -- by parser, so there is nothing more that we need to do)
1602 if not Is_Attribute_Name
(Aname
) then
1603 raise Bad_Attribute
;
1606 -- Deal with Ada 83 and Features issues
1608 if Comes_From_Source
(N
) then
1609 if not Attribute_83
(Attr_Id
) then
1610 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
1611 Error_Msg_Name_1
:= Aname
;
1612 Error_Msg_N
("(Ada 83) attribute% is not standard?", N
);
1615 if Attribute_Impl_Def
(Attr_Id
) then
1616 Check_Restriction
(No_Implementation_Attributes
, N
);
1621 -- Remote access to subprogram type access attribute reference needs
1622 -- unanalyzed copy for tree transformation. The analyzed copy is used
1623 -- for its semantic information (whether prefix is a remote subprogram
1624 -- name), the unanalyzed copy is used to construct new subtree rooted
1625 -- with N_Aggregate which represents a fat pointer aggregate.
1627 if Aname
= Name_Access
then
1628 Discard_Node
(Copy_Separate_Tree
(N
));
1631 -- Analyze prefix and exit if error in analysis. If the prefix is an
1632 -- incomplete type, use full view if available. A special case is
1633 -- that we never analyze the prefix of an Elab_Body or Elab_Spec
1634 -- or UET_Address attribute.
1636 if Aname
/= Name_Elab_Body
1638 Aname
/= Name_Elab_Spec
1640 Aname
/= Name_UET_Address
1643 P_Type
:= Etype
(P
);
1645 if Is_Entity_Name
(P
)
1646 and then Present
(Entity
(P
))
1647 and then Is_Type
(Entity
(P
))
1648 and then Ekind
(Entity
(P
)) = E_Incomplete_Type
1650 P_Type
:= Get_Full_View
(P_Type
);
1651 Set_Entity
(P
, P_Type
);
1652 Set_Etype
(P
, P_Type
);
1655 if P_Type
= Any_Type
then
1656 raise Bad_Attribute
;
1659 P_Base_Type
:= Base_Type
(P_Type
);
1662 -- Analyze expressions that may be present, exiting if an error occurs
1669 E1
:= First
(Exprs
);
1672 -- Check for missing or bad expression (result of previous error)
1674 if No
(E1
) or else Etype
(E1
) = Any_Type
then
1675 raise Bad_Attribute
;
1680 if Present
(E2
) then
1683 if Etype
(E2
) = Any_Type
then
1684 raise Bad_Attribute
;
1687 if Present
(Next
(E2
)) then
1688 Unexpected_Argument
(Next
(E2
));
1693 -- Ada 2005 (AI-345): Ensure that the compiler gives exactly the current
1694 -- output compiling in Ada 95 mode
1696 if Ada_Version
< Ada_05
1697 and then Is_Overloaded
(P
)
1698 and then Aname
/= Name_Access
1699 and then Aname
/= Name_Address
1700 and then Aname
/= Name_Code_Address
1701 and then Aname
/= Name_Count
1702 and then Aname
/= Name_Unchecked_Access
1704 Error_Attr
("ambiguous prefix for % attribute", P
);
1706 elsif Ada_Version
>= Ada_05
1707 and then Is_Overloaded
(P
)
1708 and then Aname
/= Name_Access
1709 and then Aname
/= Name_Address
1710 and then Aname
/= Name_Code_Address
1711 and then Aname
/= Name_Unchecked_Access
1713 -- Ada 2005 (AI-345): Since protected and task types have primitive
1714 -- entry wrappers, the attributes Count, Caller and AST_Entry require
1717 if Ada_Version
>= Ada_05
1718 and then (Aname
= Name_Count
1719 or else Aname
= Name_Caller
1720 or else Aname
= Name_AST_Entry
)
1723 Count
: Natural := 0;
1728 Get_First_Interp
(P
, I
, It
);
1730 while Present
(It
.Nam
) loop
1731 if Comes_From_Source
(It
.Nam
) then
1737 Get_Next_Interp
(I
, It
);
1741 Error_Attr
("ambiguous prefix for % attribute", P
);
1743 Set_Is_Overloaded
(P
, False);
1748 Error_Attr
("ambiguous prefix for % attribute", P
);
1752 -- Remaining processing depends on attribute
1760 when Attribute_Abort_Signal
=>
1761 Check_Standard_Prefix
;
1763 New_Reference_To
(Stand
.Abort_Signal
, Loc
));
1770 when Attribute_Access
=>
1771 Analyze_Access_Attribute
;
1777 when Attribute_Address
=>
1780 -- Check for some junk cases, where we have to allow the address
1781 -- attribute but it does not make much sense, so at least for now
1782 -- just replace with Null_Address.
1784 -- We also do this if the prefix is a reference to the AST_Entry
1785 -- attribute. If expansion is active, the attribute will be
1786 -- replaced by a function call, and address will work fine and
1787 -- get the proper value, but if expansion is not active, then
1788 -- the check here allows proper semantic analysis of the reference.
1790 -- An Address attribute created by expansion is legal even when it
1791 -- applies to other entity-denoting expressions.
1793 if Is_Entity_Name
(P
) then
1795 Ent
: constant Entity_Id
:= Entity
(P
);
1798 if Is_Subprogram
(Ent
) then
1799 if not Is_Library_Level_Entity
(Ent
) then
1800 Check_Restriction
(No_Implicit_Dynamic_Code
, P
);
1803 Set_Address_Taken
(Ent
);
1805 -- An Address attribute is accepted when generated by
1806 -- the compiler for dispatching operation, and an error
1807 -- is issued once the subprogram is frozen (to avoid
1808 -- confusing errors about implicit uses of Address in
1809 -- the dispatch table initialization).
1811 if Is_Always_Inlined
(Entity
(P
))
1812 and then Comes_From_Source
(P
)
1815 ("prefix of % attribute cannot be Inline_Always" &
1819 elsif Is_Object
(Ent
)
1820 or else Ekind
(Ent
) = E_Label
1822 Set_Address_Taken
(Ent
);
1824 -- If we have an address of an object, and the attribute
1825 -- comes from source, then set the object as potentially
1826 -- source modified. We do this because the resulting address
1827 -- can potentially be used to modify the variable and we
1828 -- might not detect this, leading to some junk warnings.
1830 Set_Never_Set_In_Source
(Ent
, False);
1832 elsif (Is_Concurrent_Type
(Etype
(Ent
))
1833 and then Etype
(Ent
) = Base_Type
(Ent
))
1834 or else Ekind
(Ent
) = E_Package
1835 or else Is_Generic_Unit
(Ent
)
1838 New_Occurrence_Of
(RTE
(RE_Null_Address
), Sloc
(N
)));
1841 Error_Attr
("invalid prefix for % attribute", P
);
1845 elsif Nkind
(P
) = N_Attribute_Reference
1846 and then Attribute_Name
(P
) = Name_AST_Entry
1849 New_Occurrence_Of
(RTE
(RE_Null_Address
), Sloc
(N
)));
1851 elsif Is_Object_Reference
(P
) then
1854 elsif Nkind
(P
) = N_Selected_Component
1855 and then Is_Subprogram
(Entity
(Selector_Name
(P
)))
1859 -- What exactly are we allowing here ??? and is this properly
1860 -- documented in the sinfo documentation for this node ???
1862 elsif not Comes_From_Source
(N
) then
1866 Error_Attr
("invalid prefix for % attribute", P
);
1869 Set_Etype
(N
, RTE
(RE_Address
));
1875 when Attribute_Address_Size
=>
1876 Standard_Attribute
(System_Address_Size
);
1882 when Attribute_Adjacent
=>
1883 Check_Floating_Point_Type_2
;
1884 Set_Etype
(N
, P_Base_Type
);
1885 Resolve
(E1
, P_Base_Type
);
1886 Resolve
(E2
, P_Base_Type
);
1892 when Attribute_Aft
=>
1893 Check_Fixed_Point_Type_0
;
1894 Set_Etype
(N
, Universal_Integer
);
1900 when Attribute_Alignment
=>
1902 -- Don't we need more checking here, cf Size ???
1905 Check_Not_Incomplete_Type
;
1906 Set_Etype
(N
, Universal_Integer
);
1912 when Attribute_Asm_Input
=>
1913 Check_Asm_Attribute
;
1914 Set_Etype
(N
, RTE
(RE_Asm_Input_Operand
));
1920 when Attribute_Asm_Output
=>
1921 Check_Asm_Attribute
;
1923 if Etype
(E2
) = Any_Type
then
1926 elsif Aname
= Name_Asm_Output
then
1927 if not Is_Variable
(E2
) then
1929 ("second argument for Asm_Output is not variable", E2
);
1933 Note_Possible_Modification
(E2
);
1934 Set_Etype
(N
, RTE
(RE_Asm_Output_Operand
));
1940 when Attribute_AST_Entry
=> AST_Entry
: declare
1946 -- Indicates if entry family index is present. Note the coding
1947 -- here handles the entry family case, but in fact it cannot be
1948 -- executed currently, because pragma AST_Entry does not permit
1949 -- the specification of an entry family.
1951 procedure Bad_AST_Entry
;
1952 -- Signal a bad AST_Entry pragma
1954 function OK_Entry
(E
: Entity_Id
) return Boolean;
1955 -- Checks that E is of an appropriate entity kind for an entry
1956 -- (i.e. E_Entry if Index is False, or E_Entry_Family if Index
1957 -- is set True for the entry family case). In the True case,
1958 -- makes sure that Is_AST_Entry is set on the entry.
1960 procedure Bad_AST_Entry
is
1962 Error_Attr
("prefix for % attribute must be task entry", P
);
1965 function OK_Entry
(E
: Entity_Id
) return Boolean is
1970 Result
:= (Ekind
(E
) = E_Entry_Family
);
1972 Result
:= (Ekind
(E
) = E_Entry
);
1976 if not Is_AST_Entry
(E
) then
1977 Error_Msg_Name_2
:= Aname
;
1979 ("% attribute requires previous % pragma", P
);
1986 -- Start of processing for AST_Entry
1992 -- Deal with entry family case
1994 if Nkind
(P
) = N_Indexed_Component
then
2002 Ptyp
:= Etype
(Pref
);
2004 if Ptyp
= Any_Type
or else Error_Posted
(Pref
) then
2008 -- If the prefix is a selected component whose prefix is of an
2009 -- access type, then introduce an explicit dereference.
2010 -- ??? Could we reuse Check_Dereference here?
2012 if Nkind
(Pref
) = N_Selected_Component
2013 and then Is_Access_Type
(Ptyp
)
2016 Make_Explicit_Dereference
(Sloc
(Pref
),
2017 Relocate_Node
(Pref
)));
2018 Analyze_And_Resolve
(Pref
, Designated_Type
(Ptyp
));
2021 -- Prefix can be of the form a.b, where a is a task object
2022 -- and b is one of the entries of the corresponding task type.
2024 if Nkind
(Pref
) = N_Selected_Component
2025 and then OK_Entry
(Entity
(Selector_Name
(Pref
)))
2026 and then Is_Object_Reference
(Prefix
(Pref
))
2027 and then Is_Task_Type
(Etype
(Prefix
(Pref
)))
2031 -- Otherwise the prefix must be an entry of a containing task,
2032 -- or of a variable of the enclosing task type.
2035 if Nkind
(Pref
) = N_Identifier
2036 or else Nkind
(Pref
) = N_Expanded_Name
2038 Ent
:= Entity
(Pref
);
2040 if not OK_Entry
(Ent
)
2041 or else not In_Open_Scopes
(Scope
(Ent
))
2051 Set_Etype
(N
, RTE
(RE_AST_Handler
));
2058 -- Note: when the base attribute appears in the context of a subtype
2059 -- mark, the analysis is done by Sem_Ch8.Find_Type, rather than by
2060 -- the following circuit.
2062 when Attribute_Base
=> Base
: declare
2066 Check_Either_E0_Or_E1
;
2070 if Ada_Version
>= Ada_95
2071 and then not Is_Scalar_Type
(Typ
)
2072 and then not Is_Generic_Type
(Typ
)
2074 Error_Msg_N
("prefix of Base attribute must be scalar type", N
);
2076 elsif Sloc
(Typ
) = Standard_Location
2077 and then Base_Type
(Typ
) = Typ
2078 and then Warn_On_Redundant_Constructs
2081 ("?redudant attribute, & is its own base type", N
, Typ
);
2084 Set_Etype
(N
, Base_Type
(Entity
(P
)));
2086 -- If we have an expression present, then really this is a conversion
2087 -- and the tree must be reformed. Note that this is one of the cases
2088 -- in which we do a replace rather than a rewrite, because the
2089 -- original tree is junk.
2091 if Present
(E1
) then
2093 Make_Type_Conversion
(Loc
,
2095 Make_Attribute_Reference
(Loc
,
2096 Prefix
=> Prefix
(N
),
2097 Attribute_Name
=> Name_Base
),
2098 Expression
=> Relocate_Node
(E1
)));
2100 -- E1 may be overloaded, and its interpretations preserved
2102 Save_Interps
(E1
, Expression
(N
));
2105 -- For other cases, set the proper type as the entity of the
2106 -- attribute reference, and then rewrite the node to be an
2107 -- occurrence of the referenced base type. This way, no one
2108 -- else in the compiler has to worry about the base attribute.
2111 Set_Entity
(N
, Base_Type
(Entity
(P
)));
2113 New_Reference_To
(Entity
(N
), Loc
));
2122 when Attribute_Bit
=> Bit
:
2126 if not Is_Object_Reference
(P
) then
2127 Error_Attr
("prefix for % attribute must be object", P
);
2129 -- What about the access object cases ???
2135 Set_Etype
(N
, Universal_Integer
);
2142 when Attribute_Bit_Order
=> Bit_Order
:
2147 if not Is_Record_Type
(P_Type
) then
2148 Error_Attr
("prefix of % attribute must be record type", P
);
2151 if Bytes_Big_Endian
xor Reverse_Bit_Order
(P_Type
) then
2153 New_Occurrence_Of
(RTE
(RE_High_Order_First
), Loc
));
2156 New_Occurrence_Of
(RTE
(RE_Low_Order_First
), Loc
));
2159 Set_Etype
(N
, RTE
(RE_Bit_Order
));
2162 -- Reset incorrect indication of staticness
2164 Set_Is_Static_Expression
(N
, False);
2171 -- Note: in generated code, we can have a Bit_Position attribute
2172 -- applied to a (naked) record component (i.e. the prefix is an
2173 -- identifier that references an E_Component or E_Discriminant
2174 -- entity directly, and this is interpreted as expected by Gigi.
2175 -- The following code will not tolerate such usage, but when the
2176 -- expander creates this special case, it marks it as analyzed
2177 -- immediately and sets an appropriate type.
2179 when Attribute_Bit_Position
=>
2181 if Comes_From_Source
(N
) then
2185 Set_Etype
(N
, Universal_Integer
);
2191 when Attribute_Body_Version
=>
2194 Set_Etype
(N
, RTE
(RE_Version_String
));
2200 when Attribute_Callable
=>
2202 Set_Etype
(N
, Standard_Boolean
);
2209 when Attribute_Caller
=> Caller
: declare
2216 if Nkind
(P
) = N_Identifier
2217 or else Nkind
(P
) = N_Expanded_Name
2221 if not Is_Entry
(Ent
) then
2222 Error_Attr
("invalid entry name", N
);
2226 Error_Attr
("invalid entry name", N
);
2230 for J
in reverse 0 .. Scope_Stack
.Last
loop
2231 S
:= Scope_Stack
.Table
(J
).Entity
;
2233 if S
= Scope
(Ent
) then
2234 Error_Attr
("Caller must appear in matching accept or body", N
);
2240 Set_Etype
(N
, RTE
(RO_AT_Task_Id
));
2247 when Attribute_Ceiling
=>
2248 Check_Floating_Point_Type_1
;
2249 Set_Etype
(N
, P_Base_Type
);
2250 Resolve
(E1
, P_Base_Type
);
2256 when Attribute_Class
=> Class
: declare
2258 Check_Restriction
(No_Dispatch
, N
);
2259 Check_Either_E0_Or_E1
;
2261 -- If we have an expression present, then really this is a conversion
2262 -- and the tree must be reformed into a proper conversion. This is a
2263 -- Replace rather than a Rewrite, because the original tree is junk.
2264 -- If expression is overloaded, propagate interpretations to new one.
2266 if Present
(E1
) then
2268 Make_Type_Conversion
(Loc
,
2270 Make_Attribute_Reference
(Loc
,
2271 Prefix
=> Prefix
(N
),
2272 Attribute_Name
=> Name_Class
),
2273 Expression
=> Relocate_Node
(E1
)));
2275 Save_Interps
(E1
, Expression
(N
));
2278 -- Otherwise we just need to find the proper type
2290 when Attribute_Code_Address
=>
2293 if Nkind
(P
) = N_Attribute_Reference
2294 and then (Attribute_Name
(P
) = Name_Elab_Body
2296 Attribute_Name
(P
) = Name_Elab_Spec
)
2300 elsif not Is_Entity_Name
(P
)
2301 or else (Ekind
(Entity
(P
)) /= E_Function
2303 Ekind
(Entity
(P
)) /= E_Procedure
)
2305 Error_Attr
("invalid prefix for % attribute", P
);
2306 Set_Address_Taken
(Entity
(P
));
2309 Set_Etype
(N
, RTE
(RE_Address
));
2311 --------------------
2312 -- Component_Size --
2313 --------------------
2315 when Attribute_Component_Size
=>
2317 Set_Etype
(N
, Universal_Integer
);
2319 -- Note: unlike other array attributes, unconstrained arrays are OK
2321 if Is_Array_Type
(P_Type
) and then not Is_Constrained
(P_Type
) then
2331 when Attribute_Compose
=>
2332 Check_Floating_Point_Type_2
;
2333 Set_Etype
(N
, P_Base_Type
);
2334 Resolve
(E1
, P_Base_Type
);
2335 Resolve
(E2
, Any_Integer
);
2341 when Attribute_Constrained
=>
2343 Set_Etype
(N
, Standard_Boolean
);
2345 -- Case from RM J.4(2) of constrained applied to private type
2347 if Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)) then
2348 Check_Restriction
(No_Obsolescent_Features
, N
);
2350 if Warn_On_Obsolescent_Feature
then
2352 ("constrained for private type is an " &
2353 "obsolescent feature ('R'M 'J.4)?", N
);
2356 -- If we are within an instance, the attribute must be legal
2357 -- because it was valid in the generic unit. Ditto if this is
2358 -- an inlining of a function declared in an instance.
2361 or else In_Inlined_Body
2365 -- For sure OK if we have a real private type itself, but must
2366 -- be completed, cannot apply Constrained to incomplete type.
2368 elsif Is_Private_Type
(Entity
(P
)) then
2370 -- Note: this is one of the Annex J features that does not
2371 -- generate a warning from -gnatwj, since in fact it seems
2372 -- very useful, and is used in the GNAT runtime.
2374 Check_Not_Incomplete_Type
;
2378 -- Normal (non-obsolescent case) of application to object of
2379 -- a discriminated type.
2382 Check_Object_Reference
(P
);
2384 -- If N does not come from source, then we allow the
2385 -- the attribute prefix to be of a private type whose
2386 -- full type has discriminants. This occurs in cases
2387 -- involving expanded calls to stream attributes.
2389 if not Comes_From_Source
(N
) then
2390 P_Type
:= Underlying_Type
(P_Type
);
2393 -- Must have discriminants or be an access type designating
2394 -- a type with discriminants. If it is a classwide type is
2395 -- has unknown discriminants.
2397 if Has_Discriminants
(P_Type
)
2398 or else Has_Unknown_Discriminants
(P_Type
)
2400 (Is_Access_Type
(P_Type
)
2401 and then Has_Discriminants
(Designated_Type
(P_Type
)))
2405 -- Also allow an object of a generic type if extensions allowed
2406 -- and allow this for any type at all.
2408 elsif (Is_Generic_Type
(P_Type
)
2409 or else Is_Generic_Actual_Type
(P_Type
))
2410 and then Extensions_Allowed
2416 -- Fall through if bad prefix
2419 ("prefix of % attribute must be object of discriminated type", P
);
2425 when Attribute_Copy_Sign
=>
2426 Check_Floating_Point_Type_2
;
2427 Set_Etype
(N
, P_Base_Type
);
2428 Resolve
(E1
, P_Base_Type
);
2429 Resolve
(E2
, P_Base_Type
);
2435 when Attribute_Count
=> Count
:
2444 if Nkind
(P
) = N_Identifier
2445 or else Nkind
(P
) = N_Expanded_Name
2449 if Ekind
(Ent
) /= E_Entry
then
2450 Error_Attr
("invalid entry name", N
);
2453 elsif Nkind
(P
) = N_Indexed_Component
then
2454 if not Is_Entity_Name
(Prefix
(P
))
2455 or else No
(Entity
(Prefix
(P
)))
2456 or else Ekind
(Entity
(Prefix
(P
))) /= E_Entry_Family
2458 if Nkind
(Prefix
(P
)) = N_Selected_Component
2459 and then Present
(Entity
(Selector_Name
(Prefix
(P
))))
2460 and then Ekind
(Entity
(Selector_Name
(Prefix
(P
)))) =
2464 ("attribute % must apply to entry of current task", P
);
2467 Error_Attr
("invalid entry family name", P
);
2472 Ent
:= Entity
(Prefix
(P
));
2475 elsif Nkind
(P
) = N_Selected_Component
2476 and then Present
(Entity
(Selector_Name
(P
)))
2477 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Entry
2480 ("attribute % must apply to entry of current task", P
);
2483 Error_Attr
("invalid entry name", N
);
2487 for J
in reverse 0 .. Scope_Stack
.Last
loop
2488 S
:= Scope_Stack
.Table
(J
).Entity
;
2490 if S
= Scope
(Ent
) then
2491 if Nkind
(P
) = N_Expanded_Name
then
2492 Tsk
:= Entity
(Prefix
(P
));
2494 -- The prefix denotes either the task type, or else a
2495 -- single task whose task type is being analyzed.
2500 or else (not Is_Type
(Tsk
)
2501 and then Etype
(Tsk
) = S
2502 and then not (Comes_From_Source
(S
)))
2507 ("Attribute % must apply to entry of current task", N
);
2513 elsif Ekind
(Scope
(Ent
)) in Task_Kind
2514 and then Ekind
(S
) /= E_Loop
2515 and then Ekind
(S
) /= E_Block
2516 and then Ekind
(S
) /= E_Entry
2517 and then Ekind
(S
) /= E_Entry_Family
2519 Error_Attr
("Attribute % cannot appear in inner unit", N
);
2521 elsif Ekind
(Scope
(Ent
)) = E_Protected_Type
2522 and then not Has_Completion
(Scope
(Ent
))
2524 Error_Attr
("attribute % can only be used inside body", N
);
2528 if Is_Overloaded
(P
) then
2530 Index
: Interp_Index
;
2534 Get_First_Interp
(P
, Index
, It
);
2536 while Present
(It
.Nam
) loop
2537 if It
.Nam
= Ent
then
2540 -- Ada 2005 (AI-345): Do not consider primitive entry
2541 -- wrappers generated for task or protected types.
2543 elsif Ada_Version
>= Ada_05
2544 and then not Comes_From_Source
(It
.Nam
)
2549 Error_Attr
("ambiguous entry name", N
);
2552 Get_Next_Interp
(Index
, It
);
2557 Set_Etype
(N
, Universal_Integer
);
2560 -----------------------
2561 -- Default_Bit_Order --
2562 -----------------------
2564 when Attribute_Default_Bit_Order
=> Default_Bit_Order
:
2566 Check_Standard_Prefix
;
2569 if Bytes_Big_Endian
then
2571 Make_Integer_Literal
(Loc
, False_Value
));
2574 Make_Integer_Literal
(Loc
, True_Value
));
2577 Set_Etype
(N
, Universal_Integer
);
2578 Set_Is_Static_Expression
(N
);
2579 end Default_Bit_Order
;
2585 when Attribute_Definite
=>
2586 Legal_Formal_Attribute
;
2592 when Attribute_Delta
=>
2593 Check_Fixed_Point_Type_0
;
2594 Set_Etype
(N
, Universal_Real
);
2600 when Attribute_Denorm
=>
2601 Check_Floating_Point_Type_0
;
2602 Set_Etype
(N
, Standard_Boolean
);
2608 when Attribute_Digits
=>
2612 if not Is_Floating_Point_Type
(P_Type
)
2613 and then not Is_Decimal_Fixed_Point_Type
(P_Type
)
2616 ("prefix of % attribute must be float or decimal type", P
);
2619 Set_Etype
(N
, Universal_Integer
);
2625 -- Also handles processing for Elab_Spec
2627 when Attribute_Elab_Body | Attribute_Elab_Spec
=>
2629 Check_Unit_Name
(P
);
2630 Set_Etype
(N
, Standard_Void_Type
);
2632 -- We have to manually call the expander in this case to get
2633 -- the necessary expansion (normally attributes that return
2634 -- entities are not expanded).
2642 -- Shares processing with Elab_Body
2648 when Attribute_Elaborated
=>
2651 Set_Etype
(N
, Standard_Boolean
);
2657 when Attribute_Emax
=>
2658 Check_Floating_Point_Type_0
;
2659 Set_Etype
(N
, Universal_Integer
);
2665 when Attribute_Enum_Rep
=> Enum_Rep
: declare
2667 if Present
(E1
) then
2669 Check_Discrete_Type
;
2670 Resolve
(E1
, P_Base_Type
);
2673 if not Is_Entity_Name
(P
)
2674 or else (not Is_Object
(Entity
(P
))
2676 Ekind
(Entity
(P
)) /= E_Enumeration_Literal
)
2679 ("prefix of %attribute must be " &
2680 "discrete type/object or enum literal", P
);
2684 Set_Etype
(N
, Universal_Integer
);
2691 when Attribute_Epsilon
=>
2692 Check_Floating_Point_Type_0
;
2693 Set_Etype
(N
, Universal_Real
);
2699 when Attribute_Exponent
=>
2700 Check_Floating_Point_Type_1
;
2701 Set_Etype
(N
, Universal_Integer
);
2702 Resolve
(E1
, P_Base_Type
);
2708 when Attribute_External_Tag
=>
2712 Set_Etype
(N
, Standard_String
);
2714 if not Is_Tagged_Type
(P_Type
) then
2715 Error_Attr
("prefix of % attribute must be tagged", P
);
2722 when Attribute_First
=>
2723 Check_Array_Or_Scalar_Type
;
2729 when Attribute_First_Bit
=>
2731 Set_Etype
(N
, Universal_Integer
);
2737 when Attribute_Fixed_Value
=>
2739 Check_Fixed_Point_Type
;
2740 Resolve
(E1
, Any_Integer
);
2741 Set_Etype
(N
, P_Base_Type
);
2747 when Attribute_Floor
=>
2748 Check_Floating_Point_Type_1
;
2749 Set_Etype
(N
, P_Base_Type
);
2750 Resolve
(E1
, P_Base_Type
);
2756 when Attribute_Fore
=>
2757 Check_Fixed_Point_Type_0
;
2758 Set_Etype
(N
, Universal_Integer
);
2764 when Attribute_Fraction
=>
2765 Check_Floating_Point_Type_1
;
2766 Set_Etype
(N
, P_Base_Type
);
2767 Resolve
(E1
, P_Base_Type
);
2769 -----------------------
2770 -- Has_Access_Values --
2771 -----------------------
2773 when Attribute_Has_Access_Values
=>
2776 Set_Etype
(N
, Standard_Boolean
);
2778 -----------------------
2779 -- Has_Discriminants --
2780 -----------------------
2782 when Attribute_Has_Discriminants
=>
2783 Legal_Formal_Attribute
;
2789 when Attribute_Identity
=>
2793 if Etype
(P
) = Standard_Exception_Type
then
2794 Set_Etype
(N
, RTE
(RE_Exception_Id
));
2796 elsif Is_Task_Type
(Etype
(P
))
2797 or else (Is_Access_Type
(Etype
(P
))
2798 and then Is_Task_Type
(Designated_Type
(Etype
(P
))))
2801 Set_Etype
(N
, RTE
(RO_AT_Task_Id
));
2804 Error_Attr
("prefix of % attribute must be a task or an "
2812 when Attribute_Image
=> Image
:
2814 Set_Etype
(N
, Standard_String
);
2817 if Is_Real_Type
(P_Type
) then
2818 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
2819 Error_Msg_Name_1
:= Aname
;
2821 ("(Ada 83) % attribute not allowed for real types", N
);
2825 if Is_Enumeration_Type
(P_Type
) then
2826 Check_Restriction
(No_Enumeration_Maps
, N
);
2830 Resolve
(E1
, P_Base_Type
);
2832 Validate_Non_Static_Attribute_Function_Call
;
2839 when Attribute_Img
=> Img
:
2841 Set_Etype
(N
, Standard_String
);
2843 if not Is_Scalar_Type
(P_Type
)
2844 or else (Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)))
2847 ("prefix of % attribute must be scalar object name", N
);
2857 when Attribute_Input
=>
2859 Check_Stream_Attribute
(TSS_Stream_Input
);
2860 Set_Etype
(N
, P_Base_Type
);
2866 when Attribute_Integer_Value
=>
2869 Resolve
(E1
, Any_Fixed
);
2870 Set_Etype
(N
, P_Base_Type
);
2876 when Attribute_Large
=>
2879 Set_Etype
(N
, Universal_Real
);
2885 when Attribute_Last
=>
2886 Check_Array_Or_Scalar_Type
;
2892 when Attribute_Last_Bit
=>
2894 Set_Etype
(N
, Universal_Integer
);
2900 when Attribute_Leading_Part
=>
2901 Check_Floating_Point_Type_2
;
2902 Set_Etype
(N
, P_Base_Type
);
2903 Resolve
(E1
, P_Base_Type
);
2904 Resolve
(E2
, Any_Integer
);
2910 when Attribute_Length
=>
2912 Set_Etype
(N
, Universal_Integer
);
2918 when Attribute_Machine
=>
2919 Check_Floating_Point_Type_1
;
2920 Set_Etype
(N
, P_Base_Type
);
2921 Resolve
(E1
, P_Base_Type
);
2927 when Attribute_Machine_Emax
=>
2928 Check_Floating_Point_Type_0
;
2929 Set_Etype
(N
, Universal_Integer
);
2935 when Attribute_Machine_Emin
=>
2936 Check_Floating_Point_Type_0
;
2937 Set_Etype
(N
, Universal_Integer
);
2939 ----------------------
2940 -- Machine_Mantissa --
2941 ----------------------
2943 when Attribute_Machine_Mantissa
=>
2944 Check_Floating_Point_Type_0
;
2945 Set_Etype
(N
, Universal_Integer
);
2947 -----------------------
2948 -- Machine_Overflows --
2949 -----------------------
2951 when Attribute_Machine_Overflows
=>
2954 Set_Etype
(N
, Standard_Boolean
);
2960 when Attribute_Machine_Radix
=>
2963 Set_Etype
(N
, Universal_Integer
);
2965 --------------------
2966 -- Machine_Rounds --
2967 --------------------
2969 when Attribute_Machine_Rounds
=>
2972 Set_Etype
(N
, Standard_Boolean
);
2978 when Attribute_Machine_Size
=>
2981 Check_Not_Incomplete_Type
;
2982 Set_Etype
(N
, Universal_Integer
);
2988 when Attribute_Mantissa
=>
2991 Set_Etype
(N
, Universal_Integer
);
2997 when Attribute_Max
=>
3000 Resolve
(E1
, P_Base_Type
);
3001 Resolve
(E2
, P_Base_Type
);
3002 Set_Etype
(N
, P_Base_Type
);
3004 ----------------------------------
3005 -- Max_Size_In_Storage_Elements --
3006 ----------------------------------
3008 when Attribute_Max_Size_In_Storage_Elements
=>
3011 Check_Not_Incomplete_Type
;
3012 Set_Etype
(N
, Universal_Integer
);
3014 -----------------------
3015 -- Maximum_Alignment --
3016 -----------------------
3018 when Attribute_Maximum_Alignment
=>
3019 Standard_Attribute
(Ttypes
.Maximum_Alignment
);
3021 --------------------
3022 -- Mechanism_Code --
3023 --------------------
3025 when Attribute_Mechanism_Code
=>
3026 if not Is_Entity_Name
(P
)
3027 or else not Is_Subprogram
(Entity
(P
))
3029 Error_Attr
("prefix of % attribute must be subprogram", P
);
3032 Check_Either_E0_Or_E1
;
3034 if Present
(E1
) then
3035 Resolve
(E1
, Any_Integer
);
3036 Set_Etype
(E1
, Standard_Integer
);
3038 if not Is_Static_Expression
(E1
) then
3039 Flag_Non_Static_Expr
3040 ("expression for parameter number must be static!", E1
);
3043 elsif UI_To_Int
(Intval
(E1
)) > Number_Formals
(Entity
(P
))
3044 or else UI_To_Int
(Intval
(E1
)) < 0
3046 Error_Attr
("invalid parameter number for %attribute", E1
);
3050 Set_Etype
(N
, Universal_Integer
);
3056 when Attribute_Min
=>
3059 Resolve
(E1
, P_Base_Type
);
3060 Resolve
(E2
, P_Base_Type
);
3061 Set_Etype
(N
, P_Base_Type
);
3067 when Attribute_Mod
=>
3069 -- Note: this attribute is only allowed in Ada 2005 mode, but
3070 -- we do not need to test that here, since Mod is only recognized
3071 -- as an attribute name in Ada 2005 mode during the parse.
3074 Check_Modular_Integer_Type
;
3075 Resolve
(E1
, Any_Integer
);
3076 Set_Etype
(N
, P_Base_Type
);
3082 when Attribute_Model
=>
3083 Check_Floating_Point_Type_1
;
3084 Set_Etype
(N
, P_Base_Type
);
3085 Resolve
(E1
, P_Base_Type
);
3091 when Attribute_Model_Emin
=>
3092 Check_Floating_Point_Type_0
;
3093 Set_Etype
(N
, Universal_Integer
);
3099 when Attribute_Model_Epsilon
=>
3100 Check_Floating_Point_Type_0
;
3101 Set_Etype
(N
, Universal_Real
);
3103 --------------------
3104 -- Model_Mantissa --
3105 --------------------
3107 when Attribute_Model_Mantissa
=>
3108 Check_Floating_Point_Type_0
;
3109 Set_Etype
(N
, Universal_Integer
);
3115 when Attribute_Model_Small
=>
3116 Check_Floating_Point_Type_0
;
3117 Set_Etype
(N
, Universal_Real
);
3123 when Attribute_Modulus
=>
3125 Check_Modular_Integer_Type
;
3126 Set_Etype
(N
, Universal_Integer
);
3128 --------------------
3129 -- Null_Parameter --
3130 --------------------
3132 when Attribute_Null_Parameter
=> Null_Parameter
: declare
3133 Parnt
: constant Node_Id
:= Parent
(N
);
3134 GParnt
: constant Node_Id
:= Parent
(Parnt
);
3136 procedure Bad_Null_Parameter
(Msg
: String);
3137 -- Used if bad Null parameter attribute node is found. Issues
3138 -- given error message, and also sets the type to Any_Type to
3139 -- avoid blowups later on from dealing with a junk node.
3141 procedure Must_Be_Imported
(Proc_Ent
: Entity_Id
);
3142 -- Called to check that Proc_Ent is imported subprogram
3144 ------------------------
3145 -- Bad_Null_Parameter --
3146 ------------------------
3148 procedure Bad_Null_Parameter
(Msg
: String) is
3150 Error_Msg_N
(Msg
, N
);
3151 Set_Etype
(N
, Any_Type
);
3152 end Bad_Null_Parameter
;
3154 ----------------------
3155 -- Must_Be_Imported --
3156 ----------------------
3158 procedure Must_Be_Imported
(Proc_Ent
: Entity_Id
) is
3159 Pent
: Entity_Id
:= Proc_Ent
;
3162 while Present
(Alias
(Pent
)) loop
3163 Pent
:= Alias
(Pent
);
3166 -- Ignore check if procedure not frozen yet (we will get
3167 -- another chance when the default parameter is reanalyzed)
3169 if not Is_Frozen
(Pent
) then
3172 elsif not Is_Imported
(Pent
) then
3174 ("Null_Parameter can only be used with imported subprogram");
3179 end Must_Be_Imported
;
3181 -- Start of processing for Null_Parameter
3186 Set_Etype
(N
, P_Type
);
3188 -- Case of attribute used as default expression
3190 if Nkind
(Parnt
) = N_Parameter_Specification
then
3191 Must_Be_Imported
(Defining_Entity
(GParnt
));
3193 -- Case of attribute used as actual for subprogram (positional)
3195 elsif (Nkind
(Parnt
) = N_Procedure_Call_Statement
3197 Nkind
(Parnt
) = N_Function_Call
)
3198 and then Is_Entity_Name
(Name
(Parnt
))
3200 Must_Be_Imported
(Entity
(Name
(Parnt
)));
3202 -- Case of attribute used as actual for subprogram (named)
3204 elsif Nkind
(Parnt
) = N_Parameter_Association
3205 and then (Nkind
(GParnt
) = N_Procedure_Call_Statement
3207 Nkind
(GParnt
) = N_Function_Call
)
3208 and then Is_Entity_Name
(Name
(GParnt
))
3210 Must_Be_Imported
(Entity
(Name
(GParnt
)));
3212 -- Not an allowed case
3216 ("Null_Parameter must be actual or default parameter");
3225 when Attribute_Object_Size
=>
3228 Check_Not_Incomplete_Type
;
3229 Set_Etype
(N
, Universal_Integer
);
3235 when Attribute_Output
=>
3237 Check_Stream_Attribute
(TSS_Stream_Output
);
3238 Set_Etype
(N
, Standard_Void_Type
);
3239 Resolve
(N
, Standard_Void_Type
);
3245 when Attribute_Partition_ID
=>
3248 if P_Type
/= Any_Type
then
3249 if not Is_Library_Level_Entity
(Entity
(P
)) then
3251 ("prefix of % attribute must be library-level entity", P
);
3253 -- The defining entity of prefix should not be declared inside
3254 -- a Pure unit. RM E.1(8).
3255 -- The Is_Pure flag has been set during declaration.
3257 elsif Is_Entity_Name
(P
)
3258 and then Is_Pure
(Entity
(P
))
3261 ("prefix of % attribute must not be declared pure", P
);
3265 Set_Etype
(N
, Universal_Integer
);
3267 -------------------------
3268 -- Passed_By_Reference --
3269 -------------------------
3271 when Attribute_Passed_By_Reference
=>
3274 Set_Etype
(N
, Standard_Boolean
);
3280 when Attribute_Pool_Address
=>
3282 Set_Etype
(N
, RTE
(RE_Address
));
3288 when Attribute_Pos
=>
3289 Check_Discrete_Type
;
3291 Resolve
(E1
, P_Base_Type
);
3292 Set_Etype
(N
, Universal_Integer
);
3298 when Attribute_Position
=>
3300 Set_Etype
(N
, Universal_Integer
);
3306 when Attribute_Pred
=>
3309 Resolve
(E1
, P_Base_Type
);
3310 Set_Etype
(N
, P_Base_Type
);
3312 -- Nothing to do for real type case
3314 if Is_Real_Type
(P_Type
) then
3317 -- If not modular type, test for overflow check required
3320 if not Is_Modular_Integer_Type
(P_Type
)
3321 and then not Range_Checks_Suppressed
(P_Base_Type
)
3323 Enable_Range_Check
(E1
);
3331 when Attribute_Range
=>
3332 Check_Array_Or_Scalar_Type
;
3334 if Ada_Version
= Ada_83
3335 and then Is_Scalar_Type
(P_Type
)
3336 and then Comes_From_Source
(N
)
3339 ("(Ada 83) % attribute not allowed for scalar type", P
);
3346 when Attribute_Range_Length
=>
3347 Check_Discrete_Type
;
3348 Set_Etype
(N
, Universal_Integer
);
3354 when Attribute_Read
=>
3356 Check_Stream_Attribute
(TSS_Stream_Read
);
3357 Set_Etype
(N
, Standard_Void_Type
);
3358 Resolve
(N
, Standard_Void_Type
);
3359 Note_Possible_Modification
(E2
);
3365 when Attribute_Remainder
=>
3366 Check_Floating_Point_Type_2
;
3367 Set_Etype
(N
, P_Base_Type
);
3368 Resolve
(E1
, P_Base_Type
);
3369 Resolve
(E2
, P_Base_Type
);
3375 when Attribute_Round
=>
3377 Check_Decimal_Fixed_Point_Type
;
3378 Set_Etype
(N
, P_Base_Type
);
3380 -- Because the context is universal_real (3.5.10(12)) it is a legal
3381 -- context for a universal fixed expression. This is the only
3382 -- attribute whose functional description involves U_R.
3384 if Etype
(E1
) = Universal_Fixed
then
3386 Conv
: constant Node_Id
:= Make_Type_Conversion
(Loc
,
3387 Subtype_Mark
=> New_Occurrence_Of
(Universal_Real
, Loc
),
3388 Expression
=> Relocate_Node
(E1
));
3396 Resolve
(E1
, Any_Real
);
3402 when Attribute_Rounding
=>
3403 Check_Floating_Point_Type_1
;
3404 Set_Etype
(N
, P_Base_Type
);
3405 Resolve
(E1
, P_Base_Type
);
3411 when Attribute_Safe_Emax
=>
3412 Check_Floating_Point_Type_0
;
3413 Set_Etype
(N
, Universal_Integer
);
3419 when Attribute_Safe_First
=>
3420 Check_Floating_Point_Type_0
;
3421 Set_Etype
(N
, Universal_Real
);
3427 when Attribute_Safe_Large
=>
3430 Set_Etype
(N
, Universal_Real
);
3436 when Attribute_Safe_Last
=>
3437 Check_Floating_Point_Type_0
;
3438 Set_Etype
(N
, Universal_Real
);
3444 when Attribute_Safe_Small
=>
3447 Set_Etype
(N
, Universal_Real
);
3453 when Attribute_Scale
=>
3455 Check_Decimal_Fixed_Point_Type
;
3456 Set_Etype
(N
, Universal_Integer
);
3462 when Attribute_Scaling
=>
3463 Check_Floating_Point_Type_2
;
3464 Set_Etype
(N
, P_Base_Type
);
3465 Resolve
(E1
, P_Base_Type
);
3471 when Attribute_Signed_Zeros
=>
3472 Check_Floating_Point_Type_0
;
3473 Set_Etype
(N
, Standard_Boolean
);
3479 when Attribute_Size | Attribute_VADS_Size
=>
3482 -- If prefix is parameterless function call, rewrite and resolve
3485 if Is_Entity_Name
(P
)
3486 and then Ekind
(Entity
(P
)) = E_Function
3490 -- Similar processing for a protected function call
3492 elsif Nkind
(P
) = N_Selected_Component
3493 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Function
3498 if Is_Object_Reference
(P
) then
3499 Check_Object_Reference
(P
);
3501 elsif Is_Entity_Name
(P
)
3502 and then (Is_Type
(Entity
(P
))
3503 or else Ekind
(Entity
(P
)) = E_Enumeration_Literal
)
3507 elsif Nkind
(P
) = N_Type_Conversion
3508 and then not Comes_From_Source
(P
)
3513 Error_Attr
("invalid prefix for % attribute", P
);
3516 Check_Not_Incomplete_Type
;
3517 Set_Etype
(N
, Universal_Integer
);
3523 when Attribute_Small
=>
3526 Set_Etype
(N
, Universal_Real
);
3532 when Attribute_Storage_Pool
=>
3533 if Is_Access_Type
(P_Type
) then
3536 -- Set appropriate entity
3538 if Present
(Associated_Storage_Pool
(Root_Type
(P_Type
))) then
3539 Set_Entity
(N
, Associated_Storage_Pool
(Root_Type
(P_Type
)));
3541 Set_Entity
(N
, RTE
(RE_Global_Pool_Object
));
3544 Set_Etype
(N
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
3546 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
3547 -- Storage_Pool since this attribute is not defined for such
3548 -- types (RM E.2.3(22)).
3550 Validate_Remote_Access_To_Class_Wide_Type
(N
);
3553 Error_Attr
("prefix of % attribute must be access type", P
);
3560 when Attribute_Storage_Size
=>
3562 if Is_Task_Type
(P_Type
) then
3564 Set_Etype
(N
, Universal_Integer
);
3566 elsif Is_Access_Type
(P_Type
) then
3567 if Is_Entity_Name
(P
)
3568 and then Is_Type
(Entity
(P
))
3572 Set_Etype
(N
, Universal_Integer
);
3574 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
3575 -- Storage_Size since this attribute is not defined for
3576 -- such types (RM E.2.3(22)).
3578 Validate_Remote_Access_To_Class_Wide_Type
(N
);
3580 -- The prefix is allowed to be an implicit dereference
3581 -- of an access value designating a task.
3586 Set_Etype
(N
, Universal_Integer
);
3591 ("prefix of % attribute must be access or task type", P
);
3598 when Attribute_Storage_Unit
=>
3599 Standard_Attribute
(Ttypes
.System_Storage_Unit
);
3605 when Attribute_Stream_Size
=>
3609 if Is_Entity_Name
(P
)
3610 and then Is_Elementary_Type
(Entity
(P
))
3612 Set_Etype
(N
, Universal_Integer
);
3614 Error_Attr
("invalid prefix for % attribute", P
);
3621 when Attribute_Succ
=>
3624 Resolve
(E1
, P_Base_Type
);
3625 Set_Etype
(N
, P_Base_Type
);
3627 -- Nothing to do for real type case
3629 if Is_Real_Type
(P_Type
) then
3632 -- If not modular type, test for overflow check required
3635 if not Is_Modular_Integer_Type
(P_Type
)
3636 and then not Range_Checks_Suppressed
(P_Base_Type
)
3638 Enable_Range_Check
(E1
);
3646 when Attribute_Tag
=>
3650 if not Is_Tagged_Type
(P_Type
) then
3651 Error_Attr
("prefix of % attribute must be tagged", P
);
3653 -- Next test does not apply to generated code
3654 -- why not, and what does the illegal reference mean???
3656 elsif Is_Object_Reference
(P
)
3657 and then not Is_Class_Wide_Type
(P_Type
)
3658 and then Comes_From_Source
(N
)
3661 ("% attribute can only be applied to objects of class-wide type",
3665 Set_Etype
(N
, RTE
(RE_Tag
));
3671 when Attribute_Target_Name
=> Target_Name
: declare
3672 TN
: constant String := Sdefault
.Target_Name
.all;
3676 Check_Standard_Prefix
;
3681 if TN
(TL
) = '/' or else TN
(TL
) = '\' then
3686 Make_String_Literal
(Loc
,
3687 Strval
=> TN
(TN
'First .. TL
)));
3688 Analyze_And_Resolve
(N
, Standard_String
);
3695 when Attribute_Terminated
=>
3697 Set_Etype
(N
, Standard_Boolean
);
3704 when Attribute_To_Address
=>
3708 if Nkind
(P
) /= N_Identifier
3709 or else Chars
(P
) /= Name_System
3711 Error_Attr
("prefix of %attribute must be System", P
);
3714 Generate_Reference
(RTE
(RE_Address
), P
);
3715 Analyze_And_Resolve
(E1
, Any_Integer
);
3716 Set_Etype
(N
, RTE
(RE_Address
));
3722 when Attribute_Truncation
=>
3723 Check_Floating_Point_Type_1
;
3724 Resolve
(E1
, P_Base_Type
);
3725 Set_Etype
(N
, P_Base_Type
);
3731 when Attribute_Type_Class
=>
3734 Check_Not_Incomplete_Type
;
3735 Set_Etype
(N
, RTE
(RE_Type_Class
));
3741 when Attribute_UET_Address
=>
3743 Check_Unit_Name
(P
);
3744 Set_Etype
(N
, RTE
(RE_Address
));
3746 -----------------------
3747 -- Unbiased_Rounding --
3748 -----------------------
3750 when Attribute_Unbiased_Rounding
=>
3751 Check_Floating_Point_Type_1
;
3752 Set_Etype
(N
, P_Base_Type
);
3753 Resolve
(E1
, P_Base_Type
);
3755 ----------------------
3756 -- Unchecked_Access --
3757 ----------------------
3759 when Attribute_Unchecked_Access
=>
3760 if Comes_From_Source
(N
) then
3761 Check_Restriction
(No_Unchecked_Access
, N
);
3764 Analyze_Access_Attribute
;
3766 -------------------------
3767 -- Unconstrained_Array --
3768 -------------------------
3770 when Attribute_Unconstrained_Array
=>
3773 Check_Not_Incomplete_Type
;
3774 Set_Etype
(N
, Standard_Boolean
);
3776 ------------------------------
3777 -- Universal_Literal_String --
3778 ------------------------------
3780 -- This is a GNAT specific attribute whose prefix must be a named
3781 -- number where the expression is either a single numeric literal,
3782 -- or a numeric literal immediately preceded by a minus sign. The
3783 -- result is equivalent to a string literal containing the text of
3784 -- the literal as it appeared in the source program with a possible
3785 -- leading minus sign.
3787 when Attribute_Universal_Literal_String
=> Universal_Literal_String
:
3791 if not Is_Entity_Name
(P
)
3792 or else Ekind
(Entity
(P
)) not in Named_Kind
3794 Error_Attr
("prefix for % attribute must be named number", P
);
3801 Src
: Source_Buffer_Ptr
;
3804 Expr
:= Original_Node
(Expression
(Parent
(Entity
(P
))));
3806 if Nkind
(Expr
) = N_Op_Minus
then
3808 Expr
:= Original_Node
(Right_Opnd
(Expr
));
3813 if Nkind
(Expr
) /= N_Integer_Literal
3814 and then Nkind
(Expr
) /= N_Real_Literal
3817 ("named number for % attribute must be simple literal", N
);
3820 -- Build string literal corresponding to source literal text
3825 Store_String_Char
(Get_Char_Code
('-'));
3829 Src
:= Source_Text
(Get_Source_File_Index
(S
));
3831 while Src
(S
) /= ';' and then Src
(S
) /= ' ' loop
3832 Store_String_Char
(Get_Char_Code
(Src
(S
)));
3836 -- Now we rewrite the attribute with the string literal
3839 Make_String_Literal
(Loc
, End_String
));
3843 end Universal_Literal_String
;
3845 -------------------------
3846 -- Unrestricted_Access --
3847 -------------------------
3849 -- This is a GNAT specific attribute which is like Access except that
3850 -- all scope checks and checks for aliased views are omitted.
3852 when Attribute_Unrestricted_Access
=>
3853 if Comes_From_Source
(N
) then
3854 Check_Restriction
(No_Unchecked_Access
, N
);
3857 if Is_Entity_Name
(P
) then
3858 Set_Address_Taken
(Entity
(P
));
3861 Analyze_Access_Attribute
;
3867 when Attribute_Val
=> Val
: declare
3870 Check_Discrete_Type
;
3871 Resolve
(E1
, Any_Integer
);
3872 Set_Etype
(N
, P_Base_Type
);
3874 -- Note, we need a range check in general, but we wait for the
3875 -- Resolve call to do this, since we want to let Eval_Attribute
3876 -- have a chance to find an static illegality first!
3883 when Attribute_Valid
=>
3886 -- Ignore check for object if we have a 'Valid reference generated
3887 -- by the expanded code, since in some cases valid checks can occur
3888 -- on items that are names, but are not objects (e.g. attributes).
3890 if Comes_From_Source
(N
) then
3891 Check_Object_Reference
(P
);
3894 if not Is_Scalar_Type
(P_Type
) then
3895 Error_Attr
("object for % attribute must be of scalar type", P
);
3898 Set_Etype
(N
, Standard_Boolean
);
3904 when Attribute_Value
=> Value
:
3909 if Is_Enumeration_Type
(P_Type
) then
3910 Check_Restriction
(No_Enumeration_Maps
, N
);
3913 -- Set Etype before resolving expression because expansion of
3914 -- expression may require enclosing type. Note that the type
3915 -- returned by 'Value is the base type of the prefix type.
3917 Set_Etype
(N
, P_Base_Type
);
3918 Validate_Non_Static_Attribute_Function_Call
;
3925 when Attribute_Value_Size
=>
3928 Check_Not_Incomplete_Type
;
3929 Set_Etype
(N
, Universal_Integer
);
3935 when Attribute_Version
=>
3938 Set_Etype
(N
, RTE
(RE_Version_String
));
3944 when Attribute_Wchar_T_Size
=>
3945 Standard_Attribute
(Interfaces_Wchar_T_Size
);
3951 when Attribute_Wide_Image
=> Wide_Image
:
3954 Set_Etype
(N
, Standard_Wide_String
);
3956 Resolve
(E1
, P_Base_Type
);
3957 Validate_Non_Static_Attribute_Function_Call
;
3960 ---------------------
3961 -- Wide_Wide_Image --
3962 ---------------------
3964 when Attribute_Wide_Wide_Image
=> Wide_Wide_Image
:
3967 Set_Etype
(N
, Standard_Wide_Wide_String
);
3969 Resolve
(E1
, P_Base_Type
);
3970 Validate_Non_Static_Attribute_Function_Call
;
3971 end Wide_Wide_Image
;
3977 when Attribute_Wide_Value
=> Wide_Value
:
3982 -- Set Etype before resolving expression because expansion
3983 -- of expression may require enclosing type.
3985 Set_Etype
(N
, P_Type
);
3986 Validate_Non_Static_Attribute_Function_Call
;
3989 ---------------------
3990 -- Wide_Wide_Value --
3991 ---------------------
3993 when Attribute_Wide_Wide_Value
=> Wide_Wide_Value
:
3998 -- Set Etype before resolving expression because expansion
3999 -- of expression may require enclosing type.
4001 Set_Etype
(N
, P_Type
);
4002 Validate_Non_Static_Attribute_Function_Call
;
4003 end Wide_Wide_Value
;
4005 ---------------------
4006 -- Wide_Wide_Width --
4007 ---------------------
4009 when Attribute_Wide_Wide_Width
=>
4012 Set_Etype
(N
, Universal_Integer
);
4018 when Attribute_Wide_Width
=>
4021 Set_Etype
(N
, Universal_Integer
);
4027 when Attribute_Width
=>
4030 Set_Etype
(N
, Universal_Integer
);
4036 when Attribute_Word_Size
=>
4037 Standard_Attribute
(System_Word_Size
);
4043 when Attribute_Write
=>
4045 Check_Stream_Attribute
(TSS_Stream_Write
);
4046 Set_Etype
(N
, Standard_Void_Type
);
4047 Resolve
(N
, Standard_Void_Type
);
4051 -- All errors raise Bad_Attribute, so that we get out before any further
4052 -- damage occurs when an error is detected (for example, if we check for
4053 -- one attribute expression, and the check succeeds, we want to be able
4054 -- to proceed securely assuming that an expression is in fact present.
4056 -- Note: we set the attribute analyzed in this case to prevent any
4057 -- attempt at reanalysis which could generate spurious error msgs.
4060 when Bad_Attribute
=>
4062 Set_Etype
(N
, Any_Type
);
4064 end Analyze_Attribute
;
4066 --------------------
4067 -- Eval_Attribute --
4068 --------------------
4070 procedure Eval_Attribute
(N
: Node_Id
) is
4071 Loc
: constant Source_Ptr
:= Sloc
(N
);
4072 Aname
: constant Name_Id
:= Attribute_Name
(N
);
4073 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Aname
);
4074 P
: constant Node_Id
:= Prefix
(N
);
4076 C_Type
: constant Entity_Id
:= Etype
(N
);
4077 -- The type imposed by the context
4080 -- First expression, or Empty if none
4083 -- Second expression, or Empty if none
4085 P_Entity
: Entity_Id
;
4086 -- Entity denoted by prefix
4089 -- The type of the prefix
4091 P_Base_Type
: Entity_Id
;
4092 -- The base type of the prefix type
4094 P_Root_Type
: Entity_Id
;
4095 -- The root type of the prefix type
4098 -- True if the result is Static. This is set by the general processing
4099 -- to true if the prefix is static, and all expressions are static. It
4100 -- can be reset as processing continues for particular attributes
4102 Lo_Bound
, Hi_Bound
: Node_Id
;
4103 -- Expressions for low and high bounds of type or array index referenced
4104 -- by First, Last, or Length attribute for array, set by Set_Bounds.
4107 -- Constraint error node used if we have an attribute reference has
4108 -- an argument that raises a constraint error. In this case we replace
4109 -- the attribute with a raise constraint_error node. This is important
4110 -- processing, since otherwise gigi might see an attribute which it is
4111 -- unprepared to deal with.
4113 function Aft_Value
return Nat
;
4114 -- Computes Aft value for current attribute prefix (used by Aft itself
4115 -- and also by Width for computing the Width of a fixed point type).
4117 procedure Check_Expressions
;
4118 -- In case where the attribute is not foldable, the expressions, if
4119 -- any, of the attribute, are in a non-static context. This procedure
4120 -- performs the required additional checks.
4122 function Compile_Time_Known_Bounds
(Typ
: Entity_Id
) return Boolean;
4123 -- Determines if the given type has compile time known bounds. Note
4124 -- that we enter the case statement even in cases where the prefix
4125 -- type does NOT have known bounds, so it is important to guard any
4126 -- attempt to evaluate both bounds with a call to this function.
4128 procedure Compile_Time_Known_Attribute
(N
: Node_Id
; Val
: Uint
);
4129 -- This procedure is called when the attribute N has a non-static
4130 -- but compile time known value given by Val. It includes the
4131 -- necessary checks for out of range values.
4133 procedure Float_Attribute_Universal_Integer
4142 -- This procedure evaluates a float attribute with no arguments that
4143 -- returns a universal integer result. The parameters give the values
4144 -- for the possible floating-point root types. See ttypef for details.
4145 -- The prefix type is a float type (and is thus not a generic type).
4147 procedure Float_Attribute_Universal_Real
4148 (IEEES_Val
: String;
4155 AAMPL_Val
: String);
4156 -- This procedure evaluates a float attribute with no arguments that
4157 -- returns a universal real result. The parameters give the values
4158 -- required for the possible floating-point root types in string
4159 -- format as real literals with a possible leading minus sign.
4160 -- The prefix type is a float type (and is thus not a generic type).
4162 function Fore_Value
return Nat
;
4163 -- Computes the Fore value for the current attribute prefix, which is
4164 -- known to be a static fixed-point type. Used by Fore and Width.
4166 function Mantissa
return Uint
;
4167 -- Returns the Mantissa value for the prefix type
4169 procedure Set_Bounds
;
4170 -- Used for First, Last and Length attributes applied to an array or
4171 -- array subtype. Sets the variables Lo_Bound and Hi_Bound to the low
4172 -- and high bound expressions for the index referenced by the attribute
4173 -- designator (i.e. the first index if no expression is present, and
4174 -- the N'th index if the value N is present as an expression). Also
4175 -- used for First and Last of scalar types. Static is reset to False
4176 -- if the type or index type is not statically constrained.
4178 function Statically_Denotes_Entity
(N
: Node_Id
) return Boolean;
4179 -- Verify that the prefix of a potentially static array attribute
4180 -- satisfies the conditions of 4.9 (14).
4186 function Aft_Value
return Nat
is
4192 Delta_Val
:= Delta_Value
(P_Type
);
4194 while Delta_Val
< Ureal_Tenth
loop
4195 Delta_Val
:= Delta_Val
* Ureal_10
;
4196 Result
:= Result
+ 1;
4202 -----------------------
4203 -- Check_Expressions --
4204 -----------------------
4206 procedure Check_Expressions
is
4210 while Present
(E
) loop
4211 Check_Non_Static_Context
(E
);
4214 end Check_Expressions
;
4216 ----------------------------------
4217 -- Compile_Time_Known_Attribute --
4218 ----------------------------------
4220 procedure Compile_Time_Known_Attribute
(N
: Node_Id
; Val
: Uint
) is
4221 T
: constant Entity_Id
:= Etype
(N
);
4224 Fold_Uint
(N
, Val
, False);
4226 -- Check that result is in bounds of the type if it is static
4228 if Is_In_Range
(N
, T
) then
4231 elsif Is_Out_Of_Range
(N
, T
) then
4232 Apply_Compile_Time_Constraint_Error
4233 (N
, "value not in range of}?", CE_Range_Check_Failed
);
4235 elsif not Range_Checks_Suppressed
(T
) then
4236 Enable_Range_Check
(N
);
4239 Set_Do_Range_Check
(N
, False);
4241 end Compile_Time_Known_Attribute
;
4243 -------------------------------
4244 -- Compile_Time_Known_Bounds --
4245 -------------------------------
4247 function Compile_Time_Known_Bounds
(Typ
: Entity_Id
) return Boolean is
4250 Compile_Time_Known_Value
(Type_Low_Bound
(Typ
))
4252 Compile_Time_Known_Value
(Type_High_Bound
(Typ
));
4253 end Compile_Time_Known_Bounds
;
4255 ---------------------------------------
4256 -- Float_Attribute_Universal_Integer --
4257 ---------------------------------------
4259 procedure Float_Attribute_Universal_Integer
4270 Digs
: constant Nat
:= UI_To_Int
(Digits_Value
(P_Base_Type
));
4273 if Vax_Float
(P_Base_Type
) then
4274 if Digs
= VAXFF_Digits
then
4276 elsif Digs
= VAXDF_Digits
then
4278 else pragma Assert
(Digs
= VAXGF_Digits
);
4282 elsif Is_AAMP_Float
(P_Base_Type
) then
4283 if Digs
= AAMPS_Digits
then
4285 else pragma Assert
(Digs
= AAMPL_Digits
);
4290 if Digs
= IEEES_Digits
then
4292 elsif Digs
= IEEEL_Digits
then
4294 else pragma Assert
(Digs
= IEEEX_Digits
);
4299 Fold_Uint
(N
, UI_From_Int
(Val
), True);
4300 end Float_Attribute_Universal_Integer
;
4302 ------------------------------------
4303 -- Float_Attribute_Universal_Real --
4304 ------------------------------------
4306 procedure Float_Attribute_Universal_Real
4307 (IEEES_Val
: String;
4317 Digs
: constant Nat
:= UI_To_Int
(Digits_Value
(P_Base_Type
));
4320 if Vax_Float
(P_Base_Type
) then
4321 if Digs
= VAXFF_Digits
then
4322 Val
:= Real_Convert
(VAXFF_Val
);
4323 elsif Digs
= VAXDF_Digits
then
4324 Val
:= Real_Convert
(VAXDF_Val
);
4325 else pragma Assert
(Digs
= VAXGF_Digits
);
4326 Val
:= Real_Convert
(VAXGF_Val
);
4329 elsif Is_AAMP_Float
(P_Base_Type
) then
4330 if Digs
= AAMPS_Digits
then
4331 Val
:= Real_Convert
(AAMPS_Val
);
4332 else pragma Assert
(Digs
= AAMPL_Digits
);
4333 Val
:= Real_Convert
(AAMPL_Val
);
4337 if Digs
= IEEES_Digits
then
4338 Val
:= Real_Convert
(IEEES_Val
);
4339 elsif Digs
= IEEEL_Digits
then
4340 Val
:= Real_Convert
(IEEEL_Val
);
4341 else pragma Assert
(Digs
= IEEEX_Digits
);
4342 Val
:= Real_Convert
(IEEEX_Val
);
4346 Set_Sloc
(Val
, Loc
);
4348 Set_Is_Static_Expression
(N
, Static
);
4349 Analyze_And_Resolve
(N
, C_Type
);
4350 end Float_Attribute_Universal_Real
;
4356 -- Note that the Fore calculation is based on the actual values
4357 -- of the bounds, and does not take into account possible rounding.
4359 function Fore_Value
return Nat
is
4360 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(P_Type
));
4361 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(P_Type
));
4362 Small
: constant Ureal
:= Small_Value
(P_Type
);
4363 Lo_Real
: constant Ureal
:= Lo
* Small
;
4364 Hi_Real
: constant Ureal
:= Hi
* Small
;
4369 -- Bounds are given in terms of small units, so first compute
4370 -- proper values as reals.
4372 T
:= UR_Max
(abs Lo_Real
, abs Hi_Real
);
4375 -- Loop to compute proper value if more than one digit required
4377 while T
>= Ureal_10
loop
4389 -- Table of mantissa values accessed by function Computed using
4392 -- T'Mantissa = integer next above (D * log(10)/log(2)) + 1)
4394 -- where D is T'Digits (RM83 3.5.7)
4396 Mantissa_Value
: constant array (Nat
range 1 .. 40) of Nat
:= (
4438 function Mantissa
return Uint
is
4441 UI_From_Int
(Mantissa_Value
(UI_To_Int
(Digits_Value
(P_Type
))));
4448 procedure Set_Bounds
is
4454 -- For a string literal subtype, we have to construct the bounds.
4455 -- Valid Ada code never applies attributes to string literals, but
4456 -- it is convenient to allow the expander to generate attribute
4457 -- references of this type (e.g. First and Last applied to a string
4460 -- Note that the whole point of the E_String_Literal_Subtype is to
4461 -- avoid this construction of bounds, but the cases in which we
4462 -- have to materialize them are rare enough that we don't worry!
4464 -- The low bound is simply the low bound of the base type. The
4465 -- high bound is computed from the length of the string and this
4468 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
4469 Ityp
:= Etype
(First_Index
(Base_Type
(P_Type
)));
4470 Lo_Bound
:= Type_Low_Bound
(Ityp
);
4473 Make_Integer_Literal
(Sloc
(P
),
4475 Expr_Value
(Lo_Bound
) + String_Literal_Length
(P_Type
) - 1);
4477 Set_Parent
(Hi_Bound
, P
);
4478 Analyze_And_Resolve
(Hi_Bound
, Etype
(Lo_Bound
));
4481 -- For non-array case, just get bounds of scalar type
4483 elsif Is_Scalar_Type
(P_Type
) then
4486 -- For a fixed-point type, we must freeze to get the attributes
4487 -- of the fixed-point type set now so we can reference them.
4489 if Is_Fixed_Point_Type
(P_Type
)
4490 and then not Is_Frozen
(Base_Type
(P_Type
))
4491 and then Compile_Time_Known_Value
(Type_Low_Bound
(P_Type
))
4492 and then Compile_Time_Known_Value
(Type_High_Bound
(P_Type
))
4494 Freeze_Fixed_Point_Type
(Base_Type
(P_Type
));
4497 -- For array case, get type of proper index
4503 Ndim
:= UI_To_Int
(Expr_Value
(E1
));
4506 Indx
:= First_Index
(P_Type
);
4507 for J
in 1 .. Ndim
- 1 loop
4511 -- If no index type, get out (some other error occurred, and
4512 -- we don't have enough information to complete the job!)
4520 Ityp
:= Etype
(Indx
);
4523 -- A discrete range in an index constraint is allowed to be a
4524 -- subtype indication. This is syntactically a pain, but should
4525 -- not propagate to the entity for the corresponding index subtype.
4526 -- After checking that the subtype indication is legal, the range
4527 -- of the subtype indication should be transfered to the entity.
4528 -- The attributes for the bounds should remain the simple retrievals
4529 -- that they are now.
4531 Lo_Bound
:= Type_Low_Bound
(Ityp
);
4532 Hi_Bound
:= Type_High_Bound
(Ityp
);
4534 if not Is_Static_Subtype
(Ityp
) then
4539 -------------------------------
4540 -- Statically_Denotes_Entity --
4541 -------------------------------
4543 function Statically_Denotes_Entity
(N
: Node_Id
) return Boolean is
4547 if not Is_Entity_Name
(N
) then
4554 Nkind
(Parent
(E
)) /= N_Object_Renaming_Declaration
4555 or else Statically_Denotes_Entity
(Renamed_Object
(E
));
4556 end Statically_Denotes_Entity
;
4558 -- Start of processing for Eval_Attribute
4561 -- Acquire first two expressions (at the moment, no attributes
4562 -- take more than two expressions in any case).
4564 if Present
(Expressions
(N
)) then
4565 E1
:= First
(Expressions
(N
));
4572 -- Special processing for cases where the prefix is an object. For
4573 -- this purpose, a string literal counts as an object (attributes
4574 -- of string literals can only appear in generated code).
4576 if Is_Object_Reference
(P
) or else Nkind
(P
) = N_String_Literal
then
4578 -- For Component_Size, the prefix is an array object, and we apply
4579 -- the attribute to the type of the object. This is allowed for
4580 -- both unconstrained and constrained arrays, since the bounds
4581 -- have no influence on the value of this attribute.
4583 if Id
= Attribute_Component_Size
then
4584 P_Entity
:= Etype
(P
);
4586 -- For First and Last, the prefix is an array object, and we apply
4587 -- the attribute to the type of the array, but we need a constrained
4588 -- type for this, so we use the actual subtype if available.
4590 elsif Id
= Attribute_First
4594 Id
= Attribute_Length
4597 AS
: constant Entity_Id
:= Get_Actual_Subtype_If_Available
(P
);
4600 if Present
(AS
) and then Is_Constrained
(AS
) then
4603 -- If we have an unconstrained type, cannot fold
4611 -- For Size, give size of object if available, otherwise we
4612 -- cannot fold Size.
4614 elsif Id
= Attribute_Size
then
4615 if Is_Entity_Name
(P
)
4616 and then Known_Esize
(Entity
(P
))
4618 Compile_Time_Known_Attribute
(N
, Esize
(Entity
(P
)));
4626 -- For Alignment, give size of object if available, otherwise we
4627 -- cannot fold Alignment.
4629 elsif Id
= Attribute_Alignment
then
4630 if Is_Entity_Name
(P
)
4631 and then Known_Alignment
(Entity
(P
))
4633 Fold_Uint
(N
, Alignment
(Entity
(P
)), False);
4641 -- No other attributes for objects are folded
4648 -- Cases where P is not an object. Cannot do anything if P is
4649 -- not the name of an entity.
4651 elsif not Is_Entity_Name
(P
) then
4655 -- Otherwise get prefix entity
4658 P_Entity
:= Entity
(P
);
4661 -- At this stage P_Entity is the entity to which the attribute
4662 -- is to be applied. This is usually simply the entity of the
4663 -- prefix, except in some cases of attributes for objects, where
4664 -- as described above, we apply the attribute to the object type.
4666 -- First foldable possibility is a scalar or array type (RM 4.9(7))
4667 -- that is not generic (generic types are eliminated by RM 4.9(25)).
4668 -- Note we allow non-static non-generic types at this stage as further
4671 if Is_Type
(P_Entity
)
4672 and then (Is_Scalar_Type
(P_Entity
) or Is_Array_Type
(P_Entity
))
4673 and then (not Is_Generic_Type
(P_Entity
))
4677 -- Second foldable possibility is an array object (RM 4.9(8))
4679 elsif (Ekind
(P_Entity
) = E_Variable
4681 Ekind
(P_Entity
) = E_Constant
)
4682 and then Is_Array_Type
(Etype
(P_Entity
))
4683 and then (not Is_Generic_Type
(Etype
(P_Entity
)))
4685 P_Type
:= Etype
(P_Entity
);
4687 -- If the entity is an array constant with an unconstrained
4688 -- nominal subtype then get the type from the initial value.
4689 -- If the value has been expanded into assignments, the expression
4690 -- is not present and the attribute reference remains dynamic.
4691 -- We could do better here and retrieve the type ???
4693 if Ekind
(P_Entity
) = E_Constant
4694 and then not Is_Constrained
(P_Type
)
4696 if No
(Constant_Value
(P_Entity
)) then
4699 P_Type
:= Etype
(Constant_Value
(P_Entity
));
4703 -- Definite must be folded if the prefix is not a generic type,
4704 -- that is to say if we are within an instantiation. Same processing
4705 -- applies to the GNAT attributes Has_Discriminants, Type_Class,
4706 -- and Unconstrained_Array.
4708 elsif (Id
= Attribute_Definite
4710 Id
= Attribute_Has_Access_Values
4712 Id
= Attribute_Has_Discriminants
4714 Id
= Attribute_Type_Class
4716 Id
= Attribute_Unconstrained_Array
)
4717 and then not Is_Generic_Type
(P_Entity
)
4721 -- We can fold 'Size applied to a type if the size is known
4722 -- (as happens for a size from an attribute definition clause).
4723 -- At this stage, this can happen only for types (e.g. record
4724 -- types) for which the size is always non-static. We exclude
4725 -- generic types from consideration (since they have bogus
4726 -- sizes set within templates).
4728 elsif Id
= Attribute_Size
4729 and then Is_Type
(P_Entity
)
4730 and then (not Is_Generic_Type
(P_Entity
))
4731 and then Known_Static_RM_Size
(P_Entity
)
4733 Compile_Time_Known_Attribute
(N
, RM_Size
(P_Entity
));
4736 -- We can fold 'Alignment applied to a type if the alignment is known
4737 -- (as happens for an alignment from an attribute definition clause).
4738 -- At this stage, this can happen only for types (e.g. record
4739 -- types) for which the size is always non-static. We exclude
4740 -- generic types from consideration (since they have bogus
4741 -- sizes set within templates).
4743 elsif Id
= Attribute_Alignment
4744 and then Is_Type
(P_Entity
)
4745 and then (not Is_Generic_Type
(P_Entity
))
4746 and then Known_Alignment
(P_Entity
)
4748 Compile_Time_Known_Attribute
(N
, Alignment
(P_Entity
));
4751 -- If this is an access attribute that is known to fail accessibility
4752 -- check, rewrite accordingly.
4754 elsif Attribute_Name
(N
) = Name_Access
4755 and then Raises_Constraint_Error
(N
)
4758 Make_Raise_Program_Error
(Loc
,
4759 Reason
=> PE_Accessibility_Check_Failed
));
4760 Set_Etype
(N
, C_Type
);
4763 -- No other cases are foldable (they certainly aren't static, and at
4764 -- the moment we don't try to fold any cases other than these three).
4771 -- If either attribute or the prefix is Any_Type, then propagate
4772 -- Any_Type to the result and don't do anything else at all.
4774 if P_Type
= Any_Type
4775 or else (Present
(E1
) and then Etype
(E1
) = Any_Type
)
4776 or else (Present
(E2
) and then Etype
(E2
) = Any_Type
)
4778 Set_Etype
(N
, Any_Type
);
4782 -- Scalar subtype case. We have not yet enforced the static requirement
4783 -- of (RM 4.9(7)) and we don't intend to just yet, since there are cases
4784 -- of non-static attribute references (e.g. S'Digits for a non-static
4785 -- floating-point type, which we can compute at compile time).
4787 -- Note: this folding of non-static attributes is not simply a case of
4788 -- optimization. For many of the attributes affected, Gigi cannot handle
4789 -- the attribute and depends on the front end having folded them away.
4791 -- Note: although we don't require staticness at this stage, we do set
4792 -- the Static variable to record the staticness, for easy reference by
4793 -- those attributes where it matters (e.g. Succ and Pred), and also to
4794 -- be used to ensure that non-static folded things are not marked as
4795 -- being static (a check that is done right at the end).
4797 P_Root_Type
:= Root_Type
(P_Type
);
4798 P_Base_Type
:= Base_Type
(P_Type
);
4800 -- If the root type or base type is generic, then we cannot fold. This
4801 -- test is needed because subtypes of generic types are not always
4802 -- marked as being generic themselves (which seems odd???)
4804 if Is_Generic_Type
(P_Root_Type
)
4805 or else Is_Generic_Type
(P_Base_Type
)
4810 if Is_Scalar_Type
(P_Type
) then
4811 Static
:= Is_OK_Static_Subtype
(P_Type
);
4813 -- Array case. We enforce the constrained requirement of (RM 4.9(7-8))
4814 -- since we can't do anything with unconstrained arrays. In addition,
4815 -- only the First, Last and Length attributes are possibly static.
4817 -- Definite, Has_Access_Values, Has_Discriminants, Type_Class, and
4818 -- Unconstrained_Array are again exceptions, because they apply as
4819 -- well to unconstrained types.
4821 -- In addition Component_Size is an exception since it is possibly
4822 -- foldable, even though it is never static, and it does apply to
4823 -- unconstrained arrays. Furthermore, it is essential to fold this
4824 -- in the packed case, since otherwise the value will be incorrect.
4826 elsif Id
= Attribute_Definite
4828 Id
= Attribute_Has_Access_Values
4830 Id
= Attribute_Has_Discriminants
4832 Id
= Attribute_Type_Class
4834 Id
= Attribute_Unconstrained_Array
4836 Id
= Attribute_Component_Size
4841 if not Is_Constrained
(P_Type
)
4842 or else (Id
/= Attribute_First
and then
4843 Id
/= Attribute_Last
and then
4844 Id
/= Attribute_Length
)
4850 -- The rules in (RM 4.9(7,8)) require a static array, but as in the
4851 -- scalar case, we hold off on enforcing staticness, since there are
4852 -- cases which we can fold at compile time even though they are not
4853 -- static (e.g. 'Length applied to a static index, even though other
4854 -- non-static indexes make the array type non-static). This is only
4855 -- an optimization, but it falls out essentially free, so why not.
4856 -- Again we compute the variable Static for easy reference later
4857 -- (note that no array attributes are static in Ada 83).
4859 Static
:= Ada_Version
>= Ada_95
4860 and then Statically_Denotes_Entity
(P
);
4866 N
:= First_Index
(P_Type
);
4867 while Present
(N
) loop
4868 Static
:= Static
and then Is_Static_Subtype
(Etype
(N
));
4870 -- If however the index type is generic, attributes cannot
4873 if Is_Generic_Type
(Etype
(N
))
4874 and then Id
/= Attribute_Component_Size
4884 -- Check any expressions that are present. Note that these expressions,
4885 -- depending on the particular attribute type, are either part of the
4886 -- attribute designator, or they are arguments in a case where the
4887 -- attribute reference returns a function. In the latter case, the
4888 -- rule in (RM 4.9(22)) applies and in particular requires the type
4889 -- of the expressions to be scalar in order for the attribute to be
4890 -- considered to be static.
4897 while Present
(E
) loop
4899 -- If expression is not static, then the attribute reference
4900 -- result certainly cannot be static.
4902 if not Is_Static_Expression
(E
) then
4906 -- If the result is not known at compile time, or is not of
4907 -- a scalar type, then the result is definitely not static,
4908 -- so we can quit now.
4910 if not Compile_Time_Known_Value
(E
)
4911 or else not Is_Scalar_Type
(Etype
(E
))
4913 -- An odd special case, if this is a Pos attribute, this
4914 -- is where we need to apply a range check since it does
4915 -- not get done anywhere else.
4917 if Id
= Attribute_Pos
then
4918 if Is_Integer_Type
(Etype
(E
)) then
4919 Apply_Range_Check
(E
, Etype
(N
));
4926 -- If the expression raises a constraint error, then so does
4927 -- the attribute reference. We keep going in this case because
4928 -- we are still interested in whether the attribute reference
4929 -- is static even if it is not static.
4931 elsif Raises_Constraint_Error
(E
) then
4932 Set_Raises_Constraint_Error
(N
);
4938 if Raises_Constraint_Error
(Prefix
(N
)) then
4943 -- Deal with the case of a static attribute reference that raises
4944 -- constraint error. The Raises_Constraint_Error flag will already
4945 -- have been set, and the Static flag shows whether the attribute
4946 -- reference is static. In any case we certainly can't fold such an
4947 -- attribute reference.
4949 -- Note that the rewriting of the attribute node with the constraint
4950 -- error node is essential in this case, because otherwise Gigi might
4951 -- blow up on one of the attributes it never expects to see.
4953 -- The constraint_error node must have the type imposed by the context,
4954 -- to avoid spurious errors in the enclosing expression.
4956 if Raises_Constraint_Error
(N
) then
4958 Make_Raise_Constraint_Error
(Sloc
(N
),
4959 Reason
=> CE_Range_Check_Failed
);
4960 Set_Etype
(CE_Node
, Etype
(N
));
4961 Set_Raises_Constraint_Error
(CE_Node
);
4963 Rewrite
(N
, Relocate_Node
(CE_Node
));
4964 Set_Is_Static_Expression
(N
, Static
);
4968 -- At this point we have a potentially foldable attribute reference.
4969 -- If Static is set, then the attribute reference definitely obeys
4970 -- the requirements in (RM 4.9(7,8,22)), and it definitely can be
4971 -- folded. If Static is not set, then the attribute may or may not
4972 -- be foldable, and the individual attribute processing routines
4973 -- test Static as required in cases where it makes a difference.
4975 -- In the case where Static is not set, we do know that all the
4976 -- expressions present are at least known at compile time (we
4977 -- assumed above that if this was not the case, then there was
4978 -- no hope of static evaluation). However, we did not require
4979 -- that the bounds of the prefix type be compile time known,
4980 -- let alone static). That's because there are many attributes
4981 -- that can be computed at compile time on non-static subtypes,
4982 -- even though such references are not static expressions.
4990 when Attribute_Adjacent
=>
4993 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
4999 when Attribute_Aft
=>
5000 Fold_Uint
(N
, UI_From_Int
(Aft_Value
), True);
5006 when Attribute_Alignment
=> Alignment_Block
: declare
5007 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
5010 -- Fold if alignment is set and not otherwise
5012 if Known_Alignment
(P_TypeA
) then
5013 Fold_Uint
(N
, Alignment
(P_TypeA
), Is_Discrete_Type
(P_TypeA
));
5015 end Alignment_Block
;
5021 -- Can only be folded in No_Ast_Handler case
5023 when Attribute_AST_Entry
=>
5024 if not Is_AST_Entry
(P_Entity
) then
5026 New_Occurrence_Of
(RTE
(RE_No_AST_Handler
), Loc
));
5035 -- Bit can never be folded
5037 when Attribute_Bit
=>
5044 -- Body_version can never be static
5046 when Attribute_Body_Version
=>
5053 when Attribute_Ceiling
=>
5055 Eval_Fat
.Ceiling
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
5057 --------------------
5058 -- Component_Size --
5059 --------------------
5061 when Attribute_Component_Size
=>
5062 if Known_Static_Component_Size
(P_Type
) then
5063 Fold_Uint
(N
, Component_Size
(P_Type
), False);
5070 when Attribute_Compose
=>
5073 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)),
5080 -- Constrained is never folded for now, there may be cases that
5081 -- could be handled at compile time. to be looked at later.
5083 when Attribute_Constrained
=>
5090 when Attribute_Copy_Sign
=>
5093 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
5099 when Attribute_Delta
=>
5100 Fold_Ureal
(N
, Delta_Value
(P_Type
), True);
5106 when Attribute_Definite
=>
5107 Rewrite
(N
, New_Occurrence_Of
(
5108 Boolean_Literals
(not Is_Indefinite_Subtype
(P_Entity
)), Loc
));
5109 Analyze_And_Resolve
(N
, Standard_Boolean
);
5115 when Attribute_Denorm
=>
5117 (N
, UI_From_Int
(Boolean'Pos (Denorm_On_Target
)), True);
5123 when Attribute_Digits
=>
5124 Fold_Uint
(N
, Digits_Value
(P_Type
), True);
5130 when Attribute_Emax
=>
5132 -- Ada 83 attribute is defined as (RM83 3.5.8)
5134 -- T'Emax = 4 * T'Mantissa
5136 Fold_Uint
(N
, 4 * Mantissa
, True);
5142 when Attribute_Enum_Rep
=>
5144 -- For an enumeration type with a non-standard representation use
5145 -- the Enumeration_Rep field of the proper constant. Note that this
5146 -- will not work for types Character/Wide_[Wide-]Character, since no
5147 -- real entities are created for the enumeration literals, but that
5148 -- does not matter since these two types do not have non-standard
5149 -- representations anyway.
5151 if Is_Enumeration_Type
(P_Type
)
5152 and then Has_Non_Standard_Rep
(P_Type
)
5154 Fold_Uint
(N
, Enumeration_Rep
(Expr_Value_E
(E1
)), Static
);
5156 -- For enumeration types with standard representations and all
5157 -- other cases (i.e. all integer and modular types), Enum_Rep
5158 -- is equivalent to Pos.
5161 Fold_Uint
(N
, Expr_Value
(E1
), Static
);
5168 when Attribute_Epsilon
=>
5170 -- Ada 83 attribute is defined as (RM83 3.5.8)
5172 -- T'Epsilon = 2.0**(1 - T'Mantissa)
5174 Fold_Ureal
(N
, Ureal_2
** (1 - Mantissa
), True);
5180 when Attribute_Exponent
=>
5182 Eval_Fat
.Exponent
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
5188 when Attribute_First
=> First_Attr
:
5192 if Compile_Time_Known_Value
(Lo_Bound
) then
5193 if Is_Real_Type
(P_Type
) then
5194 Fold_Ureal
(N
, Expr_Value_R
(Lo_Bound
), Static
);
5196 Fold_Uint
(N
, Expr_Value
(Lo_Bound
), Static
);
5205 when Attribute_Fixed_Value
=>
5212 when Attribute_Floor
=>
5214 Eval_Fat
.Floor
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
5220 when Attribute_Fore
=>
5221 if Compile_Time_Known_Bounds
(P_Type
) then
5222 Fold_Uint
(N
, UI_From_Int
(Fore_Value
), Static
);
5229 when Attribute_Fraction
=>
5231 Eval_Fat
.Fraction
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
5233 -----------------------
5234 -- Has_Access_Values --
5235 -----------------------
5237 when Attribute_Has_Access_Values
=>
5238 Rewrite
(N
, New_Occurrence_Of
5239 (Boolean_Literals
(Has_Access_Values
(P_Root_Type
)), Loc
));
5240 Analyze_And_Resolve
(N
, Standard_Boolean
);
5242 -----------------------
5243 -- Has_Discriminants --
5244 -----------------------
5246 when Attribute_Has_Discriminants
=>
5247 Rewrite
(N
, New_Occurrence_Of
(
5248 Boolean_Literals
(Has_Discriminants
(P_Entity
)), Loc
));
5249 Analyze_And_Resolve
(N
, Standard_Boolean
);
5255 when Attribute_Identity
=>
5262 -- Image is a scalar attribute, but is never static, because it is
5263 -- not a static function (having a non-scalar argument (RM 4.9(22))
5265 when Attribute_Image
=>
5272 -- Img is a scalar attribute, but is never static, because it is
5273 -- not a static function (having a non-scalar argument (RM 4.9(22))
5275 when Attribute_Img
=>
5282 when Attribute_Integer_Value
=>
5289 when Attribute_Large
=>
5291 -- For fixed-point, we use the identity:
5293 -- T'Large = (2.0**T'Mantissa - 1.0) * T'Small
5295 if Is_Fixed_Point_Type
(P_Type
) then
5297 Make_Op_Multiply
(Loc
,
5299 Make_Op_Subtract
(Loc
,
5303 Make_Real_Literal
(Loc
, Ureal_2
),
5305 Make_Attribute_Reference
(Loc
,
5307 Attribute_Name
=> Name_Mantissa
)),
5308 Right_Opnd
=> Make_Real_Literal
(Loc
, Ureal_1
)),
5311 Make_Real_Literal
(Loc
, Small_Value
(Entity
(P
)))));
5313 Analyze_And_Resolve
(N
, C_Type
);
5315 -- Floating-point (Ada 83 compatibility)
5318 -- Ada 83 attribute is defined as (RM83 3.5.8)
5320 -- T'Large = 2.0**T'Emax * (1.0 - 2.0**(-T'Mantissa))
5324 -- T'Emax = 4 * T'Mantissa
5327 Ureal_2
** (4 * Mantissa
) * (Ureal_1
- Ureal_2
** (-Mantissa
)),
5335 when Attribute_Last
=> Last
:
5339 if Compile_Time_Known_Value
(Hi_Bound
) then
5340 if Is_Real_Type
(P_Type
) then
5341 Fold_Ureal
(N
, Expr_Value_R
(Hi_Bound
), Static
);
5343 Fold_Uint
(N
, Expr_Value
(Hi_Bound
), Static
);
5352 when Attribute_Leading_Part
=>
5354 Eval_Fat
.Leading_Part
5355 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)), Static
);
5361 when Attribute_Length
=> Length
: declare
5365 -- In the case of a generic index type, the bounds may
5366 -- appear static but the computation is not meaningful,
5367 -- and may generate a spurious warning.
5369 Ind
:= First_Index
(P_Type
);
5371 while Present
(Ind
) loop
5372 if Is_Generic_Type
(Etype
(Ind
)) then
5381 if Compile_Time_Known_Value
(Lo_Bound
)
5382 and then Compile_Time_Known_Value
(Hi_Bound
)
5385 UI_Max
(0, 1 + (Expr_Value
(Hi_Bound
) - Expr_Value
(Lo_Bound
))),
5394 when Attribute_Machine
=>
5397 (P_Root_Type
, Expr_Value_R
(E1
), Eval_Fat
.Round
, N
),
5404 when Attribute_Machine_Emax
=>
5405 Float_Attribute_Universal_Integer
(
5413 AAMPL_Machine_Emax
);
5419 when Attribute_Machine_Emin
=>
5420 Float_Attribute_Universal_Integer
(
5428 AAMPL_Machine_Emin
);
5430 ----------------------
5431 -- Machine_Mantissa --
5432 ----------------------
5434 when Attribute_Machine_Mantissa
=>
5435 Float_Attribute_Universal_Integer
(
5436 IEEES_Machine_Mantissa
,
5437 IEEEL_Machine_Mantissa
,
5438 IEEEX_Machine_Mantissa
,
5439 VAXFF_Machine_Mantissa
,
5440 VAXDF_Machine_Mantissa
,
5441 VAXGF_Machine_Mantissa
,
5442 AAMPS_Machine_Mantissa
,
5443 AAMPL_Machine_Mantissa
);
5445 -----------------------
5446 -- Machine_Overflows --
5447 -----------------------
5449 when Attribute_Machine_Overflows
=>
5451 -- Always true for fixed-point
5453 if Is_Fixed_Point_Type
(P_Type
) then
5454 Fold_Uint
(N
, True_Value
, True);
5456 -- Floating point case
5460 UI_From_Int
(Boolean'Pos (Machine_Overflows_On_Target
)),
5468 when Attribute_Machine_Radix
=>
5469 if Is_Fixed_Point_Type
(P_Type
) then
5470 if Is_Decimal_Fixed_Point_Type
(P_Type
)
5471 and then Machine_Radix_10
(P_Type
)
5473 Fold_Uint
(N
, Uint_10
, True);
5475 Fold_Uint
(N
, Uint_2
, True);
5478 -- All floating-point type always have radix 2
5481 Fold_Uint
(N
, Uint_2
, True);
5484 --------------------
5485 -- Machine_Rounds --
5486 --------------------
5488 when Attribute_Machine_Rounds
=>
5490 -- Always False for fixed-point
5492 if Is_Fixed_Point_Type
(P_Type
) then
5493 Fold_Uint
(N
, False_Value
, True);
5495 -- Else yield proper floating-point result
5499 (N
, UI_From_Int
(Boolean'Pos (Machine_Rounds_On_Target
)), True);
5506 -- Note: Machine_Size is identical to Object_Size
5508 when Attribute_Machine_Size
=> Machine_Size
: declare
5509 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
5512 if Known_Esize
(P_TypeA
) then
5513 Fold_Uint
(N
, Esize
(P_TypeA
), True);
5521 when Attribute_Mantissa
=>
5523 -- Fixed-point mantissa
5525 if Is_Fixed_Point_Type
(P_Type
) then
5527 -- Compile time foldable case
5529 if Compile_Time_Known_Value
(Type_Low_Bound
(P_Type
))
5531 Compile_Time_Known_Value
(Type_High_Bound
(P_Type
))
5533 -- The calculation of the obsolete Ada 83 attribute Mantissa
5534 -- is annoying, because of AI00143, quoted here:
5536 -- !question 84-01-10
5538 -- Consider the model numbers for F:
5540 -- type F is delta 1.0 range -7.0 .. 8.0;
5542 -- The wording requires that F'MANTISSA be the SMALLEST
5543 -- integer number for which each bound of the specified
5544 -- range is either a model number or lies at most small
5545 -- distant from a model number. This means F'MANTISSA
5546 -- is required to be 3 since the range -7.0 .. 7.0 fits
5547 -- in 3 signed bits, and 8 is "at most" 1.0 from a model
5548 -- number, namely, 7. Is this analysis correct? Note that
5549 -- this implies the upper bound of the range is not
5550 -- represented as a model number.
5552 -- !response 84-03-17
5554 -- The analysis is correct. The upper and lower bounds for
5555 -- a fixed point type can lie outside the range of model
5566 LBound
:= Expr_Value_R
(Type_Low_Bound
(P_Type
));
5567 UBound
:= Expr_Value_R
(Type_High_Bound
(P_Type
));
5568 Bound
:= UR_Max
(UR_Abs
(LBound
), UR_Abs
(UBound
));
5569 Max_Man
:= UR_Trunc
(Bound
/ Small_Value
(P_Type
));
5571 -- If the Bound is exactly a model number, i.e. a multiple
5572 -- of Small, then we back it off by one to get the integer
5573 -- value that must be representable.
5575 if Small_Value
(P_Type
) * Max_Man
= Bound
then
5576 Max_Man
:= Max_Man
- 1;
5579 -- Now find corresponding size = Mantissa value
5582 while 2 ** Siz
< Max_Man
loop
5586 Fold_Uint
(N
, Siz
, True);
5590 -- The case of dynamic bounds cannot be evaluated at compile
5591 -- time. Instead we use a runtime routine (see Exp_Attr).
5596 -- Floating-point Mantissa
5599 Fold_Uint
(N
, Mantissa
, True);
5606 when Attribute_Max
=> Max
:
5608 if Is_Real_Type
(P_Type
) then
5610 (N
, UR_Max
(Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
5612 Fold_Uint
(N
, UI_Max
(Expr_Value
(E1
), Expr_Value
(E2
)), Static
);
5616 ----------------------------------
5617 -- Max_Size_In_Storage_Elements --
5618 ----------------------------------
5620 -- Max_Size_In_Storage_Elements is simply the Size rounded up to a
5621 -- Storage_Unit boundary. We can fold any cases for which the size
5622 -- is known by the front end.
5624 when Attribute_Max_Size_In_Storage_Elements
=>
5625 if Known_Esize
(P_Type
) then
5627 (Esize
(P_Type
) + System_Storage_Unit
- 1) /
5628 System_Storage_Unit
,
5632 --------------------
5633 -- Mechanism_Code --
5634 --------------------
5636 when Attribute_Mechanism_Code
=>
5640 Mech
: Mechanism_Type
;
5644 Mech
:= Mechanism
(P_Entity
);
5647 Val
:= UI_To_Int
(Expr_Value
(E1
));
5649 Formal
:= First_Formal
(P_Entity
);
5650 for J
in 1 .. Val
- 1 loop
5651 Next_Formal
(Formal
);
5653 Mech
:= Mechanism
(Formal
);
5657 Fold_Uint
(N
, UI_From_Int
(Int
(-Mech
)), True);
5665 when Attribute_Min
=> Min
:
5667 if Is_Real_Type
(P_Type
) then
5669 (N
, UR_Min
(Expr_Value_R
(E1
), Expr_Value_R
(E2
)), Static
);
5672 (N
, UI_Min
(Expr_Value
(E1
), Expr_Value
(E2
)), Static
);
5680 when Attribute_Mod
=>
5682 (N
, UI_Mod
(Expr_Value
(E1
), Modulus
(P_Base_Type
)), Static
);
5688 when Attribute_Model
=>
5690 Eval_Fat
.Model
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
5696 when Attribute_Model_Emin
=>
5697 Float_Attribute_Universal_Integer
(
5711 when Attribute_Model_Epsilon
=>
5712 Float_Attribute_Universal_Real
(
5713 IEEES_Model_Epsilon
'Universal_Literal_String,
5714 IEEEL_Model_Epsilon
'Universal_Literal_String,
5715 IEEEX_Model_Epsilon
'Universal_Literal_String,
5716 VAXFF_Model_Epsilon
'Universal_Literal_String,
5717 VAXDF_Model_Epsilon
'Universal_Literal_String,
5718 VAXGF_Model_Epsilon
'Universal_Literal_String,
5719 AAMPS_Model_Epsilon
'Universal_Literal_String,
5720 AAMPL_Model_Epsilon
'Universal_Literal_String);
5722 --------------------
5723 -- Model_Mantissa --
5724 --------------------
5726 when Attribute_Model_Mantissa
=>
5727 Float_Attribute_Universal_Integer
(
5728 IEEES_Model_Mantissa
,
5729 IEEEL_Model_Mantissa
,
5730 IEEEX_Model_Mantissa
,
5731 VAXFF_Model_Mantissa
,
5732 VAXDF_Model_Mantissa
,
5733 VAXGF_Model_Mantissa
,
5734 AAMPS_Model_Mantissa
,
5735 AAMPL_Model_Mantissa
);
5741 when Attribute_Model_Small
=>
5742 Float_Attribute_Universal_Real
(
5743 IEEES_Model_Small
'Universal_Literal_String,
5744 IEEEL_Model_Small
'Universal_Literal_String,
5745 IEEEX_Model_Small
'Universal_Literal_String,
5746 VAXFF_Model_Small
'Universal_Literal_String,
5747 VAXDF_Model_Small
'Universal_Literal_String,
5748 VAXGF_Model_Small
'Universal_Literal_String,
5749 AAMPS_Model_Small
'Universal_Literal_String,
5750 AAMPL_Model_Small
'Universal_Literal_String);
5756 when Attribute_Modulus
=>
5757 Fold_Uint
(N
, Modulus
(P_Type
), True);
5759 --------------------
5760 -- Null_Parameter --
5761 --------------------
5763 -- Cannot fold, we know the value sort of, but the whole point is
5764 -- that there is no way to talk about this imaginary value except
5765 -- by using the attribute, so we leave it the way it is.
5767 when Attribute_Null_Parameter
=>
5774 -- The Object_Size attribute for a type returns the Esize of the
5775 -- type and can be folded if this value is known.
5777 when Attribute_Object_Size
=> Object_Size
: declare
5778 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
5781 if Known_Esize
(P_TypeA
) then
5782 Fold_Uint
(N
, Esize
(P_TypeA
), True);
5786 -------------------------
5787 -- Passed_By_Reference --
5788 -------------------------
5790 -- Scalar types are never passed by reference
5792 when Attribute_Passed_By_Reference
=>
5793 Fold_Uint
(N
, False_Value
, True);
5799 when Attribute_Pos
=>
5800 Fold_Uint
(N
, Expr_Value
(E1
), True);
5806 when Attribute_Pred
=> Pred
:
5808 -- Floating-point case
5810 if Is_Floating_Point_Type
(P_Type
) then
5812 Eval_Fat
.Pred
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
5816 elsif Is_Fixed_Point_Type
(P_Type
) then
5818 Expr_Value_R
(E1
) - Small_Value
(P_Type
), True);
5820 -- Modular integer case (wraps)
5822 elsif Is_Modular_Integer_Type
(P_Type
) then
5823 Fold_Uint
(N
, (Expr_Value
(E1
) - 1) mod Modulus
(P_Type
), Static
);
5825 -- Other scalar cases
5828 pragma Assert
(Is_Scalar_Type
(P_Type
));
5830 if Is_Enumeration_Type
(P_Type
)
5831 and then Expr_Value
(E1
) =
5832 Expr_Value
(Type_Low_Bound
(P_Base_Type
))
5834 Apply_Compile_Time_Constraint_Error
5835 (N
, "Pred of `&''First`",
5836 CE_Overflow_Check_Failed
,
5838 Warn
=> not Static
);
5844 Fold_Uint
(N
, Expr_Value
(E1
) - 1, Static
);
5852 -- No processing required, because by this stage, Range has been
5853 -- replaced by First .. Last, so this branch can never be taken.
5855 when Attribute_Range
=>
5856 raise Program_Error
;
5862 when Attribute_Range_Length
=>
5865 if Compile_Time_Known_Value
(Hi_Bound
)
5866 and then Compile_Time_Known_Value
(Lo_Bound
)
5870 (0, Expr_Value
(Hi_Bound
) - Expr_Value
(Lo_Bound
) + 1),
5878 when Attribute_Remainder
=> Remainder
: declare
5879 X
: constant Ureal
:= Expr_Value_R
(E1
);
5880 Y
: constant Ureal
:= Expr_Value_R
(E2
);
5883 if UR_Is_Zero
(Y
) then
5884 Apply_Compile_Time_Constraint_Error
5885 (N
, "division by zero in Remainder",
5886 CE_Overflow_Check_Failed
,
5887 Warn
=> not Static
);
5893 Fold_Ureal
(N
, Eval_Fat
.Remainder
(P_Root_Type
, X
, Y
), Static
);
5900 when Attribute_Round
=> Round
:
5906 -- First we get the (exact result) in units of small
5908 Sr
:= Expr_Value_R
(E1
) / Small_Value
(C_Type
);
5910 -- Now round that exactly to an integer
5912 Si
:= UR_To_Uint
(Sr
);
5914 -- Finally the result is obtained by converting back to real
5916 Fold_Ureal
(N
, Si
* Small_Value
(C_Type
), Static
);
5923 when Attribute_Rounding
=>
5925 Eval_Fat
.Rounding
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
5931 when Attribute_Safe_Emax
=>
5932 Float_Attribute_Universal_Integer
(
5946 when Attribute_Safe_First
=>
5947 Float_Attribute_Universal_Real
(
5948 IEEES_Safe_First
'Universal_Literal_String,
5949 IEEEL_Safe_First
'Universal_Literal_String,
5950 IEEEX_Safe_First
'Universal_Literal_String,
5951 VAXFF_Safe_First
'Universal_Literal_String,
5952 VAXDF_Safe_First
'Universal_Literal_String,
5953 VAXGF_Safe_First
'Universal_Literal_String,
5954 AAMPS_Safe_First
'Universal_Literal_String,
5955 AAMPL_Safe_First
'Universal_Literal_String);
5961 when Attribute_Safe_Large
=>
5962 if Is_Fixed_Point_Type
(P_Type
) then
5964 (N
, Expr_Value_R
(Type_High_Bound
(P_Base_Type
)), Static
);
5966 Float_Attribute_Universal_Real
(
5967 IEEES_Safe_Large
'Universal_Literal_String,
5968 IEEEL_Safe_Large
'Universal_Literal_String,
5969 IEEEX_Safe_Large
'Universal_Literal_String,
5970 VAXFF_Safe_Large
'Universal_Literal_String,
5971 VAXDF_Safe_Large
'Universal_Literal_String,
5972 VAXGF_Safe_Large
'Universal_Literal_String,
5973 AAMPS_Safe_Large
'Universal_Literal_String,
5974 AAMPL_Safe_Large
'Universal_Literal_String);
5981 when Attribute_Safe_Last
=>
5982 Float_Attribute_Universal_Real
(
5983 IEEES_Safe_Last
'Universal_Literal_String,
5984 IEEEL_Safe_Last
'Universal_Literal_String,
5985 IEEEX_Safe_Last
'Universal_Literal_String,
5986 VAXFF_Safe_Last
'Universal_Literal_String,
5987 VAXDF_Safe_Last
'Universal_Literal_String,
5988 VAXGF_Safe_Last
'Universal_Literal_String,
5989 AAMPS_Safe_Last
'Universal_Literal_String,
5990 AAMPL_Safe_Last
'Universal_Literal_String);
5996 when Attribute_Safe_Small
=>
5998 -- In Ada 95, the old Ada 83 attribute Safe_Small is redundant
5999 -- for fixed-point, since is the same as Small, but we implement
6000 -- it for backwards compatibility.
6002 if Is_Fixed_Point_Type
(P_Type
) then
6003 Fold_Ureal
(N
, Small_Value
(P_Type
), Static
);
6005 -- Ada 83 Safe_Small for floating-point cases
6008 Float_Attribute_Universal_Real
(
6009 IEEES_Safe_Small
'Universal_Literal_String,
6010 IEEEL_Safe_Small
'Universal_Literal_String,
6011 IEEEX_Safe_Small
'Universal_Literal_String,
6012 VAXFF_Safe_Small
'Universal_Literal_String,
6013 VAXDF_Safe_Small
'Universal_Literal_String,
6014 VAXGF_Safe_Small
'Universal_Literal_String,
6015 AAMPS_Safe_Small
'Universal_Literal_String,
6016 AAMPL_Safe_Small
'Universal_Literal_String);
6023 when Attribute_Scale
=>
6024 Fold_Uint
(N
, Scale_Value
(P_Type
), True);
6030 when Attribute_Scaling
=>
6033 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)), Static
);
6039 when Attribute_Signed_Zeros
=>
6041 (N
, UI_From_Int
(Boolean'Pos (Signed_Zeros_On_Target
)), Static
);
6047 -- Size attribute returns the RM size. All scalar types can be folded,
6048 -- as well as any types for which the size is known by the front end,
6049 -- including any type for which a size attribute is specified.
6051 when Attribute_Size | Attribute_VADS_Size
=> Size
: declare
6052 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
6055 if RM_Size
(P_TypeA
) /= Uint_0
then
6059 if Id
= Attribute_VADS_Size
or else Use_VADS_Size
then
6061 S
: constant Node_Id
:= Size_Clause
(P_TypeA
);
6064 -- If a size clause applies, then use the size from it.
6065 -- This is one of the rare cases where we can use the
6066 -- Size_Clause field for a subtype when Has_Size_Clause
6067 -- is False. Consider:
6069 -- type x is range 1 .. 64;
6070 -- for x'size use 12;
6071 -- subtype y is x range 0 .. 3;
6073 -- Here y has a size clause inherited from x, but normally
6074 -- it does not apply, and y'size is 2. However, y'VADS_Size
6075 -- is indeed 12 and not 2.
6078 and then Is_OK_Static_Expression
(Expression
(S
))
6080 Fold_Uint
(N
, Expr_Value
(Expression
(S
)), True);
6082 -- If no size is specified, then we simply use the object
6083 -- size in the VADS_Size case (e.g. Natural'Size is equal
6084 -- to Integer'Size, not one less).
6087 Fold_Uint
(N
, Esize
(P_TypeA
), True);
6091 -- Normal case (Size) in which case we want the RM_Size
6096 Static
and then Is_Discrete_Type
(P_TypeA
));
6105 when Attribute_Small
=>
6107 -- The floating-point case is present only for Ada 83 compatability.
6108 -- Note that strictly this is an illegal addition, since we are
6109 -- extending an Ada 95 defined attribute, but we anticipate an
6110 -- ARG ruling that will permit this.
6112 if Is_Floating_Point_Type
(P_Type
) then
6114 -- Ada 83 attribute is defined as (RM83 3.5.8)
6116 -- T'Small = 2.0**(-T'Emax - 1)
6120 -- T'Emax = 4 * T'Mantissa
6122 Fold_Ureal
(N
, Ureal_2
** ((-(4 * Mantissa
)) - 1), Static
);
6124 -- Normal Ada 95 fixed-point case
6127 Fold_Ureal
(N
, Small_Value
(P_Type
), True);
6134 when Attribute_Stream_Size
=>
6141 when Attribute_Succ
=> Succ
:
6143 -- Floating-point case
6145 if Is_Floating_Point_Type
(P_Type
) then
6147 Eval_Fat
.Succ
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
6151 elsif Is_Fixed_Point_Type
(P_Type
) then
6153 Expr_Value_R
(E1
) + Small_Value
(P_Type
), Static
);
6155 -- Modular integer case (wraps)
6157 elsif Is_Modular_Integer_Type
(P_Type
) then
6158 Fold_Uint
(N
, (Expr_Value
(E1
) + 1) mod Modulus
(P_Type
), Static
);
6160 -- Other scalar cases
6163 pragma Assert
(Is_Scalar_Type
(P_Type
));
6165 if Is_Enumeration_Type
(P_Type
)
6166 and then Expr_Value
(E1
) =
6167 Expr_Value
(Type_High_Bound
(P_Base_Type
))
6169 Apply_Compile_Time_Constraint_Error
6170 (N
, "Succ of `&''Last`",
6171 CE_Overflow_Check_Failed
,
6173 Warn
=> not Static
);
6178 Fold_Uint
(N
, Expr_Value
(E1
) + 1, Static
);
6187 when Attribute_Truncation
=>
6189 Eval_Fat
.Truncation
(P_Root_Type
, Expr_Value_R
(E1
)), Static
);
6195 when Attribute_Type_Class
=> Type_Class
: declare
6196 Typ
: constant Entity_Id
:= Underlying_Type
(P_Base_Type
);
6200 if Is_Descendent_Of_Address
(Typ
) then
6201 Id
:= RE_Type_Class_Address
;
6203 elsif Is_Enumeration_Type
(Typ
) then
6204 Id
:= RE_Type_Class_Enumeration
;
6206 elsif Is_Integer_Type
(Typ
) then
6207 Id
:= RE_Type_Class_Integer
;
6209 elsif Is_Fixed_Point_Type
(Typ
) then
6210 Id
:= RE_Type_Class_Fixed_Point
;
6212 elsif Is_Floating_Point_Type
(Typ
) then
6213 Id
:= RE_Type_Class_Floating_Point
;
6215 elsif Is_Array_Type
(Typ
) then
6216 Id
:= RE_Type_Class_Array
;
6218 elsif Is_Record_Type
(Typ
) then
6219 Id
:= RE_Type_Class_Record
;
6221 elsif Is_Access_Type
(Typ
) then
6222 Id
:= RE_Type_Class_Access
;
6224 elsif Is_Enumeration_Type
(Typ
) then
6225 Id
:= RE_Type_Class_Enumeration
;
6227 elsif Is_Task_Type
(Typ
) then
6228 Id
:= RE_Type_Class_Task
;
6230 -- We treat protected types like task types. It would make more
6231 -- sense to have another enumeration value, but after all the
6232 -- whole point of this feature is to be exactly DEC compatible,
6233 -- and changing the type Type_Clas would not meet this requirement.
6235 elsif Is_Protected_Type
(Typ
) then
6236 Id
:= RE_Type_Class_Task
;
6238 -- Not clear if there are any other possibilities, but if there
6239 -- are, then we will treat them as the address case.
6242 Id
:= RE_Type_Class_Address
;
6245 Rewrite
(N
, New_Occurrence_Of
(RTE
(Id
), Loc
));
6249 -----------------------
6250 -- Unbiased_Rounding --
6251 -----------------------
6253 when Attribute_Unbiased_Rounding
=>
6255 Eval_Fat
.Unbiased_Rounding
(P_Root_Type
, Expr_Value_R
(E1
)),
6258 -------------------------
6259 -- Unconstrained_Array --
6260 -------------------------
6262 when Attribute_Unconstrained_Array
=> Unconstrained_Array
: declare
6263 Typ
: constant Entity_Id
:= Underlying_Type
(P_Type
);
6266 Rewrite
(N
, New_Occurrence_Of
(
6268 Is_Array_Type
(P_Type
)
6269 and then not Is_Constrained
(Typ
)), Loc
));
6271 -- Analyze and resolve as boolean, note that this attribute is
6272 -- a static attribute in GNAT.
6274 Analyze_And_Resolve
(N
, Standard_Boolean
);
6276 end Unconstrained_Array
;
6282 -- Processing is shared with Size
6288 when Attribute_Val
=> Val
:
6290 if Expr_Value
(E1
) < Expr_Value
(Type_Low_Bound
(P_Base_Type
))
6292 Expr_Value
(E1
) > Expr_Value
(Type_High_Bound
(P_Base_Type
))
6294 Apply_Compile_Time_Constraint_Error
6295 (N
, "Val expression out of range",
6296 CE_Range_Check_Failed
,
6297 Warn
=> not Static
);
6303 Fold_Uint
(N
, Expr_Value
(E1
), Static
);
6311 -- The Value_Size attribute for a type returns the RM size of the
6312 -- type. This an always be folded for scalar types, and can also
6313 -- be folded for non-scalar types if the size is set.
6315 when Attribute_Value_Size
=> Value_Size
: declare
6316 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
6319 if RM_Size
(P_TypeA
) /= Uint_0
then
6320 Fold_Uint
(N
, RM_Size
(P_TypeA
), True);
6329 -- Version can never be static
6331 when Attribute_Version
=>
6338 -- Wide_Image is a scalar attribute, but is never static, because it
6339 -- is not a static function (having a non-scalar argument (RM 4.9(22))
6341 when Attribute_Wide_Image
=>
6344 ---------------------
6345 -- Wide_Wide_Image --
6346 ---------------------
6348 -- Wide_Wide_Image is a scalar attribute but is never static, because it
6349 -- is not a static function (having a non-scalar argument (RM 4.9(22)).
6351 when Attribute_Wide_Wide_Image
=>
6354 ---------------------
6355 -- Wide_Wide_Width --
6356 ---------------------
6358 -- Processing for Wide_Wide_Width is combined with Width
6364 -- Processing for Wide_Width is combined with Width
6370 -- This processing also handles the case of Wide_[Wide_]Width
6372 when Attribute_Width |
6373 Attribute_Wide_Width |
6374 Attribute_Wide_Wide_Width
=> Width
:
6376 if Compile_Time_Known_Bounds
(P_Type
) then
6378 -- Floating-point types
6380 if Is_Floating_Point_Type
(P_Type
) then
6382 -- Width is zero for a null range (RM 3.5 (38))
6384 if Expr_Value_R
(Type_High_Bound
(P_Type
)) <
6385 Expr_Value_R
(Type_Low_Bound
(P_Type
))
6387 Fold_Uint
(N
, Uint_0
, True);
6390 -- For floating-point, we have +N.dddE+nnn where length
6391 -- of ddd is determined by type'Digits - 1, but is one
6392 -- if Digits is one (RM 3.5 (33)).
6394 -- nnn is set to 2 for Short_Float and Float (32 bit
6395 -- floats), and 3 for Long_Float and Long_Long_Float.
6396 -- This is not quite right, but is good enough.
6400 Int
'Max (2, UI_To_Int
(Digits_Value
(P_Type
)));
6403 if Esize
(P_Type
) <= 32 then
6409 Fold_Uint
(N
, UI_From_Int
(Len
), True);
6413 -- Fixed-point types
6415 elsif Is_Fixed_Point_Type
(P_Type
) then
6417 -- Width is zero for a null range (RM 3.5 (38))
6419 if Expr_Value
(Type_High_Bound
(P_Type
)) <
6420 Expr_Value
(Type_Low_Bound
(P_Type
))
6422 Fold_Uint
(N
, Uint_0
, True);
6424 -- The non-null case depends on the specific real type
6427 -- For fixed-point type width is Fore + 1 + Aft (RM 3.5(34))
6430 (N
, UI_From_Int
(Fore_Value
+ 1 + Aft_Value
), True);
6437 R
: constant Entity_Id
:= Root_Type
(P_Type
);
6438 Lo
: constant Uint
:=
6439 Expr_Value
(Type_Low_Bound
(P_Type
));
6440 Hi
: constant Uint
:=
6441 Expr_Value
(Type_High_Bound
(P_Type
));
6454 -- Width for types derived from Standard.Character
6455 -- and Standard.Wide_[Wide_]Character.
6457 elsif R
= Standard_Character
6458 or else R
= Standard_Wide_Character
6459 or else R
= Standard_Wide_Wide_Character
6463 -- Set W larger if needed
6465 for J
in UI_To_Int
(Lo
) .. UI_To_Int
(Hi
) loop
6467 -- All wide characters look like Hex_hhhhhhhh
6473 C
:= Character'Val (J
);
6475 -- Test for all cases where Character'Image
6476 -- yields an image that is longer than three
6477 -- characters. First the cases of Reserved_xxx
6478 -- names (length = 12).
6481 when Reserved_128 | Reserved_129 |
6482 Reserved_132 | Reserved_153
6486 when BS | HT | LF | VT | FF | CR |
6487 SO | SI | EM | FS | GS | RS |
6488 US | RI | MW | ST | PM
6492 when NUL | SOH | STX | ETX | EOT |
6493 ENQ | ACK | BEL | DLE | DC1 |
6494 DC2 | DC3 | DC4 | NAK | SYN |
6495 ETB | CAN | SUB | ESC | DEL |
6496 BPH | NBH | NEL | SSA | ESA |
6497 HTS | HTJ | VTS | PLD | PLU |
6498 SS2 | SS3 | DCS | PU1 | PU2 |
6499 STS | CCH | SPA | EPA | SOS |
6500 SCI | CSI | OSC | APC
6504 when Space
.. Tilde |
6505 No_Break_Space
.. LC_Y_Diaeresis
6510 W
:= Int
'Max (W
, Wt
);
6514 -- Width for types derived from Standard.Boolean
6516 elsif R
= Standard_Boolean
then
6523 -- Width for integer types
6525 elsif Is_Integer_Type
(P_Type
) then
6526 T
:= UI_Max
(abs Lo
, abs Hi
);
6534 -- Only remaining possibility is user declared enum type
6537 pragma Assert
(Is_Enumeration_Type
(P_Type
));
6540 L
:= First_Literal
(P_Type
);
6542 while Present
(L
) loop
6544 -- Only pay attention to in range characters
6546 if Lo
<= Enumeration_Pos
(L
)
6547 and then Enumeration_Pos
(L
) <= Hi
6549 -- For Width case, use decoded name
6551 if Id
= Attribute_Width
then
6552 Get_Decoded_Name_String
(Chars
(L
));
6553 Wt
:= Nat
(Name_Len
);
6555 -- For Wide_[Wide_]Width, use encoded name, and
6556 -- then adjust for the encoding.
6559 Get_Name_String
(Chars
(L
));
6561 -- Character literals are always of length 3
6563 if Name_Buffer
(1) = 'Q' then
6566 -- Otherwise loop to adjust for upper/wide chars
6569 Wt
:= Nat
(Name_Len
);
6571 for J
in 1 .. Name_Len
loop
6572 if Name_Buffer
(J
) = 'U' then
6574 elsif Name_Buffer
(J
) = 'W' then
6581 W
:= Int
'Max (W
, Wt
);
6588 Fold_Uint
(N
, UI_From_Int
(W
), True);
6594 -- The following attributes can never be folded, and furthermore we
6595 -- should not even have entered the case statement for any of these.
6596 -- Note that in some cases, the values have already been folded as
6597 -- a result of the processing in Analyze_Attribute.
6599 when Attribute_Abort_Signal |
6602 Attribute_Address_Size |
6603 Attribute_Asm_Input |
6604 Attribute_Asm_Output |
6606 Attribute_Bit_Order |
6607 Attribute_Bit_Position |
6608 Attribute_Callable |
6611 Attribute_Code_Address |
6613 Attribute_Default_Bit_Order |
6614 Attribute_Elaborated |
6615 Attribute_Elab_Body |
6616 Attribute_Elab_Spec |
6617 Attribute_External_Tag |
6618 Attribute_First_Bit |
6620 Attribute_Last_Bit |
6621 Attribute_Maximum_Alignment |
6623 Attribute_Partition_ID |
6624 Attribute_Pool_Address |
6625 Attribute_Position |
6627 Attribute_Storage_Pool |
6628 Attribute_Storage_Size |
6629 Attribute_Storage_Unit |
6631 Attribute_Target_Name |
6632 Attribute_Terminated |
6633 Attribute_To_Address |
6634 Attribute_UET_Address |
6635 Attribute_Unchecked_Access |
6636 Attribute_Universal_Literal_String |
6637 Attribute_Unrestricted_Access |
6640 Attribute_Wchar_T_Size |
6641 Attribute_Wide_Value |
6642 Attribute_Wide_Wide_Value |
6643 Attribute_Word_Size |
6646 raise Program_Error
;
6649 -- At the end of the case, one more check. If we did a static evaluation
6650 -- so that the result is now a literal, then set Is_Static_Expression
6651 -- in the constant only if the prefix type is a static subtype. For
6652 -- non-static subtypes, the folding is still OK, but not static.
6654 -- An exception is the GNAT attribute Constrained_Array which is
6655 -- defined to be a static attribute in all cases.
6657 if Nkind
(N
) = N_Integer_Literal
6658 or else Nkind
(N
) = N_Real_Literal
6659 or else Nkind
(N
) = N_Character_Literal
6660 or else Nkind
(N
) = N_String_Literal
6661 or else (Is_Entity_Name
(N
)
6662 and then Ekind
(Entity
(N
)) = E_Enumeration_Literal
)
6664 Set_Is_Static_Expression
(N
, Static
);
6666 -- If this is still an attribute reference, then it has not been folded
6667 -- and that means that its expressions are in a non-static context.
6669 elsif Nkind
(N
) = N_Attribute_Reference
then
6672 -- Note: the else case not covered here are odd cases where the
6673 -- processing has transformed the attribute into something other
6674 -- than a constant. Nothing more to do in such cases.
6682 ------------------------------
6683 -- Is_Anonymous_Tagged_Base --
6684 ------------------------------
6686 function Is_Anonymous_Tagged_Base
6693 Anon
= Current_Scope
6694 and then Is_Itype
(Anon
)
6695 and then Associated_Node_For_Itype
(Anon
) = Parent
(Typ
);
6696 end Is_Anonymous_Tagged_Base
;
6698 -----------------------
6699 -- Resolve_Attribute --
6700 -----------------------
6702 procedure Resolve_Attribute
(N
: Node_Id
; Typ
: Entity_Id
) is
6703 Loc
: constant Source_Ptr
:= Sloc
(N
);
6704 P
: constant Node_Id
:= Prefix
(N
);
6705 Aname
: constant Name_Id
:= Attribute_Name
(N
);
6706 Attr_Id
: constant Attribute_Id
:= Get_Attribute_Id
(Aname
);
6707 Btyp
: constant Entity_Id
:= Base_Type
(Typ
);
6708 Index
: Interp_Index
;
6710 Nom_Subt
: Entity_Id
;
6712 procedure Accessibility_Message
;
6713 -- Error, or warning within an instance, if the static accessibility
6714 -- rules of 3.10.2 are violated.
6716 ---------------------------
6717 -- Accessibility_Message --
6718 ---------------------------
6720 procedure Accessibility_Message
is
6721 Indic
: Node_Id
:= Parent
(Parent
(N
));
6724 -- In an instance, this is a runtime check, but one we
6725 -- know will fail, so generate an appropriate warning.
6727 if In_Instance_Body
then
6729 ("?non-local pointer cannot point to local object", P
);
6731 ("?Program_Error will be raised at run time", P
);
6733 Make_Raise_Program_Error
(Loc
,
6734 Reason
=> PE_Accessibility_Check_Failed
));
6740 ("non-local pointer cannot point to local object", P
);
6742 -- Check for case where we have a missing access definition
6744 if Is_Record_Type
(Current_Scope
)
6746 (Nkind
(Parent
(N
)) = N_Discriminant_Association
6748 Nkind
(Parent
(N
)) = N_Index_Or_Discriminant_Constraint
)
6750 Indic
:= Parent
(Parent
(N
));
6751 while Present
(Indic
)
6752 and then Nkind
(Indic
) /= N_Subtype_Indication
6754 Indic
:= Parent
(Indic
);
6757 if Present
(Indic
) then
6759 ("\use an access definition for" &
6760 " the access discriminant of&", N
,
6761 Entity
(Subtype_Mark
(Indic
)));
6765 end Accessibility_Message
;
6767 -- Start of processing for Resolve_Attribute
6770 -- If error during analysis, no point in continuing, except for
6771 -- array types, where we get better recovery by using unconstrained
6772 -- indices than nothing at all (see Check_Array_Type).
6775 and then Attr_Id
/= Attribute_First
6776 and then Attr_Id
/= Attribute_Last
6777 and then Attr_Id
/= Attribute_Length
6778 and then Attr_Id
/= Attribute_Range
6783 -- If attribute was universal type, reset to actual type
6785 if Etype
(N
) = Universal_Integer
6786 or else Etype
(N
) = Universal_Real
6791 -- Remaining processing depends on attribute
6799 -- For access attributes, if the prefix denotes an entity, it is
6800 -- interpreted as a name, never as a call. It may be overloaded,
6801 -- in which case resolution uses the profile of the context type.
6802 -- Otherwise prefix must be resolved.
6804 when Attribute_Access
6805 | Attribute_Unchecked_Access
6806 | Attribute_Unrestricted_Access
=>
6808 if Is_Variable
(P
) then
6809 Note_Possible_Modification
(P
);
6812 if Is_Entity_Name
(P
) then
6813 if Is_Overloaded
(P
) then
6814 Get_First_Interp
(P
, Index
, It
);
6816 while Present
(It
.Nam
) loop
6818 if Type_Conformant
(Designated_Type
(Typ
), It
.Nam
) then
6819 Set_Entity
(P
, It
.Nam
);
6821 -- The prefix is definitely NOT overloaded anymore
6822 -- at this point, so we reset the Is_Overloaded
6823 -- flag to avoid any confusion when reanalyzing
6826 Set_Is_Overloaded
(P
, False);
6827 Generate_Reference
(Entity
(P
), P
);
6831 Get_Next_Interp
(Index
, It
);
6834 -- If it is a subprogram name or a type, there is nothing
6837 elsif not Is_Overloadable
(Entity
(P
))
6838 and then not Is_Type
(Entity
(P
))
6843 Error_Msg_Name_1
:= Aname
;
6845 if not Is_Entity_Name
(P
) then
6848 elsif Is_Abstract
(Entity
(P
))
6849 and then Is_Overloadable
(Entity
(P
))
6851 Error_Msg_N
("prefix of % attribute cannot be abstract", P
);
6852 Set_Etype
(N
, Any_Type
);
6854 elsif Convention
(Entity
(P
)) = Convention_Intrinsic
then
6855 if Ekind
(Entity
(P
)) = E_Enumeration_Literal
then
6857 ("prefix of % attribute cannot be enumeration literal",
6861 ("prefix of % attribute cannot be intrinsic", P
);
6864 Set_Etype
(N
, Any_Type
);
6866 elsif Is_Thread_Body
(Entity
(P
)) then
6868 ("prefix of % attribute cannot be a thread body", P
);
6871 -- Assignments, return statements, components of aggregates,
6872 -- generic instantiations will require convention checks if
6873 -- the type is an access to subprogram. Given that there will
6874 -- also be accessibility checks on those, this is where the
6875 -- checks can eventually be centralized ???
6877 if Ekind
(Btyp
) = E_Access_Subprogram_Type
6879 Ekind
(Btyp
) = E_Anonymous_Access_Subprogram_Type
6881 Ekind
(Btyp
) = E_Anonymous_Access_Protected_Subprogram_Type
6883 if Convention
(Btyp
) /= Convention
(Entity
(P
)) then
6885 ("subprogram has invalid convention for context", P
);
6888 Check_Subtype_Conformant
6889 (New_Id
=> Entity
(P
),
6890 Old_Id
=> Designated_Type
(Btyp
),
6894 if Attr_Id
= Attribute_Unchecked_Access
then
6895 Error_Msg_Name_1
:= Aname
;
6897 ("attribute% cannot be applied to a subprogram", P
);
6899 elsif Aname
= Name_Unrestricted_Access
then
6900 null; -- Nothing to check
6902 -- Check the static accessibility rule of 3.10.2(32)
6903 -- In an instance body, if subprogram and type are both
6904 -- local, other rules prevent dangling references, and no
6905 -- warning is needed.
6907 elsif Attr_Id
= Attribute_Access
6908 and then Subprogram_Access_Level
(Entity
(P
)) >
6909 Type_Access_Level
(Btyp
)
6910 and then Ekind
(Btyp
) /=
6911 E_Anonymous_Access_Subprogram_Type
6912 and then Ekind
(Btyp
) /=
6913 E_Anonymous_Access_Protected_Subprogram_Type
6915 if not In_Instance_Body
then
6917 ("subprogram must not be deeper than access type",
6920 elsif Scope
(Entity
(P
)) /= Scope
(Btyp
) then
6922 ("subprogram must not be deeper than access type?",
6925 ("Constraint_Error will be raised ?", P
);
6926 Set_Raises_Constraint_Error
(N
);
6929 -- Check the restriction of 3.10.2(32) that disallows
6930 -- the type of the access attribute to be declared
6931 -- outside a generic body when the subprogram is declared
6932 -- within that generic body.
6934 -- Ada2005: If the expected type is for an access
6935 -- parameter, this clause does not apply.
6937 elsif Present
(Enclosing_Generic_Body
(Entity
(P
)))
6938 and then Enclosing_Generic_Body
(Entity
(P
)) /=
6939 Enclosing_Generic_Body
(Btyp
)
6941 Ekind
(Btyp
) /= E_Anonymous_Access_Subprogram_Type
6944 ("access type must not be outside generic body", P
);
6948 -- If this is a renaming, an inherited operation, or a
6949 -- subprogram instance, use the original entity.
6951 if Is_Entity_Name
(P
)
6952 and then Is_Overloadable
(Entity
(P
))
6953 and then Present
(Alias
(Entity
(P
)))
6956 New_Occurrence_Of
(Alias
(Entity
(P
)), Sloc
(P
)));
6959 elsif Nkind
(P
) = N_Selected_Component
6960 and then Is_Overloadable
(Entity
(Selector_Name
(P
)))
6962 -- Protected operation. If operation is overloaded, must
6963 -- disambiguate. Prefix that denotes protected object itself
6964 -- is resolved with its own type.
6966 if Attr_Id
= Attribute_Unchecked_Access
then
6967 Error_Msg_Name_1
:= Aname
;
6969 ("attribute% cannot be applied to protected operation", P
);
6972 Resolve
(Prefix
(P
));
6973 Generate_Reference
(Entity
(Selector_Name
(P
)), P
);
6975 elsif Is_Overloaded
(P
) then
6977 -- Use the designated type of the context to disambiguate
6978 -- Note that this was not strictly conformant to Ada 95,
6979 -- but was the implementation adopted by most Ada 95 compilers.
6980 -- The use of the context type to resolve an Access attribute
6981 -- reference is now mandated in AI-235 for Ada 2005.
6984 Index
: Interp_Index
;
6988 Get_First_Interp
(P
, Index
, It
);
6989 while Present
(It
.Typ
) loop
6990 if Covers
(Designated_Type
(Typ
), It
.Typ
) then
6991 Resolve
(P
, It
.Typ
);
6995 Get_Next_Interp
(Index
, It
);
7002 -- X'Access is illegal if X denotes a constant and the access
7003 -- type is access-to-variable. Same for 'Unchecked_Access.
7004 -- The rule does not apply to 'Unrestricted_Access.
7006 if not (Ekind
(Btyp
) = E_Access_Subprogram_Type
7007 or else Ekind
(Btyp
) = E_Anonymous_Access_Subprogram_Type
7008 or else (Is_Record_Type
(Btyp
) and then
7009 Present
(Corresponding_Remote_Type
(Btyp
)))
7010 or else Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
7011 or else Ekind
(Btyp
)
7012 = E_Anonymous_Access_Protected_Subprogram_Type
7013 or else Is_Access_Constant
(Btyp
)
7014 or else Is_Variable
(P
)
7015 or else Attr_Id
= Attribute_Unrestricted_Access
)
7017 if Comes_From_Source
(N
) then
7018 Error_Msg_N
("access-to-variable designates constant", P
);
7022 if (Attr_Id
= Attribute_Access
7024 Attr_Id
= Attribute_Unchecked_Access
)
7025 and then (Ekind
(Btyp
) = E_General_Access_Type
7026 or else Ekind
(Btyp
) = E_Anonymous_Access_Type
)
7028 -- Ada 2005 (AI-230): Check the accessibility of anonymous
7029 -- access types in record and array components. For a
7030 -- component definition the level is the same of the
7031 -- enclosing composite type.
7033 if Ada_Version
>= Ada_05
7034 and then Is_Local_Anonymous_Access
(Btyp
)
7035 and then Object_Access_Level
(P
) > Type_Access_Level
(Btyp
)
7037 -- In an instance, this is a runtime check, but one we
7038 -- know will fail, so generate an appropriate warning.
7040 if In_Instance_Body
then
7042 ("?non-local pointer cannot point to local object", P
);
7044 ("?Program_Error will be raised at run time", P
);
7046 Make_Raise_Program_Error
(Loc
,
7047 Reason
=> PE_Accessibility_Check_Failed
));
7051 ("non-local pointer cannot point to local object", P
);
7055 if Is_Dependent_Component_Of_Mutable_Object
(P
) then
7057 ("illegal attribute for discriminant-dependent component",
7061 -- Check the static matching rule of 3.10.2(27). The
7062 -- nominal subtype of the prefix must statically
7063 -- match the designated type.
7065 Nom_Subt
:= Etype
(P
);
7067 if Is_Constr_Subt_For_U_Nominal
(Nom_Subt
) then
7068 Nom_Subt
:= Etype
(Nom_Subt
);
7071 if Is_Tagged_Type
(Designated_Type
(Typ
)) then
7073 -- If the attribute is in the context of an access
7074 -- parameter, then the prefix is allowed to be of
7075 -- the class-wide type (by AI-127).
7077 if Ekind
(Typ
) = E_Anonymous_Access_Type
then
7078 if not Covers
(Designated_Type
(Typ
), Nom_Subt
)
7079 and then not Covers
(Nom_Subt
, Designated_Type
(Typ
))
7085 Desig
:= Designated_Type
(Typ
);
7087 if Is_Class_Wide_Type
(Desig
) then
7088 Desig
:= Etype
(Desig
);
7091 if Is_Anonymous_Tagged_Base
(Nom_Subt
, Desig
) then
7096 ("type of prefix: & not compatible",
7099 ("\with &, the expected designated type",
7100 P
, Designated_Type
(Typ
));
7105 elsif not Covers
(Designated_Type
(Typ
), Nom_Subt
)
7107 (not Is_Class_Wide_Type
(Designated_Type
(Typ
))
7108 and then Is_Class_Wide_Type
(Nom_Subt
))
7111 ("type of prefix: & is not covered", P
, Nom_Subt
);
7113 ("\by &, the expected designated type" &
7114 " ('R'M 3.10.2 (27))", P
, Designated_Type
(Typ
));
7117 if Is_Class_Wide_Type
(Designated_Type
(Typ
))
7118 and then Has_Discriminants
(Etype
(Designated_Type
(Typ
)))
7119 and then Is_Constrained
(Etype
(Designated_Type
(Typ
)))
7120 and then Designated_Type
(Typ
) /= Nom_Subt
7122 Apply_Discriminant_Check
7123 (N
, Etype
(Designated_Type
(Typ
)));
7126 elsif not Subtypes_Statically_Match
7127 (Designated_Type
(Base_Type
(Typ
)), Nom_Subt
)
7129 not (Has_Discriminants
(Designated_Type
(Typ
))
7132 (Designated_Type
(Base_Type
(Typ
))))
7135 ("object subtype must statically match "
7136 & "designated subtype", P
);
7138 if Is_Entity_Name
(P
)
7139 and then Is_Array_Type
(Designated_Type
(Typ
))
7143 D
: constant Node_Id
:= Declaration_Node
(Entity
(P
));
7146 Error_Msg_N
("aliased object has explicit bounds?",
7148 Error_Msg_N
("\declare without bounds"
7149 & " (and with explicit initialization)?", D
);
7150 Error_Msg_N
("\for use with unconstrained access?", D
);
7155 -- Check the static accessibility rule of 3.10.2(28).
7156 -- Note that this check is not performed for the
7157 -- case of an anonymous access type, since the access
7158 -- attribute is always legal in such a context.
7160 if Attr_Id
/= Attribute_Unchecked_Access
7161 and then Object_Access_Level
(P
) > Type_Access_Level
(Btyp
)
7162 and then Ekind
(Btyp
) = E_General_Access_Type
7164 Accessibility_Message
;
7169 if Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
7171 Ekind
(Btyp
) = E_Anonymous_Access_Protected_Subprogram_Type
7173 if Is_Entity_Name
(P
)
7174 and then not Is_Protected_Type
(Scope
(Entity
(P
)))
7176 Error_Msg_N
("context requires a protected subprogram", P
);
7178 -- Check accessibility of protected object against that
7179 -- of the access type, but only on user code, because
7180 -- the expander creates access references for handlers.
7181 -- If the context is an anonymous_access_to_protected,
7182 -- there are no accessibility checks either.
7184 elsif Object_Access_Level
(P
) > Type_Access_Level
(Btyp
)
7185 and then Comes_From_Source
(N
)
7186 and then Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
7187 and then No
(Original_Access_Type
(Typ
))
7189 Accessibility_Message
;
7193 elsif (Ekind
(Btyp
) = E_Access_Subprogram_Type
7195 Ekind
(Btyp
) = E_Anonymous_Access_Subprogram_Type
)
7196 and then Ekind
(Etype
(N
)) = E_Access_Protected_Subprogram_Type
7198 Error_Msg_N
("context requires a non-protected subprogram", P
);
7201 -- The context cannot be a pool-specific type, but this is a
7202 -- legality rule, not a resolution rule, so it must be checked
7203 -- separately, after possibly disambiguation (see AI-245).
7205 if Ekind
(Btyp
) = E_Access_Type
7206 and then Attr_Id
/= Attribute_Unrestricted_Access
7208 Wrong_Type
(N
, Typ
);
7213 -- Check for incorrect atomic/volatile reference (RM C.6(12))
7215 if Attr_Id
/= Attribute_Unrestricted_Access
then
7216 if Is_Atomic_Object
(P
)
7217 and then not Is_Atomic
(Designated_Type
(Typ
))
7220 ("access to atomic object cannot yield access-to-" &
7221 "non-atomic type", P
);
7223 elsif Is_Volatile_Object
(P
)
7224 and then not Is_Volatile
(Designated_Type
(Typ
))
7227 ("access to volatile object cannot yield access-to-" &
7228 "non-volatile type", P
);
7236 -- Deal with resolving the type for Address attribute, overloading
7237 -- is not permitted here, since there is no context to resolve it.
7239 when Attribute_Address | Attribute_Code_Address
=>
7241 -- To be safe, assume that if the address of a variable is taken,
7242 -- it may be modified via this address, so note modification.
7244 if Is_Variable
(P
) then
7245 Note_Possible_Modification
(P
);
7248 if Nkind
(P
) in N_Subexpr
7249 and then Is_Overloaded
(P
)
7251 Get_First_Interp
(P
, Index
, It
);
7252 Get_Next_Interp
(Index
, It
);
7254 if Present
(It
.Nam
) then
7255 Error_Msg_Name_1
:= Aname
;
7257 ("prefix of % attribute cannot be overloaded", P
);
7262 if not Is_Entity_Name
(P
)
7263 or else not Is_Overloadable
(Entity
(P
))
7265 if not Is_Task_Type
(Etype
(P
))
7266 or else Nkind
(P
) = N_Explicit_Dereference
7272 -- If this is the name of a derived subprogram, or that of a
7273 -- generic actual, the address is that of the original entity.
7275 if Is_Entity_Name
(P
)
7276 and then Is_Overloadable
(Entity
(P
))
7277 and then Present
(Alias
(Entity
(P
)))
7280 New_Occurrence_Of
(Alias
(Entity
(P
)), Sloc
(P
)));
7287 -- Prefix of the AST_Entry attribute is an entry name which must
7288 -- not be resolved, since this is definitely not an entry call.
7290 when Attribute_AST_Entry
=>
7297 -- Prefix of Body_Version attribute can be a subprogram name which
7298 -- must not be resolved, since this is not a call.
7300 when Attribute_Body_Version
=>
7307 -- Prefix of Caller attribute is an entry name which must not
7308 -- be resolved, since this is definitely not an entry call.
7310 when Attribute_Caller
=>
7317 -- Shares processing with Address attribute
7323 -- If the prefix of the Count attribute is an entry name it must not
7324 -- be resolved, since this is definitely not an entry call. However,
7325 -- if it is an element of an entry family, the index itself may
7326 -- have to be resolved because it can be a general expression.
7328 when Attribute_Count
=>
7329 if Nkind
(P
) = N_Indexed_Component
7330 and then Is_Entity_Name
(Prefix
(P
))
7333 Indx
: constant Node_Id
:= First
(Expressions
(P
));
7334 Fam
: constant Entity_Id
:= Entity
(Prefix
(P
));
7336 Resolve
(Indx
, Entry_Index_Type
(Fam
));
7337 Apply_Range_Check
(Indx
, Entry_Index_Type
(Fam
));
7345 -- Prefix of the Elaborated attribute is a subprogram name which
7346 -- must not be resolved, since this is definitely not a call. Note
7347 -- that it is a library unit, so it cannot be overloaded here.
7349 when Attribute_Elaborated
=>
7352 --------------------
7353 -- Mechanism_Code --
7354 --------------------
7356 -- Prefix of the Mechanism_Code attribute is a function name
7357 -- which must not be resolved. Should we check for overloaded ???
7359 when Attribute_Mechanism_Code
=>
7366 -- Most processing is done in sem_dist, after determining the
7367 -- context type. Node is rewritten as a conversion to a runtime call.
7369 when Attribute_Partition_ID
=>
7370 Process_Partition_Id
(N
);
7373 when Attribute_Pool_Address
=>
7380 -- We replace the Range attribute node with a range expression
7381 -- whose bounds are the 'First and 'Last attributes applied to the
7382 -- same prefix. The reason that we do this transformation here
7383 -- instead of in the expander is that it simplifies other parts of
7384 -- the semantic analysis which assume that the Range has been
7385 -- replaced; thus it must be done even when in semantic-only mode
7386 -- (note that the RM specifically mentions this equivalence, we
7387 -- take care that the prefix is only evaluated once).
7389 when Attribute_Range
=> Range_Attribute
:
7394 function Check_Discriminated_Prival
7397 -- The range of a private component constrained by a
7398 -- discriminant is rewritten to make the discriminant
7399 -- explicit. This solves some complex visibility problems
7400 -- related to the use of privals.
7402 --------------------------------
7403 -- Check_Discriminated_Prival --
7404 --------------------------------
7406 function Check_Discriminated_Prival
7411 if Is_Entity_Name
(N
)
7412 and then Ekind
(Entity
(N
)) = E_In_Parameter
7413 and then not Within_Init_Proc
7415 return Make_Identifier
(Sloc
(N
), Chars
(Entity
(N
)));
7417 return Duplicate_Subexpr
(N
);
7419 end Check_Discriminated_Prival
;
7421 -- Start of processing for Range_Attribute
7424 if not Is_Entity_Name
(P
)
7425 or else not Is_Type
(Entity
(P
))
7430 -- Check whether prefix is (renaming of) private component
7431 -- of protected type.
7433 if Is_Entity_Name
(P
)
7434 and then Comes_From_Source
(N
)
7435 and then Is_Array_Type
(Etype
(P
))
7436 and then Number_Dimensions
(Etype
(P
)) = 1
7437 and then (Ekind
(Scope
(Entity
(P
))) = E_Protected_Type
7439 Ekind
(Scope
(Scope
(Entity
(P
)))) =
7443 Check_Discriminated_Prival
7444 (Type_Low_Bound
(Etype
(First_Index
(Etype
(P
)))));
7447 Check_Discriminated_Prival
7448 (Type_High_Bound
(Etype
(First_Index
(Etype
(P
)))));
7452 Make_Attribute_Reference
(Loc
,
7453 Prefix
=> Duplicate_Subexpr
(P
),
7454 Attribute_Name
=> Name_Last
,
7455 Expressions
=> Expressions
(N
));
7458 Make_Attribute_Reference
(Loc
,
7460 Attribute_Name
=> Name_First
,
7461 Expressions
=> Expressions
(N
));
7464 -- If the original was marked as Must_Not_Freeze (see code
7465 -- in Sem_Ch3.Make_Index), then make sure the rewriting
7466 -- does not freeze either.
7468 if Must_Not_Freeze
(N
) then
7469 Set_Must_Not_Freeze
(HB
);
7470 Set_Must_Not_Freeze
(LB
);
7471 Set_Must_Not_Freeze
(Prefix
(HB
));
7472 Set_Must_Not_Freeze
(Prefix
(LB
));
7475 if Raises_Constraint_Error
(Prefix
(N
)) then
7477 -- Preserve Sloc of prefix in the new bounds, so that
7478 -- the posted warning can be removed if we are within
7479 -- unreachable code.
7481 Set_Sloc
(LB
, Sloc
(Prefix
(N
)));
7482 Set_Sloc
(HB
, Sloc
(Prefix
(N
)));
7485 Rewrite
(N
, Make_Range
(Loc
, LB
, HB
));
7486 Analyze_And_Resolve
(N
, Typ
);
7488 -- Normally after resolving attribute nodes, Eval_Attribute
7489 -- is called to do any possible static evaluation of the node.
7490 -- However, here since the Range attribute has just been
7491 -- transformed into a range expression it is no longer an
7492 -- attribute node and therefore the call needs to be avoided
7493 -- and is accomplished by simply returning from the procedure.
7496 end Range_Attribute
;
7502 -- Prefix must not be resolved in this case, since it is not a
7503 -- real entity reference. No action of any kind is require!
7505 when Attribute_UET_Address
=>
7508 ----------------------
7509 -- Unchecked_Access --
7510 ----------------------
7512 -- Processing is shared with Access
7514 -------------------------
7515 -- Unrestricted_Access --
7516 -------------------------
7518 -- Processing is shared with Access
7524 -- Apply range check. Note that we did not do this during the
7525 -- analysis phase, since we wanted Eval_Attribute to have a
7526 -- chance at finding an illegal out of range value.
7528 when Attribute_Val
=>
7530 -- Note that we do our own Eval_Attribute call here rather than
7531 -- use the common one, because we need to do processing after
7532 -- the call, as per above comment.
7536 -- Eval_Attribute may replace the node with a raise CE, or
7537 -- fold it to a constant. Obviously we only apply a scalar
7538 -- range check if this did not happen!
7540 if Nkind
(N
) = N_Attribute_Reference
7541 and then Attribute_Name
(N
) = Name_Val
7543 Apply_Scalar_Range_Check
(First
(Expressions
(N
)), Btyp
);
7552 -- Prefix of Version attribute can be a subprogram name which
7553 -- must not be resolved, since this is not a call.
7555 when Attribute_Version
=>
7558 ----------------------
7559 -- Other Attributes --
7560 ----------------------
7562 -- For other attributes, resolve prefix unless it is a type. If
7563 -- the attribute reference itself is a type name ('Base and 'Class)
7564 -- then this is only legal within a task or protected record.
7567 if not Is_Entity_Name
(P
)
7568 or else not Is_Type
(Entity
(P
))
7573 -- If the attribute reference itself is a type name ('Base,
7574 -- 'Class) then this is only legal within a task or protected
7575 -- record. What is this all about ???
7577 if Is_Entity_Name
(N
)
7578 and then Is_Type
(Entity
(N
))
7580 if Is_Concurrent_Type
(Entity
(N
))
7581 and then In_Open_Scopes
(Entity
(P
))
7586 ("invalid use of subtype name in expression or call", N
);
7590 -- For attributes whose argument may be a string, complete
7591 -- resolution of argument now. This avoids premature expansion
7592 -- (and the creation of transient scopes) before the attribute
7593 -- reference is resolved.
7596 when Attribute_Value
=>
7597 Resolve
(First
(Expressions
(N
)), Standard_String
);
7599 when Attribute_Wide_Value
=>
7600 Resolve
(First
(Expressions
(N
)), Standard_Wide_String
);
7602 when Attribute_Wide_Wide_Value
=>
7603 Resolve
(First
(Expressions
(N
)), Standard_Wide_Wide_String
);
7605 when others => null;
7609 -- Normally the Freezing is done by Resolve but sometimes the Prefix
7610 -- is not resolved, in which case the freezing must be done now.
7612 Freeze_Expression
(P
);
7614 -- Finally perform static evaluation on the attribute reference
7617 end Resolve_Attribute
;
7619 --------------------------------
7620 -- Stream_Attribute_Available --
7621 --------------------------------
7623 function Stream_Attribute_Available
7625 Nam
: TSS_Name_Type
;
7626 Partial_View
: Node_Id
:= Empty
) return Boolean
7628 Etyp
: Entity_Id
:= Typ
;
7630 function Has_Specified_Stream_Attribute
7632 Nam
: TSS_Name_Type
) return Boolean;
7633 -- True iff there is a visible attribute definition clause specifying
7634 -- attribute Nam for Typ.
7636 ------------------------------------
7637 -- Has_Specified_Stream_Attribute --
7638 ------------------------------------
7640 function Has_Specified_Stream_Attribute
7642 Nam
: TSS_Name_Type
) return Boolean
7647 (Nam
= TSS_Stream_Input
7648 and then Has_Specified_Stream_Input
(Typ
))
7650 (Nam
= TSS_Stream_Output
7651 and then Has_Specified_Stream_Output
(Typ
))
7653 (Nam
= TSS_Stream_Read
7654 and then Has_Specified_Stream_Read
(Typ
))
7656 (Nam
= TSS_Stream_Write
7657 and then Has_Specified_Stream_Write
(Typ
));
7658 end Has_Specified_Stream_Attribute
;
7660 -- Start of processing for Stream_Attribute_Available
7663 -- We need some comments in this body ???
7665 if Has_Specified_Stream_Attribute
(Typ
, Nam
) then
7669 if Is_Class_Wide_Type
(Typ
) then
7670 return not Is_Limited_Type
(Typ
)
7671 or else Stream_Attribute_Available
(Etype
(Typ
), Nam
);
7674 if Nam
= TSS_Stream_Input
7675 and then Is_Abstract
(Typ
)
7676 and then not Is_Class_Wide_Type
(Typ
)
7681 if not (Is_Limited_Type
(Typ
)
7682 or else (Present
(Partial_View
)
7683 and then Is_Limited_Type
(Partial_View
)))
7688 if Nam
= TSS_Stream_Input
then
7689 return Ada_Version
>= Ada_05
7690 and then Stream_Attribute_Available
(Etyp
, TSS_Stream_Read
);
7691 elsif Nam
= TSS_Stream_Output
then
7692 return Ada_Version
>= Ada_05
7693 and then Stream_Attribute_Available
(Etyp
, TSS_Stream_Write
);
7696 -- Case of Read and Write: check for attribute definition clause that
7697 -- applies to an ancestor type.
7699 while Etype
(Etyp
) /= Etyp
loop
7700 Etyp
:= Etype
(Etyp
);
7702 if Has_Specified_Stream_Attribute
(Etyp
, Nam
) then
7707 if Ada_Version
< Ada_05
then
7709 -- In Ada 95 mode, also consider a non-visible definition
7712 Btyp
: constant Entity_Id
:= Implementation_Base_Type
(Typ
);
7715 and then Stream_Attribute_Available
7716 (Btyp
, Nam
, Partial_View
=> Typ
);
7721 end Stream_Attribute_Available
;