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
177 or else Get_Pragma_Id (Result) = Pragma_Postcondition
181 Result := Parent (Result);
185 Result := Parent (Result);
189 if Nkind (Result) = N_Defining_Program_Unit_Name then
190 Result := Defining_Identifier (Result);
193 -- Do no return a scope without a proper location
196 and then Sloc (Result) = No_Location
202 end Enclosing_Subprogram_Or_Package;
204 -------------------------
205 -- Generate_Definition --
206 -------------------------
208 procedure Generate_Definition (E : Entity_Id) is
213 pragma Assert (Nkind (E) in N_Entity);
215 -- Note that we do not test Xref_Entity_Letters here. It is too early
216 -- to do so, since we are often called before the entity is fully
217 -- constructed, so that the Ekind is still E_Void.
221 -- Definition must come from source
223 -- We make an exception for subprogram child units that have no spec.
224 -- For these we generate a subprogram declaration for library use,
225 -- and the corresponding entity does not come from source.
226 -- Nevertheless, all references will be attached to it and we have
227 -- to treat is as coming from user code.
229 and then (Comes_From_Source (E) or else Is_Child_Unit (E))
231 -- And must have a reasonable source location that is not
232 -- within an instance (all entities in instances are ignored)
234 and then Sloc (E) > No_Location
235 and then Instantiation_Location (Sloc (E)) = No_Location
237 -- And must be a non-internal name from the main source unit
239 and then In_Extended_Main_Source_Unit (E)
240 and then not Is_Internal_Name (Chars (E))
242 Xrefs.Increment_Last;
244 Loc := Original_Location (Sloc (E));
246 Xrefs.Table (Indx).Ent := E;
247 Xrefs.Table (Indx).Typ := ' ';
248 Xrefs.Table (Indx).Def := No_Location;
249 Xrefs.Table (Indx).Loc := No_Location;
251 Xrefs.Table (Indx).Eun := Get_Source_Unit (Loc);
253 Xrefs.Table (Indx).Ref_Scope := Empty;
254 Xrefs.Table (Indx).Ent_Scope := Empty;
255 Xrefs.Table (Indx).Ent_Scope_File := No_Unit;
257 Set_Has_Xref_Entry (E);
259 if In_Inlined_Body then
263 end Generate_Definition;
265 ---------------------------------
266 -- Generate_Operator_Reference --
267 ---------------------------------
269 procedure Generate_Operator_Reference
274 if not In_Extended_Main_Source_Unit (N) then
278 -- If the operator is not a Standard operator, then we generate a real
279 -- reference to the user defined operator.
281 if Sloc (Entity (N)) /= Standard_Location then
282 Generate_Reference (Entity (N), N);
284 -- A reference to an implicit inequality operator is also a reference
285 -- to the user-defined equality.
287 if Nkind (N) = N_Op_Ne
288 and then not Comes_From_Source (Entity (N))
289 and then Present (Corresponding_Equality (Entity (N)))
291 Generate_Reference (Corresponding_Equality (Entity (N)), N);
294 -- For the case of Standard operators, we mark the result type as
295 -- referenced. This ensures that in the case where we are using a
296 -- derived operator, we mark an entity of the unit that implicitly
297 -- defines this operator as used. Otherwise we may think that no entity
298 -- of the unit is used. The actual entity marked as referenced is the
299 -- first subtype, which is the relevant user defined entity.
301 -- Note: we only do this for operators that come from source. The
302 -- generated code sometimes reaches for entities that do not need to be
303 -- explicitly visible (for example, when we expand the code for
304 -- comparing two record objects, the fields of the record may not be
307 elsif Comes_From_Source (N) then
308 Set_Referenced (First_Subtype (T));
310 end Generate_Operator_Reference;
312 ---------------------------------
313 -- Generate_Prim_Op_References --
314 ---------------------------------
316 procedure Generate_Prim_Op_References (Typ : Entity_Id) is
319 Prim_List : Elist_Id;
322 -- Handle subtypes of synchronized types
324 if Ekind (Typ) = E_Protected_Subtype
325 or else Ekind (Typ) = E_Task_Subtype
327 Base_T := Etype (Typ);
332 -- References to primitive operations are only relevant for tagged types
334 if not Is_Tagged_Type (Base_T)
335 or else Is_Class_Wide_Type (Base_T)
340 -- Ada 2005 (AI-345): For synchronized types generate reference to the
341 -- wrapper that allow us to dispatch calls through their implemented
342 -- abstract interface types.
344 -- The check for Present here is to protect against previously reported
347 Prim_List := Primitive_Operations (Base_T);
349 if No (Prim_List) then
353 Prim := First_Elmt (Prim_List);
354 while Present (Prim) loop
356 -- If the operation is derived, get the original for cross-reference
357 -- reference purposes (it is the original for which we want the xref
358 -- and for which the comes_from_source test must be performed).
361 (Typ, Ultimate_Alias (Node (Prim)), 'p', Set_Ref => False);
364 end Generate_Prim_Op_References;
366 ------------------------
367 -- Generate_Reference --
368 ------------------------
370 procedure Generate_Reference
373 Typ : Character := 'r';
374 Set_Ref : Boolean := True;
375 Force : Boolean := False)
383 Ref_Scope : Entity_Id;
384 Ent_Scope : Entity_Id;
388 -- Used for call to Find_Actual
391 -- If Formal is non-Empty, then its Ekind, otherwise E_Void
393 function Is_On_LHS (Node : Node_Id) return Boolean;
394 -- Used to check if a node is on the left hand side of an assignment.
395 -- The following cases are handled:
397 -- Variable Node is a direct descendant of left hand side of an
398 -- assignment statement.
400 -- Prefix Of an indexed or selected component that is present in
401 -- a subtree rooted by an assignment statement. There is
402 -- no restriction of nesting of components, thus cases
403 -- such as A.B (C).D are handled properly. However a prefix
404 -- of a dereference (either implicit or explicit) is never
405 -- considered as on a LHS.
407 -- Out param Same as above cases, but OUT parameter
409 function OK_To_Set_Referenced return Boolean;
410 -- Returns True if the Referenced flag can be set. There are a few
411 -- exceptions where we do not want to set this flag, see body for
412 -- details of these exceptional cases.
418 -- ??? There are several routines here and there that perform a similar
419 -- (but subtly different) computation, which should be factored:
421 -- Sem_Util.May_Be_Lvalue
422 -- Sem_Util.Known_To_Be_Assigned
423 -- Exp_Ch2.Expand_Entry_Parameter.In_Assignment_Context
424 -- Exp_Smem.Is_Out_Actual
426 function Is_On_LHS (Node : Node_Id) return Boolean is
432 -- Only identifiers are considered, is this necessary???
434 if Nkind (Node) /= N_Identifier then
438 -- Immediate return if appeared as OUT parameter
440 if Kind = E_Out_Parameter then
444 -- Search for assignment statement subtree root
451 if K = N_Assignment_Statement then
454 -- Check whether the parent is a component and the current node is
455 -- its prefix, but return False if the current node has an access
456 -- type, as in that case the selected or indexed component is an
457 -- implicit dereference, and the LHS is the designated object, not
458 -- the access object.
460 -- ??? case of a slice assignment?
462 -- ??? Note that in some cases this is called too early
463 -- (see comments in Sem_Ch8.Find_Direct_Name), at a point where
464 -- the tree is not fully typed yet. In that case we may lack
465 -- an Etype for N, and we must disable the check for an implicit
466 -- dereference. If the dereference is on an LHS, this causes a
469 elsif (K = N_Selected_Component or else K = N_Indexed_Component)
470 and then Prefix (P) = N
471 and then not (Present (Etype (N))
473 Is_Access_Type (Etype (N)))
477 -- All other cases, definitely not on left side
485 ---------------------------
486 -- OK_To_Set_Referenced --
487 ---------------------------
489 function OK_To_Set_Referenced return Boolean is
493 -- A reference from a pragma Unreferenced or pragma Unmodified or
494 -- pragma Warnings does not cause the Referenced flag to be set.
495 -- This avoids silly warnings about things being referenced and
496 -- not assigned when the only reference is from the pragma.
498 if Nkind (N) = N_Identifier then
501 if Nkind (P) = N_Pragma_Argument_Association then
504 if Nkind (P) = N_Pragma then
505 if Pragma_Name (P) = Name_Warnings
507 Pragma_Name (P) = Name_Unmodified
509 Pragma_Name (P) = Name_Unreferenced
518 end OK_To_Set_Referenced;
520 -- Start of processing for Generate_Reference
523 pragma Assert (Nkind (E) in N_Entity);
524 Find_Actual (N, Formal, Call);
526 if Present (Formal) then
527 Kind := Ekind (Formal);
532 -- Check for obsolescent reference to package ASCII. GNAT treats this
533 -- element of annex J specially since in practice, programs make a lot
534 -- of use of this feature, so we don't include it in the set of features
535 -- diagnosed when Warn_On_Obsolescent_Features mode is set. However we
536 -- are required to note it as a violation of the RM defined restriction.
538 if E = Standard_ASCII then
539 Check_Restriction (No_Obsolescent_Features, N);
542 -- Check for reference to entity marked with Is_Obsolescent
544 -- Note that we always allow obsolescent references in the compiler
545 -- itself and the run time, since we assume that we know what we are
546 -- doing in such cases. For example the calls in Ada.Characters.Handling
547 -- to its own obsolescent subprograms are just fine.
549 -- In any case we do not generate warnings within the extended source
550 -- unit of the entity in question, since we assume the source unit
551 -- itself knows what is going on (and for sure we do not want silly
552 -- warnings, e.g. on the end line of an obsolescent procedure body).
554 if Is_Obsolescent (E)
555 and then not GNAT_Mode
556 and then not In_Extended_Main_Source_Unit (E)
558 Check_Restriction (No_Obsolescent_Features, N);
560 if Warn_On_Obsolescent_Feature then
561 Output_Obsolescent_Entity_Warnings (N, E);
565 -- Warn if reference to Ada 2005 entity not in Ada 2005 mode. We only
566 -- detect real explicit references (modifications and references).
568 if Comes_From_Source (N)
569 and then Is_Ada_2005_Only (E)
570 and then Ada_Version < Ada_2005
571 and then Warn_On_Ada_2005_Compatibility
572 and then (Typ = 'm' or else Typ = 'r' or else Typ = 's')
574 Error_Msg_NE ("& is only defined in Ada 2005?", N, E);
577 -- Warn if reference to Ada 2012 entity not in Ada 2012 mode. We only
578 -- detect real explicit references (modifications and references).
580 if Comes_From_Source (N)
581 and then Is_Ada_2012_Only (E)
582 and then Ada_Version < Ada_2012
583 and then Warn_On_Ada_2012_Compatibility
584 and then (Typ = 'm' or else Typ = 'r')
586 Error_Msg_NE ("& is only defined in Ada 2012?", N, E);
589 -- Never collect references if not in main source unit. However, we omit
590 -- this test if Typ is 'e' or 'k', since these entries are structural,
591 -- and it is useful to have them in units that reference packages as
592 -- well as units that define packages. We also omit the test for the
593 -- case of 'p' since we want to include inherited primitive operations
594 -- from other packages.
596 -- We also omit this test is this is a body reference for a subprogram
597 -- instantiation. In this case the reference is to the generic body,
598 -- which clearly need not be in the main unit containing the instance.
599 -- For the same reason we accept an implicit reference generated for
600 -- a default in an instance.
602 if not In_Extended_Main_Source_Unit (N) then
608 or else (Typ = 'b' and then Is_Generic_Instance (E))
616 -- For reference type p, the entity must be in main source unit
618 if Typ = 'p' and then not In_Extended_Main_Source_Unit (E) then
622 -- Unless the reference is forced, we ignore references where the
623 -- reference itself does not come from source.
625 if not Force and then not Comes_From_Source (N) then
629 -- Deal with setting entity as referenced, unless suppressed. Note that
630 -- we still do Set_Referenced on entities that do not come from source.
631 -- This situation arises when we have a source reference to a derived
632 -- operation, where the derived operation itself does not come from
633 -- source, but we still want to mark it as referenced, since we really
634 -- are referencing an entity in the corresponding package (this avoids
635 -- wrong complaints that the package contains no referenced entities).
639 -- Assignable object appearing on left side of assignment or as
643 and then Is_On_LHS (N)
644 and then Ekind (E) /= E_In_Out_Parameter
646 -- For objects that are renamings, just set as simply referenced
647 -- we do not try to do assignment type tracking in this case.
649 if Present (Renamed_Object (E)) then
652 -- Out parameter case
654 elsif Kind = E_Out_Parameter then
656 -- If warning mode for all out parameters is set, or this is
657 -- the only warning parameter, then we want to mark this for
658 -- later warning logic by setting Referenced_As_Out_Parameter
660 if Warn_On_Modified_As_Out_Parameter (Formal) then
661 Set_Referenced_As_Out_Parameter (E, True);
662 Set_Referenced_As_LHS (E, False);
664 -- For OUT parameter not covered by the above cases, we simply
665 -- regard it as a normal reference (in this case we do not
666 -- want any of the warning machinery for out parameters).
672 -- For the left hand of an assignment case, we do nothing here.
673 -- The processing for Analyze_Assignment_Statement will set the
674 -- Referenced_As_LHS flag.
680 -- Check for a reference in a pragma that should not count as a
681 -- making the variable referenced for warning purposes.
683 elsif Is_Non_Significant_Pragma_Reference (N) then
686 -- A reference in an attribute definition clause does not count as a
687 -- reference except for the case of Address. The reason that 'Address
688 -- is an exception is that it creates an alias through which the
689 -- variable may be referenced.
691 elsif Nkind (Parent (N)) = N_Attribute_Definition_Clause
692 and then Chars (Parent (N)) /= Name_Address
693 and then N = Name (Parent (N))
697 -- Constant completion does not count as a reference
700 and then Ekind (E) = E_Constant
704 -- Record representation clause does not count as a reference
706 elsif Nkind (N) = N_Identifier
707 and then Nkind (Parent (N)) = N_Record_Representation_Clause
711 -- Discriminants do not need to produce a reference to record type
714 and then Nkind (Parent (N)) = N_Discriminant_Specification
721 -- Special processing for IN OUT parameters, where we have an
722 -- implicit assignment to a simple variable.
724 if Kind = E_In_Out_Parameter
725 and then Is_Assignable (E)
727 -- For sure this counts as a normal read reference
730 Set_Last_Assignment (E, Empty);
732 -- We count it as being referenced as an out parameter if the
733 -- option is set to warn on all out parameters, except that we
734 -- have a special exclusion for an intrinsic subprogram, which
735 -- is most likely an instantiation of Unchecked_Deallocation
736 -- which we do not want to consider as an assignment since it
737 -- generates false positives. We also exclude the case of an
738 -- IN OUT parameter if the name of the procedure is Free,
739 -- since we suspect similar semantics.
741 if Warn_On_All_Unread_Out_Parameters
742 and then Is_Entity_Name (Name (Call))
743 and then not Is_Intrinsic_Subprogram (Entity (Name (Call)))
744 and then Chars (Name (Call)) /= Name_Free
746 Set_Referenced_As_Out_Parameter (E, True);
747 Set_Referenced_As_LHS (E, False);
750 -- Don't count a recursive reference within a subprogram as a
751 -- reference (that allows detection of a recursive subprogram
752 -- whose only references are recursive calls as unreferenced).
754 elsif Is_Subprogram (E)
755 and then E = Nearest_Dynamic_Scope (Current_Scope)
759 -- Any other occurrence counts as referencing the entity
761 elsif OK_To_Set_Referenced then
764 -- If variable, this is an OK reference after an assignment
765 -- so we can clear the Last_Assignment indication.
767 if Is_Assignable (E) then
768 Set_Last_Assignment (E, Empty);
773 -- Check for pragma Unreferenced given and reference is within
774 -- this source unit (occasion for possible warning to be issued).
776 if Has_Unreferenced (E)
777 and then In_Same_Extended_Unit (E, N)
779 -- A reference as a named parameter in a call does not count
780 -- as a violation of pragma Unreferenced for this purpose...
782 if Nkind (N) = N_Identifier
783 and then Nkind (Parent (N)) = N_Parameter_Association
784 and then Selector_Name (Parent (N)) = N
788 -- ... Neither does a reference to a variable on the left side
791 elsif Is_On_LHS (N) then
794 -- For entry formals, we want to place the warning message on the
795 -- corresponding entity in the accept statement. The current scope
796 -- is the body of the accept, so we find the formal whose name
797 -- matches that of the entry formal (there is no link between the
798 -- two entities, and the one in the accept statement is only used
799 -- for conformance checking).
801 elsif Ekind (Scope (E)) = E_Entry then
806 BE := First_Entity (Current_Scope);
807 while Present (BE) loop
808 if Chars (BE) = Chars (E) then
809 Error_Msg_NE -- CODEFIX
810 ("?pragma Unreferenced given for&!", N, BE);
818 -- Here we issue the warning, since this is a real reference
821 Error_Msg_NE -- CODEFIX
822 ("?pragma Unreferenced given for&!", N, E);
826 -- If this is a subprogram instance, mark as well the internal
827 -- subprogram in the wrapper package, which may be a visible
830 if Is_Overloadable (E)
831 and then Is_Generic_Instance (E)
832 and then Present (Alias (E))
834 Set_Referenced (Alias (E));
838 -- Generate reference if all conditions are met:
841 -- Cross referencing must be active
845 -- The entity must be one for which we collect references
847 and then Xref_Entity_Letters (Ekind (E)) /= ' '
849 -- Both Sloc values must be set to something sensible
851 and then Sloc (E) > No_Location
852 and then Sloc (N) > No_Location
854 -- We ignore references from within an instance, except for default
855 -- subprograms, for which we generate an implicit reference.
858 (Instantiation_Location (Sloc (N)) = No_Location or else Typ = 'i')
860 -- Ignore dummy references
864 if Nkind (N) = N_Identifier
866 Nkind (N) = N_Defining_Identifier
870 Nkind (N) = N_Defining_Operator_Symbol
872 Nkind (N) = N_Operator_Symbol
874 (Nkind (N) = N_Character_Literal
875 and then Sloc (Entity (N)) /= Standard_Location)
877 Nkind (N) = N_Defining_Character_Literal
881 elsif Nkind (N) = N_Expanded_Name
883 Nkind (N) = N_Selected_Component
885 Nod := Selector_Name (N);
891 -- Normal case of source entity comes from source
893 if Comes_From_Source (E) then
896 -- Entity does not come from source, but is a derived subprogram and
897 -- the derived subprogram comes from source (after one or more
898 -- derivations) in which case the reference is to parent subprogram.
900 elsif Is_Overloadable (E)
901 and then Present (Alias (E))
904 while not Comes_From_Source (Ent) loop
905 if No (Alias (Ent)) then
912 -- The internally created defining entity for a child subprogram
913 -- that has no previous spec has valid references.
915 elsif Is_Overloadable (E)
916 and then Is_Child_Unit (E)
920 -- Record components of discriminated subtypes or derived types must
921 -- be treated as references to the original component.
923 elsif Ekind (E) = E_Component
924 and then Comes_From_Source (Original_Record_Component (E))
926 Ent := Original_Record_Component (E);
928 -- If this is an expanded reference to a discriminant, recover the
929 -- original discriminant, which gets the reference.
931 elsif Ekind (E) = E_In_Parameter
932 and then Present (Discriminal_Link (E))
934 Ent := Discriminal_Link (E);
935 Set_Referenced (Ent);
937 -- Ignore reference to any other entity that is not from source
943 -- Record reference to entity
945 Ref := Original_Location (Sloc (Nod));
946 Def := Original_Location (Sloc (Ent));
948 Ref_Scope := Enclosing_Subprogram_Or_Package (N);
949 Ent_Scope := Enclosing_Subprogram_Or_Package (Ent);
951 Xrefs.Increment_Last;
954 Xrefs.Table (Indx).Loc := Ref;
956 -- Overriding operations are marked with 'P'
959 and then Is_Subprogram (N)
960 and then Present (Overridden_Operation (N))
962 Xrefs.Table (Indx).Typ := 'P';
964 Xrefs.Table (Indx).Typ := Typ;
967 Xrefs.Table (Indx).Eun := Get_Source_Unit (Def);
968 Xrefs.Table (Indx).Lun := Get_Source_Unit (Ref);
969 Xrefs.Table (Indx).Ent := Ent;
971 Xrefs.Table (Indx).Ref_Scope := Ref_Scope;
972 Xrefs.Table (Indx).Ent_Scope := Ent_Scope;
973 Xrefs.Table (Indx).Ent_Scope_File := Get_Source_Unit (Ent_Scope);
975 Set_Has_Xref_Entry (Ent);
977 end Generate_Reference;
979 -----------------------------------
980 -- Generate_Reference_To_Formals --
981 -----------------------------------
983 procedure Generate_Reference_To_Formals (E : Entity_Id) is
987 if Is_Generic_Subprogram (E) then
988 Formal := First_Entity (E);
990 while Present (Formal)
991 and then not Is_Formal (Formal)
993 Next_Entity (Formal);
997 Formal := First_Formal (E);
1000 while Present (Formal) loop
1001 if Ekind (Formal) = E_In_Parameter then
1003 if Nkind (Parameter_Type (Parent (Formal)))
1004 = N_Access_Definition
1006 Generate_Reference (E, Formal, '^', False);
1008 Generate_Reference (E, Formal, '>', False);
1011 elsif Ekind (Formal) = E_In_Out_Parameter then
1012 Generate_Reference (E, Formal, '=', False);
1015 Generate_Reference (E, Formal, '<', False);
1018 Next_Formal (Formal);
1020 end Generate_Reference_To_Formals;
1022 -------------------------------------------
1023 -- Generate_Reference_To_Generic_Formals --
1024 -------------------------------------------
1026 procedure Generate_Reference_To_Generic_Formals (E : Entity_Id) is
1030 Formal := First_Entity (E);
1031 while Present (Formal) loop
1032 if Comes_From_Source (Formal) then
1033 Generate_Reference (E, Formal, 'z', False);
1036 Next_Entity (Formal);
1038 end Generate_Reference_To_Generic_Formals;
1044 procedure Initialize is
1053 function Lt (T1, T2 : Xref_Entry) return Boolean is
1055 -- First test: if entity is in different unit, sort by unit
1057 if T1.Eun /= T2.Eun then
1058 return Dependency_Num (T1.Eun) < Dependency_Num (T2.Eun);
1060 -- Second test: within same unit, sort by entity Sloc
1062 elsif T1.Def /= T2.Def then
1063 return T1.Def < T2.Def;
1065 -- Third test: sort definitions ahead of references
1067 elsif T1.Loc = No_Location then
1070 elsif T2.Loc = No_Location then
1073 -- Fourth test: for same entity, sort by reference location unit
1075 elsif T1.Lun /= T2.Lun then
1076 return Dependency_Num (T1.Lun) < Dependency_Num (T2.Lun);
1078 -- Fifth test: order of location within referencing unit
1080 elsif T1.Loc /= T2.Loc then
1081 return T1.Loc < T2.Loc;
1083 -- Finally, for two locations at the same address, we prefer
1084 -- the one that does NOT have the type 'r' so that a modification
1085 -- or extension takes preference, when there are more than one
1086 -- reference at the same location. As a result, in the case of
1087 -- entities that are in-out actuals, the read reference follows
1088 -- the modify reference.
1091 return T2.Typ = 'r';
1095 -----------------------
1096 -- Output_References --
1097 -----------------------
1099 procedure Output_References is
1101 procedure Get_Type_Reference
1103 Tref : out Entity_Id;
1104 Left : out Character;
1105 Right : out Character);
1106 -- Given an Entity_Id Ent, determines whether a type reference is
1107 -- required. If so, Tref is set to the entity for the type reference
1108 -- and Left and Right are set to the left/right brackets to be output
1109 -- for the reference. If no type reference is required, then Tref is
1110 -- set to Empty, and Left/Right are set to space.
1112 procedure Output_Import_Export_Info (Ent : Entity_Id);
1113 -- Output language and external name information for an interfaced
1114 -- entity, using the format <language, external_name>,
1116 ------------------------
1117 -- Get_Type_Reference --
1118 ------------------------
1120 procedure Get_Type_Reference
1122 Tref : out Entity_Id;
1123 Left : out Character;
1124 Right : out Character)
1129 -- See if we have a type reference
1138 -- Processing for types
1140 if Is_Type (Tref) then
1142 -- Case of base type
1144 if Base_Type (Tref) = Tref then
1146 -- If derived, then get first subtype
1148 if Tref /= Etype (Tref) then
1149 Tref := First_Subtype (Etype (Tref));
1151 -- Set brackets for derived type, but don't override
1152 -- pointer case since the fact that something is a
1153 -- pointer is more important.
1160 -- If non-derived ptr, get directly designated type.
1161 -- If the type has a full view, all references are on the
1162 -- partial view, that is seen first.
1164 elsif Is_Access_Type (Tref) then
1165 Tref := Directly_Designated_Type (Tref);
1169 elsif Is_Private_Type (Tref)
1170 and then Present (Full_View (Tref))
1172 if Is_Access_Type (Full_View (Tref)) then
1173 Tref := Directly_Designated_Type (Full_View (Tref));
1177 -- If the full view is an array type, we also retrieve
1178 -- the corresponding component type, because the ali
1179 -- entry already indicates that this is an array.
1181 elsif Is_Array_Type (Full_View (Tref)) then
1182 Tref := Component_Type (Full_View (Tref));
1187 -- If non-derived array, get component type. Skip component
1188 -- type for case of String or Wide_String, saves worthwhile
1191 elsif Is_Array_Type (Tref)
1192 and then Tref /= Standard_String
1193 and then Tref /= Standard_Wide_String
1195 Tref := Component_Type (Tref);
1199 -- For other non-derived base types, nothing
1205 -- For a subtype, go to ancestor subtype
1208 Tref := Ancestor_Subtype (Tref);
1210 -- If no ancestor subtype, go to base type
1213 Tref := Base_Type (Sav);
1217 -- For objects, functions, enum literals, just get type from
1220 elsif Is_Object (Tref)
1221 or else Ekind (Tref) = E_Enumeration_Literal
1222 or else Ekind (Tref) = E_Function
1223 or else Ekind (Tref) = E_Operator
1225 Tref := Etype (Tref);
1227 -- For anything else, exit
1233 -- Exit if no type reference, or we are stuck in some loop trying
1234 -- to find the type reference, or if the type is standard void
1235 -- type (the latter is an implementation artifact that should not
1236 -- show up in the generated cross-references).
1240 or else Tref = Standard_Void_Type;
1242 -- If we have a usable type reference, return, otherwise keep
1243 -- looking for something useful (we are looking for something
1244 -- that either comes from source or standard)
1246 if Sloc (Tref) = Standard_Location
1247 or else Comes_From_Source (Tref)
1249 -- If the reference is a subtype created for a generic actual,
1250 -- go actual directly, the inner subtype is not user visible.
1252 if Nkind (Parent (Tref)) = N_Subtype_Declaration
1253 and then not Comes_From_Source (Parent (Tref))
1255 (Is_Wrapper_Package (Scope (Tref))
1256 or else Is_Generic_Instance (Scope (Tref)))
1258 Tref := First_Subtype (Base_Type (Tref));
1265 -- If we fall through the loop, no type reference
1270 end Get_Type_Reference;
1272 -------------------------------
1273 -- Output_Import_Export_Info --
1274 -------------------------------
1276 procedure Output_Import_Export_Info (Ent : Entity_Id) is
1277 Language_Name : Name_Id;
1278 Conv : constant Convention_Id := Convention (Ent);
1281 -- Generate language name from convention
1283 if Conv = Convention_C then
1284 Language_Name := Name_C;
1286 elsif Conv = Convention_CPP then
1287 Language_Name := Name_CPP;
1289 elsif Conv = Convention_Ada then
1290 Language_Name := Name_Ada;
1293 -- For the moment we ignore all other cases ???
1298 Write_Info_Char ('<');
1299 Get_Unqualified_Name_String (Language_Name);
1301 for J in 1 .. Name_Len loop
1302 Write_Info_Char (Name_Buffer (J));
1305 if Present (Interface_Name (Ent)) then
1306 Write_Info_Char (',');
1307 String_To_Name_Buffer (Strval (Interface_Name (Ent)));
1309 for J in 1 .. Name_Len loop
1310 Write_Info_Char (Name_Buffer (J));
1314 Write_Info_Char ('>');
1315 end Output_Import_Export_Info;
1317 -- Start of processing for Output_References
1320 -- First we add references to the primitive operations of tagged types
1321 -- declared in the main unit.
1323 Handle_Prim_Ops : declare
1327 for J in 1 .. Xrefs.Last loop
1328 Ent := Xrefs.Table (J).Ent;
1331 and then Is_Tagged_Type (Ent)
1332 and then Is_Base_Type (Ent)
1333 and then In_Extended_Main_Source_Unit (Ent)
1335 Generate_Prim_Op_References (Ent);
1338 end Handle_Prim_Ops;
1340 -- Before we go ahead and output the references we have a problem
1341 -- that needs dealing with. So far we have captured things that are
1342 -- definitely referenced by the main unit, or defined in the main
1343 -- unit. That's because we don't want to clutter up the ali file
1344 -- for this unit with definition lines for entities in other units
1345 -- that are not referenced.
1347 -- But there is a glitch. We may reference an entity in another unit,
1348 -- and it may have a type reference to an entity that is not directly
1349 -- referenced in the main unit, which may mean that there is no xref
1350 -- entry for this entity yet in the list of references.
1352 -- If we don't do something about this, we will end with an orphan type
1353 -- reference, i.e. it will point to an entity that does not appear
1354 -- within the generated references in the ali file. That is not good for
1355 -- tools using the xref information.
1357 -- To fix this, we go through the references adding definition entries
1358 -- for any unreferenced entities that can be referenced in a type
1359 -- reference. There is a recursion problem here, and that is dealt with
1360 -- by making sure that this traversal also traverses any entries that
1361 -- get added by the traversal.
1363 Handle_Orphan_Type_References : declare
1371 pragma Warnings (Off, L);
1372 pragma Warnings (Off, R);
1374 procedure New_Entry (E : Entity_Id);
1375 -- Make an additional entry into the Xref table for a type entity
1376 -- that is related to the current entity (parent, type ancestor,
1377 -- progenitor, etc.).
1383 procedure New_Entry (E : Entity_Id) is
1386 and then not Has_Xref_Entry (E)
1387 and then Sloc (E) > No_Location
1389 Xrefs.Increment_Last;
1391 Loc := Original_Location (Sloc (E));
1392 Xrefs.Table (Indx).Ent := E;
1393 Xrefs.Table (Indx).Loc := No_Location;
1394 Xrefs.Table (Indx).Eun := Get_Source_Unit (Loc);
1395 Xrefs.Table (Indx).Lun := No_Unit;
1396 Set_Has_Xref_Entry (E);
1400 -- Start of processing for Handle_Orphan_Type_References
1403 -- Note that this is not a for loop for a very good reason. The
1404 -- processing of items in the table can add new items to the table,
1405 -- and they must be processed as well.
1408 while J <= Xrefs.Last loop
1409 Ent := Xrefs.Table (J).Ent;
1410 Get_Type_Reference (Ent, Tref, L, R);
1413 and then not Has_Xref_Entry (Tref)
1414 and then Sloc (Tref) > No_Location
1418 if Is_Record_Type (Ent)
1419 and then Present (Interfaces (Ent))
1421 -- Add an entry for each one of the given interfaces
1422 -- implemented by type Ent.
1425 Elmt : Elmt_Id := First_Elmt (Interfaces (Ent));
1427 while Present (Elmt) loop
1428 New_Entry (Node (Elmt));
1435 -- Collect inherited primitive operations that may be declared in
1436 -- another unit and have no visible reference in the current one.
1439 and then Is_Tagged_Type (Ent)
1440 and then Is_Derived_Type (Ent)
1441 and then Is_Base_Type (Ent)
1442 and then In_Extended_Main_Source_Unit (Ent)
1445 Op_List : constant Elist_Id := Primitive_Operations (Ent);
1449 function Parent_Op (E : Entity_Id) return Entity_Id;
1450 -- Find original operation, which may be inherited through
1451 -- several derivations.
1453 function Parent_Op (E : Entity_Id) return Entity_Id is
1454 Orig_Op : constant Entity_Id := Alias (E);
1457 if No (Orig_Op) then
1460 elsif not Comes_From_Source (E)
1461 and then not Has_Xref_Entry (Orig_Op)
1462 and then Comes_From_Source (Orig_Op)
1466 return Parent_Op (Orig_Op);
1471 Op := First_Elmt (Op_List);
1472 while Present (Op) loop
1473 Prim := Parent_Op (Node (Op));
1475 if Present (Prim) then
1476 Xrefs.Increment_Last;
1478 Loc := Original_Location (Sloc (Prim));
1479 Xrefs.Table (Indx).Ent := Prim;
1480 Xrefs.Table (Indx).Loc := No_Location;
1481 Xrefs.Table (Indx).Eun :=
1482 Get_Source_Unit (Sloc (Prim));
1483 Xrefs.Table (Indx).Lun := No_Unit;
1484 Set_Has_Xref_Entry (Prim);
1494 end Handle_Orphan_Type_References;
1496 -- Now we have all the references, including those for any embedded
1497 -- type references, so we can sort them, and output them.
1499 Output_Refs : declare
1501 Nrefs : Nat := Xrefs.Last;
1502 -- Number of references in table. This value may get reset (reduced)
1503 -- when we eliminate duplicate reference entries.
1505 Rnums : array (0 .. Nrefs) of Nat;
1506 -- This array contains numbers of references in the Xrefs table.
1507 -- This list is sorted in output order. The extra 0'th entry is
1508 -- convenient for the call to sort. When we sort the table, we
1509 -- move the entries in Rnums around, but we do not move the
1510 -- original table entries.
1512 Curxu : Unit_Number_Type;
1513 -- Current xref unit
1515 Curru : Unit_Number_Type;
1516 -- Current reference unit for one entity
1521 Curnam : String (1 .. Name_Buffer'Length);
1523 -- Simple name and length of current entity
1525 Curdef : Source_Ptr;
1526 -- Original source location for current entity
1529 -- Current reference location
1532 -- Entity type character
1535 -- reference kind of previous reference
1541 -- Renaming reference
1543 Trunit : Unit_Number_Type;
1544 -- Unit number for type reference
1546 function Lt (Op1, Op2 : Natural) return Boolean;
1547 -- Comparison function for Sort call
1549 function Name_Change (X : Entity_Id) return Boolean;
1550 -- Determines if entity X has a different simple name from Curent
1552 procedure Move (From : Natural; To : Natural);
1553 -- Move procedure for Sort call
1555 package Sorting is new GNAT.Heap_Sort_G (Move, Lt);
1561 function Lt (Op1, Op2 : Natural) return Boolean is
1562 T1 : Xref_Entry renames Xrefs.Table (Rnums (Nat (Op1)));
1563 T2 : Xref_Entry renames Xrefs.Table (Rnums (Nat (Op2)));
1573 procedure Move (From : Natural; To : Natural) is
1575 Rnums (Nat (To)) := Rnums (Nat (From));
1582 -- Why a string comparison here??? Why not compare Name_Id values???
1584 function Name_Change (X : Entity_Id) return Boolean is
1586 Get_Unqualified_Name_String (Chars (X));
1588 if Name_Len /= Curlen then
1591 return Name_Buffer (1 .. Curlen) /= Curnam (1 .. Curlen);
1595 -- Start of processing for Output_Refs
1598 -- Capture the definition Sloc values. We delay doing this till now,
1599 -- since at the time the reference or definition is made, private
1600 -- types may be swapped, and the Sloc value may be incorrect. We
1601 -- also set up the pointer vector for the sort.
1603 for J in 1 .. Nrefs loop
1605 Xrefs.Table (J).Def :=
1606 Original_Location (Sloc (Xrefs.Table (J).Ent));
1609 -- Sort the references
1611 Sorting.Sort (Integer (Nrefs));
1613 -- Eliminate duplicate entries
1616 NR : constant Nat := Nrefs;
1619 -- We need this test for NR because if we force ALI file
1620 -- generation in case of errors detected, it may be the case
1621 -- that Nrefs is 0, so we should not reset it here
1626 for J in 2 .. NR loop
1627 if Xrefs.Table (Rnums (J)) /=
1628 Xrefs.Table (Rnums (Nrefs))
1631 Rnums (Nrefs) := Rnums (J);
1637 -- Initialize loop through references
1641 Curdef := No_Location;
1643 Crloc := No_Location;
1646 -- Loop to output references
1648 for Refno in 1 .. Nrefs loop
1649 Output_One_Ref : declare
1652 XE : Xref_Entry renames Xrefs.Table (Rnums (Refno));
1653 -- The current entry to be accessed
1657 -- Used for {} or <> or () for type reference
1659 procedure Check_Type_Reference
1661 List_Interface : Boolean);
1662 -- Find whether there is a meaningful type reference for
1663 -- Ent, and display it accordingly. If List_Interface is
1664 -- true, then Ent is a progenitor interface of the current
1665 -- type entity being listed. In that case list it as is,
1666 -- without looking for a type reference for it.
1668 procedure Output_Instantiation_Refs (Loc : Source_Ptr);
1669 -- Recursive procedure to output instantiation references for
1670 -- the given source ptr in [file|line[...]] form. No output
1671 -- if the given location is not a generic template reference.
1673 procedure Output_Overridden_Op (Old_E : Entity_Id);
1674 -- For a subprogram that is overriding, display information
1675 -- about the inherited operation that it overrides.
1677 --------------------------
1678 -- Check_Type_Reference --
1679 --------------------------
1681 procedure Check_Type_Reference
1683 List_Interface : Boolean)
1686 if List_Interface then
1688 -- This is a progenitor interface of the type for which
1689 -- xref information is being generated.
1696 Get_Type_Reference (Ent, Tref, Left, Right);
1699 if Present (Tref) then
1701 -- Case of standard entity, output name
1703 if Sloc (Tref) = Standard_Location then
1704 Write_Info_Char (Left);
1705 Write_Info_Name (Chars (Tref));
1706 Write_Info_Char (Right);
1708 -- Case of source entity, output location
1711 Write_Info_Char (Left);
1712 Trunit := Get_Source_Unit (Sloc (Tref));
1714 if Trunit /= Curxu then
1715 Write_Info_Nat (Dependency_Num (Trunit));
1716 Write_Info_Char ('|');
1720 (Int (Get_Logical_Line_Number (Sloc (Tref))));
1728 Ctyp := Xref_Entity_Letters (Ekind (Ent));
1731 and then Present (Full_View (Ent))
1733 Ent := Underlying_Type (Ent);
1735 if Present (Ent) then
1736 Ctyp := Xref_Entity_Letters (Ekind (Ent));
1740 Write_Info_Char (Ctyp);
1744 (Int (Get_Column_Number (Sloc (Tref))));
1746 -- If the type comes from an instantiation, add the
1747 -- corresponding info.
1749 Output_Instantiation_Refs (Sloc (Tref));
1750 Write_Info_Char (Right);
1753 end Check_Type_Reference;
1755 -------------------------------
1756 -- Output_Instantiation_Refs --
1757 -------------------------------
1759 procedure Output_Instantiation_Refs (Loc : Source_Ptr) is
1760 Iloc : constant Source_Ptr := Instantiation_Location (Loc);
1761 Lun : Unit_Number_Type;
1762 Cu : constant Unit_Number_Type := Curru;
1765 -- Nothing to do if this is not an instantiation
1767 if Iloc = No_Location then
1771 -- Output instantiation reference
1773 Write_Info_Char ('[');
1774 Lun := Get_Source_Unit (Iloc);
1776 if Lun /= Curru then
1778 Write_Info_Nat (Dependency_Num (Curru));
1779 Write_Info_Char ('|');
1782 Write_Info_Nat (Int (Get_Logical_Line_Number (Iloc)));
1784 -- Recursive call to get nested instantiations
1786 Output_Instantiation_Refs (Iloc);
1788 -- Output final ] after call to get proper nesting
1790 Write_Info_Char (']');
1793 end Output_Instantiation_Refs;
1795 --------------------------
1796 -- Output_Overridden_Op --
1797 --------------------------
1799 procedure Output_Overridden_Op (Old_E : Entity_Id) is
1803 -- The overridden operation has an implicit declaration
1804 -- at the point of derivation. What we want to display
1805 -- is the original operation, which has the actual body
1806 -- (or abstract declaration) that is being overridden.
1807 -- The overridden operation is not always set, e.g. when
1808 -- it is a predefined operator.
1813 -- Follow alias chain if one is present
1815 elsif Present (Alias (Old_E)) then
1817 -- The subprogram may have been implicitly inherited
1818 -- through several levels of derivation, so find the
1819 -- ultimate (source) ancestor.
1821 Op := Ultimate_Alias (Old_E);
1823 -- Normal case of no alias present
1830 and then Sloc (Op) /= Standard_Location
1833 Loc : constant Source_Ptr := Sloc (Op);
1834 Par_Unit : constant Unit_Number_Type :=
1835 Get_Source_Unit (Loc);
1838 Write_Info_Char ('<');
1840 if Par_Unit /= Curxu then
1841 Write_Info_Nat (Dependency_Num (Par_Unit));
1842 Write_Info_Char ('|');
1845 Write_Info_Nat (Int (Get_Logical_Line_Number (Loc)));
1846 Write_Info_Char ('p');
1847 Write_Info_Nat (Int (Get_Column_Number (Loc)));
1848 Write_Info_Char ('>');
1851 end Output_Overridden_Op;
1853 -- Start of processing for Output_One_Ref
1857 Ctyp := Xref_Entity_Letters (Ekind (Ent));
1859 -- Skip reference if it is the only reference to an entity,
1860 -- and it is an END line reference, and the entity is not in
1861 -- the current extended source. This prevents junk entries
1862 -- consisting only of packages with END lines, where no
1863 -- entity from the package is actually referenced.
1866 and then Ent /= Curent
1867 and then (Refno = Nrefs or else
1868 Ent /= Xrefs.Table (Rnums (Refno + 1)).Ent)
1870 not In_Extended_Main_Source_Unit (Ent)
1875 -- For private type, get full view type
1878 and then Present (Full_View (XE.Ent))
1880 Ent := Underlying_Type (Ent);
1882 if Present (Ent) then
1883 Ctyp := Xref_Entity_Letters (Ekind (Ent));
1887 -- Special exception for Boolean
1889 if Ctyp = 'E' and then Is_Boolean_Type (Ent) then
1893 -- For variable reference, get corresponding type
1896 Ent := Etype (XE.Ent);
1897 Ctyp := Fold_Lower (Xref_Entity_Letters (Ekind (Ent)));
1899 -- If variable is private type, get full view type
1902 and then Present (Full_View (Etype (XE.Ent)))
1904 Ent := Underlying_Type (Etype (XE.Ent));
1906 if Present (Ent) then
1907 Ctyp := Fold_Lower (Xref_Entity_Letters (Ekind (Ent)));
1910 elsif Is_Generic_Type (Ent) then
1912 -- If the type of the entity is a generic private type,
1913 -- there is no usable full view, so retain the indication
1914 -- that this is an object.
1919 -- Special handling for access parameters and objects of
1920 -- an anonymous access type.
1922 if Ekind_In (Etype (XE.Ent),
1923 E_Anonymous_Access_Type,
1924 E_Anonymous_Access_Subprogram_Type,
1925 E_Anonymous_Access_Protected_Subprogram_Type)
1927 if Is_Formal (XE.Ent)
1928 or else Ekind_In (XE.Ent, E_Variable, E_Constant)
1933 -- Special handling for Boolean
1935 elsif Ctyp = 'e' and then Is_Boolean_Type (Ent) then
1940 -- Special handling for abstract types and operations
1942 if Is_Overloadable (XE.Ent)
1943 and then Is_Abstract_Subprogram (XE.Ent)
1946 Ctyp := 'x'; -- Abstract procedure
1948 elsif Ctyp = 'V' then
1949 Ctyp := 'y'; -- Abstract function
1952 elsif Is_Type (XE.Ent)
1953 and then Is_Abstract_Type (XE.Ent)
1955 if Is_Interface (XE.Ent) then
1958 elsif Ctyp = 'R' then
1959 Ctyp := 'H'; -- Abstract type
1963 -- Only output reference if interesting type of entity
1967 -- Suppress references to object definitions, used for local
1970 or else XE.Typ = 'D'
1971 or else XE.Typ = 'I'
1973 -- Suppress self references, except for bodies that act as
1976 or else (XE.Loc = XE.Def
1979 or else not Is_Subprogram (XE.Ent)))
1981 -- Also suppress definitions of body formals (we only
1982 -- treat these as references, and the references were
1983 -- separately recorded).
1985 or else (Is_Formal (XE.Ent)
1986 and then Present (Spec_Entity (XE.Ent)))
1991 -- Start new Xref section if new xref unit
1993 if XE.Eun /= Curxu then
1994 if Write_Info_Col > 1 then
2000 Write_Info_Initiate ('X');
2001 Write_Info_Char (' ');
2002 Write_Info_Nat (Dependency_Num (XE.Eun));
2003 Write_Info_Char (' ');
2004 Write_Info_Name (Reference_Name (Source_Index (XE.Eun)));
2007 -- Start new Entity line if new entity. Note that we
2008 -- consider two entities the same if they have the same
2009 -- name and source location. This causes entities in
2010 -- instantiations to be treated as though they referred
2017 (Name_Change (XE.Ent) or else XE.Def /= Curdef))
2022 Get_Unqualified_Name_String (Chars (XE.Ent));
2024 Curnam (1 .. Curlen) := Name_Buffer (1 .. Curlen);
2026 if Write_Info_Col > 1 then
2030 -- Write column number information
2032 Write_Info_Nat (Int (Get_Logical_Line_Number (XE.Def)));
2033 Write_Info_Char (Ctyp);
2034 Write_Info_Nat (Int (Get_Column_Number (XE.Def)));
2036 -- Write level information
2038 Write_Level_Info : declare
2039 function Is_Visible_Generic_Entity
2040 (E : Entity_Id) return Boolean;
2041 -- Check whether E is declared in the visible part
2042 -- of a generic package. For source navigation
2043 -- purposes, treat this as a visible entity.
2045 function Is_Private_Record_Component
2046 (E : Entity_Id) return Boolean;
2047 -- Check whether E is a non-inherited component of a
2048 -- private extension. Even if the enclosing record is
2049 -- public, we want to treat the component as private
2050 -- for navigation purposes.
2052 ---------------------------------
2053 -- Is_Private_Record_Component --
2054 ---------------------------------
2056 function Is_Private_Record_Component
2057 (E : Entity_Id) return Boolean
2059 S : constant Entity_Id := Scope (E);
2062 Ekind (E) = E_Component
2063 and then Nkind (Declaration_Node (S)) =
2064 N_Private_Extension_Declaration
2065 and then Original_Record_Component (E) = E;
2066 end Is_Private_Record_Component;
2068 -------------------------------
2069 -- Is_Visible_Generic_Entity --
2070 -------------------------------
2072 function Is_Visible_Generic_Entity
2073 (E : Entity_Id) return Boolean
2078 -- The Present check here is an error defense
2080 if Present (Scope (E))
2081 and then Ekind (Scope (E)) /= E_Generic_Package
2087 while Present (Par) loop
2089 Nkind (Par) = N_Generic_Package_Declaration
2091 -- Entity is a generic formal
2096 Nkind (Parent (Par)) = N_Package_Specification
2099 Is_List_Member (Par)
2100 and then List_Containing (Par) =
2101 Visible_Declarations (Parent (Par));
2103 Par := Parent (Par);
2108 end Is_Visible_Generic_Entity;
2110 -- Start of processing for Write_Level_Info
2113 if Is_Hidden (Curent)
2114 or else Is_Private_Record_Component (Curent)
2116 Write_Info_Char (' ');
2120 or else Is_Visible_Generic_Entity (Curent)
2122 Write_Info_Char ('*');
2125 Write_Info_Char (' ');
2127 end Write_Level_Info;
2129 -- Output entity name. We use the occurrence from the
2130 -- actual source program at the definition point.
2133 Ent_Name : constant String :=
2134 Exact_Source_Name (Sloc (XE.Ent));
2136 for C in Ent_Name'Range loop
2137 Write_Info_Char (Ent_Name (C));
2141 -- See if we have a renaming reference
2143 if Is_Object (XE.Ent)
2144 and then Present (Renamed_Object (XE.Ent))
2146 Rref := Renamed_Object (XE.Ent);
2148 elsif Is_Overloadable (XE.Ent)
2149 and then Nkind (Parent (Declaration_Node (XE.Ent))) =
2150 N_Subprogram_Renaming_Declaration
2152 Rref := Name (Parent (Declaration_Node (XE.Ent)));
2154 elsif Ekind (XE.Ent) = E_Package
2155 and then Nkind (Declaration_Node (XE.Ent)) =
2156 N_Package_Renaming_Declaration
2158 Rref := Name (Declaration_Node (XE.Ent));
2164 if Present (Rref) then
2165 if Nkind (Rref) = N_Expanded_Name then
2166 Rref := Selector_Name (Rref);
2169 if Nkind (Rref) = N_Identifier
2170 or else Nkind (Rref) = N_Operator_Symbol
2174 -- For renamed array components, use the array name
2175 -- for the renamed entity, which reflect the fact that
2176 -- in general the whole array is aliased.
2178 elsif Nkind (Rref) = N_Indexed_Component then
2179 if Nkind (Prefix (Rref)) = N_Identifier then
2180 Rref := Prefix (Rref);
2181 elsif Nkind (Prefix (Rref)) = N_Expanded_Name then
2182 Rref := Selector_Name (Prefix (Rref));
2192 -- Write out renaming reference if we have one
2194 if Present (Rref) then
2195 Write_Info_Char ('=');
2197 (Int (Get_Logical_Line_Number (Sloc (Rref))));
2198 Write_Info_Char (':');
2200 (Int (Get_Column_Number (Sloc (Rref))));
2203 -- Indicate that the entity is in the unit of the current
2208 -- Write out information about generic parent, if entity
2211 if Is_Generic_Instance (XE.Ent) then
2213 Gen_Par : constant Entity_Id :=
2216 (Unit_Declaration_Node (XE.Ent)));
2217 Loc : constant Source_Ptr := Sloc (Gen_Par);
2218 Gen_U : constant Unit_Number_Type :=
2219 Get_Source_Unit (Loc);
2222 Write_Info_Char ('[');
2224 if Curru /= Gen_U then
2225 Write_Info_Nat (Dependency_Num (Gen_U));
2226 Write_Info_Char ('|');
2230 (Int (Get_Logical_Line_Number (Loc)));
2231 Write_Info_Char (']');
2235 -- See if we have a type reference and if so output
2237 Check_Type_Reference (XE.Ent, False);
2239 -- Additional information for types with progenitors
2241 if Is_Record_Type (XE.Ent)
2242 and then Present (Interfaces (XE.Ent))
2245 Elmt : Elmt_Id := First_Elmt (Interfaces (XE.Ent));
2247 while Present (Elmt) loop
2248 Check_Type_Reference (Node (Elmt), True);
2253 -- For array types, list index types as well. (This is
2254 -- not C, indexes have distinct types).
2256 elsif Is_Array_Type (XE.Ent) then
2260 Indx := First_Index (XE.Ent);
2261 while Present (Indx) loop
2262 Check_Type_Reference
2263 (First_Subtype (Etype (Indx)), True);
2269 -- If the entity is an overriding operation, write info
2270 -- on operation that was overridden.
2272 if Is_Subprogram (XE.Ent)
2273 and then Present (Overridden_Operation (XE.Ent))
2275 Output_Overridden_Op (Overridden_Operation (XE.Ent));
2278 -- End of processing for entity output
2280 Crloc := No_Location;
2283 -- Output the reference if it is not as the same location
2284 -- as the previous one, or it is a read-reference that
2285 -- indicates that the entity is an in-out actual in a call.
2287 if XE.Loc /= No_Location
2290 or else (Prevt = 'm' and then XE.Typ = 'r'))
2295 -- Start continuation if line full, else blank
2297 if Write_Info_Col > 72 then
2299 Write_Info_Initiate ('.');
2302 Write_Info_Char (' ');
2304 -- Output file number if changed
2306 if XE.Lun /= Curru then
2308 Write_Info_Nat (Dependency_Num (Curru));
2309 Write_Info_Char ('|');
2312 Write_Info_Nat (Int (Get_Logical_Line_Number (XE.Loc)));
2313 Write_Info_Char (XE.Typ);
2315 if Is_Overloadable (XE.Ent)
2316 and then Is_Imported (XE.Ent)
2317 and then XE.Typ = 'b'
2319 Output_Import_Export_Info (XE.Ent);
2322 Write_Info_Nat (Int (Get_Column_Number (XE.Loc)));
2324 Output_Instantiation_Refs (Sloc (XE.Ent));
2335 end Output_References;