OSDN Git Service

* objc/objc-act.c (UTAG_STATICS, UTAG_PROTOCOL_LIST, USERTYPE):
[pf3gnuchains/gcc-fork.git] / gcc / ada / lib-xref.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                             L I B . X R E F                              --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --                                                                          --
10 --          Copyright (C) 1998-2002, Free Software Foundation, Inc.         --
11 --                                                                          --
12 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
13 -- terms of the  GNU General Public License as published  by the Free Soft- --
14 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
15 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
18 -- for  more details.  You should have  received  a copy of the GNU General --
19 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
20 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
21 -- MA 02111-1307, USA.                                                      --
22 --                                                                          --
23 -- GNAT was originally developed  by the GNAT team at  New York University. --
24 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
25 --                                                                          --
26 ------------------------------------------------------------------------------
27
28 --  This package contains for collecting and outputting cross-reference
29 --  information.
30
31 with Einfo; use Einfo;
32 with Types; use Types;
33
34 package Lib.Xref is
35
36    -------------------------------------------------------
37    -- Format of Cross-Reference Information in ALI File --
38    -------------------------------------------------------
39
40    --  Cross-reference sections follow the dependency section (D lines) in
41    --  an ALI file, so that they need not be read by gnatbind, gnatmake etc.
42
43    --  A cross reference section has a header of the form
44
45    --     X  dependency-number  filename
46
47    --        This header precedes xref information (entities/references from
48    --        the unit, identified by dependency number and file name. The
49    --        dependency number is the index into the generated D lines and
50    --        is ones origin (i.e. 2 = reference to second generated D line).
51
52    --        Note that the filename here will reflect the original name if
53    --        a Source_Reference pragma was encountered (since all line number
54    --        references will be with respect to the original file).
55
56    --  The lines following the header look like
57
58    --     line type col level entity renameref typeref ref  ref  ref
59
60    --        line is the line number of the referenced entity. The name of
61    --        the entity starts in column col. Columns are numbered from one,
62    --        and if horizontal tab characters are present, the column number
63    --        is computed assuming standard 1,9,17,.. tab stops. For example,
64    --        if the entity is the first token on the line, and is preceded
65    --        by space-HT-space, then the column would be column 10.
66
67    --        type is a single letter identifying the type of the entity.
68    --        See next section (Cross-Reference Entity Identifiers) for a
69    --        full list of the characters used).
70
71    --        col is the column number of the referenced entity
72
73    --        level is a single character that separates the col and
74    --        entity fields. It is an asterisk for a top level library
75    --        entity that is publicly visible, and space otherwise.
76
77    --        entity is the name of the referenced entity, with casing in
78    --        the canical casing for the source file where it is defined.
79
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:
85
86    --            =line:col
87
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.
95
96    --        typeref is the reference for a related type. This part is
97    --        optional. It is present for the following cases:
98
99    --          derived types (points to the parent type)   LR=<>
100    --          access types (points to designated type)    LR=()
101    --          subtypes (points to ancestor type)          LR={}
102    --          functions (points to result type)           LR={}
103    --          enumeration literals (points to enum type)  LR={}
104    --          objects and components (points to type)     LR={}
105
106    --          In the above list LR shows the brackets used in the output,
107    --          which has one of the two following forms:
108
109    --            L file | line type col R      user entity
110    --            L name-in-lower-case   R      standard entity
111
112    --          For the form for a user entity, file is the dependency number
113    --          of the file containing the declaration of the related type.
114    --          This number and the following vertical bar are omitted if the
115    --          relevant type is defined in the same file as the current entity.
116    --          The line, type, col are defined as previously described, and
117    --          specify the location of the relevant type declaration in the
118    --          referenced file. For the standard entity form, the name between
119    --          the brackets is the normal name of the entity in lower case.
120
121    --     There may be zero or more ref entries on each line
122
123    --        file | line type col [...]
124
125    --           file is the dependency number of the file with the reference.
126    --           It and the following vertical bar are omitted if the file is
127    --           the same as the previous ref, and the refs for the current
128    --           file are first (and do not need a bar).
129
130    --           line is the line number of the reference
131
132    --           col is the column number of the reference, as defined above.
133
134    --           type is one of
135    --              b = body entity
136    --              c = completion of private or incomplete type
137    --              e = end of spec
138    --              i = implicit reference
139    --              l = label on end line
140    --              m = modification
141    --              p = primitive operation
142    --              r = reference
143    --              t = end of body
144    --              x = type extension
145
146    --           b is used for spec entities that are repeated in a body,
147    --           including the unit (subprogram, package, task, protected
148    --           body, protected entry) name itself, and in the case of a
149    --           subprogram, the formals. This letter is also used for the
150    --           occurrence of entry names in accept statements. Such entities
151    --           are not considered to be definitions for cross-referencing
152    --           purposes, but rather are considered to be references to the
153    --           corresponding spec entities, marked with this special type.
154
155    --           c is similar to b but is used to mark the completion of a
156    --           private or incomplete type. As with b, the completion is not
157    --           regarded as a separate definition, but rather a reference to
158    --           the initial declaration, marked with this special type.
159
160    --           e is used to identify the end of a construct in the following
161    --           cases:
162
163    --             Block Statement        end [block_IDENTIFIER];
164    --             Loop Statement         end loop [loop_IDENTIFIER];
165    --             Package Specification  end [[PARENT_UNIT_NAME .] IDENTIFIER];
166    --             Task Definition        end [task_IDENTIFIER];
167    --             Protected Definition   end [protected_IDENTIFIER];
168    --             Record Definition      end record;
169    --             Enumeration Definition );
170
171    --           Note that 'e' entries are special in that they appear even
172    --           in referencing units (normally xref entries appear only
173    --           for references in the extended main source unit (see Lib) to
174    --           which the ali applies. But 'e' entries are really structural
175    --           and simply indicate where packages end. This information can
176    --           be used to reconstruct scope information for any entities
177    --           referenced from within the package. The line/column values
178    --           for these entries point to the semicolon ending the construct.
179
180    --           i is used to identify a reference to the entity in a generic
181    --           actual or in a default in a call. The node that denotes the
182    --           entity does not come from source, but it has the Sloc of the
183    --           source node that generates the implicit reference, and it is
184    --           useful to record this one.
185
186    --           l is used to identify the occurrence in the source of the
187    --           name on an end line. This is just a syntactic reference
188    --           which can be ignored for semantic purposes (such as call
189    --           graph construction). Again, in the case of an accept there
190    --           can be multiple l lines.
191
192    --           p is used to mark a primitive operation of the given entity.
193    --           For example, if we have a type Tx, and a primitive operation
194    --           Pq of this type, then an entry in the list of references to
195    --           Tx will point to the declaration of Pq. Note that this entry
196    --           type is unusual because it an implicit rather than explicit,
197    --           and the name of the refrerence does not match the name of the
198    --           entity for which a reference is generated. These entries are
199    --           generated only for entities declared in the extended main
200    --           source unit (main unit itself, its separate spec (if any).
201    --           and all subunits (considered recursively).
202
203    --           t is similar to e. It identifies the end of a corresponding
204    --           body (such a reference always links up with a b reference)
205
206    --             Subprogram Body        end [DESIGNATOR];
207    --             Package Body           end [[PARENT_UNIT_NAME .] IDENTIFIER];
208    --             Task Body              end [task_IDENTIFIER];
209    --             Entry Body             end [entry_IDENTIFIER];
210    --             Protected Body         end [protected_IDENTIFIER]
211    --             Accept Statement       end [entry_IDENTIFIER]];
212
213    --           Note that in the case of accept statements, there can
214    --           be multiple b and t entries for the same entity.
215
216    --           x is used to identify the reference as the entity from which
217    --           a tagged type is extended. This allows immediate access to
218    --           the parent of a tagged type.
219
220    --           [..] is used for generic instantiation references. These
221    --           references are present only if the entity in question is
222    --           a generic entity, and in that case the [..] contains the
223    --           reference for the instantiation. In the case of nested
224    --           instantiations, this can be nested [...[...[...]]] etc.
225    --           The reference is of the form [file|line] no column is
226    --           present since it is assumed that only one instantiation
227    --           appears on a single source line. Note that the appearence
228    --           of file numbers in such references follows the normal
229    --           rules (present only if needed, and resets the current
230    --           file for subsequent references).
231
232    --     Examples:
233
234    --        44B5*Flag_Type{boolean} 5r23 6m45 3|9r35 11r56
235
236    --           This line gives references for the publicly visible Boolean
237    --           type Flag_Type declared on line 44, column 5. There are four
238    --           references
239
240    --              a reference on line 5, column 23 of the current file
241
242    --              a modification on line 6, column 45 of the current file
243
244    --              a reference on line 9, column 35 of unit number 3
245
246    --              a reference on line 11, column 56 of unit number 3
247
248    --        2U13 p3=2:35 5b13 8r4 12r13 12t15
249
250    --           This line gives references for the non-publicly visible
251    --           procedure p3 declared on line 2, column 13. This procedure
252    --           renames the procedure whose identifier reference is at
253    --           line 2 column 35. There are four references:
254
255    --              the corresponding body entity at line 5, column 13,
256    --              of the current file.
257
258    --              a reference (e.g. a call) at line 8 column 4 of the
259    --              of the current file.
260
261    --              the END line of the body has an explict reference to
262    --              the name of the procedure at line 12, column 13.
263
264    --              the body ends at line 12, column 15, just past this label.
265
266    --        16I9*My_Type<2|4I9> 18r8
267
268    --           This line gives references for the publicly visible Integer
269    --           derived type My_Type declared on line 16, column 9. It also
270    --           gives references to the parent type declared in the unit
271    --           number 2 on line 4, column 9. There is one reference:
272
273    --              a reference (e.g. a variable declaration) at line 18 column
274    --              4 of the current file.
275
276    --        10I3*Genv{integer} 3|4I10[6|12]
277
278    --           This line gives a reference for the entity Genv in a generic
279    --           package. The reference in file 3, line 4, col 10, refers to
280    --           an instance of the generic where the instantiation can be
281    --           found in file 6 at line 12.
282
283    --  Continuation lines are used if the reference list gets too long,
284    --  a continuation line starts with a period, and then has references
285    --  continuing from the previous line. The references are sorted first
286    --  by unit, then by position in the source.
287
288    --  Note on handling of generic entities. The cross-reference is oriented
289    --  towards source references, so the entities in a generic instantiation
290    --  are not considered distinct from the entities in the template. All
291    --  definitions and references from generic instantiations are suppressed,
292    --  since they will be generated from the template. Any references to
293    --  entities in a generic instantiation from outside the instantiation
294    --  are considered to be references to the original template entity.
295
296    ----------------------------------------
297    -- Cross-Reference Entity Identifiers --
298    ----------------------------------------
299
300    --  In the cross-reference section of the ali file, entity types are
301    --  identified by a single letter, indicating the entity type. The
302    --  following table indicates the letter. A space for an entry is
303    --  used for entities that do not appear in the cross-reference table.
304
305    --  For objects, the character * appears in this table. In the xref
306    --  listing, this character is replaced by the lower case letter that
307    --  corresponds to the type of the object. For example, if a variable
308    --  is of a Float type, then, since the type is represented by an
309    --  upper case F, the object would be represented by a lower case f.
310
311    --  A special exception is the case of booleans, whose entities are
312    --  normal E_Enumeration_Type or E_Enumeration_Subtype entities, but
313    --  which appear as B/b in the xref lines, rather than E/e.
314
315    --  For private types, the character + appears in the table. In this
316    --  case the kind of the underlying type is used, if available, to
317    --  determine the character to use in the xref listing. The listing
318    --  will still include a '+' for a generic private type, for example.
319
320    Xref_Entity_Letters : array (Entity_Kind) of Character := (
321       E_Void                             => ' ',
322       E_Variable                         => '*',
323       E_Component                        => '*',
324       E_Constant                         => '*',
325       E_Discriminant                     => '*',
326
327       E_Loop_Parameter                   => '*',
328       E_In_Parameter                     => '*',
329       E_Out_Parameter                    => '*',
330       E_In_Out_Parameter                 => '*',
331       E_Generic_In_Out_Parameter         => '*',
332
333       E_Generic_In_Parameter             => '*',
334       E_Named_Integer                    => 'N',
335       E_Named_Real                       => 'N',
336       E_Enumeration_Type                 => 'E',  -- B for boolean
337       E_Enumeration_Subtype              => 'E',  -- B for boolean
338
339       E_Signed_Integer_Type              => 'I',
340       E_Signed_Integer_Subtype           => 'I',
341       E_Modular_Integer_Type             => 'M',
342       E_Modular_Integer_Subtype          => 'M',
343       E_Ordinary_Fixed_Point_Type        => 'O',
344
345       E_Ordinary_Fixed_Point_Subtype     => 'O',
346       E_Decimal_Fixed_Point_Type         => 'D',
347       E_Decimal_Fixed_Point_Subtype      => 'D',
348       E_Floating_Point_Type              => 'F',
349       E_Floating_Point_Subtype           => 'F',
350
351       E_Access_Type                      => 'P',
352       E_Access_Subtype                   => 'P',
353       E_Access_Attribute_Type            => 'P',
354       E_Allocator_Type                   => ' ',
355       E_General_Access_Type              => 'P',
356
357       E_Access_Subprogram_Type           => 'P',
358       E_Access_Protected_Subprogram_Type => 'P',
359       E_Anonymous_Access_Type            => ' ',
360       E_Array_Type                       => 'A',
361       E_Array_Subtype                    => 'A',
362
363       E_String_Type                      => 'S',
364       E_String_Subtype                   => 'S',
365       E_String_Literal_Subtype           => ' ',
366       E_Class_Wide_Type                  => 'C',
367
368       E_Class_Wide_Subtype               => 'C',
369       E_Record_Type                      => 'R',
370       E_Record_Subtype                   => 'R',
371       E_Record_Type_With_Private         => 'R',
372       E_Record_Subtype_With_Private      => 'R',
373
374       E_Private_Type                     => '+',
375       E_Private_Subtype                  => '+',
376       E_Limited_Private_Type             => '+',
377       E_Limited_Private_Subtype          => '+',
378       E_Incomplete_Type                  => '+',
379
380       E_Task_Type                        => 'T',
381       E_Task_Subtype                     => 'T',
382       E_Protected_Type                   => 'W',
383       E_Protected_Subtype                => 'W',
384       E_Exception_Type                   => ' ',
385
386       E_Subprogram_Type                  => ' ',
387       E_Enumeration_Literal              => 'n',
388       E_Function                         => 'V',
389       E_Operator                         => 'V',
390       E_Procedure                        => 'U',
391
392       E_Entry                            => 'Y',
393       E_Entry_Family                     => 'Y',
394       E_Block                            => 'q',
395       E_Entry_Index_Parameter            => '*',
396       E_Exception                        => 'X',
397
398       E_Generic_Function                 => 'v',
399       E_Generic_Package                  => 'k',
400       E_Generic_Procedure                => 'u',
401       E_Label                            => 'L',
402       E_Loop                             => 'l',
403
404       E_Package                          => 'K',
405
406       --  The following entities are not ones to which we gather
407       --  cross-references, since it does not make sense to do so
408       --  (e.g. references to a package are to the spec, not the body)
409       --  Indeed the occurrence of the body entity is considered to
410       --  be a reference to the spec entity.
411
412       E_Package_Body                     => ' ',
413       E_Protected_Object                 => ' ',
414       E_Protected_Body                   => ' ',
415       E_Task_Body                        => ' ',
416       E_Subprogram_Body                  => ' ');
417
418    --  The following table is for information purposes. It shows the
419    --  use of each character appearing as an entity type.
420
421    --  letter  lower case usage                UPPER CASE USAGE
422
423    --    a     array object (except string)    array type (except string)
424    --    b     Boolean object                  Boolean type
425    --    c     class-wide object               class-wide type
426    --    d     decimal fixed-point object      decimal fixed-point type
427    --    e     non-Boolean enumeration object  non_Boolean enumeration type
428    --    f     floating-point object           floating-point type
429    --    g     (unused)                        (unused)
430    --    h     (unused)                        (unused)
431    --    i     signed integer object           signed integer type
432    --    j     (unused)                        (unused)
433    --    k     generic package                 package
434    --    l     label on loop                   label on statement
435    --    m     modular integer object          modular integer type
436    --    n     enumeration literal             named number
437    --    o     ordinary fixed-point object     ordinary fixed-point type
438    --    p     access object                   access type
439    --    q     label on block                  (unused)
440    --    r     record object                   record type
441    --    s     string object                   string type
442    --    t     task object                     task type
443    --    u     generic procedure               procedure
444    --    v     generic function or operator    function or operator
445    --    w     protected object                protected type
446    --    x     (unused)                        exception
447    --    y     (unused)                        entry or entry family
448    --    z     (unused)                        (unused)
449
450    -----------------
451    -- Subprograms --
452    -----------------
453
454    procedure Generate_Definition (E : Entity_Id);
455    --  Records the definition of an entity
456
457    procedure Generate_Operator_Reference (N : Node_Id);
458    --  Node N is an operator node, whose entity has been set. If this entity
459    --  is a user defined operator (i.e. an operator not defined in package
460    --  Standard), then a reference to the operator is recorded at node N.
461
462    procedure Generate_Reference
463      (E       : Entity_Id;
464       N       : Node_Id;
465       Typ     : Character := 'r';
466       Set_Ref : Boolean   := True;
467       Force   : Boolean   := False);
468    --  This procedure is called to record a reference. N is the location
469    --  of the reference and E is the referenced entity. Typ is one of:
470    --
471    --    'b'  body entity
472    --    'c'  completion of incomplete or private type (see below)
473    --    'e'  end of construct
474    --    'i'  implicit reference
475    --    'l'  label on end line
476    --    'm'  modification
477    --    'p'  primitive operation
478    --    'r'  standard reference
479    --    't'  end of body
480    --    'x'  type extension
481    --    ' '  dummy reference (see below)
482    --
483    --  Note: all references to incomplete or private types are to the
484    --  original (incomplete or private type) declaration. The full
485    --  declaration is treated as a reference with type 'c'.
486    --
487    --  Note: all references to packages or subprograms are to the entity
488    --  for the spec. The entity in the body is treated as a reference
489    --  with type 'b'. Similar handling for references to subprogram formals.
490    --
491    --  The call has no effect if N is not in the extended main source unit
492    --  This check is omitted for type 'e' references (where it is useful to
493    --  have structural scoping information for other than the main source),
494    --  and for 'p' (since we want to pick up inherited primitive operations
495    --  that are defined in other packages).
496    --
497    --  The call also has no effect if any of the following conditions hold:
498    --
499    --    cross-reference collection is disabled
500    --    entity does not come from source (and Force is False)
501    --    reference does not come from source (and Force is False)
502    --    the entity is not one for which xrefs are appropriate
503    --    the type letter is blank
504    --    the node N is not an identifier, defining identifier, or expanded name
505    --    the type is 'p' and the entity is not in the extended main source
506    --
507    --  If all these conditions are met, then the Is_Referenced flag of E
508    --  is set (unless Set_Ref is False) and a cross-reference entry is
509    --  recorded for later output when Output_References is called.
510    --
511    --  Note: the dummy space entry is for the convenience of some callers,
512    --  who find it easier to pass a space to suppress the entry than to do
513    --  a specific test. The call has no effect if the type is a space.
514    --
515    --  The parameter Set_Ref is normally True, and indicates that in
516    --  addition to generating a cross-reference, the Referenced flag
517    --  of the specified entity should be set. If this parameter is
518    --  False, then setting of the Referenced flag is inhibited.
519    --
520    --  The parameter Force is set to True to force a reference to be
521    --  generated even if Comes_From_Source is false. This is used for
522    --  certain implicit references, and also for end label references.
523
524    procedure Output_References;
525    --  Output references to the current ali file
526
527 end Lib.Xref;