Reverting merge from trunk
[official-gcc.git] / gcc / ada / spark_xrefs.ads
blob2b0a708295436184c43c1123ac4abd1e58d4e183
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S P A R K _ X R E F S --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 2011-2013, 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 3, 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 COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
26 -- This package defines tables used to store information needed for the SPARK
27 -- mode. It is used by procedures in Lib.Xref.SPARK_Specific to build the
28 -- SPARK specific cross-references information before writing it out to the
29 -- ALI file, and by Get_SPARK_Xrefs/Put_SPARK_Xrefs to read and write the text
30 -- form that is used in the ALI file.
32 with Types; use Types;
33 with GNAT.Table;
35 package SPARK_Xrefs is
37 -- SPARK cross-reference information can exist in one of two forms. In the
38 -- ALI file, it is represented using a text format that is described in
39 -- this specification. Internally it is stored using three tables
40 -- SPARK_Xref_Table, SPARK_Scope_Table and SPARK_File_Table, which are also
41 -- defined in this unit.
43 -- Lib.Xref.SPARK_Specific is part of the compiler. It extracts SPARK
44 -- cross-reference information from the complete set of cross-references
45 -- generated during compilation.
47 -- Get_SPARK_Xrefs reads the text lines in ALI format and populates the
48 -- internal tables with corresponding information.
50 -- Put_SPARK_Xrefs reads the internal tables and generates text lines in
51 -- the ALI format.
53 ----------------------------
54 -- SPARK Xrefs ALI Format --
55 ----------------------------
57 -- SPARK cross-reference information is generated on a unit-by-unit basis
58 -- in the ALI file, using lines that start with the identifying character F
59 -- ("Formal"). These lines are generated if -gnatd.E or -gnatd.F (Why
60 -- generation mode) switches are set.
62 -- The SPARK cross-reference information comes after the shared
63 -- cross-reference information, so it needs not be read by tools like
64 -- gnatbind, gnatmake etc.
66 -- -------------------
67 -- -- Scope Section --
68 -- -------------------
70 -- A first section defines the scopes in which entities are defined and
71 -- referenced. A scope is a package/subprogram declaration/body. Note that
72 -- a package declaration and body define two different scopes. Similarly, a
73 -- subprogram declaration and body, when both present, define two different
74 -- scopes.
76 -- FD dependency-number filename (-> unit-filename)?
78 -- This header precedes scope information for the unit identified by
79 -- dependency number and file name. The dependency number is the index
80 -- into the generated D lines and is ones-origin (e.g. 2 = reference to
81 -- second generated D line).
83 -- The list of FD lines should match the list of D lines defined in the
84 -- ALI file, in the same order.
86 -- Note that the filename here will reflect the original name if a
87 -- Source_Reference pragma was encountered (since all line number
88 -- references will be with respect to the original file).
90 -- Note: the filename is redundant in that it could be deduced from the
91 -- corresponding D line, but it is convenient at least for human
92 -- reading of the SPARK cross-reference information, and means that
93 -- the SPARK cross-reference information can stand on its own without
94 -- needing other parts of the ALI file.
96 -- The optional unit filename is given only for subunits.
98 -- FS . scope line type col entity (-> spec-file . spec-scope)?
100 -- (The ? mark stands for an optional entry in the syntax)
102 -- scope is the ones-origin scope number for the current file (e.g. 2 =
103 -- reference to the second FS line in this FD block).
105 -- line is the line number of the scope entity. The name of the entity
106 -- starts in column col. Columns are numbered from one, and if
107 -- horizontal tab characters are present, the column number is computed
108 -- assuming standard 1,9,17,.. tab stops. For example, if the entity is
109 -- the first token on the line, and is preceded by space-HT-space, then
110 -- the column would be column 10.
112 -- type is a single letter identifying the type of the entity, using
113 -- the same code as in cross-references:
115 -- K = package
116 -- V = function
117 -- U = procedure
119 -- col is the column number of the scope entity
121 -- entity is the name of the scope entity, with casing in the canonical
122 -- casing for the source file where it is defined.
124 -- spec-file and spec-scope are respectively the file and scope for the
125 -- spec corresponding to the current body scope, when they differ.
127 -- ------------------
128 -- -- Xref Section --
129 -- ------------------
131 -- A second section defines cross-references useful for computing the set
132 -- of global variables read/written in each subprogram/package.
134 -- FX dependency-number filename . entity-number entity
136 -- dependency-number and filename identity a file in FD lines
138 -- entity-number and identity identify a scope entity in FS lines for
139 -- the file previously identified.
141 -- line typ col entity ref*
143 -- line is the line number of the referenced entity
145 -- typ is the type of the referenced entity, using a code similar to
146 -- the one used for cross-references:
148 -- > = IN parameter
149 -- < = OUT parameter
150 -- = = IN OUT parameter
151 -- * = all other cases
153 -- col is the column number of the referenced entity
155 -- entity is the name of the referenced entity as written in the source
156 -- file where it is defined.
158 -- There may be zero or more ref entries on each line
160 -- (file |)? ((. scope :)? line type col)*
162 -- file is the dependency number of the file with the reference. It and
163 -- the following vertical bar are omitted if the file is the same as
164 -- the previous ref, and the refs for the current file are first (and
165 -- do not need a bar).
167 -- scope is the scope number of the scope with the reference. It and
168 -- the following colon are omitted if the scope is the same as the
169 -- previous ref, and the refs for the current scope are first (and do
170 -- not need a colon).
172 -- line is the line number of the reference
174 -- col is the column number of the reference
176 -- type is one of the following, using the same code as in
177 -- cross-references:
179 -- m = modification
180 -- r = reference
181 -- s = subprogram reference in a static call
183 -- Special entries for reads and writes to memory reference a special
184 -- variable called "__HEAP". These special entries are present in every
185 -- scope where reads and writes to memory are present. Line and column for
186 -- this special variable are always 0.
188 -- Examples: ??? add examples here
190 ----------------
191 -- Xref Table --
192 ----------------
194 -- The following table records SPARK cross-references
196 type Xref_Index is new Int;
197 -- Used to index values in this table. Values start at 1 and are assigned
198 -- sequentially as entries are constructed.
200 type SPARK_Xref_Record is record
201 Entity_Name : String_Ptr;
202 -- Pointer to entity name in ALI file
204 Entity_Line : Nat;
205 -- Line number for the entity referenced
207 Etype : Character;
208 -- Indicates type of entity, using code used in ALI file:
209 -- > = IN parameter
210 -- < = OUT parameter
211 -- = = IN OUT parameter
212 -- * = all other cases
214 Entity_Col : Nat;
215 -- Column number for the entity referenced
217 File_Num : Nat;
218 -- Set to the file dependency number for the cross-reference. Note
219 -- that if no file entry is present explicitly, this is just a copy
220 -- of the reference for the current cross-reference section.
222 Scope_Num : Nat;
223 -- Set to the scope number for the cross-reference. Note that if no
224 -- scope entry is present explicitly, this is just a copy of the
225 -- reference for the current cross-reference section.
227 Line : Nat;
228 -- Line number for the reference
230 Rtype : Character;
231 -- Indicates type of reference, using code used in ALI file:
232 -- r = reference
233 -- m = modification
234 -- s = call
236 Col : Nat;
237 -- Column number for the reference
238 end record;
240 package SPARK_Xref_Table is new GNAT.Table (
241 Table_Component_Type => SPARK_Xref_Record,
242 Table_Index_Type => Xref_Index,
243 Table_Low_Bound => 1,
244 Table_Initial => 2000,
245 Table_Increment => 300);
247 -----------------
248 -- Scope Table --
249 -----------------
251 -- This table keeps track of the scopes and the corresponding starting and
252 -- ending indexes (From, To) in the Xref table.
254 type Scope_Index is new Int;
255 -- Used to index values in this table. Values start at 1 and are assigned
256 -- sequentially as entries are constructed.
258 type SPARK_Scope_Record is record
259 Scope_Name : String_Ptr;
260 -- Pointer to scope name in ALI file
262 File_Num : Nat;
263 -- Set to the file dependency number for the scope
265 Scope_Num : Nat;
266 -- Set to the scope number for the scope
268 Spec_File_Num : Nat;
269 -- Set to the file dependency number for the scope corresponding to the
270 -- spec of the current scope entity, if different, or else 0.
272 Spec_Scope_Num : Nat;
273 -- Set to the scope number for the scope corresponding to the spec of
274 -- the current scope entity, if different, or else 0.
276 Line : Nat;
277 -- Line number for the scope
279 Stype : Character;
280 -- Indicates type of scope, using code used in ALI file:
281 -- K = package
282 -- V = function
283 -- U = procedure
285 Col : Nat;
286 -- Column number for the scope
288 From_Xref : Xref_Index;
289 -- Starting index in Xref table for this scope
291 To_Xref : Xref_Index;
292 -- Ending index in Xref table for this scope
294 -- The following component is only used in-memory, not printed out in
295 -- ALI file.
297 Scope_Entity : Entity_Id := Empty;
298 -- Entity (subprogram or package) for the scope
299 end record;
301 package SPARK_Scope_Table is new GNAT.Table (
302 Table_Component_Type => SPARK_Scope_Record,
303 Table_Index_Type => Scope_Index,
304 Table_Low_Bound => 1,
305 Table_Initial => 200,
306 Table_Increment => 300);
308 ----------------
309 -- File Table --
310 ----------------
312 -- This table keeps track of the units and the corresponding starting and
313 -- ending indexes (From, To) in the Scope table.
315 type File_Index is new Int;
316 -- Used to index values in this table. Values start at 1 and are assigned
317 -- sequentially as entries are constructed.
319 type SPARK_File_Record is record
320 File_Name : String_Ptr;
321 -- Pointer to file name in ALI file
323 Unit_File_Name : String_Ptr;
324 -- Pointer to file name for unit in ALI file, when File_Name refers to a
325 -- subunit. Otherwise null.
327 File_Num : Nat;
328 -- Dependency number in ALI file
330 From_Scope : Scope_Index;
331 -- Starting index in Scope table for this unit
333 To_Scope : Scope_Index;
334 -- Ending index in Scope table for this unit
335 end record;
337 package SPARK_File_Table is new GNAT.Table (
338 Table_Component_Type => SPARK_File_Record,
339 Table_Index_Type => File_Index,
340 Table_Low_Bound => 1,
341 Table_Initial => 20,
342 Table_Increment => 200);
344 ---------------
345 -- Constants --
346 ---------------
348 Name_Of_Heap_Variable : constant String := "__HEAP";
349 -- Name of special variable used in effects to denote reads and writes
350 -- through explicit dereference.
352 -----------------
353 -- Subprograms --
354 -----------------
356 procedure Initialize_SPARK_Tables;
357 -- Reset tables for a new compilation
359 procedure dspark;
360 -- Debug routine to dump internal SPARK cross-reference tables. This is a
361 -- raw format dump showing exactly what the tables contain.
363 procedure pspark;
364 -- Debugging procedure to output contents of SPARK cross-reference binary
365 -- tables in the format in which they appear in an ALI file.
367 end SPARK_Xrefs;