1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2002 Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 -- This package defines the internal data structures used for representation
28 -- of Ada Library Information (ALI) acquired from the ALI files generated
31 with Casing; use Casing;
32 with Gnatvsn; use Gnatvsn;
33 with Rident; use Rident;
35 with Types; use Types;
37 with GNAT.HTable; use GNAT.HTable;
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.
49 type ALI_Id is range 0 .. 999_999;
50 -- Id values used for ALIs table entries
52 type Unit_Id is range 1_000_000 .. 1_999_999;
53 -- Id values used for Unit table entries
55 type With_Id is range 2_000_000 .. 2_999_999;
56 -- Id values used for Withs table entries
58 type Arg_Id is range 3_000_000 .. 3_999_999;
59 -- Id values used for argument table entries
61 type Sdep_Id is range 4_000_000 .. 4_999_999;
62 -- Id values used for Sdep table entries
64 type Source_Id is range 5_000_000 .. 5_999_999;
65 -- Id values used for Source table entries
71 -- Each ALI file read generates an entry in the ALIs table
73 No_ALI_Id : constant ALI_Id := ALI_Id'First;
74 -- Special value indicating no ALI entry
76 First_ALI_Entry : constant ALI_Id := No_ALI_Id + 1;
77 -- Id of first actual entry in table
79 type Main_Program_Type is (None, Proc, Func);
80 -- Indicator of whether unit can be used as main program
82 type Restrictions_String is array (All_Restrictions) of Character;
83 -- Type used to hold string from R line
85 type ALIs_Record is record
87 Afile : File_Name_Type;
90 Ofile_Full_Name : Name_Id;
91 -- Full name of object file corresponding to the ALI file
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).
98 Ver : String (1 .. Ver_Len_Max);
99 -- Value of library version (V line in ALI file)
102 -- Length of characters stored in Ver
104 First_Unit : Unit_Id;
105 -- Id of first Unit table entry for this file
108 -- Id of last Unit table entry for this file
110 First_Sdep : Sdep_Id;
111 -- Id of first Sdep table entry for this file
114 -- Id of last Sdep table entry for this file
116 Main_Program : Main_Program_Type;
117 -- Indicator of whether first unit can be used as main program
120 -- Indicates priority value if Main_Program field indicates that
121 -- this can be a main program. A value of -1 (No_Main_Priority)
122 -- indicates that no parameter was found, or no M line was present.
124 Time_Slice_Value : Int;
125 -- Indicates value of time slice parameter from T=xxx on main program
126 -- line. A value of -1 indicates that no T=xxx parameter was found,
127 -- or no M line was present.
129 WC_Encoding : Character;
130 -- Wide character encoding if main procedure. Otherwise not relevant.
132 Locking_Policy : Character;
133 -- Indicates locking policy for units in this file. Space means
134 -- tasking was not used, or that no Locking_Policy pragma was
135 -- present or that this is a language defined unit. Otherwise set
136 -- to first character (upper case) of policy name.
138 Queuing_Policy : Character;
139 -- Indicates queuing policy for units in this file. Space means
140 -- tasking was not used, or that no Queuing_Policy pragma was
141 -- present or that this is a language defined unit. Otherwise set
142 -- to first character (upper case) of policy name.
144 Task_Dispatching_Policy : Character;
145 -- Indicates task dispatching policy for units in this file. Space
146 -- means tasking was not used, or that no Task_Dispatching_Policy
147 -- pragma was present or that this is a language defined unit.
148 -- Otherwise set to first character (upper case) of policy name.
150 Compile_Errors : Boolean;
151 -- Set to True if compile errors for unit. Note that No_Object
152 -- will always be set as well in this case.
154 Float_Format : Character;
155 -- Set to float format (set to I if no float-format given)
158 -- Set to True if no object file generated
160 No_Run_Time : Boolean;
161 -- Set to True if file was compiled with pragma No_Run_Time
163 Normalize_Scalars : Boolean;
164 -- Set to True if file was compiled with Normalize_Scalars
166 Unit_Exception_Table : Boolean;
167 -- Set to True if unit exception table pointer generated
169 Zero_Cost_Exceptions : Boolean;
170 -- Set to True if file was compiled with zero cost exceptions
172 Restrictions : Restrictions_String;
173 -- Copy of restrictions letters from R line
177 No_Main_Priority : constant Int := -1;
178 -- Code for no main priority set
180 package ALIs is new Table.Table (
181 Table_Component_Type => ALIs_Record,
182 Table_Index_Type => ALI_Id,
183 Table_Low_Bound => First_ALI_Entry,
184 Table_Initial => 500,
185 Table_Increment => 200,
186 Table_Name => "ALIs");
192 -- Each unit within an ALI file generates an entry in the unit table
194 No_Unit_Id : constant Unit_Id := Unit_Id'First;
195 -- Special value indicating no unit table entry
197 First_Unit_Entry : constant Unit_Id := No_Unit_Id + 1;
198 -- Id of first actual entry in table
200 type Unit_Type is (Is_Spec, Is_Body, Is_Spec_Only, Is_Body_Only);
201 -- Indicates type of entry, if both body and spec appear in the ALI file,
202 -- then the first unit is marked Is_Body, and the second is marked Is_Spec.
203 -- If only a spec appears, then it is marked as Is_Spec_Only, and if only
204 -- a body appears, then it is marked Is_Body_Only).
206 subtype Version_String is String (1 .. 8);
207 -- Version string, taken from unit record
209 type Unit_Record is record
212 -- Corresponding ALI entry
214 Uname : Unit_Name_Type;
217 Sfile : File_Name_Type;
218 -- Name of source file
221 -- Indicates presence of PR parameter for a preelaborated package
224 -- Indicates presence of NE parameter for a unit that has does not
225 -- have an elaboration routine (since it has no elaboration code).
228 -- Indicates presence of PU parameter for a pure package
230 Dynamic_Elab : Boolean;
231 -- Set to True if the unit was compiled with dynamic elaboration
232 -- checks (i.e. either -gnatE or pragma Elaboration_Checks (Static)
233 -- was used to compile the unit).
235 Elaborate_Body : Boolean;
236 -- Indicates presence of EB parameter for a package which has a
237 -- pragma Preelaborate_Body.
239 Set_Elab_Entity : Boolean;
240 -- Indicates presence of EE parameter for a unit which has an
241 -- elaboration entity which must be set true as part of the
242 -- elaboration of the entity.
245 -- Indicates presence of RA parameter for a package that declares
246 -- at least one Remote Access to Class_Wide (RACW) object.
248 Remote_Types : Boolean;
249 -- Indicates presence of RT parameter for a package which has a
250 -- pragma Remote_Types.
252 Shared_Passive : Boolean;
253 -- Indicates presence of SP parameter for a package which has a
254 -- pragma Shared_Passive.
257 -- Indicates presence of RC parameter for a package which has a
258 -- pragma Remote_Call_Interface.
260 Predefined : Boolean;
261 -- Indicates if unit is language predefined (or a child of such a unit)
264 -- Indicates if unit is an internal unit (or a child of such a unit)
266 First_With : With_Id;
267 -- Id of first withs table entry for this file
270 -- Id of last withs table entry for this file
273 -- Id of first args table entry for this file
276 -- Id of last args table entry for this file
281 Is_Generic : Boolean;
282 -- True for generic unit (i.e. a generic declaration, or a generic
283 -- body). False for a non-generic unit.
285 Unit_Kind : Character;
286 -- Indicates the nature of the unit. 'p' for Packages and 's' for
289 Version : Version_String;
292 Icasing : Casing_Type;
293 -- Indicates casing of identifiers in source file for this unit. This
294 -- is used for informational output, and also for constructing the
295 -- main unit if it is being built in Ada.
297 Kcasing : Casing_Type;
298 -- Indicates casing of keyowords in source file for this unit. This
299 -- is used for informational output, and also for constructing the
300 -- main unit if it is being built in Ada.
302 Elab_Position : aliased Natural;
303 -- Initialized to zero. Set non-zero when a unit is chosen and
304 -- placed in the elaboration order. The value represents the
305 -- ordinal position in the elaboration order.
307 Init_Scalars : Boolean;
308 -- Set True if IS qualifier appears in ALI file, indicating that
309 -- an Initialize_Scalars pragma applies to the unit.
313 package Units is new Table.Table (
314 Table_Component_Type => Unit_Record,
315 Table_Index_Type => Unit_Id,
316 Table_Low_Bound => First_Unit_Entry,
317 Table_Initial => 100,
318 Table_Increment => 200,
319 Table_Name => "Unit");
325 -- These switches record status information about ali files that
326 -- have been read, for quick reference without searching tables.
328 Dynamic_Elaboration_Checks_Specified : Boolean := False;
329 -- Set to False by Initialize_ALI. Set to True if Read_ALI reads
330 -- a unit for which dynamic elaboration checking is enabled.
332 Float_Format_Specified : Character := ' ';
333 -- Set to blank by Initialize_ALI. Set to appropriate float format
334 -- character (V or I, see Opt.Float_Format) if an an ali file that
335 -- is read contains an F line setting the floating point format.
337 Initialize_Scalars_Used : Boolean := False;
338 -- Set True if an ali file contains the Initialize_Scalars flag
340 Locking_Policy_Specified : Character := ' ';
341 -- Set to blank by Initialize_ALI. Set to the appropriate locking policy
342 -- character if an ali file contains a P line setting the locking policy.
344 No_Normalize_Scalars_Specified : Boolean := False;
345 -- Set to False by Initialize_ALI. Set to True if an ali file indicates
346 -- that the file was compiled without normalize scalars.
348 No_Object_Specified : Boolean := False;
349 -- Set to False by Initialize_ALI. Set to True if an ali file contains
350 -- the No_Object flag.
352 Normalize_Scalars_Specified : Boolean := False;
353 -- Set to False by Initialize_ALI. Set to True if an ali file indicates
354 -- that the file was compiled in Normalize_Scalars mode.
356 No_Run_Time_Specified : Boolean := False;
357 -- Set to False by Initialize_ALI, Set to True if an ali file indicates
358 -- that the file was compiled in No_Run_Time mode.
360 Queuing_Policy_Specified : Character := ' ';
361 -- Set to blank by Initialize_ALI. Set to the appropriate queuing policy
362 -- character if an ali file contains a P line setting the queuing policy.
364 Restrictions : Restrictions_String := (others => 'n');
365 -- This array records the cumulative contributions of R lines in all
366 -- ali files. An entry is changed will be set to v if any ali file
367 -- indicates that the restriction is violated, and otherwise will be
368 -- set to r if the restriction is specified by some unit.
370 Static_Elaboration_Model_Used : Boolean := False;
371 -- Set to False by Initialize_ALI. Set to True if any ALI file for a
372 -- non-internal unit compiled with the static elaboration model is
375 Task_Dispatching_Policy_Specified : Character := ' ';
376 -- Set to blank by Initialize_ALI. Set to the appropriate task dispatching
377 -- policy character if an ali file contains a P line setting the
378 -- task dispatching policy.
380 Unreserve_All_Interrupts_Specified : Boolean := False;
381 -- Set to False by Initialize_ALI. Set to True if an ali file is read that
382 -- has P line specifying unreserve all interrupts mode.
384 Zero_Cost_Exceptions_Specified : Boolean := False;
385 -- Set to False by Initialize_ALI. Set to True if an ali file is read that
386 -- has a P line specifying the generation of zero cost exceptions.
392 -- Each With line (W line) in an ALI file generates a Withs table entry
394 No_With_Id : constant With_Id := With_Id'First;
395 -- Special value indicating no withs table entry
397 First_With_Entry : constant With_Id := No_With_Id + 1;
398 -- Id of first actual entry in table
400 type With_Record is record
402 Uname : Unit_Name_Type;
405 Sfile : File_Name_Type;
406 -- Name of source file, set to No_File in generic case
408 Afile : File_Name_Type;
409 -- Name of ALI file, set to No_File in generic case
412 -- Indicates presence of E parameter
414 Elaborate_All : Boolean;
415 -- Indicates presence of EA parameter
417 Elab_All_Desirable : Boolean;
418 -- Indicates presence of ED parameter
422 package Withs is new Table.Table (
423 Table_Component_Type => With_Record,
424 Table_Index_Type => With_Id,
425 Table_Low_Bound => First_With_Entry,
426 Table_Initial => 5000,
427 Table_Increment => 200,
428 Table_Name => "Withs");
430 ---------------------
431 -- Arguments Table --
432 ---------------------
434 -- Each Arg line (A line) in an ALI file generates an Args table entry
436 No_Arg_Id : constant Arg_Id := Arg_Id'First;
437 -- Special value indicating no args table entry
439 First_Arg_Entry : constant Arg_Id := No_Arg_Id + 1;
440 -- Id of first actual entry in table
442 package Args is new Table.Table (
443 Table_Component_Type => String_Ptr,
444 Table_Index_Type => Arg_Id,
445 Table_Low_Bound => First_Arg_Entry,
446 Table_Initial => 1000,
447 Table_Increment => 100,
448 Table_Name => "Args");
450 --------------------------
451 -- Linker_Options Table --
452 --------------------------
454 -- If an ALI file has one of more Linker_Options lines, then a single
455 -- entry is made in this table. If more than one Linker_Options lines
456 -- appears in a given ALI file, then the arguments are concatenated
457 -- to form the entry in this table, using a NUL character as the
458 -- separator, and a final NUL character is appended to the end.
460 type Linker_Option_Record is record
462 -- Name entry containing concatenated list of Linker_Options
463 -- arguments separated by NUL and ended by NUL as described above.
466 -- Unit_Id for the entry
468 Internal_File : Boolean;
469 -- Set True if the linker options are from an internal file. This is
470 -- used to insert certain standard entries after all the user entries
471 -- but before the entries from the run-time.
473 Original_Pos : Positive;
474 -- Keep track of original position in the linker options table. This
475 -- is used to implement a stable sort when we sort the linker options
479 -- Declare the Linker_Options Table
481 -- The indexes of active entries in this table range from 1 to the
482 -- value of Linker_Options.Last. The zero'th element is for sort call.
484 package Linker_Options is new Table.Table (
485 Table_Component_Type => Linker_Option_Record,
486 Table_Index_Type => Integer,
487 Table_Low_Bound => 0,
488 Table_Initial => 200,
489 Table_Increment => 400,
490 Table_Name => "Linker_Options");
492 -------------------------------------------
493 -- External Version Reference Hash Table --
494 -------------------------------------------
496 -- This hash table keeps track of external version reference strings
497 -- as read from E lines in the ali file. The stored values do not
498 -- include the terminating quote characters.
500 type Vindex is range 0 .. 98;
501 -- Type to define range of headers
503 function SHash (S : String_Ptr) return Vindex;
504 -- Hash function for this table
506 function SEq (F1, F2 : String_Ptr) return Boolean;
507 -- Equality function for this table
509 package Version_Ref is new Simple_HTable (
510 Header_Num => Vindex,
517 ------------------------------------
518 -- Sdep (Source Dependency) Table --
519 ------------------------------------
521 -- Each source dependency (D line) in an ALI file generates an
522 -- entry in the Sdep table.
524 No_Sdep_Id : constant Sdep_Id := Sdep_Id'First;
525 -- Special value indicating no Sdep table entry
527 First_Sdep_Entry : constant Sdep_Id := No_Sdep_Id + 1;
528 -- Id of first actual entry in table
530 type Sdep_Record is record
532 Sfile : File_Name_Type;
533 -- Name of source file
535 Stamp : Time_Stamp_Type;
536 -- Time stamp value. Note that this will be all zero characters
537 -- for the dummy entries for missing or non-dependent files.
540 -- Checksum value. Note that this will be all zero characters
541 -- for the dummy entries for missing or non-dependent files
543 Dummy_Entry : Boolean;
544 -- Set True for dummy entries that correspond to missing files
545 -- or files where no dependency relationship exists.
547 Subunit_Name : Name_Id;
548 -- Name_Id for subunit name if present, else No_Name
550 Rfile : File_Name_Type;
551 -- Reference file name. Same as Sfile unless a Source_Reference
552 -- pragma was used, in which case it reflects the name used in
556 -- Starting line number in file. Always 1, unless a Source_Reference
557 -- pragma was used, in which case it reflects the line number value
558 -- given in the pragma.
562 package Sdep is new Table.Table (
563 Table_Component_Type => Sdep_Record,
564 Table_Index_Type => Sdep_Id,
565 Table_Low_Bound => First_Sdep_Entry,
566 Table_Initial => 5000,
567 Table_Increment => 200,
568 Table_Name => "Sdep");
570 ----------------------------
571 -- Use of Name Table Info --
572 ----------------------------
574 -- All unit names and file names are entered into the Names table. The
575 -- Info fields of these entries are used as follows:
577 -- Unit name Info field has Unit_Id of unit table entry
578 -- ALI file name Info field has ALI_Id of ALI table entry
579 -- Source file name Info field has Source_Id of source table entry
581 --------------------------
582 -- Cross-Reference Data --
583 --------------------------
585 -- The following table records cross-reference sections, there is one
586 -- entry for each X header line in the ALI file for an xref section.
587 -- Note that there will be no entries in this table if the Read_Xref
588 -- parameter to Scan_ALI was set to False.
590 type Xref_Section_Record is record
592 -- Dependency number for file (entry in Sdep.Table)
598 -- First entry in Xref_Entity table
601 -- Last entry in Xref_Entity table
605 package Xref_Section is new Table.Table (
606 Table_Component_Type => Xref_Section_Record,
607 Table_Index_Type => Nat,
608 Table_Low_Bound => 1,
610 Table_Increment => 300,
611 Table_Name => "Xref_Section");
613 -- The following is used to indicate whether a typeref field is present
614 -- for the entity, and if so what kind of typeref field.
617 Tref_None, -- No typeref present
618 Tref_Access, -- Access type typeref (points to designated type)
619 Tref_Derived, -- Derived type typeref (points to parent type)
620 Tref_Type); -- All other cases
622 -- The following table records entities for which xrefs are recorded
624 type Xref_Entity_Record is record
626 -- Line number of definition
629 -- Set to the identification character for the entity. See section
630 -- "Cross-Reference Entity Identifiers in lib-xref.ads for details.
633 -- Column number of definition
636 -- True if entity is library level entity
642 -- This field is set to the line number of a renaming reference if
643 -- one is present, or to zero if no renaming reference is present
646 -- This field is set to the column number of a renaming reference
647 -- if one is present, or to zero if no renaming reference is present.
650 -- Indicates if a typeref is present, and if so what kind. Set to
651 -- Tref_None if no typeref field is present.
653 Tref_File_Num : Sdep_Id;
654 -- This field is set to No_Sdep_Id if no typeref is present, or
655 -- if the typeref refers to an entity in standard. Otherwise it
656 -- it is the dependency reference for the file containing the
657 -- declaration of the typeref entity.
660 -- This field is set to zero if no typeref is present, or if the
661 -- typeref refers to an entity in standard. Otherwise it contains
662 -- the line number of the declaration of the typeref entity.
664 Tref_Type : Character;
665 -- This field is set to blank if no typeref is present, or if the
666 -- typeref refers to an entity in standard. Otherwise it contains
667 -- the identification character for the typeref entity. See section
668 -- "Cross-Reference Entity Identifiers in lib-xref.ads for details.
671 -- This field is set to zero if no typeref is present, or if the
672 -- typeref refers to an entity in standard. Otherwise it contains
673 -- the column number of the declaration of the parent type.
675 Tref_Standard_Entity : Name_Id;
676 -- This field is set to No_Name if no typeref is present or if the
677 -- typeref refers to a declared entity rather than an entity in
678 -- package Standard. If there is a typeref that references an
679 -- entity in package Standard, then this field is a Name_Id
680 -- reference for the entity name.
683 -- Index into Xref table of first cross-reference
686 -- Index into Xref table of last cross-reference. The value in
687 -- Last_Xref can be less than the First_Xref value to indicate
688 -- that no entries are present in the Xref Table.
691 package Xref_Entity is new Table.Table (
692 Table_Component_Type => Xref_Entity_Record,
693 Table_Index_Type => Nat,
694 Table_Low_Bound => 1,
695 Table_Initial => 500,
696 Table_Increment => 300,
697 Table_Name => "Xref_Entity");
699 -- The following table records actual cross-references
701 type Xref_Record is record
703 -- Set to the file dependency number for the cross-reference. Note
704 -- that if no file entry is present explicitly, this is just a copy
705 -- of the reference for the current cross-reference section.
708 -- Line number for the reference
711 -- Indicates type of reference, using code used in ALI file:
715 -- c = completion of private or incomplete type
716 -- x = type extension
717 -- i = implicit reference
718 -- See description in lib-xref.ads for further details
721 -- Column number for the reference
723 -- Note: for instantiation references, Rtype is set to ' ', and Col is
724 -- set to zero. One or more such entries can follow any other reference.
727 package Xref is new Table.Table (
728 Table_Component_Type => Xref_Record,
729 Table_Index_Type => Nat,
730 Table_Low_Bound => 1,
731 Table_Initial => 2000,
732 Table_Increment => 300,
733 Table_Name => "Xref");
735 --------------------------------------
736 -- Subprograms for Reading ALI File --
737 --------------------------------------
739 procedure Initialize_ALI;
740 -- Initialize the ALI tables. Also resets all switch values to defaults.
747 Read_Xref : Boolean := False)
749 -- Given the text, T, of an ALI file, F, scan and store the information
750 -- from the file, and return the Id of the resulting entry in the ALI
751 -- table. Switch settings may be modified as described above in the
752 -- switch description settings.
754 -- Ignore_ED is normally False. If set to True, it indicates that
755 -- all ED (elaboration desirable) indications in the ALI file are
758 -- Err determines the action taken on an incorrectly formatted file.
759 -- If Err is False, then an error message is output, and the program
760 -- is terminated. If Err is True, then no error message is output,
761 -- and No_ALI_Id is returned.
763 -- Read_XREF is set True to read and acquire the cross-reference
764 -- information, otherwise the scan is terminated when a cross-
765 -- reference line is encountered.