1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
10 -- Copyright (C) 1992-2002, Free Software Foundation, Inc. --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNAT; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
23 -- GNAT was originally developed by the GNAT team at New York University. --
24 -- Extensive contributions were provided by Ada Core Technologies Inc. --
26 ------------------------------------------------------------------------------
28 with Ada
.Characters
.Latin_1
; use Ada
.Characters
.Latin_1
;
30 with Atree
; use Atree
;
31 with Checks
; use Checks
;
32 with Einfo
; use Einfo
;
33 with Errout
; use Errout
;
35 with Exp_Tss
; use Exp_Tss
;
36 with Exp_Util
; use Exp_Util
;
37 with Expander
; use Expander
;
38 with Freeze
; use Freeze
;
39 with Lib
.Xref
; use Lib
.Xref
;
40 with Namet
; use Namet
;
41 with Nlists
; use Nlists
;
42 with Nmake
; use Nmake
;
44 with Restrict
; use Restrict
;
45 with Rtsfind
; use Rtsfind
;
47 with Sem_Cat
; use Sem_Cat
;
48 with Sem_Ch6
; use Sem_Ch6
;
49 with Sem_Ch8
; use Sem_Ch8
;
50 with Sem_Dist
; use Sem_Dist
;
51 with Sem_Eval
; use Sem_Eval
;
52 with Sem_Res
; use Sem_Res
;
53 with Sem_Type
; use Sem_Type
;
54 with Sem_Util
; use Sem_Util
;
55 with Stand
; use Stand
;
56 with Sinfo
; use Sinfo
;
57 with Sinput
; use Sinput
;
58 with Snames
; use Snames
;
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
;
67 with Widechar
; use Widechar
;
69 package body Sem_Attr
is
71 True_Value
: constant Uint
:= Uint_1
;
72 False_Value
: constant Uint
:= Uint_0
;
73 -- Synonyms to be used when these constants are used as Boolean values
75 Bad_Attribute
: exception;
76 -- Exception raised if an error is detected during attribute processing,
77 -- used so that we can abandon the processing so we don't run into
78 -- trouble with cascaded errors.
80 -- The following array is the list of attributes defined in the Ada 83 RM
82 Attribute_83
: Attribute_Class_Array
:= Attribute_Class_Array
'(
88 Attribute_Constrained |
101 Attribute_Leading_Part |
103 Attribute_Machine_Emax |
104 Attribute_Machine_Emin |
105 Attribute_Machine_Mantissa |
106 Attribute_Machine_Overflows |
107 Attribute_Machine_Radix |
108 Attribute_Machine_Rounds |
114 Attribute_Safe_Emax |
115 Attribute_Safe_Large |
116 Attribute_Safe_Small |
119 Attribute_Storage_Size |
121 Attribute_Terminated |
124 Attribute_Width => True,
127 -----------------------
128 -- Local_Subprograms --
129 -----------------------
131 procedure Eval_Attribute (N : Node_Id);
132 -- Performs compile time evaluation of attributes where possible, leaving
133 -- the Is_Static_Expression/Raises_Constraint_Error flags appropriately
134 -- set, and replacing the node with a literal node if the value can be
135 -- computed at compile time. All static attribute references are folded,
136 -- as well as a number of cases of non-static attributes that can always
137 -- be computed at compile time (e.g. floating-point model attributes that
138 -- are applied to non-static subtypes). Of course in such cases, the
139 -- Is_Static_Expression flag will not be set on the resulting literal.
140 -- Note that the only required action of this procedure is to catch the
141 -- static expression cases as described in the RM. Folding of other cases
142 -- is done where convenient, but some additional non-static folding is in
143 -- N_Expand_Attribute_Reference in cases where this is more convenient.
145 function Is_Anonymous_Tagged_Base
149 -- For derived tagged types that constrain parent discriminants we build
150 -- an anonymous unconstrained base type. We need to recognize the relation
151 -- between the two when analyzing an access attribute for a constrained
152 -- component, before the full declaration for Typ has been analyzed, and
153 -- where therefore the prefix of the attribute does not match the enclosing
156 -----------------------
157 -- Analyze_Attribute --
158 -----------------------
160 procedure Analyze_Attribute (N : Node_Id) is
161 Loc : constant Source_Ptr := Sloc (N);
162 Aname : constant Name_Id := Attribute_Name (N);
163 P : constant Node_Id := Prefix (N);
164 Exprs : constant List_Id := Expressions (N);
165 Attr_Id : constant Attribute_Id := Get_Attribute_Id (Aname);
170 -- Type of prefix after analysis
172 P_Base_Type : Entity_Id;
173 -- Base type of prefix after analysis
175 P_Root_Type : Entity_Id;
176 -- Root type of prefix after analysis
178 Unanalyzed : Node_Id;
180 -----------------------
181 -- Local Subprograms --
182 -----------------------
184 procedure Access_Attribute;
185 -- Used for Access, Unchecked_Access, Unrestricted_Access attributes.
186 -- Internally, Id distinguishes which of the three cases is involved.
188 procedure Check_Array_Or_Scalar_Type;
189 -- Common procedure used by First, Last, Range attribute to check
190 -- that the prefix is a constrained array or scalar type, or a name
191 -- of an array object, and that an argument appears only if appropriate
192 -- (i.e. only in the array case).
194 procedure Check_Array_Type;
195 -- Common semantic checks for all array attributes. Checks that the
196 -- prefix is a constrained array type or the name of an array object.
197 -- The error message for non-arrays is specialized appropriately.
199 procedure Check_Asm_Attribute;
200 -- Common semantic checks for Asm_Input and Asm_Output attributes
202 procedure Check_Component;
203 -- Common processing for Bit_Position, First_Bit, Last_Bit, and
204 -- Position. Checks prefix is an appropriate selected component.
206 procedure Check_Decimal_Fixed_Point_Type;
207 -- Check that prefix of attribute N is a decimal fixed-point type
209 procedure Check_Dereference;
210 -- If the prefix of attribute is an object of an access type, then
211 -- introduce an explicit deference, and adjust P_Type accordingly.
213 procedure Check_Discrete_Type;
214 -- Verify that prefix of attribute N is a discrete type
217 -- Check that no attribute arguments are present
219 procedure Check_Either_E0_Or_E1;
220 -- Check that there are zero or one attribute arguments present
223 -- Check that exactly one attribute argument is present
226 -- Check that two attribute arguments are present
228 procedure Check_Enum_Image;
229 -- If the prefix type is an enumeration type, set all its literals
230 -- as referenced, since the image function could possibly end up
231 -- referencing any of the literals indirectly.
233 procedure Check_Fixed_Point_Type;
234 -- Verify that prefix of attribute N is a fixed type
236 procedure Check_Fixed_Point_Type_0;
237 -- Verify that prefix of attribute N is a fixed type and that
238 -- no attribute expressions are present
240 procedure Check_Floating_Point_Type;
241 -- Verify that prefix of attribute N is a float type
243 procedure Check_Floating_Point_Type_0;
244 -- Verify that prefix of attribute N is a float type and that
245 -- no attribute expressions are present
247 procedure Check_Floating_Point_Type_1;
248 -- Verify that prefix of attribute N is a float type and that
249 -- exactly one attribute expression is present
251 procedure Check_Floating_Point_Type_2;
252 -- Verify that prefix of attribute N is a float type and that
253 -- two attribute expressions are present
255 procedure Legal_Formal_Attribute;
256 -- Common processing for attributes Definite, and Has_Discriminants
258 procedure Check_Integer_Type;
259 -- Verify that prefix of attribute N is an integer type
261 procedure Check_Library_Unit;
262 -- Verify that prefix of attribute N is a library unit
264 procedure Check_Not_Incomplete_Type;
265 -- Check that P (the prefix of the attribute) is not an incomplete
266 -- type or a private type for which no full view has been given.
268 procedure Check_Object_Reference (P : Node_Id);
269 -- Check that P (the prefix of the attribute) is an object reference
271 procedure Check_Program_Unit;
272 -- Verify that prefix of attribute N is a program unit
274 procedure Check_Real_Type;
275 -- Verify that prefix of attribute N is fixed or float type
277 procedure Check_Scalar_Type;
278 -- Verify that prefix of attribute N is a scalar type
280 procedure Check_Standard_Prefix;
281 -- Verify that prefix of attribute N is package Standard
283 procedure Check_Stream_Attribute (Nam : Name_Id);
284 -- Validity checking for stream attribute. Nam is the name of the
285 -- corresponding possible defined attribute function (e.g. for the
286 -- Read attribute, Nam will be Name_uRead).
288 procedure Check_Task_Prefix;
289 -- Verify that prefix of attribute N is a task or task type
291 procedure Check_Type;
292 -- Verify that the prefix of attribute N is a type
294 procedure Check_Unit_Name (Nod : Node_Id);
295 -- Check that Nod is of the form of a library unit name, i.e that
296 -- it is an identifier, or a selected component whose prefix is
297 -- itself of the form of a library unit name. Note that this is
298 -- quite different from Check_Program_Unit, since it only checks
299 -- the syntactic form of the name, not the semantic identity. This
300 -- is because it is used with attributes (Elab_Body, Elab_Spec, and
301 -- UET_Address) which can refer to non-visible unit.
303 procedure Error_Attr (Msg : String; Error_Node : Node_Id);
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.
310 procedure Standard_Attribute (Val : Int);
311 -- Used to process attributes whose prefix is package Standard which
312 -- yield values of type Universal_Integer. The attribute reference
313 -- node is rewritten with an integer literal of the given value.
315 procedure Unexpected_Argument (En : Node_Id);
316 -- Signal unexpected attribute argument (En is the argument)
318 procedure Validate_Non_Static_Attribute_Function_Call;
319 -- Called when processing an attribute that is a function call to a
320 -- non-static function, i.e. an attribute function that either takes
321 -- non-scalar arguments or returns a non-scalar result. Verifies that
322 -- such a call does not appear in a preelaborable context.
324 ----------------------
325 -- Access_Attribute --
326 ----------------------
328 procedure Access_Attribute is
329 Acc_Type : Entity_Id;
334 function Build_Access_Object_Type (DT : Entity_Id) return Entity_Id;
335 -- Build an access-to-object type whose designated type is DT,
336 -- and whose Ekind is appropriate to the attribute type. The
337 -- type that is constructed is returned as the result.
339 procedure Build_Access_Subprogram_Type (P : Node_Id);
340 -- Build an access to subprogram whose designated type is
341 -- the type of the prefix. If prefix is overloaded, so it the
342 -- node itself. The result is stored in Acc_Type.
344 ------------------------------
345 -- Build_Access_Object_Type --
346 ------------------------------
348 function Build_Access_Object_Type (DT : Entity_Id) return Entity_Id is
352 if Aname = Name_Unrestricted_Access then
355 (E_Allocator_Type, Current_Scope, Loc, 'A
');
359 (E_Access_Attribute_Type, Current_Scope, Loc, 'A
');
362 Set_Etype (Typ, Typ);
363 Init_Size_Align (Typ);
365 Set_Associated_Node_For_Itype (Typ, N);
366 Set_Directly_Designated_Type (Typ, DT);
368 end Build_Access_Object_Type;
370 ----------------------------------
371 -- Build_Access_Subprogram_Type --
372 ----------------------------------
374 procedure Build_Access_Subprogram_Type (P : Node_Id) is
375 Index : Interp_Index;
378 function Get_Kind (E : Entity_Id) return Entity_Kind;
379 -- Distinguish between access to regular and protected
382 function Get_Kind (E : Entity_Id) return Entity_Kind is
384 if Convention (E) = Convention_Protected then
385 return E_Access_Protected_Subprogram_Type;
387 return E_Access_Subprogram_Type;
391 -- Start of processing for Build_Access_Subprogram_Type
394 if not Is_Overloaded (P) then
397 (Get_Kind (Entity (P)), Current_Scope, Loc, 'A
');
398 Set_Etype (Acc_Type, Acc_Type);
399 Set_Directly_Designated_Type (Acc_Type, Entity (P));
400 Set_Etype (N, Acc_Type);
403 Get_First_Interp (P, Index, It);
404 Set_Etype (N, Any_Type);
406 while Present (It.Nam) loop
408 if not Is_Intrinsic_Subprogram (It.Nam) then
411 (Get_Kind (It.Nam), Current_Scope, Loc, 'A
');
412 Set_Etype (Acc_Type, Acc_Type);
413 Set_Directly_Designated_Type (Acc_Type, It.Nam);
414 Add_One_Interp (N, Acc_Type, Acc_Type);
417 Get_Next_Interp (Index, It);
420 if Etype (N) = Any_Type then
421 Error_Attr ("prefix of % attribute cannot be intrinsic", P);
424 end Build_Access_Subprogram_Type;
426 -- Start of processing for Access_Attribute
431 if Nkind (P) = N_Character_Literal then
433 ("prefix of % attribute cannot be enumeration literal", P);
435 -- In the case of an access to subprogram, use the name of the
436 -- subprogram itself as the designated type. Type-checking in
437 -- this case compares the signatures of the designated types.
439 elsif Is_Entity_Name (P)
440 and then Is_Overloadable (Entity (P))
442 if not Is_Library_Level_Entity (Entity (P)) then
443 Check_Restriction (No_Implicit_Dynamic_Code, P);
446 Build_Access_Subprogram_Type (P);
449 -- Component is an operation of a protected type.
451 elsif (Nkind (P) = N_Selected_Component
452 and then Is_Overloadable (Entity (Selector_Name (P))))
454 if Ekind (Entity (Selector_Name (P))) = E_Entry then
455 Error_Attr ("prefix of % attribute must be subprogram", P);
458 Build_Access_Subprogram_Type (Selector_Name (P));
462 -- Deal with incorrect reference to a type, but note that some
463 -- accesses are allowed (references to the current type instance).
465 if Is_Entity_Name (P) then
466 Scop := Current_Scope;
469 if Is_Type (Typ) then
471 -- OK if we are within the scope of a limited type
472 -- let's mark the component as having per object constraint
474 if Is_Anonymous_Tagged_Base (Scop, Typ) then
482 Q : Node_Id := Parent (N);
486 and then Nkind (Q) /= N_Component_Declaration
491 Set_Has_Per_Object_Constraint (
492 Defining_Identifier (Q), True);
496 if Nkind (P) = N_Expanded_Name then
498 ("current instance prefix must be a direct name", P);
501 -- If a current instance attribute appears within a
502 -- a component constraint it must appear alone; other
503 -- contexts (default expressions, within a task body)
504 -- are not subject to this restriction.
506 if not In_Default_Expression
507 and then not Has_Completion (Scop)
509 Nkind (Parent (N)) /= N_Discriminant_Association
511 Nkind (Parent (N)) /= N_Index_Or_Discriminant_Constraint
514 ("current instance attribute must appear alone", N);
517 -- OK if we are in initialization procedure for the type
518 -- in question, in which case the reference to the type
519 -- is rewritten as a reference to the current object.
521 elsif Ekind (Scop) = E_Procedure
522 and then Chars (Scop) = Name_uInit_Proc
523 and then Etype (First_Formal (Scop)) = Typ
526 Make_Attribute_Reference (Loc,
527 Prefix => Make_Identifier (Loc, Name_uInit),
528 Attribute_Name => Name_Unrestricted_Access));
532 -- OK if a task type, this test needs sharpening up ???
534 elsif Is_Task_Type (Typ) then
537 -- Otherwise we have an error case
540 Error_Attr ("% attribute cannot be applied to type", P);
546 -- If we fall through, we have a normal access to object case.
547 -- Unrestricted_Access is legal wherever an allocator would be
548 -- legal, so its Etype is set to E_Allocator. The expected type
549 -- of the other attributes is a general access type, and therefore
550 -- we label them with E_Access_Attribute_Type.
552 if not Is_Overloaded (P) then
553 Acc_Type := Build_Access_Object_Type (P_Type);
554 Set_Etype (N, Acc_Type);
557 Index : Interp_Index;
561 Set_Etype (N, Any_Type);
562 Get_First_Interp (P, Index, It);
564 while Present (It.Typ) loop
565 Acc_Type := Build_Access_Object_Type (It.Typ);
566 Add_One_Interp (N, Acc_Type, Acc_Type);
567 Get_Next_Interp (Index, It);
572 -- Check for aliased view unless unrestricted case. We allow
573 -- a nonaliased prefix when within an instance because the
574 -- prefix may have been a tagged formal object, which is
575 -- defined to be aliased even when the actual might not be
576 -- (other instance cases will have been caught in the generic).
578 if Aname /= Name_Unrestricted_Access
579 and then not Is_Aliased_View (P)
580 and then not In_Instance
582 Error_Attr ("prefix of % attribute must be aliased", P);
585 end Access_Attribute;
587 --------------------------------
588 -- Check_Array_Or_Scalar_Type --
589 --------------------------------
591 procedure Check_Array_Or_Scalar_Type is
595 -- Dimension number for array attributes.
598 -- Case of string literal or string literal subtype. These cases
599 -- cannot arise from legal Ada code, but the expander is allowed
600 -- to generate them. They require special handling because string
601 -- literal subtypes do not have standard bounds (the whole idea
602 -- of these subtypes is to avoid having to generate the bounds)
604 if Ekind (P_Type) = E_String_Literal_Subtype then
605 Set_Etype (N, Etype (First_Index (P_Base_Type)));
610 elsif Is_Scalar_Type (P_Type) then
614 Error_Attr ("invalid argument in % attribute", E1);
616 Set_Etype (N, P_Base_Type);
620 -- The following is a special test to allow 'First to apply to
621 -- private scalar types if the attribute comes from generated
622 -- code. This occurs in the case of Normalize_Scalars code.
624 elsif Is_Private_Type
(P_Type
)
625 and then Present
(Full_View
(P_Type
))
626 and then Is_Scalar_Type
(Full_View
(P_Type
))
627 and then not Comes_From_Source
(N
)
629 Set_Etype
(N
, Implementation_Base_Type
(P_Type
));
631 -- Array types other than string literal subtypes handled above
636 -- We know prefix is an array type, or the name of an array
637 -- object, and that the expression, if present, is static
638 -- and within the range of the dimensions of the type.
640 if Is_Array_Type
(P_Type
) then
641 Index
:= First_Index
(P_Base_Type
);
643 else pragma Assert
(Is_Access_Type
(P_Type
));
644 Index
:= First_Index
(Base_Type
(Designated_Type
(P_Type
)));
649 -- First dimension assumed
651 Set_Etype
(N
, Base_Type
(Etype
(Index
)));
654 D
:= UI_To_Int
(Intval
(E1
));
656 for J
in 1 .. D
- 1 loop
660 Set_Etype
(N
, Base_Type
(Etype
(Index
)));
661 Set_Etype
(E1
, Standard_Integer
);
664 end Check_Array_Or_Scalar_Type
;
666 ----------------------
667 -- Check_Array_Type --
668 ----------------------
670 procedure Check_Array_Type
is
672 -- Dimension number for array attributes.
675 -- If the type is a string literal type, then this must be generated
676 -- internally, and no further check is required on its legality.
678 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
681 -- If the type is a composite, it is an illegal aggregate, no point
684 elsif P_Type
= Any_Composite
then
688 -- Normal case of array type or subtype
690 Check_Either_E0_Or_E1
;
692 if Is_Array_Type
(P_Type
) then
693 if not Is_Constrained
(P_Type
)
694 and then Is_Entity_Name
(P
)
695 and then Is_Type
(Entity
(P
))
697 -- Note: we do not call Error_Attr here, since we prefer to
698 -- continue, using the relevant index type of the array,
699 -- even though it is unconstrained. This gives better error
700 -- recovery behavior.
702 Error_Msg_Name_1
:= Aname
;
704 ("prefix for % attribute must be constrained array", P
);
707 D
:= Number_Dimensions
(P_Type
);
709 elsif Is_Access_Type
(P_Type
)
710 and then Is_Array_Type
(Designated_Type
(P_Type
))
712 if Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)) then
713 Error_Attr
("prefix of % attribute cannot be access type", P
);
716 D
:= Number_Dimensions
(Designated_Type
(P_Type
));
718 -- If there is an implicit dereference, then we must freeze
719 -- the designated type of the access type, since the type of
720 -- the referenced array is this type (see AI95-00106).
722 Freeze_Before
(N
, Designated_Type
(P_Type
));
725 if Is_Private_Type
(P_Type
) then
727 ("prefix for % attribute may not be private type", P
);
729 elsif Attr_Id
= Attribute_First
731 Attr_Id
= Attribute_Last
733 Error_Attr
("invalid prefix for % attribute", P
);
736 Error_Attr
("prefix for % attribute must be array", P
);
741 Resolve
(E1
, Any_Integer
);
742 Set_Etype
(E1
, Standard_Integer
);
744 if not Is_Static_Expression
(E1
)
745 or else Raises_Constraint_Error
(E1
)
747 Error_Attr
("expression for dimension must be static", E1
);
749 elsif UI_To_Int
(Expr_Value
(E1
)) > D
750 or else UI_To_Int
(Expr_Value
(E1
)) < 1
752 Error_Attr
("invalid dimension number for array type", E1
);
755 end Check_Array_Type
;
757 -------------------------
758 -- Check_Asm_Attribute --
759 -------------------------
761 procedure Check_Asm_Attribute
is
766 -- Check first argument is static string expression
768 Analyze_And_Resolve
(E1
, Standard_String
);
770 if Etype
(E1
) = Any_Type
then
773 elsif not Is_OK_Static_Expression
(E1
) then
775 ("constraint argument must be static string expression", E1
);
778 -- Check second argument is right type
780 Analyze_And_Resolve
(E2
, Entity
(P
));
782 -- Note: that is all we need to do, we don't need to check
783 -- that it appears in a correct context. The Ada type system
784 -- will do that for us.
786 end Check_Asm_Attribute
;
788 ---------------------
789 -- Check_Component --
790 ---------------------
792 procedure Check_Component
is
796 if Nkind
(P
) /= N_Selected_Component
798 (Ekind
(Entity
(Selector_Name
(P
))) /= E_Component
800 Ekind
(Entity
(Selector_Name
(P
))) /= E_Discriminant
)
803 ("prefix for % attribute must be selected component", P
);
807 ------------------------------------
808 -- Check_Decimal_Fixed_Point_Type --
809 ------------------------------------
811 procedure Check_Decimal_Fixed_Point_Type
is
815 if not Is_Decimal_Fixed_Point_Type
(P_Type
) then
817 ("prefix of % attribute must be decimal type", P
);
819 end Check_Decimal_Fixed_Point_Type
;
821 -----------------------
822 -- Check_Dereference --
823 -----------------------
825 procedure Check_Dereference
is
827 if Is_Object_Reference
(P
)
828 and then Is_Access_Type
(P_Type
)
831 Make_Explicit_Dereference
(Sloc
(P
),
832 Prefix
=> Relocate_Node
(P
)));
834 Analyze_And_Resolve
(P
);
837 if P_Type
= Any_Type
then
841 P_Base_Type
:= Base_Type
(P_Type
);
842 P_Root_Type
:= Root_Type
(P_Base_Type
);
844 end Check_Dereference
;
846 -------------------------
847 -- Check_Discrete_Type --
848 -------------------------
850 procedure Check_Discrete_Type
is
854 if not Is_Discrete_Type
(P_Type
) then
855 Error_Attr
("prefix of % attribute must be discrete type", P
);
857 end Check_Discrete_Type
;
863 procedure Check_E0
is
866 Unexpected_Argument
(E1
);
874 procedure Check_E1
is
876 Check_Either_E0_Or_E1
;
880 -- Special-case attributes that are functions and that appear as
881 -- the prefix of another attribute. Error is posted on parent.
883 if Nkind
(Parent
(N
)) = N_Attribute_Reference
884 and then (Attribute_Name
(Parent
(N
)) = Name_Address
886 Attribute_Name
(Parent
(N
)) = Name_Code_Address
888 Attribute_Name
(Parent
(N
)) = Name_Access
)
890 Error_Msg_Name_1
:= Attribute_Name
(Parent
(N
));
891 Error_Msg_N
("illegal prefix for % attribute", Parent
(N
));
892 Set_Etype
(Parent
(N
), Any_Type
);
893 Set_Entity
(Parent
(N
), Any_Type
);
897 Error_Attr
("missing argument for % attribute", N
);
906 procedure Check_E2
is
909 Error_Attr
("missing arguments for % attribute (2 required)", N
);
911 Error_Attr
("missing argument for % attribute (2 required)", N
);
915 ---------------------------
916 -- Check_Either_E0_Or_E1 --
917 ---------------------------
919 procedure Check_Either_E0_Or_E1
is
922 Unexpected_Argument
(E2
);
924 end Check_Either_E0_Or_E1
;
926 ----------------------
927 -- Check_Enum_Image --
928 ----------------------
930 procedure Check_Enum_Image
is
934 if Is_Enumeration_Type
(P_Base_Type
) then
935 Lit
:= First_Literal
(P_Base_Type
);
936 while Present
(Lit
) loop
937 Set_Referenced
(Lit
);
941 end Check_Enum_Image
;
943 ----------------------------
944 -- Check_Fixed_Point_Type --
945 ----------------------------
947 procedure Check_Fixed_Point_Type
is
951 if not Is_Fixed_Point_Type
(P_Type
) then
952 Error_Attr
("prefix of % attribute must be fixed point type", P
);
954 end Check_Fixed_Point_Type
;
956 ------------------------------
957 -- Check_Fixed_Point_Type_0 --
958 ------------------------------
960 procedure Check_Fixed_Point_Type_0
is
962 Check_Fixed_Point_Type
;
964 end Check_Fixed_Point_Type_0
;
966 -------------------------------
967 -- Check_Floating_Point_Type --
968 -------------------------------
970 procedure Check_Floating_Point_Type
is
974 if not Is_Floating_Point_Type
(P_Type
) then
975 Error_Attr
("prefix of % attribute must be float type", P
);
977 end Check_Floating_Point_Type
;
979 ---------------------------------
980 -- Check_Floating_Point_Type_0 --
981 ---------------------------------
983 procedure Check_Floating_Point_Type_0
is
985 Check_Floating_Point_Type
;
987 end Check_Floating_Point_Type_0
;
989 ---------------------------------
990 -- Check_Floating_Point_Type_1 --
991 ---------------------------------
993 procedure Check_Floating_Point_Type_1
is
995 Check_Floating_Point_Type
;
997 end Check_Floating_Point_Type_1
;
999 ---------------------------------
1000 -- Check_Floating_Point_Type_2 --
1001 ---------------------------------
1003 procedure Check_Floating_Point_Type_2
is
1005 Check_Floating_Point_Type
;
1007 end Check_Floating_Point_Type_2
;
1009 ------------------------
1010 -- Check_Integer_Type --
1011 ------------------------
1013 procedure Check_Integer_Type
is
1017 if not Is_Integer_Type
(P_Type
) then
1018 Error_Attr
("prefix of % attribute must be integer type", P
);
1020 end Check_Integer_Type
;
1022 ------------------------
1023 -- Check_Library_Unit --
1024 ------------------------
1026 procedure Check_Library_Unit
is
1028 if not Is_Compilation_Unit
(Entity
(P
)) then
1029 Error_Attr
("prefix of % attribute must be library unit", P
);
1031 end Check_Library_Unit
;
1033 -------------------------------
1034 -- Check_Not_Incomplete_Type --
1035 -------------------------------
1037 procedure Check_Not_Incomplete_Type
is
1039 if not Is_Entity_Name
(P
)
1040 or else not Is_Type
(Entity
(P
))
1041 or else In_Default_Expression
1046 Check_Fully_Declared
(P_Type
, P
);
1048 end Check_Not_Incomplete_Type
;
1050 ----------------------------
1051 -- Check_Object_Reference --
1052 ----------------------------
1054 procedure Check_Object_Reference
(P
: Node_Id
) is
1058 -- If we need an object, and we have a prefix that is the name of
1059 -- a function entity, convert it into a function call.
1061 if Is_Entity_Name
(P
)
1062 and then Ekind
(Entity
(P
)) = E_Function
1064 Rtyp
:= Etype
(Entity
(P
));
1067 Make_Function_Call
(Sloc
(P
),
1068 Name
=> Relocate_Node
(P
)));
1070 Analyze_And_Resolve
(P
, Rtyp
);
1072 -- Otherwise we must have an object reference
1074 elsif not Is_Object_Reference
(P
) then
1075 Error_Attr
("prefix of % attribute must be object", P
);
1077 end Check_Object_Reference
;
1079 ------------------------
1080 -- Check_Program_Unit --
1081 ------------------------
1083 procedure Check_Program_Unit
is
1085 if Is_Entity_Name
(P
) then
1087 K
: constant Entity_Kind
:= Ekind
(Entity
(P
));
1088 T
: constant Entity_Id
:= Etype
(Entity
(P
));
1091 if K
in Subprogram_Kind
1092 or else K
in Task_Kind
1093 or else K
in Protected_Kind
1094 or else K
= E_Package
1095 or else K
in Generic_Unit_Kind
1096 or else (K
= E_Variable
1100 Is_Protected_Type
(T
)))
1107 Error_Attr
("prefix of % attribute must be program unit", P
);
1108 end Check_Program_Unit
;
1110 ---------------------
1111 -- Check_Real_Type --
1112 ---------------------
1114 procedure Check_Real_Type
is
1118 if not Is_Real_Type
(P_Type
) then
1119 Error_Attr
("prefix of % attribute must be real type", P
);
1121 end Check_Real_Type
;
1123 -----------------------
1124 -- Check_Scalar_Type --
1125 -----------------------
1127 procedure Check_Scalar_Type
is
1131 if not Is_Scalar_Type
(P_Type
) then
1132 Error_Attr
("prefix of % attribute must be scalar type", P
);
1134 end Check_Scalar_Type
;
1136 ---------------------------
1137 -- Check_Standard_Prefix --
1138 ---------------------------
1140 procedure Check_Standard_Prefix
is
1144 if Nkind
(P
) /= N_Identifier
1145 or else Chars
(P
) /= Name_Standard
1147 Error_Attr
("only allowed prefix for % attribute is Standard", P
);
1150 end Check_Standard_Prefix
;
1152 ----------------------------
1153 -- Check_Stream_Attribute --
1154 ----------------------------
1156 procedure Check_Stream_Attribute
(Nam
: Name_Id
) is
1161 Validate_Non_Static_Attribute_Function_Call
;
1163 -- With the exception of 'Input, Stream attributes are procedures,
1164 -- and can only appear at the position of procedure calls. We check
1165 -- for this here, before they are rewritten, to give a more precise
1168 if Nam
= Name_uInput
then
1171 elsif Is_List_Member
(N
)
1172 and then Nkind
(Parent
(N
)) /= N_Procedure_Call_Statement
1173 and then Nkind
(Parent
(N
)) /= N_Aggregate
1179 ("invalid context for attribute %, which is a procedure", N
);
1183 Btyp
:= Implementation_Base_Type
(P_Type
);
1185 -- Stream attributes not allowed on limited types unless the
1186 -- special OK_For_Stream flag is set.
1188 if Is_Limited_Type
(P_Type
)
1189 and then Comes_From_Source
(N
)
1190 and then not Present
(TSS
(Btyp
, Nam
))
1191 and then No
(Get_Rep_Pragma
(Btyp
, Name_Stream_Convert
))
1193 -- Special case the message if we are compiling the stub version
1194 -- of a remote operation. One error on the type is sufficient.
1196 if (Is_Remote_Types
(Current_Scope
)
1197 or else Is_Remote_Call_Interface
(Current_Scope
))
1198 and then not Error_Posted
(Btyp
)
1200 Error_Msg_Node_2
:= Current_Scope
;
1202 ("limited type& used in& has no stream attributes", P
, Btyp
);
1203 Set_Error_Posted
(Btyp
);
1205 elsif not Error_Posted
(Btyp
) then
1207 ("limited type& has no stream attributes", P
, Btyp
);
1211 -- Here we must check that the first argument is an access type
1212 -- that is compatible with Ada.Streams.Root_Stream_Type'Class.
1214 Analyze_And_Resolve
(E1
);
1217 -- Note: the double call to Root_Type here is needed because the
1218 -- root type of a class-wide type is the corresponding type (e.g.
1219 -- X for X'Class, and we really want to go to the root.
1221 if not Is_Access_Type
(Etyp
)
1222 or else Root_Type
(Root_Type
(Designated_Type
(Etyp
))) /=
1223 RTE
(RE_Root_Stream_Type
)
1226 ("expected access to Ada.Streams.Root_Stream_Type''Class", E1
);
1229 -- Check that the second argument is of the right type if there is
1230 -- one (the Input attribute has only one argument so this is skipped)
1232 if Present
(E2
) then
1236 and then not Is_OK_Variable_For_Out_Formal
(E2
)
1239 ("second argument of % attribute must be a variable", E2
);
1242 Resolve
(E2
, P_Type
);
1244 end Check_Stream_Attribute
;
1246 -----------------------
1247 -- Check_Task_Prefix --
1248 -----------------------
1250 procedure Check_Task_Prefix
is
1254 if Is_Task_Type
(Etype
(P
))
1255 or else (Is_Access_Type
(Etype
(P
))
1256 and then Is_Task_Type
(Designated_Type
(Etype
(P
))))
1258 Resolve
(P
, Etype
(P
));
1260 Error_Attr
("prefix of % attribute must be a task", P
);
1262 end Check_Task_Prefix
;
1268 -- The possibilities are an entity name denoting a type, or an
1269 -- attribute reference that denotes a type (Base or Class). If
1270 -- the type is incomplete, replace it with its full view.
1272 procedure Check_Type
is
1274 if not Is_Entity_Name
(P
)
1275 or else not Is_Type
(Entity
(P
))
1277 Error_Attr
("prefix of % attribute must be a type", P
);
1279 elsif Ekind
(Entity
(P
)) = E_Incomplete_Type
1280 and then Present
(Full_View
(Entity
(P
)))
1282 P_Type
:= Full_View
(Entity
(P
));
1283 Set_Entity
(P
, P_Type
);
1287 ---------------------
1288 -- Check_Unit_Name --
1289 ---------------------
1291 procedure Check_Unit_Name
(Nod
: Node_Id
) is
1293 if Nkind
(Nod
) = N_Identifier
then
1296 elsif Nkind
(Nod
) = N_Selected_Component
then
1297 Check_Unit_Name
(Prefix
(Nod
));
1299 if Nkind
(Selector_Name
(Nod
)) = N_Identifier
then
1304 Error_Attr
("argument for % attribute must be unit name", P
);
1305 end Check_Unit_Name
;
1311 procedure Error_Attr
(Msg
: String; Error_Node
: Node_Id
) is
1313 Error_Msg_Name_1
:= Aname
;
1314 Error_Msg_N
(Msg
, Error_Node
);
1315 Set_Etype
(N
, Any_Type
);
1316 Set_Entity
(N
, Any_Type
);
1317 raise Bad_Attribute
;
1320 ----------------------------
1321 -- Legal_Formal_Attribute --
1322 ----------------------------
1324 procedure Legal_Formal_Attribute
is
1328 if not Is_Entity_Name
(P
)
1329 or else not Is_Type
(Entity
(P
))
1331 Error_Attr
("prefix of % attribute must be generic type", N
);
1333 elsif Is_Generic_Actual_Type
(Entity
(P
))
1338 elsif Is_Generic_Type
(Entity
(P
)) then
1339 if not Is_Indefinite_Subtype
(Entity
(P
)) then
1341 ("prefix of % attribute must be indefinite generic type", N
);
1346 ("prefix of % attribute must be indefinite generic type", N
);
1349 Set_Etype
(N
, Standard_Boolean
);
1350 end Legal_Formal_Attribute
;
1352 ------------------------
1353 -- Standard_Attribute --
1354 ------------------------
1356 procedure Standard_Attribute
(Val
: Int
) is
1358 Check_Standard_Prefix
;
1360 Make_Integer_Literal
(Loc
, Val
));
1362 end Standard_Attribute
;
1364 -------------------------
1365 -- Unexpected Argument --
1366 -------------------------
1368 procedure Unexpected_Argument
(En
: Node_Id
) is
1370 Error_Attr
("unexpected argument for % attribute", En
);
1371 end Unexpected_Argument
;
1373 -------------------------------------------------
1374 -- Validate_Non_Static_Attribute_Function_Call --
1375 -------------------------------------------------
1377 -- This function should be moved to Sem_Dist ???
1379 procedure Validate_Non_Static_Attribute_Function_Call
is
1381 if In_Preelaborated_Unit
1382 and then not In_Subprogram_Or_Concurrent_Unit
1384 Error_Msg_N
("non-static function call in preelaborated unit", N
);
1386 end Validate_Non_Static_Attribute_Function_Call
;
1388 -----------------------------------------------
1389 -- Start of Processing for Analyze_Attribute --
1390 -----------------------------------------------
1393 -- Immediate return if unrecognized attribute (already diagnosed
1394 -- by parser, so there is nothing more that we need to do)
1396 if not Is_Attribute_Name
(Aname
) then
1397 raise Bad_Attribute
;
1400 -- Deal with Ada 83 and Features issues
1402 if not Attribute_83
(Attr_Id
) then
1403 if Ada_83
and then Comes_From_Source
(N
) then
1404 Error_Msg_Name_1
:= Aname
;
1405 Error_Msg_N
("(Ada 83) attribute% is not standard?", N
);
1408 if Attribute_Impl_Def
(Attr_Id
) then
1409 Check_Restriction
(No_Implementation_Attributes
, N
);
1413 -- Remote access to subprogram type access attribute reference needs
1414 -- unanalyzed copy for tree transformation. The analyzed copy is used
1415 -- for its semantic information (whether prefix is a remote subprogram
1416 -- name), the unanalyzed copy is used to construct new subtree rooted
1417 -- with N_aggregate which represents a fat pointer aggregate.
1419 if Aname
= Name_Access
then
1420 Unanalyzed
:= Copy_Separate_Tree
(N
);
1423 -- Analyze prefix and exit if error in analysis. If the prefix is an
1424 -- incomplete type, use full view if available. A special case is
1425 -- that we never analyze the prefix of an Elab_Body or Elab_Spec
1426 -- or UET_Address attribute.
1428 if Aname
/= Name_Elab_Body
1430 Aname
/= Name_Elab_Spec
1432 Aname
/= Name_UET_Address
1435 P_Type
:= Etype
(P
);
1437 if Is_Entity_Name
(P
)
1438 and then Present
(Entity
(P
))
1439 and then Is_Type
(Entity
(P
))
1440 and then Ekind
(Entity
(P
)) = E_Incomplete_Type
1442 P_Type
:= Get_Full_View
(P_Type
);
1443 Set_Entity
(P
, P_Type
);
1444 Set_Etype
(P
, P_Type
);
1447 if P_Type
= Any_Type
then
1448 raise Bad_Attribute
;
1451 P_Base_Type
:= Base_Type
(P_Type
);
1452 P_Root_Type
:= Root_Type
(P_Base_Type
);
1455 -- Analyze expressions that may be present, exiting if an error occurs
1462 E1
:= First
(Exprs
);
1465 -- Check for missing or bad expression (result of previous error)
1467 if No
(E1
) or else Etype
(E1
) = Any_Type
then
1468 raise Bad_Attribute
;
1473 if Present
(E2
) then
1476 if Etype
(E2
) = Any_Type
then
1477 raise Bad_Attribute
;
1480 if Present
(Next
(E2
)) then
1481 Unexpected_Argument
(Next
(E2
));
1486 if Is_Overloaded
(P
)
1487 and then Aname
/= Name_Access
1488 and then Aname
/= Name_Address
1489 and then Aname
/= Name_Code_Address
1490 and then Aname
/= Name_Count
1491 and then Aname
/= Name_Unchecked_Access
1493 Error_Attr
("ambiguous prefix for % attribute", P
);
1496 -- Remaining processing depends on attribute
1504 when Attribute_Abort_Signal
=>
1505 Check_Standard_Prefix
;
1507 New_Reference_To
(Stand
.Abort_Signal
, Loc
));
1514 when Attribute_Access
=>
1521 when Attribute_Address
=>
1524 -- Check for some junk cases, where we have to allow the address
1525 -- attribute but it does not make much sense, so at least for now
1526 -- just replace with Null_Address.
1528 -- We also do this if the prefix is a reference to the AST_Entry
1529 -- attribute. If expansion is active, the attribute will be
1530 -- replaced by a function call, and address will work fine and
1531 -- get the proper value, but if expansion is not active, then
1532 -- the check here allows proper semantic analysis of the reference.
1534 -- An Address attribute created by expansion is legal even when it
1535 -- applies to other entity-denoting expressions.
1537 if (Is_Entity_Name
(P
)) then
1538 if Is_Subprogram
(Entity
(P
)) then
1539 if not Is_Library_Level_Entity
(Entity
(P
)) then
1540 Check_Restriction
(No_Implicit_Dynamic_Code
, P
);
1543 Set_Address_Taken
(Entity
(P
));
1545 elsif Is_Object
(Entity
(P
))
1546 or else Ekind
(Entity
(P
)) = E_Label
1548 Set_Address_Taken
(Entity
(P
));
1550 elsif (Is_Concurrent_Type
(Etype
(Entity
(P
)))
1551 and then Etype
(Entity
(P
)) = Base_Type
(Entity
(P
)))
1552 or else Ekind
(Entity
(P
)) = E_Package
1553 or else Is_Generic_Unit
(Entity
(P
))
1556 New_Occurrence_Of
(RTE
(RE_Null_Address
), Sloc
(N
)));
1559 Error_Attr
("invalid prefix for % attribute", P
);
1562 elsif Nkind
(P
) = N_Attribute_Reference
1563 and then Attribute_Name
(P
) = Name_AST_Entry
1566 New_Occurrence_Of
(RTE
(RE_Null_Address
), Sloc
(N
)));
1568 elsif Is_Object_Reference
(P
) then
1571 elsif Nkind
(P
) = N_Selected_Component
1572 and then Is_Subprogram
(Entity
(Selector_Name
(P
)))
1576 elsif not Comes_From_Source
(N
) then
1580 Error_Attr
("invalid prefix for % attribute", P
);
1583 Set_Etype
(N
, RTE
(RE_Address
));
1589 when Attribute_Address_Size
=>
1590 Standard_Attribute
(System_Address_Size
);
1596 when Attribute_Adjacent
=>
1597 Check_Floating_Point_Type_2
;
1598 Set_Etype
(N
, P_Base_Type
);
1599 Resolve
(E1
, P_Base_Type
);
1600 Resolve
(E2
, P_Base_Type
);
1606 when Attribute_Aft
=>
1607 Check_Fixed_Point_Type_0
;
1608 Set_Etype
(N
, Universal_Integer
);
1614 when Attribute_Alignment
=>
1616 -- Don't we need more checking here, cf Size ???
1619 Check_Not_Incomplete_Type
;
1620 Set_Etype
(N
, Universal_Integer
);
1626 when Attribute_Asm_Input
=>
1627 Check_Asm_Attribute
;
1628 Set_Etype
(N
, RTE
(RE_Asm_Input_Operand
));
1634 when Attribute_Asm_Output
=>
1635 Check_Asm_Attribute
;
1637 if Etype
(E2
) = Any_Type
then
1640 elsif Aname
= Name_Asm_Output
then
1641 if not Is_Variable
(E2
) then
1643 ("second argument for Asm_Output is not variable", E2
);
1647 Note_Possible_Modification
(E2
);
1648 Set_Etype
(N
, RTE
(RE_Asm_Output_Operand
));
1654 when Attribute_AST_Entry
=> AST_Entry
: declare
1660 -- Indicates if entry family index is present. Note the coding
1661 -- here handles the entry family case, but in fact it cannot be
1662 -- executed currently, because pragma AST_Entry does not permit
1663 -- the specification of an entry family.
1665 procedure Bad_AST_Entry
;
1666 -- Signal a bad AST_Entry pragma
1668 function OK_Entry
(E
: Entity_Id
) return Boolean;
1669 -- Checks that E is of an appropriate entity kind for an entry
1670 -- (i.e. E_Entry if Index is False, or E_Entry_Family if Index
1671 -- is set True for the entry family case). In the True case,
1672 -- makes sure that Is_AST_Entry is set on the entry.
1674 procedure Bad_AST_Entry
is
1676 Error_Attr
("prefix for % attribute must be task entry", P
);
1679 function OK_Entry
(E
: Entity_Id
) return Boolean is
1684 Result
:= (Ekind
(E
) = E_Entry_Family
);
1686 Result
:= (Ekind
(E
) = E_Entry
);
1690 if not Is_AST_Entry
(E
) then
1691 Error_Msg_Name_2
:= Aname
;
1693 ("% attribute requires previous % pragma", P
);
1700 -- Start of processing for AST_Entry
1706 -- Deal with entry family case
1708 if Nkind
(P
) = N_Indexed_Component
then
1716 Ptyp
:= Etype
(Pref
);
1718 if Ptyp
= Any_Type
or else Error_Posted
(Pref
) then
1722 -- If the prefix is a selected component whose prefix is of an
1723 -- access type, then introduce an explicit dereference.
1725 if Nkind
(Pref
) = N_Selected_Component
1726 and then Is_Access_Type
(Ptyp
)
1729 Make_Explicit_Dereference
(Sloc
(Pref
),
1730 Relocate_Node
(Pref
)));
1731 Analyze_And_Resolve
(Pref
, Designated_Type
(Ptyp
));
1734 -- Prefix can be of the form a.b, where a is a task object
1735 -- and b is one of the entries of the corresponding task type.
1737 if Nkind
(Pref
) = N_Selected_Component
1738 and then OK_Entry
(Entity
(Selector_Name
(Pref
)))
1739 and then Is_Object_Reference
(Prefix
(Pref
))
1740 and then Is_Task_Type
(Etype
(Prefix
(Pref
)))
1744 -- Otherwise the prefix must be an entry of a containing task,
1745 -- or of a variable of the enclosing task type.
1748 if Nkind
(Pref
) = N_Identifier
1749 or else Nkind
(Pref
) = N_Expanded_Name
1751 Ent
:= Entity
(Pref
);
1753 if not OK_Entry
(Ent
)
1754 or else not In_Open_Scopes
(Scope
(Ent
))
1764 Set_Etype
(N
, RTE
(RE_AST_Handler
));
1771 when Attribute_Base
=> Base
: declare
1775 Check_Either_E0_Or_E1
;
1779 if Sloc
(Typ
) = Standard_Location
1780 and then Base_Type
(Typ
) = Typ
1781 and then Warn_On_Redundant_Constructs
1784 ("?redudant attribute, & is its own base type", N
, Typ
);
1787 Set_Etype
(N
, Base_Type
(Entity
(P
)));
1789 -- If we have an expression present, then really this is a conversion
1790 -- and the tree must be reformed. Note that this is one of the cases
1791 -- in which we do a replace rather than a rewrite, because the
1792 -- original tree is junk.
1794 if Present
(E1
) then
1796 Make_Type_Conversion
(Loc
,
1798 Make_Attribute_Reference
(Loc
,
1799 Prefix
=> Prefix
(N
),
1800 Attribute_Name
=> Name_Base
),
1801 Expression
=> Relocate_Node
(E1
)));
1803 -- E1 may be overloaded, and its interpretations preserved.
1805 Save_Interps
(E1
, Expression
(N
));
1808 -- For other cases, set the proper type as the entity of the
1809 -- attribute reference, and then rewrite the node to be an
1810 -- occurrence of the referenced base type. This way, no one
1811 -- else in the compiler has to worry about the base attribute.
1814 Set_Entity
(N
, Base_Type
(Entity
(P
)));
1816 New_Reference_To
(Entity
(N
), Loc
));
1825 when Attribute_Bit
=> Bit
:
1829 if not Is_Object_Reference
(P
) then
1830 Error_Attr
("prefix for % attribute must be object", P
);
1832 -- What about the access object cases ???
1838 Set_Etype
(N
, Universal_Integer
);
1845 when Attribute_Bit_Order
=> Bit_Order
:
1850 if not Is_Record_Type
(P_Type
) then
1851 Error_Attr
("prefix of % attribute must be record type", P
);
1854 if Bytes_Big_Endian
xor Reverse_Bit_Order
(P_Type
) then
1856 New_Occurrence_Of
(RTE
(RE_High_Order_First
), Loc
));
1859 New_Occurrence_Of
(RTE
(RE_Low_Order_First
), Loc
));
1862 Set_Etype
(N
, RTE
(RE_Bit_Order
));
1863 Resolve
(N
, Etype
(N
));
1865 -- Reset incorrect indication of staticness
1867 Set_Is_Static_Expression
(N
, False);
1874 -- Note: in generated code, we can have a Bit_Position attribute
1875 -- applied to a (naked) record component (i.e. the prefix is an
1876 -- identifier that references an E_Component or E_Discriminant
1877 -- entity directly, and this is interpreted as expected by Gigi.
1878 -- The following code will not tolerate such usage, but when the
1879 -- expander creates this special case, it marks it as analyzed
1880 -- immediately and sets an appropriate type.
1882 when Attribute_Bit_Position
=>
1884 if Comes_From_Source
(N
) then
1888 Set_Etype
(N
, Universal_Integer
);
1894 when Attribute_Body_Version
=>
1897 Set_Etype
(N
, RTE
(RE_Version_String
));
1903 when Attribute_Callable
=>
1905 Set_Etype
(N
, Standard_Boolean
);
1912 when Attribute_Caller
=> Caller
: declare
1919 if Nkind
(P
) = N_Identifier
1920 or else Nkind
(P
) = N_Expanded_Name
1924 if not Is_Entry
(Ent
) then
1925 Error_Attr
("invalid entry name", N
);
1929 Error_Attr
("invalid entry name", N
);
1933 for J
in reverse 0 .. Scope_Stack
.Last
loop
1934 S
:= Scope_Stack
.Table
(J
).Entity
;
1936 if S
= Scope
(Ent
) then
1937 Error_Attr
("Caller must appear in matching accept or body", N
);
1943 Set_Etype
(N
, RTE
(RO_AT_Task_ID
));
1950 when Attribute_Ceiling
=>
1951 Check_Floating_Point_Type_1
;
1952 Set_Etype
(N
, P_Base_Type
);
1953 Resolve
(E1
, P_Base_Type
);
1959 when Attribute_Class
=> Class
: declare
1961 Check_Restriction
(No_Dispatch
, N
);
1962 Check_Either_E0_Or_E1
;
1964 -- If we have an expression present, then really this is a conversion
1965 -- and the tree must be reformed into a proper conversion. This is a
1966 -- Replace rather than a Rewrite, because the original tree is junk.
1967 -- If expression is overloaded, propagate interpretations to new one.
1969 if Present
(E1
) then
1971 Make_Type_Conversion
(Loc
,
1973 Make_Attribute_Reference
(Loc
,
1974 Prefix
=> Prefix
(N
),
1975 Attribute_Name
=> Name_Class
),
1976 Expression
=> Relocate_Node
(E1
)));
1978 Save_Interps
(E1
, Expression
(N
));
1981 -- Otherwise we just need to find the proper type
1993 when Attribute_Code_Address
=>
1996 if Nkind
(P
) = N_Attribute_Reference
1997 and then (Attribute_Name
(P
) = Name_Elab_Body
1999 Attribute_Name
(P
) = Name_Elab_Spec
)
2003 elsif not Is_Entity_Name
(P
)
2004 or else (Ekind
(Entity
(P
)) /= E_Function
2006 Ekind
(Entity
(P
)) /= E_Procedure
)
2008 Error_Attr
("invalid prefix for % attribute", P
);
2009 Set_Address_Taken
(Entity
(P
));
2012 Set_Etype
(N
, RTE
(RE_Address
));
2014 --------------------
2015 -- Component_Size --
2016 --------------------
2018 when Attribute_Component_Size
=>
2020 Set_Etype
(N
, Universal_Integer
);
2022 -- Note: unlike other array attributes, unconstrained arrays are OK
2024 if Is_Array_Type
(P_Type
) and then not Is_Constrained
(P_Type
) then
2034 when Attribute_Compose
=>
2035 Check_Floating_Point_Type_2
;
2036 Set_Etype
(N
, P_Base_Type
);
2037 Resolve
(E1
, P_Base_Type
);
2038 Resolve
(E2
, Any_Integer
);
2044 when Attribute_Constrained
=>
2046 Set_Etype
(N
, Standard_Boolean
);
2048 -- Case from RM J.4(2) of constrained applied to private type
2050 if Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)) then
2052 -- If we are within an instance, the attribute must be legal
2053 -- because it was valid in the generic unit.
2058 -- For sure OK if we have a real private type itself, but must
2059 -- be completed, cannot apply Constrained to incomplete type.
2061 elsif Is_Private_Type
(Entity
(P
)) then
2062 Check_Not_Incomplete_Type
;
2067 Check_Object_Reference
(P
);
2069 -- If N does not come from source, then we allow the
2070 -- the attribute prefix to be of a private type whose
2071 -- full type has discriminants. This occurs in cases
2072 -- involving expanded calls to stream attributes.
2074 if not Comes_From_Source
(N
) then
2075 P_Type
:= Underlying_Type
(P_Type
);
2078 -- Must have discriminants or be an access type designating
2079 -- a type with discriminants. If it is a classwide type is
2080 -- has unknown discriminants.
2082 if Has_Discriminants
(P_Type
)
2083 or else Has_Unknown_Discriminants
(P_Type
)
2085 (Is_Access_Type
(P_Type
)
2086 and then Has_Discriminants
(Designated_Type
(P_Type
)))
2090 -- Also allow an object of a generic type if extensions allowed
2091 -- and allow this for any type at all.
2093 elsif (Is_Generic_Type
(P_Type
)
2094 or else Is_Generic_Actual_Type
(P_Type
))
2095 and then Extensions_Allowed
2101 -- Fall through if bad prefix
2104 ("prefix of % attribute must be object of discriminated type", P
);
2110 when Attribute_Copy_Sign
=>
2111 Check_Floating_Point_Type_2
;
2112 Set_Etype
(N
, P_Base_Type
);
2113 Resolve
(E1
, P_Base_Type
);
2114 Resolve
(E2
, P_Base_Type
);
2120 when Attribute_Count
=> Count
:
2129 if Nkind
(P
) = N_Identifier
2130 or else Nkind
(P
) = N_Expanded_Name
2134 if Ekind
(Ent
) /= E_Entry
then
2135 Error_Attr
("invalid entry name", N
);
2138 elsif Nkind
(P
) = N_Indexed_Component
then
2139 if not Is_Entity_Name
(Prefix
(P
))
2140 or else No
(Entity
(Prefix
(P
)))
2141 or else Ekind
(Entity
(Prefix
(P
))) /= E_Entry_Family
2143 if Nkind
(Prefix
(P
)) = N_Selected_Component
2144 and then Present
(Entity
(Selector_Name
(Prefix
(P
))))
2145 and then Ekind
(Entity
(Selector_Name
(Prefix
(P
)))) =
2149 ("attribute % must apply to entry of current task", P
);
2152 Error_Attr
("invalid entry family name", P
);
2157 Ent
:= Entity
(Prefix
(P
));
2160 elsif Nkind
(P
) = N_Selected_Component
2161 and then Present
(Entity
(Selector_Name
(P
)))
2162 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Entry
2165 ("attribute % must apply to entry of current task", P
);
2168 Error_Attr
("invalid entry name", N
);
2172 for J
in reverse 0 .. Scope_Stack
.Last
loop
2173 S
:= Scope_Stack
.Table
(J
).Entity
;
2175 if S
= Scope
(Ent
) then
2176 if Nkind
(P
) = N_Expanded_Name
then
2177 Tsk
:= Entity
(Prefix
(P
));
2179 -- The prefix denotes either the task type, or else a
2180 -- single task whose task type is being analyzed.
2185 or else (not Is_Type
(Tsk
)
2186 and then Etype
(Tsk
) = S
2187 and then not (Comes_From_Source
(S
)))
2192 ("Attribute % must apply to entry of current task", N
);
2198 elsif Ekind
(Scope
(Ent
)) in Task_Kind
2199 and then Ekind
(S
) /= E_Loop
2200 and then Ekind
(S
) /= E_Block
2201 and then Ekind
(S
) /= E_Entry
2202 and then Ekind
(S
) /= E_Entry_Family
2204 Error_Attr
("Attribute % cannot appear in inner unit", N
);
2206 elsif Ekind
(Scope
(Ent
)) = E_Protected_Type
2207 and then not Has_Completion
(Scope
(Ent
))
2209 Error_Attr
("attribute % can only be used inside body", N
);
2213 if Is_Overloaded
(P
) then
2215 Index
: Interp_Index
;
2219 Get_First_Interp
(P
, Index
, It
);
2221 while Present
(It
.Nam
) loop
2222 if It
.Nam
= Ent
then
2225 elsif Scope
(It
.Nam
) = Scope
(Ent
) then
2226 Error_Attr
("ambiguous entry name", N
);
2229 -- For now make this into a warning. Will become an
2230 -- error after the 3.15 release.
2233 ("ambiguous name, resolved to entry?", N
);
2235 ("\(this will become an error in a later release)?", N
);
2238 Get_Next_Interp
(Index
, It
);
2243 Set_Etype
(N
, Universal_Integer
);
2246 -----------------------
2247 -- Default_Bit_Order --
2248 -----------------------
2250 when Attribute_Default_Bit_Order
=> Default_Bit_Order
:
2252 Check_Standard_Prefix
;
2255 if Bytes_Big_Endian
then
2257 Make_Integer_Literal
(Loc
, False_Value
));
2260 Make_Integer_Literal
(Loc
, True_Value
));
2263 Set_Etype
(N
, Universal_Integer
);
2264 Set_Is_Static_Expression
(N
);
2265 end Default_Bit_Order
;
2271 when Attribute_Definite
=>
2272 Legal_Formal_Attribute
;
2278 when Attribute_Delta
=>
2279 Check_Fixed_Point_Type_0
;
2280 Set_Etype
(N
, Universal_Real
);
2286 when Attribute_Denorm
=>
2287 Check_Floating_Point_Type_0
;
2288 Set_Etype
(N
, Standard_Boolean
);
2294 when Attribute_Digits
=>
2298 if not Is_Floating_Point_Type
(P_Type
)
2299 and then not Is_Decimal_Fixed_Point_Type
(P_Type
)
2302 ("prefix of % attribute must be float or decimal type", P
);
2305 Set_Etype
(N
, Universal_Integer
);
2311 -- Also handles processing for Elab_Spec
2313 when Attribute_Elab_Body | Attribute_Elab_Spec
=>
2315 Check_Unit_Name
(P
);
2316 Set_Etype
(N
, Standard_Void_Type
);
2318 -- We have to manually call the expander in this case to get
2319 -- the necessary expansion (normally attributes that return
2320 -- entities are not expanded).
2328 -- Shares processing with Elab_Body
2334 when Attribute_Elaborated
=>
2337 Set_Etype
(N
, Standard_Boolean
);
2343 when Attribute_Emax
=>
2344 Check_Floating_Point_Type_0
;
2345 Set_Etype
(N
, Universal_Integer
);
2351 when Attribute_Enum_Rep
=> Enum_Rep
: declare
2353 if Present
(E1
) then
2355 Check_Discrete_Type
;
2356 Resolve
(E1
, P_Base_Type
);
2359 if not Is_Entity_Name
(P
)
2360 or else (not Is_Object
(Entity
(P
))
2362 Ekind
(Entity
(P
)) /= E_Enumeration_Literal
)
2365 ("prefix of %attribute must be " &
2366 "discrete type/object or enum literal", P
);
2370 Set_Etype
(N
, Universal_Integer
);
2377 when Attribute_Epsilon
=>
2378 Check_Floating_Point_Type_0
;
2379 Set_Etype
(N
, Universal_Real
);
2385 when Attribute_Exponent
=>
2386 Check_Floating_Point_Type_1
;
2387 Set_Etype
(N
, Universal_Integer
);
2388 Resolve
(E1
, P_Base_Type
);
2394 when Attribute_External_Tag
=>
2398 Set_Etype
(N
, Standard_String
);
2400 if not Is_Tagged_Type
(P_Type
) then
2401 Error_Attr
("prefix of % attribute must be tagged", P
);
2408 when Attribute_First
=>
2409 Check_Array_Or_Scalar_Type
;
2415 when Attribute_First_Bit
=>
2417 Set_Etype
(N
, Universal_Integer
);
2423 when Attribute_Fixed_Value
=>
2425 Check_Fixed_Point_Type
;
2426 Resolve
(E1
, Any_Integer
);
2427 Set_Etype
(N
, P_Base_Type
);
2433 when Attribute_Floor
=>
2434 Check_Floating_Point_Type_1
;
2435 Set_Etype
(N
, P_Base_Type
);
2436 Resolve
(E1
, P_Base_Type
);
2442 when Attribute_Fore
=>
2443 Check_Fixed_Point_Type_0
;
2444 Set_Etype
(N
, Universal_Integer
);
2450 when Attribute_Fraction
=>
2451 Check_Floating_Point_Type_1
;
2452 Set_Etype
(N
, P_Base_Type
);
2453 Resolve
(E1
, P_Base_Type
);
2455 -----------------------
2456 -- Has_Discriminants --
2457 -----------------------
2459 when Attribute_Has_Discriminants
=>
2460 Legal_Formal_Attribute
;
2466 when Attribute_Identity
=>
2470 if Etype
(P
) = Standard_Exception_Type
then
2471 Set_Etype
(N
, RTE
(RE_Exception_Id
));
2473 elsif Is_Task_Type
(Etype
(P
))
2474 or else (Is_Access_Type
(Etype
(P
))
2475 and then Is_Task_Type
(Designated_Type
(Etype
(P
))))
2477 Resolve
(P
, Etype
(P
));
2478 Set_Etype
(N
, RTE
(RO_AT_Task_ID
));
2481 Error_Attr
("prefix of % attribute must be a task or an "
2489 when Attribute_Image
=> Image
:
2491 Set_Etype
(N
, Standard_String
);
2494 if Is_Real_Type
(P_Type
) then
2495 if Ada_83
and then Comes_From_Source
(N
) then
2496 Error_Msg_Name_1
:= Aname
;
2498 ("(Ada 83) % attribute not allowed for real types", N
);
2502 if Is_Enumeration_Type
(P_Type
) then
2503 Check_Restriction
(No_Enumeration_Maps
, N
);
2507 Resolve
(E1
, P_Base_Type
);
2509 Validate_Non_Static_Attribute_Function_Call
;
2516 when Attribute_Img
=> Img
:
2518 Set_Etype
(N
, Standard_String
);
2520 if not Is_Scalar_Type
(P_Type
)
2521 or else (Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)))
2524 ("prefix of % attribute must be scalar object name", N
);
2534 when Attribute_Input
=>
2536 Check_Stream_Attribute
(Name_uInput
);
2537 Disallow_In_No_Run_Time_Mode
(N
);
2538 Set_Etype
(N
, P_Base_Type
);
2544 when Attribute_Integer_Value
=>
2547 Resolve
(E1
, Any_Fixed
);
2548 Set_Etype
(N
, P_Base_Type
);
2554 when Attribute_Large
=>
2557 Set_Etype
(N
, Universal_Real
);
2563 when Attribute_Last
=>
2564 Check_Array_Or_Scalar_Type
;
2570 when Attribute_Last_Bit
=>
2572 Set_Etype
(N
, Universal_Integer
);
2578 when Attribute_Leading_Part
=>
2579 Check_Floating_Point_Type_2
;
2580 Set_Etype
(N
, P_Base_Type
);
2581 Resolve
(E1
, P_Base_Type
);
2582 Resolve
(E2
, Any_Integer
);
2588 when Attribute_Length
=>
2590 Set_Etype
(N
, Universal_Integer
);
2596 when Attribute_Machine
=>
2597 Check_Floating_Point_Type_1
;
2598 Set_Etype
(N
, P_Base_Type
);
2599 Resolve
(E1
, P_Base_Type
);
2605 when Attribute_Machine_Emax
=>
2606 Check_Floating_Point_Type_0
;
2607 Set_Etype
(N
, Universal_Integer
);
2613 when Attribute_Machine_Emin
=>
2614 Check_Floating_Point_Type_0
;
2615 Set_Etype
(N
, Universal_Integer
);
2617 ----------------------
2618 -- Machine_Mantissa --
2619 ----------------------
2621 when Attribute_Machine_Mantissa
=>
2622 Check_Floating_Point_Type_0
;
2623 Set_Etype
(N
, Universal_Integer
);
2625 -----------------------
2626 -- Machine_Overflows --
2627 -----------------------
2629 when Attribute_Machine_Overflows
=>
2632 Set_Etype
(N
, Standard_Boolean
);
2638 when Attribute_Machine_Radix
=>
2641 Set_Etype
(N
, Universal_Integer
);
2643 --------------------
2644 -- Machine_Rounds --
2645 --------------------
2647 when Attribute_Machine_Rounds
=>
2650 Set_Etype
(N
, Standard_Boolean
);
2656 when Attribute_Machine_Size
=>
2659 Check_Not_Incomplete_Type
;
2660 Set_Etype
(N
, Universal_Integer
);
2666 when Attribute_Mantissa
=>
2669 Set_Etype
(N
, Universal_Integer
);
2675 when Attribute_Max
=>
2678 Resolve
(E1
, P_Base_Type
);
2679 Resolve
(E2
, P_Base_Type
);
2680 Set_Etype
(N
, P_Base_Type
);
2682 ----------------------------------
2683 -- Max_Size_In_Storage_Elements --
2684 ----------------------------------
2686 when Attribute_Max_Size_In_Storage_Elements
=>
2689 Check_Not_Incomplete_Type
;
2690 Set_Etype
(N
, Universal_Integer
);
2692 -----------------------
2693 -- Maximum_Alignment --
2694 -----------------------
2696 when Attribute_Maximum_Alignment
=>
2697 Standard_Attribute
(Ttypes
.Maximum_Alignment
);
2699 --------------------
2700 -- Mechanism_Code --
2701 --------------------
2703 when Attribute_Mechanism_Code
=>
2705 if not Is_Entity_Name
(P
)
2706 or else not Is_Subprogram
(Entity
(P
))
2708 Error_Attr
("prefix of % attribute must be subprogram", P
);
2711 Check_Either_E0_Or_E1
;
2713 if Present
(E1
) then
2714 Resolve
(E1
, Any_Integer
);
2715 Set_Etype
(E1
, Standard_Integer
);
2717 if not Is_Static_Expression
(E1
) then
2719 ("expression for parameter number must be static", E1
);
2721 elsif UI_To_Int
(Intval
(E1
)) > Number_Formals
(Entity
(P
))
2722 or else UI_To_Int
(Intval
(E1
)) < 0
2724 Error_Attr
("invalid parameter number for %attribute", E1
);
2728 Set_Etype
(N
, Universal_Integer
);
2734 when Attribute_Min
=>
2737 Resolve
(E1
, P_Base_Type
);
2738 Resolve
(E2
, P_Base_Type
);
2739 Set_Etype
(N
, P_Base_Type
);
2745 when Attribute_Model
=>
2746 Check_Floating_Point_Type_1
;
2747 Set_Etype
(N
, P_Base_Type
);
2748 Resolve
(E1
, P_Base_Type
);
2754 when Attribute_Model_Emin
=>
2755 Check_Floating_Point_Type_0
;
2756 Set_Etype
(N
, Universal_Integer
);
2762 when Attribute_Model_Epsilon
=>
2763 Check_Floating_Point_Type_0
;
2764 Set_Etype
(N
, Universal_Real
);
2766 --------------------
2767 -- Model_Mantissa --
2768 --------------------
2770 when Attribute_Model_Mantissa
=>
2771 Check_Floating_Point_Type_0
;
2772 Set_Etype
(N
, Universal_Integer
);
2778 when Attribute_Model_Small
=>
2779 Check_Floating_Point_Type_0
;
2780 Set_Etype
(N
, Universal_Real
);
2786 when Attribute_Modulus
=>
2790 if not Is_Modular_Integer_Type
(P_Type
) then
2791 Error_Attr
("prefix of % attribute must be modular type", P
);
2794 Set_Etype
(N
, Universal_Integer
);
2796 --------------------
2797 -- Null_Parameter --
2798 --------------------
2800 when Attribute_Null_Parameter
=> Null_Parameter
: declare
2801 Parnt
: constant Node_Id
:= Parent
(N
);
2802 GParnt
: constant Node_Id
:= Parent
(Parnt
);
2804 procedure Bad_Null_Parameter
(Msg
: String);
2805 -- Used if bad Null parameter attribute node is found. Issues
2806 -- given error message, and also sets the type to Any_Type to
2807 -- avoid blowups later on from dealing with a junk node.
2809 procedure Must_Be_Imported
(Proc_Ent
: Entity_Id
);
2810 -- Called to check that Proc_Ent is imported subprogram
2812 ------------------------
2813 -- Bad_Null_Parameter --
2814 ------------------------
2816 procedure Bad_Null_Parameter
(Msg
: String) is
2818 Error_Msg_N
(Msg
, N
);
2819 Set_Etype
(N
, Any_Type
);
2820 end Bad_Null_Parameter
;
2822 ----------------------
2823 -- Must_Be_Imported --
2824 ----------------------
2826 procedure Must_Be_Imported
(Proc_Ent
: Entity_Id
) is
2827 Pent
: Entity_Id
:= Proc_Ent
;
2830 while Present
(Alias
(Pent
)) loop
2831 Pent
:= Alias
(Pent
);
2834 -- Ignore check if procedure not frozen yet (we will get
2835 -- another chance when the default parameter is reanalyzed)
2837 if not Is_Frozen
(Pent
) then
2840 elsif not Is_Imported
(Pent
) then
2842 ("Null_Parameter can only be used with imported subprogram");
2847 end Must_Be_Imported
;
2849 -- Start of processing for Null_Parameter
2854 Set_Etype
(N
, P_Type
);
2856 -- Case of attribute used as default expression
2858 if Nkind
(Parnt
) = N_Parameter_Specification
then
2859 Must_Be_Imported
(Defining_Entity
(GParnt
));
2861 -- Case of attribute used as actual for subprogram (positional)
2863 elsif (Nkind
(Parnt
) = N_Procedure_Call_Statement
2865 Nkind
(Parnt
) = N_Function_Call
)
2866 and then Is_Entity_Name
(Name
(Parnt
))
2868 Must_Be_Imported
(Entity
(Name
(Parnt
)));
2870 -- Case of attribute used as actual for subprogram (named)
2872 elsif Nkind
(Parnt
) = N_Parameter_Association
2873 and then (Nkind
(GParnt
) = N_Procedure_Call_Statement
2875 Nkind
(GParnt
) = N_Function_Call
)
2876 and then Is_Entity_Name
(Name
(GParnt
))
2878 Must_Be_Imported
(Entity
(Name
(GParnt
)));
2880 -- Not an allowed case
2884 ("Null_Parameter must be actual or default parameter");
2893 when Attribute_Object_Size
=>
2896 Check_Not_Incomplete_Type
;
2897 Set_Etype
(N
, Universal_Integer
);
2903 when Attribute_Output
=>
2905 Check_Stream_Attribute
(Name_uInput
);
2906 Set_Etype
(N
, Standard_Void_Type
);
2907 Disallow_In_No_Run_Time_Mode
(N
);
2908 Resolve
(N
, Standard_Void_Type
);
2914 when Attribute_Partition_ID
=>
2917 if P_Type
/= Any_Type
then
2918 if not Is_Library_Level_Entity
(Entity
(P
)) then
2920 ("prefix of % attribute must be library-level entity", P
);
2922 -- The defining entity of prefix should not be declared inside
2923 -- a Pure unit. RM E.1(8).
2924 -- The Is_Pure flag has been set during declaration.
2926 elsif Is_Entity_Name
(P
)
2927 and then Is_Pure
(Entity
(P
))
2930 ("prefix of % attribute must not be declared pure", P
);
2934 Set_Etype
(N
, Universal_Integer
);
2936 -------------------------
2937 -- Passed_By_Reference --
2938 -------------------------
2940 when Attribute_Passed_By_Reference
=>
2943 Set_Etype
(N
, Standard_Boolean
);
2949 when Attribute_Pos
=>
2950 Check_Discrete_Type
;
2952 Resolve
(E1
, P_Base_Type
);
2953 Set_Etype
(N
, Universal_Integer
);
2959 when Attribute_Position
=>
2961 Set_Etype
(N
, Universal_Integer
);
2967 when Attribute_Pred
=>
2970 Resolve
(E1
, P_Base_Type
);
2971 Set_Etype
(N
, P_Base_Type
);
2973 -- Nothing to do for real type case
2975 if Is_Real_Type
(P_Type
) then
2978 -- If not modular type, test for overflow check required
2981 if not Is_Modular_Integer_Type
(P_Type
)
2982 and then not Range_Checks_Suppressed
(P_Base_Type
)
2984 Enable_Range_Check
(E1
);
2992 when Attribute_Range
=>
2993 Check_Array_Or_Scalar_Type
;
2996 and then Is_Scalar_Type
(P_Type
)
2997 and then Comes_From_Source
(N
)
3000 ("(Ada 83) % attribute not allowed for scalar type", P
);
3007 when Attribute_Range_Length
=>
3008 Check_Discrete_Type
;
3009 Set_Etype
(N
, Universal_Integer
);
3015 when Attribute_Read
=>
3017 Check_Stream_Attribute
(Name_uRead
);
3018 Set_Etype
(N
, Standard_Void_Type
);
3019 Resolve
(N
, Standard_Void_Type
);
3020 Disallow_In_No_Run_Time_Mode
(N
);
3021 Note_Possible_Modification
(E2
);
3027 when Attribute_Remainder
=>
3028 Check_Floating_Point_Type_2
;
3029 Set_Etype
(N
, P_Base_Type
);
3030 Resolve
(E1
, P_Base_Type
);
3031 Resolve
(E2
, P_Base_Type
);
3037 when Attribute_Round
=>
3039 Check_Decimal_Fixed_Point_Type
;
3040 Set_Etype
(N
, P_Base_Type
);
3042 -- Because the context is universal_real (3.5.10(12)) it is a legal
3043 -- context for a universal fixed expression. This is the only
3044 -- attribute whose functional description involves U_R.
3046 if Etype
(E1
) = Universal_Fixed
then
3048 Conv
: constant Node_Id
:= Make_Type_Conversion
(Loc
,
3049 Subtype_Mark
=> New_Occurrence_Of
(Universal_Real
, Loc
),
3050 Expression
=> Relocate_Node
(E1
));
3058 Resolve
(E1
, Any_Real
);
3064 when Attribute_Rounding
=>
3065 Check_Floating_Point_Type_1
;
3066 Set_Etype
(N
, P_Base_Type
);
3067 Resolve
(E1
, P_Base_Type
);
3073 when Attribute_Safe_Emax
=>
3074 Check_Floating_Point_Type_0
;
3075 Set_Etype
(N
, Universal_Integer
);
3081 when Attribute_Safe_First
=>
3082 Check_Floating_Point_Type_0
;
3083 Set_Etype
(N
, Universal_Real
);
3089 when Attribute_Safe_Large
=>
3092 Set_Etype
(N
, Universal_Real
);
3098 when Attribute_Safe_Last
=>
3099 Check_Floating_Point_Type_0
;
3100 Set_Etype
(N
, Universal_Real
);
3106 when Attribute_Safe_Small
=>
3109 Set_Etype
(N
, Universal_Real
);
3115 when Attribute_Scale
=>
3117 Check_Decimal_Fixed_Point_Type
;
3118 Set_Etype
(N
, Universal_Integer
);
3124 when Attribute_Scaling
=>
3125 Check_Floating_Point_Type_2
;
3126 Set_Etype
(N
, P_Base_Type
);
3127 Resolve
(E1
, P_Base_Type
);
3133 when Attribute_Signed_Zeros
=>
3134 Check_Floating_Point_Type_0
;
3135 Set_Etype
(N
, Standard_Boolean
);
3141 when Attribute_Size | Attribute_VADS_Size
=>
3144 if Is_Object_Reference
(P
)
3145 or else (Is_Entity_Name
(P
)
3146 and then Ekind
(Entity
(P
)) = E_Function
)
3148 Check_Object_Reference
(P
);
3150 elsif Is_Entity_Name
(P
)
3151 and then Is_Type
(Entity
(P
))
3155 elsif Nkind
(P
) = N_Type_Conversion
3156 and then not Comes_From_Source
(P
)
3161 Error_Attr
("invalid prefix for % attribute", P
);
3164 Check_Not_Incomplete_Type
;
3165 Set_Etype
(N
, Universal_Integer
);
3171 when Attribute_Small
=>
3174 Set_Etype
(N
, Universal_Real
);
3180 when Attribute_Storage_Pool
=>
3181 if Is_Access_Type
(P_Type
) then
3184 -- Set appropriate entity
3186 if Present
(Associated_Storage_Pool
(Root_Type
(P_Type
))) then
3187 Set_Entity
(N
, Associated_Storage_Pool
(Root_Type
(P_Type
)));
3189 Set_Entity
(N
, RTE
(RE_Global_Pool_Object
));
3192 Set_Etype
(N
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
3194 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
3195 -- Storage_Pool since this attribute is not defined for such
3196 -- types (RM E.2.3(22)).
3198 Validate_Remote_Access_To_Class_Wide_Type
(N
);
3201 Error_Attr
("prefix of % attribute must be access type", P
);
3208 when Attribute_Storage_Size
=>
3210 if Is_Task_Type
(P_Type
) then
3212 Set_Etype
(N
, Universal_Integer
);
3214 elsif Is_Access_Type
(P_Type
) then
3215 if Is_Entity_Name
(P
)
3216 and then Is_Type
(Entity
(P
))
3220 Set_Etype
(N
, Universal_Integer
);
3222 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
3223 -- Storage_Size since this attribute is not defined for
3224 -- such types (RM E.2.3(22)).
3226 Validate_Remote_Access_To_Class_Wide_Type
(N
);
3228 -- The prefix is allowed to be an implicit dereference
3229 -- of an access value designating a task.
3234 Set_Etype
(N
, Universal_Integer
);
3239 ("prefix of % attribute must be access or task type", P
);
3246 when Attribute_Storage_Unit
=>
3247 Standard_Attribute
(Ttypes
.System_Storage_Unit
);
3253 when Attribute_Succ
=>
3256 Resolve
(E1
, P_Base_Type
);
3257 Set_Etype
(N
, P_Base_Type
);
3259 -- Nothing to do for real type case
3261 if Is_Real_Type
(P_Type
) then
3264 -- If not modular type, test for overflow check required.
3267 if not Is_Modular_Integer_Type
(P_Type
)
3268 and then not Range_Checks_Suppressed
(P_Base_Type
)
3270 Enable_Range_Check
(E1
);
3278 when Attribute_Tag
=>
3282 if not Is_Tagged_Type
(P_Type
) then
3283 Error_Attr
("prefix of % attribute must be tagged", P
);
3285 -- Next test does not apply to generated code
3286 -- why not, and what does the illegal reference mean???
3288 elsif Is_Object_Reference
(P
)
3289 and then not Is_Class_Wide_Type
(P_Type
)
3290 and then Comes_From_Source
(N
)
3293 ("% attribute can only be applied to objects of class-wide type",
3297 Set_Etype
(N
, RTE
(RE_Tag
));
3303 when Attribute_Terminated
=>
3305 Set_Etype
(N
, Standard_Boolean
);
3312 when Attribute_To_Address
=>
3316 if Nkind
(P
) /= N_Identifier
3317 or else Chars
(P
) /= Name_System
3319 Error_Attr
("prefix of %attribute must be System", P
);
3322 Generate_Reference
(RTE
(RE_Address
), P
);
3323 Analyze_And_Resolve
(E1
, Any_Integer
);
3324 Set_Etype
(N
, RTE
(RE_Address
));
3330 when Attribute_Truncation
=>
3331 Check_Floating_Point_Type_1
;
3332 Resolve
(E1
, P_Base_Type
);
3333 Set_Etype
(N
, P_Base_Type
);
3339 when Attribute_Type_Class
=>
3342 Check_Not_Incomplete_Type
;
3343 Set_Etype
(N
, RTE
(RE_Type_Class
));
3349 when Attribute_UET_Address
=>
3351 Check_Unit_Name
(P
);
3352 Set_Etype
(N
, RTE
(RE_Address
));
3354 -----------------------
3355 -- Unbiased_Rounding --
3356 -----------------------
3358 when Attribute_Unbiased_Rounding
=>
3359 Check_Floating_Point_Type_1
;
3360 Set_Etype
(N
, P_Base_Type
);
3361 Resolve
(E1
, P_Base_Type
);
3363 ----------------------
3364 -- Unchecked_Access --
3365 ----------------------
3367 when Attribute_Unchecked_Access
=>
3368 if Comes_From_Source
(N
) then
3369 Check_Restriction
(No_Unchecked_Access
, N
);
3374 ------------------------------
3375 -- Universal_Literal_String --
3376 ------------------------------
3378 -- This is a GNAT specific attribute whose prefix must be a named
3379 -- number where the expression is either a single numeric literal,
3380 -- or a numeric literal immediately preceded by a minus sign. The
3381 -- result is equivalent to a string literal containing the text of
3382 -- the literal as it appeared in the source program with a possible
3383 -- leading minus sign.
3385 when Attribute_Universal_Literal_String
=> Universal_Literal_String
:
3389 if not Is_Entity_Name
(P
)
3390 or else Ekind
(Entity
(P
)) not in Named_Kind
3392 Error_Attr
("prefix for % attribute must be named number", P
);
3399 Src
: Source_Buffer_Ptr
;
3402 Expr
:= Original_Node
(Expression
(Parent
(Entity
(P
))));
3404 if Nkind
(Expr
) = N_Op_Minus
then
3406 Expr
:= Original_Node
(Right_Opnd
(Expr
));
3411 if Nkind
(Expr
) /= N_Integer_Literal
3412 and then Nkind
(Expr
) /= N_Real_Literal
3415 ("named number for % attribute must be simple literal", N
);
3418 -- Build string literal corresponding to source literal text
3423 Store_String_Char
(Get_Char_Code
('-'));
3427 Src
:= Source_Text
(Get_Source_File_Index
(S
));
3429 while Src
(S
) /= ';' and then Src
(S
) /= ' ' loop
3430 Store_String_Char
(Get_Char_Code
(Src
(S
)));
3434 -- Now we rewrite the attribute with the string literal
3437 Make_String_Literal
(Loc
, End_String
));
3441 end Universal_Literal_String
;
3443 -------------------------
3444 -- Unrestricted_Access --
3445 -------------------------
3447 -- This is a GNAT specific attribute which is like Access except that
3448 -- all scope checks and checks for aliased views are omitted.
3450 when Attribute_Unrestricted_Access
=>
3451 if Comes_From_Source
(N
) then
3452 Check_Restriction
(No_Unchecked_Access
, N
);
3455 if Is_Entity_Name
(P
) then
3456 Set_Address_Taken
(Entity
(P
));
3465 when Attribute_Val
=> Val
: declare
3468 Check_Discrete_Type
;
3469 Resolve
(E1
, Any_Integer
);
3470 Set_Etype
(N
, P_Base_Type
);
3472 -- Note, we need a range check in general, but we wait for the
3473 -- Resolve call to do this, since we want to let Eval_Attribute
3474 -- have a chance to find an static illegality first!
3481 when Attribute_Valid
=>
3484 -- Ignore check for object if we have a 'Valid reference generated
3485 -- by the expanded code, since in some cases valid checks can occur
3486 -- on items that are names, but are not objects (e.g. attributes).
3488 if Comes_From_Source
(N
) then
3489 Check_Object_Reference
(P
);
3492 if not Is_Scalar_Type
(P_Type
) then
3493 Error_Attr
("object for % attribute must be of scalar type", P
);
3496 Set_Etype
(N
, Standard_Boolean
);
3502 when Attribute_Value
=> Value
:
3507 if Is_Enumeration_Type
(P_Type
) then
3508 Check_Restriction
(No_Enumeration_Maps
, N
);
3511 -- Set Etype before resolving expression because expansion
3512 -- of expression may require enclosing type.
3514 Set_Etype
(N
, P_Type
);
3515 Validate_Non_Static_Attribute_Function_Call
;
3522 when Attribute_Value_Size
=>
3525 Check_Not_Incomplete_Type
;
3526 Set_Etype
(N
, Universal_Integer
);
3532 when Attribute_Version
=>
3535 Set_Etype
(N
, RTE
(RE_Version_String
));
3541 when Attribute_Wchar_T_Size
=>
3542 Standard_Attribute
(Interfaces_Wchar_T_Size
);
3548 when Attribute_Wide_Image
=> Wide_Image
:
3551 Set_Etype
(N
, Standard_Wide_String
);
3553 Resolve
(E1
, P_Base_Type
);
3554 Validate_Non_Static_Attribute_Function_Call
;
3561 when Attribute_Wide_Value
=> Wide_Value
:
3566 -- Set Etype before resolving expression because expansion
3567 -- of expression may require enclosing type.
3569 Set_Etype
(N
, P_Type
);
3570 Validate_Non_Static_Attribute_Function_Call
;
3577 when Attribute_Wide_Width
=>
3580 Set_Etype
(N
, Universal_Integer
);
3586 when Attribute_Width
=>
3589 Set_Etype
(N
, Universal_Integer
);
3595 when Attribute_Word_Size
=>
3596 Standard_Attribute
(System_Word_Size
);
3602 when Attribute_Write
=>
3604 Check_Stream_Attribute
(Name_uWrite
);
3605 Set_Etype
(N
, Standard_Void_Type
);
3606 Disallow_In_No_Run_Time_Mode
(N
);
3607 Resolve
(N
, Standard_Void_Type
);
3611 -- All errors raise Bad_Attribute, so that we get out before any further
3612 -- damage occurs when an error is detected (for example, if we check for
3613 -- one attribute expression, and the check succeeds, we want to be able
3614 -- to proceed securely assuming that an expression is in fact present.
3617 when Bad_Attribute
=>
3618 Set_Etype
(N
, Any_Type
);
3621 end Analyze_Attribute
;
3623 --------------------
3624 -- Eval_Attribute --
3625 --------------------
3627 procedure Eval_Attribute
(N
: Node_Id
) is
3628 Loc
: constant Source_Ptr
:= Sloc
(N
);
3629 Aname
: constant Name_Id
:= Attribute_Name
(N
);
3630 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Aname
);
3631 P
: constant Node_Id
:= Prefix
(N
);
3633 C_Type
: constant Entity_Id
:= Etype
(N
);
3634 -- The type imposed by the context.
3637 -- First expression, or Empty if none
3640 -- Second expression, or Empty if none
3642 P_Entity
: Entity_Id
;
3643 -- Entity denoted by prefix
3646 -- The type of the prefix
3648 P_Base_Type
: Entity_Id
;
3649 -- The base type of the prefix type
3651 P_Root_Type
: Entity_Id
;
3652 -- The root type of the prefix type
3655 -- True if prefix type is static
3657 Lo_Bound
, Hi_Bound
: Node_Id
;
3658 -- Expressions for low and high bounds of type or array index referenced
3659 -- by First, Last, or Length attribute for array, set by Set_Bounds.
3662 -- Constraint error node used if we have an attribute reference has
3663 -- an argument that raises a constraint error. In this case we replace
3664 -- the attribute with a raise constraint_error node. This is important
3665 -- processing, since otherwise gigi might see an attribute which it is
3666 -- unprepared to deal with.
3668 function Aft_Value
return Nat
;
3669 -- Computes Aft value for current attribute prefix (used by Aft itself
3670 -- and also by Width for computing the Width of a fixed point type).
3672 procedure Check_Expressions
;
3673 -- In case where the attribute is not foldable, the expressions, if
3674 -- any, of the attribute, are in a non-static context. This procedure
3675 -- performs the required additional checks.
3677 procedure Compile_Time_Known_Attribute
(N
: Node_Id
; Val
: Uint
);
3678 -- This procedure is called when the attribute N has a non-static
3679 -- but compile time known value given by Val. It includes the
3680 -- necessary checks for out of range values.
3682 procedure Float_Attribute_Universal_Integer
3689 -- This procedure evaluates a float attribute with no arguments that
3690 -- returns a universal integer result. The parameters give the values
3691 -- for the possible floating-point root types. See ttypef for details.
3692 -- The prefix type is a float type (and is thus not a generic type).
3694 procedure Float_Attribute_Universal_Real
3695 (IEEES_Val
: String;
3700 VAXGF_Val
: String);
3701 -- This procedure evaluates a float attribute with no arguments that
3702 -- returns a universal real result. The parameters give the values
3703 -- required for the possible floating-point root types in string
3704 -- format as real literals with a possible leading minus sign.
3705 -- The prefix type is a float type (and is thus not a generic type).
3707 function Fore_Value
return Nat
;
3708 -- Computes the Fore value for the current attribute prefix, which is
3709 -- known to be a static fixed-point type. Used by Fore and Width.
3711 function Mantissa
return Uint
;
3712 -- Returns the Mantissa value for the prefix type
3714 procedure Set_Bounds
;
3715 -- Used for First, Last and Length attributes applied to an array or
3716 -- array subtype. Sets the variables Index_Lo and Index_Hi to the low
3717 -- and high bound expressions for the index referenced by the attribute
3718 -- designator (i.e. the first index if no expression is present, and
3719 -- the N'th index if the value N is present as an expression). Also
3720 -- used for First and Last of scalar types.
3726 function Aft_Value
return Nat
is
3732 Delta_Val
:= Delta_Value
(P_Type
);
3734 while Delta_Val
< Ureal_Tenth
loop
3735 Delta_Val
:= Delta_Val
* Ureal_10
;
3736 Result
:= Result
+ 1;
3742 -----------------------
3743 -- Check_Expressions --
3744 -----------------------
3746 procedure Check_Expressions
is
3750 while Present
(E
) loop
3751 Check_Non_Static_Context
(E
);
3754 end Check_Expressions
;
3756 ----------------------------------
3757 -- Compile_Time_Known_Attribute --
3758 ----------------------------------
3760 procedure Compile_Time_Known_Attribute
(N
: Node_Id
; Val
: Uint
) is
3761 T
: constant Entity_Id
:= Etype
(N
);
3765 Set_Is_Static_Expression
(N
, False);
3767 -- Check that result is in bounds of the type if it is static
3769 if Is_In_Range
(N
, T
) then
3772 elsif Is_Out_Of_Range
(N
, T
) then
3773 Apply_Compile_Time_Constraint_Error
3774 (N
, "value not in range of}?", CE_Range_Check_Failed
);
3776 elsif not Range_Checks_Suppressed
(T
) then
3777 Enable_Range_Check
(N
);
3780 Set_Do_Range_Check
(N
, False);
3782 end Compile_Time_Known_Attribute
;
3784 ---------------------------------------
3785 -- Float_Attribute_Universal_Integer --
3786 ---------------------------------------
3788 procedure Float_Attribute_Universal_Integer
3797 Digs
: constant Nat
:= UI_To_Int
(Digits_Value
(P_Base_Type
));
3800 if not Vax_Float
(P_Base_Type
) then
3801 if Digs
= IEEES_Digits
then
3803 elsif Digs
= IEEEL_Digits
then
3805 else pragma Assert
(Digs
= IEEEX_Digits
);
3810 if Digs
= VAXFF_Digits
then
3812 elsif Digs
= VAXDF_Digits
then
3814 else pragma Assert
(Digs
= VAXGF_Digits
);
3819 Fold_Uint
(N
, UI_From_Int
(Val
));
3820 end Float_Attribute_Universal_Integer
;
3822 ------------------------------------
3823 -- Float_Attribute_Universal_Real --
3824 ------------------------------------
3826 procedure Float_Attribute_Universal_Real
3827 (IEEES_Val
: String;
3835 Digs
: constant Nat
:= UI_To_Int
(Digits_Value
(P_Base_Type
));
3838 if not Vax_Float
(P_Base_Type
) then
3839 if Digs
= IEEES_Digits
then
3840 Val
:= Real_Convert
(IEEES_Val
);
3841 elsif Digs
= IEEEL_Digits
then
3842 Val
:= Real_Convert
(IEEEL_Val
);
3843 else pragma Assert
(Digs
= IEEEX_Digits
);
3844 Val
:= Real_Convert
(IEEEX_Val
);
3848 if Digs
= VAXFF_Digits
then
3849 Val
:= Real_Convert
(VAXFF_Val
);
3850 elsif Digs
= VAXDF_Digits
then
3851 Val
:= Real_Convert
(VAXDF_Val
);
3852 else pragma Assert
(Digs
= VAXGF_Digits
);
3853 Val
:= Real_Convert
(VAXGF_Val
);
3857 Set_Sloc
(Val
, Loc
);
3859 Analyze_And_Resolve
(N
, C_Type
);
3860 end Float_Attribute_Universal_Real
;
3866 -- Note that the Fore calculation is based on the actual values
3867 -- of the bounds, and does not take into account possible rounding.
3869 function Fore_Value
return Nat
is
3870 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(P_Type
));
3871 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(P_Type
));
3872 Small
: constant Ureal
:= Small_Value
(P_Type
);
3873 Lo_Real
: constant Ureal
:= Lo
* Small
;
3874 Hi_Real
: constant Ureal
:= Hi
* Small
;
3879 -- Bounds are given in terms of small units, so first compute
3880 -- proper values as reals.
3882 T
:= UR_Max
(abs Lo_Real
, abs Hi_Real
);
3885 -- Loop to compute proper value if more than one digit required
3887 while T
>= Ureal_10
loop
3899 -- Table of mantissa values accessed by function Computed using
3902 -- T'Mantissa = integer next above (D * log(10)/log(2)) + 1)
3904 -- where D is T'Digits (RM83 3.5.7)
3906 Mantissa_Value
: constant array (Nat
range 1 .. 40) of Nat
:= (
3948 function Mantissa
return Uint
is
3951 UI_From_Int
(Mantissa_Value
(UI_To_Int
(Digits_Value
(P_Type
))));
3958 procedure Set_Bounds
is
3964 -- For a string literal subtype, we have to construct the bounds.
3965 -- Valid Ada code never applies attributes to string literals, but
3966 -- it is convenient to allow the expander to generate attribute
3967 -- references of this type (e.g. First and Last applied to a string
3970 -- Note that the whole point of the E_String_Literal_Subtype is to
3971 -- avoid this construction of bounds, but the cases in which we
3972 -- have to materialize them are rare enough that we don't worry!
3974 -- The low bound is simply the low bound of the base type. The
3975 -- high bound is computed from the length of the string and this
3978 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
3980 Type_Low_Bound
(Etype
(First_Index
(Base_Type
(P_Type
))));
3983 Make_Integer_Literal
(Sloc
(P
),
3985 Expr_Value
(Lo_Bound
) + String_Literal_Length
(P_Type
) - 1);
3987 Set_Parent
(Hi_Bound
, P
);
3988 Analyze_And_Resolve
(Hi_Bound
, Etype
(Lo_Bound
));
3991 -- For non-array case, just get bounds of scalar type
3993 elsif Is_Scalar_Type
(P_Type
) then
3996 if Is_Fixed_Point_Type
(P_Type
)
3997 and then not Is_Frozen
(Base_Type
(P_Type
))
3998 and then Compile_Time_Known_Value
(Type_Low_Bound
(P_Type
))
3999 and then Compile_Time_Known_Value
(Type_High_Bound
(P_Type
))
4001 Freeze_Fixed_Point_Type
(Base_Type
(P_Type
));
4004 -- For array case, get type of proper index
4010 Ndim
:= UI_To_Int
(Expr_Value
(E1
));
4013 Indx
:= First_Index
(P_Type
);
4014 for J
in 1 .. Ndim
- 1 loop
4018 -- If no index type, get out (some other error occurred, and
4019 -- we don't have enough information to complete the job!)
4027 Ityp
:= Etype
(Indx
);
4030 -- A discrete range in an index constraint is allowed to be a
4031 -- subtype indication. This is syntactically a pain, but should
4032 -- not propagate to the entity for the corresponding index subtype.
4033 -- After checking that the subtype indication is legal, the range
4034 -- of the subtype indication should be transfered to the entity.
4035 -- The attributes for the bounds should remain the simple retrievals
4036 -- that they are now.
4038 Lo_Bound
:= Type_Low_Bound
(Ityp
);
4039 Hi_Bound
:= Type_High_Bound
(Ityp
);
4043 -- Start of processing for Eval_Attribute
4046 -- Acquire first two expressions (at the moment, no attributes
4047 -- take more than two expressions in any case).
4049 if Present
(Expressions
(N
)) then
4050 E1
:= First
(Expressions
(N
));
4057 -- Special processing for cases where the prefix is an object
4059 if Is_Object_Reference
(P
) then
4061 -- For Component_Size, the prefix is an array object, and we apply
4062 -- the attribute to the type of the object. This is allowed for
4063 -- both unconstrained and constrained arrays, since the bounds
4064 -- have no influence on the value of this attribute.
4066 if Id
= Attribute_Component_Size
then
4067 P_Entity
:= Etype
(P
);
4069 -- For First and Last, the prefix is an array object, and we apply
4070 -- the attribute to the type of the array, but we need a constrained
4071 -- type for this, so we use the actual subtype if available.
4073 elsif Id
= Attribute_First
4077 Id
= Attribute_Length
4080 AS
: constant Entity_Id
:= Get_Actual_Subtype_If_Available
(P
);
4083 if Present
(AS
) then
4086 -- If no actual subtype, cannot fold
4094 -- For Size, give size of object if available, otherwise we
4095 -- cannot fold Size.
4097 elsif Id
= Attribute_Size
then
4099 if Is_Entity_Name
(P
)
4100 and then Known_Esize
(Entity
(P
))
4102 Compile_Time_Known_Attribute
(N
, Esize
(Entity
(P
)));
4110 -- For Alignment, give size of object if available, otherwise we
4111 -- cannot fold Alignment.
4113 elsif Id
= Attribute_Alignment
then
4115 if Is_Entity_Name
(P
)
4116 and then Known_Alignment
(Entity
(P
))
4118 Fold_Uint
(N
, Alignment
(Entity
(P
)));
4119 Set_Is_Static_Expression
(N
, False);
4127 -- No other attributes for objects are folded
4134 -- Cases where P is not an object. Cannot do anything if P is
4135 -- not the name of an entity.
4137 elsif not Is_Entity_Name
(P
) then
4141 -- Otherwise get prefix entity
4144 P_Entity
:= Entity
(P
);
4147 -- At this stage P_Entity is the entity to which the attribute
4148 -- is to be applied. This is usually simply the entity of the
4149 -- prefix, except in some cases of attributes for objects, where
4150 -- as described above, we apply the attribute to the object type.
4152 -- First foldable possibility is a scalar or array type (RM 4.9(7))
4153 -- that is not generic (generic types are eliminated by RM 4.9(25)).
4154 -- Note we allow non-static non-generic types at this stage as further
4157 if Is_Type
(P_Entity
)
4158 and then (Is_Scalar_Type
(P_Entity
) or Is_Array_Type
(P_Entity
))
4159 and then (not Is_Generic_Type
(P_Entity
))
4163 -- Second foldable possibility is an array object (RM 4.9(8))
4165 elsif (Ekind
(P_Entity
) = E_Variable
4167 Ekind
(P_Entity
) = E_Constant
)
4168 and then Is_Array_Type
(Etype
(P_Entity
))
4169 and then (not Is_Generic_Type
(Etype
(P_Entity
)))
4171 P_Type
:= Etype
(P_Entity
);
4173 -- If the entity is an array constant with an unconstrained
4174 -- nominal subtype then get the type from the initial value.
4175 -- If the value has been expanded into assignments, the expression
4176 -- is not present and the attribute reference remains dynamic.
4177 -- We could do better here and retrieve the type ???
4179 if Ekind
(P_Entity
) = E_Constant
4180 and then not Is_Constrained
(P_Type
)
4182 if No
(Constant_Value
(P_Entity
)) then
4185 P_Type
:= Etype
(Constant_Value
(P_Entity
));
4189 -- Definite must be folded if the prefix is not a generic type,
4190 -- that is to say if we are within an instantiation. Same processing
4191 -- applies to the GNAT attributes Has_Discriminants and Type_Class
4193 elsif (Id
= Attribute_Definite
4195 Id
= Attribute_Has_Discriminants
4197 Id
= Attribute_Type_Class
)
4198 and then not Is_Generic_Type
(P_Entity
)
4202 -- We can fold 'Size applied to a type if the size is known
4203 -- (as happens for a size from an attribute definition clause).
4204 -- At this stage, this can happen only for types (e.g. record
4205 -- types) for which the size is always non-static. We exclude
4206 -- generic types from consideration (since they have bogus
4207 -- sizes set within templates).
4209 elsif Id
= Attribute_Size
4210 and then Is_Type
(P_Entity
)
4211 and then (not Is_Generic_Type
(P_Entity
))
4212 and then Known_Static_RM_Size
(P_Entity
)
4214 Compile_Time_Known_Attribute
(N
, RM_Size
(P_Entity
));
4217 -- No other cases are foldable (they certainly aren't static, and at
4218 -- the moment we don't try to fold any cases other than the two above)
4225 -- If either attribute or the prefix is Any_Type, then propagate
4226 -- Any_Type to the result and don't do anything else at all.
4228 if P_Type
= Any_Type
4229 or else (Present
(E1
) and then Etype
(E1
) = Any_Type
)
4230 or else (Present
(E2
) and then Etype
(E2
) = Any_Type
)
4232 Set_Etype
(N
, Any_Type
);
4236 -- Scalar subtype case. We have not yet enforced the static requirement
4237 -- of (RM 4.9(7)) and we don't intend to just yet, since there are cases
4238 -- of non-static attribute references (e.g. S'Digits for a non-static
4239 -- floating-point type, which we can compute at compile time).
4241 -- Note: this folding of non-static attributes is not simply a case of
4242 -- optimization. For many of the attributes affected, Gigi cannot handle
4243 -- the attribute and depends on the front end having folded them away.
4245 -- Note: although we don't require staticness at this stage, we do set
4246 -- the Static variable to record the staticness, for easy reference by
4247 -- those attributes where it matters (e.g. Succ and Pred), and also to
4248 -- be used to ensure that non-static folded things are not marked as
4249 -- being static (a check that is done right at the end).
4251 P_Root_Type
:= Root_Type
(P_Type
);
4252 P_Base_Type
:= Base_Type
(P_Type
);
4254 -- If the root type or base type is generic, then we cannot fold. This
4255 -- test is needed because subtypes of generic types are not always
4256 -- marked as being generic themselves (which seems odd???)
4258 if Is_Generic_Type
(P_Root_Type
)
4259 or else Is_Generic_Type
(P_Base_Type
)
4264 if Is_Scalar_Type
(P_Type
) then
4265 Static
:= Is_OK_Static_Subtype
(P_Type
);
4267 -- Array case. We enforce the constrained requirement of (RM 4.9(7-8))
4268 -- since we can't do anything with unconstrained arrays. In addition,
4269 -- only the First, Last and Length attributes are possibly static.
4270 -- In addition Component_Size is possibly foldable, even though it
4271 -- can never be static.
4273 -- Definite, Has_Discriminants and Type_Class are again exceptions,
4274 -- because they apply as well to unconstrained types.
4276 elsif Id
= Attribute_Definite
4278 Id
= Attribute_Has_Discriminants
4280 Id
= Attribute_Type_Class
4285 if not Is_Constrained
(P_Type
)
4286 or else (Id
/= Attribute_Component_Size
and then
4287 Id
/= Attribute_First
and then
4288 Id
/= Attribute_Last
and then
4289 Id
/= Attribute_Length
)
4295 -- The rules in (RM 4.9(7,8)) require a static array, but as in the
4296 -- scalar case, we hold off on enforcing staticness, since there are
4297 -- cases which we can fold at compile time even though they are not
4298 -- static (e.g. 'Length applied to a static index, even though other
4299 -- non-static indexes make the array type non-static). This is only
4300 -- ab optimization, but it falls out essentially free, so why not.
4301 -- Again we compute the variable Static for easy reference later
4302 -- (note that no array attributes are static in Ada 83).
4310 N
:= First_Index
(P_Type
);
4311 while Present
(N
) loop
4312 Static
:= Static
and Is_Static_Subtype
(Etype
(N
));
4318 -- Check any expressions that are present. Note that these expressions,
4319 -- depending on the particular attribute type, are either part of the
4320 -- attribute designator, or they are arguments in a case where the
4321 -- attribute reference returns a function. In the latter case, the
4322 -- rule in (RM 4.9(22)) applies and in particular requires the type
4323 -- of the expressions to be scalar in order for the attribute to be
4324 -- considered to be static.
4331 while Present
(E
) loop
4333 -- If expression is not static, then the attribute reference
4334 -- certainly is neither foldable nor static, so we can quit
4335 -- after calling Apply_Range_Check for 'Pos attributes.
4337 -- We can also quit if the expression is not of a scalar type
4340 if not Is_Static_Expression
(E
)
4341 or else not Is_Scalar_Type
(Etype
(E
))
4343 if Id
= Attribute_Pos
then
4344 if Is_Integer_Type
(Etype
(E
)) then
4345 Apply_Range_Check
(E
, Etype
(N
));
4352 -- If the expression raises a constraint error, then so does
4353 -- the attribute reference. We keep going in this case because
4354 -- we are still interested in whether the attribute reference
4355 -- is static even if it is not static.
4357 elsif Raises_Constraint_Error
(E
) then
4358 Set_Raises_Constraint_Error
(N
);
4364 if Raises_Constraint_Error
(Prefix
(N
)) then
4369 -- Deal with the case of a static attribute reference that raises
4370 -- constraint error. The Raises_Constraint_Error flag will already
4371 -- have been set, and the Static flag shows whether the attribute
4372 -- reference is static. In any case we certainly can't fold such an
4373 -- attribute reference.
4375 -- Note that the rewriting of the attribute node with the constraint
4376 -- error node is essential in this case, because otherwise Gigi might
4377 -- blow up on one of the attributes it never expects to see.
4379 -- The constraint_error node must have the type imposed by the context,
4380 -- to avoid spurious errors in the enclosing expression.
4382 if Raises_Constraint_Error
(N
) then
4384 Make_Raise_Constraint_Error
(Sloc
(N
),
4385 Reason
=> CE_Range_Check_Failed
);
4386 Set_Etype
(CE_Node
, Etype
(N
));
4387 Set_Raises_Constraint_Error
(CE_Node
);
4389 Rewrite
(N
, Relocate_Node
(CE_Node
));
4390 Set_Is_Static_Expression
(N
, Static
);
4394 -- At this point we have a potentially foldable attribute reference.
4395 -- If Static is set, then the attribute reference definitely obeys
4396 -- the requirements in (RM 4.9(7,8,22)), and it definitely can be
4397 -- folded. If Static is not set, then the attribute may or may not
4398 -- be foldable, and the individual attribute processing routines
4399 -- test Static as required in cases where it makes a difference.
4407 when Attribute_Adjacent
=>
4411 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value_R
(E2
)));
4418 when Attribute_Aft
=>
4419 Fold_Uint
(N
, UI_From_Int
(Aft_Value
));
4425 when Attribute_Alignment
=> Alignment_Block
: declare
4426 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
4429 -- Fold if alignment is set and not otherwise
4431 if Known_Alignment
(P_TypeA
) then
4432 Fold_Uint
(N
, Alignment
(P_TypeA
));
4434 end Alignment_Block
;
4440 -- Can only be folded in No_Ast_Handler case
4442 when Attribute_AST_Entry
=>
4443 if not Is_AST_Entry
(P_Entity
) then
4445 New_Occurrence_Of
(RTE
(RE_No_AST_Handler
), Loc
));
4454 -- Bit can never be folded
4456 when Attribute_Bit
=>
4463 -- Body_version can never be static
4465 when Attribute_Body_Version
=>
4472 when Attribute_Ceiling
=>
4475 Eval_Fat
.Ceiling
(P_Root_Type
, Expr_Value_R
(E1
)));
4478 --------------------
4479 -- Component_Size --
4480 --------------------
4482 when Attribute_Component_Size
=>
4483 if Component_Size
(P_Type
) /= 0 then
4484 Fold_Uint
(N
, Component_Size
(P_Type
));
4491 when Attribute_Compose
=>
4495 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)));
4502 -- Constrained is never folded for now, there may be cases that
4503 -- could be handled at compile time. to be looked at later.
4505 when Attribute_Constrained
=>
4512 when Attribute_Copy_Sign
=>
4516 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value_R
(E2
)));
4523 when Attribute_Delta
=>
4524 Fold_Ureal
(N
, Delta_Value
(P_Type
));
4530 when Attribute_Definite
=>
4535 if Is_Indefinite_Subtype
(P_Entity
) then
4536 Result
:= New_Occurrence_Of
(Standard_False
, Loc
);
4538 Result
:= New_Occurrence_Of
(Standard_True
, Loc
);
4541 Rewrite
(N
, Result
);
4542 Analyze_And_Resolve
(N
, Standard_Boolean
);
4549 when Attribute_Denorm
=>
4551 (N
, UI_From_Int
(Boolean'Pos (Denorm_On_Target
)));
4557 when Attribute_Digits
=>
4558 Fold_Uint
(N
, Digits_Value
(P_Type
));
4564 when Attribute_Emax
=>
4566 -- Ada 83 attribute is defined as (RM83 3.5.8)
4568 -- T'Emax = 4 * T'Mantissa
4570 Fold_Uint
(N
, 4 * Mantissa
);
4576 when Attribute_Enum_Rep
=>
4579 -- For an enumeration type with a non-standard representation
4580 -- use the Enumeration_Rep field of the proper constant. Note
4581 -- that this would not work for types Character/Wide_Character,
4582 -- since no real entities are created for the enumeration
4583 -- literals, but that does not matter since these two types
4584 -- do not have non-standard representations anyway.
4586 if Is_Enumeration_Type
(P_Type
)
4587 and then Has_Non_Standard_Rep
(P_Type
)
4589 Fold_Uint
(N
, Enumeration_Rep
(Expr_Value_E
(E1
)));
4591 -- For enumeration types with standard representations and all
4592 -- other cases (i.e. all integer and modular types), Enum_Rep
4593 -- is equivalent to Pos.
4596 Fold_Uint
(N
, Expr_Value
(E1
));
4604 when Attribute_Epsilon
=>
4606 -- Ada 83 attribute is defined as (RM83 3.5.8)
4608 -- T'Epsilon = 2.0**(1 - T'Mantissa)
4610 Fold_Ureal
(N
, Ureal_2
** (1 - Mantissa
));
4616 when Attribute_Exponent
=>
4619 Eval_Fat
.Exponent
(P_Root_Type
, Expr_Value_R
(E1
)));
4626 when Attribute_First
=> First_Attr
:
4630 if Compile_Time_Known_Value
(Lo_Bound
) then
4631 if Is_Real_Type
(P_Type
) then
4632 Fold_Ureal
(N
, Expr_Value_R
(Lo_Bound
));
4634 Fold_Uint
(N
, Expr_Value
(Lo_Bound
));
4643 when Attribute_Fixed_Value
=>
4650 when Attribute_Floor
=>
4653 Eval_Fat
.Floor
(P_Root_Type
, Expr_Value_R
(E1
)));
4660 when Attribute_Fore
=>
4662 Fold_Uint
(N
, UI_From_Int
(Fore_Value
));
4669 when Attribute_Fraction
=>
4672 Eval_Fat
.Fraction
(P_Root_Type
, Expr_Value_R
(E1
)));
4675 -----------------------
4676 -- Has_Discriminants --
4677 -----------------------
4679 when Attribute_Has_Discriminants
=>
4684 if Has_Discriminants
(P_Entity
) then
4685 Result
:= New_Occurrence_Of
(Standard_True
, Loc
);
4687 Result
:= New_Occurrence_Of
(Standard_False
, Loc
);
4690 Rewrite
(N
, Result
);
4691 Analyze_And_Resolve
(N
, Standard_Boolean
);
4698 when Attribute_Identity
=>
4705 -- Image is a scalar attribute, but is never static, because it is
4706 -- not a static function (having a non-scalar argument (RM 4.9(22))
4708 when Attribute_Image
=>
4715 -- Img is a scalar attribute, but is never static, because it is
4716 -- not a static function (having a non-scalar argument (RM 4.9(22))
4718 when Attribute_Img
=>
4725 when Attribute_Integer_Value
=>
4732 when Attribute_Large
=>
4734 -- For fixed-point, we use the identity:
4736 -- T'Large = (2.0**T'Mantissa - 1.0) * T'Small
4738 if Is_Fixed_Point_Type
(P_Type
) then
4740 Make_Op_Multiply
(Loc
,
4742 Make_Op_Subtract
(Loc
,
4746 Make_Real_Literal
(Loc
, Ureal_2
),
4748 Make_Attribute_Reference
(Loc
,
4750 Attribute_Name
=> Name_Mantissa
)),
4751 Right_Opnd
=> Make_Real_Literal
(Loc
, Ureal_1
)),
4754 Make_Real_Literal
(Loc
, Small_Value
(Entity
(P
)))));
4756 Analyze_And_Resolve
(N
, C_Type
);
4758 -- Floating-point (Ada 83 compatibility)
4761 -- Ada 83 attribute is defined as (RM83 3.5.8)
4763 -- T'Large = 2.0**T'Emax * (1.0 - 2.0**(-T'Mantissa))
4767 -- T'Emax = 4 * T'Mantissa
4770 Ureal_2
** (4 * Mantissa
) *
4771 (Ureal_1
- Ureal_2
** (-Mantissa
)));
4778 when Attribute_Last
=> Last
:
4782 if Compile_Time_Known_Value
(Hi_Bound
) then
4783 if Is_Real_Type
(P_Type
) then
4784 Fold_Ureal
(N
, Expr_Value_R
(Hi_Bound
));
4786 Fold_Uint
(N
, Expr_Value
(Hi_Bound
));
4795 when Attribute_Leading_Part
=>
4798 Eval_Fat
.Leading_Part
4799 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)));
4806 when Attribute_Length
=> Length
:
4810 if Compile_Time_Known_Value
(Lo_Bound
)
4811 and then Compile_Time_Known_Value
(Hi_Bound
)
4814 UI_Max
(0, 1 + (Expr_Value
(Hi_Bound
) - Expr_Value
(Lo_Bound
))));
4822 when Attribute_Machine
=>
4825 Eval_Fat
.Machine
(P_Root_Type
, Expr_Value_R
(E1
),
4833 when Attribute_Machine_Emax
=>
4834 Float_Attribute_Universal_Integer
(
4840 VAXGF_Machine_Emax
);
4846 when Attribute_Machine_Emin
=>
4847 Float_Attribute_Universal_Integer
(
4853 VAXGF_Machine_Emin
);
4855 ----------------------
4856 -- Machine_Mantissa --
4857 ----------------------
4859 when Attribute_Machine_Mantissa
=>
4860 Float_Attribute_Universal_Integer
(
4861 IEEES_Machine_Mantissa
,
4862 IEEEL_Machine_Mantissa
,
4863 IEEEX_Machine_Mantissa
,
4864 VAXFF_Machine_Mantissa
,
4865 VAXDF_Machine_Mantissa
,
4866 VAXGF_Machine_Mantissa
);
4868 -----------------------
4869 -- Machine_Overflows --
4870 -----------------------
4872 when Attribute_Machine_Overflows
=>
4874 -- Always true for fixed-point
4876 if Is_Fixed_Point_Type
(P_Type
) then
4877 Fold_Uint
(N
, True_Value
);
4879 -- Floating point case
4883 (N
, UI_From_Int
(Boolean'Pos (Machine_Overflows_On_Target
)));
4890 when Attribute_Machine_Radix
=>
4891 if Is_Fixed_Point_Type
(P_Type
) then
4892 if Is_Decimal_Fixed_Point_Type
(P_Type
)
4893 and then Machine_Radix_10
(P_Type
)
4895 Fold_Uint
(N
, Uint_10
);
4897 Fold_Uint
(N
, Uint_2
);
4900 -- All floating-point type always have radix 2
4903 Fold_Uint
(N
, Uint_2
);
4906 --------------------
4907 -- Machine_Rounds --
4908 --------------------
4910 when Attribute_Machine_Rounds
=>
4912 -- Always False for fixed-point
4914 if Is_Fixed_Point_Type
(P_Type
) then
4915 Fold_Uint
(N
, False_Value
);
4917 -- Else yield proper floating-point result
4921 (N
, UI_From_Int
(Boolean'Pos (Machine_Rounds_On_Target
)));
4928 -- Note: Machine_Size is identical to Object_Size
4930 when Attribute_Machine_Size
=> Machine_Size
: declare
4931 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
4934 if Known_Esize
(P_TypeA
) then
4935 Fold_Uint
(N
, Esize
(P_TypeA
));
4943 when Attribute_Mantissa
=>
4945 -- Fixed-point mantissa
4947 if Is_Fixed_Point_Type
(P_Type
) then
4949 -- Compile time foldable case
4951 if Compile_Time_Known_Value
(Type_Low_Bound
(P_Type
))
4953 Compile_Time_Known_Value
(Type_High_Bound
(P_Type
))
4955 -- The calculation of the obsolete Ada 83 attribute Mantissa
4956 -- is annoying, because of AI00143, quoted here:
4958 -- !question 84-01-10
4960 -- Consider the model numbers for F:
4962 -- type F is delta 1.0 range -7.0 .. 8.0;
4964 -- The wording requires that F'MANTISSA be the SMALLEST
4965 -- integer number for which each bound of the specified
4966 -- range is either a model number or lies at most small
4967 -- distant from a model number. This means F'MANTISSA
4968 -- is required to be 3 since the range -7.0 .. 7.0 fits
4969 -- in 3 signed bits, and 8 is "at most" 1.0 from a model
4970 -- number, namely, 7. Is this analysis correct? Note that
4971 -- this implies the upper bound of the range is not
4972 -- represented as a model number.
4974 -- !response 84-03-17
4976 -- The analysis is correct. The upper and lower bounds for
4977 -- a fixed point type can lie outside the range of model
4988 LBound
:= Expr_Value_R
(Type_Low_Bound
(P_Type
));
4989 UBound
:= Expr_Value_R
(Type_High_Bound
(P_Type
));
4990 Bound
:= UR_Max
(UR_Abs
(LBound
), UR_Abs
(UBound
));
4991 Max_Man
:= UR_Trunc
(Bound
/ Small_Value
(P_Type
));
4993 -- If the Bound is exactly a model number, i.e. a multiple
4994 -- of Small, then we back it off by one to get the integer
4995 -- value that must be representable.
4997 if Small_Value
(P_Type
) * Max_Man
= Bound
then
4998 Max_Man
:= Max_Man
- 1;
5001 -- Now find corresponding size = Mantissa value
5004 while 2 ** Siz
< Max_Man
loop
5012 -- The case of dynamic bounds cannot be evaluated at compile
5013 -- time. Instead we use a runtime routine (see Exp_Attr).
5018 -- Floating-point Mantissa
5021 Fold_Uint
(N
, Mantissa
);
5028 when Attribute_Max
=> Max
:
5030 if Is_Real_Type
(P_Type
) then
5031 Fold_Ureal
(N
, UR_Max
(Expr_Value_R
(E1
), Expr_Value_R
(E2
)));
5033 Fold_Uint
(N
, UI_Max
(Expr_Value
(E1
), Expr_Value
(E2
)));
5037 ----------------------------------
5038 -- Max_Size_In_Storage_Elements --
5039 ----------------------------------
5041 -- Max_Size_In_Storage_Elements is simply the Size rounded up to a
5042 -- Storage_Unit boundary. We can fold any cases for which the size
5043 -- is known by the front end.
5045 when Attribute_Max_Size_In_Storage_Elements
=>
5046 if Known_Esize
(P_Type
) then
5048 (Esize
(P_Type
) + System_Storage_Unit
- 1) /
5049 System_Storage_Unit
);
5052 --------------------
5053 -- Mechanism_Code --
5054 --------------------
5056 when Attribute_Mechanism_Code
=>
5060 Mech
: Mechanism_Type
;
5064 Mech
:= Mechanism
(P_Entity
);
5067 Val
:= UI_To_Int
(Expr_Value
(E1
));
5069 Formal
:= First_Formal
(P_Entity
);
5070 for J
in 1 .. Val
- 1 loop
5071 Next_Formal
(Formal
);
5073 Mech
:= Mechanism
(Formal
);
5077 Fold_Uint
(N
, UI_From_Int
(Int
(-Mech
)));
5085 when Attribute_Min
=> Min
:
5087 if Is_Real_Type
(P_Type
) then
5088 Fold_Ureal
(N
, UR_Min
(Expr_Value_R
(E1
), Expr_Value_R
(E2
)));
5090 Fold_Uint
(N
, UI_Min
(Expr_Value
(E1
), Expr_Value
(E2
)));
5098 when Attribute_Model
=>
5101 Eval_Fat
.Model
(P_Root_Type
, Expr_Value_R
(E1
)));
5108 when Attribute_Model_Emin
=>
5109 Float_Attribute_Universal_Integer
(
5121 when Attribute_Model_Epsilon
=>
5122 Float_Attribute_Universal_Real
(
5123 IEEES_Model_Epsilon
'Universal_Literal_String,
5124 IEEEL_Model_Epsilon
'Universal_Literal_String,
5125 IEEEX_Model_Epsilon
'Universal_Literal_String,
5126 VAXFF_Model_Epsilon
'Universal_Literal_String,
5127 VAXDF_Model_Epsilon
'Universal_Literal_String,
5128 VAXGF_Model_Epsilon
'Universal_Literal_String);
5130 --------------------
5131 -- Model_Mantissa --
5132 --------------------
5134 when Attribute_Model_Mantissa
=>
5135 Float_Attribute_Universal_Integer
(
5136 IEEES_Model_Mantissa
,
5137 IEEEL_Model_Mantissa
,
5138 IEEEX_Model_Mantissa
,
5139 VAXFF_Model_Mantissa
,
5140 VAXDF_Model_Mantissa
,
5141 VAXGF_Model_Mantissa
);
5147 when Attribute_Model_Small
=>
5148 Float_Attribute_Universal_Real
(
5149 IEEES_Model_Small
'Universal_Literal_String,
5150 IEEEL_Model_Small
'Universal_Literal_String,
5151 IEEEX_Model_Small
'Universal_Literal_String,
5152 VAXFF_Model_Small
'Universal_Literal_String,
5153 VAXDF_Model_Small
'Universal_Literal_String,
5154 VAXGF_Model_Small
'Universal_Literal_String);
5160 when Attribute_Modulus
=>
5161 Fold_Uint
(N
, Modulus
(P_Type
));
5163 --------------------
5164 -- Null_Parameter --
5165 --------------------
5167 -- Cannot fold, we know the value sort of, but the whole point is
5168 -- that there is no way to talk about this imaginary value except
5169 -- by using the attribute, so we leave it the way it is.
5171 when Attribute_Null_Parameter
=>
5178 -- The Object_Size attribute for a type returns the Esize of the
5179 -- type and can be folded if this value is known.
5181 when Attribute_Object_Size
=> Object_Size
: declare
5182 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
5185 if Known_Esize
(P_TypeA
) then
5186 Fold_Uint
(N
, Esize
(P_TypeA
));
5190 -------------------------
5191 -- Passed_By_Reference --
5192 -------------------------
5194 -- Scalar types are never passed by reference
5196 when Attribute_Passed_By_Reference
=>
5197 Fold_Uint
(N
, False_Value
);
5203 when Attribute_Pos
=>
5204 Fold_Uint
(N
, Expr_Value
(E1
));
5210 when Attribute_Pred
=> Pred
:
5214 -- Floating-point case. For now, do not fold this, since we
5215 -- don't know how to do it right (see fixed bug 3512-001 ???)
5217 if Is_Floating_Point_Type
(P_Type
) then
5219 Eval_Fat
.Pred
(P_Root_Type
, Expr_Value_R
(E1
)));
5223 elsif Is_Fixed_Point_Type
(P_Type
) then
5225 Expr_Value_R
(E1
) - Small_Value
(P_Type
));
5227 -- Modular integer case (wraps)
5229 elsif Is_Modular_Integer_Type
(P_Type
) then
5230 Fold_Uint
(N
, (Expr_Value
(E1
) - 1) mod Modulus
(P_Type
));
5232 -- Other scalar cases
5235 pragma Assert
(Is_Scalar_Type
(P_Type
));
5237 if Is_Enumeration_Type
(P_Type
)
5238 and then Expr_Value
(E1
) =
5239 Expr_Value
(Type_Low_Bound
(P_Base_Type
))
5241 Apply_Compile_Time_Constraint_Error
5242 (N
, "Pred of type''First", CE_Overflow_Check_Failed
);
5247 Fold_Uint
(N
, Expr_Value
(E1
) - 1);
5256 -- No processing required, because by this stage, Range has been
5257 -- replaced by First .. Last, so this branch can never be taken.
5259 when Attribute_Range
=>
5260 raise Program_Error
;
5266 when Attribute_Range_Length
=>
5269 if Compile_Time_Known_Value
(Hi_Bound
)
5270 and then Compile_Time_Known_Value
(Lo_Bound
)
5274 (0, Expr_Value
(Hi_Bound
) - Expr_Value
(Lo_Bound
) + 1));
5281 when Attribute_Remainder
=>
5285 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value_R
(E2
)));
5292 when Attribute_Round
=> Round
:
5299 -- First we get the (exact result) in units of small
5301 Sr
:= Expr_Value_R
(E1
) / Small_Value
(C_Type
);
5303 -- Now round that exactly to an integer
5305 Si
:= UR_To_Uint
(Sr
);
5307 -- Finally the result is obtained by converting back to real
5309 Fold_Ureal
(N
, Si
* Small_Value
(C_Type
));
5317 when Attribute_Rounding
=>
5320 Eval_Fat
.Rounding
(P_Root_Type
, Expr_Value_R
(E1
)));
5327 when Attribute_Safe_Emax
=>
5328 Float_Attribute_Universal_Integer
(
5340 when Attribute_Safe_First
=>
5341 Float_Attribute_Universal_Real
(
5342 IEEES_Safe_First
'Universal_Literal_String,
5343 IEEEL_Safe_First
'Universal_Literal_String,
5344 IEEEX_Safe_First
'Universal_Literal_String,
5345 VAXFF_Safe_First
'Universal_Literal_String,
5346 VAXDF_Safe_First
'Universal_Literal_String,
5347 VAXGF_Safe_First
'Universal_Literal_String);
5353 when Attribute_Safe_Large
=>
5354 if Is_Fixed_Point_Type
(P_Type
) then
5355 Fold_Ureal
(N
, Expr_Value_R
(Type_High_Bound
(P_Base_Type
)));
5357 Float_Attribute_Universal_Real
(
5358 IEEES_Safe_Large
'Universal_Literal_String,
5359 IEEEL_Safe_Large
'Universal_Literal_String,
5360 IEEEX_Safe_Large
'Universal_Literal_String,
5361 VAXFF_Safe_Large
'Universal_Literal_String,
5362 VAXDF_Safe_Large
'Universal_Literal_String,
5363 VAXGF_Safe_Large
'Universal_Literal_String);
5370 when Attribute_Safe_Last
=>
5371 Float_Attribute_Universal_Real
(
5372 IEEES_Safe_Last
'Universal_Literal_String,
5373 IEEEL_Safe_Last
'Universal_Literal_String,
5374 IEEEX_Safe_Last
'Universal_Literal_String,
5375 VAXFF_Safe_Last
'Universal_Literal_String,
5376 VAXDF_Safe_Last
'Universal_Literal_String,
5377 VAXGF_Safe_Last
'Universal_Literal_String);
5383 when Attribute_Safe_Small
=>
5385 -- In Ada 95, the old Ada 83 attribute Safe_Small is redundant
5386 -- for fixed-point, since is the same as Small, but we implement
5387 -- it for backwards compatibility.
5389 if Is_Fixed_Point_Type
(P_Type
) then
5390 Fold_Ureal
(N
, Small_Value
(P_Type
));
5392 -- Ada 83 Safe_Small for floating-point cases
5395 Float_Attribute_Universal_Real
(
5396 IEEES_Safe_Small
'Universal_Literal_String,
5397 IEEEL_Safe_Small
'Universal_Literal_String,
5398 IEEEX_Safe_Small
'Universal_Literal_String,
5399 VAXFF_Safe_Small
'Universal_Literal_String,
5400 VAXDF_Safe_Small
'Universal_Literal_String,
5401 VAXGF_Safe_Small
'Universal_Literal_String);
5408 when Attribute_Scale
=>
5409 Fold_Uint
(N
, Scale_Value
(P_Type
));
5415 when Attribute_Scaling
=>
5419 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)));
5426 when Attribute_Signed_Zeros
=>
5428 (N
, UI_From_Int
(Boolean'Pos (Signed_Zeros_On_Target
)));
5434 -- Size attribute returns the RM size. All scalar types can be folded,
5435 -- as well as any types for which the size is known by the front end,
5436 -- including any type for which a size attribute is specified.
5438 when Attribute_Size | Attribute_VADS_Size
=> Size
: declare
5439 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
5442 if RM_Size
(P_TypeA
) /= Uint_0
then
5446 if (Id
= Attribute_VADS_Size
or else Use_VADS_Size
) then
5449 S
: constant Node_Id
:= Size_Clause
(P_TypeA
);
5452 -- If a size clause applies, then use the size from it.
5453 -- This is one of the rare cases where we can use the
5454 -- Size_Clause field for a subtype when Has_Size_Clause
5455 -- is False. Consider:
5457 -- type x is range 1 .. 64;
5458 -- for x'size use 12;
5459 -- subtype y is x range 0 .. 3;
5461 -- Here y has a size clause inherited from x, but normally
5462 -- it does not apply, and y'size is 2. However, y'VADS_Size
5463 -- is indeed 12 and not 2.
5466 and then Is_OK_Static_Expression
(Expression
(S
))
5468 Fold_Uint
(N
, Expr_Value
(Expression
(S
)));
5470 -- If no size is specified, then we simply use the object
5471 -- size in the VADS_Size case (e.g. Natural'Size is equal
5472 -- to Integer'Size, not one less).
5475 Fold_Uint
(N
, Esize
(P_TypeA
));
5479 -- Normal case (Size) in which case we want the RM_Size
5482 Fold_Uint
(N
, RM_Size
(P_TypeA
));
5491 when Attribute_Small
=>
5493 -- The floating-point case is present only for Ada 83 compatibility.
5494 -- Note that strictly this is an illegal addition, since we are
5495 -- extending an Ada 95 defined attribute, but we anticipate an
5496 -- ARG ruling that will permit this.
5498 if Is_Floating_Point_Type
(P_Type
) then
5500 -- Ada 83 attribute is defined as (RM83 3.5.8)
5502 -- T'Small = 2.0**(-T'Emax - 1)
5506 -- T'Emax = 4 * T'Mantissa
5508 Fold_Ureal
(N
, Ureal_2
** ((-(4 * Mantissa
)) - 1));
5510 -- Normal Ada 95 fixed-point case
5513 Fold_Ureal
(N
, Small_Value
(P_Type
));
5520 when Attribute_Succ
=> Succ
:
5524 -- Floating-point case. For now, do not fold this, since we
5525 -- don't know how to do it right (see fixed bug 3512-001 ???)
5527 if Is_Floating_Point_Type
(P_Type
) then
5529 Eval_Fat
.Succ
(P_Root_Type
, Expr_Value_R
(E1
)));
5533 elsif Is_Fixed_Point_Type
(P_Type
) then
5535 Expr_Value_R
(E1
) + Small_Value
(P_Type
));
5537 -- Modular integer case (wraps)
5539 elsif Is_Modular_Integer_Type
(P_Type
) then
5540 Fold_Uint
(N
, (Expr_Value
(E1
) + 1) mod Modulus
(P_Type
));
5542 -- Other scalar cases
5545 pragma Assert
(Is_Scalar_Type
(P_Type
));
5547 if Is_Enumeration_Type
(P_Type
)
5548 and then Expr_Value
(E1
) =
5549 Expr_Value
(Type_High_Bound
(P_Base_Type
))
5551 Apply_Compile_Time_Constraint_Error
5552 (N
, "Succ of type''Last", CE_Overflow_Check_Failed
);
5556 Fold_Uint
(N
, Expr_Value
(E1
) + 1);
5566 when Attribute_Truncation
=>
5569 Eval_Fat
.Truncation
(P_Root_Type
, Expr_Value_R
(E1
)));
5576 when Attribute_Type_Class
=> Type_Class
: declare
5577 Typ
: constant Entity_Id
:= Underlying_Type
(P_Base_Type
);
5581 if Is_RTE
(P_Root_Type
, RE_Address
) then
5582 Id
:= RE_Type_Class_Address
;
5584 elsif Is_Enumeration_Type
(Typ
) then
5585 Id
:= RE_Type_Class_Enumeration
;
5587 elsif Is_Integer_Type
(Typ
) then
5588 Id
:= RE_Type_Class_Integer
;
5590 elsif Is_Fixed_Point_Type
(Typ
) then
5591 Id
:= RE_Type_Class_Fixed_Point
;
5593 elsif Is_Floating_Point_Type
(Typ
) then
5594 Id
:= RE_Type_Class_Floating_Point
;
5596 elsif Is_Array_Type
(Typ
) then
5597 Id
:= RE_Type_Class_Array
;
5599 elsif Is_Record_Type
(Typ
) then
5600 Id
:= RE_Type_Class_Record
;
5602 elsif Is_Access_Type
(Typ
) then
5603 Id
:= RE_Type_Class_Access
;
5605 elsif Is_Enumeration_Type
(Typ
) then
5606 Id
:= RE_Type_Class_Enumeration
;
5608 elsif Is_Task_Type
(Typ
) then
5609 Id
:= RE_Type_Class_Task
;
5611 -- We treat protected types like task types. It would make more
5612 -- sense to have another enumeration value, but after all the
5613 -- whole point of this feature is to be exactly DEC compatible,
5614 -- and changing the type Type_Clas would not meet this requirement.
5616 elsif Is_Protected_Type
(Typ
) then
5617 Id
:= RE_Type_Class_Task
;
5619 -- Not clear if there are any other possibilities, but if there
5620 -- are, then we will treat them as the address case.
5623 Id
:= RE_Type_Class_Address
;
5626 Rewrite
(N
, New_Occurrence_Of
(RTE
(Id
), Loc
));
5630 -----------------------
5631 -- Unbiased_Rounding --
5632 -----------------------
5634 when Attribute_Unbiased_Rounding
=>
5637 Eval_Fat
.Unbiased_Rounding
(P_Root_Type
, Expr_Value_R
(E1
)));
5644 -- Processing is shared with Size
5650 when Attribute_Val
=> Val
:
5653 if Expr_Value
(E1
) < Expr_Value
(Type_Low_Bound
(P_Base_Type
))
5655 Expr_Value
(E1
) > Expr_Value
(Type_High_Bound
(P_Base_Type
))
5657 Apply_Compile_Time_Constraint_Error
5658 (N
, "Val expression out of range", CE_Range_Check_Failed
);
5662 Fold_Uint
(N
, Expr_Value
(E1
));
5671 -- The Value_Size attribute for a type returns the RM size of the
5672 -- type. This an always be folded for scalar types, and can also
5673 -- be folded for non-scalar types if the size is set.
5675 when Attribute_Value_Size
=> Value_Size
: declare
5676 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
5679 if RM_Size
(P_TypeA
) /= Uint_0
then
5680 Fold_Uint
(N
, RM_Size
(P_TypeA
));
5689 -- Version can never be static
5691 when Attribute_Version
=>
5698 -- Wide_Image is a scalar attribute, but is never static, because it
5699 -- is not a static function (having a non-scalar argument (RM 4.9(22))
5701 when Attribute_Wide_Image
=>
5708 -- Processing for Wide_Width is combined with Width
5714 -- This processing also handles the case of Wide_Width
5716 when Attribute_Width | Attribute_Wide_Width
=> Width
:
5720 -- Floating-point types
5722 if Is_Floating_Point_Type
(P_Type
) then
5724 -- Width is zero for a null range (RM 3.5 (38))
5726 if Expr_Value_R
(Type_High_Bound
(P_Type
)) <
5727 Expr_Value_R
(Type_Low_Bound
(P_Type
))
5729 Fold_Uint
(N
, Uint_0
);
5732 -- For floating-point, we have +N.dddE+nnn where length
5733 -- of ddd is determined by type'Digits - 1, but is one
5734 -- if Digits is one (RM 3.5 (33)).
5736 -- nnn is set to 2 for Short_Float and Float (32 bit
5737 -- floats), and 3 for Long_Float and Long_Long_Float.
5738 -- This is not quite right, but is good enough.
5742 Int
'Max (2, UI_To_Int
(Digits_Value
(P_Type
)));
5745 if Esize
(P_Type
) <= 32 then
5751 Fold_Uint
(N
, UI_From_Int
(Len
));
5755 -- Fixed-point types
5757 elsif Is_Fixed_Point_Type
(P_Type
) then
5759 -- Width is zero for a null range (RM 3.5 (38))
5761 if Expr_Value
(Type_High_Bound
(P_Type
)) <
5762 Expr_Value
(Type_Low_Bound
(P_Type
))
5764 Fold_Uint
(N
, Uint_0
);
5766 -- The non-null case depends on the specific real type
5769 -- For fixed-point type width is Fore + 1 + Aft (RM 3.5(34))
5771 Fold_Uint
(N
, UI_From_Int
(Fore_Value
+ 1 + Aft_Value
));
5778 R
: constant Entity_Id
:= Root_Type
(P_Type
);
5779 Lo
: constant Uint
:=
5780 Expr_Value
(Type_Low_Bound
(P_Type
));
5781 Hi
: constant Uint
:=
5782 Expr_Value
(Type_High_Bound
(P_Type
));
5795 -- Width for types derived from Standard.Character
5796 -- and Standard.Wide_Character.
5798 elsif R
= Standard_Character
5799 or else R
= Standard_Wide_Character
5803 -- Set W larger if needed
5805 for J
in UI_To_Int
(Lo
) .. UI_To_Int
(Hi
) loop
5807 -- Assume all wide-character escape sequences are
5808 -- same length, so we can quit when we reach one.
5811 if Id
= Attribute_Wide_Width
then
5812 W
:= Int
'Max (W
, 3);
5815 W
:= Int
'Max (W
, Length_Wide
);
5820 C
:= Character'Val (J
);
5822 -- Test for all cases where Character'Image
5823 -- yields an image that is longer than three
5824 -- characters. First the cases of Reserved_xxx
5825 -- names (length = 12).
5828 when Reserved_128 | Reserved_129 |
5829 Reserved_132 | Reserved_153
5833 when BS | HT | LF | VT | FF | CR |
5834 SO | SI | EM | FS | GS | RS |
5835 US | RI | MW | ST | PM
5839 when NUL | SOH | STX | ETX | EOT |
5840 ENQ | ACK | BEL | DLE | DC1 |
5841 DC2 | DC3 | DC4 | NAK | SYN |
5842 ETB | CAN | SUB | ESC | DEL |
5843 BPH | NBH | NEL | SSA | ESA |
5844 HTS | HTJ | VTS | PLD | PLU |
5845 SS2 | SS3 | DCS | PU1 | PU2 |
5846 STS | CCH | SPA | EPA | SOS |
5847 SCI | CSI | OSC | APC
5851 when Space
.. Tilde |
5852 No_Break_Space
.. LC_Y_Diaeresis
5858 W
:= Int
'Max (W
, Wt
);
5862 -- Width for types derived from Standard.Boolean
5864 elsif R
= Standard_Boolean
then
5871 -- Width for integer types
5873 elsif Is_Integer_Type
(P_Type
) then
5874 T
:= UI_Max
(abs Lo
, abs Hi
);
5882 -- Only remaining possibility is user declared enum type
5885 pragma Assert
(Is_Enumeration_Type
(P_Type
));
5888 L
:= First_Literal
(P_Type
);
5890 while Present
(L
) loop
5892 -- Only pay attention to in range characters
5894 if Lo
<= Enumeration_Pos
(L
)
5895 and then Enumeration_Pos
(L
) <= Hi
5897 -- For Width case, use decoded name
5899 if Id
= Attribute_Width
then
5900 Get_Decoded_Name_String
(Chars
(L
));
5901 Wt
:= Nat
(Name_Len
);
5903 -- For Wide_Width, use encoded name, and then
5904 -- adjust for the encoding.
5907 Get_Name_String
(Chars
(L
));
5909 -- Character literals are always of length 3
5911 if Name_Buffer
(1) = 'Q' then
5914 -- Otherwise loop to adjust for upper/wide chars
5917 Wt
:= Nat
(Name_Len
);
5919 for J
in 1 .. Name_Len
loop
5920 if Name_Buffer
(J
) = 'U' then
5922 elsif Name_Buffer
(J
) = 'W' then
5929 W
:= Int
'Max (W
, Wt
);
5936 Fold_Uint
(N
, UI_From_Int
(W
));
5942 -- The following attributes can never be folded, and furthermore we
5943 -- should not even have entered the case statement for any of these.
5944 -- Note that in some cases, the values have already been folded as
5945 -- a result of the processing in Analyze_Attribute.
5947 when Attribute_Abort_Signal |
5950 Attribute_Address_Size |
5951 Attribute_Asm_Input |
5952 Attribute_Asm_Output |
5954 Attribute_Bit_Order |
5955 Attribute_Bit_Position |
5956 Attribute_Callable |
5959 Attribute_Code_Address |
5961 Attribute_Default_Bit_Order |
5962 Attribute_Elaborated |
5963 Attribute_Elab_Body |
5964 Attribute_Elab_Spec |
5965 Attribute_External_Tag |
5966 Attribute_First_Bit |
5968 Attribute_Last_Bit |
5969 Attribute_Maximum_Alignment |
5971 Attribute_Partition_ID |
5972 Attribute_Position |
5974 Attribute_Storage_Pool |
5975 Attribute_Storage_Size |
5976 Attribute_Storage_Unit |
5978 Attribute_Terminated |
5979 Attribute_To_Address |
5980 Attribute_UET_Address |
5981 Attribute_Unchecked_Access |
5982 Attribute_Universal_Literal_String |
5983 Attribute_Unrestricted_Access |
5986 Attribute_Wchar_T_Size |
5987 Attribute_Wide_Value |
5988 Attribute_Word_Size |
5991 raise Program_Error
;
5995 -- At the end of the case, one more check. If we did a static evaluation
5996 -- so that the result is now a literal, then set Is_Static_Expression
5997 -- in the constant only if the prefix type is a static subtype. For
5998 -- non-static subtypes, the folding is still OK, but not static.
6000 if Nkind
(N
) = N_Integer_Literal
6001 or else Nkind
(N
) = N_Real_Literal
6002 or else Nkind
(N
) = N_Character_Literal
6003 or else Nkind
(N
) = N_String_Literal
6004 or else (Is_Entity_Name
(N
)
6005 and then Ekind
(Entity
(N
)) = E_Enumeration_Literal
)
6007 Set_Is_Static_Expression
(N
, Static
);
6009 -- If this is still an attribute reference, then it has not been folded
6010 -- and that means that its expressions are in a non-static context.
6012 elsif Nkind
(N
) = N_Attribute_Reference
then
6015 -- Note: the else case not covered here are odd cases where the
6016 -- processing has transformed the attribute into something other
6017 -- than a constant. Nothing more to do in such cases.
6025 ------------------------------
6026 -- Is_Anonymous_Tagged_Base --
6027 ------------------------------
6029 function Is_Anonymous_Tagged_Base
6036 Anon
= Current_Scope
6037 and then Is_Itype
(Anon
)
6038 and then Associated_Node_For_Itype
(Anon
) = Parent
(Typ
);
6039 end Is_Anonymous_Tagged_Base
;
6041 -----------------------
6042 -- Resolve_Attribute --
6043 -----------------------
6045 procedure Resolve_Attribute
(N
: Node_Id
; Typ
: Entity_Id
) is
6046 Loc
: constant Source_Ptr
:= Sloc
(N
);
6047 P
: constant Node_Id
:= Prefix
(N
);
6048 Aname
: constant Name_Id
:= Attribute_Name
(N
);
6049 Attr_Id
: constant Attribute_Id
:= Get_Attribute_Id
(Aname
);
6050 Index
: Interp_Index
;
6052 Btyp
: Entity_Id
:= Base_Type
(Typ
);
6053 Nom_Subt
: Entity_Id
;
6056 -- If error during analysis, no point in continuing, except for
6057 -- array types, where we get better recovery by using unconstrained
6058 -- indices than nothing at all (see Check_Array_Type).
6061 and then Attr_Id
/= Attribute_First
6062 and then Attr_Id
/= Attribute_Last
6063 and then Attr_Id
/= Attribute_Length
6064 and then Attr_Id
/= Attribute_Range
6069 -- If attribute was universal type, reset to actual type
6071 if Etype
(N
) = Universal_Integer
6072 or else Etype
(N
) = Universal_Real
6077 -- Remaining processing depends on attribute
6085 -- For access attributes, if the prefix denotes an entity, it is
6086 -- interpreted as a name, never as a call. It may be overloaded,
6087 -- in which case resolution uses the profile of the context type.
6088 -- Otherwise prefix must be resolved.
6090 when Attribute_Access
6091 | Attribute_Unchecked_Access
6092 | Attribute_Unrestricted_Access
=>
6094 if Is_Variable
(P
) then
6095 Note_Possible_Modification
(P
);
6098 if Is_Entity_Name
(P
) then
6100 if Is_Overloaded
(P
) then
6101 Get_First_Interp
(P
, Index
, It
);
6103 while Present
(It
.Nam
) loop
6105 if Type_Conformant
(Designated_Type
(Typ
), It
.Nam
) then
6106 Set_Entity
(P
, It
.Nam
);
6108 -- The prefix is definitely NOT overloaded anymore
6109 -- at this point, so we reset the Is_Overloaded
6110 -- flag to avoid any confusion when reanalyzing
6113 Set_Is_Overloaded
(P
, False);
6114 Generate_Reference
(Entity
(P
), P
);
6118 Get_Next_Interp
(Index
, It
);
6121 -- If it is a subprogram name or a type, there is nothing
6124 elsif not Is_Overloadable
(Entity
(P
))
6125 and then not Is_Type
(Entity
(P
))
6127 Resolve
(P
, Etype
(P
));
6130 if not Is_Entity_Name
(P
) then
6133 elsif Is_Abstract
(Entity
(P
))
6134 and then Is_Overloadable
(Entity
(P
))
6136 Error_Msg_Name_1
:= Aname
;
6137 Error_Msg_N
("prefix of % attribute cannot be abstract", P
);
6138 Set_Etype
(N
, Any_Type
);
6140 elsif Convention
(Entity
(P
)) = Convention_Intrinsic
then
6141 Error_Msg_Name_1
:= Aname
;
6143 if Ekind
(Entity
(P
)) = E_Enumeration_Literal
then
6145 ("prefix of % attribute cannot be enumeration literal",
6149 ("prefix of % attribute cannot be intrinsic", P
);
6152 Set_Etype
(N
, Any_Type
);
6155 -- Assignments, return statements, components of aggregates,
6156 -- generic instantiations will require convention checks if
6157 -- the type is an access to subprogram. Given that there will
6158 -- also be accessibility checks on those, this is where the
6159 -- checks can eventually be centralized ???
6161 if Ekind
(Btyp
) = E_Access_Subprogram_Type
then
6162 if Convention
(Btyp
) /= Convention
(Entity
(P
)) then
6164 ("subprogram has invalid convention for context", P
);
6167 Check_Subtype_Conformant
6168 (New_Id
=> Entity
(P
),
6169 Old_Id
=> Designated_Type
(Btyp
),
6173 if Attr_Id
= Attribute_Unchecked_Access
then
6174 Error_Msg_Name_1
:= Aname
;
6176 ("attribute% cannot be applied to a subprogram", P
);
6178 elsif Aname
= Name_Unrestricted_Access
then
6179 null; -- Nothing to check
6181 -- Check the static accessibility rule of 3.10.2(32)
6183 elsif Attr_Id
= Attribute_Access
6184 and then Subprogram_Access_Level
(Entity
(P
))
6185 > Type_Access_Level
(Btyp
)
6187 if not In_Instance_Body
then
6189 ("subprogram must not be deeper than access type",
6192 Warn_On_Instance
:= True;
6194 ("subprogram must not be deeper than access type?",
6197 ("Constraint_Error will be raised ?", P
);
6198 Set_Raises_Constraint_Error
(N
);
6199 Warn_On_Instance
:= False;
6202 -- Check the restriction of 3.10.2(32) that disallows
6203 -- the type of the access attribute to be declared
6204 -- outside a generic body when the attribute occurs
6205 -- within that generic body.
6207 elsif Enclosing_Generic_Body
(Entity
(P
))
6208 /= Enclosing_Generic_Body
(Btyp
)
6211 ("access type must not be outside generic body", P
);
6215 -- if this is a renaming, an inherited operation, or a
6216 -- subprogram instance, use the original entity.
6218 if Is_Entity_Name
(P
)
6219 and then Is_Overloadable
(Entity
(P
))
6220 and then Present
(Alias
(Entity
(P
)))
6223 New_Occurrence_Of
(Alias
(Entity
(P
)), Sloc
(P
)));
6226 elsif Nkind
(P
) = N_Selected_Component
6227 and then Is_Overloadable
(Entity
(Selector_Name
(P
)))
6229 -- Protected operation. If operation is overloaded, must
6230 -- disambiguate. Prefix that denotes protected object itself
6231 -- is resolved with its own type.
6233 if Attr_Id
= Attribute_Unchecked_Access
then
6234 Error_Msg_Name_1
:= Aname
;
6236 ("attribute% cannot be applied to protected operation", P
);
6239 Resolve
(Prefix
(P
), Etype
(Prefix
(P
)));
6240 Generate_Reference
(Entity
(Selector_Name
(P
)), P
);
6242 elsif Is_Overloaded
(P
) then
6244 -- Use the designated type of the context to disambiguate.
6246 Index
: Interp_Index
;
6249 Get_First_Interp
(P
, Index
, It
);
6251 while Present
(It
.Typ
) loop
6252 if Covers
(Designated_Type
(Typ
), It
.Typ
) then
6253 Resolve
(P
, It
.Typ
);
6257 Get_Next_Interp
(Index
, It
);
6261 Resolve
(P
, Etype
(P
));
6264 -- X'Access is illegal if X denotes a constant and the access
6265 -- type is access-to-variable. Same for 'Unchecked_Access.
6266 -- The rule does not apply to 'Unrestricted_Access.
6268 if not (Ekind
(Btyp
) = E_Access_Subprogram_Type
6269 or else (Is_Record_Type
(Btyp
) and then
6270 Present
(Corresponding_Remote_Type
(Btyp
)))
6271 or else Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
6272 or else Is_Access_Constant
(Btyp
)
6273 or else Is_Variable
(P
)
6274 or else Attr_Id
= Attribute_Unrestricted_Access
)
6276 if Comes_From_Source
(N
) then
6277 Error_Msg_N
("access-to-variable designates constant", P
);
6281 if (Attr_Id
= Attribute_Access
6283 Attr_Id
= Attribute_Unchecked_Access
)
6284 and then (Ekind
(Btyp
) = E_General_Access_Type
6285 or else Ekind
(Btyp
) = E_Anonymous_Access_Type
)
6287 if Is_Dependent_Component_Of_Mutable_Object
(P
) then
6289 ("illegal attribute for discriminant-dependent component",
6293 -- Check the static matching rule of 3.10.2(27). The
6294 -- nominal subtype of the prefix must statically
6295 -- match the designated type.
6297 Nom_Subt
:= Etype
(P
);
6299 if Is_Constr_Subt_For_U_Nominal
(Nom_Subt
) then
6300 Nom_Subt
:= Etype
(Nom_Subt
);
6303 if Is_Tagged_Type
(Designated_Type
(Typ
)) then
6305 -- If the attribute is in the context of an access
6306 -- parameter, then the prefix is allowed to be of
6307 -- the class-wide type (by AI-127).
6309 if Ekind
(Typ
) = E_Anonymous_Access_Type
then
6310 if not Covers
(Designated_Type
(Typ
), Nom_Subt
)
6311 and then not Covers
(Nom_Subt
, Designated_Type
(Typ
))
6317 Desig
:= Designated_Type
(Typ
);
6319 if Is_Class_Wide_Type
(Desig
) then
6320 Desig
:= Etype
(Desig
);
6323 if Is_Anonymous_Tagged_Base
(Nom_Subt
, Desig
) then
6328 ("type of prefix: & not compatible",
6331 ("\with &, the expected designated type",
6332 P
, Designated_Type
(Typ
));
6337 elsif not Covers
(Designated_Type
(Typ
), Nom_Subt
)
6339 (not Is_Class_Wide_Type
(Designated_Type
(Typ
))
6340 and then Is_Class_Wide_Type
(Nom_Subt
))
6343 ("type of prefix: & is not covered", P
, Nom_Subt
);
6345 ("\by &, the expected designated type" &
6346 " ('R'M 3.10.2 (27))", P
, Designated_Type
(Typ
));
6349 if Is_Class_Wide_Type
(Designated_Type
(Typ
))
6350 and then Has_Discriminants
(Etype
(Designated_Type
(Typ
)))
6351 and then Is_Constrained
(Etype
(Designated_Type
(Typ
)))
6352 and then Designated_Type
(Typ
) /= Nom_Subt
6354 Apply_Discriminant_Check
6355 (N
, Etype
(Designated_Type
(Typ
)));
6358 elsif not Subtypes_Statically_Match
6359 (Designated_Type
(Typ
), Nom_Subt
)
6361 not (Has_Discriminants
(Designated_Type
(Typ
))
6362 and then not Is_Constrained
(Designated_Type
(Typ
)))
6365 ("object subtype must statically match "
6366 & "designated subtype", P
);
6368 if Is_Entity_Name
(P
)
6369 and then Is_Array_Type
(Designated_Type
(Typ
))
6373 D
: constant Node_Id
:= Declaration_Node
(Entity
(P
));
6376 Error_Msg_N
("aliased object has explicit bounds?",
6378 Error_Msg_N
("\declare without bounds"
6379 & " (and with explicit initialization)?", D
);
6380 Error_Msg_N
("\for use with unconstrained access?", D
);
6385 -- Check the static accessibility rule of 3.10.2(28).
6386 -- Note that this check is not performed for the
6387 -- case of an anonymous access type, since the access
6388 -- attribute is always legal in such a context.
6390 if Attr_Id
/= Attribute_Unchecked_Access
6391 and then Object_Access_Level
(P
) > Type_Access_Level
(Btyp
)
6392 and then Ekind
(Btyp
) = E_General_Access_Type
6394 -- In an instance, this is a runtime check, but one we
6395 -- know will fail, so generate an appropriate warning.
6397 if In_Instance_Body
then
6399 ("?non-local pointer cannot point to local object", P
);
6401 ("?Program_Error will be raised at run time", P
);
6403 Make_Raise_Program_Error
(Loc
,
6404 Reason
=> PE_Accessibility_Check_Failed
));
6410 ("non-local pointer cannot point to local object", P
);
6412 if Is_Record_Type
(Current_Scope
)
6413 and then (Nkind
(Parent
(N
)) =
6414 N_Discriminant_Association
6416 Nkind
(Parent
(N
)) =
6417 N_Index_Or_Discriminant_Constraint
)
6420 Indic
: Node_Id
:= Parent
(Parent
(N
));
6423 while Present
(Indic
)
6424 and then Nkind
(Indic
) /= N_Subtype_Indication
6426 Indic
:= Parent
(Indic
);
6429 if Present
(Indic
) then
6431 ("\use an access definition for" &
6432 " the access discriminant of&", N
,
6433 Entity
(Subtype_Mark
(Indic
)));
6441 if Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
6442 and then Is_Entity_Name
(P
)
6443 and then not Is_Protected_Type
(Scope
(Entity
(P
)))
6445 Error_Msg_N
("context requires a protected subprogram", P
);
6447 elsif Ekind
(Btyp
) = E_Access_Subprogram_Type
6448 and then Ekind
(Etype
(N
)) = E_Access_Protected_Subprogram_Type
6450 Error_Msg_N
("context requires a non-protected subprogram", P
);
6453 -- The context cannot be a pool-specific type, but this is a
6454 -- legality rule, not a resolution rule, so it must be checked
6455 -- separately, after possibly disambiguation (see AI-245).
6457 if Ekind
(Btyp
) = E_Access_Type
6458 and then Attr_Id
/= Attribute_Unrestricted_Access
6460 Wrong_Type
(N
, Typ
);
6465 -- Check for incorrect atomic/volatile reference (RM C.6(12))
6467 if Attr_Id
/= Attribute_Unrestricted_Access
then
6468 if Is_Atomic_Object
(P
)
6469 and then not Is_Atomic
(Designated_Type
(Typ
))
6472 ("access to atomic object cannot yield access-to-" &
6473 "non-atomic type", P
);
6475 elsif Is_Volatile_Object
(P
)
6476 and then not Is_Volatile
(Designated_Type
(Typ
))
6479 ("access to volatile object cannot yield access-to-" &
6480 "non-volatile type", P
);
6488 -- Deal with resolving the type for Address attribute, overloading
6489 -- is not permitted here, since there is no context to resolve it.
6491 when Attribute_Address | Attribute_Code_Address
=>
6493 -- To be safe, assume that if the address of a variable is taken,
6494 -- it may be modified via this address, so note modification.
6496 if Is_Variable
(P
) then
6497 Note_Possible_Modification
(P
);
6500 if Nkind
(P
) in N_Subexpr
6501 and then Is_Overloaded
(P
)
6503 Get_First_Interp
(P
, Index
, It
);
6504 Get_Next_Interp
(Index
, It
);
6506 if Present
(It
.Nam
) then
6507 Error_Msg_Name_1
:= Aname
;
6509 ("prefix of % attribute cannot be overloaded", N
);
6514 if not Is_Entity_Name
(P
)
6515 or else not Is_Overloadable
(Entity
(P
))
6517 if not Is_Task_Type
(Etype
(P
))
6518 or else Nkind
(P
) = N_Explicit_Dereference
6520 Resolve
(P
, Etype
(P
));
6524 -- If this is the name of a derived subprogram, or that of a
6525 -- generic actual, the address is that of the original entity.
6527 if Is_Entity_Name
(P
)
6528 and then Is_Overloadable
(Entity
(P
))
6529 and then Present
(Alias
(Entity
(P
)))
6532 New_Occurrence_Of
(Alias
(Entity
(P
)), Sloc
(P
)));
6539 -- Prefix of the AST_Entry attribute is an entry name which must
6540 -- not be resolved, since this is definitely not an entry call.
6542 when Attribute_AST_Entry
=>
6549 -- Prefix of Body_Version attribute can be a subprogram name which
6550 -- must not be resolved, since this is not a call.
6552 when Attribute_Body_Version
=>
6559 -- Prefix of Caller attribute is an entry name which must not
6560 -- be resolved, since this is definitely not an entry call.
6562 when Attribute_Caller
=>
6569 -- Shares processing with Address attribute
6575 -- Prefix of the Count attribute is an entry name which must not
6576 -- be resolved, since this is definitely not an entry call.
6578 when Attribute_Count
=>
6585 -- Prefix of the Elaborated attribute is a subprogram name which
6586 -- must not be resolved, since this is definitely not a call. Note
6587 -- that it is a library unit, so it cannot be overloaded here.
6589 when Attribute_Elaborated
=>
6592 --------------------
6593 -- Mechanism_Code --
6594 --------------------
6596 -- Prefix of the Mechanism_Code attribute is a function name
6597 -- which must not be resolved. Should we check for overloaded ???
6599 when Attribute_Mechanism_Code
=>
6606 -- Most processing is done in sem_dist, after determining the
6607 -- context type. Node is rewritten as a conversion to a runtime call.
6609 when Attribute_Partition_ID
=>
6610 Process_Partition_Id
(N
);
6617 -- We replace the Range attribute node with a range expression
6618 -- whose bounds are the 'First and 'Last attributes applied to the
6619 -- same prefix. The reason that we do this transformation here
6620 -- instead of in the expander is that it simplifies other parts of
6621 -- the semantic analysis which assume that the Range has been
6622 -- replaced; thus it must be done even when in semantic-only mode
6623 -- (note that the RM specifically mentions this equivalence, we
6624 -- take care that the prefix is only evaluated once).
6626 when Attribute_Range
=> Range_Attribute
:
6631 function Check_Discriminated_Prival
6634 -- The range of a private component constrained by a
6635 -- discriminant is rewritten to make the discriminant
6636 -- explicit. This solves some complex visibility problems
6637 -- related to the use of privals.
6639 function Check_Discriminated_Prival
6644 if Is_Entity_Name
(N
)
6645 and then Ekind
(Entity
(N
)) = E_In_Parameter
6646 and then not Within_Init_Proc
6648 return Make_Identifier
(Sloc
(N
), Chars
(Entity
(N
)));
6650 return Duplicate_Subexpr
(N
);
6652 end Check_Discriminated_Prival
;
6654 -- Start of processing for Range_Attribute
6657 if not Is_Entity_Name
(P
)
6658 or else not Is_Type
(Entity
(P
))
6660 Resolve
(P
, Etype
(P
));
6663 -- Check whether prefix is (renaming of) private component
6664 -- of protected type.
6666 if Is_Entity_Name
(P
)
6667 and then Comes_From_Source
(N
)
6668 and then Is_Array_Type
(Etype
(P
))
6669 and then Number_Dimensions
(Etype
(P
)) = 1
6670 and then (Ekind
(Scope
(Entity
(P
))) = E_Protected_Type
6672 Ekind
(Scope
(Scope
(Entity
(P
)))) =
6675 LB
:= Check_Discriminated_Prival
(
6676 Type_Low_Bound
(Etype
(First_Index
(Etype
(P
)))));
6678 HB
:= Check_Discriminated_Prival
(
6679 Type_High_Bound
(Etype
(First_Index
(Etype
(P
)))));
6683 Make_Attribute_Reference
(Loc
,
6684 Prefix
=> Duplicate_Subexpr
(P
),
6685 Attribute_Name
=> Name_Last
,
6686 Expressions
=> Expressions
(N
));
6689 Make_Attribute_Reference
(Loc
,
6691 Attribute_Name
=> Name_First
,
6692 Expressions
=> Expressions
(N
));
6695 -- If the original was marked as Must_Not_Freeze (see code
6696 -- in Sem_Ch3.Make_Index), then make sure the rewriting
6697 -- does not freeze either.
6699 if Must_Not_Freeze
(N
) then
6700 Set_Must_Not_Freeze
(HB
);
6701 Set_Must_Not_Freeze
(LB
);
6702 Set_Must_Not_Freeze
(Prefix
(HB
));
6703 Set_Must_Not_Freeze
(Prefix
(LB
));
6706 if Raises_Constraint_Error
(Prefix
(N
)) then
6708 -- Preserve Sloc of prefix in the new bounds, so that
6709 -- the posted warning can be removed if we are within
6710 -- unreachable code.
6712 Set_Sloc
(LB
, Sloc
(Prefix
(N
)));
6713 Set_Sloc
(HB
, Sloc
(Prefix
(N
)));
6716 Rewrite
(N
, Make_Range
(Loc
, LB
, HB
));
6717 Analyze_And_Resolve
(N
, Typ
);
6719 -- Normally after resolving attribute nodes, Eval_Attribute
6720 -- is called to do any possible static evaluation of the node.
6721 -- However, here since the Range attribute has just been
6722 -- transformed into a range expression it is no longer an
6723 -- attribute node and therefore the call needs to be avoided
6724 -- and is accomplished by simply returning from the procedure.
6727 end Range_Attribute
;
6733 -- Prefix must not be resolved in this case, since it is not a
6734 -- real entity reference. No action of any kind is require!
6736 when Attribute_UET_Address
=>
6739 ----------------------
6740 -- Unchecked_Access --
6741 ----------------------
6743 -- Processing is shared with Access
6745 -------------------------
6746 -- Unrestricted_Access --
6747 -------------------------
6749 -- Processing is shared with Access
6755 -- Apply range check. Note that we did not do this during the
6756 -- analysis phase, since we wanted Eval_Attribute to have a
6757 -- chance at finding an illegal out of range value.
6759 when Attribute_Val
=>
6761 -- Note that we do our own Eval_Attribute call here rather than
6762 -- use the common one, because we need to do processing after
6763 -- the call, as per above comment.
6767 -- Eval_Attribute may replace the node with a raise CE, or
6768 -- fold it to a constant. Obviously we only apply a scalar
6769 -- range check if this did not happen!
6771 if Nkind
(N
) = N_Attribute_Reference
6772 and then Attribute_Name
(N
) = Name_Val
6774 Apply_Scalar_Range_Check
(First
(Expressions
(N
)), Btyp
);
6783 -- Prefix of Version attribute can be a subprogram name which
6784 -- must not be resolved, since this is not a call.
6786 when Attribute_Version
=>
6789 ----------------------
6790 -- Other Attributes --
6791 ----------------------
6793 -- For other attributes, resolve prefix unless it is a type. If
6794 -- the attribute reference itself is a type name ('Base and 'Class)
6795 -- then this is only legal within a task or protected record.
6798 if not Is_Entity_Name
(P
)
6799 or else not Is_Type
(Entity
(P
))
6801 Resolve
(P
, Etype
(P
));
6804 -- If the attribute reference itself is a type name ('Base,
6805 -- 'Class) then this is only legal within a task or protected
6806 -- record. What is this all about ???
6808 if Is_Entity_Name
(N
)
6809 and then Is_Type
(Entity
(N
))
6811 if Is_Concurrent_Type
(Entity
(N
))
6812 and then In_Open_Scopes
(Entity
(P
))
6817 ("invalid use of subtype name in expression or call", N
);
6821 -- For attributes whose argument may be a string, complete
6822 -- resolution of argument now. This avoids premature expansion
6823 -- (and the creation of transient scopes) before the attribute
6824 -- reference is resolved.
6827 when Attribute_Value
=>
6828 Resolve
(First
(Expressions
(N
)), Standard_String
);
6830 when Attribute_Wide_Value
=>
6831 Resolve
(First
(Expressions
(N
)), Standard_Wide_String
);
6833 when others => null;
6837 -- Normally the Freezing is done by Resolve but sometimes the Prefix
6838 -- is not resolved, in which case the freezing must be done now.
6840 Freeze_Expression
(P
);
6842 -- Finally perform static evaluation on the attribute reference
6846 end Resolve_Attribute
;