1------------------------------------------------------------------------------ 2-- -- 3-- GPR PROJECT MANAGER -- 4-- -- 5-- Copyright (C) 2001-2016, 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-- The following package declares the data types for GNAT project. 26-- These data types may be used by GNAT Project-aware tools. 27 28-- Children of this package implement various services on these data types 29 30with GNAT.Dynamic_HTables; use GNAT.Dynamic_HTables; 31with GNAT.Dynamic_Tables; 32 33pragma Warnings (Off); 34with System.OS_Lib; use System.OS_Lib; 35 36with System.Storage_Elements; 37 38package GPR is 39 40 EOF : constant Character := ASCII.SUB; 41 -- The character SUB (16#1A#) is used in DOS and other systems derived 42 -- from DOS (XP, NT etc) to signal the end of a text file. Internally all 43 -- source files are ended by an EOF character, even on Unix systems. An EOF 44 -- character acts as the end of file only as the last character of a source 45 -- buffer, in any other position, it is treated as a blank if it appears 46 -- between tokens, and as an illegal character otherwise. This makes 47 -- life easier dealing with files that originated from DOS, including 48 -- concatenated files with interspersed EOF characters. 49 50 ----------- 51 -- Types -- 52 ----------- 53 54 ------------------------------- 55 -- General Use Integer Types -- 56 ------------------------------- 57 58 type Int is range -2 ** 31 .. +2 ** 31 - 1; 59 -- Signed 32-bit integer 60 61 subtype Nat is Int range 0 .. Int'Last; 62 -- Non-negative Int values 63 64 subtype Pos is Int range 1 .. Int'Last; 65 -- Positive Int values 66 67 type Word is mod 2 ** 32; 68 -- Unsigned 32-bit integer 69 70 subtype Upper_Half_Character is 71 Character range Character'Val (16#80#) .. Character'Val (16#FF#); 72 -- 8-bit Characters with the upper bit set 73 74 type Source_Ptr is new Int; 75 -- Type used to represent a source location, which is a subscript of a 76 -- character in the source buffer. As noted above, different source buffers 77 -- have different ranges, so it is possible to tell from a Source_Ptr value 78 -- which source it refers to. Note that negative numbers are allowed to 79 -- accommodate the following special values. 80 81 No_Location : constant Source_Ptr := -1; 82 -- Value used to indicate no source position set in a node. A test for a 83 -- Source_Ptr value being > No_Location is the approved way to test for a 84 -- standard value that does not include No_Location or any of the following 85 -- special definitions. One important use of No_Location is to label 86 -- generated nodes that we don't want the debugger to see in normal mode 87 -- (very often we conditionalize so that we set No_Location in normal mode 88 -- and the corresponding source line in -gnatD mode). 89 90 First_Source_Ptr : constant Source_Ptr := 0; 91 -- Starting source pointer index value for first source program 92 93 type Source_File_Index is new Int range -1 .. Int'Last; 94 -- Type used to index the source file table (see package GPR.Sinput) 95 96 No_Source_File : constant Source_File_Index := 0; 97 -- Value used to indicate no source file present 98 99 ----------- 100 -- Nodes -- 101 ----------- 102 type Node_Id is range 0 .. 99_999_999; 103 -- Type used to identify nodes in the tree 104 105 Empty_Node : constant Node_Id := 0; 106 -- Used to indicate null node. A node is actually allocated with this Id 107 -- value, so that Nkind (Empty) = N_Empty. Note that Node_Low_Bound is 108 -- zero, so Empty = No_List = zero. 109 110 Error_Node : constant Node_Id := 1; 111 -- Used to indicate an error in the source program. A node is actually 112 -- allocated with this Id value, so that Nkind (Error) = N_Error. 113 114 First_Node_Id : constant Node_Id := 0; 115 -- Subscript of first allocated node. Note that Empty and Error are both 116 -- allocated nodes, whose Nkind fields can be accessed without error. 117 118 Unrecoverable_Error : exception; 119 120 ------------------- 121 -- Project nodes -- 122 ------------------- 123 124 Project_Nodes_Initial : constant := 1_000; 125 Project_Nodes_Increment : constant := 100; 126 -- Allocation parameters for initializing and extending number 127 -- of nodes in table Tree_Private_Part.Project_Nodes 128 129 Project_Node_Low_Bound : constant := 0; 130 Project_Node_High_Bound : constant := 099_999_999; 131 -- Range of values for project node id's (in practice infinite) 132 133 type Project_Node_Id is range 134 Project_Node_Low_Bound .. Project_Node_High_Bound; 135 -- The index of table Tree_Private_Part.Project_Nodes 136 137 Empty_Project_Node : constant Project_Node_Id := Project_Node_Low_Bound; 138 -- Designates no node in table Project_Nodes 139 140 First_Project_Node_Id : constant Project_Node_Id := 141 Project_Node_Low_Bound + 1; 142 143 type Response_File_Format is 144 (None, 145 GNU, 146 Object_List, 147 Option_List, 148 GCC, 149 GCC_GNU, 150 GCC_Object_List, 151 GCC_Option_List); 152 -- The format of the different response files 153 154 ------------ 155 -- Stamps -- 156 ------------ 157 158 package Stamps is 159 160 ----------------------------------- 161 -- Representation of Time Stamps -- 162 ----------------------------------- 163 164 -- All compiled units are marked with a time stamp which is derived from 165 -- the source file (we assume that the host system has the concept of a 166 -- file time stamp which is modified when a file is modified). These 167 -- time stamps are used to ensure consistency of the set of units that 168 -- constitutes a library. Time stamps are 14-character strings with 169 -- with the following format: 170 171 -- YYYYMMDDHHMMSS 172 173 -- YYYY year 174 -- MM month (2 digits 01-12) 175 -- DD day (2 digits 01-31) 176 -- HH hour (2 digits 00-23) 177 -- MM minutes (2 digits 00-59) 178 -- SS seconds (2 digits 00-59) 179 180 -- In the case of Unix systems (and other systems which keep the time in 181 -- GMT), the time stamp is the GMT time of the file, not the local time. 182 -- This solves problems in using libraries across networks with clients 183 -- spread across multiple time-zones. 184 185 Time_Stamp_Length : constant := 14; 186 -- Length of time stamp value 187 188 subtype Time_Stamp_Index is Natural range 1 .. Time_Stamp_Length; 189 type Time_Stamp_Type is new String (Time_Stamp_Index); 190 -- Type used to represent time stamp 191 192 Empty_Time_Stamp : constant Time_Stamp_Type := (others => ' '); 193 -- Value representing an empty or missing time stamp. Looks less than 194 -- any real time stamp if two time stamps are compared. Note that 195 -- although this is not private, clients should not rely on the exact 196 -- way in which this string is represented, and instead should use the 197 -- subprograms below. 198 199 Dummy_Time_Stamp : constant Time_Stamp_Type := (others => '0'); 200 -- This is used for dummy time stamp values used in the D lines for 201 -- non-existent files, and is intended to be an impossible value. 202 203 function "=" (Left, Right : Time_Stamp_Type) return Boolean; 204 function "<=" (Left, Right : Time_Stamp_Type) return Boolean; 205 function ">=" (Left, Right : Time_Stamp_Type) return Boolean; 206 function "<" (Left, Right : Time_Stamp_Type) return Boolean; 207 function ">" (Left, Right : Time_Stamp_Type) return Boolean; 208 -- Comparison functions on time stamps. Note that two time stamps are 209 -- defined as being equal if they have the same day/month/year and the 210 -- hour/minutes/seconds values are within 2 seconds of one another. This 211 -- deals with rounding effects in library file time stamps caused by 212 -- copying operations during installation. We have particularly noticed 213 -- that WinNT seems susceptible to such changes. 214 -- 215 -- Note : the Empty_Time_Stamp value looks equal to itself, and less 216 -- than any non-empty time stamp value. 217 end Stamps; 218 219 use Stamps; 220 221 -------------------- 222 -- Default Output -- 223 -------------------- 224 225 type Section_Type is (Setup, Compile, Build_Libraries, Bind, Link); 226 -- Different sections in the default output, when switches -q and -v are 227 -- not used. 228 229 procedure Set (Section : Section_Type); 230 -- Indicate that the section header does not need to be output again. 231 -- This is used by gprbind and gprlib to avoid display the section header 232 -- again. 233 234 procedure Display 235 (Section : Section_Type; 236 Command : String; 237 Argument : String); 238 -- Display a command in the standard output. Display first the section 239 -- header if it has not been already displayed. 240 241 -------------------- 242 243 type Name_Id is range 0 .. 99_999_999; 244 No_Name : constant Name_Id := 0; 245 Error_Name : constant Name_Id := 1; 246 247 First_Name_Id : constant Name_Id := 2; 248 -- Subscript of first entry in names table 249 250 type Unit_Name_Type is new Name_Id; 251 -- Unit names are stored in the names table and this type is used to 252 -- indicate that a Name_Id value is being used to hold a unit name, 253 -- which terminates in %b for a body or %s for a spec. 254 255 No_Unit_Name : constant Unit_Name_Type := Unit_Name_Type (No_Name); 256 -- Constant used to indicate no file name present 257 258 Error_Unit_Name : constant Unit_Name_Type := Unit_Name_Type (Error_Name); 259 -- The special Unit_Name_Type value Error_Unit_Name is used to indicate 260 -- a unit name where some previous processing has found an error. 261 262 type Added_Rec; 263 type Added_Ptr is access Added_Rec; 264 type Added_Rec is record 265 Name : Name_Id; 266 Next : Added_Ptr; 267 end record; 268 269 ------------------------------ 270 -- File and Path Name Types -- 271 ------------------------------ 272 273 type File_Name_Type is new Name_Id; 274 -- File names are stored in the names table and this type is used to 275 -- indicate that a Name_Id value is being used to hold a simple file 276 -- name (which does not include any directory information). 277 278 No_File : constant File_Name_Type := File_Name_Type (No_Name); 279 -- Constant used to indicate no file is present (this is used for 280 -- example when a search for a file indicates that no file of the 281 -- name exists). 282 283 Error_File_Name : constant File_Name_Type := File_Name_Type (Error_Name); 284 -- The special File_Name_Type value Error_File_Name is used to indicate 285 -- a unit name where some previous processing has found an error. 286 287 type Path_Name_Type is new Name_Id; 288 -- Path names are stored in the names table and this type is used to 289 -- indicate that a Name_Id value is being used to hold a path name (that 290 -- may contain directory information). 291 292 No_Path : constant Path_Name_Type := Path_Name_Type (No_Name); 293 -- Constant used to indicate no path name is present 294 295 File_Attributes_Size : constant Natural := 32; 296 type File_Attributes is 297 array (1 .. File_Attributes_Size) 298 of System.Storage_Elements.Storage_Element; 299 for File_Attributes'Alignment use Standard'Maximum_Alignment; 300 -- A cache for various attributes for a file (length, accessibility,...) 301 -- This must be initialized to Unknown_Attributes prior to the first call. 302 303 Unknown_Attributes : constant File_Attributes := (others => 0); 304 305 Ada_Include_Path : constant String := "ADA_INCLUDE_PATH"; 306 Ada_Objects_Path : constant String := "ADA_OBJECTS_PATH"; 307 Project_Include_Path_File : constant String := "ADA_PRJ_INCLUDE_FILE"; 308 Project_Objects_Path_File : constant String := "ADA_PRJ_OBJECTS_FILE"; 309 310 procedure Add_Restricted_Language (Name : String); 311 -- Call by gprbuild for each language specified by switch 312 -- --restricted-to-languages=. 313 314 procedure Remove_All_Restricted_Languages; 315 -- Call by gprbuild in CodePeer mode to ignore switches 316 -- --restricted-to-languages=. 317 318 function Is_Allowed_Language (Name : Name_Id) return Boolean; 319 -- Returns True if --restricted-to-languages= is not used or if Name 320 -- is one of the restricted languages. 321 322 function Languages_Are_Restricted return Boolean; 323 -- Returns True iff the list of restricted languages is not empty. 324 325 All_Other_Names : constant Name_Id := Name_Id'Last; 326 -- Name used to replace others as an index of an associative array 327 -- attribute in situations where this is allowed. 328 329 Subdirs : String_Access := null; 330 -- The value after the equal sign in switch --subdirs=... 331 -- Contains the relative subdirectory. 332 333 Build_Tree_Dir : String_Access := null; 334 -- A root directory for building out-of-tree projects. All relative object 335 -- directories will be rooted at this location. 336 337 Root_Dir : String_Access := null; 338 -- When using out-of-tree build we need to keep information about the root 339 -- directory of artifacts to properly relocate them. Note that the root 340 -- directory is not necessarily the directory of the main project. 341 342 type Library_Support is (None, Static_Only, Full); 343 -- Support for Library Project File. 344 -- - None: Library Project Files are not supported at all 345 -- - Static_Only: Library Project Files are only supported for static 346 -- libraries. 347 -- - Full: Library Project Files are supported for static and dynamic 348 -- (shared) libraries. 349 350 type Yes_No_Unknown is (Yes, No, Unknown); 351 -- Tri-state to decide if -lgnarl is needed when linking 352 353 type Attribute_Default_Value is 354 (Read_Only_Value, -- For read only attributes (Name, Project_Dir) 355 Empty_Value, -- Empty string or empty string list 356 Dot_Value, -- "." or (".") 357 Object_Dir_Value, -- 'Object_Dir 358 Target_Value, -- 'Target (special rules) 359 Runtime_Value); -- 'Runtime (special rules) 360 -- Describe the default values of attributes that are referenced but not 361 -- declared. 362 363 pragma Warnings (Off); 364 type Project_Qualifier is 365 (Unspecified, 366 367 -- The following clash with Standard is OK, and justified by the context 368 -- which really wants to use the same set of qualifiers. 369 370 Standard, 371 372 Library, 373 Configuration, 374 Abstract_Project, 375 Aggregate, 376 Aggregate_Library); 377 pragma Warnings (On); 378 -- Qualifiers that can prefix the reserved word "project" in a project 379 -- file: 380 -- Standard: standard project ... 381 -- Library: library project is ... 382 -- Abstract_Project: abstract project is 383 -- Aggregate: aggregate project is 384 -- Aggregate_Library: aggregate library project is ... 385 -- Configuration: configuration project is ... 386 387 subtype Aggregate_Project is 388 Project_Qualifier range Aggregate .. Aggregate_Library; 389 390 All_Packages : constant String_List_Access; 391 -- Default value of parameter Packages of procedures Parse, in Prj.Pars and 392 -- Prj.Part, indicating that all packages should be checked. 393 394 type Project_Tree_Data; 395 type Project_Tree_Ref is access all Project_Tree_Data; 396 -- Reference to a project tree. Several project trees may exist in memory 397 -- at the same time. 398 399 No_Project_Tree : constant Project_Tree_Ref; 400 401 procedure Free (Tree : in out Project_Tree_Ref); 402 -- Free memory associated with the tree 403 404 Config_Project_File_Extension : String := ".cgpr"; 405 Project_File_Extension : String := ".gpr"; 406 -- The standard config and user project file name extensions. They are not 407 -- constants, because Canonical_Case_File_Name is called on these variables 408 -- in the body of Prj. 409 410 function Empty_File return File_Name_Type; 411 function Empty_String return Name_Id; 412 -- Return the id for an empty string "" 413 414 function Dot_String return Name_Id; 415 -- Return the id for "." 416 417 type Path_Information is record 418 Name : Path_Name_Type := No_Path; 419 Display_Name : Path_Name_Type := No_Path; 420 end record; 421 -- Directory names always end with a directory separator 422 423 No_Path_Information : constant Path_Information := (No_Path, No_Path); 424 425 type Project_Data; 426 type Project_Id is access all Project_Data; 427 No_Project : constant Project_Id := null; 428 -- Id of a Project File 429 430 type String_List_Id is new Nat; 431 Nil_String : constant String_List_Id := 0; 432 type String_Element is record 433 Value : Name_Id := No_Name; 434 Index : Int := 0; 435 Display_Value : Name_Id := No_Name; 436 Location : Source_Ptr := No_Location; 437 Flag : Boolean := False; 438 Next : String_List_Id := Nil_String; 439 end record; 440 -- To hold values for string list variables and array elements. 441 -- Component Flag may be used for various purposes. For source 442 -- directories, it indicates if the directory contains Ada source(s). 443 444 package String_Element_Table is new GNAT.Dynamic_Tables 445 (Table_Component_Type => String_Element, 446 Table_Index_Type => String_List_Id, 447 Table_Low_Bound => 1, 448 Table_Initial => 200, 449 Table_Increment => 100); 450 -- The table for string elements in string lists 451 452 type Variable_Kind is (Undefined, List, Single); 453 -- Different kinds of variables 454 455 subtype Defined_Variable_Kind is Variable_Kind range List .. Single; 456 -- The defined kinds of variables 457 458 Ignored : constant Variable_Kind; 459 -- Used to indicate that a package declaration must be ignored while 460 -- processing the project tree (unknown package name). 461 462 type Variable_Value (Kind : Variable_Kind := Undefined) is record 463 Project : Project_Id := No_Project; 464 Location : Source_Ptr := No_Location; 465 String_Type : Project_Node_Id := Empty_Project_Node; 466 Default : Boolean := False; 467 case Kind is 468 when Undefined => 469 null; 470 when List => 471 Values : String_List_Id := Nil_String; 472 when Single => 473 Value : Name_Id := No_Name; 474 Index : Int := 0; 475 end case; 476 end record; 477 -- Values for variables and array elements. Default is True if the 478 -- current value is the default one for the variable. String_Type is 479 -- Empty_Project_Node, except for typed variables where it designates 480 -- the string type node. 481 482 Nil_Variable_Value : constant Variable_Value; 483 -- Value of a non existing variable or array element 484 485 type Variable_Id is new Nat; 486 No_Variable : constant Variable_Id := 0; 487 type Variable is record 488 Next : Variable_Id := No_Variable; 489 Name : Name_Id; 490 Value : Variable_Value; 491 end record; 492 -- To hold the list of variables in a project file and in packages 493 494 package Variable_Element_Table is new GNAT.Dynamic_Tables 495 (Table_Component_Type => Variable, 496 Table_Index_Type => Variable_Id, 497 Table_Low_Bound => 1, 498 Table_Initial => 200, 499 Table_Increment => 100); 500 -- The table of variable in list of variables 501 502 type Array_Element_Id is new Nat; 503 No_Array_Element : constant Array_Element_Id := 0; 504 type Array_Element is record 505 Index : Name_Id; 506 Restricted : Boolean := False; 507 Src_Index : Int := 0; 508 Index_Case_Sensitive : Boolean := True; 509 Value : Variable_Value; 510 Next : Array_Element_Id := No_Array_Element; 511 end record; 512 -- Each Array_Element represents an array element and is linked (Next) 513 -- to the next array element, if any, in the array. 514 515 package Array_Element_Table is new GNAT.Dynamic_Tables 516 (Table_Component_Type => Array_Element, 517 Table_Index_Type => Array_Element_Id, 518 Table_Low_Bound => 1, 519 Table_Initial => 200, 520 Table_Increment => 100); 521 -- The table that contains all array elements 522 523 type Array_Id is new Nat; 524 No_Array : constant Array_Id := 0; 525 type Array_Data is record 526 Name : Name_Id := No_Name; 527 Location : Source_Ptr := No_Location; 528 Value : Array_Element_Id := No_Array_Element; 529 Next : Array_Id := No_Array; 530 end record; 531 -- Each Array_Data value represents an array. 532 -- Value is the id of the first element. 533 -- Next is the id of the next array in the project file or package. 534 535 package Array_Table is new GNAT.Dynamic_Tables 536 (Table_Component_Type => Array_Data, 537 Table_Index_Type => Array_Id, 538 Table_Low_Bound => 1, 539 Table_Initial => 200, 540 Table_Increment => 100); 541 -- The table that contains all arrays 542 543 type Package_Id is new Nat; 544 No_Package : constant Package_Id := 0; 545 type Declarations is record 546 Variables : Variable_Id := No_Variable; 547 Attributes : Variable_Id := No_Variable; 548 Arrays : Array_Id := No_Array; 549 Packages : Package_Id := No_Package; 550 end record; 551 -- Contains the declarations (variables, single and array attributes, 552 -- packages) for a project or a package in a project. 553 554 No_Declarations : constant Declarations := 555 (Variables => No_Variable, 556 Attributes => No_Variable, 557 Arrays => No_Array, 558 Packages => No_Package); 559 -- Default value of Declarations: used if there are no declarations 560 561 type Package_Element is record 562 Name : Name_Id := No_Name; 563 Decl : Declarations := No_Declarations; 564 Parent : Package_Id := No_Package; 565 Next : Package_Id := No_Package; 566 end record; 567 -- A package (includes declarations that may include other packages) 568 569 package Package_Table is new GNAT.Dynamic_Tables 570 (Table_Component_Type => Package_Element, 571 Table_Index_Type => Package_Id, 572 Table_Low_Bound => 1, 573 Table_Initial => 100, 574 Table_Increment => 100); 575 -- The table that contains all packages 576 577 type Language_Data; 578 type Language_Ptr is access all Language_Data; 579 -- Index of language data 580 581 No_Language_Index : constant Language_Ptr := null; 582 -- Constant indicating that there is no language data 583 584 function Get_Language_From_Name 585 (Project : Project_Id; 586 Name : String) return Language_Ptr; 587 -- Get a language from a project. This might return null if no such 588 -- language exists in the project 589 590 Max_Header_Num : constant := 6150; 591 type Header_Num is range 0 .. Max_Header_Num; 592 -- Size for hash table below. The upper bound is an arbitrary value, the 593 -- value here was chosen after testing to determine a good compromise 594 -- between speed of access and memory usage. 595 596 function Hash (Name : Name_Id) return Header_Num; 597 function Hash (Name : File_Name_Type) return Header_Num; 598 function Hash (Name : Path_Name_Type) return Header_Num; 599 function Hash (Project : Project_Id) return Header_Num; 600 -- Used for computing hash values for names put into hash tables 601 602 type Language_Kind is (File_Based, Unit_Based); 603 -- Type for the kind of language. All languages are file based, except Ada 604 -- which is unit based. 605 606 -- Type of dependency to be checked 607 608 type Dependency_File_Kind is 609 (None, 610 -- There is no dependency file, the source must always be recompiled 611 612 Makefile, 613 -- The dependency file is a Makefile fragment indicating all the files 614 -- the source depends on. If the object file or the dependency file is 615 -- more recent than any of these files, the source must be recompiled. 616 617 ALI_File, 618 -- The dependency file is an ALI file and the source must be recompiled 619 -- if the object or ALI file is more recent than any of the sources 620 -- listed in the D lines. 621 622 ALI_Closure); 623 -- The dependency file is an ALI file and the source must be recompiled 624 -- if the object or ALI file is more recent than any source in the full 625 -- closure. 626 627 Makefile_Dependency_Suffix : constant String := ".d"; 628 ALI_Dependency_Suffix : constant String := ".ali"; 629 Switches_Dependency_Suffix : constant String := ".cswi"; 630 631 Binder_Exchange_Suffix : constant String := ".bexch"; 632 -- Suffix for binder exchange files 633 634 Library_Exchange_Suffix : constant String := ".lexch"; 635 -- Suffix for library exchange files 636 637 type Name_List_Index is new Nat; 638 No_Name_List : constant Name_List_Index := 0; 639 640 type Name_Node is record 641 Name : Name_Id := No_Name; 642 Next : Name_List_Index := No_Name_List; 643 end record; 644 645 package Name_List_Table is new GNAT.Dynamic_Tables 646 (Table_Component_Type => Name_Node, 647 Table_Index_Type => Name_List_Index, 648 Table_Low_Bound => 1, 649 Table_Initial => 10, 650 Table_Increment => 100); 651 -- The table for lists of names 652 653 function Length 654 (Table : Name_List_Table.Instance; 655 List : Name_List_Index) return Natural; 656 -- Return the number of elements in specified list 657 658 type Number_List_Index is new Nat; 659 No_Number_List : constant Number_List_Index := 0; 660 661 type Number_Node is record 662 Number : Natural := 0; 663 Next : Number_List_Index := No_Number_List; 664 end record; 665 666 package Number_List_Table is new GNAT.Dynamic_Tables 667 (Table_Component_Type => Number_Node, 668 Table_Index_Type => Number_List_Index, 669 Table_Low_Bound => 1, 670 Table_Initial => 10, 671 Table_Increment => 100); 672 -- The table for lists of numbers 673 674 package Mapping_Files_Htable is new Simple_HTable 675 (Header_Num => Header_Num, 676 Element => Path_Name_Type, 677 No_Element => No_Path, 678 Key => Path_Name_Type, 679 Hash => Hash, 680 Equal => "="); 681 -- A hash table to store the mapping files that are not used 682 683 -- The following record ??? 684 685 type Casing_Type is ( 686 687 All_Upper_Case, 688 -- All letters are upper case 689 690 All_Lower_Case, 691 -- All letters are lower case 692 693 Mixed_Case, 694 -- The initial letter, and any letters after underlines are upper case. 695 -- All other letters are lower case 696 697 Unknown 698 -- Used if an identifier does not distinguish between the above cases, 699 -- (e.g. X, Y_3, M4, A_B, or if it is inconsistent ABC_def). 700 ); 701 702 subtype Known_Casing is Casing_Type range All_Upper_Case .. Mixed_Case; 703 -- Exclude Unknown casing 704 705 type Lang_Naming_Data is record 706 Dot_Replacement : File_Name_Type := No_File; 707 -- The string to replace '.' in the source file name (for Ada) 708 709 Casing : Casing_Type := All_Lower_Case; 710 -- The casing of the source file name (for Ada) 711 712 Separate_Suffix : File_Name_Type := No_File; 713 -- String to append to unit name for source file name of an Ada subunit 714 715 Spec_Suffix : File_Name_Type := No_File; 716 -- The string to append to the unit name for the 717 -- source file name of a spec. 718 719 Body_Suffix : File_Name_Type := No_File; 720 -- The string to append to the unit name for the 721 -- source file name of a body. 722 end record; 723 724 No_Lang_Naming_Data : constant Lang_Naming_Data := 725 (Dot_Replacement => No_File, 726 Casing => All_Lower_Case, 727 Separate_Suffix => No_File, 728 Spec_Suffix => No_File, 729 Body_Suffix => No_File); 730 731 function Is_Standard_GNAT_Naming (Naming : Lang_Naming_Data) return Boolean; 732 -- True if the naming scheme is GNAT's default naming scheme. This 733 -- is to take into account shortened names like "Ada." (a-), "System." (s-) 734 -- and so on. 735 736 type Source_Data; 737 type Source_Id is access all Source_Data; 738 739 function Is_Compilable (Source : Source_Id) return Boolean; 740 pragma Inline (Is_Compilable); 741 -- Return True if we know how to compile Source (i.e. if a compiler is 742 -- defined). This doesn't indicate whether the source should be compiled. 743 744 function Object_To_Global_Archive (Source : Source_Id) return Boolean; 745 pragma Inline (Object_To_Global_Archive); 746 -- Return True if the object file should be put in the global archive. 747 -- This is for Ada, when only the closure of a main needs to be 748 -- (re)compiled. 749 750 function Other_Part (Source : Source_Id) return Source_Id; 751 pragma Inline (Other_Part); 752 -- Source ID for the other part, if any: for a spec, returns its body; 753 -- for a body, returns its spec. 754 755 No_Source : constant Source_Id := null; 756 757 type Path_Syntax_Kind is 758 (Canonical, -- Unix style 759 Host); -- Host specific syntax 760 761 -- The following record describes the configuration of a language 762 763 type Language_Config is record 764 Kind : Language_Kind := File_Based; 765 -- Kind of language. Most languages are file based. A few, such as Ada, 766 -- are unit based. 767 768 Naming_Data : Lang_Naming_Data; 769 -- The naming data for the languages (prefixes, etc.) 770 771 Include_Compatible_Languages : Name_List_Index := No_Name_List; 772 -- List of languages that are "include compatible" with this language. A 773 -- language B (for example "C") is "include compatible" with a language 774 -- A (for example "C++") if it is expected that sources of language A 775 -- may "include" header files from language B. 776 777 Compiler_Driver : File_Name_Type := No_File; 778 -- The name of the executable for the compiler of the language 779 780 Compiler_Driver_Path : String_Access := null; 781 -- The path name of the executable for the compiler of the language 782 783 Compiler_Leading_Required_Switches : Name_List_Index := No_Name_List; 784 -- The list of initial switches that are required as a minimum to invoke 785 -- the compiler driver. 786 787 Compiler_Trailing_Required_Switches : Name_List_Index := No_Name_List; 788 -- The list of final switches that are required as a minimum to invoke 789 -- the compiler driver. 790 791 Multi_Unit_Switches : Name_List_Index := No_Name_List; 792 -- The switch(es) to indicate the index of a unit in a multi-source file 793 794 Multi_Unit_Object_Separator : Character := ' '; 795 -- The string separating the base name of a source from the index of the 796 -- unit in a multi-source file, in the object file name. 797 798 Path_Syntax : Path_Syntax_Kind := Host; 799 -- Value may be Canonical (Unix style) or Host (host syntax) 800 801 Source_File_Switches : Name_List_Index := No_Name_List; 802 -- Optional switches to be put before the source file. The source file 803 -- path name is appended to the last switch in the list. 804 -- Example: ("-i", ""); 805 806 Object_File_Suffix : Name_Id := No_Name; 807 -- Optional alternate object file suffix 808 809 Object_File_Switches : Name_List_Index := No_Name_List; 810 -- Optional object file switches. When this is defined, the switches 811 -- are used to specify the object file. The object file name is appended 812 -- to the last switch in the list. Example: ("-o", ""). 813 814 Object_Path_Switches : Name_List_Index := No_Name_List; 815 -- List of switches to specify to the compiler the path name of a 816 -- temporary file containing the list of object directories in the 817 -- correct order. 818 819 Compilation_PIC_Option : Name_List_Index := No_Name_List; 820 -- The option(s) to compile a source in Position Independent Code for 821 -- shared libraries. Specified in the configuration. When not specified, 822 -- there is no need for such switch. 823 824 Object_Generated : Boolean := True; 825 -- False if no object file is generated 826 827 Objects_Linked : Boolean := True; 828 -- False if object files are not use to link executables and build 829 -- libraries. 830 831 Runtime_Library_Dirs : Name_List_Index := No_Name_List; 832 -- Path names of the runtime library directories, if any 833 834 Runtime_Source_Dirs : Name_List_Index := No_Name_List; 835 -- Path names of the runtime source directories, if any 836 837 Mapping_File_Switches : Name_List_Index := No_Name_List; 838 -- The option(s) to provide a mapping file to the compiler. Specified in 839 -- the configuration. When value is No_Name_List, there is no mapping 840 -- file. 841 842 Mapping_Spec_Suffix : File_Name_Type := No_File; 843 -- Placeholder representing the spec suffix in a mapping file 844 845 Mapping_Body_Suffix : File_Name_Type := No_File; 846 -- Placeholder representing the body suffix in a mapping file 847 848 Config_File_Switches : Name_List_Index := No_Name_List; 849 -- The option(s) to provide a config file to the compiler. Specified in 850 -- the configuration. If value is No_Name_List there is no config file. 851 852 Dependency_Kind : Dependency_File_Kind := None; 853 -- The kind of dependency to be checked: none, Makefile fragment or 854 -- ALI file (for Ada). 855 856 Dependency_Option : Name_List_Index := No_Name_List; 857 -- The option(s) to be used to create the dependency file. When value is 858 -- No_Name_List, there is not such option(s). 859 860 Compute_Dependency : Name_List_Index := No_Name_List; 861 -- Hold the value of attribute Dependency_Driver, if declared for the 862 -- language. 863 864 Include_Option : Name_List_Index := No_Name_List; 865 -- Hold the value of attribute Include_Switches, if declared for the 866 -- language. 867 868 Include_Path : Name_Id := No_Name; 869 -- Name of environment variable declared by attribute Include_Path for 870 -- the language. 871 872 Include_Path_File : Name_Id := No_Name; 873 -- Name of environment variable declared by attribute Include_Path_File 874 -- for the language. 875 876 Objects_Path : Name_Id := No_Name; 877 -- Name of environment variable declared by attribute Objects_Path for 878 -- the language. 879 880 Objects_Path_File : Name_Id := No_Name; 881 -- Name of environment variable declared by attribute Objects_Path_File 882 -- for the language. 883 884 Config_Body : Name_Id := No_Name; 885 -- The template for a pragma Source_File_Name(_Project) for a specific 886 -- file name of a body. 887 888 Config_Body_Index : Name_Id := No_Name; 889 -- The template for a pragma Source_File_Name(_Project) for a specific 890 -- file name of a body in a multi-source file. 891 892 Config_Body_Pattern : Name_Id := No_Name; 893 -- The template for a pragma Source_File_Name(_Project) for a naming 894 -- body pattern. 895 896 Config_Spec : Name_Id := No_Name; 897 -- The template for a pragma Source_File_Name(_Project) for a specific 898 -- file name of a spec. 899 900 Config_Spec_Index : Name_Id := No_Name; 901 -- The template for a pragma Source_File_Name(_Project) for a specific 902 -- file name of a spec in a multi-source file. 903 904 Config_Spec_Pattern : Name_Id := No_Name; 905 -- The template for a pragma Source_File_Name(_Project) for a naming 906 -- spec pattern. 907 908 Config_File_Unique : Boolean := False; 909 -- True if the config file specified to the compiler needs to be unique. 910 -- If it is unique, then all config files are concatenated into a temp 911 -- config file. 912 913 Binder_Driver : File_Name_Type := No_File; 914 -- The name of the binder driver for the language, if any 915 916 Binder_Driver_Path : Path_Name_Type := No_Path; 917 -- The path name of the binder driver 918 919 Binder_Required_Switches : Name_List_Index := No_Name_List; 920 -- Hold the value of attribute Binder'Required_Switches for the language 921 922 Binder_Prefix : Name_Id := No_Name; 923 -- Hold the value of attribute Binder'Prefix for the language 924 925 Toolchain_Version : Name_Id := No_Name; 926 -- Hold the value of attribute Toolchain_Version for the language 927 928 Toolchain_Description : Name_Id := No_Name; 929 -- Hold the value of attribute Toolchain_Description for the language 930 931 Clean_Object_Artifacts : Name_List_Index := No_Name_List; 932 -- List of object artifact extensions to be deleted by gprclean 933 934 Clean_Source_Artifacts : Name_List_Index := No_Name_List; 935 -- List of source artifact extensions to be deleted by gprclean 936 937 Resp_File_Format : Response_File_Format := None; 938 -- The format of a response file, when compiling with a response file is 939 -- supported. 940 941 Resp_File_Options : Name_List_Index := No_Name_List; 942 -- The switches, if any, that precede the path name of the response 943 -- file in the invocation of the compiler. 944 945 end record; 946 947 No_Language_Config : constant Language_Config := 948 (Kind => File_Based, 949 Naming_Data => No_Lang_Naming_Data, 950 Include_Compatible_Languages => No_Name_List, 951 Compiler_Driver => No_File, 952 Compiler_Driver_Path => null, 953 Compiler_Leading_Required_Switches 954 => No_Name_List, 955 Compiler_Trailing_Required_Switches 956 => No_Name_List, 957 Multi_Unit_Switches => No_Name_List, 958 Multi_Unit_Object_Separator => ' ', 959 Path_Syntax => Canonical, 960 Source_File_Switches => No_Name_List, 961 Object_File_Suffix => No_Name, 962 Object_File_Switches => No_Name_List, 963 Object_Path_Switches => No_Name_List, 964 Compilation_PIC_Option => No_Name_List, 965 Object_Generated => True, 966 Objects_Linked => True, 967 Runtime_Library_Dirs => No_Name_List, 968 Runtime_Source_Dirs => No_Name_List, 969 Mapping_File_Switches => No_Name_List, 970 Mapping_Spec_Suffix => No_File, 971 Mapping_Body_Suffix => No_File, 972 Config_File_Switches => No_Name_List, 973 Dependency_Kind => None, 974 Dependency_Option => No_Name_List, 975 Compute_Dependency => No_Name_List, 976 Include_Option => No_Name_List, 977 Include_Path => No_Name, 978 Include_Path_File => No_Name, 979 Objects_Path => No_Name, 980 Objects_Path_File => No_Name, 981 Config_Body => No_Name, 982 Config_Body_Index => No_Name, 983 Config_Body_Pattern => No_Name, 984 Config_Spec => No_Name, 985 Config_Spec_Index => No_Name, 986 Config_Spec_Pattern => No_Name, 987 Config_File_Unique => False, 988 Binder_Driver => No_File, 989 Binder_Driver_Path => No_Path, 990 Binder_Required_Switches => No_Name_List, 991 Binder_Prefix => No_Name, 992 Toolchain_Version => No_Name, 993 Toolchain_Description => No_Name, 994 Clean_Object_Artifacts => No_Name_List, 995 Clean_Source_Artifacts => No_Name_List, 996 Resp_File_Format => None, 997 Resp_File_Options => No_Name_List); 998 999 type Language_Data is record 1000 Name : Name_Id := No_Name; 1001 -- The name of the language in lower case 1002 1003 Display_Name : Name_Id := No_Name; 1004 -- The name of the language, as found in attribute Languages 1005 1006 Config : Language_Config := No_Language_Config; 1007 -- Configuration of the language 1008 1009 First_Source : Source_Id := No_Source; 1010 -- Head of the list of sources of the language in the project 1011 1012 Mapping_Files : Mapping_Files_Htable.Instance := 1013 Mapping_Files_Htable.Nil; 1014 -- Hash table containing the mapping of the sources to their path names 1015 1016 Next : Language_Ptr := No_Language_Index; 1017 -- Next language of the project 1018 1019 end record; 1020 1021 No_Language_Data : constant Language_Data := 1022 (Name => No_Name, 1023 Display_Name => No_Name, 1024 Config => No_Language_Config, 1025 First_Source => No_Source, 1026 Mapping_Files => Mapping_Files_Htable.Nil, 1027 Next => No_Language_Index); 1028 1029 type Language_List_Element; 1030 type Language_List is access all Language_List_Element; 1031 type Language_List_Element is record 1032 Language : Language_Ptr := No_Language_Index; 1033 Next : Language_List; 1034 end record; 1035 1036 type Source_Kind is (Spec, Impl, Sep); 1037 subtype Spec_Or_Body is Source_Kind range Spec .. Impl; 1038 1039 -- The following declarations declare a structure used to store the Name 1040 -- and File and Path names of a unit, with a reference to its GNAT Project 1041 -- File(s). Some units might have neither Spec nor Impl when they were 1042 -- created for a "separate". 1043 1044 type File_Names_Data is array (Spec_Or_Body) of Source_Id; 1045 1046 type Unit_Data is record 1047 Name : Name_Id := No_Name; 1048 File_Names : File_Names_Data; 1049 end record; 1050 1051 type Unit_Index is access all Unit_Data; 1052 1053 No_Unit_Index : constant Unit_Index := null; 1054 -- Used to indicate a null entry for no unit 1055 1056 type Source_Roots; 1057 type Roots_Access is access Source_Roots; 1058 type Source_Roots is record 1059 Root : Source_Id; 1060 Next : Roots_Access; 1061 end record; 1062 -- A list to store the roots associated with a main unit. These are the 1063 -- files that need to linked along with the main (for instance a C file 1064 -- corresponding to an Ada file). In general, these are dependencies that 1065 -- cannot be computed automatically by the builder. 1066 1067 type Naming_Exception_Type is (No, Yes, Inherited); 1068 1069 -- Structure to define source data 1070 1071 type Source_Data is record 1072 Initialized : Boolean := False; 1073 -- Set to True when Source_Data is completely initialized 1074 1075 Project : Project_Id := No_Project; 1076 -- Project of the source 1077 1078 Location : Source_Ptr := No_Location; 1079 -- Location in the project file of the declaration of the source in 1080 -- package Naming. 1081 1082 Source_Dir_Rank : Natural := 0; 1083 -- The rank of the source directory in list declared with attribute 1084 -- Source_Dirs. Two source files with the same name cannot appears in 1085 -- different directory with the same rank. That can happen when the 1086 -- recursive notation <dir>/** is used in attribute Source_Dirs. 1087 1088 Language : Language_Ptr := No_Language_Index; 1089 -- Language of the source 1090 1091 In_Interfaces : Boolean := True; 1092 -- False when the source is not included in interfaces, when attribute 1093 -- Interfaces is declared. 1094 1095 Declared_In_Interfaces : Boolean := False; 1096 -- True when source is declared in attribute Interfaces 1097 1098 Alternate_Languages : Language_List := null; 1099 -- List of languages a header file may also be, in addition of language 1100 -- Language_Name. 1101 1102 Kind : Source_Kind := Spec; 1103 -- Kind of the source: spec, body or subunit 1104 1105 Unit : Unit_Index := No_Unit_Index; 1106 -- Name of the unit, if language is unit based. This is only set for 1107 -- those files that are part of the compilation set (for instance a 1108 -- file in an extended project that is overridden will not have this 1109 -- field set). 1110 1111 Index : Int := 0; 1112 -- Index of the source in a multi unit source file (the same Source_Data 1113 -- is duplicated several times when there are several units in the same 1114 -- file). Index is 0 if there is either no unit or a single one, and 1115 -- starts at 1 when there are multiple units 1116 1117 Compilable : Yes_No_Unknown := Unknown; 1118 -- Updated at the first call to Is_Compilable. Yes if source file is 1119 -- compilable. 1120 1121 In_The_Queue : Boolean := False; 1122 -- True if the source has been put in the queue 1123 1124 Locally_Removed : Boolean := False; 1125 -- True if the source has been "excluded" 1126 1127 Suppressed : Boolean := False; 1128 -- True if the source is a locally removed direct source of the project. 1129 -- These sources should not be put in the mapping file. 1130 1131 Replaced_By : Source_Id := No_Source; 1132 -- Source in an extending project that replaces the current source 1133 1134 File : File_Name_Type := No_File; 1135 -- Canonical file name of the source 1136 1137 Display_File : File_Name_Type := No_File; 1138 -- File name of the source, for display purposes 1139 1140 Path : Path_Information := No_Path_Information; 1141 -- Path name of the source 1142 1143 Source_TS : Time_Stamp_Type := Empty_Time_Stamp; 1144 -- Time stamp of the source file 1145 1146 Object_Project : Project_Id := No_Project; 1147 -- Project where the object file is. This might be different from 1148 -- Project when using extending project files. 1149 1150 Object : File_Name_Type := No_File; 1151 -- File name of the object file 1152 1153 Current_Object_Path : Path_Name_Type := No_Path; 1154 -- Object path of an existing object file 1155 1156 Object_Path : Path_Name_Type := No_Path; 1157 -- Object path of the real object file 1158 1159 Object_TS : Time_Stamp_Type := Empty_Time_Stamp; 1160 -- Object file time stamp 1161 1162 Dep_Name : File_Name_Type := No_File; 1163 -- Dependency file simple name 1164 1165 Current_Dep_Path : Path_Name_Type := No_Path; 1166 -- Path name of an existing dependency file 1167 1168 Dep_Path : Path_Name_Type := No_Path; 1169 -- Path name of the real dependency file 1170 1171 Dep_TS : aliased File_Attributes := Unknown_Attributes; 1172 -- Dependency file time stamp 1173 1174 Switches : File_Name_Type := No_File; 1175 -- File name of the switches file. For all languages, this is a file 1176 -- that ends with the .cswi extension. 1177 1178 Switches_Path : Path_Name_Type := No_Path; 1179 -- Path name of the switches file 1180 1181 Switches_TS : Time_Stamp_Type := Empty_Time_Stamp; 1182 -- Switches file time stamp 1183 1184 Naming_Exception : Naming_Exception_Type := No; 1185 -- True if the source has an exceptional name 1186 1187 Duplicate_Unit : Boolean := False; 1188 -- True when a duplicate unit has been reported for this source 1189 1190 Next_In_Lang : Source_Id := No_Source; 1191 -- Link to another source of the same language in the same project 1192 1193 Next_With_File_Name : Source_Id := No_Source; 1194 -- Link to another source with the same base file name 1195 1196 Roots : Roots_Access := null; 1197 -- The roots for a main unit 1198 1199 end record; 1200 1201 No_Source_Data : constant Source_Data := 1202 (Initialized => False, 1203 Project => No_Project, 1204 Location => No_Location, 1205 Source_Dir_Rank => 0, 1206 Language => No_Language_Index, 1207 In_Interfaces => True, 1208 Declared_In_Interfaces => False, 1209 Alternate_Languages => null, 1210 Kind => Spec, 1211 Unit => No_Unit_Index, 1212 Index => 0, 1213 Locally_Removed => False, 1214 Suppressed => False, 1215 Compilable => Unknown, 1216 In_The_Queue => False, 1217 Replaced_By => No_Source, 1218 File => No_File, 1219 Display_File => No_File, 1220 Path => No_Path_Information, 1221 Source_TS => Empty_Time_Stamp, 1222 Object_Project => No_Project, 1223 Object => No_File, 1224 Current_Object_Path => No_Path, 1225 Object_Path => No_Path, 1226 Object_TS => Empty_Time_Stamp, 1227 Dep_Name => No_File, 1228 Current_Dep_Path => No_Path, 1229 Dep_Path => No_Path, 1230 Dep_TS => Unknown_Attributes, 1231 Switches => No_File, 1232 Switches_Path => No_Path, 1233 Switches_TS => Empty_Time_Stamp, 1234 Naming_Exception => No, 1235 Duplicate_Unit => False, 1236 Next_In_Lang => No_Source, 1237 Next_With_File_Name => No_Source, 1238 Roots => null); 1239 1240 package Source_Files_Htable is new Simple_HTable 1241 (Header_Num => Header_Num, 1242 Element => Source_Id, 1243 No_Element => No_Source, 1244 Key => File_Name_Type, 1245 Hash => Hash, 1246 Equal => "="); 1247 -- Mapping of source file names to source ids 1248 1249 package Source_Paths_Htable is new Simple_HTable 1250 (Header_Num => Header_Num, 1251 Element => Source_Id, 1252 No_Element => No_Source, 1253 Key => Path_Name_Type, 1254 Hash => Hash, 1255 Equal => "="); 1256 -- Mapping of source paths to source ids 1257 1258 type Lib_Kind is (Static, Static_Pic, Dynamic, Relocatable); 1259 1260 function Image (Kind : Lib_Kind) return String; 1261 -- Return image of Lib_kind as used in project files 1262 1263 type Policy is (Restricted, Unrestricted); 1264 -- Type to specify the symbol policy, when symbol control is supported. 1265 -- Restricted: Restrict the symbols to those in the symbol file 1266 -- Unrestrictedt: All symbols are exported 1267 1268 type Symbol_Record is record 1269 Symbol_File : Path_Name_Type := No_Path; 1270 Symbol_Policy : Policy := Restricted; 1271 end record; 1272 -- Type to keep the symbol data to be used when building a shared library 1273 1274 No_Symbols : constant Symbol_Record := 1275 (Symbol_File => No_Path, 1276 Symbol_Policy => Restricted); 1277 -- The default value of the symbol data 1278 1279 function Image (The_Casing : Casing_Type) return String; 1280 -- Similar to 'Image (but avoid use of this attribute in compiler) 1281 1282 function Value (Image : String) return Casing_Type; 1283 -- Similar to 'Value (but avoid use of this attribute in compiler) 1284 -- Raises Constraint_Error if not a Casing_Type image. 1285 1286 -- The following record contains data for a naming scheme 1287 1288 function Get_Object_Directory 1289 (Project : Project_Id; 1290 Including_Libraries : Boolean; 1291 Only_If_Ada : Boolean := False) return Path_Name_Type; 1292 -- Return the object directory to use for the project. This depends on 1293 -- whether we have a library project or a standard project. This function 1294 -- might return No_Name when no directory applies. If the project is a 1295 -- library project file and Including_Libraries is True then the library 1296 -- ALI dir is returned instead of the object dir, except when there is no 1297 -- ALI files in the Library ALI dir and the object directory exists. If 1298 -- Only_If_Ada is True, then No_Name is returned when the project doesn't 1299 -- include any Ada source. 1300 1301 procedure Compute_All_Imported_Projects 1302 (Root_Project : Project_Id; 1303 Tree : Project_Tree_Ref); 1304 -- For all projects in the tree, compute the list of the projects imported 1305 -- directly or indirectly by project Root_Project. The result is stored in 1306 -- Project.All_Imported_Projects for each project 1307 1308 function Ultimate_Extending_Project_Of 1309 (Proj : Project_Id) return Project_Id; 1310 -- Returns the ultimate extending project of project Proj. If project Proj 1311 -- is not extended, returns Proj. 1312 1313 type Project_List_Element; 1314 type Project_List is access all Project_List_Element; 1315 type Project_List_Element is record 1316 Project : Project_Id := No_Project; 1317 From_Encapsulated_Lib : Boolean := False; 1318 Next : Project_List := null; 1319 end record; 1320 -- A list of projects 1321 1322 procedure Free_List 1323 (List : in out Project_List; 1324 Free_Project : Boolean); 1325 -- Free the list of projects, if Free_Project, each project is also freed 1326 1327 type Export_File_Format is 1328 (None, 1329 Flat, 1330 GNU, 1331 Def); 1332 -- The format of the different exported symbol files 1333 1334 type Project_Configuration is record 1335 Target : Name_Id := No_Name; 1336 -- The target of the configuration, when specified 1337 1338 Run_Path_Option : Name_List_Index := No_Name_List; 1339 -- The option to use when linking to specify the path where to look for 1340 -- libraries. 1341 1342 Run_Path_Origin : Name_Id := No_Name; 1343 -- Specify the string (such as "$ORIGIN") to indicate paths relative to 1344 -- the directory of the executable in the run path option. 1345 1346 Library_Install_Name_Option : Name_Id := No_Name; 1347 -- When this is not an empty list, this option, followed by the single 1348 -- name of the shared library file is used when linking a shared 1349 -- library. 1350 1351 Separate_Run_Path_Options : Boolean := False; 1352 -- True if each directory needs to be specified in a separate run path 1353 -- option. 1354 1355 Executable_Suffix : Name_Id := No_Name; 1356 -- The suffix of executables, when specified in the configuration or in 1357 -- package Builder of the main project. When this is not specified, the 1358 -- executable suffix is the default for the platform. 1359 1360 -- Linking 1361 1362 Linker : Path_Name_Type := No_Path; 1363 -- Path name of the linker driver. Specified in the configuration or in 1364 -- the package Builder of the main project. 1365 1366 Map_File_Option : Name_Id := No_Name; 1367 -- Option to use when invoking the linker to build a map file 1368 1369 Trailing_Linker_Required_Switches : Name_List_Index := No_Name_List; 1370 -- The minimum options for the linker driver. Specified in the 1371 -- configuration. 1372 1373 Linker_Executable_Option : Name_List_Index := No_Name_List; 1374 -- The option(s) to indicate the name of the executable in the linker 1375 -- command. Specified in the configuration. When not specified, default 1376 -- to -o <executable name>. 1377 1378 Linker_Lib_Dir_Option : Name_Id := No_Name; 1379 -- The option to specify where to find a library for linking. Specified 1380 -- in the configuration. When not specified, defaults to "-L". 1381 1382 Linker_Lib_Name_Option : Name_Id := No_Name; 1383 -- The option to specify the name of a library for linking. Specified in 1384 -- the configuration. When not specified, defaults to "-l". 1385 1386 Max_Command_Line_Length : Natural := 0; 1387 -- When positive and when Resp_File_Format (see below) is not None, 1388 -- if the command line for the invocation of the linker would be greater 1389 -- than this value, a response file is used to invoke the linker. 1390 -- Also used for compiler supporting response files. 1391 1392 Resp_File_Format : Response_File_Format := None; 1393 -- The format of a response file, when linking with a response file is 1394 -- supported. 1395 1396 Resp_File_Options : Name_List_Index := No_Name_List; 1397 -- The switches, if any, that precede the path name of the response 1398 -- file in the invocation of the linker. 1399 1400 -- Libraries 1401 1402 Library_Builder : Path_Name_Type := No_Path; 1403 -- The executable to build library (specified in the configuration) 1404 1405 Lib_Support : Library_Support := None; 1406 -- The level of library support. Specified in the configuration. Support 1407 -- is none, static libraries only or both static and shared libraries. 1408 1409 Lib_Encapsulated_Supported : Boolean := False; 1410 -- True when building fully standalone libraries supported on the target 1411 1412 Archive_Builder : Name_List_Index := No_Name_List; 1413 -- The name of the executable to build archives, with the minimum 1414 -- switches. Specified in the configuration. 1415 1416 Archive_Builder_Append_Option : Name_List_Index := No_Name_List; 1417 -- The options to append object files to an archive 1418 1419 Archive_Indexer : Name_List_Index := No_Name_List; 1420 -- The name of the executable to index archives, with the minimum 1421 -- switches. Specified in the configuration. 1422 1423 Archive_Suffix : File_Name_Type := No_File; 1424 -- The suffix of archives. Specified in the configuration. When not 1425 -- specified, defaults to ".a". 1426 1427 Object_Lister : Name_List_Index := No_Name_List; 1428 -- The object lister if any defined 1429 1430 Object_Lister_Matcher : Name_Id := No_Name; 1431 -- Pattern to match symbols out of the object lister output 1432 1433 Export_File_Format : GPR.Export_File_Format := GPR.None; 1434 -- The format of the expor file 1435 1436 Export_File_Switch : Name_Id := No_Name; 1437 -- Swicth to pass the export file to the linker 1438 1439 Lib_Partial_Linker : Name_List_Index := No_Name_List; 1440 1441 -- Shared libraries 1442 1443 Shared_Lib_Driver : File_Name_Type := No_File; 1444 -- The driver to link shared libraries. Set with attribute Library_GCC. 1445 -- Default to gcc. 1446 1447 Shared_Lib_Prefix : File_Name_Type := No_File; 1448 -- Part of a shared library file name that precedes the name of the 1449 -- library. Specified in the configuration. When not specified, defaults 1450 -- to "lib". 1451 1452 Shared_Lib_Suffix : File_Name_Type := No_File; 1453 -- Suffix of shared libraries, after the library name in the shared 1454 -- library name. Specified in the configuration. When not specified, 1455 -- default to ".so". 1456 1457 Shared_Lib_Min_Options : Name_List_Index := No_Name_List; 1458 -- The minimum options to use when building a shared library 1459 1460 Lib_Version_Options : Name_List_Index := No_Name_List; 1461 -- The options to use to specify a library version 1462 1463 Symbolic_Link_Supported : Boolean := False; 1464 -- True if the platform supports symbolic link files 1465 1466 Lib_Maj_Min_Id_Supported : Boolean := False; 1467 -- True if platform supports library major and minor options, such as 1468 -- libname.so -> libname.so.2 -> libname.so.2.4 1469 1470 Auto_Init_Supported : Boolean := False; 1471 -- True if automatic initialisation is supported for shared stand-alone 1472 -- libraries. 1473 1474 -- Cleaning 1475 1476 Artifacts_In_Exec_Dir : Name_List_Index := No_Name_List; 1477 -- List of regexp file names to be cleaned in the exec directory of the 1478 -- main project. 1479 1480 Artifacts_In_Object_Dir : Name_List_Index := No_Name_List; 1481 -- List of regexp file names to be cleaned in the object directory of 1482 -- all projects. 1483 end record; 1484 1485 Default_Project_Config : constant Project_Configuration := 1486 (Target => No_Name, 1487 Run_Path_Option => No_Name_List, 1488 Run_Path_Origin => No_Name, 1489 Library_Install_Name_Option => No_Name, 1490 Separate_Run_Path_Options => False, 1491 Executable_Suffix => No_Name, 1492 Linker => No_Path, 1493 Map_File_Option => No_Name, 1494 Trailing_Linker_Required_Switches => 1495 No_Name_List, 1496 Linker_Executable_Option => No_Name_List, 1497 Linker_Lib_Dir_Option => No_Name, 1498 Linker_Lib_Name_Option => No_Name, 1499 Library_Builder => No_Path, 1500 Max_Command_Line_Length => 0, 1501 Resp_File_Format => None, 1502 Resp_File_Options => No_Name_List, 1503 Lib_Support => None, 1504 Lib_Encapsulated_Supported => False, 1505 Archive_Builder => No_Name_List, 1506 Archive_Builder_Append_Option => No_Name_List, 1507 Archive_Indexer => No_Name_List, 1508 Archive_Suffix => No_File, 1509 Object_Lister => No_Name_List, 1510 Object_Lister_Matcher => No_Name, 1511 Export_File_Format => GPR.None, 1512 Export_File_Switch => No_Name, 1513 Lib_Partial_Linker => No_Name_List, 1514 Shared_Lib_Driver => No_File, 1515 Shared_Lib_Prefix => No_File, 1516 Shared_Lib_Suffix => No_File, 1517 Shared_Lib_Min_Options => No_Name_List, 1518 Lib_Version_Options => No_Name_List, 1519 Symbolic_Link_Supported => False, 1520 Lib_Maj_Min_Id_Supported => False, 1521 Auto_Init_Supported => False, 1522 Artifacts_In_Exec_Dir => No_Name_List, 1523 Artifacts_In_Object_Dir => No_Name_List); 1524 1525 ------------------------- 1526 -- Aggregated projects -- 1527 ------------------------- 1528 1529 type Project_Node_Kind is 1530 (N_Project, 1531 N_With_Clause, 1532 N_Project_Declaration, 1533 N_Declarative_Item, 1534 N_Package_Declaration, 1535 N_String_Type_Declaration, 1536 N_Literal_String, 1537 N_Attribute_Declaration, 1538 N_Typed_Variable_Declaration, 1539 N_Variable_Declaration, 1540 N_Expression, 1541 N_Term, 1542 N_Literal_String_List, 1543 N_Variable_Reference, 1544 N_External_Value, 1545 N_Attribute_Reference, 1546 N_Case_Construction, 1547 N_Case_Item, 1548 N_Comment_Zones, 1549 N_Comment); 1550 -- Each node in the tree is of a Project_Node_Kind. For the signification 1551 -- of the fields in each node of Project_Node_Kind, look at package 1552 -- Tree_Private_Part. 1553 1554 subtype Variable_Node_Id is Project_Node_Id; 1555 -- Used to designate a node whose expected kind is one of 1556 -- N_Typed_Variable_Declaration, N_Variable_Declaration or 1557 -- N_Variable_Reference. 1558 1559 subtype Package_Declaration_Id is Project_Node_Id; 1560 -- Used to designate a node whose expected kind is N_Project_Declaration 1561 1562 Packages_Initial : constant := 10; 1563 Packages_Increment : constant := 100; 1564 1565 Package_Node_Low_Bound : constant := 0; 1566 Package_Node_High_Bound : constant := 099_999_999; 1567 1568 type Pkg_Node_Id is 1569 range Package_Node_Low_Bound .. Package_Node_High_Bound; 1570 -- Index type for table Package_Attributes in the body 1571 1572 type Package_Node_Id is record 1573 Value : Pkg_Node_Id := Package_Node_Low_Bound; 1574 end record; 1575 -- Full declaration of self-initialized private type 1576 1577 Empty_Pkg : constant Pkg_Node_Id := Package_Node_Low_Bound; 1578 Empty_Package : constant Package_Node_Id := (Value => Empty_Pkg); 1579 Unknown_Pkg : constant Pkg_Node_Id := Package_Node_High_Bound; 1580 Unknown_Package : constant Package_Node_Id := (Value => Unknown_Pkg); 1581 1582 ------------------------------- 1583 -- Restricted Access Section -- 1584 ------------------------------- 1585 1586 package Tree_Private_Part is 1587 1588 -- This is conceptually in the private part. However, for efficiency, 1589 -- some packages are accessing it directly. 1590 1591 type Project_Node_Record is record 1592 1593 Kind : Project_Node_Kind; 1594 1595 Qualifier : Project_Qualifier := Unspecified; 1596 1597 Location : Source_Ptr := No_Location; 1598 1599 Directory : Path_Name_Type := No_Path; 1600 -- Only for N_Project 1601 1602 Display_Name : Name_Id := No_Name; 1603 -- Only for N_Project 1604 1605 Expr_Kind : Variable_Kind := Undefined; 1606 -- See below for what Project_Node_Kind it is used 1607 1608 Variables : Variable_Node_Id := Empty_Project_Node; 1609 -- First variable in a project or a package 1610 1611 Packages : Package_Declaration_Id := Empty_Project_Node; 1612 -- First package declaration in a project 1613 1614 Pkg_Id : Package_Node_Id := Empty_Package; 1615 -- Only used for N_Package_Declaration 1616 -- 1617 -- The component Pkg_Id is an entry into the table Package_Attributes 1618 -- (in Prj.Attr). It is used to indicate all the attributes of the 1619 -- package with their characteristics. 1620 -- 1621 -- The tables Prj.Attr.Attributes and Prj.Attr.Package_Attributes 1622 -- are built once and for all through a call (from Prj.Initialize) 1623 -- to procedure Prj.Attr.Initialize. It is never modified after that. 1624 1625 Name : Name_Id := No_Name; 1626 -- See below for what Project_Node_Kind it is used 1627 1628 Src_Index : Int := 0; 1629 -- Index of a unit in a multi-unit source. 1630 -- Only for some N_Attribute_Declaration and N_Literal_String. 1631 1632 Path_Name : Path_Name_Type := No_Path; 1633 -- See below for what Project_Node_Kind it is used 1634 1635 Value : Name_Id := No_Name; 1636 -- See below for what Project_Node_Kind it is used 1637 1638 Default : Attribute_Default_Value := Empty_Value; 1639 -- Only used in N_Attribute_Reference 1640 1641 Field1 : Project_Node_Id := Empty_Project_Node; 1642 -- See below the meaning for each Project_Node_Kind 1643 1644 Field2 : Project_Node_Id := Empty_Project_Node; 1645 -- See below the meaning for each Project_Node_Kind 1646 1647 Field3 : Project_Node_Id := Empty_Project_Node; 1648 -- See below the meaning for each Project_Node_Kind 1649 1650 Field4 : Project_Node_Id := Empty_Project_Node; 1651 -- See below the meaning for each Project_Node_Kind 1652 1653 Flag1 : Boolean := False; 1654 -- This flag is significant only for: 1655 -- 1656 -- N_Attribute_Declaration and N_Attribute_Reference 1657 -- Indicates for an associative array attribute, that the 1658 -- index is case insensitive. 1659 -- 1660 -- N_Comment 1661 -- Indicates that the comment is preceded by an empty line. 1662 -- 1663 -- N_Project 1664 -- Indicates that there are comments in the project source that 1665 -- cannot be kept in the tree. 1666 -- 1667 -- N_Project_Declaration 1668 -- Indicates that there are unkept comments in the project. 1669 -- 1670 -- N_With_Clause 1671 -- Indicates that this is not the last with in a with clause. 1672 -- Set for "A", but not for "B" in with "B"; and with "A", "B"; 1673 1674 Flag2 : Boolean := False; 1675 -- This flag is significant only for: 1676 -- 1677 -- N_Project 1678 -- Indicates that the project "extends all" another project. 1679 -- 1680 -- N_Comment 1681 -- Indicates that the comment is followed by an empty line. 1682 -- 1683 -- N_With_Clause 1684 -- Indicates that the originally imported project is an extending 1685 -- all project. 1686 1687 Comments : Project_Node_Id := Empty_Project_Node; 1688 -- For nodes other that N_Comment_Zones or N_Comment, designates the 1689 -- comment zones associated with the node. 1690 -- 1691 -- For N_Comment_Zones, designates the comment after the "end" of 1692 -- the construct. 1693 -- 1694 -- For N_Comment, designates the next comment, if any. 1695 1696 end record; 1697 1698 -- type Project_Node_Kind is 1699 1700 -- (N_Project, 1701 -- -- Name: project name 1702 -- -- Path_Name: project path name 1703 -- -- Expr_Kind: Undefined 1704 -- -- Field1: first with clause 1705 -- -- Field2: project declaration 1706 -- -- Field3: first string type 1707 -- -- Field4: parent project, if any 1708 -- -- Value: extended project path name (if any) 1709 1710 -- N_With_Clause, 1711 -- -- Name: imported project name 1712 -- -- Path_Name: imported project path name 1713 -- -- Expr_Kind: Undefined 1714 -- -- Field1: project node 1715 -- -- Field2: next with clause 1716 -- -- Field3: project node or empty if "limited with" 1717 -- -- Field4: not used 1718 -- -- Value: literal string withed 1719 1720 -- N_Project_Declaration, 1721 -- -- Name: not used 1722 -- -- Path_Name: not used 1723 -- -- Expr_Kind: Undefined 1724 -- -- Field1: first declarative item 1725 -- -- Field2: extended project 1726 -- -- Field3: extending project 1727 -- -- Field4: not used 1728 -- -- Value: not used 1729 1730 -- N_Declarative_Item, 1731 -- -- Name: not used 1732 -- -- Path_Name: not used 1733 -- -- Expr_Kind: Undefined 1734 -- -- Field1: current item node 1735 -- -- Field2: next declarative item 1736 -- -- Field3: not used 1737 -- -- Field4: not used 1738 -- -- Value: not used 1739 1740 -- N_Package_Declaration, 1741 -- -- Name: package name 1742 -- -- Path_Name: not used 1743 -- -- Expr_Kind: Undefined 1744 -- -- Field1: project of renamed package (if any) 1745 -- -- Field2: first declarative item 1746 -- -- Field3: next package in project 1747 -- -- Field4: not used 1748 -- -- Value: not used 1749 1750 -- N_String_Type_Declaration, 1751 -- -- Name: type name 1752 -- -- Path_Name: not used 1753 -- -- Expr_Kind: Undefined 1754 -- -- Field1: first literal string 1755 -- -- Field2: next string type 1756 -- -- Field3: project node 1757 -- -- Field4: not used 1758 -- -- Value: not used 1759 1760 -- N_Literal_String, 1761 -- -- Name: not used 1762 -- -- Path_Name: not used 1763 -- -- Expr_Kind: Single 1764 -- -- Field1: next literal string 1765 -- -- Field2: not used 1766 -- -- Field3: not used 1767 -- -- Field4: not used 1768 -- -- Value: string value 1769 1770 -- N_Attribute_Declaration, 1771 -- -- Name: attribute name 1772 -- -- Path_Name: not used 1773 -- -- Expr_Kind: attribute kind 1774 -- -- Field1: expression 1775 -- -- Field2: project of full associative array 1776 -- -- Field3: package of full associative array 1777 -- -- Field4: not used 1778 -- -- Value: associative array index 1779 -- -- (if an associative array element) 1780 1781 -- N_Typed_Variable_Declaration, 1782 -- -- Name: variable name 1783 -- -- Path_Name: not used 1784 -- -- Expr_Kind: Single 1785 -- -- Field1: expression 1786 -- -- Field2: type of variable (N_String_Type_Declaration) 1787 -- -- Field3: next variable 1788 -- -- Field4: project node 1789 -- -- Value: not used 1790 1791 -- N_Variable_Declaration, 1792 -- -- Name: variable name 1793 -- -- Path_Name: not used 1794 -- -- Expr_Kind: variable kind 1795 -- -- Field1: expression 1796 -- -- Field2: not used 1797 -- -- Field3 is used for next variable, instead of Field2, 1798 -- -- so that it is the same field for 1799 -- -- N_Variable_Declaration and 1800 -- -- N_Typed_Variable_Declaration 1801 -- -- Field3: next variable 1802 -- -- Field4: not used 1803 -- -- Value: not used 1804 1805 -- N_Expression, 1806 -- -- Name: not used 1807 -- -- Path_Name: not used 1808 -- -- Expr_Kind: expression kind 1809 -- -- Field1: first term 1810 -- -- Field2: next expression in list 1811 -- -- Field3: not used 1812 -- -- Value: not used 1813 1814 -- N_Term, 1815 -- -- Name: not used 1816 -- -- Path_Name: not used 1817 -- -- Expr_Kind: term kind 1818 -- -- Field1: current term 1819 -- -- Field2: next term in the expression 1820 -- -- Field3: not used 1821 -- -- Field4: not used 1822 -- -- Value: not used 1823 1824 -- N_Literal_String_List, 1825 -- -- Designates a list of string expressions between brackets 1826 -- -- separated by commas. The string expressions are not necessarily 1827 -- -- literal strings. 1828 -- -- Name: not used 1829 -- -- Path_Name: not used 1830 -- -- Expr_Kind: List 1831 -- -- Field1: first expression 1832 -- -- Field2: not used 1833 -- -- Field3: not used 1834 -- -- Field4: not used 1835 -- -- Value: not used 1836 1837 -- N_Variable_Reference, 1838 -- -- Name: variable name 1839 -- -- Path_Name: not used 1840 -- -- Expr_Kind: variable kind 1841 -- -- Field1: project (if specified) 1842 -- -- Field2: package (if specified) 1843 -- -- Field3: type of variable (N_String_Type_Declaration), if any 1844 -- -- Field4: not used 1845 -- -- Value: not used 1846 1847 -- N_External_Value, 1848 -- -- Name: not used 1849 -- -- Path_Name: not used 1850 -- -- Expr_Kind: Single 1851 -- -- Field1: Name of the external reference (literal string) 1852 -- -- Field2: Default (literal string) 1853 -- -- Field3: not used 1854 -- -- Value: not used 1855 1856 -- N_Attribute_Reference, 1857 -- -- Name: attribute name 1858 -- -- Path_Name: not used 1859 -- -- Expr_Kind: attribute kind 1860 -- -- Field1: project 1861 -- -- Field2: package (if attribute of a package) 1862 -- -- Field3: not used 1863 -- -- Field4: not used 1864 -- -- Value: associative array index 1865 -- -- (if an associative array element) 1866 1867 -- N_Case_Construction, 1868 -- -- Name: not used 1869 -- -- Path_Name: not used 1870 -- -- Expr_Kind: Undefined 1871 -- -- Field1: case variable reference 1872 -- -- Field2: first case item 1873 -- -- Field3: not used 1874 -- -- Field4: not used 1875 -- -- Value: not used 1876 1877 -- N_Case_Item 1878 -- -- Name: not used 1879 -- -- Path_Name: not used 1880 -- -- Expr_Kind: not used 1881 -- -- Field1: first choice (literal string), or Empty_Node 1882 -- -- for when others 1883 -- -- Field2: first declarative item 1884 -- -- Field3: next case item 1885 -- -- Field4: not used 1886 -- -- Value: not used 1887 1888 -- N_Comment_zones 1889 -- -- Name: not used 1890 -- -- Path_Name: not used 1891 -- -- Expr_Kind: not used 1892 -- -- Field1: comment before the construct 1893 -- -- Field2: comment after the construct 1894 -- -- Field3: comment before the "end" of the construct 1895 -- -- Value: end of line comment 1896 -- -- Field4: not used 1897 -- -- Comments: comment after the "end" of the construct 1898 1899 -- N_Comment 1900 -- -- Name: not used 1901 -- -- Path_Name: not used 1902 -- -- Expr_Kind: not used 1903 -- -- Field1: not used 1904 -- -- Field2: not used 1905 -- -- Field3: not used 1906 -- -- Field4: not used 1907 -- -- Value: comment 1908 -- -- Flag1: comment is preceded by an empty line 1909 -- -- Flag2: comment is followed by an empty line 1910 -- -- Comments: next comment 1911 1912 package Project_Node_Table is new 1913 GNAT.Dynamic_Tables 1914 (Table_Component_Type => Project_Node_Record, 1915 Table_Index_Type => Project_Node_Id, 1916 Table_Low_Bound => First_Project_Node_Id, 1917 Table_Initial => Project_Nodes_Initial, 1918 Table_Increment => Project_Nodes_Increment); 1919 -- Table contains the syntactic tree of project data from project files 1920 1921 type Project_Name_And_Node is record 1922 Name : Name_Id; 1923 -- Name of the project 1924 1925 Node : Project_Node_Id; 1926 -- Node of the project in table Project_Nodes 1927 1928 Resolved_Path : Path_Name_Type; 1929 -- Resolved and canonical path of a real project file. 1930 -- No_Name in case of virtual projects. 1931 1932 Extended : Boolean; 1933 -- True when the project is being extended by another project 1934 1935 From_Extended : Boolean; 1936 -- True when the project is only imported by projects that are 1937 -- extended. 1938 1939 Proj_Qualifier : Project_Qualifier; 1940 -- The project qualifier of the project, if any 1941 end record; 1942 1943 No_Project_Name_And_Node : constant Project_Name_And_Node := 1944 (Name => No_Name, 1945 Node => Empty_Project_Node, 1946 Resolved_Path => No_Path, 1947 Extended => True, 1948 From_Extended => False, 1949 Proj_Qualifier => Unspecified); 1950 1951 package Projects_Htable is new GNAT.Dynamic_HTables.Simple_HTable 1952 (Header_Num => Header_Num, 1953 Element => Project_Name_And_Node, 1954 No_Element => No_Project_Name_And_Node, 1955 Key => Name_Id, 1956 Hash => Hash, 1957 Equal => "="); 1958 -- This hash table contains a mapping of project names to project nodes. 1959 -- Note that this hash table contains only the nodes whose Kind is 1960 -- N_Project. It is used to find the node of a project from its name, 1961 -- and to verify if a project has already been parsed, knowing its name. 1962 1963 end Tree_Private_Part; 1964 1965 type Project_Node_Tree_Data is record 1966 Project_Nodes : Tree_Private_Part.Project_Node_Table.Instance; 1967 Projects_HT : Tree_Private_Part.Projects_Htable.Instance; 1968 1969 Incomplete_With : Boolean := False; 1970 -- Set to True if the projects were loaded with the flag 1971 -- Ignore_Missing_With set to True, and there were indeed some with 1972 -- statements that could not be resolved 1973 end record; 1974 1975 type Project_Node_Tree_Ref is access all Project_Node_Tree_Data; 1976 -- Type to designate a project node tree, so that several project node 1977 -- trees can coexist in memory. 1978 1979 procedure Free (Proj : in out Project_Node_Tree_Ref); 1980 -- Free memory used by Prj 1981 1982 type Aggregated_Project; 1983 type Aggregated_Project_List is access all Aggregated_Project; 1984 type Aggregated_Project is record 1985 Path : Path_Name_Type; 1986 Tree : Project_Tree_Ref; 1987 Node_Tree : Project_Node_Tree_Ref; 1988 Project : Project_Id; 1989 Next : Aggregated_Project_List; 1990 end record; 1991 1992 procedure Free (List : in out Aggregated_Project_List); 1993 -- Free the memory used for List 1994 1995 procedure Add_Aggregated_Project 1996 (Project : Project_Id; 1997 Path : Path_Name_Type); 1998 -- Add a new aggregated project in Project. 1999 -- The aggregated project has not been processed yet. This procedure should 2000 -- the called while processing the aggregate project, and as a result 2001 -- Prj.Proc.Process will then automatically process the aggregated projects 2002 2003 ------------------ 2004 -- Project_Data -- 2005 ------------------ 2006 2007 -- The following record describes a project file representation 2008 2009 pragma Warnings (Off); 2010 type Standalone is 2011 (No, 2012 2013 -- The following clash with Standard is OK, and justified by the context 2014 -- which really wants to use the same set of qualifiers. 2015 2016 Standard, 2017 2018 Encapsulated); 2019 pragma Warnings (On); 2020 2021 type Project_Data (Qualifier : Project_Qualifier := Unspecified) is record 2022 2023 ------------- 2024 -- General -- 2025 ------------- 2026 2027 Name : Name_Id := No_Name; 2028 -- The name of the project 2029 2030 Display_Name : Name_Id := No_Name; 2031 -- The name of the project with the spelling of its declaration 2032 2033 Externally_Built : Boolean := False; 2034 -- True if the project is externally built. In such case, the Project 2035 -- Manager will not modify anything in this project. 2036 2037 Config : Project_Configuration; 2038 2039 Path : Path_Information := No_Path_Information; 2040 -- The path name of the project file. This include base name of the 2041 -- project file. 2042 2043 Virtual : Boolean := False; 2044 -- True for virtual extending projects 2045 2046 Location : Source_Ptr := No_Location; 2047 -- The location in the project file source of the project name that 2048 -- immediately follows the reserved word "project". 2049 2050 --------------- 2051 -- Languages -- 2052 --------------- 2053 2054 Languages : Language_Ptr := No_Language_Index; 2055 -- First index of the language data in the project. Traversing the list 2056 -- gives access to all the languages supported by the project. 2057 2058 -------------- 2059 -- Projects -- 2060 -------------- 2061 2062 Mains : String_List_Id := Nil_String; 2063 -- List of mains specified by attribute Main 2064 2065 Extends : Project_Id := No_Project; 2066 -- The reference of the project file, if any, that this project file 2067 -- extends. 2068 2069 Extended_By : Project_Id := No_Project; 2070 -- The reference of the project file, if any, that extends this project 2071 -- file. 2072 2073 Decl : Declarations := No_Declarations; 2074 -- The declarations (variables, attributes and packages) of this project 2075 -- file. 2076 2077 Imported_Projects : Project_List := null; 2078 -- The list of all directly imported projects, if any 2079 2080 All_Imported_Projects : Project_List := null; 2081 -- The list of all projects imported directly or indirectly, if any. 2082 -- This does not include the project itself. 2083 2084 ----------------- 2085 -- Directories -- 2086 ----------------- 2087 2088 Directory : Path_Information := No_Path_Information; 2089 -- Path name of the directory where the project file resides 2090 2091 Object_Directory : Path_Information := No_Path_Information; 2092 -- The path name of the object directory of this project file 2093 2094 Exec_Directory : Path_Information := No_Path_Information; 2095 -- The path name of the exec directory of this project file. Default is 2096 -- equal to Object_Directory. 2097 2098 Object_Path_File : Path_Name_Type := No_Path; 2099 -- Store the name of the temporary file that contains the list of object 2100 -- directories, when attribute Object_Path_Switches is declared. 2101 2102 ------------- 2103 -- Library -- 2104 ------------- 2105 2106 Library : Boolean := False; 2107 -- True if this is a library project 2108 2109 Library_Name : Name_Id := No_Name; 2110 -- If a library project, name of the library 2111 2112 Library_Kind : Lib_Kind := Static; 2113 -- If a library project, kind of library 2114 2115 Library_Dir : Path_Information := No_Path_Information; 2116 -- If a library project, path name of the directory where the library 2117 -- resides. 2118 2119 Library_TS : Time_Stamp_Type := Empty_Time_Stamp; 2120 -- The timestamp of a library file in a library project 2121 2122 Library_Src_Dir : Path_Information := No_Path_Information; 2123 -- If a Stand-Alone Library project, path name of the directory where 2124 -- the sources of the interfaces of the library are copied. By default, 2125 -- if attribute Library_Src_Dir is not specified, sources of the 2126 -- interfaces are not copied anywhere. 2127 2128 Library_ALI_Dir : Path_Information := No_Path_Information; 2129 -- In a library project, path name of the directory where the ALI files 2130 -- are copied. If attribute Library_ALI_Dir is not specified, ALI files 2131 -- are copied in the Library_Dir. 2132 2133 Lib_Internal_Name : Name_Id := No_Name; 2134 -- If a library project, internal name store inside the library 2135 2136 Standalone_Library : Standalone := No; 2137 -- Indicate that this is a Standalone Library Project File 2138 2139 Lib_Interface_ALIs : String_List_Id := Nil_String; 2140 -- For Standalone Library Project Files, list of Interface ALI files 2141 2142 Other_Interfaces : String_List_Id := Nil_String; 2143 -- List of non unit based sources in attribute Interfaces 2144 2145 Lib_Auto_Init : Boolean := False; 2146 -- For non static Stand-Alone Library Project Files, True if the library 2147 -- initialisation should be automatic. 2148 2149 Symbol_Data : Symbol_Record := No_Symbols; 2150 -- Symbol file name, reference symbol file name, symbol policy 2151 2152 Need_To_Build_Lib : Boolean := False; 2153 -- True if the library of a Library Project needs to be built or rebuilt 2154 2155 ------------- 2156 -- Sources -- 2157 ------------- 2158 -- The sources for all languages including Ada are accessible through 2159 -- the Source_Iterator type 2160 2161 Interfaces_Defined : Boolean := False; 2162 -- True if attribute Interfaces is declared for the project or any 2163 -- project it extends. 2164 2165 Include_Path_File : Path_Name_Type := No_Path; 2166 -- The path name of the of the source search directory file. 2167 -- This is only used by gnatmake 2168 2169 Source_Dirs : String_List_Id := Nil_String; 2170 -- The list of all the source directories 2171 2172 Source_Dir_Ranks : Number_List_Index := No_Number_List; 2173 2174 Ada_Include_Path : String_Access := null; 2175 -- The cached value of source search path for this project file. Set by 2176 -- the first call to Prj.Env.Ada_Include_Path for the project. Do not 2177 -- use this field directly outside of the project manager, use 2178 -- Prj.Env.Ada_Include_Path instead. 2179 2180 Has_Multi_Unit_Sources : Boolean := False; 2181 -- Whether there is at least one source file containing multiple units 2182 2183 ------------------- 2184 -- Miscellaneous -- 2185 ------------------- 2186 2187 Ada_Objects_Path : String_Access := null; 2188 -- The cached value of ADA_OBJECTS_PATH for this project file, with 2189 -- library ALI directories for library projects instead of object 2190 -- directories. Do not use this field directly outside of the 2191 -- compiler, use Prj.Env.Ada_Objects_Path instead. 2192 2193 Ada_Objects_Path_No_Libs : String_Access := null; 2194 -- The cached value of ADA_OBJECTS_PATH for this project file with all 2195 -- object directories (no library ALI dir for library projects). 2196 2197 Libgnarl_Needed : Yes_No_Unknown := Unknown; 2198 -- Set to True when libgnarl is needed to link 2199 2200 Objects_Path : String_Access := null; 2201 -- The cached value of the object dir path, used during the binding 2202 -- phase of gprbuild. 2203 2204 Objects_Path_File_With_Libs : Path_Name_Type := No_Path; 2205 -- The cached value of the object path temp file (including library 2206 -- dirs) for this project file. 2207 2208 Objects_Path_File_Without_Libs : Path_Name_Type := No_Path; 2209 -- The cached value of the object path temp file (excluding library 2210 -- dirs) for this project file. 2211 2212 Config_File_Name : Path_Name_Type := No_Path; 2213 -- The path name of the configuration pragmas file, if any 2214 2215 Config_File_Temp : Boolean := False; 2216 -- True if the configuration pragmas file is a temporary file that must 2217 -- be deleted at the end. 2218 2219 Config_Checked : Boolean := False; 2220 -- A flag to avoid checking repetitively the configuration pragmas file 2221 2222 Depth : Natural := 0; 2223 -- The maximum depth of a project in the project graph. Depth of main 2224 -- project is 0. 2225 2226 Unkept_Comments : Boolean := False; 2227 -- True if there are comments in the project sources that cannot be kept 2228 -- in the project tree. 2229 2230 ----------------------------- 2231 -- Qualifier-Specific data -- 2232 ----------------------------- 2233 2234 -- The following fields are only valid for specific types of projects 2235 2236 case Qualifier is 2237 when Aggregate | Aggregate_Library => 2238 Aggregated_Projects : Aggregated_Project_List := null; 2239 -- List of aggregated projects (which could themselves be 2240 -- aggregate projects). 2241 2242 when others => 2243 null; 2244 end case; 2245 end record; 2246 2247 function Empty_Project (Qualifier : Project_Qualifier) return Project_Data; 2248 -- Return the representation of an empty project 2249 2250 function Is_Extending 2251 (Extending : Project_Id; 2252 Extended : Project_Id) return Boolean; 2253 -- Return True if Extending is extending the Extended project 2254 2255 function Is_Ext 2256 (Extending : Project_Id; 2257 Extended : Project_Id) return Boolean renames Is_Extending; 2258 2259 function Has_Ada_Sources (Data : Project_Id) return Boolean; 2260 -- Return True if the project has Ada sources 2261 2262 Project_Error : exception; 2263 -- Raised by some subprograms in Prj.Attr 2264 2265 package Units_Htable is new Simple_HTable 2266 (Header_Num => Header_Num, 2267 Element => Unit_Index, 2268 No_Element => No_Unit_Index, 2269 Key => Name_Id, 2270 Hash => Hash, 2271 Equal => "="); 2272 -- Mapping of unit names to indexes in the Units table 2273 2274 --------------------- 2275 -- Source_Iterator -- 2276 --------------------- 2277 2278 type Source_Iterator is private; 2279 2280 function For_Each_Source 2281 (In_Tree : Project_Tree_Ref; 2282 Project : Project_Id := No_Project; 2283 Language : Name_Id := No_Name; 2284 Encapsulated_Libs : Boolean := True; 2285 Locally_Removed : Boolean := True) return Source_Iterator; 2286 -- Returns an iterator for all the sources of a project tree, or a specific 2287 -- project, or a specific language. Include sources from aggregated libs if 2288 -- Aggregated_Libs is True. If Locally_Removed is set to False the 2289 -- Locally_Removed files won't be reported. 2290 2291 function Element (Iter : Source_Iterator) return Source_Id; 2292 -- Return the current source (or No_Source if there are no more sources) 2293 2294 procedure Next (Iter : in out Source_Iterator); 2295 -- Move on to the next source 2296 2297 function Find_Source 2298 (In_Tree : Project_Tree_Ref; 2299 Project : Project_Id; 2300 In_Imported_Only : Boolean := False; 2301 In_Extended_Only : Boolean := False; 2302 Base_Name : File_Name_Type; 2303 Index : Int := 0) return Source_Id; 2304 -- Find the first source file with the given name. 2305 -- If In_Extended_Only is True, it will search in project and the project 2306 -- it extends, but not in the imported projects. 2307 -- Elsif In_Imported_Only is True, it will search in project and the 2308 -- projects it imports, but not in the others or in aggregated projects. 2309 -- Else it searches in the whole tree. 2310 -- If Index is specified, this only search for a source with that index. 2311 2312 type Source_Ids is array (Positive range <>) of Source_Id; 2313 No_Sources : constant Source_Ids := (1 .. 0 => No_Source); 2314 2315 function Find_All_Sources 2316 (In_Tree : Project_Tree_Ref; 2317 Project : Project_Id; 2318 In_Imported_Only : Boolean := False; 2319 In_Extended_Only : Boolean := False; 2320 Base_Name : File_Name_Type; 2321 Index : Int := 0) return Source_Ids; 2322 -- Find all source files with the given name: 2323 -- 2324 -- If In_Extended_Only is True, it will search in project and the project 2325 -- it extends, but not in the imported projects. 2326 -- 2327 -- If Extended_Only is False, and In_Imported_Only is True, it will 2328 -- search in project and the projects it imports, but not in the others 2329 -- or in aggregated projects. 2330 -- 2331 -- If both Extended_Only and In_Imported_Only are False (the default) 2332 -- then it searches the whole tree. 2333 -- 2334 -- If Index is specified, this only search for sources with that index. 2335 2336 ----------------------- 2337 -- Project_Tree_Data -- 2338 ----------------------- 2339 2340 package Replaced_Source_HTable is new Simple_HTable 2341 (Header_Num => Header_Num, 2342 Element => File_Name_Type, 2343 No_Element => No_File, 2344 Key => File_Name_Type, 2345 Hash => Hash, 2346 Equal => "="); 2347 2348 type Private_Project_Tree_Data is private; 2349 -- Data for a project tree that is used only by the Project Manager 2350 2351 type Shared_Project_Tree_Data is record 2352 Name_Lists : Name_List_Table.Instance; 2353 Number_Lists : Number_List_Table.Instance; 2354 String_Elements : String_Element_Table.Instance; 2355 Variable_Elements : Variable_Element_Table.Instance; 2356 Array_Elements : Array_Element_Table.Instance; 2357 Arrays : Array_Table.Instance; 2358 Packages : Package_Table.Instance; 2359 Private_Part : Private_Project_Tree_Data; 2360 Dot_String_List : String_List_Id := Nil_String; 2361 end record; 2362 type Shared_Project_Tree_Data_Access is access all Shared_Project_Tree_Data; 2363 -- The data that is shared among multiple trees, when these trees are 2364 -- loaded through the same aggregate project. 2365 -- To avoid ambiguities, limit the number of parameters to the 2366 -- subprograms (we would have to parse the "root project tree" since this 2367 -- is where the configuration file was loaded, in addition to the project's 2368 -- own tree) and make the comparison of projects easier, all trees store 2369 -- the lists in the same tables. 2370 2371 type Project_Tree_Appdata is tagged null record; 2372 type Project_Tree_Appdata_Access is access all Project_Tree_Appdata'Class; 2373 -- Application-specific data that can be associated with a project tree. 2374 -- We do not make the Project_Tree_Data itself tagged for several reasons: 2375 -- - it couldn't have a default value for its discriminant 2376 -- - it would require a "factory" to allocate such data, because trees 2377 -- are created automatically when parsing aggregate projects. 2378 2379 procedure Free (Tree : in out Project_Tree_Appdata); 2380 -- Should be overridden if your derive your own data 2381 2382 type Project_Tree_Data (Is_Root_Tree : Boolean := True) is record 2383 -- The root tree is the one loaded by the user from the command line. 2384 -- Is_Root_Tree is only false for projects aggregated within a root 2385 -- aggregate project. 2386 2387 Projects : Project_List; 2388 -- List of projects in this tree 2389 2390 Replaced_Sources : Replaced_Source_HTable.Instance; 2391 -- The list of sources that have been replaced by sources with 2392 -- different file names. 2393 2394 Replaced_Source_Number : Natural := 0; 2395 -- The number of entries in Replaced_Sources 2396 2397 Units_HT : Units_Htable.Instance; 2398 -- Unit name to Unit_Index (and from there to Source_Id) 2399 2400 Source_Files_HT : Source_Files_Htable.Instance; 2401 -- Base source file names to Source_Id list 2402 2403 Source_Paths_HT : Source_Paths_Htable.Instance; 2404 -- Full path to Source_Id 2405 -- ??? What is behavior for multi-unit source files, where there are 2406 -- several source_id per file ? 2407 2408 Source_Info_File_Name : String_Access := null; 2409 -- The name of the source info file, if specified by the builder 2410 2411 Source_Info_File_Exists : Boolean := False; 2412 -- True when a source info file has been successfully read 2413 2414 Shared : Shared_Project_Tree_Data_Access; 2415 -- The shared data for this tree and all aggregated trees 2416 2417 Appdata : Project_Tree_Appdata_Access; 2418 -- Application-specific data for this tree 2419 2420 Added_Projects : Added_Ptr; 2421 2422 case Is_Root_Tree is 2423 when True => 2424 Shared_Data : aliased Shared_Project_Tree_Data; 2425 -- Do not access directly, only through Shared 2426 2427 when False => 2428 null; 2429 end case; 2430 end record; 2431 -- Data for a project tree 2432 2433 function Debug_Name (Tree : Project_Tree_Ref) return Name_Id; 2434 -- If debug traces are activated, return an identitier for the project 2435 -- tree. This modifies Name_Buffer. 2436 2437 procedure Initialize (Tree : Project_Tree_Ref); 2438 -- This procedure must be called before using any services from the Prj 2439 -- hierarchy. Namet.Initialize must be called before Prj.Initialize. 2440 2441 procedure Reset (Tree : Project_Tree_Ref); 2442 -- This procedure resets all the tables that are used when processing a 2443 -- project file tree. Initialize must be called before the call to Reset. 2444 2445 package Project_Boolean_Htable is new Simple_HTable 2446 (Header_Num => Header_Num, 2447 Element => Boolean, 2448 No_Element => False, 2449 Key => Project_Id, 2450 Hash => Hash, 2451 Equal => "="); 2452 -- A table that associates a project to a boolean. This is used to detect 2453 -- whether a project was already processed for instance. 2454 2455 generic 2456 with procedure Action (Project : Project_Id; Tree : Project_Tree_Ref); 2457 procedure For_Project_And_Aggregated 2458 (Root_Project : Project_Id; 2459 Root_Tree : Project_Tree_Ref); 2460 -- Execute Action for Root_Project and all its aggregated projects 2461 -- recursively. 2462 2463 generic 2464 type State is limited private; 2465 with procedure Action 2466 (Project : Project_Id; 2467 Tree : Project_Tree_Ref; 2468 With_State : in out State); 2469 procedure For_Every_Project_Imported 2470 (By : Project_Id; 2471 Tree : Project_Tree_Ref; 2472 With_State : in out State; 2473 Include_Aggregated : Boolean := True; 2474 Imported_First : Boolean := False); 2475 -- Call Action for each project imported directly or indirectly by project 2476 -- By, as well as extended projects. 2477 -- 2478 -- The order of processing depends on Imported_First: 2479 -- 2480 -- If False, Action is called according to the order of importation: if A 2481 -- imports B, directly or indirectly, Action will be called for A before 2482 -- it is called for B. If two projects import each other directly or 2483 -- indirectly (using at least one "limited with"), it is not specified 2484 -- for which of these two projects Action will be called first. 2485 -- 2486 -- The order is reversed if Imported_First is True 2487 -- 2488 -- With_State may be used by Action to choose a behavior or to report some 2489 -- global result. 2490 -- 2491 -- If Include_Aggregated is True, then an aggregate project will recurse 2492 -- into the projects it aggregates. Otherwise, the latter are never 2493 -- returned. 2494 -- 2495 -- In_Aggregate_Lib is True if the project is in an aggregate library 2496 -- 2497 -- The Tree argument passed to the callback is required in the case of 2498 -- aggregated projects, since they might not be using the same tree as 'By' 2499 2500 type Project_Context is record 2501 In_Aggregate_Lib : Boolean; 2502 -- True if the project is part of an aggregate library 2503 2504 From_Encapsulated_Lib : Boolean; 2505 -- True if the project is imported from an encapsulated library 2506 end record; 2507 2508 generic 2509 type State is limited private; 2510 with procedure Action 2511 (Project : Project_Id; 2512 Tree : Project_Tree_Ref; 2513 Context : Project_Context; 2514 With_State : in out State); 2515 procedure For_Every_Project_Imported_Context 2516 (By : Project_Id; 2517 Tree : Project_Tree_Ref; 2518 With_State : in out State; 2519 Include_Aggregated : Boolean := True; 2520 Imported_First : Boolean := False); 2521 -- As for For_Every_Project_Imported but with an associated context 2522 2523 generic 2524 with procedure Action 2525 (Project : Project_Id; 2526 Tree : Project_Tree_Ref; 2527 Context : Project_Context); 2528 procedure For_Project_And_Aggregated_Context 2529 (Root_Project : Project_Id; 2530 Root_Tree : Project_Tree_Ref); 2531 -- As for For_Project_And_Aggregated but with an associated context 2532 2533 function Extend_Name 2534 (File : File_Name_Type; 2535 With_Suffix : String) return File_Name_Type; 2536 -- Replace the extension of File with With_Suffix 2537 2538 function Object_Name 2539 (Source_File_Name : File_Name_Type; 2540 Object_File_Suffix : Name_Id := No_Name) return File_Name_Type; 2541 -- Returns the object file name corresponding to a source file name 2542 2543 function Object_Name 2544 (Source_File_Name : File_Name_Type; 2545 Source_Index : Int; 2546 Index_Separator : Character; 2547 Object_File_Suffix : Name_Id := No_Name) return File_Name_Type; 2548 -- Returns the object file name corresponding to a unit in a multi-source 2549 -- file. 2550 2551 function Dependency_Name 2552 (Source_File_Name : File_Name_Type; 2553 Dependency : Dependency_File_Kind) return File_Name_Type; 2554 -- Returns the dependency file name corresponding to a source file name 2555 2556 function Switches_Name 2557 (Source_File_Name : File_Name_Type) return File_Name_Type; 2558 -- Returns the switches file name corresponding to a source file name 2559 2560 procedure Set_Path_File_Var (Name : String; Value : String); 2561 -- Call Setenv, after calling To_Host_File_Spec 2562 2563 function Current_Source_Path_File_Of 2564 (Shared : Shared_Project_Tree_Data_Access) return Path_Name_Type; 2565 -- Get the current include path file name 2566 2567 procedure Set_Current_Source_Path_File_Of 2568 (Shared : Shared_Project_Tree_Data_Access; 2569 To : Path_Name_Type); 2570 -- Record the current include path file name 2571 2572 function Current_Object_Path_File_Of 2573 (Shared : Shared_Project_Tree_Data_Access) return Path_Name_Type; 2574 -- Get the current object path file name 2575 2576 procedure Set_Current_Object_Path_File_Of 2577 (Shared : Shared_Project_Tree_Data_Access; 2578 To : Path_Name_Type); 2579 -- Record the current object path file name 2580 2581 ----------- 2582 -- Flags -- 2583 ----------- 2584 2585 type Processing_Flags is private; 2586 -- Flags used while parsing and processing a project tree to configure the 2587 -- behavior of the parser, and indicate how to report error messages. This 2588 -- structure does not allocate memory and never needs to be freed 2589 2590 type Error_Warning is (Silent, Warning, Error); 2591 -- Severity of some situations, such as: no Ada sources in a project where 2592 -- Ada is one of the language. 2593 -- 2594 -- When the situation occurs, the behaviour depends on the setting: 2595 -- 2596 -- - Silent: no action 2597 -- - Warning: issue a warning, does not cause the tool to fail 2598 -- - Error: issue an error, causes the tool to fail 2599 2600 type Error_Handler is access procedure 2601 (Project : Project_Id; 2602 Is_Warning : Boolean); 2603 -- This warns when an error was found when parsing a project. The error 2604 -- itself is handled through Prj.Err (and Prj.Err.Finalize should be called 2605 -- to actually print the error). This ensures that duplicate error messages 2606 -- are always correctly removed, that errors msgs are sorted, and that all 2607 -- tools will report the same error to the user. 2608 2609 function Create_Flags 2610 (Report_Error : Error_Handler; 2611 When_No_Sources : Error_Warning; 2612 Require_Sources_Other_Lang : Boolean := True; 2613 Allow_Duplicate_Basenames : Boolean := True; 2614 Compiler_Driver_Mandatory : Boolean := False; 2615 Error_On_Unknown_Language : Boolean := True; 2616 Require_Obj_Dirs : Error_Warning := Error; 2617 Allow_Invalid_External : Error_Warning := Error; 2618 Missing_Source_Files : Error_Warning := Error; 2619 Ignore_Missing_With : Boolean := False; 2620 Check_Configuration_Only : Boolean := False) 2621 return Processing_Flags; 2622 -- Function used to create Processing_Flags structure 2623 -- 2624 -- If Allow_Duplicate_Basenames, then files with the same base names are 2625 -- authorized within a project for source-based languages (never for unit 2626 -- based languages). 2627 -- 2628 -- If Compiler_Driver_Mandatory is true, then a Compiler.Driver attribute 2629 -- for each language must be defined, or we will not look for its source 2630 -- files. 2631 -- 2632 -- When_No_Sources indicates what should be done when no sources of a 2633 -- language are found in a project where this language is declared. 2634 -- If Require_Sources_Other_Lang is true, then all languages must have at 2635 -- least one source file, or an error is reported via When_No_Sources. If 2636 -- it is false, this is only required for Ada (and only if it is a language 2637 -- of the project). When this parameter is set to False, we do not check 2638 -- that a proper naming scheme is defined for languages other than Ada. 2639 -- 2640 -- If Report_Error is null, use the standard error reporting mechanism 2641 -- (Errout). Otherwise, report errors using Report_Error. 2642 -- 2643 -- If Error_On_Unknown_Language is true, an error is displayed if some of 2644 -- the source files listed in the project do not match any naming scheme 2645 -- 2646 -- If Require_Obj_Dirs is true, then all object directories must exist 2647 -- (possibly after they have been created automatically if the appropriate 2648 -- switches were specified), or an error is raised. 2649 -- 2650 -- If Allow_Invalid_External is Silent, then no error is reported when an 2651 -- invalid value is used for an external variable (and it doesn't match its 2652 -- type). Instead, the first possible value is used. 2653 -- 2654 -- Missing_Source_Files indicates whether it is an error or a warning that 2655 -- a source file mentioned in the Source_Files attributes is not actually 2656 -- found in the source directories. This also impacts errors for missing 2657 -- source directories. 2658 -- 2659 -- If Ignore_Missing_With is True, then a "with" statement that cannot be 2660 -- resolved will simply be ignored. However, in such a case, the flag 2661 -- Incomplete_With in the project tree will be set to True. 2662 -- This is meant for use by tools so that they can properly set the 2663 -- project path in such a case: 2664 -- * no "gnatls" found (so no default project path) 2665 -- * user project sets Project.IDE'gnatls attribute to a cross gnatls 2666 -- * user project also includes a "with" that can only be resolved 2667 -- once we have found the gnatls 2668 2669 procedure Set_Ignore_Missing_With 2670 (Flags : in out Processing_Flags; 2671 Value : Boolean); 2672 -- Set the value of component Ignore_Missing_With in Flags to Value 2673 2674 Gprbuild_Flags : constant Processing_Flags; 2675 Gprinstall_Flags : constant Processing_Flags; 2676 Gprclean_Flags : constant Processing_Flags; 2677 Gprname_Flags : constant Processing_Flags; 2678 Gprls_Flags : constant Processing_Flags; 2679 -- Flags used by the various tools. They all display the error messages 2680 -- through Prj.Err. 2681 2682 ---------------- 2683 -- Temp Files -- 2684 ---------------- 2685 2686 procedure Record_Temp_File 2687 (Shared : Shared_Project_Tree_Data_Access; 2688 Path : Path_Name_Type); 2689 -- Record the path of a newly created temporary file, so that it can be 2690 -- deleted later. 2691 2692 procedure Delete_All_Temp_Files 2693 (Shared : Shared_Project_Tree_Data_Access); 2694 -- Delete all recorded temporary files. 2695 -- Does nothing if Debug.Debug_Flag_N is set 2696 2697 procedure Delete_Temporary_File 2698 (Shared : Shared_Project_Tree_Data_Access := null; 2699 Path : Path_Name_Type); 2700 -- Delete a temporary file from the disk. The file is also removed from the 2701 -- list of temporary files to delete at the end of the program, in case 2702 -- another program running on the same machine has recreated it. Does 2703 -- nothing if Debug.Debug_Flag_N is set 2704 2705 Virtual_Prefix : constant String := "v$"; 2706 -- The prefix for virtual extending projects. Because of the '$', which is 2707 -- normally forbidden for project names, there cannot be any name clash. 2708 2709 ----------- 2710 -- Debug -- 2711 ----------- 2712 2713 type Verbosity is (Default, Medium, High); 2714 pragma Ordered (Verbosity); 2715 -- Verbosity when parsing GNAT Project Files 2716 -- Default is default (very quiet, if no errors). 2717 -- Medium is more verbose. 2718 -- High is extremely verbose. 2719 2720 Current_Verbosity : Verbosity := Default; 2721 -- The current value of the verbosity the project files are parsed with 2722 2723 procedure Debug_Indent; 2724 -- Inserts a series of blanks depending on the current indentation level 2725 2726 procedure Debug_Output (Str : String); 2727 procedure Debug_Output (Str : String; Str2 : Name_Id); 2728 -- If Current_Verbosity is not Default, outputs Str. 2729 -- This indents Str based on the current indentation level for traces 2730 -- Debug_Error is intended to be used to report an error in the traces. 2731 2732 procedure Debug_Increase_Indent 2733 (Str : String := ""; Str2 : Name_Id := No_Name); 2734 procedure Debug_Decrease_Indent (Str : String := ""); 2735 -- Increase or decrease the indentation level for debug traces. This 2736 -- indentation level only affects output done through Debug_Output. 2737 2738 Total_Errors_Detected : Nat := 0; 2739 2740 Warnings_Detected : Nat := 0; 2741 2742private 2743 Tool_Name : String_Access := null; 2744 2745 Serious_Errors_Detected : Nat := 0; 2746 2747 Warnings_Treated_As_Errors : Nat := 0; 2748 2749 Info_Messages : Nat := 0; 2750 2751 All_Packages : constant String_List_Access := null; 2752 2753 No_Project_Tree : constant Project_Tree_Ref := null; 2754 2755 Ignored : constant Variable_Kind := Single; 2756 2757 Nil_Variable_Value : constant Variable_Value := 2758 (Project => No_Project, 2759 Kind => Undefined, 2760 Location => No_Location, 2761 Default => False, 2762 String_Type => Empty_Project_Node); 2763 2764 type Source_Iterator is record 2765 In_Tree : Project_Tree_Ref; 2766 2767 Project : Project_List; 2768 All_Projects : Boolean; 2769 -- Current project and whether we should move on to the next 2770 2771 Language : Language_Ptr; 2772 -- Current language processed 2773 2774 Language_Name : Name_Id; 2775 -- Only sources of this language will be returned (or all if No_Name) 2776 2777 Current : Source_Id; 2778 2779 Encapsulated_Libs : Boolean; 2780 -- True if we want to include the sources from encapsulated libs 2781 2782 Locally_Removed : Boolean; 2783 end record; 2784 2785 procedure Add_To_Buffer 2786 (S : String; 2787 To : in out String_Access; 2788 Last : in out Natural); 2789 -- Append a String to the Buffer 2790 2791 -- Table used to store the path name of all the created temporary files, so 2792 -- that they can be deleted at the end, or when the program is interrupted. 2793 2794 package Temp_Files_Table is new GNAT.Dynamic_Tables 2795 (Table_Component_Type => Path_Name_Type, 2796 Table_Index_Type => Integer, 2797 Table_Low_Bound => 1, 2798 Table_Initial => 10, 2799 Table_Increment => 10); 2800 2801 -- The following type is used to represent the part of a project tree which 2802 -- is private to the Project Manager. 2803 2804 type Private_Project_Tree_Data is record 2805 Temp_Files : Temp_Files_Table.Instance; 2806 -- Temporary files created as part of running tools (pragma files, 2807 -- mapping files,...) 2808 2809 Current_Source_Path_File : Path_Name_Type := No_Path; 2810 -- Current value of project source path file env var. Used to avoid 2811 -- setting the env var to the same value. When different from No_Path, 2812 -- this indicates that environment variables were created and should be 2813 -- deassigned to avoid polluting the environment. For gnatmake only. 2814 2815 Current_Object_Path_File : Path_Name_Type := No_Path; 2816 -- Current value of project object path file env var. Used to avoid 2817 -- setting the env var to the same value. 2818 -- gnatmake only 2819 end record; 2820 2821 Executable_Extension_On_Target : Name_Id := No_Name; 2822 2823 -- The following type is used to hold processing flags which show what 2824 -- functions are required for the various tools that are handled. 2825 2826 type Processing_Flags is record 2827 Require_Sources_Other_Lang : Boolean; 2828 Report_Error : Error_Handler; 2829 When_No_Sources : Error_Warning; 2830 Allow_Duplicate_Basenames : Boolean; 2831 Compiler_Driver_Mandatory : Boolean; 2832 Error_On_Unknown_Language : Boolean; 2833 Require_Obj_Dirs : Error_Warning; 2834 Allow_Invalid_External : Error_Warning; 2835 Missing_Source_Files : Error_Warning; 2836 Ignore_Missing_With : Boolean; 2837 Check_Configuration_Only : Boolean; 2838 2839 Incomplete_Withs : Boolean := False; 2840 -- This flag is set to True when the projects are parsed while ignoring 2841 -- missing withed project and some withed projects are not found. 2842 2843 end record; 2844 2845 Gprbuild_Flags : constant Processing_Flags := 2846 (Report_Error => null, 2847 When_No_Sources => Warning, 2848 Require_Sources_Other_Lang => True, 2849 Allow_Duplicate_Basenames => False, 2850 Compiler_Driver_Mandatory => True, 2851 Error_On_Unknown_Language => True, 2852 Require_Obj_Dirs => Error, 2853 Allow_Invalid_External => Error, 2854 Missing_Source_Files => Error, 2855 Ignore_Missing_With => False, 2856 Incomplete_Withs => False, 2857 Check_Configuration_Only => False); 2858 2859 Gprinstall_Flags : constant Processing_Flags := 2860 (Report_Error => null, 2861 When_No_Sources => Warning, 2862 Require_Sources_Other_Lang => True, 2863 Allow_Duplicate_Basenames => False, 2864 Compiler_Driver_Mandatory => True, 2865 Error_On_Unknown_Language => True, 2866 Require_Obj_Dirs => Silent, 2867 Allow_Invalid_External => Error, 2868 Missing_Source_Files => Error, 2869 Ignore_Missing_With => False, 2870 Incomplete_Withs => False, 2871 Check_Configuration_Only => False); 2872 2873 Gprclean_Flags : constant Processing_Flags := 2874 (Report_Error => null, 2875 When_No_Sources => Warning, 2876 Require_Sources_Other_Lang => True, 2877 Allow_Duplicate_Basenames => False, 2878 Compiler_Driver_Mandatory => True, 2879 Error_On_Unknown_Language => True, 2880 Require_Obj_Dirs => Warning, 2881 Allow_Invalid_External => Error, 2882 Missing_Source_Files => Error, 2883 Ignore_Missing_With => False, 2884 Incomplete_Withs => False, 2885 Check_Configuration_Only => False); 2886 2887 Gprname_Flags : constant Processing_Flags := 2888 (Report_Error => null, 2889 When_No_Sources => Warning, 2890 Require_Sources_Other_Lang => True, 2891 Allow_Duplicate_Basenames => False, 2892 Compiler_Driver_Mandatory => True, 2893 Error_On_Unknown_Language => True, 2894 Require_Obj_Dirs => Error, 2895 Allow_Invalid_External => Error, 2896 Missing_Source_Files => Error, 2897 Ignore_Missing_With => False, 2898 Incomplete_Withs => False, 2899 Check_Configuration_Only => True); 2900 2901 Gprls_Flags : constant Processing_Flags := 2902 (Report_Error => null, 2903 When_No_Sources => Warning, 2904 Require_Sources_Other_Lang => True, 2905 Allow_Duplicate_Basenames => False, 2906 Compiler_Driver_Mandatory => True, 2907 Error_On_Unknown_Language => True, 2908 Require_Obj_Dirs => Error, 2909 Allow_Invalid_External => Error, 2910 Missing_Source_Files => Error, 2911 Ignore_Missing_With => False, 2912 Incomplete_Withs => False, 2913 Check_Configuration_Only => False); 2914end GPR; 2915