2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / ada / lib-xref.ads
blob34434b9696f1b553b8689c3e08d6539db3645079
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- L I B . X R E F --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 1998-2003, 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 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 -- --
25 ------------------------------------------------------------------------------
27 -- This package contains for collecting and outputting cross-reference
28 -- information.
30 with Einfo; use Einfo;
31 with Types; use Types;
33 package Lib.Xref is
35 -------------------------------------------------------
36 -- Format of Cross-Reference Information in ALI File --
37 -------------------------------------------------------
39 -- Cross-reference sections follow the dependency section (D lines) in
40 -- an ALI file, so that they need not be read by gnatbind, gnatmake etc.
42 -- A cross reference section has a header of the form
44 -- X dependency-number filename
46 -- This header precedes xref information (entities/references from
47 -- the unit, identified by dependency number and file name. The
48 -- dependency number is the index into the generated D lines and
49 -- is ones origin (i.e. 2 = reference to second generated D line).
51 -- Note that the filename here will reflect the original name if
52 -- a Source_Reference pragma was encountered (since all line number
53 -- references will be with respect to the original file).
55 -- The lines following the header look like
57 -- line type col level entity renameref typeref ref ref ref
59 -- line is the line number of the referenced entity. The name of
60 -- the entity starts in column col. Columns are numbered from one,
61 -- and if horizontal tab characters are present, the column number
62 -- is computed assuming standard 1,9,17,.. tab stops. For example,
63 -- if the entity is the first token on the line, and is preceded
64 -- by space-HT-space, then the column would be column 10.
66 -- type is a single letter identifying the type of the entity.
67 -- See next section (Cross-Reference Entity Identifiers) for a
68 -- full list of the characters used).
70 -- col is the column number of the referenced entity
72 -- level is a single character that separates the col and
73 -- entity fields. It is an asterisk for a top level library
74 -- entity that is publicly visible, as well for an entity declared
75 -- in the visible part of a generic package, and space otherwise.
77 -- entity is the name of the referenced entity, with casing in
78 -- the canical casing for the source file where it is defined.
80 -- renameref provides information on renaming. If the entity is
81 -- a package, object or overloadable entity which is declared by
82 -- a renaming declaration, and the renaming refers to an entity
83 -- with a simple identifier or expanded name, then renameref has
84 -- the form:
86 -- =line:col
88 -- Here line:col give the reference to the identifier that
89 -- appears in the renaming declaration. Note that we never need
90 -- a file entry, since this identifier is always in the current
91 -- file in which the entity is declared. Currently, renameref
92 -- appears only for the simple renaming case. If the renaming
93 -- reference is a complex expressions, then renameref is omitted.
94 -- Here line/col give line/column as defined above.
96 -- typeref is the reference for a related type. This part is
97 -- optional. It is present for the following cases:
99 -- derived types (points to the parent type) LR=<>
100 -- access types (points to designated type) LR=()
101 -- array types (points to component type) LR=()
102 -- subtypes (points to ancestor type) LR={}
103 -- functions (points to result type) LR={}
104 -- enumeration literals (points to enum type) LR={}
105 -- objects and components (points to type) LR={}
107 -- In the above list LR shows the brackets used in the output,
108 -- which has one of the two following forms:
110 -- L file | line type col R user entity
111 -- L name-in-lower-case R standard entity
113 -- For the form for a user entity, file is the dependency number
114 -- of the file containing the declaration of the related type.
115 -- This number and the following vertical bar are omitted if the
116 -- relevant type is defined in the same file as the current entity.
117 -- The line, type, col are defined as previously described, and
118 -- specify the location of the relevant type declaration in the
119 -- referenced file. For the standard entity form, the name between
120 -- the brackets is the normal name of the entity in lower case.
122 -- There may be zero or more ref entries on each line
124 -- file | line type col [...]
126 -- file is the dependency number of the file with the reference.
127 -- It and the following vertical bar are omitted if the file is
128 -- the same as the previous ref, and the refs for the current
129 -- file are first (and do not need a bar).
131 -- line is the line number of the reference
133 -- col is the column number of the reference, as defined above.
135 -- type is one of
136 -- b = body entity
137 -- c = completion of private or incomplete type
138 -- d = discriminant of type
139 -- e = end of spec
140 -- H = abstract type
141 -- i = implicit reference
142 -- k = implicit reference to parent unit in child unit
143 -- l = label on END line
144 -- m = modification
145 -- p = primitive operation
146 -- P = overriding primitive operation
147 -- r = reference
148 -- t = end of body
149 -- w = WITH line
150 -- x = type extension
151 -- z = generic formal parameter
152 -- > = subprogram IN parameter
153 -- = = subprogram IN OUT parameter
154 -- < = subprogram OUT parameter
155 -- > = subprogram ACCESS parameter
157 -- b is used for spec entities that are repeated in a body,
158 -- including the unit (subprogram, package, task, protected
159 -- body, protected entry) name itself, and in the case of a
160 -- subprogram, the formals. This letter is also used for the
161 -- occurrence of entry names in accept statements. Such entities
162 -- are not considered to be definitions for cross-referencing
163 -- purposes, but rather are considered to be references to the
164 -- corresponding spec entities, marked with this special type.
166 -- c is similar to b but is used to mark the completion of a
167 -- private or incomplete type. As with b, the completion is not
168 -- regarded as a separate definition, but rather a reference to
169 -- the initial declaration, marked with this special type.
171 -- d is used to identify a discriminant of a type. If this is
172 -- an incomplete or private type with discriminants, the entry
173 -- denotes the occurrence of the discriminant in the partial view
174 -- which is also the point of definition of the discriminant.
175 -- The occurrence of the same discriminant in the full view is
176 -- a regular reference to it.
178 -- e is used to identify the end of a construct in the following
179 -- cases:
181 -- Block Statement end [block_IDENTIFIER];
182 -- Loop Statement end loop [loop_IDENTIFIER];
183 -- Package Specification end [[PARENT_UNIT_NAME .] IDENTIFIER];
184 -- Task Definition end [task_IDENTIFIER];
185 -- Protected Definition end [protected_IDENTIFIER];
186 -- Record Definition end record;
187 -- Enumeration Definition );
189 -- Note that 'e' entries are special in that they appear even
190 -- in referencing units (normally xref entries appear only
191 -- for references in the extended main source unit (see Lib) to
192 -- which the ali applies. But 'e' entries are really structural
193 -- and simply indicate where packages end. This information can
194 -- be used to reconstruct scope information for any entities
195 -- referenced from within the package. The line/column values
196 -- for these entries point to the semicolon ending the construct.
198 -- i is used to identify a reference to the entity in a generic
199 -- actual or in a default in a call. The node that denotes the
200 -- entity does not come from source, but it has the Sloc of the
201 -- source node that generates the implicit reference, and it is
202 -- useful to record this one.
204 -- k is used to denote a reference to the parent unit, in the
205 -- cross-reference line for a child unit.
207 -- l is used to identify the occurrence in the source of the
208 -- name on an end line. This is just a syntactic reference
209 -- which can be ignored for semantic purposes (such as call
210 -- graph construction). Again, in the case of an accept there
211 -- can be multiple l lines.
213 -- p is used to mark a primitive operation of the given entity.
214 -- For example, if we have a type Tx, and a primitive operation
215 -- Pq of this type, then an entry in the list of references to
216 -- Tx will point to the declaration of Pq. Note that this entry
217 -- type is unusual because it an implicit rather than explicit,
218 -- and the name of the refrerence does not match the name of the
219 -- entity for which a reference is generated. These entries are
220 -- generated only for entities declared in the extended main
221 -- source unit (main unit itself, its separate spec (if any).
222 -- and all subunits (considered recursively).
224 -- If the primitive operation overrides an inherited primitive
225 -- operation of the parent type, the letter 'P' is used in the
226 -- corresponding entry.
228 -- t is similar to e. It identifies the end of a corresponding
229 -- body (such a reference always links up with a b reference)
231 -- Subprogram Body end [DESIGNATOR];
232 -- Package Body end [[PARENT_UNIT_NAME .] IDENTIFIER];
233 -- Task Body end [task_IDENTIFIER];
234 -- Entry Body end [entry_IDENTIFIER];
235 -- Protected Body end [protected_IDENTIFIER]
236 -- Accept Statement end [entry_IDENTIFIER]];
238 -- Note that in the case of accept statements, there can
239 -- be multiple b and t entries for the same entity.
241 -- x is used to identify the reference as the entity from which
242 -- a tagged type is extended. This allows immediate access to
243 -- the parent of a tagged type.
245 -- z is used on the cross-reference line for a generic unit, to
246 -- mark the definition of a generic formal of the unit.
247 -- This entry type is similar to 'k' and 'p' in that it is an
248 -- implicit reference for an entity with a different name.
250 -- The characters >, <. =, and ^ are used on the cross-reference
251 -- line for a subprogram, to denote formal parameters and their
252 -- modes. As with the 'z' and 'p' entries, each such entry is
253 -- an implicit reference to an entity with a different name.
255 -- [..] is used for generic instantiation references. These
256 -- references are present only if the entity in question is
257 -- a generic entity, and in that case the [..] contains the
258 -- reference for the instantiation. In the case of nested
259 -- instantiations, this can be nested [...[...[...]]] etc.
260 -- The reference is of the form [file|line] no column is
261 -- present since it is assumed that only one instantiation
262 -- appears on a single source line. Note that the appearence
263 -- of file numbers in such references follows the normal
264 -- rules (present only if needed, and resets the current
265 -- file for subsequent references).
267 -- Examples:
269 -- 44B5*Flag_Type{boolean} 5r23 6m45 3|9r35 11r56
271 -- This line gives references for the publicly visible Boolean
272 -- type Flag_Type declared on line 44, column 5. There are four
273 -- references
275 -- a reference on line 5, column 23 of the current file
277 -- a modification on line 6, column 45 of the current file
279 -- a reference on line 9, column 35 of unit number 3
281 -- a reference on line 11, column 56 of unit number 3
283 -- 2U13 p3=2:35 5b13 8r4 12r13 12t15
285 -- This line gives references for the non-publicly visible
286 -- procedure p3 declared on line 2, column 13. This procedure
287 -- renames the procedure whose identifier reference is at
288 -- line 2 column 35. There are four references:
290 -- the corresponding body entity at line 5, column 13,
291 -- of the current file.
293 -- a reference (e.g. a call) at line 8 column 4 of the
294 -- of the current file.
296 -- the END line of the body has an explict reference to
297 -- the name of the procedure at line 12, column 13.
299 -- the body ends at line 12, column 15, just past this label.
301 -- 16I9*My_Type<2|4I9> 18r8
303 -- This line gives references for the publicly visible Integer
304 -- derived type My_Type declared on line 16, column 9. It also
305 -- gives references to the parent type declared in the unit
306 -- number 2 on line 4, column 9. There is one reference:
308 -- a reference (e.g. a variable declaration) at line 18 column
309 -- 4 of the current file.
311 -- 10I3*Genv{integer} 3|4I10[6|12]
313 -- This line gives a reference for the entity Genv in a generic
314 -- package. The reference in file 3, line 4, col 10, refers to
315 -- an instance of the generic where the instantiation can be
316 -- found in file 6 at line 12.
318 -- Continuation lines are used if the reference list gets too long,
319 -- a continuation line starts with a period, and then has references
320 -- continuing from the previous line. The references are sorted first
321 -- by unit, then by position in the source.
323 -- Note on handling of generic entities. The cross-reference is oriented
324 -- towards source references, so the entities in a generic instantiation
325 -- are not considered distinct from the entities in the template. All
326 -- definitions and references from generic instantiations are suppressed,
327 -- since they will be generated from the template. Any references to
328 -- entities in a generic instantiation from outside the instantiation
329 -- are considered to be references to the original template entity.
331 ----------------------------------------
332 -- Cross-Reference Entity Identifiers --
333 ----------------------------------------
335 -- In the cross-reference section of the ali file, entity types are
336 -- identified by a single letter, indicating the entity type. The
337 -- following table indicates the letter. A space for an entry is
338 -- used for entities that do not appear in the cross-reference table.
340 -- For objects, the character * appears in this table. In the xref
341 -- listing, this character is replaced by the lower case letter that
342 -- corresponds to the type of the object. For example, if a variable
343 -- is of a Float type, then, since the type is represented by an
344 -- upper case F, the object would be represented by a lower case f.
346 -- A special exception is the case of booleans, whose entities are
347 -- normal E_Enumeration_Type or E_Enumeration_Subtype entities, but
348 -- which appear as B/b in the xref lines, rather than E/e.
350 -- For private types, the character + appears in the table. In this
351 -- case the kind of the underlying type is used, if available, to
352 -- determine the character to use in the xref listing. The listing
353 -- will still include a '+' for a generic private type, for example.
355 -- For subprograms, the characters 'U' and 'V' appear in the table,
356 -- indicating procedures and functions. If the operation is abstract,
357 -- these letters are replaced in the xref by 'x' and 'y' respectively.
359 Xref_Entity_Letters : array (Entity_Kind) of Character := (
360 E_Void => ' ',
361 E_Variable => '*',
362 E_Component => '*',
363 E_Constant => '*',
364 E_Discriminant => '*',
366 E_Loop_Parameter => '*',
367 E_In_Parameter => '*',
368 E_Out_Parameter => '*',
369 E_In_Out_Parameter => '*',
370 E_Generic_In_Out_Parameter => '*',
372 E_Generic_In_Parameter => '*',
373 E_Named_Integer => 'N',
374 E_Named_Real => 'N',
375 E_Enumeration_Type => 'E', -- B for boolean
376 E_Enumeration_Subtype => 'E', -- B for boolean
378 E_Signed_Integer_Type => 'I',
379 E_Signed_Integer_Subtype => 'I',
380 E_Modular_Integer_Type => 'M',
381 E_Modular_Integer_Subtype => 'M',
382 E_Ordinary_Fixed_Point_Type => 'O',
384 E_Ordinary_Fixed_Point_Subtype => 'O',
385 E_Decimal_Fixed_Point_Type => 'D',
386 E_Decimal_Fixed_Point_Subtype => 'D',
387 E_Floating_Point_Type => 'F',
388 E_Floating_Point_Subtype => 'F',
390 E_Access_Type => 'P',
391 E_Access_Subtype => 'P',
392 E_Access_Attribute_Type => 'P',
393 E_Allocator_Type => ' ',
394 E_General_Access_Type => 'P',
396 E_Access_Subprogram_Type => 'P',
397 E_Access_Protected_Subprogram_Type => 'P',
398 E_Anonymous_Access_Type => ' ',
399 E_Array_Type => 'A',
400 E_Array_Subtype => 'A',
402 E_String_Type => 'S',
403 E_String_Subtype => 'S',
404 E_String_Literal_Subtype => ' ',
405 E_Class_Wide_Type => 'C',
407 E_Class_Wide_Subtype => 'C',
408 E_Record_Type => 'R',
409 E_Record_Subtype => 'R',
410 E_Record_Type_With_Private => 'R',
411 E_Record_Subtype_With_Private => 'R',
413 E_Private_Type => '+',
414 E_Private_Subtype => '+',
415 E_Limited_Private_Type => '+',
416 E_Limited_Private_Subtype => '+',
417 E_Incomplete_Type => '+',
419 E_Task_Type => 'T',
420 E_Task_Subtype => 'T',
421 E_Protected_Type => 'W',
422 E_Protected_Subtype => 'W',
423 E_Exception_Type => ' ',
425 E_Subprogram_Type => ' ',
426 E_Enumeration_Literal => 'n',
427 E_Function => 'V',
428 E_Operator => 'V',
429 E_Procedure => 'U',
431 E_Entry => 'Y',
432 E_Entry_Family => 'Y',
433 E_Block => 'q',
434 E_Entry_Index_Parameter => '*',
435 E_Exception => 'X',
437 E_Generic_Function => 'v',
438 E_Generic_Package => 'k',
439 E_Generic_Procedure => 'u',
440 E_Label => 'L',
441 E_Loop => 'l',
443 E_Package => 'K',
445 -- The following entities are not ones to which we gather
446 -- cross-references, since it does not make sense to do so
447 -- (e.g. references to a package are to the spec, not the body)
448 -- Indeed the occurrence of the body entity is considered to
449 -- be a reference to the spec entity.
451 E_Package_Body => ' ',
452 E_Protected_Object => ' ',
453 E_Protected_Body => ' ',
454 E_Task_Body => ' ',
455 E_Subprogram_Body => ' ');
457 -- The following table is for information purposes. It shows the
458 -- use of each character appearing as an entity type.
460 -- letter lower case usage UPPER CASE USAGE
462 -- a array object (except string) array type (except string)
463 -- b Boolean object Boolean type
464 -- c class-wide object class-wide type
465 -- d decimal fixed-point object decimal fixed-point type
466 -- e non-Boolean enumeration object non_Boolean enumeration type
467 -- f floating-point object floating-point type
468 -- g (unused) (unused)
469 -- h (unused) Abstract type
470 -- i signed integer object signed integer type
471 -- j (unused) (unused)
472 -- k generic package package
473 -- l label on loop label on statement
474 -- m modular integer object modular integer type
475 -- n enumeration literal named number
476 -- o ordinary fixed-point object ordinary fixed-point type
477 -- p access object access type
478 -- q label on block (unused)
479 -- r record object record type
480 -- s string object string type
481 -- t task object task type
482 -- u generic procedure procedure
483 -- v generic function or operator function or operator
484 -- w protected object protected type
485 -- x abstract procedure exception
486 -- y abstract function entry or entry family
487 -- z generic formal parameter (unused)
489 --------------------------------------
490 -- Handling of Imported Subprograms --
491 --------------------------------------
493 -- If a pragma Import or Interface applies to a subprogram, the
494 -- pragma is the completion of the subprogram. This is noted in
495 -- the ALI file by making the occurrence of the subprogram in the
496 -- pragma into a body reference ('b') and by including the external
497 -- name of the subprogram and its language, bracketed by '<' and '>'
498 -- in that reference. For example:
500 -- 3U13*elsewhere 4b<c,there>21
502 -- indicates that procedure elsewhere, declared at line 3, has a
503 -- pragma Import at line 4, that its body is in C, and that the link
504 -- name as given in the pragma is "there".
506 -----------------
507 -- Subprograms --
508 -----------------
510 procedure Generate_Definition (E : Entity_Id);
511 -- Records the definition of an entity
513 procedure Generate_Operator_Reference
514 (N : Node_Id;
515 T : Entity_Id);
516 -- Node N is an operator node, whose entity has been set. If this entity
517 -- is a user defined operator (i.e. an operator not defined in package
518 -- Standard), then a reference to the operator is recorded at node N.
519 -- T is the operand type of of the operator. A reference to the operator
520 -- is an implicit reference to the type, and that needs to be recorded
521 -- to avoid spurious warnings on unused entities, when the operator is
522 -- a renaming of a predefined operator.
524 procedure Generate_Reference
525 (E : Entity_Id;
526 N : Node_Id;
527 Typ : Character := 'r';
528 Set_Ref : Boolean := True;
529 Force : Boolean := False);
530 -- This procedure is called to record a reference. N is the location
531 -- of the reference and E is the referenced entity. Typ is one of:
533 -- 'b' body entity
534 -- 'c' completion of incomplete or private type (see below)
535 -- 'e' end of construct
536 -- 'i' implicit reference
537 -- 'l' label on end line
538 -- 'm' modification
539 -- 'p' primitive operation
540 -- 'r' standard reference
541 -- 't' end of body
542 -- 'x' type extension
543 -- ' ' dummy reference (see below)
545 -- Note: all references to incomplete or private types are to the
546 -- original (incomplete or private type) declaration. The full
547 -- declaration is treated as a reference with type 'c'.
549 -- Note: all references to packages or subprograms are to the entity
550 -- for the spec. The entity in the body is treated as a reference
551 -- with type 'b'. Similar handling for references to subprogram formals.
553 -- The call has no effect if N is not in the extended main source unit
554 -- This check is omitted for type 'e' references (where it is useful to
555 -- have structural scoping information for other than the main source),
556 -- and for 'p' (since we want to pick up inherited primitive operations
557 -- that are defined in other packages).
559 -- The call also has no effect if any of the following conditions hold:
561 -- cross-reference collection is disabled
562 -- entity does not come from source (and Force is False)
563 -- reference does not come from source (and Force is False)
564 -- the entity is not one for which xrefs are appropriate
565 -- the type letter is blank
566 -- the node N is not an identifier, defining identifier, or expanded name
567 -- the type is 'p' and the entity is not in the extended main source
569 -- If all these conditions are met, then the Is_Referenced flag of E
570 -- is set (unless Set_Ref is False) and a cross-reference entry is
571 -- recorded for later output when Output_References is called.
573 -- Note: the dummy space entry is for the convenience of some callers,
574 -- who find it easier to pass a space to suppress the entry than to do
575 -- a specific test. The call has no effect if the type is a space.
577 -- The parameter Set_Ref is normally True, and indicates that in
578 -- addition to generating a cross-reference, the Referenced flag
579 -- of the specified entity should be set. If this parameter is
580 -- False, then setting of the Referenced flag is inhibited.
582 -- The parameter Force is set to True to force a reference to be
583 -- generated even if Comes_From_Source is false. This is used for
584 -- certain implicit references, and also for end label references.
586 procedure Generate_Reference_To_Formals (E : Entity_Id);
587 -- Add a reference to the definition of each formal on the line for
588 -- a subprogram.
590 procedure Generate_Reference_To_Generic_Formals (E : Entity_Id);
591 -- Add a reference to the definition of each generic formal on the line
592 -- for a generic unit.
594 procedure Output_References;
595 -- Output references to the current ali file
597 procedure Initialize;
598 -- Initialize internal tables.
600 end Lib.Xref;