2002-04-02 David S. Miller <davem@redhat.com>
[official-gcc.git] / gcc / ada / xref_lib.ads
blob0d2beeb34e25d484919f37576e0624455fcfd61d
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- X R E F _ L I B --
6 -- --
7 -- S p e c --
8 -- --
9 -- --
10 -- Copyright (C) 1998-2001 Free Software Foundation, Inc. --
11 -- --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNAT; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
22 -- --
23 -- GNAT is maintained by Ada Core Technologies Inc (http://www.gnat.com). --
24 -- --
25 ------------------------------------------------------------------------------
27 with Hostparm;
28 with GNAT.Directory_Operations; use GNAT.Directory_Operations;
29 with GNAT.OS_Lib; use GNAT.OS_Lib;
30 with GNAT.Dynamic_Tables;
32 with Xr_Tabls; use Xr_Tabls;
33 with GNAT.Regexp; use GNAT.Regexp;
35 -- Misc. utilities for the cross-referencing tool
37 package Xref_Lib is
39 subtype File_Name_String is String (1 .. Hostparm.Max_Name_Length);
40 subtype Line_String is String (1 .. Hostparm.Max_Line_Length);
42 type ALI_File is limited private;
44 ---------------------
45 -- Directory Input --
46 ---------------------
47 type Rec_DIR is limited private;
48 -- This one is used for recursive search of .ali files
50 procedure Find_ALI_Files;
51 -- Find all the ali files that we will have to parse, and have them to
52 -- the file list
54 ---------------------
55 -- Search patterns --
56 ---------------------
58 type Search_Pattern is private;
59 type Search_Pattern_Ptr is access all Search_Pattern;
61 procedure Add_Entity
62 (Pattern : in out Search_Pattern;
63 Entity : String;
64 Glob : Boolean := False);
65 -- Add a new entity to the search pattern (the entity should have the
66 -- form pattern[:file[:line[:column]]], and it is parsed entirely in
67 -- this procedure. Glob indicates if we should use the 'globbing
68 -- patterns' (True) or the full regular expressions (False)
70 procedure Add_Xref_File (File : String);
71 -- Add a new file in the list of files to search for references. File
72 -- is interpreted as a globbing regular expression, which is expanded.
74 Invalid_Argument : exception;
75 -- Exception raised when there is a syntax error in the command line
77 function Match
78 (Pattern : Search_Pattern;
79 Symbol : String)
80 return Boolean;
81 -- Returns true if Symbol matches one of the entities in the command line
83 -----------------------
84 -- Output Algorithms --
85 -----------------------
87 procedure Print_Gnatfind
88 (References : in Boolean;
89 Full_Path_Name : in Boolean);
90 procedure Print_Unused (Full_Path_Name : in Boolean);
91 procedure Print_Vi (Full_Path_Name : in Boolean);
92 procedure Print_Xref (Full_Path_Name : in Boolean);
93 -- The actual print procedures. These functions step through the symbol
94 -- table and print all the symbols if they match the files given on the
95 -- command line (they already match the entities if they are in the
96 -- symbol table)
98 ------------------------
99 -- General Algorithms --
100 ------------------------
101 function Default_Project_File (Dir_Name : in String) return String;
102 -- Returns the default Project file name
104 procedure Search
105 (Pattern : Search_Pattern;
106 Local_Symbols : Boolean;
107 Wide_Search : Boolean;
108 Read_Only : Boolean;
109 Der_Info : Boolean;
110 Type_Tree : Boolean);
111 -- Search every ali file (following the Readdir rule above), for
112 -- each line matching Pattern, and executes Process on these
113 -- lines. If World is True, Search will look into every .ali file
114 -- in the object search path. If Read_Only is True, we parse the
115 -- read-only ali files too. If Der_Mode is true then the derived type
116 -- information will be processed. If Type_Tree is true then the type
117 -- hierarchy will be search going from pattern to the parent type
119 procedure Search_Xref
120 (Local_Symbols : Boolean;
121 Read_Only : Boolean;
122 Der_Info : Boolean);
123 -- Search every ali file given in the command line and all their
124 -- dependencies. If Read_Only is True, we parse the read-only ali
125 -- files too. If Der_Mode is true then the derived type information will
126 -- be processed
128 ---------------
129 -- ALI files --
130 ---------------
132 function Current_Xref_File
133 (File : ALI_File)
134 return Xr_Tabls.File_Reference;
135 -- Returns the name of the file in which the last identifier
136 -- is declared
138 function File_Name
139 (File : ALI_File;
140 Num : Positive)
141 return Xr_Tabls.File_Reference;
142 -- Returns the dependency file name number Num
144 function Get_Full_Type (Abbrev : Character) return String;
145 -- Returns the full type corresponding to a type letter as found in
146 -- the .ali files.
148 procedure Open
149 (Name : in String;
150 File : out ALI_File;
151 Dependencies : in Boolean := False);
152 -- Open a new ALI file
153 -- if Dependencies is True, the insert every library file 'with'ed in
154 -- the files database (used for gnatxref)
156 private
157 type Rec_DIR is limited record
158 Dir : GNAT.Directory_Operations.Dir_Type;
159 end record;
161 package Dependencies_Tables is new GNAT.Dynamic_Tables
162 (Table_Component_Type => Xr_Tabls.File_Reference,
163 Table_Index_Type => Positive,
164 Table_Low_Bound => 1,
165 Table_Initial => 400,
166 Table_Increment => 100);
167 use Dependencies_Tables;
169 type Dependencies is new Dependencies_Tables.Instance;
171 type ALI_File is limited record
172 Buffer : String_Access := null;
173 -- Buffer used to read the whole file at once
175 Current_Line : Positive;
176 -- Start of the current line in Buffer
178 Xref_Line : Positive;
179 -- Start of the xref lines in Buffer
181 X_File : Xr_Tabls.File_Reference;
182 -- Stores the cross-referencing file-name ("X..." lines), as an
183 -- index into the dependencies table
185 Dep : Dependencies;
186 -- Store file name associated with each number ("D..." lines)
187 end record;
189 -- The following record type stores all the patterns that are searched for
191 type Search_Pattern is record
192 Entity : GNAT.Regexp.Regexp;
193 -- A regular expression matching the entities we are looking for.
194 -- File is a list of the places where the declaration of the entities
195 -- has to be. When the user enters a file:line:column on the command
196 -- line, it is stored as "Entity_Name Declaration_File:line:column"
198 Initialized : Boolean := False;
199 -- Set to True when Entity has been initialized.
200 end record;
201 -- Stores all the pattern that are search for.
202 end Xref_Lib;