1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1998-2011, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree; use Atree;
27 with Csets; use Csets;
28 with Elists; use Elists;
29 with Errout; use Errout;
30 with Nlists; use Nlists;
32 with Restrict; use Restrict;
33 with Rident; use Rident;
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;
46 with GNAT.Heap_Sort_G;
48 package body Lib.Xref is
54 -- The Xref table is used to record references. The Loc field is set
55 -- to No_Location for a definition entry.
57 subtype Xref_Entry_Number is Int;
59 type Xref_Entry is record
61 -- Entity referenced (E parameter to Generate_Reference)
64 -- Original source location for entity being referenced. Note that these
65 -- values are used only during the output process, they are not set when
66 -- the entries are originally built. This is because private entities
67 -- can be swapped when the initial call is made.
70 -- Location of reference (Original_Location (Sloc field of N parameter
71 -- to Generate_Reference). Set to No_Location for the case of a
72 -- defining occurrence.
75 -- Reference type (Typ param to Generate_Reference)
77 Eun : Unit_Number_Type;
78 -- Unit number corresponding to Ent
80 Lun : Unit_Number_Type;
81 -- Unit number corresponding to Loc. Value is undefined and not
82 -- referenced if Loc is set to No_Location.
84 -- The following components are only used for ALFA cross-references
86 Ref_Scope : Entity_Id;
87 -- Entity of the closest subprogram or package enclosing the reference
89 Ent_Scope : Entity_Id;
90 -- Entity of the closest subprogram or package enclosing the definition,
91 -- which should be located in the same file as the definition itself.
93 Ent_Scope_File : Unit_Number_Type;
94 -- File for entity Ent_Scope
97 package Xrefs is new Table.Table (
98 Table_Component_Type => Xref_Entry,
99 Table_Index_Type => Xref_Entry_Number,
100 Table_Low_Bound => 1,
101 Table_Initial => Alloc.Xrefs_Initial,
102 Table_Increment => Alloc.Xrefs_Increment,
103 Table_Name => "Xrefs");
105 ----------------------
106 -- ALFA Information --
107 ----------------------
109 package body ALFA is separate;
111 ------------------------
112 -- Local Subprograms --
113 ------------------------
115 function Enclosing_Subprogram_Or_Package (N : Node_Id) return Entity_Id;
116 -- Return the closest enclosing subprogram of package
118 procedure Generate_Prim_Op_References (Typ : Entity_Id);
119 -- For a tagged type, generate implicit references to its primitive
120 -- operations, for source navigation. This is done right before emitting
121 -- cross-reference information rather than at the freeze point of the type
122 -- in order to handle late bodies that are primitive operations.
124 function Lt (T1, T2 : Xref_Entry) return Boolean;
125 -- Order cross-references
127 -------------------------------------
128 -- Enclosing_Subprogram_Or_Package --
129 -------------------------------------
131 function Enclosing_Subprogram_Or_Package (N : Node_Id) return Entity_Id is
135 -- If N is the defining identifier for a subprogram, then return the
136 -- enclosing subprogram or package, not this subprogram.
138 if Nkind_In (N, N_Defining_Identifier, N_Defining_Operator_Symbol)
139 and then Nkind (Parent (N)) in N_Subprogram_Specification
141 Result := Parent (Parent (Parent (N)));
147 exit when No (Result);
149 case Nkind (Result) is
150 when N_Package_Specification =>
151 Result := Defining_Unit_Name (Result);
154 when N_Package_Body =>
155 Result := Defining_Unit_Name (Result);
158 when N_Subprogram_Specification =>
159 Result := Defining_Unit_Name (Result);
162 when N_Subprogram_Declaration =>
163 Result := Defining_Unit_Name (Specification (Result));
166 when N_Subprogram_Body =>
167 Result := Defining_Unit_Name (Specification (Result));
170 -- The enclosing subprogram for a pre- or postconditions should be
171 -- the subprogram to which the pragma is attached. This is not
172 -- always the case in the AST, as the pragma may be declared after
173 -- the declaration of the subprogram. Return Empty in this case.
176 if Get_Pragma_Id (Result) = Pragma_Precondition
178 Get_Pragma_Id (Result) = Pragma_Postcondition
182 Result := Parent (Result);
186 Result := Parent (Result);
190 if Nkind (Result) = N_Defining_Program_Unit_Name then
191 Result := Defining_Identifier (Result);
194 -- Do no return a scope without a proper location
197 and then Sloc (Result) = No_Location
203 end Enclosing_Subprogram_Or_Package;
205 -------------------------
206 -- Generate_Definition --
207 -------------------------
209 procedure Generate_Definition (E : Entity_Id) is
214 pragma Assert (Nkind (E) in N_Entity);
216 -- Note that we do not test Xref_Entity_Letters here. It is too early
217 -- to do so, since we are often called before the entity is fully
218 -- constructed, so that the Ekind is still E_Void.
222 -- Definition must come from source
224 -- We make an exception for subprogram child units that have no spec.
225 -- For these we generate a subprogram declaration for library use,
226 -- and the corresponding entity does not come from source.
227 -- Nevertheless, all references will be attached to it and we have
228 -- to treat is as coming from user code.
230 and then (Comes_From_Source (E) or else Is_Child_Unit (E))
232 -- And must have a reasonable source location that is not
233 -- within an instance (all entities in instances are ignored)
235 and then Sloc (E) > No_Location
236 and then Instantiation_Location (Sloc (E)) = No_Location
238 -- And must be a non-internal name from the main source unit
240 and then In_Extended_Main_Source_Unit (E)
241 and then not Is_Internal_Name (Chars (E))
243 Xrefs.Increment_Last;
245 Loc := Original_Location (Sloc (E));
247 Xrefs.Table (Indx).Ent := E;
248 Xrefs.Table (Indx).Typ := ' ';
249 Xrefs.Table (Indx).Def := No_Location;
250 Xrefs.Table (Indx).Loc := No_Location;
252 Xrefs.Table (Indx).Eun := Get_Source_Unit (Loc);
254 Xrefs.Table (Indx).Ref_Scope := Empty;
255 Xrefs.Table (Indx).Ent_Scope := Empty;
256 Xrefs.Table (Indx).Ent_Scope_File := No_Unit;
258 Set_Has_Xref_Entry (E);
260 if In_Inlined_Body then
264 end Generate_Definition;
266 ---------------------------------
267 -- Generate_Operator_Reference --
268 ---------------------------------
270 procedure Generate_Operator_Reference
275 if not In_Extended_Main_Source_Unit (N) then
279 -- If the operator is not a Standard operator, then we generate a real
280 -- reference to the user defined operator.
282 if Sloc (Entity (N)) /= Standard_Location then
283 Generate_Reference (Entity (N), N);
285 -- A reference to an implicit inequality operator is also a reference
286 -- to the user-defined equality.
288 if Nkind (N) = N_Op_Ne
289 and then not Comes_From_Source (Entity (N))
290 and then Present (Corresponding_Equality (Entity (N)))
292 Generate_Reference (Corresponding_Equality (Entity (N)), N);
295 -- For the case of Standard operators, we mark the result type as
296 -- referenced. This ensures that in the case where we are using a
297 -- derived operator, we mark an entity of the unit that implicitly
298 -- defines this operator as used. Otherwise we may think that no entity
299 -- of the unit is used. The actual entity marked as referenced is the
300 -- first subtype, which is the relevant user defined entity.
302 -- Note: we only do this for operators that come from source. The
303 -- generated code sometimes reaches for entities that do not need to be
304 -- explicitly visible (for example, when we expand the code for
305 -- comparing two record objects, the fields of the record may not be
308 elsif Comes_From_Source (N) then
309 Set_Referenced (First_Subtype (T));
311 end Generate_Operator_Reference;
313 ---------------------------------
314 -- Generate_Prim_Op_References --
315 ---------------------------------
317 procedure Generate_Prim_Op_References (Typ : Entity_Id) is
320 Prim_List : Elist_Id;
323 -- Handle subtypes of synchronized types
325 if Ekind (Typ) = E_Protected_Subtype
326 or else Ekind (Typ) = E_Task_Subtype
328 Base_T := Etype (Typ);
333 -- References to primitive operations are only relevant for tagged types
335 if not Is_Tagged_Type (Base_T)
336 or else Is_Class_Wide_Type (Base_T)
341 -- Ada 2005 (AI-345): For synchronized types generate reference to the
342 -- wrapper that allow us to dispatch calls through their implemented
343 -- abstract interface types.
345 -- The check for Present here is to protect against previously reported
348 Prim_List := Primitive_Operations (Base_T);
350 if No (Prim_List) then
354 Prim := First_Elmt (Prim_List);
355 while Present (Prim) loop
357 -- If the operation is derived, get the original for cross-reference
358 -- reference purposes (it is the original for which we want the xref
359 -- and for which the comes_from_source test must be performed).
362 (Typ, Ultimate_Alias (Node (Prim)), 'p', Set_Ref => False);
365 end Generate_Prim_Op_References;
367 ------------------------
368 -- Generate_Reference --
369 ------------------------
371 procedure Generate_Reference
374 Typ : Character := 'r';
375 Set_Ref : Boolean := True;
376 Force : Boolean := False)
384 Ref_Scope : Entity_Id;
385 Ent_Scope : Entity_Id;
389 -- Used for call to Find_Actual
392 -- If Formal is non-Empty, then its Ekind, otherwise E_Void
394 function Is_On_LHS (Node : Node_Id) return Boolean;
395 -- Used to check if a node is on the left hand side of an assignment.
396 -- The following cases are handled:
398 -- Variable Node is a direct descendant of left hand side of an
399 -- assignment statement.
401 -- Prefix Of an indexed or selected component that is present in
402 -- a subtree rooted by an assignment statement. There is
403 -- no restriction of nesting of components, thus cases
404 -- such as A.B (C).D are handled properly. However a prefix
405 -- of a dereference (either implicit or explicit) is never
406 -- considered as on a LHS.
408 -- Out param Same as above cases, but OUT parameter
410 function OK_To_Set_Referenced return Boolean;
411 -- Returns True if the Referenced flag can be set. There are a few
412 -- exceptions where we do not want to set this flag, see body for
413 -- details of these exceptional cases.
419 -- ??? There are several routines here and there that perform a similar
420 -- (but subtly different) computation, which should be factored:
422 -- Sem_Util.May_Be_Lvalue
423 -- Sem_Util.Known_To_Be_Assigned
424 -- Exp_Ch2.Expand_Entry_Parameter.In_Assignment_Context
425 -- Exp_Smem.Is_Out_Actual
427 function Is_On_LHS (Node : Node_Id) return Boolean is
433 -- Only identifiers are considered, is this necessary???
435 if Nkind (Node) /= N_Identifier then
439 -- Immediate return if appeared as OUT parameter
441 if Kind = E_Out_Parameter then
445 -- Search for assignment statement subtree root
452 if K = N_Assignment_Statement then
455 -- Check whether the parent is a component and the current node is
456 -- its prefix, but return False if the current node has an access
457 -- type, as in that case the selected or indexed component is an
458 -- implicit dereference, and the LHS is the designated object, not
459 -- the access object.
461 -- ??? case of a slice assignment?
463 -- ??? Note that in some cases this is called too early
464 -- (see comments in Sem_Ch8.Find_Direct_Name), at a point where
465 -- the tree is not fully typed yet. In that case we may lack
466 -- an Etype for N, and we must disable the check for an implicit
467 -- dereference. If the dereference is on an LHS, this causes a
470 elsif (K = N_Selected_Component or else K = N_Indexed_Component)
471 and then Prefix (P) = N
472 and then not (Present (Etype (N))
474 Is_Access_Type (Etype (N)))
478 -- All other cases, definitely not on left side
486 ---------------------------
487 -- OK_To_Set_Referenced --
488 ---------------------------
490 function OK_To_Set_Referenced return Boolean is
494 -- A reference from a pragma Unreferenced or pragma Unmodified or
495 -- pragma Warnings does not cause the Referenced flag to be set.
496 -- This avoids silly warnings about things being referenced and
497 -- not assigned when the only reference is from the pragma.
499 if Nkind (N) = N_Identifier then
502 if Nkind (P) = N_Pragma_Argument_Association then
505 if Nkind (P) = N_Pragma then
506 if Pragma_Name (P) = Name_Warnings
508 Pragma_Name (P) = Name_Unmodified
510 Pragma_Name (P) = Name_Unreferenced
519 end OK_To_Set_Referenced;
521 -- Start of processing for Generate_Reference
524 pragma Assert (Nkind (E) in N_Entity);
525 Find_Actual (N, Formal, Call);
527 if Present (Formal) then
528 Kind := Ekind (Formal);
533 -- Check for obsolescent reference to package ASCII. GNAT treats this
534 -- element of annex J specially since in practice, programs make a lot
535 -- of use of this feature, so we don't include it in the set of features
536 -- diagnosed when Warn_On_Obsolescent_Features mode is set. However we
537 -- are required to note it as a violation of the RM defined restriction.
539 if E = Standard_ASCII then
540 Check_Restriction (No_Obsolescent_Features, N);
543 -- Check for reference to entity marked with Is_Obsolescent
545 -- Note that we always allow obsolescent references in the compiler
546 -- itself and the run time, since we assume that we know what we are
547 -- doing in such cases. For example the calls in Ada.Characters.Handling
548 -- to its own obsolescent subprograms are just fine.
550 -- In any case we do not generate warnings within the extended source
551 -- unit of the entity in question, since we assume the source unit
552 -- itself knows what is going on (and for sure we do not want silly
553 -- warnings, e.g. on the end line of an obsolescent procedure body).
555 if Is_Obsolescent (E)
556 and then not GNAT_Mode
557 and then not In_Extended_Main_Source_Unit (E)
559 Check_Restriction (No_Obsolescent_Features, N);
561 if Warn_On_Obsolescent_Feature then
562 Output_Obsolescent_Entity_Warnings (N, E);
566 -- Warn if reference to Ada 2005 entity not in Ada 2005 mode. We only
567 -- detect real explicit references (modifications and references).
569 if Comes_From_Source (N)
570 and then Is_Ada_2005_Only (E)
571 and then Ada_Version < Ada_2005
572 and then Warn_On_Ada_2005_Compatibility
573 and then (Typ = 'm' or else Typ = 'r' or else Typ = 's')
575 Error_Msg_NE ("& is only defined in Ada 2005?", N, E);
578 -- Warn if reference to Ada 2012 entity not in Ada 2012 mode. We only
579 -- detect real explicit references (modifications and references).
581 if Comes_From_Source (N)
582 and then Is_Ada_2012_Only (E)
583 and then Ada_Version < Ada_2012
584 and then Warn_On_Ada_2012_Compatibility
585 and then (Typ = 'm' or else Typ = 'r')
587 Error_Msg_NE ("& is only defined in Ada 2012?", N, E);
590 -- Never collect references if not in main source unit. However, we omit
591 -- this test if Typ is 'e' or 'k', since these entries are structural,
592 -- and it is useful to have them in units that reference packages as
593 -- well as units that define packages. We also omit the test for the
594 -- case of 'p' since we want to include inherited primitive operations
595 -- from other packages.
597 -- We also omit this test is this is a body reference for a subprogram
598 -- instantiation. In this case the reference is to the generic body,
599 -- which clearly need not be in the main unit containing the instance.
600 -- For the same reason we accept an implicit reference generated for
601 -- a default in an instance.
603 if not In_Extended_Main_Source_Unit (N) then
609 or else (Typ = 'b' and then Is_Generic_Instance (E))
617 -- For reference type p, the entity must be in main source unit
619 if Typ = 'p' and then not In_Extended_Main_Source_Unit (E) then
623 -- Unless the reference is forced, we ignore references where the
624 -- reference itself does not come from source.
626 if not Force and then not Comes_From_Source (N) then
630 -- Deal with setting entity as referenced, unless suppressed. Note that
631 -- we still do Set_Referenced on entities that do not come from source.
632 -- This situation arises when we have a source reference to a derived
633 -- operation, where the derived operation itself does not come from
634 -- source, but we still want to mark it as referenced, since we really
635 -- are referencing an entity in the corresponding package (this avoids
636 -- wrong complaints that the package contains no referenced entities).
640 -- Assignable object appearing on left side of assignment or as
644 and then Is_On_LHS (N)
645 and then Ekind (E) /= E_In_Out_Parameter
647 -- For objects that are renamings, just set as simply referenced
648 -- we do not try to do assignment type tracking in this case.
650 if Present (Renamed_Object (E)) then
653 -- Out parameter case
655 elsif Kind = E_Out_Parameter then
657 -- If warning mode for all out parameters is set, or this is
658 -- the only warning parameter, then we want to mark this for
659 -- later warning logic by setting Referenced_As_Out_Parameter
661 if Warn_On_Modified_As_Out_Parameter (Formal) then
662 Set_Referenced_As_Out_Parameter (E, True);
663 Set_Referenced_As_LHS (E, False);
665 -- For OUT parameter not covered by the above cases, we simply
666 -- regard it as a normal reference (in this case we do not
667 -- want any of the warning machinery for out parameters).
673 -- For the left hand of an assignment case, we do nothing here.
674 -- The processing for Analyze_Assignment_Statement will set the
675 -- Referenced_As_LHS flag.
681 -- Check for a reference in a pragma that should not count as a
682 -- making the variable referenced for warning purposes.
684 elsif Is_Non_Significant_Pragma_Reference (N) then
687 -- A reference in an attribute definition clause does not count as a
688 -- reference except for the case of Address. The reason that 'Address
689 -- is an exception is that it creates an alias through which the
690 -- variable may be referenced.
692 elsif Nkind (Parent (N)) = N_Attribute_Definition_Clause
693 and then Chars (Parent (N)) /= Name_Address
694 and then N = Name (Parent (N))
698 -- Constant completion does not count as a reference
701 and then Ekind (E) = E_Constant
705 -- Record representation clause does not count as a reference
707 elsif Nkind (N) = N_Identifier
708 and then Nkind (Parent (N)) = N_Record_Representation_Clause
712 -- Discriminants do not need to produce a reference to record type
715 and then Nkind (Parent (N)) = N_Discriminant_Specification
722 -- Special processing for IN OUT parameters, where we have an
723 -- implicit assignment to a simple variable.
725 if Kind = E_In_Out_Parameter
726 and then Is_Assignable (E)
728 -- For sure this counts as a normal read reference
731 Set_Last_Assignment (E, Empty);
733 -- We count it as being referenced as an out parameter if the
734 -- option is set to warn on all out parameters, except that we
735 -- have a special exclusion for an intrinsic subprogram, which
736 -- is most likely an instantiation of Unchecked_Deallocation
737 -- which we do not want to consider as an assignment since it
738 -- generates false positives. We also exclude the case of an
739 -- IN OUT parameter if the name of the procedure is Free,
740 -- since we suspect similar semantics.
742 if Warn_On_All_Unread_Out_Parameters
743 and then Is_Entity_Name (Name (Call))
744 and then not Is_Intrinsic_Subprogram (Entity (Name (Call)))
745 and then Chars (Name (Call)) /= Name_Free
747 Set_Referenced_As_Out_Parameter (E, True);
748 Set_Referenced_As_LHS (E, False);
751 -- Don't count a recursive reference within a subprogram as a
752 -- reference (that allows detection of a recursive subprogram
753 -- whose only references are recursive calls as unreferenced).
755 elsif Is_Subprogram (E)
756 and then E = Nearest_Dynamic_Scope (Current_Scope)
760 -- Any other occurrence counts as referencing the entity
762 elsif OK_To_Set_Referenced then
765 -- If variable, this is an OK reference after an assignment
766 -- so we can clear the Last_Assignment indication.
768 if Is_Assignable (E) then
769 Set_Last_Assignment (E, Empty);
774 -- Check for pragma Unreferenced given and reference is within
775 -- this source unit (occasion for possible warning to be issued).
777 if Has_Unreferenced (E)
778 and then In_Same_Extended_Unit (E, N)
780 -- A reference as a named parameter in a call does not count
781 -- as a violation of pragma Unreferenced for this purpose...
783 if Nkind (N) = N_Identifier
784 and then Nkind (Parent (N)) = N_Parameter_Association
785 and then Selector_Name (Parent (N)) = N
789 -- ... Neither does a reference to a variable on the left side
792 elsif Is_On_LHS (N) then
795 -- For entry formals, we want to place the warning message on the
796 -- corresponding entity in the accept statement. The current scope
797 -- is the body of the accept, so we find the formal whose name
798 -- matches that of the entry formal (there is no link between the
799 -- two entities, and the one in the accept statement is only used
800 -- for conformance checking).
802 elsif Ekind (Scope (E)) = E_Entry then
807 BE := First_Entity (Current_Scope);
808 while Present (BE) loop
809 if Chars (BE) = Chars (E) then
810 Error_Msg_NE -- CODEFIX
811 ("?pragma Unreferenced given for&!", N, BE);
819 -- Here we issue the warning, since this is a real reference
822 Error_Msg_NE -- CODEFIX
823 ("?pragma Unreferenced given for&!", N, E);
827 -- If this is a subprogram instance, mark as well the internal
828 -- subprogram in the wrapper package, which may be a visible
831 if Is_Overloadable (E)
832 and then Is_Generic_Instance (E)
833 and then Present (Alias (E))
835 Set_Referenced (Alias (E));
839 -- Generate reference if all conditions are met:
842 -- Cross referencing must be active
846 -- The entity must be one for which we collect references
848 and then Xref_Entity_Letters (Ekind (E)) /= ' '
850 -- Both Sloc values must be set to something sensible
852 and then Sloc (E) > No_Location
853 and then Sloc (N) > No_Location
855 -- We ignore references from within an instance, except for default
856 -- subprograms, for which we generate an implicit reference.
859 (Instantiation_Location (Sloc (N)) = No_Location or else Typ = 'i')
861 -- Ignore dummy references
865 if Nkind (N) = N_Identifier
867 Nkind (N) = N_Defining_Identifier
871 Nkind (N) = N_Defining_Operator_Symbol
873 Nkind (N) = N_Operator_Symbol
875 (Nkind (N) = N_Character_Literal
876 and then Sloc (Entity (N)) /= Standard_Location)
878 Nkind (N) = N_Defining_Character_Literal
882 elsif Nkind (N) = N_Expanded_Name
884 Nkind (N) = N_Selected_Component
886 Nod := Selector_Name (N);
892 -- Normal case of source entity comes from source
894 if Comes_From_Source (E) then
897 -- Entity does not come from source, but is a derived subprogram and
898 -- the derived subprogram comes from source (after one or more
899 -- derivations) in which case the reference is to parent subprogram.
901 elsif Is_Overloadable (E)
902 and then Present (Alias (E))
905 while not Comes_From_Source (Ent) loop
906 if No (Alias (Ent)) then
913 -- The internally created defining entity for a child subprogram
914 -- that has no previous spec has valid references.
916 elsif Is_Overloadable (E)
917 and then Is_Child_Unit (E)
921 -- Record components of discriminated subtypes or derived types must
922 -- be treated as references to the original component.
924 elsif Ekind (E) = E_Component
925 and then Comes_From_Source (Original_Record_Component (E))
927 Ent := Original_Record_Component (E);
929 -- If this is an expanded reference to a discriminant, recover the
930 -- original discriminant, which gets the reference.
932 elsif Ekind (E) = E_In_Parameter
933 and then Present (Discriminal_Link (E))
935 Ent := Discriminal_Link (E);
936 Set_Referenced (Ent);
938 -- Ignore reference to any other entity that is not from source
944 -- Record reference to entity
946 Ref := Original_Location (Sloc (Nod));
947 Def := Original_Location (Sloc (Ent));
949 Ref_Scope := Enclosing_Subprogram_Or_Package (N);
950 Ent_Scope := Enclosing_Subprogram_Or_Package (Ent);
952 Xrefs.Increment_Last;
955 Xrefs.Table (Indx).Loc := Ref;
957 -- Overriding operations are marked with 'P'
960 and then Is_Subprogram (N)
961 and then Present (Overridden_Operation (N))
963 Xrefs.Table (Indx).Typ := 'P';
965 Xrefs.Table (Indx).Typ := Typ;
968 Xrefs.Table (Indx).Eun := Get_Source_Unit (Def);
969 Xrefs.Table (Indx).Lun := Get_Source_Unit (Ref);
970 Xrefs.Table (Indx).Ent := Ent;
972 Xrefs.Table (Indx).Ref_Scope := Ref_Scope;
973 Xrefs.Table (Indx).Ent_Scope := Ent_Scope;
974 Xrefs.Table (Indx).Ent_Scope_File := Get_Source_Unit (Ent_Scope);
976 Set_Has_Xref_Entry (Ent);
978 end Generate_Reference;
980 -----------------------------------
981 -- Generate_Reference_To_Formals --
982 -----------------------------------
984 procedure Generate_Reference_To_Formals (E : Entity_Id) is
988 if Is_Generic_Subprogram (E) then
989 Formal := First_Entity (E);
991 while Present (Formal)
992 and then not Is_Formal (Formal)
994 Next_Entity (Formal);
998 Formal := First_Formal (E);
1001 while Present (Formal) loop
1002 if Ekind (Formal) = E_In_Parameter then
1004 if Nkind (Parameter_Type (Parent (Formal)))
1005 = N_Access_Definition
1007 Generate_Reference (E, Formal, '^', False);
1009 Generate_Reference (E, Formal, '>', False);
1012 elsif Ekind (Formal) = E_In_Out_Parameter then
1013 Generate_Reference (E, Formal, '=', False);
1016 Generate_Reference (E, Formal, '<', False);
1019 Next_Formal (Formal);
1021 end Generate_Reference_To_Formals;
1023 -------------------------------------------
1024 -- Generate_Reference_To_Generic_Formals --
1025 -------------------------------------------
1027 procedure Generate_Reference_To_Generic_Formals (E : Entity_Id) is
1031 Formal := First_Entity (E);
1032 while Present (Formal) loop
1033 if Comes_From_Source (Formal) then
1034 Generate_Reference (E, Formal, 'z', False);
1037 Next_Entity (Formal);
1039 end Generate_Reference_To_Generic_Formals;
1045 procedure Initialize is
1054 function Lt (T1, T2 : Xref_Entry) return Boolean is
1056 -- First test: if entity is in different unit, sort by unit
1058 if T1.Eun /= T2.Eun then
1059 return Dependency_Num (T1.Eun) < Dependency_Num (T2.Eun);
1061 -- Second test: within same unit, sort by entity Sloc
1063 elsif T1.Def /= T2.Def then
1064 return T1.Def < T2.Def;
1066 -- Third test: sort definitions ahead of references
1068 elsif T1.Loc = No_Location then
1071 elsif T2.Loc = No_Location then
1074 -- Fourth test: for same entity, sort by reference location unit
1076 elsif T1.Lun /= T2.Lun then
1077 return Dependency_Num (T1.Lun) < Dependency_Num (T2.Lun);
1079 -- Fifth test: order of location within referencing unit
1081 elsif T1.Loc /= T2.Loc then
1082 return T1.Loc < T2.Loc;
1084 -- Finally, for two locations at the same address, we prefer
1085 -- the one that does NOT have the type 'r' so that a modification
1086 -- or extension takes preference, when there are more than one
1087 -- reference at the same location. As a result, in the case of
1088 -- entities that are in-out actuals, the read reference follows
1089 -- the modify reference.
1092 return T2.Typ = 'r';
1096 -----------------------
1097 -- Output_References --
1098 -----------------------
1100 procedure Output_References is
1102 procedure Get_Type_Reference
1104 Tref : out Entity_Id;
1105 Left : out Character;
1106 Right : out Character);
1107 -- Given an Entity_Id Ent, determines whether a type reference is
1108 -- required. If so, Tref is set to the entity for the type reference
1109 -- and Left and Right are set to the left/right brackets to be output
1110 -- for the reference. If no type reference is required, then Tref is
1111 -- set to Empty, and Left/Right are set to space.
1113 procedure Output_Import_Export_Info (Ent : Entity_Id);
1114 -- Output language and external name information for an interfaced
1115 -- entity, using the format <language, external_name>,
1117 ------------------------
1118 -- Get_Type_Reference --
1119 ------------------------
1121 procedure Get_Type_Reference
1123 Tref : out Entity_Id;
1124 Left : out Character;
1125 Right : out Character)
1130 -- See if we have a type reference
1139 -- Processing for types
1141 if Is_Type (Tref) then
1143 -- Case of base type
1145 if Base_Type (Tref) = Tref then
1147 -- If derived, then get first subtype
1149 if Tref /= Etype (Tref) then
1150 Tref := First_Subtype (Etype (Tref));
1152 -- Set brackets for derived type, but don't override
1153 -- pointer case since the fact that something is a
1154 -- pointer is more important.
1161 -- If non-derived ptr, get directly designated type.
1162 -- If the type has a full view, all references are on the
1163 -- partial view, that is seen first.
1165 elsif Is_Access_Type (Tref) then
1166 Tref := Directly_Designated_Type (Tref);
1170 elsif Is_Private_Type (Tref)
1171 and then Present (Full_View (Tref))
1173 if Is_Access_Type (Full_View (Tref)) then
1174 Tref := Directly_Designated_Type (Full_View (Tref));
1178 -- If the full view is an array type, we also retrieve
1179 -- the corresponding component type, because the ali
1180 -- entry already indicates that this is an array.
1182 elsif Is_Array_Type (Full_View (Tref)) then
1183 Tref := Component_Type (Full_View (Tref));
1188 -- If non-derived array, get component type. Skip component
1189 -- type for case of String or Wide_String, saves worthwhile
1192 elsif Is_Array_Type (Tref)
1193 and then Tref /= Standard_String
1194 and then Tref /= Standard_Wide_String
1196 Tref := Component_Type (Tref);
1200 -- For other non-derived base types, nothing
1206 -- For a subtype, go to ancestor subtype
1209 Tref := Ancestor_Subtype (Tref);
1211 -- If no ancestor subtype, go to base type
1214 Tref := Base_Type (Sav);
1218 -- For objects, functions, enum literals, just get type from
1221 elsif Is_Object (Tref)
1222 or else Ekind (Tref) = E_Enumeration_Literal
1223 or else Ekind (Tref) = E_Function
1224 or else Ekind (Tref) = E_Operator
1226 Tref := Etype (Tref);
1228 -- For anything else, exit
1234 -- Exit if no type reference, or we are stuck in some loop trying
1235 -- to find the type reference, or if the type is standard void
1236 -- type (the latter is an implementation artifact that should not
1237 -- show up in the generated cross-references).
1241 or else Tref = Standard_Void_Type;
1243 -- If we have a usable type reference, return, otherwise keep
1244 -- looking for something useful (we are looking for something
1245 -- that either comes from source or standard)
1247 if Sloc (Tref) = Standard_Location
1248 or else Comes_From_Source (Tref)
1250 -- If the reference is a subtype created for a generic actual,
1251 -- go actual directly, the inner subtype is not user visible.
1253 if Nkind (Parent (Tref)) = N_Subtype_Declaration
1254 and then not Comes_From_Source (Parent (Tref))
1256 (Is_Wrapper_Package (Scope (Tref))
1257 or else Is_Generic_Instance (Scope (Tref)))
1259 Tref := First_Subtype (Base_Type (Tref));
1266 -- If we fall through the loop, no type reference
1271 end Get_Type_Reference;
1273 -------------------------------
1274 -- Output_Import_Export_Info --
1275 -------------------------------
1277 procedure Output_Import_Export_Info (Ent : Entity_Id) is
1278 Language_Name : Name_Id;
1279 Conv : constant Convention_Id := Convention (Ent);
1282 -- Generate language name from convention
1284 if Conv = Convention_C then
1285 Language_Name := Name_C;
1287 elsif Conv = Convention_CPP then
1288 Language_Name := Name_CPP;
1290 elsif Conv = Convention_Ada then
1291 Language_Name := Name_Ada;
1294 -- For the moment we ignore all other cases ???
1299 Write_Info_Char ('<');
1300 Get_Unqualified_Name_String (Language_Name);
1302 for J in 1 .. Name_Len loop
1303 Write_Info_Char (Name_Buffer (J));
1306 if Present (Interface_Name (Ent)) then
1307 Write_Info_Char (',');
1308 String_To_Name_Buffer (Strval (Interface_Name (Ent)));
1310 for J in 1 .. Name_Len loop
1311 Write_Info_Char (Name_Buffer (J));
1315 Write_Info_Char ('>');
1316 end Output_Import_Export_Info;
1318 -- Start of processing for Output_References
1321 -- First we add references to the primitive operations of tagged types
1322 -- declared in the main unit.
1324 Handle_Prim_Ops : declare
1328 for J in 1 .. Xrefs.Last loop
1329 Ent := Xrefs.Table (J).Ent;
1332 and then Is_Tagged_Type (Ent)
1333 and then Is_Base_Type (Ent)
1334 and then In_Extended_Main_Source_Unit (Ent)
1336 Generate_Prim_Op_References (Ent);
1339 end Handle_Prim_Ops;
1341 -- Before we go ahead and output the references we have a problem
1342 -- that needs dealing with. So far we have captured things that are
1343 -- definitely referenced by the main unit, or defined in the main
1344 -- unit. That's because we don't want to clutter up the ali file
1345 -- for this unit with definition lines for entities in other units
1346 -- that are not referenced.
1348 -- But there is a glitch. We may reference an entity in another unit,
1349 -- and it may have a type reference to an entity that is not directly
1350 -- referenced in the main unit, which may mean that there is no xref
1351 -- entry for this entity yet in the list of references.
1353 -- If we don't do something about this, we will end with an orphan type
1354 -- reference, i.e. it will point to an entity that does not appear
1355 -- within the generated references in the ali file. That is not good for
1356 -- tools using the xref information.
1358 -- To fix this, we go through the references adding definition entries
1359 -- for any unreferenced entities that can be referenced in a type
1360 -- reference. There is a recursion problem here, and that is dealt with
1361 -- by making sure that this traversal also traverses any entries that
1362 -- get added by the traversal.
1364 Handle_Orphan_Type_References : declare
1372 pragma Warnings (Off, L);
1373 pragma Warnings (Off, R);
1375 procedure New_Entry (E : Entity_Id);
1376 -- Make an additional entry into the Xref table for a type entity
1377 -- that is related to the current entity (parent, type ancestor,
1378 -- progenitor, etc.).
1384 procedure New_Entry (E : Entity_Id) is
1387 and then not Has_Xref_Entry (E)
1388 and then Sloc (E) > No_Location
1390 Xrefs.Increment_Last;
1392 Loc := Original_Location (Sloc (E));
1393 Xrefs.Table (Indx).Ent := E;
1394 Xrefs.Table (Indx).Loc := No_Location;
1395 Xrefs.Table (Indx).Eun := Get_Source_Unit (Loc);
1396 Xrefs.Table (Indx).Lun := No_Unit;
1397 Set_Has_Xref_Entry (E);
1401 -- Start of processing for Handle_Orphan_Type_References
1404 -- Note that this is not a for loop for a very good reason. The
1405 -- processing of items in the table can add new items to the table,
1406 -- and they must be processed as well.
1409 while J <= Xrefs.Last loop
1410 Ent := Xrefs.Table (J).Ent;
1411 Get_Type_Reference (Ent, Tref, L, R);
1414 and then not Has_Xref_Entry (Tref)
1415 and then Sloc (Tref) > No_Location
1419 if Is_Record_Type (Ent)
1420 and then Present (Interfaces (Ent))
1422 -- Add an entry for each one of the given interfaces
1423 -- implemented by type Ent.
1426 Elmt : Elmt_Id := First_Elmt (Interfaces (Ent));
1428 while Present (Elmt) loop
1429 New_Entry (Node (Elmt));
1436 -- Collect inherited primitive operations that may be declared in
1437 -- another unit and have no visible reference in the current one.
1440 and then Is_Tagged_Type (Ent)
1441 and then Is_Derived_Type (Ent)
1442 and then Is_Base_Type (Ent)
1443 and then In_Extended_Main_Source_Unit (Ent)
1446 Op_List : constant Elist_Id := Primitive_Operations (Ent);
1450 function Parent_Op (E : Entity_Id) return Entity_Id;
1451 -- Find original operation, which may be inherited through
1452 -- several derivations.
1454 function Parent_Op (E : Entity_Id) return Entity_Id is
1455 Orig_Op : constant Entity_Id := Alias (E);
1458 if No (Orig_Op) then
1461 elsif not Comes_From_Source (E)
1462 and then not Has_Xref_Entry (Orig_Op)
1463 and then Comes_From_Source (Orig_Op)
1467 return Parent_Op (Orig_Op);
1472 Op := First_Elmt (Op_List);
1473 while Present (Op) loop
1474 Prim := Parent_Op (Node (Op));
1476 if Present (Prim) then
1477 Xrefs.Increment_Last;
1479 Loc := Original_Location (Sloc (Prim));
1480 Xrefs.Table (Indx).Ent := Prim;
1481 Xrefs.Table (Indx).Loc := No_Location;
1482 Xrefs.Table (Indx).Eun :=
1483 Get_Source_Unit (Sloc (Prim));
1484 Xrefs.Table (Indx).Lun := No_Unit;
1485 Set_Has_Xref_Entry (Prim);
1495 end Handle_Orphan_Type_References;
1497 -- Now we have all the references, including those for any embedded
1498 -- type references, so we can sort them, and output them.
1500 Output_Refs : declare
1502 Nrefs : Nat := Xrefs.Last;
1503 -- Number of references in table. This value may get reset (reduced)
1504 -- when we eliminate duplicate reference entries.
1506 Rnums : array (0 .. Nrefs) of Nat;
1507 -- This array contains numbers of references in the Xrefs table.
1508 -- This list is sorted in output order. The extra 0'th entry is
1509 -- convenient for the call to sort. When we sort the table, we
1510 -- move the entries in Rnums around, but we do not move the
1511 -- original table entries.
1513 Curxu : Unit_Number_Type;
1514 -- Current xref unit
1516 Curru : Unit_Number_Type;
1517 -- Current reference unit for one entity
1522 Curnam : String (1 .. Name_Buffer'Length);
1524 -- Simple name and length of current entity
1526 Curdef : Source_Ptr;
1527 -- Original source location for current entity
1530 -- Current reference location
1533 -- Entity type character
1536 -- reference kind of previous reference
1542 -- Renaming reference
1544 Trunit : Unit_Number_Type;
1545 -- Unit number for type reference
1547 function Lt (Op1, Op2 : Natural) return Boolean;
1548 -- Comparison function for Sort call
1550 function Name_Change (X : Entity_Id) return Boolean;
1551 -- Determines if entity X has a different simple name from Curent
1553 procedure Move (From : Natural; To : Natural);
1554 -- Move procedure for Sort call
1556 package Sorting is new GNAT.Heap_Sort_G (Move, Lt);
1562 function Lt (Op1, Op2 : Natural) return Boolean is
1563 T1 : Xref_Entry renames Xrefs.Table (Rnums (Nat (Op1)));
1564 T2 : Xref_Entry renames Xrefs.Table (Rnums (Nat (Op2)));
1574 procedure Move (From : Natural; To : Natural) is
1576 Rnums (Nat (To)) := Rnums (Nat (From));
1583 -- Why a string comparison here??? Why not compare Name_Id values???
1585 function Name_Change (X : Entity_Id) return Boolean is
1587 Get_Unqualified_Name_String (Chars (X));
1589 if Name_Len /= Curlen then
1592 return Name_Buffer (1 .. Curlen) /= Curnam (1 .. Curlen);
1596 -- Start of processing for Output_Refs
1599 -- Capture the definition Sloc values. We delay doing this till now,
1600 -- since at the time the reference or definition is made, private
1601 -- types may be swapped, and the Sloc value may be incorrect. We
1602 -- also set up the pointer vector for the sort.
1604 for J in 1 .. Nrefs loop
1606 Xrefs.Table (J).Def :=
1607 Original_Location (Sloc (Xrefs.Table (J).Ent));
1610 -- Sort the references
1612 Sorting.Sort (Integer (Nrefs));
1614 -- Eliminate duplicate entries
1617 NR : constant Nat := Nrefs;
1620 -- We need this test for NR because if we force ALI file
1621 -- generation in case of errors detected, it may be the case
1622 -- that Nrefs is 0, so we should not reset it here
1627 for J in 2 .. NR loop
1628 if Xrefs.Table (Rnums (J)) /=
1629 Xrefs.Table (Rnums (Nrefs))
1632 Rnums (Nrefs) := Rnums (J);
1638 -- Initialize loop through references
1642 Curdef := No_Location;
1644 Crloc := No_Location;
1647 -- Loop to output references
1649 for Refno in 1 .. Nrefs loop
1650 Output_One_Ref : declare
1653 XE : Xref_Entry renames Xrefs.Table (Rnums (Refno));
1654 -- The current entry to be accessed
1658 -- Used for {} or <> or () for type reference
1660 procedure Check_Type_Reference
1662 List_Interface : Boolean);
1663 -- Find whether there is a meaningful type reference for
1664 -- Ent, and display it accordingly. If List_Interface is
1665 -- true, then Ent is a progenitor interface of the current
1666 -- type entity being listed. In that case list it as is,
1667 -- without looking for a type reference for it.
1669 procedure Output_Instantiation_Refs (Loc : Source_Ptr);
1670 -- Recursive procedure to output instantiation references for
1671 -- the given source ptr in [file|line[...]] form. No output
1672 -- if the given location is not a generic template reference.
1674 procedure Output_Overridden_Op (Old_E : Entity_Id);
1675 -- For a subprogram that is overriding, display information
1676 -- about the inherited operation that it overrides.
1678 --------------------------
1679 -- Check_Type_Reference --
1680 --------------------------
1682 procedure Check_Type_Reference
1684 List_Interface : Boolean)
1687 if List_Interface then
1689 -- This is a progenitor interface of the type for which
1690 -- xref information is being generated.
1697 Get_Type_Reference (Ent, Tref, Left, Right);
1700 if Present (Tref) then
1702 -- Case of standard entity, output name
1704 if Sloc (Tref) = Standard_Location then
1705 Write_Info_Char (Left);
1706 Write_Info_Name (Chars (Tref));
1707 Write_Info_Char (Right);
1709 -- Case of source entity, output location
1712 Write_Info_Char (Left);
1713 Trunit := Get_Source_Unit (Sloc (Tref));
1715 if Trunit /= Curxu then
1716 Write_Info_Nat (Dependency_Num (Trunit));
1717 Write_Info_Char ('|');
1721 (Int (Get_Logical_Line_Number (Sloc (Tref))));
1729 Ctyp := Xref_Entity_Letters (Ekind (Ent));
1732 and then Present (Full_View (Ent))
1734 Ent := Underlying_Type (Ent);
1736 if Present (Ent) then
1737 Ctyp := Xref_Entity_Letters (Ekind (Ent));
1741 Write_Info_Char (Ctyp);
1745 (Int (Get_Column_Number (Sloc (Tref))));
1747 -- If the type comes from an instantiation, add the
1748 -- corresponding info.
1750 Output_Instantiation_Refs (Sloc (Tref));
1751 Write_Info_Char (Right);
1754 end Check_Type_Reference;
1756 -------------------------------
1757 -- Output_Instantiation_Refs --
1758 -------------------------------
1760 procedure Output_Instantiation_Refs (Loc : Source_Ptr) is
1761 Iloc : constant Source_Ptr := Instantiation_Location (Loc);
1762 Lun : Unit_Number_Type;
1763 Cu : constant Unit_Number_Type := Curru;
1766 -- Nothing to do if this is not an instantiation
1768 if Iloc = No_Location then
1772 -- Output instantiation reference
1774 Write_Info_Char ('[');
1775 Lun := Get_Source_Unit (Iloc);
1777 if Lun /= Curru then
1779 Write_Info_Nat (Dependency_Num (Curru));
1780 Write_Info_Char ('|');
1783 Write_Info_Nat (Int (Get_Logical_Line_Number (Iloc)));
1785 -- Recursive call to get nested instantiations
1787 Output_Instantiation_Refs (Iloc);
1789 -- Output final ] after call to get proper nesting
1791 Write_Info_Char (']');
1794 end Output_Instantiation_Refs;
1796 --------------------------
1797 -- Output_Overridden_Op --
1798 --------------------------
1800 procedure Output_Overridden_Op (Old_E : Entity_Id) is
1804 -- The overridden operation has an implicit declaration
1805 -- at the point of derivation. What we want to display
1806 -- is the original operation, which has the actual body
1807 -- (or abstract declaration) that is being overridden.
1808 -- The overridden operation is not always set, e.g. when
1809 -- it is a predefined operator.
1814 -- Follow alias chain if one is present
1816 elsif Present (Alias (Old_E)) then
1818 -- The subprogram may have been implicitly inherited
1819 -- through several levels of derivation, so find the
1820 -- ultimate (source) ancestor.
1822 Op := Ultimate_Alias (Old_E);
1824 -- Normal case of no alias present
1831 and then Sloc (Op) /= Standard_Location
1834 Loc : constant Source_Ptr := Sloc (Op);
1835 Par_Unit : constant Unit_Number_Type :=
1836 Get_Source_Unit (Loc);
1839 Write_Info_Char ('<');
1841 if Par_Unit /= Curxu then
1842 Write_Info_Nat (Dependency_Num (Par_Unit));
1843 Write_Info_Char ('|');
1846 Write_Info_Nat (Int (Get_Logical_Line_Number (Loc)));
1847 Write_Info_Char ('p');
1848 Write_Info_Nat (Int (Get_Column_Number (Loc)));
1849 Write_Info_Char ('>');
1852 end Output_Overridden_Op;
1854 -- Start of processing for Output_One_Ref
1858 Ctyp := Xref_Entity_Letters (Ekind (Ent));
1860 -- Skip reference if it is the only reference to an entity,
1861 -- and it is an END line reference, and the entity is not in
1862 -- the current extended source. This prevents junk entries
1863 -- consisting only of packages with END lines, where no
1864 -- entity from the package is actually referenced.
1867 and then Ent /= Curent
1868 and then (Refno = Nrefs or else
1869 Ent /= Xrefs.Table (Rnums (Refno + 1)).Ent)
1871 not In_Extended_Main_Source_Unit (Ent)
1876 -- For private type, get full view type
1879 and then Present (Full_View (XE.Ent))
1881 Ent := Underlying_Type (Ent);
1883 if Present (Ent) then
1884 Ctyp := Xref_Entity_Letters (Ekind (Ent));
1888 -- Special exception for Boolean
1890 if Ctyp = 'E' and then Is_Boolean_Type (Ent) then
1894 -- For variable reference, get corresponding type
1897 Ent := Etype (XE.Ent);
1898 Ctyp := Fold_Lower (Xref_Entity_Letters (Ekind (Ent)));
1900 -- If variable is private type, get full view type
1903 and then Present (Full_View (Etype (XE.Ent)))
1905 Ent := Underlying_Type (Etype (XE.Ent));
1907 if Present (Ent) then
1908 Ctyp := Fold_Lower (Xref_Entity_Letters (Ekind (Ent)));
1911 elsif Is_Generic_Type (Ent) then
1913 -- If the type of the entity is a generic private type,
1914 -- there is no usable full view, so retain the indication
1915 -- that this is an object.
1920 -- Special handling for access parameters and objects of
1921 -- an anonymous access type.
1923 if Ekind_In (Etype (XE.Ent),
1924 E_Anonymous_Access_Type,
1925 E_Anonymous_Access_Subprogram_Type,
1926 E_Anonymous_Access_Protected_Subprogram_Type)
1928 if Is_Formal (XE.Ent)
1929 or else Ekind_In (XE.Ent, E_Variable, E_Constant)
1934 -- Special handling for Boolean
1936 elsif Ctyp = 'e' and then Is_Boolean_Type (Ent) then
1941 -- Special handling for abstract types and operations
1943 if Is_Overloadable (XE.Ent)
1944 and then Is_Abstract_Subprogram (XE.Ent)
1947 Ctyp := 'x'; -- Abstract procedure
1949 elsif Ctyp = 'V' then
1950 Ctyp := 'y'; -- Abstract function
1953 elsif Is_Type (XE.Ent)
1954 and then Is_Abstract_Type (XE.Ent)
1956 if Is_Interface (XE.Ent) then
1959 elsif Ctyp = 'R' then
1960 Ctyp := 'H'; -- Abstract type
1964 -- Only output reference if interesting type of entity
1968 -- Suppress references to object definitions, used for local
1971 or else XE.Typ = 'D'
1972 or else XE.Typ = 'I'
1974 -- Suppress self references, except for bodies that act as
1977 or else (XE.Loc = XE.Def
1980 or else not Is_Subprogram (XE.Ent)))
1982 -- Also suppress definitions of body formals (we only
1983 -- treat these as references, and the references were
1984 -- separately recorded).
1986 or else (Is_Formal (XE.Ent)
1987 and then Present (Spec_Entity (XE.Ent)))
1992 -- Start new Xref section if new xref unit
1994 if XE.Eun /= Curxu then
1995 if Write_Info_Col > 1 then
2001 Write_Info_Initiate ('X');
2002 Write_Info_Char (' ');
2003 Write_Info_Nat (Dependency_Num (XE.Eun));
2004 Write_Info_Char (' ');
2005 Write_Info_Name (Reference_Name (Source_Index (XE.Eun)));
2008 -- Start new Entity line if new entity. Note that we
2009 -- consider two entities the same if they have the same
2010 -- name and source location. This causes entities in
2011 -- instantiations to be treated as though they referred
2018 (Name_Change (XE.Ent) or else XE.Def /= Curdef))
2023 Get_Unqualified_Name_String (Chars (XE.Ent));
2025 Curnam (1 .. Curlen) := Name_Buffer (1 .. Curlen);
2027 if Write_Info_Col > 1 then
2031 -- Write column number information
2033 Write_Info_Nat (Int (Get_Logical_Line_Number (XE.Def)));
2034 Write_Info_Char (Ctyp);
2035 Write_Info_Nat (Int (Get_Column_Number (XE.Def)));
2037 -- Write level information
2039 Write_Level_Info : declare
2040 function Is_Visible_Generic_Entity
2041 (E : Entity_Id) return Boolean;
2042 -- Check whether E is declared in the visible part
2043 -- of a generic package. For source navigation
2044 -- purposes, treat this as a visible entity.
2046 function Is_Private_Record_Component
2047 (E : Entity_Id) return Boolean;
2048 -- Check whether E is a non-inherited component of a
2049 -- private extension. Even if the enclosing record is
2050 -- public, we want to treat the component as private
2051 -- for navigation purposes.
2053 ---------------------------------
2054 -- Is_Private_Record_Component --
2055 ---------------------------------
2057 function Is_Private_Record_Component
2058 (E : Entity_Id) return Boolean
2060 S : constant Entity_Id := Scope (E);
2063 Ekind (E) = E_Component
2064 and then Nkind (Declaration_Node (S)) =
2065 N_Private_Extension_Declaration
2066 and then Original_Record_Component (E) = E;
2067 end Is_Private_Record_Component;
2069 -------------------------------
2070 -- Is_Visible_Generic_Entity --
2071 -------------------------------
2073 function Is_Visible_Generic_Entity
2074 (E : Entity_Id) return Boolean
2079 -- The Present check here is an error defense
2081 if Present (Scope (E))
2082 and then Ekind (Scope (E)) /= E_Generic_Package
2088 while Present (Par) loop
2090 Nkind (Par) = N_Generic_Package_Declaration
2092 -- Entity is a generic formal
2097 Nkind (Parent (Par)) = N_Package_Specification
2100 Is_List_Member (Par)
2101 and then List_Containing (Par) =
2102 Visible_Declarations (Parent (Par));
2104 Par := Parent (Par);
2109 end Is_Visible_Generic_Entity;
2111 -- Start of processing for Write_Level_Info
2114 if Is_Hidden (Curent)
2115 or else Is_Private_Record_Component (Curent)
2117 Write_Info_Char (' ');
2121 or else Is_Visible_Generic_Entity (Curent)
2123 Write_Info_Char ('*');
2126 Write_Info_Char (' ');
2128 end Write_Level_Info;
2130 -- Output entity name. We use the occurrence from the
2131 -- actual source program at the definition point.
2134 Ent_Name : constant String :=
2135 Exact_Source_Name (Sloc (XE.Ent));
2137 for C in Ent_Name'Range loop
2138 Write_Info_Char (Ent_Name (C));
2142 -- See if we have a renaming reference
2144 if Is_Object (XE.Ent)
2145 and then Present (Renamed_Object (XE.Ent))
2147 Rref := Renamed_Object (XE.Ent);
2149 elsif Is_Overloadable (XE.Ent)
2150 and then Nkind (Parent (Declaration_Node (XE.Ent))) =
2151 N_Subprogram_Renaming_Declaration
2153 Rref := Name (Parent (Declaration_Node (XE.Ent)));
2155 elsif Ekind (XE.Ent) = E_Package
2156 and then Nkind (Declaration_Node (XE.Ent)) =
2157 N_Package_Renaming_Declaration
2159 Rref := Name (Declaration_Node (XE.Ent));
2165 if Present (Rref) then
2166 if Nkind (Rref) = N_Expanded_Name then
2167 Rref := Selector_Name (Rref);
2170 if Nkind (Rref) = N_Identifier
2171 or else Nkind (Rref) = N_Operator_Symbol
2175 -- For renamed array components, use the array name
2176 -- for the renamed entity, which reflect the fact that
2177 -- in general the whole array is aliased.
2179 elsif Nkind (Rref) = N_Indexed_Component then
2180 if Nkind (Prefix (Rref)) = N_Identifier then
2181 Rref := Prefix (Rref);
2182 elsif Nkind (Prefix (Rref)) = N_Expanded_Name then
2183 Rref := Selector_Name (Prefix (Rref));
2193 -- Write out renaming reference if we have one
2195 if Present (Rref) then
2196 Write_Info_Char ('=');
2198 (Int (Get_Logical_Line_Number (Sloc (Rref))));
2199 Write_Info_Char (':');
2201 (Int (Get_Column_Number (Sloc (Rref))));
2204 -- Indicate that the entity is in the unit of the current
2209 -- Write out information about generic parent, if entity
2212 if Is_Generic_Instance (XE.Ent) then
2214 Gen_Par : constant Entity_Id :=
2217 (Unit_Declaration_Node (XE.Ent)));
2218 Loc : constant Source_Ptr := Sloc (Gen_Par);
2219 Gen_U : constant Unit_Number_Type :=
2220 Get_Source_Unit (Loc);
2223 Write_Info_Char ('[');
2225 if Curru /= Gen_U then
2226 Write_Info_Nat (Dependency_Num (Gen_U));
2227 Write_Info_Char ('|');
2231 (Int (Get_Logical_Line_Number (Loc)));
2232 Write_Info_Char (']');
2236 -- See if we have a type reference and if so output
2238 Check_Type_Reference (XE.Ent, False);
2240 -- Additional information for types with progenitors
2242 if Is_Record_Type (XE.Ent)
2243 and then Present (Interfaces (XE.Ent))
2246 Elmt : Elmt_Id := First_Elmt (Interfaces (XE.Ent));
2248 while Present (Elmt) loop
2249 Check_Type_Reference (Node (Elmt), True);
2254 -- For array types, list index types as well. (This is
2255 -- not C, indexes have distinct types).
2257 elsif Is_Array_Type (XE.Ent) then
2261 Indx := First_Index (XE.Ent);
2262 while Present (Indx) loop
2263 Check_Type_Reference
2264 (First_Subtype (Etype (Indx)), True);
2270 -- If the entity is an overriding operation, write info
2271 -- on operation that was overridden.
2273 if Is_Subprogram (XE.Ent)
2274 and then Present (Overridden_Operation (XE.Ent))
2276 Output_Overridden_Op (Overridden_Operation (XE.Ent));
2279 -- End of processing for entity output
2281 Crloc := No_Location;
2284 -- Output the reference if it is not as the same location
2285 -- as the previous one, or it is a read-reference that
2286 -- indicates that the entity is an in-out actual in a call.
2288 if XE.Loc /= No_Location
2291 or else (Prevt = 'm' and then XE.Typ = 'r'))
2296 -- Start continuation if line full, else blank
2298 if Write_Info_Col > 72 then
2300 Write_Info_Initiate ('.');
2303 Write_Info_Char (' ');
2305 -- Output file number if changed
2307 if XE.Lun /= Curru then
2309 Write_Info_Nat (Dependency_Num (Curru));
2310 Write_Info_Char ('|');
2313 Write_Info_Nat (Int (Get_Logical_Line_Number (XE.Loc)));
2314 Write_Info_Char (XE.Typ);
2316 if Is_Overloadable (XE.Ent)
2317 and then Is_Imported (XE.Ent)
2318 and then XE.Typ = 'b'
2320 Output_Import_Export_Info (XE.Ent);
2323 Write_Info_Nat (Int (Get_Column_Number (XE.Loc)));
2325 Output_Instantiation_Refs (Sloc (XE.Ent));
2336 end Output_References;