1
------------------------------------------------------------------------------
3
-- GNATELIM COMPONENTS --
5
-- A S I S . E X T E N S I O N S . H O M O N Y M S --
7
-- P a c k a g e B o d y --
10
-- Copyright (C) 2002-2003 Ada Core Technologies, Inc. --
12
-- GNATELIM is free software; you can redistribute it and/or modify it --
13
-- under the terms of the GNU General Public License as published by the --
14
-- Free Software Foundation; either version 2 or (at your option) any later --
15
-- version. GNATELIM is distributed in the hope that it will be useful, but --
16
-- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABI- --
17
-- LITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public Li- --
18
-- cense for more details. You should have received a copy of the GNU --
19
-- General Public License distributed with GNAT; see file COPYING. If not, --
20
-- write to the Free Software Foundation, 59 Temple Place - Suite 330, --
21
-- Boston, MA 02111-1307, USA. --
23
-- The original version of Gnatelim was developed by Alain Le Guennec --
24
-- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com) --
26
------------------------------------------------------------------------------
28
with Atree; use Atree;
29
with Einfo; use Einfo;
30
with Sinfo; use Sinfo;
32
package body Asis.Extensions.Homonyms is
38
function Has_Homonym (E : Asis.Element) return Boolean is
40
function Has_Homonym_Internal (Entity : Entity_Id) return Boolean;
41
-- Returns true if a given Entity in GNAT tree corresponds to the
42
-- subprogram that has a homonym in the same scope. Derived from
45
--------------------------
46
-- Has_Homonym_Internal --
47
--------------------------
49
function Has_Homonym_Internal (Entity : Entity_Id) return Boolean is
50
E : Entity_Id := Entity;
54
-- If this is a child unit, we want the child
56
if Nkind (E) = N_Defining_Program_Unit_Name then
57
E := Defining_Identifier (Entity);
60
-- If the entity is a subprogram instance that is not a compilation
61
-- unit, go to the original Ada entity
63
if Is_Generic_Instance (E)
64
and then Is_Subprogram (E)
65
and then not Is_Compilation_Unit (Scope (E))
67
E := Related_Instance (Scope (E));
70
return Has_Homonym (E);
72
end Has_Homonym_Internal;
76
return Has_Homonym_Internal (E.R_Node);
84
function Homonym_Number (E : Asis.Element) return Natural is
86
function Homonym_Number_Internal (Entity : Entity_Id) return Natural;
87
-- Returns the homonym number of a given entity or zero if the entity
90
-----------------------------
91
-- Homonym_Number_Internal --
92
-----------------------------
94
function Homonym_Number_Internal (Entity : Entity_Id) return Natural is
95
E : Entity_Id := Entity;
99
-- If this is a child unit, we want the child
101
if Nkind (E) = N_Defining_Program_Unit_Name then
102
E := Defining_Identifier (Entity);
105
-- If the entity is a subprogram instance that is not a compilation
106
-- unit, go to the original Ada entity
108
if Is_Generic_Instance (E)
109
and then Is_Subprogram (E)
110
and then not Is_Compilation_Unit (Scope (E))
112
E := Related_Instance (Scope (E));
115
if Has_Homonym (E) then
117
H : Entity_Id := Homonym (E);
121
while Present (H) loop
122
if Scope (H) = Scope (E) then
133
end Homonym_Number_Internal;
137
return Homonym_Number_Internal (E.R_Node);
141
end Asis.Extensions.Homonyms;