ee23d17c5295b29654d2050e54b94577f7cac756
[platform/upstream/gcc.git] / gcc / ada / sem_aux.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                              S E M _ A U X                               --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --          Copyright (C) 1992-2010, 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 -- As a special exception,  if other files  instantiate  generics from this --
22 -- unit, or you link  this unit with other files  to produce an executable, --
23 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
24 -- covered  by the  GNU  General  Public  License.  This exception does not --
25 -- however invalidate  any other reasons why  the executable file  might be --
26 -- covered by the  GNU Public License.                                      --
27 --                                                                          --
28 -- GNAT was originally developed  by the GNAT team at  New York University. --
29 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
30 --                                                                          --
31 ------------------------------------------------------------------------------
32
33 with Atree;  use Atree;
34 with Einfo;  use Einfo;
35 with Namet;  use Namet;
36 with Sinfo;  use Sinfo;
37 with Snames; use Snames;
38 with Stand;  use Stand;
39
40 package body Sem_Aux is
41
42    ----------------------
43    -- Ancestor_Subtype --
44    ----------------------
45
46    function Ancestor_Subtype (Typ : Entity_Id) return Entity_Id is
47    begin
48       --  If this is first subtype, or is a base type, then there is no
49       --  ancestor subtype, so we return Empty to indicate this fact.
50
51       if Is_First_Subtype (Typ) or else Typ = Base_Type (Typ) then
52          return Empty;
53       end if;
54
55       declare
56          D : constant Node_Id := Declaration_Node (Typ);
57
58       begin
59          --  If we have a subtype declaration, get the ancestor subtype
60
61          if Nkind (D) = N_Subtype_Declaration then
62             if Nkind (Subtype_Indication (D)) = N_Subtype_Indication then
63                return Entity (Subtype_Mark (Subtype_Indication (D)));
64             else
65                return Entity (Subtype_Indication (D));
66             end if;
67
68          --  If not, then no subtype indication is available
69
70          else
71             return Empty;
72          end if;
73       end;
74    end Ancestor_Subtype;
75
76    --------------------
77    -- Available_View --
78    --------------------
79
80    function Available_View (Typ : Entity_Id) return Entity_Id is
81    begin
82       if Is_Incomplete_Type (Typ)
83         and then Present (Non_Limited_View (Typ))
84       then
85          --  The non-limited view may itself be an incomplete type, in which
86          --  case get its full view.
87
88          return Get_Full_View (Non_Limited_View (Typ));
89
90       elsif Is_Class_Wide_Type (Typ)
91         and then Is_Incomplete_Type (Etype (Typ))
92         and then Present (Non_Limited_View (Etype (Typ)))
93       then
94          return Class_Wide_Type (Non_Limited_View (Etype (Typ)));
95
96       else
97          return Typ;
98       end if;
99    end Available_View;
100
101    --------------------
102    -- Constant_Value --
103    --------------------
104
105    function Constant_Value (Ent : Entity_Id) return Node_Id is
106       D      : constant Node_Id := Declaration_Node (Ent);
107       Full_D : Node_Id;
108
109    begin
110       --  If we have no declaration node, then return no constant value. Not
111       --  clear how this can happen, but it does sometimes and this is the
112       --  safest approach.
113
114       if No (D) then
115          return Empty;
116
117       --  Normal case where a declaration node is present
118
119       elsif Nkind (D) = N_Object_Renaming_Declaration then
120          return Renamed_Object (Ent);
121
122       --  If this is a component declaration whose entity is a constant, it is
123       --  a prival within a protected function (and so has no constant value).
124
125       elsif Nkind (D) = N_Component_Declaration then
126          return Empty;
127
128       --  If there is an expression, return it
129
130       elsif Present (Expression (D)) then
131          return (Expression (D));
132
133       --  For a constant, see if we have a full view
134
135       elsif Ekind (Ent) = E_Constant
136         and then Present (Full_View (Ent))
137       then
138          Full_D := Parent (Full_View (Ent));
139
140          --  The full view may have been rewritten as an object renaming
141
142          if Nkind (Full_D) = N_Object_Renaming_Declaration then
143             return Name (Full_D);
144          else
145             return Expression (Full_D);
146          end if;
147
148       --  Otherwise we have no expression to return
149
150       else
151          return Empty;
152       end if;
153    end Constant_Value;
154
155    -----------------------------
156    -- Enclosing_Dynamic_Scope --
157    -----------------------------
158
159    function Enclosing_Dynamic_Scope (Ent : Entity_Id) return Entity_Id is
160       S : Entity_Id;
161
162    begin
163       --  The following test is an error defense against some syntax errors
164       --  that can leave scopes very messed up.
165
166       if Ent = Standard_Standard then
167          return Ent;
168       end if;
169
170       --  Normal case, search enclosing scopes
171
172       --  Note: the test for Present (S) should not be required, it defends
173       --  against an ill-formed tree.
174
175       S := Scope (Ent);
176       loop
177          --  If we somehow got an empty value for Scope, the tree must be
178          --  malformed. Rather than blow up we return Standard in this case.
179
180          if No (S) then
181             return Standard_Standard;
182
183          --  Quit if we get to standard or a dynamic scope
184
185          elsif S = Standard_Standard
186            or else Is_Dynamic_Scope (S)
187          then
188             return S;
189
190          --  Otherwise keep climbing
191
192          else
193             S := Scope (S);
194          end if;
195       end loop;
196    end Enclosing_Dynamic_Scope;
197
198    ------------------------
199    -- First_Discriminant --
200    ------------------------
201
202    function First_Discriminant (Typ : Entity_Id) return Entity_Id is
203       Ent : Entity_Id;
204
205    begin
206       pragma Assert
207         (Has_Discriminants (Typ) or else Has_Unknown_Discriminants (Typ));
208
209       Ent := First_Entity (Typ);
210
211       --  The discriminants are not necessarily contiguous, because access
212       --  discriminants will generate itypes. They are not the first entities
213       --  either, because tag and controller record must be ahead of them.
214
215       if Chars (Ent) = Name_uTag then
216          Ent := Next_Entity (Ent);
217       end if;
218
219       if Chars (Ent) = Name_uController then
220          Ent := Next_Entity (Ent);
221       end if;
222
223       --  Skip all hidden stored discriminants if any
224
225       while Present (Ent) loop
226          exit when Ekind (Ent) = E_Discriminant
227            and then not Is_Completely_Hidden (Ent);
228
229          Ent := Next_Entity (Ent);
230       end loop;
231
232       pragma Assert (Ekind (Ent) = E_Discriminant);
233
234       return Ent;
235    end First_Discriminant;
236
237    -------------------------------
238    -- First_Stored_Discriminant --
239    -------------------------------
240
241    function First_Stored_Discriminant (Typ : Entity_Id) return Entity_Id is
242       Ent : Entity_Id;
243
244       function Has_Completely_Hidden_Discriminant
245         (Typ : Entity_Id) return Boolean;
246       --  Scans the Discriminants to see whether any are Completely_Hidden
247       --  (the mechanism for describing non-specified stored discriminants)
248
249       ----------------------------------------
250       -- Has_Completely_Hidden_Discriminant --
251       ----------------------------------------
252
253       function Has_Completely_Hidden_Discriminant
254         (Typ : Entity_Id) return Boolean
255       is
256          Ent : Entity_Id;
257
258       begin
259          pragma Assert (Ekind (Typ) = E_Discriminant);
260
261          Ent := Typ;
262          while Present (Ent) and then Ekind (Ent) = E_Discriminant loop
263             if Is_Completely_Hidden (Ent) then
264                return True;
265             end if;
266
267             Ent := Next_Entity (Ent);
268          end loop;
269
270          return False;
271       end Has_Completely_Hidden_Discriminant;
272
273    --  Start of processing for First_Stored_Discriminant
274
275    begin
276       pragma Assert
277         (Has_Discriminants (Typ)
278           or else Has_Unknown_Discriminants (Typ));
279
280       Ent := First_Entity (Typ);
281
282       if Chars (Ent) = Name_uTag then
283          Ent := Next_Entity (Ent);
284       end if;
285
286       if Chars (Ent) = Name_uController then
287          Ent := Next_Entity (Ent);
288       end if;
289
290       if Has_Completely_Hidden_Discriminant (Ent) then
291
292          while Present (Ent) loop
293             exit when Is_Completely_Hidden (Ent);
294             Ent := Next_Entity (Ent);
295          end loop;
296
297       end if;
298
299       pragma Assert (Ekind (Ent) = E_Discriminant);
300
301       return Ent;
302    end First_Stored_Discriminant;
303
304    -------------------
305    -- First_Subtype --
306    -------------------
307
308    function First_Subtype (Typ : Entity_Id) return Entity_Id is
309       B   : constant Entity_Id := Base_Type (Typ);
310       F   : constant Node_Id   := Freeze_Node (B);
311       Ent : Entity_Id;
312
313    begin
314       --  If the base type has no freeze node, it is a type in Standard, and
315       --  always acts as its own first subtype, except where it is one of the
316       --  predefined integer types. If the type is formal, it is also a first
317       --  subtype, and its base type has no freeze node. On the other hand, a
318       --  subtype of a generic formal is not its own first subtype. Its base
319       --  type, if anonymous, is attached to the formal type decl. from which
320       --  the first subtype is obtained.
321
322       if No (F) then
323          if B = Base_Type (Standard_Integer) then
324             return Standard_Integer;
325
326          elsif B = Base_Type (Standard_Long_Integer) then
327             return Standard_Long_Integer;
328
329          elsif B = Base_Type (Standard_Short_Short_Integer) then
330             return Standard_Short_Short_Integer;
331
332          elsif B = Base_Type (Standard_Short_Integer) then
333             return Standard_Short_Integer;
334
335          elsif B = Base_Type (Standard_Long_Long_Integer) then
336             return Standard_Long_Long_Integer;
337
338          elsif Is_Generic_Type (Typ) then
339             if Present (Parent (B)) then
340                return Defining_Identifier (Parent (B));
341             else
342                return Defining_Identifier (Associated_Node_For_Itype (B));
343             end if;
344
345          else
346             return B;
347          end if;
348
349       --  Otherwise we check the freeze node, if it has a First_Subtype_Link
350       --  then we use that link, otherwise (happens with some Itypes), we use
351       --  the base type itself.
352
353       else
354          Ent := First_Subtype_Link (F);
355
356          if Present (Ent) then
357             return Ent;
358          else
359             return B;
360          end if;
361       end if;
362    end First_Subtype;
363
364    -------------------------
365    -- First_Tag_Component --
366    -------------------------
367
368    function First_Tag_Component (Typ : Entity_Id) return Entity_Id is
369       Comp : Entity_Id;
370       Ctyp : Entity_Id;
371
372    begin
373       Ctyp := Typ;
374       pragma Assert (Is_Tagged_Type (Ctyp));
375
376       if Is_Class_Wide_Type (Ctyp) then
377          Ctyp := Root_Type (Ctyp);
378       end if;
379
380       if Is_Private_Type (Ctyp) then
381          Ctyp := Underlying_Type (Ctyp);
382
383          --  If the underlying type is missing then the source program has
384          --  errors and there is nothing else to do (the full-type declaration
385          --  associated with the private type declaration is missing).
386
387          if No (Ctyp) then
388             return Empty;
389          end if;
390       end if;
391
392       Comp := First_Entity (Ctyp);
393       while Present (Comp) loop
394          if Is_Tag (Comp) then
395             return Comp;
396          end if;
397
398          Comp := Next_Entity (Comp);
399       end loop;
400
401       --  No tag component found
402
403       return Empty;
404    end First_Tag_Component;
405
406    ----------------
407    -- Initialize --
408    ----------------
409
410    procedure Initialize is
411    begin
412       Obsolescent_Warnings.Init;
413    end Initialize;
414
415    ---------------------
416    -- Is_By_Copy_Type --
417    ---------------------
418
419    function Is_By_Copy_Type (Ent : Entity_Id) return Boolean is
420    begin
421       --  If Id is a private type whose full declaration has not been seen,
422       --  we assume for now that it is not a By_Copy type. Clearly this
423       --  attribute should not be used before the type is frozen, but it is
424       --  needed to build the associated record of a protected type. Another
425       --  place where some lookahead for a full view is needed ???
426
427       return
428         Is_Elementary_Type (Ent)
429           or else (Is_Private_Type (Ent)
430                      and then Present (Underlying_Type (Ent))
431                      and then Is_Elementary_Type (Underlying_Type (Ent)));
432    end Is_By_Copy_Type;
433
434    --------------------------
435    -- Is_By_Reference_Type --
436    --------------------------
437
438    function Is_By_Reference_Type (Ent : Entity_Id) return Boolean is
439       Btype : constant Entity_Id := Base_Type (Ent);
440
441    begin
442       if Error_Posted (Ent)
443         or else Error_Posted (Btype)
444       then
445          return False;
446
447       elsif Is_Private_Type (Btype) then
448          declare
449             Utyp : constant Entity_Id := Underlying_Type (Btype);
450          begin
451             if No (Utyp) then
452                return False;
453             else
454                return Is_By_Reference_Type (Utyp);
455             end if;
456          end;
457
458       elsif Is_Incomplete_Type (Btype) then
459          declare
460             Ftyp : constant Entity_Id := Full_View (Btype);
461          begin
462             if No (Ftyp) then
463                return False;
464             else
465                return Is_By_Reference_Type (Ftyp);
466             end if;
467          end;
468
469       elsif Is_Concurrent_Type (Btype) then
470          return True;
471
472       elsif Is_Record_Type (Btype) then
473          if Is_Limited_Record (Btype)
474            or else Is_Tagged_Type (Btype)
475            or else Is_Volatile (Btype)
476          then
477             return True;
478
479          else
480             declare
481                C : Entity_Id;
482
483             begin
484                C := First_Component (Btype);
485                while Present (C) loop
486                   if Is_By_Reference_Type (Etype (C))
487                     or else Is_Volatile (Etype (C))
488                   then
489                      return True;
490                   end if;
491
492                   C := Next_Component (C);
493                end loop;
494             end;
495
496             return False;
497          end if;
498
499       elsif Is_Array_Type (Btype) then
500          return
501            Is_Volatile (Btype)
502              or else Is_By_Reference_Type (Component_Type (Btype))
503              or else Is_Volatile (Component_Type (Btype))
504              or else Has_Volatile_Components (Btype);
505
506       else
507          return False;
508       end if;
509    end Is_By_Reference_Type;
510
511    ---------------------
512    -- Is_Derived_Type --
513    ---------------------
514
515    function Is_Derived_Type (Ent : E) return B is
516       Par : Node_Id;
517
518    begin
519       if Is_Type (Ent)
520         and then Base_Type (Ent) /= Root_Type (Ent)
521         and then not Is_Class_Wide_Type (Ent)
522       then
523          if not Is_Numeric_Type (Root_Type (Ent)) then
524             return True;
525
526          else
527             Par := Parent (First_Subtype (Ent));
528
529             return Present (Par)
530               and then Nkind (Par) = N_Full_Type_Declaration
531               and then Nkind (Type_Definition (Par)) =
532                          N_Derived_Type_Definition;
533          end if;
534
535       else
536          return False;
537       end if;
538    end Is_Derived_Type;
539
540    ---------------------------
541    -- Is_Indefinite_Subtype --
542    ---------------------------
543
544    function Is_Indefinite_Subtype (Ent : Entity_Id) return Boolean is
545       K : constant Entity_Kind := Ekind (Ent);
546
547    begin
548       if Is_Constrained (Ent) then
549          return False;
550
551       elsif K in Array_Kind
552         or else K in Class_Wide_Kind
553         or else Has_Unknown_Discriminants (Ent)
554       then
555          return True;
556
557       --  Known discriminants: indefinite if there are no default values
558
559       elsif K in Record_Kind
560         or else Is_Incomplete_Or_Private_Type (Ent)
561         or else Is_Concurrent_Type (Ent)
562       then
563          return (Has_Discriminants (Ent)
564            and then
565              No (Discriminant_Default_Value (First_Discriminant (Ent))));
566
567       else
568          return False;
569       end if;
570    end Is_Indefinite_Subtype;
571
572    -------------------------------
573    -- Is_Immutably_Limited_Type --
574    -------------------------------
575
576    function Is_Immutably_Limited_Type (Ent : Entity_Id) return Boolean is
577       Btype : constant Entity_Id := Base_Type (Ent);
578
579    begin
580       if Is_Limited_Record (Btype) then
581          return True;
582
583       elsif Ekind (Btype) = E_Limited_Private_Type
584         and then Nkind (Parent (Btype)) = N_Formal_Type_Declaration
585       then
586          return not In_Package_Body (Scope ((Btype)));
587       end if;
588
589       if Is_Private_Type (Btype) then
590
591          --  AI05-0063: A type derived from a limited private formal type is
592          --  not immutably limited in a generic body.
593
594          if Is_Derived_Type (Btype)
595            and then Is_Generic_Type (Etype (Btype))
596          then
597             if not Is_Limited_Type (Etype (Btype)) then
598                return False;
599
600             --  A descendant of a limited formal type is not immutably limited
601             --  in the generic body, or in the body of a generic child.
602
603             elsif Ekind (Scope (Etype (Btype))) = E_Generic_Package then
604                return not In_Package_Body (Scope (Btype));
605
606             else
607                return False;
608             end if;
609
610          else
611             declare
612                Utyp : constant Entity_Id := Underlying_Type (Btype);
613             begin
614                if No (Utyp) then
615                   return False;
616                else
617                   return Is_Immutably_Limited_Type (Utyp);
618                end if;
619             end;
620          end if;
621
622       elsif Is_Concurrent_Type (Btype) then
623          return True;
624
625       elsif Is_Record_Type (Btype) then
626
627          --  Note that we return True for all limited interfaces, even though
628          --  (unsynchronized) limited interfaces can have descendants that are
629          --  nonlimited, because this is a predicate on the type itself, and
630          --  things like functions with limited interface results need to be
631          --  handled as build in place even though they might return objects
632          --  of a type that is not inherently limited.
633
634          if Is_Class_Wide_Type (Btype) then
635             return Is_Immutably_Limited_Type (Root_Type (Btype));
636
637          else
638             declare
639                C : Entity_Id;
640
641             begin
642                C := First_Component (Btype);
643                while Present (C) loop
644
645                   --  Don't consider components with interface types (which can
646                   --  only occur in the case of a _parent component anyway).
647                   --  They don't have any components, plus it would cause this
648                   --  function to return true for nonlimited types derived from
649                   --  limited intefaces.
650
651                   if not Is_Interface (Etype (C))
652                     and then Is_Immutably_Limited_Type (Etype (C))
653                   then
654                      return True;
655                   end if;
656
657                   C := Next_Component (C);
658                end loop;
659             end;
660
661             return False;
662          end if;
663
664       elsif Is_Array_Type (Btype) then
665          return Is_Immutably_Limited_Type (Component_Type (Btype));
666
667       else
668          return False;
669       end if;
670    end Is_Immutably_Limited_Type;
671
672    ---------------------
673    -- Is_Limited_Type --
674    ---------------------
675
676    function Is_Limited_Type (Ent : Entity_Id) return Boolean is
677       Btype : constant E := Base_Type (Ent);
678       Rtype : constant E := Root_Type (Btype);
679
680    begin
681       if not Is_Type (Ent) then
682          return False;
683
684       elsif Ekind (Btype) = E_Limited_Private_Type
685         or else Is_Limited_Composite (Btype)
686       then
687          return True;
688
689       elsif Is_Concurrent_Type (Btype) then
690          return True;
691
692          --  The Is_Limited_Record flag normally indicates that the type is
693          --  limited. The exception is that a type does not inherit limitedness
694          --  from its interface ancestor. So the type may be derived from a
695          --  limited interface, but is not limited.
696
697       elsif Is_Limited_Record (Ent)
698         and then not Is_Interface (Ent)
699       then
700          return True;
701
702       --  Otherwise we will look around to see if there is some other reason
703       --  for it to be limited, except that if an error was posted on the
704       --  entity, then just assume it is non-limited, because it can cause
705       --  trouble to recurse into a murky erroneous entity!
706
707       elsif Error_Posted (Ent) then
708          return False;
709
710       elsif Is_Record_Type (Btype) then
711
712          if Is_Limited_Interface (Ent) then
713             return True;
714
715          --  AI-419: limitedness is not inherited from a limited interface
716
717          elsif Is_Limited_Record (Rtype) then
718             return not Is_Interface (Rtype)
719               or else Is_Protected_Interface (Rtype)
720               or else Is_Synchronized_Interface (Rtype)
721               or else Is_Task_Interface (Rtype);
722
723          elsif Is_Class_Wide_Type (Btype) then
724             return Is_Limited_Type (Rtype);
725
726          else
727             declare
728                C : E;
729
730             begin
731                C := First_Component (Btype);
732                while Present (C) loop
733                   if Is_Limited_Type (Etype (C)) then
734                      return True;
735                   end if;
736
737                   C := Next_Component (C);
738                end loop;
739             end;
740
741             return False;
742          end if;
743
744       elsif Is_Array_Type (Btype) then
745          return Is_Limited_Type (Component_Type (Btype));
746
747       else
748          return False;
749       end if;
750    end Is_Limited_Type;
751
752    ----------------------
753    -- Nearest_Ancestor --
754    ----------------------
755
756    function Nearest_Ancestor (Typ : Entity_Id) return Entity_Id is
757          D : constant Node_Id := Declaration_Node (Typ);
758
759    begin
760       --  If we have a subtype declaration, get the ancestor subtype
761
762       if Nkind (D) = N_Subtype_Declaration then
763          if Nkind (Subtype_Indication (D)) = N_Subtype_Indication then
764             return Entity (Subtype_Mark (Subtype_Indication (D)));
765          else
766             return Entity (Subtype_Indication (D));
767          end if;
768
769       --  If derived type declaration, find who we are derived from
770
771       elsif Nkind (D) = N_Full_Type_Declaration
772         and then Nkind (Type_Definition (D)) = N_Derived_Type_Definition
773       then
774          declare
775             DTD : constant Entity_Id := Type_Definition (D);
776             SI  : constant Entity_Id := Subtype_Indication (DTD);
777          begin
778             if Is_Entity_Name (SI) then
779                return Entity (SI);
780             else
781                return Entity (Subtype_Mark (SI));
782             end if;
783          end;
784
785       --  Otherwise, nothing useful to return, return Empty
786
787       else
788          return Empty;
789       end if;
790    end Nearest_Ancestor;
791
792    ---------------------------
793    -- Nearest_Dynamic_Scope --
794    ---------------------------
795
796    function Nearest_Dynamic_Scope (Ent : Entity_Id) return Entity_Id is
797    begin
798       if Is_Dynamic_Scope (Ent) then
799          return Ent;
800       else
801          return Enclosing_Dynamic_Scope (Ent);
802       end if;
803    end Nearest_Dynamic_Scope;
804
805    ------------------------
806    -- Next_Tag_Component --
807    ------------------------
808
809    function Next_Tag_Component (Tag : Entity_Id) return Entity_Id is
810       Comp : Entity_Id;
811
812    begin
813       pragma Assert (Is_Tag (Tag));
814
815       --  Loop to look for next tag component
816
817       Comp := Next_Entity (Tag);
818       while Present (Comp) loop
819          if Is_Tag (Comp) then
820             pragma Assert (Chars (Comp) /= Name_uTag);
821             return Comp;
822          end if;
823
824          Comp := Next_Entity (Comp);
825       end loop;
826
827       --  No tag component found
828
829       return Empty;
830    end Next_Tag_Component;
831
832    --------------------------
833    -- Number_Discriminants --
834    --------------------------
835
836    function Number_Discriminants (Typ : Entity_Id) return Pos is
837       N     : Int;
838       Discr : Entity_Id;
839
840    begin
841       N := 0;
842       Discr := First_Discriminant (Typ);
843       while Present (Discr) loop
844          N := N + 1;
845          Discr := Next_Discriminant (Discr);
846       end loop;
847
848       return N;
849    end Number_Discriminants;
850
851    ---------------
852    -- Tree_Read --
853    ---------------
854
855    procedure Tree_Read is
856    begin
857       Obsolescent_Warnings.Tree_Read;
858    end Tree_Read;
859
860    ----------------
861    -- Tree_Write --
862    ----------------
863
864    procedure Tree_Write is
865    begin
866       Obsolescent_Warnings.Tree_Write;
867    end Tree_Write;
868
869    --------------------
870    -- Ultimate_Alias --
871    --------------------
872
873    function Ultimate_Alias (Prim : Entity_Id) return Entity_Id is
874       E : Entity_Id := Prim;
875
876    begin
877       while Present (Alias (E)) loop
878          pragma Assert (Alias (E) /= E);
879          E := Alias (E);
880       end loop;
881
882       return E;
883    end Ultimate_Alias;
884
885 end Sem_Aux;