1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2002, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Ada
.Characters
.Latin_1
; use Ada
.Characters
.Latin_1
;
29 with Atree
; use Atree
;
30 with Checks
; use Checks
;
31 with Einfo
; use Einfo
;
32 with Errout
; use Errout
;
34 with Exp_Tss
; use Exp_Tss
;
35 with Exp_Util
; use Exp_Util
;
36 with Expander
; use Expander
;
37 with Freeze
; use Freeze
;
38 with Lib
.Xref
; use Lib
.Xref
;
39 with Namet
; use Namet
;
40 with Nlists
; use Nlists
;
41 with Nmake
; use Nmake
;
43 with Restrict
; use Restrict
;
44 with Rtsfind
; use Rtsfind
;
46 with Sem_Cat
; use Sem_Cat
;
47 with Sem_Ch6
; use Sem_Ch6
;
48 with Sem_Ch8
; use Sem_Ch8
;
49 with Sem_Dist
; use Sem_Dist
;
50 with Sem_Eval
; use Sem_Eval
;
51 with Sem_Res
; use Sem_Res
;
52 with Sem_Type
; use Sem_Type
;
53 with Sem_Util
; use Sem_Util
;
54 with Stand
; use Stand
;
55 with Sinfo
; use Sinfo
;
56 with Sinput
; use Sinput
;
57 with Snames
; use Snames
;
59 with Stringt
; use Stringt
;
60 with Targparm
; use Targparm
;
61 with Ttypes
; use Ttypes
;
62 with Ttypef
; use Ttypef
;
63 with Tbuild
; use Tbuild
;
64 with Uintp
; use Uintp
;
65 with Urealp
; use Urealp
;
66 with Widechar
; use Widechar
;
68 package body Sem_Attr
is
70 True_Value
: constant Uint
:= Uint_1
;
71 False_Value
: constant Uint
:= Uint_0
;
72 -- Synonyms to be used when these constants are used as Boolean values
74 Bad_Attribute
: exception;
75 -- Exception raised if an error is detected during attribute processing,
76 -- used so that we can abandon the processing so we don't run into
77 -- trouble with cascaded errors.
79 -- The following array is the list of attributes defined in the Ada 83 RM
81 Attribute_83
: Attribute_Class_Array
:= Attribute_Class_Array
'(
87 Attribute_Constrained |
100 Attribute_Leading_Part |
102 Attribute_Machine_Emax |
103 Attribute_Machine_Emin |
104 Attribute_Machine_Mantissa |
105 Attribute_Machine_Overflows |
106 Attribute_Machine_Radix |
107 Attribute_Machine_Rounds |
113 Attribute_Safe_Emax |
114 Attribute_Safe_Large |
115 Attribute_Safe_Small |
118 Attribute_Storage_Size |
120 Attribute_Terminated |
123 Attribute_Width => True,
126 -----------------------
127 -- Local_Subprograms --
128 -----------------------
130 procedure Eval_Attribute (N : Node_Id);
131 -- Performs compile time evaluation of attributes where possible, leaving
132 -- the Is_Static_Expression/Raises_Constraint_Error flags appropriately
133 -- set, and replacing the node with a literal node if the value can be
134 -- computed at compile time. All static attribute references are folded,
135 -- as well as a number of cases of non-static attributes that can always
136 -- be computed at compile time (e.g. floating-point model attributes that
137 -- are applied to non-static subtypes). Of course in such cases, the
138 -- Is_Static_Expression flag will not be set on the resulting literal.
139 -- Note that the only required action of this procedure is to catch the
140 -- static expression cases as described in the RM. Folding of other cases
141 -- is done where convenient, but some additional non-static folding is in
142 -- N_Expand_Attribute_Reference in cases where this is more convenient.
144 function Is_Anonymous_Tagged_Base
148 -- For derived tagged types that constrain parent discriminants we build
149 -- an anonymous unconstrained base type. We need to recognize the relation
150 -- between the two when analyzing an access attribute for a constrained
151 -- component, before the full declaration for Typ has been analyzed, and
152 -- where therefore the prefix of the attribute does not match the enclosing
155 -----------------------
156 -- Analyze_Attribute --
157 -----------------------
159 procedure Analyze_Attribute (N : Node_Id) is
160 Loc : constant Source_Ptr := Sloc (N);
161 Aname : constant Name_Id := Attribute_Name (N);
162 P : constant Node_Id := Prefix (N);
163 Exprs : constant List_Id := Expressions (N);
164 Attr_Id : constant Attribute_Id := Get_Attribute_Id (Aname);
169 -- Type of prefix after analysis
171 P_Base_Type : Entity_Id;
172 -- Base type of prefix after analysis
174 P_Root_Type : Entity_Id;
175 -- Root type of prefix after analysis
177 Unanalyzed : Node_Id;
179 -----------------------
180 -- Local Subprograms --
181 -----------------------
183 procedure Access_Attribute;
184 -- Used for Access, Unchecked_Access, Unrestricted_Access attributes.
185 -- Internally, Id distinguishes which of the three cases is involved.
187 procedure Check_Array_Or_Scalar_Type;
188 -- Common procedure used by First, Last, Range attribute to check
189 -- that the prefix is a constrained array or scalar type, or a name
190 -- of an array object, and that an argument appears only if appropriate
191 -- (i.e. only in the array case).
193 procedure Check_Array_Type;
194 -- Common semantic checks for all array attributes. Checks that the
195 -- prefix is a constrained array type or the name of an array object.
196 -- The error message for non-arrays is specialized appropriately.
198 procedure Check_Asm_Attribute;
199 -- Common semantic checks for Asm_Input and Asm_Output attributes
201 procedure Check_Component;
202 -- Common processing for Bit_Position, First_Bit, Last_Bit, and
203 -- Position. Checks prefix is an appropriate selected component.
205 procedure Check_Decimal_Fixed_Point_Type;
206 -- Check that prefix of attribute N is a decimal fixed-point type
208 procedure Check_Dereference;
209 -- If the prefix of attribute is an object of an access type, then
210 -- introduce an explicit deference, and adjust P_Type accordingly.
212 procedure Check_Discrete_Type;
213 -- Verify that prefix of attribute N is a discrete type
216 -- Check that no attribute arguments are present
218 procedure Check_Either_E0_Or_E1;
219 -- Check that there are zero or one attribute arguments present
222 -- Check that exactly one attribute argument is present
225 -- Check that two attribute arguments are present
227 procedure Check_Enum_Image;
228 -- If the prefix type is an enumeration type, set all its literals
229 -- as referenced, since the image function could possibly end up
230 -- referencing any of the literals indirectly.
232 procedure Check_Fixed_Point_Type;
233 -- Verify that prefix of attribute N is a fixed type
235 procedure Check_Fixed_Point_Type_0;
236 -- Verify that prefix of attribute N is a fixed type and that
237 -- no attribute expressions are present
239 procedure Check_Floating_Point_Type;
240 -- Verify that prefix of attribute N is a float type
242 procedure Check_Floating_Point_Type_0;
243 -- Verify that prefix of attribute N is a float type and that
244 -- no attribute expressions are present
246 procedure Check_Floating_Point_Type_1;
247 -- Verify that prefix of attribute N is a float type and that
248 -- exactly one attribute expression is present
250 procedure Check_Floating_Point_Type_2;
251 -- Verify that prefix of attribute N is a float type and that
252 -- two attribute expressions are present
254 procedure Legal_Formal_Attribute;
255 -- Common processing for attributes Definite, and Has_Discriminants
257 procedure Check_Integer_Type;
258 -- Verify that prefix of attribute N is an integer type
260 procedure Check_Library_Unit;
261 -- Verify that prefix of attribute N is a library unit
263 procedure Check_Not_Incomplete_Type;
264 -- Check that P (the prefix of the attribute) is not an incomplete
265 -- type or a private type for which no full view has been given.
267 procedure Check_Object_Reference (P : Node_Id);
268 -- Check that P (the prefix of the attribute) is an object reference
270 procedure Check_Program_Unit;
271 -- Verify that prefix of attribute N is a program unit
273 procedure Check_Real_Type;
274 -- Verify that prefix of attribute N is fixed or float type
276 procedure Check_Scalar_Type;
277 -- Verify that prefix of attribute N is a scalar type
279 procedure Check_Standard_Prefix;
280 -- Verify that prefix of attribute N is package Standard
282 procedure Check_Stream_Attribute (Nam : Name_Id);
283 -- Validity checking for stream attribute. Nam is the name of the
284 -- corresponding possible defined attribute function (e.g. for the
285 -- Read attribute, Nam will be Name_uRead).
287 procedure Check_Task_Prefix;
288 -- Verify that prefix of attribute N is a task or task type
290 procedure Check_Type;
291 -- Verify that the prefix of attribute N is a type
293 procedure Check_Unit_Name (Nod : Node_Id);
294 -- Check that Nod is of the form of a library unit name, i.e that
295 -- it is an identifier, or a selected component whose prefix is
296 -- itself of the form of a library unit name. Note that this is
297 -- quite different from Check_Program_Unit, since it only checks
298 -- the syntactic form of the name, not the semantic identity. This
299 -- is because it is used with attributes (Elab_Body, Elab_Spec, and
300 -- UET_Address) which can refer to non-visible unit.
302 procedure Error_Attr (Msg : String; Error_Node : Node_Id);
303 pragma No_Return (Error_Attr);
304 -- Posts error using Error_Msg_N at given node, sets type of attribute
305 -- node to Any_Type, and then raises Bad_Attribute to avoid any further
306 -- semantic processing. The message typically contains a % insertion
307 -- character which is replaced by the attribute name.
309 procedure Standard_Attribute (Val : Int);
310 -- Used to process attributes whose prefix is package Standard which
311 -- yield values of type Universal_Integer. The attribute reference
312 -- node is rewritten with an integer literal of the given value.
314 procedure Unexpected_Argument (En : Node_Id);
315 -- Signal unexpected attribute argument (En is the argument)
317 procedure Validate_Non_Static_Attribute_Function_Call;
318 -- Called when processing an attribute that is a function call to a
319 -- non-static function, i.e. an attribute function that either takes
320 -- non-scalar arguments or returns a non-scalar result. Verifies that
321 -- such a call does not appear in a preelaborable context.
323 ----------------------
324 -- Access_Attribute --
325 ----------------------
327 procedure Access_Attribute is
328 Acc_Type : Entity_Id;
333 function Build_Access_Object_Type (DT : Entity_Id) return Entity_Id;
334 -- Build an access-to-object type whose designated type is DT,
335 -- and whose Ekind is appropriate to the attribute type. The
336 -- type that is constructed is returned as the result.
338 procedure Build_Access_Subprogram_Type (P : Node_Id);
339 -- Build an access to subprogram whose designated type is
340 -- the type of the prefix. If prefix is overloaded, so it the
341 -- node itself. The result is stored in Acc_Type.
343 ------------------------------
344 -- Build_Access_Object_Type --
345 ------------------------------
347 function Build_Access_Object_Type (DT : Entity_Id) return Entity_Id is
351 if Aname = Name_Unrestricted_Access then
354 (E_Allocator_Type, Current_Scope, Loc, 'A
');
358 (E_Access_Attribute_Type, Current_Scope, Loc, 'A
');
361 Set_Etype (Typ, Typ);
362 Init_Size_Align (Typ);
364 Set_Associated_Node_For_Itype (Typ, N);
365 Set_Directly_Designated_Type (Typ, DT);
367 end Build_Access_Object_Type;
369 ----------------------------------
370 -- Build_Access_Subprogram_Type --
371 ----------------------------------
373 procedure Build_Access_Subprogram_Type (P : Node_Id) is
374 Index : Interp_Index;
377 function Get_Kind (E : Entity_Id) return Entity_Kind;
378 -- Distinguish between access to regular and protected
381 function Get_Kind (E : Entity_Id) return Entity_Kind is
383 if Convention (E) = Convention_Protected then
384 return E_Access_Protected_Subprogram_Type;
386 return E_Access_Subprogram_Type;
390 -- Start of processing for Build_Access_Subprogram_Type
393 if not Is_Overloaded (P) then
396 (Get_Kind (Entity (P)), Current_Scope, Loc, 'A
');
397 Set_Etype (Acc_Type, Acc_Type);
398 Set_Directly_Designated_Type (Acc_Type, Entity (P));
399 Set_Etype (N, Acc_Type);
402 Get_First_Interp (P, Index, It);
403 Set_Etype (N, Any_Type);
405 while Present (It.Nam) loop
407 if not Is_Intrinsic_Subprogram (It.Nam) then
410 (Get_Kind (It.Nam), Current_Scope, Loc, 'A
');
411 Set_Etype (Acc_Type, Acc_Type);
412 Set_Directly_Designated_Type (Acc_Type, It.Nam);
413 Add_One_Interp (N, Acc_Type, Acc_Type);
416 Get_Next_Interp (Index, It);
419 if Etype (N) = Any_Type then
420 Error_Attr ("prefix of % attribute cannot be intrinsic", P);
423 end Build_Access_Subprogram_Type;
425 -- Start of processing for Access_Attribute
430 if Nkind (P) = N_Character_Literal then
432 ("prefix of % attribute cannot be enumeration literal", P);
434 -- In the case of an access to subprogram, use the name of the
435 -- subprogram itself as the designated type. Type-checking in
436 -- this case compares the signatures of the designated types.
438 elsif Is_Entity_Name (P)
439 and then Is_Overloadable (Entity (P))
441 if not Is_Library_Level_Entity (Entity (P)) then
442 Check_Restriction (No_Implicit_Dynamic_Code, P);
445 Build_Access_Subprogram_Type (P);
448 -- Component is an operation of a protected type.
450 elsif (Nkind (P) = N_Selected_Component
451 and then Is_Overloadable (Entity (Selector_Name (P))))
453 if Ekind (Entity (Selector_Name (P))) = E_Entry then
454 Error_Attr ("prefix of % attribute must be subprogram", P);
457 Build_Access_Subprogram_Type (Selector_Name (P));
461 -- Deal with incorrect reference to a type, but note that some
462 -- accesses are allowed (references to the current type instance).
464 if Is_Entity_Name (P) then
465 Scop := Current_Scope;
468 if Is_Type (Typ) then
470 -- OK if we are within the scope of a limited type
471 -- let's mark the component as having per object constraint
473 if Is_Anonymous_Tagged_Base (Scop, Typ) then
481 Q : Node_Id := Parent (N);
485 and then Nkind (Q) /= N_Component_Declaration
490 Set_Has_Per_Object_Constraint (
491 Defining_Identifier (Q), True);
495 if Nkind (P) = N_Expanded_Name then
497 ("current instance prefix must be a direct name", P);
500 -- If a current instance attribute appears within a
501 -- a component constraint it must appear alone; other
502 -- contexts (default expressions, within a task body)
503 -- are not subject to this restriction.
505 if not In_Default_Expression
506 and then not Has_Completion (Scop)
508 Nkind (Parent (N)) /= N_Discriminant_Association
510 Nkind (Parent (N)) /= N_Index_Or_Discriminant_Constraint
513 ("current instance attribute must appear alone", N);
516 -- OK if we are in initialization procedure for the type
517 -- in question, in which case the reference to the type
518 -- is rewritten as a reference to the current object.
520 elsif Ekind (Scop) = E_Procedure
521 and then Chars (Scop) = Name_uInit_Proc
522 and then Etype (First_Formal (Scop)) = Typ
525 Make_Attribute_Reference (Loc,
526 Prefix => Make_Identifier (Loc, Name_uInit),
527 Attribute_Name => Name_Unrestricted_Access));
531 -- OK if a task type, this test needs sharpening up ???
533 elsif Is_Task_Type (Typ) then
536 -- Otherwise we have an error case
539 Error_Attr ("% attribute cannot be applied to type", P);
545 -- If we fall through, we have a normal access to object case.
546 -- Unrestricted_Access is legal wherever an allocator would be
547 -- legal, so its Etype is set to E_Allocator. The expected type
548 -- of the other attributes is a general access type, and therefore
549 -- we label them with E_Access_Attribute_Type.
551 if not Is_Overloaded (P) then
552 Acc_Type := Build_Access_Object_Type (P_Type);
553 Set_Etype (N, Acc_Type);
556 Index : Interp_Index;
560 Set_Etype (N, Any_Type);
561 Get_First_Interp (P, Index, It);
563 while Present (It.Typ) loop
564 Acc_Type := Build_Access_Object_Type (It.Typ);
565 Add_One_Interp (N, Acc_Type, Acc_Type);
566 Get_Next_Interp (Index, It);
571 -- Check for aliased view unless unrestricted case. We allow
572 -- a nonaliased prefix when within an instance because the
573 -- prefix may have been a tagged formal object, which is
574 -- defined to be aliased even when the actual might not be
575 -- (other instance cases will have been caught in the generic).
577 if Aname /= Name_Unrestricted_Access
578 and then not Is_Aliased_View (P)
579 and then not In_Instance
581 Error_Attr ("prefix of % attribute must be aliased", P);
584 end Access_Attribute;
586 --------------------------------
587 -- Check_Array_Or_Scalar_Type --
588 --------------------------------
590 procedure Check_Array_Or_Scalar_Type is
594 -- Dimension number for array attributes.
597 -- Case of string literal or string literal subtype. These cases
598 -- cannot arise from legal Ada code, but the expander is allowed
599 -- to generate them. They require special handling because string
600 -- literal subtypes do not have standard bounds (the whole idea
601 -- of these subtypes is to avoid having to generate the bounds)
603 if Ekind (P_Type) = E_String_Literal_Subtype then
604 Set_Etype (N, Etype (First_Index (P_Base_Type)));
609 elsif Is_Scalar_Type (P_Type) then
613 Error_Attr ("invalid argument in % attribute", E1);
615 Set_Etype (N, P_Base_Type);
619 -- The following is a special test to allow 'First to apply to
620 -- private scalar types if the attribute comes from generated
621 -- code. This occurs in the case of Normalize_Scalars code.
623 elsif Is_Private_Type
(P_Type
)
624 and then Present
(Full_View
(P_Type
))
625 and then Is_Scalar_Type
(Full_View
(P_Type
))
626 and then not Comes_From_Source
(N
)
628 Set_Etype
(N
, Implementation_Base_Type
(P_Type
));
630 -- Array types other than string literal subtypes handled above
635 -- We know prefix is an array type, or the name of an array
636 -- object, and that the expression, if present, is static
637 -- and within the range of the dimensions of the type.
639 if Is_Array_Type
(P_Type
) then
640 Index
:= First_Index
(P_Base_Type
);
642 else pragma Assert
(Is_Access_Type
(P_Type
));
643 Index
:= First_Index
(Base_Type
(Designated_Type
(P_Type
)));
648 -- First dimension assumed
650 Set_Etype
(N
, Base_Type
(Etype
(Index
)));
653 D
:= UI_To_Int
(Intval
(E1
));
655 for J
in 1 .. D
- 1 loop
659 Set_Etype
(N
, Base_Type
(Etype
(Index
)));
660 Set_Etype
(E1
, Standard_Integer
);
663 end Check_Array_Or_Scalar_Type
;
665 ----------------------
666 -- Check_Array_Type --
667 ----------------------
669 procedure Check_Array_Type
is
671 -- Dimension number for array attributes.
674 -- If the type is a string literal type, then this must be generated
675 -- internally, and no further check is required on its legality.
677 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
680 -- If the type is a composite, it is an illegal aggregate, no point
683 elsif P_Type
= Any_Composite
then
687 -- Normal case of array type or subtype
689 Check_Either_E0_Or_E1
;
691 if Is_Array_Type
(P_Type
) then
692 if not Is_Constrained
(P_Type
)
693 and then Is_Entity_Name
(P
)
694 and then Is_Type
(Entity
(P
))
696 -- Note: we do not call Error_Attr here, since we prefer to
697 -- continue, using the relevant index type of the array,
698 -- even though it is unconstrained. This gives better error
699 -- recovery behavior.
701 Error_Msg_Name_1
:= Aname
;
703 ("prefix for % attribute must be constrained array", P
);
706 D
:= Number_Dimensions
(P_Type
);
708 elsif Is_Access_Type
(P_Type
)
709 and then Is_Array_Type
(Designated_Type
(P_Type
))
711 if Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)) then
712 Error_Attr
("prefix of % attribute cannot be access type", P
);
715 D
:= Number_Dimensions
(Designated_Type
(P_Type
));
717 -- If there is an implicit dereference, then we must freeze
718 -- the designated type of the access type, since the type of
719 -- the referenced array is this type (see AI95-00106).
721 Freeze_Before
(N
, Designated_Type
(P_Type
));
724 if Is_Private_Type
(P_Type
) then
726 ("prefix for % attribute may not be private type", P
);
728 elsif Attr_Id
= Attribute_First
730 Attr_Id
= Attribute_Last
732 Error_Attr
("invalid prefix for % attribute", P
);
735 Error_Attr
("prefix for % attribute must be array", P
);
740 Resolve
(E1
, Any_Integer
);
741 Set_Etype
(E1
, Standard_Integer
);
743 if not Is_Static_Expression
(E1
)
744 or else Raises_Constraint_Error
(E1
)
746 Error_Attr
("expression for dimension must be static", E1
);
748 elsif UI_To_Int
(Expr_Value
(E1
)) > D
749 or else UI_To_Int
(Expr_Value
(E1
)) < 1
751 Error_Attr
("invalid dimension number for array type", E1
);
754 end Check_Array_Type
;
756 -------------------------
757 -- Check_Asm_Attribute --
758 -------------------------
760 procedure Check_Asm_Attribute
is
765 -- Check first argument is static string expression
767 Analyze_And_Resolve
(E1
, Standard_String
);
769 if Etype
(E1
) = Any_Type
then
772 elsif not Is_OK_Static_Expression
(E1
) then
774 ("constraint argument must be static string expression", E1
);
777 -- Check second argument is right type
779 Analyze_And_Resolve
(E2
, Entity
(P
));
781 -- Note: that is all we need to do, we don't need to check
782 -- that it appears in a correct context. The Ada type system
783 -- will do that for us.
785 end Check_Asm_Attribute
;
787 ---------------------
788 -- Check_Component --
789 ---------------------
791 procedure Check_Component
is
795 if Nkind
(P
) /= N_Selected_Component
797 (Ekind
(Entity
(Selector_Name
(P
))) /= E_Component
799 Ekind
(Entity
(Selector_Name
(P
))) /= E_Discriminant
)
802 ("prefix for % attribute must be selected component", P
);
806 ------------------------------------
807 -- Check_Decimal_Fixed_Point_Type --
808 ------------------------------------
810 procedure Check_Decimal_Fixed_Point_Type
is
814 if not Is_Decimal_Fixed_Point_Type
(P_Type
) then
816 ("prefix of % attribute must be decimal type", P
);
818 end Check_Decimal_Fixed_Point_Type
;
820 -----------------------
821 -- Check_Dereference --
822 -----------------------
824 procedure Check_Dereference
is
826 if Is_Object_Reference
(P
)
827 and then Is_Access_Type
(P_Type
)
830 Make_Explicit_Dereference
(Sloc
(P
),
831 Prefix
=> Relocate_Node
(P
)));
833 Analyze_And_Resolve
(P
);
836 if P_Type
= Any_Type
then
840 P_Base_Type
:= Base_Type
(P_Type
);
841 P_Root_Type
:= Root_Type
(P_Base_Type
);
843 end Check_Dereference
;
845 -------------------------
846 -- Check_Discrete_Type --
847 -------------------------
849 procedure Check_Discrete_Type
is
853 if not Is_Discrete_Type
(P_Type
) then
854 Error_Attr
("prefix of % attribute must be discrete type", P
);
856 end Check_Discrete_Type
;
862 procedure Check_E0
is
865 Unexpected_Argument
(E1
);
873 procedure Check_E1
is
875 Check_Either_E0_Or_E1
;
879 -- Special-case attributes that are functions and that appear as
880 -- the prefix of another attribute. Error is posted on parent.
882 if Nkind
(Parent
(N
)) = N_Attribute_Reference
883 and then (Attribute_Name
(Parent
(N
)) = Name_Address
885 Attribute_Name
(Parent
(N
)) = Name_Code_Address
887 Attribute_Name
(Parent
(N
)) = Name_Access
)
889 Error_Msg_Name_1
:= Attribute_Name
(Parent
(N
));
890 Error_Msg_N
("illegal prefix for % attribute", Parent
(N
));
891 Set_Etype
(Parent
(N
), Any_Type
);
892 Set_Entity
(Parent
(N
), Any_Type
);
896 Error_Attr
("missing argument for % attribute", N
);
905 procedure Check_E2
is
908 Error_Attr
("missing arguments for % attribute (2 required)", N
);
910 Error_Attr
("missing argument for % attribute (2 required)", N
);
914 ---------------------------
915 -- Check_Either_E0_Or_E1 --
916 ---------------------------
918 procedure Check_Either_E0_Or_E1
is
921 Unexpected_Argument
(E2
);
923 end Check_Either_E0_Or_E1
;
925 ----------------------
926 -- Check_Enum_Image --
927 ----------------------
929 procedure Check_Enum_Image
is
933 if Is_Enumeration_Type
(P_Base_Type
) then
934 Lit
:= First_Literal
(P_Base_Type
);
935 while Present
(Lit
) loop
936 Set_Referenced
(Lit
);
940 end Check_Enum_Image
;
942 ----------------------------
943 -- Check_Fixed_Point_Type --
944 ----------------------------
946 procedure Check_Fixed_Point_Type
is
950 if not Is_Fixed_Point_Type
(P_Type
) then
951 Error_Attr
("prefix of % attribute must be fixed point type", P
);
953 end Check_Fixed_Point_Type
;
955 ------------------------------
956 -- Check_Fixed_Point_Type_0 --
957 ------------------------------
959 procedure Check_Fixed_Point_Type_0
is
961 Check_Fixed_Point_Type
;
963 end Check_Fixed_Point_Type_0
;
965 -------------------------------
966 -- Check_Floating_Point_Type --
967 -------------------------------
969 procedure Check_Floating_Point_Type
is
973 if not Is_Floating_Point_Type
(P_Type
) then
974 Error_Attr
("prefix of % attribute must be float type", P
);
976 end Check_Floating_Point_Type
;
978 ---------------------------------
979 -- Check_Floating_Point_Type_0 --
980 ---------------------------------
982 procedure Check_Floating_Point_Type_0
is
984 Check_Floating_Point_Type
;
986 end Check_Floating_Point_Type_0
;
988 ---------------------------------
989 -- Check_Floating_Point_Type_1 --
990 ---------------------------------
992 procedure Check_Floating_Point_Type_1
is
994 Check_Floating_Point_Type
;
996 end Check_Floating_Point_Type_1
;
998 ---------------------------------
999 -- Check_Floating_Point_Type_2 --
1000 ---------------------------------
1002 procedure Check_Floating_Point_Type_2
is
1004 Check_Floating_Point_Type
;
1006 end Check_Floating_Point_Type_2
;
1008 ------------------------
1009 -- Check_Integer_Type --
1010 ------------------------
1012 procedure Check_Integer_Type
is
1016 if not Is_Integer_Type
(P_Type
) then
1017 Error_Attr
("prefix of % attribute must be integer type", P
);
1019 end Check_Integer_Type
;
1021 ------------------------
1022 -- Check_Library_Unit --
1023 ------------------------
1025 procedure Check_Library_Unit
is
1027 if not Is_Compilation_Unit
(Entity
(P
)) then
1028 Error_Attr
("prefix of % attribute must be library unit", P
);
1030 end Check_Library_Unit
;
1032 -------------------------------
1033 -- Check_Not_Incomplete_Type --
1034 -------------------------------
1036 procedure Check_Not_Incomplete_Type
is
1038 if not Is_Entity_Name
(P
)
1039 or else not Is_Type
(Entity
(P
))
1040 or else In_Default_Expression
1045 Check_Fully_Declared
(P_Type
, P
);
1047 end Check_Not_Incomplete_Type
;
1049 ----------------------------
1050 -- Check_Object_Reference --
1051 ----------------------------
1053 procedure Check_Object_Reference
(P
: Node_Id
) is
1057 -- If we need an object, and we have a prefix that is the name of
1058 -- a function entity, convert it into a function call.
1060 if Is_Entity_Name
(P
)
1061 and then Ekind
(Entity
(P
)) = E_Function
1063 Rtyp
:= Etype
(Entity
(P
));
1066 Make_Function_Call
(Sloc
(P
),
1067 Name
=> Relocate_Node
(P
)));
1069 Analyze_And_Resolve
(P
, Rtyp
);
1071 -- Otherwise we must have an object reference
1073 elsif not Is_Object_Reference
(P
) then
1074 Error_Attr
("prefix of % attribute must be object", P
);
1076 end Check_Object_Reference
;
1078 ------------------------
1079 -- Check_Program_Unit --
1080 ------------------------
1082 procedure Check_Program_Unit
is
1084 if Is_Entity_Name
(P
) then
1086 K
: constant Entity_Kind
:= Ekind
(Entity
(P
));
1087 T
: constant Entity_Id
:= Etype
(Entity
(P
));
1090 if K
in Subprogram_Kind
1091 or else K
in Task_Kind
1092 or else K
in Protected_Kind
1093 or else K
= E_Package
1094 or else K
in Generic_Unit_Kind
1095 or else (K
= E_Variable
1099 Is_Protected_Type
(T
)))
1106 Error_Attr
("prefix of % attribute must be program unit", P
);
1107 end Check_Program_Unit
;
1109 ---------------------
1110 -- Check_Real_Type --
1111 ---------------------
1113 procedure Check_Real_Type
is
1117 if not Is_Real_Type
(P_Type
) then
1118 Error_Attr
("prefix of % attribute must be real type", P
);
1120 end Check_Real_Type
;
1122 -----------------------
1123 -- Check_Scalar_Type --
1124 -----------------------
1126 procedure Check_Scalar_Type
is
1130 if not Is_Scalar_Type
(P_Type
) then
1131 Error_Attr
("prefix of % attribute must be scalar type", P
);
1133 end Check_Scalar_Type
;
1135 ---------------------------
1136 -- Check_Standard_Prefix --
1137 ---------------------------
1139 procedure Check_Standard_Prefix
is
1143 if Nkind
(P
) /= N_Identifier
1144 or else Chars
(P
) /= Name_Standard
1146 Error_Attr
("only allowed prefix for % attribute is Standard", P
);
1149 end Check_Standard_Prefix
;
1151 ----------------------------
1152 -- Check_Stream_Attribute --
1153 ----------------------------
1155 procedure Check_Stream_Attribute
(Nam
: Name_Id
) is
1160 Validate_Non_Static_Attribute_Function_Call
;
1162 -- With the exception of 'Input, Stream attributes are procedures,
1163 -- and can only appear at the position of procedure calls. We check
1164 -- for this here, before they are rewritten, to give a more precise
1167 if Nam
= Name_uInput
then
1170 elsif Is_List_Member
(N
)
1171 and then Nkind
(Parent
(N
)) /= N_Procedure_Call_Statement
1172 and then Nkind
(Parent
(N
)) /= N_Aggregate
1178 ("invalid context for attribute %, which is a procedure", N
);
1182 Btyp
:= Implementation_Base_Type
(P_Type
);
1184 -- Stream attributes not allowed on limited types unless the
1185 -- special OK_For_Stream flag is set.
1187 if Is_Limited_Type
(P_Type
)
1188 and then Comes_From_Source
(N
)
1189 and then not Present
(TSS
(Btyp
, Nam
))
1190 and then No
(Get_Rep_Pragma
(Btyp
, Name_Stream_Convert
))
1192 -- Special case the message if we are compiling the stub version
1193 -- of a remote operation. One error on the type is sufficient.
1195 if (Is_Remote_Types
(Current_Scope
)
1196 or else Is_Remote_Call_Interface
(Current_Scope
))
1197 and then not Error_Posted
(Btyp
)
1199 Error_Msg_Node_2
:= Current_Scope
;
1201 ("limited type& used in& has no stream attributes", P
, Btyp
);
1202 Set_Error_Posted
(Btyp
);
1204 elsif not Error_Posted
(Btyp
) then
1206 ("limited type& has no stream attributes", P
, Btyp
);
1210 -- Here we must check that the first argument is an access type
1211 -- that is compatible with Ada.Streams.Root_Stream_Type'Class.
1213 Analyze_And_Resolve
(E1
);
1216 -- Note: the double call to Root_Type here is needed because the
1217 -- root type of a class-wide type is the corresponding type (e.g.
1218 -- X for X'Class, and we really want to go to the root.
1220 if not Is_Access_Type
(Etyp
)
1221 or else Root_Type
(Root_Type
(Designated_Type
(Etyp
))) /=
1222 RTE
(RE_Root_Stream_Type
)
1225 ("expected access to Ada.Streams.Root_Stream_Type''Class", E1
);
1228 -- Check that the second argument is of the right type if there is
1229 -- one (the Input attribute has only one argument so this is skipped)
1231 if Present
(E2
) then
1235 and then not Is_OK_Variable_For_Out_Formal
(E2
)
1238 ("second argument of % attribute must be a variable", E2
);
1241 Resolve
(E2
, P_Type
);
1243 end Check_Stream_Attribute
;
1245 -----------------------
1246 -- Check_Task_Prefix --
1247 -----------------------
1249 procedure Check_Task_Prefix
is
1253 if Is_Task_Type
(Etype
(P
))
1254 or else (Is_Access_Type
(Etype
(P
))
1255 and then Is_Task_Type
(Designated_Type
(Etype
(P
))))
1257 Resolve
(P
, Etype
(P
));
1259 Error_Attr
("prefix of % attribute must be a task", P
);
1261 end Check_Task_Prefix
;
1267 -- The possibilities are an entity name denoting a type, or an
1268 -- attribute reference that denotes a type (Base or Class). If
1269 -- the type is incomplete, replace it with its full view.
1271 procedure Check_Type
is
1273 if not Is_Entity_Name
(P
)
1274 or else not Is_Type
(Entity
(P
))
1276 Error_Attr
("prefix of % attribute must be a type", P
);
1278 elsif Ekind
(Entity
(P
)) = E_Incomplete_Type
1279 and then Present
(Full_View
(Entity
(P
)))
1281 P_Type
:= Full_View
(Entity
(P
));
1282 Set_Entity
(P
, P_Type
);
1286 ---------------------
1287 -- Check_Unit_Name --
1288 ---------------------
1290 procedure Check_Unit_Name
(Nod
: Node_Id
) is
1292 if Nkind
(Nod
) = N_Identifier
then
1295 elsif Nkind
(Nod
) = N_Selected_Component
then
1296 Check_Unit_Name
(Prefix
(Nod
));
1298 if Nkind
(Selector_Name
(Nod
)) = N_Identifier
then
1303 Error_Attr
("argument for % attribute must be unit name", P
);
1304 end Check_Unit_Name
;
1310 procedure Error_Attr
(Msg
: String; Error_Node
: Node_Id
) is
1312 Error_Msg_Name_1
:= Aname
;
1313 Error_Msg_N
(Msg
, Error_Node
);
1314 Set_Etype
(N
, Any_Type
);
1315 Set_Entity
(N
, Any_Type
);
1316 raise Bad_Attribute
;
1319 ----------------------------
1320 -- Legal_Formal_Attribute --
1321 ----------------------------
1323 procedure Legal_Formal_Attribute
is
1327 if not Is_Entity_Name
(P
)
1328 or else not Is_Type
(Entity
(P
))
1330 Error_Attr
("prefix of % attribute must be generic type", N
);
1332 elsif Is_Generic_Actual_Type
(Entity
(P
))
1337 elsif Is_Generic_Type
(Entity
(P
)) then
1338 if not Is_Indefinite_Subtype
(Entity
(P
)) then
1340 ("prefix of % attribute must be indefinite generic type", N
);
1345 ("prefix of % attribute must be indefinite generic type", N
);
1348 Set_Etype
(N
, Standard_Boolean
);
1349 end Legal_Formal_Attribute
;
1351 ------------------------
1352 -- Standard_Attribute --
1353 ------------------------
1355 procedure Standard_Attribute
(Val
: Int
) is
1357 Check_Standard_Prefix
;
1359 Make_Integer_Literal
(Loc
, Val
));
1361 end Standard_Attribute
;
1363 -------------------------
1364 -- Unexpected Argument --
1365 -------------------------
1367 procedure Unexpected_Argument
(En
: Node_Id
) is
1369 Error_Attr
("unexpected argument for % attribute", En
);
1370 end Unexpected_Argument
;
1372 -------------------------------------------------
1373 -- Validate_Non_Static_Attribute_Function_Call --
1374 -------------------------------------------------
1376 -- This function should be moved to Sem_Dist ???
1378 procedure Validate_Non_Static_Attribute_Function_Call
is
1380 if In_Preelaborated_Unit
1381 and then not In_Subprogram_Or_Concurrent_Unit
1383 Error_Msg_N
("non-static function call in preelaborated unit", N
);
1385 end Validate_Non_Static_Attribute_Function_Call
;
1387 -----------------------------------------------
1388 -- Start of Processing for Analyze_Attribute --
1389 -----------------------------------------------
1392 -- Immediate return if unrecognized attribute (already diagnosed
1393 -- by parser, so there is nothing more that we need to do)
1395 if not Is_Attribute_Name
(Aname
) then
1396 raise Bad_Attribute
;
1399 -- Deal with Ada 83 and Features issues
1401 if not Attribute_83
(Attr_Id
) then
1402 if Ada_83
and then Comes_From_Source
(N
) then
1403 Error_Msg_Name_1
:= Aname
;
1404 Error_Msg_N
("(Ada 83) attribute% is not standard?", N
);
1407 if Attribute_Impl_Def
(Attr_Id
) then
1408 Check_Restriction
(No_Implementation_Attributes
, N
);
1412 -- Remote access to subprogram type access attribute reference needs
1413 -- unanalyzed copy for tree transformation. The analyzed copy is used
1414 -- for its semantic information (whether prefix is a remote subprogram
1415 -- name), the unanalyzed copy is used to construct new subtree rooted
1416 -- with N_aggregate which represents a fat pointer aggregate.
1418 if Aname
= Name_Access
then
1419 Unanalyzed
:= Copy_Separate_Tree
(N
);
1422 -- Analyze prefix and exit if error in analysis. If the prefix is an
1423 -- incomplete type, use full view if available. A special case is
1424 -- that we never analyze the prefix of an Elab_Body or Elab_Spec
1425 -- or UET_Address attribute.
1427 if Aname
/= Name_Elab_Body
1429 Aname
/= Name_Elab_Spec
1431 Aname
/= Name_UET_Address
1434 P_Type
:= Etype
(P
);
1436 if Is_Entity_Name
(P
)
1437 and then Present
(Entity
(P
))
1438 and then Is_Type
(Entity
(P
))
1439 and then Ekind
(Entity
(P
)) = E_Incomplete_Type
1441 P_Type
:= Get_Full_View
(P_Type
);
1442 Set_Entity
(P
, P_Type
);
1443 Set_Etype
(P
, P_Type
);
1446 if P_Type
= Any_Type
then
1447 raise Bad_Attribute
;
1450 P_Base_Type
:= Base_Type
(P_Type
);
1451 P_Root_Type
:= Root_Type
(P_Base_Type
);
1454 -- Analyze expressions that may be present, exiting if an error occurs
1461 E1
:= First
(Exprs
);
1464 -- Check for missing or bad expression (result of previous error)
1466 if No
(E1
) or else Etype
(E1
) = Any_Type
then
1467 raise Bad_Attribute
;
1472 if Present
(E2
) then
1475 if Etype
(E2
) = Any_Type
then
1476 raise Bad_Attribute
;
1479 if Present
(Next
(E2
)) then
1480 Unexpected_Argument
(Next
(E2
));
1485 if Is_Overloaded
(P
)
1486 and then Aname
/= Name_Access
1487 and then Aname
/= Name_Address
1488 and then Aname
/= Name_Code_Address
1489 and then Aname
/= Name_Count
1490 and then Aname
/= Name_Unchecked_Access
1492 Error_Attr
("ambiguous prefix for % attribute", P
);
1495 -- Remaining processing depends on attribute
1503 when Attribute_Abort_Signal
=>
1504 Check_Standard_Prefix
;
1506 New_Reference_To
(Stand
.Abort_Signal
, Loc
));
1513 when Attribute_Access
=>
1520 when Attribute_Address
=>
1523 -- Check for some junk cases, where we have to allow the address
1524 -- attribute but it does not make much sense, so at least for now
1525 -- just replace with Null_Address.
1527 -- We also do this if the prefix is a reference to the AST_Entry
1528 -- attribute. If expansion is active, the attribute will be
1529 -- replaced by a function call, and address will work fine and
1530 -- get the proper value, but if expansion is not active, then
1531 -- the check here allows proper semantic analysis of the reference.
1533 -- An Address attribute created by expansion is legal even when it
1534 -- applies to other entity-denoting expressions.
1536 if (Is_Entity_Name
(P
)) then
1537 if Is_Subprogram
(Entity
(P
)) then
1538 if not Is_Library_Level_Entity
(Entity
(P
)) then
1539 Check_Restriction
(No_Implicit_Dynamic_Code
, P
);
1542 Set_Address_Taken
(Entity
(P
));
1544 elsif Is_Object
(Entity
(P
))
1545 or else Ekind
(Entity
(P
)) = E_Label
1547 Set_Address_Taken
(Entity
(P
));
1549 elsif (Is_Concurrent_Type
(Etype
(Entity
(P
)))
1550 and then Etype
(Entity
(P
)) = Base_Type
(Entity
(P
)))
1551 or else Ekind
(Entity
(P
)) = E_Package
1552 or else Is_Generic_Unit
(Entity
(P
))
1555 New_Occurrence_Of
(RTE
(RE_Null_Address
), Sloc
(N
)));
1558 Error_Attr
("invalid prefix for % attribute", P
);
1561 elsif Nkind
(P
) = N_Attribute_Reference
1562 and then Attribute_Name
(P
) = Name_AST_Entry
1565 New_Occurrence_Of
(RTE
(RE_Null_Address
), Sloc
(N
)));
1567 elsif Is_Object_Reference
(P
) then
1570 elsif Nkind
(P
) = N_Selected_Component
1571 and then Is_Subprogram
(Entity
(Selector_Name
(P
)))
1575 elsif not Comes_From_Source
(N
) then
1579 Error_Attr
("invalid prefix for % attribute", P
);
1582 Set_Etype
(N
, RTE
(RE_Address
));
1588 when Attribute_Address_Size
=>
1589 Standard_Attribute
(System_Address_Size
);
1595 when Attribute_Adjacent
=>
1596 Check_Floating_Point_Type_2
;
1597 Set_Etype
(N
, P_Base_Type
);
1598 Resolve
(E1
, P_Base_Type
);
1599 Resolve
(E2
, P_Base_Type
);
1605 when Attribute_Aft
=>
1606 Check_Fixed_Point_Type_0
;
1607 Set_Etype
(N
, Universal_Integer
);
1613 when Attribute_Alignment
=>
1615 -- Don't we need more checking here, cf Size ???
1618 Check_Not_Incomplete_Type
;
1619 Set_Etype
(N
, Universal_Integer
);
1625 when Attribute_Asm_Input
=>
1626 Check_Asm_Attribute
;
1627 Set_Etype
(N
, RTE
(RE_Asm_Input_Operand
));
1633 when Attribute_Asm_Output
=>
1634 Check_Asm_Attribute
;
1636 if Etype
(E2
) = Any_Type
then
1639 elsif Aname
= Name_Asm_Output
then
1640 if not Is_Variable
(E2
) then
1642 ("second argument for Asm_Output is not variable", E2
);
1646 Note_Possible_Modification
(E2
);
1647 Set_Etype
(N
, RTE
(RE_Asm_Output_Operand
));
1653 when Attribute_AST_Entry
=> AST_Entry
: declare
1659 -- Indicates if entry family index is present. Note the coding
1660 -- here handles the entry family case, but in fact it cannot be
1661 -- executed currently, because pragma AST_Entry does not permit
1662 -- the specification of an entry family.
1664 procedure Bad_AST_Entry
;
1665 -- Signal a bad AST_Entry pragma
1667 function OK_Entry
(E
: Entity_Id
) return Boolean;
1668 -- Checks that E is of an appropriate entity kind for an entry
1669 -- (i.e. E_Entry if Index is False, or E_Entry_Family if Index
1670 -- is set True for the entry family case). In the True case,
1671 -- makes sure that Is_AST_Entry is set on the entry.
1673 procedure Bad_AST_Entry
is
1675 Error_Attr
("prefix for % attribute must be task entry", P
);
1678 function OK_Entry
(E
: Entity_Id
) return Boolean is
1683 Result
:= (Ekind
(E
) = E_Entry_Family
);
1685 Result
:= (Ekind
(E
) = E_Entry
);
1689 if not Is_AST_Entry
(E
) then
1690 Error_Msg_Name_2
:= Aname
;
1692 ("% attribute requires previous % pragma", P
);
1699 -- Start of processing for AST_Entry
1705 -- Deal with entry family case
1707 if Nkind
(P
) = N_Indexed_Component
then
1715 Ptyp
:= Etype
(Pref
);
1717 if Ptyp
= Any_Type
or else Error_Posted
(Pref
) then
1721 -- If the prefix is a selected component whose prefix is of an
1722 -- access type, then introduce an explicit dereference.
1724 if Nkind
(Pref
) = N_Selected_Component
1725 and then Is_Access_Type
(Ptyp
)
1728 Make_Explicit_Dereference
(Sloc
(Pref
),
1729 Relocate_Node
(Pref
)));
1730 Analyze_And_Resolve
(Pref
, Designated_Type
(Ptyp
));
1733 -- Prefix can be of the form a.b, where a is a task object
1734 -- and b is one of the entries of the corresponding task type.
1736 if Nkind
(Pref
) = N_Selected_Component
1737 and then OK_Entry
(Entity
(Selector_Name
(Pref
)))
1738 and then Is_Object_Reference
(Prefix
(Pref
))
1739 and then Is_Task_Type
(Etype
(Prefix
(Pref
)))
1743 -- Otherwise the prefix must be an entry of a containing task,
1744 -- or of a variable of the enclosing task type.
1747 if Nkind
(Pref
) = N_Identifier
1748 or else Nkind
(Pref
) = N_Expanded_Name
1750 Ent
:= Entity
(Pref
);
1752 if not OK_Entry
(Ent
)
1753 or else not In_Open_Scopes
(Scope
(Ent
))
1763 Set_Etype
(N
, RTE
(RE_AST_Handler
));
1770 when Attribute_Base
=> Base
: declare
1774 Check_Either_E0_Or_E1
;
1778 if Sloc
(Typ
) = Standard_Location
1779 and then Base_Type
(Typ
) = Typ
1780 and then Warn_On_Redundant_Constructs
1783 ("?redudant attribute, & is its own base type", N
, Typ
);
1786 Set_Etype
(N
, Base_Type
(Entity
(P
)));
1788 -- If we have an expression present, then really this is a conversion
1789 -- and the tree must be reformed. Note that this is one of the cases
1790 -- in which we do a replace rather than a rewrite, because the
1791 -- original tree is junk.
1793 if Present
(E1
) then
1795 Make_Type_Conversion
(Loc
,
1797 Make_Attribute_Reference
(Loc
,
1798 Prefix
=> Prefix
(N
),
1799 Attribute_Name
=> Name_Base
),
1800 Expression
=> Relocate_Node
(E1
)));
1802 -- E1 may be overloaded, and its interpretations preserved.
1804 Save_Interps
(E1
, Expression
(N
));
1807 -- For other cases, set the proper type as the entity of the
1808 -- attribute reference, and then rewrite the node to be an
1809 -- occurrence of the referenced base type. This way, no one
1810 -- else in the compiler has to worry about the base attribute.
1813 Set_Entity
(N
, Base_Type
(Entity
(P
)));
1815 New_Reference_To
(Entity
(N
), Loc
));
1824 when Attribute_Bit
=> Bit
:
1828 if not Is_Object_Reference
(P
) then
1829 Error_Attr
("prefix for % attribute must be object", P
);
1831 -- What about the access object cases ???
1837 Set_Etype
(N
, Universal_Integer
);
1844 when Attribute_Bit_Order
=> Bit_Order
:
1849 if not Is_Record_Type
(P_Type
) then
1850 Error_Attr
("prefix of % attribute must be record type", P
);
1853 if Bytes_Big_Endian
xor Reverse_Bit_Order
(P_Type
) then
1855 New_Occurrence_Of
(RTE
(RE_High_Order_First
), Loc
));
1858 New_Occurrence_Of
(RTE
(RE_Low_Order_First
), Loc
));
1861 Set_Etype
(N
, RTE
(RE_Bit_Order
));
1862 Resolve
(N
, Etype
(N
));
1864 -- Reset incorrect indication of staticness
1866 Set_Is_Static_Expression
(N
, False);
1873 -- Note: in generated code, we can have a Bit_Position attribute
1874 -- applied to a (naked) record component (i.e. the prefix is an
1875 -- identifier that references an E_Component or E_Discriminant
1876 -- entity directly, and this is interpreted as expected by Gigi.
1877 -- The following code will not tolerate such usage, but when the
1878 -- expander creates this special case, it marks it as analyzed
1879 -- immediately and sets an appropriate type.
1881 when Attribute_Bit_Position
=>
1883 if Comes_From_Source
(N
) then
1887 Set_Etype
(N
, Universal_Integer
);
1893 when Attribute_Body_Version
=>
1896 Set_Etype
(N
, RTE
(RE_Version_String
));
1902 when Attribute_Callable
=>
1904 Set_Etype
(N
, Standard_Boolean
);
1911 when Attribute_Caller
=> Caller
: declare
1918 if Nkind
(P
) = N_Identifier
1919 or else Nkind
(P
) = N_Expanded_Name
1923 if not Is_Entry
(Ent
) then
1924 Error_Attr
("invalid entry name", N
);
1928 Error_Attr
("invalid entry name", N
);
1932 for J
in reverse 0 .. Scope_Stack
.Last
loop
1933 S
:= Scope_Stack
.Table
(J
).Entity
;
1935 if S
= Scope
(Ent
) then
1936 Error_Attr
("Caller must appear in matching accept or body", N
);
1942 Set_Etype
(N
, RTE
(RO_AT_Task_ID
));
1949 when Attribute_Ceiling
=>
1950 Check_Floating_Point_Type_1
;
1951 Set_Etype
(N
, P_Base_Type
);
1952 Resolve
(E1
, P_Base_Type
);
1958 when Attribute_Class
=> Class
: declare
1960 Check_Restriction
(No_Dispatch
, N
);
1961 Check_Either_E0_Or_E1
;
1963 -- If we have an expression present, then really this is a conversion
1964 -- and the tree must be reformed into a proper conversion. This is a
1965 -- Replace rather than a Rewrite, because the original tree is junk.
1966 -- If expression is overloaded, propagate interpretations to new one.
1968 if Present
(E1
) then
1970 Make_Type_Conversion
(Loc
,
1972 Make_Attribute_Reference
(Loc
,
1973 Prefix
=> Prefix
(N
),
1974 Attribute_Name
=> Name_Class
),
1975 Expression
=> Relocate_Node
(E1
)));
1977 Save_Interps
(E1
, Expression
(N
));
1980 -- Otherwise we just need to find the proper type
1992 when Attribute_Code_Address
=>
1995 if Nkind
(P
) = N_Attribute_Reference
1996 and then (Attribute_Name
(P
) = Name_Elab_Body
1998 Attribute_Name
(P
) = Name_Elab_Spec
)
2002 elsif not Is_Entity_Name
(P
)
2003 or else (Ekind
(Entity
(P
)) /= E_Function
2005 Ekind
(Entity
(P
)) /= E_Procedure
)
2007 Error_Attr
("invalid prefix for % attribute", P
);
2008 Set_Address_Taken
(Entity
(P
));
2011 Set_Etype
(N
, RTE
(RE_Address
));
2013 --------------------
2014 -- Component_Size --
2015 --------------------
2017 when Attribute_Component_Size
=>
2019 Set_Etype
(N
, Universal_Integer
);
2021 -- Note: unlike other array attributes, unconstrained arrays are OK
2023 if Is_Array_Type
(P_Type
) and then not Is_Constrained
(P_Type
) then
2033 when Attribute_Compose
=>
2034 Check_Floating_Point_Type_2
;
2035 Set_Etype
(N
, P_Base_Type
);
2036 Resolve
(E1
, P_Base_Type
);
2037 Resolve
(E2
, Any_Integer
);
2043 when Attribute_Constrained
=>
2045 Set_Etype
(N
, Standard_Boolean
);
2047 -- Case from RM J.4(2) of constrained applied to private type
2049 if Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)) then
2051 -- If we are within an instance, the attribute must be legal
2052 -- because it was valid in the generic unit.
2057 -- For sure OK if we have a real private type itself, but must
2058 -- be completed, cannot apply Constrained to incomplete type.
2060 elsif Is_Private_Type
(Entity
(P
)) then
2061 Check_Not_Incomplete_Type
;
2066 Check_Object_Reference
(P
);
2068 -- If N does not come from source, then we allow the
2069 -- the attribute prefix to be of a private type whose
2070 -- full type has discriminants. This occurs in cases
2071 -- involving expanded calls to stream attributes.
2073 if not Comes_From_Source
(N
) then
2074 P_Type
:= Underlying_Type
(P_Type
);
2077 -- Must have discriminants or be an access type designating
2078 -- a type with discriminants. If it is a classwide type is
2079 -- has unknown discriminants.
2081 if Has_Discriminants
(P_Type
)
2082 or else Has_Unknown_Discriminants
(P_Type
)
2084 (Is_Access_Type
(P_Type
)
2085 and then Has_Discriminants
(Designated_Type
(P_Type
)))
2089 -- Also allow an object of a generic type if extensions allowed
2090 -- and allow this for any type at all.
2092 elsif (Is_Generic_Type
(P_Type
)
2093 or else Is_Generic_Actual_Type
(P_Type
))
2094 and then Extensions_Allowed
2100 -- Fall through if bad prefix
2103 ("prefix of % attribute must be object of discriminated type", P
);
2109 when Attribute_Copy_Sign
=>
2110 Check_Floating_Point_Type_2
;
2111 Set_Etype
(N
, P_Base_Type
);
2112 Resolve
(E1
, P_Base_Type
);
2113 Resolve
(E2
, P_Base_Type
);
2119 when Attribute_Count
=> Count
:
2128 if Nkind
(P
) = N_Identifier
2129 or else Nkind
(P
) = N_Expanded_Name
2133 if Ekind
(Ent
) /= E_Entry
then
2134 Error_Attr
("invalid entry name", N
);
2137 elsif Nkind
(P
) = N_Indexed_Component
then
2138 if not Is_Entity_Name
(Prefix
(P
))
2139 or else No
(Entity
(Prefix
(P
)))
2140 or else Ekind
(Entity
(Prefix
(P
))) /= E_Entry_Family
2142 if Nkind
(Prefix
(P
)) = N_Selected_Component
2143 and then Present
(Entity
(Selector_Name
(Prefix
(P
))))
2144 and then Ekind
(Entity
(Selector_Name
(Prefix
(P
)))) =
2148 ("attribute % must apply to entry of current task", P
);
2151 Error_Attr
("invalid entry family name", P
);
2156 Ent
:= Entity
(Prefix
(P
));
2159 elsif Nkind
(P
) = N_Selected_Component
2160 and then Present
(Entity
(Selector_Name
(P
)))
2161 and then Ekind
(Entity
(Selector_Name
(P
))) = E_Entry
2164 ("attribute % must apply to entry of current task", P
);
2167 Error_Attr
("invalid entry name", N
);
2171 for J
in reverse 0 .. Scope_Stack
.Last
loop
2172 S
:= Scope_Stack
.Table
(J
).Entity
;
2174 if S
= Scope
(Ent
) then
2175 if Nkind
(P
) = N_Expanded_Name
then
2176 Tsk
:= Entity
(Prefix
(P
));
2178 -- The prefix denotes either the task type, or else a
2179 -- single task whose task type is being analyzed.
2184 or else (not Is_Type
(Tsk
)
2185 and then Etype
(Tsk
) = S
2186 and then not (Comes_From_Source
(S
)))
2191 ("Attribute % must apply to entry of current task", N
);
2197 elsif Ekind
(Scope
(Ent
)) in Task_Kind
2198 and then Ekind
(S
) /= E_Loop
2199 and then Ekind
(S
) /= E_Block
2200 and then Ekind
(S
) /= E_Entry
2201 and then Ekind
(S
) /= E_Entry_Family
2203 Error_Attr
("Attribute % cannot appear in inner unit", N
);
2205 elsif Ekind
(Scope
(Ent
)) = E_Protected_Type
2206 and then not Has_Completion
(Scope
(Ent
))
2208 Error_Attr
("attribute % can only be used inside body", N
);
2212 if Is_Overloaded
(P
) then
2214 Index
: Interp_Index
;
2218 Get_First_Interp
(P
, Index
, It
);
2220 while Present
(It
.Nam
) loop
2221 if It
.Nam
= Ent
then
2224 elsif Scope
(It
.Nam
) = Scope
(Ent
) then
2225 Error_Attr
("ambiguous entry name", N
);
2228 -- For now make this into a warning. Will become an
2229 -- error after the 3.15 release.
2232 ("ambiguous name, resolved to entry?", N
);
2234 ("\(this will become an error in a later release)?", N
);
2237 Get_Next_Interp
(Index
, It
);
2242 Set_Etype
(N
, Universal_Integer
);
2245 -----------------------
2246 -- Default_Bit_Order --
2247 -----------------------
2249 when Attribute_Default_Bit_Order
=> Default_Bit_Order
:
2251 Check_Standard_Prefix
;
2254 if Bytes_Big_Endian
then
2256 Make_Integer_Literal
(Loc
, False_Value
));
2259 Make_Integer_Literal
(Loc
, True_Value
));
2262 Set_Etype
(N
, Universal_Integer
);
2263 Set_Is_Static_Expression
(N
);
2264 end Default_Bit_Order
;
2270 when Attribute_Definite
=>
2271 Legal_Formal_Attribute
;
2277 when Attribute_Delta
=>
2278 Check_Fixed_Point_Type_0
;
2279 Set_Etype
(N
, Universal_Real
);
2285 when Attribute_Denorm
=>
2286 Check_Floating_Point_Type_0
;
2287 Set_Etype
(N
, Standard_Boolean
);
2293 when Attribute_Digits
=>
2297 if not Is_Floating_Point_Type
(P_Type
)
2298 and then not Is_Decimal_Fixed_Point_Type
(P_Type
)
2301 ("prefix of % attribute must be float or decimal type", P
);
2304 Set_Etype
(N
, Universal_Integer
);
2310 -- Also handles processing for Elab_Spec
2312 when Attribute_Elab_Body | Attribute_Elab_Spec
=>
2314 Check_Unit_Name
(P
);
2315 Set_Etype
(N
, Standard_Void_Type
);
2317 -- We have to manually call the expander in this case to get
2318 -- the necessary expansion (normally attributes that return
2319 -- entities are not expanded).
2327 -- Shares processing with Elab_Body
2333 when Attribute_Elaborated
=>
2336 Set_Etype
(N
, Standard_Boolean
);
2342 when Attribute_Emax
=>
2343 Check_Floating_Point_Type_0
;
2344 Set_Etype
(N
, Universal_Integer
);
2350 when Attribute_Enum_Rep
=> Enum_Rep
: declare
2352 if Present
(E1
) then
2354 Check_Discrete_Type
;
2355 Resolve
(E1
, P_Base_Type
);
2358 if not Is_Entity_Name
(P
)
2359 or else (not Is_Object
(Entity
(P
))
2361 Ekind
(Entity
(P
)) /= E_Enumeration_Literal
)
2364 ("prefix of %attribute must be " &
2365 "discrete type/object or enum literal", P
);
2369 Set_Etype
(N
, Universal_Integer
);
2376 when Attribute_Epsilon
=>
2377 Check_Floating_Point_Type_0
;
2378 Set_Etype
(N
, Universal_Real
);
2384 when Attribute_Exponent
=>
2385 Check_Floating_Point_Type_1
;
2386 Set_Etype
(N
, Universal_Integer
);
2387 Resolve
(E1
, P_Base_Type
);
2393 when Attribute_External_Tag
=>
2397 Set_Etype
(N
, Standard_String
);
2399 if not Is_Tagged_Type
(P_Type
) then
2400 Error_Attr
("prefix of % attribute must be tagged", P
);
2407 when Attribute_First
=>
2408 Check_Array_Or_Scalar_Type
;
2414 when Attribute_First_Bit
=>
2416 Set_Etype
(N
, Universal_Integer
);
2422 when Attribute_Fixed_Value
=>
2424 Check_Fixed_Point_Type
;
2425 Resolve
(E1
, Any_Integer
);
2426 Set_Etype
(N
, P_Base_Type
);
2432 when Attribute_Floor
=>
2433 Check_Floating_Point_Type_1
;
2434 Set_Etype
(N
, P_Base_Type
);
2435 Resolve
(E1
, P_Base_Type
);
2441 when Attribute_Fore
=>
2442 Check_Fixed_Point_Type_0
;
2443 Set_Etype
(N
, Universal_Integer
);
2449 when Attribute_Fraction
=>
2450 Check_Floating_Point_Type_1
;
2451 Set_Etype
(N
, P_Base_Type
);
2452 Resolve
(E1
, P_Base_Type
);
2454 -----------------------
2455 -- Has_Discriminants --
2456 -----------------------
2458 when Attribute_Has_Discriminants
=>
2459 Legal_Formal_Attribute
;
2465 when Attribute_Identity
=>
2469 if Etype
(P
) = Standard_Exception_Type
then
2470 Set_Etype
(N
, RTE
(RE_Exception_Id
));
2472 elsif Is_Task_Type
(Etype
(P
))
2473 or else (Is_Access_Type
(Etype
(P
))
2474 and then Is_Task_Type
(Designated_Type
(Etype
(P
))))
2476 Resolve
(P
, Etype
(P
));
2477 Set_Etype
(N
, RTE
(RO_AT_Task_ID
));
2480 Error_Attr
("prefix of % attribute must be a task or an "
2488 when Attribute_Image
=> Image
:
2490 Set_Etype
(N
, Standard_String
);
2493 if Is_Real_Type
(P_Type
) then
2494 if Ada_83
and then Comes_From_Source
(N
) then
2495 Error_Msg_Name_1
:= Aname
;
2497 ("(Ada 83) % attribute not allowed for real types", N
);
2501 if Is_Enumeration_Type
(P_Type
) then
2502 Check_Restriction
(No_Enumeration_Maps
, N
);
2506 Resolve
(E1
, P_Base_Type
);
2508 Validate_Non_Static_Attribute_Function_Call
;
2515 when Attribute_Img
=> Img
:
2517 Set_Etype
(N
, Standard_String
);
2519 if not Is_Scalar_Type
(P_Type
)
2520 or else (Is_Entity_Name
(P
) and then Is_Type
(Entity
(P
)))
2523 ("prefix of % attribute must be scalar object name", N
);
2533 when Attribute_Input
=>
2535 Check_Stream_Attribute
(Name_uInput
);
2536 Disallow_In_No_Run_Time_Mode
(N
);
2537 Set_Etype
(N
, P_Base_Type
);
2543 when Attribute_Integer_Value
=>
2546 Resolve
(E1
, Any_Fixed
);
2547 Set_Etype
(N
, P_Base_Type
);
2553 when Attribute_Large
=>
2556 Set_Etype
(N
, Universal_Real
);
2562 when Attribute_Last
=>
2563 Check_Array_Or_Scalar_Type
;
2569 when Attribute_Last_Bit
=>
2571 Set_Etype
(N
, Universal_Integer
);
2577 when Attribute_Leading_Part
=>
2578 Check_Floating_Point_Type_2
;
2579 Set_Etype
(N
, P_Base_Type
);
2580 Resolve
(E1
, P_Base_Type
);
2581 Resolve
(E2
, Any_Integer
);
2587 when Attribute_Length
=>
2589 Set_Etype
(N
, Universal_Integer
);
2595 when Attribute_Machine
=>
2596 Check_Floating_Point_Type_1
;
2597 Set_Etype
(N
, P_Base_Type
);
2598 Resolve
(E1
, P_Base_Type
);
2604 when Attribute_Machine_Emax
=>
2605 Check_Floating_Point_Type_0
;
2606 Set_Etype
(N
, Universal_Integer
);
2612 when Attribute_Machine_Emin
=>
2613 Check_Floating_Point_Type_0
;
2614 Set_Etype
(N
, Universal_Integer
);
2616 ----------------------
2617 -- Machine_Mantissa --
2618 ----------------------
2620 when Attribute_Machine_Mantissa
=>
2621 Check_Floating_Point_Type_0
;
2622 Set_Etype
(N
, Universal_Integer
);
2624 -----------------------
2625 -- Machine_Overflows --
2626 -----------------------
2628 when Attribute_Machine_Overflows
=>
2631 Set_Etype
(N
, Standard_Boolean
);
2637 when Attribute_Machine_Radix
=>
2640 Set_Etype
(N
, Universal_Integer
);
2642 --------------------
2643 -- Machine_Rounds --
2644 --------------------
2646 when Attribute_Machine_Rounds
=>
2649 Set_Etype
(N
, Standard_Boolean
);
2655 when Attribute_Machine_Size
=>
2658 Check_Not_Incomplete_Type
;
2659 Set_Etype
(N
, Universal_Integer
);
2665 when Attribute_Mantissa
=>
2668 Set_Etype
(N
, Universal_Integer
);
2674 when Attribute_Max
=>
2677 Resolve
(E1
, P_Base_Type
);
2678 Resolve
(E2
, P_Base_Type
);
2679 Set_Etype
(N
, P_Base_Type
);
2681 ----------------------------------
2682 -- Max_Size_In_Storage_Elements --
2683 ----------------------------------
2685 when Attribute_Max_Size_In_Storage_Elements
=>
2688 Check_Not_Incomplete_Type
;
2689 Set_Etype
(N
, Universal_Integer
);
2691 -----------------------
2692 -- Maximum_Alignment --
2693 -----------------------
2695 when Attribute_Maximum_Alignment
=>
2696 Standard_Attribute
(Ttypes
.Maximum_Alignment
);
2698 --------------------
2699 -- Mechanism_Code --
2700 --------------------
2702 when Attribute_Mechanism_Code
=>
2704 if not Is_Entity_Name
(P
)
2705 or else not Is_Subprogram
(Entity
(P
))
2707 Error_Attr
("prefix of % attribute must be subprogram", P
);
2710 Check_Either_E0_Or_E1
;
2712 if Present
(E1
) then
2713 Resolve
(E1
, Any_Integer
);
2714 Set_Etype
(E1
, Standard_Integer
);
2716 if not Is_Static_Expression
(E1
) then
2718 ("expression for parameter number must be static", E1
);
2720 elsif UI_To_Int
(Intval
(E1
)) > Number_Formals
(Entity
(P
))
2721 or else UI_To_Int
(Intval
(E1
)) < 0
2723 Error_Attr
("invalid parameter number for %attribute", E1
);
2727 Set_Etype
(N
, Universal_Integer
);
2733 when Attribute_Min
=>
2736 Resolve
(E1
, P_Base_Type
);
2737 Resolve
(E2
, P_Base_Type
);
2738 Set_Etype
(N
, P_Base_Type
);
2744 when Attribute_Model
=>
2745 Check_Floating_Point_Type_1
;
2746 Set_Etype
(N
, P_Base_Type
);
2747 Resolve
(E1
, P_Base_Type
);
2753 when Attribute_Model_Emin
=>
2754 Check_Floating_Point_Type_0
;
2755 Set_Etype
(N
, Universal_Integer
);
2761 when Attribute_Model_Epsilon
=>
2762 Check_Floating_Point_Type_0
;
2763 Set_Etype
(N
, Universal_Real
);
2765 --------------------
2766 -- Model_Mantissa --
2767 --------------------
2769 when Attribute_Model_Mantissa
=>
2770 Check_Floating_Point_Type_0
;
2771 Set_Etype
(N
, Universal_Integer
);
2777 when Attribute_Model_Small
=>
2778 Check_Floating_Point_Type_0
;
2779 Set_Etype
(N
, Universal_Real
);
2785 when Attribute_Modulus
=>
2789 if not Is_Modular_Integer_Type
(P_Type
) then
2790 Error_Attr
("prefix of % attribute must be modular type", P
);
2793 Set_Etype
(N
, Universal_Integer
);
2795 --------------------
2796 -- Null_Parameter --
2797 --------------------
2799 when Attribute_Null_Parameter
=> Null_Parameter
: declare
2800 Parnt
: constant Node_Id
:= Parent
(N
);
2801 GParnt
: constant Node_Id
:= Parent
(Parnt
);
2803 procedure Bad_Null_Parameter
(Msg
: String);
2804 -- Used if bad Null parameter attribute node is found. Issues
2805 -- given error message, and also sets the type to Any_Type to
2806 -- avoid blowups later on from dealing with a junk node.
2808 procedure Must_Be_Imported
(Proc_Ent
: Entity_Id
);
2809 -- Called to check that Proc_Ent is imported subprogram
2811 ------------------------
2812 -- Bad_Null_Parameter --
2813 ------------------------
2815 procedure Bad_Null_Parameter
(Msg
: String) is
2817 Error_Msg_N
(Msg
, N
);
2818 Set_Etype
(N
, Any_Type
);
2819 end Bad_Null_Parameter
;
2821 ----------------------
2822 -- Must_Be_Imported --
2823 ----------------------
2825 procedure Must_Be_Imported
(Proc_Ent
: Entity_Id
) is
2826 Pent
: Entity_Id
:= Proc_Ent
;
2829 while Present
(Alias
(Pent
)) loop
2830 Pent
:= Alias
(Pent
);
2833 -- Ignore check if procedure not frozen yet (we will get
2834 -- another chance when the default parameter is reanalyzed)
2836 if not Is_Frozen
(Pent
) then
2839 elsif not Is_Imported
(Pent
) then
2841 ("Null_Parameter can only be used with imported subprogram");
2846 end Must_Be_Imported
;
2848 -- Start of processing for Null_Parameter
2853 Set_Etype
(N
, P_Type
);
2855 -- Case of attribute used as default expression
2857 if Nkind
(Parnt
) = N_Parameter_Specification
then
2858 Must_Be_Imported
(Defining_Entity
(GParnt
));
2860 -- Case of attribute used as actual for subprogram (positional)
2862 elsif (Nkind
(Parnt
) = N_Procedure_Call_Statement
2864 Nkind
(Parnt
) = N_Function_Call
)
2865 and then Is_Entity_Name
(Name
(Parnt
))
2867 Must_Be_Imported
(Entity
(Name
(Parnt
)));
2869 -- Case of attribute used as actual for subprogram (named)
2871 elsif Nkind
(Parnt
) = N_Parameter_Association
2872 and then (Nkind
(GParnt
) = N_Procedure_Call_Statement
2874 Nkind
(GParnt
) = N_Function_Call
)
2875 and then Is_Entity_Name
(Name
(GParnt
))
2877 Must_Be_Imported
(Entity
(Name
(GParnt
)));
2879 -- Not an allowed case
2883 ("Null_Parameter must be actual or default parameter");
2892 when Attribute_Object_Size
=>
2895 Check_Not_Incomplete_Type
;
2896 Set_Etype
(N
, Universal_Integer
);
2902 when Attribute_Output
=>
2904 Check_Stream_Attribute
(Name_uInput
);
2905 Set_Etype
(N
, Standard_Void_Type
);
2906 Disallow_In_No_Run_Time_Mode
(N
);
2907 Resolve
(N
, Standard_Void_Type
);
2913 when Attribute_Partition_ID
=>
2916 if P_Type
/= Any_Type
then
2917 if not Is_Library_Level_Entity
(Entity
(P
)) then
2919 ("prefix of % attribute must be library-level entity", P
);
2921 -- The defining entity of prefix should not be declared inside
2922 -- a Pure unit. RM E.1(8).
2923 -- The Is_Pure flag has been set during declaration.
2925 elsif Is_Entity_Name
(P
)
2926 and then Is_Pure
(Entity
(P
))
2929 ("prefix of % attribute must not be declared pure", P
);
2933 Set_Etype
(N
, Universal_Integer
);
2935 -------------------------
2936 -- Passed_By_Reference --
2937 -------------------------
2939 when Attribute_Passed_By_Reference
=>
2942 Set_Etype
(N
, Standard_Boolean
);
2948 when Attribute_Pos
=>
2949 Check_Discrete_Type
;
2951 Resolve
(E1
, P_Base_Type
);
2952 Set_Etype
(N
, Universal_Integer
);
2958 when Attribute_Position
=>
2960 Set_Etype
(N
, Universal_Integer
);
2966 when Attribute_Pred
=>
2969 Resolve
(E1
, P_Base_Type
);
2970 Set_Etype
(N
, P_Base_Type
);
2972 -- Nothing to do for real type case
2974 if Is_Real_Type
(P_Type
) then
2977 -- If not modular type, test for overflow check required
2980 if not Is_Modular_Integer_Type
(P_Type
)
2981 and then not Range_Checks_Suppressed
(P_Base_Type
)
2983 Enable_Range_Check
(E1
);
2991 when Attribute_Range
=>
2992 Check_Array_Or_Scalar_Type
;
2995 and then Is_Scalar_Type
(P_Type
)
2996 and then Comes_From_Source
(N
)
2999 ("(Ada 83) % attribute not allowed for scalar type", P
);
3006 when Attribute_Range_Length
=>
3007 Check_Discrete_Type
;
3008 Set_Etype
(N
, Universal_Integer
);
3014 when Attribute_Read
=>
3016 Check_Stream_Attribute
(Name_uRead
);
3017 Set_Etype
(N
, Standard_Void_Type
);
3018 Resolve
(N
, Standard_Void_Type
);
3019 Disallow_In_No_Run_Time_Mode
(N
);
3020 Note_Possible_Modification
(E2
);
3026 when Attribute_Remainder
=>
3027 Check_Floating_Point_Type_2
;
3028 Set_Etype
(N
, P_Base_Type
);
3029 Resolve
(E1
, P_Base_Type
);
3030 Resolve
(E2
, P_Base_Type
);
3036 when Attribute_Round
=>
3038 Check_Decimal_Fixed_Point_Type
;
3039 Set_Etype
(N
, P_Base_Type
);
3041 -- Because the context is universal_real (3.5.10(12)) it is a legal
3042 -- context for a universal fixed expression. This is the only
3043 -- attribute whose functional description involves U_R.
3045 if Etype
(E1
) = Universal_Fixed
then
3047 Conv
: constant Node_Id
:= Make_Type_Conversion
(Loc
,
3048 Subtype_Mark
=> New_Occurrence_Of
(Universal_Real
, Loc
),
3049 Expression
=> Relocate_Node
(E1
));
3057 Resolve
(E1
, Any_Real
);
3063 when Attribute_Rounding
=>
3064 Check_Floating_Point_Type_1
;
3065 Set_Etype
(N
, P_Base_Type
);
3066 Resolve
(E1
, P_Base_Type
);
3072 when Attribute_Safe_Emax
=>
3073 Check_Floating_Point_Type_0
;
3074 Set_Etype
(N
, Universal_Integer
);
3080 when Attribute_Safe_First
=>
3081 Check_Floating_Point_Type_0
;
3082 Set_Etype
(N
, Universal_Real
);
3088 when Attribute_Safe_Large
=>
3091 Set_Etype
(N
, Universal_Real
);
3097 when Attribute_Safe_Last
=>
3098 Check_Floating_Point_Type_0
;
3099 Set_Etype
(N
, Universal_Real
);
3105 when Attribute_Safe_Small
=>
3108 Set_Etype
(N
, Universal_Real
);
3114 when Attribute_Scale
=>
3116 Check_Decimal_Fixed_Point_Type
;
3117 Set_Etype
(N
, Universal_Integer
);
3123 when Attribute_Scaling
=>
3124 Check_Floating_Point_Type_2
;
3125 Set_Etype
(N
, P_Base_Type
);
3126 Resolve
(E1
, P_Base_Type
);
3132 when Attribute_Signed_Zeros
=>
3133 Check_Floating_Point_Type_0
;
3134 Set_Etype
(N
, Standard_Boolean
);
3140 when Attribute_Size | Attribute_VADS_Size
=>
3143 if Is_Object_Reference
(P
)
3144 or else (Is_Entity_Name
(P
)
3145 and then Ekind
(Entity
(P
)) = E_Function
)
3147 Check_Object_Reference
(P
);
3149 elsif Is_Entity_Name
(P
)
3150 and then Is_Type
(Entity
(P
))
3154 elsif Nkind
(P
) = N_Type_Conversion
3155 and then not Comes_From_Source
(P
)
3160 Error_Attr
("invalid prefix for % attribute", P
);
3163 Check_Not_Incomplete_Type
;
3164 Set_Etype
(N
, Universal_Integer
);
3170 when Attribute_Small
=>
3173 Set_Etype
(N
, Universal_Real
);
3179 when Attribute_Storage_Pool
=>
3180 if Is_Access_Type
(P_Type
) then
3183 -- Set appropriate entity
3185 if Present
(Associated_Storage_Pool
(Root_Type
(P_Type
))) then
3186 Set_Entity
(N
, Associated_Storage_Pool
(Root_Type
(P_Type
)));
3188 Set_Entity
(N
, RTE
(RE_Global_Pool_Object
));
3191 Set_Etype
(N
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
3193 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
3194 -- Storage_Pool since this attribute is not defined for such
3195 -- types (RM E.2.3(22)).
3197 Validate_Remote_Access_To_Class_Wide_Type
(N
);
3200 Error_Attr
("prefix of % attribute must be access type", P
);
3207 when Attribute_Storage_Size
=>
3209 if Is_Task_Type
(P_Type
) then
3211 Set_Etype
(N
, Universal_Integer
);
3213 elsif Is_Access_Type
(P_Type
) then
3214 if Is_Entity_Name
(P
)
3215 and then Is_Type
(Entity
(P
))
3219 Set_Etype
(N
, Universal_Integer
);
3221 -- Validate_Remote_Access_To_Class_Wide_Type for attribute
3222 -- Storage_Size since this attribute is not defined for
3223 -- such types (RM E.2.3(22)).
3225 Validate_Remote_Access_To_Class_Wide_Type
(N
);
3227 -- The prefix is allowed to be an implicit dereference
3228 -- of an access value designating a task.
3233 Set_Etype
(N
, Universal_Integer
);
3238 ("prefix of % attribute must be access or task type", P
);
3245 when Attribute_Storage_Unit
=>
3246 Standard_Attribute
(Ttypes
.System_Storage_Unit
);
3252 when Attribute_Succ
=>
3255 Resolve
(E1
, P_Base_Type
);
3256 Set_Etype
(N
, P_Base_Type
);
3258 -- Nothing to do for real type case
3260 if Is_Real_Type
(P_Type
) then
3263 -- If not modular type, test for overflow check required.
3266 if not Is_Modular_Integer_Type
(P_Type
)
3267 and then not Range_Checks_Suppressed
(P_Base_Type
)
3269 Enable_Range_Check
(E1
);
3277 when Attribute_Tag
=>
3281 if not Is_Tagged_Type
(P_Type
) then
3282 Error_Attr
("prefix of % attribute must be tagged", P
);
3284 -- Next test does not apply to generated code
3285 -- why not, and what does the illegal reference mean???
3287 elsif Is_Object_Reference
(P
)
3288 and then not Is_Class_Wide_Type
(P_Type
)
3289 and then Comes_From_Source
(N
)
3292 ("% attribute can only be applied to objects of class-wide type",
3296 Set_Etype
(N
, RTE
(RE_Tag
));
3302 when Attribute_Terminated
=>
3304 Set_Etype
(N
, Standard_Boolean
);
3311 when Attribute_To_Address
=>
3315 if Nkind
(P
) /= N_Identifier
3316 or else Chars
(P
) /= Name_System
3318 Error_Attr
("prefix of %attribute must be System", P
);
3321 Generate_Reference
(RTE
(RE_Address
), P
);
3322 Analyze_And_Resolve
(E1
, Any_Integer
);
3323 Set_Etype
(N
, RTE
(RE_Address
));
3329 when Attribute_Truncation
=>
3330 Check_Floating_Point_Type_1
;
3331 Resolve
(E1
, P_Base_Type
);
3332 Set_Etype
(N
, P_Base_Type
);
3338 when Attribute_Type_Class
=>
3341 Check_Not_Incomplete_Type
;
3342 Set_Etype
(N
, RTE
(RE_Type_Class
));
3348 when Attribute_UET_Address
=>
3350 Check_Unit_Name
(P
);
3351 Set_Etype
(N
, RTE
(RE_Address
));
3353 -----------------------
3354 -- Unbiased_Rounding --
3355 -----------------------
3357 when Attribute_Unbiased_Rounding
=>
3358 Check_Floating_Point_Type_1
;
3359 Set_Etype
(N
, P_Base_Type
);
3360 Resolve
(E1
, P_Base_Type
);
3362 ----------------------
3363 -- Unchecked_Access --
3364 ----------------------
3366 when Attribute_Unchecked_Access
=>
3367 if Comes_From_Source
(N
) then
3368 Check_Restriction
(No_Unchecked_Access
, N
);
3373 ------------------------------
3374 -- Universal_Literal_String --
3375 ------------------------------
3377 -- This is a GNAT specific attribute whose prefix must be a named
3378 -- number where the expression is either a single numeric literal,
3379 -- or a numeric literal immediately preceded by a minus sign. The
3380 -- result is equivalent to a string literal containing the text of
3381 -- the literal as it appeared in the source program with a possible
3382 -- leading minus sign.
3384 when Attribute_Universal_Literal_String
=> Universal_Literal_String
:
3388 if not Is_Entity_Name
(P
)
3389 or else Ekind
(Entity
(P
)) not in Named_Kind
3391 Error_Attr
("prefix for % attribute must be named number", P
);
3398 Src
: Source_Buffer_Ptr
;
3401 Expr
:= Original_Node
(Expression
(Parent
(Entity
(P
))));
3403 if Nkind
(Expr
) = N_Op_Minus
then
3405 Expr
:= Original_Node
(Right_Opnd
(Expr
));
3410 if Nkind
(Expr
) /= N_Integer_Literal
3411 and then Nkind
(Expr
) /= N_Real_Literal
3414 ("named number for % attribute must be simple literal", N
);
3417 -- Build string literal corresponding to source literal text
3422 Store_String_Char
(Get_Char_Code
('-'));
3426 Src
:= Source_Text
(Get_Source_File_Index
(S
));
3428 while Src
(S
) /= ';' and then Src
(S
) /= ' ' loop
3429 Store_String_Char
(Get_Char_Code
(Src
(S
)));
3433 -- Now we rewrite the attribute with the string literal
3436 Make_String_Literal
(Loc
, End_String
));
3440 end Universal_Literal_String
;
3442 -------------------------
3443 -- Unrestricted_Access --
3444 -------------------------
3446 -- This is a GNAT specific attribute which is like Access except that
3447 -- all scope checks and checks for aliased views are omitted.
3449 when Attribute_Unrestricted_Access
=>
3450 if Comes_From_Source
(N
) then
3451 Check_Restriction
(No_Unchecked_Access
, N
);
3454 if Is_Entity_Name
(P
) then
3455 Set_Address_Taken
(Entity
(P
));
3464 when Attribute_Val
=> Val
: declare
3467 Check_Discrete_Type
;
3468 Resolve
(E1
, Any_Integer
);
3469 Set_Etype
(N
, P_Base_Type
);
3471 -- Note, we need a range check in general, but we wait for the
3472 -- Resolve call to do this, since we want to let Eval_Attribute
3473 -- have a chance to find an static illegality first!
3480 when Attribute_Valid
=>
3483 -- Ignore check for object if we have a 'Valid reference generated
3484 -- by the expanded code, since in some cases valid checks can occur
3485 -- on items that are names, but are not objects (e.g. attributes).
3487 if Comes_From_Source
(N
) then
3488 Check_Object_Reference
(P
);
3491 if not Is_Scalar_Type
(P_Type
) then
3492 Error_Attr
("object for % attribute must be of scalar type", P
);
3495 Set_Etype
(N
, Standard_Boolean
);
3501 when Attribute_Value
=> Value
:
3506 if Is_Enumeration_Type
(P_Type
) then
3507 Check_Restriction
(No_Enumeration_Maps
, N
);
3510 -- Set Etype before resolving expression because expansion
3511 -- of expression may require enclosing type.
3513 Set_Etype
(N
, P_Type
);
3514 Validate_Non_Static_Attribute_Function_Call
;
3521 when Attribute_Value_Size
=>
3524 Check_Not_Incomplete_Type
;
3525 Set_Etype
(N
, Universal_Integer
);
3531 when Attribute_Version
=>
3534 Set_Etype
(N
, RTE
(RE_Version_String
));
3540 when Attribute_Wchar_T_Size
=>
3541 Standard_Attribute
(Interfaces_Wchar_T_Size
);
3547 when Attribute_Wide_Image
=> Wide_Image
:
3550 Set_Etype
(N
, Standard_Wide_String
);
3552 Resolve
(E1
, P_Base_Type
);
3553 Validate_Non_Static_Attribute_Function_Call
;
3560 when Attribute_Wide_Value
=> Wide_Value
:
3565 -- Set Etype before resolving expression because expansion
3566 -- of expression may require enclosing type.
3568 Set_Etype
(N
, P_Type
);
3569 Validate_Non_Static_Attribute_Function_Call
;
3576 when Attribute_Wide_Width
=>
3579 Set_Etype
(N
, Universal_Integer
);
3585 when Attribute_Width
=>
3588 Set_Etype
(N
, Universal_Integer
);
3594 when Attribute_Word_Size
=>
3595 Standard_Attribute
(System_Word_Size
);
3601 when Attribute_Write
=>
3603 Check_Stream_Attribute
(Name_uWrite
);
3604 Set_Etype
(N
, Standard_Void_Type
);
3605 Disallow_In_No_Run_Time_Mode
(N
);
3606 Resolve
(N
, Standard_Void_Type
);
3610 -- All errors raise Bad_Attribute, so that we get out before any further
3611 -- damage occurs when an error is detected (for example, if we check for
3612 -- one attribute expression, and the check succeeds, we want to be able
3613 -- to proceed securely assuming that an expression is in fact present.
3616 when Bad_Attribute
=>
3617 Set_Etype
(N
, Any_Type
);
3620 end Analyze_Attribute
;
3622 --------------------
3623 -- Eval_Attribute --
3624 --------------------
3626 procedure Eval_Attribute
(N
: Node_Id
) is
3627 Loc
: constant Source_Ptr
:= Sloc
(N
);
3628 Aname
: constant Name_Id
:= Attribute_Name
(N
);
3629 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Aname
);
3630 P
: constant Node_Id
:= Prefix
(N
);
3632 C_Type
: constant Entity_Id
:= Etype
(N
);
3633 -- The type imposed by the context.
3636 -- First expression, or Empty if none
3639 -- Second expression, or Empty if none
3641 P_Entity
: Entity_Id
;
3642 -- Entity denoted by prefix
3645 -- The type of the prefix
3647 P_Base_Type
: Entity_Id
;
3648 -- The base type of the prefix type
3650 P_Root_Type
: Entity_Id
;
3651 -- The root type of the prefix type
3654 -- True if prefix type is static
3656 Lo_Bound
, Hi_Bound
: Node_Id
;
3657 -- Expressions for low and high bounds of type or array index referenced
3658 -- by First, Last, or Length attribute for array, set by Set_Bounds.
3661 -- Constraint error node used if we have an attribute reference has
3662 -- an argument that raises a constraint error. In this case we replace
3663 -- the attribute with a raise constraint_error node. This is important
3664 -- processing, since otherwise gigi might see an attribute which it is
3665 -- unprepared to deal with.
3667 function Aft_Value
return Nat
;
3668 -- Computes Aft value for current attribute prefix (used by Aft itself
3669 -- and also by Width for computing the Width of a fixed point type).
3671 procedure Check_Expressions
;
3672 -- In case where the attribute is not foldable, the expressions, if
3673 -- any, of the attribute, are in a non-static context. This procedure
3674 -- performs the required additional checks.
3676 procedure Compile_Time_Known_Attribute
(N
: Node_Id
; Val
: Uint
);
3677 -- This procedure is called when the attribute N has a non-static
3678 -- but compile time known value given by Val. It includes the
3679 -- necessary checks for out of range values.
3681 procedure Float_Attribute_Universal_Integer
3688 -- This procedure evaluates a float attribute with no arguments that
3689 -- returns a universal integer result. The parameters give the values
3690 -- for the possible floating-point root types. See ttypef for details.
3691 -- The prefix type is a float type (and is thus not a generic type).
3693 procedure Float_Attribute_Universal_Real
3694 (IEEES_Val
: String;
3699 VAXGF_Val
: String);
3700 -- This procedure evaluates a float attribute with no arguments that
3701 -- returns a universal real result. The parameters give the values
3702 -- required for the possible floating-point root types in string
3703 -- format as real literals with a possible leading minus sign.
3704 -- The prefix type is a float type (and is thus not a generic type).
3706 function Fore_Value
return Nat
;
3707 -- Computes the Fore value for the current attribute prefix, which is
3708 -- known to be a static fixed-point type. Used by Fore and Width.
3710 function Mantissa
return Uint
;
3711 -- Returns the Mantissa value for the prefix type
3713 procedure Set_Bounds
;
3714 -- Used for First, Last and Length attributes applied to an array or
3715 -- array subtype. Sets the variables Index_Lo and Index_Hi to the low
3716 -- and high bound expressions for the index referenced by the attribute
3717 -- designator (i.e. the first index if no expression is present, and
3718 -- the N'th index if the value N is present as an expression). Also
3719 -- used for First and Last of scalar types.
3725 function Aft_Value
return Nat
is
3731 Delta_Val
:= Delta_Value
(P_Type
);
3733 while Delta_Val
< Ureal_Tenth
loop
3734 Delta_Val
:= Delta_Val
* Ureal_10
;
3735 Result
:= Result
+ 1;
3741 -----------------------
3742 -- Check_Expressions --
3743 -----------------------
3745 procedure Check_Expressions
is
3749 while Present
(E
) loop
3750 Check_Non_Static_Context
(E
);
3753 end Check_Expressions
;
3755 ----------------------------------
3756 -- Compile_Time_Known_Attribute --
3757 ----------------------------------
3759 procedure Compile_Time_Known_Attribute
(N
: Node_Id
; Val
: Uint
) is
3760 T
: constant Entity_Id
:= Etype
(N
);
3764 Set_Is_Static_Expression
(N
, False);
3766 -- Check that result is in bounds of the type if it is static
3768 if Is_In_Range
(N
, T
) then
3771 elsif Is_Out_Of_Range
(N
, T
) then
3772 Apply_Compile_Time_Constraint_Error
3773 (N
, "value not in range of}?", CE_Range_Check_Failed
);
3775 elsif not Range_Checks_Suppressed
(T
) then
3776 Enable_Range_Check
(N
);
3779 Set_Do_Range_Check
(N
, False);
3781 end Compile_Time_Known_Attribute
;
3783 ---------------------------------------
3784 -- Float_Attribute_Universal_Integer --
3785 ---------------------------------------
3787 procedure Float_Attribute_Universal_Integer
3796 Digs
: constant Nat
:= UI_To_Int
(Digits_Value
(P_Base_Type
));
3799 if not Vax_Float
(P_Base_Type
) then
3800 if Digs
= IEEES_Digits
then
3802 elsif Digs
= IEEEL_Digits
then
3804 else pragma Assert
(Digs
= IEEEX_Digits
);
3809 if Digs
= VAXFF_Digits
then
3811 elsif Digs
= VAXDF_Digits
then
3813 else pragma Assert
(Digs
= VAXGF_Digits
);
3818 Fold_Uint
(N
, UI_From_Int
(Val
));
3819 end Float_Attribute_Universal_Integer
;
3821 ------------------------------------
3822 -- Float_Attribute_Universal_Real --
3823 ------------------------------------
3825 procedure Float_Attribute_Universal_Real
3826 (IEEES_Val
: String;
3834 Digs
: constant Nat
:= UI_To_Int
(Digits_Value
(P_Base_Type
));
3837 if not Vax_Float
(P_Base_Type
) then
3838 if Digs
= IEEES_Digits
then
3839 Val
:= Real_Convert
(IEEES_Val
);
3840 elsif Digs
= IEEEL_Digits
then
3841 Val
:= Real_Convert
(IEEEL_Val
);
3842 else pragma Assert
(Digs
= IEEEX_Digits
);
3843 Val
:= Real_Convert
(IEEEX_Val
);
3847 if Digs
= VAXFF_Digits
then
3848 Val
:= Real_Convert
(VAXFF_Val
);
3849 elsif Digs
= VAXDF_Digits
then
3850 Val
:= Real_Convert
(VAXDF_Val
);
3851 else pragma Assert
(Digs
= VAXGF_Digits
);
3852 Val
:= Real_Convert
(VAXGF_Val
);
3856 Set_Sloc
(Val
, Loc
);
3858 Analyze_And_Resolve
(N
, C_Type
);
3859 end Float_Attribute_Universal_Real
;
3865 -- Note that the Fore calculation is based on the actual values
3866 -- of the bounds, and does not take into account possible rounding.
3868 function Fore_Value
return Nat
is
3869 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(P_Type
));
3870 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(P_Type
));
3871 Small
: constant Ureal
:= Small_Value
(P_Type
);
3872 Lo_Real
: constant Ureal
:= Lo
* Small
;
3873 Hi_Real
: constant Ureal
:= Hi
* Small
;
3878 -- Bounds are given in terms of small units, so first compute
3879 -- proper values as reals.
3881 T
:= UR_Max
(abs Lo_Real
, abs Hi_Real
);
3884 -- Loop to compute proper value if more than one digit required
3886 while T
>= Ureal_10
loop
3898 -- Table of mantissa values accessed by function Computed using
3901 -- T'Mantissa = integer next above (D * log(10)/log(2)) + 1)
3903 -- where D is T'Digits (RM83 3.5.7)
3905 Mantissa_Value
: constant array (Nat
range 1 .. 40) of Nat
:= (
3947 function Mantissa
return Uint
is
3950 UI_From_Int
(Mantissa_Value
(UI_To_Int
(Digits_Value
(P_Type
))));
3957 procedure Set_Bounds
is
3963 -- For a string literal subtype, we have to construct the bounds.
3964 -- Valid Ada code never applies attributes to string literals, but
3965 -- it is convenient to allow the expander to generate attribute
3966 -- references of this type (e.g. First and Last applied to a string
3969 -- Note that the whole point of the E_String_Literal_Subtype is to
3970 -- avoid this construction of bounds, but the cases in which we
3971 -- have to materialize them are rare enough that we don't worry!
3973 -- The low bound is simply the low bound of the base type. The
3974 -- high bound is computed from the length of the string and this
3977 if Ekind
(P_Type
) = E_String_Literal_Subtype
then
3979 Type_Low_Bound
(Etype
(First_Index
(Base_Type
(P_Type
))));
3982 Make_Integer_Literal
(Sloc
(P
),
3984 Expr_Value
(Lo_Bound
) + String_Literal_Length
(P_Type
) - 1);
3986 Set_Parent
(Hi_Bound
, P
);
3987 Analyze_And_Resolve
(Hi_Bound
, Etype
(Lo_Bound
));
3990 -- For non-array case, just get bounds of scalar type
3992 elsif Is_Scalar_Type
(P_Type
) then
3995 if Is_Fixed_Point_Type
(P_Type
)
3996 and then not Is_Frozen
(Base_Type
(P_Type
))
3997 and then Compile_Time_Known_Value
(Type_Low_Bound
(P_Type
))
3998 and then Compile_Time_Known_Value
(Type_High_Bound
(P_Type
))
4000 Freeze_Fixed_Point_Type
(Base_Type
(P_Type
));
4003 -- For array case, get type of proper index
4009 Ndim
:= UI_To_Int
(Expr_Value
(E1
));
4012 Indx
:= First_Index
(P_Type
);
4013 for J
in 1 .. Ndim
- 1 loop
4017 -- If no index type, get out (some other error occurred, and
4018 -- we don't have enough information to complete the job!)
4026 Ityp
:= Etype
(Indx
);
4029 -- A discrete range in an index constraint is allowed to be a
4030 -- subtype indication. This is syntactically a pain, but should
4031 -- not propagate to the entity for the corresponding index subtype.
4032 -- After checking that the subtype indication is legal, the range
4033 -- of the subtype indication should be transfered to the entity.
4034 -- The attributes for the bounds should remain the simple retrievals
4035 -- that they are now.
4037 Lo_Bound
:= Type_Low_Bound
(Ityp
);
4038 Hi_Bound
:= Type_High_Bound
(Ityp
);
4042 -- Start of processing for Eval_Attribute
4045 -- Acquire first two expressions (at the moment, no attributes
4046 -- take more than two expressions in any case).
4048 if Present
(Expressions
(N
)) then
4049 E1
:= First
(Expressions
(N
));
4056 -- Special processing for cases where the prefix is an object
4058 if Is_Object_Reference
(P
) then
4060 -- For Component_Size, the prefix is an array object, and we apply
4061 -- the attribute to the type of the object. This is allowed for
4062 -- both unconstrained and constrained arrays, since the bounds
4063 -- have no influence on the value of this attribute.
4065 if Id
= Attribute_Component_Size
then
4066 P_Entity
:= Etype
(P
);
4068 -- For First and Last, the prefix is an array object, and we apply
4069 -- the attribute to the type of the array, but we need a constrained
4070 -- type for this, so we use the actual subtype if available.
4072 elsif Id
= Attribute_First
4076 Id
= Attribute_Length
4079 AS
: constant Entity_Id
:= Get_Actual_Subtype_If_Available
(P
);
4082 if Present
(AS
) then
4085 -- If no actual subtype, cannot fold
4093 -- For Size, give size of object if available, otherwise we
4094 -- cannot fold Size.
4096 elsif Id
= Attribute_Size
then
4098 if Is_Entity_Name
(P
)
4099 and then Known_Esize
(Entity
(P
))
4101 Compile_Time_Known_Attribute
(N
, Esize
(Entity
(P
)));
4109 -- For Alignment, give size of object if available, otherwise we
4110 -- cannot fold Alignment.
4112 elsif Id
= Attribute_Alignment
then
4114 if Is_Entity_Name
(P
)
4115 and then Known_Alignment
(Entity
(P
))
4117 Fold_Uint
(N
, Alignment
(Entity
(P
)));
4118 Set_Is_Static_Expression
(N
, False);
4126 -- No other attributes for objects are folded
4133 -- Cases where P is not an object. Cannot do anything if P is
4134 -- not the name of an entity.
4136 elsif not Is_Entity_Name
(P
) then
4140 -- Otherwise get prefix entity
4143 P_Entity
:= Entity
(P
);
4146 -- At this stage P_Entity is the entity to which the attribute
4147 -- is to be applied. This is usually simply the entity of the
4148 -- prefix, except in some cases of attributes for objects, where
4149 -- as described above, we apply the attribute to the object type.
4151 -- First foldable possibility is a scalar or array type (RM 4.9(7))
4152 -- that is not generic (generic types are eliminated by RM 4.9(25)).
4153 -- Note we allow non-static non-generic types at this stage as further
4156 if Is_Type
(P_Entity
)
4157 and then (Is_Scalar_Type
(P_Entity
) or Is_Array_Type
(P_Entity
))
4158 and then (not Is_Generic_Type
(P_Entity
))
4162 -- Second foldable possibility is an array object (RM 4.9(8))
4164 elsif (Ekind
(P_Entity
) = E_Variable
4166 Ekind
(P_Entity
) = E_Constant
)
4167 and then Is_Array_Type
(Etype
(P_Entity
))
4168 and then (not Is_Generic_Type
(Etype
(P_Entity
)))
4170 P_Type
:= Etype
(P_Entity
);
4172 -- If the entity is an array constant with an unconstrained
4173 -- nominal subtype then get the type from the initial value.
4174 -- If the value has been expanded into assignments, the expression
4175 -- is not present and the attribute reference remains dynamic.
4176 -- We could do better here and retrieve the type ???
4178 if Ekind
(P_Entity
) = E_Constant
4179 and then not Is_Constrained
(P_Type
)
4181 if No
(Constant_Value
(P_Entity
)) then
4184 P_Type
:= Etype
(Constant_Value
(P_Entity
));
4188 -- Definite must be folded if the prefix is not a generic type,
4189 -- that is to say if we are within an instantiation. Same processing
4190 -- applies to the GNAT attributes Has_Discriminants and Type_Class
4192 elsif (Id
= Attribute_Definite
4194 Id
= Attribute_Has_Discriminants
4196 Id
= Attribute_Type_Class
)
4197 and then not Is_Generic_Type
(P_Entity
)
4201 -- We can fold 'Size applied to a type if the size is known
4202 -- (as happens for a size from an attribute definition clause).
4203 -- At this stage, this can happen only for types (e.g. record
4204 -- types) for which the size is always non-static. We exclude
4205 -- generic types from consideration (since they have bogus
4206 -- sizes set within templates).
4208 elsif Id
= Attribute_Size
4209 and then Is_Type
(P_Entity
)
4210 and then (not Is_Generic_Type
(P_Entity
))
4211 and then Known_Static_RM_Size
(P_Entity
)
4213 Compile_Time_Known_Attribute
(N
, RM_Size
(P_Entity
));
4216 -- No other cases are foldable (they certainly aren't static, and at
4217 -- the moment we don't try to fold any cases other than the two above)
4224 -- If either attribute or the prefix is Any_Type, then propagate
4225 -- Any_Type to the result and don't do anything else at all.
4227 if P_Type
= Any_Type
4228 or else (Present
(E1
) and then Etype
(E1
) = Any_Type
)
4229 or else (Present
(E2
) and then Etype
(E2
) = Any_Type
)
4231 Set_Etype
(N
, Any_Type
);
4235 -- Scalar subtype case. We have not yet enforced the static requirement
4236 -- of (RM 4.9(7)) and we don't intend to just yet, since there are cases
4237 -- of non-static attribute references (e.g. S'Digits for a non-static
4238 -- floating-point type, which we can compute at compile time).
4240 -- Note: this folding of non-static attributes is not simply a case of
4241 -- optimization. For many of the attributes affected, Gigi cannot handle
4242 -- the attribute and depends on the front end having folded them away.
4244 -- Note: although we don't require staticness at this stage, we do set
4245 -- the Static variable to record the staticness, for easy reference by
4246 -- those attributes where it matters (e.g. Succ and Pred), and also to
4247 -- be used to ensure that non-static folded things are not marked as
4248 -- being static (a check that is done right at the end).
4250 P_Root_Type
:= Root_Type
(P_Type
);
4251 P_Base_Type
:= Base_Type
(P_Type
);
4253 -- If the root type or base type is generic, then we cannot fold. This
4254 -- test is needed because subtypes of generic types are not always
4255 -- marked as being generic themselves (which seems odd???)
4257 if Is_Generic_Type
(P_Root_Type
)
4258 or else Is_Generic_Type
(P_Base_Type
)
4263 if Is_Scalar_Type
(P_Type
) then
4264 Static
:= Is_OK_Static_Subtype
(P_Type
);
4266 -- Array case. We enforce the constrained requirement of (RM 4.9(7-8))
4267 -- since we can't do anything with unconstrained arrays. In addition,
4268 -- only the First, Last and Length attributes are possibly static.
4269 -- In addition Component_Size is possibly foldable, even though it
4270 -- can never be static.
4272 -- Definite, Has_Discriminants and Type_Class are again exceptions,
4273 -- because they apply as well to unconstrained types.
4275 elsif Id
= Attribute_Definite
4277 Id
= Attribute_Has_Discriminants
4279 Id
= Attribute_Type_Class
4284 if not Is_Constrained
(P_Type
)
4285 or else (Id
/= Attribute_Component_Size
and then
4286 Id
/= Attribute_First
and then
4287 Id
/= Attribute_Last
and then
4288 Id
/= Attribute_Length
)
4294 -- The rules in (RM 4.9(7,8)) require a static array, but as in the
4295 -- scalar case, we hold off on enforcing staticness, since there are
4296 -- cases which we can fold at compile time even though they are not
4297 -- static (e.g. 'Length applied to a static index, even though other
4298 -- non-static indexes make the array type non-static). This is only
4299 -- ab optimization, but it falls out essentially free, so why not.
4300 -- Again we compute the variable Static for easy reference later
4301 -- (note that no array attributes are static in Ada 83).
4309 N
:= First_Index
(P_Type
);
4310 while Present
(N
) loop
4311 Static
:= Static
and Is_Static_Subtype
(Etype
(N
));
4317 -- Check any expressions that are present. Note that these expressions,
4318 -- depending on the particular attribute type, are either part of the
4319 -- attribute designator, or they are arguments in a case where the
4320 -- attribute reference returns a function. In the latter case, the
4321 -- rule in (RM 4.9(22)) applies and in particular requires the type
4322 -- of the expressions to be scalar in order for the attribute to be
4323 -- considered to be static.
4330 while Present
(E
) loop
4332 -- If expression is not static, then the attribute reference
4333 -- certainly is neither foldable nor static, so we can quit
4334 -- after calling Apply_Range_Check for 'Pos attributes.
4336 -- We can also quit if the expression is not of a scalar type
4339 if not Is_Static_Expression
(E
)
4340 or else not Is_Scalar_Type
(Etype
(E
))
4342 if Id
= Attribute_Pos
then
4343 if Is_Integer_Type
(Etype
(E
)) then
4344 Apply_Range_Check
(E
, Etype
(N
));
4351 -- If the expression raises a constraint error, then so does
4352 -- the attribute reference. We keep going in this case because
4353 -- we are still interested in whether the attribute reference
4354 -- is static even if it is not static.
4356 elsif Raises_Constraint_Error
(E
) then
4357 Set_Raises_Constraint_Error
(N
);
4363 if Raises_Constraint_Error
(Prefix
(N
)) then
4368 -- Deal with the case of a static attribute reference that raises
4369 -- constraint error. The Raises_Constraint_Error flag will already
4370 -- have been set, and the Static flag shows whether the attribute
4371 -- reference is static. In any case we certainly can't fold such an
4372 -- attribute reference.
4374 -- Note that the rewriting of the attribute node with the constraint
4375 -- error node is essential in this case, because otherwise Gigi might
4376 -- blow up on one of the attributes it never expects to see.
4378 -- The constraint_error node must have the type imposed by the context,
4379 -- to avoid spurious errors in the enclosing expression.
4381 if Raises_Constraint_Error
(N
) then
4383 Make_Raise_Constraint_Error
(Sloc
(N
),
4384 Reason
=> CE_Range_Check_Failed
);
4385 Set_Etype
(CE_Node
, Etype
(N
));
4386 Set_Raises_Constraint_Error
(CE_Node
);
4388 Rewrite
(N
, Relocate_Node
(CE_Node
));
4389 Set_Is_Static_Expression
(N
, Static
);
4393 -- At this point we have a potentially foldable attribute reference.
4394 -- If Static is set, then the attribute reference definitely obeys
4395 -- the requirements in (RM 4.9(7,8,22)), and it definitely can be
4396 -- folded. If Static is not set, then the attribute may or may not
4397 -- be foldable, and the individual attribute processing routines
4398 -- test Static as required in cases where it makes a difference.
4406 when Attribute_Adjacent
=>
4410 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value_R
(E2
)));
4417 when Attribute_Aft
=>
4418 Fold_Uint
(N
, UI_From_Int
(Aft_Value
));
4424 when Attribute_Alignment
=> Alignment_Block
: declare
4425 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
4428 -- Fold if alignment is set and not otherwise
4430 if Known_Alignment
(P_TypeA
) then
4431 Fold_Uint
(N
, Alignment
(P_TypeA
));
4433 end Alignment_Block
;
4439 -- Can only be folded in No_Ast_Handler case
4441 when Attribute_AST_Entry
=>
4442 if not Is_AST_Entry
(P_Entity
) then
4444 New_Occurrence_Of
(RTE
(RE_No_AST_Handler
), Loc
));
4453 -- Bit can never be folded
4455 when Attribute_Bit
=>
4462 -- Body_version can never be static
4464 when Attribute_Body_Version
=>
4471 when Attribute_Ceiling
=>
4474 Eval_Fat
.Ceiling
(P_Root_Type
, Expr_Value_R
(E1
)));
4477 --------------------
4478 -- Component_Size --
4479 --------------------
4481 when Attribute_Component_Size
=>
4482 if Component_Size
(P_Type
) /= 0 then
4483 Fold_Uint
(N
, Component_Size
(P_Type
));
4490 when Attribute_Compose
=>
4494 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)));
4501 -- Constrained is never folded for now, there may be cases that
4502 -- could be handled at compile time. to be looked at later.
4504 when Attribute_Constrained
=>
4511 when Attribute_Copy_Sign
=>
4515 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value_R
(E2
)));
4522 when Attribute_Delta
=>
4523 Fold_Ureal
(N
, Delta_Value
(P_Type
));
4529 when Attribute_Definite
=>
4534 if Is_Indefinite_Subtype
(P_Entity
) then
4535 Result
:= New_Occurrence_Of
(Standard_False
, Loc
);
4537 Result
:= New_Occurrence_Of
(Standard_True
, Loc
);
4540 Rewrite
(N
, Result
);
4541 Analyze_And_Resolve
(N
, Standard_Boolean
);
4548 when Attribute_Denorm
=>
4550 (N
, UI_From_Int
(Boolean'Pos (Denorm_On_Target
)));
4556 when Attribute_Digits
=>
4557 Fold_Uint
(N
, Digits_Value
(P_Type
));
4563 when Attribute_Emax
=>
4565 -- Ada 83 attribute is defined as (RM83 3.5.8)
4567 -- T'Emax = 4 * T'Mantissa
4569 Fold_Uint
(N
, 4 * Mantissa
);
4575 when Attribute_Enum_Rep
=>
4578 -- For an enumeration type with a non-standard representation
4579 -- use the Enumeration_Rep field of the proper constant. Note
4580 -- that this would not work for types Character/Wide_Character,
4581 -- since no real entities are created for the enumeration
4582 -- literals, but that does not matter since these two types
4583 -- do not have non-standard representations anyway.
4585 if Is_Enumeration_Type
(P_Type
)
4586 and then Has_Non_Standard_Rep
(P_Type
)
4588 Fold_Uint
(N
, Enumeration_Rep
(Expr_Value_E
(E1
)));
4590 -- For enumeration types with standard representations and all
4591 -- other cases (i.e. all integer and modular types), Enum_Rep
4592 -- is equivalent to Pos.
4595 Fold_Uint
(N
, Expr_Value
(E1
));
4603 when Attribute_Epsilon
=>
4605 -- Ada 83 attribute is defined as (RM83 3.5.8)
4607 -- T'Epsilon = 2.0**(1 - T'Mantissa)
4609 Fold_Ureal
(N
, Ureal_2
** (1 - Mantissa
));
4615 when Attribute_Exponent
=>
4618 Eval_Fat
.Exponent
(P_Root_Type
, Expr_Value_R
(E1
)));
4625 when Attribute_First
=> First_Attr
:
4629 if Compile_Time_Known_Value
(Lo_Bound
) then
4630 if Is_Real_Type
(P_Type
) then
4631 Fold_Ureal
(N
, Expr_Value_R
(Lo_Bound
));
4633 Fold_Uint
(N
, Expr_Value
(Lo_Bound
));
4642 when Attribute_Fixed_Value
=>
4649 when Attribute_Floor
=>
4652 Eval_Fat
.Floor
(P_Root_Type
, Expr_Value_R
(E1
)));
4659 when Attribute_Fore
=>
4661 Fold_Uint
(N
, UI_From_Int
(Fore_Value
));
4668 when Attribute_Fraction
=>
4671 Eval_Fat
.Fraction
(P_Root_Type
, Expr_Value_R
(E1
)));
4674 -----------------------
4675 -- Has_Discriminants --
4676 -----------------------
4678 when Attribute_Has_Discriminants
=>
4683 if Has_Discriminants
(P_Entity
) then
4684 Result
:= New_Occurrence_Of
(Standard_True
, Loc
);
4686 Result
:= New_Occurrence_Of
(Standard_False
, Loc
);
4689 Rewrite
(N
, Result
);
4690 Analyze_And_Resolve
(N
, Standard_Boolean
);
4697 when Attribute_Identity
=>
4704 -- Image is a scalar attribute, but is never static, because it is
4705 -- not a static function (having a non-scalar argument (RM 4.9(22))
4707 when Attribute_Image
=>
4714 -- Img is a scalar attribute, but is never static, because it is
4715 -- not a static function (having a non-scalar argument (RM 4.9(22))
4717 when Attribute_Img
=>
4724 when Attribute_Integer_Value
=>
4731 when Attribute_Large
=>
4733 -- For fixed-point, we use the identity:
4735 -- T'Large = (2.0**T'Mantissa - 1.0) * T'Small
4737 if Is_Fixed_Point_Type
(P_Type
) then
4739 Make_Op_Multiply
(Loc
,
4741 Make_Op_Subtract
(Loc
,
4745 Make_Real_Literal
(Loc
, Ureal_2
),
4747 Make_Attribute_Reference
(Loc
,
4749 Attribute_Name
=> Name_Mantissa
)),
4750 Right_Opnd
=> Make_Real_Literal
(Loc
, Ureal_1
)),
4753 Make_Real_Literal
(Loc
, Small_Value
(Entity
(P
)))));
4755 Analyze_And_Resolve
(N
, C_Type
);
4757 -- Floating-point (Ada 83 compatibility)
4760 -- Ada 83 attribute is defined as (RM83 3.5.8)
4762 -- T'Large = 2.0**T'Emax * (1.0 - 2.0**(-T'Mantissa))
4766 -- T'Emax = 4 * T'Mantissa
4769 Ureal_2
** (4 * Mantissa
) *
4770 (Ureal_1
- Ureal_2
** (-Mantissa
)));
4777 when Attribute_Last
=> Last
:
4781 if Compile_Time_Known_Value
(Hi_Bound
) then
4782 if Is_Real_Type
(P_Type
) then
4783 Fold_Ureal
(N
, Expr_Value_R
(Hi_Bound
));
4785 Fold_Uint
(N
, Expr_Value
(Hi_Bound
));
4794 when Attribute_Leading_Part
=>
4797 Eval_Fat
.Leading_Part
4798 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)));
4805 when Attribute_Length
=> Length
:
4809 if Compile_Time_Known_Value
(Lo_Bound
)
4810 and then Compile_Time_Known_Value
(Hi_Bound
)
4813 UI_Max
(0, 1 + (Expr_Value
(Hi_Bound
) - Expr_Value
(Lo_Bound
))));
4821 when Attribute_Machine
=>
4824 Eval_Fat
.Machine
(P_Root_Type
, Expr_Value_R
(E1
),
4832 when Attribute_Machine_Emax
=>
4833 Float_Attribute_Universal_Integer
(
4839 VAXGF_Machine_Emax
);
4845 when Attribute_Machine_Emin
=>
4846 Float_Attribute_Universal_Integer
(
4852 VAXGF_Machine_Emin
);
4854 ----------------------
4855 -- Machine_Mantissa --
4856 ----------------------
4858 when Attribute_Machine_Mantissa
=>
4859 Float_Attribute_Universal_Integer
(
4860 IEEES_Machine_Mantissa
,
4861 IEEEL_Machine_Mantissa
,
4862 IEEEX_Machine_Mantissa
,
4863 VAXFF_Machine_Mantissa
,
4864 VAXDF_Machine_Mantissa
,
4865 VAXGF_Machine_Mantissa
);
4867 -----------------------
4868 -- Machine_Overflows --
4869 -----------------------
4871 when Attribute_Machine_Overflows
=>
4873 -- Always true for fixed-point
4875 if Is_Fixed_Point_Type
(P_Type
) then
4876 Fold_Uint
(N
, True_Value
);
4878 -- Floating point case
4882 (N
, UI_From_Int
(Boolean'Pos (Machine_Overflows_On_Target
)));
4889 when Attribute_Machine_Radix
=>
4890 if Is_Fixed_Point_Type
(P_Type
) then
4891 if Is_Decimal_Fixed_Point_Type
(P_Type
)
4892 and then Machine_Radix_10
(P_Type
)
4894 Fold_Uint
(N
, Uint_10
);
4896 Fold_Uint
(N
, Uint_2
);
4899 -- All floating-point type always have radix 2
4902 Fold_Uint
(N
, Uint_2
);
4905 --------------------
4906 -- Machine_Rounds --
4907 --------------------
4909 when Attribute_Machine_Rounds
=>
4911 -- Always False for fixed-point
4913 if Is_Fixed_Point_Type
(P_Type
) then
4914 Fold_Uint
(N
, False_Value
);
4916 -- Else yield proper floating-point result
4920 (N
, UI_From_Int
(Boolean'Pos (Machine_Rounds_On_Target
)));
4927 -- Note: Machine_Size is identical to Object_Size
4929 when Attribute_Machine_Size
=> Machine_Size
: declare
4930 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
4933 if Known_Esize
(P_TypeA
) then
4934 Fold_Uint
(N
, Esize
(P_TypeA
));
4942 when Attribute_Mantissa
=>
4944 -- Fixed-point mantissa
4946 if Is_Fixed_Point_Type
(P_Type
) then
4948 -- Compile time foldable case
4950 if Compile_Time_Known_Value
(Type_Low_Bound
(P_Type
))
4952 Compile_Time_Known_Value
(Type_High_Bound
(P_Type
))
4954 -- The calculation of the obsolete Ada 83 attribute Mantissa
4955 -- is annoying, because of AI00143, quoted here:
4957 -- !question 84-01-10
4959 -- Consider the model numbers for F:
4961 -- type F is delta 1.0 range -7.0 .. 8.0;
4963 -- The wording requires that F'MANTISSA be the SMALLEST
4964 -- integer number for which each bound of the specified
4965 -- range is either a model number or lies at most small
4966 -- distant from a model number. This means F'MANTISSA
4967 -- is required to be 3 since the range -7.0 .. 7.0 fits
4968 -- in 3 signed bits, and 8 is "at most" 1.0 from a model
4969 -- number, namely, 7. Is this analysis correct? Note that
4970 -- this implies the upper bound of the range is not
4971 -- represented as a model number.
4973 -- !response 84-03-17
4975 -- The analysis is correct. The upper and lower bounds for
4976 -- a fixed point type can lie outside the range of model
4987 LBound
:= Expr_Value_R
(Type_Low_Bound
(P_Type
));
4988 UBound
:= Expr_Value_R
(Type_High_Bound
(P_Type
));
4989 Bound
:= UR_Max
(UR_Abs
(LBound
), UR_Abs
(UBound
));
4990 Max_Man
:= UR_Trunc
(Bound
/ Small_Value
(P_Type
));
4992 -- If the Bound is exactly a model number, i.e. a multiple
4993 -- of Small, then we back it off by one to get the integer
4994 -- value that must be representable.
4996 if Small_Value
(P_Type
) * Max_Man
= Bound
then
4997 Max_Man
:= Max_Man
- 1;
5000 -- Now find corresponding size = Mantissa value
5003 while 2 ** Siz
< Max_Man
loop
5011 -- The case of dynamic bounds cannot be evaluated at compile
5012 -- time. Instead we use a runtime routine (see Exp_Attr).
5017 -- Floating-point Mantissa
5020 Fold_Uint
(N
, Mantissa
);
5027 when Attribute_Max
=> Max
:
5029 if Is_Real_Type
(P_Type
) then
5030 Fold_Ureal
(N
, UR_Max
(Expr_Value_R
(E1
), Expr_Value_R
(E2
)));
5032 Fold_Uint
(N
, UI_Max
(Expr_Value
(E1
), Expr_Value
(E2
)));
5036 ----------------------------------
5037 -- Max_Size_In_Storage_Elements --
5038 ----------------------------------
5040 -- Max_Size_In_Storage_Elements is simply the Size rounded up to a
5041 -- Storage_Unit boundary. We can fold any cases for which the size
5042 -- is known by the front end.
5044 when Attribute_Max_Size_In_Storage_Elements
=>
5045 if Known_Esize
(P_Type
) then
5047 (Esize
(P_Type
) + System_Storage_Unit
- 1) /
5048 System_Storage_Unit
);
5051 --------------------
5052 -- Mechanism_Code --
5053 --------------------
5055 when Attribute_Mechanism_Code
=>
5059 Mech
: Mechanism_Type
;
5063 Mech
:= Mechanism
(P_Entity
);
5066 Val
:= UI_To_Int
(Expr_Value
(E1
));
5068 Formal
:= First_Formal
(P_Entity
);
5069 for J
in 1 .. Val
- 1 loop
5070 Next_Formal
(Formal
);
5072 Mech
:= Mechanism
(Formal
);
5076 Fold_Uint
(N
, UI_From_Int
(Int
(-Mech
)));
5084 when Attribute_Min
=> Min
:
5086 if Is_Real_Type
(P_Type
) then
5087 Fold_Ureal
(N
, UR_Min
(Expr_Value_R
(E1
), Expr_Value_R
(E2
)));
5089 Fold_Uint
(N
, UI_Min
(Expr_Value
(E1
), Expr_Value
(E2
)));
5097 when Attribute_Model
=>
5100 Eval_Fat
.Model
(P_Root_Type
, Expr_Value_R
(E1
)));
5107 when Attribute_Model_Emin
=>
5108 Float_Attribute_Universal_Integer
(
5120 when Attribute_Model_Epsilon
=>
5121 Float_Attribute_Universal_Real
(
5122 IEEES_Model_Epsilon
'Universal_Literal_String,
5123 IEEEL_Model_Epsilon
'Universal_Literal_String,
5124 IEEEX_Model_Epsilon
'Universal_Literal_String,
5125 VAXFF_Model_Epsilon
'Universal_Literal_String,
5126 VAXDF_Model_Epsilon
'Universal_Literal_String,
5127 VAXGF_Model_Epsilon
'Universal_Literal_String);
5129 --------------------
5130 -- Model_Mantissa --
5131 --------------------
5133 when Attribute_Model_Mantissa
=>
5134 Float_Attribute_Universal_Integer
(
5135 IEEES_Model_Mantissa
,
5136 IEEEL_Model_Mantissa
,
5137 IEEEX_Model_Mantissa
,
5138 VAXFF_Model_Mantissa
,
5139 VAXDF_Model_Mantissa
,
5140 VAXGF_Model_Mantissa
);
5146 when Attribute_Model_Small
=>
5147 Float_Attribute_Universal_Real
(
5148 IEEES_Model_Small
'Universal_Literal_String,
5149 IEEEL_Model_Small
'Universal_Literal_String,
5150 IEEEX_Model_Small
'Universal_Literal_String,
5151 VAXFF_Model_Small
'Universal_Literal_String,
5152 VAXDF_Model_Small
'Universal_Literal_String,
5153 VAXGF_Model_Small
'Universal_Literal_String);
5159 when Attribute_Modulus
=>
5160 Fold_Uint
(N
, Modulus
(P_Type
));
5162 --------------------
5163 -- Null_Parameter --
5164 --------------------
5166 -- Cannot fold, we know the value sort of, but the whole point is
5167 -- that there is no way to talk about this imaginary value except
5168 -- by using the attribute, so we leave it the way it is.
5170 when Attribute_Null_Parameter
=>
5177 -- The Object_Size attribute for a type returns the Esize of the
5178 -- type and can be folded if this value is known.
5180 when Attribute_Object_Size
=> Object_Size
: declare
5181 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
5184 if Known_Esize
(P_TypeA
) then
5185 Fold_Uint
(N
, Esize
(P_TypeA
));
5189 -------------------------
5190 -- Passed_By_Reference --
5191 -------------------------
5193 -- Scalar types are never passed by reference
5195 when Attribute_Passed_By_Reference
=>
5196 Fold_Uint
(N
, False_Value
);
5202 when Attribute_Pos
=>
5203 Fold_Uint
(N
, Expr_Value
(E1
));
5209 when Attribute_Pred
=> Pred
:
5213 -- Floating-point case. For now, do not fold this, since we
5214 -- don't know how to do it right (see fixed bug 3512-001 ???)
5216 if Is_Floating_Point_Type
(P_Type
) then
5218 Eval_Fat
.Pred
(P_Root_Type
, Expr_Value_R
(E1
)));
5222 elsif Is_Fixed_Point_Type
(P_Type
) then
5224 Expr_Value_R
(E1
) - Small_Value
(P_Type
));
5226 -- Modular integer case (wraps)
5228 elsif Is_Modular_Integer_Type
(P_Type
) then
5229 Fold_Uint
(N
, (Expr_Value
(E1
) - 1) mod Modulus
(P_Type
));
5231 -- Other scalar cases
5234 pragma Assert
(Is_Scalar_Type
(P_Type
));
5236 if Is_Enumeration_Type
(P_Type
)
5237 and then Expr_Value
(E1
) =
5238 Expr_Value
(Type_Low_Bound
(P_Base_Type
))
5240 Apply_Compile_Time_Constraint_Error
5241 (N
, "Pred of type''First", CE_Overflow_Check_Failed
);
5246 Fold_Uint
(N
, Expr_Value
(E1
) - 1);
5255 -- No processing required, because by this stage, Range has been
5256 -- replaced by First .. Last, so this branch can never be taken.
5258 when Attribute_Range
=>
5259 raise Program_Error
;
5265 when Attribute_Range_Length
=>
5268 if Compile_Time_Known_Value
(Hi_Bound
)
5269 and then Compile_Time_Known_Value
(Lo_Bound
)
5273 (0, Expr_Value
(Hi_Bound
) - Expr_Value
(Lo_Bound
) + 1));
5280 when Attribute_Remainder
=>
5284 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value_R
(E2
)));
5291 when Attribute_Round
=> Round
:
5298 -- First we get the (exact result) in units of small
5300 Sr
:= Expr_Value_R
(E1
) / Small_Value
(C_Type
);
5302 -- Now round that exactly to an integer
5304 Si
:= UR_To_Uint
(Sr
);
5306 -- Finally the result is obtained by converting back to real
5308 Fold_Ureal
(N
, Si
* Small_Value
(C_Type
));
5316 when Attribute_Rounding
=>
5319 Eval_Fat
.Rounding
(P_Root_Type
, Expr_Value_R
(E1
)));
5326 when Attribute_Safe_Emax
=>
5327 Float_Attribute_Universal_Integer
(
5339 when Attribute_Safe_First
=>
5340 Float_Attribute_Universal_Real
(
5341 IEEES_Safe_First
'Universal_Literal_String,
5342 IEEEL_Safe_First
'Universal_Literal_String,
5343 IEEEX_Safe_First
'Universal_Literal_String,
5344 VAXFF_Safe_First
'Universal_Literal_String,
5345 VAXDF_Safe_First
'Universal_Literal_String,
5346 VAXGF_Safe_First
'Universal_Literal_String);
5352 when Attribute_Safe_Large
=>
5353 if Is_Fixed_Point_Type
(P_Type
) then
5354 Fold_Ureal
(N
, Expr_Value_R
(Type_High_Bound
(P_Base_Type
)));
5356 Float_Attribute_Universal_Real
(
5357 IEEES_Safe_Large
'Universal_Literal_String,
5358 IEEEL_Safe_Large
'Universal_Literal_String,
5359 IEEEX_Safe_Large
'Universal_Literal_String,
5360 VAXFF_Safe_Large
'Universal_Literal_String,
5361 VAXDF_Safe_Large
'Universal_Literal_String,
5362 VAXGF_Safe_Large
'Universal_Literal_String);
5369 when Attribute_Safe_Last
=>
5370 Float_Attribute_Universal_Real
(
5371 IEEES_Safe_Last
'Universal_Literal_String,
5372 IEEEL_Safe_Last
'Universal_Literal_String,
5373 IEEEX_Safe_Last
'Universal_Literal_String,
5374 VAXFF_Safe_Last
'Universal_Literal_String,
5375 VAXDF_Safe_Last
'Universal_Literal_String,
5376 VAXGF_Safe_Last
'Universal_Literal_String);
5382 when Attribute_Safe_Small
=>
5384 -- In Ada 95, the old Ada 83 attribute Safe_Small is redundant
5385 -- for fixed-point, since is the same as Small, but we implement
5386 -- it for backwards compatibility.
5388 if Is_Fixed_Point_Type
(P_Type
) then
5389 Fold_Ureal
(N
, Small_Value
(P_Type
));
5391 -- Ada 83 Safe_Small for floating-point cases
5394 Float_Attribute_Universal_Real
(
5395 IEEES_Safe_Small
'Universal_Literal_String,
5396 IEEEL_Safe_Small
'Universal_Literal_String,
5397 IEEEX_Safe_Small
'Universal_Literal_String,
5398 VAXFF_Safe_Small
'Universal_Literal_String,
5399 VAXDF_Safe_Small
'Universal_Literal_String,
5400 VAXGF_Safe_Small
'Universal_Literal_String);
5407 when Attribute_Scale
=>
5408 Fold_Uint
(N
, Scale_Value
(P_Type
));
5414 when Attribute_Scaling
=>
5418 (P_Root_Type
, Expr_Value_R
(E1
), Expr_Value
(E2
)));
5425 when Attribute_Signed_Zeros
=>
5427 (N
, UI_From_Int
(Boolean'Pos (Signed_Zeros_On_Target
)));
5433 -- Size attribute returns the RM size. All scalar types can be folded,
5434 -- as well as any types for which the size is known by the front end,
5435 -- including any type for which a size attribute is specified.
5437 when Attribute_Size | Attribute_VADS_Size
=> Size
: declare
5438 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
5441 if RM_Size
(P_TypeA
) /= Uint_0
then
5445 if (Id
= Attribute_VADS_Size
or else Use_VADS_Size
) then
5448 S
: constant Node_Id
:= Size_Clause
(P_TypeA
);
5451 -- If a size clause applies, then use the size from it.
5452 -- This is one of the rare cases where we can use the
5453 -- Size_Clause field for a subtype when Has_Size_Clause
5454 -- is False. Consider:
5456 -- type x is range 1 .. 64;
5457 -- for x'size use 12;
5458 -- subtype y is x range 0 .. 3;
5460 -- Here y has a size clause inherited from x, but normally
5461 -- it does not apply, and y'size is 2. However, y'VADS_Size
5462 -- is indeed 12 and not 2.
5465 and then Is_OK_Static_Expression
(Expression
(S
))
5467 Fold_Uint
(N
, Expr_Value
(Expression
(S
)));
5469 -- If no size is specified, then we simply use the object
5470 -- size in the VADS_Size case (e.g. Natural'Size is equal
5471 -- to Integer'Size, not one less).
5474 Fold_Uint
(N
, Esize
(P_TypeA
));
5478 -- Normal case (Size) in which case we want the RM_Size
5481 Fold_Uint
(N
, RM_Size
(P_TypeA
));
5490 when Attribute_Small
=>
5492 -- The floating-point case is present only for Ada 83 compatibility.
5493 -- Note that strictly this is an illegal addition, since we are
5494 -- extending an Ada 95 defined attribute, but we anticipate an
5495 -- ARG ruling that will permit this.
5497 if Is_Floating_Point_Type
(P_Type
) then
5499 -- Ada 83 attribute is defined as (RM83 3.5.8)
5501 -- T'Small = 2.0**(-T'Emax - 1)
5505 -- T'Emax = 4 * T'Mantissa
5507 Fold_Ureal
(N
, Ureal_2
** ((-(4 * Mantissa
)) - 1));
5509 -- Normal Ada 95 fixed-point case
5512 Fold_Ureal
(N
, Small_Value
(P_Type
));
5519 when Attribute_Succ
=> Succ
:
5523 -- Floating-point case. For now, do not fold this, since we
5524 -- don't know how to do it right (see fixed bug 3512-001 ???)
5526 if Is_Floating_Point_Type
(P_Type
) then
5528 Eval_Fat
.Succ
(P_Root_Type
, Expr_Value_R
(E1
)));
5532 elsif Is_Fixed_Point_Type
(P_Type
) then
5534 Expr_Value_R
(E1
) + Small_Value
(P_Type
));
5536 -- Modular integer case (wraps)
5538 elsif Is_Modular_Integer_Type
(P_Type
) then
5539 Fold_Uint
(N
, (Expr_Value
(E1
) + 1) mod Modulus
(P_Type
));
5541 -- Other scalar cases
5544 pragma Assert
(Is_Scalar_Type
(P_Type
));
5546 if Is_Enumeration_Type
(P_Type
)
5547 and then Expr_Value
(E1
) =
5548 Expr_Value
(Type_High_Bound
(P_Base_Type
))
5550 Apply_Compile_Time_Constraint_Error
5551 (N
, "Succ of type''Last", CE_Overflow_Check_Failed
);
5555 Fold_Uint
(N
, Expr_Value
(E1
) + 1);
5565 when Attribute_Truncation
=>
5568 Eval_Fat
.Truncation
(P_Root_Type
, Expr_Value_R
(E1
)));
5575 when Attribute_Type_Class
=> Type_Class
: declare
5576 Typ
: constant Entity_Id
:= Underlying_Type
(P_Base_Type
);
5580 if Is_RTE
(P_Root_Type
, RE_Address
) then
5581 Id
:= RE_Type_Class_Address
;
5583 elsif Is_Enumeration_Type
(Typ
) then
5584 Id
:= RE_Type_Class_Enumeration
;
5586 elsif Is_Integer_Type
(Typ
) then
5587 Id
:= RE_Type_Class_Integer
;
5589 elsif Is_Fixed_Point_Type
(Typ
) then
5590 Id
:= RE_Type_Class_Fixed_Point
;
5592 elsif Is_Floating_Point_Type
(Typ
) then
5593 Id
:= RE_Type_Class_Floating_Point
;
5595 elsif Is_Array_Type
(Typ
) then
5596 Id
:= RE_Type_Class_Array
;
5598 elsif Is_Record_Type
(Typ
) then
5599 Id
:= RE_Type_Class_Record
;
5601 elsif Is_Access_Type
(Typ
) then
5602 Id
:= RE_Type_Class_Access
;
5604 elsif Is_Enumeration_Type
(Typ
) then
5605 Id
:= RE_Type_Class_Enumeration
;
5607 elsif Is_Task_Type
(Typ
) then
5608 Id
:= RE_Type_Class_Task
;
5610 -- We treat protected types like task types. It would make more
5611 -- sense to have another enumeration value, but after all the
5612 -- whole point of this feature is to be exactly DEC compatible,
5613 -- and changing the type Type_Clas would not meet this requirement.
5615 elsif Is_Protected_Type
(Typ
) then
5616 Id
:= RE_Type_Class_Task
;
5618 -- Not clear if there are any other possibilities, but if there
5619 -- are, then we will treat them as the address case.
5622 Id
:= RE_Type_Class_Address
;
5625 Rewrite
(N
, New_Occurrence_Of
(RTE
(Id
), Loc
));
5629 -----------------------
5630 -- Unbiased_Rounding --
5631 -----------------------
5633 when Attribute_Unbiased_Rounding
=>
5636 Eval_Fat
.Unbiased_Rounding
(P_Root_Type
, Expr_Value_R
(E1
)));
5643 -- Processing is shared with Size
5649 when Attribute_Val
=> Val
:
5652 if Expr_Value
(E1
) < Expr_Value
(Type_Low_Bound
(P_Base_Type
))
5654 Expr_Value
(E1
) > Expr_Value
(Type_High_Bound
(P_Base_Type
))
5656 Apply_Compile_Time_Constraint_Error
5657 (N
, "Val expression out of range", CE_Range_Check_Failed
);
5661 Fold_Uint
(N
, Expr_Value
(E1
));
5670 -- The Value_Size attribute for a type returns the RM size of the
5671 -- type. This an always be folded for scalar types, and can also
5672 -- be folded for non-scalar types if the size is set.
5674 when Attribute_Value_Size
=> Value_Size
: declare
5675 P_TypeA
: constant Entity_Id
:= Underlying_Type
(P_Type
);
5678 if RM_Size
(P_TypeA
) /= Uint_0
then
5679 Fold_Uint
(N
, RM_Size
(P_TypeA
));
5688 -- Version can never be static
5690 when Attribute_Version
=>
5697 -- Wide_Image is a scalar attribute, but is never static, because it
5698 -- is not a static function (having a non-scalar argument (RM 4.9(22))
5700 when Attribute_Wide_Image
=>
5707 -- Processing for Wide_Width is combined with Width
5713 -- This processing also handles the case of Wide_Width
5715 when Attribute_Width | Attribute_Wide_Width
=> Width
:
5719 -- Floating-point types
5721 if Is_Floating_Point_Type
(P_Type
) then
5723 -- Width is zero for a null range (RM 3.5 (38))
5725 if Expr_Value_R
(Type_High_Bound
(P_Type
)) <
5726 Expr_Value_R
(Type_Low_Bound
(P_Type
))
5728 Fold_Uint
(N
, Uint_0
);
5731 -- For floating-point, we have +N.dddE+nnn where length
5732 -- of ddd is determined by type'Digits - 1, but is one
5733 -- if Digits is one (RM 3.5 (33)).
5735 -- nnn is set to 2 for Short_Float and Float (32 bit
5736 -- floats), and 3 for Long_Float and Long_Long_Float.
5737 -- This is not quite right, but is good enough.
5741 Int
'Max (2, UI_To_Int
(Digits_Value
(P_Type
)));
5744 if Esize
(P_Type
) <= 32 then
5750 Fold_Uint
(N
, UI_From_Int
(Len
));
5754 -- Fixed-point types
5756 elsif Is_Fixed_Point_Type
(P_Type
) then
5758 -- Width is zero for a null range (RM 3.5 (38))
5760 if Expr_Value
(Type_High_Bound
(P_Type
)) <
5761 Expr_Value
(Type_Low_Bound
(P_Type
))
5763 Fold_Uint
(N
, Uint_0
);
5765 -- The non-null case depends on the specific real type
5768 -- For fixed-point type width is Fore + 1 + Aft (RM 3.5(34))
5770 Fold_Uint
(N
, UI_From_Int
(Fore_Value
+ 1 + Aft_Value
));
5777 R
: constant Entity_Id
:= Root_Type
(P_Type
);
5778 Lo
: constant Uint
:=
5779 Expr_Value
(Type_Low_Bound
(P_Type
));
5780 Hi
: constant Uint
:=
5781 Expr_Value
(Type_High_Bound
(P_Type
));
5794 -- Width for types derived from Standard.Character
5795 -- and Standard.Wide_Character.
5797 elsif R
= Standard_Character
5798 or else R
= Standard_Wide_Character
5802 -- Set W larger if needed
5804 for J
in UI_To_Int
(Lo
) .. UI_To_Int
(Hi
) loop
5806 -- Assume all wide-character escape sequences are
5807 -- same length, so we can quit when we reach one.
5810 if Id
= Attribute_Wide_Width
then
5811 W
:= Int
'Max (W
, 3);
5814 W
:= Int
'Max (W
, Length_Wide
);
5819 C
:= Character'Val (J
);
5821 -- Test for all cases where Character'Image
5822 -- yields an image that is longer than three
5823 -- characters. First the cases of Reserved_xxx
5824 -- names (length = 12).
5827 when Reserved_128 | Reserved_129 |
5828 Reserved_132 | Reserved_153
5832 when BS | HT | LF | VT | FF | CR |
5833 SO | SI | EM | FS | GS | RS |
5834 US | RI | MW | ST | PM
5838 when NUL | SOH | STX | ETX | EOT |
5839 ENQ | ACK | BEL | DLE | DC1 |
5840 DC2 | DC3 | DC4 | NAK | SYN |
5841 ETB | CAN | SUB | ESC | DEL |
5842 BPH | NBH | NEL | SSA | ESA |
5843 HTS | HTJ | VTS | PLD | PLU |
5844 SS2 | SS3 | DCS | PU1 | PU2 |
5845 STS | CCH | SPA | EPA | SOS |
5846 SCI | CSI | OSC | APC
5850 when Space
.. Tilde |
5851 No_Break_Space
.. LC_Y_Diaeresis
5857 W
:= Int
'Max (W
, Wt
);
5861 -- Width for types derived from Standard.Boolean
5863 elsif R
= Standard_Boolean
then
5870 -- Width for integer types
5872 elsif Is_Integer_Type
(P_Type
) then
5873 T
:= UI_Max
(abs Lo
, abs Hi
);
5881 -- Only remaining possibility is user declared enum type
5884 pragma Assert
(Is_Enumeration_Type
(P_Type
));
5887 L
:= First_Literal
(P_Type
);
5889 while Present
(L
) loop
5891 -- Only pay attention to in range characters
5893 if Lo
<= Enumeration_Pos
(L
)
5894 and then Enumeration_Pos
(L
) <= Hi
5896 -- For Width case, use decoded name
5898 if Id
= Attribute_Width
then
5899 Get_Decoded_Name_String
(Chars
(L
));
5900 Wt
:= Nat
(Name_Len
);
5902 -- For Wide_Width, use encoded name, and then
5903 -- adjust for the encoding.
5906 Get_Name_String
(Chars
(L
));
5908 -- Character literals are always of length 3
5910 if Name_Buffer
(1) = 'Q' then
5913 -- Otherwise loop to adjust for upper/wide chars
5916 Wt
:= Nat
(Name_Len
);
5918 for J
in 1 .. Name_Len
loop
5919 if Name_Buffer
(J
) = 'U' then
5921 elsif Name_Buffer
(J
) = 'W' then
5928 W
:= Int
'Max (W
, Wt
);
5935 Fold_Uint
(N
, UI_From_Int
(W
));
5941 -- The following attributes can never be folded, and furthermore we
5942 -- should not even have entered the case statement for any of these.
5943 -- Note that in some cases, the values have already been folded as
5944 -- a result of the processing in Analyze_Attribute.
5946 when Attribute_Abort_Signal |
5949 Attribute_Address_Size |
5950 Attribute_Asm_Input |
5951 Attribute_Asm_Output |
5953 Attribute_Bit_Order |
5954 Attribute_Bit_Position |
5955 Attribute_Callable |
5958 Attribute_Code_Address |
5960 Attribute_Default_Bit_Order |
5961 Attribute_Elaborated |
5962 Attribute_Elab_Body |
5963 Attribute_Elab_Spec |
5964 Attribute_External_Tag |
5965 Attribute_First_Bit |
5967 Attribute_Last_Bit |
5968 Attribute_Maximum_Alignment |
5970 Attribute_Partition_ID |
5971 Attribute_Position |
5973 Attribute_Storage_Pool |
5974 Attribute_Storage_Size |
5975 Attribute_Storage_Unit |
5977 Attribute_Terminated |
5978 Attribute_To_Address |
5979 Attribute_UET_Address |
5980 Attribute_Unchecked_Access |
5981 Attribute_Universal_Literal_String |
5982 Attribute_Unrestricted_Access |
5985 Attribute_Wchar_T_Size |
5986 Attribute_Wide_Value |
5987 Attribute_Word_Size |
5990 raise Program_Error
;
5994 -- At the end of the case, one more check. If we did a static evaluation
5995 -- so that the result is now a literal, then set Is_Static_Expression
5996 -- in the constant only if the prefix type is a static subtype. For
5997 -- non-static subtypes, the folding is still OK, but not static.
5999 if Nkind
(N
) = N_Integer_Literal
6000 or else Nkind
(N
) = N_Real_Literal
6001 or else Nkind
(N
) = N_Character_Literal
6002 or else Nkind
(N
) = N_String_Literal
6003 or else (Is_Entity_Name
(N
)
6004 and then Ekind
(Entity
(N
)) = E_Enumeration_Literal
)
6006 Set_Is_Static_Expression
(N
, Static
);
6008 -- If this is still an attribute reference, then it has not been folded
6009 -- and that means that its expressions are in a non-static context.
6011 elsif Nkind
(N
) = N_Attribute_Reference
then
6014 -- Note: the else case not covered here are odd cases where the
6015 -- processing has transformed the attribute into something other
6016 -- than a constant. Nothing more to do in such cases.
6024 ------------------------------
6025 -- Is_Anonymous_Tagged_Base --
6026 ------------------------------
6028 function Is_Anonymous_Tagged_Base
6035 Anon
= Current_Scope
6036 and then Is_Itype
(Anon
)
6037 and then Associated_Node_For_Itype
(Anon
) = Parent
(Typ
);
6038 end Is_Anonymous_Tagged_Base
;
6040 -----------------------
6041 -- Resolve_Attribute --
6042 -----------------------
6044 procedure Resolve_Attribute
(N
: Node_Id
; Typ
: Entity_Id
) is
6045 Loc
: constant Source_Ptr
:= Sloc
(N
);
6046 P
: constant Node_Id
:= Prefix
(N
);
6047 Aname
: constant Name_Id
:= Attribute_Name
(N
);
6048 Attr_Id
: constant Attribute_Id
:= Get_Attribute_Id
(Aname
);
6049 Index
: Interp_Index
;
6051 Btyp
: Entity_Id
:= Base_Type
(Typ
);
6052 Nom_Subt
: Entity_Id
;
6055 -- If error during analysis, no point in continuing, except for
6056 -- array types, where we get better recovery by using unconstrained
6057 -- indices than nothing at all (see Check_Array_Type).
6060 and then Attr_Id
/= Attribute_First
6061 and then Attr_Id
/= Attribute_Last
6062 and then Attr_Id
/= Attribute_Length
6063 and then Attr_Id
/= Attribute_Range
6068 -- If attribute was universal type, reset to actual type
6070 if Etype
(N
) = Universal_Integer
6071 or else Etype
(N
) = Universal_Real
6076 -- Remaining processing depends on attribute
6084 -- For access attributes, if the prefix denotes an entity, it is
6085 -- interpreted as a name, never as a call. It may be overloaded,
6086 -- in which case resolution uses the profile of the context type.
6087 -- Otherwise prefix must be resolved.
6089 when Attribute_Access
6090 | Attribute_Unchecked_Access
6091 | Attribute_Unrestricted_Access
=>
6093 if Is_Variable
(P
) then
6094 Note_Possible_Modification
(P
);
6097 if Is_Entity_Name
(P
) then
6099 if Is_Overloaded
(P
) then
6100 Get_First_Interp
(P
, Index
, It
);
6102 while Present
(It
.Nam
) loop
6104 if Type_Conformant
(Designated_Type
(Typ
), It
.Nam
) then
6105 Set_Entity
(P
, It
.Nam
);
6107 -- The prefix is definitely NOT overloaded anymore
6108 -- at this point, so we reset the Is_Overloaded
6109 -- flag to avoid any confusion when reanalyzing
6112 Set_Is_Overloaded
(P
, False);
6113 Generate_Reference
(Entity
(P
), P
);
6117 Get_Next_Interp
(Index
, It
);
6120 -- If it is a subprogram name or a type, there is nothing
6123 elsif not Is_Overloadable
(Entity
(P
))
6124 and then not Is_Type
(Entity
(P
))
6126 Resolve
(P
, Etype
(P
));
6129 if not Is_Entity_Name
(P
) then
6132 elsif Is_Abstract
(Entity
(P
))
6133 and then Is_Overloadable
(Entity
(P
))
6135 Error_Msg_Name_1
:= Aname
;
6136 Error_Msg_N
("prefix of % attribute cannot be abstract", P
);
6137 Set_Etype
(N
, Any_Type
);
6139 elsif Convention
(Entity
(P
)) = Convention_Intrinsic
then
6140 Error_Msg_Name_1
:= Aname
;
6142 if Ekind
(Entity
(P
)) = E_Enumeration_Literal
then
6144 ("prefix of % attribute cannot be enumeration literal",
6148 ("prefix of % attribute cannot be intrinsic", P
);
6151 Set_Etype
(N
, Any_Type
);
6154 -- Assignments, return statements, components of aggregates,
6155 -- generic instantiations will require convention checks if
6156 -- the type is an access to subprogram. Given that there will
6157 -- also be accessibility checks on those, this is where the
6158 -- checks can eventually be centralized ???
6160 if Ekind
(Btyp
) = E_Access_Subprogram_Type
then
6161 if Convention
(Btyp
) /= Convention
(Entity
(P
)) then
6163 ("subprogram has invalid convention for context", P
);
6166 Check_Subtype_Conformant
6167 (New_Id
=> Entity
(P
),
6168 Old_Id
=> Designated_Type
(Btyp
),
6172 if Attr_Id
= Attribute_Unchecked_Access
then
6173 Error_Msg_Name_1
:= Aname
;
6175 ("attribute% cannot be applied to a subprogram", P
);
6177 elsif Aname
= Name_Unrestricted_Access
then
6178 null; -- Nothing to check
6180 -- Check the static accessibility rule of 3.10.2(32)
6182 elsif Attr_Id
= Attribute_Access
6183 and then Subprogram_Access_Level
(Entity
(P
))
6184 > Type_Access_Level
(Btyp
)
6186 if not In_Instance_Body
then
6188 ("subprogram must not be deeper than access type",
6191 Warn_On_Instance
:= True;
6193 ("subprogram must not be deeper than access type?",
6196 ("Constraint_Error will be raised ?", P
);
6197 Set_Raises_Constraint_Error
(N
);
6198 Warn_On_Instance
:= False;
6201 -- Check the restriction of 3.10.2(32) that disallows
6202 -- the type of the access attribute to be declared
6203 -- outside a generic body when the attribute occurs
6204 -- within that generic body.
6206 elsif Enclosing_Generic_Body
(Entity
(P
))
6207 /= Enclosing_Generic_Body
(Btyp
)
6210 ("access type must not be outside generic body", P
);
6214 -- if this is a renaming, an inherited operation, or a
6215 -- subprogram instance, use the original entity.
6217 if Is_Entity_Name
(P
)
6218 and then Is_Overloadable
(Entity
(P
))
6219 and then Present
(Alias
(Entity
(P
)))
6222 New_Occurrence_Of
(Alias
(Entity
(P
)), Sloc
(P
)));
6225 elsif Nkind
(P
) = N_Selected_Component
6226 and then Is_Overloadable
(Entity
(Selector_Name
(P
)))
6228 -- Protected operation. If operation is overloaded, must
6229 -- disambiguate. Prefix that denotes protected object itself
6230 -- is resolved with its own type.
6232 if Attr_Id
= Attribute_Unchecked_Access
then
6233 Error_Msg_Name_1
:= Aname
;
6235 ("attribute% cannot be applied to protected operation", P
);
6238 Resolve
(Prefix
(P
), Etype
(Prefix
(P
)));
6239 Generate_Reference
(Entity
(Selector_Name
(P
)), P
);
6241 elsif Is_Overloaded
(P
) then
6243 -- Use the designated type of the context to disambiguate.
6245 Index
: Interp_Index
;
6248 Get_First_Interp
(P
, Index
, It
);
6250 while Present
(It
.Typ
) loop
6251 if Covers
(Designated_Type
(Typ
), It
.Typ
) then
6252 Resolve
(P
, It
.Typ
);
6256 Get_Next_Interp
(Index
, It
);
6260 Resolve
(P
, Etype
(P
));
6263 -- X'Access is illegal if X denotes a constant and the access
6264 -- type is access-to-variable. Same for 'Unchecked_Access.
6265 -- The rule does not apply to 'Unrestricted_Access.
6267 if not (Ekind
(Btyp
) = E_Access_Subprogram_Type
6268 or else (Is_Record_Type
(Btyp
) and then
6269 Present
(Corresponding_Remote_Type
(Btyp
)))
6270 or else Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
6271 or else Is_Access_Constant
(Btyp
)
6272 or else Is_Variable
(P
)
6273 or else Attr_Id
= Attribute_Unrestricted_Access
)
6275 if Comes_From_Source
(N
) then
6276 Error_Msg_N
("access-to-variable designates constant", P
);
6280 if (Attr_Id
= Attribute_Access
6282 Attr_Id
= Attribute_Unchecked_Access
)
6283 and then (Ekind
(Btyp
) = E_General_Access_Type
6284 or else Ekind
(Btyp
) = E_Anonymous_Access_Type
)
6286 if Is_Dependent_Component_Of_Mutable_Object
(P
) then
6288 ("illegal attribute for discriminant-dependent component",
6292 -- Check the static matching rule of 3.10.2(27). The
6293 -- nominal subtype of the prefix must statically
6294 -- match the designated type.
6296 Nom_Subt
:= Etype
(P
);
6298 if Is_Constr_Subt_For_U_Nominal
(Nom_Subt
) then
6299 Nom_Subt
:= Etype
(Nom_Subt
);
6302 if Is_Tagged_Type
(Designated_Type
(Typ
)) then
6304 -- If the attribute is in the context of an access
6305 -- parameter, then the prefix is allowed to be of
6306 -- the class-wide type (by AI-127).
6308 if Ekind
(Typ
) = E_Anonymous_Access_Type
then
6309 if not Covers
(Designated_Type
(Typ
), Nom_Subt
)
6310 and then not Covers
(Nom_Subt
, Designated_Type
(Typ
))
6316 Desig
:= Designated_Type
(Typ
);
6318 if Is_Class_Wide_Type
(Desig
) then
6319 Desig
:= Etype
(Desig
);
6322 if Is_Anonymous_Tagged_Base
(Nom_Subt
, Desig
) then
6327 ("type of prefix: & not compatible",
6330 ("\with &, the expected designated type",
6331 P
, Designated_Type
(Typ
));
6336 elsif not Covers
(Designated_Type
(Typ
), Nom_Subt
)
6338 (not Is_Class_Wide_Type
(Designated_Type
(Typ
))
6339 and then Is_Class_Wide_Type
(Nom_Subt
))
6342 ("type of prefix: & is not covered", P
, Nom_Subt
);
6344 ("\by &, the expected designated type" &
6345 " ('R'M 3.10.2 (27))", P
, Designated_Type
(Typ
));
6348 if Is_Class_Wide_Type
(Designated_Type
(Typ
))
6349 and then Has_Discriminants
(Etype
(Designated_Type
(Typ
)))
6350 and then Is_Constrained
(Etype
(Designated_Type
(Typ
)))
6351 and then Designated_Type
(Typ
) /= Nom_Subt
6353 Apply_Discriminant_Check
6354 (N
, Etype
(Designated_Type
(Typ
)));
6357 elsif not Subtypes_Statically_Match
6358 (Designated_Type
(Typ
), Nom_Subt
)
6360 not (Has_Discriminants
(Designated_Type
(Typ
))
6361 and then not Is_Constrained
(Designated_Type
(Typ
)))
6364 ("object subtype must statically match "
6365 & "designated subtype", P
);
6367 if Is_Entity_Name
(P
)
6368 and then Is_Array_Type
(Designated_Type
(Typ
))
6372 D
: constant Node_Id
:= Declaration_Node
(Entity
(P
));
6375 Error_Msg_N
("aliased object has explicit bounds?",
6377 Error_Msg_N
("\declare without bounds"
6378 & " (and with explicit initialization)?", D
);
6379 Error_Msg_N
("\for use with unconstrained access?", D
);
6384 -- Check the static accessibility rule of 3.10.2(28).
6385 -- Note that this check is not performed for the
6386 -- case of an anonymous access type, since the access
6387 -- attribute is always legal in such a context.
6389 if Attr_Id
/= Attribute_Unchecked_Access
6390 and then Object_Access_Level
(P
) > Type_Access_Level
(Btyp
)
6391 and then Ekind
(Btyp
) = E_General_Access_Type
6393 -- In an instance, this is a runtime check, but one we
6394 -- know will fail, so generate an appropriate warning.
6396 if In_Instance_Body
then
6398 ("?non-local pointer cannot point to local object", P
);
6400 ("?Program_Error will be raised at run time", P
);
6402 Make_Raise_Program_Error
(Loc
,
6403 Reason
=> PE_Accessibility_Check_Failed
));
6409 ("non-local pointer cannot point to local object", P
);
6411 if Is_Record_Type
(Current_Scope
)
6412 and then (Nkind
(Parent
(N
)) =
6413 N_Discriminant_Association
6415 Nkind
(Parent
(N
)) =
6416 N_Index_Or_Discriminant_Constraint
)
6419 Indic
: Node_Id
:= Parent
(Parent
(N
));
6422 while Present
(Indic
)
6423 and then Nkind
(Indic
) /= N_Subtype_Indication
6425 Indic
:= Parent
(Indic
);
6428 if Present
(Indic
) then
6430 ("\use an access definition for" &
6431 " the access discriminant of&", N
,
6432 Entity
(Subtype_Mark
(Indic
)));
6440 if Ekind
(Btyp
) = E_Access_Protected_Subprogram_Type
6441 and then Is_Entity_Name
(P
)
6442 and then not Is_Protected_Type
(Scope
(Entity
(P
)))
6444 Error_Msg_N
("context requires a protected subprogram", P
);
6446 elsif Ekind
(Btyp
) = E_Access_Subprogram_Type
6447 and then Ekind
(Etype
(N
)) = E_Access_Protected_Subprogram_Type
6449 Error_Msg_N
("context requires a non-protected subprogram", P
);
6452 -- The context cannot be a pool-specific type, but this is a
6453 -- legality rule, not a resolution rule, so it must be checked
6454 -- separately, after possibly disambiguation (see AI-245).
6456 if Ekind
(Btyp
) = E_Access_Type
6457 and then Attr_Id
/= Attribute_Unrestricted_Access
6459 Wrong_Type
(N
, Typ
);
6464 -- Check for incorrect atomic/volatile reference (RM C.6(12))
6466 if Attr_Id
/= Attribute_Unrestricted_Access
then
6467 if Is_Atomic_Object
(P
)
6468 and then not Is_Atomic
(Designated_Type
(Typ
))
6471 ("access to atomic object cannot yield access-to-" &
6472 "non-atomic type", P
);
6474 elsif Is_Volatile_Object
(P
)
6475 and then not Is_Volatile
(Designated_Type
(Typ
))
6478 ("access to volatile object cannot yield access-to-" &
6479 "non-volatile type", P
);
6487 -- Deal with resolving the type for Address attribute, overloading
6488 -- is not permitted here, since there is no context to resolve it.
6490 when Attribute_Address | Attribute_Code_Address
=>
6492 -- To be safe, assume that if the address of a variable is taken,
6493 -- it may be modified via this address, so note modification.
6495 if Is_Variable
(P
) then
6496 Note_Possible_Modification
(P
);
6499 if Nkind
(P
) in N_Subexpr
6500 and then Is_Overloaded
(P
)
6502 Get_First_Interp
(P
, Index
, It
);
6503 Get_Next_Interp
(Index
, It
);
6505 if Present
(It
.Nam
) then
6506 Error_Msg_Name_1
:= Aname
;
6508 ("prefix of % attribute cannot be overloaded", N
);
6513 if not Is_Entity_Name
(P
)
6514 or else not Is_Overloadable
(Entity
(P
))
6516 if not Is_Task_Type
(Etype
(P
))
6517 or else Nkind
(P
) = N_Explicit_Dereference
6519 Resolve
(P
, Etype
(P
));
6523 -- If this is the name of a derived subprogram, or that of a
6524 -- generic actual, the address is that of the original entity.
6526 if Is_Entity_Name
(P
)
6527 and then Is_Overloadable
(Entity
(P
))
6528 and then Present
(Alias
(Entity
(P
)))
6531 New_Occurrence_Of
(Alias
(Entity
(P
)), Sloc
(P
)));
6538 -- Prefix of the AST_Entry attribute is an entry name which must
6539 -- not be resolved, since this is definitely not an entry call.
6541 when Attribute_AST_Entry
=>
6548 -- Prefix of Body_Version attribute can be a subprogram name which
6549 -- must not be resolved, since this is not a call.
6551 when Attribute_Body_Version
=>
6558 -- Prefix of Caller attribute is an entry name which must not
6559 -- be resolved, since this is definitely not an entry call.
6561 when Attribute_Caller
=>
6568 -- Shares processing with Address attribute
6574 -- Prefix of the Count attribute is an entry name which must not
6575 -- be resolved, since this is definitely not an entry call.
6577 when Attribute_Count
=>
6584 -- Prefix of the Elaborated attribute is a subprogram name which
6585 -- must not be resolved, since this is definitely not a call. Note
6586 -- that it is a library unit, so it cannot be overloaded here.
6588 when Attribute_Elaborated
=>
6591 --------------------
6592 -- Mechanism_Code --
6593 --------------------
6595 -- Prefix of the Mechanism_Code attribute is a function name
6596 -- which must not be resolved. Should we check for overloaded ???
6598 when Attribute_Mechanism_Code
=>
6605 -- Most processing is done in sem_dist, after determining the
6606 -- context type. Node is rewritten as a conversion to a runtime call.
6608 when Attribute_Partition_ID
=>
6609 Process_Partition_Id
(N
);
6616 -- We replace the Range attribute node with a range expression
6617 -- whose bounds are the 'First and 'Last attributes applied to the
6618 -- same prefix. The reason that we do this transformation here
6619 -- instead of in the expander is that it simplifies other parts of
6620 -- the semantic analysis which assume that the Range has been
6621 -- replaced; thus it must be done even when in semantic-only mode
6622 -- (note that the RM specifically mentions this equivalence, we
6623 -- take care that the prefix is only evaluated once).
6625 when Attribute_Range
=> Range_Attribute
:
6630 function Check_Discriminated_Prival
6633 -- The range of a private component constrained by a
6634 -- discriminant is rewritten to make the discriminant
6635 -- explicit. This solves some complex visibility problems
6636 -- related to the use of privals.
6638 function Check_Discriminated_Prival
6643 if Is_Entity_Name
(N
)
6644 and then Ekind
(Entity
(N
)) = E_In_Parameter
6645 and then not Within_Init_Proc
6647 return Make_Identifier
(Sloc
(N
), Chars
(Entity
(N
)));
6649 return Duplicate_Subexpr
(N
);
6651 end Check_Discriminated_Prival
;
6653 -- Start of processing for Range_Attribute
6656 if not Is_Entity_Name
(P
)
6657 or else not Is_Type
(Entity
(P
))
6659 Resolve
(P
, Etype
(P
));
6662 -- Check whether prefix is (renaming of) private component
6663 -- of protected type.
6665 if Is_Entity_Name
(P
)
6666 and then Comes_From_Source
(N
)
6667 and then Is_Array_Type
(Etype
(P
))
6668 and then Number_Dimensions
(Etype
(P
)) = 1
6669 and then (Ekind
(Scope
(Entity
(P
))) = E_Protected_Type
6671 Ekind
(Scope
(Scope
(Entity
(P
)))) =
6674 LB
:= Check_Discriminated_Prival
(
6675 Type_Low_Bound
(Etype
(First_Index
(Etype
(P
)))));
6677 HB
:= Check_Discriminated_Prival
(
6678 Type_High_Bound
(Etype
(First_Index
(Etype
(P
)))));
6682 Make_Attribute_Reference
(Loc
,
6683 Prefix
=> Duplicate_Subexpr
(P
),
6684 Attribute_Name
=> Name_Last
,
6685 Expressions
=> Expressions
(N
));
6688 Make_Attribute_Reference
(Loc
,
6690 Attribute_Name
=> Name_First
,
6691 Expressions
=> Expressions
(N
));
6694 -- If the original was marked as Must_Not_Freeze (see code
6695 -- in Sem_Ch3.Make_Index), then make sure the rewriting
6696 -- does not freeze either.
6698 if Must_Not_Freeze
(N
) then
6699 Set_Must_Not_Freeze
(HB
);
6700 Set_Must_Not_Freeze
(LB
);
6701 Set_Must_Not_Freeze
(Prefix
(HB
));
6702 Set_Must_Not_Freeze
(Prefix
(LB
));
6705 if Raises_Constraint_Error
(Prefix
(N
)) then
6707 -- Preserve Sloc of prefix in the new bounds, so that
6708 -- the posted warning can be removed if we are within
6709 -- unreachable code.
6711 Set_Sloc
(LB
, Sloc
(Prefix
(N
)));
6712 Set_Sloc
(HB
, Sloc
(Prefix
(N
)));
6715 Rewrite
(N
, Make_Range
(Loc
, LB
, HB
));
6716 Analyze_And_Resolve
(N
, Typ
);
6718 -- Normally after resolving attribute nodes, Eval_Attribute
6719 -- is called to do any possible static evaluation of the node.
6720 -- However, here since the Range attribute has just been
6721 -- transformed into a range expression it is no longer an
6722 -- attribute node and therefore the call needs to be avoided
6723 -- and is accomplished by simply returning from the procedure.
6726 end Range_Attribute
;
6732 -- Prefix must not be resolved in this case, since it is not a
6733 -- real entity reference. No action of any kind is require!
6735 when Attribute_UET_Address
=>
6738 ----------------------
6739 -- Unchecked_Access --
6740 ----------------------
6742 -- Processing is shared with Access
6744 -------------------------
6745 -- Unrestricted_Access --
6746 -------------------------
6748 -- Processing is shared with Access
6754 -- Apply range check. Note that we did not do this during the
6755 -- analysis phase, since we wanted Eval_Attribute to have a
6756 -- chance at finding an illegal out of range value.
6758 when Attribute_Val
=>
6760 -- Note that we do our own Eval_Attribute call here rather than
6761 -- use the common one, because we need to do processing after
6762 -- the call, as per above comment.
6766 -- Eval_Attribute may replace the node with a raise CE, or
6767 -- fold it to a constant. Obviously we only apply a scalar
6768 -- range check if this did not happen!
6770 if Nkind
(N
) = N_Attribute_Reference
6771 and then Attribute_Name
(N
) = Name_Val
6773 Apply_Scalar_Range_Check
(First
(Expressions
(N
)), Btyp
);
6782 -- Prefix of Version attribute can be a subprogram name which
6783 -- must not be resolved, since this is not a call.
6785 when Attribute_Version
=>
6788 ----------------------
6789 -- Other Attributes --
6790 ----------------------
6792 -- For other attributes, resolve prefix unless it is a type. If
6793 -- the attribute reference itself is a type name ('Base and 'Class)
6794 -- then this is only legal within a task or protected record.
6797 if not Is_Entity_Name
(P
)
6798 or else not Is_Type
(Entity
(P
))
6800 Resolve
(P
, Etype
(P
));
6803 -- If the attribute reference itself is a type name ('Base,
6804 -- 'Class) then this is only legal within a task or protected
6805 -- record. What is this all about ???
6807 if Is_Entity_Name
(N
)
6808 and then Is_Type
(Entity
(N
))
6810 if Is_Concurrent_Type
(Entity
(N
))
6811 and then In_Open_Scopes
(Entity
(P
))
6816 ("invalid use of subtype name in expression or call", N
);
6820 -- For attributes whose argument may be a string, complete
6821 -- resolution of argument now. This avoids premature expansion
6822 -- (and the creation of transient scopes) before the attribute
6823 -- reference is resolved.
6826 when Attribute_Value
=>
6827 Resolve
(First
(Expressions
(N
)), Standard_String
);
6829 when Attribute_Wide_Value
=>
6830 Resolve
(First
(Expressions
(N
)), Standard_Wide_String
);
6832 when others => null;
6836 -- Normally the Freezing is done by Resolve but sometimes the Prefix
6837 -- is not resolved, in which case the freezing must be done now.
6839 Freeze_Expression
(P
);
6841 -- Finally perform static evaluation on the attribute reference
6845 end Resolve_Attribute
;