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));
171 Result := Parent (Result);
175 if Nkind (Result) = N_Defining_Program_Unit_Name then
176 Result := Defining_Identifier (Result);
179 -- Do no return a scope without a proper location
182 and then Sloc (Result) = No_Location
188 end Enclosing_Subprogram_Or_Package;
190 -------------------------
191 -- Generate_Definition --
192 -------------------------
194 procedure Generate_Definition (E : Entity_Id) is
199 pragma Assert (Nkind (E) in N_Entity);
201 -- Note that we do not test Xref_Entity_Letters here. It is too early
202 -- to do so, since we are often called before the entity is fully
203 -- constructed, so that the Ekind is still E_Void.
207 -- Definition must come from source
209 -- We make an exception for subprogram child units that have no spec.
210 -- For these we generate a subprogram declaration for library use,
211 -- and the corresponding entity does not come from source.
212 -- Nevertheless, all references will be attached to it and we have
213 -- to treat is as coming from user code.
215 and then (Comes_From_Source (E) or else Is_Child_Unit (E))
217 -- And must have a reasonable source location that is not
218 -- within an instance (all entities in instances are ignored)
220 and then Sloc (E) > No_Location
221 and then Instantiation_Location (Sloc (E)) = No_Location
223 -- And must be a non-internal name from the main source unit
225 and then In_Extended_Main_Source_Unit (E)
226 and then not Is_Internal_Name (Chars (E))
228 Xrefs.Increment_Last;
230 Loc := Original_Location (Sloc (E));
232 Xrefs.Table (Indx).Ent := E;
233 Xrefs.Table (Indx).Typ := ' ';
234 Xrefs.Table (Indx).Def := No_Location;
235 Xrefs.Table (Indx).Loc := No_Location;
237 Xrefs.Table (Indx).Eun := Get_Source_Unit (Loc);
239 Xrefs.Table (Indx).Ref_Scope := Empty;
240 Xrefs.Table (Indx).Ent_Scope := Empty;
241 Xrefs.Table (Indx).Ent_Scope_File := No_Unit;
243 Set_Has_Xref_Entry (E);
245 if In_Inlined_Body then
249 end Generate_Definition;
251 ---------------------------------
252 -- Generate_Operator_Reference --
253 ---------------------------------
255 procedure Generate_Operator_Reference
260 if not In_Extended_Main_Source_Unit (N) then
264 -- If the operator is not a Standard operator, then we generate a real
265 -- reference to the user defined operator.
267 if Sloc (Entity (N)) /= Standard_Location then
268 Generate_Reference (Entity (N), N);
270 -- A reference to an implicit inequality operator is also a reference
271 -- to the user-defined equality.
273 if Nkind (N) = N_Op_Ne
274 and then not Comes_From_Source (Entity (N))
275 and then Present (Corresponding_Equality (Entity (N)))
277 Generate_Reference (Corresponding_Equality (Entity (N)), N);
280 -- For the case of Standard operators, we mark the result type as
281 -- referenced. This ensures that in the case where we are using a
282 -- derived operator, we mark an entity of the unit that implicitly
283 -- defines this operator as used. Otherwise we may think that no entity
284 -- of the unit is used. The actual entity marked as referenced is the
285 -- first subtype, which is the relevant user defined entity.
287 -- Note: we only do this for operators that come from source. The
288 -- generated code sometimes reaches for entities that do not need to be
289 -- explicitly visible (for example, when we expand the code for
290 -- comparing two record objects, the fields of the record may not be
293 elsif Comes_From_Source (N) then
294 Set_Referenced (First_Subtype (T));
296 end Generate_Operator_Reference;
298 ---------------------------------
299 -- Generate_Prim_Op_References --
300 ---------------------------------
302 procedure Generate_Prim_Op_References (Typ : Entity_Id) is
305 Prim_List : Elist_Id;
308 -- Handle subtypes of synchronized types
310 if Ekind (Typ) = E_Protected_Subtype
311 or else Ekind (Typ) = E_Task_Subtype
313 Base_T := Etype (Typ);
318 -- References to primitive operations are only relevant for tagged types
320 if not Is_Tagged_Type (Base_T)
321 or else Is_Class_Wide_Type (Base_T)
326 -- Ada 2005 (AI-345): For synchronized types generate reference to the
327 -- wrapper that allow us to dispatch calls through their implemented
328 -- abstract interface types.
330 -- The check for Present here is to protect against previously reported
333 Prim_List := Primitive_Operations (Base_T);
335 if No (Prim_List) then
339 Prim := First_Elmt (Prim_List);
340 while Present (Prim) loop
342 -- If the operation is derived, get the original for cross-reference
343 -- reference purposes (it is the original for which we want the xref
344 -- and for which the comes_from_source test must be performed).
347 (Typ, Ultimate_Alias (Node (Prim)), 'p', Set_Ref => False);
350 end Generate_Prim_Op_References;
352 ------------------------
353 -- Generate_Reference --
354 ------------------------
356 procedure Generate_Reference
359 Typ : Character := 'r';
360 Set_Ref : Boolean := True;
361 Force : Boolean := False)
369 Ref_Scope : Entity_Id;
370 Ent_Scope : Entity_Id;
374 -- Used for call to Find_Actual
377 -- If Formal is non-Empty, then its Ekind, otherwise E_Void
379 function Is_On_LHS (Node : Node_Id) return Boolean;
380 -- Used to check if a node is on the left hand side of an assignment.
381 -- The following cases are handled:
383 -- Variable Node is a direct descendant of left hand side of an
384 -- assignment statement.
386 -- Prefix Of an indexed or selected component that is present in
387 -- a subtree rooted by an assignment statement. There is
388 -- no restriction of nesting of components, thus cases
389 -- such as A.B (C).D are handled properly. However a prefix
390 -- of a dereference (either implicit or explicit) is never
391 -- considered as on a LHS.
393 -- Out param Same as above cases, but OUT parameter
395 function OK_To_Set_Referenced return Boolean;
396 -- Returns True if the Referenced flag can be set. There are a few
397 -- exceptions where we do not want to set this flag, see body for
398 -- details of these exceptional cases.
404 -- ??? There are several routines here and there that perform a similar
405 -- (but subtly different) computation, which should be factored:
407 -- Sem_Util.May_Be_Lvalue
408 -- Sem_Util.Known_To_Be_Assigned
409 -- Exp_Ch2.Expand_Entry_Parameter.In_Assignment_Context
410 -- Exp_Smem.Is_Out_Actual
412 function Is_On_LHS (Node : Node_Id) return Boolean is
418 -- Only identifiers are considered, is this necessary???
420 if Nkind (Node) /= N_Identifier then
424 -- Immediate return if appeared as OUT parameter
426 if Kind = E_Out_Parameter then
430 -- Search for assignment statement subtree root
437 if K = N_Assignment_Statement then
440 -- Check whether the parent is a component and the current node is
441 -- its prefix, but return False if the current node has an access
442 -- type, as in that case the selected or indexed component is an
443 -- implicit dereference, and the LHS is the designated object, not
444 -- the access object.
446 -- ??? case of a slice assignment?
448 -- ??? Note that in some cases this is called too early
449 -- (see comments in Sem_Ch8.Find_Direct_Name), at a point where
450 -- the tree is not fully typed yet. In that case we may lack
451 -- an Etype for N, and we must disable the check for an implicit
452 -- dereference. If the dereference is on an LHS, this causes a
455 elsif (K = N_Selected_Component or else K = N_Indexed_Component)
456 and then Prefix (P) = N
457 and then not (Present (Etype (N))
459 Is_Access_Type (Etype (N)))
463 -- All other cases, definitely not on left side
471 ---------------------------
472 -- OK_To_Set_Referenced --
473 ---------------------------
475 function OK_To_Set_Referenced return Boolean is
479 -- A reference from a pragma Unreferenced or pragma Unmodified or
480 -- pragma Warnings does not cause the Referenced flag to be set.
481 -- This avoids silly warnings about things being referenced and
482 -- not assigned when the only reference is from the pragma.
484 if Nkind (N) = N_Identifier then
487 if Nkind (P) = N_Pragma_Argument_Association then
490 if Nkind (P) = N_Pragma then
491 if Pragma_Name (P) = Name_Warnings
493 Pragma_Name (P) = Name_Unmodified
495 Pragma_Name (P) = Name_Unreferenced
504 end OK_To_Set_Referenced;
506 -- Start of processing for Generate_Reference
509 pragma Assert (Nkind (E) in N_Entity);
510 Find_Actual (N, Formal, Call);
512 if Present (Formal) then
513 Kind := Ekind (Formal);
518 -- Check for obsolescent reference to package ASCII. GNAT treats this
519 -- element of annex J specially since in practice, programs make a lot
520 -- of use of this feature, so we don't include it in the set of features
521 -- diagnosed when Warn_On_Obsolescent_Features mode is set. However we
522 -- are required to note it as a violation of the RM defined restriction.
524 if E = Standard_ASCII then
525 Check_Restriction (No_Obsolescent_Features, N);
528 -- Check for reference to entity marked with Is_Obsolescent
530 -- Note that we always allow obsolescent references in the compiler
531 -- itself and the run time, since we assume that we know what we are
532 -- doing in such cases. For example the calls in Ada.Characters.Handling
533 -- to its own obsolescent subprograms are just fine.
535 -- In any case we do not generate warnings within the extended source
536 -- unit of the entity in question, since we assume the source unit
537 -- itself knows what is going on (and for sure we do not want silly
538 -- warnings, e.g. on the end line of an obsolescent procedure body).
540 if Is_Obsolescent (E)
541 and then not GNAT_Mode
542 and then not In_Extended_Main_Source_Unit (E)
544 Check_Restriction (No_Obsolescent_Features, N);
546 if Warn_On_Obsolescent_Feature then
547 Output_Obsolescent_Entity_Warnings (N, E);
551 -- Warn if reference to Ada 2005 entity not in Ada 2005 mode. We only
552 -- detect real explicit references (modifications and references).
554 if Comes_From_Source (N)
555 and then Is_Ada_2005_Only (E)
556 and then Ada_Version < Ada_2005
557 and then Warn_On_Ada_2005_Compatibility
558 and then (Typ = 'm' or else Typ = 'r' or else Typ = 's')
560 Error_Msg_NE ("& is only defined in Ada 2005?", N, E);
563 -- Warn if reference to Ada 2012 entity not in Ada 2012 mode. We only
564 -- detect real explicit references (modifications and references).
566 if Comes_From_Source (N)
567 and then Is_Ada_2012_Only (E)
568 and then Ada_Version < Ada_2012
569 and then Warn_On_Ada_2012_Compatibility
570 and then (Typ = 'm' or else Typ = 'r')
572 Error_Msg_NE ("& is only defined in Ada 2012?", N, E);
575 -- Never collect references if not in main source unit. However, we omit
576 -- this test if Typ is 'e' or 'k', since these entries are structural,
577 -- and it is useful to have them in units that reference packages as
578 -- well as units that define packages. We also omit the test for the
579 -- case of 'p' since we want to include inherited primitive operations
580 -- from other packages.
582 -- We also omit this test is this is a body reference for a subprogram
583 -- instantiation. In this case the reference is to the generic body,
584 -- which clearly need not be in the main unit containing the instance.
585 -- For the same reason we accept an implicit reference generated for
586 -- a default in an instance.
588 if not In_Extended_Main_Source_Unit (N) then
594 or else (Typ = 'b' and then Is_Generic_Instance (E))
602 -- For reference type p, the entity must be in main source unit
604 if Typ = 'p' and then not In_Extended_Main_Source_Unit (E) then
608 -- Unless the reference is forced, we ignore references where the
609 -- reference itself does not come from source.
611 if not Force and then not Comes_From_Source (N) then
615 -- Deal with setting entity as referenced, unless suppressed. Note that
616 -- we still do Set_Referenced on entities that do not come from source.
617 -- This situation arises when we have a source reference to a derived
618 -- operation, where the derived operation itself does not come from
619 -- source, but we still want to mark it as referenced, since we really
620 -- are referencing an entity in the corresponding package (this avoids
621 -- wrong complaints that the package contains no referenced entities).
625 -- Assignable object appearing on left side of assignment or as
629 and then Is_On_LHS (N)
630 and then Ekind (E) /= E_In_Out_Parameter
632 -- For objects that are renamings, just set as simply referenced
633 -- we do not try to do assignment type tracking in this case.
635 if Present (Renamed_Object (E)) then
638 -- Out parameter case
640 elsif Kind = E_Out_Parameter then
642 -- If warning mode for all out parameters is set, or this is
643 -- the only warning parameter, then we want to mark this for
644 -- later warning logic by setting Referenced_As_Out_Parameter
646 if Warn_On_Modified_As_Out_Parameter (Formal) then
647 Set_Referenced_As_Out_Parameter (E, True);
648 Set_Referenced_As_LHS (E, False);
650 -- For OUT parameter not covered by the above cases, we simply
651 -- regard it as a normal reference (in this case we do not
652 -- want any of the warning machinery for out parameters).
658 -- For the left hand of an assignment case, we do nothing here.
659 -- The processing for Analyze_Assignment_Statement will set the
660 -- Referenced_As_LHS flag.
666 -- Check for a reference in a pragma that should not count as a
667 -- making the variable referenced for warning purposes.
669 elsif Is_Non_Significant_Pragma_Reference (N) then
672 -- A reference in an attribute definition clause does not count as a
673 -- reference except for the case of Address. The reason that 'Address
674 -- is an exception is that it creates an alias through which the
675 -- variable may be referenced.
677 elsif Nkind (Parent (N)) = N_Attribute_Definition_Clause
678 and then Chars (Parent (N)) /= Name_Address
679 and then N = Name (Parent (N))
683 -- Constant completion does not count as a reference
686 and then Ekind (E) = E_Constant
690 -- Record representation clause does not count as a reference
692 elsif Nkind (N) = N_Identifier
693 and then Nkind (Parent (N)) = N_Record_Representation_Clause
697 -- Discriminants do not need to produce a reference to record type
700 and then Nkind (Parent (N)) = N_Discriminant_Specification
707 -- Special processing for IN OUT parameters, where we have an
708 -- implicit assignment to a simple variable.
710 if Kind = E_In_Out_Parameter
711 and then Is_Assignable (E)
713 -- For sure this counts as a normal read reference
716 Set_Last_Assignment (E, Empty);
718 -- We count it as being referenced as an out parameter if the
719 -- option is set to warn on all out parameters, except that we
720 -- have a special exclusion for an intrinsic subprogram, which
721 -- is most likely an instantiation of Unchecked_Deallocation
722 -- which we do not want to consider as an assignment since it
723 -- generates false positives. We also exclude the case of an
724 -- IN OUT parameter if the name of the procedure is Free,
725 -- since we suspect similar semantics.
727 if Warn_On_All_Unread_Out_Parameters
728 and then Is_Entity_Name (Name (Call))
729 and then not Is_Intrinsic_Subprogram (Entity (Name (Call)))
730 and then Chars (Name (Call)) /= Name_Free
732 Set_Referenced_As_Out_Parameter (E, True);
733 Set_Referenced_As_LHS (E, False);
736 -- Don't count a recursive reference within a subprogram as a
737 -- reference (that allows detection of a recursive subprogram
738 -- whose only references are recursive calls as unreferenced).
740 elsif Is_Subprogram (E)
741 and then E = Nearest_Dynamic_Scope (Current_Scope)
745 -- Any other occurrence counts as referencing the entity
747 elsif OK_To_Set_Referenced then
750 -- If variable, this is an OK reference after an assignment
751 -- so we can clear the Last_Assignment indication.
753 if Is_Assignable (E) then
754 Set_Last_Assignment (E, Empty);
759 -- Check for pragma Unreferenced given and reference is within
760 -- this source unit (occasion for possible warning to be issued).
762 if Has_Unreferenced (E)
763 and then In_Same_Extended_Unit (E, N)
765 -- A reference as a named parameter in a call does not count
766 -- as a violation of pragma Unreferenced for this purpose...
768 if Nkind (N) = N_Identifier
769 and then Nkind (Parent (N)) = N_Parameter_Association
770 and then Selector_Name (Parent (N)) = N
774 -- ... Neither does a reference to a variable on the left side
777 elsif Is_On_LHS (N) then
780 -- For entry formals, we want to place the warning message on the
781 -- corresponding entity in the accept statement. The current scope
782 -- is the body of the accept, so we find the formal whose name
783 -- matches that of the entry formal (there is no link between the
784 -- two entities, and the one in the accept statement is only used
785 -- for conformance checking).
787 elsif Ekind (Scope (E)) = E_Entry then
792 BE := First_Entity (Current_Scope);
793 while Present (BE) loop
794 if Chars (BE) = Chars (E) then
795 Error_Msg_NE -- CODEFIX
796 ("?pragma Unreferenced given for&!", N, BE);
804 -- Here we issue the warning, since this is a real reference
807 Error_Msg_NE -- CODEFIX
808 ("?pragma Unreferenced given for&!", N, E);
812 -- If this is a subprogram instance, mark as well the internal
813 -- subprogram in the wrapper package, which may be a visible
816 if Is_Overloadable (E)
817 and then Is_Generic_Instance (E)
818 and then Present (Alias (E))
820 Set_Referenced (Alias (E));
824 -- Generate reference if all conditions are met:
827 -- Cross referencing must be active
831 -- The entity must be one for which we collect references
833 and then Xref_Entity_Letters (Ekind (E)) /= ' '
835 -- Both Sloc values must be set to something sensible
837 and then Sloc (E) > No_Location
838 and then Sloc (N) > No_Location
840 -- We ignore references from within an instance, except for default
841 -- subprograms, for which we generate an implicit reference.
844 (Instantiation_Location (Sloc (N)) = No_Location or else Typ = 'i')
846 -- Ignore dummy references
850 if Nkind (N) = N_Identifier
852 Nkind (N) = N_Defining_Identifier
856 Nkind (N) = N_Defining_Operator_Symbol
858 Nkind (N) = N_Operator_Symbol
860 (Nkind (N) = N_Character_Literal
861 and then Sloc (Entity (N)) /= Standard_Location)
863 Nkind (N) = N_Defining_Character_Literal
867 elsif Nkind (N) = N_Expanded_Name
869 Nkind (N) = N_Selected_Component
871 Nod := Selector_Name (N);
877 -- Normal case of source entity comes from source
879 if Comes_From_Source (E) then
882 -- Entity does not come from source, but is a derived subprogram and
883 -- the derived subprogram comes from source (after one or more
884 -- derivations) in which case the reference is to parent subprogram.
886 elsif Is_Overloadable (E)
887 and then Present (Alias (E))
890 while not Comes_From_Source (Ent) loop
891 if No (Alias (Ent)) then
898 -- The internally created defining entity for a child subprogram
899 -- that has no previous spec has valid references.
901 elsif Is_Overloadable (E)
902 and then Is_Child_Unit (E)
906 -- Record components of discriminated subtypes or derived types must
907 -- be treated as references to the original component.
909 elsif Ekind (E) = E_Component
910 and then Comes_From_Source (Original_Record_Component (E))
912 Ent := Original_Record_Component (E);
914 -- If this is an expanded reference to a discriminant, recover the
915 -- original discriminant, which gets the reference.
917 elsif Ekind (E) = E_In_Parameter
918 and then Present (Discriminal_Link (E))
920 Ent := Discriminal_Link (E);
921 Set_Referenced (Ent);
923 -- Ignore reference to any other entity that is not from source
929 -- Record reference to entity
931 Ref := Original_Location (Sloc (Nod));
932 Def := Original_Location (Sloc (Ent));
934 Ref_Scope := Enclosing_Subprogram_Or_Package (N);
935 Ent_Scope := Enclosing_Subprogram_Or_Package (Ent);
937 Xrefs.Increment_Last;
940 Xrefs.Table (Indx).Loc := Ref;
942 -- Overriding operations are marked with 'P'
945 and then Is_Subprogram (N)
946 and then Present (Overridden_Operation (N))
948 Xrefs.Table (Indx).Typ := 'P';
950 Xrefs.Table (Indx).Typ := Typ;
953 Xrefs.Table (Indx).Eun := Get_Source_Unit (Def);
954 Xrefs.Table (Indx).Lun := Get_Source_Unit (Ref);
955 Xrefs.Table (Indx).Ent := Ent;
957 Xrefs.Table (Indx).Ref_Scope := Ref_Scope;
958 Xrefs.Table (Indx).Ent_Scope := Ent_Scope;
959 Xrefs.Table (Indx).Ent_Scope_File := Get_Source_Unit (Ent_Scope);
961 Set_Has_Xref_Entry (Ent);
963 end Generate_Reference;
965 -----------------------------------
966 -- Generate_Reference_To_Formals --
967 -----------------------------------
969 procedure Generate_Reference_To_Formals (E : Entity_Id) is
973 if Is_Generic_Subprogram (E) then
974 Formal := First_Entity (E);
976 while Present (Formal)
977 and then not Is_Formal (Formal)
979 Next_Entity (Formal);
983 Formal := First_Formal (E);
986 while Present (Formal) loop
987 if Ekind (Formal) = E_In_Parameter then
989 if Nkind (Parameter_Type (Parent (Formal)))
990 = N_Access_Definition
992 Generate_Reference (E, Formal, '^', False);
994 Generate_Reference (E, Formal, '>', False);
997 elsif Ekind (Formal) = E_In_Out_Parameter then
998 Generate_Reference (E, Formal, '=', False);
1001 Generate_Reference (E, Formal, '<', False);
1004 Next_Formal (Formal);
1006 end Generate_Reference_To_Formals;
1008 -------------------------------------------
1009 -- Generate_Reference_To_Generic_Formals --
1010 -------------------------------------------
1012 procedure Generate_Reference_To_Generic_Formals (E : Entity_Id) is
1016 Formal := First_Entity (E);
1017 while Present (Formal) loop
1018 if Comes_From_Source (Formal) then
1019 Generate_Reference (E, Formal, 'z', False);
1022 Next_Entity (Formal);
1024 end Generate_Reference_To_Generic_Formals;
1030 procedure Initialize is
1039 function Lt (T1, T2 : Xref_Entry) return Boolean is
1041 -- First test: if entity is in different unit, sort by unit
1043 if T1.Eun /= T2.Eun then
1044 return Dependency_Num (T1.Eun) < Dependency_Num (T2.Eun);
1046 -- Second test: within same unit, sort by entity Sloc
1048 elsif T1.Def /= T2.Def then
1049 return T1.Def < T2.Def;
1051 -- Third test: sort definitions ahead of references
1053 elsif T1.Loc = No_Location then
1056 elsif T2.Loc = No_Location then
1059 -- Fourth test: for same entity, sort by reference location unit
1061 elsif T1.Lun /= T2.Lun then
1062 return Dependency_Num (T1.Lun) < Dependency_Num (T2.Lun);
1064 -- Fifth test: order of location within referencing unit
1066 elsif T1.Loc /= T2.Loc then
1067 return T1.Loc < T2.Loc;
1069 -- Finally, for two locations at the same address, we prefer
1070 -- the one that does NOT have the type 'r' so that a modification
1071 -- or extension takes preference, when there are more than one
1072 -- reference at the same location. As a result, in the case of
1073 -- entities that are in-out actuals, the read reference follows
1074 -- the modify reference.
1077 return T2.Typ = 'r';
1081 -----------------------
1082 -- Output_References --
1083 -----------------------
1085 procedure Output_References is
1087 procedure Get_Type_Reference
1089 Tref : out Entity_Id;
1090 Left : out Character;
1091 Right : out Character);
1092 -- Given an Entity_Id Ent, determines whether a type reference is
1093 -- required. If so, Tref is set to the entity for the type reference
1094 -- and Left and Right are set to the left/right brackets to be output
1095 -- for the reference. If no type reference is required, then Tref is
1096 -- set to Empty, and Left/Right are set to space.
1098 procedure Output_Import_Export_Info (Ent : Entity_Id);
1099 -- Output language and external name information for an interfaced
1100 -- entity, using the format <language, external_name>,
1102 ------------------------
1103 -- Get_Type_Reference --
1104 ------------------------
1106 procedure Get_Type_Reference
1108 Tref : out Entity_Id;
1109 Left : out Character;
1110 Right : out Character)
1115 -- See if we have a type reference
1124 -- Processing for types
1126 if Is_Type (Tref) then
1128 -- Case of base type
1130 if Base_Type (Tref) = Tref then
1132 -- If derived, then get first subtype
1134 if Tref /= Etype (Tref) then
1135 Tref := First_Subtype (Etype (Tref));
1137 -- Set brackets for derived type, but don't override
1138 -- pointer case since the fact that something is a
1139 -- pointer is more important.
1146 -- If non-derived ptr, get directly designated type.
1147 -- If the type has a full view, all references are on the
1148 -- partial view, that is seen first.
1150 elsif Is_Access_Type (Tref) then
1151 Tref := Directly_Designated_Type (Tref);
1155 elsif Is_Private_Type (Tref)
1156 and then Present (Full_View (Tref))
1158 if Is_Access_Type (Full_View (Tref)) then
1159 Tref := Directly_Designated_Type (Full_View (Tref));
1163 -- If the full view is an array type, we also retrieve
1164 -- the corresponding component type, because the ali
1165 -- entry already indicates that this is an array.
1167 elsif Is_Array_Type (Full_View (Tref)) then
1168 Tref := Component_Type (Full_View (Tref));
1173 -- If non-derived array, get component type. Skip component
1174 -- type for case of String or Wide_String, saves worthwhile
1177 elsif Is_Array_Type (Tref)
1178 and then Tref /= Standard_String
1179 and then Tref /= Standard_Wide_String
1181 Tref := Component_Type (Tref);
1185 -- For other non-derived base types, nothing
1191 -- For a subtype, go to ancestor subtype
1194 Tref := Ancestor_Subtype (Tref);
1196 -- If no ancestor subtype, go to base type
1199 Tref := Base_Type (Sav);
1203 -- For objects, functions, enum literals, just get type from
1206 elsif Is_Object (Tref)
1207 or else Ekind (Tref) = E_Enumeration_Literal
1208 or else Ekind (Tref) = E_Function
1209 or else Ekind (Tref) = E_Operator
1211 Tref := Etype (Tref);
1213 -- For anything else, exit
1219 -- Exit if no type reference, or we are stuck in some loop trying
1220 -- to find the type reference, or if the type is standard void
1221 -- type (the latter is an implementation artifact that should not
1222 -- show up in the generated cross-references).
1226 or else Tref = Standard_Void_Type;
1228 -- If we have a usable type reference, return, otherwise keep
1229 -- looking for something useful (we are looking for something
1230 -- that either comes from source or standard)
1232 if Sloc (Tref) = Standard_Location
1233 or else Comes_From_Source (Tref)
1235 -- If the reference is a subtype created for a generic actual,
1236 -- go actual directly, the inner subtype is not user visible.
1238 if Nkind (Parent (Tref)) = N_Subtype_Declaration
1239 and then not Comes_From_Source (Parent (Tref))
1241 (Is_Wrapper_Package (Scope (Tref))
1242 or else Is_Generic_Instance (Scope (Tref)))
1244 Tref := First_Subtype (Base_Type (Tref));
1251 -- If we fall through the loop, no type reference
1256 end Get_Type_Reference;
1258 -------------------------------
1259 -- Output_Import_Export_Info --
1260 -------------------------------
1262 procedure Output_Import_Export_Info (Ent : Entity_Id) is
1263 Language_Name : Name_Id;
1264 Conv : constant Convention_Id := Convention (Ent);
1267 -- Generate language name from convention
1269 if Conv = Convention_C then
1270 Language_Name := Name_C;
1272 elsif Conv = Convention_CPP then
1273 Language_Name := Name_CPP;
1275 elsif Conv = Convention_Ada then
1276 Language_Name := Name_Ada;
1279 -- For the moment we ignore all other cases ???
1284 Write_Info_Char ('<');
1285 Get_Unqualified_Name_String (Language_Name);
1287 for J in 1 .. Name_Len loop
1288 Write_Info_Char (Name_Buffer (J));
1291 if Present (Interface_Name (Ent)) then
1292 Write_Info_Char (',');
1293 String_To_Name_Buffer (Strval (Interface_Name (Ent)));
1295 for J in 1 .. Name_Len loop
1296 Write_Info_Char (Name_Buffer (J));
1300 Write_Info_Char ('>');
1301 end Output_Import_Export_Info;
1303 -- Start of processing for Output_References
1306 -- First we add references to the primitive operations of tagged types
1307 -- declared in the main unit.
1309 Handle_Prim_Ops : declare
1313 for J in 1 .. Xrefs.Last loop
1314 Ent := Xrefs.Table (J).Ent;
1317 and then Is_Tagged_Type (Ent)
1318 and then Is_Base_Type (Ent)
1319 and then In_Extended_Main_Source_Unit (Ent)
1321 Generate_Prim_Op_References (Ent);
1324 end Handle_Prim_Ops;
1326 -- Before we go ahead and output the references we have a problem
1327 -- that needs dealing with. So far we have captured things that are
1328 -- definitely referenced by the main unit, or defined in the main
1329 -- unit. That's because we don't want to clutter up the ali file
1330 -- for this unit with definition lines for entities in other units
1331 -- that are not referenced.
1333 -- But there is a glitch. We may reference an entity in another unit,
1334 -- and it may have a type reference to an entity that is not directly
1335 -- referenced in the main unit, which may mean that there is no xref
1336 -- entry for this entity yet in the list of references.
1338 -- If we don't do something about this, we will end with an orphan type
1339 -- reference, i.e. it will point to an entity that does not appear
1340 -- within the generated references in the ali file. That is not good for
1341 -- tools using the xref information.
1343 -- To fix this, we go through the references adding definition entries
1344 -- for any unreferenced entities that can be referenced in a type
1345 -- reference. There is a recursion problem here, and that is dealt with
1346 -- by making sure that this traversal also traverses any entries that
1347 -- get added by the traversal.
1349 Handle_Orphan_Type_References : declare
1357 pragma Warnings (Off, L);
1358 pragma Warnings (Off, R);
1360 procedure New_Entry (E : Entity_Id);
1361 -- Make an additional entry into the Xref table for a type entity
1362 -- that is related to the current entity (parent, type ancestor,
1363 -- progenitor, etc.).
1369 procedure New_Entry (E : Entity_Id) is
1372 and then not Has_Xref_Entry (E)
1373 and then Sloc (E) > No_Location
1375 Xrefs.Increment_Last;
1377 Loc := Original_Location (Sloc (E));
1378 Xrefs.Table (Indx).Ent := E;
1379 Xrefs.Table (Indx).Loc := No_Location;
1380 Xrefs.Table (Indx).Eun := Get_Source_Unit (Loc);
1381 Xrefs.Table (Indx).Lun := No_Unit;
1382 Set_Has_Xref_Entry (E);
1386 -- Start of processing for Handle_Orphan_Type_References
1389 -- Note that this is not a for loop for a very good reason. The
1390 -- processing of items in the table can add new items to the table,
1391 -- and they must be processed as well.
1394 while J <= Xrefs.Last loop
1395 Ent := Xrefs.Table (J).Ent;
1396 Get_Type_Reference (Ent, Tref, L, R);
1399 and then not Has_Xref_Entry (Tref)
1400 and then Sloc (Tref) > No_Location
1404 if Is_Record_Type (Ent)
1405 and then Present (Interfaces (Ent))
1407 -- Add an entry for each one of the given interfaces
1408 -- implemented by type Ent.
1411 Elmt : Elmt_Id := First_Elmt (Interfaces (Ent));
1413 while Present (Elmt) loop
1414 New_Entry (Node (Elmt));
1421 -- Collect inherited primitive operations that may be declared in
1422 -- another unit and have no visible reference in the current one.
1425 and then Is_Tagged_Type (Ent)
1426 and then Is_Derived_Type (Ent)
1427 and then Is_Base_Type (Ent)
1428 and then In_Extended_Main_Source_Unit (Ent)
1431 Op_List : constant Elist_Id := Primitive_Operations (Ent);
1435 function Parent_Op (E : Entity_Id) return Entity_Id;
1436 -- Find original operation, which may be inherited through
1437 -- several derivations.
1439 function Parent_Op (E : Entity_Id) return Entity_Id is
1440 Orig_Op : constant Entity_Id := Alias (E);
1443 if No (Orig_Op) then
1446 elsif not Comes_From_Source (E)
1447 and then not Has_Xref_Entry (Orig_Op)
1448 and then Comes_From_Source (Orig_Op)
1452 return Parent_Op (Orig_Op);
1457 Op := First_Elmt (Op_List);
1458 while Present (Op) loop
1459 Prim := Parent_Op (Node (Op));
1461 if Present (Prim) then
1462 Xrefs.Increment_Last;
1464 Loc := Original_Location (Sloc (Prim));
1465 Xrefs.Table (Indx).Ent := Prim;
1466 Xrefs.Table (Indx).Loc := No_Location;
1467 Xrefs.Table (Indx).Eun :=
1468 Get_Source_Unit (Sloc (Prim));
1469 Xrefs.Table (Indx).Lun := No_Unit;
1470 Set_Has_Xref_Entry (Prim);
1480 end Handle_Orphan_Type_References;
1482 -- Now we have all the references, including those for any embedded
1483 -- type references, so we can sort them, and output them.
1485 Output_Refs : declare
1487 Nrefs : Nat := Xrefs.Last;
1488 -- Number of references in table. This value may get reset (reduced)
1489 -- when we eliminate duplicate reference entries.
1491 Rnums : array (0 .. Nrefs) of Nat;
1492 -- This array contains numbers of references in the Xrefs table.
1493 -- This list is sorted in output order. The extra 0'th entry is
1494 -- convenient for the call to sort. When we sort the table, we
1495 -- move the entries in Rnums around, but we do not move the
1496 -- original table entries.
1498 Curxu : Unit_Number_Type;
1499 -- Current xref unit
1501 Curru : Unit_Number_Type;
1502 -- Current reference unit for one entity
1507 Curnam : String (1 .. Name_Buffer'Length);
1509 -- Simple name and length of current entity
1511 Curdef : Source_Ptr;
1512 -- Original source location for current entity
1515 -- Current reference location
1518 -- Entity type character
1521 -- reference kind of previous reference
1527 -- Renaming reference
1529 Trunit : Unit_Number_Type;
1530 -- Unit number for type reference
1532 function Lt (Op1, Op2 : Natural) return Boolean;
1533 -- Comparison function for Sort call
1535 function Name_Change (X : Entity_Id) return Boolean;
1536 -- Determines if entity X has a different simple name from Curent
1538 procedure Move (From : Natural; To : Natural);
1539 -- Move procedure for Sort call
1541 package Sorting is new GNAT.Heap_Sort_G (Move, Lt);
1547 function Lt (Op1, Op2 : Natural) return Boolean is
1548 T1 : Xref_Entry renames Xrefs.Table (Rnums (Nat (Op1)));
1549 T2 : Xref_Entry renames Xrefs.Table (Rnums (Nat (Op2)));
1559 procedure Move (From : Natural; To : Natural) is
1561 Rnums (Nat (To)) := Rnums (Nat (From));
1568 -- Why a string comparison here??? Why not compare Name_Id values???
1570 function Name_Change (X : Entity_Id) return Boolean is
1572 Get_Unqualified_Name_String (Chars (X));
1574 if Name_Len /= Curlen then
1577 return Name_Buffer (1 .. Curlen) /= Curnam (1 .. Curlen);
1581 -- Start of processing for Output_Refs
1584 -- Capture the definition Sloc values. We delay doing this till now,
1585 -- since at the time the reference or definition is made, private
1586 -- types may be swapped, and the Sloc value may be incorrect. We
1587 -- also set up the pointer vector for the sort.
1589 for J in 1 .. Nrefs loop
1591 Xrefs.Table (J).Def :=
1592 Original_Location (Sloc (Xrefs.Table (J).Ent));
1595 -- Sort the references
1597 Sorting.Sort (Integer (Nrefs));
1599 -- Eliminate duplicate entries
1602 NR : constant Nat := Nrefs;
1605 -- We need this test for NR because if we force ALI file
1606 -- generation in case of errors detected, it may be the case
1607 -- that Nrefs is 0, so we should not reset it here
1612 for J in 2 .. NR loop
1613 if Xrefs.Table (Rnums (J)) /=
1614 Xrefs.Table (Rnums (Nrefs))
1617 Rnums (Nrefs) := Rnums (J);
1623 -- Initialize loop through references
1627 Curdef := No_Location;
1629 Crloc := No_Location;
1632 -- Loop to output references
1634 for Refno in 1 .. Nrefs loop
1635 Output_One_Ref : declare
1638 XE : Xref_Entry renames Xrefs.Table (Rnums (Refno));
1639 -- The current entry to be accessed
1643 -- Used for {} or <> or () for type reference
1645 procedure Check_Type_Reference
1647 List_Interface : Boolean);
1648 -- Find whether there is a meaningful type reference for
1649 -- Ent, and display it accordingly. If List_Interface is
1650 -- true, then Ent is a progenitor interface of the current
1651 -- type entity being listed. In that case list it as is,
1652 -- without looking for a type reference for it.
1654 procedure Output_Instantiation_Refs (Loc : Source_Ptr);
1655 -- Recursive procedure to output instantiation references for
1656 -- the given source ptr in [file|line[...]] form. No output
1657 -- if the given location is not a generic template reference.
1659 procedure Output_Overridden_Op (Old_E : Entity_Id);
1660 -- For a subprogram that is overriding, display information
1661 -- about the inherited operation that it overrides.
1663 --------------------------
1664 -- Check_Type_Reference --
1665 --------------------------
1667 procedure Check_Type_Reference
1669 List_Interface : Boolean)
1672 if List_Interface then
1674 -- This is a progenitor interface of the type for which
1675 -- xref information is being generated.
1682 Get_Type_Reference (Ent, Tref, Left, Right);
1685 if Present (Tref) then
1687 -- Case of standard entity, output name
1689 if Sloc (Tref) = Standard_Location then
1690 Write_Info_Char (Left);
1691 Write_Info_Name (Chars (Tref));
1692 Write_Info_Char (Right);
1694 -- Case of source entity, output location
1697 Write_Info_Char (Left);
1698 Trunit := Get_Source_Unit (Sloc (Tref));
1700 if Trunit /= Curxu then
1701 Write_Info_Nat (Dependency_Num (Trunit));
1702 Write_Info_Char ('|');
1706 (Int (Get_Logical_Line_Number (Sloc (Tref))));
1714 Ctyp := Xref_Entity_Letters (Ekind (Ent));
1717 and then Present (Full_View (Ent))
1719 Ent := Underlying_Type (Ent);
1721 if Present (Ent) then
1722 Ctyp := Xref_Entity_Letters (Ekind (Ent));
1726 Write_Info_Char (Ctyp);
1730 (Int (Get_Column_Number (Sloc (Tref))));
1732 -- If the type comes from an instantiation, add the
1733 -- corresponding info.
1735 Output_Instantiation_Refs (Sloc (Tref));
1736 Write_Info_Char (Right);
1739 end Check_Type_Reference;
1741 -------------------------------
1742 -- Output_Instantiation_Refs --
1743 -------------------------------
1745 procedure Output_Instantiation_Refs (Loc : Source_Ptr) is
1746 Iloc : constant Source_Ptr := Instantiation_Location (Loc);
1747 Lun : Unit_Number_Type;
1748 Cu : constant Unit_Number_Type := Curru;
1751 -- Nothing to do if this is not an instantiation
1753 if Iloc = No_Location then
1757 -- Output instantiation reference
1759 Write_Info_Char ('[');
1760 Lun := Get_Source_Unit (Iloc);
1762 if Lun /= Curru then
1764 Write_Info_Nat (Dependency_Num (Curru));
1765 Write_Info_Char ('|');
1768 Write_Info_Nat (Int (Get_Logical_Line_Number (Iloc)));
1770 -- Recursive call to get nested instantiations
1772 Output_Instantiation_Refs (Iloc);
1774 -- Output final ] after call to get proper nesting
1776 Write_Info_Char (']');
1779 end Output_Instantiation_Refs;
1781 --------------------------
1782 -- Output_Overridden_Op --
1783 --------------------------
1785 procedure Output_Overridden_Op (Old_E : Entity_Id) is
1789 -- The overridden operation has an implicit declaration
1790 -- at the point of derivation. What we want to display
1791 -- is the original operation, which has the actual body
1792 -- (or abstract declaration) that is being overridden.
1793 -- The overridden operation is not always set, e.g. when
1794 -- it is a predefined operator.
1799 -- Follow alias chain if one is present
1801 elsif Present (Alias (Old_E)) then
1803 -- The subprogram may have been implicitly inherited
1804 -- through several levels of derivation, so find the
1805 -- ultimate (source) ancestor.
1807 Op := Ultimate_Alias (Old_E);
1809 -- Normal case of no alias present
1816 and then Sloc (Op) /= Standard_Location
1819 Loc : constant Source_Ptr := Sloc (Op);
1820 Par_Unit : constant Unit_Number_Type :=
1821 Get_Source_Unit (Loc);
1824 Write_Info_Char ('<');
1826 if Par_Unit /= Curxu then
1827 Write_Info_Nat (Dependency_Num (Par_Unit));
1828 Write_Info_Char ('|');
1831 Write_Info_Nat (Int (Get_Logical_Line_Number (Loc)));
1832 Write_Info_Char ('p');
1833 Write_Info_Nat (Int (Get_Column_Number (Loc)));
1834 Write_Info_Char ('>');
1837 end Output_Overridden_Op;
1839 -- Start of processing for Output_One_Ref
1843 Ctyp := Xref_Entity_Letters (Ekind (Ent));
1845 -- Skip reference if it is the only reference to an entity,
1846 -- and it is an END line reference, and the entity is not in
1847 -- the current extended source. This prevents junk entries
1848 -- consisting only of packages with END lines, where no
1849 -- entity from the package is actually referenced.
1852 and then Ent /= Curent
1853 and then (Refno = Nrefs or else
1854 Ent /= Xrefs.Table (Rnums (Refno + 1)).Ent)
1856 not In_Extended_Main_Source_Unit (Ent)
1861 -- For private type, get full view type
1864 and then Present (Full_View (XE.Ent))
1866 Ent := Underlying_Type (Ent);
1868 if Present (Ent) then
1869 Ctyp := Xref_Entity_Letters (Ekind (Ent));
1873 -- Special exception for Boolean
1875 if Ctyp = 'E' and then Is_Boolean_Type (Ent) then
1879 -- For variable reference, get corresponding type
1882 Ent := Etype (XE.Ent);
1883 Ctyp := Fold_Lower (Xref_Entity_Letters (Ekind (Ent)));
1885 -- If variable is private type, get full view type
1888 and then Present (Full_View (Etype (XE.Ent)))
1890 Ent := Underlying_Type (Etype (XE.Ent));
1892 if Present (Ent) then
1893 Ctyp := Fold_Lower (Xref_Entity_Letters (Ekind (Ent)));
1896 elsif Is_Generic_Type (Ent) then
1898 -- If the type of the entity is a generic private type,
1899 -- there is no usable full view, so retain the indication
1900 -- that this is an object.
1905 -- Special handling for access parameters and objects of
1906 -- an anonymous access type.
1908 if Ekind_In (Etype (XE.Ent),
1909 E_Anonymous_Access_Type,
1910 E_Anonymous_Access_Subprogram_Type,
1911 E_Anonymous_Access_Protected_Subprogram_Type)
1913 if Is_Formal (XE.Ent)
1914 or else Ekind_In (XE.Ent, E_Variable, E_Constant)
1919 -- Special handling for Boolean
1921 elsif Ctyp = 'e' and then Is_Boolean_Type (Ent) then
1926 -- Special handling for abstract types and operations
1928 if Is_Overloadable (XE.Ent)
1929 and then Is_Abstract_Subprogram (XE.Ent)
1932 Ctyp := 'x'; -- Abstract procedure
1934 elsif Ctyp = 'V' then
1935 Ctyp := 'y'; -- Abstract function
1938 elsif Is_Type (XE.Ent)
1939 and then Is_Abstract_Type (XE.Ent)
1941 if Is_Interface (XE.Ent) then
1944 elsif Ctyp = 'R' then
1945 Ctyp := 'H'; -- Abstract type
1949 -- Only output reference if interesting type of entity
1953 -- Suppress references to object definitions, used for local
1956 or else XE.Typ = 'D'
1957 or else XE.Typ = 'I'
1959 -- Suppress self references, except for bodies that act as
1962 or else (XE.Loc = XE.Def
1965 or else not Is_Subprogram (XE.Ent)))
1967 -- Also suppress definitions of body formals (we only
1968 -- treat these as references, and the references were
1969 -- separately recorded).
1971 or else (Is_Formal (XE.Ent)
1972 and then Present (Spec_Entity (XE.Ent)))
1977 -- Start new Xref section if new xref unit
1979 if XE.Eun /= Curxu then
1980 if Write_Info_Col > 1 then
1986 Write_Info_Initiate ('X');
1987 Write_Info_Char (' ');
1988 Write_Info_Nat (Dependency_Num (XE.Eun));
1989 Write_Info_Char (' ');
1990 Write_Info_Name (Reference_Name (Source_Index (XE.Eun)));
1993 -- Start new Entity line if new entity. Note that we
1994 -- consider two entities the same if they have the same
1995 -- name and source location. This causes entities in
1996 -- instantiations to be treated as though they referred
2003 (Name_Change (XE.Ent) or else XE.Def /= Curdef))
2008 Get_Unqualified_Name_String (Chars (XE.Ent));
2010 Curnam (1 .. Curlen) := Name_Buffer (1 .. Curlen);
2012 if Write_Info_Col > 1 then
2016 -- Write column number information
2018 Write_Info_Nat (Int (Get_Logical_Line_Number (XE.Def)));
2019 Write_Info_Char (Ctyp);
2020 Write_Info_Nat (Int (Get_Column_Number (XE.Def)));
2022 -- Write level information
2024 Write_Level_Info : declare
2025 function Is_Visible_Generic_Entity
2026 (E : Entity_Id) return Boolean;
2027 -- Check whether E is declared in the visible part
2028 -- of a generic package. For source navigation
2029 -- purposes, treat this as a visible entity.
2031 function Is_Private_Record_Component
2032 (E : Entity_Id) return Boolean;
2033 -- Check whether E is a non-inherited component of a
2034 -- private extension. Even if the enclosing record is
2035 -- public, we want to treat the component as private
2036 -- for navigation purposes.
2038 ---------------------------------
2039 -- Is_Private_Record_Component --
2040 ---------------------------------
2042 function Is_Private_Record_Component
2043 (E : Entity_Id) return Boolean
2045 S : constant Entity_Id := Scope (E);
2048 Ekind (E) = E_Component
2049 and then Nkind (Declaration_Node (S)) =
2050 N_Private_Extension_Declaration
2051 and then Original_Record_Component (E) = E;
2052 end Is_Private_Record_Component;
2054 -------------------------------
2055 -- Is_Visible_Generic_Entity --
2056 -------------------------------
2058 function Is_Visible_Generic_Entity
2059 (E : Entity_Id) return Boolean
2064 -- The Present check here is an error defense
2066 if Present (Scope (E))
2067 and then Ekind (Scope (E)) /= E_Generic_Package
2073 while Present (Par) loop
2075 Nkind (Par) = N_Generic_Package_Declaration
2077 -- Entity is a generic formal
2082 Nkind (Parent (Par)) = N_Package_Specification
2085 Is_List_Member (Par)
2086 and then List_Containing (Par) =
2087 Visible_Declarations (Parent (Par));
2089 Par := Parent (Par);
2094 end Is_Visible_Generic_Entity;
2096 -- Start of processing for Write_Level_Info
2099 if Is_Hidden (Curent)
2100 or else Is_Private_Record_Component (Curent)
2102 Write_Info_Char (' ');
2106 or else Is_Visible_Generic_Entity (Curent)
2108 Write_Info_Char ('*');
2111 Write_Info_Char (' ');
2113 end Write_Level_Info;
2115 -- Output entity name. We use the occurrence from the
2116 -- actual source program at the definition point.
2119 Ent_Name : constant String :=
2120 Exact_Source_Name (Sloc (XE.Ent));
2122 for C in Ent_Name'Range loop
2123 Write_Info_Char (Ent_Name (C));
2127 -- See if we have a renaming reference
2129 if Is_Object (XE.Ent)
2130 and then Present (Renamed_Object (XE.Ent))
2132 Rref := Renamed_Object (XE.Ent);
2134 elsif Is_Overloadable (XE.Ent)
2135 and then Nkind (Parent (Declaration_Node (XE.Ent))) =
2136 N_Subprogram_Renaming_Declaration
2138 Rref := Name (Parent (Declaration_Node (XE.Ent)));
2140 elsif Ekind (XE.Ent) = E_Package
2141 and then Nkind (Declaration_Node (XE.Ent)) =
2142 N_Package_Renaming_Declaration
2144 Rref := Name (Declaration_Node (XE.Ent));
2150 if Present (Rref) then
2151 if Nkind (Rref) = N_Expanded_Name then
2152 Rref := Selector_Name (Rref);
2155 if Nkind (Rref) = N_Identifier
2156 or else Nkind (Rref) = N_Operator_Symbol
2160 -- For renamed array components, use the array name
2161 -- for the renamed entity, which reflect the fact that
2162 -- in general the whole array is aliased.
2164 elsif Nkind (Rref) = N_Indexed_Component then
2165 if Nkind (Prefix (Rref)) = N_Identifier then
2166 Rref := Prefix (Rref);
2167 elsif Nkind (Prefix (Rref)) = N_Expanded_Name then
2168 Rref := Selector_Name (Prefix (Rref));
2178 -- Write out renaming reference if we have one
2180 if Present (Rref) then
2181 Write_Info_Char ('=');
2183 (Int (Get_Logical_Line_Number (Sloc (Rref))));
2184 Write_Info_Char (':');
2186 (Int (Get_Column_Number (Sloc (Rref))));
2189 -- Indicate that the entity is in the unit of the current
2194 -- Write out information about generic parent, if entity
2197 if Is_Generic_Instance (XE.Ent) then
2199 Gen_Par : constant Entity_Id :=
2202 (Unit_Declaration_Node (XE.Ent)));
2203 Loc : constant Source_Ptr := Sloc (Gen_Par);
2204 Gen_U : constant Unit_Number_Type :=
2205 Get_Source_Unit (Loc);
2208 Write_Info_Char ('[');
2210 if Curru /= Gen_U then
2211 Write_Info_Nat (Dependency_Num (Gen_U));
2212 Write_Info_Char ('|');
2216 (Int (Get_Logical_Line_Number (Loc)));
2217 Write_Info_Char (']');
2221 -- See if we have a type reference and if so output
2223 Check_Type_Reference (XE.Ent, False);
2225 -- Additional information for types with progenitors
2227 if Is_Record_Type (XE.Ent)
2228 and then Present (Interfaces (XE.Ent))
2231 Elmt : Elmt_Id := First_Elmt (Interfaces (XE.Ent));
2233 while Present (Elmt) loop
2234 Check_Type_Reference (Node (Elmt), True);
2239 -- For array types, list index types as well. (This is
2240 -- not C, indexes have distinct types).
2242 elsif Is_Array_Type (XE.Ent) then
2246 Indx := First_Index (XE.Ent);
2247 while Present (Indx) loop
2248 Check_Type_Reference
2249 (First_Subtype (Etype (Indx)), True);
2255 -- If the entity is an overriding operation, write info
2256 -- on operation that was overridden.
2258 if Is_Subprogram (XE.Ent)
2259 and then Present (Overridden_Operation (XE.Ent))
2261 Output_Overridden_Op (Overridden_Operation (XE.Ent));
2264 -- End of processing for entity output
2266 Crloc := No_Location;
2269 -- Output the reference if it is not as the same location
2270 -- as the previous one, or it is a read-reference that
2271 -- indicates that the entity is an in-out actual in a call.
2273 if XE.Loc /= No_Location
2276 or else (Prevt = 'm' and then XE.Typ = 'r'))
2281 -- Start continuation if line full, else blank
2283 if Write_Info_Col > 72 then
2285 Write_Info_Initiate ('.');
2288 Write_Info_Char (' ');
2290 -- Output file number if changed
2292 if XE.Lun /= Curru then
2294 Write_Info_Nat (Dependency_Num (Curru));
2295 Write_Info_Char ('|');
2298 Write_Info_Nat (Int (Get_Logical_Line_Number (XE.Loc)));
2299 Write_Info_Char (XE.Typ);
2301 if Is_Overloadable (XE.Ent)
2302 and then Is_Imported (XE.Ent)
2303 and then XE.Typ = 'b'
2305 Output_Import_Export_Info (XE.Ent);
2308 Write_Info_Nat (Int (Get_Column_Number (XE.Loc)));
2310 Output_Instantiation_Refs (Sloc (XE.Ent));
2321 end Output_References;