1------------------------------------------------------------------------------ 2-- -- 3-- GPR PROJECT MANAGER -- 4-- -- 5-- Copyright (C) 1992-2015, Free Software Foundation, Inc. -- 6-- -- 7-- This library is free software; you can redistribute it and/or modify it -- 8-- under terms of the GNU General Public License as published by the Free -- 9-- Software Foundation; either version 3, or (at your option) any later -- 10-- version. This library is distributed in the hope that it will be useful, -- 11-- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- -- 12-- TABILITY or FITNESS FOR A PARTICULAR PURPOSE. -- 13-- -- 14-- As a special exception under Section 7 of GPL version 3, you are granted -- 15-- additional permissions described in the GCC Runtime Library Exception, -- 16-- version 3.1, as published by the Free Software Foundation. -- 17-- -- 18-- You should have received a copy of the GNU General Public License and -- 19-- a copy of the GCC Runtime Library Exception along with this program; -- 20-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -- 21-- <http://www.gnu.org/licenses/>. -- 22-- -- 23------------------------------------------------------------------------------ 24 25-- This package defines the internal data structures used for representation 26-- of Ada Library Information (ALI) acquired from the ALI files generated by 27-- the front end. 28 29with System.Rident; 30 31with GNAT.Table; 32 33with GPR.Osint; use GPR.Osint; 34 35package GPR.ALI is 36 37 package Rident is new System.Rident; 38 use Rident; 39 40 -------------- 41 -- Id Types -- 42 -------------- 43 44 -- The various entries are stored in tables with distinct subscript ranges. 45 -- The following type definitions show the ranges used for the subscripts 46 -- (Id values) for the various tables. 47 48 type ALI_Id is range 0 .. 99_999_999; 49 -- Id values used for ALIs table entries 50 51 type Unit_Id is range 0 .. 99_999_999; 52 -- Id values used for Unit table entries 53 54 type With_Id is range 0 .. 99_999_999; 55 -- Id values used for Withs table entries 56 57 type Arg_Id is range 0 .. 99_999_999; 58 -- Id values used for argument table entries 59 60 type Sdep_Id is range 0 .. 99_999_999; 61 -- Id values used for Sdep table entries 62 63 type Source_Id is range 0 .. 99_999_999; 64 -- Id values used for Source table entries 65 66 type Interrupt_State_Id is range 0 .. 99_999_999; 67 -- Id values used for Interrupt_State table entries 68 69 type Priority_Specific_Dispatching_Id is range 0 .. 99_999_999; 70 -- Id values used for Priority_Specific_Dispatching table entries 71 72 -------------------- 73 -- ALI File Table -- 74 -------------------- 75 76 -- Each ALI file read generates an entry in the ALIs table 77 78 No_ALI_Id : constant ALI_Id := ALI_Id'First; 79 -- Special value indicating no ALI entry 80 81 First_ALI_Entry : constant ALI_Id := No_ALI_Id + 1; 82 -- Id of first actual entry in table 83 84 type Main_Program_Type is (None, Proc, Func); 85 -- Indicator of whether unit can be used as main program 86 87 type ALIs_Record is record 88 89 Afile : File_Name_Type; 90 -- Name of ALI file 91 92 Ofile_Full_Name : File_Name_Type; 93 -- Full name of object file corresponding to the ALI file 94 95 Sfile : File_Name_Type; 96 -- Name of source file that generates this ALI file (which is equal 97 -- to the name of the source file in the first unit table entry for 98 -- this ALI file, since the body if present is always first). 99 100 SAL_Interface : Boolean; 101 -- Set True when this is an interface to a standalone library 102 103 First_Unit : Unit_Id; 104 -- Id of first Unit table entry for this file 105 106 Last_Unit : Unit_Id; 107 -- Id of last Unit table entry for this file 108 109 First_Sdep : Sdep_Id; 110 -- Id of first Sdep table entry for this file 111 112 Last_Sdep : Sdep_Id; 113 -- Id of last Sdep table entry for this file 114 115 Main_Program : Main_Program_Type; 116 -- Indicator of whether first unit can be used as main program. Not set 117 -- if 'M' appears in Ignore_Lines. 118 119 Main_Priority : Int; 120 -- Indicates priority value if Main_Program field indicates that this 121 -- can be a main program. A value of -1 (No_Main_Priority) indicates 122 -- that no parameter was found, or no M line was present. Not set if 123 -- 'M' appears in Ignore_Lines. 124 125 Main_CPU : Int; 126 -- Indicates processor if Main_Program field indicates that this can 127 -- be a main program. A value of -1 (No_Main_CPU) indicates that no C 128 -- parameter was found, or no M line was present. Not set if 'M' appears 129 -- in Ignore_Lines. 130 131 Time_Slice_Value : Int; 132 -- Indicates value of time slice parameter from T=xxx on main program 133 -- line. A value of -1 indicates that no T=xxx parameter was found, or 134 -- no M line was present. Not set if 'M' appears in Ignore_Lines. 135 136 WC_Encoding : Character; 137 -- Wide character encoding if main procedure. Otherwise not relevant. 138 -- Not set if 'M' appears in Ignore_Lines. 139 140 Locking_Policy : Character; 141 -- Indicates locking policy for units in this file. Space means tasking 142 -- was not used, or that no Locking_Policy pragma was present or that 143 -- this is a language defined unit. Otherwise set to first character 144 -- (upper case) of policy name. Not set if 'P' appears in Ignore_Lines. 145 146 Partition_Elaboration_Policy : Character; 147 -- Indicates partition elaboration policy for units in this file. Space 148 -- means that no Partition_Elaboration_Policy pragma was present or that 149 -- this is a language defined unit. Otherwise set to first character 150 -- (upper case) of policy name. Not set if 'P' appears in Ignore_Lines. 151 152 Queuing_Policy : Character; 153 -- Indicates queuing policy for units in this file. Space means tasking 154 -- was not used, or that no Queuing_Policy pragma was present or that 155 -- this is a language defined unit. Otherwise set to first character 156 -- (upper case) of policy name. Not set if 'P' appears in Ignore_Lines. 157 158 Task_Dispatching_Policy : Character; 159 -- Indicates task dispatching policy for units in this file. Space means 160 -- tasking was not used, or that no Task_Dispatching_Policy pragma was 161 -- present or that this is a language defined unit. Otherwise set to 162 -- first character (upper case) of policy name. Not set if 'P' appears 163 -- in Ignore_Lines. 164 165 Compile_Errors : Boolean; 166 -- Set to True if compile errors for unit. Note that No_Object will 167 -- always be set as well in this case. Not set if 'P' appears in 168 -- Ignore_Lines. 169 170 GNATprove_Mode : Boolean; 171 -- Set to True if ALI and object file produced in GNATprove_Mode as 172 -- signalled by GP appearing on the P line. Not set if 'P' appears in 173 -- Ignore_Lines. 174 175 No_Object : Boolean; 176 -- Set to True if no object file generated. Not set if 'P' appears in 177 -- Ignore_Lines. 178 179 Normalize_Scalars : Boolean; 180 -- Set to True if file was compiled with Normalize_Scalars. Not set if 181 -- 'P' appears in Ignore_Lines. 182 183 SSO_Default : Character; 184 -- Set to 'H' or 'L' if file was compiled with a configuration pragma 185 -- file containing Default_Scalar_Storage_Order (High/Low_Order_First). 186 -- Set to ' ' if neither pragma was present. Not set if 'P' appears in 187 -- Ignore_Lines. 188 189 Unit_Exception_Table : Boolean; 190 -- Set to True if unit exception table pointer generated. Not set if 'P' 191 -- appears in Ignore_Lines. 192 193 Zero_Cost_Exceptions : Boolean; 194 -- Set to True if file was compiled with zero cost exceptions. Not set 195 -- if 'P' appears in Ignore_Lines. 196 197 Restrictions : Restrictions_Info; 198 -- Restrictions information reconstructed from R lines 199 200 end record; 201 202 No_Main_Priority : constant Int := -1; 203 -- Code for no main priority set 204 205 No_Main_CPU : constant Int := -1; 206 -- Code for no main cpu set 207 208 package ALIs is new GNAT.Table ( 209 Table_Component_Type => ALIs_Record, 210 Table_Index_Type => ALI_Id, 211 Table_Low_Bound => First_ALI_Entry, 212 Table_Initial => 500, 213 Table_Increment => 200); 214 215 ---------------- 216 -- Unit Table -- 217 ---------------- 218 219 -- Each unit within an ALI file generates an entry in the unit table 220 221 No_Unit_Id : constant Unit_Id := Unit_Id'First; 222 -- Special value indicating no unit table entry 223 224 First_Unit_Entry : constant Unit_Id := No_Unit_Id + 1; 225 -- Id of first actual entry in table 226 227 type Unit_Type is (Is_Spec, Is_Body, Is_Spec_Only, Is_Body_Only); 228 -- Indicates type of entry, if both body and spec appear in the ALI file, 229 -- then the first unit is marked Is_Body, and the second is marked Is_Spec. 230 -- If only a spec appears, then it is marked as Is_Spec_Only, and if only 231 -- a body appears, then it is marked Is_Body_Only). 232 233 subtype Version_String is String (1 .. 8); 234 -- Version string, taken from unit record 235 236 type Unit_Record is record 237 238 My_ALI : ALI_Id; 239 -- Corresponding ALI entry 240 241 Uname : Unit_Name_Type; 242 -- Name of Unit 243 244 Sfile : File_Name_Type; 245 -- Name of source file 246 247 Preelab : Boolean; 248 -- Indicates presence of PR parameter for a preelaborated package 249 250 No_Elab : Boolean; 251 -- Indicates presence of NE parameter for a unit that has does not 252 -- have an elaboration routine (since it has no elaboration code). 253 254 Pure : Boolean; 255 -- Indicates presence of PU parameter for a package having pragma Pure 256 257 Dynamic_Elab : Boolean; 258 -- Set to True if the unit was compiled with dynamic elaboration checks 259 -- (i.e. either -gnatE or pragma Elaboration_Checks (RM) was used to 260 -- compile the unit). 261 262 Elaborate_Body : Boolean; 263 -- Indicates presence of EB parameter for a package which has a pragma 264 -- Elaborate_Body, and also for generic package instantiations. 265 266 Set_Elab_Entity : Boolean; 267 -- Indicates presence of EE parameter for a unit which has an 268 -- elaboration entity which must be set true as part of the 269 -- elaboration of the unit. 270 271 Has_RACW : Boolean; 272 -- Indicates presence of RA parameter for a package that declares at 273 -- least one Remote Access to Class_Wide (RACW) object. 274 275 Remote_Types : Boolean; 276 -- Indicates presence of RT parameter for a package which has a 277 -- pragma Remote_Types. 278 279 Serious_Errors : Boolean; 280 -- Indicates presence of SE parameter indicating that compilation of 281 -- the unit encountered as serious error. 282 283 Shared_Passive : Boolean; 284 -- Indicates presence of SP parameter for a package which has a pragma 285 -- Shared_Passive. 286 287 RCI : Boolean; 288 -- Indicates presence of RC parameter for a package which has a pragma 289 -- Remote_Call_Interface. 290 291 Predefined : Boolean; 292 -- Indicates if unit is language predefined (or a child of such a unit) 293 294 Internal : Boolean; 295 -- Indicates if unit is an internal unit (or a child of such a unit) 296 297 First_With : With_Id; 298 -- Id of first withs table entry for this file 299 300 Last_With : With_Id; 301 -- Id of last withs table entry for this file 302 303 First_Arg : Arg_Id; 304 -- Id of first args table entry for this file 305 306 Last_Arg : Arg_Id; 307 -- Id of last args table entry for this file 308 309 Utype : Unit_Type; 310 -- Type of entry 311 312 Is_Generic : Boolean; 313 -- True for generic unit (i.e. a generic declaration, or a generic 314 -- body). False for a non-generic unit. 315 316 Unit_Kind : Character; 317 -- Indicates the nature of the unit. 'p' for Packages and 's' for 318 -- subprograms. 319 320 Version : Version_String; 321 -- Version of unit 322 323 Icasing : Casing_Type; 324 -- Indicates casing of identifiers in source file for this unit. This 325 -- is used for informational output, and also for constructing the main 326 -- unit if it is being built in Ada. 327 328 Kcasing : Casing_Type; 329 -- Indicates casing of keywords in source file for this unit. This is 330 -- used for informational output, and also for constructing the main 331 -- unit if it is being built in Ada. 332 333 Elab_Position : aliased Natural; 334 -- Initialized to zero. Set non-zero when a unit is chosen and 335 -- placed in the elaboration order. The value represents the 336 -- ordinal position in the elaboration order. 337 338 Init_Scalars : Boolean; 339 -- Set True if IS qualifier appears in ALI file, indicating that 340 -- an Initialize_Scalars pragma applies to the unit. 341 342 SAL_Interface : Boolean; 343 -- Set True when this is an interface to a standalone library 344 345 Directly_Scanned : Boolean; 346 -- True iff it is a unit from an ALI file specified to gnatbind 347 348 Body_Needed_For_SAL : Boolean; 349 -- Indicates that the source for the body of the unit (subprogram, 350 -- package, or generic unit) must be included in a standalone library. 351 352 Elaborate_Body_Desirable : Boolean; 353 -- Indicates that the front end elaboration circuitry decided that it 354 -- would be a good idea if this package had Elaborate_Body. The binder 355 -- will attempt, but does not promise, to place the elaboration call 356 -- for the body right after the call for the spec, or at least as close 357 -- together as possible. 358 359 Optimize_Alignment : Character; 360 -- Optimize_Alignment setting. Set to L/S/T/O for OL/OS/OT/OO present 361 362 Has_Finalizer : Boolean; 363 -- Indicates whether a package body or a spec has a library-level 364 -- finalization routine. 365 end record; 366 367 package Units is new GNAT.Table ( 368 Table_Component_Type => Unit_Record, 369 Table_Index_Type => Unit_Id, 370 Table_Low_Bound => First_Unit_Entry, 371 Table_Initial => 100, 372 Table_Increment => 200); 373 374 Stack_Check_Switch_Set : Boolean := False; 375 -- Set to True if at least one ALI file contains '-fstack-check' in its 376 -- argument list. 377 378 ----------------- 379 -- Withs Table -- 380 ----------------- 381 382 -- Each With line (W line) in an ALI file generates a Withs table entry 383 384 -- Note: there will be no entries in this table if 'W' lines are ignored 385 386 No_With_Id : constant With_Id := With_Id'First; 387 -- Special value indicating no withs table entry 388 389 First_With_Entry : constant With_Id := No_With_Id + 1; 390 -- Id of first actual entry in table 391 392 type With_Record is record 393 394 Uname : Unit_Name_Type; 395 -- Name of Unit 396 397 Sfile : File_Name_Type; 398 -- Name of source file, set to No_File in generic case 399 400 Afile : File_Name_Type; 401 -- Name of ALI file, set to No_File in generic case 402 403 Elaborate : Boolean; 404 -- Indicates presence of E parameter 405 406 Elaborate_All : Boolean; 407 -- Indicates presence of EA parameter 408 409 Elab_All_Desirable : Boolean; 410 -- Indicates presence of AD parameter 411 412 Elab_Desirable : Boolean; 413 -- Indicates presence of ED parameter 414 415 SAL_Interface : Boolean := False; 416 -- True if the Unit is an Interface of a Stand-Alone Library 417 418 Limited_With : Boolean := False; 419 -- True if unit is named in a limited_with_clause 420 421 Implicit_With_From_Instantiation : Boolean := False; 422 -- True if this is an implicit with from a generic instantiation 423 end record; 424 425 package Withs is new GNAT.Table ( 426 Table_Component_Type => With_Record, 427 Table_Index_Type => With_Id, 428 Table_Low_Bound => First_With_Entry, 429 Table_Initial => 5000, 430 Table_Increment => 200); 431 432 --------------------- 433 -- Arguments Table -- 434 --------------------- 435 436 -- Each Arg line (A line) in an ALI file generates an Args table entry 437 438 -- Note: there will be no entries in this table if 'A' lines are ignored 439 440 No_Arg_Id : constant Arg_Id := Arg_Id'First; 441 -- Special value indicating no args table entry 442 443 First_Arg_Entry : constant Arg_Id := No_Arg_Id + 1; 444 -- Id of first actual entry in table 445 446 package Args is new GNAT.Table ( 447 Table_Component_Type => String_Access, 448 Table_Index_Type => Arg_Id, 449 Table_Low_Bound => First_Arg_Entry, 450 Table_Initial => 1000, 451 Table_Increment => 100); 452 453 ------------------------------------ 454 -- Sdep (Source Dependency) Table -- 455 ------------------------------------ 456 457 -- Each source dependency (D line) in an ALI file generates an entry in the 458 -- Sdep table. 459 460 -- Note: there will be no entries in this table if 'D' lines are ignored 461 462 No_Sdep_Id : constant Sdep_Id := Sdep_Id'First; 463 -- Special value indicating no Sdep table entry 464 465 First_Sdep_Entry : Sdep_Id := No_Sdep_Id + 1; 466 -- Id of first Sdep entry for current ali file. This is initialized to the 467 -- first Sdep entry in the table, and then incremented appropriately as 468 -- successive ALI files are scanned. 469 470 type Sdep_Record is record 471 472 Sfile : File_Name_Type; 473 -- Name of source file 474 475 Stamp : Time_Stamp_Type; 476 -- Time stamp value. Note that this will be all zero characters for the 477 -- dummy entries for missing or non-dependent files. 478 479 Checksum : Word; 480 -- Checksum value. Note that this will be all zero characters for the 481 -- dummy entries for missing or non-dependent files 482 483 Dummy_Entry : Boolean; 484 -- Set True for dummy entries that correspond to missing files or files 485 -- where no dependency relationship exists. 486 487 Subunit_Name : Name_Id; 488 -- Name_Id for subunit name if present, else No_Name 489 490 Unit_Name : Name_Id; 491 -- Name_Id for the unit name if not a subunit (No_Name for a subunit) 492 Rfile : File_Name_Type; 493 -- Reference file name. Same as Sfile unless a Source_Reference pragma 494 -- was used, in which case it reflects the name used in the pragma. 495 496 Start_Line : Nat; 497 -- Starting line number in file. Always 1, unless a Source_Reference 498 -- pragma was used, in which case it reflects the line number value 499 -- given in the pragma. 500 501 end record; 502 503 package Sdep is new GNAT.Table ( 504 Table_Component_Type => Sdep_Record, 505 Table_Index_Type => Sdep_Id, 506 Table_Low_Bound => First_Sdep_Entry, 507 Table_Initial => 5000, 508 Table_Increment => 200); 509 510 ---------------------------- 511 -- Use of Name Table Info -- 512 ---------------------------- 513 514 -- All unit names and file names are entered into the Names table. The Info 515 -- fields of these entries are used as follows: 516 517 -- Unit name Info field has Unit_Id of unit table entry 518 -- ALI file name Info field has ALI_Id of ALI table entry 519 -- Source file name Info field has Source_Id of source table entry 520 521 -------------------------------------- 522 -- Subprograms for Reading ALI File -- 523 -------------------------------------- 524 525 procedure Initialize_ALI; 526 -- Initialize the ALI tables. Also resets all switch values to defaults 527 528 function Scan_ALI 529 (F : File_Name_Type; 530 T : Text_Buffer_Ptr; 531 Ignore_ED : Boolean; 532 Err : Boolean; 533 Read_Lines : String; 534 Object_Path : File_Name_Type := No_File) return ALI_Id; 535 -- Given the text, T, of an ALI file, F, scan and store the information 536 -- from the file, and return the Id of the resulting entry in the ALI 537 -- table. Switch settings may be modified as described above in the 538 -- switch description settings. 539 -- 540 -- Ignore_ED is normally False. If set to True, it indicates that 541 -- all AD/ED (elaboration desirable) indications in the ALI file are 542 -- to be ignored. This parameter is obsolete now that the -f switch 543 -- is removed from gnatbind, and should be removed ??? 544 -- 545 -- Err determines the action taken on an incorrectly formatted file. 546 -- If Err is False, then an error message is output, and the program 547 -- is terminated. If Err is True, then no error message is output, 548 -- and No_ALI_Id is returned. 549 -- 550 -- Ignore_Lines requests that Scan_ALI ignore any lines that start 551 -- with any given key character. The default value of X causes all 552 -- Xref lines to be ignored. The corresponding data in the ALI 553 -- tables will not be filled in this case. It is not possible 554 -- to ignore U (unit) lines, they are always read. 555 -- 556 -- Read_Lines requests that Scan_ALI process only lines that start 557 -- with one of the given characters. The corresponding data in the 558 -- ALI file for any characters not given in the list will not be 559 -- set. The default value of the null string indicates that all 560 -- lines should be read (unless Ignore_Lines is specified). U 561 -- (unit) lines are always read regardless of the value of this 562 -- parameter. 563 -- 564 -- Note: either Ignore_Lines or Read_Lines should be non-null, but not 565 -- both. If both are provided then only the Read_Lines value is used, 566 -- and the Ignore_Lines parameter is ignored. 567 -- 568 -- Read_XREF is set True to read and acquire the cross-reference 569 -- information. If Read_XREF is set to True, then the effect is to ignore 570 -- all lines other than U, W, D and X lines and the Ignore_Lines and 571 -- Read_Lines parameters are ignored (i.e. the use of True for Read_XREF 572 -- is equivalent to specifying an argument of "UWDX" for Read_Lines. 573 -- 574 -- Ignore_Errors is normally False. If it is set True, then Scan_ALI 575 -- will do its best to scan through a file and extract all information 576 -- it can, even if there are errors. In this case Err is only set if 577 -- Scan_ALI was completely unable to process the file (e.g. it did not 578 -- look like an ALI file at all). Ignore_Errors is intended to improve 579 -- the downward compatibility of new compilers with old tools. 580 -- 581 -- Directly_Scanned is normally False. If it is set to True, then the 582 -- units (spec and/or body) corresponding to the ALI file are marked as 583 -- such. It is used to decide for what units gnatbind should generate 584 -- the symbols corresponding to 'Version or 'Body_Version in 585 -- Stand-Alone Libraries. 586 587end GPR.ALI; 588