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 procedure Generate_Prim_Op_References (Typ : Entity_Id);
116 -- For a tagged type, generate implicit references to its primitive
117 -- operations, for source navigation. This is done right before emitting
118 -- cross-reference information rather than at the freeze point of the type
119 -- in order to handle late bodies that are primitive operations.
121 function Lt (T1, T2 : Xref_Entry) return Boolean;
122 -- Order cross-references
124 -------------------------
125 -- Generate_Definition --
126 -------------------------
128 procedure Generate_Definition (E : Entity_Id) is
133 pragma Assert (Nkind (E) in N_Entity);
135 -- Note that we do not test Xref_Entity_Letters here. It is too early
136 -- to do so, since we are often called before the entity is fully
137 -- constructed, so that the Ekind is still E_Void.
141 -- Definition must come from source
143 -- We make an exception for subprogram child units that have no spec.
144 -- For these we generate a subprogram declaration for library use,
145 -- and the corresponding entity does not come from source.
146 -- Nevertheless, all references will be attached to it and we have
147 -- to treat is as coming from user code.
149 and then (Comes_From_Source (E) or else Is_Child_Unit (E))
151 -- And must have a reasonable source location that is not
152 -- within an instance (all entities in instances are ignored)
154 and then Sloc (E) > No_Location
155 and then Instantiation_Location (Sloc (E)) = No_Location
157 -- And must be a non-internal name from the main source unit
159 and then In_Extended_Main_Source_Unit (E)
160 and then not Is_Internal_Name (Chars (E))
162 Xrefs.Increment_Last;
164 Loc := Original_Location (Sloc (E));
166 Xrefs.Table (Indx).Ent := E;
167 Xrefs.Table (Indx).Typ := ' ';
168 Xrefs.Table (Indx).Def := No_Location;
169 Xrefs.Table (Indx).Loc := No_Location;
171 Xrefs.Table (Indx).Eun := Get_Source_Unit (Loc);
173 Xrefs.Table (Indx).Ref_Scope := Empty;
174 Xrefs.Table (Indx).Ent_Scope := Empty;
175 Xrefs.Table (Indx).Ent_Scope_File := No_Unit;
177 Set_Has_Xref_Entry (E);
179 if In_Inlined_Body then
183 end Generate_Definition;
185 ---------------------------------
186 -- Generate_Operator_Reference --
187 ---------------------------------
189 procedure Generate_Operator_Reference
194 if not In_Extended_Main_Source_Unit (N) then
198 -- If the operator is not a Standard operator, then we generate a real
199 -- reference to the user defined operator.
201 if Sloc (Entity (N)) /= Standard_Location then
202 Generate_Reference (Entity (N), N);
204 -- A reference to an implicit inequality operator is also a reference
205 -- to the user-defined equality.
207 if Nkind (N) = N_Op_Ne
208 and then not Comes_From_Source (Entity (N))
209 and then Present (Corresponding_Equality (Entity (N)))
211 Generate_Reference (Corresponding_Equality (Entity (N)), N);
214 -- For the case of Standard operators, we mark the result type as
215 -- referenced. This ensures that in the case where we are using a
216 -- derived operator, we mark an entity of the unit that implicitly
217 -- defines this operator as used. Otherwise we may think that no entity
218 -- of the unit is used. The actual entity marked as referenced is the
219 -- first subtype, which is the relevant user defined entity.
221 -- Note: we only do this for operators that come from source. The
222 -- generated code sometimes reaches for entities that do not need to be
223 -- explicitly visible (for example, when we expand the code for
224 -- comparing two record objects, the fields of the record may not be
227 elsif Comes_From_Source (N) then
228 Set_Referenced (First_Subtype (T));
230 end Generate_Operator_Reference;
232 ---------------------------------
233 -- Generate_Prim_Op_References --
234 ---------------------------------
236 procedure Generate_Prim_Op_References (Typ : Entity_Id) is
239 Prim_List : Elist_Id;
242 -- Handle subtypes of synchronized types
244 if Ekind (Typ) = E_Protected_Subtype
245 or else Ekind (Typ) = E_Task_Subtype
247 Base_T := Etype (Typ);
252 -- References to primitive operations are only relevant for tagged types
254 if not Is_Tagged_Type (Base_T)
255 or else Is_Class_Wide_Type (Base_T)
260 -- Ada 2005 (AI-345): For synchronized types generate reference to the
261 -- wrapper that allow us to dispatch calls through their implemented
262 -- abstract interface types.
264 -- The check for Present here is to protect against previously reported
267 Prim_List := Primitive_Operations (Base_T);
269 if No (Prim_List) then
273 Prim := First_Elmt (Prim_List);
274 while Present (Prim) loop
276 -- If the operation is derived, get the original for cross-reference
277 -- reference purposes (it is the original for which we want the xref
278 -- and for which the comes_from_source test must be performed).
281 (Typ, Ultimate_Alias (Node (Prim)), 'p', Set_Ref => False);
284 end Generate_Prim_Op_References;
286 ------------------------
287 -- Generate_Reference --
288 ------------------------
290 procedure Generate_Reference
293 Typ : Character := 'r';
294 Set_Ref : Boolean := True;
295 Force : Boolean := False)
303 Ref_Scope : Entity_Id;
304 Ent_Scope : Entity_Id;
308 -- Used for call to Find_Actual
311 -- If Formal is non-Empty, then its Ekind, otherwise E_Void
313 function Is_On_LHS (Node : Node_Id) return Boolean;
314 -- Used to check if a node is on the left hand side of an assignment.
315 -- The following cases are handled:
317 -- Variable Node is a direct descendant of left hand side of an
318 -- assignment statement.
320 -- Prefix Of an indexed or selected component that is present in
321 -- a subtree rooted by an assignment statement. There is
322 -- no restriction of nesting of components, thus cases
323 -- such as A.B (C).D are handled properly. However a prefix
324 -- of a dereference (either implicit or explicit) is never
325 -- considered as on a LHS.
327 -- Out param Same as above cases, but OUT parameter
329 function OK_To_Set_Referenced return Boolean;
330 -- Returns True if the Referenced flag can be set. There are a few
331 -- exceptions where we do not want to set this flag, see body for
332 -- details of these exceptional cases.
338 -- ??? There are several routines here and there that perform a similar
339 -- (but subtly different) computation, which should be factored:
341 -- Sem_Util.May_Be_Lvalue
342 -- Sem_Util.Known_To_Be_Assigned
343 -- Exp_Ch2.Expand_Entry_Parameter.In_Assignment_Context
344 -- Exp_Smem.Is_Out_Actual
346 function Is_On_LHS (Node : Node_Id) return Boolean is
352 -- Only identifiers are considered, is this necessary???
354 if Nkind (Node) /= N_Identifier then
358 -- Immediate return if appeared as OUT parameter
360 if Kind = E_Out_Parameter then
364 -- Search for assignment statement subtree root
371 if K = N_Assignment_Statement then
374 -- Check whether the parent is a component and the current node is
375 -- its prefix, but return False if the current node has an access
376 -- type, as in that case the selected or indexed component is an
377 -- implicit dereference, and the LHS is the designated object, not
378 -- the access object.
380 -- ??? case of a slice assignment?
382 -- ??? Note that in some cases this is called too early
383 -- (see comments in Sem_Ch8.Find_Direct_Name), at a point where
384 -- the tree is not fully typed yet. In that case we may lack
385 -- an Etype for N, and we must disable the check for an implicit
386 -- dereference. If the dereference is on an LHS, this causes a
389 elsif (K = N_Selected_Component or else K = N_Indexed_Component)
390 and then Prefix (P) = N
391 and then not (Present (Etype (N))
393 Is_Access_Type (Etype (N)))
397 -- All other cases, definitely not on left side
405 ---------------------------
406 -- OK_To_Set_Referenced --
407 ---------------------------
409 function OK_To_Set_Referenced return Boolean is
413 -- A reference from a pragma Unreferenced or pragma Unmodified or
414 -- pragma Warnings does not cause the Referenced flag to be set.
415 -- This avoids silly warnings about things being referenced and
416 -- not assigned when the only reference is from the pragma.
418 if Nkind (N) = N_Identifier then
421 if Nkind (P) = N_Pragma_Argument_Association then
424 if Nkind (P) = N_Pragma then
425 if Pragma_Name (P) = Name_Warnings
427 Pragma_Name (P) = Name_Unmodified
429 Pragma_Name (P) = Name_Unreferenced
438 end OK_To_Set_Referenced;
440 -- Start of processing for Generate_Reference
443 pragma Assert (Nkind (E) in N_Entity);
444 Find_Actual (N, Formal, Call);
446 if Present (Formal) then
447 Kind := Ekind (Formal);
452 -- Check for obsolescent reference to package ASCII. GNAT treats this
453 -- element of annex J specially since in practice, programs make a lot
454 -- of use of this feature, so we don't include it in the set of features
455 -- diagnosed when Warn_On_Obsolescent_Features mode is set. However we
456 -- are required to note it as a violation of the RM defined restriction.
458 if E = Standard_ASCII then
459 Check_Restriction (No_Obsolescent_Features, N);
462 -- Check for reference to entity marked with Is_Obsolescent
464 -- Note that we always allow obsolescent references in the compiler
465 -- itself and the run time, since we assume that we know what we are
466 -- doing in such cases. For example the calls in Ada.Characters.Handling
467 -- to its own obsolescent subprograms are just fine.
469 -- In any case we do not generate warnings within the extended source
470 -- unit of the entity in question, since we assume the source unit
471 -- itself knows what is going on (and for sure we do not want silly
472 -- warnings, e.g. on the end line of an obsolescent procedure body).
474 if Is_Obsolescent (E)
475 and then not GNAT_Mode
476 and then not In_Extended_Main_Source_Unit (E)
478 Check_Restriction (No_Obsolescent_Features, N);
480 if Warn_On_Obsolescent_Feature then
481 Output_Obsolescent_Entity_Warnings (N, E);
485 -- Warn if reference to Ada 2005 entity not in Ada 2005 mode. We only
486 -- detect real explicit references (modifications and references).
488 if Comes_From_Source (N)
489 and then Is_Ada_2005_Only (E)
490 and then Ada_Version < Ada_2005
491 and then Warn_On_Ada_2005_Compatibility
492 and then (Typ = 'm' or else Typ = 'r' or else Typ = 's')
494 Error_Msg_NE ("& is only defined in Ada 2005?", N, E);
497 -- Warn if reference to Ada 2012 entity not in Ada 2012 mode. We only
498 -- detect real explicit references (modifications and references).
500 if Comes_From_Source (N)
501 and then Is_Ada_2012_Only (E)
502 and then Ada_Version < Ada_2012
503 and then Warn_On_Ada_2012_Compatibility
504 and then (Typ = 'm' or else Typ = 'r')
506 Error_Msg_NE ("& is only defined in Ada 2012?", N, E);
509 -- Never collect references if not in main source unit. However, we omit
510 -- this test if Typ is 'e' or 'k', since these entries are structural,
511 -- and it is useful to have them in units that reference packages as
512 -- well as units that define packages. We also omit the test for the
513 -- case of 'p' since we want to include inherited primitive operations
514 -- from other packages.
516 -- We also omit this test is this is a body reference for a subprogram
517 -- instantiation. In this case the reference is to the generic body,
518 -- which clearly need not be in the main unit containing the instance.
519 -- For the same reason we accept an implicit reference generated for
520 -- a default in an instance.
522 if not In_Extended_Main_Source_Unit (N) then
528 or else (Typ = 'b' and then Is_Generic_Instance (E))
536 -- For reference type p, the entity must be in main source unit
538 if Typ = 'p' and then not In_Extended_Main_Source_Unit (E) then
542 -- Unless the reference is forced, we ignore references where the
543 -- reference itself does not come from source.
545 if not Force and then not Comes_From_Source (N) then
549 -- Deal with setting entity as referenced, unless suppressed. Note that
550 -- we still do Set_Referenced on entities that do not come from source.
551 -- This situation arises when we have a source reference to a derived
552 -- operation, where the derived operation itself does not come from
553 -- source, but we still want to mark it as referenced, since we really
554 -- are referencing an entity in the corresponding package (this avoids
555 -- wrong complaints that the package contains no referenced entities).
559 -- Assignable object appearing on left side of assignment or as
563 and then Is_On_LHS (N)
564 and then Ekind (E) /= E_In_Out_Parameter
566 -- For objects that are renamings, just set as simply referenced
567 -- we do not try to do assignment type tracking in this case.
569 if Present (Renamed_Object (E)) then
572 -- Out parameter case
574 elsif Kind = E_Out_Parameter then
576 -- If warning mode for all out parameters is set, or this is
577 -- the only warning parameter, then we want to mark this for
578 -- later warning logic by setting Referenced_As_Out_Parameter
580 if Warn_On_Modified_As_Out_Parameter (Formal) then
581 Set_Referenced_As_Out_Parameter (E, True);
582 Set_Referenced_As_LHS (E, False);
584 -- For OUT parameter not covered by the above cases, we simply
585 -- regard it as a normal reference (in this case we do not
586 -- want any of the warning machinery for out parameters).
592 -- For the left hand of an assignment case, we do nothing here.
593 -- The processing for Analyze_Assignment_Statement will set the
594 -- Referenced_As_LHS flag.
600 -- Check for a reference in a pragma that should not count as a
601 -- making the variable referenced for warning purposes.
603 elsif Is_Non_Significant_Pragma_Reference (N) then
606 -- A reference in an attribute definition clause does not count as a
607 -- reference except for the case of Address. The reason that 'Address
608 -- is an exception is that it creates an alias through which the
609 -- variable may be referenced.
611 elsif Nkind (Parent (N)) = N_Attribute_Definition_Clause
612 and then Chars (Parent (N)) /= Name_Address
613 and then N = Name (Parent (N))
617 -- Constant completion does not count as a reference
620 and then Ekind (E) = E_Constant
624 -- Record representation clause does not count as a reference
626 elsif Nkind (N) = N_Identifier
627 and then Nkind (Parent (N)) = N_Record_Representation_Clause
631 -- Discriminants do not need to produce a reference to record type
634 and then Nkind (Parent (N)) = N_Discriminant_Specification
641 -- Special processing for IN OUT parameters, where we have an
642 -- implicit assignment to a simple variable.
644 if Kind = E_In_Out_Parameter
645 and then Is_Assignable (E)
647 -- For sure this counts as a normal read reference
650 Set_Last_Assignment (E, Empty);
652 -- We count it as being referenced as an out parameter if the
653 -- option is set to warn on all out parameters, except that we
654 -- have a special exclusion for an intrinsic subprogram, which
655 -- is most likely an instantiation of Unchecked_Deallocation
656 -- which we do not want to consider as an assignment since it
657 -- generates false positives. We also exclude the case of an
658 -- IN OUT parameter if the name of the procedure is Free,
659 -- since we suspect similar semantics.
661 if Warn_On_All_Unread_Out_Parameters
662 and then Is_Entity_Name (Name (Call))
663 and then not Is_Intrinsic_Subprogram (Entity (Name (Call)))
664 and then Chars (Name (Call)) /= Name_Free
666 Set_Referenced_As_Out_Parameter (E, True);
667 Set_Referenced_As_LHS (E, False);
670 -- Don't count a recursive reference within a subprogram as a
671 -- reference (that allows detection of a recursive subprogram
672 -- whose only references are recursive calls as unreferenced).
674 elsif Is_Subprogram (E)
675 and then E = Nearest_Dynamic_Scope (Current_Scope)
679 -- Any other occurrence counts as referencing the entity
681 elsif OK_To_Set_Referenced then
684 -- If variable, this is an OK reference after an assignment
685 -- so we can clear the Last_Assignment indication.
687 if Is_Assignable (E) then
688 Set_Last_Assignment (E, Empty);
693 -- Check for pragma Unreferenced given and reference is within
694 -- this source unit (occasion for possible warning to be issued).
696 if Has_Unreferenced (E)
697 and then In_Same_Extended_Unit (E, N)
699 -- A reference as a named parameter in a call does not count
700 -- as a violation of pragma Unreferenced for this purpose...
702 if Nkind (N) = N_Identifier
703 and then Nkind (Parent (N)) = N_Parameter_Association
704 and then Selector_Name (Parent (N)) = N
708 -- ... Neither does a reference to a variable on the left side
711 elsif Is_On_LHS (N) then
714 -- For entry formals, we want to place the warning message on the
715 -- corresponding entity in the accept statement. The current scope
716 -- is the body of the accept, so we find the formal whose name
717 -- matches that of the entry formal (there is no link between the
718 -- two entities, and the one in the accept statement is only used
719 -- for conformance checking).
721 elsif Ekind (Scope (E)) = E_Entry then
726 BE := First_Entity (Current_Scope);
727 while Present (BE) loop
728 if Chars (BE) = Chars (E) then
729 Error_Msg_NE -- CODEFIX
730 ("?pragma Unreferenced given for&!", N, BE);
738 -- Here we issue the warning, since this is a real reference
741 Error_Msg_NE -- CODEFIX
742 ("?pragma Unreferenced given for&!", N, E);
746 -- If this is a subprogram instance, mark as well the internal
747 -- subprogram in the wrapper package, which may be a visible
750 if Is_Overloadable (E)
751 and then Is_Generic_Instance (E)
752 and then Present (Alias (E))
754 Set_Referenced (Alias (E));
758 -- Generate reference if all conditions are met:
761 -- Cross referencing must be active
765 -- The entity must be one for which we collect references
767 and then Xref_Entity_Letters (Ekind (E)) /= ' '
769 -- Both Sloc values must be set to something sensible
771 and then Sloc (E) > No_Location
772 and then Sloc (N) > No_Location
774 -- We ignore references from within an instance, except for default
775 -- subprograms, for which we generate an implicit reference.
778 (Instantiation_Location (Sloc (N)) = No_Location or else Typ = 'i')
780 -- Ignore dummy references
784 if Nkind (N) = N_Identifier
786 Nkind (N) = N_Defining_Identifier
790 Nkind (N) = N_Defining_Operator_Symbol
792 Nkind (N) = N_Operator_Symbol
794 (Nkind (N) = N_Character_Literal
795 and then Sloc (Entity (N)) /= Standard_Location)
797 Nkind (N) = N_Defining_Character_Literal
801 elsif Nkind (N) = N_Expanded_Name
803 Nkind (N) = N_Selected_Component
805 Nod := Selector_Name (N);
811 -- Normal case of source entity comes from source
813 if Comes_From_Source (E) then
816 -- Entity does not come from source, but is a derived subprogram and
817 -- the derived subprogram comes from source (after one or more
818 -- derivations) in which case the reference is to parent subprogram.
820 elsif Is_Overloadable (E)
821 and then Present (Alias (E))
824 while not Comes_From_Source (Ent) loop
825 if No (Alias (Ent)) then
832 -- The internally created defining entity for a child subprogram
833 -- that has no previous spec has valid references.
835 elsif Is_Overloadable (E)
836 and then Is_Child_Unit (E)
840 -- Record components of discriminated subtypes or derived types must
841 -- be treated as references to the original component.
843 elsif Ekind (E) = E_Component
844 and then Comes_From_Source (Original_Record_Component (E))
846 Ent := Original_Record_Component (E);
848 -- If this is an expanded reference to a discriminant, recover the
849 -- original discriminant, which gets the reference.
851 elsif Ekind (E) = E_In_Parameter
852 and then Present (Discriminal_Link (E))
854 Ent := Discriminal_Link (E);
855 Set_Referenced (Ent);
857 -- Ignore reference to any other entity that is not from source
863 -- Record reference to entity
865 Ref := Original_Location (Sloc (Nod));
866 Def := Original_Location (Sloc (Ent));
868 Ref_Scope := ALFA.Enclosing_Subprogram_Or_Package (N);
869 Ent_Scope := ALFA.Enclosing_Subprogram_Or_Package (Ent);
871 Xrefs.Increment_Last;
874 Xrefs.Table (Indx).Loc := Ref;
876 -- Overriding operations are marked with 'P'
879 and then Is_Subprogram (N)
880 and then Present (Overridden_Operation (N))
882 Xrefs.Table (Indx).Typ := 'P';
884 Xrefs.Table (Indx).Typ := Typ;
887 Xrefs.Table (Indx).Eun := Get_Source_Unit (Def);
888 Xrefs.Table (Indx).Lun := Get_Source_Unit (Ref);
889 Xrefs.Table (Indx).Ent := Ent;
891 Xrefs.Table (Indx).Ref_Scope := Ref_Scope;
892 Xrefs.Table (Indx).Ent_Scope := Ent_Scope;
893 Xrefs.Table (Indx).Ent_Scope_File := Get_Source_Unit (Ent_Scope);
895 Set_Has_Xref_Entry (Ent);
897 end Generate_Reference;
899 -----------------------------------
900 -- Generate_Reference_To_Formals --
901 -----------------------------------
903 procedure Generate_Reference_To_Formals (E : Entity_Id) is
907 if Is_Generic_Subprogram (E) then
908 Formal := First_Entity (E);
910 while Present (Formal)
911 and then not Is_Formal (Formal)
913 Next_Entity (Formal);
917 Formal := First_Formal (E);
920 while Present (Formal) loop
921 if Ekind (Formal) = E_In_Parameter then
923 if Nkind (Parameter_Type (Parent (Formal)))
924 = N_Access_Definition
926 Generate_Reference (E, Formal, '^', False);
928 Generate_Reference (E, Formal, '>', False);
931 elsif Ekind (Formal) = E_In_Out_Parameter then
932 Generate_Reference (E, Formal, '=', False);
935 Generate_Reference (E, Formal, '<', False);
938 Next_Formal (Formal);
940 end Generate_Reference_To_Formals;
942 -------------------------------------------
943 -- Generate_Reference_To_Generic_Formals --
944 -------------------------------------------
946 procedure Generate_Reference_To_Generic_Formals (E : Entity_Id) is
950 Formal := First_Entity (E);
951 while Present (Formal) loop
952 if Comes_From_Source (Formal) then
953 Generate_Reference (E, Formal, 'z', False);
956 Next_Entity (Formal);
958 end Generate_Reference_To_Generic_Formals;
964 procedure Initialize is
973 function Lt (T1, T2 : Xref_Entry) return Boolean is
975 -- First test: if entity is in different unit, sort by unit
977 if T1.Eun /= T2.Eun then
978 return Dependency_Num (T1.Eun) < Dependency_Num (T2.Eun);
980 -- Second test: within same unit, sort by entity Sloc
982 elsif T1.Def /= T2.Def then
983 return T1.Def < T2.Def;
985 -- Third test: sort definitions ahead of references
987 elsif T1.Loc = No_Location then
990 elsif T2.Loc = No_Location then
993 -- Fourth test: for same entity, sort by reference location unit
995 elsif T1.Lun /= T2.Lun then
996 return Dependency_Num (T1.Lun) < Dependency_Num (T2.Lun);
998 -- Fifth test: order of location within referencing unit
1000 elsif T1.Loc /= T2.Loc then
1001 return T1.Loc < T2.Loc;
1003 -- Finally, for two locations at the same address, we prefer
1004 -- the one that does NOT have the type 'r' so that a modification
1005 -- or extension takes preference, when there are more than one
1006 -- reference at the same location. As a result, in the case of
1007 -- entities that are in-out actuals, the read reference follows
1008 -- the modify reference.
1011 return T2.Typ = 'r';
1015 -----------------------
1016 -- Output_References --
1017 -----------------------
1019 procedure Output_References is
1021 procedure Get_Type_Reference
1023 Tref : out Entity_Id;
1024 Left : out Character;
1025 Right : out Character);
1026 -- Given an Entity_Id Ent, determines whether a type reference is
1027 -- required. If so, Tref is set to the entity for the type reference
1028 -- and Left and Right are set to the left/right brackets to be output
1029 -- for the reference. If no type reference is required, then Tref is
1030 -- set to Empty, and Left/Right are set to space.
1032 procedure Output_Import_Export_Info (Ent : Entity_Id);
1033 -- Output language and external name information for an interfaced
1034 -- entity, using the format <language, external_name>,
1036 ------------------------
1037 -- Get_Type_Reference --
1038 ------------------------
1040 procedure Get_Type_Reference
1042 Tref : out Entity_Id;
1043 Left : out Character;
1044 Right : out Character)
1049 -- See if we have a type reference
1058 -- Processing for types
1060 if Is_Type (Tref) then
1062 -- Case of base type
1064 if Base_Type (Tref) = Tref then
1066 -- If derived, then get first subtype
1068 if Tref /= Etype (Tref) then
1069 Tref := First_Subtype (Etype (Tref));
1071 -- Set brackets for derived type, but don't override
1072 -- pointer case since the fact that something is a
1073 -- pointer is more important.
1080 -- If non-derived ptr, get directly designated type.
1081 -- If the type has a full view, all references are on the
1082 -- partial view, that is seen first.
1084 elsif Is_Access_Type (Tref) then
1085 Tref := Directly_Designated_Type (Tref);
1089 elsif Is_Private_Type (Tref)
1090 and then Present (Full_View (Tref))
1092 if Is_Access_Type (Full_View (Tref)) then
1093 Tref := Directly_Designated_Type (Full_View (Tref));
1097 -- If the full view is an array type, we also retrieve
1098 -- the corresponding component type, because the ali
1099 -- entry already indicates that this is an array.
1101 elsif Is_Array_Type (Full_View (Tref)) then
1102 Tref := Component_Type (Full_View (Tref));
1107 -- If non-derived array, get component type. Skip component
1108 -- type for case of String or Wide_String, saves worthwhile
1111 elsif Is_Array_Type (Tref)
1112 and then Tref /= Standard_String
1113 and then Tref /= Standard_Wide_String
1115 Tref := Component_Type (Tref);
1119 -- For other non-derived base types, nothing
1125 -- For a subtype, go to ancestor subtype
1128 Tref := Ancestor_Subtype (Tref);
1130 -- If no ancestor subtype, go to base type
1133 Tref := Base_Type (Sav);
1137 -- For objects, functions, enum literals, just get type from
1140 elsif Is_Object (Tref)
1141 or else Ekind (Tref) = E_Enumeration_Literal
1142 or else Ekind (Tref) = E_Function
1143 or else Ekind (Tref) = E_Operator
1145 Tref := Etype (Tref);
1147 -- For anything else, exit
1153 -- Exit if no type reference, or we are stuck in some loop trying
1154 -- to find the type reference, or if the type is standard void
1155 -- type (the latter is an implementation artifact that should not
1156 -- show up in the generated cross-references).
1160 or else Tref = Standard_Void_Type;
1162 -- If we have a usable type reference, return, otherwise keep
1163 -- looking for something useful (we are looking for something
1164 -- that either comes from source or standard)
1166 if Sloc (Tref) = Standard_Location
1167 or else Comes_From_Source (Tref)
1169 -- If the reference is a subtype created for a generic actual,
1170 -- go actual directly, the inner subtype is not user visible.
1172 if Nkind (Parent (Tref)) = N_Subtype_Declaration
1173 and then not Comes_From_Source (Parent (Tref))
1175 (Is_Wrapper_Package (Scope (Tref))
1176 or else Is_Generic_Instance (Scope (Tref)))
1178 Tref := First_Subtype (Base_Type (Tref));
1185 -- If we fall through the loop, no type reference
1190 end Get_Type_Reference;
1192 -------------------------------
1193 -- Output_Import_Export_Info --
1194 -------------------------------
1196 procedure Output_Import_Export_Info (Ent : Entity_Id) is
1197 Language_Name : Name_Id;
1198 Conv : constant Convention_Id := Convention (Ent);
1201 -- Generate language name from convention
1203 if Conv = Convention_C then
1204 Language_Name := Name_C;
1206 elsif Conv = Convention_CPP then
1207 Language_Name := Name_CPP;
1209 elsif Conv = Convention_Ada then
1210 Language_Name := Name_Ada;
1213 -- For the moment we ignore all other cases ???
1218 Write_Info_Char ('<');
1219 Get_Unqualified_Name_String (Language_Name);
1221 for J in 1 .. Name_Len loop
1222 Write_Info_Char (Name_Buffer (J));
1225 if Present (Interface_Name (Ent)) then
1226 Write_Info_Char (',');
1227 String_To_Name_Buffer (Strval (Interface_Name (Ent)));
1229 for J in 1 .. Name_Len loop
1230 Write_Info_Char (Name_Buffer (J));
1234 Write_Info_Char ('>');
1235 end Output_Import_Export_Info;
1237 -- Start of processing for Output_References
1240 -- First we add references to the primitive operations of tagged types
1241 -- declared in the main unit.
1243 Handle_Prim_Ops : declare
1247 for J in 1 .. Xrefs.Last loop
1248 Ent := Xrefs.Table (J).Ent;
1251 and then Is_Tagged_Type (Ent)
1252 and then Is_Base_Type (Ent)
1253 and then In_Extended_Main_Source_Unit (Ent)
1255 Generate_Prim_Op_References (Ent);
1258 end Handle_Prim_Ops;
1260 -- Before we go ahead and output the references we have a problem
1261 -- that needs dealing with. So far we have captured things that are
1262 -- definitely referenced by the main unit, or defined in the main
1263 -- unit. That's because we don't want to clutter up the ali file
1264 -- for this unit with definition lines for entities in other units
1265 -- that are not referenced.
1267 -- But there is a glitch. We may reference an entity in another unit,
1268 -- and it may have a type reference to an entity that is not directly
1269 -- referenced in the main unit, which may mean that there is no xref
1270 -- entry for this entity yet in the list of references.
1272 -- If we don't do something about this, we will end with an orphan type
1273 -- reference, i.e. it will point to an entity that does not appear
1274 -- within the generated references in the ali file. That is not good for
1275 -- tools using the xref information.
1277 -- To fix this, we go through the references adding definition entries
1278 -- for any unreferenced entities that can be referenced in a type
1279 -- reference. There is a recursion problem here, and that is dealt with
1280 -- by making sure that this traversal also traverses any entries that
1281 -- get added by the traversal.
1283 Handle_Orphan_Type_References : declare
1291 pragma Warnings (Off, L);
1292 pragma Warnings (Off, R);
1294 procedure New_Entry (E : Entity_Id);
1295 -- Make an additional entry into the Xref table for a type entity
1296 -- that is related to the current entity (parent, type ancestor,
1297 -- progenitor, etc.).
1303 procedure New_Entry (E : Entity_Id) is
1306 and then not Has_Xref_Entry (E)
1307 and then Sloc (E) > No_Location
1309 Xrefs.Increment_Last;
1311 Loc := Original_Location (Sloc (E));
1312 Xrefs.Table (Indx).Ent := E;
1313 Xrefs.Table (Indx).Loc := No_Location;
1314 Xrefs.Table (Indx).Eun := Get_Source_Unit (Loc);
1315 Xrefs.Table (Indx).Lun := No_Unit;
1316 Set_Has_Xref_Entry (E);
1320 -- Start of processing for Handle_Orphan_Type_References
1323 -- Note that this is not a for loop for a very good reason. The
1324 -- processing of items in the table can add new items to the table,
1325 -- and they must be processed as well.
1328 while J <= Xrefs.Last loop
1329 Ent := Xrefs.Table (J).Ent;
1330 Get_Type_Reference (Ent, Tref, L, R);
1333 and then not Has_Xref_Entry (Tref)
1334 and then Sloc (Tref) > No_Location
1338 if Is_Record_Type (Ent)
1339 and then Present (Interfaces (Ent))
1341 -- Add an entry for each one of the given interfaces
1342 -- implemented by type Ent.
1345 Elmt : Elmt_Id := First_Elmt (Interfaces (Ent));
1347 while Present (Elmt) loop
1348 New_Entry (Node (Elmt));
1355 -- Collect inherited primitive operations that may be declared in
1356 -- another unit and have no visible reference in the current one.
1359 and then Is_Tagged_Type (Ent)
1360 and then Is_Derived_Type (Ent)
1361 and then Is_Base_Type (Ent)
1362 and then In_Extended_Main_Source_Unit (Ent)
1365 Op_List : constant Elist_Id := Primitive_Operations (Ent);
1369 function Parent_Op (E : Entity_Id) return Entity_Id;
1370 -- Find original operation, which may be inherited through
1371 -- several derivations.
1373 function Parent_Op (E : Entity_Id) return Entity_Id is
1374 Orig_Op : constant Entity_Id := Alias (E);
1377 if No (Orig_Op) then
1380 elsif not Comes_From_Source (E)
1381 and then not Has_Xref_Entry (Orig_Op)
1382 and then Comes_From_Source (Orig_Op)
1386 return Parent_Op (Orig_Op);
1391 Op := First_Elmt (Op_List);
1392 while Present (Op) loop
1393 Prim := Parent_Op (Node (Op));
1395 if Present (Prim) then
1396 Xrefs.Increment_Last;
1398 Loc := Original_Location (Sloc (Prim));
1399 Xrefs.Table (Indx).Ent := Prim;
1400 Xrefs.Table (Indx).Loc := No_Location;
1401 Xrefs.Table (Indx).Eun :=
1402 Get_Source_Unit (Sloc (Prim));
1403 Xrefs.Table (Indx).Lun := No_Unit;
1404 Set_Has_Xref_Entry (Prim);
1414 end Handle_Orphan_Type_References;
1416 -- Now we have all the references, including those for any embedded
1417 -- type references, so we can sort them, and output them.
1419 Output_Refs : declare
1421 Nrefs : Nat := Xrefs.Last;
1422 -- Number of references in table. This value may get reset (reduced)
1423 -- when we eliminate duplicate reference entries.
1425 Rnums : array (0 .. Nrefs) of Nat;
1426 -- This array contains numbers of references in the Xrefs table.
1427 -- This list is sorted in output order. The extra 0'th entry is
1428 -- convenient for the call to sort. When we sort the table, we
1429 -- move the entries in Rnums around, but we do not move the
1430 -- original table entries.
1432 Curxu : Unit_Number_Type;
1433 -- Current xref unit
1435 Curru : Unit_Number_Type;
1436 -- Current reference unit for one entity
1441 Curnam : String (1 .. Name_Buffer'Length);
1443 -- Simple name and length of current entity
1445 Curdef : Source_Ptr;
1446 -- Original source location for current entity
1449 -- Current reference location
1452 -- Entity type character
1455 -- reference kind of previous reference
1461 -- Renaming reference
1463 Trunit : Unit_Number_Type;
1464 -- Unit number for type reference
1466 function Lt (Op1, Op2 : Natural) return Boolean;
1467 -- Comparison function for Sort call
1469 function Name_Change (X : Entity_Id) return Boolean;
1470 -- Determines if entity X has a different simple name from Curent
1472 procedure Move (From : Natural; To : Natural);
1473 -- Move procedure for Sort call
1475 package Sorting is new GNAT.Heap_Sort_G (Move, Lt);
1481 function Lt (Op1, Op2 : Natural) return Boolean is
1482 T1 : Xref_Entry renames Xrefs.Table (Rnums (Nat (Op1)));
1483 T2 : Xref_Entry renames Xrefs.Table (Rnums (Nat (Op2)));
1493 procedure Move (From : Natural; To : Natural) is
1495 Rnums (Nat (To)) := Rnums (Nat (From));
1502 -- Why a string comparison here??? Why not compare Name_Id values???
1504 function Name_Change (X : Entity_Id) return Boolean is
1506 Get_Unqualified_Name_String (Chars (X));
1508 if Name_Len /= Curlen then
1511 return Name_Buffer (1 .. Curlen) /= Curnam (1 .. Curlen);
1515 -- Start of processing for Output_Refs
1518 -- Capture the definition Sloc values. We delay doing this till now,
1519 -- since at the time the reference or definition is made, private
1520 -- types may be swapped, and the Sloc value may be incorrect. We
1521 -- also set up the pointer vector for the sort.
1523 for J in 1 .. Nrefs loop
1525 Xrefs.Table (J).Def :=
1526 Original_Location (Sloc (Xrefs.Table (J).Ent));
1529 -- Sort the references
1531 Sorting.Sort (Integer (Nrefs));
1533 -- Eliminate duplicate entries
1536 NR : constant Nat := Nrefs;
1539 -- We need this test for NR because if we force ALI file
1540 -- generation in case of errors detected, it may be the case
1541 -- that Nrefs is 0, so we should not reset it here
1546 for J in 2 .. NR loop
1547 if Xrefs.Table (Rnums (J)) /=
1548 Xrefs.Table (Rnums (Nrefs))
1551 Rnums (Nrefs) := Rnums (J);
1557 -- Initialize loop through references
1561 Curdef := No_Location;
1563 Crloc := No_Location;
1566 -- Loop to output references
1568 for Refno in 1 .. Nrefs loop
1569 Output_One_Ref : declare
1572 XE : Xref_Entry renames Xrefs.Table (Rnums (Refno));
1573 -- The current entry to be accessed
1577 -- Used for {} or <> or () for type reference
1579 procedure Check_Type_Reference
1581 List_Interface : Boolean);
1582 -- Find whether there is a meaningful type reference for
1583 -- Ent, and display it accordingly. If List_Interface is
1584 -- true, then Ent is a progenitor interface of the current
1585 -- type entity being listed. In that case list it as is,
1586 -- without looking for a type reference for it.
1588 procedure Output_Instantiation_Refs (Loc : Source_Ptr);
1589 -- Recursive procedure to output instantiation references for
1590 -- the given source ptr in [file|line[...]] form. No output
1591 -- if the given location is not a generic template reference.
1593 procedure Output_Overridden_Op (Old_E : Entity_Id);
1594 -- For a subprogram that is overriding, display information
1595 -- about the inherited operation that it overrides.
1597 --------------------------
1598 -- Check_Type_Reference --
1599 --------------------------
1601 procedure Check_Type_Reference
1603 List_Interface : Boolean)
1606 if List_Interface then
1608 -- This is a progenitor interface of the type for which
1609 -- xref information is being generated.
1616 Get_Type_Reference (Ent, Tref, Left, Right);
1619 if Present (Tref) then
1621 -- Case of standard entity, output name
1623 if Sloc (Tref) = Standard_Location then
1624 Write_Info_Char (Left);
1625 Write_Info_Name (Chars (Tref));
1626 Write_Info_Char (Right);
1628 -- Case of source entity, output location
1631 Write_Info_Char (Left);
1632 Trunit := Get_Source_Unit (Sloc (Tref));
1634 if Trunit /= Curxu then
1635 Write_Info_Nat (Dependency_Num (Trunit));
1636 Write_Info_Char ('|');
1640 (Int (Get_Logical_Line_Number (Sloc (Tref))));
1648 Ctyp := Xref_Entity_Letters (Ekind (Ent));
1651 and then Present (Full_View (Ent))
1653 Ent := Underlying_Type (Ent);
1655 if Present (Ent) then
1656 Ctyp := Xref_Entity_Letters (Ekind (Ent));
1660 Write_Info_Char (Ctyp);
1664 (Int (Get_Column_Number (Sloc (Tref))));
1666 -- If the type comes from an instantiation, add the
1667 -- corresponding info.
1669 Output_Instantiation_Refs (Sloc (Tref));
1670 Write_Info_Char (Right);
1673 end Check_Type_Reference;
1675 -------------------------------
1676 -- Output_Instantiation_Refs --
1677 -------------------------------
1679 procedure Output_Instantiation_Refs (Loc : Source_Ptr) is
1680 Iloc : constant Source_Ptr := Instantiation_Location (Loc);
1681 Lun : Unit_Number_Type;
1682 Cu : constant Unit_Number_Type := Curru;
1685 -- Nothing to do if this is not an instantiation
1687 if Iloc = No_Location then
1691 -- Output instantiation reference
1693 Write_Info_Char ('[');
1694 Lun := Get_Source_Unit (Iloc);
1696 if Lun /= Curru then
1698 Write_Info_Nat (Dependency_Num (Curru));
1699 Write_Info_Char ('|');
1702 Write_Info_Nat (Int (Get_Logical_Line_Number (Iloc)));
1704 -- Recursive call to get nested instantiations
1706 Output_Instantiation_Refs (Iloc);
1708 -- Output final ] after call to get proper nesting
1710 Write_Info_Char (']');
1713 end Output_Instantiation_Refs;
1715 --------------------------
1716 -- Output_Overridden_Op --
1717 --------------------------
1719 procedure Output_Overridden_Op (Old_E : Entity_Id) is
1723 -- The overridden operation has an implicit declaration
1724 -- at the point of derivation. What we want to display
1725 -- is the original operation, which has the actual body
1726 -- (or abstract declaration) that is being overridden.
1727 -- The overridden operation is not always set, e.g. when
1728 -- it is a predefined operator.
1733 -- Follow alias chain if one is present
1735 elsif Present (Alias (Old_E)) then
1737 -- The subprogram may have been implicitly inherited
1738 -- through several levels of derivation, so find the
1739 -- ultimate (source) ancestor.
1741 Op := Ultimate_Alias (Old_E);
1743 -- Normal case of no alias present
1750 and then Sloc (Op) /= Standard_Location
1753 Loc : constant Source_Ptr := Sloc (Op);
1754 Par_Unit : constant Unit_Number_Type :=
1755 Get_Source_Unit (Loc);
1758 Write_Info_Char ('<');
1760 if Par_Unit /= Curxu then
1761 Write_Info_Nat (Dependency_Num (Par_Unit));
1762 Write_Info_Char ('|');
1765 Write_Info_Nat (Int (Get_Logical_Line_Number (Loc)));
1766 Write_Info_Char ('p');
1767 Write_Info_Nat (Int (Get_Column_Number (Loc)));
1768 Write_Info_Char ('>');
1771 end Output_Overridden_Op;
1773 -- Start of processing for Output_One_Ref
1777 Ctyp := Xref_Entity_Letters (Ekind (Ent));
1779 -- Skip reference if it is the only reference to an entity,
1780 -- and it is an END line reference, and the entity is not in
1781 -- the current extended source. This prevents junk entries
1782 -- consisting only of packages with END lines, where no
1783 -- entity from the package is actually referenced.
1786 and then Ent /= Curent
1787 and then (Refno = Nrefs or else
1788 Ent /= Xrefs.Table (Rnums (Refno + 1)).Ent)
1790 not In_Extended_Main_Source_Unit (Ent)
1795 -- For private type, get full view type
1798 and then Present (Full_View (XE.Ent))
1800 Ent := Underlying_Type (Ent);
1802 if Present (Ent) then
1803 Ctyp := Xref_Entity_Letters (Ekind (Ent));
1807 -- Special exception for Boolean
1809 if Ctyp = 'E' and then Is_Boolean_Type (Ent) then
1813 -- For variable reference, get corresponding type
1816 Ent := Etype (XE.Ent);
1817 Ctyp := Fold_Lower (Xref_Entity_Letters (Ekind (Ent)));
1819 -- If variable is private type, get full view type
1822 and then Present (Full_View (Etype (XE.Ent)))
1824 Ent := Underlying_Type (Etype (XE.Ent));
1826 if Present (Ent) then
1827 Ctyp := Fold_Lower (Xref_Entity_Letters (Ekind (Ent)));
1830 elsif Is_Generic_Type (Ent) then
1832 -- If the type of the entity is a generic private type,
1833 -- there is no usable full view, so retain the indication
1834 -- that this is an object.
1839 -- Special handling for access parameters and objects of
1840 -- an anonymous access type.
1842 if Ekind_In (Etype (XE.Ent),
1843 E_Anonymous_Access_Type,
1844 E_Anonymous_Access_Subprogram_Type,
1845 E_Anonymous_Access_Protected_Subprogram_Type)
1847 if Is_Formal (XE.Ent)
1848 or else Ekind_In (XE.Ent, E_Variable, E_Constant)
1853 -- Special handling for Boolean
1855 elsif Ctyp = 'e' and then Is_Boolean_Type (Ent) then
1860 -- Special handling for abstract types and operations
1862 if Is_Overloadable (XE.Ent)
1863 and then Is_Abstract_Subprogram (XE.Ent)
1866 Ctyp := 'x'; -- Abstract procedure
1868 elsif Ctyp = 'V' then
1869 Ctyp := 'y'; -- Abstract function
1872 elsif Is_Type (XE.Ent)
1873 and then Is_Abstract_Type (XE.Ent)
1875 if Is_Interface (XE.Ent) then
1878 elsif Ctyp = 'R' then
1879 Ctyp := 'H'; -- Abstract type
1883 -- Only output reference if interesting type of entity
1887 -- Suppress references to object definitions, used for local
1890 or else XE.Typ = 'D'
1891 or else XE.Typ = 'I'
1893 -- Suppress self references, except for bodies that act as
1896 or else (XE.Loc = XE.Def
1899 or else not Is_Subprogram (XE.Ent)))
1901 -- Also suppress definitions of body formals (we only
1902 -- treat these as references, and the references were
1903 -- separately recorded).
1905 or else (Is_Formal (XE.Ent)
1906 and then Present (Spec_Entity (XE.Ent)))
1911 -- Start new Xref section if new xref unit
1913 if XE.Eun /= Curxu then
1914 if Write_Info_Col > 1 then
1920 Write_Info_Initiate ('X');
1921 Write_Info_Char (' ');
1922 Write_Info_Nat (Dependency_Num (XE.Eun));
1923 Write_Info_Char (' ');
1924 Write_Info_Name (Reference_Name (Source_Index (XE.Eun)));
1927 -- Start new Entity line if new entity. Note that we
1928 -- consider two entities the same if they have the same
1929 -- name and source location. This causes entities in
1930 -- instantiations to be treated as though they referred
1937 (Name_Change (XE.Ent) or else XE.Def /= Curdef))
1942 Get_Unqualified_Name_String (Chars (XE.Ent));
1944 Curnam (1 .. Curlen) := Name_Buffer (1 .. Curlen);
1946 if Write_Info_Col > 1 then
1950 -- Write column number information
1952 Write_Info_Nat (Int (Get_Logical_Line_Number (XE.Def)));
1953 Write_Info_Char (Ctyp);
1954 Write_Info_Nat (Int (Get_Column_Number (XE.Def)));
1956 -- Write level information
1958 Write_Level_Info : declare
1959 function Is_Visible_Generic_Entity
1960 (E : Entity_Id) return Boolean;
1961 -- Check whether E is declared in the visible part
1962 -- of a generic package. For source navigation
1963 -- purposes, treat this as a visible entity.
1965 function Is_Private_Record_Component
1966 (E : Entity_Id) return Boolean;
1967 -- Check whether E is a non-inherited component of a
1968 -- private extension. Even if the enclosing record is
1969 -- public, we want to treat the component as private
1970 -- for navigation purposes.
1972 ---------------------------------
1973 -- Is_Private_Record_Component --
1974 ---------------------------------
1976 function Is_Private_Record_Component
1977 (E : Entity_Id) return Boolean
1979 S : constant Entity_Id := Scope (E);
1982 Ekind (E) = E_Component
1983 and then Nkind (Declaration_Node (S)) =
1984 N_Private_Extension_Declaration
1985 and then Original_Record_Component (E) = E;
1986 end Is_Private_Record_Component;
1988 -------------------------------
1989 -- Is_Visible_Generic_Entity --
1990 -------------------------------
1992 function Is_Visible_Generic_Entity
1993 (E : Entity_Id) return Boolean
1998 -- The Present check here is an error defense
2000 if Present (Scope (E))
2001 and then Ekind (Scope (E)) /= E_Generic_Package
2007 while Present (Par) loop
2009 Nkind (Par) = N_Generic_Package_Declaration
2011 -- Entity is a generic formal
2016 Nkind (Parent (Par)) = N_Package_Specification
2019 Is_List_Member (Par)
2020 and then List_Containing (Par) =
2021 Visible_Declarations (Parent (Par));
2023 Par := Parent (Par);
2028 end Is_Visible_Generic_Entity;
2030 -- Start of processing for Write_Level_Info
2033 if Is_Hidden (Curent)
2034 or else Is_Private_Record_Component (Curent)
2036 Write_Info_Char (' ');
2040 or else Is_Visible_Generic_Entity (Curent)
2042 Write_Info_Char ('*');
2045 Write_Info_Char (' ');
2047 end Write_Level_Info;
2049 -- Output entity name. We use the occurrence from the
2050 -- actual source program at the definition point.
2053 Ent_Name : constant String :=
2054 Exact_Source_Name (Sloc (XE.Ent));
2056 for C in Ent_Name'Range loop
2057 Write_Info_Char (Ent_Name (C));
2061 -- See if we have a renaming reference
2063 if Is_Object (XE.Ent)
2064 and then Present (Renamed_Object (XE.Ent))
2066 Rref := Renamed_Object (XE.Ent);
2068 elsif Is_Overloadable (XE.Ent)
2069 and then Nkind (Parent (Declaration_Node (XE.Ent))) =
2070 N_Subprogram_Renaming_Declaration
2072 Rref := Name (Parent (Declaration_Node (XE.Ent)));
2074 elsif Ekind (XE.Ent) = E_Package
2075 and then Nkind (Declaration_Node (XE.Ent)) =
2076 N_Package_Renaming_Declaration
2078 Rref := Name (Declaration_Node (XE.Ent));
2084 if Present (Rref) then
2085 if Nkind (Rref) = N_Expanded_Name then
2086 Rref := Selector_Name (Rref);
2089 if Nkind (Rref) = N_Identifier
2090 or else Nkind (Rref) = N_Operator_Symbol
2094 -- For renamed array components, use the array name
2095 -- for the renamed entity, which reflect the fact that
2096 -- in general the whole array is aliased.
2098 elsif Nkind (Rref) = N_Indexed_Component then
2099 if Nkind (Prefix (Rref)) = N_Identifier then
2100 Rref := Prefix (Rref);
2101 elsif Nkind (Prefix (Rref)) = N_Expanded_Name then
2102 Rref := Selector_Name (Prefix (Rref));
2112 -- Write out renaming reference if we have one
2114 if Present (Rref) then
2115 Write_Info_Char ('=');
2117 (Int (Get_Logical_Line_Number (Sloc (Rref))));
2118 Write_Info_Char (':');
2120 (Int (Get_Column_Number (Sloc (Rref))));
2123 -- Indicate that the entity is in the unit of the current
2128 -- Write out information about generic parent, if entity
2131 if Is_Generic_Instance (XE.Ent) then
2133 Gen_Par : constant Entity_Id :=
2136 (Unit_Declaration_Node (XE.Ent)));
2137 Loc : constant Source_Ptr := Sloc (Gen_Par);
2138 Gen_U : constant Unit_Number_Type :=
2139 Get_Source_Unit (Loc);
2142 Write_Info_Char ('[');
2144 if Curru /= Gen_U then
2145 Write_Info_Nat (Dependency_Num (Gen_U));
2146 Write_Info_Char ('|');
2150 (Int (Get_Logical_Line_Number (Loc)));
2151 Write_Info_Char (']');
2155 -- See if we have a type reference and if so output
2157 Check_Type_Reference (XE.Ent, False);
2159 -- Additional information for types with progenitors
2161 if Is_Record_Type (XE.Ent)
2162 and then Present (Interfaces (XE.Ent))
2165 Elmt : Elmt_Id := First_Elmt (Interfaces (XE.Ent));
2167 while Present (Elmt) loop
2168 Check_Type_Reference (Node (Elmt), True);
2173 -- For array types, list index types as well. (This is
2174 -- not C, indexes have distinct types).
2176 elsif Is_Array_Type (XE.Ent) then
2180 Indx := First_Index (XE.Ent);
2181 while Present (Indx) loop
2182 Check_Type_Reference
2183 (First_Subtype (Etype (Indx)), True);
2189 -- If the entity is an overriding operation, write info
2190 -- on operation that was overridden.
2192 if Is_Subprogram (XE.Ent)
2193 and then Present (Overridden_Operation (XE.Ent))
2195 Output_Overridden_Op (Overridden_Operation (XE.Ent));
2198 -- End of processing for entity output
2200 Crloc := No_Location;
2203 -- Output the reference if it is not as the same location
2204 -- as the previous one, or it is a read-reference that
2205 -- indicates that the entity is an in-out actual in a call.
2207 if XE.Loc /= No_Location
2210 or else (Prevt = 'm' and then XE.Typ = 'r'))
2215 -- Start continuation if line full, else blank
2217 if Write_Info_Col > 72 then
2219 Write_Info_Initiate ('.');
2222 Write_Info_Char (' ');
2224 -- Output file number if changed
2226 if XE.Lun /= Curru then
2228 Write_Info_Nat (Dependency_Num (Curru));
2229 Write_Info_Char ('|');
2232 Write_Info_Nat (Int (Get_Logical_Line_Number (XE.Loc)));
2233 Write_Info_Char (XE.Typ);
2235 if Is_Overloadable (XE.Ent)
2236 and then Is_Imported (XE.Ent)
2237 and then XE.Typ = 'b'
2239 Output_Import_Export_Info (XE.Ent);
2242 Write_Info_Nat (Int (Get_Column_Number (XE.Loc)));
2244 Output_Instantiation_Refs (Sloc (XE.Ent));
2255 end Output_References;