OSDN Git Service

2005-11-14 Robert Dewar <dewar@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / ali.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                                  A L I                                   --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --          Copyright (C) 1992-2005, Free Software Foundation, Inc.         --
10 --                                                                          --
11 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
12 -- terms of the  GNU General Public License as published  by the Free Soft- --
13 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
14 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
17 -- for  more details.  You should have  received  a copy of the GNU General --
18 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
19 -- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
20 -- Boston, MA 02110-1301, USA.                                              --
21 --                                                                          --
22 -- GNAT was originally developed  by the GNAT team at  New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
24 --                                                                          --
25 ------------------------------------------------------------------------------
26
27 --  This package defines the internal data structures used for representation
28 --  of Ada Library Information (ALI) acquired from the ALI files generated
29 --  by the front end.
30
31 with Casing;  use Casing;
32 with Gnatvsn; use Gnatvsn;
33 with Rident;  use Rident;
34 with Table;
35 with Types;   use Types;
36
37 with GNAT.HTable; use GNAT.HTable;
38
39 package ALI is
40
41    --------------
42    -- Id Types --
43    --------------
44
45    --  The various entries are stored in tables with distinct subscript
46    --  ranges. The following type definitions indicate the ranges used
47    --  for the subscripts (Id values) for the various tables.
48
49    type ALI_Id is range 0 .. 999_999;
50    --  Id values used for ALIs table entries
51
52    type Unit_Id is range 1_000_000 .. 1_999_999;
53    --  Id values used for Unit table entries
54
55    type With_Id is range 2_000_000 .. 2_999_999;
56    --  Id values used for Withs table entries
57
58    type Arg_Id is range 3_000_000 .. 3_999_999;
59    --  Id values used for argument table entries
60
61    type Sdep_Id is range 4_000_000 .. 4_999_999;
62    --  Id values used for Sdep table entries
63
64    type Source_Id is range 5_000_000 .. 5_999_999;
65    --  Id values used for Source table entries
66
67    type Interrupt_State_Id is range 6_000_000 .. 6_999_999;
68    --  Id values used for Interrupt_State table entries
69
70    --------------------
71    -- ALI File Table --
72    --------------------
73
74    --  Each ALI file read generates an entry in the ALIs table
75
76    No_ALI_Id : constant ALI_Id := ALI_Id'First;
77    --  Special value indicating no ALI entry
78
79    First_ALI_Entry : constant ALI_Id := No_ALI_Id + 1;
80    --  Id of first actual entry in table
81
82    type Main_Program_Type is (None, Proc, Func);
83    --  Indicator of whether unit can be used as main program
84
85    type ALIs_Record is record
86
87       Afile : File_Name_Type;
88       --  Name of ALI file
89
90       Ofile_Full_Name : Name_Id;
91       --  Full name of object file corresponding to the ALI file
92
93       Sfile : File_Name_Type;
94       --  Name of source file that generates this ALI file (which is equal
95       --  to the name of the source file in the first unit table entry for
96       --  this ALI file, since the body if present is always first).
97
98       Ver : String (1 .. Ver_Len_Max);
99       --  Value of library version (V line in ALI file). Not set if
100       --  V lines are ignored as a result of the Ignore_Lines parameter.
101
102       Ver_Len : Natural;
103       --  Length of characters stored in Ver. Not set if V lines are
104       --  ignored as a result of the Ignore_Lines parameter.
105
106       SAL_Interface : Boolean;
107       --  Set True when this is an interface to a standalone library
108
109       First_Unit : Unit_Id;
110       --  Id of first Unit table entry for this file
111
112       Last_Unit : Unit_Id;
113       --  Id of last Unit table entry for this file
114
115       First_Sdep : Sdep_Id;
116       --  Id of first Sdep table entry for this file
117
118       Last_Sdep : Sdep_Id;
119       --  Id of last Sdep table entry for this file
120
121       Main_Program : Main_Program_Type;
122       --  Indicator of whether first unit can be used as main program.
123       --  Not set if 'M' appears in Ignore_Lines.
124
125       Main_Priority : Int;
126       --  Indicates priority value if Main_Program field indicates that
127       --  this can be a main program. A value of -1 (No_Main_Priority)
128       --  indicates that no parameter was found, or no M line was present.
129       --  Not set if 'M' appears in Ignore_Lines.
130
131       Time_Slice_Value : Int;
132       --  Indicates value of time slice parameter from T=xxx on main program
133       --  line. A value of -1 indicates that no T=xxx parameter was found,
134       --  or no M line was present.
135       --  Not set if 'M' appears in Ignore_Lines.
136
137       WC_Encoding : Character;
138       --  Wide character encoding if main procedure. Otherwise not relevant.
139       --  Not set if 'M' appears in Ignore_Lines.
140
141       Locking_Policy : Character;
142       --  Indicates locking policy for units in this file. Space means
143       --  tasking was not used, or that no Locking_Policy pragma was
144       --  present or that this is a language defined unit. Otherwise set
145       --  to first character (upper case) of policy name.
146       --  Not set if 'P' appears in Ignore_Lines.
147
148       Queuing_Policy : Character;
149       --  Indicates queuing policy for units in this file. Space means
150       --  tasking was not used, or that no Queuing_Policy pragma was
151       --  present or that this is a language defined unit. Otherwise set
152       --  to first character (upper case) of policy name.
153       --  Not set if 'P' appears in Ignore_Lines.
154
155       Task_Dispatching_Policy : Character;
156       --  Indicates task dispatching policy for units in this file. Space
157       --  means tasking was not used, or that no Task_Dispatching_Policy
158       --  pragma was present or that this is a language defined unit.
159       --  Otherwise set to first character (upper case) of policy name.
160       --  Not set if 'P' appears in Ignore_Lines.
161
162       Compile_Errors : Boolean;
163       --  Set to True if compile errors for unit. Note that No_Object
164       --  will always be set as well in this case.
165       --  Not set if 'P' appears in Ignore_Lines.
166
167       Float_Format : Character;
168       --  Set to float format (set to I if no float-format given).
169       --  Not set if 'P' appears in Ignore_Lines.
170
171       No_Object : Boolean;
172       --  Set to True if no object file generated.
173       --  Not set if 'P' appears in Ignore_Lines.
174
175       Normalize_Scalars : Boolean;
176       --  Set to True if file was compiled with Normalize_Scalars.
177       --  Not set if 'P' appears in Ignore_Lines.
178
179       Unit_Exception_Table : Boolean;
180       --  Set to True if unit exception table pointer generated.
181       --  Not set if 'P' appears in Ignore_Lines.
182
183       Zero_Cost_Exceptions : Boolean;
184       --  Set to True if file was compiled with zero cost exceptions.
185       --  Not set if 'P' appears in Ignore_Lines.
186
187       Restrictions : Restrictions_Info;
188       --  Restrictions information reconstructed from R lines
189
190       First_Interrupt_State : Interrupt_State_Id;
191       Last_Interrupt_State  : Interrupt_State_Id'Base;
192       --  These point to the first and last entries in the interrupt
193       --  state table for this unit. If there are no entries, then
194       --  Last_Interrupt_State = First_Interrupt_State - 1 (that's
195       --  why the 'Base reference is there, it can be one less than
196       --  the lower bound of the subtype).
197       --  Not set if 'I' appears in Ignore_Lines
198
199    end record;
200
201    No_Main_Priority : constant Int := -1;
202    --  Code for no main priority set
203
204    package ALIs is new Table.Table (
205      Table_Component_Type => ALIs_Record,
206      Table_Index_Type     => ALI_Id,
207      Table_Low_Bound      => First_ALI_Entry,
208      Table_Initial        => 500,
209      Table_Increment      => 200,
210      Table_Name           => "ALIs");
211
212    ----------------
213    -- Unit Table --
214    ----------------
215
216    --  Each unit within an ALI file generates an entry in the unit table
217
218    No_Unit_Id : constant Unit_Id := Unit_Id'First;
219    --  Special value indicating no unit table entry
220
221    First_Unit_Entry : constant Unit_Id := No_Unit_Id + 1;
222    --  Id of first actual entry in table
223
224    type Unit_Type is (Is_Spec, Is_Body, Is_Spec_Only, Is_Body_Only);
225    --  Indicates type of entry, if both body and spec appear in the ALI file,
226    --  then the first unit is marked Is_Body, and the second is marked Is_Spec.
227    --  If only a spec appears, then it is marked as Is_Spec_Only, and if only
228    --  a body appears, then it is marked Is_Body_Only).
229
230    subtype Version_String is String (1 .. 8);
231    --  Version string, taken from unit record
232
233    type Unit_Record is record
234
235       My_ALI : ALI_Id;
236       --  Corresponding ALI entry
237
238       Uname : Unit_Name_Type;
239       --  Name of Unit
240
241       Sfile : File_Name_Type;
242       --  Name of source file
243
244       Preelab : Boolean;
245       --  Indicates presence of PR parameter for a preelaborated package
246
247       No_Elab : Boolean;
248       --  Indicates presence of NE parameter for a unit that has does not
249       --  have an elaboration routine (since it has no elaboration code).
250
251       Pure : Boolean;
252       --  Indicates presence of PU parameter for a pure package
253
254       Dynamic_Elab : Boolean;
255       --  Set to True if the unit was compiled with dynamic elaboration
256       --  checks (i.e. either -gnatE or pragma Elaboration_Checks (RM)
257       --  was used to compile the unit).
258
259       Elaborate_Body : Boolean;
260       --  Indicates presence of EB parameter for a package which has a
261       --  pragma Preelaborate_Body.
262
263       Set_Elab_Entity : Boolean;
264       --  Indicates presence of EE parameter for a unit which has an
265       --  elaboration entity which must be set true as part of the
266       --  elaboration of the entity.
267
268       Has_RACW : Boolean;
269       --  Indicates presence of RA parameter for a package that declares
270       --  at least one Remote Access to Class_Wide (RACW) object.
271
272       Remote_Types : Boolean;
273       --  Indicates presence of RT parameter for a package which has a
274       --  pragma Remote_Types.
275
276       Shared_Passive : Boolean;
277       --  Indicates presence of SP parameter for a package which has a
278       --  pragma Shared_Passive.
279
280       RCI : Boolean;
281       --  Indicates presence of RC parameter for a package which has a
282       --  pragma Remote_Call_Interface.
283
284       Predefined : Boolean;
285       --  Indicates if unit is language predefined (or a child of such a unit)
286
287       Internal : Boolean;
288       --  Indicates if unit is an internal unit (or a child of such a unit)
289
290       First_With : With_Id;
291       --  Id of first withs table entry for this file
292
293       Last_With : With_Id;
294       --  Id of last withs table entry for this file
295
296       First_Arg : Arg_Id;
297       --  Id of first args table entry for this file
298
299       Last_Arg : Arg_Id;
300       --  Id of last args table entry for this file
301
302       Utype : Unit_Type;
303       --  Type of entry
304
305       Is_Generic : Boolean;
306       --  True for generic unit (i.e. a generic declaration, or a generic
307       --  body). False for a non-generic unit.
308
309       Unit_Kind : Character;
310       --  Indicates the nature of the unit. 'p' for Packages and 's' for
311       --  subprograms.
312
313       Version : Version_String;
314       --  Version of unit
315
316       Icasing : Casing_Type;
317       --  Indicates casing of identifiers in source file for this unit. This
318       --  is used for informational output, and also for constructing the
319       --  main unit if it is being built in Ada.
320
321       Kcasing : Casing_Type;
322       --  Indicates casing of keyowords in source file for this unit. This
323       --  is used for informational output, and also for constructing the
324       --  main unit if it is being built in Ada.
325
326       Elab_Position : aliased Natural;
327       --  Initialized to zero. Set non-zero when a unit is chosen and
328       --  placed in the elaboration order. The value represents the
329       --  ordinal position in the elaboration order.
330
331       Init_Scalars : Boolean;
332       --  Set True if IS qualifier appears in ALI file, indicating that
333       --  an Initialize_Scalars pragma applies to the unit.
334
335       SAL_Interface : Boolean;
336       --  Set True when this is an interface to a standalone library
337
338       Body_Needed_For_SAL : Boolean;
339       --  Indicates that the source for the body of the unit (subprogram,
340       --  package, or generic unit) must be included in a standalone library.
341    end record;
342
343    package Units is new Table.Table (
344      Table_Component_Type => Unit_Record,
345      Table_Index_Type     => Unit_Id,
346      Table_Low_Bound      => First_Unit_Entry,
347      Table_Initial        => 100,
348      Table_Increment      => 200,
349      Table_Name           => "Unit");
350
351    ---------------------------
352    -- Interrupt State Table --
353    ---------------------------
354
355    --  An entry is made in this table for each I (interrupt state) line
356    --  encountered in the input ALI file. The First/Last_Interrupt_Id
357    --  fields of the ALI file entry show the range of entries defined
358    --  within a particular ALI file.
359
360    type Interrupt_State_Record is record
361       Interrupt_Id : Nat;
362       --  Id from interrupt state entry
363
364       Interrupt_State : Character;
365       --  State from interrupt state entry ('u'/'r'/'s')
366
367       IS_Pragma_Line : Nat;
368       --  Line number of Interrupt_State pragma
369    end record;
370
371    package Interrupt_States is new Table.Table (
372      Table_Component_Type => Interrupt_State_Record,
373      Table_Index_Type     => Interrupt_State_Id'Base,
374      Table_Low_Bound      => Interrupt_State_Id'First,
375      Table_Initial        => 100,
376      Table_Increment      => 200,
377      Table_Name           => "Interrupt_States");
378
379    --------------
380    -- Switches --
381    --------------
382
383    --  These switches record status information about ali files that
384    --  have been read, for quick reference without searching tables.
385
386    --  Note: a switch will be left set at its default value if the line
387    --  which might otherwise set it is ignored (from Ignore_Lines).
388
389    Dynamic_Elaboration_Checks_Specified : Boolean := False;
390    --  Set to False by Initialize_ALI. Set to True if Scan_ALI reads
391    --  a unit for which dynamic elaboration checking is enabled.
392
393    Float_Format_Specified : Character := ' ';
394    --  Set to blank by Initialize_ALI. Set to appropriate float format
395    --  character (V or I, see Opt.Float_Format) if an an ali file that
396    --  is read contains an F line setting the floating point format.
397
398    Initialize_Scalars_Used : Boolean := False;
399    --  Set True if an ali file contains the Initialize_Scalars flag
400
401    Locking_Policy_Specified : Character := ' ';
402    --  Set to blank by Initialize_ALI. Set to the appropriate locking policy
403    --  character if an ali file contains a P line setting the locking policy.
404
405    No_Normalize_Scalars_Specified : Boolean := False;
406    --  Set to False by Initialize_ALI. Set to True if an ali file indicates
407    --  that the file was compiled without normalize scalars.
408
409    No_Object_Specified : Boolean := False;
410    --  Set to False by Initialize_ALI. Set to True if an ali file contains
411    --  the No_Object flag.
412
413    Normalize_Scalars_Specified : Boolean := False;
414    --  Set to False by Initialize_ALI. Set to True if an ali file indicates
415    --  that the file was compiled in Normalize_Scalars mode.
416
417    Queuing_Policy_Specified : Character := ' ';
418    --  Set to blank by Initialize_ALI. Set to the appropriate queuing policy
419    --  character if an ali file contains a P line setting the queuing policy.
420
421    Cumulative_Restrictions : Restrictions_Info;
422    --  This variable records the cumulative contributions of R lines in all
423    --  ali files, showing whether a restriction pragma exists anywhere, and
424    --  accumulating the aggregate knowledge of violations.
425
426    Static_Elaboration_Model_Used : Boolean := False;
427    --  Set to False by Initialize_ALI. Set to True if any ALI file for a
428    --  non-internal unit compiled with the static elaboration model is
429    --  encountered.
430
431    Task_Dispatching_Policy_Specified : Character := ' ';
432    --  Set to blank by Initialize_ALI. Set to the appropriate task dispatching
433    --  policy character if an ali file contains a P line setting the
434    --  task dispatching policy.
435
436    Unreserve_All_Interrupts_Specified : Boolean := False;
437    --  Set to False by Initialize_ALI. Set to True if an ali file is read that
438    --  has  P line specifying unreserve all interrupts mode.
439
440    Zero_Cost_Exceptions_Specified : Boolean := False;
441    --  Set to False by Initialize_ALI. Set to True if an ali file is read that
442    --  has a P line specifying the generation of zero cost exceptions.
443
444    -----------------
445    -- Withs Table --
446    -----------------
447
448    --  Each With line (W line) in an ALI file generates a Withs table entry
449
450    --  Note: there will be no entries in this table if 'W' lines are ignored
451
452    No_With_Id : constant With_Id := With_Id'First;
453    --  Special value indicating no withs table entry
454
455    First_With_Entry : constant With_Id := No_With_Id + 1;
456    --  Id of first actual entry in table
457
458    type With_Record is record
459
460       Uname : Unit_Name_Type;
461       --  Name of Unit
462
463       Sfile : File_Name_Type;
464       --  Name of source file, set to No_File in generic case
465
466       Afile : File_Name_Type;
467       --  Name of ALI file, set to No_File in generic case
468
469       Elaborate : Boolean;
470       --  Indicates presence of E parameter
471
472       Elaborate_All : Boolean;
473       --  Indicates presence of EA parameter
474
475       Elab_All_Desirable : Boolean;
476       --  Indicates presence of AD parameter
477
478       Elab_Desirable     : Boolean;
479       --  Indicates presence of ED parameter
480
481       SAL_Interface : Boolean := False;
482       --  True if the Unit is an Interface of a Stand-Alone Library
483
484    end record;
485
486    package Withs is new Table.Table (
487      Table_Component_Type => With_Record,
488      Table_Index_Type     => With_Id,
489      Table_Low_Bound      => First_With_Entry,
490      Table_Initial        => 5000,
491      Table_Increment      => 200,
492      Table_Name           => "Withs");
493
494    ---------------------
495    -- Arguments Table --
496    ---------------------
497
498    --  Each Arg line (A line) in an ALI file generates an Args table entry
499
500    --  Note: there will be no entries in this table if 'A' lines are ignored
501
502    No_Arg_Id : constant Arg_Id := Arg_Id'First;
503    --  Special value indicating no args table entry
504
505    First_Arg_Entry : constant Arg_Id := No_Arg_Id + 1;
506    --  Id of first actual entry in table
507
508    package Args is new Table.Table (
509      Table_Component_Type => String_Ptr,
510      Table_Index_Type     => Arg_Id,
511      Table_Low_Bound      => First_Arg_Entry,
512      Table_Initial        => 1000,
513      Table_Increment      => 100,
514      Table_Name           => "Args");
515
516    --------------------------
517    -- Linker_Options Table --
518    --------------------------
519
520    --  If an ALI file has one of more Linker_Options lines, then a single
521    --  entry is made in this table. If more than one Linker_Options lines
522    --  appears in a given ALI file, then the arguments are concatenated
523    --  to form the entry in this table, using a NUL character as the
524    --  separator, and a final NUL character is appended to the end.
525
526    --  Note: there will be no entries in this table if 'L' lines are ignored
527
528    type Linker_Option_Record is record
529       Name : Name_Id;
530       --  Name entry containing concatenated list of Linker_Options
531       --  arguments separated by NUL and ended by NUL as described above.
532
533       Unit : Unit_Id;
534       --  Unit_Id for the entry
535
536       Internal_File : Boolean;
537       --  Set True if the linker options are from an internal file. This is
538       --  used to insert certain standard entries after all the user entries
539       --  but before the entries from the run-time.
540
541       Original_Pos : Positive;
542       --  Keep track of original position in the linker options table. This
543       --  is used to implement a stable sort when we sort the linker options
544       --  table.
545    end record;
546
547    --  Declare the Linker_Options Table
548
549    --  The indexes of active entries in this table range from 1 to the
550    --  value of Linker_Options.Last. The zero'th element is for sort call.
551
552    package Linker_Options is new Table.Table (
553      Table_Component_Type => Linker_Option_Record,
554      Table_Index_Type     => Integer,
555      Table_Low_Bound      => 0,
556      Table_Initial        => 200,
557      Table_Increment      => 400,
558      Table_Name           => "Linker_Options");
559
560    -------------------------------------------
561    -- External Version Reference Hash Table --
562    -------------------------------------------
563
564    --  This hash table keeps track of external version reference strings
565    --  as read from E lines in the ali file. The stored values do not
566    --  include the terminating quote characters.
567
568    --  Note: there will be no entries in this table if 'E' lines are ignored
569
570    type Vindex is range 0 .. 98;
571    --  Type to define range of headers
572
573    function SHash (S : String_Ptr) return Vindex;
574    --  Hash function for this table
575
576    function SEq (F1, F2 : String_Ptr) return Boolean;
577    --  Equality function for this table
578
579    package Version_Ref is new Simple_HTable (
580      Header_Num => Vindex,
581      Element    => Boolean,
582      No_Element => False,
583      Key        => String_Ptr,
584      Hash       => SHash,
585      Equal      => SEq);
586
587    -------------------------
588    -- No_Dependency Table --
589    -------------------------
590
591    --  Each R line for a No_Dependency Restriction generates an entry in
592    --  this No_Dependency table.
593
594    type No_Dep_Record is record
595       ALI_File : ALI_Id;
596       --  ALI File containing the entry
597
598       No_Dep_Unit : Name_Id;
599       --  Id for names table entry including entire name, including periods
600    end record;
601
602    package No_Deps is new Table.Table (
603      Table_Component_Type => No_Dep_Record,
604      Table_Index_Type     => Integer,
605      Table_Low_Bound      => 0,
606      Table_Initial        => 200,
607      Table_Increment      => 400,
608      Table_Name           => "No_Deps");
609
610    ------------------------------------
611    -- Sdep (Source Dependency) Table --
612    ------------------------------------
613
614    --  Each source dependency (D line) in an ALI file generates an
615    --  entry in the Sdep table.
616
617    --  Note: there will be no entries in this table if 'D' lines are ignored
618
619    No_Sdep_Id : constant Sdep_Id := Sdep_Id'First;
620    --  Special value indicating no Sdep table entry
621
622    First_Sdep_Entry : Sdep_Id := No_Sdep_Id + 1;
623    --  Id of first Sdep entry for current ali file. This is initialized to
624    --  the first Sdep entry in the table, and then incremented appropriately
625    --  as successive ALI files are scanned.
626
627    type Sdep_Record is record
628
629       Sfile : File_Name_Type;
630       --  Name of source file
631
632       Stamp : Time_Stamp_Type;
633       --  Time stamp value. Note that this will be all zero characters
634       --  for the dummy entries for missing or non-dependent files.
635
636       Checksum : Word;
637       --  Checksum value. Note that this will be all zero characters
638       --  for the dummy entries for missing or non-dependent files
639
640       Dummy_Entry : Boolean;
641       --  Set True for dummy entries that correspond to missing files
642       --  or files where no dependency relationship exists.
643
644       Subunit_Name : Name_Id;
645       --  Name_Id for subunit name if present, else No_Name
646
647       Rfile : File_Name_Type;
648       --  Reference file name. Same as Sfile unless a Source_Reference
649       --  pragma was used, in which case it reflects the name used in
650       --  the pragma.
651
652       Start_Line : Nat;
653       --  Starting line number in file. Always 1, unless a Source_Reference
654       --  pragma was used, in which case it reflects the line number value
655       --  given in the pragma.
656
657    end record;
658
659    package Sdep is new Table.Table (
660      Table_Component_Type => Sdep_Record,
661      Table_Index_Type     => Sdep_Id,
662      Table_Low_Bound      => First_Sdep_Entry,
663      Table_Initial        => 5000,
664      Table_Increment      => 200,
665      Table_Name           => "Sdep");
666
667    ----------------------------
668    -- Use of Name Table Info --
669    ----------------------------
670
671    --  All unit names and file names are entered into the Names table. The
672    --  Info fields of these entries are used as follows:
673
674    --    Unit name           Info field has Unit_Id of unit table entry
675    --    ALI file name       Info field has ALI_Id of ALI table entry
676    --    Source file name    Info field has Source_Id of source table entry
677
678    --------------------------
679    -- Cross-Reference Data --
680    --------------------------
681
682    --  The following table records cross-reference sections, there is one
683    --  entry for each X header line in the ALI file for an xref section.
684
685    --  Note: there will be no entries in this table if 'X' lines are ignored
686
687    type Xref_Section_Record is record
688       File_Num : Sdep_Id;
689       --  Dependency number for file (entry in Sdep.Table)
690
691       File_Name : Name_Id;
692       --  Name of file
693
694       First_Entity : Nat;
695       --  First entry in Xref_Entity table
696
697       Last_Entity : Nat;
698       --  Last entry in Xref_Entity table
699    end record;
700
701    package Xref_Section is new Table.Table (
702      Table_Component_Type => Xref_Section_Record,
703      Table_Index_Type     => Nat,
704      Table_Low_Bound      => 1,
705      Table_Initial        => 50,
706      Table_Increment      => 300,
707      Table_Name           => "Xref_Section");
708
709    --  The following is used to indicate whether a typeref field is present
710    --  for the entity, and if so what kind of typeref field.
711
712    type Tref_Kind is (
713      Tref_None,    --  No typeref present
714      Tref_Access,  --  Access type typeref (points to designated type)
715      Tref_Derived, --  Derived type typeref (points to parent type)
716      Tref_Type);   --  All other cases
717
718    --  The following table records entities for which xrefs are recorded
719
720    type Xref_Entity_Record is record
721       Line : Pos;
722       --  Line number of definition
723
724       Etype : Character;
725       --  Set to the identification character for the entity. See section
726       --  "Cross-Reference Entity Identifiers" in lib-xref.ads for details.
727
728       Col : Pos;
729       --  Column number of definition
730
731       Lib : Boolean;
732       --  True if entity is library level entity
733
734       Entity : Name_Id;
735       --  Name of entity
736
737       Iref_File_Num : Sdep_Id;
738       --  This field is set to the dependency reference for the file containing
739       --  the generic entity that this one instantiates, or to No_Sdep_Id if
740       --  the current entity is not an instantiation
741
742       Iref_Line : Nat;
743       --  This field is set to the line number in Iref_File_Num of the generic
744       --  entity that this one instantiates, or to zero if the current entity
745       --  is not an instantiation.
746
747       Rref_Line : Nat;
748       --  This field is set to the line number of a renaming reference if
749       --  one is present, or to zero if no renaming reference is present
750
751       Rref_Col : Nat;
752       --  This field is set to the column number of a renaming reference
753       --  if one is present, or to zero if no renaming reference is present.
754
755       Tref : Tref_Kind;
756       --  Indicates if a typeref is present, and if so what kind. Set to
757       --  Tref_None if no typeref field is present.
758
759       Tref_File_Num : Sdep_Id;
760       --  This field is set to No_Sdep_Id if no typeref is present, or
761       --  if the typeref refers to an entity in standard. Otherwise it
762       --  it is the dependency reference for the file containing the
763       --  declaration of the typeref entity.
764
765       Tref_Line : Nat;
766       --  This field is set to zero if no typeref is present, or if the
767       --  typeref refers to an entity in standard. Otherwise it contains
768       --  the line number of the declaration of the typeref entity.
769
770       Tref_Type : Character;
771       --  This field is set to blank if no typeref is present, or if the
772       --  typeref refers to an entity in standard. Otherwise it contains
773       --  the identification character for the typeref entity. See section
774       --  "Cross-Reference Entity Identifiers" in lib-xref.ads for details.
775
776       Tref_Col : Nat;
777       --  This field is set to zero if no typeref is present, or if the
778       --  typeref refers to an entity in standard. Otherwise it contains
779       --  the column number of the declaration of the parent type.
780
781       Tref_Standard_Entity : Name_Id;
782       --  This field is set to No_Name if no typeref is present or if the
783       --  typeref refers to a declared entity rather than an entity in
784       --  package Standard. If there is a typeref that references an
785       --  entity in package Standard, then this field is a Name_Id
786       --  reference for the entity name.
787
788       Oref_File_Num : Sdep_Id;
789       --  This field is set to No_Sdep_Id is the entity doesn't override any
790       --  other entity, or to the dependency reference for the overriden
791       --  entity.
792
793       Oref_Line : Nat;
794       Oref_Col  : Nat;
795       --  These two fields are set to the line and column of the overriden
796       --  entity.
797
798       First_Xref : Nat;
799       --  Index into Xref table of first cross-reference
800
801       Last_Xref : Nat;
802       --  Index into Xref table of last cross-reference. The value in
803       --  Last_Xref can be less than the First_Xref value to indicate
804       --  that no entries are present in the Xref Table.
805    end record;
806
807    package Xref_Entity is new Table.Table (
808      Table_Component_Type => Xref_Entity_Record,
809      Table_Index_Type     => Nat,
810      Table_Low_Bound      => 1,
811      Table_Initial        => 500,
812      Table_Increment      => 300,
813      Table_Name           => "Xref_Entity");
814
815    --  The following table records actual cross-references
816
817    type Xref_Record is record
818       File_Num : Sdep_Id;
819       --  Set to the file dependency number for the cross-reference. Note
820       --  that if no file entry is present explicitly, this is just a copy
821       --  of the reference for the current cross-reference section.
822
823       Line : Pos;
824       --  Line number for the reference
825
826       Rtype : Character;
827       --  Indicates type of reference, using code used in ALI file:
828       --    r = reference
829       --    m = modification
830       --    b = body entity
831       --    c = completion of private or incomplete type
832       --    x = type extension
833       --    i = implicit reference
834       --  See description in lib-xref.ads for further details
835
836       Col : Nat;
837       --  Column number for the reference
838
839       --  Note: for instantiation references, Rtype is set to ' ', and Col is
840       --  set to zero. One or more such entries can follow any other reference.
841       --  When there is more than one such entry, this is to be read as:
842       --     e.g. ref1  ref2  ref3
843       --     ref1 is a reference to an entity that was instantied at ref2.
844       --     ref2 itself is also the result of an instantiation, that took
845       --     place at ref3
846    end record;
847
848    package Xref is new Table.Table (
849      Table_Component_Type => Xref_Record,
850      Table_Index_Type     => Nat,
851      Table_Low_Bound      => 1,
852      Table_Initial        => 2000,
853      Table_Increment      => 300,
854      Table_Name           => "Xref");
855
856    --------------------------------------
857    -- Subprograms for Reading ALI File --
858    --------------------------------------
859
860    procedure Initialize_ALI;
861    --  Initialize the ALI tables. Also resets all switch values to defaults
862
863    function Scan_ALI
864      (F             : File_Name_Type;
865       T             : Text_Buffer_Ptr;
866       Ignore_ED     : Boolean;
867       Err           : Boolean;
868       Read_Xref     : Boolean := False;
869       Read_Lines    : String  := "";
870       Ignore_Lines  : String  := "X";
871       Ignore_Errors : Boolean := False) return ALI_Id;
872    --  Given the text, T, of an ALI file, F, scan and store the information
873    --  from the file, and return the Id of the resulting entry in the ALI
874    --  table. Switch settings may be modified as described above in the
875    --  switch description settings.
876    --
877    --    Ignore_ED is normally False. If set to True, it indicates that
878    --    all AD/ED (elaboration desirable) indications in the ALI file are
879    --    to be ignored. This parameter is obsolete now that the -f switch
880    --    is removed from gnatbind, and should be removed ???
881    --
882    --    Err determines the action taken on an incorrectly formatted file.
883    --    If Err is False, then an error message is output, and the program
884    --    is terminated. If Err is True, then no error message is output,
885    --    and No_ALI_Id is returned.
886    --
887    --    Ignore_Lines requests that Scan_ALI ignore any lines that start
888    --    with any given key character. The default value of X causes all
889    --    Xref lines to be ignored. The corresponding data in the ALI
890    --    tables will not be filled in in this case. It is not possible
891    --    to ignore U (unit) lines, they are always read.
892    --
893    --    Read_Lines requests that Scan_ALI process only lines that start
894    --    with one of the given characters. The corresponding data in the
895    --    ALI file for any characters not given in the list will not be
896    --    set. The default value of the null string indicates that all
897    --    lines should be read (unless Ignore_Lines is specified). U
898    --    (unit) lines are always read regardless of the value of this
899    --    parameter.
900    --
901    --    Note: either Ignore_Lines or Read_Lines should be non-null.
902    --    but not both. If both are given then only the Read_Lines
903    --    value is processed, and the Ignore_Lines parameter is
904    --    not processed.
905    --
906    --    Read_XREF is set True to read and acquire the cross-reference
907    --    information. If Read_XREF is set to True, then the effect is
908    --    to ignore all lines other than U, W, D and X lines and the
909    --    Ignore_Lines and Read_Lines parameters are ignored (i.e. the
910    --    use of True for Read_XREF is equivalent to specifying an
911    --    argument of "UWDX" for Read_Lines.
912    --
913    --    Ignore_Errors is normally False. If it is set True, then Scan_ALI
914    --    will do its best to scan through a file and extract all information
915    --    it can, even if there are errors. In this case Err is only set if
916    --    Scan_ALI was completely unable to process the file (e.g. it did not
917    --    look like an ALI file at all). Ignore_Errors is intended to improve
918    --    the downward compatibility of new compilers with old tools.
919
920 end ALI;