1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
11 -- Copyright (C) 1992-2001 Free Software Foundation, Inc. --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
24 -- GNAT was originally developed by the GNAT team at New York University. --
25 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
27 ------------------------------------------------------------------------------
29 -- This package defines the internal data structures used for representation
30 -- of Ada Library Information (ALI) acquired from the ALI files generated
33 with Casing; use Casing;
34 with Gnatvsn; use Gnatvsn;
35 with Rident; use Rident;
37 with Types; use Types;
39 with GNAT.HTable; use GNAT.HTable;
47 -- The various entries are stored in tables with distinct subscript
48 -- ranges. The following type definitions indicate the ranges used
49 -- for the subscripts (Id values) for the various tables.
51 type ALI_Id is range 0 .. 999_999;
52 -- Id values used for ALIs table entries
54 type Unit_Id is range 1_000_000 .. 1_999_999;
55 -- Id values used for Unit table entries
57 type With_Id is range 2_000_000 .. 2_999_999;
58 -- Id values used for Withs table entries
60 type Arg_Id is range 3_000_000 .. 3_999_999;
61 -- Id values used for argument table entries
63 type Sdep_Id is range 4_000_000 .. 4_999_999;
64 -- Id values used for Sdep table entries
66 type Source_Id is range 5_000_000 .. 5_999_999;
67 -- Id values used for Source table entries
73 -- Each ALI file read generates an entry in the ALIs table
75 No_ALI_Id : constant ALI_Id := ALI_Id'First;
76 -- Special value indicating no ALI entry
78 First_ALI_Entry : constant ALI_Id := No_ALI_Id + 1;
79 -- Id of first actual entry in table
81 type Main_Program_Type is (None, Proc, Func);
82 -- Indicator of whether unit can be used as main program
84 type Restrictions_String is array (Partition_Restrictions) of Character;
85 -- Type used to hold string from R line
87 type ALIs_Record is record
89 Afile : File_Name_Type;
92 Ofile_Full_Name : Name_Id;
93 -- Full name of object file corresponding to the ALI file
95 Sfile : File_Name_Type;
96 -- Name of source file that generates this ALI file (which is equal
97 -- to the name of the source file in the first unit table entry for
98 -- this ALI file, since the body if present is always first).
100 Ver : String (1 .. Ver_Len_Max);
101 -- Value of library version (V line in ALI file)
104 -- Length of characters stored in Ver
106 First_Unit : Unit_Id;
107 -- Id of first Unit table entry for this file
110 -- Id of last Unit table entry for this file
112 First_Sdep : Sdep_Id;
113 -- Id of first Sdep table entry for this file
116 -- Id of last Sdep table entry for this file
118 Main_Program : Main_Program_Type;
119 -- Indicator of whether first unit can be used as main program
122 -- Indicates priority value if Main_Program field indicates that
123 -- this can be a main program. A value of -1 (No_Main_Priority)
124 -- indicates that no parameter was found, or no M line was present.
126 Time_Slice_Value : Int;
127 -- Indicates value of time slice parameter from T=xxx on main program
128 -- line. A value of -1 indicates that no T=xxx parameter was found,
129 -- or no M line was present.
131 WC_Encoding : Character;
132 -- Wide character encoding if main procedure. Otherwise not relevant.
134 Locking_Policy : Character;
135 -- Indicates locking policy for units in this file. Space means
136 -- tasking was not used, or that no Locking_Policy pragma was
137 -- present or that this is a language defined unit. Otherwise set
138 -- to first character (upper case) of policy name.
140 Queuing_Policy : Character;
141 -- Indicates queuing policy for units in this file. Space means
142 -- tasking was not used, or that no Queuing_Policy pragma was
143 -- present or that this is a language defined unit. Otherwise set
144 -- to first character (upper case) of policy name.
146 Task_Dispatching_Policy : Character;
147 -- Indicates task dispatching policy for units in this file. Space
148 -- means tasking was not used, or that no Task_Dispatching_Policy
149 -- pragma was present or that this is a language defined unit.
150 -- Otherwise set to first character (upper case) of policy name.
152 Compile_Errors : Boolean;
153 -- Set to True if compile errors for unit. Note that No_Object
154 -- will always be set as well in this case.
156 Float_Format : Character;
157 -- Set to float format (set to I if no float-format given)
160 -- Set to True if no object file generated
162 No_Run_Time : Boolean;
163 -- Set to True if file was compiled with pragma No_Run_Time
165 Normalize_Scalars : Boolean;
166 -- Set to True if file was compiled with Normalize_Scalars
168 Unit_Exception_Table : Boolean;
169 -- Set to True if unit exception table pointer generated
171 Zero_Cost_Exceptions : Boolean;
172 -- Set to True if file was compiled with zero cost exceptions
174 Restrictions : Restrictions_String;
175 -- Copy of restrictions letters from R line
179 No_Main_Priority : constant Int := -1;
180 -- Code for no main priority set
182 package ALIs is new Table.Table (
183 Table_Component_Type => ALIs_Record,
184 Table_Index_Type => ALI_Id,
185 Table_Low_Bound => First_ALI_Entry,
186 Table_Initial => 500,
187 Table_Increment => 200,
188 Table_Name => "ALIs");
194 -- Each unit within an ALI file generates an entry in the unit table
196 No_Unit_Id : constant Unit_Id := Unit_Id'First;
197 -- Special value indicating no unit table entry
199 First_Unit_Entry : constant Unit_Id := No_Unit_Id + 1;
200 -- Id of first actual entry in table
202 type Unit_Type is (Is_Spec, Is_Body, Is_Spec_Only, Is_Body_Only);
203 -- Indicates type of entry, if both body and spec appear in the ALI file,
204 -- then the first unit is marked Is_Body, and the second is marked Is_Spec.
205 -- If only a spec appears, then it is marked as Is_Spec_Only, and if only
206 -- a body appears, then it is marked Is_Body_Only).
208 subtype Version_String is String (1 .. 8);
209 -- Version string, taken from unit record
211 type Unit_Record is record
214 -- Corresponding ALI entry
216 Uname : Unit_Name_Type;
219 Sfile : File_Name_Type;
220 -- Name of source file
223 -- Indicates presence of PR parameter for a preelaborated package
226 -- Indicates presence of NE parameter for a unit that has does not
227 -- have an elaboration routine (since it has no elaboration code).
230 -- Indicates presence of PU parameter for a pure package
232 Dynamic_Elab : Boolean;
233 -- Set to True if the unit was compiled with dynamic elaboration
234 -- checks (i.e. either -gnatE or pragma Elaboration_Checks (Static)
235 -- was used to compile the unit).
237 Elaborate_Body : Boolean;
238 -- Indicates presence of EB parameter for a package which has a
239 -- pragma Preelaborate_Body.
241 Set_Elab_Entity : Boolean;
242 -- Indicates presence of EE parameter for a unit which has an
243 -- elaboration entity which must be set true as part of the
244 -- elaboration of the entity.
247 -- Indicates presence of RA parameter for a package that declares
248 -- at least one Remote Access to Class_Wide (RACW) object.
250 Remote_Types : Boolean;
251 -- Indicates presence of RT parameter for a package which has a
252 -- pragma Remote_Types.
254 Shared_Passive : Boolean;
255 -- Indicates presence of SP parameter for a package which has a
256 -- pragma Shared_Passive.
259 -- Indicates presence of RC parameter for a package which has a
260 -- pragma Remote_Call_Interface.
262 Predefined : Boolean;
263 -- Indicates if unit is language predefined (or a child of such a unit)
266 -- Indicates if unit is an internal unit (or a child of such a unit)
268 First_With : With_Id;
269 -- Id of first withs table entry for this file
272 -- Id of last withs table entry for this file
275 -- Id of first args table entry for this file
278 -- Id of last args table entry for this file
283 Is_Generic : Boolean;
284 -- True for generic unit (i.e. a generic declaration, or a generic
285 -- body). False for a non-generic unit.
287 Unit_Kind : Character;
288 -- Indicates the nature of the unit. 'p' for Packages and 's' for
291 Version : Version_String;
294 Icasing : Casing_Type;
295 -- Indicates casing of identifiers in source file for this unit. This
296 -- is used for informational output, and also for constructing the
297 -- main unit if it is being built in Ada.
299 Kcasing : Casing_Type;
300 -- Indicates casing of keyowords in source file for this unit. This
301 -- is used for informational output, and also for constructing the
302 -- main unit if it is being built in Ada.
304 Elab_Position : aliased Natural;
305 -- Initialized to zero. Set non-zero when a unit is chosen and
306 -- placed in the elaboration order. The value represents the
307 -- ordinal position in the elaboration order.
309 Init_Scalars : Boolean;
310 -- Set True if IS qualifier appears in ALI file, indicating that
311 -- an Initialize_Scalars pragma applies to the unit.
315 package Units is new Table.Table (
316 Table_Component_Type => Unit_Record,
317 Table_Index_Type => Unit_Id,
318 Table_Low_Bound => First_Unit_Entry,
319 Table_Initial => 100,
320 Table_Increment => 200,
321 Table_Name => "Unit");
327 -- These switches record status information about ali files that
328 -- have been read, for quick reference without searching tables.
330 Dynamic_Elaboration_Checks_Specified : Boolean := False;
331 -- Set to False by Initialize_ALI. Set to True if Read_ALI reads
332 -- a unit for which dynamic elaboration checking is enabled.
334 Float_Format_Specified : Character := ' ';
335 -- Set to blank by Initialize_ALI. Set to appropriate float format
336 -- character (V or I, see Opt.Float_Format) if an an ali file that
337 -- is read contains an F line setting the floating point format.
339 Initialize_Scalars_Used : Boolean := False;
340 -- Set True if an ali file contains the Initialize_Scalars flag
342 Locking_Policy_Specified : Character := ' ';
343 -- Set to blank by Initialize_ALI. Set to the appropriate locking policy
344 -- character if an ali file contains a P line setting the locking policy.
346 No_Normalize_Scalars_Specified : Boolean := False;
347 -- Set to False by Initialize_ALI. Set to True if an ali file indicates
348 -- that the file was compiled without normalize scalars.
350 No_Object_Specified : Boolean := False;
351 -- Set to False by Initialize_ALI. Set to True if an ali file contains
352 -- the No_Object flag.
354 Normalize_Scalars_Specified : Boolean := False;
355 -- Set to False by Initialize_ALI. Set to True if an ali file indicates
356 -- that the file was compiled in Normalize_Scalars mode.
358 No_Run_Time_Specified : Boolean := False;
359 -- Set to False by Initialize_ALI, Set to True if an ali file indicates
360 -- that the file was compiled in No_Run_Time mode.
362 Queuing_Policy_Specified : Character := ' ';
363 -- Set to blank by Initialize_ALI. Set to the appropriate queuing policy
364 -- character if an ali file contains a P line setting the queuing policy.
366 Static_Elaboration_Model_Used : Boolean := False;
367 -- Set to False by Initialize_ALI. Set to True if any ALI file for a
368 -- non-internal unit compiled with the static elaboration model is
371 Task_Dispatching_Policy_Specified : Character := ' ';
372 -- Set to blank by Initialize_ALI. Set to the appropriate task dispatching
373 -- policy character if an ali file contains a P line setting the
374 -- task dispatching policy.
376 Unreserve_All_Interrupts_Specified : Boolean := False;
377 -- Set to False by Initialize_ALI. Set to True if an ali file is read that
378 -- has P line specifying unreserve all interrupts mode.
380 Zero_Cost_Exceptions_Specified : Boolean := False;
381 -- Set to False by Initialize_ALI. Set to True if an ali file is read that
382 -- has a P line specifying the generation of zero cost exceptions.
388 -- Each With line (W line) in an ALI file generates a Withs table entry
390 No_With_Id : constant With_Id := With_Id'First;
391 -- Special value indicating no withs table entry
393 First_With_Entry : constant With_Id := No_With_Id + 1;
394 -- Id of first actual entry in table
396 type With_Record is record
398 Uname : Unit_Name_Type;
401 Sfile : File_Name_Type;
402 -- Name of source file, set to No_File in generic case
404 Afile : File_Name_Type;
405 -- Name of ALI file, set to No_File in generic case
408 -- Indicates presence of E parameter
410 Elaborate_All : Boolean;
411 -- Indicates presence of EA parameter
413 Elab_All_Desirable : Boolean;
414 -- Indicates presence of ED parameter
418 package Withs is new Table.Table (
419 Table_Component_Type => With_Record,
420 Table_Index_Type => With_Id,
421 Table_Low_Bound => First_With_Entry,
422 Table_Initial => 5000,
423 Table_Increment => 200,
424 Table_Name => "Withs");
426 ---------------------
427 -- Arguments Table --
428 ---------------------
430 -- Each Arg line (A line) in an ALI file generates an Args table entry
432 No_Arg_Id : constant Arg_Id := Arg_Id'First;
433 -- Special value indicating no args table entry
435 First_Arg_Entry : constant Arg_Id := No_Arg_Id + 1;
436 -- Id of first actual entry in table
438 package Args is new Table.Table (
439 Table_Component_Type => String_Ptr,
440 Table_Index_Type => Arg_Id,
441 Table_Low_Bound => First_Arg_Entry,
442 Table_Initial => 1000,
443 Table_Increment => 100,
444 Table_Name => "Args");
446 --------------------------
447 -- Linker_Options Table --
448 --------------------------
450 -- Each unique linker option (L line) in an ALI file generates
451 -- an entry in the Linker_Options table. Note that only unique
452 -- entries are stored, i.e. if the same entry appears twice, the
453 -- second entry is suppressed. Each entry is a character sequence
454 -- terminated by a NUL character.
456 type Linker_Option_Record is record
459 Internal_File : Boolean;
460 Original_Pos : Positive;
463 -- Declare the Linker_Options Table
465 -- The indexes of active entries in this table range from 1 to the
466 -- value of Linker_Options.Last. The zero'th element is for sort call.
468 package Linker_Options is new Table.Table (
469 Table_Component_Type => Linker_Option_Record,
470 Table_Index_Type => Integer,
471 Table_Low_Bound => 0,
472 Table_Initial => 200,
473 Table_Increment => 400,
474 Table_Name => "Linker_Options");
476 -------------------------------------------
477 -- External Version Reference Hash Table --
478 -------------------------------------------
480 -- This hash table keeps track of external version reference strings
481 -- as read from E lines in the ali file. The stored values do not
482 -- include the terminating quote characters.
484 type Vindex is range 0 .. 98;
485 -- Type to define range of headers
487 function SHash (S : String_Ptr) return Vindex;
488 -- Hash function for this table
490 function SEq (F1, F2 : String_Ptr) return Boolean;
491 -- Equality function for this table
493 package Version_Ref is new Simple_HTable (
494 Header_Num => Vindex,
501 ------------------------------------
502 -- Sdep (Source Dependency) Table --
503 ------------------------------------
505 -- Each source dependency (D line) in an ALI file generates an
506 -- entry in the Sdep table.
508 No_Sdep_Id : constant Sdep_Id := Sdep_Id'First;
509 -- Special value indicating no Sdep table entry
511 First_Sdep_Entry : constant Sdep_Id := No_Sdep_Id + 1;
512 -- Id of first actual entry in table
514 type Sdep_Record is record
516 Sfile : File_Name_Type;
517 -- Name of source file
519 Stamp : Time_Stamp_Type;
520 -- Time stamp value. Note that this will be all zero characters
521 -- for the dummy entries for missing or non-dependent files.
524 -- Checksum value. Note that this will be all zero characters
525 -- for the dummy entries for missing or non-dependent files
527 Dummy_Entry : Boolean;
528 -- Set True for dummy entries that correspond to missing files
529 -- or files where no dependency relationship exists.
531 Subunit_Name : Name_Id;
532 -- Name_Id for subunit name if present, else No_Name
534 Rfile : File_Name_Type;
535 -- Reference file name. Same as Sfile unless a Source_Reference
536 -- pragma was used, in which case it reflects the name used in
540 -- Starting line number in file. Always 1, unless a Source_Reference
541 -- pragma was used, in which case it reflects the line number value
542 -- given in the pragma.
546 package Sdep is new Table.Table (
547 Table_Component_Type => Sdep_Record,
548 Table_Index_Type => Sdep_Id,
549 Table_Low_Bound => First_Sdep_Entry,
550 Table_Initial => 5000,
551 Table_Increment => 200,
552 Table_Name => "Sdep");
554 ----------------------------
555 -- Use of Name Table Info --
556 ----------------------------
558 -- All unit names and file names are entered into the Names table. The
559 -- Info fields of these entries are used as follows:
561 -- Unit name Info field has Unit_Id of unit table entry
562 -- ALI file name Info field has ALI_Id of ALI table entry
563 -- Source file name Info field has Source_Id of source table entry
565 --------------------------
566 -- Cross-Reference Data --
567 --------------------------
569 -- The following table records cross-reference sections, there is one
570 -- entry for each X header line in the ALI file for an xref section.
571 -- Note that there will be no entries in this table if the Read_Xref
572 -- parameter to Scan_ALI was set to False.
574 type Xref_Section_Record is record
576 -- Dependency number for file (entry in Sdep.Table)
582 -- First entry in Xref_Entity table
585 -- Last entry in Xref_Entity table
589 package Xref_Section is new Table.Table (
590 Table_Component_Type => Xref_Section_Record,
591 Table_Index_Type => Nat,
592 Table_Low_Bound => 1,
594 Table_Increment => 300,
595 Table_Name => "Xref_Section");
597 -- The following is used to indicate whether a typeref field is present
598 -- for the entity, and if so what kind of typeref field.
601 Tref_None, -- No typeref present
602 Tref_Access, -- Access type typeref (points to designated type)
603 Tref_Derived, -- Derived type typeref (points to parent type)
604 Tref_Type); -- All other cases
606 -- The following table records entities for which xrefs are recorded
608 type Xref_Entity_Record is record
610 -- Line number of definition
613 -- Set to the identification character for the entity. See section
614 -- "Cross-Reference Entity Identifiers in lib-xref.ads for details.
617 -- Column number of definition
620 -- True if entity is library level entity
626 -- This field is set to the line number of a renaming reference if
627 -- one is present, or to zero if no renaming reference is present
630 -- This field is set to the column number of a renaming reference
631 -- if one is present, or to zero if no renaming reference is present.
634 -- Indicates if a typeref is present, and if so what kind. Set to
635 -- Tref_None if no typeref field is present.
637 Tref_File_Num : Sdep_Id;
638 -- This field is set to No_Sdep_Id if no typeref is present, or
639 -- if the typeref refers to an entity in standard. Otherwise it
640 -- it is the dependency reference for the file containing the
641 -- declaration of the typeref entity.
644 -- This field is set to zero if no typeref is present, or if the
645 -- typeref refers to an entity in standard. Otherwise it contains
646 -- the line number of the declaration of the typeref entity.
648 Tref_Type : Character;
649 -- This field is set to blank if no typeref is present, or if the
650 -- typeref refers to an entity in standard. Otherwise it contains
651 -- the identification character for the typeref entity. See section
652 -- "Cross-Reference Entity Identifiers in lib-xref.ads for details.
655 -- This field is set to zero if no typeref is present, or if the
656 -- typeref refers to an entity in standard. Otherwise it contains
657 -- the column number of the declaration of the parent type.
659 Tref_Standard_Entity : Name_Id;
660 -- This field is set to No_Name if no typeref is present or if the
661 -- typeref refers to a declared entity rather than an entity in
662 -- package Standard. If there is a typeref that references an
663 -- entity in package Standard, then this field is a Name_Id
664 -- reference for the entity name.
667 -- Index into Xref table of first cross-reference
670 -- Index into Xref table of last cross-reference. The value in
671 -- Last_Xref can be less than the First_Xref value to indicate
672 -- that no entries are present in the Xref Table.
675 package Xref_Entity is new Table.Table (
676 Table_Component_Type => Xref_Entity_Record,
677 Table_Index_Type => Nat,
678 Table_Low_Bound => 1,
679 Table_Initial => 500,
680 Table_Increment => 300,
681 Table_Name => "Xref_Entity");
683 -- The following table records actual cross-references
685 type Xref_Record is record
687 -- Set to the file dependency number for the cross-reference. Note
688 -- that if no file entry is present explicitly, this is just a copy
689 -- of the reference for the current cross-reference section.
692 -- Line number for the reference
695 -- Indicates type of reference, using code used in ALI file:
699 -- c = completion of private or incomplete type
700 -- x = type extension
701 -- i = implicit reference
702 -- See description in lib-xref.ads for further details
705 -- Column number for the reference
707 -- Note: for instantiation references, Rtype is set to ' ', and Col is
708 -- set to zero. One or more such entries can follow any other reference.
711 package Xref is new Table.Table (
712 Table_Component_Type => Xref_Record,
713 Table_Index_Type => Nat,
714 Table_Low_Bound => 1,
715 Table_Initial => 2000,
716 Table_Increment => 300,
717 Table_Name => "Xref");
719 --------------------------------------
720 -- Subprograms for Reading ALI File --
721 --------------------------------------
723 procedure Initialize_ALI;
724 -- Initialize the ALI tables. Also resets all switch values to defaults.
731 Read_Xref : Boolean := False)
733 -- Given the text, T, of an ALI file, F, scan and store the information
734 -- from the file, and return the Id of the resulting entry in the ALI
735 -- table. Switch settings may be modified as described above in the
736 -- switch description settings.
738 -- Ignore_ED is normally False. If set to True, it indicates that
739 -- all ED (elaboration desirable) indications in the ALI file are
742 -- Err determines the action taken on an incorrectly formatted file.
743 -- If Err is False, then an error message is output, and the program
744 -- is terminated. If Err is True, then no error message is output,
745 -- and No_ALI_Id is returned.
747 -- Read_XREF is set True to read and acquire the cross-reference
748 -- information, otherwise the scan is terminated when a cross-
749 -- reference line is encountered.