1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1998-2010, 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 Lib.Util; use Lib.Util;
31 with Nlists; use Nlists;
33 with Restrict; use Restrict;
34 with Rident; use Rident;
36 with Sem_Aux; use Sem_Aux;
37 with Sem_Prag; use Sem_Prag;
38 with Sem_Util; use Sem_Util;
39 with Sem_Warn; use Sem_Warn;
40 with Sinfo; use Sinfo;
41 with Sinput; use Sinput;
42 with Snames; use Snames;
43 with Stringt; use Stringt;
44 with Stand; use Stand;
45 with Table; use Table;
46 with Widechar; use Widechar;
48 with GNAT.Heap_Sort_G;
50 package body Lib.Xref is
56 -- The Xref table is used to record references. The Loc field is set
57 -- to No_Location for a definition entry.
59 subtype Xref_Entry_Number is Int;
61 type Xref_Entry is record
63 -- Entity referenced (E parameter to Generate_Reference)
66 -- Original source location for entity being referenced. Note that these
67 -- values are used only during the output process, they are not set when
68 -- the entries are originally built. This is because private entities
69 -- can be swapped when the initial call is made.
72 -- Location of reference (Original_Location (Sloc field of N parameter
73 -- to Generate_Reference). Set to No_Location for the case of a
74 -- defining occurrence.
77 -- Reference type (Typ param to Generate_Reference)
79 Eun : Unit_Number_Type;
80 -- Unit number corresponding to Ent
82 Lun : Unit_Number_Type;
83 -- Unit number corresponding to Loc. Value is undefined and not
84 -- referenced if Loc is set to No_Location.
88 package Xrefs is new Table.Table (
89 Table_Component_Type => Xref_Entry,
90 Table_Index_Type => Xref_Entry_Number,
92 Table_Initial => Alloc.Xrefs_Initial,
93 Table_Increment => Alloc.Xrefs_Increment,
94 Table_Name => "Xrefs");
96 ------------------------
97 -- Local Subprograms --
98 ------------------------
100 procedure Generate_Prim_Op_References (Typ : Entity_Id);
101 -- For a tagged type, generate implicit references to its primitive
102 -- operations, for source navigation. This is done right before emitting
103 -- cross-reference information rather than at the freeze point of the type
104 -- in order to handle late bodies that are primitive operations.
106 -------------------------
107 -- Generate_Definition --
108 -------------------------
110 procedure Generate_Definition (E : Entity_Id) is
115 pragma Assert (Nkind (E) in N_Entity);
117 -- Note that we do not test Xref_Entity_Letters here. It is too early
118 -- to do so, since we are often called before the entity is fully
119 -- constructed, so that the Ekind is still E_Void.
123 -- Definition must come from source
125 -- We make an exception for subprogram child units that have no spec.
126 -- For these we generate a subprogram declaration for library use,
127 -- and the corresponding entity does not come from source.
128 -- Nevertheless, all references will be attached to it and we have
129 -- to treat is as coming from user code.
131 and then (Comes_From_Source (E) or else Is_Child_Unit (E))
133 -- And must have a reasonable source location that is not
134 -- within an instance (all entities in instances are ignored)
136 and then Sloc (E) > No_Location
137 and then Instantiation_Location (Sloc (E)) = No_Location
139 -- And must be a non-internal name from the main source unit
141 and then In_Extended_Main_Source_Unit (E)
142 and then not Is_Internal_Name (Chars (E))
144 Xrefs.Increment_Last;
146 Loc := Original_Location (Sloc (E));
148 Xrefs.Table (Indx).Ent := E;
149 Xrefs.Table (Indx).Def := No_Location;
150 Xrefs.Table (Indx).Loc := No_Location;
151 Xrefs.Table (Indx).Typ := ' ';
152 Xrefs.Table (Indx).Eun := Get_Source_Unit (Loc);
153 Xrefs.Table (Indx).Lun := No_Unit;
154 Set_Has_Xref_Entry (E);
156 if In_Inlined_Body then
160 end Generate_Definition;
162 ---------------------------------
163 -- Generate_Operator_Reference --
164 ---------------------------------
166 procedure Generate_Operator_Reference
171 if not In_Extended_Main_Source_Unit (N) then
175 -- If the operator is not a Standard operator, then we generate a real
176 -- reference to the user defined operator.
178 if Sloc (Entity (N)) /= Standard_Location then
179 Generate_Reference (Entity (N), N);
181 -- A reference to an implicit inequality operator is also a reference
182 -- to the user-defined equality.
184 if Nkind (N) = N_Op_Ne
185 and then not Comes_From_Source (Entity (N))
186 and then Present (Corresponding_Equality (Entity (N)))
188 Generate_Reference (Corresponding_Equality (Entity (N)), N);
191 -- For the case of Standard operators, we mark the result type as
192 -- referenced. This ensures that in the case where we are using a
193 -- derived operator, we mark an entity of the unit that implicitly
194 -- defines this operator as used. Otherwise we may think that no entity
195 -- of the unit is used. The actual entity marked as referenced is the
196 -- first subtype, which is the relevant user defined entity.
198 -- Note: we only do this for operators that come from source. The
199 -- generated code sometimes reaches for entities that do not need to be
200 -- explicitly visible (for example, when we expand the code for
201 -- comparing two record objects, the fields of the record may not be
204 elsif Comes_From_Source (N) then
205 Set_Referenced (First_Subtype (T));
207 end Generate_Operator_Reference;
209 ---------------------------------
210 -- Generate_Prim_Op_References --
211 ---------------------------------
213 procedure Generate_Prim_Op_References (Typ : Entity_Id) is
216 Prim_List : Elist_Id;
220 -- Handle subtypes of synchronized types
222 if Ekind (Typ) = E_Protected_Subtype
223 or else Ekind (Typ) = E_Task_Subtype
225 Base_T := Etype (Typ);
230 -- References to primitive operations are only relevant for tagged types
232 if not Is_Tagged_Type (Base_T)
233 or else Is_Class_Wide_Type (Base_T)
238 -- Ada 2005 (AI-345): For synchronized types generate reference
239 -- to the wrapper that allow us to dispatch calls through their
240 -- implemented abstract interface types.
242 -- The check for Present here is to protect against previously
243 -- reported critical errors.
245 if Is_Concurrent_Type (Base_T)
246 and then Present (Corresponding_Record_Type (Base_T))
248 Prim_List := Primitive_Operations
249 (Corresponding_Record_Type (Base_T));
251 Prim_List := Primitive_Operations (Base_T);
254 if No (Prim_List) then
258 Prim := First_Elmt (Prim_List);
259 while Present (Prim) loop
261 -- If the operation is derived, get the original for cross-reference
262 -- reference purposes (it is the original for which we want the xref
263 -- and for which the comes_from_source test must be performed).
266 while Present (Alias (Ent)) loop
270 Generate_Reference (Typ, Ent, 'p', Set_Ref => False);
273 end Generate_Prim_Op_References;
275 ------------------------
276 -- Generate_Reference --
277 ------------------------
279 procedure Generate_Reference
282 Typ : Character := 'r';
283 Set_Ref : Boolean := True;
284 Force : Boolean := False)
294 -- Used for call to Find_Actual
297 -- If Formal is non-Empty, then its Ekind, otherwise E_Void
299 function Is_On_LHS (Node : Node_Id) return Boolean;
300 -- Used to check if a node is on the left hand side of an assignment.
301 -- The following cases are handled:
303 -- Variable Node is a direct descendant of left hand side of an
304 -- assignment statement.
306 -- Prefix Of an indexed or selected component that is present in
307 -- a subtree rooted by an assignment statement. There is
308 -- no restriction of nesting of components, thus cases
309 -- such as A.B (C).D are handled properly. However a prefix
310 -- of a dereference (either implicit or explicit) is never
311 -- considered as on a LHS.
313 -- Out param Same as above cases, but OUT parameter
315 function OK_To_Set_Referenced return Boolean;
316 -- Returns True if the Referenced flag can be set. There are a few
317 -- exceptions where we do not want to set this flag, see body for
318 -- details of these exceptional cases.
324 -- ??? There are several routines here and there that perform a similar
325 -- (but subtly different) computation, which should be factored:
327 -- Sem_Util.May_Be_Lvalue
328 -- Sem_Util.Known_To_Be_Assigned
329 -- Exp_Ch2.Expand_Entry_Parameter.In_Assignment_Context
330 -- Exp_Smem.Is_Out_Actual
332 function Is_On_LHS (Node : Node_Id) return Boolean is
338 -- Only identifiers are considered, is this necessary???
340 if Nkind (Node) /= N_Identifier then
344 -- Immediate return if appeared as OUT parameter
346 if Kind = E_Out_Parameter then
350 -- Search for assignment statement subtree root
357 if K = N_Assignment_Statement then
360 -- Check whether the parent is a component and the current node is
361 -- its prefix, but return False if the current node has an access
362 -- type, as in that case the selected or indexed component is an
363 -- implicit dereference, and the LHS is the designated object, not
364 -- the access object.
366 -- ??? case of a slice assignment?
368 -- ??? Note that in some cases this is called too early
369 -- (see comments in Sem_Ch8.Find_Direct_Name), at a point where
370 -- the tree is not fully typed yet. In that case we may lack
371 -- an Etype for N, and we must disable the check for an implicit
372 -- dereference. If the dereference is on an LHS, this causes a
375 elsif (K = N_Selected_Component or else K = N_Indexed_Component)
376 and then Prefix (P) = N
377 and then not (Present (Etype (N))
379 Is_Access_Type (Etype (N)))
383 -- All other cases, definitely not on left side
391 ---------------------------
392 -- OK_To_Set_Referenced --
393 ---------------------------
395 function OK_To_Set_Referenced return Boolean is
399 -- A reference from a pragma Unreferenced or pragma Unmodified or
400 -- pragma Warnings does not cause the Referenced flag to be set.
401 -- This avoids silly warnings about things being referenced and
402 -- not assigned when the only reference is from the pragma.
404 if Nkind (N) = N_Identifier then
407 if Nkind (P) = N_Pragma_Argument_Association then
410 if Nkind (P) = N_Pragma then
411 if Pragma_Name (P) = Name_Warnings
413 Pragma_Name (P) = Name_Unmodified
415 Pragma_Name (P) = Name_Unreferenced
424 end OK_To_Set_Referenced;
426 -- Start of processing for Generate_Reference
429 pragma Assert (Nkind (E) in N_Entity);
430 Find_Actual (N, Formal, Call);
432 if Present (Formal) then
433 Kind := Ekind (Formal);
438 -- Check for obsolescent reference to package ASCII. GNAT treats this
439 -- element of annex J specially since in practice, programs make a lot
440 -- of use of this feature, so we don't include it in the set of features
441 -- diagnosed when Warn_On_Obsolescent_Features mode is set. However we
442 -- are required to note it as a violation of the RM defined restriction.
444 if E = Standard_ASCII then
445 Check_Restriction (No_Obsolescent_Features, N);
448 -- Check for reference to entity marked with Is_Obsolescent
450 -- Note that we always allow obsolescent references in the compiler
451 -- itself and the run time, since we assume that we know what we are
452 -- doing in such cases. For example the calls in Ada.Characters.Handling
453 -- to its own obsolescent subprograms are just fine.
455 -- In any case we do not generate warnings within the extended source
456 -- unit of the entity in question, since we assume the source unit
457 -- itself knows what is going on (and for sure we do not want silly
458 -- warnings, e.g. on the end line of an obsolescent procedure body).
460 if Is_Obsolescent (E)
461 and then not GNAT_Mode
462 and then not In_Extended_Main_Source_Unit (E)
464 Check_Restriction (No_Obsolescent_Features, N);
466 if Warn_On_Obsolescent_Feature then
467 Output_Obsolescent_Entity_Warnings (N, E);
471 -- Warn if reference to Ada 2005 entity not in Ada 2005 mode. We only
472 -- detect real explicit references (modifications and references).
474 if Comes_From_Source (N)
475 and then Is_Ada_2005_Only (E)
476 and then Ada_Version < Ada_05
477 and then Warn_On_Ada_2005_Compatibility
478 and then (Typ = 'm' or else Typ = 'r')
480 Error_Msg_NE ("& is only defined in Ada 2005?", N, E);
483 -- Never collect references if not in main source unit. However, we omit
484 -- this test if Typ is 'e' or 'k', since these entries are structural,
485 -- and it is useful to have them in units that reference packages as
486 -- well as units that define packages. We also omit the test for the
487 -- case of 'p' since we want to include inherited primitive operations
488 -- from other packages.
490 -- We also omit this test is this is a body reference for a subprogram
491 -- instantiation. In this case the reference is to the generic body,
492 -- which clearly need not be in the main unit containing the instance.
493 -- For the same reason we accept an implicit reference generated for
494 -- a default in an instance.
496 if not In_Extended_Main_Source_Unit (N) then
501 or else (Typ = 'b' and then Is_Generic_Instance (E))
509 -- For reference type p, the entity must be in main source unit
511 if Typ = 'p' and then not In_Extended_Main_Source_Unit (E) then
515 -- Unless the reference is forced, we ignore references where the
516 -- reference itself does not come from source.
518 if not Force and then not Comes_From_Source (N) then
522 -- Deal with setting entity as referenced, unless suppressed. Note that
523 -- we still do Set_Referenced on entities that do not come from source.
524 -- This situation arises when we have a source reference to a derived
525 -- operation, where the derived operation itself does not come from
526 -- source, but we still want to mark it as referenced, since we really
527 -- are referencing an entity in the corresponding package (this avoids
528 -- wrong complaints that the package contains no referenced entities).
532 -- Assignable object appearing on left side of assignment or as
536 and then Is_On_LHS (N)
537 and then Ekind (E) /= E_In_Out_Parameter
539 -- For objects that are renamings, just set as simply referenced
540 -- we do not try to do assignment type tracking in this case.
542 if Present (Renamed_Object (E)) then
545 -- Out parameter case
547 elsif Kind = E_Out_Parameter then
549 -- If warning mode for all out parameters is set, or this is
550 -- the only warning parameter, then we want to mark this for
551 -- later warning logic by setting Referenced_As_Out_Parameter
553 if Warn_On_Modified_As_Out_Parameter (Formal) then
554 Set_Referenced_As_Out_Parameter (E, True);
555 Set_Referenced_As_LHS (E, False);
557 -- For OUT parameter not covered by the above cases, we simply
558 -- regard it as a normal reference (in this case we do not
559 -- want any of the warning machinery for out parameters).
565 -- For the left hand of an assignment case, we do nothing here.
566 -- The processing for Analyze_Assignment_Statement will set the
567 -- Referenced_As_LHS flag.
573 -- Check for a reference in a pragma that should not count as a
574 -- making the variable referenced for warning purposes.
576 elsif Is_Non_Significant_Pragma_Reference (N) then
579 -- A reference in an attribute definition clause does not count as a
580 -- reference except for the case of Address. The reason that 'Address
581 -- is an exception is that it creates an alias through which the
582 -- variable may be referenced.
584 elsif Nkind (Parent (N)) = N_Attribute_Definition_Clause
585 and then Chars (Parent (N)) /= Name_Address
586 and then N = Name (Parent (N))
590 -- Constant completion does not count as a reference
593 and then Ekind (E) = E_Constant
597 -- Record representation clause does not count as a reference
599 elsif Nkind (N) = N_Identifier
600 and then Nkind (Parent (N)) = N_Record_Representation_Clause
604 -- Discriminants do not need to produce a reference to record type
607 and then Nkind (Parent (N)) = N_Discriminant_Specification
614 -- Special processing for IN OUT parameters, where we have an
615 -- implicit assignment to a simple variable.
617 if Kind = E_In_Out_Parameter
618 and then Is_Assignable (E)
620 -- For sure this counts as a normal read reference
623 Set_Last_Assignment (E, Empty);
625 -- We count it as being referenced as an out parameter if the
626 -- option is set to warn on all out parameters, except that we
627 -- have a special exclusion for an intrinsic subprogram, which
628 -- is most likely an instantiation of Unchecked_Deallocation
629 -- which we do not want to consider as an assignment since it
630 -- generates false positives. We also exclude the case of an
631 -- IN OUT parameter if the name of the procedure is Free,
632 -- since we suspect similar semantics.
634 if Warn_On_All_Unread_Out_Parameters
635 and then Is_Entity_Name (Name (Call))
636 and then not Is_Intrinsic_Subprogram (Entity (Name (Call)))
637 and then Chars (Name (Call)) /= Name_Free
639 Set_Referenced_As_Out_Parameter (E, True);
640 Set_Referenced_As_LHS (E, False);
643 -- Don't count a recursive reference within a subprogram as a
644 -- reference (that allows detection of a recursive subprogram
645 -- whose only references are recursive calls as unreferenced).
647 elsif Is_Subprogram (E)
648 and then E = Nearest_Dynamic_Scope (Current_Scope)
652 -- Any other occurrence counts as referencing the entity
654 elsif OK_To_Set_Referenced then
657 -- If variable, this is an OK reference after an assignment
658 -- so we can clear the Last_Assignment indication.
660 if Is_Assignable (E) then
661 Set_Last_Assignment (E, Empty);
666 -- Check for pragma Unreferenced given and reference is within
667 -- this source unit (occasion for possible warning to be issued).
669 if Has_Unreferenced (E)
670 and then In_Same_Extended_Unit (E, N)
672 -- A reference as a named parameter in a call does not count
673 -- as a violation of pragma Unreferenced for this purpose...
675 if Nkind (N) = N_Identifier
676 and then Nkind (Parent (N)) = N_Parameter_Association
677 and then Selector_Name (Parent (N)) = N
681 -- ... Neither does a reference to a variable on the left side
684 elsif Is_On_LHS (N) then
687 -- For entry formals, we want to place the warning message on the
688 -- corresponding entity in the accept statement. The current scope
689 -- is the body of the accept, so we find the formal whose name
690 -- matches that of the entry formal (there is no link between the
691 -- two entities, and the one in the accept statement is only used
692 -- for conformance checking).
694 elsif Ekind (Scope (E)) = E_Entry then
699 BE := First_Entity (Current_Scope);
700 while Present (BE) loop
701 if Chars (BE) = Chars (E) then
702 Error_Msg_NE -- CODEFIX
703 ("?pragma Unreferenced given for&!", N, BE);
711 -- Here we issue the warning, since this is a real reference
714 Error_Msg_NE -- CODEFIX
715 ("?pragma Unreferenced given for&!", N, E);
719 -- If this is a subprogram instance, mark as well the internal
720 -- subprogram in the wrapper package, which may be a visible
723 if Is_Overloadable (E)
724 and then Is_Generic_Instance (E)
725 and then Present (Alias (E))
727 Set_Referenced (Alias (E));
731 -- Generate reference if all conditions are met:
734 -- Cross referencing must be active
738 -- The entity must be one for which we collect references
740 and then Xref_Entity_Letters (Ekind (E)) /= ' '
742 -- Both Sloc values must be set to something sensible
744 and then Sloc (E) > No_Location
745 and then Sloc (N) > No_Location
747 -- We ignore references from within an instance, except for default
748 -- subprograms, for which we generate an implicit reference.
751 (Instantiation_Location (Sloc (N)) = No_Location or else Typ = 'i')
753 -- Ignore dummy references
757 if Nkind (N) = N_Identifier
759 Nkind (N) = N_Defining_Identifier
763 Nkind (N) = N_Defining_Operator_Symbol
765 Nkind (N) = N_Operator_Symbol
767 (Nkind (N) = N_Character_Literal
768 and then Sloc (Entity (N)) /= Standard_Location)
770 Nkind (N) = N_Defining_Character_Literal
774 elsif Nkind (N) = N_Expanded_Name
776 Nkind (N) = N_Selected_Component
778 Nod := Selector_Name (N);
784 -- Normal case of source entity comes from source
786 if Comes_From_Source (E) then
789 -- Entity does not come from source, but is a derived subprogram and
790 -- the derived subprogram comes from source (after one or more
791 -- derivations) in which case the reference is to parent subprogram.
793 elsif Is_Overloadable (E)
794 and then Present (Alias (E))
797 while not Comes_From_Source (Ent) loop
798 if No (Alias (Ent)) then
805 -- The internally created defining entity for a child subprogram
806 -- that has no previous spec has valid references.
808 elsif Is_Overloadable (E)
809 and then Is_Child_Unit (E)
813 -- Record components of discriminated subtypes or derived types must
814 -- be treated as references to the original component.
816 elsif Ekind (E) = E_Component
817 and then Comes_From_Source (Original_Record_Component (E))
819 Ent := Original_Record_Component (E);
821 -- If this is an expanded reference to a discriminant, recover the
822 -- original discriminant, which gets the reference.
824 elsif Ekind (E) = E_In_Parameter
825 and then Present (Discriminal_Link (E))
827 Ent := Discriminal_Link (E);
828 Set_Referenced (Ent);
830 -- Ignore reference to any other entity that is not from source
836 -- Record reference to entity
838 Ref := Original_Location (Sloc (Nod));
839 Def := Original_Location (Sloc (Ent));
841 Xrefs.Increment_Last;
844 Xrefs.Table (Indx).Loc := Ref;
846 -- Overriding operations are marked with 'P'
849 and then Is_Subprogram (N)
850 and then Is_Overriding_Operation (N)
852 Xrefs.Table (Indx).Typ := 'P';
854 Xrefs.Table (Indx).Typ := Typ;
857 Xrefs.Table (Indx).Eun := Get_Source_Unit (Def);
858 Xrefs.Table (Indx).Lun := Get_Source_Unit (Ref);
859 Xrefs.Table (Indx).Ent := Ent;
860 Set_Has_Xref_Entry (Ent);
862 end Generate_Reference;
864 -----------------------------------
865 -- Generate_Reference_To_Formals --
866 -----------------------------------
868 procedure Generate_Reference_To_Formals (E : Entity_Id) is
872 if Is_Generic_Subprogram (E) then
873 Formal := First_Entity (E);
875 while Present (Formal)
876 and then not Is_Formal (Formal)
878 Next_Entity (Formal);
882 Formal := First_Formal (E);
885 while Present (Formal) loop
886 if Ekind (Formal) = E_In_Parameter then
888 if Nkind (Parameter_Type (Parent (Formal)))
889 = N_Access_Definition
891 Generate_Reference (E, Formal, '^', False);
893 Generate_Reference (E, Formal, '>', False);
896 elsif Ekind (Formal) = E_In_Out_Parameter then
897 Generate_Reference (E, Formal, '=', False);
900 Generate_Reference (E, Formal, '<', False);
903 Next_Formal (Formal);
905 end Generate_Reference_To_Formals;
907 -------------------------------------------
908 -- Generate_Reference_To_Generic_Formals --
909 -------------------------------------------
911 procedure Generate_Reference_To_Generic_Formals (E : Entity_Id) is
915 Formal := First_Entity (E);
916 while Present (Formal) loop
917 if Comes_From_Source (Formal) then
918 Generate_Reference (E, Formal, 'z', False);
921 Next_Entity (Formal);
923 end Generate_Reference_To_Generic_Formals;
929 procedure Initialize is
934 -----------------------
935 -- Output_References --
936 -----------------------
938 procedure Output_References is
940 procedure Get_Type_Reference
942 Tref : out Entity_Id;
943 Left : out Character;
944 Right : out Character);
945 -- Given an Entity_Id Ent, determines whether a type reference is
946 -- required. If so, Tref is set to the entity for the type reference
947 -- and Left and Right are set to the left/right brackets to be output
948 -- for the reference. If no type reference is required, then Tref is
949 -- set to Empty, and Left/Right are set to space.
951 procedure Output_Import_Export_Info (Ent : Entity_Id);
952 -- Output language and external name information for an interfaced
953 -- entity, using the format <language, external_name>,
955 ------------------------
956 -- Get_Type_Reference --
957 ------------------------
959 procedure Get_Type_Reference
961 Tref : out Entity_Id;
962 Left : out Character;
963 Right : out Character)
968 -- See if we have a type reference
977 -- Processing for types
979 if Is_Type (Tref) then
983 if Base_Type (Tref) = Tref then
985 -- If derived, then get first subtype
987 if Tref /= Etype (Tref) then
988 Tref := First_Subtype (Etype (Tref));
990 -- Set brackets for derived type, but don't override
991 -- pointer case since the fact that something is a
992 -- pointer is more important.
999 -- If non-derived ptr, get directly designated type.
1000 -- If the type has a full view, all references are on the
1001 -- partial view, that is seen first.
1003 elsif Is_Access_Type (Tref) then
1004 Tref := Directly_Designated_Type (Tref);
1008 elsif Is_Private_Type (Tref)
1009 and then Present (Full_View (Tref))
1011 if Is_Access_Type (Full_View (Tref)) then
1012 Tref := Directly_Designated_Type (Full_View (Tref));
1016 -- If the full view is an array type, we also retrieve
1017 -- the corresponding component type, because the ali
1018 -- entry already indicates that this is an array.
1020 elsif Is_Array_Type (Full_View (Tref)) then
1021 Tref := Component_Type (Full_View (Tref));
1026 -- If non-derived array, get component type. Skip component
1027 -- type for case of String or Wide_String, saves worthwhile
1030 elsif Is_Array_Type (Tref)
1031 and then Tref /= Standard_String
1032 and then Tref /= Standard_Wide_String
1034 Tref := Component_Type (Tref);
1038 -- For other non-derived base types, nothing
1044 -- For a subtype, go to ancestor subtype
1047 Tref := Ancestor_Subtype (Tref);
1049 -- If no ancestor subtype, go to base type
1052 Tref := Base_Type (Sav);
1056 -- For objects, functions, enum literals, just get type from
1059 elsif Is_Object (Tref)
1060 or else Ekind (Tref) = E_Enumeration_Literal
1061 or else Ekind (Tref) = E_Function
1062 or else Ekind (Tref) = E_Operator
1064 Tref := Etype (Tref);
1066 -- For anything else, exit
1072 -- Exit if no type reference, or we are stuck in some loop trying
1073 -- to find the type reference, or if the type is standard void
1074 -- type (the latter is an implementation artifact that should not
1075 -- show up in the generated cross-references).
1079 or else Tref = Standard_Void_Type;
1081 -- If we have a usable type reference, return, otherwise keep
1082 -- looking for something useful (we are looking for something
1083 -- that either comes from source or standard)
1085 if Sloc (Tref) = Standard_Location
1086 or else Comes_From_Source (Tref)
1088 -- If the reference is a subtype created for a generic actual,
1089 -- go actual directly, the inner subtype is not user visible.
1091 if Nkind (Parent (Tref)) = N_Subtype_Declaration
1092 and then not Comes_From_Source (Parent (Tref))
1094 (Is_Wrapper_Package (Scope (Tref))
1095 or else Is_Generic_Instance (Scope (Tref)))
1097 Tref := First_Subtype (Base_Type (Tref));
1104 -- If we fall through the loop, no type reference
1109 end Get_Type_Reference;
1111 -------------------------------
1112 -- Output_Import_Export_Info --
1113 -------------------------------
1115 procedure Output_Import_Export_Info (Ent : Entity_Id) is
1116 Language_Name : Name_Id;
1117 Conv : constant Convention_Id := Convention (Ent);
1120 -- Generate language name from convention
1122 if Conv = Convention_C then
1123 Language_Name := Name_C;
1125 elsif Conv = Convention_CPP then
1126 Language_Name := Name_CPP;
1128 elsif Conv = Convention_Ada then
1129 Language_Name := Name_Ada;
1132 -- For the moment we ignore all other cases ???
1137 Write_Info_Char ('<');
1138 Get_Unqualified_Name_String (Language_Name);
1140 for J in 1 .. Name_Len loop
1141 Write_Info_Char (Name_Buffer (J));
1144 if Present (Interface_Name (Ent)) then
1145 Write_Info_Char (',');
1146 String_To_Name_Buffer (Strval (Interface_Name (Ent)));
1148 for J in 1 .. Name_Len loop
1149 Write_Info_Char (Name_Buffer (J));
1153 Write_Info_Char ('>');
1154 end Output_Import_Export_Info;
1156 -- Start of processing for Output_References
1159 if not Opt.Xref_Active then
1163 -- First we add references to the primitive operations of tagged
1164 -- types declared in the main unit.
1166 Handle_Prim_Ops : declare
1170 for J in 1 .. Xrefs.Last loop
1171 Ent := Xrefs.Table (J).Ent;
1174 and then Is_Tagged_Type (Ent)
1175 and then Ent = Base_Type (Ent)
1176 and then In_Extended_Main_Source_Unit (Ent)
1178 Generate_Prim_Op_References (Ent);
1181 end Handle_Prim_Ops;
1183 -- Before we go ahead and output the references we have a problem
1184 -- that needs dealing with. So far we have captured things that are
1185 -- definitely referenced by the main unit, or defined in the main
1186 -- unit. That's because we don't want to clutter up the ali file
1187 -- for this unit with definition lines for entities in other units
1188 -- that are not referenced.
1190 -- But there is a glitch. We may reference an entity in another unit,
1191 -- and it may have a type reference to an entity that is not directly
1192 -- referenced in the main unit, which may mean that there is no xref
1193 -- entry for this entity yet in the list of references.
1195 -- If we don't do something about this, we will end with an orphan type
1196 -- reference, i.e. it will point to an entity that does not appear
1197 -- within the generated references in the ali file. That is not good for
1198 -- tools using the xref information.
1200 -- To fix this, we go through the references adding definition entries
1201 -- for any unreferenced entities that can be referenced in a type
1202 -- reference. There is a recursion problem here, and that is dealt with
1203 -- by making sure that this traversal also traverses any entries that
1204 -- get added by the traversal.
1206 Handle_Orphan_Type_References : declare
1214 pragma Warnings (Off, L);
1215 pragma Warnings (Off, R);
1217 procedure New_Entry (E : Entity_Id);
1218 -- Make an additional entry into the Xref table for a type entity
1219 -- that is related to the current entity (parent, type ancestor,
1220 -- progenitor, etc.).
1226 procedure New_Entry (E : Entity_Id) is
1229 and then not Has_Xref_Entry (E)
1230 and then Sloc (E) > No_Location
1232 Xrefs.Increment_Last;
1234 Loc := Original_Location (Sloc (E));
1235 Xrefs.Table (Indx).Ent := E;
1236 Xrefs.Table (Indx).Loc := No_Location;
1237 Xrefs.Table (Indx).Eun := Get_Source_Unit (Loc);
1238 Xrefs.Table (Indx).Lun := No_Unit;
1239 Set_Has_Xref_Entry (E);
1243 -- Start of processing for Handle_Orphan_Type_References
1246 -- Note that this is not a for loop for a very good reason. The
1247 -- processing of items in the table can add new items to the table,
1248 -- and they must be processed as well.
1251 while J <= Xrefs.Last loop
1252 Ent := Xrefs.Table (J).Ent;
1253 Get_Type_Reference (Ent, Tref, L, R);
1256 and then not Has_Xref_Entry (Tref)
1257 and then Sloc (Tref) > No_Location
1261 if Is_Record_Type (Ent)
1262 and then Present (Interfaces (Ent))
1264 -- Add an entry for each one of the given interfaces
1265 -- implemented by type Ent.
1268 Elmt : Elmt_Id := First_Elmt (Interfaces (Ent));
1270 while Present (Elmt) loop
1271 New_Entry (Node (Elmt));
1278 -- Collect inherited primitive operations that may be declared in
1279 -- another unit and have no visible reference in the current one.
1282 and then Is_Tagged_Type (Ent)
1283 and then Is_Derived_Type (Ent)
1284 and then Ent = Base_Type (Ent)
1285 and then In_Extended_Main_Source_Unit (Ent)
1288 Op_List : constant Elist_Id := Primitive_Operations (Ent);
1292 function Parent_Op (E : Entity_Id) return Entity_Id;
1293 -- Find original operation, which may be inherited through
1294 -- several derivations.
1296 function Parent_Op (E : Entity_Id) return Entity_Id is
1297 Orig_Op : constant Entity_Id := Alias (E);
1300 if No (Orig_Op) then
1303 elsif not Comes_From_Source (E)
1304 and then not Has_Xref_Entry (Orig_Op)
1305 and then Comes_From_Source (Orig_Op)
1309 return Parent_Op (Orig_Op);
1314 Op := First_Elmt (Op_List);
1315 while Present (Op) loop
1316 Prim := Parent_Op (Node (Op));
1318 if Present (Prim) then
1319 Xrefs.Increment_Last;
1321 Loc := Original_Location (Sloc (Prim));
1322 Xrefs.Table (Indx).Ent := Prim;
1323 Xrefs.Table (Indx).Loc := No_Location;
1324 Xrefs.Table (Indx).Eun :=
1325 Get_Source_Unit (Sloc (Prim));
1326 Xrefs.Table (Indx).Lun := No_Unit;
1327 Set_Has_Xref_Entry (Prim);
1337 end Handle_Orphan_Type_References;
1339 -- Now we have all the references, including those for any embedded
1340 -- type references, so we can sort them, and output them.
1342 Output_Refs : declare
1344 Nrefs : Nat := Xrefs.Last;
1345 -- Number of references in table. This value may get reset (reduced)
1346 -- when we eliminate duplicate reference entries.
1348 Rnums : array (0 .. Nrefs) of Nat;
1349 -- This array contains numbers of references in the Xrefs table.
1350 -- This list is sorted in output order. The extra 0'th entry is
1351 -- convenient for the call to sort. When we sort the table, we
1352 -- move the entries in Rnums around, but we do not move the
1353 -- original table entries.
1355 Curxu : Unit_Number_Type;
1356 -- Current xref unit
1358 Curru : Unit_Number_Type;
1359 -- Current reference unit for one entity
1361 Cursrc : Source_Buffer_Ptr;
1362 -- Current xref unit source text
1367 Curnam : String (1 .. Name_Buffer'Length);
1369 -- Simple name and length of current entity
1371 Curdef : Source_Ptr;
1372 -- Original source location for current entity
1375 -- Current reference location
1378 -- Entity type character
1384 -- Renaming reference
1386 Trunit : Unit_Number_Type;
1387 -- Unit number for type reference
1389 function Lt (Op1, Op2 : Natural) return Boolean;
1390 -- Comparison function for Sort call
1392 function Name_Change (X : Entity_Id) return Boolean;
1393 -- Determines if entity X has a different simple name from Curent
1395 procedure Move (From : Natural; To : Natural);
1396 -- Move procedure for Sort call
1398 package Sorting is new GNAT.Heap_Sort_G (Move, Lt);
1404 function Lt (Op1, Op2 : Natural) return Boolean is
1405 T1 : Xref_Entry renames Xrefs.Table (Rnums (Nat (Op1)));
1406 T2 : Xref_Entry renames Xrefs.Table (Rnums (Nat (Op2)));
1409 -- First test: if entity is in different unit, sort by unit
1411 if T1.Eun /= T2.Eun then
1412 return Dependency_Num (T1.Eun) < Dependency_Num (T2.Eun);
1414 -- Second test: within same unit, sort by entity Sloc
1416 elsif T1.Def /= T2.Def then
1417 return T1.Def < T2.Def;
1419 -- Third test: sort definitions ahead of references
1421 elsif T1.Loc = No_Location then
1424 elsif T2.Loc = No_Location then
1427 -- Fourth test: for same entity, sort by reference location unit
1429 elsif T1.Lun /= T2.Lun then
1430 return Dependency_Num (T1.Lun) < Dependency_Num (T2.Lun);
1432 -- Fifth test: order of location within referencing unit
1434 elsif T1.Loc /= T2.Loc then
1435 return T1.Loc < T2.Loc;
1437 -- Finally, for two locations at the same address, we prefer
1438 -- the one that does NOT have the type 'r' so that a modification
1439 -- or extension takes preference, when there are more than one
1440 -- reference at the same location.
1443 return T2.Typ = 'r';
1451 procedure Move (From : Natural; To : Natural) is
1453 Rnums (Nat (To)) := Rnums (Nat (From));
1460 -- Why a string comparison here??? Why not compare Name_Id values???
1462 function Name_Change (X : Entity_Id) return Boolean is
1464 Get_Unqualified_Name_String (Chars (X));
1466 if Name_Len /= Curlen then
1469 return Name_Buffer (1 .. Curlen) /= Curnam (1 .. Curlen);
1473 -- Start of processing for Output_Refs
1476 -- Capture the definition Sloc values. We delay doing this till now,
1477 -- since at the time the reference or definition is made, private
1478 -- types may be swapped, and the Sloc value may be incorrect. We
1479 -- also set up the pointer vector for the sort.
1481 for J in 1 .. Nrefs loop
1483 Xrefs.Table (J).Def :=
1484 Original_Location (Sloc (Xrefs.Table (J).Ent));
1487 -- Sort the references
1489 Sorting.Sort (Integer (Nrefs));
1491 -- Eliminate duplicate entries
1494 NR : constant Nat := Nrefs;
1497 -- We need this test for NR because if we force ALI file
1498 -- generation in case of errors detected, it may be the case
1499 -- that Nrefs is 0, so we should not reset it here
1504 for J in 2 .. NR loop
1505 if Xrefs.Table (Rnums (J)) /=
1506 Xrefs.Table (Rnums (Nrefs))
1509 Rnums (Nrefs) := Rnums (J);
1515 -- Initialize loop through references
1519 Curdef := No_Location;
1521 Crloc := No_Location;
1523 -- Loop to output references
1525 for Refno in 1 .. Nrefs loop
1526 Output_One_Ref : declare
1532 pragma Warnings (Off, WC);
1533 pragma Warnings (Off, Err);
1535 XE : Xref_Entry renames Xrefs.Table (Rnums (Refno));
1536 -- The current entry to be accessed
1539 -- Used to index into source buffer to get entity name
1543 -- Used for {} or <> or () for type reference
1545 procedure Check_Type_Reference
1547 List_Interface : Boolean);
1548 -- Find whether there is a meaningful type reference for
1549 -- Ent, and display it accordingly. If List_Interface is
1550 -- true, then Ent is a progenitor interface of the current
1551 -- type entity being listed. In that case list it as is,
1552 -- without looking for a type reference for it.
1554 procedure Output_Instantiation_Refs (Loc : Source_Ptr);
1555 -- Recursive procedure to output instantiation references for
1556 -- the given source ptr in [file|line[...]] form. No output
1557 -- if the given location is not a generic template reference.
1559 procedure Output_Overridden_Op (Old_E : Entity_Id);
1560 -- For a subprogram that is overriding, display information
1561 -- about the inherited operation that it overrides.
1563 --------------------------
1564 -- Check_Type_Reference --
1565 --------------------------
1567 procedure Check_Type_Reference
1569 List_Interface : Boolean)
1572 if List_Interface then
1574 -- This is a progenitor interface of the type for which
1575 -- xref information is being generated.
1582 Get_Type_Reference (Ent, Tref, Left, Right);
1585 if Present (Tref) then
1587 -- Case of standard entity, output name
1589 if Sloc (Tref) = Standard_Location then
1590 Write_Info_Char (Left);
1591 Write_Info_Name (Chars (Tref));
1592 Write_Info_Char (Right);
1594 -- Case of source entity, output location
1597 Write_Info_Char (Left);
1598 Trunit := Get_Source_Unit (Sloc (Tref));
1600 if Trunit /= Curxu then
1601 Write_Info_Nat (Dependency_Num (Trunit));
1602 Write_Info_Char ('|');
1606 (Int (Get_Logical_Line_Number (Sloc (Tref))));
1614 Ctyp := Xref_Entity_Letters (Ekind (Ent));
1617 and then Present (Full_View (Ent))
1619 Ent := Underlying_Type (Ent);
1621 if Present (Ent) then
1622 Ctyp := Xref_Entity_Letters (Ekind (Ent));
1626 Write_Info_Char (Ctyp);
1630 (Int (Get_Column_Number (Sloc (Tref))));
1632 -- If the type comes from an instantiation, add the
1633 -- corresponding info.
1635 Output_Instantiation_Refs (Sloc (Tref));
1636 Write_Info_Char (Right);
1639 end Check_Type_Reference;
1641 -------------------------------
1642 -- Output_Instantiation_Refs --
1643 -------------------------------
1645 procedure Output_Instantiation_Refs (Loc : Source_Ptr) is
1646 Iloc : constant Source_Ptr := Instantiation_Location (Loc);
1647 Lun : Unit_Number_Type;
1648 Cu : constant Unit_Number_Type := Curru;
1651 -- Nothing to do if this is not an instantiation
1653 if Iloc = No_Location then
1657 -- Output instantiation reference
1659 Write_Info_Char ('[');
1660 Lun := Get_Source_Unit (Iloc);
1662 if Lun /= Curru then
1664 Write_Info_Nat (Dependency_Num (Curru));
1665 Write_Info_Char ('|');
1668 Write_Info_Nat (Int (Get_Logical_Line_Number (Iloc)));
1670 -- Recursive call to get nested instantiations
1672 Output_Instantiation_Refs (Iloc);
1674 -- Output final ] after call to get proper nesting
1676 Write_Info_Char (']');
1679 end Output_Instantiation_Refs;
1681 --------------------------
1682 -- Output_Overridden_Op --
1683 --------------------------
1685 procedure Output_Overridden_Op (Old_E : Entity_Id) is
1689 -- The overridden operation has an implicit declaration
1690 -- at the point of derivation. What we want to display
1691 -- is the original operation, which has the actual body
1692 -- (or abstract declaration) that is being overridden.
1693 -- The overridden operation is not always set, e.g. when
1694 -- it is a predefined operator.
1699 -- Follow alias chain if one is present
1701 elsif Present (Alias (Old_E)) then
1703 -- The subprogram may have been implicitly inherited
1704 -- through several levels of derivation, so find the
1705 -- ultimate (source) ancestor.
1707 Op := Alias (Old_E);
1708 while Present (Alias (Op)) loop
1712 -- Normal case of no alias present
1719 and then Sloc (Op) /= Standard_Location
1722 Loc : constant Source_Ptr := Sloc (Op);
1723 Par_Unit : constant Unit_Number_Type :=
1724 Get_Source_Unit (Loc);
1727 Write_Info_Char ('<');
1729 if Par_Unit /= Curxu then
1730 Write_Info_Nat (Dependency_Num (Par_Unit));
1731 Write_Info_Char ('|');
1734 Write_Info_Nat (Int (Get_Logical_Line_Number (Loc)));
1735 Write_Info_Char ('p');
1736 Write_Info_Nat (Int (Get_Column_Number (Loc)));
1737 Write_Info_Char ('>');
1740 end Output_Overridden_Op;
1742 -- Start of processing for Output_One_Ref
1746 Ctyp := Xref_Entity_Letters (Ekind (Ent));
1748 -- Skip reference if it is the only reference to an entity,
1749 -- and it is an END line reference, and the entity is not in
1750 -- the current extended source. This prevents junk entries
1751 -- consisting only of packages with END lines, where no
1752 -- entity from the package is actually referenced.
1755 and then Ent /= Curent
1756 and then (Refno = Nrefs or else
1757 Ent /= Xrefs.Table (Rnums (Refno + 1)).Ent)
1759 not In_Extended_Main_Source_Unit (Ent)
1764 -- For private type, get full view type
1767 and then Present (Full_View (XE.Ent))
1769 Ent := Underlying_Type (Ent);
1771 if Present (Ent) then
1772 Ctyp := Xref_Entity_Letters (Ekind (Ent));
1776 -- Special exception for Boolean
1778 if Ctyp = 'E' and then Is_Boolean_Type (Ent) then
1782 -- For variable reference, get corresponding type
1785 Ent := Etype (XE.Ent);
1786 Ctyp := Fold_Lower (Xref_Entity_Letters (Ekind (Ent)));
1788 -- If variable is private type, get full view type
1791 and then Present (Full_View (Etype (XE.Ent)))
1793 Ent := Underlying_Type (Etype (XE.Ent));
1795 if Present (Ent) then
1796 Ctyp := Fold_Lower (Xref_Entity_Letters (Ekind (Ent)));
1799 elsif Is_Generic_Type (Ent) then
1801 -- If the type of the entity is a generic private type,
1802 -- there is no usable full view, so retain the indication
1803 -- that this is an object.
1808 -- Special handling for access parameter
1811 K : constant Entity_Kind := Ekind (Etype (XE.Ent));
1814 if (K = E_Anonymous_Access_Type
1816 K = E_Anonymous_Access_Subprogram_Type
1818 E_Anonymous_Access_Protected_Subprogram_Type)
1819 and then Is_Formal (XE.Ent)
1823 -- Special handling for Boolean
1825 elsif Ctyp = 'e' and then Is_Boolean_Type (Ent) then
1831 -- Special handling for abstract types and operations
1833 if Is_Overloadable (XE.Ent)
1834 and then Is_Abstract_Subprogram (XE.Ent)
1837 Ctyp := 'x'; -- Abstract procedure
1839 elsif Ctyp = 'V' then
1840 Ctyp := 'y'; -- Abstract function
1843 elsif Is_Type (XE.Ent)
1844 and then Is_Abstract_Type (XE.Ent)
1846 if Is_Interface (XE.Ent) then
1849 elsif Ctyp = 'R' then
1850 Ctyp := 'H'; -- Abstract type
1854 -- Only output reference if interesting type of entity, and
1855 -- suppress self references, except for bodies that act as
1856 -- specs. Also suppress definitions of body formals (we only
1857 -- treat these as references, and the references were
1858 -- separately recorded).
1861 or else (XE.Loc = XE.Def
1864 or else not Is_Subprogram (XE.Ent)))
1865 or else (Is_Formal (XE.Ent)
1866 and then Present (Spec_Entity (XE.Ent)))
1871 -- Start new Xref section if new xref unit
1873 if XE.Eun /= Curxu then
1874 if Write_Info_Col > 1 then
1879 Cursrc := Source_Text (Source_Index (Curxu));
1881 Write_Info_Initiate ('X');
1882 Write_Info_Char (' ');
1883 Write_Info_Nat (Dependency_Num (XE.Eun));
1884 Write_Info_Char (' ');
1885 Write_Info_Name (Reference_Name (Source_Index (XE.Eun)));
1888 -- Start new Entity line if new entity. Note that we
1889 -- consider two entities the same if they have the same
1890 -- name and source location. This causes entities in
1891 -- instantiations to be treated as though they referred
1898 (Name_Change (XE.Ent) or else XE.Def /= Curdef))
1903 Get_Unqualified_Name_String (Chars (XE.Ent));
1905 Curnam (1 .. Curlen) := Name_Buffer (1 .. Curlen);
1907 if Write_Info_Col > 1 then
1911 -- Write column number information
1913 Write_Info_Nat (Int (Get_Logical_Line_Number (XE.Def)));
1914 Write_Info_Char (Ctyp);
1915 Write_Info_Nat (Int (Get_Column_Number (XE.Def)));
1917 -- Write level information
1919 Write_Level_Info : declare
1920 function Is_Visible_Generic_Entity
1921 (E : Entity_Id) return Boolean;
1922 -- Check whether E is declared in the visible part
1923 -- of a generic package. For source navigation
1924 -- purposes, treat this as a visible entity.
1926 function Is_Private_Record_Component
1927 (E : Entity_Id) return Boolean;
1928 -- Check whether E is a non-inherited component of a
1929 -- private extension. Even if the enclosing record is
1930 -- public, we want to treat the component as private
1931 -- for navigation purposes.
1933 ---------------------------------
1934 -- Is_Private_Record_Component --
1935 ---------------------------------
1937 function Is_Private_Record_Component
1938 (E : Entity_Id) return Boolean
1940 S : constant Entity_Id := Scope (E);
1943 Ekind (E) = E_Component
1944 and then Nkind (Declaration_Node (S)) =
1945 N_Private_Extension_Declaration
1946 and then Original_Record_Component (E) = E;
1947 end Is_Private_Record_Component;
1949 -------------------------------
1950 -- Is_Visible_Generic_Entity --
1951 -------------------------------
1953 function Is_Visible_Generic_Entity
1954 (E : Entity_Id) return Boolean
1959 -- The Present check here is an error defense
1961 if Present (Scope (E))
1962 and then Ekind (Scope (E)) /= E_Generic_Package
1968 while Present (Par) loop
1970 Nkind (Par) = N_Generic_Package_Declaration
1972 -- Entity is a generic formal
1977 Nkind (Parent (Par)) = N_Package_Specification
1980 Is_List_Member (Par)
1981 and then List_Containing (Par) =
1982 Visible_Declarations (Parent (Par));
1984 Par := Parent (Par);
1989 end Is_Visible_Generic_Entity;
1991 -- Start of processing for Write_Level_Info
1994 if Is_Hidden (Curent)
1995 or else Is_Private_Record_Component (Curent)
1997 Write_Info_Char (' ');
2001 or else Is_Visible_Generic_Entity (Curent)
2003 Write_Info_Char ('*');
2006 Write_Info_Char (' ');
2008 end Write_Level_Info;
2010 -- Output entity name. We use the occurrence from the
2011 -- actual source program at the definition point.
2013 P := Original_Location (Sloc (XE.Ent));
2015 -- Entity is character literal
2017 if Cursrc (P) = ''' then
2018 Write_Info_Char (Cursrc (P));
2019 Write_Info_Char (Cursrc (P + 1));
2020 Write_Info_Char (Cursrc (P + 2));
2022 -- Entity is operator symbol
2024 elsif Cursrc (P) = '"' or else Cursrc (P) = '%' then
2025 Write_Info_Char (Cursrc (P));
2030 Write_Info_Char (Cursrc (P2));
2031 exit when Cursrc (P2) = Cursrc (P);
2034 -- Entity is identifier
2038 if Is_Start_Of_Wide_Char (Cursrc, P) then
2039 Scan_Wide (Cursrc, P, WC, Err);
2040 elsif not Identifier_Char (Cursrc (P)) then
2047 -- Write out the identifier by copying the exact
2048 -- source characters used in its declaration. Note
2049 -- that this means wide characters will be in their
2050 -- original encoded form.
2053 Original_Location (Sloc (XE.Ent)) .. P - 1
2055 Write_Info_Char (Cursrc (J));
2059 -- See if we have a renaming reference
2061 if Is_Object (XE.Ent)
2062 and then Present (Renamed_Object (XE.Ent))
2064 Rref := Renamed_Object (XE.Ent);
2066 elsif Is_Overloadable (XE.Ent)
2067 and then Nkind (Parent (Declaration_Node (XE.Ent))) =
2068 N_Subprogram_Renaming_Declaration
2070 Rref := Name (Parent (Declaration_Node (XE.Ent)));
2072 elsif Ekind (XE.Ent) = E_Package
2073 and then Nkind (Declaration_Node (XE.Ent)) =
2074 N_Package_Renaming_Declaration
2076 Rref := Name (Declaration_Node (XE.Ent));
2082 if Present (Rref) then
2083 if Nkind (Rref) = N_Expanded_Name then
2084 Rref := Selector_Name (Rref);
2087 if Nkind (Rref) = N_Identifier
2088 or else Nkind (Rref) = N_Operator_Symbol
2092 -- For renamed array components, use the array name
2093 -- for the renamed entity, which reflect the fact that
2094 -- in general the whole array is aliased.
2096 elsif Nkind (Rref) = N_Indexed_Component then
2097 if Nkind (Prefix (Rref)) = N_Identifier then
2098 Rref := Prefix (Rref);
2099 elsif Nkind (Prefix (Rref)) = N_Expanded_Name then
2100 Rref := Selector_Name (Prefix (Rref));
2110 -- Write out renaming reference if we have one
2112 if Present (Rref) then
2113 Write_Info_Char ('=');
2115 (Int (Get_Logical_Line_Number (Sloc (Rref))));
2116 Write_Info_Char (':');
2118 (Int (Get_Column_Number (Sloc (Rref))));
2121 -- Indicate that the entity is in the unit of the current
2126 -- Write out information about generic parent, if entity
2129 if Is_Generic_Instance (XE.Ent) then
2131 Gen_Par : constant Entity_Id :=
2134 (Unit_Declaration_Node (XE.Ent)));
2135 Loc : constant Source_Ptr := Sloc (Gen_Par);
2136 Gen_U : constant Unit_Number_Type :=
2137 Get_Source_Unit (Loc);
2140 Write_Info_Char ('[');
2142 if Curru /= Gen_U then
2143 Write_Info_Nat (Dependency_Num (Gen_U));
2144 Write_Info_Char ('|');
2148 (Int (Get_Logical_Line_Number (Loc)));
2149 Write_Info_Char (']');
2153 -- See if we have a type reference and if so output
2155 Check_Type_Reference (XE.Ent, False);
2157 -- Additional information for types with progenitors
2159 if Is_Record_Type (XE.Ent)
2160 and then Present (Interfaces (XE.Ent))
2163 Elmt : Elmt_Id := First_Elmt (Interfaces (XE.Ent));
2165 while Present (Elmt) loop
2166 Check_Type_Reference (Node (Elmt), True);
2171 -- For array types, list index types as well.
2172 -- (This is not C, indices have distinct types).
2174 elsif Is_Array_Type (XE.Ent) then
2178 Indx := First_Index (XE.Ent);
2179 while Present (Indx) loop
2180 Check_Type_Reference
2181 (First_Subtype (Etype (Indx)), True);
2187 -- If the entity is an overriding operation, write info
2188 -- on operation that was overridden.
2190 if Is_Subprogram (XE.Ent)
2191 and then Is_Overriding_Operation (XE.Ent)
2193 Output_Overridden_Op (Overridden_Operation (XE.Ent));
2196 -- End of processing for entity output
2198 Crloc := No_Location;
2201 -- Output the reference
2203 if XE.Loc /= No_Location
2204 and then XE.Loc /= Crloc
2208 -- Start continuation if line full, else blank
2210 if Write_Info_Col > 72 then
2212 Write_Info_Initiate ('.');
2215 Write_Info_Char (' ');
2217 -- Output file number if changed
2219 if XE.Lun /= Curru then
2221 Write_Info_Nat (Dependency_Num (Curru));
2222 Write_Info_Char ('|');
2225 Write_Info_Nat (Int (Get_Logical_Line_Number (XE.Loc)));
2226 Write_Info_Char (XE.Typ);
2228 if Is_Overloadable (XE.Ent)
2229 and then Is_Imported (XE.Ent)
2230 and then XE.Typ = 'b'
2232 Output_Import_Export_Info (XE.Ent);
2235 Write_Info_Nat (Int (Get_Column_Number (XE.Loc)));
2237 Output_Instantiation_Refs (Sloc (XE.Ent));
2248 end Output_References;