OSDN Git Service

* Make-lang.in (gnat_ug_unx.info): Add dependency on stmp-docobjdir.
[pf3gnuchains/gcc-fork.git] / gcc / ada / xref_lib.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                              X R E F _ L I B                             --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --       Copyright (C) 1998-2001 Free Software Foundation, Inc.             --
10 --                                                                          --
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.                                                      --
21 --                                                                          --
22 -- Extensive contributions were provided by Ada Core Technologies Inc.   --
23 --                                                                          --
24 ------------------------------------------------------------------------------
25
26 with Hostparm;
27 with GNAT.Directory_Operations; use GNAT.Directory_Operations;
28 with GNAT.OS_Lib;               use GNAT.OS_Lib;
29 with GNAT.Dynamic_Tables;
30
31 with Xr_Tabls;                  use Xr_Tabls;
32 with GNAT.Regexp;               use GNAT.Regexp;
33
34 --  Misc. utilities for the cross-referencing tool
35
36 package Xref_Lib is
37
38    subtype File_Name_String is String (1 .. Hostparm.Max_Name_Length);
39    subtype Line_String      is String (1 .. Hostparm.Max_Line_Length);
40
41    type ALI_File is limited private;
42
43    ---------------------
44    -- Directory Input --
45    ---------------------
46    type Rec_DIR is limited private;
47    --  This one is used for recursive search of .ali files
48
49    procedure Find_ALI_Files;
50    --  Find all the ali files that we will have to parse, and have them to
51    --  the file list
52
53    ---------------------
54    -- Search patterns --
55    ---------------------
56
57    type Search_Pattern is private;
58    type Search_Pattern_Ptr is access all Search_Pattern;
59
60    procedure Add_Entity
61      (Pattern : in out Search_Pattern;
62       Entity  : String;
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)
68
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.
72
73    Invalid_Argument : exception;
74    --  Exception raised when there is a syntax error in the command line
75
76    function Match
77      (Pattern : Search_Pattern;
78       Symbol  : String)
79       return    Boolean;
80    --  Returns true if Symbol matches one of the entities in the command line
81
82    -----------------------
83    -- Output Algorithms --
84    -----------------------
85
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
95    --  symbol table)
96
97    ------------------------
98    -- General Algorithms --
99    ------------------------
100    function Default_Project_File (Dir_Name : in String) return String;
101    --  Returns the default Project file name
102
103    procedure Search
104      (Pattern       : Search_Pattern;
105       Local_Symbols : Boolean;
106       Wide_Search   : Boolean;
107       Read_Only     : Boolean;
108       Der_Info      : 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
117
118    procedure Search_Xref
119      (Local_Symbols : Boolean;
120       Read_Only     : Boolean;
121       Der_Info      : 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
125    --  be processed
126
127    ---------------
128    -- ALI files --
129    ---------------
130
131    function Current_Xref_File
132      (File : ALI_File)
133       return Xr_Tabls.File_Reference;
134    --  Returns the name of the file in which the last identifier
135    --  is declared
136
137    function File_Name
138      (File : ALI_File;
139       Num  : Positive)
140       return Xr_Tabls.File_Reference;
141    --  Returns the dependency file name number Num
142
143    function Get_Full_Type (Abbrev : Character) return String;
144    --  Returns the full type corresponding to a type letter as found in
145    --  the .ali files.
146
147    procedure Open
148      (Name         : in  String;
149       File         : out ALI_File;
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)
154
155 private
156    type Rec_DIR is limited record
157       Dir : GNAT.Directory_Operations.Dir_Type;
158    end record;
159
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;
167
168    type Dependencies is new Dependencies_Tables.Instance;
169
170    type ALI_File is limited record
171       Buffer         : String_Access := null;
172       --  Buffer used to read the whole file at once
173
174       Current_Line   : Positive;
175       --  Start of the current line in Buffer
176
177       Xref_Line      : Positive;
178       --  Start of the xref lines in Buffer
179
180       X_File         : Xr_Tabls.File_Reference;
181       --  Stores the cross-referencing file-name ("X..." lines), as an
182       --  index into the dependencies table
183
184       Dep : Dependencies;
185       --  Store file name associated with each number ("D..." lines)
186    end record;
187
188    --  The following record type stores all the patterns that are searched for
189
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"
196
197       Initialized : Boolean := False;
198       --  Set to True when Entity has been initialized.
199    end record;
200    --  Stores all the pattern that are search for.
201 end Xref_Lib;