1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1998-2001 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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
27 with GNAT
.Directory_Operations
; use GNAT
.Directory_Operations
;
28 with GNAT
.OS_Lib
; use GNAT
.OS_Lib
;
29 with GNAT
.Dynamic_Tables
;
31 with Xr_Tabls
; use Xr_Tabls
;
32 with GNAT
.Regexp
; use GNAT
.Regexp
;
34 -- Misc. utilities for the cross-referencing tool
38 subtype File_Name_String
is String (1 .. Hostparm
.Max_Name_Length
);
39 subtype Line_String
is String (1 .. Hostparm
.Max_Line_Length
);
41 type ALI_File
is limited private;
46 type Rec_DIR
is limited private;
47 -- This one is used for recursive search of .ali files
49 procedure Find_ALI_Files
;
50 -- Find all the ali files that we will have to parse, and have them to
57 type Search_Pattern
is private;
58 type Search_Pattern_Ptr
is access all Search_Pattern
;
61 (Pattern
: in out Search_Pattern
;
63 Glob
: Boolean := False);
64 -- Add a new entity to the search pattern (the entity should have the
65 -- form pattern[:file[:line[:column]]], and it is parsed entirely in
66 -- this procedure. Glob indicates if we should use the 'globbing
67 -- patterns' (True) or the full regular expressions (False)
69 procedure Add_Xref_File
(File
: String);
70 -- Add a new file in the list of files to search for references. File
71 -- is interpreted as a globbing regular expression, which is expanded.
73 Invalid_Argument
: exception;
74 -- Exception raised when there is a syntax error in the command line
77 (Pattern
: Search_Pattern
;
80 -- Returns true if Symbol matches one of the entities in the command line
82 -----------------------
83 -- Output Algorithms --
84 -----------------------
86 procedure Print_Gnatfind
87 (References
: in Boolean;
88 Full_Path_Name
: in Boolean);
89 procedure Print_Unused
(Full_Path_Name
: in Boolean);
90 procedure Print_Vi
(Full_Path_Name
: in Boolean);
91 procedure Print_Xref
(Full_Path_Name
: in Boolean);
92 -- The actual print procedures. These functions step through the symbol
93 -- table and print all the symbols if they match the files given on the
94 -- command line (they already match the entities if they are in the
97 ------------------------
98 -- General Algorithms --
99 ------------------------
100 function Default_Project_File
(Dir_Name
: in String) return String;
101 -- Returns the default Project file name
104 (Pattern
: Search_Pattern
;
105 Local_Symbols
: Boolean;
106 Wide_Search
: Boolean;
109 Type_Tree
: Boolean);
110 -- Search every ali file (following the Readdir rule above), for
111 -- each line matching Pattern, and executes Process on these
112 -- lines. If World is True, Search will look into every .ali file
113 -- in the object search path. If Read_Only is True, we parse the
114 -- read-only ali files too. If Der_Mode is true then the derived type
115 -- information will be processed. If Type_Tree is true then the type
116 -- hierarchy will be search going from pattern to the parent type
118 procedure Search_Xref
119 (Local_Symbols
: Boolean;
122 -- Search every ali file given in the command line and all their
123 -- dependencies. If Read_Only is True, we parse the read-only ali
124 -- files too. If Der_Mode is true then the derived type information will
131 function Current_Xref_File
133 return Xr_Tabls
.File_Reference
;
134 -- Returns the name of the file in which the last identifier
140 return Xr_Tabls
.File_Reference
;
141 -- Returns the dependency file name number Num
143 function Get_Full_Type
(Abbrev
: Character) return String;
144 -- Returns the full type corresponding to a type letter as found in
150 Dependencies
: in Boolean := False);
151 -- Open a new ALI file
152 -- if Dependencies is True, the insert every library file 'with'ed in
153 -- the files database (used for gnatxref)
156 type Rec_DIR
is limited record
157 Dir
: GNAT
.Directory_Operations
.Dir_Type
;
160 package Dependencies_Tables
is new GNAT
.Dynamic_Tables
161 (Table_Component_Type
=> Xr_Tabls
.File_Reference
,
162 Table_Index_Type
=> Positive,
163 Table_Low_Bound
=> 1,
164 Table_Initial
=> 400,
165 Table_Increment
=> 100);
166 use Dependencies_Tables
;
168 type Dependencies
is new Dependencies_Tables
.Instance
;
170 type ALI_File
is limited record
171 Buffer
: String_Access
:= null;
172 -- Buffer used to read the whole file at once
174 Current_Line
: Positive;
175 -- Start of the current line in Buffer
177 Xref_Line
: Positive;
178 -- Start of the xref lines in Buffer
180 X_File
: Xr_Tabls
.File_Reference
;
181 -- Stores the cross-referencing file-name ("X..." lines), as an
182 -- index into the dependencies table
185 -- Store file name associated with each number ("D..." lines)
188 -- The following record type stores all the patterns that are searched for
190 type Search_Pattern
is record
191 Entity
: GNAT
.Regexp
.Regexp
;
192 -- A regular expression matching the entities we are looking for.
193 -- File is a list of the places where the declaration of the entities
194 -- has to be. When the user enters a file:line:column on the command
195 -- line, it is stored as "Entity_Name Declaration_File:line:column"
197 Initialized
: Boolean := False;
198 -- Set to True when Entity has been initialized.
200 -- Stores all the pattern that are search for.