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