1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- E I N F O . U T I L S --
9 -- Copyright (C) 2020-2024, 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 3, 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 COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree
; use Atree
;
27 with Elists
; use Elists
;
28 with Nlists
; use Nlists
;
29 with Output
; use Output
;
30 with Sinfo
; use Sinfo
;
31 with Sinfo
.Utils
; use Sinfo
.Utils
;
33 package body Einfo
.Utils
is
35 -----------------------
36 -- Local subprograms --
37 -----------------------
40 (State_Id
: Entity_Id
;
41 Option_Nam
: Name_Id
) return Boolean;
42 -- Determine whether abstract state State_Id has particular option denoted
43 -- by the name Option_Nam.
45 -------------------------------------------
46 -- Aliases/Renamings of Renamed_Or_Alias --
47 -------------------------------------------
49 function Alias
(N
: Entity_Id
) return Entity_Id
is
51 return Val
: constant Entity_Id
:= Renamed_Or_Alias
(N
) do
53 (Is_Overloadable
(N
) or else Ekind
(N
) = E_Subprogram_Type
);
54 pragma Assert
(Val
in N_Entity_Id | N_Empty_Id
);
58 procedure Set_Alias
(N
: Entity_Id
; Val
: Entity_Id
) is
61 (Is_Overloadable
(N
) or else Ekind
(N
) = E_Subprogram_Type
);
62 pragma Assert
(Val
in N_Entity_Id | N_Empty_Id
);
64 Set_Renamed_Or_Alias
(N
, Val
);
67 function Renamed_Entity
(N
: Entity_Id
) return Entity_Id
is
69 return Val
: constant Entity_Id
:= Renamed_Or_Alias
(N
) do
70 pragma Assert
(not Is_Object
(N
) or else Etype
(N
) = Any_Type
);
71 pragma Assert
(Val
in N_Entity_Id | N_Empty_Id
);
75 procedure Set_Renamed_Entity
(N
: Entity_Id
; Val
: Entity_Id
) is
77 pragma Assert
(not Is_Object
(N
));
78 pragma Assert
(Val
in N_Entity_Id
);
80 Set_Renamed_Or_Alias
(N
, Val
);
81 end Set_Renamed_Entity
;
83 function Renamed_Object
(N
: Entity_Id
) return Node_Id
is
85 return Val
: constant Node_Id
:= Renamed_Or_Alias
(N
) do
86 -- Formal_Kind uses the entity, not a name of it. This happens
87 -- in front-end inlining, which also sets to Empty. Also in
88 -- Exp_Ch9, where formals are renamed for the benefit of gdb.
90 if Ekind
(N
) not in Formal_Kind
then
91 pragma Assert
(Is_Object
(N
));
92 pragma Assert
(Val
in N_Subexpr_Id | N_Empty_Id
);
98 procedure Set_Renamed_Object
(N
: Entity_Id
; Val
: Node_Id
) is
100 if Ekind
(N
) not in Formal_Kind
then
101 pragma Assert
(Is_Object
(N
));
102 pragma Assert
(Val
in N_Subexpr_Id | N_Empty_Id
);
106 Set_Renamed_Or_Alias
(N
, Val
);
107 end Set_Renamed_Object
;
109 function Renamed_Entity_Or_Object
(N
: Entity_Id
) return Node_Id
is
111 if Is_Object
(N
) then
112 return Renamed_Object
(N
);
114 return Renamed_Entity
(N
);
116 end Renamed_Entity_Or_Object
;
118 procedure Set_Renamed_Object_Of_Possibly_Void
119 (N
: Entity_Id
; Val
: Node_Id
)
122 pragma Assert
(Val
in N_Subexpr_Id
);
123 Set_Renamed_Or_Alias
(N
, Val
);
124 end Set_Renamed_Object_Of_Possibly_Void
;
131 (State_Id
: Entity_Id
;
132 Option_Nam
: Name_Id
) return Boolean
134 Decl
: constant Node_Id
:= Parent
(State_Id
);
139 pragma Assert
(Ekind
(State_Id
) = E_Abstract_State
);
141 -- The declaration of abstract states with options appear as an
142 -- extension aggregate. If this is not the case, the option is not
145 if Nkind
(Decl
) /= N_Extension_Aggregate
then
151 Opt
:= First
(Expressions
(Decl
));
152 while Present
(Opt
) loop
153 if Nkind
(Opt
) = N_Identifier
and then Chars
(Opt
) = Option_Nam
then
160 -- Complex options with various specifiers
162 Opt
:= First
(Component_Associations
(Decl
));
163 while Present
(Opt
) loop
164 Opt_Nam
:= First
(Choices
(Opt
));
166 if Nkind
(Opt_Nam
) = N_Identifier
167 and then Chars
(Opt_Nam
) = Option_Nam
178 ------------------------------
179 -- Classification Functions --
180 ------------------------------
182 function Is_Access_Object_Type
(Id
: E
) return B
is
184 return Is_Access_Type
(Id
)
185 and then Ekind
(Directly_Designated_Type
(Id
)) /= E_Subprogram_Type
;
186 end Is_Access_Object_Type
;
188 function Is_Access_Type
(Id
: E
) return B
is
190 return Ekind
(Id
) in Access_Kind
;
193 function Is_Access_Protected_Subprogram_Type
(Id
: E
) return B
is
195 return Ekind
(Id
) in Access_Protected_Kind
;
196 end Is_Access_Protected_Subprogram_Type
;
198 function Is_Access_Subprogram_Type
(Id
: E
) return B
is
200 return Is_Access_Type
(Id
)
201 and then Ekind
(Directly_Designated_Type
(Id
)) = E_Subprogram_Type
;
202 end Is_Access_Subprogram_Type
;
204 function Is_Address_Compatible_Type
(Id
: E
) return B
is
206 return Is_Descendant_Of_Address
(Id
) or else Id
= Standard_Address
;
207 end Is_Address_Compatible_Type
;
209 function Is_Aggregate_Type
(Id
: E
) return B
is
211 return Ekind
(Id
) in Aggregate_Kind
;
212 end Is_Aggregate_Type
;
214 function Is_Anonymous_Access_Type
(Id
: E
) return B
is
216 return Ekind
(Id
) in Anonymous_Access_Kind
;
217 end Is_Anonymous_Access_Type
;
219 function Is_Array_Type
(Id
: E
) return B
is
221 return Ekind
(Id
) in Array_Kind
;
224 function Is_Assignable
(Id
: E
) return B
is
226 return Ekind
(Id
) in Assignable_Kind
;
229 function Is_Class_Wide_Type
(Id
: E
) return B
is
231 return Ekind
(Id
) in Class_Wide_Kind
;
232 end Is_Class_Wide_Type
;
234 function Is_Composite_Type
(Id
: E
) return B
is
236 return Ekind
(Id
) in Composite_Kind
;
237 end Is_Composite_Type
;
239 function Is_Concurrent_Body
(Id
: E
) return B
is
241 return Ekind
(Id
) in Concurrent_Body_Kind
;
242 end Is_Concurrent_Body
;
244 function Is_Concurrent_Type
(Id
: E
) return B
is
246 return Ekind
(Id
) in Concurrent_Kind
;
247 end Is_Concurrent_Type
;
249 function Is_Decimal_Fixed_Point_Type
(Id
: E
) return B
is
251 return Ekind
(Id
) in Decimal_Fixed_Point_Kind
;
252 end Is_Decimal_Fixed_Point_Type
;
254 function Is_Digits_Type
(Id
: E
) return B
is
256 return Ekind
(Id
) in Digits_Kind
;
259 function Is_Discrete_Or_Fixed_Point_Type
(Id
: E
) return B
is
261 return Ekind
(Id
) in Discrete_Or_Fixed_Point_Kind
;
262 end Is_Discrete_Or_Fixed_Point_Type
;
264 function Is_Discrete_Type
(Id
: E
) return B
is
266 return Ekind
(Id
) in Discrete_Kind
;
267 end Is_Discrete_Type
;
269 function Is_Elementary_Type
(Id
: E
) return B
is
271 return Ekind
(Id
) in Elementary_Kind
;
272 end Is_Elementary_Type
;
274 function Is_Entry
(Id
: E
) return B
is
276 return Ekind
(Id
) in Entry_Kind
;
279 function Is_Enumeration_Type
(Id
: E
) return B
is
281 return Ekind
(Id
) in Enumeration_Kind
;
282 end Is_Enumeration_Type
;
284 function Is_Fixed_Point_Type
(Id
: E
) return B
is
286 return Ekind
(Id
) in Fixed_Point_Kind
;
287 end Is_Fixed_Point_Type
;
289 function Is_Floating_Point_Type
(Id
: E
) return B
is
291 return Ekind
(Id
) in Float_Kind
;
292 end Is_Floating_Point_Type
;
294 function Is_Formal
(Id
: E
) return B
is
296 return Ekind
(Id
) in Formal_Kind
;
299 function Is_Formal_Object
(Id
: E
) return B
is
301 return Ekind
(Id
) in Formal_Object_Kind
;
302 end Is_Formal_Object
;
304 function Is_Generic_Subprogram
(Id
: E
) return B
is
306 return Ekind
(Id
) in Generic_Subprogram_Kind
;
307 end Is_Generic_Subprogram
;
309 function Is_Generic_Unit
(Id
: E
) return B
is
311 return Ekind
(Id
) in Generic_Unit_Kind
;
314 function Is_Ghost_Entity
(Id
: E
) return Boolean is
316 return Is_Checked_Ghost_Entity
(Id
) or else Is_Ignored_Ghost_Entity
(Id
);
319 function Is_Incomplete_Or_Private_Type
(Id
: E
) return B
is
321 return Ekind
(Id
) in Incomplete_Or_Private_Kind
;
322 end Is_Incomplete_Or_Private_Type
;
324 function Is_Incomplete_Type
(Id
: E
) return B
is
326 return Ekind
(Id
) in Incomplete_Kind
;
327 end Is_Incomplete_Type
;
329 function Is_Integer_Type
(Id
: E
) return B
is
331 return Ekind
(Id
) in Integer_Kind
;
334 function Is_Modular_Integer_Type
(Id
: E
) return B
is
336 return Ekind
(Id
) in Modular_Integer_Kind
;
337 end Is_Modular_Integer_Type
;
339 function Is_Named_Access_Type
(Id
: E
) return B
is
341 return Ekind
(Id
) in Named_Access_Kind
;
342 end Is_Named_Access_Type
;
344 function Is_Named_Number
(Id
: E
) return B
is
346 return Ekind
(Id
) in Named_Kind
;
349 function Is_Numeric_Type
(Id
: E
) return B
is
351 return Ekind
(Id
) in Numeric_Kind
;
354 function Is_Object
(Id
: E
) return B
is
356 return Ekind
(Id
) in Object_Kind
;
359 function Is_Ordinary_Fixed_Point_Type
(Id
: E
) return B
is
361 return Ekind
(Id
) in Ordinary_Fixed_Point_Kind
;
362 end Is_Ordinary_Fixed_Point_Type
;
364 function Is_Overloadable
(Id
: E
) return B
is
366 return Ekind
(Id
) in Overloadable_Kind
;
369 function Is_Private_Type
(Id
: E
) return B
is
371 return Ekind
(Id
) in Private_Kind
;
374 function Is_Protected_Type
(Id
: E
) return B
is
376 return Ekind
(Id
) in Protected_Kind
;
377 end Is_Protected_Type
;
379 function Is_Real_Type
(Id
: E
) return B
is
381 return Ekind
(Id
) in Real_Kind
;
384 function Is_Record_Type
(Id
: E
) return B
is
386 return Ekind
(Id
) in Record_Kind
;
389 function Is_Scalar_Type
(Id
: E
) return B
is
391 return Ekind
(Id
) in Scalar_Kind
;
394 function Is_Signed_Integer_Type
(Id
: E
) return B
is
396 return Ekind
(Id
) in Signed_Integer_Kind
;
397 end Is_Signed_Integer_Type
;
399 function Is_Subprogram
(Id
: E
) return B
is
401 return Ekind
(Id
) in Subprogram_Kind
;
404 function Is_Subprogram_Or_Entry
(Id
: E
) return B
is
406 return Ekind
(Id
) in Subprogram_Kind
408 Ekind
(Id
) in Entry_Kind
;
409 end Is_Subprogram_Or_Entry
;
411 function Is_Subprogram_Or_Generic_Subprogram
(Id
: E
) return B
is
413 return Ekind
(Id
) in Subprogram_Kind
415 Ekind
(Id
) in Generic_Subprogram_Kind
;
416 end Is_Subprogram_Or_Generic_Subprogram
;
418 function Is_Task_Type
(Id
: E
) return B
is
420 return Ekind
(Id
) in Task_Kind
;
423 function Is_Type
(Id
: E
) return B
is
425 return Ekind
(Id
) in Type_Kind
;
428 ------------------------------------------
429 -- Type Representation Attribute Fields --
430 ------------------------------------------
432 function Known_Alignment
(E
: Entity_Id
) return B
is
434 -- For some reason, Empty is passed to this sometimes
436 return No
(E
) or else not Field_Is_Initial_Zero
(E
, F_Alignment
);
439 procedure Reinit_Alignment
(Id
: E
) is
441 Reinit_Field_To_Zero
(Id
, F_Alignment
);
442 end Reinit_Alignment
;
444 procedure Copy_Alignment
(To
, From
: E
) is
446 if Known_Alignment
(From
) then
447 Set_Alignment
(To
, Alignment
(From
));
449 Reinit_Alignment
(To
);
453 function Known_Component_Bit_Offset
(E
: Entity_Id
) return B
is
455 return Present
(Component_Bit_Offset
(E
));
456 end Known_Component_Bit_Offset
;
458 function Known_Static_Component_Bit_Offset
(E
: Entity_Id
) return B
is
460 return Known_Component_Bit_Offset
(E
)
461 and then Component_Bit_Offset
(E
) >= Uint_0
;
462 end Known_Static_Component_Bit_Offset
;
464 function Known_Component_Size
(E
: Entity_Id
) return B
is
466 return Present
(Component_Size
(E
));
467 end Known_Component_Size
;
469 function Known_Static_Component_Size
(E
: Entity_Id
) return B
is
471 return Known_Component_Size
(E
) and then Component_Size
(E
) >= Uint_0
;
472 end Known_Static_Component_Size
;
474 function Known_Esize
(E
: Entity_Id
) return B
is
476 return Present
(Esize
(E
));
479 function Known_Static_Esize
(E
: Entity_Id
) return B
is
481 return Known_Esize
(E
)
482 and then Esize
(E
) >= Uint_0
483 and then not Is_Generic_Type
(E
);
484 end Known_Static_Esize
;
486 procedure Reinit_Esize
(Id
: E
) is
488 Reinit_Field_To_Zero
(Id
, F_Esize
);
491 procedure Copy_Esize
(To
, From
: E
) is
493 if Known_Esize
(From
) then
494 Set_Esize
(To
, Esize
(From
));
500 function Known_Normalized_First_Bit
(E
: Entity_Id
) return B
is
502 return Present
(Normalized_First_Bit
(E
));
503 end Known_Normalized_First_Bit
;
505 function Known_Static_Normalized_First_Bit
(E
: Entity_Id
) return B
is
507 return Known_Normalized_First_Bit
(E
)
508 and then Normalized_First_Bit
(E
) >= Uint_0
;
509 end Known_Static_Normalized_First_Bit
;
511 function Known_Normalized_Position
(E
: Entity_Id
) return B
is
513 return Present
(Normalized_Position
(E
));
514 end Known_Normalized_Position
;
516 function Known_Static_Normalized_Position
(E
: Entity_Id
) return B
is
518 return Known_Normalized_Position
(E
)
519 and then Normalized_Position
(E
) >= Uint_0
;
520 end Known_Static_Normalized_Position
;
522 function Known_RM_Size
(E
: Entity_Id
) return B
is
524 return Present
(RM_Size
(E
));
527 function Known_Static_RM_Size
(E
: Entity_Id
) return B
is
529 return Known_RM_Size
(E
)
530 and then RM_Size
(E
) >= Uint_0
531 and then not Is_Generic_Type
(E
);
532 end Known_Static_RM_Size
;
534 procedure Reinit_RM_Size
(Id
: E
) is
536 Reinit_Field_To_Zero
(Id
, F_RM_Size
);
539 procedure Copy_RM_Size
(To
, From
: E
) is
541 if Known_RM_Size
(From
) then
542 Set_RM_Size
(To
, RM_Size
(From
));
548 -------------------------------
549 -- Reinit_Component_Location --
550 -------------------------------
552 procedure Reinit_Component_Location
(Id
: E
) is
554 Set_Normalized_First_Bit
(Id
, No_Uint
);
555 Set_Component_Bit_Offset
(Id
, No_Uint
);
557 Set_Normalized_Position
(Id
, No_Uint
);
558 end Reinit_Component_Location
;
560 ------------------------------
561 -- Reinit_Object_Size_Align --
562 ------------------------------
564 procedure Reinit_Object_Size_Align
(Id
: E
) is
567 Reinit_Alignment
(Id
);
568 end Reinit_Object_Size_Align
;
574 procedure Init_Size
(Id
: E
; V
: Int
) is
576 pragma Assert
(Is_Type
(Id
));
577 pragma Assert
(not Known_Esize
(Id
) or else Esize
(Id
) = V
);
578 pragma Assert
(not Known_RM_Size
(Id
) or else RM_Size
(Id
) = V
);
580 Set_Esize
(Id
, UI_From_Int
(V
));
581 Set_RM_Size
(Id
, UI_From_Int
(V
));
584 -----------------------
585 -- Reinit_Size_Align --
586 -----------------------
588 procedure Reinit_Size_Align
(Id
: E
) is
590 pragma Assert
(Ekind
(Id
) in Type_Kind | E_Void
);
593 Reinit_Alignment
(Id
);
594 end Reinit_Size_Align
;
600 function Address_Clause
(Id
: E
) return Node_Id
is
602 return Get_Attribute_Definition_Clause
(Id
, Attribute_Address
);
609 function Aft_Value
(Id
: E
) return U
is
611 Delta_Val
: Ureal
:= Delta_Value
(Id
);
613 while Delta_Val
< Ureal_Tenth
loop
614 Delta_Val
:= Delta_Val
* Ureal_10
;
615 Result
:= Result
+ 1;
618 return UI_From_Int
(Result
);
621 ----------------------
622 -- Alignment_Clause --
623 ----------------------
625 function Alignment_Clause
(Id
: E
) return Node_Id
is
627 return Get_Attribute_Definition_Clause
(Id
, Attribute_Alignment
);
628 end Alignment_Clause
;
634 procedure Append_Entity
(Id
: Entity_Id
; Scop
: Entity_Id
) is
635 Last
: constant Entity_Id
:= Last_Entity
(Scop
);
638 Set_Scope
(Id
, Scop
);
639 Set_Prev_Entity
(Id
, Empty
); -- Empty <-- Id
641 -- The entity chain is empty
644 Set_First_Entity
(Scop
, Id
);
646 -- Otherwise the entity chain has at least one element
649 Link_Entities
(Last
, Id
); -- Last <-- Id, Last --> Id
652 -- NOTE: The setting of the Next_Entity attribute of Id must happen
653 -- here as opposed to at the beginning of the routine because doing
654 -- so causes the binder to hang. It is not clear why ???
656 Set_Next_Entity
(Id
, Empty
); -- Id --> Empty
658 Set_Last_Entity
(Scop
, Id
);
665 function Base_Type
(Id
: E
) return E
is
668 if Is_Base_Type
(Id
) then
671 pragma Assert
(Is_Type
(Id
));
672 Result
:= Etype
(Id
);
674 pragma Assert
(Is_Base_Type
(Result
));
675 -- ???It seems like Base_Type should return a base type,
676 -- but this assertion is disabled because it is not always
677 -- true. Hence the need to say "Base_Type (Base_Type (...))"
678 -- in some cases; Base_Type is not idempotent as one might
685 ----------------------
686 -- Declaration_Node --
687 ----------------------
689 function Declaration_Node
(Id
: E
) return Node_Id
is
693 if Ekind
(Id
) = E_Incomplete_Type
694 and then Present
(Full_View
(Id
))
696 P
:= Parent
(Full_View
(Id
));
701 while Nkind
(P
) in N_Selected_Component | N_Expanded_Name
702 or else (Nkind
(P
) = N_Defining_Program_Unit_Name
703 and then Is_Child_Unit
(Id
))
709 and then Nkind
(P
) not in
710 N_Full_Type_Declaration | N_Subtype_Declaration
715 -- Declarations are sometimes removed by replacing them with other
716 -- irrelevant nodes. For example, a declare expression can be turned
717 -- into a literal by constant folding. In these cases we want to
721 N_Assignment_Statement
723 | N_Procedure_Call_Statement
724 | N_Subtype_Indication
730 -- The following Assert indicates what kinds of nodes can be returned;
731 -- they are not all "declarations".
733 if Serious_Errors_Detected
= 0 then
735 (Nkind
(P
) in N_Is_Decl | N_Empty
,
736 "Declaration_Node incorrect kind: " & Node_Kind
'Image (Nkind
(P
)));
740 end Declaration_Node
;
742 ---------------------
743 -- Designated_Type --
744 ---------------------
746 function Designated_Type
(Id
: E
) return E
is
747 Desig_Type
: Entity_Id
;
750 Desig_Type
:= Directly_Designated_Type
(Id
);
752 if No
(Desig_Type
) then
753 pragma Assert
(Error_Posted
(Id
));
757 if Is_Incomplete_Type
(Desig_Type
)
758 and then Present
(Full_View
(Desig_Type
))
760 return Full_View
(Desig_Type
);
763 if Is_Class_Wide_Type
(Desig_Type
)
764 and then Is_Incomplete_Type
(Etype
(Desig_Type
))
765 and then Present
(Full_View
(Etype
(Desig_Type
)))
766 and then Present
(Class_Wide_Type
(Full_View
(Etype
(Desig_Type
))))
768 return Class_Wide_Type
(Full_View
(Etype
(Desig_Type
)));
774 ----------------------
775 -- Entry_Index_Type --
776 ----------------------
778 function Entry_Index_Type
(Id
: E
) return E
is
780 pragma Assert
(Ekind
(Id
) = E_Entry_Family
);
781 return Etype
(Discrete_Subtype_Definition
(Parent
(Id
)));
782 end Entry_Index_Type
;
784 ---------------------
785 -- First_Component --
786 ---------------------
788 function First_Component
(Id
: E
) return Entity_Id
is
793 (Is_Concurrent_Type
(Id
)
794 or else Is_Incomplete_Or_Private_Type
(Id
)
795 or else Is_Record_Type
(Id
));
797 Comp_Id
:= First_Entity
(Id
);
798 while Present
(Comp_Id
) loop
799 exit when Ekind
(Comp_Id
) = E_Component
;
800 Next_Entity
(Comp_Id
);
806 -------------------------------------
807 -- First_Component_Or_Discriminant --
808 -------------------------------------
810 function First_Component_Or_Discriminant
(Id
: E
) return Entity_Id
is
815 (Is_Concurrent_Type
(Id
)
816 or else Is_Incomplete_Or_Private_Type
(Id
)
817 or else Is_Record_Type
(Id
)
818 or else Has_Discriminants
(Id
));
820 Comp_Id
:= First_Entity
(Id
);
821 while Present
(Comp_Id
) loop
822 exit when Ekind
(Comp_Id
) in E_Component | E_Discriminant
;
823 Next_Entity
(Comp_Id
);
827 end First_Component_Or_Discriminant
;
833 function First_Formal
(Id
: E
) return Entity_Id
is
838 (Is_Generic_Subprogram
(Id
)
839 or else Is_Overloadable
(Id
)
840 or else Ekind
(Id
) in E_Entry_Family
842 | E_Subprogram_Type
);
844 if Ekind
(Id
) = E_Enumeration_Literal
then
848 Formal
:= First_Entity
(Id
);
850 -- Deal with the common, non-generic case first
852 if No
(Formal
) or else Is_Formal
(Formal
) then
856 -- The first/next entity chain of a generic subprogram contains all
857 -- generic formal parameters, followed by the formal parameters.
859 if Is_Generic_Subprogram
(Id
) then
860 while Present
(Formal
) and then not Is_Formal
(Formal
) loop
861 Next_Entity
(Formal
);
870 ------------------------------
871 -- First_Formal_With_Extras --
872 ------------------------------
874 function First_Formal_With_Extras
(Id
: E
) return Entity_Id
is
879 (Is_Generic_Subprogram
(Id
)
880 or else Is_Overloadable
(Id
)
881 or else Ekind
(Id
) in E_Entry_Family
883 | E_Subprogram_Type
);
885 if Ekind
(Id
) = E_Enumeration_Literal
then
889 Formal
:= First_Entity
(Id
);
891 -- The first/next entity chain of a generic subprogram contains all
892 -- generic formal parameters, followed by the formal parameters. Go
893 -- directly to the parameters by skipping the formal part.
895 if Is_Generic_Subprogram
(Id
) then
896 while Present
(Formal
) and then not Is_Formal
(Formal
) loop
897 Next_Entity
(Formal
);
901 if Present
(Formal
) and then Is_Formal
(Formal
) then
904 return Extra_Formals
(Id
); -- Empty if no extra formals
907 end First_Formal_With_Extras
;
913 function Float_Rep
(N
: Entity_Id
) return Float_Rep_Kind
is
914 pragma Unreferenced
(N
);
915 pragma Assert
(Float_Rep_Kind
'First = Float_Rep_Kind
'Last);
917 -- There is only one value, so we don't need to store it, see types.ads.
919 Val
: constant Float_Rep_Kind
:= IEEE_Binary
;
925 -------------------------------------
926 -- Get_Attribute_Definition_Clause --
927 -------------------------------------
929 function Get_Attribute_Definition_Clause
931 Id
: Attribute_Id
) return Node_Id
936 N
:= First_Rep_Item
(E
);
937 while Present
(N
) loop
938 if Nkind
(N
) = N_Attribute_Definition_Clause
939 and then Get_Attribute_Id
(Chars
(N
)) = Id
948 end Get_Attribute_Definition_Clause
;
950 ---------------------------
951 -- Get_Class_Wide_Pragma --
952 ---------------------------
954 function Get_Class_Wide_Pragma
956 Id
: Pragma_Id
) return Node_Id
962 Items
:= Contract
(E
);
968 Item
:= Pre_Post_Conditions
(Items
);
969 while Present
(Item
) loop
970 if Nkind
(Item
) = N_Pragma
971 and then Get_Pragma_Id
(Pragma_Name_Unmapped
(Item
)) = Id
972 and then Class_Present
(Item
)
977 Item
:= Next_Pragma
(Item
);
981 end Get_Class_Wide_Pragma
;
987 function Get_Full_View
(T
: Entity_Id
) return Entity_Id
is
989 if Is_Incomplete_Type
(T
) and then Present
(Full_View
(T
)) then
990 return Full_View
(T
);
992 elsif Is_Class_Wide_Type
(T
)
993 and then Is_Incomplete_Type
(Root_Type
(T
))
994 and then Present
(Full_View
(Root_Type
(T
)))
996 return Class_Wide_Type
(Full_View
(Root_Type
(T
)));
1007 function Get_Pragma
(E
: Entity_Id
; Id
: Pragma_Id
) return Node_Id
is
1009 -- Classification pragmas
1011 Is_CLS
: constant Boolean :=
1012 Id
= Pragma_Abstract_State
or else
1013 Id
= Pragma_Attach_Handler
or else
1014 Id
= Pragma_Async_Readers
or else
1015 Id
= Pragma_Async_Writers
or else
1016 Id
= Pragma_Constant_After_Elaboration
or else
1017 Id
= Pragma_Depends
or else
1018 Id
= Pragma_Effective_Reads
or else
1019 Id
= Pragma_Effective_Writes
or else
1020 Id
= Pragma_Extensions_Visible
or else
1021 Id
= Pragma_Global
or else
1022 Id
= Pragma_Initial_Condition
or else
1023 Id
= Pragma_Initializes
or else
1024 Id
= Pragma_Interrupt_Handler
or else
1025 Id
= Pragma_No_Caching
or else
1026 Id
= Pragma_Part_Of
or else
1027 Id
= Pragma_Refined_Depends
or else
1028 Id
= Pragma_Refined_Global
or else
1029 Id
= Pragma_Refined_State
or else
1030 Id
= Pragma_Side_Effects
or else
1031 Id
= Pragma_Volatile_Function
;
1033 -- Contract / subprogram variant / test case pragmas
1035 Is_CTC
: constant Boolean :=
1036 Id
= Pragma_Always_Terminates
or else
1037 Id
= Pragma_Contract_Cases
or else
1038 Id
= Pragma_Exceptional_Cases
or else
1039 Id
= Pragma_Subprogram_Variant
or else
1040 Id
= Pragma_Test_Case
;
1042 -- Pre / postcondition pragmas
1044 Is_PPC
: constant Boolean :=
1045 Id
= Pragma_Precondition
or else
1046 Id
= Pragma_Postcondition
or else
1047 Id
= Pragma_Refined_Post
;
1049 In_Contract
: constant Boolean := Is_CLS
or Is_CTC
or Is_PPC
;
1055 -- Handle pragmas that appear in N_Contract nodes. Those have to be
1056 -- extracted from their specialized list.
1059 Items
:= Contract
(E
);
1065 Item
:= Classifications
(Items
);
1068 Item
:= Contract_Test_Cases
(Items
);
1071 Item
:= Pre_Post_Conditions
(Items
);
1077 Item
:= First_Rep_Item
(E
);
1080 while Present
(Item
) loop
1081 if Nkind
(Item
) = N_Pragma
1082 and then Get_Pragma_Id
(Pragma_Name_Unmapped
(Item
)) = Id
1086 -- All nodes in N_Contract are chained using Next_Pragma
1088 elsif In_Contract
then
1089 Item
:= Next_Pragma
(Item
);
1094 Next_Rep_Item
(Item
);
1101 --------------------------------------
1102 -- Get_Record_Representation_Clause --
1103 --------------------------------------
1105 function Get_Record_Representation_Clause
(E
: Entity_Id
) return Node_Id
is
1109 N
:= First_Rep_Item
(E
);
1110 while Present
(N
) loop
1111 if Nkind
(N
) = N_Record_Representation_Clause
then
1119 end Get_Record_Representation_Clause
;
1121 ------------------------
1122 -- Has_Attach_Handler --
1123 ------------------------
1125 function Has_Attach_Handler
(Id
: E
) return B
is
1129 pragma Assert
(Is_Protected_Type
(Id
));
1131 Ritem
:= First_Rep_Item
(Id
);
1132 while Present
(Ritem
) loop
1133 if Nkind
(Ritem
) = N_Pragma
1134 and then Pragma_Name
(Ritem
) = Name_Attach_Handler
1138 Next_Rep_Item
(Ritem
);
1143 end Has_Attach_Handler
;
1149 function Has_DIC
(Id
: E
) return B
is
1151 return Has_Own_DIC
(Id
) or else Has_Inherited_DIC
(Id
);
1158 function Has_Entries
(Id
: E
) return B
is
1162 pragma Assert
(Is_Concurrent_Type
(Id
));
1164 Ent
:= First_Entity
(Id
);
1165 while Present
(Ent
) loop
1166 if Is_Entry
(Ent
) then
1176 ----------------------------
1177 -- Has_Foreign_Convention --
1178 ----------------------------
1180 function Has_Foreign_Convention
(Id
: E
) return B
is
1182 -- While regular Intrinsics such as the Standard operators fit in the
1183 -- "Ada" convention, those with an Interface_Name materialize GCC
1184 -- builtin imports for which Ada special treatments shouldn't apply.
1186 return Convention
(Id
) in Foreign_Convention
1187 or else (Convention
(Id
) = Convention_Intrinsic
1188 and then Present
(Interface_Name
(Id
)));
1189 end Has_Foreign_Convention
;
1191 ---------------------------
1192 -- Has_Interrupt_Handler --
1193 ---------------------------
1195 function Has_Interrupt_Handler
(Id
: E
) return B
is
1199 pragma Assert
(Is_Protected_Type
(Id
));
1201 Ritem
:= First_Rep_Item
(Id
);
1202 while Present
(Ritem
) loop
1203 if Nkind
(Ritem
) = N_Pragma
1204 and then Pragma_Name
(Ritem
) = Name_Interrupt_Handler
1208 Next_Rep_Item
(Ritem
);
1213 end Has_Interrupt_Handler
;
1215 --------------------
1216 -- Has_Invariants --
1217 --------------------
1219 function Has_Invariants
(Id
: E
) return B
is
1221 return Has_Own_Invariants
(Id
) or else Has_Inherited_Invariants
(Id
);
1224 --------------------------
1225 -- Has_Limited_View --
1226 --------------------------
1228 function Has_Limited_View
(Id
: E
) return B
is
1230 return Ekind
(Id
) = E_Package
1231 and then not Is_Generic_Instance
(Id
)
1232 and then Present
(Limited_View
(Id
));
1233 end Has_Limited_View
;
1235 --------------------------
1236 -- Has_Non_Limited_View --
1237 --------------------------
1239 function Has_Non_Limited_View
(Id
: E
) return B
is
1241 return (Ekind
(Id
) in Incomplete_Kind
1242 or else Ekind
(Id
) in Class_Wide_Kind
1243 or else Ekind
(Id
) = E_Abstract_State
)
1244 and then Present
(Non_Limited_View
(Id
));
1245 end Has_Non_Limited_View
;
1247 ---------------------------------
1248 -- Has_Non_Null_Abstract_State --
1249 ---------------------------------
1251 function Has_Non_Null_Abstract_State
(Id
: E
) return B
is
1253 pragma Assert
(Is_Package_Or_Generic_Package
(Id
));
1256 Present
(Abstract_States
(Id
))
1258 not Is_Null_State
(Node
(First_Elmt
(Abstract_States
(Id
))));
1259 end Has_Non_Null_Abstract_State
;
1261 -------------------------------------
1262 -- Has_Non_Null_Visible_Refinement --
1263 -------------------------------------
1265 function Has_Non_Null_Visible_Refinement
(Id
: E
) return B
is
1266 Constits
: Elist_Id
;
1269 -- "Refinement" is a concept applicable only to abstract states
1271 pragma Assert
(Ekind
(Id
) = E_Abstract_State
);
1272 Constits
:= Refinement_Constituents
(Id
);
1274 -- A partial refinement is always non-null. For a full refinement to be
1275 -- non-null, the first constituent must be anything other than null.
1278 Has_Partial_Visible_Refinement
(Id
)
1279 or else (Has_Visible_Refinement
(Id
)
1280 and then Present
(Constits
)
1281 and then Nkind
(Node
(First_Elmt
(Constits
))) /= N_Null
);
1282 end Has_Non_Null_Visible_Refinement
;
1284 -----------------------------
1285 -- Has_Null_Abstract_State --
1286 -----------------------------
1288 function Has_Null_Abstract_State
(Id
: E
) return B
is
1289 pragma Assert
(Is_Package_Or_Generic_Package
(Id
));
1291 States
: constant Elist_Id
:= Abstract_States
(Id
);
1294 -- Check first available state of related package. A null abstract
1295 -- state always appears as the sole element of the state list.
1299 and then Is_Null_State
(Node
(First_Elmt
(States
)));
1300 end Has_Null_Abstract_State
;
1302 ---------------------------------
1303 -- Has_Null_Visible_Refinement --
1304 ---------------------------------
1306 function Has_Null_Visible_Refinement
(Id
: E
) return B
is
1307 Constits
: Elist_Id
;
1310 -- "Refinement" is a concept applicable only to abstract states
1312 pragma Assert
(Ekind
(Id
) = E_Abstract_State
);
1313 Constits
:= Refinement_Constituents
(Id
);
1315 -- For a refinement to be null, the state's sole constituent must be a
1319 Has_Visible_Refinement
(Id
)
1320 and then Present
(Constits
)
1321 and then Nkind
(Node
(First_Elmt
(Constits
))) = N_Null
;
1322 end Has_Null_Visible_Refinement
;
1324 --------------------
1325 -- Has_Unmodified --
1326 --------------------
1328 function Has_Unmodified
(E
: Entity_Id
) return Boolean is
1330 if Has_Pragma_Unmodified
(E
) then
1332 elsif Warnings_Off
(E
) then
1333 Set_Warnings_Off_Used_Unmodified
(E
);
1340 ---------------------
1341 -- Has_Unreferenced --
1342 ---------------------
1344 function Has_Unreferenced
(E
: Entity_Id
) return Boolean is
1346 if Has_Pragma_Unreferenced
(E
) then
1348 elsif Warnings_Off
(E
) then
1349 Set_Warnings_Off_Used_Unreferenced
(E
);
1354 end Has_Unreferenced
;
1356 ----------------------
1357 -- Has_Warnings_Off --
1358 ----------------------
1360 function Has_Warnings_Off
(E
: Entity_Id
) return Boolean is
1362 if Warnings_Off
(E
) then
1363 Set_Warnings_Off_Used
(E
);
1368 end Has_Warnings_Off
;
1370 ------------------------------
1371 -- Implementation_Base_Type --
1372 ------------------------------
1374 function Implementation_Base_Type
(Id
: E
) return E
is
1379 Bastyp
:= Base_Type
(Id
);
1381 if Is_Incomplete_Or_Private_Type
(Bastyp
) then
1382 Imptyp
:= Underlying_Type
(Bastyp
);
1384 -- If we have an implementation type, then just return it,
1385 -- otherwise we return the Base_Type anyway. This can only
1386 -- happen in error situations and should avoid some error bombs.
1388 if Present
(Imptyp
) then
1389 return Base_Type
(Imptyp
);
1397 end Implementation_Base_Type
;
1399 -------------------------
1400 -- Invariant_Procedure --
1401 -------------------------
1403 function Invariant_Procedure
(Id
: E
) return Entity_Id
is
1404 Subp_Elmt
: Elmt_Id
;
1405 Subp_Id
: Entity_Id
;
1409 pragma Assert
(Is_Type
(Id
));
1411 Subps
:= Subprograms_For_Type
(Base_Type
(Id
));
1413 if Present
(Subps
) then
1414 Subp_Elmt
:= First_Elmt
(Subps
);
1415 while Present
(Subp_Elmt
) loop
1416 Subp_Id
:= Node
(Subp_Elmt
);
1418 if Is_Invariant_Procedure
(Subp_Id
) then
1422 Next_Elmt
(Subp_Elmt
);
1427 end Invariant_Procedure
;
1433 -- Global flag table allowing rapid computation of this function
1435 Entity_Is_Base_Type
: constant array (Entity_Kind
) of Boolean :=
1436 (E_Enumeration_Subtype |
1437 E_Incomplete_Subtype |
1438 E_Signed_Integer_Subtype |
1439 E_Modular_Integer_Subtype |
1440 E_Floating_Point_Subtype |
1441 E_Ordinary_Fixed_Point_Subtype |
1442 E_Decimal_Fixed_Point_Subtype |
1446 E_Record_Subtype_With_Private |
1447 E_Limited_Private_Subtype |
1449 E_Protected_Subtype |
1451 E_String_Literal_Subtype |
1452 E_Class_Wide_Subtype
=> False,
1455 function Is_Base_Type
(Id
: E
) return Boolean is
1457 return Entity_Is_Base_Type
(Ekind
(Id
));
1460 ---------------------
1461 -- Is_Boolean_Type --
1462 ---------------------
1464 function Is_Boolean_Type
(Id
: E
) return B
is
1466 return Root_Type
(Id
) = Standard_Boolean
;
1467 end Is_Boolean_Type
;
1469 ------------------------
1470 -- Is_Constant_Object --
1471 ------------------------
1473 function Is_Constant_Object
(Id
: E
) return B
is
1475 return Ekind
(Id
) in E_Constant | E_In_Parameter | E_Loop_Parameter
;
1476 end Is_Constant_Object
;
1482 function Is_Controlled
(Id
: E
) return B
is
1484 return Is_Controlled_Active
(Id
) and then not Disable_Controlled
(Id
);
1487 --------------------
1488 -- Is_Discriminal --
1489 --------------------
1491 function Is_Discriminal
(Id
: E
) return B
is
1493 return Ekind
(Id
) in E_Constant | E_In_Parameter
1494 and then Present
(Discriminal_Link
(Id
));
1497 ----------------------
1498 -- Is_Dynamic_Scope --
1499 ----------------------
1501 function Is_Dynamic_Scope
(Id
: E
) return B
is
1503 return Ekind
(Id
) in E_Block
1504 -- Including an E_Block that came from an N_Expression_With_Actions
1509 | E_Return_Statement
1513 (Ekind
(Id
) = E_Limited_Private_Type
1514 and then Present
(Full_View
(Id
))
1515 and then Ekind
(Full_View
(Id
)) = E_Task_Type
);
1516 end Is_Dynamic_Scope
;
1518 --------------------
1519 -- Is_Entity_Name --
1520 --------------------
1522 function Is_Entity_Name
(N
: Node_Id
) return Boolean is
1523 Kind
: constant Node_Kind
:= Nkind
(N
);
1526 -- Identifiers, operator symbols, expanded names are entity names.
1527 -- (But not N_Character_Literal.)
1529 return Kind
in N_Identifier | N_Operator_Symbol | N_Expanded_Name
1531 -- Attribute references are entity names if they refer to an entity.
1532 -- Note that we don't do this by testing for the presence of the
1533 -- Entity field in the N_Attribute_Reference node, since it may not
1534 -- have been set yet.
1536 or else (Kind
= N_Attribute_Reference
1537 and then Is_Entity_Attribute_Name
(Attribute_Name
(N
)));
1540 ---------------------------
1541 -- Is_Elaboration_Target --
1542 ---------------------------
1544 function Is_Elaboration_Target
(Id
: E
) return Boolean is
1547 Ekind
(Id
) in E_Constant | E_Package | E_Variable
1548 or else Is_Entry
(Id
)
1549 or else Is_Generic_Unit
(Id
)
1550 or else Is_Subprogram
(Id
)
1551 or else Is_Task_Type
(Id
);
1552 end Is_Elaboration_Target
;
1554 -----------------------
1555 -- Is_External_State --
1556 -----------------------
1558 function Is_External_State
(Id
: E
) return B
is
1560 -- To qualify, the abstract state must appear with option "external" or
1561 -- "synchronous" (SPARK RM 7.1.4(7) and (9)).
1564 Ekind
(Id
) = E_Abstract_State
1565 and then (Has_Option
(Id
, Name_External
)
1567 Has_Option
(Id
, Name_Synchronous
));
1568 end Is_External_State
;
1574 function Is_Finalizer
(Id
: E
) return B
is
1576 return Ekind
(Id
) = E_Procedure
and then Chars
(Id
) = Name_uFinalizer
;
1579 ----------------------
1580 -- Is_Full_Access --
1581 ----------------------
1583 function Is_Full_Access
(Id
: E
) return B
is
1585 return Is_Atomic
(Id
) or else Is_Volatile_Full_Access
(Id
);
1592 function Is_Null_State
(Id
: E
) return B
is
1595 Ekind
(Id
) = E_Abstract_State
and then Nkind
(Parent
(Id
)) = N_Null
;
1598 -----------------------------------
1599 -- Is_Package_Or_Generic_Package --
1600 -----------------------------------
1602 function Is_Package_Or_Generic_Package
(Id
: E
) return B
is
1604 return Ekind
(Id
) in E_Generic_Package | E_Package
;
1605 end Is_Package_Or_Generic_Package
;
1607 ---------------------
1608 -- Is_Packed_Array --
1609 ---------------------
1611 function Is_Packed_Array
(Id
: E
) return B
is
1613 return Is_Array_Type
(Id
) and then Is_Packed
(Id
);
1614 end Is_Packed_Array
;
1620 function Is_Prival
(Id
: E
) return B
is
1622 return Ekind
(Id
) in E_Constant | E_Variable
1623 and then Present
(Prival_Link
(Id
));
1626 ----------------------------
1627 -- Is_Protected_Component --
1628 ----------------------------
1630 function Is_Protected_Component
(Id
: E
) return B
is
1632 return Ekind
(Id
) = E_Component
and then Is_Protected_Type
(Scope
(Id
));
1633 end Is_Protected_Component
;
1635 ----------------------------
1636 -- Is_Protected_Interface --
1637 ----------------------------
1639 function Is_Protected_Interface
(Id
: E
) return B
is
1640 Typ
: constant Entity_Id
:= Base_Type
(Id
);
1642 if not Is_Interface
(Typ
) then
1644 elsif Is_Class_Wide_Type
(Typ
) then
1645 return Is_Protected_Interface
(Etype
(Typ
));
1647 return Protected_Present
(Type_Definition
(Parent
(Typ
)));
1649 end Is_Protected_Interface
;
1651 ------------------------------
1652 -- Is_Protected_Record_Type --
1653 ------------------------------
1655 function Is_Protected_Record_Type
(Id
: E
) return B
is
1658 Is_Concurrent_Record_Type
(Id
)
1659 and then Is_Protected_Type
(Corresponding_Concurrent_Type
(Id
));
1660 end Is_Protected_Record_Type
;
1662 --------------------------------
1663 -- Is_Standard_Character_Type --
1664 --------------------------------
1666 function Is_Standard_Character_Type
(Id
: E
) return B
is
1669 and then Root_Type
(Id
) in Standard_Character
1670 | Standard_Wide_Character
1671 | Standard_Wide_Wide_Character
;
1672 end Is_Standard_Character_Type
;
1674 -----------------------------
1675 -- Is_Standard_String_Type --
1676 -----------------------------
1678 function Is_Standard_String_Type
(Id
: E
) return B
is
1681 and then Root_Type
(Id
) in Standard_String
1682 | Standard_Wide_String
1683 | Standard_Wide_Wide_String
;
1684 end Is_Standard_String_Type
;
1686 --------------------
1687 -- Is_String_Type --
1688 --------------------
1690 function Is_String_Type
(Id
: E
) return B
is
1692 return Is_Array_Type
(Id
)
1693 and then Id
/= Any_Composite
1694 and then Number_Dimensions
(Id
) = 1
1695 and then Is_Character_Type
(Component_Type
(Id
));
1698 -------------------------------
1699 -- Is_Synchronized_Interface --
1700 -------------------------------
1702 function Is_Synchronized_Interface
(Id
: E
) return B
is
1703 Typ
: constant Entity_Id
:= Base_Type
(Id
);
1706 if not Is_Interface
(Typ
) then
1709 elsif Is_Class_Wide_Type
(Typ
) then
1710 return Is_Synchronized_Interface
(Etype
(Typ
));
1713 return Protected_Present
(Type_Definition
(Parent
(Typ
)))
1714 or else Synchronized_Present
(Type_Definition
(Parent
(Typ
)))
1715 or else Task_Present
(Type_Definition
(Parent
(Typ
)));
1717 end Is_Synchronized_Interface
;
1719 ---------------------------
1720 -- Is_Synchronized_State --
1721 ---------------------------
1723 function Is_Synchronized_State
(Id
: E
) return B
is
1725 -- To qualify, the abstract state must appear with simple option
1726 -- "synchronous" (SPARK RM 7.1.4(9)).
1729 Ekind
(Id
) = E_Abstract_State
1730 and then Has_Option
(Id
, Name_Synchronous
);
1731 end Is_Synchronized_State
;
1733 -----------------------
1734 -- Is_Task_Interface --
1735 -----------------------
1737 function Is_Task_Interface
(Id
: E
) return B
is
1738 Typ
: constant Entity_Id
:= Base_Type
(Id
);
1740 if not Is_Interface
(Typ
) then
1742 elsif Is_Class_Wide_Type
(Typ
) then
1743 return Is_Task_Interface
(Etype
(Typ
));
1745 return Task_Present
(Type_Definition
(Parent
(Typ
)));
1747 end Is_Task_Interface
;
1749 -------------------------
1750 -- Is_Task_Record_Type --
1751 -------------------------
1753 function Is_Task_Record_Type
(Id
: E
) return B
is
1756 Is_Concurrent_Record_Type
(Id
)
1757 and then Is_Task_Type
(Corresponding_Concurrent_Type
(Id
));
1758 end Is_Task_Record_Type
;
1760 ------------------------
1761 -- Is_Wrapper_Package --
1762 ------------------------
1764 function Is_Wrapper_Package
(Id
: E
) return B
is
1766 return Ekind
(Id
) = E_Package
and then Present
(Related_Instance
(Id
));
1767 end Is_Wrapper_Package
;
1773 function Last_Formal
(Id
: E
) return Entity_Id
is
1778 (Is_Overloadable
(Id
)
1779 or else Ekind
(Id
) in E_Entry_Family
1781 | E_Subprogram_Type
);
1783 if Ekind
(Id
) = E_Enumeration_Literal
then
1787 Formal
:= First_Formal
(Id
);
1789 if Present
(Formal
) then
1790 while Present
(Next_Formal
(Formal
)) loop
1791 Next_Formal
(Formal
);
1803 procedure Link_Entities
(First
, Second
: Entity_Id
) is
1805 if Present
(Second
) then
1806 Set_Prev_Entity
(Second
, First
); -- First <-- Second
1809 Set_Next_Entity
(First
, Second
); -- First --> Second
1812 ------------------------
1813 -- Machine_Emax_Value --
1814 ------------------------
1816 function Machine_Emax_Value
(Id
: E
) return Uint
is
1817 Digs
: constant Pos
:= UI_To_Int
(Digits_Value
(Base_Type
(Id
)));
1820 case Float_Rep
(Id
) is
1823 when 1 .. 6 => return Uint_128
;
1824 when 7 .. 15 => return 2**10;
1825 when 16 .. 33 => return 2**14;
1826 when others => return No_Uint
;
1829 end Machine_Emax_Value
;
1831 ------------------------
1832 -- Machine_Emin_Value --
1833 ------------------------
1835 function Machine_Emin_Value
(Id
: E
) return Uint
is
1837 case Float_Rep
(Id
) is
1838 when IEEE_Binary
=> return Uint_3
- Machine_Emax_Value
(Id
);
1840 end Machine_Emin_Value
;
1842 ----------------------------
1843 -- Machine_Mantissa_Value --
1844 ----------------------------
1846 function Machine_Mantissa_Value
(Id
: E
) return Uint
is
1847 Digs
: constant Pos
:= UI_To_Int
(Digits_Value
(Base_Type
(Id
)));
1850 case Float_Rep
(Id
) is
1853 when 1 .. 6 => return Uint_24
;
1854 when 7 .. 15 => return UI_From_Int
(53);
1855 when 16 .. 18 => return Uint_64
;
1856 when 19 .. 33 => return UI_From_Int
(113);
1857 when others => return No_Uint
;
1860 end Machine_Mantissa_Value
;
1862 -------------------------
1863 -- Machine_Radix_Value --
1864 -------------------------
1866 function Machine_Radix_Value
(Id
: E
) return U
is
1868 case Float_Rep
(Id
) is
1872 end Machine_Radix_Value
;
1874 ----------------------
1875 -- Model_Emin_Value --
1876 ----------------------
1878 function Model_Emin_Value
(Id
: E
) return Uint
is
1880 return Machine_Emin_Value
(Id
);
1881 end Model_Emin_Value
;
1883 -------------------------
1884 -- Model_Epsilon_Value --
1885 -------------------------
1887 function Model_Epsilon_Value
(Id
: E
) return Ureal
is
1888 Radix
: constant Ureal
:= UR_From_Uint
(Machine_Radix_Value
(Id
));
1890 return Radix
** (1 - Model_Mantissa_Value
(Id
));
1891 end Model_Epsilon_Value
;
1893 --------------------------
1894 -- Model_Mantissa_Value --
1895 --------------------------
1897 function Model_Mantissa_Value
(Id
: E
) return Uint
is
1899 return Machine_Mantissa_Value
(Id
);
1900 end Model_Mantissa_Value
;
1902 -----------------------
1903 -- Model_Small_Value --
1904 -----------------------
1906 function Model_Small_Value
(Id
: E
) return Ureal
is
1907 Radix
: constant Ureal
:= UR_From_Uint
(Machine_Radix_Value
(Id
));
1909 return Radix
** (Model_Emin_Value
(Id
) - 1);
1910 end Model_Small_Value
;
1912 --------------------
1913 -- Next_Component --
1914 --------------------
1916 function Next_Component
(Id
: E
) return Entity_Id
is
1917 Comp_Id
: Entity_Id
;
1920 Comp_Id
:= Next_Entity
(Id
);
1921 while Present
(Comp_Id
) loop
1922 exit when Ekind
(Comp_Id
) = E_Component
;
1923 Next_Entity
(Comp_Id
);
1929 ------------------------------------
1930 -- Next_Component_Or_Discriminant --
1931 ------------------------------------
1933 function Next_Component_Or_Discriminant
(Id
: E
) return Entity_Id
is
1934 Comp_Id
: Entity_Id
;
1937 Comp_Id
:= Next_Entity
(Id
);
1938 while Present
(Comp_Id
) loop
1939 exit when Ekind
(Comp_Id
) in E_Component | E_Discriminant
;
1940 Next_Entity
(Comp_Id
);
1944 end Next_Component_Or_Discriminant
;
1946 -----------------------
1947 -- Next_Discriminant --
1948 -----------------------
1950 -- This function actually implements both Next_Discriminant and
1951 -- Next_Stored_Discriminant by making sure that the Discriminant
1952 -- returned is of the same variety as Id.
1954 function Next_Discriminant
(Id
: E
) return Entity_Id
is
1956 -- Derived Tagged types with private extensions look like this...
1958 -- E_Discriminant d1
1959 -- E_Discriminant d2
1961 -- E_Discriminant d1
1962 -- E_Discriminant d2
1965 -- so it is critical not to go past the leading discriminants
1967 D
: Entity_Id
:= Id
;
1970 pragma Assert
(Ekind
(Id
) = E_Discriminant
);
1975 or else (Ekind
(D
) /= E_Discriminant
1976 and then not Is_Itype
(D
))
1981 exit when Ekind
(D
) = E_Discriminant
1982 and then Is_Completely_Hidden
(D
) = Is_Completely_Hidden
(Id
);
1986 end Next_Discriminant
;
1992 function Next_Formal
(Id
: E
) return Entity_Id
is
1996 -- Follow the chain of declared entities as long as the kind of the
1997 -- entity corresponds to a formal parameter. Skip internal entities
1998 -- that may have been created for implicit subtypes, in the process
1999 -- of analyzing default expressions.
2005 if No
(P
) or else Is_Formal
(P
) then
2007 elsif not Is_Internal
(P
) then
2013 -----------------------------
2014 -- Next_Formal_With_Extras --
2015 -----------------------------
2017 function Next_Formal_With_Extras
(Id
: E
) return Entity_Id
is
2019 if Present
(Extra_Formal
(Id
)) then
2020 return Extra_Formal
(Id
);
2022 return Next_Formal
(Id
);
2024 end Next_Formal_With_Extras
;
2030 function Next_Index
(Id
: N
) return Node_Id
is
2031 pragma Assert
(Nkind
(Id
) in N_Is_Index
);
2032 Result
: constant Node_Id
:= Next
(Id
);
2033 pragma Assert
(No
(Result
) or else Nkind
(Result
) in N_Is_Index
);
2042 function Next_Literal
(Id
: E
) return Entity_Id
is
2044 pragma Assert
(Nkind
(Id
) in N_Entity
);
2048 ------------------------------
2049 -- Next_Stored_Discriminant --
2050 ------------------------------
2052 function Next_Stored_Discriminant
(Id
: E
) return Entity_Id
is
2054 -- See comment in Next_Discriminant
2056 return Next_Discriminant
(Id
);
2057 end Next_Stored_Discriminant
;
2059 -----------------------
2060 -- Number_Dimensions --
2061 -----------------------
2063 function Number_Dimensions
(Id
: E
) return Pos
is
2068 if Ekind
(Id
) = E_String_Literal_Subtype
then
2073 T
:= First_Index
(Id
);
2074 while Present
(T
) loop
2081 end Number_Dimensions
;
2083 --------------------
2084 -- Number_Entries --
2085 --------------------
2087 function Number_Entries
(Id
: E
) return Nat
is
2092 pragma Assert
(Is_Concurrent_Type
(Id
));
2095 Ent
:= First_Entity
(Id
);
2096 while Present
(Ent
) loop
2097 if Is_Entry
(Ent
) then
2107 --------------------
2108 -- Number_Formals --
2109 --------------------
2111 function Number_Formals
(Id
: E
) return Nat
is
2117 Formal
:= First_Formal
(Id
);
2118 while Present
(Formal
) loop
2120 Next_Formal
(Formal
);
2126 ------------------------
2127 -- Object_Size_Clause --
2128 ------------------------
2130 function Object_Size_Clause
(Id
: E
) return Node_Id
is
2132 return Get_Attribute_Definition_Clause
(Id
, Attribute_Object_Size
);
2133 end Object_Size_Clause
;
2135 --------------------
2136 -- Parameter_Mode --
2137 --------------------
2139 function Parameter_Mode
(Id
: E
) return Formal_Kind
is
2148 function DIC_Procedure
(Id
: E
) return Entity_Id
is
2149 Subp_Elmt
: Elmt_Id
;
2150 Subp_Id
: Entity_Id
;
2154 pragma Assert
(Is_Type
(Id
));
2156 Subps
:= Subprograms_For_Type
(Base_Type
(Id
));
2158 if Present
(Subps
) then
2159 Subp_Elmt
:= First_Elmt
(Subps
);
2160 while Present
(Subp_Elmt
) loop
2161 Subp_Id
:= Node
(Subp_Elmt
);
2163 -- Currently the flag Is_DIC_Procedure is set for both normal DIC
2164 -- check procedures as well as for partial DIC check procedures,
2165 -- and we don't have a flag for the partial procedures.
2167 if Is_DIC_Procedure
(Subp_Id
)
2168 and then not Is_Partial_DIC_Procedure
(Subp_Id
)
2173 Next_Elmt
(Subp_Elmt
);
2180 function Partial_DIC_Procedure
(Id
: E
) return Entity_Id
is
2181 Subp_Elmt
: Elmt_Id
;
2182 Subp_Id
: Entity_Id
;
2186 pragma Assert
(Is_Type
(Id
));
2188 Subps
:= Subprograms_For_Type
(Base_Type
(Id
));
2190 if Present
(Subps
) then
2191 Subp_Elmt
:= First_Elmt
(Subps
);
2192 while Present
(Subp_Elmt
) loop
2193 Subp_Id
:= Node
(Subp_Elmt
);
2195 if Is_Partial_DIC_Procedure
(Subp_Id
) then
2199 Next_Elmt
(Subp_Elmt
);
2204 end Partial_DIC_Procedure
;
2206 function Is_Partial_DIC_Procedure
(Id
: E
) return B
is
2207 Partial_DIC_Suffix
: constant String := "Partial_DIC";
2208 DIC_Nam
: constant String := Get_Name_String
(Chars
(Id
));
2211 pragma Assert
(Ekind
(Id
) in E_Function | E_Procedure
);
2213 -- Instead of adding a new Entity_Id flag (which are in short supply),
2214 -- we test the form of the subprogram name. When the node field and flag
2215 -- situation is eased, this should be replaced with a flag. ???
2217 if DIC_Nam
'Length > Partial_DIC_Suffix
'Length
2220 (DIC_Nam
'Last - Partial_DIC_Suffix
'Length + 1 .. DIC_Nam
'Last) =
2227 end Is_Partial_DIC_Procedure
;
2229 ---------------------------------
2230 -- Partial_Invariant_Procedure --
2231 ---------------------------------
2233 function Partial_Invariant_Procedure
(Id
: E
) return Entity_Id
is
2234 Subp_Elmt
: Elmt_Id
;
2235 Subp_Id
: Entity_Id
;
2239 pragma Assert
(Is_Type
(Id
));
2241 Subps
:= Subprograms_For_Type
(Base_Type
(Id
));
2243 if Present
(Subps
) then
2244 Subp_Elmt
:= First_Elmt
(Subps
);
2245 while Present
(Subp_Elmt
) loop
2246 Subp_Id
:= Node
(Subp_Elmt
);
2248 if Is_Partial_Invariant_Procedure
(Subp_Id
) then
2252 Next_Elmt
(Subp_Elmt
);
2257 end Partial_Invariant_Procedure
;
2259 -------------------------------------
2260 -- Partial_Refinement_Constituents --
2261 -------------------------------------
2263 function Partial_Refinement_Constituents
(Id
: E
) return L
is
2264 Constits
: Elist_Id
:= No_Elist
;
2266 procedure Add_Usable_Constituents
(Item
: E
);
2267 -- Add global item Item and/or its constituents to list Constits when
2268 -- they can be used in a global refinement within the current scope. The
2270 -- 1) If Item is an abstract state with full refinement visible, add
2271 -- its constituents.
2272 -- 2) If Item is an abstract state with only partial refinement
2273 -- visible, add both Item and its constituents.
2274 -- 3) If Item is an abstract state without a visible refinement, add
2276 -- 4) If Id is not an abstract state, add it.
2278 procedure Add_Usable_Constituents
(List
: Elist_Id
);
2279 -- Apply Add_Usable_Constituents to every constituent in List
2281 -----------------------------
2282 -- Add_Usable_Constituents --
2283 -----------------------------
2285 procedure Add_Usable_Constituents
(Item
: E
) is
2287 if Ekind
(Item
) = E_Abstract_State
then
2288 if Has_Visible_Refinement
(Item
) then
2289 Add_Usable_Constituents
(Refinement_Constituents
(Item
));
2291 elsif Has_Partial_Visible_Refinement
(Item
) then
2292 Append_New_Elmt
(Item
, Constits
);
2293 Add_Usable_Constituents
(Part_Of_Constituents
(Item
));
2296 Append_New_Elmt
(Item
, Constits
);
2300 Append_New_Elmt
(Item
, Constits
);
2302 end Add_Usable_Constituents
;
2304 procedure Add_Usable_Constituents
(List
: Elist_Id
) is
2305 Constit_Elmt
: Elmt_Id
;
2307 if Present
(List
) then
2308 Constit_Elmt
:= First_Elmt
(List
);
2309 while Present
(Constit_Elmt
) loop
2310 Add_Usable_Constituents
(Node
(Constit_Elmt
));
2311 Next_Elmt
(Constit_Elmt
);
2314 end Add_Usable_Constituents
;
2316 -- Start of processing for Partial_Refinement_Constituents
2319 -- "Refinement" is a concept applicable only to abstract states
2321 pragma Assert
(Ekind
(Id
) = E_Abstract_State
);
2323 if Has_Visible_Refinement
(Id
) then
2324 Constits
:= Refinement_Constituents
(Id
);
2326 -- A refinement may be partially visible when objects declared in the
2327 -- private part of a package are subject to a Part_Of indicator.
2329 elsif Has_Partial_Visible_Refinement
(Id
) then
2330 Add_Usable_Constituents
(Part_Of_Constituents
(Id
));
2332 -- Function should only be called when full or partial refinement is
2336 raise Program_Error
;
2340 end Partial_Refinement_Constituents
;
2342 ------------------------
2343 -- Predicate_Function --
2344 ------------------------
2346 function Predicate_Function
(Id
: E
) return Entity_Id
is
2347 Subp_Elmt
: Elmt_Id
;
2348 Subp_Id
: Entity_Id
;
2353 pragma Assert
(Is_Type
(Id
));
2355 -- If type is private and has a completion, predicate may be defined on
2358 if Is_Private_Type
(Id
)
2360 (not Has_Predicates
(Id
) or else No
(Subprograms_For_Type
(Id
)))
2361 and then Present
(Full_View
(Id
))
2363 Typ
:= Full_View
(Id
);
2365 elsif Ekind
(Id
) in E_Array_Subtype
2367 | E_Record_Subtype_With_Private
2368 and then Present
(Predicated_Parent
(Id
))
2370 Typ
:= Predicated_Parent
(Id
);
2376 Subps
:= Subprograms_For_Type
(Typ
);
2378 if Present
(Subps
) then
2379 Subp_Elmt
:= First_Elmt
(Subps
);
2380 while Present
(Subp_Elmt
) loop
2381 Subp_Id
:= Node
(Subp_Elmt
);
2383 if Ekind
(Subp_Id
) = E_Function
2384 and then Is_Predicate_Function
(Subp_Id
)
2389 Next_Elmt
(Subp_Elmt
);
2394 end Predicate_Function
;
2396 -------------------------
2397 -- Present_In_Rep_Item --
2398 -------------------------
2400 function Present_In_Rep_Item
(E
: Entity_Id
; N
: Node_Id
) return Boolean is
2404 Ritem
:= First_Rep_Item
(E
);
2406 while Present
(Ritem
) loop
2411 Next_Rep_Item
(Ritem
);
2415 end Present_In_Rep_Item
;
2417 --------------------------
2418 -- Primitive_Operations --
2419 --------------------------
2421 function Primitive_Operations
(Id
: E
) return L
is
2423 if Is_Concurrent_Type
(Id
) then
2424 if Present
(Corresponding_Record_Type
(Id
)) then
2426 Direct_Primitive_Operations
(Corresponding_Record_Type
(Id
));
2428 -- When expansion is disabled, the corresponding record type is
2429 -- absent, but if this is a tagged type with ancestors, or if the
2430 -- extension of prefixed calls for untagged types is enabled, then
2431 -- it may have associated primitive operations.
2434 return Direct_Primitive_Operations
(Id
);
2438 return Direct_Primitive_Operations
(Id
);
2440 end Primitive_Operations
;
2442 ---------------------
2443 -- Record_Rep_Item --
2444 ---------------------
2446 procedure Record_Rep_Item
(E
: Entity_Id
; N
: Node_Id
) is
2448 Set_Next_Rep_Item
(N
, First_Rep_Item
(E
));
2449 Set_First_Rep_Item
(E
, N
);
2450 end Record_Rep_Item
;
2456 procedure Remove_Entity
(Id
: Entity_Id
) is
2457 Next
: constant Entity_Id
:= Next_Entity
(Id
);
2458 Prev
: constant Entity_Id
:= Prev_Entity
(Id
);
2459 Scop
: constant Entity_Id
:= Scope
(Id
);
2460 First
: constant Entity_Id
:= First_Entity
(Scop
);
2461 Last
: constant Entity_Id
:= Last_Entity
(Scop
);
2464 -- Eliminate any existing linkages from the entity
2466 Set_Prev_Entity
(Id
, Empty
); -- Empty <-- Id
2467 Set_Next_Entity
(Id
, Empty
); -- Id --> Empty
2469 -- The eliminated entity was the only element in the entity chain
2471 if Id
= First
and then Id
= Last
then
2472 Set_First_Entity
(Scop
, Empty
);
2473 Set_Last_Entity
(Scop
, Empty
);
2475 -- The eliminated entity was the head of the entity chain
2477 elsif Id
= First
then
2478 Set_First_Entity
(Scop
, Next
);
2479 Set_Prev_Entity
(Next
, Empty
); -- Empty <-- First_Entity
2481 -- The eliminated entity was the tail of the entity chain
2483 elsif Id
= Last
then
2484 Set_Last_Entity
(Scop
, Prev
);
2485 Set_Next_Entity
(Prev
, Empty
); -- Last_Entity --> Empty
2487 -- Otherwise the eliminated entity comes from the middle of the entity
2491 Link_Entities
(Prev
, Next
); -- Prev <-- Next, Prev --> Next
2499 function Root_Type
(Id
: E
) return E
is
2500 T
, Etyp
: Entity_Id
;
2503 pragma Assert
(Nkind
(Id
) in N_Entity
);
2505 T
:= Base_Type
(Id
);
2507 if Ekind
(T
) = E_Class_Wide_Type
then
2519 -- Following test catches some error cases resulting from
2522 elsif No
(Etyp
) then
2523 Check_Error_Detected
;
2526 elsif Is_Private_Type
(T
) and then Etyp
= Full_View
(T
) then
2529 elsif Is_Private_Type
(Etyp
) and then Full_View
(Etyp
) = T
then
2535 -- Return if there is a circularity in the inheritance chain. This
2536 -- happens in some error situations and we do not want to get
2537 -- stuck in this loop.
2539 if T
= Base_Type
(Id
) then
2546 ---------------------
2547 -- Safe_Emax_Value --
2548 ---------------------
2550 function Safe_Emax_Value
(Id
: E
) return Uint
is
2552 return Machine_Emax_Value
(Id
);
2553 end Safe_Emax_Value
;
2555 ----------------------
2556 -- Safe_First_Value --
2557 ----------------------
2559 function Safe_First_Value
(Id
: E
) return Ureal
is
2561 return -Safe_Last_Value
(Id
);
2562 end Safe_First_Value
;
2564 ---------------------
2565 -- Safe_Last_Value --
2566 ---------------------
2568 function Safe_Last_Value
(Id
: E
) return Ureal
is
2569 Radix
: constant Uint
:= Machine_Radix_Value
(Id
);
2570 Mantissa
: constant Uint
:= Machine_Mantissa_Value
(Id
);
2571 Emax
: constant Uint
:= Safe_Emax_Value
(Id
);
2572 Significand
: constant Uint
:= Radix
** Mantissa
- 1;
2573 Exponent
: constant Uint
:= Emax
- Mantissa
;
2579 (Num
=> Significand
* 2 ** (Exponent
mod 4),
2580 Den
=> -Exponent
/ 4,
2585 (Num
=> Significand
,
2589 end Safe_Last_Value
;
2595 function Scope_Depth
(Id
: Scope_Kind_Id
) return Uint
is
2600 while Is_Record_Type
(Scop
) loop
2601 Scop
:= Scope
(Scop
);
2604 return Scope_Depth_Value
(Scop
);
2607 function Scope_Depth_Default_0
(Id
: Scope_Kind_Id
) return U
is
2609 if Scope_Depth_Set
(Id
) then
2610 return Scope_Depth
(Id
);
2615 end Scope_Depth_Default_0
;
2617 ---------------------
2618 -- Scope_Depth_Set --
2619 ---------------------
2621 function Scope_Depth_Set
(Id
: Scope_Kind_Id
) return B
is
2623 return not Is_Record_Type
(Id
)
2624 and then not Field_Is_Initial_Zero
(Id
, F_Scope_Depth_Value
);
2625 -- We can't call Scope_Depth_Value here, because Empty is not a valid
2626 -- value of type Uint.
2627 end Scope_Depth_Set
;
2629 --------------------
2630 -- Set_Convention --
2631 --------------------
2633 procedure Set_Convention
(E
: Entity_Id
; Val
: Snames
.Convention_Id
) is
2635 Set_Basic_Convention
(E
, Val
);
2637 if Ekind
(E
) in Access_Subprogram_Kind
2638 and then Has_Foreign_Convention
(E
)
2640 Set_Can_Use_Internal_Rep
(E
, False);
2643 -- If E is an object, including a component, and the type of E is an
2644 -- anonymous access type with no convention set, then also set the
2645 -- convention of the anonymous access type. We do not do this for
2646 -- anonymous protected types, since protected types always have the
2647 -- default convention.
2649 if Present
(Etype
(E
))
2650 and then (Is_Object
(E
)
2652 -- Allow E_Void (happens for pragma Convention appearing
2653 -- in the middle of a record applying to a component)
2655 or else Ekind
(E
) = E_Void
)
2658 Typ
: constant Entity_Id
:= Etype
(E
);
2661 if Ekind
(Typ
) in E_Anonymous_Access_Type
2662 | E_Anonymous_Access_Subprogram_Type
2663 and then not Has_Convention_Pragma
(Typ
)
2665 Set_Convention
(Typ
, Val
);
2666 Set_Has_Convention_Pragma
(Typ
);
2668 -- And for the access subprogram type, deal similarly with the
2669 -- designated E_Subprogram_Type, which is always internal.
2671 if Ekind
(Typ
) = E_Anonymous_Access_Subprogram_Type
then
2673 Dtype
: constant Entity_Id
:= Designated_Type
(Typ
);
2675 if Ekind
(Dtype
) = E_Subprogram_Type
then
2676 pragma Assert
(not Has_Convention_Pragma
(Dtype
));
2677 Set_Convention
(Dtype
, Val
);
2678 Set_Has_Convention_Pragma
(Dtype
);
2687 -----------------------
2688 -- Set_DIC_Procedure --
2689 -----------------------
2691 procedure Set_DIC_Procedure
(Id
: E
; V
: E
) is
2692 Base_Typ
: Entity_Id
;
2696 pragma Assert
(Is_Type
(Id
));
2698 Base_Typ
:= Base_Type
(Id
);
2699 Subps
:= Subprograms_For_Type
(Base_Typ
);
2702 Subps
:= New_Elmt_List
;
2703 Set_Subprograms_For_Type
(Base_Typ
, Subps
);
2706 Prepend_Elmt
(V
, Subps
);
2707 end Set_DIC_Procedure
;
2709 procedure Set_Partial_DIC_Procedure
(Id
: E
; V
: E
) is
2711 Set_DIC_Procedure
(Id
, V
);
2712 end Set_Partial_DIC_Procedure
;
2718 procedure Set_Float_Rep
2719 (Ignore_N
: Entity_Id
; Ignore_Val
: Float_Rep_Kind
) is
2721 pragma Assert
(Float_Rep_Kind
'First = Float_Rep_Kind
'Last);
2722 -- There is only one value, so we don't need to store it (see
2726 -----------------------------
2727 -- Set_Invariant_Procedure --
2728 -----------------------------
2730 procedure Set_Invariant_Procedure
(Id
: E
; V
: E
) is
2731 Base_Typ
: Entity_Id
;
2732 Subp_Elmt
: Elmt_Id
;
2733 Subp_Id
: Entity_Id
;
2737 pragma Assert
(Is_Type
(Id
));
2739 Base_Typ
:= Base_Type
(Id
);
2740 Subps
:= Subprograms_For_Type
(Base_Typ
);
2743 Subps
:= New_Elmt_List
;
2744 Set_Subprograms_For_Type
(Base_Typ
, Subps
);
2747 Subp_Elmt
:= First_Elmt
(Subps
);
2748 Prepend_Elmt
(V
, Subps
);
2750 -- Check for a duplicate invariant procedure
2752 while Present
(Subp_Elmt
) loop
2753 Subp_Id
:= Node
(Subp_Elmt
);
2755 if Is_Invariant_Procedure
(Subp_Id
) then
2756 raise Program_Error
;
2759 Next_Elmt
(Subp_Elmt
);
2761 end Set_Invariant_Procedure
;
2763 -------------------------------------
2764 -- Set_Partial_Invariant_Procedure --
2765 -------------------------------------
2767 procedure Set_Partial_Invariant_Procedure
(Id
: E
; V
: E
) is
2768 Base_Typ
: Entity_Id
;
2769 Subp_Elmt
: Elmt_Id
;
2770 Subp_Id
: Entity_Id
;
2774 pragma Assert
(Is_Type
(Id
));
2776 Base_Typ
:= Base_Type
(Id
);
2777 Subps
:= Subprograms_For_Type
(Base_Typ
);
2780 Subps
:= New_Elmt_List
;
2781 Set_Subprograms_For_Type
(Base_Typ
, Subps
);
2784 Subp_Elmt
:= First_Elmt
(Subps
);
2785 Prepend_Elmt
(V
, Subps
);
2787 -- Check for a duplicate partial invariant procedure
2789 while Present
(Subp_Elmt
) loop
2790 Subp_Id
:= Node
(Subp_Elmt
);
2792 if Is_Partial_Invariant_Procedure
(Subp_Id
) then
2793 raise Program_Error
;
2796 Next_Elmt
(Subp_Elmt
);
2798 end Set_Partial_Invariant_Procedure
;
2800 ----------------------------
2801 -- Set_Predicate_Function --
2802 ----------------------------
2804 procedure Set_Predicate_Function
(Id
: E
; V
: E
) is
2805 Subp_Elmt
: Elmt_Id
;
2806 Subp_Id
: Entity_Id
;
2810 pragma Assert
(Is_Type
(Id
) and then Has_Predicates
(Id
));
2812 Subps
:= Subprograms_For_Type
(Id
);
2815 Subps
:= New_Elmt_List
;
2816 Set_Subprograms_For_Type
(Id
, Subps
);
2819 Subp_Elmt
:= First_Elmt
(Subps
);
2820 Prepend_Elmt
(V
, Subps
);
2822 -- Check for a duplicate predication function
2824 while Present
(Subp_Elmt
) loop
2825 Subp_Id
:= Node
(Subp_Elmt
);
2827 if Ekind
(Subp_Id
) = E_Function
2828 and then Is_Predicate_Function
(Subp_Id
)
2830 raise Program_Error
;
2833 Next_Elmt
(Subp_Elmt
);
2835 end Set_Predicate_Function
;
2841 function Size_Clause
(Id
: E
) return Node_Id
is
2842 Result
: Node_Id
:= Get_Attribute_Definition_Clause
(Id
, Attribute_Size
);
2845 Result
:= Get_Attribute_Definition_Clause
(Id
, Attribute_Value_Size
);
2851 ------------------------
2852 -- Stream_Size_Clause --
2853 ------------------------
2855 function Stream_Size_Clause
(Id
: E
) return N
is
2857 return Get_Attribute_Definition_Clause
(Id
, Attribute_Stream_Size
);
2858 end Stream_Size_Clause
;
2864 function Subtype_Kind
(K
: Entity_Kind
) return Entity_Kind
is
2870 Kind
:= E_Access_Subtype
;
2872 when E_Array_Subtype
2875 Kind
:= E_Array_Subtype
;
2877 when E_Class_Wide_Subtype
2880 Kind
:= E_Class_Wide_Subtype
;
2882 when E_Decimal_Fixed_Point_Subtype
2883 | E_Decimal_Fixed_Point_Type
2885 Kind
:= E_Decimal_Fixed_Point_Subtype
;
2887 when E_Ordinary_Fixed_Point_Subtype
2888 | E_Ordinary_Fixed_Point_Type
2890 Kind
:= E_Ordinary_Fixed_Point_Subtype
;
2892 when E_Private_Subtype
2895 Kind
:= E_Private_Subtype
;
2897 when E_Limited_Private_Subtype
2898 | E_Limited_Private_Type
2900 Kind
:= E_Limited_Private_Subtype
;
2902 when E_Record_Subtype_With_Private
2903 | E_Record_Type_With_Private
2905 Kind
:= E_Record_Subtype_With_Private
;
2907 when E_Record_Subtype
2910 Kind
:= E_Record_Subtype
;
2912 when Enumeration_Kind
=>
2913 Kind
:= E_Enumeration_Subtype
;
2915 when E_Incomplete_Type
=>
2916 Kind
:= E_Incomplete_Subtype
;
2919 Kind
:= E_Floating_Point_Subtype
;
2921 when Signed_Integer_Kind
=>
2922 Kind
:= E_Signed_Integer_Subtype
;
2924 when Modular_Integer_Kind
=>
2925 Kind
:= E_Modular_Integer_Subtype
;
2927 when Protected_Kind
=>
2928 Kind
:= E_Protected_Subtype
;
2931 Kind
:= E_Task_Subtype
;
2934 raise Program_Error
;
2940 ---------------------
2941 -- Type_High_Bound --
2942 ---------------------
2944 function Type_High_Bound
(Id
: E
) return N
is
2945 Rng
: constant Node_Id
:= Scalar_Range
(Id
);
2947 if Nkind
(Rng
) = N_Subtype_Indication
then
2948 return High_Bound
(Range_Expression
(Constraint
(Rng
)));
2950 return High_Bound
(Rng
);
2952 end Type_High_Bound
;
2954 --------------------
2955 -- Type_Low_Bound --
2956 --------------------
2958 function Type_Low_Bound
(Id
: E
) return N
is
2959 Rng
: constant Node_Id
:= Scalar_Range
(Id
);
2961 if Nkind
(Rng
) = N_Subtype_Indication
then
2962 return Low_Bound
(Range_Expression
(Constraint
(Rng
)));
2964 return Low_Bound
(Rng
);
2968 ---------------------
2969 -- Underlying_Type --
2970 ---------------------
2972 function Underlying_Type
(Id
: E
) return Entity_Id
is
2974 -- For record_with_private the underlying type is always the direct full
2975 -- view. Never try to take the full view of the parent it does not make
2978 if Ekind
(Id
) = E_Record_Type_With_Private
then
2979 return Full_View
(Id
);
2981 -- If we have a class-wide type that comes from the limited view then we
2982 -- return the Underlying_Type of its nonlimited view.
2984 elsif Ekind
(Id
) = E_Class_Wide_Type
2985 and then From_Limited_With
(Id
)
2986 and then Present
(Non_Limited_View
(Id
))
2988 return Underlying_Type
(Non_Limited_View
(Id
));
2990 elsif Ekind
(Id
) in Incomplete_Or_Private_Kind
then
2992 -- If we have an incomplete or private type with a full view, then we
2993 -- return the Underlying_Type of this full view.
2995 if Present
(Full_View
(Id
)) then
2996 if Id
= Full_View
(Id
) then
2998 -- Previous error in declaration
3003 return Underlying_Type
(Full_View
(Id
));
3006 -- If we have a private type with an underlying full view, then we
3007 -- return the Underlying_Type of this underlying full view.
3009 elsif Ekind
(Id
) in Private_Kind
3010 and then Present
(Underlying_Full_View
(Id
))
3012 return Underlying_Type
(Underlying_Full_View
(Id
));
3014 -- If we have an incomplete entity that comes from the limited view
3015 -- then we return the Underlying_Type of its nonlimited view.
3017 elsif From_Limited_With
(Id
)
3018 and then Present
(Non_Limited_View
(Id
))
3020 return Underlying_Type
(Non_Limited_View
(Id
));
3022 -- Otherwise check for the case where we have a derived type or
3023 -- subtype, and if so get the Underlying_Type of the parent type.
3025 elsif Present
(Etype
(Id
)) and then Etype
(Id
) /= Id
then
3026 return Underlying_Type
(Etype
(Id
));
3028 -- Otherwise we have an incomplete or private type that has no full
3029 -- view, which means that we have not encountered the completion, so
3030 -- return Empty to indicate the underlying type is not yet known.
3036 -- For non-incomplete, non-private types, return the type itself. Also
3037 -- for entities that are not types at all return the entity itself.
3042 end Underlying_Type
;
3044 ------------------------
3045 -- Unlink_Next_Entity --
3046 ------------------------
3048 procedure Unlink_Next_Entity
(Id
: Entity_Id
) is
3049 Next
: constant Entity_Id
:= Next_Entity
(Id
);
3052 if Present
(Next
) then
3053 Set_Prev_Entity
(Next
, Empty
); -- Empty <-- Next
3056 Set_Next_Entity
(Id
, Empty
); -- Id --> Empty
3057 end Unlink_Next_Entity
;
3059 ----------------------------------
3060 -- Is_Volatile, Set_Is_Volatile --
3061 ----------------------------------
3063 function Is_Volatile
(Id
: E
) return B
is
3065 pragma Assert
(Nkind
(Id
) in N_Entity
);
3067 if Is_Type
(Id
) then
3068 return Is_Volatile_Type
(Base_Type
(Id
));
3070 return Is_Volatile_Object
(Id
);
3074 procedure Set_Is_Volatile
(Id
: E
; V
: B
:= True) is
3076 pragma Assert
(Nkind
(Id
) in N_Entity
);
3078 if Is_Type
(Id
) then
3079 Set_Is_Volatile_Type
(Id
, V
);
3081 Set_Is_Volatile_Object
(Id
, V
);
3083 end Set_Is_Volatile
;
3085 -----------------------
3086 -- Write_Entity_Info --
3087 -----------------------
3089 procedure Write_Entity_Info
(Id
: Entity_Id
; Prefix
: String) is
3091 procedure Write_Attribute
(Which
: String; Nam
: E
);
3092 -- Write attribute value with given string name
3094 procedure Write_Kind
(Id
: Entity_Id
);
3095 -- Write Ekind field of entity
3097 ---------------------
3098 -- Write_Attribute --
3099 ---------------------
3101 procedure Write_Attribute
(Which
: String; Nam
: E
) is
3105 Write_Int
(Int
(Nam
));
3107 Write_Name
(Chars
(Nam
));
3109 end Write_Attribute
;
3115 procedure Write_Kind
(Id
: Entity_Id
) is
3116 K
: constant String := Entity_Kind
'Image (Ekind
(Id
));
3120 Write_Str
(" Kind ");
3122 if Is_Type
(Id
) and then Is_Tagged_Type
(Id
) then
3123 Write_Str
("TAGGED ");
3126 Write_Str
(K
(3 .. K
'Length));
3129 if Is_Type
(Id
) and then Depends_On_Private
(Id
) then
3130 Write_Str
("Depends_On_Private ");
3134 -- Start of processing for Write_Entity_Info
3138 Write_Attribute
("Name ", Id
);
3139 Write_Int
(Int
(Id
));
3143 Write_Attribute
(" Type ", Etype
(Id
));
3145 if Id
/= Standard_Standard
then
3146 Write_Attribute
(" Scope ", Scope
(Id
));
3151 when Discrete_Kind
=>
3152 Write_Str
("Bounds: Id = ");
3154 if Present
(Scalar_Range
(Id
)) then
3155 Write_Int
(Int
(Type_Low_Bound
(Id
)));
3156 Write_Str
(" .. Id = ");
3157 Write_Int
(Int
(Type_High_Bound
(Id
)));
3159 Write_Str
("Empty");
3170 (" Component Type ", Component_Type
(Id
));
3173 Write_Str
(" Indexes ");
3175 Index
:= First_Index
(Id
);
3176 while Present
(Index
) loop
3177 Write_Attribute
(" ", Etype
(Index
));
3186 (" Directly Designated Type ",
3187 Directly_Designated_Type
(Id
));
3190 when Overloadable_Kind
=>
3191 if Present
(Homonym
(Id
)) then
3192 Write_Str
(" Homonym ");
3193 Write_Name
(Chars
(Homonym
(Id
)));
3195 Write_Int
(Int
(Homonym
(Id
)));
3202 if Ekind
(Scope
(Id
)) in Record_Kind
then
3204 " Original_Record_Component ",
3205 Original_Record_Component
(Id
));
3206 Write_Int
(Int
(Original_Record_Component
(Id
)));
3213 end Write_Entity_Info
;
3215 -------------------------
3216 -- Iterator Procedures --
3217 -------------------------
3219 procedure Next_Component
(N
: in out Node_Id
) is
3221 N
:= Next_Component
(N
);
3224 procedure Next_Component_Or_Discriminant
(N
: in out Node_Id
) is
3226 N
:= Next_Component_Or_Discriminant
(N
);
3227 end Next_Component_Or_Discriminant
;
3229 procedure Next_Discriminant
(N
: in out Node_Id
) is
3231 N
:= Next_Discriminant
(N
);
3232 end Next_Discriminant
;
3234 procedure Next_Formal
(N
: in out Node_Id
) is
3236 N
:= Next_Formal
(N
);
3239 procedure Next_Formal_With_Extras
(N
: in out Node_Id
) is
3241 N
:= Next_Formal_With_Extras
(N
);
3242 end Next_Formal_With_Extras
;
3244 procedure Next_Index
(N
: in out Node_Id
) is
3246 N
:= Next_Index
(N
);
3249 procedure Next_Inlined_Subprogram
(N
: in out Node_Id
) is
3251 N
:= Next_Inlined_Subprogram
(N
);
3252 end Next_Inlined_Subprogram
;
3254 procedure Next_Literal
(N
: in out Node_Id
) is
3256 N
:= Next_Literal
(N
);
3259 procedure Next_Stored_Discriminant
(N
: in out Node_Id
) is
3261 N
:= Next_Stored_Discriminant
(N
);
3262 end Next_Stored_Discriminant
;