| 1 |
------------------------------------------------------------------------------ |
| 2 |
-- -- |
| 3 |
-- GNAT COMPILER COMPONENTS -- |
| 4 |
-- -- |
| 5 |
-- L I B -- |
| 6 |
-- -- |
| 7 |
-- S p e c -- |
| 8 |
-- -- |
| 9 |
-- Copyright (C) 1992-2025, 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 3, 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 COPYING3. If not, go to -- |
| 19 |
-- http://www.gnu.org/licenses for a complete copy of the license. -- |
| 20 |
-- -- |
| 21 |
-- GNAT was originally developed by the GNAT team at New York University. -- |
| 22 |
-- Extensive contributions were provided by Ada Core Technologies Inc. -- |
| 23 |
-- -- |
| 24 |
------------------------------------------------------------------------------ |
| 25 |
|
| 26 |
-- This package contains routines for accessing and outputting the library |
| 27 |
-- information. It contains the routine to load subsidiary units. |
| 28 |
|
| 29 |
with Alloc; |
| 30 |
with Namet; use Namet; |
| 31 |
with Table; |
| 32 |
with Types; use Types; |
| 33 |
|
| 34 |
with GNAT.HTable; |
| 35 |
|
| 36 |
package Lib is |
| 37 |
|
| 38 |
type Unit_Ref_Table is array (Pos range <>) of Unit_Number_Type; |
| 39 |
-- Type to hold list of indirect references to unit number table |
| 40 |
|
| 41 |
type Compiler_State_Type is (Parsing, Analyzing); |
| 42 |
Compiler_State : Compiler_State_Type := Parsing; |
| 43 |
-- Indicates current state of compilation. This is used to implement the |
| 44 |
-- function In_Extended_Main_Source_Unit. |
| 45 |
|
| 46 |
Parsing_Main_Extended_Source : Boolean := False; |
| 47 |
-- Set True if we are currently parsing a file that is part of the main |
| 48 |
-- extended source (the main unit, its spec, or one of its subunits). This |
| 49 |
-- is used to implement In_Extended_Main_Source_Unit. |
| 50 |
|
| 51 |
Analysing_Subunit_Of_Main : Boolean := False; |
| 52 |
-- Set to True when analyzing a subunit of the main source. When True, if |
| 53 |
-- the subunit is preprocessed and -gnateG is specified, then the |
| 54 |
-- preprocessed file (.prep) is written. |
| 55 |
|
| 56 |
-------------------------------------------- |
| 57 |
-- General Approach to Library Management -- |
| 58 |
-------------------------------------------- |
| 59 |
|
| 60 |
-- As described in GNote #1, when a unit is compiled, all its subsidiary |
| 61 |
-- units are recompiled, including the following: |
| 62 |
|
| 63 |
-- (a) Corresponding spec for a body |
| 64 |
-- (b) Parent spec of a child library spec |
| 65 |
-- (c) With'ed specs |
| 66 |
-- (d) Parent body of a subunit |
| 67 |
-- (e) Subunits corresponding to any specified stubs |
| 68 |
-- (f) Bodies of inlined subprograms that are called |
| 69 |
-- (g) Bodies of generic subprograms or packages that are instantiated |
| 70 |
-- (h) Bodies of packages containing either of the above two items |
| 71 |
-- (i) Specs and bodies of runtime units |
| 72 |
-- (j) Parent specs for with'ed child library units |
| 73 |
|
| 74 |
-- If a unit is being compiled only for syntax checking, then no subsidiary |
| 75 |
-- units are loaded, the syntax check applies only to the main unit, |
| 76 |
-- i.e. the one contained in the source submitted to the library. |
| 77 |
|
| 78 |
-- If a unit is being compiled for syntax and semantic checking, then only |
| 79 |
-- cases (a)-(d) loads are performed, since the full semantic checking can |
| 80 |
-- be carried out without needing (e)-(i) loads. In this case no object |
| 81 |
-- file, or library information file, is generated, so the missing units |
| 82 |
-- do not affect the results. |
| 83 |
|
| 84 |
-- Specifications of library subprograms, subunits, and generic specs |
| 85 |
-- and bodies, can only be compiled in syntax/semantic checking mode, |
| 86 |
-- since no code is ever generated directly for these units. In the case |
| 87 |
-- of subunits, only the compilation of the ultimate parent unit generates |
| 88 |
-- actual code. If a subunit is submitted to the compiler in syntax/ |
| 89 |
-- semantic checking mode, the parent (or parents in the nested case) are |
| 90 |
-- semantically checked only up to the point of the corresponding stub. |
| 91 |
|
| 92 |
-- If code is being generated, then all the above units are required, |
| 93 |
-- although the need for bodies of inlined procedures can be suppressed |
| 94 |
-- by the use of a switch that sets the mode to ignore pragma Inline |
| 95 |
-- statements. |
| 96 |
|
| 97 |
-- The two main sections of the front end, Par and Sem, are recursive. |
| 98 |
-- Compilation proceeds unit by unit making recursive calls as necessary. |
| 99 |
-- The process is controlled from the GNAT main program, which makes calls |
| 100 |
-- to Par and Sem sequence for the main unit. |
| 101 |
|
| 102 |
-- Par parses the given unit, and then, after the parse is complete, uses |
| 103 |
-- the Par.Load subprogram to load all its subsidiary units in categories |
| 104 |
-- (a)-(d) above, installing pointers to the loaded units in the parse |
| 105 |
-- tree, as described in a later section of this spec. If any of these |
| 106 |
-- required units is missing, a fatal error is signalled, so that no |
| 107 |
-- attempt is made to run Sem in such cases, since it is assumed that |
| 108 |
-- too many cascaded errors would result, and the confusion would not |
| 109 |
-- be helpful. |
| 110 |
|
| 111 |
-- Following the call to Par on the main unit, the entire tree of required |
| 112 |
-- units is thus loaded, and Sem is called on the main unit. The parameter |
| 113 |
-- passed to Sem is the unit to be analyzed. The visibility table, which |
| 114 |
-- is a single global structure, starts out containing only the entries |
| 115 |
-- for the visible entities in Standard. Every call to Sem establishes a |
| 116 |
-- new scope stack table, pushing an entry for Standard on entry to provide |
| 117 |
-- the proper initial scope environment. |
| 118 |
|
| 119 |
-- Sem first proceeds to perform semantic analysis on the currently loaded |
| 120 |
-- units as follows: |
| 121 |
|
| 122 |
-- In the case of a body (case (a) above), Sem analyzes the corresponding |
| 123 |
-- spec, using a recursive call to Sem. As is always expected to be the |
| 124 |
-- case with calls to Sem, any entities installed in the visibility table |
| 125 |
-- are removed on exit from Sem, so that these entities have to be |
| 126 |
-- reinstalled on return to continue the analysis of the body which of |
| 127 |
-- course needs visibility of these entities. |
| 128 |
-- |
| 129 |
-- In the case of the parent of a child spec (case (b) above), a similar |
| 130 |
-- call is made to Sem to analyze the parent. Again, on return, the |
| 131 |
-- entities from the analyzed parent spec have to be installed in the |
| 132 |
-- visibility table of the caller (the child unit), which must have |
| 133 |
-- visibility to the entities in its parent spec. |
| 134 |
|
| 135 |
-- For with'ed specs (case (c) above), a recursive call to Sem is made |
| 136 |
-- to analyze each spec in turn. After all the spec's have been analyzed, |
| 137 |
-- but not till that point, the entities from all the with'ed units are |
| 138 |
-- reinstalled in the visibility table so that the caller can proceed |
| 139 |
-- with the analysis of the unit doing the with's with the necessary |
| 140 |
-- entities made either potentially use visible or visible by selection |
| 141 |
-- as needed. |
| 142 |
|
| 143 |
-- Case (d) arises when Sem is passed a subunit to analyze. This means |
| 144 |
-- that the main unit is a subunit, and the unit passed to Sem is either |
| 145 |
-- the main unit, or one of its ancestors that is still a subunit. Since |
| 146 |
-- analysis must start at the top of the tree, Sem essentially cancels |
| 147 |
-- the current call by immediately making a call to analyze the parent |
| 148 |
-- (when this call is finished it immediately returns, so logically this |
| 149 |
-- call is like a goto). The subunit will then be analyzed at the proper |
| 150 |
-- time as described for the stub case. Note that we also turn off the |
| 151 |
-- indication that code should be generated in this case, since the only |
| 152 |
-- time we generate code for subunits is when compiling the main parent. |
| 153 |
|
| 154 |
-- Case (e), subunits corresponding to stubs, are handled as the stubs |
| 155 |
-- are encountered. There are three sub-cases: |
| 156 |
|
| 157 |
-- If the subunit has already been loaded, then this means that the |
| 158 |
-- main unit was a subunit, and we are back on our way down to it |
| 159 |
-- after following the initial processing described for case (d). |
| 160 |
-- In this case we analyze this particular subunit, as described |
| 161 |
-- for the case where we are generating code, but when we get back |
| 162 |
-- we are all done, since the rest of the parent is irrelevant. To |
| 163 |
-- get out of the parent, we raise the exception Subunit_Found, which |
| 164 |
-- is handled at the outer level of Sem. |
| 165 |
|
| 166 |
-- The cases where the subunit has not already been loaded correspond |
| 167 |
-- to cases where the main unit was a parent. In this case the action |
| 168 |
-- depends on whether or not we are generating code. If we are not |
| 169 |
-- generating code, then this is the case where we can simply ignore |
| 170 |
-- the subunit, since in checking mode we don't even want to insist |
| 171 |
-- that the subunit exist, much less waste time checking it. |
| 172 |
|
| 173 |
-- If we are generating code, then we need to load and analyze |
| 174 |
-- all subunits. This is achieved with a call to Lib.Load to load |
| 175 |
-- and parse the unit, followed by processing that installs the |
| 176 |
-- context clause of the subunit, analyzes the subunit, and then |
| 177 |
-- removes the context clause (from the visibility chains of the |
| 178 |
-- parent). Note that we do *not* do a recursive call to Sem in |
| 179 |
-- this case, precisely because we need to do the analysis of the |
| 180 |
-- subunit with the current visibility table and scope stack. |
| 181 |
|
| 182 |
-- Case (f) applies only to subprograms for which a pragma Inline is |
| 183 |
-- given, providing that the compiler is operating in the mode where |
| 184 |
-- pragma Inline's are activated. When the expander encounters a call |
| 185 |
-- to such a subprogram, it loads the body of the subprogram if it has |
| 186 |
-- not already been loaded, and calls Sem to process it. |
| 187 |
|
| 188 |
-- Case (g) is similar to case (f), except that the body of a generic |
| 189 |
-- is unconditionally required, regardless of compiler mode settings. |
| 190 |
-- As in the subprogram case, when the expander encounters a generic |
| 191 |
-- instantiation, it loads the generic body of the subprogram if it |
| 192 |
-- has not already been loaded, and calls Sem to process it. |
| 193 |
|
| 194 |
-- Case (h) arises when a package contains either an inlined subprogram |
| 195 |
-- which is called, or a generic which is instantiated. In this case the |
| 196 |
-- body of the package must be loaded and analyzed with a call to Sem. |
| 197 |
|
| 198 |
-- Case (i) is handled by adding implicit with clauses to the context |
| 199 |
-- clauses of all units that potentially reference the relevant runtime |
| 200 |
-- entities. Note that since we have the full set of units available, |
| 201 |
-- the parser can always determine the set of runtime units that is |
| 202 |
-- needed. These with clauses do not have associated use clauses, so |
| 203 |
-- all references to the entities must be by selection. Once the with |
| 204 |
-- clauses have been added, subsequent processing is as for normal |
| 205 |
-- with clauses. |
| 206 |
|
| 207 |
-- Case (j) is also handled by adding appropriate implicit with clauses |
| 208 |
-- to any unit that withs a child unit. Again there is no use clause, |
| 209 |
-- and subsequent processing proceeds as for an explicit with clause. |
| 210 |
|
| 211 |
-- Sem thus completes the loading of all required units, except those |
| 212 |
-- required for inline subprogram bodies or inlined generics. If any |
| 213 |
-- of these load attempts fails, then the expander will not be called, |
| 214 |
-- even if code was to be generated. If the load attempts all succeed |
| 215 |
-- then the expander is called, though the attempt to generate code may |
| 216 |
-- still fail if an error occurs during a load attempt for an inlined |
| 217 |
-- body or a generic body. |
| 218 |
|
| 219 |
------------------------------------------- |
| 220 |
-- Special Handling of Subprogram Bodies -- |
| 221 |
------------------------------------------- |
| 222 |
|
| 223 |
-- A subprogram body (in an adb file) may stand for both a spec and a body. |
| 224 |
-- A simple model (and one that was adopted through version 2.07) is simply |
| 225 |
-- to assume that such an adb file acts as its own spec if no ads file is |
| 226 |
-- is present. |
| 227 |
|
| 228 |
-- However, this is not correct. RM 10.1.4(4) requires that such a body |
| 229 |
-- act as a spec unless a subprogram declaration of the same name is |
| 230 |
-- already present. The correct interpretation of this in GNAT library |
| 231 |
-- terms is to ignore an existing ads file of the same name unless this |
| 232 |
-- ads file contains a subprogram declaration with the same name. |
| 233 |
|
| 234 |
-- If there is an ads file with a unit other than a subprogram declaration |
| 235 |
-- with the same name, then a fatal message is output, noting that this |
| 236 |
-- irrelevant file must be deleted before the body can be compiled. See |
| 237 |
-- ACVC test CA1020D to see how this processing is required. |
| 238 |
|
| 239 |
----------------- |
| 240 |
-- Global Data -- |
| 241 |
----------------- |
| 242 |
|
| 243 |
Current_Sem_Unit : Unit_Number_Type := Main_Unit; |
| 244 |
-- Unit number of unit currently being analyzed/expanded. This is set when |
| 245 |
-- ever a new unit is entered, saving and restoring the old value, so that |
| 246 |
-- it always reflects the unit currently being analyzed. The initial value |
| 247 |
-- of Main_Unit ensures that a proper value is set initially, and in |
| 248 |
-- particular for analysis of configuration pragmas in gnat.adc. |
| 249 |
|
| 250 |
Main_Unit_Entity : Entity_Id; |
| 251 |
-- Entity of main unit, same as Cunit_Entity (Main_Unit) except where |
| 252 |
-- Main_Unit is a body with a separate spec, in which case it is the |
| 253 |
-- entity for the spec. |
| 254 |
|
| 255 |
----------------- |
| 256 |
-- Units Table -- |
| 257 |
----------------- |
| 258 |
|
| 259 |
-- The units table has an entry for each unit (source file) read in by the |
| 260 |
-- current compilation. The table is indexed by the unit number value. |
| 261 |
-- The first entry in the table, subscript Main_Unit, is for the main file. |
| 262 |
-- Each entry in this units table contains the following data. |
| 263 |
|
| 264 |
-- Cunit |
| 265 |
-- Pointer to the N_Compilation_Unit node. Initially set to Empty by |
| 266 |
-- Lib.Load, and then reset to the required node by the parser when |
| 267 |
-- the unit is parsed. |
| 268 |
|
| 269 |
-- Cunit_Entity |
| 270 |
-- Pointer to the entity node for the compilation unit. Initially set |
| 271 |
-- to Empty by Lib.Load, and then reset to the required entity by the |
| 272 |
-- parser when the unit is parsed. |
| 273 |
|
| 274 |
-- Dependency_Num |
| 275 |
-- This is the number of the unit within the generated dependency |
| 276 |
-- lines (D lines in the ALI file) which are sorted into alphabetical |
| 277 |
-- order. The number is ones origin, so a value of 2 refers to the |
| 278 |
-- second generated D line. The Dependency_Num values are set as the |
| 279 |
-- D lines are generated, and are used to generate proper unit |
| 280 |
-- references in the generated xref information and SCO output. |
| 281 |
|
| 282 |
-- Dynamic_Elab |
| 283 |
-- A flag indicating if this unit was compiled with dynamic elaboration |
| 284 |
-- checks specified (as the result of using the -gnatE compilation |
| 285 |
-- option or a pragma Elaboration_Checks (Dynamic)). |
| 286 |
|
| 287 |
-- Error_Location |
| 288 |
-- This is copied from the Sloc field of the Enode argument passed |
| 289 |
-- to Load_Unit. It refers to the enclosing construct which caused |
| 290 |
-- this unit to be loaded, e.g. most typically the with clause that |
| 291 |
-- referenced the unit, and is used for error handling in Par.Load. |
| 292 |
|
| 293 |
-- Expected_Unit |
| 294 |
-- This is the expected unit name for a file other than the main unit, |
| 295 |
-- since these are cases where we load the unit using Lib.Load and we |
| 296 |
-- know the unit that is expected. It must be the same as Unit_Name |
| 297 |
-- if it is set (see test in Par.Load). Expected_Unit is set to |
| 298 |
-- No_Name for the main unit. |
| 299 |
|
| 300 |
-- Fatal_Error |
| 301 |
-- A flag that is initialized to None and gets set to Error if a fatal |
| 302 |
-- error occurs during the processing of a unit. A fatal error is one |
| 303 |
-- defined as serious enough to stop the next phase of the compiler |
| 304 |
-- from running (i.e. fatal error during parsing stops semantics, |
| 305 |
-- fatal error during semantics stops code generation). Note that |
| 306 |
-- currently, errors of any kind cause Fatal_Error to be set, but |
| 307 |
-- eventually perhaps only errors labeled as fatal errors should be |
| 308 |
-- this severe if we decide to try Sem on sources with minor errors. |
| 309 |
-- There are three settings (see declaration of Fatal_Type). |
| 310 |
|
| 311 |
-- Generate_Code |
| 312 |
-- This flag is set True for all units in the current file for which |
| 313 |
-- code is to be generated. This includes the unit explicitly compiled, |
| 314 |
-- together with its specification, and any subunits. |
| 315 |
|
| 316 |
-- Has_RACW |
| 317 |
-- A Boolean flag, initially set to False when a unit entry is created, |
| 318 |
-- and set to True if the unit defines a remote access to class wide |
| 319 |
-- (RACW) object. This is used for controlling generation of the RA |
| 320 |
-- attribute in the ali file. |
| 321 |
|
| 322 |
-- Ident_String |
| 323 |
-- N_String_Literal node from a valid pragma Ident that applies to |
| 324 |
-- this unit. If no Ident pragma applies to the unit, then Empty. |
| 325 |
|
| 326 |
-- Is_Predefined_Renaming |
| 327 |
-- True if this unit is a predefined renaming, as in "Text_IO renames |
| 328 |
-- Ada.Text_IO"). |
| 329 |
|
| 330 |
-- Is_Internal_Unit |
| 331 |
-- Same as In_Predefined_Unit, except units in the GNAT hierarchy are |
| 332 |
-- included. |
| 333 |
|
| 334 |
-- Is_Predefined_Unit |
| 335 |
-- True if this unit is predefined (i.e. part of the Ada, System, or |
| 336 |
-- Interface hierarchies, or Is_Predefined_Renaming). Note that units |
| 337 |
-- in the GNAT hierarchy are not considered predefined. |
| 338 |
|
| 339 |
-- Loading |
| 340 |
-- A flag that is used to catch circular WITH dependencies. It is set |
| 341 |
-- True when an entry is initially created in the file table, and set |
| 342 |
-- False when the load is completed, or ends with an error. |
| 343 |
|
| 344 |
-- Main_Priority |
| 345 |
-- This field is used to indicate the priority of a possible main |
| 346 |
-- program, as set by a pragma Priority. A value of -1 indicates |
| 347 |
-- that the default priority is to be used (and is also used for |
| 348 |
-- entries that do not correspond to possible main programs). |
| 349 |
|
| 350 |
-- Main_CPU |
| 351 |
-- This field is used to indicate the affinity of a possible main |
| 352 |
-- program, as set by a pragma CPU. A value of -1 indicates |
| 353 |
-- that the default affinity is to be used (and is also used for |
| 354 |
-- entries that do not correspond to possible main programs). |
| 355 |
|
| 356 |
-- Munit_Index |
| 357 |
-- The index of the unit within the file for multiple unit per file |
| 358 |
-- mode. Set to zero in normal single unit per file mode. |
| 359 |
|
| 360 |
-- No_Elab_Code_All |
| 361 |
-- A flag set when a pragma or aspect No_Elaboration_Code_All applies |
| 362 |
-- to the unit. This is used to implement the transitive WITH rules |
| 363 |
-- (and for no other purpose). |
| 364 |
|
| 365 |
-- OA_Setting |
| 366 |
-- This is a character field containing L if Optimize_Alignment mode |
| 367 |
-- was set locally, and O/T/S for Off/Time/Space default if not. |
| 368 |
|
| 369 |
-- Primary_Stack_Count |
| 370 |
-- The number of primary stacks belonging to tasks defined within the |
| 371 |
-- unit that have no Storage_Size specified when the either restriction |
| 372 |
-- No_Implicit_Heap_Allocations or No_Implicit_Task_Allocations is |
| 373 |
-- active. Only used by the binder to generate stacks for these tasks |
| 374 |
-- at bind time. |
| 375 |
|
| 376 |
-- Sec_Stack_Count |
| 377 |
-- The number of secondary stacks belonging to tasks defined within the |
| 378 |
-- unit that have no Secondary_Stack_Size specified when the either |
| 379 |
-- the No_Implicit_Heap_Allocations or No_Implicit_Task_Allocations |
| 380 |
-- restrictions are active. Only used by the binder to generate stacks |
| 381 |
-- for these tasks at bind time. |
| 382 |
|
| 383 |
-- Serial_Number |
| 384 |
-- This field holds a serial number used by New_Internal_Name to |
| 385 |
-- generate unique temporary numbers on a unit by unit basis. The |
| 386 |
-- only access to this field is via the Increment_Serial_Number |
| 387 |
-- routine which increments the current value and returns it. This |
| 388 |
-- serial number is separate for each unit. |
| 389 |
|
| 390 |
-- Source_Index |
| 391 |
-- The index in the source file table of the corresponding source file. |
| 392 |
-- Set when the entry is created by a call to Lib.Load and then cannot |
| 393 |
-- be changed. |
| 394 |
|
| 395 |
-- Unit_File_Name |
| 396 |
-- The name of the source file containing the unit. Set when the entry |
| 397 |
-- is created by a call to Lib.Load, and then cannot be changed. |
| 398 |
|
| 399 |
-- Unit_Name |
| 400 |
-- The name of the unit. Initialized to No_Name by Lib.Load, and then |
| 401 |
-- set by the parser when the unit is parsed to the unit name actually |
| 402 |
-- found in the file (which should, in the absence of errors) be the |
| 403 |
-- same name as Expected_Unit. |
| 404 |
|
| 405 |
-- Version |
| 406 |
-- This field holds the version of the unit, which is computed as |
| 407 |
-- the exclusive or of the checksums of this unit, and all its |
| 408 |
-- semantically dependent units. Access to the version number field |
| 409 |
-- is not direct, but is done through the routines described below. |
| 410 |
-- When a unit table entry is created, this field is initialized to |
| 411 |
-- the checksum of the corresponding source file. Version_Update is |
| 412 |
-- then called to reflect the contributions of any unit on which this |
| 413 |
-- unit is semantically dependent. |
| 414 |
|
| 415 |
-- The units table is reset to empty at the start of the compilation of |
| 416 |
-- each main unit by Lib.Initialize. Entries are then added by calls to |
| 417 |
-- the Lib.Load procedure. The following subprograms are used to access |
| 418 |
-- and modify entries in the Units table. Individual entries are accessed |
| 419 |
-- using a unit number value which ranges from Main_Unit (the first entry, |
| 420 |
-- which is always for the current main unit) to Last_Unit. |
| 421 |
|
| 422 |
Default_Main_Priority : constant Int := -1; |
| 423 |
-- Value used in Main_Priority field to indicate default main priority |
| 424 |
|
| 425 |
Default_Main_CPU : constant Int := -1; |
| 426 |
-- Value used in Main_CPU field to indicate default main affinity |
| 427 |
|
| 428 |
-- The following defines settings for the Fatal_Error field |
| 429 |
|
| 430 |
type Fatal_Type is ( |
| 431 |
None, |
| 432 |
-- No error detected for this unit |
| 433 |
|
| 434 |
Error_Detected, |
| 435 |
-- Fatal error detected that prevents moving to the next phase. For |
| 436 |
-- example, a fatal error during parsing inhibits semantic analysis. |
| 437 |
|
| 438 |
Error_Ignored); |
| 439 |
-- A fatal error was detected, but we are in Try_Semantics mode (as set |
| 440 |
-- by -gnatq or -gnatQ). This does not stop the compiler from proceding, |
| 441 |
-- but tools can use this status (e.g. ASIS looking at the generated |
| 442 |
-- tree) to know that a fatal error was detected. |
| 443 |
|
| 444 |
function Cunit (U : Unit_Number_Type) return Node_Id; |
| 445 |
function Cunit_Entity (U : Unit_Number_Type) return Entity_Id; |
| 446 |
function Dependency_Num (U : Unit_Number_Type) return Nat; |
| 447 |
function Dynamic_Elab (U : Unit_Number_Type) return Boolean; |
| 448 |
function Error_Location (U : Unit_Number_Type) return Source_Ptr; |
| 449 |
function Expected_Unit (U : Unit_Number_Type) return Unit_Name_Type; |
| 450 |
function Fatal_Error (U : Unit_Number_Type) return Fatal_Type; |
| 451 |
function Generate_Code (U : Unit_Number_Type) return Boolean; |
| 452 |
function Ident_String (U : Unit_Number_Type) return Node_Id; |
| 453 |
function Has_RACW (U : Unit_Number_Type) return Boolean; |
| 454 |
function Is_Predefined_Renaming |
| 455 |
(U : Unit_Number_Type) return Boolean; |
| 456 |
function Is_Internal_Unit (U : Unit_Number_Type) return Boolean; |
| 457 |
function Is_Predefined_Unit |
| 458 |
(U : Unit_Number_Type) return Boolean; |
| 459 |
function Loading (U : Unit_Number_Type) return Boolean; |
| 460 |
function Main_CPU (U : Unit_Number_Type) return Int; |
| 461 |
function Main_Priority (U : Unit_Number_Type) return Int; |
| 462 |
function Munit_Index (U : Unit_Number_Type) return Nat; |
| 463 |
function No_Elab_Code_All (U : Unit_Number_Type) return Boolean; |
| 464 |
function OA_Setting (U : Unit_Number_Type) return Character; |
| 465 |
function Primary_Stack_Count |
| 466 |
(U : Unit_Number_Type) return Nat; |
| 467 |
function Sec_Stack_Count (U : Unit_Number_Type) return Nat; |
| 468 |
function Source_Index (U : Unit_Number_Type) return Source_File_Index; |
| 469 |
function Unit_File_Name (U : Unit_Number_Type) return File_Name_Type; |
| 470 |
function Unit_Name (U : Unit_Number_Type) return Unit_Name_Type; |
| 471 |
-- Get value of named field from given units table entry |
| 472 |
|
| 473 |
-- WARNING: There is a matching C declaration of a few subprograms in fe.h |
| 474 |
|
| 475 |
procedure Set_Cunit (U : Unit_Number_Type; N : Node_Id); |
| 476 |
procedure Set_Cunit_Entity (U : Unit_Number_Type; E : Entity_Id); |
| 477 |
procedure Set_Dynamic_Elab (U : Unit_Number_Type; B : Boolean := True); |
| 478 |
procedure Set_Error_Location (U : Unit_Number_Type; W : Source_Ptr); |
| 479 |
procedure Set_Fatal_Error (U : Unit_Number_Type; V : Fatal_Type); |
| 480 |
procedure Set_Generate_Code (U : Unit_Number_Type; B : Boolean := True); |
| 481 |
procedure Set_Has_RACW (U : Unit_Number_Type; B : Boolean := True); |
| 482 |
procedure Set_Ident_String (U : Unit_Number_Type; N : Node_Id); |
| 483 |
procedure Set_Loading (U : Unit_Number_Type; B : Boolean := True); |
| 484 |
procedure Set_Main_CPU (U : Unit_Number_Type; P : Int); |
| 485 |
procedure Set_No_Elab_Code_All (U : Unit_Number_Type; B : Boolean := True); |
| 486 |
procedure Set_Main_Priority (U : Unit_Number_Type; P : Int); |
| 487 |
procedure Set_OA_Setting (U : Unit_Number_Type; C : Character); |
| 488 |
procedure Set_Unit_Name (U : Unit_Number_Type; N : Unit_Name_Type); |
| 489 |
-- Set value of named field for given units table entry. Note that we |
| 490 |
-- do not have an entry for each possible field, since some of the fields |
| 491 |
-- can only be set by specialized interfaces (defined below). |
| 492 |
|
| 493 |
function Compilation_Switches_Last return Nat; |
| 494 |
-- Return the count of stored compilation switches |
| 495 |
|
| 496 |
procedure Disable_Switch_Storing; |
| 497 |
-- Disable registration of switches by Store_Compilation_Switch. Used to |
| 498 |
-- avoid registering switches added automatically by the gcc driver at the |
| 499 |
-- end of the command line. |
| 500 |
|
| 501 |
function Earlier_In_Extended_Unit |
| 502 |
(S1 : Source_Ptr; |
| 503 |
S2 : Source_Ptr) return Boolean; |
| 504 |
-- Given two Sloc values for which In_Same_Extended_Unit is true, determine |
| 505 |
-- if S1 appears before S2. Returns True if S1 appears before S2, and False |
| 506 |
-- otherwise. The result is undefined if S1 and S2 are not in the same |
| 507 |
-- extended unit. Note: this routine will not give reliable results if |
| 508 |
-- called after Sprint has been called with -gnatD set. |
| 509 |
|
| 510 |
function Earlier_In_Extended_Unit |
| 511 |
(N1 : Node_Or_Entity_Id; |
| 512 |
N2 : Node_Or_Entity_Id) return Boolean; |
| 513 |
-- Same as above, but the inputs denote nodes or entities |
| 514 |
|
| 515 |
procedure Enable_Switch_Storing; |
| 516 |
-- Enable registration of switches by Store_Compilation_Switch. Used to |
| 517 |
-- avoid registering switches added automatically by the gcc driver at the |
| 518 |
-- beginning of the command line. |
| 519 |
|
| 520 |
function Entity_Is_In_Main_Unit (E : Entity_Id) return Boolean; |
| 521 |
-- Returns True if the entity E is declared in the main unit, or, in |
| 522 |
-- its corresponding spec, or one of its subunits. Entities declared |
| 523 |
-- within generic instantiations return True if the instantiation is |
| 524 |
-- itself "in the main unit" by this definition. Otherwise False. |
| 525 |
|
| 526 |
function Exact_Source_Name (Loc : Source_Ptr) return String; |
| 527 |
-- Return name of entity at location Loc exactly as written in the source. |
| 528 |
-- This includes copying the wide character encodings exactly as they were |
| 529 |
-- used in the source, so the caller must be aware of the possibility of |
| 530 |
-- such encodings. |
| 531 |
|
| 532 |
function Get_Compilation_Switch (N : Pos) return String_Ptr; |
| 533 |
-- Return the Nth stored compilation switch, or null if less than N |
| 534 |
-- switches have been stored. Used by back ends written in Ada. |
| 535 |
|
| 536 |
function Generic_May_Lack_ALI (Unum : Unit_Number_Type) return Boolean; |
| 537 |
-- Generic units must be separately compiled. Since we always use |
| 538 |
-- macro substitution for generics, the resulting object file is a dummy |
| 539 |
-- one with no code, but the ALI file has the normal form, and we need |
| 540 |
-- this ALI file so that the binder can work out a correct order of |
| 541 |
-- elaboration. |
| 542 |
-- |
| 543 |
-- However, ancient versions of GNAT used to not generate code or ALI |
| 544 |
-- files for generic units, and this would yield complex order of |
| 545 |
-- elaboration issues. These were fixed in GNAT 3.10. The support for not |
| 546 |
-- compiling language-defined library generics was retained nonetheless |
| 547 |
-- to facilitate bootstrap. Specifically, it is convenient to have |
| 548 |
-- the same list of files to be compiled for all stages. So, if the |
| 549 |
-- bootstrap compiler does not generate code for a given file, then |
| 550 |
-- the stage1 compiler (and binder) also must deal with the case of |
| 551 |
-- that file not being compiled. The predicate Generic_May_Lack_ALI is |
| 552 |
-- True for those generic units for which missing ALI files are allowed. |
| 553 |
|
| 554 |
function Get_Cunit_Unit_Number (N : Node_Id) return Unit_Number_Type; |
| 555 |
-- Return unit number of the unit whose N_Compilation_Unit node is the |
| 556 |
-- one passed as an argument. This must always succeed since the node |
| 557 |
-- could not have been built without making a unit table entry. |
| 558 |
|
| 559 |
function Get_Cunit_Entity_Unit_Number |
| 560 |
(E : Entity_Id) return Unit_Number_Type; |
| 561 |
-- Return unit number of the unit whose compilation unit spec entity is |
| 562 |
-- the one passed as an argument. This must always succeed since the |
| 563 |
-- entity could not have been built without making a unit table entry. |
| 564 |
|
| 565 |
function Get_Source_Unit (N : Node_Or_Entity_Id) return Unit_Number_Type; |
| 566 |
pragma Inline (Get_Source_Unit); |
| 567 |
function Get_Source_Unit (S : Source_Ptr) return Unit_Number_Type; |
| 568 |
-- Return unit number of file identified by given source pointer value. |
| 569 |
-- This call must always succeed, since any valid source pointer value |
| 570 |
-- belongs to some previously loaded module. If the given source pointer |
| 571 |
-- value is within an instantiation, this function returns the unit number |
| 572 |
-- of the template, i.e. the unit containing the source code corresponding |
| 573 |
-- to the given Source_Ptr value. The version taking a Node_Id argument, N, |
| 574 |
-- simply applies the function to Sloc (N). |
| 575 |
|
| 576 |
function Get_Code_Unit (N : Node_Or_Entity_Id) return Unit_Number_Type; |
| 577 |
pragma Inline (Get_Code_Unit); |
| 578 |
function Get_Code_Unit (S : Source_Ptr) return Unit_Number_Type; |
| 579 |
-- This is like Get_Source_Unit, except that in the instantiation case, |
| 580 |
-- it uses the location of the top level instantiation, rather than the |
| 581 |
-- template, so it returns the unit number containing the code that |
| 582 |
-- corresponds to the node N, or the source location S. |
| 583 |
|
| 584 |
function Get_Top_Level_Code_Unit |
| 585 |
(N : Node_Or_Entity_Id) return Unit_Number_Type; |
| 586 |
pragma Inline (Get_Code_Unit); |
| 587 |
function Get_Top_Level_Code_Unit (S : Source_Ptr) return Unit_Number_Type; |
| 588 |
-- This is like Get_Code_Unit, except that in the case of subunits, it |
| 589 |
-- returns the top-level unit to which the subunit belongs instead of |
| 590 |
-- the subunit. |
| 591 |
-- |
| 592 |
-- Note: for nodes and slocs in declarations of library-level instances of |
| 593 |
-- generics these routines wrongly return the unit number corresponding to |
| 594 |
-- the body of the instance. In effect, locations of SPARK references in |
| 595 |
-- ALI files are bogus. However, fixing this is not worth the effort, since |
| 596 |
-- these references are only used for debugging. |
| 597 |
|
| 598 |
function In_Extended_Main_Code_Unit |
| 599 |
(N : Node_Or_Entity_Id) return Boolean; |
| 600 |
-- Return True if the node is in the generated code of the extended main |
| 601 |
-- unit, defined as the main unit, its specification (if any), and all |
| 602 |
-- its subunits (considered recursively). Units for which this enquiry |
| 603 |
-- returns True are those for which code will be generated. Nodes from |
| 604 |
-- instantiations are included in the extended main unit for this call. |
| 605 |
-- If the main unit is itself a subunit, then the extended main code unit |
| 606 |
-- includes its parent unit, and the parent unit spec if it is separate. |
| 607 |
-- |
| 608 |
-- This routine (and the following three routines) all return False if |
| 609 |
-- Sloc (N) is No_Location or Standard_Location. In an earlier version, |
| 610 |
-- they returned True for Standard_Location, but this was odd, and some |
| 611 |
-- archeology indicated that this was done for the sole benefit of the |
| 612 |
-- call in Restrict.Check_Restriction_No_Dependence, so we have moved |
| 613 |
-- the special case check to that routine. This avoids some difficulties |
| 614 |
-- with some other calls that malfunctioned with the odd return of True. |
| 615 |
|
| 616 |
-- WARNING: There is a matching C declaration of this subprogram in fe.h |
| 617 |
|
| 618 |
function In_Extended_Main_Code_Unit (Loc : Source_Ptr) return Boolean; |
| 619 |
-- Same as above, but for Source_Ptr |
| 620 |
|
| 621 |
function In_Extended_Main_Source_Unit |
| 622 |
(N : Node_Or_Entity_Id) return Boolean; |
| 623 |
-- Return True if the node is in the source text of the extended main |
| 624 |
-- unit, defined as the main unit, its specification (if any), and all |
| 625 |
-- its subunits (considered recursively). Units for which this enquiry |
| 626 |
-- returns True are those for which code will be generated. This differs |
| 627 |
-- from In_Extended_Main_Code_Unit only in that instantiations are not |
| 628 |
-- included for the purposes of this call. If the main unit is itself |
| 629 |
-- a subunit, then the extended main source unit includes its parent unit, |
| 630 |
-- and the parent unit spec if it is separate. |
| 631 |
|
| 632 |
function In_Extended_Main_Source_Unit (Loc : Source_Ptr) return Boolean; |
| 633 |
-- Same as above, but for Source_Ptr |
| 634 |
|
| 635 |
function ipu (N : Node_Or_Entity_Id) return Boolean; |
| 636 |
-- Same as In_Predefined_Unit, but renamed so it can assist debugging. |
| 637 |
-- Otherwise, there is a disambiguous name conflict in the two versions of |
| 638 |
-- In_Predefined_Unit which makes it inconvient to set as a breakpoint |
| 639 |
-- condition. |
| 640 |
|
| 641 |
function In_Predefined_Unit (N : Node_Or_Entity_Id) return Boolean; |
| 642 |
-- Returns True if the given node or entity appears within the source text |
| 643 |
-- of a predefined unit (i.e. within Ada, Interfaces, System or within one |
| 644 |
-- of the descendant packages of one of these three packages). |
| 645 |
|
| 646 |
function In_Predefined_Unit (S : Source_Ptr) return Boolean; |
| 647 |
pragma Inline (In_Predefined_Unit); |
| 648 |
-- Same as above, but for Source_Ptr |
| 649 |
|
| 650 |
function In_Internal_Unit (N : Node_Or_Entity_Id) return Boolean; |
| 651 |
function In_Internal_Unit (S : Source_Ptr) return Boolean; |
| 652 |
pragma Inline (In_Internal_Unit); |
| 653 |
-- Same as In_Predefined_Unit, except units in the GNAT hierarchy are |
| 654 |
-- included. |
| 655 |
|
| 656 |
function In_Predefined_Renaming (N : Node_Or_Entity_Id) return Boolean; |
| 657 |
function In_Predefined_Renaming (S : Source_Ptr) return Boolean; |
| 658 |
pragma Inline (In_Predefined_Renaming); |
| 659 |
-- Returns True if N or S is in a predefined renaming unit |
| 660 |
|
| 661 |
function In_Same_Code_Unit (N1, N2 : Node_Or_Entity_Id) return Boolean; |
| 662 |
pragma Inline (In_Same_Code_Unit); |
| 663 |
-- Determines if the two nodes or entities N1 and N2 are in the same |
| 664 |
-- code unit, the criterion being that Get_Code_Unit yields the same |
| 665 |
-- value for each argument. |
| 666 |
|
| 667 |
function In_Same_Extended_Unit (N1, N2 : Node_Or_Entity_Id) return Boolean; |
| 668 |
pragma Inline (In_Same_Extended_Unit); |
| 669 |
-- Determines if two nodes or entities N1 and N2 are in the same |
| 670 |
-- extended unit, where an extended unit is defined as a unit and all |
| 671 |
-- its subunits (considered recursively, i.e. subunits of subunits are |
| 672 |
-- included). Returns true if S1 and S2 are in the same extended unit |
| 673 |
-- and False otherwise. |
| 674 |
|
| 675 |
function In_Same_Extended_Unit (S1, S2 : Source_Ptr) return Boolean; |
| 676 |
pragma Inline (In_Same_Extended_Unit); |
| 677 |
-- Determines if the two source locations S1 and S2 are in the same |
| 678 |
-- extended unit, where an extended unit is defined as a unit and all |
| 679 |
-- its subunits (considered recursively, i.e. subunits of subunits are |
| 680 |
-- included). Returns true if S1 and S2 are in the same extended unit |
| 681 |
-- and False otherwise. |
| 682 |
|
| 683 |
function In_Same_Source_Unit (N1, N2 : Node_Or_Entity_Id) return Boolean; |
| 684 |
pragma Inline (In_Same_Source_Unit); |
| 685 |
-- Determines if the two nodes or entities N1 and N2 are in the same |
| 686 |
-- source unit, the criterion being that Get_Source_Unit yields the |
| 687 |
-- same value for each argument. |
| 688 |
|
| 689 |
procedure Increment_Primary_Stack_Count (Increment : Nat); |
| 690 |
-- Increment the Primary_Stack_Count field for the current unit by |
| 691 |
-- Increment. |
| 692 |
|
| 693 |
procedure Increment_Sec_Stack_Count (Increment : Nat); |
| 694 |
-- Increment the Sec_Stack_Count field for the current unit by Increment |
| 695 |
|
| 696 |
function Increment_Serial_Number return Nat; |
| 697 |
-- Increment Serial_Number field for current unit, and return the |
| 698 |
-- incremented value. |
| 699 |
|
| 700 |
procedure Initialize; |
| 701 |
-- Initialize internal tables |
| 702 |
|
| 703 |
function Is_Loaded (Uname : Unit_Name_Type) return Boolean; |
| 704 |
-- Determines if unit with given name is already loaded, i.e. there is |
| 705 |
-- already an entry in the file table with this unit name for which the |
| 706 |
-- corresponding file was found and parsed. Note that the Fatal_Error value |
| 707 |
-- of this entry must be checked before proceeding with further processing. |
| 708 |
|
| 709 |
function Last_Unit return Unit_Number_Type; |
| 710 |
-- Unit number of last allocated unit |
| 711 |
|
| 712 |
procedure List (File_Names_Only : Boolean := False); |
| 713 |
-- Lists units in active library (i.e. generates output consisting of a |
| 714 |
-- sorted listing of the units represented in File table, except for the |
| 715 |
-- main unit). If File_Names_Only is set to True, then the list includes |
| 716 |
-- only file names, and no other information. Otherwise the unit name and |
| 717 |
-- time stamp are also output. File_Names_Only also restricts the list to |
| 718 |
-- exclude any predefined files. |
| 719 |
|
| 720 |
procedure Lock; |
| 721 |
-- Lock internal tables before calling back end |
| 722 |
|
| 723 |
function Num_Units return Nat; |
| 724 |
-- Number of units currently in unit table |
| 725 |
|
| 726 |
procedure Remove_Unit (U : Unit_Number_Type); |
| 727 |
-- Remove unit U from unit table. Currently this is effective only if U is |
| 728 |
-- the last unit currently stored in the unit table. |
| 729 |
|
| 730 |
procedure Replace_Linker_Option_String |
| 731 |
(S : String_Id; |
| 732 |
Match_String : String); |
| 733 |
-- Replace an existing Linker_Option if the prefix Match_String matches, |
| 734 |
-- otherwise call Store_Linker_Option_String. |
| 735 |
|
| 736 |
procedure Store_Compilation_Switch (Switch : String); |
| 737 |
-- Called to register a compilation switch, either front-end or back-end, |
| 738 |
-- which may influence the generated output file(s). Switch is the text of |
| 739 |
-- the switch to store (except that -fRTS gets changed back to --RTS). |
| 740 |
|
| 741 |
procedure Store_Linker_Option_String (S : String_Id); |
| 742 |
-- This procedure is called to register the string from a pragma |
| 743 |
-- Linker_Option. The argument is the Id of the string to register. |
| 744 |
|
| 745 |
procedure Store_Note (N : Node_Id); |
| 746 |
-- This procedure is called to register a pragma N for which a notes |
| 747 |
-- entry is required. |
| 748 |
|
| 749 |
procedure Synchronize_Serial_Number (SN : Nat); |
| 750 |
-- This function increments the Serial_Number field for the current unit |
| 751 |
-- up to SN if it is initially lower and does nothing otherwise. This is |
| 752 |
-- used in situations where one path of control increments serial numbers |
| 753 |
-- and the other path does not and it is important to keep serial numbers |
| 754 |
-- synchronized in the two cases (e.g. when the references in a package |
| 755 |
-- and a client must be kept consistent). |
| 756 |
|
| 757 |
procedure Unlock; |
| 758 |
-- Unlock internal tables, in cases where the back end needs to modify them |
| 759 |
|
| 760 |
function Version_Get (U : Unit_Number_Type) return Word_Hex_String; |
| 761 |
-- Returns the version as a string with 8 hex digits (upper case letters) |
| 762 |
|
| 763 |
procedure Version_Referenced (S : String_Id); |
| 764 |
-- This routine is called from Exp_Attr to register the use of a Version |
| 765 |
-- or Body_Version attribute. The argument is the external name used to |
| 766 |
-- access the version string. |
| 767 |
|
| 768 |
procedure Write_Unit_Info |
| 769 |
(Unit_Num : Unit_Number_Type; |
| 770 |
Item : Node_Id; |
| 771 |
Prefix : String := ""; |
| 772 |
Withs : Boolean := False); |
| 773 |
-- Print out debugging information about the unit. Prefix precedes the rest |
| 774 |
-- of the printout. If Withs is True, we print out units with'ed by this |
| 775 |
-- unit (not counting limited withs). |
| 776 |
|
| 777 |
--------------------------------------------------------------- |
| 778 |
-- Special Handling for Restriction_Set (No_Dependence) Case -- |
| 779 |
--------------------------------------------------------------- |
| 780 |
|
| 781 |
-- If we have a Restriction_Set attribute for No_Dependence => unit, |
| 782 |
-- and the unit is not given in a No_Dependence restriction that we |
| 783 |
-- can see, the attribute will return False. |
| 784 |
|
| 785 |
-- We have to ensure in this case that the binder will reject any attempt |
| 786 |
-- to set a No_Dependence restriction in some other unit in the partition. |
| 787 |
|
| 788 |
-- If the unit is in the semantic closure, then of course it is properly |
| 789 |
-- WITH'ed by someone, and the binder will do this job automatically as |
| 790 |
-- part of its normal processing. |
| 791 |
|
| 792 |
-- But if the unit is not in the semantic closure, we must make sure the |
| 793 |
-- binder knows about it. The use of the Restriction_Set attribute giving |
| 794 |
-- a result of False does not mean of itself that we have to include the |
| 795 |
-- unit in the partition. So what we do is to generate a with (W) line in |
| 796 |
-- the ali file (with no file name information), but no corresponding D |
| 797 |
-- (dependency) line. This is recognized by the binder as meaning "Don't |
| 798 |
-- let anyone specify No_Dependence for this unit, but you don't have to |
| 799 |
-- include it if there is no real W line for the unit". |
| 800 |
|
| 801 |
-- The following table keeps track of relevant units. It is used in the |
| 802 |
-- Lib.Writ circuit for outputting With lines to output the special with |
| 803 |
-- line with RA if the unit is not in the semantic closure. |
| 804 |
|
| 805 |
package Restriction_Set_Dependences is new Table.Table ( |
| 806 |
Table_Component_Type => Unit_Name_Type, |
| 807 |
Table_Index_Type => Int, |
| 808 |
Table_Low_Bound => 0, |
| 809 |
Table_Initial => 10, |
| 810 |
Table_Increment => 100, |
| 811 |
Table_Name => "Restriction_Attribute_Dependences"); |
| 812 |
|
| 813 |
private |
| 814 |
pragma Inline (Cunit); |
| 815 |
pragma Inline (Cunit_Entity); |
| 816 |
pragma Inline (Dependency_Num); |
| 817 |
pragma Inline (Fatal_Error); |
| 818 |
pragma Inline (Generate_Code); |
| 819 |
pragma Inline (Has_RACW); |
| 820 |
pragma Inline (Increment_Primary_Stack_Count); |
| 821 |
pragma Inline (Increment_Sec_Stack_Count); |
| 822 |
pragma Inline (Increment_Serial_Number); |
| 823 |
pragma Inline (Is_Internal_Unit); |
| 824 |
pragma Inline (Is_Loaded); |
| 825 |
pragma Inline (Is_Predefined_Renaming); |
| 826 |
pragma Inline (Is_Predefined_Unit); |
| 827 |
pragma Inline (Loading); |
| 828 |
pragma Inline (Main_CPU); |
| 829 |
pragma Inline (Main_Priority); |
| 830 |
pragma Inline (Munit_Index); |
| 831 |
pragma Inline (No_Elab_Code_All); |
| 832 |
pragma Inline (OA_Setting); |
| 833 |
pragma Inline (Primary_Stack_Count); |
| 834 |
pragma Inline (Set_Cunit); |
| 835 |
pragma Inline (Set_Cunit_Entity); |
| 836 |
pragma Inline (Set_Fatal_Error); |
| 837 |
pragma Inline (Set_Generate_Code); |
| 838 |
pragma Inline (Set_Has_RACW); |
| 839 |
pragma Inline (Sec_Stack_Count); |
| 840 |
pragma Inline (Set_Loading); |
| 841 |
pragma Inline (Set_Main_CPU); |
| 842 |
pragma Inline (Set_Main_Priority); |
| 843 |
pragma Inline (Set_No_Elab_Code_All); |
| 844 |
pragma Inline (Set_OA_Setting); |
| 845 |
pragma Inline (Set_Unit_Name); |
| 846 |
pragma Inline (Source_Index); |
| 847 |
pragma Inline (Unit_File_Name); |
| 848 |
pragma Inline (Unit_Name); |
| 849 |
|
| 850 |
-- The Units Table |
| 851 |
|
| 852 |
type Unit_Record is record |
| 853 |
Unit_File_Name : File_Name_Type; |
| 854 |
Unit_Name : Unit_Name_Type; |
| 855 |
Munit_Index : Nat; |
| 856 |
Expected_Unit : Unit_Name_Type; |
| 857 |
Source_Index : Source_File_Index; |
| 858 |
Cunit : Node_Id; |
| 859 |
Cunit_Entity : Entity_Id; |
| 860 |
Dependency_Num : Int; |
| 861 |
Ident_String : Node_Id; |
| 862 |
Main_Priority : Int; |
| 863 |
Main_CPU : Int; |
| 864 |
Primary_Stack_Count : Nat; |
| 865 |
Sec_Stack_Count : Nat; |
| 866 |
Serial_Number : Nat; |
| 867 |
Version : Word; |
| 868 |
Error_Location : Source_Ptr; |
| 869 |
Fatal_Error : Fatal_Type; |
| 870 |
Generate_Code : Boolean; |
| 871 |
Has_RACW : Boolean; |
| 872 |
Dynamic_Elab : Boolean; |
| 873 |
No_Elab_Code_All : Boolean; |
| 874 |
Filler : Boolean; |
| 875 |
Loading : Boolean; |
| 876 |
OA_Setting : Character; |
| 877 |
|
| 878 |
Is_Predefined_Renaming : Boolean; |
| 879 |
Is_Internal_Unit : Boolean; |
| 880 |
Is_Predefined_Unit : Boolean; |
| 881 |
Filler2 : Boolean; |
| 882 |
end record; |
| 883 |
|
| 884 |
-- The following representation clause ensures that the above record |
| 885 |
-- has no holes. We do this so that when instances of this record are |
| 886 |
-- written by Tree_Gen, we do not write uninitialized values to the file. |
| 887 |
|
| 888 |
for Unit_Record use record |
| 889 |
Unit_File_Name at 0 range 0 .. 31; |
| 890 |
Unit_Name at 4 range 0 .. 31; |
| 891 |
Munit_Index at 8 range 0 .. 31; |
| 892 |
Expected_Unit at 12 range 0 .. 31; |
| 893 |
Source_Index at 16 range 0 .. 31; |
| 894 |
Cunit at 20 range 0 .. 31; |
| 895 |
Cunit_Entity at 24 range 0 .. 31; |
| 896 |
Dependency_Num at 28 range 0 .. 31; |
| 897 |
Ident_String at 32 range 0 .. 31; |
| 898 |
Main_Priority at 36 range 0 .. 31; |
| 899 |
Main_CPU at 40 range 0 .. 31; |
| 900 |
Primary_Stack_Count at 44 range 0 .. 31; |
| 901 |
Sec_Stack_Count at 48 range 0 .. 31; |
| 902 |
Serial_Number at 52 range 0 .. 31; |
| 903 |
Version at 56 range 0 .. 31; |
| 904 |
Error_Location at 60 range 0 .. 31; |
| 905 |
Fatal_Error at 64 range 0 .. 7; |
| 906 |
Generate_Code at 65 range 0 .. 7; |
| 907 |
Has_RACW at 66 range 0 .. 7; |
| 908 |
Dynamic_Elab at 67 range 0 .. 7; |
| 909 |
No_Elab_Code_All at 68 range 0 .. 7; |
| 910 |
Filler at 69 range 0 .. 7; |
| 911 |
OA_Setting at 70 range 0 .. 7; |
| 912 |
Loading at 71 range 0 .. 7; |
| 913 |
|
| 914 |
Is_Predefined_Renaming at 72 range 0 .. 7; |
| 915 |
Is_Internal_Unit at 73 range 0 .. 7; |
| 916 |
Is_Predefined_Unit at 74 range 0 .. 7; |
| 917 |
Filler2 at 75 range 0 .. 7; |
| 918 |
end record; |
| 919 |
|
| 920 |
for Unit_Record'Size use 76 * 8; |
| 921 |
-- This ensures that we did not leave out any fields |
| 922 |
|
| 923 |
package Units is new Table.Table ( |
| 924 |
Table_Component_Type => Unit_Record, |
| 925 |
Table_Index_Type => Unit_Number_Type, |
| 926 |
Table_Low_Bound => Main_Unit, |
| 927 |
Table_Initial => Alloc.Units_Initial, |
| 928 |
Table_Increment => Alloc.Units_Increment, |
| 929 |
Table_Name => "Units"); |
| 930 |
|
| 931 |
-- The following table records a mapping between a name and the entry in |
| 932 |
-- the units table whose Unit_Name is this name. It is used to speed up |
| 933 |
-- the Is_Loaded function, whose original implementation (linear search) |
| 934 |
-- could account for 2% of the time spent in the front end. When the unit |
| 935 |
-- is an instance of a generic, the unit might get duplicated in the unit |
| 936 |
-- table - see Make_Instance_Unit for more information. Note that, in |
| 937 |
-- the case of source files containing multiple units, the units table may |
| 938 |
-- temporarily contain two entries with the same Unit_Name during parsing, |
| 939 |
-- which means that the mapping must be to the first entry in the table. |
| 940 |
|
| 941 |
Unit_Name_Table_Size : constant := 257; |
| 942 |
-- Number of headers in hash table |
| 943 |
|
| 944 |
subtype Unit_Name_Header_Num is Integer range 0 .. Unit_Name_Table_Size - 1; |
| 945 |
-- Range of headers in hash table |
| 946 |
|
| 947 |
function Unit_Name_Hash (Id : Unit_Name_Type) return Unit_Name_Header_Num; |
| 948 |
-- Simple hash function for Unit_Name_Types |
| 949 |
|
| 950 |
package Unit_Names is new GNAT.Htable.Simple_HTable |
| 951 |
(Header_Num => Unit_Name_Header_Num, |
| 952 |
Element => Unit_Number_Type, |
| 953 |
No_Element => No_Unit, |
| 954 |
Key => Unit_Name_Type, |
| 955 |
Hash => Unit_Name_Hash, |
| 956 |
Equal => "="); |
| 957 |
|
| 958 |
procedure Init_Unit_Name (U : Unit_Number_Type; N : Unit_Name_Type); |
| 959 |
pragma Inline (Init_Unit_Name); |
| 960 |
-- Both set the Unit_Name for the given units table entry and register a |
| 961 |
-- mapping between this name and the entry. |
| 962 |
|
| 963 |
-- The following table stores strings from pragma Linker_Option lines |
| 964 |
|
| 965 |
type Linker_Option_Entry is record |
| 966 |
Option : String_Id; |
| 967 |
-- The string for the linker option line |
| 968 |
|
| 969 |
Unit : Unit_Number_Type; |
| 970 |
-- The unit from which the linker option comes |
| 971 |
end record; |
| 972 |
|
| 973 |
package Linker_Option_Lines is new Table.Table ( |
| 974 |
Table_Component_Type => Linker_Option_Entry, |
| 975 |
Table_Index_Type => Integer, |
| 976 |
Table_Low_Bound => 1, |
| 977 |
Table_Initial => Alloc.Linker_Option_Lines_Initial, |
| 978 |
Table_Increment => Alloc.Linker_Option_Lines_Increment, |
| 979 |
Table_Name => "Linker_Option_Lines"); |
| 980 |
|
| 981 |
-- The following table stores references to pragmas that generate Notes |
| 982 |
|
| 983 |
package Notes is new Table.Table ( |
| 984 |
Table_Component_Type => Node_Id, |
| 985 |
Table_Index_Type => Integer, |
| 986 |
Table_Low_Bound => 1, |
| 987 |
Table_Initial => Alloc.Notes_Initial, |
| 988 |
Table_Increment => Alloc.Notes_Increment, |
| 989 |
Table_Name => "Notes"); |
| 990 |
|
| 991 |
-- The following table records the compilation switches used to compile |
| 992 |
-- the main unit. The table includes only switches. It excludes -o |
| 993 |
-- switches as well as artifacts of the gcc/gnat1 interface such as |
| 994 |
-- -quiet, or -dumpbase. |
| 995 |
|
| 996 |
-- This table is set as part of the compiler argument scanning in |
| 997 |
-- Back_End. It can also be reset in -gnatc mode from the data in an |
| 998 |
-- existing ali file. |
| 999 |
|
| 1000 |
package Compilation_Switches is new Table.Table ( |
| 1001 |
Table_Component_Type => String_Ptr, |
| 1002 |
Table_Index_Type => Nat, |
| 1003 |
Table_Low_Bound => 1, |
| 1004 |
Table_Initial => 30, |
| 1005 |
Table_Increment => 100, |
| 1006 |
Table_Name => "Compilation_Switches"); |
| 1007 |
|
| 1008 |
Load_Msg_Sloc : Source_Ptr; |
| 1009 |
-- Location for placing error messages (a token in the main source text) |
| 1010 |
-- This is set from Sloc (Enode) by Load only in the case where this Sloc |
| 1011 |
-- is in the main source file. This ensures that not found messages and |
| 1012 |
-- circular dependency messages reference the original with in this source. |
| 1013 |
|
| 1014 |
type Load_Stack_Entry is record |
| 1015 |
Unit_Number : Unit_Number_Type; |
| 1016 |
With_Node : Node_Id; |
| 1017 |
end record; |
| 1018 |
|
| 1019 |
-- The Load_Stack table contains a list of unit numbers (indexes into the |
| 1020 |
-- unit table) of units being loaded on a single dependency chain, and a |
| 1021 |
-- flag to indicate whether this unit is loaded through a limited_with |
| 1022 |
-- clause. The First entry is the main unit. The second entry, if present |
| 1023 |
-- is a unit on which the first unit depends, etc. This stack is used to |
| 1024 |
-- generate error messages showing the dependency chain if a file is not |
| 1025 |
-- found, or whether a true circular dependency exists. The Load_Unit |
| 1026 |
-- function makes an entry in this table when it is called, and removes |
| 1027 |
-- the entry just before it returns. |
| 1028 |
|
| 1029 |
package Load_Stack is new Table.Table ( |
| 1030 |
Table_Component_Type => Load_Stack_Entry, |
| 1031 |
Table_Index_Type => Int, |
| 1032 |
Table_Low_Bound => 0, |
| 1033 |
Table_Initial => Alloc.Load_Stack_Initial, |
| 1034 |
Table_Increment => Alloc.Load_Stack_Increment, |
| 1035 |
Table_Name => "Load_Stack"); |
| 1036 |
|
| 1037 |
procedure Sort (Tbl : in out Unit_Ref_Table); |
| 1038 |
-- This procedure sorts the given unit reference table in order of |
| 1039 |
-- ascending unit names, where the ordering relation is as described |
| 1040 |
-- by the comparison routines provided by package Uname. |
| 1041 |
|
| 1042 |
-- The Version_Ref table records Body_Version and Version attribute |
| 1043 |
-- references. The entries are simply the strings for the external |
| 1044 |
-- names that correspond to the referenced values. |
| 1045 |
|
| 1046 |
package Version_Ref is new Table.Table ( |
| 1047 |
Table_Component_Type => String_Id, |
| 1048 |
Table_Index_Type => Nat, |
| 1049 |
Table_Low_Bound => 1, |
| 1050 |
Table_Initial => 20, |
| 1051 |
Table_Increment => 100, |
| 1052 |
Table_Name => "Version_Ref"); |
| 1053 |
|
| 1054 |
end Lib; |