[multiple changes]
[gcc.git] / gcc / ada / lib-xref.adb
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- L I B . X R E F --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1998-2012, 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 Csets; use Csets;
28 with Elists; use Elists;
29 with Errout; use Errout;
30 with Nlists; use Nlists;
31 with Opt; use Opt;
32 with Restrict; use Restrict;
33 with Rident; use Rident;
34 with Sem; use Sem;
35 with Sem_Aux; use Sem_Aux;
36 with Sem_Prag; use Sem_Prag;
37 with Sem_Util; use Sem_Util;
38 with Sem_Warn; use Sem_Warn;
39 with Sinfo; use Sinfo;
40 with Sinput; use Sinput;
41 with Snames; use Snames;
42 with Stringt; use Stringt;
43 with Stand; use Stand;
44 with Table; use Table;
45
46 with GNAT.Heap_Sort_G;
47 with GNAT.HTable;
48
49 package body Lib.Xref is
50
51 ------------------
52 -- Declarations --
53 ------------------
54
55 -- The Xref table is used to record references. The Loc field is set
56 -- to No_Location for a definition entry.
57
58 subtype Xref_Entry_Number is Int;
59
60 type Xref_Key is record
61 -- These are the components of Xref_Entry that participate in hash
62 -- lookups.
63
64 Ent : Entity_Id;
65 -- Entity referenced (E parameter to Generate_Reference)
66
67 Loc : Source_Ptr;
68 -- Location of reference (Original_Location (Sloc field of N parameter
69 -- to Generate_Reference). Set to No_Location for the case of a
70 -- defining occurrence.
71
72 Typ : Character;
73 -- Reference type (Typ param to Generate_Reference)
74
75 Eun : Unit_Number_Type;
76 -- Unit number corresponding to Ent
77
78 Lun : Unit_Number_Type;
79 -- Unit number corresponding to Loc. Value is undefined and not
80 -- referenced if Loc is set to No_Location.
81
82 -- The following components are only used for Alfa cross-references
83
84 Ref_Scope : Entity_Id;
85 -- Entity of the closest subprogram or package enclosing the reference
86
87 Ent_Scope : Entity_Id;
88 -- Entity of the closest subprogram or package enclosing the definition,
89 -- which should be located in the same file as the definition itself.
90 end record;
91
92 type Xref_Entry is record
93 Key : Xref_Key;
94
95 Ent_Scope_File : Unit_Number_Type;
96 -- File for entity Ent_Scope
97
98 Def : Source_Ptr;
99 -- Original source location for entity being referenced. Note that these
100 -- values are used only during the output process, they are not set when
101 -- the entries are originally built. This is because private entities
102 -- can be swapped when the initial call is made.
103
104 HTable_Next : Xref_Entry_Number;
105 -- For use only by Static_HTable
106 end record;
107
108 package Xrefs is new Table.Table (
109 Table_Component_Type => Xref_Entry,
110 Table_Index_Type => Xref_Entry_Number,
111 Table_Low_Bound => 1,
112 Table_Initial => Alloc.Xrefs_Initial,
113 Table_Increment => Alloc.Xrefs_Increment,
114 Table_Name => "Xrefs");
115
116 --------------
117 -- Xref_Set --
118 --------------
119
120 -- We keep a set of xref entries, in order to avoid inserting duplicate
121 -- entries into the above Xrefs table. An entry is in Xref_Set if and only
122 -- if it is in Xrefs.
123
124 Num_Buckets : constant := 2**16;
125
126 subtype Header_Num is Integer range 0 .. Num_Buckets - 1;
127 type Null_Type is null record;
128 pragma Unreferenced (Null_Type);
129
130 function Hash (F : Xref_Entry_Number) return Header_Num;
131
132 function Equal (F1, F2 : Xref_Entry_Number) return Boolean;
133
134 procedure HT_Set_Next (E : Xref_Entry_Number; Next : Xref_Entry_Number);
135
136 function HT_Next (E : Xref_Entry_Number) return Xref_Entry_Number;
137
138 function Get_Key (E : Xref_Entry_Number) return Xref_Entry_Number;
139
140 pragma Inline (Hash, Equal, HT_Set_Next, HT_Next, Get_Key);
141
142 package Xref_Set is new GNAT.HTable.Static_HTable (
143 Header_Num,
144 Element => Xref_Entry,
145 Elmt_Ptr => Xref_Entry_Number,
146 Null_Ptr => 0,
147 Set_Next => HT_Set_Next,
148 Next => HT_Next,
149 Key => Xref_Entry_Number,
150 Get_Key => Get_Key,
151 Hash => Hash,
152 Equal => Equal);
153
154 ----------------------
155 -- Alfa Information --
156 ----------------------
157
158 package body Alfa is separate;
159
160 ------------------------
161 -- Local Subprograms --
162 ------------------------
163
164 procedure Add_Entry (Key : Xref_Key; Ent_Scope_File : Unit_Number_Type);
165 -- Add an entry to the tables of Xref_Entries, avoiding duplicates
166
167 procedure Generate_Prim_Op_References (Typ : Entity_Id);
168 -- For a tagged type, generate implicit references to its primitive
169 -- operations, for source navigation. This is done right before emitting
170 -- cross-reference information rather than at the freeze point of the type
171 -- in order to handle late bodies that are primitive operations.
172
173 function Lt (T1, T2 : Xref_Entry) return Boolean;
174 -- Order cross-references
175
176 ---------------
177 -- Add_Entry --
178 ---------------
179
180 procedure Add_Entry (Key : Xref_Key; Ent_Scope_File : Unit_Number_Type) is
181 begin
182 Xrefs.Increment_Last; -- tentative
183 Xrefs.Table (Xrefs.Last).Key := Key;
184
185 -- Set the entry in Xref_Set, and if newly set, keep the above
186 -- tentative increment.
187
188 if Xref_Set.Set_If_Not_Present (Xrefs.Last) then
189 Xrefs.Table (Xrefs.Last).Ent_Scope_File := Ent_Scope_File;
190 -- Leave Def and HTable_Next uninitialized
191
192 Set_Has_Xref_Entry (Key.Ent);
193
194 -- It was already in Xref_Set, so throw away the tentatively-added
195 -- entry
196
197 else
198 Xrefs.Decrement_Last;
199 end if;
200 end Add_Entry;
201
202 -----------
203 -- Equal --
204 -----------
205
206 function Equal (F1, F2 : Xref_Entry_Number) return Boolean is
207 Result : constant Boolean :=
208 Xrefs.Table (F1).Key = Xrefs.Table (F2).Key;
209 begin
210 return Result;
211 end Equal;
212
213 -------------------------
214 -- Generate_Definition --
215 -------------------------
216
217 procedure Generate_Definition (E : Entity_Id) is
218 begin
219 pragma Assert (Nkind (E) in N_Entity);
220
221 -- Note that we do not test Xref_Entity_Letters here. It is too early
222 -- to do so, since we are often called before the entity is fully
223 -- constructed, so that the Ekind is still E_Void.
224
225 if Opt.Xref_Active
226
227 -- Definition must come from source
228
229 -- We make an exception for subprogram child units that have no spec.
230 -- For these we generate a subprogram declaration for library use,
231 -- and the corresponding entity does not come from source.
232 -- Nevertheless, all references will be attached to it and we have
233 -- to treat is as coming from user code.
234
235 and then (Comes_From_Source (E) or else Is_Child_Unit (E))
236
237 -- And must have a reasonable source location that is not
238 -- within an instance (all entities in instances are ignored)
239
240 and then Sloc (E) > No_Location
241 and then Instantiation_Location (Sloc (E)) = No_Location
242
243 -- And must be a non-internal name from the main source unit
244
245 and then In_Extended_Main_Source_Unit (E)
246 and then not Is_Internal_Name (Chars (E))
247 then
248 Add_Entry
249 ((Ent => E,
250 Loc => No_Location,
251 Typ => ' ',
252 Eun => Get_Source_Unit (Original_Location (Sloc (E))),
253 Lun => No_Unit,
254 Ref_Scope => Empty,
255 Ent_Scope => Empty),
256 Ent_Scope_File => No_Unit);
257
258 if In_Inlined_Body then
259 Set_Referenced (E);
260 end if;
261 end if;
262 end Generate_Definition;
263
264 ---------------------------------
265 -- Generate_Operator_Reference --
266 ---------------------------------
267
268 procedure Generate_Operator_Reference
269 (N : Node_Id;
270 T : Entity_Id)
271 is
272 begin
273 if not In_Extended_Main_Source_Unit (N) then
274 return;
275 end if;
276
277 -- If the operator is not a Standard operator, then we generate a real
278 -- reference to the user defined operator.
279
280 if Sloc (Entity (N)) /= Standard_Location then
281 Generate_Reference (Entity (N), N);
282
283 -- A reference to an implicit inequality operator is also a reference
284 -- to the user-defined equality.
285
286 if Nkind (N) = N_Op_Ne
287 and then not Comes_From_Source (Entity (N))
288 and then Present (Corresponding_Equality (Entity (N)))
289 then
290 Generate_Reference (Corresponding_Equality (Entity (N)), N);
291 end if;
292
293 -- For the case of Standard operators, we mark the result type as
294 -- referenced. This ensures that in the case where we are using a
295 -- derived operator, we mark an entity of the unit that implicitly
296 -- defines this operator as used. Otherwise we may think that no entity
297 -- of the unit is used. The actual entity marked as referenced is the
298 -- first subtype, which is the relevant user defined entity.
299
300 -- Note: we only do this for operators that come from source. The
301 -- generated code sometimes reaches for entities that do not need to be
302 -- explicitly visible (for example, when we expand the code for
303 -- comparing two record objects, the fields of the record may not be
304 -- visible).
305
306 elsif Comes_From_Source (N) then
307 Set_Referenced (First_Subtype (T));
308 end if;
309 end Generate_Operator_Reference;
310
311 ---------------------------------
312 -- Generate_Prim_Op_References --
313 ---------------------------------
314
315 procedure Generate_Prim_Op_References (Typ : Entity_Id) is
316 Base_T : Entity_Id;
317 Prim : Elmt_Id;
318 Prim_List : Elist_Id;
319
320 begin
321 -- Handle subtypes of synchronized types
322
323 if Ekind (Typ) = E_Protected_Subtype
324 or else Ekind (Typ) = E_Task_Subtype
325 then
326 Base_T := Etype (Typ);
327 else
328 Base_T := Typ;
329 end if;
330
331 -- References to primitive operations are only relevant for tagged types
332
333 if not Is_Tagged_Type (Base_T)
334 or else Is_Class_Wide_Type (Base_T)
335 then
336 return;
337 end if;
338
339 -- Ada 2005 (AI-345): For synchronized types generate reference to the
340 -- wrapper that allow us to dispatch calls through their implemented
341 -- abstract interface types.
342
343 -- The check for Present here is to protect against previously reported
344 -- critical errors.
345
346 Prim_List := Primitive_Operations (Base_T);
347
348 if No (Prim_List) then
349 return;
350 end if;
351
352 Prim := First_Elmt (Prim_List);
353 while Present (Prim) loop
354
355 -- If the operation is derived, get the original for cross-reference
356 -- reference purposes (it is the original for which we want the xref
357 -- and for which the comes_from_source test must be performed).
358
359 Generate_Reference
360 (Typ, Ultimate_Alias (Node (Prim)), 'p', Set_Ref => False);
361 Next_Elmt (Prim);
362 end loop;
363 end Generate_Prim_Op_References;
364
365 ------------------------
366 -- Generate_Reference --
367 ------------------------
368
369 procedure Generate_Reference
370 (E : Entity_Id;
371 N : Node_Id;
372 Typ : Character := 'r';
373 Set_Ref : Boolean := True;
374 Force : Boolean := False)
375 is
376 Actual_Typ : Character := Typ;
377 Call : Node_Id;
378 Def : Source_Ptr;
379 Ent : Entity_Id;
380 Ent_Scope : Entity_Id;
381 Ent_Scope_File : Unit_Number_Type;
382 Formal : Entity_Id;
383 Kind : Entity_Kind;
384 Nod : Node_Id;
385 Ref : Source_Ptr;
386 Ref_Scope : Entity_Id;
387
388 function Get_Through_Renamings (E : Entity_Id) return Entity_Id;
389 -- Get the enclosing entity through renamings, which may come from
390 -- source or from the translation of generic instantiations.
391
392 function Is_On_LHS (Node : Node_Id) return Boolean;
393 -- Used to check if a node is on the left hand side of an assignment.
394 -- The following cases are handled:
395 --
396 -- Variable Node is a direct descendant of left hand side of an
397 -- assignment statement.
398 --
399 -- Prefix Of an indexed or selected component that is present in
400 -- a subtree rooted by an assignment statement. There is
401 -- no restriction of nesting of components, thus cases
402 -- such as A.B (C).D are handled properly. However a prefix
403 -- of a dereference (either implicit or explicit) is never
404 -- considered as on a LHS.
405 --
406 -- Out param Same as above cases, but OUT parameter
407
408 function OK_To_Set_Referenced return Boolean;
409 -- Returns True if the Referenced flag can be set. There are a few
410 -- exceptions where we do not want to set this flag, see body for
411 -- details of these exceptional cases.
412
413 ---------------------------
414 -- Get_Through_Renamings --
415 ---------------------------
416
417 function Get_Through_Renamings (E : Entity_Id) return Entity_Id is
418 Result : Entity_Id := E;
419 begin
420 while Present (Result)
421 and then Is_Object (Result)
422 and then Present (Renamed_Object (Result))
423 loop
424 Result := Get_Enclosing_Object (Renamed_Object (Result));
425 end loop;
426 return Result;
427 end Get_Through_Renamings;
428
429 ---------------
430 -- Is_On_LHS --
431 ---------------
432
433 -- ??? There are several routines here and there that perform a similar
434 -- (but subtly different) computation, which should be factored:
435
436 -- Sem_Util.May_Be_Lvalue
437 -- Sem_Util.Known_To_Be_Assigned
438 -- Exp_Ch2.Expand_Entry_Parameter.In_Assignment_Context
439 -- Exp_Smem.Is_Out_Actual
440
441 function Is_On_LHS (Node : Node_Id) return Boolean is
442 N : Node_Id;
443 P : Node_Id;
444 K : Node_Kind;
445
446 begin
447 -- Only identifiers are considered, is this necessary???
448
449 if Nkind (Node) /= N_Identifier then
450 return False;
451 end if;
452
453 -- Immediate return if appeared as OUT parameter
454
455 if Kind = E_Out_Parameter then
456 return True;
457 end if;
458
459 -- Search for assignment statement subtree root
460
461 N := Node;
462 loop
463 P := Parent (N);
464 K := Nkind (P);
465
466 if K = N_Assignment_Statement then
467 return Name (P) = N;
468
469 -- Check whether the parent is a component and the current node is
470 -- its prefix, but return False if the current node has an access
471 -- type, as in that case the selected or indexed component is an
472 -- implicit dereference, and the LHS is the designated object, not
473 -- the access object.
474
475 -- ??? case of a slice assignment?
476
477 -- ??? Note that in some cases this is called too early
478 -- (see comments in Sem_Ch8.Find_Direct_Name), at a point where
479 -- the tree is not fully typed yet. In that case we may lack
480 -- an Etype for N, and we must disable the check for an implicit
481 -- dereference. If the dereference is on an LHS, this causes a
482 -- false positive.
483
484 elsif (K = N_Selected_Component or else K = N_Indexed_Component)
485 and then Prefix (P) = N
486 and then not (Present (Etype (N))
487 and then
488 Is_Access_Type (Etype (N)))
489 then
490 N := P;
491
492 -- All other cases, definitely not on left side
493
494 else
495 return False;
496 end if;
497 end loop;
498 end Is_On_LHS;
499
500 ---------------------------
501 -- OK_To_Set_Referenced --
502 ---------------------------
503
504 function OK_To_Set_Referenced return Boolean is
505 P : Node_Id;
506
507 begin
508 -- A reference from a pragma Unreferenced or pragma Unmodified or
509 -- pragma Warnings does not cause the Referenced flag to be set.
510 -- This avoids silly warnings about things being referenced and
511 -- not assigned when the only reference is from the pragma.
512
513 if Nkind (N) = N_Identifier then
514 P := Parent (N);
515
516 if Nkind (P) = N_Pragma_Argument_Association then
517 P := Parent (P);
518
519 if Nkind (P) = N_Pragma then
520 if Pragma_Name (P) = Name_Warnings
521 or else
522 Pragma_Name (P) = Name_Unmodified
523 or else
524 Pragma_Name (P) = Name_Unreferenced
525 then
526 return False;
527 end if;
528 end if;
529
530 -- A reference to a formal in a named parameter association does
531 -- not make the formal referenced. Formals that are unused in the
532 -- subprogram body are properly flagged as such, even if calls
533 -- elsewhere use named notation.
534
535 elsif Nkind (P) = N_Parameter_Association
536 and then N = Selector_Name (P)
537 then
538 return False;
539 end if;
540 end if;
541
542 return True;
543 end OK_To_Set_Referenced;
544
545 -- Start of processing for Generate_Reference
546
547 begin
548 pragma Assert (Nkind (E) in N_Entity);
549 Find_Actual (N, Formal, Call);
550
551 if Present (Formal) then
552 Kind := Ekind (Formal);
553 else
554 Kind := E_Void;
555 end if;
556
557 -- Check for obsolescent reference to package ASCII. GNAT treats this
558 -- element of annex J specially since in practice, programs make a lot
559 -- of use of this feature, so we don't include it in the set of features
560 -- diagnosed when Warn_On_Obsolescent_Features mode is set. However we
561 -- are required to note it as a violation of the RM defined restriction.
562
563 if E = Standard_ASCII then
564 Check_Restriction (No_Obsolescent_Features, N);
565 end if;
566
567 -- Check for reference to entity marked with Is_Obsolescent
568
569 -- Note that we always allow obsolescent references in the compiler
570 -- itself and the run time, since we assume that we know what we are
571 -- doing in such cases. For example the calls in Ada.Characters.Handling
572 -- to its own obsolescent subprograms are just fine.
573
574 -- In any case we only generate warnings if we are in the extended main
575 -- source unit, and the entity itself is not in the extended main source
576 -- unit, since we assume the source unit itself knows what is going on
577 -- (and for sure we do not want silly warnings, e.g. on the end line of
578 -- an obsolescent procedure body).
579
580 if Is_Obsolescent (E)
581 and then not GNAT_Mode
582 and then not In_Extended_Main_Source_Unit (E)
583 and then In_Extended_Main_Source_Unit (N)
584 then
585 Check_Restriction (No_Obsolescent_Features, N);
586
587 if Warn_On_Obsolescent_Feature then
588 Output_Obsolescent_Entity_Warnings (N, E);
589 end if;
590 end if;
591
592 -- Warn if reference to Ada 2005 entity not in Ada 2005 mode. We only
593 -- detect real explicit references (modifications and references).
594
595 if Comes_From_Source (N)
596 and then Is_Ada_2005_Only (E)
597 and then Ada_Version < Ada_2005
598 and then Warn_On_Ada_2005_Compatibility
599 and then (Typ = 'm' or else Typ = 'r' or else Typ = 's')
600 then
601 Error_Msg_NE ("& is only defined in Ada 2005?", N, E);
602 end if;
603
604 -- Warn if reference to Ada 2012 entity not in Ada 2012 mode. We only
605 -- detect real explicit references (modifications and references).
606
607 if Comes_From_Source (N)
608 and then Is_Ada_2012_Only (E)
609 and then Ada_Version < Ada_2012
610 and then Warn_On_Ada_2012_Compatibility
611 and then (Typ = 'm' or else Typ = 'r')
612 then
613 Error_Msg_NE ("& is only defined in Ada 2012?", N, E);
614 end if;
615
616 -- Never collect references if not in main source unit. However, we omit
617 -- this test if Typ is 'e' or 'k', since these entries are structural,
618 -- and it is useful to have them in units that reference packages as
619 -- well as units that define packages. We also omit the test for the
620 -- case of 'p' since we want to include inherited primitive operations
621 -- from other packages.
622
623 -- We also omit this test is this is a body reference for a subprogram
624 -- instantiation. In this case the reference is to the generic body,
625 -- which clearly need not be in the main unit containing the instance.
626 -- For the same reason we accept an implicit reference generated for
627 -- a default in an instance.
628
629 if not In_Extended_Main_Source_Unit (N) then
630 if Typ = 'e'
631 or else Typ = 'I'
632 or else Typ = 'p'
633 or else Typ = 'i'
634 or else Typ = 'k'
635 or else (Typ = 'b' and then Is_Generic_Instance (E))
636 then
637 null;
638 else
639 return;
640 end if;
641 end if;
642
643 -- For reference type p, the entity must be in main source unit
644
645 if Typ = 'p' and then not In_Extended_Main_Source_Unit (E) then
646 return;
647 end if;
648
649 -- Unless the reference is forced, we ignore references where the
650 -- reference itself does not come from source.
651
652 if not Force and then not Comes_From_Source (N) then
653 return;
654 end if;
655
656 -- Deal with setting entity as referenced, unless suppressed. Note that
657 -- we still do Set_Referenced on entities that do not come from source.
658 -- This situation arises when we have a source reference to a derived
659 -- operation, where the derived operation itself does not come from
660 -- source, but we still want to mark it as referenced, since we really
661 -- are referencing an entity in the corresponding package (this avoids
662 -- wrong complaints that the package contains no referenced entities).
663
664 if Set_Ref then
665
666 -- Assignable object appearing on left side of assignment or as
667 -- an out parameter.
668
669 if Is_Assignable (E)
670 and then Is_On_LHS (N)
671 and then Ekind (E) /= E_In_Out_Parameter
672 then
673 -- For objects that are renamings, just set as simply referenced
674 -- we do not try to do assignment type tracking in this case.
675
676 if Present (Renamed_Object (E)) then
677 Set_Referenced (E);
678
679 -- Out parameter case
680
681 elsif Kind = E_Out_Parameter then
682
683 -- If warning mode for all out parameters is set, or this is
684 -- the only warning parameter, then we want to mark this for
685 -- later warning logic by setting Referenced_As_Out_Parameter
686
687 if Warn_On_Modified_As_Out_Parameter (Formal) then
688 Set_Referenced_As_Out_Parameter (E, True);
689 Set_Referenced_As_LHS (E, False);
690
691 -- For OUT parameter not covered by the above cases, we simply
692 -- regard it as a normal reference (in this case we do not
693 -- want any of the warning machinery for out parameters).
694
695 else
696 Set_Referenced (E);
697 end if;
698
699 -- For the left hand of an assignment case, we do nothing here.
700 -- The processing for Analyze_Assignment_Statement will set the
701 -- Referenced_As_LHS flag.
702
703 else
704 null;
705 end if;
706
707 -- Check for a reference in a pragma that should not count as a
708 -- making the variable referenced for warning purposes.
709
710 elsif Is_Non_Significant_Pragma_Reference (N) then
711 null;
712
713 -- A reference in an attribute definition clause does not count as a
714 -- reference except for the case of Address. The reason that 'Address
715 -- is an exception is that it creates an alias through which the
716 -- variable may be referenced.
717
718 elsif Nkind (Parent (N)) = N_Attribute_Definition_Clause
719 and then Chars (Parent (N)) /= Name_Address
720 and then N = Name (Parent (N))
721 then
722 null;
723
724 -- Constant completion does not count as a reference
725
726 elsif Typ = 'c'
727 and then Ekind (E) = E_Constant
728 then
729 null;
730
731 -- Record representation clause does not count as a reference
732
733 elsif Nkind (N) = N_Identifier
734 and then Nkind (Parent (N)) = N_Record_Representation_Clause
735 then
736 null;
737
738 -- Discriminants do not need to produce a reference to record type
739
740 elsif Typ = 'd'
741 and then Nkind (Parent (N)) = N_Discriminant_Specification
742 then
743 null;
744
745 -- All other cases
746
747 else
748 -- Special processing for IN OUT parameters, where we have an
749 -- implicit assignment to a simple variable.
750
751 if Kind = E_In_Out_Parameter
752 and then Is_Assignable (E)
753 then
754 -- For sure this counts as a normal read reference
755
756 Set_Referenced (E);
757 Set_Last_Assignment (E, Empty);
758
759 -- We count it as being referenced as an out parameter if the
760 -- option is set to warn on all out parameters, except that we
761 -- have a special exclusion for an intrinsic subprogram, which
762 -- is most likely an instantiation of Unchecked_Deallocation
763 -- which we do not want to consider as an assignment since it
764 -- generates false positives. We also exclude the case of an
765 -- IN OUT parameter if the name of the procedure is Free,
766 -- since we suspect similar semantics.
767
768 if Warn_On_All_Unread_Out_Parameters
769 and then Is_Entity_Name (Name (Call))
770 and then not Is_Intrinsic_Subprogram (Entity (Name (Call)))
771 and then Chars (Name (Call)) /= Name_Free
772 then
773 Set_Referenced_As_Out_Parameter (E, True);
774 Set_Referenced_As_LHS (E, False);
775 end if;
776
777 -- Don't count a recursive reference within a subprogram as a
778 -- reference (that allows detection of a recursive subprogram
779 -- whose only references are recursive calls as unreferenced).
780
781 elsif Is_Subprogram (E)
782 and then E = Nearest_Dynamic_Scope (Current_Scope)
783 then
784 null;
785
786 -- Any other occurrence counts as referencing the entity
787
788 elsif OK_To_Set_Referenced then
789 Set_Referenced (E);
790
791 -- If variable, this is an OK reference after an assignment
792 -- so we can clear the Last_Assignment indication.
793
794 if Is_Assignable (E) then
795 Set_Last_Assignment (E, Empty);
796 end if;
797 end if;
798 end if;
799
800 -- Check for pragma Unreferenced given and reference is within
801 -- this source unit (occasion for possible warning to be issued).
802
803 if Has_Unreferenced (E)
804 and then In_Same_Extended_Unit (E, N)
805 then
806 -- A reference as a named parameter in a call does not count
807 -- as a violation of pragma Unreferenced for this purpose...
808
809 if Nkind (N) = N_Identifier
810 and then Nkind (Parent (N)) = N_Parameter_Association
811 and then Selector_Name (Parent (N)) = N
812 then
813 null;
814
815 -- ... Neither does a reference to a variable on the left side
816 -- of an assignment.
817
818 elsif Is_On_LHS (N) then
819 null;
820
821 -- For entry formals, we want to place the warning message on the
822 -- corresponding entity in the accept statement. The current scope
823 -- is the body of the accept, so we find the formal whose name
824 -- matches that of the entry formal (there is no link between the
825 -- two entities, and the one in the accept statement is only used
826 -- for conformance checking).
827
828 elsif Ekind (Scope (E)) = E_Entry then
829 declare
830 BE : Entity_Id;
831
832 begin
833 BE := First_Entity (Current_Scope);
834 while Present (BE) loop
835 if Chars (BE) = Chars (E) then
836 Error_Msg_NE -- CODEFIX
837 ("?pragma Unreferenced given for&!", N, BE);
838 exit;
839 end if;
840
841 Next_Entity (BE);
842 end loop;
843 end;
844
845 -- Here we issue the warning, since this is a real reference
846
847 else
848 Error_Msg_NE -- CODEFIX
849 ("?pragma Unreferenced given for&!", N, E);
850 end if;
851 end if;
852
853 -- If this is a subprogram instance, mark as well the internal
854 -- subprogram in the wrapper package, which may be a visible
855 -- compilation unit.
856
857 if Is_Overloadable (E)
858 and then Is_Generic_Instance (E)
859 and then Present (Alias (E))
860 then
861 Set_Referenced (Alias (E));
862 end if;
863 end if;
864
865 -- Generate reference if all conditions are met:
866
867 if
868 -- Cross referencing must be active
869
870 Opt.Xref_Active
871
872 -- The entity must be one for which we collect references
873
874 and then Xref_Entity_Letters (Ekind (E)) /= ' '
875
876 -- Both Sloc values must be set to something sensible
877
878 and then Sloc (E) > No_Location
879 and then Sloc (N) > No_Location
880
881 -- Ignore references from within an instance. The only exceptions to
882 -- this are default subprograms, for which we generate an implicit
883 -- reference.
884
885 and then
886 (Instantiation_Location (Sloc (N)) = No_Location
887 or else Typ = 'i')
888
889 -- Ignore dummy references
890
891 and then Typ /= ' '
892 then
893 if Nkind (N) = N_Identifier
894 or else
895 Nkind (N) = N_Defining_Identifier
896 or else
897 Nkind (N) in N_Op
898 or else
899 Nkind (N) = N_Defining_Operator_Symbol
900 or else
901 Nkind (N) = N_Operator_Symbol
902 or else
903 (Nkind (N) = N_Character_Literal
904 and then Sloc (Entity (N)) /= Standard_Location)
905 or else
906 Nkind (N) = N_Defining_Character_Literal
907 then
908 Nod := N;
909
910 elsif Nkind (N) = N_Expanded_Name
911 or else
912 Nkind (N) = N_Selected_Component
913 then
914 Nod := Selector_Name (N);
915
916 else
917 return;
918 end if;
919
920 -- Normal case of source entity comes from source
921
922 if Comes_From_Source (E) then
923 Ent := E;
924
925 -- Entity does not come from source, but is a derived subprogram and
926 -- the derived subprogram comes from source (after one or more
927 -- derivations) in which case the reference is to parent subprogram.
928
929 elsif Is_Overloadable (E)
930 and then Present (Alias (E))
931 then
932 Ent := Alias (E);
933 while not Comes_From_Source (Ent) loop
934 if No (Alias (Ent)) then
935 return;
936 end if;
937
938 Ent := Alias (Ent);
939 end loop;
940
941 -- The internally created defining entity for a child subprogram
942 -- that has no previous spec has valid references.
943
944 elsif Is_Overloadable (E)
945 and then Is_Child_Unit (E)
946 then
947 Ent := E;
948
949 -- Record components of discriminated subtypes or derived types must
950 -- be treated as references to the original component.
951
952 elsif Ekind (E) = E_Component
953 and then Comes_From_Source (Original_Record_Component (E))
954 then
955 Ent := Original_Record_Component (E);
956
957 -- If this is an expanded reference to a discriminant, recover the
958 -- original discriminant, which gets the reference.
959
960 elsif Ekind (E) = E_In_Parameter
961 and then Present (Discriminal_Link (E))
962 then
963 Ent := Discriminal_Link (E);
964 Set_Referenced (Ent);
965
966 -- Ignore reference to any other entity that is not from source
967
968 else
969 return;
970 end if;
971
972 -- In Alfa mode, consider the underlying entity renamed instead of
973 -- the renaming, which is needed to compute a valid set of effects
974 -- (reads, writes) for the enclosing subprogram.
975
976 if Alfa_Mode then
977 Ent := Get_Through_Renamings (Ent);
978
979 -- If no enclosing object, then it could be a reference to any
980 -- location not tracked individually, like heap-allocated data.
981 -- Conservatively approximate this possibility by generating a
982 -- dereference, and return.
983
984 if No (Ent) then
985 if Actual_Typ = 'w' then
986 Alfa.Generate_Dereference (Nod, 'r');
987 Alfa.Generate_Dereference (Nod, 'w');
988 else
989 Alfa.Generate_Dereference (Nod, 'r');
990 end if;
991
992 return;
993 end if;
994 end if;
995
996 -- Record reference to entity
997
998 Ref := Original_Location (Sloc (Nod));
999 Def := Original_Location (Sloc (Ent));
1000
1001 if Actual_Typ = 'p'
1002 and then Is_Subprogram (Nod)
1003 and then Present (Overridden_Operation (Nod))
1004 then
1005 Actual_Typ := 'P';
1006 end if;
1007
1008 if Alfa_Mode then
1009 Ref_Scope := Alfa.Enclosing_Subprogram_Or_Package (Nod);
1010 Ent_Scope := Alfa.Enclosing_Subprogram_Or_Package (Ent);
1011
1012 -- Since we are reaching through renamings in Alfa mode, we may
1013 -- end up with standard constants. Ignore those.
1014
1015 if Sloc (Ent_Scope) <= Standard_Location
1016 or else Def <= Standard_Location
1017 then
1018 return;
1019 end if;
1020
1021 Ent_Scope_File := Get_Source_Unit (Ent_Scope);
1022 else
1023 Ref_Scope := Empty;
1024 Ent_Scope := Empty;
1025 Ent_Scope_File := No_Unit;
1026 end if;
1027
1028 Add_Entry
1029 ((Ent => Ent,
1030 Loc => Ref,
1031 Typ => Actual_Typ,
1032 Eun => Get_Source_Unit (Def),
1033 Lun => Get_Source_Unit (Ref),
1034 Ref_Scope => Ref_Scope,
1035 Ent_Scope => Ent_Scope),
1036 Ent_Scope_File => Ent_Scope_File);
1037 end if;
1038 end Generate_Reference;
1039
1040 -----------------------------------
1041 -- Generate_Reference_To_Formals --
1042 -----------------------------------
1043
1044 procedure Generate_Reference_To_Formals (E : Entity_Id) is
1045 Formal : Entity_Id;
1046
1047 begin
1048 if Is_Generic_Subprogram (E) then
1049 Formal := First_Entity (E);
1050
1051 while Present (Formal)
1052 and then not Is_Formal (Formal)
1053 loop
1054 Next_Entity (Formal);
1055 end loop;
1056
1057 else
1058 Formal := First_Formal (E);
1059 end if;
1060
1061 while Present (Formal) loop
1062 if Ekind (Formal) = E_In_Parameter then
1063
1064 if Nkind (Parameter_Type (Parent (Formal)))
1065 = N_Access_Definition
1066 then
1067 Generate_Reference (E, Formal, '^', False);
1068 else
1069 Generate_Reference (E, Formal, '>', False);
1070 end if;
1071
1072 elsif Ekind (Formal) = E_In_Out_Parameter then
1073 Generate_Reference (E, Formal, '=', False);
1074
1075 else
1076 Generate_Reference (E, Formal, '<', False);
1077 end if;
1078
1079 Next_Formal (Formal);
1080 end loop;
1081 end Generate_Reference_To_Formals;
1082
1083 -------------------------------------------
1084 -- Generate_Reference_To_Generic_Formals --
1085 -------------------------------------------
1086
1087 procedure Generate_Reference_To_Generic_Formals (E : Entity_Id) is
1088 Formal : Entity_Id;
1089
1090 begin
1091 Formal := First_Entity (E);
1092 while Present (Formal) loop
1093 if Comes_From_Source (Formal) then
1094 Generate_Reference (E, Formal, 'z', False);
1095 end if;
1096
1097 Next_Entity (Formal);
1098 end loop;
1099 end Generate_Reference_To_Generic_Formals;
1100
1101 -------------
1102 -- Get_Key --
1103 -------------
1104
1105 function Get_Key (E : Xref_Entry_Number) return Xref_Entry_Number is
1106 begin
1107 return E;
1108 end Get_Key;
1109
1110 ----------
1111 -- Hash --
1112 ----------
1113
1114 function Hash (F : Xref_Entry_Number) return Header_Num is
1115 -- It is unlikely to have two references to the same entity at the same
1116 -- source location, so the hash function depends only on the Ent and Loc
1117 -- fields.
1118
1119 XE : Xref_Entry renames Xrefs.Table (F);
1120 type M is mod 2**32;
1121
1122 H : constant M := M (XE.Key.Ent) + 2 ** 7 * M (abs XE.Key.Loc);
1123 -- It would be more natural to write:
1124 --
1125 -- H : constant M := M'Mod (XE.Key.Ent) + 2**7 * M'Mod (XE.Key.Loc);
1126 --
1127 -- But we can't use M'Mod, because it prevents bootstrapping with older
1128 -- compilers. Loc can be negative, so we do "abs" before converting.
1129 -- One day this can be cleaned up ???
1130
1131 begin
1132 return Header_Num (H mod Num_Buckets);
1133 end Hash;
1134
1135 -----------------
1136 -- HT_Set_Next --
1137 -----------------
1138
1139 procedure HT_Set_Next (E : Xref_Entry_Number; Next : Xref_Entry_Number) is
1140 begin
1141 Xrefs.Table (E).HTable_Next := Next;
1142 end HT_Set_Next;
1143
1144 -------------
1145 -- HT_Next --
1146 -------------
1147
1148 function HT_Next (E : Xref_Entry_Number) return Xref_Entry_Number is
1149 begin
1150 return Xrefs.Table (E).HTable_Next;
1151 end HT_Next;
1152
1153 ----------------
1154 -- Initialize --
1155 ----------------
1156
1157 procedure Initialize is
1158 begin
1159 Xrefs.Init;
1160 end Initialize;
1161
1162 --------
1163 -- Lt --
1164 --------
1165
1166 function Lt (T1, T2 : Xref_Entry) return Boolean is
1167 begin
1168 -- First test: if entity is in different unit, sort by unit
1169
1170 if T1.Key.Eun /= T2.Key.Eun then
1171 return Dependency_Num (T1.Key.Eun) < Dependency_Num (T2.Key.Eun);
1172
1173 -- Second test: within same unit, sort by entity Sloc
1174
1175 elsif T1.Def /= T2.Def then
1176 return T1.Def < T2.Def;
1177
1178 -- Third test: sort definitions ahead of references
1179
1180 elsif T1.Key.Loc = No_Location then
1181 return True;
1182
1183 elsif T2.Key.Loc = No_Location then
1184 return False;
1185
1186 -- Fourth test: for same entity, sort by reference location unit
1187
1188 elsif T1.Key.Lun /= T2.Key.Lun then
1189 return Dependency_Num (T1.Key.Lun) < Dependency_Num (T2.Key.Lun);
1190
1191 -- Fifth test: order of location within referencing unit
1192
1193 elsif T1.Key.Loc /= T2.Key.Loc then
1194 return T1.Key.Loc < T2.Key.Loc;
1195
1196 -- Finally, for two locations at the same address, we prefer
1197 -- the one that does NOT have the type 'r' so that a modification
1198 -- or extension takes preference, when there are more than one
1199 -- reference at the same location. As a result, in the case of
1200 -- entities that are in-out actuals, the read reference follows
1201 -- the modify reference.
1202
1203 else
1204 return T2.Key.Typ = 'r';
1205 end if;
1206 end Lt;
1207
1208 -----------------------
1209 -- Output_References --
1210 -----------------------
1211
1212 procedure Output_References is
1213
1214 procedure Get_Type_Reference
1215 (Ent : Entity_Id;
1216 Tref : out Entity_Id;
1217 Left : out Character;
1218 Right : out Character);
1219 -- Given an Entity_Id Ent, determines whether a type reference is
1220 -- required. If so, Tref is set to the entity for the type reference
1221 -- and Left and Right are set to the left/right brackets to be output
1222 -- for the reference. If no type reference is required, then Tref is
1223 -- set to Empty, and Left/Right are set to space.
1224
1225 procedure Output_Import_Export_Info (Ent : Entity_Id);
1226 -- Output language and external name information for an interfaced
1227 -- entity, using the format <language, external_name>.
1228
1229 ------------------------
1230 -- Get_Type_Reference --
1231 ------------------------
1232
1233 procedure Get_Type_Reference
1234 (Ent : Entity_Id;
1235 Tref : out Entity_Id;
1236 Left : out Character;
1237 Right : out Character)
1238 is
1239 Sav : Entity_Id;
1240
1241 begin
1242 -- See if we have a type reference
1243
1244 Tref := Ent;
1245 Left := '{';
1246 Right := '}';
1247
1248 loop
1249 Sav := Tref;
1250
1251 -- Processing for types
1252
1253 if Is_Type (Tref) then
1254
1255 -- Case of base type
1256
1257 if Base_Type (Tref) = Tref then
1258
1259 -- If derived, then get first subtype
1260
1261 if Tref /= Etype (Tref) then
1262 Tref := First_Subtype (Etype (Tref));
1263
1264 -- Set brackets for derived type, but don't override
1265 -- pointer case since the fact that something is a
1266 -- pointer is more important.
1267
1268 if Left /= '(' then
1269 Left := '<';
1270 Right := '>';
1271 end if;
1272
1273 -- If non-derived ptr, get directly designated type.
1274 -- If the type has a full view, all references are on the
1275 -- partial view, that is seen first.
1276
1277 elsif Is_Access_Type (Tref) then
1278 Tref := Directly_Designated_Type (Tref);
1279 Left := '(';
1280 Right := ')';
1281
1282 elsif Is_Private_Type (Tref)
1283 and then Present (Full_View (Tref))
1284 then
1285 if Is_Access_Type (Full_View (Tref)) then
1286 Tref := Directly_Designated_Type (Full_View (Tref));
1287 Left := '(';
1288 Right := ')';
1289
1290 -- If the full view is an array type, we also retrieve
1291 -- the corresponding component type, because the ali
1292 -- entry already indicates that this is an array.
1293
1294 elsif Is_Array_Type (Full_View (Tref)) then
1295 Tref := Component_Type (Full_View (Tref));
1296 Left := '(';
1297 Right := ')';
1298 end if;
1299
1300 -- If non-derived array, get component type. Skip component
1301 -- type for case of String or Wide_String, saves worthwhile
1302 -- space.
1303
1304 elsif Is_Array_Type (Tref)
1305 and then Tref /= Standard_String
1306 and then Tref /= Standard_Wide_String
1307 then
1308 Tref := Component_Type (Tref);
1309 Left := '(';
1310 Right := ')';
1311
1312 -- For other non-derived base types, nothing
1313
1314 else
1315 exit;
1316 end if;
1317
1318 -- For a subtype, go to ancestor subtype
1319
1320 else
1321 Tref := Ancestor_Subtype (Tref);
1322
1323 -- If no ancestor subtype, go to base type
1324
1325 if No (Tref) then
1326 Tref := Base_Type (Sav);
1327 end if;
1328 end if;
1329
1330 -- For objects, functions, enum literals, just get type from
1331 -- Etype field.
1332
1333 elsif Is_Object (Tref)
1334 or else Ekind (Tref) = E_Enumeration_Literal
1335 or else Ekind (Tref) = E_Function
1336 or else Ekind (Tref) = E_Operator
1337 then
1338 Tref := Etype (Tref);
1339
1340 -- For anything else, exit
1341
1342 else
1343 exit;
1344 end if;
1345
1346 -- Exit if no type reference, or we are stuck in some loop trying
1347 -- to find the type reference, or if the type is standard void
1348 -- type (the latter is an implementation artifact that should not
1349 -- show up in the generated cross-references).
1350
1351 exit when No (Tref)
1352 or else Tref = Sav
1353 or else Tref = Standard_Void_Type;
1354
1355 -- If we have a usable type reference, return, otherwise keep
1356 -- looking for something useful (we are looking for something
1357 -- that either comes from source or standard)
1358
1359 if Sloc (Tref) = Standard_Location
1360 or else Comes_From_Source (Tref)
1361 then
1362 -- If the reference is a subtype created for a generic actual,
1363 -- go actual directly, the inner subtype is not user visible.
1364
1365 if Nkind (Parent (Tref)) = N_Subtype_Declaration
1366 and then not Comes_From_Source (Parent (Tref))
1367 and then
1368 (Is_Wrapper_Package (Scope (Tref))
1369 or else Is_Generic_Instance (Scope (Tref)))
1370 then
1371 Tref := First_Subtype (Base_Type (Tref));
1372 end if;
1373
1374 return;
1375 end if;
1376 end loop;
1377
1378 -- If we fall through the loop, no type reference
1379
1380 Tref := Empty;
1381 Left := ' ';
1382 Right := ' ';
1383 end Get_Type_Reference;
1384
1385 -------------------------------
1386 -- Output_Import_Export_Info --
1387 -------------------------------
1388
1389 procedure Output_Import_Export_Info (Ent : Entity_Id) is
1390 Language_Name : Name_Id;
1391 Conv : constant Convention_Id := Convention (Ent);
1392
1393 begin
1394 -- Generate language name from convention
1395
1396 if Conv = Convention_C then
1397 Language_Name := Name_C;
1398
1399 elsif Conv = Convention_CPP then
1400 Language_Name := Name_CPP;
1401
1402 elsif Conv = Convention_Ada then
1403 Language_Name := Name_Ada;
1404
1405 else
1406 -- For the moment we ignore all other cases ???
1407
1408 return;
1409 end if;
1410
1411 Write_Info_Char ('<');
1412 Get_Unqualified_Name_String (Language_Name);
1413
1414 for J in 1 .. Name_Len loop
1415 Write_Info_Char (Name_Buffer (J));
1416 end loop;
1417
1418 if Present (Interface_Name (Ent)) then
1419 Write_Info_Char (',');
1420 String_To_Name_Buffer (Strval (Interface_Name (Ent)));
1421
1422 for J in 1 .. Name_Len loop
1423 Write_Info_Char (Name_Buffer (J));
1424 end loop;
1425 end if;
1426
1427 Write_Info_Char ('>');
1428 end Output_Import_Export_Info;
1429
1430 -- Start of processing for Output_References
1431
1432 begin
1433 -- First we add references to the primitive operations of tagged types
1434 -- declared in the main unit.
1435
1436 Handle_Prim_Ops : declare
1437 Ent : Entity_Id;
1438
1439 begin
1440 for J in 1 .. Xrefs.Last loop
1441 Ent := Xrefs.Table (J).Key.Ent;
1442
1443 if Is_Type (Ent)
1444 and then Is_Tagged_Type (Ent)
1445 and then Is_Base_Type (Ent)
1446 and then In_Extended_Main_Source_Unit (Ent)
1447 then
1448 Generate_Prim_Op_References (Ent);
1449 end if;
1450 end loop;
1451 end Handle_Prim_Ops;
1452
1453 -- Before we go ahead and output the references we have a problem
1454 -- that needs dealing with. So far we have captured things that are
1455 -- definitely referenced by the main unit, or defined in the main
1456 -- unit. That's because we don't want to clutter up the ali file
1457 -- for this unit with definition lines for entities in other units
1458 -- that are not referenced.
1459
1460 -- But there is a glitch. We may reference an entity in another unit,
1461 -- and it may have a type reference to an entity that is not directly
1462 -- referenced in the main unit, which may mean that there is no xref
1463 -- entry for this entity yet in the list of references.
1464
1465 -- If we don't do something about this, we will end with an orphan type
1466 -- reference, i.e. it will point to an entity that does not appear
1467 -- within the generated references in the ali file. That is not good for
1468 -- tools using the xref information.
1469
1470 -- To fix this, we go through the references adding definition entries
1471 -- for any unreferenced entities that can be referenced in a type
1472 -- reference. There is a recursion problem here, and that is dealt with
1473 -- by making sure that this traversal also traverses any entries that
1474 -- get added by the traversal.
1475
1476 Handle_Orphan_Type_References : declare
1477 J : Nat;
1478 Tref : Entity_Id;
1479 Ent : Entity_Id;
1480
1481 L, R : Character;
1482 pragma Warnings (Off, L);
1483 pragma Warnings (Off, R);
1484
1485 procedure New_Entry (E : Entity_Id);
1486 -- Make an additional entry into the Xref table for a type entity
1487 -- that is related to the current entity (parent, type ancestor,
1488 -- progenitor, etc.).
1489
1490 ----------------
1491 -- New_Entry --
1492 ----------------
1493
1494 procedure New_Entry (E : Entity_Id) is
1495 begin
1496 pragma Assert (Present (E));
1497
1498 if not Has_Xref_Entry (Implementation_Base_Type (E))
1499 and then Sloc (E) > No_Location
1500 then
1501 Add_Entry
1502 ((Ent => E,
1503 Loc => No_Location,
1504 Typ => Character'First,
1505 Eun => Get_Source_Unit (Original_Location (Sloc (E))),
1506 Lun => No_Unit,
1507 Ref_Scope => Empty,
1508 Ent_Scope => Empty),
1509 Ent_Scope_File => No_Unit);
1510 end if;
1511 end New_Entry;
1512
1513 -- Start of processing for Handle_Orphan_Type_References
1514
1515 begin
1516 -- Note that this is not a for loop for a very good reason. The
1517 -- processing of items in the table can add new items to the table,
1518 -- and they must be processed as well.
1519
1520 J := 1;
1521 while J <= Xrefs.Last loop
1522 Ent := Xrefs.Table (J).Key.Ent;
1523 Get_Type_Reference (Ent, Tref, L, R);
1524
1525 if Present (Tref)
1526 and then not Has_Xref_Entry (Tref)
1527 and then Sloc (Tref) > No_Location
1528 then
1529 New_Entry (Tref);
1530
1531 if Is_Record_Type (Ent)
1532 and then Present (Interfaces (Ent))
1533 then
1534 -- Add an entry for each one of the given interfaces
1535 -- implemented by type Ent.
1536
1537 declare
1538 Elmt : Elmt_Id := First_Elmt (Interfaces (Ent));
1539 begin
1540 while Present (Elmt) loop
1541 New_Entry (Node (Elmt));
1542 Next_Elmt (Elmt);
1543 end loop;
1544 end;
1545 end if;
1546 end if;
1547
1548 -- Collect inherited primitive operations that may be declared in
1549 -- another unit and have no visible reference in the current one.
1550
1551 if Is_Type (Ent)
1552 and then Is_Tagged_Type (Ent)
1553 and then Is_Derived_Type (Ent)
1554 and then Is_Base_Type (Ent)
1555 and then In_Extended_Main_Source_Unit (Ent)
1556 then
1557 declare
1558 Op_List : constant Elist_Id := Primitive_Operations (Ent);
1559 Op : Elmt_Id;
1560 Prim : Entity_Id;
1561
1562 function Parent_Op (E : Entity_Id) return Entity_Id;
1563 -- Find original operation, which may be inherited through
1564 -- several derivations.
1565
1566 function Parent_Op (E : Entity_Id) return Entity_Id is
1567 Orig_Op : constant Entity_Id := Alias (E);
1568
1569 begin
1570 if No (Orig_Op) then
1571 return Empty;
1572
1573 elsif not Comes_From_Source (E)
1574 and then not Has_Xref_Entry (Orig_Op)
1575 and then Comes_From_Source (Orig_Op)
1576 then
1577 return Orig_Op;
1578 else
1579 return Parent_Op (Orig_Op);
1580 end if;
1581 end Parent_Op;
1582
1583 begin
1584 Op := First_Elmt (Op_List);
1585 while Present (Op) loop
1586 Prim := Parent_Op (Node (Op));
1587
1588 if Present (Prim) then
1589 Add_Entry
1590 ((Ent => Prim,
1591 Loc => No_Location,
1592 Typ => Character'First,
1593 Eun => Get_Source_Unit (Sloc (Prim)),
1594 Lun => No_Unit,
1595 Ref_Scope => Empty,
1596 Ent_Scope => Empty),
1597 Ent_Scope_File => No_Unit);
1598 end if;
1599
1600 Next_Elmt (Op);
1601 end loop;
1602 end;
1603 end if;
1604
1605 J := J + 1;
1606 end loop;
1607 end Handle_Orphan_Type_References;
1608
1609 -- Now we have all the references, including those for any embedded
1610 -- type references, so we can sort them, and output them.
1611
1612 Output_Refs : declare
1613
1614 Nrefs : constant Nat := Xrefs.Last;
1615 -- Number of references in table
1616
1617 Rnums : array (0 .. Nrefs) of Nat;
1618 -- This array contains numbers of references in the Xrefs table.
1619 -- This list is sorted in output order. The extra 0'th entry is
1620 -- convenient for the call to sort. When we sort the table, we
1621 -- move the entries in Rnums around, but we do not move the
1622 -- original table entries.
1623
1624 Curxu : Unit_Number_Type;
1625 -- Current xref unit
1626
1627 Curru : Unit_Number_Type;
1628 -- Current reference unit for one entity
1629
1630 Curent : Entity_Id;
1631 -- Current entity
1632
1633 Curnam : String (1 .. Name_Buffer'Length);
1634 Curlen : Natural;
1635 -- Simple name and length of current entity
1636
1637 Curdef : Source_Ptr;
1638 -- Original source location for current entity
1639
1640 Crloc : Source_Ptr;
1641 -- Current reference location
1642
1643 Ctyp : Character;
1644 -- Entity type character
1645
1646 Prevt : Character;
1647 -- reference kind of previous reference
1648
1649 Tref : Entity_Id;
1650 -- Type reference
1651
1652 Rref : Node_Id;
1653 -- Renaming reference
1654
1655 Trunit : Unit_Number_Type;
1656 -- Unit number for type reference
1657
1658 function Lt (Op1, Op2 : Natural) return Boolean;
1659 -- Comparison function for Sort call
1660
1661 function Name_Change (X : Entity_Id) return Boolean;
1662 -- Determines if entity X has a different simple name from Curent
1663
1664 procedure Move (From : Natural; To : Natural);
1665 -- Move procedure for Sort call
1666
1667 package Sorting is new GNAT.Heap_Sort_G (Move, Lt);
1668
1669 --------
1670 -- Lt --
1671 --------
1672
1673 function Lt (Op1, Op2 : Natural) return Boolean is
1674 T1 : Xref_Entry renames Xrefs.Table (Rnums (Nat (Op1)));
1675 T2 : Xref_Entry renames Xrefs.Table (Rnums (Nat (Op2)));
1676
1677 begin
1678 return Lt (T1, T2);
1679 end Lt;
1680
1681 ----------
1682 -- Move --
1683 ----------
1684
1685 procedure Move (From : Natural; To : Natural) is
1686 begin
1687 Rnums (Nat (To)) := Rnums (Nat (From));
1688 end Move;
1689
1690 -----------------
1691 -- Name_Change --
1692 -----------------
1693
1694 -- Why a string comparison here??? Why not compare Name_Id values???
1695
1696 function Name_Change (X : Entity_Id) return Boolean is
1697 begin
1698 Get_Unqualified_Name_String (Chars (X));
1699
1700 if Name_Len /= Curlen then
1701 return True;
1702 else
1703 return Name_Buffer (1 .. Curlen) /= Curnam (1 .. Curlen);
1704 end if;
1705 end Name_Change;
1706
1707 -- Start of processing for Output_Refs
1708
1709 begin
1710 -- Capture the definition Sloc values. We delay doing this till now,
1711 -- since at the time the reference or definition is made, private
1712 -- types may be swapped, and the Sloc value may be incorrect. We
1713 -- also set up the pointer vector for the sort.
1714
1715 for J in 1 .. Nrefs loop
1716 Rnums (J) := J;
1717 Xrefs.Table (J).Def :=
1718 Original_Location (Sloc (Xrefs.Table (J).Key.Ent));
1719 end loop;
1720
1721 -- Sort the references
1722
1723 Sorting.Sort (Integer (Nrefs));
1724
1725 -- Initialize loop through references
1726
1727 Curxu := No_Unit;
1728 Curent := Empty;
1729 Curdef := No_Location;
1730 Curru := No_Unit;
1731 Crloc := No_Location;
1732 Prevt := 'm';
1733
1734 -- Loop to output references
1735
1736 for Refno in 1 .. Nrefs loop
1737 Output_One_Ref : declare
1738 Ent : Entity_Id;
1739
1740 XE : Xref_Entry renames Xrefs.Table (Rnums (Refno));
1741 -- The current entry to be accessed
1742
1743 Left : Character;
1744 Right : Character;
1745 -- Used for {} or <> or () for type reference
1746
1747 procedure Check_Type_Reference
1748 (Ent : Entity_Id;
1749 List_Interface : Boolean);
1750 -- Find whether there is a meaningful type reference for
1751 -- Ent, and display it accordingly. If List_Interface is
1752 -- true, then Ent is a progenitor interface of the current
1753 -- type entity being listed. In that case list it as is,
1754 -- without looking for a type reference for it.
1755
1756 procedure Output_Instantiation_Refs (Loc : Source_Ptr);
1757 -- Recursive procedure to output instantiation references for
1758 -- the given source ptr in [file|line[...]] form. No output
1759 -- if the given location is not a generic template reference.
1760
1761 procedure Output_Overridden_Op (Old_E : Entity_Id);
1762 -- For a subprogram that is overriding, display information
1763 -- about the inherited operation that it overrides.
1764
1765 --------------------------
1766 -- Check_Type_Reference --
1767 --------------------------
1768
1769 procedure Check_Type_Reference
1770 (Ent : Entity_Id;
1771 List_Interface : Boolean)
1772 is
1773 begin
1774 if List_Interface then
1775
1776 -- This is a progenitor interface of the type for which
1777 -- xref information is being generated.
1778
1779 Tref := Ent;
1780 Left := '<';
1781 Right := '>';
1782
1783 else
1784 Get_Type_Reference (Ent, Tref, Left, Right);
1785 end if;
1786
1787 if Present (Tref) then
1788
1789 -- Case of standard entity, output name
1790
1791 if Sloc (Tref) = Standard_Location then
1792 Write_Info_Char (Left);
1793 Write_Info_Name (Chars (Tref));
1794 Write_Info_Char (Right);
1795
1796 -- Case of source entity, output location
1797
1798 else
1799 Write_Info_Char (Left);
1800 Trunit := Get_Source_Unit (Sloc (Tref));
1801
1802 if Trunit /= Curxu then
1803 Write_Info_Nat (Dependency_Num (Trunit));
1804 Write_Info_Char ('|');
1805 end if;
1806
1807 Write_Info_Nat
1808 (Int (Get_Logical_Line_Number (Sloc (Tref))));
1809
1810 declare
1811 Ent : Entity_Id;
1812 Ctyp : Character;
1813
1814 begin
1815 Ent := Tref;
1816 Ctyp := Xref_Entity_Letters (Ekind (Ent));
1817
1818 if Ctyp = '+'
1819 and then Present (Full_View (Ent))
1820 then
1821 Ent := Underlying_Type (Ent);
1822
1823 if Present (Ent) then
1824 Ctyp := Xref_Entity_Letters (Ekind (Ent));
1825 end if;
1826 end if;
1827
1828 Write_Info_Char (Ctyp);
1829 end;
1830
1831 Write_Info_Nat
1832 (Int (Get_Column_Number (Sloc (Tref))));
1833
1834 -- If the type comes from an instantiation, add the
1835 -- corresponding info.
1836
1837 Output_Instantiation_Refs (Sloc (Tref));
1838 Write_Info_Char (Right);
1839 end if;
1840 end if;
1841 end Check_Type_Reference;
1842
1843 -------------------------------
1844 -- Output_Instantiation_Refs --
1845 -------------------------------
1846
1847 procedure Output_Instantiation_Refs (Loc : Source_Ptr) is
1848 Iloc : constant Source_Ptr := Instantiation_Location (Loc);
1849 Lun : Unit_Number_Type;
1850 Cu : constant Unit_Number_Type := Curru;
1851
1852 begin
1853 -- Nothing to do if this is not an instantiation
1854
1855 if Iloc = No_Location then
1856 return;
1857 end if;
1858
1859 -- Output instantiation reference
1860
1861 Write_Info_Char ('[');
1862 Lun := Get_Source_Unit (Iloc);
1863
1864 if Lun /= Curru then
1865 Curru := Lun;
1866 Write_Info_Nat (Dependency_Num (Curru));
1867 Write_Info_Char ('|');
1868 end if;
1869
1870 Write_Info_Nat (Int (Get_Logical_Line_Number (Iloc)));
1871
1872 -- Recursive call to get nested instantiations
1873
1874 Output_Instantiation_Refs (Iloc);
1875
1876 -- Output final ] after call to get proper nesting
1877
1878 Write_Info_Char (']');
1879 Curru := Cu;
1880 return;
1881 end Output_Instantiation_Refs;
1882
1883 --------------------------
1884 -- Output_Overridden_Op --
1885 --------------------------
1886
1887 procedure Output_Overridden_Op (Old_E : Entity_Id) is
1888 Op : Entity_Id;
1889
1890 begin
1891 -- The overridden operation has an implicit declaration
1892 -- at the point of derivation. What we want to display
1893 -- is the original operation, which has the actual body
1894 -- (or abstract declaration) that is being overridden.
1895 -- The overridden operation is not always set, e.g. when
1896 -- it is a predefined operator.
1897
1898 if No (Old_E) then
1899 return;
1900
1901 -- Follow alias chain if one is present
1902
1903 elsif Present (Alias (Old_E)) then
1904
1905 -- The subprogram may have been implicitly inherited
1906 -- through several levels of derivation, so find the
1907 -- ultimate (source) ancestor.
1908
1909 Op := Ultimate_Alias (Old_E);
1910
1911 -- Normal case of no alias present. We omit generated
1912 -- primitives like tagged equality, that have no source
1913 -- representation.
1914
1915 else
1916 Op := Old_E;
1917 end if;
1918
1919 if Present (Op)
1920 and then Sloc (Op) /= Standard_Location
1921 and then Comes_From_Source (Op)
1922 then
1923 declare
1924 Loc : constant Source_Ptr := Sloc (Op);
1925 Par_Unit : constant Unit_Number_Type :=
1926 Get_Source_Unit (Loc);
1927
1928 begin
1929 Write_Info_Char ('<');
1930
1931 if Par_Unit /= Curxu then
1932 Write_Info_Nat (Dependency_Num (Par_Unit));
1933 Write_Info_Char ('|');
1934 end if;
1935
1936 Write_Info_Nat (Int (Get_Logical_Line_Number (Loc)));
1937 Write_Info_Char ('p');
1938 Write_Info_Nat (Int (Get_Column_Number (Loc)));
1939 Write_Info_Char ('>');
1940 end;
1941 end if;
1942 end Output_Overridden_Op;
1943
1944 -- Start of processing for Output_One_Ref
1945
1946 begin
1947 Ent := XE.Key.Ent;
1948 Ctyp := Xref_Entity_Letters (Ekind (Ent));
1949
1950 -- Skip reference if it is the only reference to an entity,
1951 -- and it is an END line reference, and the entity is not in
1952 -- the current extended source. This prevents junk entries
1953 -- consisting only of packages with END lines, where no
1954 -- entity from the package is actually referenced.
1955
1956 if XE.Key.Typ = 'e'
1957 and then Ent /= Curent
1958 and then (Refno = Nrefs
1959 or else
1960 Ent /= Xrefs.Table (Rnums (Refno + 1)).Key.Ent)
1961 and then not In_Extended_Main_Source_Unit (Ent)
1962 then
1963 goto Continue;
1964 end if;
1965
1966 -- For private type, get full view type
1967
1968 if Ctyp = '+'
1969 and then Present (Full_View (XE.Key.Ent))
1970 then
1971 Ent := Underlying_Type (Ent);
1972
1973 if Present (Ent) then
1974 Ctyp := Xref_Entity_Letters (Ekind (Ent));
1975 end if;
1976 end if;
1977
1978 -- Special exception for Boolean
1979
1980 if Ctyp = 'E' and then Is_Boolean_Type (Ent) then
1981 Ctyp := 'B';
1982 end if;
1983
1984 -- For variable reference, get corresponding type
1985
1986 if Ctyp = '*' then
1987 Ent := Etype (XE.Key.Ent);
1988 Ctyp := Fold_Lower (Xref_Entity_Letters (Ekind (Ent)));
1989
1990 -- If variable is private type, get full view type
1991
1992 if Ctyp = '+'
1993 and then Present (Full_View (Etype (XE.Key.Ent)))
1994 then
1995 Ent := Underlying_Type (Etype (XE.Key.Ent));
1996
1997 if Present (Ent) then
1998 Ctyp := Fold_Lower (Xref_Entity_Letters (Ekind (Ent)));
1999 end if;
2000
2001 elsif Is_Generic_Type (Ent) then
2002
2003 -- If the type of the entity is a generic private type,
2004 -- there is no usable full view, so retain the indication
2005 -- that this is an object.
2006
2007 Ctyp := '*';
2008 end if;
2009
2010 -- Special handling for access parameters and objects of
2011 -- an anonymous access type.
2012
2013 if Ekind_In (Etype (XE.Key.Ent),
2014 E_Anonymous_Access_Type,
2015 E_Anonymous_Access_Subprogram_Type,
2016 E_Anonymous_Access_Protected_Subprogram_Type)
2017 then
2018 if Is_Formal (XE.Key.Ent)
2019 or else Ekind_In (XE.Key.Ent, E_Variable, E_Constant)
2020 then
2021 Ctyp := 'p';
2022 end if;
2023
2024 -- Special handling for Boolean
2025
2026 elsif Ctyp = 'e' and then Is_Boolean_Type (Ent) then
2027 Ctyp := 'b';
2028 end if;
2029 end if;
2030
2031 -- Special handling for abstract types and operations
2032
2033 if Is_Overloadable (XE.Key.Ent)
2034 and then Is_Abstract_Subprogram (XE.Key.Ent)
2035 then
2036 if Ctyp = 'U' then
2037 Ctyp := 'x'; -- Abstract procedure
2038
2039 elsif Ctyp = 'V' then
2040 Ctyp := 'y'; -- Abstract function
2041 end if;
2042
2043 elsif Is_Type (XE.Key.Ent)
2044 and then Is_Abstract_Type (XE.Key.Ent)
2045 then
2046 if Is_Interface (XE.Key.Ent) then
2047 Ctyp := 'h';
2048
2049 elsif Ctyp = 'R' then
2050 Ctyp := 'H'; -- Abstract type
2051 end if;
2052 end if;
2053
2054 -- Only output reference if interesting type of entity
2055
2056 if Ctyp = ' '
2057
2058 -- Suppress references to object definitions, used for local
2059 -- references.
2060
2061 or else XE.Key.Typ = 'D'
2062 or else XE.Key.Typ = 'I'
2063
2064 -- Suppress self references, except for bodies that act as
2065 -- specs.
2066
2067 or else (XE.Key.Loc = XE.Def
2068 and then
2069 (XE.Key.Typ /= 'b'
2070 or else not Is_Subprogram (XE.Key.Ent)))
2071
2072 -- Also suppress definitions of body formals (we only
2073 -- treat these as references, and the references were
2074 -- separately recorded).
2075
2076 or else (Is_Formal (XE.Key.Ent)
2077 and then Present (Spec_Entity (XE.Key.Ent)))
2078 then
2079 null;
2080
2081 else
2082 -- Start new Xref section if new xref unit
2083
2084 if XE.Key.Eun /= Curxu then
2085 if Write_Info_Col > 1 then
2086 Write_Info_EOL;
2087 end if;
2088
2089 Curxu := XE.Key.Eun;
2090
2091 Write_Info_Initiate ('X');
2092 Write_Info_Char (' ');
2093 Write_Info_Nat (Dependency_Num (XE.Key.Eun));
2094 Write_Info_Char (' ');
2095 Write_Info_Name
2096 (Reference_Name (Source_Index (XE.Key.Eun)));
2097 end if;
2098
2099 -- Start new Entity line if new entity. Note that we
2100 -- consider two entities the same if they have the same
2101 -- name and source location. This causes entities in
2102 -- instantiations to be treated as though they referred
2103 -- to the template.
2104
2105 if No (Curent)
2106 or else
2107 (XE.Key.Ent /= Curent
2108 and then
2109 (Name_Change (XE.Key.Ent) or else XE.Def /= Curdef))
2110 then
2111 Curent := XE.Key.Ent;
2112 Curdef := XE.Def;
2113
2114 Get_Unqualified_Name_String (Chars (XE.Key.Ent));
2115 Curlen := Name_Len;
2116 Curnam (1 .. Curlen) := Name_Buffer (1 .. Curlen);
2117
2118 if Write_Info_Col > 1 then
2119 Write_Info_EOL;
2120 end if;
2121
2122 -- Write column number information
2123
2124 Write_Info_Nat (Int (Get_Logical_Line_Number (XE.Def)));
2125 Write_Info_Char (Ctyp);
2126 Write_Info_Nat (Int (Get_Column_Number (XE.Def)));
2127
2128 -- Write level information
2129
2130 Write_Level_Info : declare
2131 function Is_Visible_Generic_Entity
2132 (E : Entity_Id) return Boolean;
2133 -- Check whether E is declared in the visible part
2134 -- of a generic package. For source navigation
2135 -- purposes, treat this as a visible entity.
2136
2137 function Is_Private_Record_Component
2138 (E : Entity_Id) return Boolean;
2139 -- Check whether E is a non-inherited component of a
2140 -- private extension. Even if the enclosing record is
2141 -- public, we want to treat the component as private
2142 -- for navigation purposes.
2143
2144 ---------------------------------
2145 -- Is_Private_Record_Component --
2146 ---------------------------------
2147
2148 function Is_Private_Record_Component
2149 (E : Entity_Id) return Boolean
2150 is
2151 S : constant Entity_Id := Scope (E);
2152 begin
2153 return
2154 Ekind (E) = E_Component
2155 and then Nkind (Declaration_Node (S)) =
2156 N_Private_Extension_Declaration
2157 and then Original_Record_Component (E) = E;
2158 end Is_Private_Record_Component;
2159
2160 -------------------------------
2161 -- Is_Visible_Generic_Entity --
2162 -------------------------------
2163
2164 function Is_Visible_Generic_Entity
2165 (E : Entity_Id) return Boolean
2166 is
2167 Par : Node_Id;
2168
2169 begin
2170 -- The Present check here is an error defense
2171
2172 if Present (Scope (E))
2173 and then Ekind (Scope (E)) /= E_Generic_Package
2174 then
2175 return False;
2176 end if;
2177
2178 Par := Parent (E);
2179 while Present (Par) loop
2180 if
2181 Nkind (Par) = N_Generic_Package_Declaration
2182 then
2183 -- Entity is a generic formal
2184
2185 return False;
2186
2187 elsif
2188 Nkind (Parent (Par)) = N_Package_Specification
2189 then
2190 return
2191 Is_List_Member (Par)
2192 and then List_Containing (Par) =
2193 Visible_Declarations (Parent (Par));
2194 else
2195 Par := Parent (Par);
2196 end if;
2197 end loop;
2198
2199 return False;
2200 end Is_Visible_Generic_Entity;
2201
2202 -- Start of processing for Write_Level_Info
2203
2204 begin
2205 if Is_Hidden (Curent)
2206 or else Is_Private_Record_Component (Curent)
2207 then
2208 Write_Info_Char (' ');
2209
2210 elsif
2211 Is_Public (Curent)
2212 or else Is_Visible_Generic_Entity (Curent)
2213 then
2214 Write_Info_Char ('*');
2215
2216 else
2217 Write_Info_Char (' ');
2218 end if;
2219 end Write_Level_Info;
2220
2221 -- Output entity name. We use the occurrence from the
2222 -- actual source program at the definition point.
2223
2224 declare
2225 Ent_Name : constant String :=
2226 Exact_Source_Name (Sloc (XE.Key.Ent));
2227 begin
2228 for C in Ent_Name'Range loop
2229 Write_Info_Char (Ent_Name (C));
2230 end loop;
2231 end;
2232
2233 -- See if we have a renaming reference
2234
2235 if Is_Object (XE.Key.Ent)
2236 and then Present (Renamed_Object (XE.Key.Ent))
2237 then
2238 Rref := Renamed_Object (XE.Key.Ent);
2239
2240 elsif Is_Overloadable (XE.Key.Ent)
2241 and then Nkind (Parent (Declaration_Node (XE.Key.Ent)))
2242 = N_Subprogram_Renaming_Declaration
2243 then
2244 Rref := Name (Parent (Declaration_Node (XE.Key.Ent)));
2245
2246 elsif Ekind (XE.Key.Ent) = E_Package
2247 and then Nkind (Declaration_Node (XE.Key.Ent)) =
2248 N_Package_Renaming_Declaration
2249 then
2250 Rref := Name (Declaration_Node (XE.Key.Ent));
2251
2252 else
2253 Rref := Empty;
2254 end if;
2255
2256 if Present (Rref) then
2257 if Nkind (Rref) = N_Expanded_Name then
2258 Rref := Selector_Name (Rref);
2259 end if;
2260
2261 if Nkind (Rref) = N_Identifier
2262 or else Nkind (Rref) = N_Operator_Symbol
2263 then
2264 null;
2265
2266 -- For renamed array components, use the array name
2267 -- for the renamed entity, which reflect the fact that
2268 -- in general the whole array is aliased.
2269
2270 elsif Nkind (Rref) = N_Indexed_Component then
2271 if Nkind (Prefix (Rref)) = N_Identifier then
2272 Rref := Prefix (Rref);
2273 elsif Nkind (Prefix (Rref)) = N_Expanded_Name then
2274 Rref := Selector_Name (Prefix (Rref));
2275 else
2276 Rref := Empty;
2277 end if;
2278
2279 else
2280 Rref := Empty;
2281 end if;
2282 end if;
2283
2284 -- Write out renaming reference if we have one
2285
2286 if Present (Rref) then
2287 Write_Info_Char ('=');
2288 Write_Info_Nat
2289 (Int (Get_Logical_Line_Number (Sloc (Rref))));
2290 Write_Info_Char (':');
2291 Write_Info_Nat
2292 (Int (Get_Column_Number (Sloc (Rref))));
2293 end if;
2294
2295 -- Indicate that the entity is in the unit of the current
2296 -- xref section.
2297
2298 Curru := Curxu;
2299
2300 -- Write out information about generic parent, if entity
2301 -- is an instance.
2302
2303 if Is_Generic_Instance (XE.Key.Ent) then
2304 declare
2305 Gen_Par : constant Entity_Id :=
2306 Generic_Parent
2307 (Specification
2308 (Unit_Declaration_Node
2309 (XE.Key.Ent)));
2310 Loc : constant Source_Ptr := Sloc (Gen_Par);
2311 Gen_U : constant Unit_Number_Type :=
2312 Get_Source_Unit (Loc);
2313
2314 begin
2315 Write_Info_Char ('[');
2316
2317 if Curru /= Gen_U then
2318 Write_Info_Nat (Dependency_Num (Gen_U));
2319 Write_Info_Char ('|');
2320 end if;
2321
2322 Write_Info_Nat
2323 (Int (Get_Logical_Line_Number (Loc)));
2324 Write_Info_Char (']');
2325 end;
2326 end if;
2327
2328 -- See if we have a type reference and if so output
2329
2330 Check_Type_Reference (XE.Key.Ent, False);
2331
2332 -- Additional information for types with progenitors
2333
2334 if Is_Record_Type (XE.Key.Ent)
2335 and then Present (Interfaces (XE.Key.Ent))
2336 then
2337 declare
2338 Elmt : Elmt_Id :=
2339 First_Elmt (Interfaces (XE.Key.Ent));
2340 begin
2341 while Present (Elmt) loop
2342 Check_Type_Reference (Node (Elmt), True);
2343 Next_Elmt (Elmt);
2344 end loop;
2345 end;
2346
2347 -- For array types, list index types as well. (This is
2348 -- not C, indexes have distinct types).
2349
2350 elsif Is_Array_Type (XE.Key.Ent) then
2351 declare
2352 Indx : Node_Id;
2353 begin
2354 Indx := First_Index (XE.Key.Ent);
2355 while Present (Indx) loop
2356 Check_Type_Reference
2357 (First_Subtype (Etype (Indx)), True);
2358 Next_Index (Indx);
2359 end loop;
2360 end;
2361 end if;
2362
2363 -- If the entity is an overriding operation, write info
2364 -- on operation that was overridden.
2365
2366 if Is_Subprogram (XE.Key.Ent)
2367 and then Present (Overridden_Operation (XE.Key.Ent))
2368 then
2369 Output_Overridden_Op
2370 (Overridden_Operation (XE.Key.Ent));
2371 end if;
2372
2373 -- End of processing for entity output
2374
2375 Crloc := No_Location;
2376 end if;
2377
2378 -- Output the reference if it is not as the same location
2379 -- as the previous one, or it is a read-reference that
2380 -- indicates that the entity is an in-out actual in a call.
2381
2382 if XE.Key.Loc /= No_Location
2383 and then
2384 (XE.Key.Loc /= Crloc
2385 or else (Prevt = 'm' and then XE.Key.Typ = 'r'))
2386 then
2387 Crloc := XE.Key.Loc;
2388 Prevt := XE.Key.Typ;
2389
2390 -- Start continuation if line full, else blank
2391
2392 if Write_Info_Col > 72 then
2393 Write_Info_EOL;
2394 Write_Info_Initiate ('.');
2395 end if;
2396
2397 Write_Info_Char (' ');
2398
2399 -- Output file number if changed
2400
2401 if XE.Key.Lun /= Curru then
2402 Curru := XE.Key.Lun;
2403 Write_Info_Nat (Dependency_Num (Curru));
2404 Write_Info_Char ('|');
2405 end if;
2406
2407 Write_Info_Nat
2408 (Int (Get_Logical_Line_Number (XE.Key.Loc)));
2409 Write_Info_Char (XE.Key.Typ);
2410
2411 if Is_Overloadable (XE.Key.Ent)
2412 and then Is_Imported (XE.Key.Ent)
2413 and then XE.Key.Typ = 'b'
2414 then
2415 Output_Import_Export_Info (XE.Key.Ent);
2416 end if;
2417
2418 Write_Info_Nat (Int (Get_Column_Number (XE.Key.Loc)));
2419
2420 Output_Instantiation_Refs (Sloc (XE.Key.Ent));
2421 end if;
2422 end if;
2423 end Output_One_Ref;
2424
2425 <<Continue>>
2426 null;
2427 end loop;
2428
2429 Write_Info_EOL;
2430 end Output_Refs;
2431 end Output_References;
2432
2433 -- Start of elaboration for Lib.Xref
2434
2435 begin
2436 -- Reset is necessary because Elmt_Ptr does not default to Null_Ptr,
2437 -- because it's not an access type.
2438
2439 Xref_Set.Reset;
2440 end Lib.Xref;