OSDN Git Service

Update FSF address
[pf3gnuchains/gcc-fork.git] / gcc / ada / lib.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                                  L I B                                   --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --          Copyright (C) 1992-2004 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 -- As a special exception,  if other files  instantiate  generics from this --
23 -- unit, or you link  this unit with other files  to produce an executable, --
24 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
25 -- covered  by the  GNU  General  Public  License.  This exception does not --
26 -- however invalidate  any other reasons why  the executable file  might be --
27 -- covered by the  GNU Public License.                                      --
28 --                                                                          --
29 -- GNAT was originally developed  by the GNAT team at  New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
31 --                                                                          --
32 ------------------------------------------------------------------------------
33
34 --  This package contains routines for accessing and outputting the library
35 --  information. It contains the routine to load subsidiary units.
36
37 with Alloc;
38 with Table;
39 with Types;  use Types;
40
41 package Lib is
42
43    --------------------------------------------
44    -- General Approach to Library Management --
45    --------------------------------------------
46
47    --  As described in GNote #1, when a unit is compiled, all its subsidiary
48    --  units are recompiled, including the following:
49
50    --    (a) Corresponding spec for a body
51    --    (b) Parent spec of a child library spec
52    --    (d) With'ed specs
53    --    (d) Parent body of a subunit
54    --    (e) Subunits corresponding to any specified stubs
55    --    (f) Bodies of inlined subprograms that are called
56    --    (g) Bodies of generic subprograms or packages that are instantiated
57    --    (h) Bodies of packages containing either of the above two items
58    --    (i) Specs and bodies of runtime units
59    --    (j) Parent specs for with'ed child library units
60
61    --  If a unit is being compiled only for syntax checking, then no subsidiary
62    --  units are loaded, the syntax check applies only to the main unit,
63    --  i.e. the one contained in the source submitted to the library.
64
65    --  If a unit is being compiled for syntax and semantic checking, then only
66    --  cases (a)-(d) loads are performed, since the full semantic checking can
67    --  be carried out without needing (e)-(i) loads. In this case no object
68    --  file, or library information file, is generated, so the missing units
69    --  do not affect the results.
70
71    --  Specifications of library subprograms, subunits, and generic specs
72    --  and bodies, can only be compiled in syntax/semantic checking mode,
73    --  since no code is ever generated directly for these units. In the case
74    --  of subunits, only the compilation of the ultimate parent unit generates
75    --  actual code. If a subunit is submitted to the compiler in syntax/
76    --  semantic checking mode, the parent (or parents in the nested case) are
77    --  semantically checked only up to the point of the corresponding stub.
78
79    --  If code is being generated, then all the above units are required,
80    --  although the need for bodies of inlined procedures can be suppressed
81    --  by the use of a switch that sets the mode to ignore pragma Inline
82    --  statements.
83
84    --  The two main sections of the front end, Par and Sem, are recursive.
85    --  Compilation proceeds unit by unit making recursive calls as necessary.
86    --  The process is controlled from the GNAT main program, which makes calls
87    --  to Par and Sem sequence for the main unit.
88
89    --  Par parses the given unit, and then, after the parse is complete, uses
90    --  the Par.Load subprogram to load all its subsidiary units in categories
91    --  (a)-(d) above, installing pointers to the loaded units in the parse
92    --  tree, as described in a later section of this spec. If any of these
93    --  required units is missing, a fatal error is signalled, so that no
94    --  attempt is made to run Sem in such cases, since it is assumed that
95    --  too many cascaded errors would result, and the confusion would not
96    --  be helpful.
97
98    --  Following the call to Par on the main unit, the entire tree of required
99    --  units is thus loaded, and Sem is called on the main unit. The parameter
100    --  passed to Sem is the unit to be analyzed. The visibility table, which
101    --  is a single global structure, starts out containing only the entries
102    --  for the visible entities in Standard. Every call to Sem establishes a
103    --  new scope stack table, pushing an entry for Standard on entry to provide
104    --  the proper initial scope environment.
105
106    --  Sem first proceeds to perform semantic analysis on the currently loaded
107    --  units as follows:
108
109    --    In the case of a body (case (a) above), Sem analyzes the corresponding
110    --    spec, using a recursive call to Sem. As is always expected to be the
111    --    case with calls to Sem, any entities installed in the visibility table
112    --    are removed on exit from Sem, so that these entities have to be
113    --    reinstalled on return to continue the analysis of the body which of
114    --    course needs visibility of these entities.
115    --
116    --    In the case of the parent of a child spec (case (b) above), a similar
117    --    call is made to Sem to analyze the parent. Again, on return, the
118    --    entities from the analyzed parent spec have to be installed in the
119    --    visibility table of the caller (the child unit), which must have
120    --    visibility to the entities in its parent spec.
121
122    --    For with'ed specs (case (c) above), a recursive call to Sem is made
123    --    to analyze each spec in turn. After all the spec's have been analyzed,
124    --    but not till that point, the entities from all the with'ed units are
125    --    reinstalled in the visibility table so that the caller can proceed
126    --    with the analysis of the unit doing the with's with the necessary
127    --    entities made either potentially use visible or visible by selection
128    --    as needed.
129
130    --    Case (d) arises when Sem is passed a subunit to analyze. This means
131    --    that the main unit is a subunit, and the unit passed to Sem is either
132    --    the main unit, or one of its ancestors that is still a subunit. Since
133    --    analysis must start at the top of the tree, Sem essentially cancels
134    --    the current call by immediately making a call to analyze the parent
135    --    (when this call is finished it immediately returns, so logically this
136    --    call is like a goto). The subunit will then be analyzed at the proper
137    --    time as described for the stub case. Note that we also turn off the
138    --    indication that code should be generated in this case, since the only
139    --    time we generate code for subunits is when compiling the main parent.
140
141    --    Case (e), subunits corresponding to stubs, are handled as the stubs
142    --    are encountered. There are three sub-cases:
143
144    --      If the subunit has already been loaded, then this means that the
145    --      main unit was a subunit, and we are back on our way down to it
146    --      after following the initial processing described for case (d).
147    --      In this case we analyze this particular subunit, as described
148    --      for the case where we are generating code, but when we get back
149    --      we are all done, since the rest of the parent is irrelevant. To
150    --      get out of the parent, we raise the exception Subunit_Found, which
151    --      is handled at the outer level of Sem.
152
153    --      The cases where the subunit has not already been loaded correspond
154    --      to cases where the main unit was a parent. In this case the action
155    --      depends on whether or not we are generating code. If we are not
156    --      generating code, then this is the case where we can simply ignore
157    --      the subunit, since in checking mode we don't even want to insist
158    --      that the subunit exist, much less waste time checking it.
159
160    --      If we are generating code, then we need to load and analyze
161    --      all subunits. This is achieved with a call to Lib.Load to load
162    --      and parse the unit, followed by processing that installs the
163    --      context clause of the subunit, analyzes the subunit, and then
164    --      removes the context clause (from the visibility chains of the
165    --      parent). Note that we do *not* do a recursive call to Sem in
166    --      this case, precisely because we need to do the analysis of the
167    --      subunit with the current visibility table and scope stack.
168
169    --    Case (f) applies only to subprograms for which a pragma Inline is
170    --    given, providing that the compiler is operating in the mode where
171    --    pragma Inline's are activated. When the expander encounters a call
172    --    to such a subprogram, it loads the body of the subprogram if it has
173    --    not already been loaded, and calls Sem to process it.
174
175    --    Case (g) is similar to case (f), except that the body of a generic
176    --    is unconditionally required, regardless of compiler mode settings.
177    --    As in the subprogram case, when the expander encounters a generic
178    --    instantiation, it loads the generic body of the subprogram if it
179    --    has not already been loaded, and calls Sem to process it.
180
181    --    Case (h) arises when a package contains either an inlined subprogram
182    --    which is called, or a generic which is instantiated. In this case the
183    --    body of the package must be loaded and analyzed with a call to Sem.
184
185    --    Case (i) is handled by adding implicit with clauses to the context
186    --    clauses of all units that potentially reference the relevant runtime
187    --    entities. Note that since we have the full set of units available,
188    --    the parser can always determine the set of runtime units that is
189    --    needed. These with clauses do not have associated use clauses, so
190    --    all references to the entities must be by selection. Once the with
191    --    clauses have been added, subsequent processing is as for normal
192    --    with clauses.
193
194    --    Case (j) is also handled by adding appropriate implicit with clauses
195    --    to any unit that withs a child unit. Again there is no use clause,
196    --    and subsequent processing proceeds as for an explicit with clause.
197
198    --  Sem thus completes the loading of all required units, except those
199    --  required for inline subprogram bodies or inlined generics. If any
200    --  of these load attempts fails, then the expander will not be called,
201    --  even if code was to be generated. If the load attempts all succeed
202    --  then the expander is called, though the attempt to generate code may
203    --  still fail if an error occurs during a load attempt for an inlined
204    --  body or a generic body.
205
206    -------------------------------------------
207    -- Special Handling of Subprogram Bodies --
208    -------------------------------------------
209
210    --  A subprogram body (in an adb file) may stand for both a spec and a
211    --  body. A simple model (and one that was adopted through version 2.07),
212    --  is simply to assume that such an adb file acts as its own spec if no
213    --  ads file is present.
214
215    --  However, this is not correct. RM 10.1.4(4) requires that such a body
216    --  act as a spec unless a subprogram declaration of the same name is
217    --  already present. The correct interpretation of this in GNAT library
218    --  terms is to ignore an existing ads file of the same name unless this
219    --  ads file contains a subprogram declaration with the same name.
220
221    --  If there is an ads file with a unit other than a subprogram declaration
222    --  with the same name, then a fatal message is output, noting that this
223    --  irrelevant file must be deleted before the body can be compiled. See
224    --  ACVC test CA1020D to see how this processing is required.
225
226    -----------------
227    -- Global Data --
228    -----------------
229
230    Current_Sem_Unit : Unit_Number_Type := Main_Unit;
231    --  Unit number of unit currently being analyzed/expanded. This is set when
232    --  ever a new unit is entered, saving and restoring the old value, so that
233    --  it always reflects the unit currently being analyzed. The initial value
234    --  of Main_Unit ensures that a proper value is set initially, and in
235    --  particular for analysis of configuration pragmas in gnat.adc.
236
237    Main_Unit_Entity : Entity_Id;
238    --  Entity of main unit, same as Cunit_Entity (Main_Unit) except where
239    --  Main_Unit is a body with a separate spec, in which case it is the
240    --  entity for the spec.
241
242    Unit_Exception_Table_Present : Boolean;
243    --  Set true if a unit exception table is present for the unit (i.e.
244    --  zero cost exception handling is active and there is at least one
245    --  subprogram in the extended unit).
246
247    -----------------
248    -- Units Table --
249    -----------------
250
251    --  The units table has an entry for each unit (source file) read in by the
252    --  current compilation. The table is indexed by the unit number value,
253    --  The first entry in the table, subscript Main_Unit, is for the main file.
254    --  Each entry in this units table contains the following data.
255
256    --    Unit_File_Name
257    --      The name of the source file containing the unit. Set when the entry
258    --      is created by a call to Lib.Load, and then cannot be changed.
259
260    --    Source_Index
261    --      The index in the source file table of the corresponding source file.
262    --      Set when the entry is created by a call to Lib.Load and then cannot
263    --      be changed.
264
265    --    Munit_Index
266    --      The index of the unit within the file for multiple unit per file
267    --      mode. Set to zero in normal single unit per file mode.
268
269    --    Error_Location
270    --      This is copied from the Sloc field of the Enode argument passed
271    --      to Load_Unit. It refers to the enclosing construct which caused
272    --      this unit to be loaded, e.g. most typically the with clause that
273    --      referenced the unit, and is used for error handling in Par.Load.
274
275    --    Expected_Unit
276    --      This is the expected unit name for a file other than the main unit,
277    --      since these are cases where we load the unit using Lib.Load and we
278    --      know the unit that is expected. It must be the same as Unit_Name
279    --      if it is set (see test in Par.Load). Expected_Unit is set to
280    --      No_Name for the main unit.
281
282    --    Unit_Name
283    --      The name of the unit. Initialized to No_Name by Lib.Load, and then
284    --      set by the parser when the unit is parsed to the unit name actually
285    --      found in the file (which should, in the absence of errors) be the
286    --      same name as Expected_Unit.
287
288    --    Cunit
289    --      Pointer to the N_Compilation_Unit node. Initially set to Empty by
290    --      Lib.Load, and then reset to the required node by the parser when
291    --      the unit is parsed.
292
293    --    Cunit_Entity
294    --      Pointer to the entity node for the compilation unit. Initially set
295    --      to Empty by Lib.Load, and then reset to the required entity by the
296    --      parser when the unit is parsed.
297
298    --    Dependency_Num
299    --      This is the number of the unit within the generated dependency
300    --      lines (D lines in the ALI file) which are sorted into alphabetical
301    --      order. The number is ones origin, so a value of 2 refers to the
302    --      second generated D line. The Dependency_Number values are set
303    --      as the D lines are generated, and are used to generate proper
304    --      unit references in the generated xref information.
305
306    --    Dynamic_Elab
307    --      A flag indicating if this unit was compiled with dynamic elaboration
308    --      checks specified (as the result of using the -gnatE compilation
309    --      option or a pragma Elaboration_Checks (Dynamic).
310
311    --    Fatal_Error
312    --      A flag that is initialized to False, and gets set to True if a fatal
313    --      error occurs during the processing of a unit. A fatal error is one
314    --      defined as serious enough to stop the next phase of the compiler
315    --      from running (i.e. fatal error during parsing stops semantics,
316    --      fatal error during semantics stops code generation). Note that
317    --      currently, errors of any kind cause Fatal_Error to be set, but
318    --      eventually perhaps only errors labeled as Fatal_Errors should be
319    --      this severe if we decide to try Sem on sources with minor errors.
320
321    --    Generate_Code
322    --      This flag is set True for all units in the current file for which
323    --      code is to be generated. This includes the unit explicitly compiled,
324    --      together with its specification, and any subunits.
325
326    --    Has_RACW
327    --      A Boolean flag, initially set to False when a unit entry is created,
328    --      and set to True if the unit defines a remote access to class wide
329    --      (RACW) object. This is used for controlling generation of the RA
330    --      attribute in the ali file.
331
332    --    Ident_String
333    --      N_String_Literal node from a valid pragma Ident that applies to
334    --      this unit. If no Ident pragma applies to the unit, then Empty.
335
336    --    Loading
337    --      A flag that is used to catch circular WITH dependencies. It is set
338    --      True when an entry is initially created in the file table, and set
339    --      False when the load is completed, or ends with an error.
340
341    --    Main_Priority
342    --      This field is used to indicate the priority of a possible main
343    --      program, as set by a pragma Priority. A value of -1 indicates
344    --      that the default priority is to be used (and is also used for
345    --      entries that do not correspond to possible main programs).
346
347    --    Serial_Number
348    --      This field holds a serial number used by New_Internal_Name to
349    --      generate unique temporary numbers on a unit by unit basis. The
350    --      only access to this field is via the Increment_Serial_Number
351    --      routine which increments the current value and returns it. This
352    --      serial number is separate for each unit.
353
354    --    Version
355    --      This field holds the version of the unit, which is computed as
356    --      the exclusive or of the checksums of this unit, and all its
357    --      semantically dependent units. Access to the version number field
358    --      is not direct, but is done through the routines described below.
359    --      When a unit table entry is created, this field is initialized to
360    --      the checksum of the corresponding source file. Version_Update is
361    --      then called to reflect the contributions of any unit on which this
362    --      unit is semantically dependent.
363
364    --  The units table is reset to empty at the start of the compilation of
365    --  each main unit by Lib.Initialize. Entries are then added by calls to
366    --  the Lib.Load procedure. The following subprograms are used to access
367    --  and modify entries in the Units table. Individual entries are accessed
368    --  using a unit number value which ranges from Main_Unit (the first entry,
369    --  which is always for the current main unit) to Last_Unit.
370
371    Default_Main_Priority : constant Int := -1;
372    --  Value used in Main_Priority field to indicate default main priority
373
374    function Cunit            (U : Unit_Number_Type) return Node_Id;
375    function Cunit_Entity     (U : Unit_Number_Type) return Entity_Id;
376    function Dependency_Num   (U : Unit_Number_Type) return Nat;
377    function Dynamic_Elab     (U : Unit_Number_Type) return Boolean;
378    function Error_Location   (U : Unit_Number_Type) return Source_Ptr;
379    function Expected_Unit    (U : Unit_Number_Type) return Unit_Name_Type;
380    function Fatal_Error      (U : Unit_Number_Type) return Boolean;
381    function Generate_Code    (U : Unit_Number_Type) return Boolean;
382    function Ident_String     (U : Unit_Number_Type) return Node_Id;
383    function Has_RACW         (U : Unit_Number_Type) return Boolean;
384    function Loading          (U : Unit_Number_Type) return Boolean;
385    function Main_Priority    (U : Unit_Number_Type) return Int;
386    function Munit_Index      (U : Unit_Number_Type) return Nat;
387    function Source_Index     (U : Unit_Number_Type) return Source_File_Index;
388    function Unit_File_Name   (U : Unit_Number_Type) return File_Name_Type;
389    function Unit_Name        (U : Unit_Number_Type) return Unit_Name_Type;
390    --  Get value of named field from given units table entry
391
392    procedure Set_Cunit          (U : Unit_Number_Type; N : Node_Id);
393    procedure Set_Cunit_Entity   (U : Unit_Number_Type; E : Entity_Id);
394    procedure Set_Dynamic_Elab   (U : Unit_Number_Type; B : Boolean := True);
395    procedure Set_Error_Location (U : Unit_Number_Type; W : Source_Ptr);
396    procedure Set_Fatal_Error    (U : Unit_Number_Type; B : Boolean := True);
397    procedure Set_Generate_Code  (U : Unit_Number_Type; B : Boolean := True);
398    procedure Set_Has_RACW       (U : Unit_Number_Type; B : Boolean := True);
399    procedure Set_Ident_String   (U : Unit_Number_Type; N : Node_Id);
400    procedure Set_Loading        (U : Unit_Number_Type; B : Boolean := True);
401    procedure Set_Main_Priority  (U : Unit_Number_Type; P : Int);
402    procedure Set_Unit_Name      (U : Unit_Number_Type; N : Unit_Name_Type);
403    --  Set value of named field for given units table entry. Note that we
404    --  do not have an entry for each possible field, since some of the fields
405    --  can only be set by specialized interfaces (defined below).
406
407    function Version_Get (U : Unit_Number_Type) return Word_Hex_String;
408    --  Returns the version as a string with 8 hex digits (upper case letters)
409
410    function Last_Unit return Unit_Number_Type;
411    --  Unit number of last allocated unit
412
413    function Num_Units return Nat;
414    --  Number of units currently in unit table
415
416    procedure Remove_Unit (U : Unit_Number_Type);
417    --  Remove unit U from unit table. Currently this is effective only
418    --  if U is the last unit currently stored in the unit table.
419
420    function Entity_Is_In_Main_Unit (E : Entity_Id) return Boolean;
421    --  Returns True if the entity E is declared in the main unit, or, in
422    --  its corresponding spec, or one of its subunits. Entities declared
423    --  within generic instantiations return True if the instantiation is
424    --  itself "in the main unit" by this definition. Otherwise False.
425
426    function Get_Source_Unit (N : Node_Or_Entity_Id) return Unit_Number_Type;
427    pragma Inline (Get_Source_Unit);
428    function Get_Source_Unit (S : Source_Ptr) return Unit_Number_Type;
429    --  Return unit number of file identified by given source pointer value.
430    --  This call must always succeed, since any valid source pointer value
431    --  belongs to some previously loaded module. If the given source pointer
432    --  value is within an instantiation, this function returns the unit
433    --  number of the templace, i.e. the unit containing the source code
434    --  corresponding to the given Source_Ptr value. The version taking
435    --  a Node_Id argument, N, simply applies the function to Sloc (N).
436
437    function Get_Code_Unit (N : Node_Or_Entity_Id) return Unit_Number_Type;
438    pragma Inline (Get_Code_Unit);
439    function Get_Code_Unit (S : Source_Ptr) return Unit_Number_Type;
440    --  This is like Get_Source_Unit, except that in the instantiation case,
441    --  it uses the location of the top level instantiation, rather than the
442    --  template, so it returns the unit number containing the code that
443    --  corresponds to the node N, or the source location S.
444
445    function In_Same_Source_Unit (N1, N2 : Node_Or_Entity_Id) return Boolean;
446    pragma Inline (In_Same_Source_Unit);
447    --  Determines if the two nodes or entities N1 and N2 are in the same
448    --  source unit, the criterion being that Get_Source_Unit yields the
449    --  same value for each argument.
450
451    function In_Same_Code_Unit (N1, N2 : Node_Or_Entity_Id) return Boolean;
452    pragma Inline (In_Same_Code_Unit);
453    --  Determines if the two nodes or entities N1 and N2 are in the same
454    --  code unit, the criterion being that Get_Code_Unit yields the same
455    --  value for each argument.
456
457    function In_Same_Extended_Unit (N1, N2 : Node_Or_Entity_Id) return Boolean;
458    pragma Inline (In_Same_Extended_Unit);
459    --  Determines if two nodes or entities N1 and N2 are in the same
460    --  extended unit, where an extended unit is defined as a unit and all
461    --  its subunits (considered recursively, i.e. subunits of subunits are
462    --  included). Returns true if S1 and S2 are in the same extended unit
463    --  and False otherwise.
464
465    function In_Same_Extended_Unit (S1, S2 : Source_Ptr) return Boolean;
466    pragma Inline (In_Same_Extended_Unit);
467    --  Determines if the two source locations S1 and S2 are in the same
468    --  extended unit, where an extended unit is defined as a unit and all
469    --  its subunits (considered recursively, i.e. subunits of subunits are
470    --  included). Returns true if S1 and S2 are in the same extended unit
471    --  and False otherwise.
472
473    function In_Extended_Main_Code_Unit
474      (N : Node_Or_Entity_Id) return Boolean;
475    --  Return True if the node is in the generated code of the extended main
476    --  unit, defined as the main unit, its specification (if any), and all
477    --  its subunits (considered recursively). Units for which this enquiry
478    --  returns True are those for which code will be generated. Nodes from
479    --  instantiations are included in the extended main unit for this call.
480    --  If the main unit is itself a subunit, then the extended main unit
481    --  includes its parent unit, and the parent unit spec if it is separate.
482
483    function In_Extended_Main_Code_Unit (Loc : Source_Ptr) return Boolean;
484    --  Same function as above, but argument is a source pointer rather
485    --  than a node.
486
487    function In_Extended_Main_Source_Unit
488      (N : Node_Or_Entity_Id) return Boolean;
489    --  Return True if the node is in the source text of the extended main
490    --  unit, defined as the main unit, its specification (if any), and all
491    --  its subunits (considered recursively). Units for which this enquiry
492    --  returns True are those for which code will be generated. This differs
493    --  from In_Extended_Main_Code_Unit only in that instantiations are not
494    --  included for the purposes of this call. If the main unit is itself
495    --  a subunit, then the extended main unit includes its parent unit,
496    --  and the parent unit spec if it is separate.
497
498    function In_Extended_Main_Source_Unit (Loc : Source_Ptr) return Boolean;
499    --  Same function as above, but argument is a source pointer rather
500    --  than a node.
501
502    function Earlier_In_Extended_Unit (S1, S2 : Source_Ptr) return Boolean;
503    --  Given two Sloc values  for which In_Same_Extended_Unit is true,
504    --  determine if S1 appears before S2. Returns True if S1 appears before
505    --  S2, and False otherwise. The result is undefined if S1 and S2 are
506    --  not in the same extended unit.
507
508    function Compilation_Switches_Last return Nat;
509    --  Return the count of stored compilation switches
510
511    function Get_Compilation_Switch (N : Pos) return String_Ptr;
512    --  Return the Nth stored compilation switch, or null if less than N
513    --  switches have been stored. Used by ASIS and back ends written in Ada.
514
515    function Get_Cunit_Unit_Number (N : Node_Id) return Unit_Number_Type;
516    --  Return unit number of the unit whose N_Compilation_Unit node is the
517    --  one passed as an argument. This must always succeed since the node
518    --  could not have been built without making a unit table entry.
519
520    function Get_Cunit_Entity_Unit_Number
521      (E : Entity_Id) return Unit_Number_Type;
522    --  Return unit number of the unit whose compilation unit spec entity is
523    --  the one passed as an argument. This must always succeed since the
524    --  entity could not have been built without making a unit table entry.
525
526    function Increment_Serial_Number return Nat;
527    --  Increment Serial_Number field for current unit, and return the
528    --  incremented value.
529
530    procedure Synchronize_Serial_Number;
531    --  This function increments the Serial_Number field for the current
532    --  unit but does not return the incremented value. This is used when
533    --  there is a situation where one path of control increments a serial
534    --  number (using Increment_Serial_Number), and the other path does not
535    --  and it is important to keep the serial numbers synchronized in the
536    --  two cases (e.g. when the references in a package and a client must
537    --  be kept consistent).
538
539    procedure Replace_Linker_Option_String
540      (S            : String_Id;
541       Match_String : String);
542    --  Replace an existing Linker_Option if the prefix Match_String
543    --  matches, otherwise call Store_Linker_Option_String.
544
545    procedure Store_Compilation_Switch (Switch : String);
546    --  Called to register a compilation switch, either front-end or
547    --  back-end, which may influence the generated output file(s).
548
549    procedure Disable_Switch_Storing;
550    --  Disable the registration of compilation switches with
551    --  Store_Compilation_Switch. This is used to not register switches added
552    --  automatically by the gcc driver.
553
554    procedure Store_Linker_Option_String (S : String_Id);
555    --  This procedure is called to register the string from a pragma
556    --  Linker_Option. The argument is the Id of the string to register.
557
558    procedure Initialize;
559    --  Initialize internal tables
560
561    procedure Lock;
562    --  Lock internal tables before calling back end
563
564    procedure Tree_Read;
565    --  Initializes internal tables from current tree file using the relevant
566    --  Table.Tree_Read routines.
567
568    procedure Tree_Write;
569    --  Writes out internal tables to current tree file using the relevant
570    --  Table.Tree_Write routines.
571
572    function Is_Loaded (Uname : Unit_Name_Type) return Boolean;
573    --  Determines if unit with given name is already loaded, i.e. there is
574    --  already an entry in the file table with this unit name for which the
575    --  corresponding file was found and parsed. Note that the Fatal_Error flag
576    --  of this entry must be checked before proceeding with further processing.
577
578    procedure Version_Referenced (S : String_Id);
579    --  This routine is called from Exp_Attr to register the use of a Version
580    --  or Body_Version attribute. The argument is the external name used to
581    --  access the version string.
582
583    procedure List (File_Names_Only : Boolean := False);
584    --  Lists units in active library (i.e. generates output consisting of a
585    --  sorted listing of the units represented in File table, with the
586    --  exception of the main unit). If File_Names_Only is set to True, then
587    --  the list includes only file names, and no other information. Otherwise
588    --  the unit name and time stamp are also output. File_Names_Only also
589    --  restricts the list to exclude any predefined files.
590
591    function Generic_Separately_Compiled (E : Entity_Id) return Boolean;
592    --  This is the old version of tbe documentation of this function:
593    --
594    --  Most generic units must be separately compiled. Since we always use
595    --  macro substitution for generics, the resulting object file is a dummy
596    --  one with no code, but the ali file has the normal form, and we need
597    --  this ali file so that the binder can work out a correct order of
598    --  elaboration. However, we do not need to separate compile generics
599    --  if the generic files are language defined, since in this case there
600    --  are no order of elaborration problems, and we can simply incorporate
601    --  the context clause of the generic unit into the client. There are two
602    --  reasons for making this exception for predefined units. First, clearly
603    --  it is more efficient not to introduce extra unnecessary files. Second,
604    --  the old version of GNAT did not compile any generic units. That was
605    --  clearly incorrect in some cases of complex order of elaboration and
606    --  was fixed in version 3.10 of GNAT. However, the transition would have
607    --  caused bootstrap path problems in the case of generics used in the
608    --  compiler itself. The only such generics are predefined ones. This
609    --  function returns True if the given generic unit entity E is for a
610    --  generic unit that should be separately compiled, and false otherwise.
611    --
612    --  Now GNAT can compile any generic unit including predefined ones, but
613    --  because of the backward compatibility (to keep the ability to use old
614    --  compiler versions to build GNAT) compiling library generics is an
615    --  option. That is, now GNAT compiles a library generic as an ordinary
616    --  unit, but it also can build an exeutable in case if its library
617    --  contains some (or all) predefined generics non compiled. See 9628-002
618    --  for the description of changes to be done to get rid of a special
619    --  processing of library generic.
620    --
621    --  So now this function returns TRUE if a generic MUST be separately
622    --  compiled with the current approach.
623
624    function Generic_Separately_Compiled
625      (Sfile : File_Name_Type) return  Boolean;
626    --  Same as the previous function, but works directly on a unit file name.
627
628 private
629    pragma Inline (Cunit);
630    pragma Inline (Cunit_Entity);
631    pragma Inline (Dependency_Num);
632    pragma Inline (Fatal_Error);
633    pragma Inline (Generate_Code);
634    pragma Inline (Has_RACW);
635    pragma Inline (Increment_Serial_Number);
636    pragma Inline (Loading);
637    pragma Inline (Main_Priority);
638    pragma Inline (Munit_Index);
639    pragma Inline (Set_Cunit);
640    pragma Inline (Set_Cunit_Entity);
641    pragma Inline (Set_Fatal_Error);
642    pragma Inline (Set_Generate_Code);
643    pragma Inline (Set_Has_RACW);
644    pragma Inline (Set_Loading);
645    pragma Inline (Set_Main_Priority);
646    pragma Inline (Set_Unit_Name);
647    pragma Inline (Source_Index);
648    pragma Inline (Unit_File_Name);
649    pragma Inline (Unit_Name);
650
651    type Unit_Record is record
652       Unit_File_Name   : File_Name_Type;
653       Unit_Name        : Unit_Name_Type;
654       Munit_Index      : Nat;
655       Expected_Unit    : Unit_Name_Type;
656       Source_Index     : Source_File_Index;
657       Cunit            : Node_Id;
658       Cunit_Entity     : Entity_Id;
659       Dependency_Num   : Int;
660       Fatal_Error      : Boolean;
661       Generate_Code    : Boolean;
662       Has_RACW         : Boolean;
663       Ident_String     : Node_Id;
664       Loading          : Boolean;
665       Main_Priority    : Int;
666       Serial_Number    : Nat;
667       Version          : Word;
668       Dynamic_Elab     : Boolean;
669       Error_Location   : Source_Ptr;
670    end record;
671
672    package Units is new Table.Table (
673      Table_Component_Type => Unit_Record,
674      Table_Index_Type     => Unit_Number_Type,
675      Table_Low_Bound      => Main_Unit,
676      Table_Initial        => Alloc.Units_Initial,
677      Table_Increment      => Alloc.Units_Increment,
678      Table_Name           => "Units");
679
680    --  The following table stores strings from pragma Linker_Option lines
681
682    type Linker_Option_Entry is record
683       Option : String_Id;
684       --  The string for the linker option line
685
686       Unit : Unit_Number_Type;
687       --  The unit from which the linker option comes
688    end record;
689
690    package Linker_Option_Lines is new Table.Table (
691      Table_Component_Type => Linker_Option_Entry,
692      Table_Index_Type     => Integer,
693      Table_Low_Bound      => 1,
694      Table_Initial        => Alloc.Linker_Option_Lines_Initial,
695      Table_Increment      => Alloc.Linker_Option_Lines_Increment,
696      Table_Name           => "Linker_Option_Lines");
697
698    --  The following table records the compilation switches used to compile
699    --  the main unit. The table includes only switches and excludes -quiet,
700    --  -dumpbase, and -o switches, since the latter are typically artifacts
701    --  of the gcc/gnat1 interface.
702
703    --  This table is set as part of the compiler argument scanning in
704    --  Back_End. It can also be reset in -gnatc mode from the data in an
705    --  existing ali file, and is read and written by the Tree_Read and
706    --  Tree_Write routines for ASIS.
707
708    package Compilation_Switches is new Table.Table (
709      Table_Component_Type => String_Ptr,
710      Table_Index_Type     => Nat,
711      Table_Low_Bound      => 1,
712      Table_Initial        => 30,
713      Table_Increment      => 100,
714      Table_Name           => "Compilation_Switches");
715
716    Load_Msg_Sloc : Source_Ptr;
717    --  Location for placing error messages (a token in the main source text)
718    --  This is set from Sloc (Enode) by Load only in the case where this Sloc
719    --  is in the main source file. This ensures that not found messages and
720    --  circular dependency messages reference the original with in this source.
721
722    type Unit_Ref_Table is array (Pos range <>) of Unit_Number_Type;
723    --  Type to hold list of indirect references to unit number table
724
725    --  The Load_Stack table contains a list of unit numbers (indexes into the
726    --  unit table) of units being loaded on a single dependency chain. The
727    --  First entry is the main unit. The second entry, if present is a unit
728    --  on which the first unit depends, etc. This stack is used to generate
729    --  error messages showing the dependency chain if a file is not found.
730    --  The Load function makes an entry in this table when it is called, and
731    --  removes the entry just before it returns.
732
733    package Load_Stack is new Table.Table (
734      Table_Component_Type => Unit_Number_Type,
735      Table_Index_Type     => Nat,
736      Table_Low_Bound      => 0,
737      Table_Initial        => Alloc.Load_Stack_Initial,
738      Table_Increment      => Alloc.Load_Stack_Increment,
739      Table_Name           => "Load_Stack");
740
741    procedure Sort (Tbl : in out Unit_Ref_Table);
742    --  This procedure sorts the given unit reference table in order of
743    --  ascending unit names, where the ordering relation is as described
744    --  by the comparison routines provided by package Uname.
745
746    --  The Version_Ref table records Body_Version and Version attribute
747    --  references. The entries are simply the strings for the external
748    --  names that correspond to the referenced values.
749
750    package Version_Ref is new Table.Table (
751      Table_Component_Type => String_Id,
752      Table_Index_Type     => Nat,
753      Table_Low_Bound      => 1,
754      Table_Initial        => 20,
755      Table_Increment      => 100,
756      Table_Name           => "Version_Ref");
757
758 end Lib;