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