Debian Codegraph @

gcc/ada/einfo-utils.adb

raw
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- E I N F O . U T I L S --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 2020-2025, Free Software Foundation, Inc. --
10 -- --
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. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
25
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;
32
33 package body Einfo.Utils is
34
35 -----------------------
36 -- Local subprograms --
37 -----------------------
38
39 function Has_Option
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.
44
45 -------------------------------------------
46 -- Aliases/Renamings of Renamed_Or_Alias --
47 -------------------------------------------
48
49 function Alias (N : Entity_Id) return Entity_Id is
50 begin
51 return Val : constant Entity_Id := Renamed_Or_Alias (N) do
52 pragma Assert
53 (Is_Overloadable (N) or else Ekind (N) = E_Subprogram_Type);
54 pragma Assert (Val in N_Entity_Id | N_Empty_Id);
55 end return;
56 end Alias;
57
58 procedure Set_Alias (N : Entity_Id; Val : Entity_Id) is
59 begin
60 pragma Assert
61 (Is_Overloadable (N) or else Ekind (N) = E_Subprogram_Type);
62 pragma Assert (Val in N_Entity_Id | N_Empty_Id);
63
64 Set_Renamed_Or_Alias (N, Val);
65 end Set_Alias;
66
67 function Renamed_Entity (N : Entity_Id) return Entity_Id is
68 begin
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);
72 end return;
73 end Renamed_Entity;
74
75 procedure Set_Renamed_Entity (N : Entity_Id; Val : Entity_Id) is
76 begin
77 pragma Assert (not Is_Object (N));
78 pragma Assert (Val in N_Entity_Id);
79
80 Set_Renamed_Or_Alias (N, Val);
81 end Set_Renamed_Entity;
82
83 function Renamed_Object (N : Entity_Id) return Node_Id is
84 begin
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.
89
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);
93 null;
94 end if;
95 end return;
96 end Renamed_Object;
97
98 procedure Set_Renamed_Object (N : Entity_Id; Val : Node_Id) is
99 begin
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);
103 null;
104 end if;
105
106 Set_Renamed_Or_Alias (N, Val);
107 end Set_Renamed_Object;
108
109 function Renamed_Entity_Or_Object (N : Entity_Id) return Node_Id is
110 begin
111 if Is_Object (N) then
112 return Renamed_Object (N);
113 else
114 return Renamed_Entity (N);
115 end if;
116 end Renamed_Entity_Or_Object;
117
118 procedure Set_Renamed_Object_Of_Possibly_Void
119 (N : Entity_Id; Val : Node_Id)
120 is
121 begin
122 pragma Assert (Val in N_Subexpr_Id);
123 Set_Renamed_Or_Alias (N, Val);
124 end Set_Renamed_Object_Of_Possibly_Void;
125
126 ----------------
127 -- Has_Option --
128 ----------------
129
130 function Has_Option
131 (State_Id : Entity_Id;
132 Option_Nam : Name_Id) return Boolean
133 is
134 Decl : constant Node_Id := Parent (State_Id);
135 Opt : Node_Id;
136 Opt_Nam : Node_Id;
137
138 begin
139 pragma Assert (Ekind (State_Id) = E_Abstract_State);
140
141 -- The declaration of abstract states with options appear as an
142 -- extension aggregate. If this is not the case, the option is not
143 -- available.
144
145 if Nkind (Decl) /= N_Extension_Aggregate then
146 return False;
147 end if;
148
149 -- Simple options
150
151 Opt := First (Expressions (Decl));
152 while Present (Opt) loop
153 if Nkind (Opt) = N_Identifier and then Chars (Opt) = Option_Nam then
154 return True;
155 end if;
156
157 Next (Opt);
158 end loop;
159
160 -- Complex options with various specifiers
161
162 Opt := First (Component_Associations (Decl));
163 while Present (Opt) loop
164 Opt_Nam := First (Choices (Opt));
165
166 if Nkind (Opt_Nam) = N_Identifier
167 and then Chars (Opt_Nam) = Option_Nam
168 then
169 return True;
170 end if;
171
172 Next (Opt);
173 end loop;
174
175 return False;
176 end Has_Option;
177
178 ------------------------------
179 -- Classification Functions --
180 ------------------------------
181
182 function Is_Access_Object_Type (Id : E) return B is
183 begin
184 return Is_Access_Type (Id)
185 and then Ekind (Directly_Designated_Type (Id)) /= E_Subprogram_Type;
186 end Is_Access_Object_Type;
187
188 function Is_Access_Type (Id : E) return B is
189 begin
190 return Ekind (Id) in Access_Kind;
191 end Is_Access_Type;
192
193 function Is_Access_Protected_Subprogram_Type (Id : E) return B is
194 begin
195 return Ekind (Id) in Access_Protected_Kind;
196 end Is_Access_Protected_Subprogram_Type;
197
198 function Is_Access_Subprogram_Type (Id : E) return B is
199 begin
200 return Is_Access_Type (Id)
201 and then Ekind (Directly_Designated_Type (Id)) = E_Subprogram_Type;
202 end Is_Access_Subprogram_Type;
203
204 function Is_Address_Compatible_Type (Id : E) return B is
205 begin
206 return Is_Descendant_Of_Address (Id) or else Id = Standard_Address;
207 end Is_Address_Compatible_Type;
208
209 function Is_Aggregate_Type (Id : E) return B is
210 begin
211 return Ekind (Id) in Aggregate_Kind;
212 end Is_Aggregate_Type;
213
214 function Is_Anonymous_Access_Type (Id : E) return B is
215 begin
216 return Ekind (Id) in Anonymous_Access_Kind;
217 end Is_Anonymous_Access_Type;
218
219 function Is_Array_Type (Id : E) return B is
220 begin
221 return Ekind (Id) in Array_Kind;
222 end Is_Array_Type;
223
224 function Is_Assignable (Id : E) return B is
225 begin
226 return Ekind (Id) in Assignable_Kind;
227 end Is_Assignable;
228
229 function Is_Class_Wide_Type (Id : E) return B is
230 begin
231 return Ekind (Id) in Class_Wide_Kind;
232 end Is_Class_Wide_Type;
233
234 function Is_Composite_Type (Id : E) return B is
235 begin
236 return Ekind (Id) in Composite_Kind;
237 end Is_Composite_Type;
238
239 function Is_Concurrent_Body (Id : E) return B is
240 begin
241 return Ekind (Id) in Concurrent_Body_Kind;
242 end Is_Concurrent_Body;
243
244 function Is_Concurrent_Type (Id : E) return B is
245 begin
246 return Ekind (Id) in Concurrent_Kind;
247 end Is_Concurrent_Type;
248
249 function Is_Decimal_Fixed_Point_Type (Id : E) return B is
250 begin
251 return Ekind (Id) in Decimal_Fixed_Point_Kind;
252 end Is_Decimal_Fixed_Point_Type;
253
254 function Is_Digits_Type (Id : E) return B is
255 begin
256 return Ekind (Id) in Digits_Kind;
257 end Is_Digits_Type;
258
259 function Is_Discrete_Or_Fixed_Point_Type (Id : E) return B is
260 begin
261 return Ekind (Id) in Discrete_Or_Fixed_Point_Kind;
262 end Is_Discrete_Or_Fixed_Point_Type;
263
264 function Is_Discrete_Type (Id : E) return B is
265 begin
266 return Ekind (Id) in Discrete_Kind;
267 end Is_Discrete_Type;
268
269 function Is_Elementary_Type (Id : E) return B is
270 begin
271 return Ekind (Id) in Elementary_Kind;
272 end Is_Elementary_Type;
273
274 function Is_Entry (Id : E) return B is
275 begin
276 return Ekind (Id) in Entry_Kind;
277 end Is_Entry;
278
279 function Is_Enumeration_Type (Id : E) return B is
280 begin
281 return Ekind (Id) in Enumeration_Kind;
282 end Is_Enumeration_Type;
283
284 function Is_Fixed_Point_Type (Id : E) return B is
285 begin
286 return Ekind (Id) in Fixed_Point_Kind;
287 end Is_Fixed_Point_Type;
288
289 function Is_Floating_Point_Type (Id : E) return B is
290 begin
291 return Ekind (Id) in Float_Kind;
292 end Is_Floating_Point_Type;
293
294 function Is_Formal (Id : E) return B is
295 begin
296 return Ekind (Id) in Formal_Kind;
297 end Is_Formal;
298
299 function Is_Formal_Object (Id : E) return B is
300 begin
301 return Ekind (Id) in Formal_Object_Kind;
302 end Is_Formal_Object;
303
304 function Is_Generic_Subprogram (Id : E) return B is
305 begin
306 return Ekind (Id) in Generic_Subprogram_Kind;
307 end Is_Generic_Subprogram;
308
309 function Is_Generic_Unit (Id : E) return B is
310 begin
311 return Ekind (Id) in Generic_Unit_Kind;
312 end Is_Generic_Unit;
313
314 function Is_Ghost_Entity (Id : E) return Boolean is
315 begin
316 return Is_Checked_Ghost_Entity (Id) or else Is_Ignored_Ghost_Entity (Id);
317 end Is_Ghost_Entity;
318
319 function Is_Incomplete_Or_Private_Type (Id : E) return B is
320 begin
321 return Ekind (Id) in Incomplete_Or_Private_Kind;
322 end Is_Incomplete_Or_Private_Type;
323
324 function Is_Incomplete_Type (Id : E) return B is
325 begin
326 return Ekind (Id) in Incomplete_Kind;
327 end Is_Incomplete_Type;
328
329 function Is_Integer_Type (Id : E) return B is
330 begin
331 return Ekind (Id) in Integer_Kind;
332 end Is_Integer_Type;
333
334 function Is_Modular_Integer_Type (Id : E) return B is
335 begin
336 return Ekind (Id) in Modular_Integer_Kind;
337 end Is_Modular_Integer_Type;
338
339 function Is_Named_Access_Type (Id : E) return B is
340 begin
341 return Ekind (Id) in Named_Access_Kind;
342 end Is_Named_Access_Type;
343
344 function Is_Named_Number (Id : E) return B is
345 begin
346 return Ekind (Id) in Named_Kind;
347 end Is_Named_Number;
348
349 function Is_Numeric_Type (Id : E) return B is
350 begin
351 return Ekind (Id) in Numeric_Kind;
352 end Is_Numeric_Type;
353
354 function Is_Object (Id : E) return B is
355 begin
356 return Ekind (Id) in Object_Kind;
357 end Is_Object;
358
359 function Is_Ordinary_Fixed_Point_Type (Id : E) return B is
360 begin
361 return Ekind (Id) in Ordinary_Fixed_Point_Kind;
362 end Is_Ordinary_Fixed_Point_Type;
363
364 function Is_Overloadable (Id : E) return B is
365 begin
366 return Ekind (Id) in Overloadable_Kind;
367 end Is_Overloadable;
368
369 function Is_Private_Type (Id : E) return B is
370 begin
371 return Ekind (Id) in Private_Kind;
372 end Is_Private_Type;
373
374 function Is_Protected_Type (Id : E) return B is
375 begin
376 return Ekind (Id) in Protected_Kind;
377 end Is_Protected_Type;
378
379 function Is_Real_Type (Id : E) return B is
380 begin
381 return Ekind (Id) in Real_Kind;
382 end Is_Real_Type;
383
384 function Is_Record_Type (Id : E) return B is
385 begin
386 return Ekind (Id) in Record_Kind;
387 end Is_Record_Type;
388
389 function Is_Scalar_Type (Id : E) return B is
390 begin
391 return Ekind (Id) in Scalar_Kind;
392 end Is_Scalar_Type;
393
394 function Is_Signed_Integer_Type (Id : E) return B is
395 begin
396 return Ekind (Id) in Signed_Integer_Kind;
397 end Is_Signed_Integer_Type;
398
399 function Is_Subprogram (Id : E) return B is
400 begin
401 return Ekind (Id) in Subprogram_Kind;
402 end Is_Subprogram;
403
404 function Is_Subprogram_Or_Entry (Id : E) return B is
405 begin
406 return Ekind (Id) in Subprogram_Kind
407 or else
408 Ekind (Id) in Entry_Kind;
409 end Is_Subprogram_Or_Entry;
410
411 function Is_Subprogram_Or_Generic_Subprogram (Id : E) return B is
412 begin
413 return Ekind (Id) in Subprogram_Kind
414 or else
415 Ekind (Id) in Generic_Subprogram_Kind;
416 end Is_Subprogram_Or_Generic_Subprogram;
417
418 function Is_Task_Type (Id : E) return B is
419 begin
420 return Ekind (Id) in Task_Kind;
421 end Is_Task_Type;
422
423 function Is_Type (Id : E) return B is
424 begin
425 return Ekind (Id) in Type_Kind;
426 end Is_Type;
427
428 ------------------------------------------
429 -- Type Representation Attribute Fields --
430 ------------------------------------------
431
432 function Known_Alignment (E : Entity_Id) return B is
433 begin
434 -- For some reason, Empty is passed to this sometimes
435
436 return No (E) or else not Field_Is_Initial_Zero (E, F_Alignment);
437 end Known_Alignment;
438
439 procedure Reinit_Alignment (Id : E) is
440 begin
441 Reinit_Field_To_Zero (Id, F_Alignment);
442 end Reinit_Alignment;
443
444 procedure Copy_Alignment (To, From : E) is
445 begin
446 if Known_Alignment (From) then
447 Set_Alignment (To, Alignment (From));
448 else
449 Reinit_Alignment (To);
450 end if;
451 end Copy_Alignment;
452
453 function Known_Component_Bit_Offset (E : Entity_Id) return B is
454 begin
455 return Present (Component_Bit_Offset (E));
456 end Known_Component_Bit_Offset;
457
458 function Known_Static_Component_Bit_Offset (E : Entity_Id) return B is
459 begin
460 return Known_Component_Bit_Offset (E)
461 and then Component_Bit_Offset (E) >= Uint_0;
462 end Known_Static_Component_Bit_Offset;
463
464 function Known_Component_Size (E : Entity_Id) return B is
465 begin
466 return Present (Component_Size (E));
467 end Known_Component_Size;
468
469 function Known_Static_Component_Size (E : Entity_Id) return B is
470 begin
471 return Known_Component_Size (E) and then Component_Size (E) >= Uint_0;
472 end Known_Static_Component_Size;
473
474 function Known_Esize (E : Entity_Id) return B is
475 begin
476 return Present (Esize (E));
477 end Known_Esize;
478
479 function Known_Static_Esize (E : Entity_Id) return B is
480 begin
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;
485
486 procedure Reinit_Esize (Id : E) is
487 begin
488 Reinit_Field_To_Zero (Id, F_Esize);
489 end Reinit_Esize;
490
491 procedure Copy_Esize (To, From : E) is
492 begin
493 if Known_Esize (From) then
494 Set_Esize (To, Esize (From));
495 else
496 Reinit_Esize (To);
497 end if;
498 end Copy_Esize;
499
500 function Known_Normalized_First_Bit (E : Entity_Id) return B is
501 begin
502 return Present (Normalized_First_Bit (E));
503 end Known_Normalized_First_Bit;
504
505 function Known_Static_Normalized_First_Bit (E : Entity_Id) return B is
506 begin
507 return Known_Normalized_First_Bit (E)
508 and then Normalized_First_Bit (E) >= Uint_0;
509 end Known_Static_Normalized_First_Bit;
510
511 function Known_Normalized_Position (E : Entity_Id) return B is
512 begin
513 return Present (Normalized_Position (E));
514 end Known_Normalized_Position;
515
516 function Known_Static_Normalized_Position (E : Entity_Id) return B is
517 begin
518 return Known_Normalized_Position (E)
519 and then Normalized_Position (E) >= Uint_0;
520 end Known_Static_Normalized_Position;
521
522 function Known_RM_Size (E : Entity_Id) return B is
523 begin
524 return Present (RM_Size (E));
525 end Known_RM_Size;
526
527 function Known_Static_RM_Size (E : Entity_Id) return B is
528 begin
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;
533
534 procedure Reinit_RM_Size (Id : E) is
535 begin
536 Reinit_Field_To_Zero (Id, F_RM_Size);
537 end Reinit_RM_Size;
538
539 procedure Copy_RM_Size (To, From : E) is
540 begin
541 if Known_RM_Size (From) then
542 Set_RM_Size (To, RM_Size (From));
543 else
544 Reinit_RM_Size (To);
545 end if;
546 end Copy_RM_Size;
547
548 -------------------------------
549 -- Reinit_Component_Location --
550 -------------------------------
551
552 procedure Reinit_Component_Location (Id : E) is
553 begin
554 Set_Normalized_First_Bit (Id, No_Uint);
555 Set_Component_Bit_Offset (Id, No_Uint);
556 Reinit_Esize (Id);
557 Set_Normalized_Position (Id, No_Uint);
558 end Reinit_Component_Location;
559
560 ------------------------------
561 -- Reinit_Object_Size_Align --
562 ------------------------------
563
564 procedure Reinit_Object_Size_Align (Id : E) is
565 begin
566 Reinit_Esize (Id);
567 Reinit_Alignment (Id);
568 end Reinit_Object_Size_Align;
569
570 ---------------
571 -- Init_Size --
572 ---------------
573
574 procedure Init_Size (Id : E; V : Int) is
575 begin
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);
579
580 Set_Esize (Id, UI_From_Int (V));
581 Set_RM_Size (Id, UI_From_Int (V));
582 end Init_Size;
583
584 -----------------------
585 -- Reinit_Size_Align --
586 -----------------------
587
588 procedure Reinit_Size_Align (Id : E) is
589 begin
590 pragma Assert (Ekind (Id) in Type_Kind | E_Void);
591 Reinit_Esize (Id);
592 Reinit_RM_Size (Id);
593 Reinit_Alignment (Id);
594 end Reinit_Size_Align;
595
596 --------------------
597 -- Address_Clause --
598 --------------------
599
600 function Address_Clause (Id : E) return Node_Id is
601 begin
602 return Get_Attribute_Definition_Clause (Id, Attribute_Address);
603 end Address_Clause;
604
605 ---------------
606 -- Aft_Value --
607 ---------------
608
609 function Aft_Value (Id : E) return U is
610 Result : Nat := 1;
611 Delta_Val : Ureal := Delta_Value (Id);
612 begin
613 while Delta_Val < Ureal_Tenth loop
614 Delta_Val := Delta_Val * Ureal_10;
615 Result := Result + 1;
616 end loop;
617
618 return UI_From_Int (Result);
619 end Aft_Value;
620
621 ----------------------
622 -- Alignment_Clause --
623 ----------------------
624
625 function Alignment_Clause (Id : E) return Node_Id is
626 begin
627 return Get_Attribute_Definition_Clause (Id, Attribute_Alignment);
628 end Alignment_Clause;
629
630 -------------------
631 -- Append_Entity --
632 -------------------
633
634 procedure Append_Entity (Id : Entity_Id; Scop : Entity_Id) is
635 Last : constant Entity_Id := Last_Entity (Scop);
636
637 begin
638 Set_Scope (Id, Scop);
639 Set_Prev_Entity (Id, Empty); -- Empty <-- Id
640
641 -- The entity chain is empty
642
643 if No (Last) then
644 Set_First_Entity (Scop, Id);
645
646 -- Otherwise the entity chain has at least one element
647
648 else
649 Link_Entities (Last, Id); -- Last <-- Id, Last --> Id
650 end if;
651
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 ???
655
656 Set_Next_Entity (Id, Empty); -- Id --> Empty
657
658 Set_Last_Entity (Scop, Id);
659 end Append_Entity;
660
661 ---------------
662 -- Base_Type --
663 ---------------
664
665 function Base_Type (Id : E) return E is
666 begin
667 return Result : E do
668 if Is_Base_Type (Id) then
669 Result := Id;
670 else
671 pragma Assert (Is_Type (Id));
672 Result := Etype (Id);
673 if False then
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
679 -- expect.
680 end if;
681 end if;
682 end return;
683 end Base_Type;
684
685 ----------------------
686 -- Declaration_Node --
687 ----------------------
688
689 function Declaration_Node (Id : E) return Node_Id is
690 P : Node_Id;
691
692 begin
693 if Ekind (Id) = E_Incomplete_Type
694 and then Present (Full_View (Id))
695 then
696 P := Parent (Full_View (Id));
697 else
698 P := Parent (Id);
699 end if;
700
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))
704 loop
705 P := Parent (P);
706 end loop;
707
708 if Is_Itype (Id)
709 and then Nkind (P) not in
710 N_Full_Type_Declaration | N_Subtype_Declaration
711 then
712 P := Empty;
713 end if;
714
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
718 -- return Empty.
719
720 if Nkind (P) in
721 N_Assignment_Statement
722 | N_Integer_Literal
723 | N_Procedure_Call_Statement
724 | N_Subtype_Indication
725 | N_Type_Conversion
726 then
727 P := Empty;
728 end if;
729
730 -- The following Assert indicates what kinds of nodes can be returned;
731 -- they are not all "declarations".
732
733 if Serious_Errors_Detected = 0 then
734 pragma Assert
735 (Nkind (P) in N_Is_Decl | N_Empty,
736 "Declaration_Node incorrect kind: " & Node_Kind'Image (Nkind (P)));
737 end if;
738
739 return P;
740 end Declaration_Node;
741
742 ---------------------
743 -- Designated_Type --
744 ---------------------
745
746 function Designated_Type (Id : E) return E is
747 Desig_Type : Entity_Id;
748
749 begin
750 Desig_Type := Directly_Designated_Type (Id);
751
752 if No (Desig_Type) then
753 pragma Assert (Error_Posted (Id));
754 return Any_Type;
755 end if;
756
757 if Is_Incomplete_Type (Desig_Type)
758 and then Present (Full_View (Desig_Type))
759 then
760 return Full_View (Desig_Type);
761 end if;
762
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))))
767 then
768 return Class_Wide_Type (Full_View (Etype (Desig_Type)));
769 end if;
770
771 return Desig_Type;
772 end Designated_Type;
773
774 ----------------------
775 -- Entry_Index_Type --
776 ----------------------
777
778 function Entry_Index_Type (Id : E) return E is
779 begin
780 pragma Assert (Ekind (Id) = E_Entry_Family);
781 return Etype (Discrete_Subtype_Definition (Parent (Id)));
782 end Entry_Index_Type;
783
784 ---------------------
785 -- First_Component --
786 ---------------------
787
788 function First_Component (Id : E) return Entity_Id is
789 Comp_Id : Entity_Id;
790
791 begin
792 pragma Assert
793 (Is_Concurrent_Type (Id)
794 or else Is_Incomplete_Or_Private_Type (Id)
795 or else Is_Record_Type (Id));
796
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);
801 end loop;
802
803 return Comp_Id;
804 end First_Component;
805
806 -------------------------------------
807 -- First_Component_Or_Discriminant --
808 -------------------------------------
809
810 function First_Component_Or_Discriminant (Id : E) return Entity_Id is
811 Comp_Id : Entity_Id;
812
813 begin
814 pragma Assert
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));
819
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);
824 end loop;
825
826 return Comp_Id;
827 end First_Component_Or_Discriminant;
828
829 ------------------
830 -- First_Formal --
831 ------------------
832
833 function First_Formal (Id : E) return Entity_Id is
834 Formal : Entity_Id;
835
836 begin
837 pragma Assert
838 (Is_Generic_Subprogram (Id)
839 or else Is_Overloadable (Id)
840 or else Ekind (Id) in E_Entry_Family
841 | E_Subprogram_Body
842 | E_Subprogram_Type);
843
844 if Ekind (Id) = E_Enumeration_Literal then
845 return Empty;
846
847 else
848 Formal := First_Entity (Id);
849
850 -- Deal with the common, non-generic case first
851
852 if No (Formal) or else Is_Formal (Formal) then
853 return Formal;
854 end if;
855
856 -- The first/next entity chain of a generic subprogram contains all
857 -- generic formal parameters, followed by the formal parameters.
858
859 if Is_Generic_Subprogram (Id) then
860 while Present (Formal) and then not Is_Formal (Formal) loop
861 Next_Entity (Formal);
862 end loop;
863 return Formal;
864 else
865 return Empty;
866 end if;
867 end if;
868 end First_Formal;
869
870 ------------------------------
871 -- First_Formal_With_Extras --
872 ------------------------------
873
874 function First_Formal_With_Extras (Id : E) return Entity_Id is
875 Formal : Entity_Id;
876
877 begin
878 pragma Assert
879 (Is_Generic_Subprogram (Id)
880 or else Is_Overloadable (Id)
881 or else Ekind (Id) in E_Entry_Family
882 | E_Subprogram_Body
883 | E_Subprogram_Type);
884
885 if Ekind (Id) = E_Enumeration_Literal then
886 return Empty;
887
888 else
889 Formal := First_Entity (Id);
890
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.
894
895 if Is_Generic_Subprogram (Id) then
896 while Present (Formal) and then not Is_Formal (Formal) loop
897 Next_Entity (Formal);
898 end loop;
899 end if;
900
901 if Present (Formal) and then Is_Formal (Formal) then
902 return Formal;
903 else
904 return Extra_Formals (Id); -- Empty if no extra formals
905 end if;
906 end if;
907 end First_Formal_With_Extras;
908
909 ---------------
910 -- Float_Rep --
911 ---------------
912
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);
916
917 -- There is only one value, so we don't need to store it, see types.ads.
918
919 Val : constant Float_Rep_Kind := IEEE_Binary;
920
921 begin
922 return Val;
923 end Float_Rep;
924
925 -------------------------------------
926 -- Get_Attribute_Definition_Clause --
927 -------------------------------------
928
929 function Get_Attribute_Definition_Clause
930 (E : Entity_Id;
931 Id : Attribute_Id) return Node_Id
932 is
933 N : Node_Id;
934
935 begin
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
940 then
941 return N;
942 else
943 Next_Rep_Item (N);
944 end if;
945 end loop;
946
947 return Empty;
948 end Get_Attribute_Definition_Clause;
949
950 ---------------------------
951 -- Get_Class_Wide_Pragma --
952 ---------------------------
953
954 function Get_Class_Wide_Pragma
955 (E : Entity_Id;
956 Id : Pragma_Id) return Node_Id
957 is
958 Item : Node_Id;
959 Items : Node_Id;
960
961 begin
962 Items := Contract (E);
963
964 if No (Items) then
965 return Empty;
966 end if;
967
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)
973 then
974 return Item;
975 end if;
976
977 Item := Next_Pragma (Item);
978 end loop;
979
980 return Empty;
981 end Get_Class_Wide_Pragma;
982
983 -------------------
984 -- Get_Full_View --
985 -------------------
986
987 function Get_Full_View (T : Entity_Id) return Entity_Id is
988 begin
989 if Is_Incomplete_Type (T) and then Present (Full_View (T)) then
990 return Full_View (T);
991
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)))
995 then
996 return Class_Wide_Type (Full_View (Root_Type (T)));
997
998 else
999 return T;
1000 end if;
1001 end Get_Full_View;
1002
1003 ----------------
1004 -- Get_Pragma --
1005 ----------------
1006
1007 function Get_Pragma (E : Entity_Id; Id : Pragma_Id) return Node_Id is
1008
1009 -- Classification pragmas
1010
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;
1032
1033 -- Contract / subprogram variant / test case pragmas
1034
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_Exit_Cases or else
1040 Id = Pragma_Subprogram_Variant or else
1041 Id = Pragma_Test_Case;
1042
1043 -- Pre / postcondition pragmas
1044
1045 Is_PPC : constant Boolean :=
1046 Id = Pragma_Precondition or else
1047 Id = Pragma_Postcondition or else
1048 Id = Pragma_Refined_Post;
1049
1050 In_Contract : constant Boolean := Is_CLS or Is_CTC or Is_PPC;
1051
1052 Item : Node_Id;
1053 Items : Node_Id;
1054
1055 begin
1056 -- Handle pragmas that appear in N_Contract nodes. Those have to be
1057 -- extracted from their specialized list.
1058
1059 if In_Contract then
1060 Items := Contract (E);
1061
1062 if No (Items) then
1063 return Empty;
1064
1065 elsif Is_CLS then
1066 Item := Classifications (Items);
1067
1068 elsif Is_CTC then
1069 Item := Contract_Test_Cases (Items);
1070
1071 else
1072 Item := Pre_Post_Conditions (Items);
1073 end if;
1074
1075 -- Regular pragmas
1076
1077 else
1078 Item := First_Rep_Item (E);
1079 end if;
1080
1081 while Present (Item) loop
1082 if Nkind (Item) = N_Pragma
1083 and then Get_Pragma_Id (Pragma_Name_Unmapped (Item)) = Id
1084 then
1085 return Item;
1086
1087 -- All nodes in N_Contract are chained using Next_Pragma
1088
1089 elsif In_Contract then
1090 Item := Next_Pragma (Item);
1091
1092 -- Regular pragmas
1093
1094 else
1095 Next_Rep_Item (Item);
1096 end if;
1097 end loop;
1098
1099 return Empty;
1100 end Get_Pragma;
1101
1102 --------------------------------------
1103 -- Get_Record_Representation_Clause --
1104 --------------------------------------
1105
1106 function Get_Record_Representation_Clause (E : Entity_Id) return Node_Id is
1107 N : Node_Id;
1108
1109 begin
1110 N := First_Rep_Item (E);
1111 while Present (N) loop
1112 if Nkind (N) = N_Record_Representation_Clause then
1113 return N;
1114 end if;
1115
1116 Next_Rep_Item (N);
1117 end loop;
1118
1119 return Empty;
1120 end Get_Record_Representation_Clause;
1121
1122 ------------------------
1123 -- Has_Attach_Handler --
1124 ------------------------
1125
1126 function Has_Attach_Handler (Id : E) return B is
1127 Ritem : Node_Id;
1128
1129 begin
1130 pragma Assert (Is_Protected_Type (Id));
1131
1132 Ritem := First_Rep_Item (Id);
1133 while Present (Ritem) loop
1134 if Nkind (Ritem) = N_Pragma
1135 and then Pragma_Name (Ritem) = Name_Attach_Handler
1136 then
1137 return True;
1138 else
1139 Next_Rep_Item (Ritem);
1140 end if;
1141 end loop;
1142
1143 return False;
1144 end Has_Attach_Handler;
1145
1146 -------------
1147 -- Has_DIC --
1148 -------------
1149
1150 function Has_DIC (Id : E) return B is
1151 begin
1152 return Has_Own_DIC (Id) or else Has_Inherited_DIC (Id);
1153 end Has_DIC;
1154
1155 -----------------
1156 -- Has_Entries --
1157 -----------------
1158
1159 function Has_Entries (Id : E) return B is
1160 Ent : Entity_Id;
1161
1162 begin
1163 pragma Assert (Is_Concurrent_Type (Id));
1164
1165 Ent := First_Entity (Id);
1166 while Present (Ent) loop
1167 if Is_Entry (Ent) then
1168 return True;
1169 end if;
1170
1171 Next_Entity (Ent);
1172 end loop;
1173
1174 return False;
1175 end Has_Entries;
1176
1177 ----------------------------
1178 -- Has_Foreign_Convention --
1179 ----------------------------
1180
1181 function Has_Foreign_Convention (Id : E) return B is
1182 begin
1183 -- While regular Intrinsics such as the Standard operators fit in the
1184 -- "Ada" convention, those with an Interface_Name materialize GCC
1185 -- builtin imports for which Ada special treatments shouldn't apply.
1186
1187 return Convention (Id) in Foreign_Convention
1188 or else (Convention (Id) = Convention_Intrinsic
1189 and then Present (Interface_Name (Id)));
1190 end Has_Foreign_Convention;
1191
1192 ---------------------------
1193 -- Has_Interrupt_Handler --
1194 ---------------------------
1195
1196 function Has_Interrupt_Handler (Id : E) return B is
1197 Ritem : Node_Id;
1198
1199 begin
1200 pragma Assert (Is_Protected_Type (Id));
1201
1202 Ritem := First_Rep_Item (Id);
1203 while Present (Ritem) loop
1204 if Nkind (Ritem) = N_Pragma
1205 and then Pragma_Name (Ritem) = Name_Interrupt_Handler
1206 then
1207 return True;
1208 else
1209 Next_Rep_Item (Ritem);
1210 end if;
1211 end loop;
1212
1213 return False;
1214 end Has_Interrupt_Handler;
1215
1216 --------------------
1217 -- Has_Invariants --
1218 --------------------
1219
1220 function Has_Invariants (Id : E) return B is
1221 begin
1222 return Has_Own_Invariants (Id) or else Has_Inherited_Invariants (Id);
1223 end Has_Invariants;
1224
1225 --------------------------
1226 -- Has_Limited_View --
1227 --------------------------
1228
1229 function Has_Limited_View (Id : E) return B is
1230 begin
1231 return Ekind (Id) = E_Package
1232 and then not Is_Generic_Instance (Id)
1233 and then Present (Limited_View (Id));
1234 end Has_Limited_View;
1235
1236 --------------------------
1237 -- Has_Non_Limited_View --
1238 --------------------------
1239
1240 function Has_Non_Limited_View (Id : E) return B is
1241 begin
1242 return (Ekind (Id) in Incomplete_Kind
1243 or else Ekind (Id) in Class_Wide_Kind
1244 or else Ekind (Id) = E_Abstract_State)
1245 and then Present (Non_Limited_View (Id));
1246 end Has_Non_Limited_View;
1247
1248 ---------------------------------
1249 -- Has_Non_Null_Abstract_State --
1250 ---------------------------------
1251
1252 function Has_Non_Null_Abstract_State (Id : E) return B is
1253 begin
1254 pragma Assert (Is_Package_Or_Generic_Package (Id));
1255
1256 return
1257 Present (Abstract_States (Id))
1258 and then
1259 not Is_Null_State (Node (First_Elmt (Abstract_States (Id))));
1260 end Has_Non_Null_Abstract_State;
1261
1262 -------------------------------------
1263 -- Has_Non_Null_Visible_Refinement --
1264 -------------------------------------
1265
1266 function Has_Non_Null_Visible_Refinement (Id : E) return B is
1267 Constits : Elist_Id;
1268
1269 begin
1270 -- "Refinement" is a concept applicable only to abstract states
1271
1272 pragma Assert (Ekind (Id) = E_Abstract_State);
1273 Constits := Refinement_Constituents (Id);
1274
1275 -- A partial refinement is always non-null. For a full refinement to be
1276 -- non-null, the first constituent must be anything other than null.
1277
1278 return
1279 Has_Partial_Visible_Refinement (Id)
1280 or else (Has_Visible_Refinement (Id)
1281 and then Present (Constits)
1282 and then Nkind (Node (First_Elmt (Constits))) /= N_Null);
1283 end Has_Non_Null_Visible_Refinement;
1284
1285 -----------------------------
1286 -- Has_Null_Abstract_State --
1287 -----------------------------
1288
1289 function Has_Null_Abstract_State (Id : E) return B is
1290 pragma Assert (Is_Package_Or_Generic_Package (Id));
1291
1292 States : constant Elist_Id := Abstract_States (Id);
1293
1294 begin
1295 -- Check first available state of related package. A null abstract
1296 -- state always appears as the sole element of the state list.
1297
1298 return
1299 Present (States)
1300 and then Is_Null_State (Node (First_Elmt (States)));
1301 end Has_Null_Abstract_State;
1302
1303 ---------------------------------
1304 -- Has_Null_Visible_Refinement --
1305 ---------------------------------
1306
1307 function Has_Null_Visible_Refinement (Id : E) return B is
1308 Constits : Elist_Id;
1309
1310 begin
1311 -- "Refinement" is a concept applicable only to abstract states
1312
1313 pragma Assert (Ekind (Id) = E_Abstract_State);
1314 Constits := Refinement_Constituents (Id);
1315
1316 -- For a refinement to be null, the state's sole constituent must be a
1317 -- null.
1318
1319 return
1320 Has_Visible_Refinement (Id)
1321 and then Present (Constits)
1322 and then Nkind (Node (First_Elmt (Constits))) = N_Null;
1323 end Has_Null_Visible_Refinement;
1324
1325 --------------------
1326 -- Has_Unmodified --
1327 --------------------
1328
1329 function Has_Unmodified (E : Entity_Id) return Boolean is
1330 begin
1331 if Has_Pragma_Unmodified (E) then
1332 return True;
1333 elsif Warnings_Off (E) then
1334 Set_Warnings_Off_Used_Unmodified (E);
1335 return True;
1336 else
1337 return False;
1338 end if;
1339 end Has_Unmodified;
1340
1341 ---------------------
1342 -- Has_Unreferenced --
1343 ---------------------
1344
1345 function Has_Unreferenced (E : Entity_Id) return Boolean is
1346 begin
1347 if Has_Pragma_Unreferenced (E) then
1348 return True;
1349 elsif Warnings_Off (E) then
1350 Set_Warnings_Off_Used_Unreferenced (E);
1351 return True;
1352 else
1353 return False;
1354 end if;
1355 end Has_Unreferenced;
1356
1357 ----------------------
1358 -- Has_Warnings_Off --
1359 ----------------------
1360
1361 function Has_Warnings_Off (E : Entity_Id) return Boolean is
1362 begin
1363 if Warnings_Off (E) then
1364 Set_Warnings_Off_Used (E);
1365 return True;
1366 else
1367 return False;
1368 end if;
1369 end Has_Warnings_Off;
1370
1371 ------------------------------
1372 -- Implementation_Base_Type --
1373 ------------------------------
1374
1375 function Implementation_Base_Type (Id : E) return E is
1376 Bastyp : Entity_Id;
1377 Imptyp : Entity_Id;
1378
1379 begin
1380 Bastyp := Base_Type (Id);
1381
1382 if Is_Incomplete_Or_Private_Type (Bastyp) then
1383 Imptyp := Underlying_Type (Bastyp);
1384
1385 -- If we have an implementation type, then just return it,
1386 -- otherwise we return the Base_Type anyway. This can only
1387 -- happen in error situations and should avoid some error bombs.
1388
1389 if Present (Imptyp) then
1390 return Base_Type (Imptyp);
1391 else
1392 return Bastyp;
1393 end if;
1394
1395 else
1396 return Bastyp;
1397 end if;
1398 end Implementation_Base_Type;
1399
1400 -------------------------
1401 -- Invariant_Procedure --
1402 -------------------------
1403
1404 function Invariant_Procedure (Id : E) return Entity_Id is
1405 Subp_Elmt : Elmt_Id;
1406 Subp_Id : Entity_Id;
1407 Subps : Elist_Id;
1408
1409 begin
1410 pragma Assert (Is_Type (Id));
1411
1412 Subps := Subprograms_For_Type (Base_Type (Id));
1413
1414 if Present (Subps) then
1415 Subp_Elmt := First_Elmt (Subps);
1416 while Present (Subp_Elmt) loop
1417 Subp_Id := Node (Subp_Elmt);
1418
1419 if Is_Invariant_Procedure (Subp_Id) then
1420 return Subp_Id;
1421 end if;
1422
1423 Next_Elmt (Subp_Elmt);
1424 end loop;
1425 end if;
1426
1427 return Empty;
1428 end Invariant_Procedure;
1429
1430 ------------------
1431 -- Is_Base_Type --
1432 ------------------
1433
1434 -- Global flag table allowing rapid computation of this function
1435
1436 Entity_Is_Base_Type : constant array (Entity_Kind) of Boolean :=
1437 (E_Enumeration_Subtype |
1438 E_Incomplete_Subtype |
1439 E_Signed_Integer_Subtype |
1440 E_Modular_Integer_Subtype |
1441 E_Floating_Point_Subtype |
1442 E_Ordinary_Fixed_Point_Subtype |
1443 E_Decimal_Fixed_Point_Subtype |
1444 E_Array_Subtype |
1445 E_Record_Subtype |
1446 E_Private_Subtype |
1447 E_Record_Subtype_With_Private |
1448 E_Limited_Private_Subtype |
1449 E_Access_Subtype |
1450 E_Protected_Subtype |
1451 E_Task_Subtype |
1452 E_String_Literal_Subtype |
1453 E_Class_Wide_Subtype => False,
1454 others => True);
1455
1456 function Is_Base_Type (Id : E) return Boolean is
1457 begin
1458 return Entity_Is_Base_Type (Ekind (Id));
1459 end Is_Base_Type;
1460
1461 ---------------------
1462 -- Is_Boolean_Type --
1463 ---------------------
1464
1465 function Is_Boolean_Type (Id : E) return B is
1466 begin
1467 return Root_Type (Id) = Standard_Boolean;
1468 end Is_Boolean_Type;
1469
1470 ------------------------
1471 -- Is_Constant_Object --
1472 ------------------------
1473
1474 function Is_Constant_Object (Id : E) return B is
1475 begin
1476 return Ekind (Id) in E_Constant | E_In_Parameter | E_Loop_Parameter;
1477 end Is_Constant_Object;
1478
1479 -------------------
1480 -- Is_Controlled --
1481 -------------------
1482
1483 function Is_Controlled (Id : E) return B is
1484 begin
1485 return Is_Controlled_Active (Id) and then not Disable_Controlled (Id);
1486 end Is_Controlled;
1487
1488 --------------------
1489 -- Is_Discriminal --
1490 --------------------
1491
1492 function Is_Discriminal (Id : E) return B is
1493 begin
1494 return Ekind (Id) in E_Constant | E_In_Parameter
1495 and then Present (Discriminal_Link (Id));
1496 end Is_Discriminal;
1497
1498 ----------------------
1499 -- Is_Dynamic_Scope --
1500 ----------------------
1501
1502 function Is_Dynamic_Scope (Id : E) return B is
1503 begin
1504 return Ekind (Id) in E_Block
1505 -- Including an E_Block that came from an N_Expression_With_Actions
1506 | E_Entry
1507 | E_Entry_Family
1508 | E_Function
1509 | E_Procedure
1510 | E_Return_Statement
1511 | E_Subprogram_Body
1512 | E_Task_Type
1513 or else
1514 (Ekind (Id) = E_Limited_Private_Type
1515 and then Present (Full_View (Id))
1516 and then Ekind (Full_View (Id)) = E_Task_Type);
1517 end Is_Dynamic_Scope;
1518
1519 --------------------
1520 -- Is_Entity_Name --
1521 --------------------
1522
1523 function Is_Entity_Name (N : Node_Id) return Boolean is
1524 Kind : constant Node_Kind := Nkind (N);
1525
1526 begin
1527 -- Identifiers, operator symbols, expanded names are entity names.
1528 -- (But not N_Character_Literal.)
1529
1530 return Kind in N_Identifier | N_Operator_Symbol | N_Expanded_Name
1531
1532 -- Attribute references are entity names if they refer to an entity.
1533 -- Note that we don't do this by testing for the presence of the
1534 -- Entity field in the N_Attribute_Reference node, since it may not
1535 -- have been set yet.
1536
1537 or else (Kind = N_Attribute_Reference
1538 and then Is_Entity_Attribute_Name (Attribute_Name (N)));
1539 end Is_Entity_Name;
1540
1541 ---------------------------
1542 -- Is_Elaboration_Target --
1543 ---------------------------
1544
1545 function Is_Elaboration_Target (Id : E) return Boolean is
1546 begin
1547 return
1548 Ekind (Id) in E_Constant | E_Package | E_Variable
1549 or else Is_Entry (Id)
1550 or else Is_Generic_Unit (Id)
1551 or else Is_Subprogram (Id)
1552 or else Is_Task_Type (Id);
1553 end Is_Elaboration_Target;
1554
1555 -----------------------
1556 -- Is_External_State --
1557 -----------------------
1558
1559 function Is_External_State (Id : E) return B is
1560 begin
1561 -- To qualify, the abstract state must appear with option "external" or
1562 -- "synchronous" (SPARK RM 7.1.4(7) and (9)).
1563
1564 return
1565 Ekind (Id) = E_Abstract_State
1566 and then (Has_Option (Id, Name_External)
1567 or else
1568 Has_Option (Id, Name_Synchronous));
1569 end Is_External_State;
1570
1571 ----------------------
1572 -- Is_Full_Access --
1573 ----------------------
1574
1575 function Is_Full_Access (Id : E) return B is
1576 begin
1577 return Is_Atomic (Id) or else Is_Volatile_Full_Access (Id);
1578 end Is_Full_Access;
1579
1580 -------------------
1581 -- Is_Null_State --
1582 -------------------
1583
1584 function Is_Null_State (Id : E) return B is
1585 begin
1586 return
1587 Ekind (Id) = E_Abstract_State and then Nkind (Parent (Id)) = N_Null;
1588 end Is_Null_State;
1589
1590 -----------------------------------
1591 -- Is_Package_Or_Generic_Package --
1592 -----------------------------------
1593
1594 function Is_Package_Or_Generic_Package (Id : E) return B is
1595 begin
1596 return Ekind (Id) in E_Generic_Package | E_Package;
1597 end Is_Package_Or_Generic_Package;
1598
1599 ---------------------
1600 -- Is_Packed_Array --
1601 ---------------------
1602
1603 function Is_Packed_Array (Id : E) return B is
1604 begin
1605 return Is_Array_Type (Id) and then Is_Packed (Id);
1606 end Is_Packed_Array;
1607
1608 ---------------
1609 -- Is_Prival --
1610 ---------------
1611
1612 function Is_Prival (Id : E) return B is
1613 begin
1614 return Ekind (Id) in E_Constant | E_Variable
1615 and then Present (Prival_Link (Id));
1616 end Is_Prival;
1617
1618 ----------------------------
1619 -- Is_Protected_Component --
1620 ----------------------------
1621
1622 function Is_Protected_Component (Id : E) return B is
1623 begin
1624 return Ekind (Id) = E_Component and then Is_Protected_Type (Scope (Id));
1625 end Is_Protected_Component;
1626
1627 ----------------------------
1628 -- Is_Protected_Interface --
1629 ----------------------------
1630
1631 function Is_Protected_Interface (Id : E) return B is
1632 Typ : constant Entity_Id := Base_Type (Id);
1633 begin
1634 if not Is_Interface (Typ) then
1635 return False;
1636 elsif Is_Class_Wide_Type (Typ) then
1637 return Is_Protected_Interface (Etype (Typ));
1638 else
1639 return Protected_Present (Type_Definition (Parent (Typ)));
1640 end if;
1641 end Is_Protected_Interface;
1642
1643 ------------------------------
1644 -- Is_Protected_Record_Type --
1645 ------------------------------
1646
1647 function Is_Protected_Record_Type (Id : E) return B is
1648 begin
1649 return
1650 Is_Concurrent_Record_Type (Id)
1651 and then Is_Protected_Type (Corresponding_Concurrent_Type (Id));
1652 end Is_Protected_Record_Type;
1653
1654 --------------------------------
1655 -- Is_Standard_Character_Type --
1656 --------------------------------
1657
1658 function Is_Standard_Character_Type (Id : E) return B is
1659 begin
1660 return Is_Type (Id)
1661 and then Root_Type (Id) in Standard_Character
1662 | Standard_Wide_Character
1663 | Standard_Wide_Wide_Character;
1664 end Is_Standard_Character_Type;
1665
1666 -----------------------------
1667 -- Is_Standard_String_Type --
1668 -----------------------------
1669
1670 function Is_Standard_String_Type (Id : E) return B is
1671 begin
1672 return Is_Type (Id)
1673 and then Root_Type (Id) in Standard_String
1674 | Standard_Wide_String
1675 | Standard_Wide_Wide_String;
1676 end Is_Standard_String_Type;
1677
1678 --------------------
1679 -- Is_String_Type --
1680 --------------------
1681
1682 function Is_String_Type (Id : E) return B is
1683 begin
1684 return Is_Array_Type (Id)
1685 and then Id /= Any_Composite
1686 and then Number_Dimensions (Id) = 1
1687 and then Is_Character_Type (Component_Type (Id));
1688 end Is_String_Type;
1689
1690 -------------------------------
1691 -- Is_Synchronized_Interface --
1692 -------------------------------
1693
1694 function Is_Synchronized_Interface (Id : E) return B is
1695 Typ : constant Entity_Id := Base_Type (Id);
1696
1697 begin
1698 if not Is_Interface (Typ) then
1699 return False;
1700
1701 elsif Is_Class_Wide_Type (Typ) then
1702 return Is_Synchronized_Interface (Etype (Typ));
1703
1704 else
1705 return Protected_Present (Type_Definition (Parent (Typ)))
1706 or else Synchronized_Present (Type_Definition (Parent (Typ)))
1707 or else Task_Present (Type_Definition (Parent (Typ)));
1708 end if;
1709 end Is_Synchronized_Interface;
1710
1711 ---------------------------
1712 -- Is_Synchronized_State --
1713 ---------------------------
1714
1715 function Is_Synchronized_State (Id : E) return B is
1716 begin
1717 -- To qualify, the abstract state must appear with simple option
1718 -- "synchronous" (SPARK RM 7.1.4(9)).
1719
1720 return
1721 Ekind (Id) = E_Abstract_State
1722 and then Has_Option (Id, Name_Synchronous);
1723 end Is_Synchronized_State;
1724
1725 -----------------------
1726 -- Is_Task_Interface --
1727 -----------------------
1728
1729 function Is_Task_Interface (Id : E) return B is
1730 Typ : constant Entity_Id := Base_Type (Id);
1731 begin
1732 if not Is_Interface (Typ) then
1733 return False;
1734 elsif Is_Class_Wide_Type (Typ) then
1735 return Is_Task_Interface (Etype (Typ));
1736 else
1737 return Task_Present (Type_Definition (Parent (Typ)));
1738 end if;
1739 end Is_Task_Interface;
1740
1741 -------------------------
1742 -- Is_Task_Record_Type --
1743 -------------------------
1744
1745 function Is_Task_Record_Type (Id : E) return B is
1746 begin
1747 return
1748 Is_Concurrent_Record_Type (Id)
1749 and then Is_Task_Type (Corresponding_Concurrent_Type (Id));
1750 end Is_Task_Record_Type;
1751
1752 ------------------------
1753 -- Is_Wrapper_Package --
1754 ------------------------
1755
1756 function Is_Wrapper_Package (Id : E) return B is
1757 begin
1758 return Ekind (Id) = E_Package and then Present (Related_Instance (Id));
1759 end Is_Wrapper_Package;
1760
1761 -----------------
1762 -- Last_Formal --
1763 -----------------
1764
1765 function Last_Formal (Id : E) return Entity_Id is
1766 Formal : Entity_Id;
1767
1768 begin
1769 pragma Assert
1770 (Is_Overloadable (Id)
1771 or else Ekind (Id) in E_Entry_Family
1772 | E_Subprogram_Body
1773 | E_Subprogram_Type);
1774
1775 if Ekind (Id) = E_Enumeration_Literal then
1776 return Empty;
1777
1778 else
1779 Formal := First_Formal (Id);
1780
1781 if Present (Formal) then
1782 while Present (Next_Formal (Formal)) loop
1783 Next_Formal (Formal);
1784 end loop;
1785 end if;
1786
1787 return Formal;
1788 end if;
1789 end Last_Formal;
1790
1791 -------------------
1792 -- Link_Entities --
1793 -------------------
1794
1795 procedure Link_Entities (First, Second : Entity_Id) is
1796 begin
1797 if Present (Second) then
1798 Set_Prev_Entity (Second, First); -- First <-- Second
1799 end if;
1800
1801 Set_Next_Entity (First, Second); -- First --> Second
1802 end Link_Entities;
1803
1804 ------------------------
1805 -- Machine_Emax_Value --
1806 ------------------------
1807
1808 function Machine_Emax_Value (Id : E) return Uint is
1809 Digs : constant Pos := UI_To_Int (Digits_Value (Base_Type (Id)));
1810
1811 begin
1812 case Float_Rep (Id) is
1813 when IEEE_Binary =>
1814 case Digs is
1815 when 1 .. 6 => return Uint_128;
1816 when 7 .. 15 => return 2**10;
1817 when 16 .. 33 => return 2**14;
1818 when others => return No_Uint;
1819 end case;
1820 end case;
1821 end Machine_Emax_Value;
1822
1823 ------------------------
1824 -- Machine_Emin_Value --
1825 ------------------------
1826
1827 function Machine_Emin_Value (Id : E) return Uint is
1828 begin
1829 case Float_Rep (Id) is
1830 when IEEE_Binary => return Uint_3 - Machine_Emax_Value (Id);
1831 end case;
1832 end Machine_Emin_Value;
1833
1834 ----------------------------
1835 -- Machine_Mantissa_Value --
1836 ----------------------------
1837
1838 function Machine_Mantissa_Value (Id : E) return Uint is
1839 Digs : constant Pos := UI_To_Int (Digits_Value (Base_Type (Id)));
1840
1841 begin
1842 case Float_Rep (Id) is
1843 when IEEE_Binary =>
1844 case Digs is
1845 when 1 .. 6 => return Uint_24;
1846 when 7 .. 15 => return UI_From_Int (53);
1847 when 16 .. 18 => return Uint_64;
1848 when 19 .. 33 => return UI_From_Int (113);
1849 when others => return No_Uint;
1850 end case;
1851 end case;
1852 end Machine_Mantissa_Value;
1853
1854 -------------------------
1855 -- Machine_Radix_Value --
1856 -------------------------
1857
1858 function Machine_Radix_Value (Id : E) return U is
1859 begin
1860 case Float_Rep (Id) is
1861 when IEEE_Binary =>
1862 return Uint_2;
1863 end case;
1864 end Machine_Radix_Value;
1865
1866 ----------------------
1867 -- Model_Emin_Value --
1868 ----------------------
1869
1870 function Model_Emin_Value (Id : E) return Uint is
1871 begin
1872 return Machine_Emin_Value (Id);
1873 end Model_Emin_Value;
1874
1875 -------------------------
1876 -- Model_Epsilon_Value --
1877 -------------------------
1878
1879 function Model_Epsilon_Value (Id : E) return Ureal is
1880 Radix : constant Ureal := UR_From_Uint (Machine_Radix_Value (Id));
1881 begin
1882 return Radix ** (1 - Model_Mantissa_Value (Id));
1883 end Model_Epsilon_Value;
1884
1885 --------------------------
1886 -- Model_Mantissa_Value --
1887 --------------------------
1888
1889 function Model_Mantissa_Value (Id : E) return Uint is
1890 begin
1891 return Machine_Mantissa_Value (Id);
1892 end Model_Mantissa_Value;
1893
1894 -----------------------
1895 -- Model_Small_Value --
1896 -----------------------
1897
1898 function Model_Small_Value (Id : E) return Ureal is
1899 Radix : constant Ureal := UR_From_Uint (Machine_Radix_Value (Id));
1900 begin
1901 return Radix ** (Model_Emin_Value (Id) - 1);
1902 end Model_Small_Value;
1903
1904 --------------------
1905 -- Next_Component --
1906 --------------------
1907
1908 function Next_Component (Id : E) return Entity_Id is
1909 Comp_Id : Entity_Id;
1910
1911 begin
1912 Comp_Id := Next_Entity (Id);
1913 while Present (Comp_Id) loop
1914 exit when Ekind (Comp_Id) = E_Component;
1915 Next_Entity (Comp_Id);
1916 end loop;
1917
1918 return Comp_Id;
1919 end Next_Component;
1920
1921 ------------------------------------
1922 -- Next_Component_Or_Discriminant --
1923 ------------------------------------
1924
1925 function Next_Component_Or_Discriminant (Id : E) return Entity_Id is
1926 Comp_Id : Entity_Id;
1927
1928 begin
1929 Comp_Id := Next_Entity (Id);
1930 while Present (Comp_Id) loop
1931 exit when Ekind (Comp_Id) in E_Component | E_Discriminant;
1932 Next_Entity (Comp_Id);
1933 end loop;
1934
1935 return Comp_Id;
1936 end Next_Component_Or_Discriminant;
1937
1938 -----------------------
1939 -- Next_Discriminant --
1940 -----------------------
1941
1942 -- This function actually implements both Next_Discriminant and
1943 -- Next_Stored_Discriminant by making sure that the Discriminant
1944 -- returned is of the same variety as Id.
1945
1946 function Next_Discriminant (Id : E) return Entity_Id is
1947
1948 -- Derived Tagged types with private extensions look like this...
1949
1950 -- E_Discriminant d1
1951 -- E_Discriminant d2
1952 -- E_Component _tag
1953 -- E_Discriminant d1
1954 -- E_Discriminant d2
1955 -- ...
1956
1957 -- so it is critical not to go past the leading discriminants
1958
1959 D : Entity_Id := Id;
1960
1961 begin
1962 pragma Assert (Ekind (Id) = E_Discriminant);
1963
1964 loop
1965 Next_Entity (D);
1966 if No (D)
1967 or else (Ekind (D) /= E_Discriminant
1968 and then not Is_Itype (D))
1969 then
1970 return Empty;
1971 end if;
1972
1973 exit when Ekind (D) = E_Discriminant
1974 and then Is_Completely_Hidden (D) = Is_Completely_Hidden (Id);
1975 end loop;
1976
1977 return D;
1978 end Next_Discriminant;
1979
1980 -----------------
1981 -- Next_Formal --
1982 -----------------
1983
1984 function Next_Formal (Id : E) return Entity_Id is
1985 P : Entity_Id;
1986
1987 begin
1988 -- Follow the chain of declared entities as long as the kind of the
1989 -- entity corresponds to a formal parameter. Skip internal entities
1990 -- that may have been created for implicit subtypes, in the process
1991 -- of analyzing default expressions.
1992
1993 P := Id;
1994 loop
1995 Next_Entity (P);
1996
1997 if No (P) or else Is_Formal (P) then
1998 return P;
1999 elsif not Is_Internal (P) then
2000 return Empty;
2001 end if;
2002 end loop;
2003 end Next_Formal;
2004
2005 -----------------------------
2006 -- Next_Formal_With_Extras --
2007 -----------------------------
2008
2009 function Next_Formal_With_Extras (Id : E) return Entity_Id is
2010 begin
2011 if Present (Extra_Formal (Id)) then
2012 return Extra_Formal (Id);
2013 else
2014 return Next_Formal (Id);
2015 end if;
2016 end Next_Formal_With_Extras;
2017
2018 ----------------
2019 -- Next_Index --
2020 ----------------
2021
2022 function Next_Index (Id : N) return Node_Id is
2023 pragma Assert (Nkind (Id) in N_Is_Index);
2024 Result : constant Node_Id := Next (Id);
2025 pragma Assert (No (Result) or else Nkind (Result) in N_Is_Index);
2026 begin
2027 return Result;
2028 end Next_Index;
2029
2030 ------------------
2031 -- Next_Literal --
2032 ------------------
2033
2034 function Next_Literal (Id : E) return Entity_Id is
2035 begin
2036 pragma Assert (Nkind (Id) in N_Entity);
2037 return Next (Id);
2038 end Next_Literal;
2039
2040 ------------------------------
2041 -- Next_Stored_Discriminant --
2042 ------------------------------
2043
2044 function Next_Stored_Discriminant (Id : E) return Entity_Id is
2045 begin
2046 -- See comment in Next_Discriminant
2047
2048 return Next_Discriminant (Id);
2049 end Next_Stored_Discriminant;
2050
2051 -----------------------
2052 -- Number_Dimensions --
2053 -----------------------
2054
2055 function Number_Dimensions (Id : E) return Pos is
2056 N : Int;
2057 T : Node_Id;
2058
2059 begin
2060 if Ekind (Id) = E_String_Literal_Subtype then
2061 return 1;
2062
2063 else
2064 N := 0;
2065 T := First_Index (Id);
2066 while Present (T) loop
2067 N := N + 1;
2068 Next_Index (T);
2069 end loop;
2070
2071 return N;
2072 end if;
2073 end Number_Dimensions;
2074
2075 --------------------
2076 -- Number_Entries --
2077 --------------------
2078
2079 function Number_Entries (Id : E) return Nat is
2080 N : Nat;
2081 Ent : Entity_Id;
2082
2083 begin
2084 pragma Assert (Is_Concurrent_Type (Id));
2085
2086 N := 0;
2087 Ent := First_Entity (Id);
2088 while Present (Ent) loop
2089 if Is_Entry (Ent) then
2090 N := N + 1;
2091 end if;
2092
2093 Next_Entity (Ent);
2094 end loop;
2095
2096 return N;
2097 end Number_Entries;
2098
2099 --------------------
2100 -- Number_Formals --
2101 --------------------
2102
2103 function Number_Formals (Id : E) return Nat is
2104 N : Nat;
2105 Formal : Entity_Id;
2106
2107 begin
2108 N := 0;
2109 Formal := First_Formal (Id);
2110 while Present (Formal) loop
2111 N := N + 1;
2112 Next_Formal (Formal);
2113 end loop;
2114
2115 return N;
2116 end Number_Formals;
2117
2118 ------------------------
2119 -- Object_Size_Clause --
2120 ------------------------
2121
2122 function Object_Size_Clause (Id : E) return Node_Id is
2123 begin
2124 return Get_Attribute_Definition_Clause (Id, Attribute_Object_Size);
2125 end Object_Size_Clause;
2126
2127 --------------------
2128 -- Parameter_Mode --
2129 --------------------
2130
2131 function Parameter_Mode (Id : E) return Formal_Kind is
2132 begin
2133 return Ekind (Id);
2134 end Parameter_Mode;
2135
2136 -------------------
2137 -- DIC_Procedure --
2138 -------------------
2139
2140 function DIC_Procedure (Id : E) return Entity_Id is
2141 Subp_Elmt : Elmt_Id;
2142 Subp_Id : Entity_Id;
2143 Subps : Elist_Id;
2144
2145 begin
2146 pragma Assert (Is_Type (Id));
2147
2148 Subps := Subprograms_For_Type (Base_Type (Id));
2149
2150 if Present (Subps) then
2151 Subp_Elmt := First_Elmt (Subps);
2152 while Present (Subp_Elmt) loop
2153 Subp_Id := Node (Subp_Elmt);
2154
2155 -- Currently the flag Is_DIC_Procedure is set for both normal DIC
2156 -- check procedures as well as for partial DIC check procedures,
2157 -- and we don't have a flag for the partial procedures.
2158
2159 if Is_DIC_Procedure (Subp_Id)
2160 and then not Is_Partial_DIC_Procedure (Subp_Id)
2161 then
2162 return Subp_Id;
2163 end if;
2164
2165 Next_Elmt (Subp_Elmt);
2166 end loop;
2167 end if;
2168
2169 return Empty;
2170 end DIC_Procedure;
2171
2172 function Partial_DIC_Procedure (Id : E) return Entity_Id is
2173 Subp_Elmt : Elmt_Id;
2174 Subp_Id : Entity_Id;
2175 Subps : Elist_Id;
2176
2177 begin
2178 pragma Assert (Is_Type (Id));
2179
2180 Subps := Subprograms_For_Type (Base_Type (Id));
2181
2182 if Present (Subps) then
2183 Subp_Elmt := First_Elmt (Subps);
2184 while Present (Subp_Elmt) loop
2185 Subp_Id := Node (Subp_Elmt);
2186
2187 if Is_Partial_DIC_Procedure (Subp_Id) then
2188 return Subp_Id;
2189 end if;
2190
2191 Next_Elmt (Subp_Elmt);
2192 end loop;
2193 end if;
2194
2195 return Empty;
2196 end Partial_DIC_Procedure;
2197
2198 function Is_Partial_DIC_Procedure (Id : E) return B is
2199 Partial_DIC_Suffix : constant String := "Partial_DIC";
2200 DIC_Nam : constant String := Get_Name_String (Chars (Id));
2201
2202 begin
2203 pragma Assert (Ekind (Id) in E_Function | E_Procedure);
2204
2205 -- Instead of adding a new Entity_Id flag (which are in short supply),
2206 -- we test the form of the subprogram name. When the node field and flag
2207 -- situation is eased, this should be replaced with a flag. ???
2208
2209 if DIC_Nam'Length > Partial_DIC_Suffix'Length
2210 and then
2211 DIC_Nam
2212 (DIC_Nam'Last - Partial_DIC_Suffix'Length + 1 .. DIC_Nam'Last) =
2213 Partial_DIC_Suffix
2214 then
2215 return True;
2216 else
2217 return False;
2218 end if;
2219 end Is_Partial_DIC_Procedure;
2220
2221 ---------------------------------
2222 -- Partial_Invariant_Procedure --
2223 ---------------------------------
2224
2225 function Partial_Invariant_Procedure (Id : E) return Entity_Id is
2226 Subp_Elmt : Elmt_Id;
2227 Subp_Id : Entity_Id;
2228 Subps : Elist_Id;
2229
2230 begin
2231 pragma Assert (Is_Type (Id));
2232
2233 Subps := Subprograms_For_Type (Base_Type (Id));
2234
2235 if Present (Subps) then
2236 Subp_Elmt := First_Elmt (Subps);
2237 while Present (Subp_Elmt) loop
2238 Subp_Id := Node (Subp_Elmt);
2239
2240 if Is_Partial_Invariant_Procedure (Subp_Id) then
2241 return Subp_Id;
2242 end if;
2243
2244 Next_Elmt (Subp_Elmt);
2245 end loop;
2246 end if;
2247
2248 return Empty;
2249 end Partial_Invariant_Procedure;
2250
2251 -------------------------------------
2252 -- Partial_Refinement_Constituents --
2253 -------------------------------------
2254
2255 function Partial_Refinement_Constituents (Id : E) return L is
2256 Constits : Elist_Id := No_Elist;
2257
2258 procedure Add_Usable_Constituents (Item : E);
2259 -- Add global item Item and/or its constituents to list Constits when
2260 -- they can be used in a global refinement within the current scope. The
2261 -- criteria are:
2262 -- 1) If Item is an abstract state with full refinement visible, add
2263 -- its constituents.
2264 -- 2) If Item is an abstract state with only partial refinement
2265 -- visible, add both Item and its constituents.
2266 -- 3) If Item is an abstract state without a visible refinement, add
2267 -- it.
2268 -- 4) If Id is not an abstract state, add it.
2269
2270 procedure Add_Usable_Constituents (List : Elist_Id);
2271 -- Apply Add_Usable_Constituents to every constituent in List
2272
2273 -----------------------------
2274 -- Add_Usable_Constituents --
2275 -----------------------------
2276
2277 procedure Add_Usable_Constituents (Item : E) is
2278 begin
2279 if Ekind (Item) = E_Abstract_State then
2280 if Has_Visible_Refinement (Item) then
2281 Add_Usable_Constituents (Refinement_Constituents (Item));
2282
2283 elsif Has_Partial_Visible_Refinement (Item) then
2284 Append_New_Elmt (Item, Constits);
2285 Add_Usable_Constituents (Part_Of_Constituents (Item));
2286
2287 else
2288 Append_New_Elmt (Item, Constits);
2289 end if;
2290
2291 else
2292 Append_New_Elmt (Item, Constits);
2293 end if;
2294 end Add_Usable_Constituents;
2295
2296 procedure Add_Usable_Constituents (List : Elist_Id) is
2297 Constit_Elmt : Elmt_Id;
2298 begin
2299 if Present (List) then
2300 Constit_Elmt := First_Elmt (List);
2301 while Present (Constit_Elmt) loop
2302 Add_Usable_Constituents (Node (Constit_Elmt));
2303 Next_Elmt (Constit_Elmt);
2304 end loop;
2305 end if;
2306 end Add_Usable_Constituents;
2307
2308 -- Start of processing for Partial_Refinement_Constituents
2309
2310 begin
2311 -- "Refinement" is a concept applicable only to abstract states
2312
2313 pragma Assert (Ekind (Id) = E_Abstract_State);
2314
2315 if Has_Visible_Refinement (Id) then
2316 Constits := Refinement_Constituents (Id);
2317
2318 -- A refinement may be partially visible when objects declared in the
2319 -- private part of a package are subject to a Part_Of indicator.
2320
2321 elsif Has_Partial_Visible_Refinement (Id) then
2322 Add_Usable_Constituents (Part_Of_Constituents (Id));
2323
2324 -- Function should only be called when full or partial refinement is
2325 -- visible.
2326
2327 else
2328 raise Program_Error;
2329 end if;
2330
2331 return Constits;
2332 end Partial_Refinement_Constituents;
2333
2334 ------------------------
2335 -- Predicate_Function --
2336 ------------------------
2337
2338 function Predicate_Function (Id : E) return Entity_Id is
2339 Subp_Elmt : Elmt_Id;
2340 Subp_Id : Entity_Id;
2341 Subps : Elist_Id;
2342 Typ : Entity_Id;
2343
2344 begin
2345 pragma Assert (Is_Type (Id));
2346
2347 -- If type is private and has a completion, predicate may be defined on
2348 -- the full view.
2349
2350 if Is_Private_Type (Id)
2351 and then
2352 (not Has_Predicates (Id) or else No (Subprograms_For_Type (Id)))
2353 and then Present (Full_View (Id))
2354 then
2355 Typ := Full_View (Id);
2356
2357 elsif Ekind (Id) in E_Array_Subtype
2358 | E_Record_Subtype
2359 | E_Record_Subtype_With_Private
2360 and then Present (Predicated_Parent (Id))
2361 then
2362 Typ := Predicated_Parent (Id);
2363
2364 else
2365 Typ := Id;
2366 end if;
2367
2368 Subps := Subprograms_For_Type (Typ);
2369
2370 if Present (Subps) then
2371 Subp_Elmt := First_Elmt (Subps);
2372 while Present (Subp_Elmt) loop
2373 Subp_Id := Node (Subp_Elmt);
2374
2375 if Ekind (Subp_Id) = E_Function
2376 and then Is_Predicate_Function (Subp_Id)
2377 then
2378 return Subp_Id;
2379 end if;
2380
2381 Next_Elmt (Subp_Elmt);
2382 end loop;
2383 end if;
2384
2385 return Empty;
2386 end Predicate_Function;
2387
2388 -------------------------
2389 -- Present_In_Rep_Item --
2390 -------------------------
2391
2392 function Present_In_Rep_Item (E : Entity_Id; N : Node_Id) return Boolean is
2393 Ritem : Node_Id;
2394
2395 begin
2396 Ritem := First_Rep_Item (E);
2397
2398 while Present (Ritem) loop
2399 if Ritem = N then
2400 return True;
2401 end if;
2402
2403 Next_Rep_Item (Ritem);
2404 end loop;
2405
2406 return False;
2407 end Present_In_Rep_Item;
2408
2409 --------------------------
2410 -- Primitive_Operations --
2411 --------------------------
2412
2413 function Primitive_Operations (Id : E) return L is
2414 begin
2415 if Is_Concurrent_Type (Id) then
2416 if Present (Corresponding_Record_Type (Id)) then
2417 return
2418 Direct_Primitive_Operations (Corresponding_Record_Type (Id));
2419
2420 -- When expansion is disabled, the corresponding record type is
2421 -- absent, but if this is a tagged type with ancestors, or if the
2422 -- extension of prefixed calls for untagged types is enabled, then
2423 -- it may have associated primitive operations.
2424
2425 else
2426 return Direct_Primitive_Operations (Id);
2427 end if;
2428
2429 else
2430 return Direct_Primitive_Operations (Id);
2431 end if;
2432 end Primitive_Operations;
2433
2434 ---------------------
2435 -- Record_Rep_Item --
2436 ---------------------
2437
2438 procedure Record_Rep_Item (E : Entity_Id; N : Node_Id) is
2439 begin
2440 Set_Next_Rep_Item (N, First_Rep_Item (E));
2441 Set_First_Rep_Item (E, N);
2442 end Record_Rep_Item;
2443
2444 -------------------
2445 -- Remove_Entity --
2446 -------------------
2447
2448 procedure Remove_Entity (Id : Entity_Id) is
2449 Next : constant Entity_Id := Next_Entity (Id);
2450 Prev : constant Entity_Id := Prev_Entity (Id);
2451 Scop : constant Entity_Id := Scope (Id);
2452 First : constant Entity_Id := First_Entity (Scop);
2453 Last : constant Entity_Id := Last_Entity (Scop);
2454
2455 begin
2456 -- Eliminate any existing linkages from the entity
2457
2458 Set_Prev_Entity (Id, Empty); -- Empty <-- Id
2459 Set_Next_Entity (Id, Empty); -- Id --> Empty
2460
2461 -- The eliminated entity was the only element in the entity chain
2462
2463 if Id = First and then Id = Last then
2464 Set_First_Entity (Scop, Empty);
2465 Set_Last_Entity (Scop, Empty);
2466
2467 -- The eliminated entity was the head of the entity chain
2468
2469 elsif Id = First then
2470 Set_First_Entity (Scop, Next);
2471 Set_Prev_Entity (Next, Empty); -- Empty <-- First_Entity
2472
2473 -- The eliminated entity was the tail of the entity chain
2474
2475 elsif Id = Last then
2476 Set_Last_Entity (Scop, Prev);
2477 Set_Next_Entity (Prev, Empty); -- Last_Entity --> Empty
2478
2479 -- Otherwise the eliminated entity comes from the middle of the entity
2480 -- chain.
2481
2482 else
2483 Link_Entities (Prev, Next); -- Prev <-- Next, Prev --> Next
2484 end if;
2485 end Remove_Entity;
2486
2487 ---------------
2488 -- Root_Type --
2489 ---------------
2490
2491 function Root_Type (Id : E) return E is
2492 T, Etyp : Entity_Id;
2493
2494 begin
2495 pragma Assert (Nkind (Id) in N_Entity);
2496
2497 T := Base_Type (Id);
2498
2499 if Ekind (T) = E_Class_Wide_Type then
2500 return Etype (T);
2501
2502 -- Other cases
2503
2504 else
2505 loop
2506 Etyp := Etype (T);
2507
2508 if T = Etyp then
2509 return T;
2510
2511 -- Following test catches some error cases resulting from
2512 -- previous errors.
2513
2514 elsif No (Etyp) then
2515 Check_Error_Detected;
2516 return T;
2517
2518 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
2519 return T;
2520
2521 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
2522 return T;
2523 end if;
2524
2525 T := Etyp;
2526
2527 -- Return if there is a circularity in the inheritance chain. This
2528 -- happens in some error situations and we do not want to get
2529 -- stuck in this loop.
2530
2531 if T = Base_Type (Id) then
2532 return T;
2533 end if;
2534 end loop;
2535 end if;
2536 end Root_Type;
2537
2538 ---------------------
2539 -- Safe_Emax_Value --
2540 ---------------------
2541
2542 function Safe_Emax_Value (Id : E) return Uint is
2543 begin
2544 return Machine_Emax_Value (Id);
2545 end Safe_Emax_Value;
2546
2547 ----------------------
2548 -- Safe_First_Value --
2549 ----------------------
2550
2551 function Safe_First_Value (Id : E) return Ureal is
2552 begin
2553 return -Safe_Last_Value (Id);
2554 end Safe_First_Value;
2555
2556 ---------------------
2557 -- Safe_Last_Value --
2558 ---------------------
2559
2560 function Safe_Last_Value (Id : E) return Ureal is
2561 Radix : constant Uint := Machine_Radix_Value (Id);
2562 Mantissa : constant Uint := Machine_Mantissa_Value (Id);
2563 Emax : constant Uint := Safe_Emax_Value (Id);
2564 Significand : constant Uint := Radix ** Mantissa - 1;
2565 Exponent : constant Uint := Emax - Mantissa;
2566
2567 begin
2568 if Radix = 2 then
2569 return
2570 UR_From_Components
2571 (Num => Significand * 2 ** (Exponent mod 4),
2572 Den => -Exponent / 4,
2573 Rbase => 16);
2574 else
2575 return
2576 UR_From_Components
2577 (Num => Significand,
2578 Den => -Exponent,
2579 Rbase => 16);
2580 end if;
2581 end Safe_Last_Value;
2582
2583 -----------------
2584 -- Scope_Depth --
2585 -----------------
2586
2587 function Scope_Depth (Id : Scope_Kind_Id) return Uint is
2588 Scop : Entity_Id;
2589
2590 begin
2591 Scop := Id;
2592 while Is_Record_Type (Scop) loop
2593 Scop := Scope (Scop);
2594 end loop;
2595
2596 return Scope_Depth_Value (Scop);
2597 end Scope_Depth;
2598
2599 function Scope_Depth_Default_0 (Id : Scope_Kind_Id) return U is
2600 begin
2601 if Scope_Depth_Set (Id) then
2602 return Scope_Depth (Id);
2603
2604 else
2605 return Uint_0;
2606 end if;
2607 end Scope_Depth_Default_0;
2608
2609 ---------------------
2610 -- Scope_Depth_Set --
2611 ---------------------
2612
2613 function Scope_Depth_Set (Id : Scope_Kind_Id) return B is
2614 begin
2615 return not Is_Record_Type (Id)
2616 and then not Field_Is_Initial_Zero (Id, F_Scope_Depth_Value);
2617 -- We can't call Scope_Depth_Value here, because Empty is not a valid
2618 -- value of type Uint.
2619 end Scope_Depth_Set;
2620
2621 --------------------
2622 -- Set_Convention --
2623 --------------------
2624
2625 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
2626 begin
2627 Set_Basic_Convention (E, Val);
2628
2629 if Ekind (E) in Access_Subprogram_Kind
2630 and then Has_Foreign_Convention (E)
2631 then
2632 Set_Can_Use_Internal_Rep (E, False);
2633 end if;
2634
2635 -- If E is an object, including a component, and the type of E is an
2636 -- anonymous access type with no convention set, then also set the
2637 -- convention of the anonymous access type. We do not do this for
2638 -- anonymous protected types, since protected types always have the
2639 -- default convention.
2640
2641 if Present (Etype (E))
2642 and then (Is_Object (E)
2643
2644 -- Allow E_Void (happens for pragma Convention appearing
2645 -- in the middle of a record applying to a component)
2646
2647 or else Ekind (E) = E_Void)
2648 then
2649 declare
2650 Typ : constant Entity_Id := Etype (E);
2651
2652 begin
2653 if Ekind (Typ) in E_Anonymous_Access_Type
2654 | E_Anonymous_Access_Subprogram_Type
2655 and then not Has_Convention_Pragma (Typ)
2656 then
2657 Set_Convention (Typ, Val);
2658 Set_Has_Convention_Pragma (Typ);
2659
2660 -- And for the access subprogram type, deal similarly with the
2661 -- designated E_Subprogram_Type, which is always internal.
2662
2663 if Ekind (Typ) = E_Anonymous_Access_Subprogram_Type then
2664 declare
2665 Dtype : constant Entity_Id := Designated_Type (Typ);
2666 begin
2667 if Ekind (Dtype) = E_Subprogram_Type then
2668 pragma Assert (not Has_Convention_Pragma (Dtype));
2669 Set_Convention (Dtype, Val);
2670 Set_Has_Convention_Pragma (Dtype);
2671 end if;
2672 end;
2673 end if;
2674 end if;
2675 end;
2676 end if;
2677 end Set_Convention;
2678
2679 -----------------------
2680 -- Set_DIC_Procedure --
2681 -----------------------
2682
2683 procedure Set_DIC_Procedure (Id : E; V : E) is
2684 Base_Typ : Entity_Id;
2685 Subps : Elist_Id;
2686
2687 begin
2688 pragma Assert (Is_Type (Id));
2689
2690 Base_Typ := Base_Type (Id);
2691 Subps := Subprograms_For_Type (Base_Typ);
2692
2693 if No (Subps) then
2694 Subps := New_Elmt_List;
2695 Set_Subprograms_For_Type (Base_Typ, Subps);
2696 end if;
2697
2698 Prepend_Elmt (V, Subps);
2699 end Set_DIC_Procedure;
2700
2701 procedure Set_Partial_DIC_Procedure (Id : E; V : E) is
2702 begin
2703 Set_DIC_Procedure (Id, V);
2704 end Set_Partial_DIC_Procedure;
2705
2706 -------------------
2707 -- Set_Float_Rep --
2708 -------------------
2709
2710 procedure Set_Float_Rep
2711 (Ignore_N : Entity_Id; Ignore_Val : Float_Rep_Kind) is
2712 begin
2713 pragma Assert (Float_Rep_Kind'First = Float_Rep_Kind'Last);
2714 -- There is only one value, so we don't need to store it (see
2715 -- types.ads).
2716 end Set_Float_Rep;
2717
2718 -----------------------------
2719 -- Set_Invariant_Procedure --
2720 -----------------------------
2721
2722 procedure Set_Invariant_Procedure (Id : E; V : E) is
2723 Base_Typ : Entity_Id;
2724 Subp_Elmt : Elmt_Id;
2725 Subp_Id : Entity_Id;
2726 Subps : Elist_Id;
2727
2728 begin
2729 pragma Assert (Is_Type (Id));
2730
2731 Base_Typ := Base_Type (Id);
2732 Subps := Subprograms_For_Type (Base_Typ);
2733
2734 if No (Subps) then
2735 Subps := New_Elmt_List;
2736 Set_Subprograms_For_Type (Base_Typ, Subps);
2737 end if;
2738
2739 Subp_Elmt := First_Elmt (Subps);
2740 Prepend_Elmt (V, Subps);
2741
2742 -- Check for a duplicate invariant procedure
2743
2744 while Present (Subp_Elmt) loop
2745 Subp_Id := Node (Subp_Elmt);
2746
2747 if Is_Invariant_Procedure (Subp_Id) then
2748 raise Program_Error;
2749 end if;
2750
2751 Next_Elmt (Subp_Elmt);
2752 end loop;
2753 end Set_Invariant_Procedure;
2754
2755 -------------------------------------
2756 -- Set_Partial_Invariant_Procedure --
2757 -------------------------------------
2758
2759 procedure Set_Partial_Invariant_Procedure (Id : E; V : E) is
2760 Base_Typ : Entity_Id;
2761 Subp_Elmt : Elmt_Id;
2762 Subp_Id : Entity_Id;
2763 Subps : Elist_Id;
2764
2765 begin
2766 pragma Assert (Is_Type (Id));
2767
2768 Base_Typ := Base_Type (Id);
2769 Subps := Subprograms_For_Type (Base_Typ);
2770
2771 if No (Subps) then
2772 Subps := New_Elmt_List;
2773 Set_Subprograms_For_Type (Base_Typ, Subps);
2774 end if;
2775
2776 Subp_Elmt := First_Elmt (Subps);
2777 Prepend_Elmt (V, Subps);
2778
2779 -- Check for a duplicate partial invariant procedure
2780
2781 while Present (Subp_Elmt) loop
2782 Subp_Id := Node (Subp_Elmt);
2783
2784 if Is_Partial_Invariant_Procedure (Subp_Id) then
2785 raise Program_Error;
2786 end if;
2787
2788 Next_Elmt (Subp_Elmt);
2789 end loop;
2790 end Set_Partial_Invariant_Procedure;
2791
2792 ----------------------------
2793 -- Set_Predicate_Function --
2794 ----------------------------
2795
2796 procedure Set_Predicate_Function (Id : E; V : E) is
2797 Subp_Elmt : Elmt_Id;
2798 Subp_Id : Entity_Id;
2799 Subps : Elist_Id;
2800
2801 begin
2802 pragma Assert (Is_Type (Id) and then Has_Predicates (Id));
2803
2804 Subps := Subprograms_For_Type (Id);
2805
2806 if No (Subps) then
2807 Subps := New_Elmt_List;
2808 Set_Subprograms_For_Type (Id, Subps);
2809 end if;
2810
2811 Subp_Elmt := First_Elmt (Subps);
2812 Prepend_Elmt (V, Subps);
2813
2814 -- Check for a duplicate predication function
2815
2816 while Present (Subp_Elmt) loop
2817 Subp_Id := Node (Subp_Elmt);
2818
2819 if Ekind (Subp_Id) = E_Function
2820 and then Is_Predicate_Function (Subp_Id)
2821 then
2822 raise Program_Error;
2823 end if;
2824
2825 Next_Elmt (Subp_Elmt);
2826 end loop;
2827 end Set_Predicate_Function;
2828
2829 -----------------
2830 -- Size_Clause --
2831 -----------------
2832
2833 function Size_Clause (Id : E) return Node_Id is
2834 Result : Node_Id := Get_Attribute_Definition_Clause (Id, Attribute_Size);
2835 begin
2836 if No (Result) then
2837 Result := Get_Attribute_Definition_Clause (Id, Attribute_Value_Size);
2838 end if;
2839
2840 return Result;
2841 end Size_Clause;
2842
2843 ------------------------
2844 -- Stream_Size_Clause --
2845 ------------------------
2846
2847 function Stream_Size_Clause (Id : E) return N is
2848 begin
2849 return Get_Attribute_Definition_Clause (Id, Attribute_Stream_Size);
2850 end Stream_Size_Clause;
2851
2852 ------------------
2853 -- Subtype_Kind --
2854 ------------------
2855
2856 function Subtype_Kind (K : Entity_Kind) return Entity_Kind is
2857 Kind : Entity_Kind;
2858
2859 begin
2860 case K is
2861 when Access_Kind =>
2862 Kind := E_Access_Subtype;
2863
2864 when E_Array_Subtype
2865 | E_Array_Type
2866 =>
2867 Kind := E_Array_Subtype;
2868
2869 when E_Class_Wide_Subtype
2870 | E_Class_Wide_Type
2871 =>
2872 Kind := E_Class_Wide_Subtype;
2873
2874 when E_Decimal_Fixed_Point_Subtype
2875 | E_Decimal_Fixed_Point_Type
2876 =>
2877 Kind := E_Decimal_Fixed_Point_Subtype;
2878
2879 when E_Ordinary_Fixed_Point_Subtype
2880 | E_Ordinary_Fixed_Point_Type
2881 =>
2882 Kind := E_Ordinary_Fixed_Point_Subtype;
2883
2884 when E_Private_Subtype
2885 | E_Private_Type
2886 =>
2887 Kind := E_Private_Subtype;
2888
2889 when E_Limited_Private_Subtype
2890 | E_Limited_Private_Type
2891 =>
2892 Kind := E_Limited_Private_Subtype;
2893
2894 when E_Record_Subtype_With_Private
2895 | E_Record_Type_With_Private
2896 =>
2897 Kind := E_Record_Subtype_With_Private;
2898
2899 when E_Record_Subtype
2900 | E_Record_Type
2901 =>
2902 Kind := E_Record_Subtype;
2903
2904 when Enumeration_Kind =>
2905 Kind := E_Enumeration_Subtype;
2906
2907 when E_Incomplete_Type =>
2908 Kind := E_Incomplete_Subtype;
2909
2910 when Float_Kind =>
2911 Kind := E_Floating_Point_Subtype;
2912
2913 when Signed_Integer_Kind =>
2914 Kind := E_Signed_Integer_Subtype;
2915
2916 when Modular_Integer_Kind =>
2917 Kind := E_Modular_Integer_Subtype;
2918
2919 when Protected_Kind =>
2920 Kind := E_Protected_Subtype;
2921
2922 when Task_Kind =>
2923 Kind := E_Task_Subtype;
2924
2925 when others =>
2926 raise Program_Error;
2927 end case;
2928
2929 return Kind;
2930 end Subtype_Kind;
2931
2932 ---------------------
2933 -- Type_High_Bound --
2934 ---------------------
2935
2936 function Type_High_Bound (Id : E) return N is
2937 Rng : constant Node_Id := Scalar_Range (Id);
2938 begin
2939 if Nkind (Rng) = N_Subtype_Indication then
2940 return High_Bound (Range_Expression (Constraint (Rng)));
2941 else
2942 return High_Bound (Rng);
2943 end if;
2944 end Type_High_Bound;
2945
2946 --------------------
2947 -- Type_Low_Bound --
2948 --------------------
2949
2950 function Type_Low_Bound (Id : E) return N is
2951 Rng : constant Node_Id := Scalar_Range (Id);
2952 begin
2953 if Nkind (Rng) = N_Subtype_Indication then
2954 return Low_Bound (Range_Expression (Constraint (Rng)));
2955 else
2956 return Low_Bound (Rng);
2957 end if;
2958 end Type_Low_Bound;
2959
2960 ---------------------
2961 -- Underlying_Type --
2962 ---------------------
2963
2964 function Underlying_Type (Id : E) return Entity_Id is
2965 begin
2966 -- For record_with_private the underlying type is always the direct full
2967 -- view. Never try to take the full view of the parent it does not make
2968 -- sense.
2969
2970 if Ekind (Id) = E_Record_Type_With_Private then
2971 return Full_View (Id);
2972
2973 -- If we have a class-wide type that comes from the limited view then we
2974 -- return the Underlying_Type of its nonlimited view.
2975
2976 elsif Ekind (Id) = E_Class_Wide_Type
2977 and then From_Limited_With (Id)
2978 and then Present (Non_Limited_View (Id))
2979 then
2980 return Underlying_Type (Non_Limited_View (Id));
2981
2982 elsif Ekind (Id) in Incomplete_Or_Private_Kind then
2983
2984 -- If we have an incomplete or private type with a full view, then we
2985 -- return the Underlying_Type of this full view.
2986
2987 if Present (Full_View (Id)) then
2988 if Id = Full_View (Id) then
2989
2990 -- Previous error in declaration
2991
2992 return Empty;
2993
2994 else
2995 return Underlying_Type (Full_View (Id));
2996 end if;
2997
2998 -- If we have a private type with an underlying full view, then we
2999 -- return the Underlying_Type of this underlying full view.
3000
3001 elsif Ekind (Id) in Private_Kind
3002 and then Present (Underlying_Full_View (Id))
3003 then
3004 return Underlying_Type (Underlying_Full_View (Id));
3005
3006 -- If we have an incomplete entity that comes from the limited view
3007 -- then we return the Underlying_Type of its nonlimited view.
3008
3009 elsif From_Limited_With (Id)
3010 and then Present (Non_Limited_View (Id))
3011 then
3012 return Underlying_Type (Non_Limited_View (Id));
3013
3014 -- Otherwise check for the case where we have a derived type or
3015 -- subtype, and if so get the Underlying_Type of the parent type.
3016
3017 elsif Present (Etype (Id)) and then Etype (Id) /= Id then
3018 return Underlying_Type (Etype (Id));
3019
3020 -- Otherwise we have an incomplete or private type that has no full
3021 -- view, which means that we have not encountered the completion, so
3022 -- return Empty to indicate the underlying type is not yet known.
3023
3024 else
3025 return Empty;
3026 end if;
3027
3028 -- For non-incomplete, non-private types, return the type itself. Also
3029 -- for entities that are not types at all return the entity itself.
3030
3031 else
3032 return Id;
3033 end if;
3034 end Underlying_Type;
3035
3036 ------------------------
3037 -- Unlink_Next_Entity --
3038 ------------------------
3039
3040 procedure Unlink_Next_Entity (Id : Entity_Id) is
3041 Next : constant Entity_Id := Next_Entity (Id);
3042
3043 begin
3044 if Present (Next) then
3045 Set_Prev_Entity (Next, Empty); -- Empty <-- Next
3046 end if;
3047
3048 Set_Next_Entity (Id, Empty); -- Id --> Empty
3049 end Unlink_Next_Entity;
3050
3051 ----------------------------------
3052 -- Is_Volatile, Set_Is_Volatile --
3053 ----------------------------------
3054
3055 function Is_Volatile (Id : E) return B is
3056 begin
3057 pragma Assert (Nkind (Id) in N_Entity);
3058
3059 if Is_Type (Id) then
3060 return Is_Volatile_Type (Base_Type (Id));
3061 else
3062 return Is_Volatile_Object (Id);
3063 end if;
3064 end Is_Volatile;
3065
3066 procedure Set_Is_Volatile (Id : E; V : B := True) is
3067 begin
3068 pragma Assert (Nkind (Id) in N_Entity);
3069
3070 if Is_Type (Id) then
3071 Set_Is_Volatile_Type (Id, V);
3072 else
3073 Set_Is_Volatile_Object (Id, V);
3074 end if;
3075 end Set_Is_Volatile;
3076
3077 -----------------------
3078 -- Write_Entity_Info --
3079 -----------------------
3080
3081 procedure Write_Entity_Info (Id : Entity_Id; Prefix : String) is
3082
3083 procedure Write_Attribute (Which : String; Nam : E);
3084 -- Write attribute value with given string name
3085
3086 procedure Write_Kind (Id : Entity_Id);
3087 -- Write Ekind field of entity
3088
3089 ---------------------
3090 -- Write_Attribute --
3091 ---------------------
3092
3093 procedure Write_Attribute (Which : String; Nam : E) is
3094 begin
3095 Write_Str (Prefix);
3096 Write_Str (Which);
3097 Write_Int (Int (Nam));
3098 Write_Str (" ");
3099 Write_Name (Chars (Nam));
3100 Write_Str (" ");
3101 end Write_Attribute;
3102
3103 ----------------
3104 -- Write_Kind --
3105 ----------------
3106
3107 procedure Write_Kind (Id : Entity_Id) is
3108 K : constant String := Entity_Kind'Image (Ekind (Id));
3109
3110 begin
3111 Write_Str (Prefix);
3112 Write_Str (" Kind ");
3113
3114 if Is_Type (Id) and then Is_Tagged_Type (Id) then
3115 Write_Str ("TAGGED ");
3116 end if;
3117
3118 Write_Str (K (3 .. K'Length));
3119 Write_Str (" ");
3120
3121 if Is_Type (Id) and then Depends_On_Private (Id) then
3122 Write_Str ("Depends_On_Private ");
3123 end if;
3124 end Write_Kind;
3125
3126 -- Start of processing for Write_Entity_Info
3127
3128 begin
3129 Write_Eol;
3130 Write_Attribute ("Name ", Id);
3131 Write_Int (Int (Id));
3132 Write_Eol;
3133 Write_Kind (Id);
3134 Write_Eol;
3135 Write_Attribute (" Type ", Etype (Id));
3136 Write_Eol;
3137 if Id /= Standard_Standard then
3138 Write_Attribute (" Scope ", Scope (Id));
3139 end if;
3140 Write_Eol;
3141
3142 case Ekind (Id) is
3143 when Discrete_Kind =>
3144 Write_Str ("Bounds: Id = ");
3145
3146 if Present (Scalar_Range (Id)) then
3147 Write_Int (Int (Type_Low_Bound (Id)));
3148 Write_Str (" .. Id = ");
3149 Write_Int (Int (Type_High_Bound (Id)));
3150 else
3151 Write_Str ("Empty");
3152 end if;
3153
3154 Write_Eol;
3155
3156 when Array_Kind =>
3157 declare
3158 Index : Entity_Id;
3159
3160 begin
3161 Write_Attribute
3162 (" Component Type ", Component_Type (Id));
3163 Write_Eol;
3164 Write_Str (Prefix);
3165 Write_Str (" Indexes ");
3166
3167 Index := First_Index (Id);
3168 while Present (Index) loop
3169 Write_Attribute (" ", Etype (Index));
3170 Next_Index (Index);
3171 end loop;
3172
3173 Write_Eol;
3174 end;
3175
3176 when Access_Kind =>
3177 Write_Attribute
3178 (" Directly Designated Type ",
3179 Directly_Designated_Type (Id));
3180 Write_Eol;
3181
3182 when Overloadable_Kind =>
3183 if Present (Homonym (Id)) then
3184 Write_Str (" Homonym ");
3185 Write_Name (Chars (Homonym (Id)));
3186 Write_Str (" ");
3187 Write_Int (Int (Homonym (Id)));
3188 Write_Eol;
3189 end if;
3190
3191 Write_Eol;
3192
3193 when E_Component =>
3194 if Ekind (Scope (Id)) in Record_Kind then
3195 Write_Attribute (
3196 " Original_Record_Component ",
3197 Original_Record_Component (Id));
3198 Write_Int (Int (Original_Record_Component (Id)));
3199 Write_Eol;
3200 end if;
3201
3202 when others =>
3203 null;
3204 end case;
3205 end Write_Entity_Info;
3206
3207 -------------------------
3208 -- Iterator Procedures --
3209 -------------------------
3210
3211 procedure Next_Component (N : in out Node_Id) is
3212 begin
3213 N := Next_Component (N);
3214 end Next_Component;
3215
3216 procedure Next_Component_Or_Discriminant (N : in out Node_Id) is
3217 begin
3218 N := Next_Component_Or_Discriminant (N);
3219 end Next_Component_Or_Discriminant;
3220
3221 procedure Next_Discriminant (N : in out Node_Id) is
3222 begin
3223 N := Next_Discriminant (N);
3224 end Next_Discriminant;
3225
3226 procedure Next_Formal (N : in out Node_Id) is
3227 begin
3228 N := Next_Formal (N);
3229 end Next_Formal;
3230
3231 procedure Next_Formal_With_Extras (N : in out Node_Id) is
3232 begin
3233 N := Next_Formal_With_Extras (N);
3234 end Next_Formal_With_Extras;
3235
3236 procedure Next_Index (N : in out Node_Id) is
3237 begin
3238 N := Next_Index (N);
3239 end Next_Index;
3240
3241 procedure Next_Inlined_Subprogram (N : in out Node_Id) is
3242 begin
3243 N := Next_Inlined_Subprogram (N);
3244 end Next_Inlined_Subprogram;
3245
3246 procedure Next_Literal (N : in out Node_Id) is
3247 begin
3248 N := Next_Literal (N);
3249 end Next_Literal;
3250
3251 procedure Next_Stored_Discriminant (N : in out Node_Id) is
3252 begin
3253 N := Next_Stored_Discriminant (N);
3254 end Next_Stored_Discriminant;
3255
3256 end Einfo.Utils;