OSDN Git Service

2007-04-20 Vincent Celier <celier@adacore.com>
[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-2006, 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,  51  Franklin  Street,  Fifth  Floor, --
20 -- Boston, MA 02110-1301, USA.                                              --
21 --                                                                          --
22 -- GNAT was originally developed  by the GNAT team at  New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
24 --                                                                          --
25 ------------------------------------------------------------------------------
26
27 --  Miscellaneous utilities for the cross-referencing tool
28
29 with Hostparm;
30 with Xr_Tabls;  use Xr_Tabls;
31
32 with GNAT.Directory_Operations; use GNAT.Directory_Operations;
33 with GNAT.OS_Lib;               use GNAT.OS_Lib;
34 with GNAT.Dynamic_Tables;
35 with GNAT.Regexp;               use GNAT.Regexp;
36
37 package Xref_Lib is
38
39    subtype File_Name_String is String (1 .. Hostparm.Max_Name_Length);
40    subtype Line_String      is String (1 .. Hostparm.Max_Line_Length);
41
42    type ALI_File is limited private;
43
44    ---------------------
45    -- Directory Input --
46    ---------------------
47
48    type Rec_DIR is limited private;
49    --  This one is used for recursive search of .ali files
50
51    procedure Find_ALI_Files;
52    --  Find all the ali files that we will have to parse, and have them to
53    --  the file list
54
55    ---------------------
56    -- Search patterns --
57    ---------------------
58
59    type Search_Pattern is private;
60    type Search_Pattern_Ptr is access all Search_Pattern;
61
62    procedure Add_Entity
63      (Pattern : in out Search_Pattern;
64       Entity  : String;
65       Glob    : Boolean := False);
66    --  Add a new entity to the search pattern (the entity should have the
67    --  form pattern[:file[:line[:column]]], and it is parsed entirely in
68    --  this procedure. Glob indicates if we should use the 'globbing
69    --  patterns' (True) or the full regular expressions (False)
70
71    procedure Add_Xref_File (File : String);
72    --  Add a new file in the list of files to search for references. File
73    --  is interpreted as a globbing regular expression, which is expanded.
74
75    Invalid_Argument : exception;
76    --  Exception raised when there is a syntax error in the command line
77
78    -----------------------
79    -- Output Algorithms --
80    -----------------------
81
82    procedure Print_Gnatfind
83      (References     : Boolean;
84       Full_Path_Name : Boolean);
85    procedure Print_Unused (Full_Path_Name : Boolean);
86    procedure Print_Vi     (Full_Path_Name : Boolean);
87    procedure Print_Xref   (Full_Path_Name : Boolean);
88    --  The actual print procedures. These functions step through the symbol
89    --  table and print all the symbols if they match the files given on the
90    --  command line (they already match the entities if they are in the
91    --  symbol table)
92
93    ------------------------
94    -- General Algorithms --
95    ------------------------
96
97    function Default_Project_File (Dir_Name : String) return String;
98    --  Returns the default Project file name for the directory Dir_Name
99
100    procedure Search
101      (Pattern       : Search_Pattern;
102       Local_Symbols : Boolean;
103       Wide_Search   : Boolean;
104       Read_Only     : Boolean;
105       Der_Info      : Boolean;
106       Type_Tree     : Boolean);
107    --  Search every ALI file for entities matching Pattern, and add
108    --  these entities to the internal symbol tables.
109    --
110    --  If Wide_Search is True, all ALI files found in the object path
111    --  are searched.
112    --
113    --  If Read_Only is True, read-only ALI files will also be parsed,
114    --  similar to gnatmake -a.
115    --
116    --  If Der_Info is true, then the derived type information will be
117    --  processed.
118    --
119    --  If Type_Tree is true, then the type hierarchy wil be searched
120    --  going from the pattern to the parent type.
121
122    procedure Search_Xref
123      (Local_Symbols : Boolean;
124       Read_Only     : Boolean;
125       Der_Info      : Boolean);
126    --  Search every ali file given in the command line and all their
127    --  dependencies. If Read_Only is True, we parse the read-only ali
128    --  files too. If Der_Mode is true then the derived type information will
129    --  be processed
130
131 private
132    type Rec_DIR is limited record
133       Dir : GNAT.Directory_Operations.Dir_Type;
134    end record;
135
136    package Dependencies_Tables is new GNAT.Dynamic_Tables
137      (Table_Component_Type => Xr_Tabls.File_Reference,
138       Table_Index_Type     => Positive,
139       Table_Low_Bound      => 1,
140       Table_Initial        => 400,
141       Table_Increment      => 100);
142    use Dependencies_Tables;
143
144    type Dependencies is new Dependencies_Tables.Instance;
145
146    type ALI_File is limited record
147       Buffer : String_Access := null;
148       --  Buffer used to read the whole file at once
149
150       Current_Line : Positive;
151       --  Start of the current line in Buffer
152
153       Xref_Line : Positive;
154       --  Start of the xref lines in Buffer
155
156       X_File : Xr_Tabls.File_Reference;
157       --  Stores the cross-referencing file-name ("X..." lines), as an
158       --  index into the dependencies table
159
160       Dep : Dependencies;
161       --  Store file name associated with each number ("D..." lines)
162    end record;
163
164    --  The following record type stores all the patterns that are searched for
165
166    type Search_Pattern is record
167       Entity : GNAT.Regexp.Regexp;
168       --  A regular expression matching the entities we are looking for.
169       --  File is a list of the places where the declaration of the entities
170       --  has to be. When the user enters a file:line:column on the command
171       --  line, it is stored as "Entity_Name Declaration_File:line:column"
172
173       File_Ref : Xr_Tabls.File_Reference;
174       --  A reference to the source file, if any
175
176       Initialized : Boolean := False;
177       --  Set to True when Entity has been initialized
178    end record;
179
180 end Xref_Lib;