1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1998-2008, 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_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
;
45 with Widechar
; use Widechar
;
47 with GNAT
.Heap_Sort_G
;
49 package body Lib
.Xref
is
55 -- The Xref table is used to record references. The Loc field is set
56 -- to No_Location for a definition entry.
58 subtype Xref_Entry_Number
is Int
;
60 type Xref_Entry
is record
62 -- Entity referenced (E parameter to Generate_Reference)
65 -- Original source location for entity being referenced. Note that these
66 -- values are used only during the output process, they are not set when
67 -- the entries are originally built. This is because private entities
68 -- can be swapped when the initial call is made.
71 -- Location of reference (Original_Location (Sloc field of N parameter
72 -- to Generate_Reference). Set to No_Location for the case of a
73 -- defining occurrence.
76 -- Reference type (Typ param to Generate_Reference)
78 Eun
: Unit_Number_Type
;
79 -- Unit number corresponding to Ent
81 Lun
: Unit_Number_Type
;
82 -- Unit number corresponding to Loc. Value is undefined and not
83 -- referenced if Loc is set to No_Location.
87 package Xrefs
is new Table
.Table
(
88 Table_Component_Type
=> Xref_Entry
,
89 Table_Index_Type
=> Xref_Entry_Number
,
91 Table_Initial
=> Alloc
.Xrefs_Initial
,
92 Table_Increment
=> Alloc
.Xrefs_Increment
,
93 Table_Name
=> "Xrefs");
95 -------------------------
96 -- Generate_Definition --
97 -------------------------
99 procedure Generate_Definition
(E
: Entity_Id
) is
104 pragma Assert
(Nkind
(E
) in N_Entity
);
106 -- Note that we do not test Xref_Entity_Letters here. It is too early
107 -- to do so, since we are often called before the entity is fully
108 -- constructed, so that the Ekind is still E_Void.
112 -- Definition must come from source
114 -- We make an exception for subprogram child units that have no spec.
115 -- For these we generate a subprogram declaration for library use,
116 -- and the corresponding entity does not come from source.
117 -- Nevertheless, all references will be attached to it and we have
118 -- to treat is as coming from user code.
120 and then (Comes_From_Source
(E
) or else Is_Child_Unit
(E
))
122 -- And must have a reasonable source location that is not
123 -- within an instance (all entities in instances are ignored)
125 and then Sloc
(E
) > No_Location
126 and then Instantiation_Location
(Sloc
(E
)) = No_Location
128 -- And must be a non-internal name from the main source unit
130 and then In_Extended_Main_Source_Unit
(E
)
131 and then not Is_Internal_Name
(Chars
(E
))
133 Xrefs
.Increment_Last
;
135 Loc
:= Original_Location
(Sloc
(E
));
137 Xrefs
.Table
(Indx
).Ent
:= E
;
138 Xrefs
.Table
(Indx
).Def
:= No_Location
;
139 Xrefs
.Table
(Indx
).Loc
:= No_Location
;
140 Xrefs
.Table
(Indx
).Typ
:= ' ';
141 Xrefs
.Table
(Indx
).Eun
:= Get_Source_Unit
(Loc
);
142 Xrefs
.Table
(Indx
).Lun
:= No_Unit
;
143 Set_Has_Xref_Entry
(E
);
145 if In_Inlined_Body
then
149 end Generate_Definition
;
151 ---------------------------------
152 -- Generate_Operator_Reference --
153 ---------------------------------
155 procedure Generate_Operator_Reference
160 if not In_Extended_Main_Source_Unit
(N
) then
164 -- If the operator is not a Standard operator, then we generate a real
165 -- reference to the user defined operator.
167 if Sloc
(Entity
(N
)) /= Standard_Location
then
168 Generate_Reference
(Entity
(N
), N
);
170 -- A reference to an implicit inequality operator is also a reference
171 -- to the user-defined equality.
173 if Nkind
(N
) = N_Op_Ne
174 and then not Comes_From_Source
(Entity
(N
))
175 and then Present
(Corresponding_Equality
(Entity
(N
)))
177 Generate_Reference
(Corresponding_Equality
(Entity
(N
)), N
);
180 -- For the case of Standard operators, we mark the result type as
181 -- referenced. This ensures that in the case where we are using a
182 -- derived operator, we mark an entity of the unit that implicitly
183 -- defines this operator as used. Otherwise we may think that no entity
184 -- of the unit is used. The actual entity marked as referenced is the
185 -- first subtype, which is the relevant user defined entity.
187 -- Note: we only do this for operators that come from source. The
188 -- generated code sometimes reaches for entities that do not need to be
189 -- explicitly visible (for example, when we expand the code for
190 -- comparing two record objects, the fields of the record may not be
193 elsif Comes_From_Source
(N
) then
194 Set_Referenced
(First_Subtype
(T
));
196 end Generate_Operator_Reference
;
198 ------------------------
199 -- Generate_Reference --
200 ------------------------
202 procedure Generate_Reference
205 Typ
: Character := 'r';
206 Set_Ref
: Boolean := True;
207 Force
: Boolean := False)
217 -- Used for call to Find_Actual
220 -- If Formal is non-Empty, then its Ekind, otherwise E_Void
222 function Is_On_LHS
(Node
: Node_Id
) return Boolean;
223 -- Used to check if a node is on the left hand side of an assignment.
224 -- The following cases are handled:
226 -- Variable Node is a direct descendant of left hand side of an
227 -- assignment statement.
229 -- Prefix Of an indexed or selected component that is present in
230 -- a subtree rooted by an assignment statement. There is
231 -- no restriction of nesting of components, thus cases
232 -- such as A.B (C).D are handled properly. However a prefix
233 -- of a dereference (either implicit or explicit) is never
234 -- considered as on a LHS.
236 -- Out param Same as above cases, but OUT parameter
238 function OK_To_Set_Referenced
return Boolean;
239 -- Returns True if the Referenced flag can be set. There are a few
240 -- exceptions where we do not want to set this flag, see body for
241 -- details of these exceptional cases.
247 -- ??? There are several routines here and there that perform a similar
248 -- (but subtly different) computation, which should be factored:
250 -- Sem_Util.May_Be_Lvalue
251 -- Sem_Util.Known_To_Be_Assigned
252 -- Exp_Ch2.Expand_Entry_Parameter.In_Assignment_Context
253 -- Exp_Smem.Is_Out_Actual
255 function Is_On_LHS
(Node
: Node_Id
) return Boolean is
261 -- Only identifiers are considered, is this necessary???
263 if Nkind
(Node
) /= N_Identifier
then
267 -- Immediate return if appeared as OUT parameter
269 if Kind
= E_Out_Parameter
then
273 -- Search for assignment statement subtree root
280 if K
= N_Assignment_Statement
then
283 -- Check whether the parent is a component and the current node is
284 -- its prefix, but return False if the current node has an access
285 -- type, as in that case the selected or indexed component is an
286 -- implicit dereference, and the LHS is the designated object, not
287 -- the access object.
289 -- ??? case of a slice assignment?
291 -- ??? Note that in some cases this is called too early
292 -- (see comments in Sem_Ch8.Find_Direct_Name), at a point where
293 -- the tree is not fully typed yet. In that case we may lack
294 -- an Etype for N, and we must disable the check for an implicit
295 -- dereference. If the dereference is on an LHS, this causes a
298 elsif (K
= N_Selected_Component
or else K
= N_Indexed_Component
)
299 and then Prefix
(P
) = N
300 and then not (Present
(Etype
(N
))
302 Is_Access_Type
(Etype
(N
)))
306 -- All other cases, definitely not on left side
314 ---------------------------
315 -- OK_To_Set_Referenced --
316 ---------------------------
318 function OK_To_Set_Referenced
return Boolean is
322 -- A reference from a pragma Unreferenced or pragma Unmodified or
323 -- pragma Warnings does not cause the Referenced flag to be set.
324 -- This avoids silly warnings about things being referenced and
325 -- not assigned when the only reference is from the pragma.
327 if Nkind
(N
) = N_Identifier
then
330 if Nkind
(P
) = N_Pragma_Argument_Association
then
333 if Nkind
(P
) = N_Pragma
then
334 if Pragma_Name
(P
) = Name_Warnings
336 Pragma_Name
(P
) = Name_Unmodified
338 Pragma_Name
(P
) = Name_Unreferenced
347 end OK_To_Set_Referenced
;
349 -- Start of processing for Generate_Reference
352 pragma Assert
(Nkind
(E
) in N_Entity
);
353 Find_Actual
(N
, Formal
, Call
);
355 if Present
(Formal
) then
356 Kind
:= Ekind
(Formal
);
361 -- Check for obsolescent reference to package ASCII. GNAT treats this
362 -- element of annex J specially since in practice, programs make a lot
363 -- of use of this feature, so we don't include it in the set of features
364 -- diagnosed when Warn_On_Obsolescent_Features mode is set. However we
365 -- are required to note it as a violation of the RM defined restriction.
367 if E
= Standard_ASCII
then
368 Check_Restriction
(No_Obsolescent_Features
, N
);
371 -- Check for reference to entity marked with Is_Obsolescent
373 -- Note that we always allow obsolescent references in the compiler
374 -- itself and the run time, since we assume that we know what we are
375 -- doing in such cases. For example the calls in Ada.Characters.Handling
376 -- to its own obsolescent subprograms are just fine.
378 -- In any case we do not generate warnings within the extended source
379 -- unit of the entity in question, since we assume the source unit
380 -- itself knows what is going on (and for sure we do not want silly
381 -- warnings, e.g. on the end line of an obsolescent procedure body).
383 if Is_Obsolescent
(E
)
384 and then not GNAT_Mode
385 and then not In_Extended_Main_Source_Unit
(E
)
387 Check_Restriction
(No_Obsolescent_Features
, N
);
389 if Warn_On_Obsolescent_Feature
then
390 Output_Obsolescent_Entity_Warnings
(N
, E
);
394 -- Warn if reference to Ada 2005 entity not in Ada 2005 mode. We only
395 -- detect real explicit references (modifications and references).
397 if Comes_From_Source
(N
)
398 and then Is_Ada_2005_Only
(E
)
399 and then Ada_Version
< Ada_05
400 and then Warn_On_Ada_2005_Compatibility
401 and then (Typ
= 'm' or else Typ
= 'r')
403 Error_Msg_NE
("& is only defined in Ada 2005?", N
, E
);
406 -- Never collect references if not in main source unit. However, we omit
407 -- this test if Typ is 'e' or 'k', since these entries are structural,
408 -- and it is useful to have them in units that reference packages as
409 -- well as units that define packages. We also omit the test for the
410 -- case of 'p' since we want to include inherited primitive operations
411 -- from other packages.
413 -- We also omit this test is this is a body reference for a subprogram
414 -- instantiation. In this case the reference is to the generic body,
415 -- which clearly need not be in the main unit containing the instance.
416 -- For the same reason we accept an implicit reference generated for
417 -- a default in an instance.
419 if not In_Extended_Main_Source_Unit
(N
) then
424 or else (Typ
= 'b' and then Is_Generic_Instance
(E
))
432 -- For reference type p, the entity must be in main source unit
434 if Typ
= 'p' and then not In_Extended_Main_Source_Unit
(E
) then
438 -- Unless the reference is forced, we ignore references where the
439 -- reference itself does not come from source.
441 if not Force
and then not Comes_From_Source
(N
) then
445 -- Deal with setting entity as referenced, unless suppressed. Note that
446 -- we still do Set_Referenced on entities that do not come from source.
447 -- This situation arises when we have a source reference to a derived
448 -- operation, where the derived operation itself does not come from
449 -- source, but we still want to mark it as referenced, since we really
450 -- are referencing an entity in the corresponding package (this avoids
451 -- wrong complaints that the package contains no referenced entities).
455 -- Assignable object appearing on left side of assignment or as
459 and then Is_On_LHS
(N
)
460 and then Ekind
(E
) /= E_In_Out_Parameter
462 -- For objects that are renamings, just set as simply referenced
463 -- we do not try to do assignment type tracking in this case.
465 if Present
(Renamed_Object
(E
)) then
468 -- Out parameter case
470 elsif Kind
= E_Out_Parameter
then
472 -- If warning mode for all out parameters is set, or this is
473 -- the only warning parameter, then we want to mark this for
474 -- later warning logic by setting Referenced_As_Out_Parameter
476 if Warn_On_Modified_As_Out_Parameter
(Formal
) then
477 Set_Referenced_As_Out_Parameter
(E
, True);
478 Set_Referenced_As_LHS
(E
, False);
480 -- For OUT parameter not covered by the above cases, we simply
481 -- regard it as a normal reference (in this case we do not
482 -- want any of the warning machinery for out parameters).
488 -- For the left hand of an assignment case, we do nothing here.
489 -- The processing for Analyze_Assignment_Statement will set the
490 -- Referenced_As_LHS flag.
496 -- Check for a reference in a pragma that should not count as a
497 -- making the variable referenced for warning purposes.
499 elsif Is_Non_Significant_Pragma_Reference
(N
) then
502 -- A reference in an attribute definition clause does not count as a
503 -- reference except for the case of Address. The reason that 'Address
504 -- is an exception is that it creates an alias through which the
505 -- variable may be referenced.
507 elsif Nkind
(Parent
(N
)) = N_Attribute_Definition_Clause
508 and then Chars
(Parent
(N
)) /= Name_Address
509 and then N
= Name
(Parent
(N
))
513 -- Constant completion does not count as a reference
516 and then Ekind
(E
) = E_Constant
520 -- Record representation clause does not count as a reference
522 elsif Nkind
(N
) = N_Identifier
523 and then Nkind
(Parent
(N
)) = N_Record_Representation_Clause
527 -- Discriminants do not need to produce a reference to record type
530 and then Nkind
(Parent
(N
)) = N_Discriminant_Specification
537 -- Special processing for IN OUT parameters, where we have an
538 -- implicit assignment to a simple variable.
540 if Kind
= E_In_Out_Parameter
541 and then Is_Assignable
(E
)
543 -- For sure this counts as a normal read reference
546 Set_Last_Assignment
(E
, Empty
);
548 -- We count it as being referenced as an out parameter if the
549 -- option is set to warn on all out parameters, except that we
550 -- have a special exclusion for an intrinsic subprogram, which
551 -- is most likely an instantiation of Unchecked_Deallocation
552 -- which we do not want to consider as an assignment since it
553 -- generates false positives. We also exclude the case of an
554 -- IN OUT parameter if the name of the procedure is Free,
555 -- since we suspect similar semantics.
557 if Warn_On_All_Unread_Out_Parameters
558 and then Is_Entity_Name
(Name
(Call
))
559 and then not Is_Intrinsic_Subprogram
(Entity
(Name
(Call
)))
560 and then Chars
(Name
(Call
)) /= Name_Free
562 Set_Referenced_As_Out_Parameter
(E
, True);
563 Set_Referenced_As_LHS
(E
, False);
566 -- Any other occurrence counts as referencing the entity
568 elsif OK_To_Set_Referenced
then
571 -- If variable, this is an OK reference after an assignment
572 -- so we can clear the Last_Assignment indication.
574 if Is_Assignable
(E
) then
575 Set_Last_Assignment
(E
, Empty
);
580 -- Check for pragma Unreferenced given and reference is within
581 -- this source unit (occasion for possible warning to be issued).
583 if Has_Pragma_Unreferenced
(E
)
584 and then In_Same_Extended_Unit
(E
, N
)
586 -- A reference as a named parameter in a call does not count
587 -- as a violation of pragma Unreferenced for this purpose...
589 if Nkind
(N
) = N_Identifier
590 and then Nkind
(Parent
(N
)) = N_Parameter_Association
591 and then Selector_Name
(Parent
(N
)) = N
595 -- ... Neither does a reference to a variable on the left side
598 elsif Is_On_LHS
(N
) then
601 -- For entry formals, we want to place the warning message on the
602 -- corresponding entity in the accept statement. The current scope
603 -- is the body of the accept, so we find the formal whose name
604 -- matches that of the entry formal (there is no link between the
605 -- two entities, and the one in the accept statement is only used
606 -- for conformance checking).
608 elsif Ekind
(Scope
(E
)) = E_Entry
then
613 BE
:= First_Entity
(Current_Scope
);
614 while Present
(BE
) loop
615 if Chars
(BE
) = Chars
(E
) then
617 ("?pragma Unreferenced given for&!", N
, BE
);
625 -- Here we issue the warning, since this is a real reference
628 Error_Msg_NE
("?pragma Unreferenced given for&!", N
, E
);
632 -- If this is a subprogram instance, mark as well the internal
633 -- subprogram in the wrapper package, which may be a visible
636 if Is_Overloadable
(E
)
637 and then Is_Generic_Instance
(E
)
638 and then Present
(Alias
(E
))
640 Set_Referenced
(Alias
(E
));
644 -- Generate reference if all conditions are met:
647 -- Cross referencing must be active
651 -- The entity must be one for which we collect references
653 and then Xref_Entity_Letters
(Ekind
(E
)) /= ' '
655 -- Both Sloc values must be set to something sensible
657 and then Sloc
(E
) > No_Location
658 and then Sloc
(N
) > No_Location
660 -- We ignore references from within an instance
662 and then Instantiation_Location
(Sloc
(N
)) = No_Location
664 -- Ignore dummy references
668 if Nkind
(N
) = N_Identifier
670 Nkind
(N
) = N_Defining_Identifier
674 Nkind
(N
) = N_Defining_Operator_Symbol
676 Nkind
(N
) = N_Operator_Symbol
678 (Nkind
(N
) = N_Character_Literal
679 and then Sloc
(Entity
(N
)) /= Standard_Location
)
681 Nkind
(N
) = N_Defining_Character_Literal
685 elsif Nkind
(N
) = N_Expanded_Name
687 Nkind
(N
) = N_Selected_Component
689 Nod
:= Selector_Name
(N
);
695 -- Normal case of source entity comes from source
697 if Comes_From_Source
(E
) then
700 -- Entity does not come from source, but is a derived subprogram and
701 -- the derived subprogram comes from source (after one or more
702 -- derivations) in which case the reference is to parent subprogram.
704 elsif Is_Overloadable
(E
)
705 and then Present
(Alias
(E
))
708 while not Comes_From_Source
(Ent
) loop
709 if No
(Alias
(Ent
)) then
716 -- The internally created defining entity for a child subprogram
717 -- that has no previous spec has valid references.
719 elsif Is_Overloadable
(E
)
720 and then Is_Child_Unit
(E
)
724 -- Record components of discriminated subtypes or derived types must
725 -- be treated as references to the original component.
727 elsif Ekind
(E
) = E_Component
728 and then Comes_From_Source
(Original_Record_Component
(E
))
730 Ent
:= Original_Record_Component
(E
);
732 -- If this is an expanded reference to a discriminant, recover the
733 -- original discriminant, which gets the reference.
735 elsif Ekind
(E
) = E_In_Parameter
736 and then Present
(Discriminal_Link
(E
))
738 Ent
:= Discriminal_Link
(E
);
739 Set_Referenced
(Ent
);
741 -- Ignore reference to any other entity that is not from source
747 -- Record reference to entity
749 Ref
:= Original_Location
(Sloc
(Nod
));
750 Def
:= Original_Location
(Sloc
(Ent
));
752 Xrefs
.Increment_Last
;
755 Xrefs
.Table
(Indx
).Loc
:= Ref
;
757 -- Overriding operations are marked with 'P'
760 and then Is_Subprogram
(N
)
761 and then Is_Overriding_Operation
(N
)
763 Xrefs
.Table
(Indx
).Typ
:= 'P';
765 Xrefs
.Table
(Indx
).Typ
:= Typ
;
768 Xrefs
.Table
(Indx
).Eun
:= Get_Source_Unit
(Def
);
769 Xrefs
.Table
(Indx
).Lun
:= Get_Source_Unit
(Ref
);
770 Xrefs
.Table
(Indx
).Ent
:= Ent
;
771 Set_Has_Xref_Entry
(Ent
);
773 end Generate_Reference
;
775 -----------------------------------
776 -- Generate_Reference_To_Formals --
777 -----------------------------------
779 procedure Generate_Reference_To_Formals
(E
: Entity_Id
) is
783 if Is_Generic_Subprogram
(E
) then
784 Formal
:= First_Entity
(E
);
786 while Present
(Formal
)
787 and then not Is_Formal
(Formal
)
789 Next_Entity
(Formal
);
793 Formal
:= First_Formal
(E
);
796 while Present
(Formal
) loop
797 if Ekind
(Formal
) = E_In_Parameter
then
799 if Nkind
(Parameter_Type
(Parent
(Formal
)))
800 = N_Access_Definition
802 Generate_Reference
(E
, Formal
, '^', False);
804 Generate_Reference
(E
, Formal
, '>', False);
807 elsif Ekind
(Formal
) = E_In_Out_Parameter
then
808 Generate_Reference
(E
, Formal
, '=', False);
811 Generate_Reference
(E
, Formal
, '<', False);
814 Next_Formal
(Formal
);
816 end Generate_Reference_To_Formals
;
818 -------------------------------------------
819 -- Generate_Reference_To_Generic_Formals --
820 -------------------------------------------
822 procedure Generate_Reference_To_Generic_Formals
(E
: Entity_Id
) is
826 Formal
:= First_Entity
(E
);
827 while Present
(Formal
) loop
828 if Comes_From_Source
(Formal
) then
829 Generate_Reference
(E
, Formal
, 'z', False);
832 Next_Entity
(Formal
);
834 end Generate_Reference_To_Generic_Formals
;
840 procedure Initialize
is
845 -----------------------
846 -- Output_References --
847 -----------------------
849 procedure Output_References
is
851 procedure Get_Type_Reference
853 Tref
: out Entity_Id
;
854 Left
: out Character;
855 Right
: out Character);
856 -- Given an Entity_Id Ent, determines whether a type reference is
857 -- required. If so, Tref is set to the entity for the type reference
858 -- and Left and Right are set to the left/right brackets to be output
859 -- for the reference. If no type reference is required, then Tref is
860 -- set to Empty, and Left/Right are set to space.
862 procedure Output_Import_Export_Info
(Ent
: Entity_Id
);
863 -- Output language and external name information for an interfaced
864 -- entity, using the format <language, external_name>,
866 ------------------------
867 -- Get_Type_Reference --
868 ------------------------
870 procedure Get_Type_Reference
872 Tref
: out Entity_Id
;
873 Left
: out Character;
874 Right
: out Character)
879 -- See if we have a type reference
888 -- Processing for types
890 if Is_Type
(Tref
) then
894 if Base_Type
(Tref
) = Tref
then
896 -- If derived, then get first subtype
898 if Tref
/= Etype
(Tref
) then
899 Tref
:= First_Subtype
(Etype
(Tref
));
901 -- Set brackets for derived type, but don't override
902 -- pointer case since the fact that something is a
903 -- pointer is more important.
910 -- If non-derived ptr, get directly designated type.
911 -- If the type has a full view, all references are on the
912 -- partial view, that is seen first.
914 elsif Is_Access_Type
(Tref
) then
915 Tref
:= Directly_Designated_Type
(Tref
);
919 elsif Is_Private_Type
(Tref
)
920 and then Present
(Full_View
(Tref
))
922 if Is_Access_Type
(Full_View
(Tref
)) then
923 Tref
:= Directly_Designated_Type
(Full_View
(Tref
));
927 -- If the full view is an array type, we also retrieve
928 -- the corresponding component type, because the ali
929 -- entry already indicates that this is an array.
931 elsif Is_Array_Type
(Full_View
(Tref
)) then
932 Tref
:= Component_Type
(Full_View
(Tref
));
937 -- If non-derived array, get component type. Skip component
938 -- type for case of String or Wide_String, saves worthwhile
941 elsif Is_Array_Type
(Tref
)
942 and then Tref
/= Standard_String
943 and then Tref
/= Standard_Wide_String
945 Tref
:= Component_Type
(Tref
);
949 -- For other non-derived base types, nothing
955 -- For a subtype, go to ancestor subtype
958 Tref
:= Ancestor_Subtype
(Tref
);
960 -- If no ancestor subtype, go to base type
963 Tref
:= Base_Type
(Sav
);
967 -- For objects, functions, enum literals, just get type from
970 elsif Is_Object
(Tref
)
971 or else Ekind
(Tref
) = E_Enumeration_Literal
972 or else Ekind
(Tref
) = E_Function
973 or else Ekind
(Tref
) = E_Operator
975 Tref
:= Etype
(Tref
);
977 -- For anything else, exit
983 -- Exit if no type reference, or we are stuck in some loop trying
984 -- to find the type reference, or if the type is standard void
985 -- type (the latter is an implementation artifact that should not
986 -- show up in the generated cross-references).
990 or else Tref
= Standard_Void_Type
;
992 -- If we have a usable type reference, return, otherwise keep
993 -- looking for something useful (we are looking for something
994 -- that either comes from source or standard)
996 if Sloc
(Tref
) = Standard_Location
997 or else Comes_From_Source
(Tref
)
999 -- If the reference is a subtype created for a generic actual,
1000 -- go actual directly, the inner subtype is not user visible.
1002 if Nkind
(Parent
(Tref
)) = N_Subtype_Declaration
1003 and then not Comes_From_Source
(Parent
(Tref
))
1005 (Is_Wrapper_Package
(Scope
(Tref
))
1006 or else Is_Generic_Instance
(Scope
(Tref
)))
1008 Tref
:= First_Subtype
(Base_Type
(Tref
));
1015 -- If we fall through the loop, no type reference
1020 end Get_Type_Reference
;
1022 -------------------------------
1023 -- Output_Import_Export_Info --
1024 -------------------------------
1026 procedure Output_Import_Export_Info
(Ent
: Entity_Id
) is
1027 Language_Name
: Name_Id
;
1028 Conv
: constant Convention_Id
:= Convention
(Ent
);
1031 -- Generate language name from convention
1033 if Conv
= Convention_C
then
1034 Language_Name
:= Name_C
;
1036 elsif Conv
= Convention_CPP
then
1037 Language_Name
:= Name_CPP
;
1039 elsif Conv
= Convention_Ada
then
1040 Language_Name
:= Name_Ada
;
1043 -- For the moment we ignore all other cases ???
1048 Write_Info_Char
('<');
1049 Get_Unqualified_Name_String
(Language_Name
);
1051 for J
in 1 .. Name_Len
loop
1052 Write_Info_Char
(Name_Buffer
(J
));
1055 if Present
(Interface_Name
(Ent
)) then
1056 Write_Info_Char
(',');
1057 String_To_Name_Buffer
(Strval
(Interface_Name
(Ent
)));
1059 for J
in 1 .. Name_Len
loop
1060 Write_Info_Char
(Name_Buffer
(J
));
1064 Write_Info_Char
('>');
1065 end Output_Import_Export_Info
;
1067 -- Start of processing for Output_References
1070 if not Opt
.Xref_Active
then
1074 -- Before we go ahead and output the references we have a problem
1075 -- that needs dealing with. So far we have captured things that are
1076 -- definitely referenced by the main unit, or defined in the main
1077 -- unit. That's because we don't want to clutter up the ali file
1078 -- for this unit with definition lines for entities in other units
1079 -- that are not referenced.
1081 -- But there is a glitch. We may reference an entity in another unit,
1082 -- and it may have a type reference to an entity that is not directly
1083 -- referenced in the main unit, which may mean that there is no xref
1084 -- entry for this entity yet in the list of references.
1086 -- If we don't do something about this, we will end with an orphan type
1087 -- reference, i.e. it will point to an entity that does not appear
1088 -- within the generated references in the ali file. That is not good for
1089 -- tools using the xref information.
1091 -- To fix this, we go through the references adding definition entries
1092 -- for any unreferenced entities that can be referenced in a type
1093 -- reference. There is a recursion problem here, and that is dealt with
1094 -- by making sure that this traversal also traverses any entries that
1095 -- get added by the traversal.
1097 Handle_Orphan_Type_References
: declare
1105 pragma Warnings
(Off
, L
);
1106 pragma Warnings
(Off
, R
);
1108 procedure New_Entry
(E
: Entity_Id
);
1109 -- Make an additional entry into the Xref table for a type entity
1110 -- that is related to the current entity (parent, type ancestor,
1111 -- progenitor, etc.).
1117 procedure New_Entry
(E
: Entity_Id
) is
1120 and then not Has_Xref_Entry
(E
)
1121 and then Sloc
(E
) > No_Location
1123 Xrefs
.Increment_Last
;
1125 Loc
:= Original_Location
(Sloc
(E
));
1126 Xrefs
.Table
(Indx
).Ent
:= E
;
1127 Xrefs
.Table
(Indx
).Loc
:= No_Location
;
1128 Xrefs
.Table
(Indx
).Eun
:= Get_Source_Unit
(Loc
);
1129 Xrefs
.Table
(Indx
).Lun
:= No_Unit
;
1130 Set_Has_Xref_Entry
(E
);
1134 -- Start of processing for Handle_Orphan_Type_References
1137 -- Note that this is not a for loop for a very good reason. The
1138 -- processing of items in the table can add new items to the table,
1139 -- and they must be processed as well.
1142 while J
<= Xrefs
.Last
loop
1143 Ent
:= Xrefs
.Table
(J
).Ent
;
1144 Get_Type_Reference
(Ent
, Tref
, L
, R
);
1147 and then not Has_Xref_Entry
(Tref
)
1148 and then Sloc
(Tref
) > No_Location
1152 if Is_Record_Type
(Ent
)
1153 and then Present
(Abstract_Interfaces
(Ent
))
1155 -- Add an entry for each one of the given interfaces
1156 -- implemented by type Ent.
1162 Elmt
:= First_Elmt
(Abstract_Interfaces
(Ent
));
1163 while Present
(Elmt
) loop
1164 New_Entry
(Node
(Elmt
));
1171 -- Collect inherited primitive operations that may be declared in
1172 -- another unit and have no visible reference in the current one.
1175 and then Is_Tagged_Type
(Ent
)
1176 and then Is_Derived_Type
(Ent
)
1177 and then Ent
= Base_Type
(Ent
)
1178 and then In_Extended_Main_Source_Unit
(Ent
)
1181 Op_List
: constant Elist_Id
:= Primitive_Operations
(Ent
);
1185 function Parent_Op
(E
: Entity_Id
) return Entity_Id
;
1186 -- Find original operation, which may be inherited through
1187 -- several derivations.
1189 function Parent_Op
(E
: Entity_Id
) return Entity_Id
is
1190 Orig_Op
: constant Entity_Id
:= Alias
(E
);
1192 if No
(Orig_Op
) then
1194 elsif not Comes_From_Source
(E
)
1195 and then not Has_Xref_Entry
(Orig_Op
)
1196 and then Comes_From_Source
(Orig_Op
)
1200 return Parent_Op
(Orig_Op
);
1205 Op
:= First_Elmt
(Op_List
);
1206 while Present
(Op
) loop
1207 Prim
:= Parent_Op
(Node
(Op
));
1209 if Present
(Prim
) then
1210 Xrefs
.Increment_Last
;
1212 Loc
:= Original_Location
(Sloc
(Prim
));
1213 Xrefs
.Table
(Indx
).Ent
:= Prim
;
1214 Xrefs
.Table
(Indx
).Loc
:= No_Location
;
1215 Xrefs
.Table
(Indx
).Eun
:=
1216 Get_Source_Unit
(Sloc
(Prim
));
1217 Xrefs
.Table
(Indx
).Lun
:= No_Unit
;
1218 Set_Has_Xref_Entry
(Prim
);
1228 end Handle_Orphan_Type_References
;
1230 -- Now we have all the references, including those for any embedded
1231 -- type references, so we can sort them, and output them.
1233 Output_Refs
: declare
1235 Nrefs
: Nat
:= Xrefs
.Last
;
1236 -- Number of references in table. This value may get reset (reduced)
1237 -- when we eliminate duplicate reference entries.
1239 Rnums
: array (0 .. Nrefs
) of Nat
;
1240 -- This array contains numbers of references in the Xrefs table.
1241 -- This list is sorted in output order. The extra 0'th entry is
1242 -- convenient for the call to sort. When we sort the table, we
1243 -- move the entries in Rnums around, but we do not move the
1244 -- original table entries.
1246 Curxu
: Unit_Number_Type
;
1247 -- Current xref unit
1249 Curru
: Unit_Number_Type
;
1250 -- Current reference unit for one entity
1252 Cursrc
: Source_Buffer_Ptr
;
1253 -- Current xref unit source text
1258 Curnam
: String (1 .. Name_Buffer
'Length);
1260 -- Simple name and length of current entity
1262 Curdef
: Source_Ptr
;
1263 -- Original source location for current entity
1266 -- Current reference location
1269 -- Entity type character
1275 -- Renaming reference
1277 Trunit
: Unit_Number_Type
;
1278 -- Unit number for type reference
1280 function Lt
(Op1
, Op2
: Natural) return Boolean;
1281 -- Comparison function for Sort call
1283 function Name_Change
(X
: Entity_Id
) return Boolean;
1284 -- Determines if entity X has a different simple name from Curent
1286 procedure Move
(From
: Natural; To
: Natural);
1287 -- Move procedure for Sort call
1289 package Sorting
is new GNAT
.Heap_Sort_G
(Move
, Lt
);
1295 function Lt
(Op1
, Op2
: Natural) return Boolean is
1296 T1
: Xref_Entry
renames Xrefs
.Table
(Rnums
(Nat
(Op1
)));
1297 T2
: Xref_Entry
renames Xrefs
.Table
(Rnums
(Nat
(Op2
)));
1300 -- First test: if entity is in different unit, sort by unit
1302 if T1
.Eun
/= T2
.Eun
then
1303 return Dependency_Num
(T1
.Eun
) < Dependency_Num
(T2
.Eun
);
1305 -- Second test: within same unit, sort by entity Sloc
1307 elsif T1
.Def
/= T2
.Def
then
1308 return T1
.Def
< T2
.Def
;
1310 -- Third test: sort definitions ahead of references
1312 elsif T1
.Loc
= No_Location
then
1315 elsif T2
.Loc
= No_Location
then
1318 -- Fourth test: for same entity, sort by reference location unit
1320 elsif T1
.Lun
/= T2
.Lun
then
1321 return Dependency_Num
(T1
.Lun
) < Dependency_Num
(T2
.Lun
);
1323 -- Fifth test: order of location within referencing unit
1325 elsif T1
.Loc
/= T2
.Loc
then
1326 return T1
.Loc
< T2
.Loc
;
1328 -- Finally, for two locations at the same address, we prefer
1329 -- the one that does NOT have the type 'r' so that a modification
1330 -- or extension takes preference, when there are more than one
1331 -- reference at the same location.
1334 return T2
.Typ
= 'r';
1342 procedure Move
(From
: Natural; To
: Natural) is
1344 Rnums
(Nat
(To
)) := Rnums
(Nat
(From
));
1351 -- Why a string comparison here??? Why not compare Name_Id values???
1353 function Name_Change
(X
: Entity_Id
) return Boolean is
1355 Get_Unqualified_Name_String
(Chars
(X
));
1357 if Name_Len
/= Curlen
then
1361 return Name_Buffer
(1 .. Curlen
) /= Curnam
(1 .. Curlen
);
1365 -- Start of processing for Output_Refs
1368 -- Capture the definition Sloc values. We delay doing this till now,
1369 -- since at the time the reference or definition is made, private
1370 -- types may be swapped, and the Sloc value may be incorrect. We
1371 -- also set up the pointer vector for the sort.
1373 for J
in 1 .. Nrefs
loop
1375 Xrefs
.Table
(J
).Def
:=
1376 Original_Location
(Sloc
(Xrefs
.Table
(J
).Ent
));
1379 -- Sort the references
1381 Sorting
.Sort
(Integer (Nrefs
));
1383 -- Eliminate duplicate entries
1386 NR
: constant Nat
:= Nrefs
;
1389 -- We need this test for NR because if we force ALI file
1390 -- generation in case of errors detected, it may be the case
1391 -- that Nrefs is 0, so we should not reset it here
1396 for J
in 2 .. NR
loop
1397 if Xrefs
.Table
(Rnums
(J
)) /=
1398 Xrefs
.Table
(Rnums
(Nrefs
))
1401 Rnums
(Nrefs
) := Rnums
(J
);
1407 -- Initialize loop through references
1411 Curdef
:= No_Location
;
1413 Crloc
:= No_Location
;
1415 -- Loop to output references
1417 for Refno
in 1 .. Nrefs
loop
1418 Output_One_Ref
: declare
1424 pragma Warnings
(Off
, WC
);
1425 pragma Warnings
(Off
, Err
);
1427 XE
: Xref_Entry
renames Xrefs
.Table
(Rnums
(Refno
));
1428 -- The current entry to be accessed
1431 -- Used to index into source buffer to get entity name
1435 -- Used for {} or <> or () for type reference
1437 procedure Check_Type_Reference
1439 List_Interface
: Boolean);
1440 -- Find whether there is a meaningful type reference for
1441 -- Ent, and display it accordingly. If List_Interface is
1442 -- true, then Ent is a progenitor interface of the current
1443 -- type entity being listed. In that case list it as is,
1444 -- without looking for a type reference for it.
1446 procedure Output_Instantiation_Refs
(Loc
: Source_Ptr
);
1447 -- Recursive procedure to output instantiation references for
1448 -- the given source ptr in [file|line[...]] form. No output
1449 -- if the given location is not a generic template reference.
1451 procedure Output_Overridden_Op
(Old_E
: Entity_Id
);
1452 -- For a subprogram that is overriding, display information
1453 -- about the inherited operation that it overrides.
1455 --------------------------
1456 -- Check_Type_Reference --
1457 --------------------------
1459 procedure Check_Type_Reference
1461 List_Interface
: Boolean)
1464 if List_Interface
then
1466 -- This is a progenitor interface of the type for which
1467 -- xref information is being generated.
1474 Get_Type_Reference
(Ent
, Tref
, Left
, Right
);
1477 if Present
(Tref
) then
1479 -- Case of standard entity, output name
1481 if Sloc
(Tref
) = Standard_Location
then
1482 Write_Info_Char
(Left
);
1483 Write_Info_Name
(Chars
(Tref
));
1484 Write_Info_Char
(Right
);
1486 -- Case of source entity, output location
1489 Write_Info_Char
(Left
);
1490 Trunit
:= Get_Source_Unit
(Sloc
(Tref
));
1492 if Trunit
/= Curxu
then
1493 Write_Info_Nat
(Dependency_Num
(Trunit
));
1494 Write_Info_Char
('|');
1498 (Int
(Get_Logical_Line_Number
(Sloc
(Tref
))));
1506 Ctyp
:= Xref_Entity_Letters
(Ekind
(Ent
));
1509 and then Present
(Full_View
(Ent
))
1511 Ent
:= Underlying_Type
(Ent
);
1513 if Present
(Ent
) then
1514 Ctyp
:= Xref_Entity_Letters
(Ekind
(Ent
));
1518 Write_Info_Char
(Ctyp
);
1522 (Int
(Get_Column_Number
(Sloc
(Tref
))));
1524 -- If the type comes from an instantiation, add the
1525 -- corresponding info.
1527 Output_Instantiation_Refs
(Sloc
(Tref
));
1528 Write_Info_Char
(Right
);
1531 end Check_Type_Reference
;
1533 -------------------------------
1534 -- Output_Instantiation_Refs --
1535 -------------------------------
1537 procedure Output_Instantiation_Refs
(Loc
: Source_Ptr
) is
1538 Iloc
: constant Source_Ptr
:= Instantiation_Location
(Loc
);
1539 Lun
: Unit_Number_Type
;
1540 Cu
: constant Unit_Number_Type
:= Curru
;
1543 -- Nothing to do if this is not an instantiation
1545 if Iloc
= No_Location
then
1549 -- Output instantiation reference
1551 Write_Info_Char
('[');
1552 Lun
:= Get_Source_Unit
(Iloc
);
1554 if Lun
/= Curru
then
1556 Write_Info_Nat
(Dependency_Num
(Curru
));
1557 Write_Info_Char
('|');
1560 Write_Info_Nat
(Int
(Get_Logical_Line_Number
(Iloc
)));
1562 -- Recursive call to get nested instantiations
1564 Output_Instantiation_Refs
(Iloc
);
1566 -- Output final ] after call to get proper nesting
1568 Write_Info_Char
(']');
1571 end Output_Instantiation_Refs
;
1573 --------------------------
1574 -- Output_Overridden_Op --
1575 --------------------------
1577 procedure Output_Overridden_Op
(Old_E
: Entity_Id
) is
1581 -- The overridden operation has an implicit declaration
1582 -- at the point of derivation. What we want to display
1583 -- is the original operation, which has the actual body
1584 -- (or abstract declaration) that is being overridden.
1585 -- The overridden operation is not always set, e.g. when
1586 -- it is a predefined operator.
1591 elsif Present
(Alias
(Old_E
)) then
1592 Op
:= Alias
(Old_E
);
1599 and then Sloc
(Op
) /= Standard_Location
1602 Loc
: constant Source_Ptr
:= Sloc
(Op
);
1603 Par_Unit
: constant Unit_Number_Type
:=
1604 Get_Source_Unit
(Loc
);
1607 Write_Info_Char
('<');
1609 if Par_Unit
/= Curxu
then
1610 Write_Info_Nat
(Dependency_Num
(Par_Unit
));
1611 Write_Info_Char
('|');
1614 Write_Info_Nat
(Int
(Get_Logical_Line_Number
(Loc
)));
1615 Write_Info_Char
('p');
1616 Write_Info_Nat
(Int
(Get_Column_Number
(Loc
)));
1617 Write_Info_Char
('>');
1620 end Output_Overridden_Op
;
1622 -- Start of processing for Output_One_Ref
1626 Ctyp
:= Xref_Entity_Letters
(Ekind
(Ent
));
1628 -- Skip reference if it is the only reference to an entity,
1629 -- and it is an END line reference, and the entity is not in
1630 -- the current extended source. This prevents junk entries
1631 -- consisting only of packages with END lines, where no
1632 -- entity from the package is actually referenced.
1635 and then Ent
/= Curent
1636 and then (Refno
= Nrefs
or else
1637 Ent
/= Xrefs
.Table
(Rnums
(Refno
+ 1)).Ent
)
1639 not In_Extended_Main_Source_Unit
(Ent
)
1644 -- For private type, get full view type
1647 and then Present
(Full_View
(XE
.Ent
))
1649 Ent
:= Underlying_Type
(Ent
);
1651 if Present
(Ent
) then
1652 Ctyp
:= Xref_Entity_Letters
(Ekind
(Ent
));
1656 -- Special exception for Boolean
1658 if Ctyp
= 'E' and then Is_Boolean_Type
(Ent
) then
1662 -- For variable reference, get corresponding type
1665 Ent
:= Etype
(XE
.Ent
);
1666 Ctyp
:= Fold_Lower
(Xref_Entity_Letters
(Ekind
(Ent
)));
1668 -- If variable is private type, get full view type
1671 and then Present
(Full_View
(Etype
(XE
.Ent
)))
1673 Ent
:= Underlying_Type
(Etype
(XE
.Ent
));
1675 if Present
(Ent
) then
1676 Ctyp
:= Fold_Lower
(Xref_Entity_Letters
(Ekind
(Ent
)));
1679 elsif Is_Generic_Type
(Ent
) then
1681 -- If the type of the entity is a generic private type,
1682 -- there is no usable full view, so retain the indication
1683 -- that this is an object.
1688 -- Special handling for access parameter
1691 K
: constant Entity_Kind
:= Ekind
(Etype
(XE
.Ent
));
1694 if (K
= E_Anonymous_Access_Type
1696 K
= E_Anonymous_Access_Subprogram_Type
1698 E_Anonymous_Access_Protected_Subprogram_Type
)
1699 and then Is_Formal
(XE
.Ent
)
1703 -- Special handling for Boolean
1705 elsif Ctyp
= 'e' and then Is_Boolean_Type
(Ent
) then
1711 -- Special handling for abstract types and operations
1713 if Is_Overloadable
(XE
.Ent
)
1714 and then Is_Abstract_Subprogram
(XE
.Ent
)
1717 Ctyp
:= 'x'; -- Abstract procedure
1719 elsif Ctyp
= 'V' then
1720 Ctyp
:= 'y'; -- Abstract function
1723 elsif Is_Type
(XE
.Ent
)
1724 and then Is_Abstract_Type
(XE
.Ent
)
1726 if Is_Interface
(XE
.Ent
) then
1729 elsif Ctyp
= 'R' then
1730 Ctyp
:= 'H'; -- Abstract type
1734 -- Only output reference if interesting type of entity, and
1735 -- suppress self references, except for bodies that act as
1736 -- specs. Also suppress definitions of body formals (we only
1737 -- treat these as references, and the references were
1738 -- separately recorded).
1741 or else (XE
.Loc
= XE
.Def
1744 or else not Is_Subprogram
(XE
.Ent
)))
1745 or else (Is_Formal
(XE
.Ent
)
1746 and then Present
(Spec_Entity
(XE
.Ent
)))
1751 -- Start new Xref section if new xref unit
1753 if XE
.Eun
/= Curxu
then
1754 if Write_Info_Col
> 1 then
1759 Cursrc
:= Source_Text
(Source_Index
(Curxu
));
1761 Write_Info_Initiate
('X');
1762 Write_Info_Char
(' ');
1763 Write_Info_Nat
(Dependency_Num
(XE
.Eun
));
1764 Write_Info_Char
(' ');
1765 Write_Info_Name
(Reference_Name
(Source_Index
(XE
.Eun
)));
1768 -- Start new Entity line if new entity. Note that we
1769 -- consider two entities the same if they have the same
1770 -- name and source location. This causes entities in
1771 -- instantiations to be treated as though they referred
1778 (Name_Change
(XE
.Ent
) or else XE
.Def
/= Curdef
))
1783 Get_Unqualified_Name_String
(Chars
(XE
.Ent
));
1785 Curnam
(1 .. Curlen
) := Name_Buffer
(1 .. Curlen
);
1787 if Write_Info_Col
> 1 then
1791 -- Write column number information
1793 Write_Info_Nat
(Int
(Get_Logical_Line_Number
(XE
.Def
)));
1794 Write_Info_Char
(Ctyp
);
1795 Write_Info_Nat
(Int
(Get_Column_Number
(XE
.Def
)));
1797 -- Write level information
1799 Write_Level_Info
: declare
1800 function Is_Visible_Generic_Entity
1801 (E
: Entity_Id
) return Boolean;
1802 -- Check whether E is declared in the visible part
1803 -- of a generic package. For source navigation
1804 -- purposes, treat this as a visible entity.
1806 function Is_Private_Record_Component
1807 (E
: Entity_Id
) return Boolean;
1808 -- Check whether E is a non-inherited component of a
1809 -- private extension. Even if the enclosing record is
1810 -- public, we want to treat the component as private
1811 -- for navigation purposes.
1813 ---------------------------------
1814 -- Is_Private_Record_Component --
1815 ---------------------------------
1817 function Is_Private_Record_Component
1818 (E
: Entity_Id
) return Boolean
1820 S
: constant Entity_Id
:= Scope
(E
);
1823 Ekind
(E
) = E_Component
1824 and then Nkind
(Declaration_Node
(S
)) =
1825 N_Private_Extension_Declaration
1826 and then Original_Record_Component
(E
) = E
;
1827 end Is_Private_Record_Component
;
1829 -------------------------------
1830 -- Is_Visible_Generic_Entity --
1831 -------------------------------
1833 function Is_Visible_Generic_Entity
1834 (E
: Entity_Id
) return Boolean
1839 if Ekind
(Scope
(E
)) /= E_Generic_Package
then
1844 while Present
(Par
) loop
1846 Nkind
(Par
) = N_Generic_Package_Declaration
1848 -- Entity is a generic formal
1853 Nkind
(Parent
(Par
)) = N_Package_Specification
1856 Is_List_Member
(Par
)
1857 and then List_Containing
(Par
) =
1858 Visible_Declarations
(Parent
(Par
));
1860 Par
:= Parent
(Par
);
1865 end Is_Visible_Generic_Entity
;
1867 -- Start of processing for Write_Level_Info
1870 if Is_Hidden
(Curent
)
1871 or else Is_Private_Record_Component
(Curent
)
1873 Write_Info_Char
(' ');
1877 or else Is_Visible_Generic_Entity
(Curent
)
1879 Write_Info_Char
('*');
1882 Write_Info_Char
(' ');
1884 end Write_Level_Info
;
1886 -- Output entity name. We use the occurrence from the
1887 -- actual source program at the definition point.
1889 P
:= Original_Location
(Sloc
(XE
.Ent
));
1891 -- Entity is character literal
1893 if Cursrc
(P
) = ''' then
1894 Write_Info_Char
(Cursrc
(P
));
1895 Write_Info_Char
(Cursrc
(P
+ 1));
1896 Write_Info_Char
(Cursrc
(P
+ 2));
1898 -- Entity is operator symbol
1900 elsif Cursrc
(P
) = '"' or else Cursrc
(P
) = '%' then
1901 Write_Info_Char
(Cursrc
(P
));
1906 Write_Info_Char
(Cursrc
(P2
));
1907 exit when Cursrc
(P2
) = Cursrc
(P
);
1910 -- Entity is identifier
1914 if Is_Start_Of_Wide_Char
(Cursrc
, P
) then
1915 Scan_Wide
(Cursrc
, P
, WC
, Err
);
1916 elsif not Identifier_Char
(Cursrc
(P
)) then
1923 -- Write out the identifier by copying the exact
1924 -- source characters used in its declaration. Note
1925 -- that this means wide characters will be in their
1926 -- original encoded form.
1929 Original_Location
(Sloc
(XE
.Ent
)) .. P
- 1
1931 Write_Info_Char
(Cursrc
(J
));
1935 -- See if we have a renaming reference
1937 if Is_Object
(XE
.Ent
)
1938 and then Present
(Renamed_Object
(XE
.Ent
))
1940 Rref
:= Renamed_Object
(XE
.Ent
);
1942 elsif Is_Overloadable
(XE
.Ent
)
1943 and then Nkind
(Parent
(Declaration_Node
(XE
.Ent
))) =
1944 N_Subprogram_Renaming_Declaration
1946 Rref
:= Name
(Parent
(Declaration_Node
(XE
.Ent
)));
1948 elsif Ekind
(XE
.Ent
) = E_Package
1949 and then Nkind
(Declaration_Node
(XE
.Ent
)) =
1950 N_Package_Renaming_Declaration
1952 Rref
:= Name
(Declaration_Node
(XE
.Ent
));
1958 if Present
(Rref
) then
1959 if Nkind
(Rref
) = N_Expanded_Name
then
1960 Rref
:= Selector_Name
(Rref
);
1963 if Nkind
(Rref
) = N_Identifier
1964 or else Nkind
(Rref
) = N_Operator_Symbol
1968 -- For renamed array components, use the array name
1969 -- for the renamed entity, which reflect the fact that
1970 -- in general the whole array is aliased.
1972 elsif Nkind
(Rref
) = N_Indexed_Component
then
1973 if Nkind
(Prefix
(Rref
)) = N_Identifier
then
1974 Rref
:= Prefix
(Rref
);
1975 elsif Nkind
(Prefix
(Rref
)) = N_Expanded_Name
then
1976 Rref
:= Selector_Name
(Prefix
(Rref
));
1986 -- Write out renaming reference if we have one
1988 if Present
(Rref
) then
1989 Write_Info_Char
('=');
1991 (Int
(Get_Logical_Line_Number
(Sloc
(Rref
))));
1992 Write_Info_Char
(':');
1994 (Int
(Get_Column_Number
(Sloc
(Rref
))));
1997 -- Indicate that the entity is in the unit of the current
2002 -- Write out information about generic parent, if entity
2005 if Is_Generic_Instance
(XE
.Ent
) then
2007 Gen_Par
: constant Entity_Id
:=
2010 (Unit_Declaration_Node
(XE
.Ent
)));
2011 Loc
: constant Source_Ptr
:= Sloc
(Gen_Par
);
2012 Gen_U
: constant Unit_Number_Type
:=
2013 Get_Source_Unit
(Loc
);
2016 Write_Info_Char
('[');
2017 if Curru
/= Gen_U
then
2018 Write_Info_Nat
(Dependency_Num
(Gen_U
));
2019 Write_Info_Char
('|');
2023 (Int
(Get_Logical_Line_Number
(Loc
)));
2024 Write_Info_Char
(']');
2028 -- See if we have a type reference and if so output
2030 Check_Type_Reference
(XE
.Ent
, False);
2032 -- Additional information for types with progenitors
2034 if Is_Record_Type
(XE
.Ent
)
2035 and then Present
(Abstract_Interfaces
(XE
.Ent
))
2041 Elmt
:= First_Elmt
(Abstract_Interfaces
(XE
.Ent
));
2042 while Present
(Elmt
) loop
2043 Check_Type_Reference
(Node
(Elmt
), True);
2048 -- For array types, list index types as well.
2049 -- (This is not C, indices have distinct types).
2051 elsif Is_Array_Type
(XE
.Ent
) then
2055 Indx
:= First_Index
(XE
.Ent
);
2056 while Present
(Indx
) loop
2057 Check_Type_Reference
2058 (First_Subtype
(Etype
(Indx
)), True);
2064 -- If the entity is an overriding operation, write info
2065 -- on operation that was overridden.
2067 if Is_Subprogram
(XE
.Ent
)
2068 and then Is_Overriding_Operation
(XE
.Ent
)
2070 Output_Overridden_Op
(Overridden_Operation
(XE
.Ent
));
2073 -- End of processing for entity output
2075 Crloc
:= No_Location
;
2078 -- Output the reference
2080 if XE
.Loc
/= No_Location
2081 and then XE
.Loc
/= Crloc
2085 -- Start continuation if line full, else blank
2087 if Write_Info_Col
> 72 then
2089 Write_Info_Initiate
('.');
2092 Write_Info_Char
(' ');
2094 -- Output file number if changed
2096 if XE
.Lun
/= Curru
then
2098 Write_Info_Nat
(Dependency_Num
(Curru
));
2099 Write_Info_Char
('|');
2102 Write_Info_Nat
(Int
(Get_Logical_Line_Number
(XE
.Loc
)));
2103 Write_Info_Char
(XE
.Typ
);
2105 if Is_Overloadable
(XE
.Ent
)
2106 and then Is_Imported
(XE
.Ent
)
2107 and then XE
.Typ
= 'b'
2109 Output_Import_Export_Info
(XE
.Ent
);
2112 Write_Info_Nat
(Int
(Get_Column_Number
(XE
.Loc
)));
2114 Output_Instantiation_Refs
(Sloc
(XE
.Ent
));
2125 end Output_References
;