File : prj.ads


   1 ------------------------------------------------------------------------------
   2 --                                                                          --
   3 --                         GNAT COMPILER COMPONENTS                         --
   4 --                                                                          --
   5 --                                  P R J                                   --
   6 --                                                                          --
   7 --                                 S p e c                                  --
   8 --                                                                          --
   9 --          Copyright (C) 2001-2015, Free Software Foundation, Inc.         --
  10 --                                                                          --
  11 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
  12 -- terms of the  GNU General Public License as published  by the Free Soft- --
  13 -- ware  Foundation;  either version 3,  or (at your option) any later ver- --
  14 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
  15 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
  16 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
  17 -- for  more details.  You should have  received  a copy of the GNU General --
  18 -- Public License  distributed with GNAT; see file COPYING3.  If not, go to --
  19 -- http://www.gnu.org/licenses for a complete copy of the license.          --
  20 --                                                                          --
  21 -- GNAT was originally developed  by the GNAT team at  New York University. --
  22 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
  23 --                                                                          --
  24 ------------------------------------------------------------------------------
  25 
  26 --  The following package declares the data types for GNAT project.
  27 --  These data types may be used by GNAT Project-aware tools.
  28 
  29 --  Children of these package implements various services on these data types.
  30 --  See in particular Prj.Pars and Prj.Env.
  31 
  32 with Casing; use Casing;
  33 with Namet;  use Namet;
  34 with Osint;
  35 with Scans;  use Scans;
  36 with Types;  use Types;
  37 
  38 with GNAT.Dynamic_HTables; use GNAT.Dynamic_HTables;
  39 with GNAT.Dynamic_Tables;
  40 with GNAT.OS_Lib;          use GNAT.OS_Lib;
  41 
  42 package Prj is
  43 
  44    procedure Add_Restricted_Language (Name : String);
  45    --  Call by gprbuild for each language specify by switch
  46    --  --restricted-to-languages=.
  47 
  48    procedure Remove_All_Restricted_Languages;
  49    --  Call by gprbuild in CodePeer mode to ignore switches
  50    --  --restricted-to-languages=.
  51 
  52    function Is_Allowed_Language (Name : Name_Id) return Boolean;
  53    --  Returns True if --restricted-to-languages= is not used or if Name
  54    --  is one of the restricted languages.
  55 
  56    All_Other_Names : constant Name_Id := Names_High_Bound;
  57    --  Name used to replace others as an index of an associative array
  58    --  attribute in situations where this is allowed.
  59 
  60    Subdirs : String_Ptr := null;
  61    --  The value after the equal sign in switch --subdirs=...
  62    --  Contains the relative subdirectory.
  63 
  64    Build_Tree_Dir : String_Ptr := null;
  65    --  A root directory for building out-of-tree projects. All relative object
  66    --  directories will be rooted at this location.
  67 
  68    Root_Dir : String_Ptr := null;
  69    --  When using out-of-tree build we need to keep information about the root
  70    --  directory of artifacts to properly relocate them. Note that the root
  71    --  directory is not necessarily the directory of the main project.
  72 
  73    type Library_Support is (None, Static_Only, Full);
  74    --  Support for Library Project File.
  75    --  - None: Library Project Files are not supported at all
  76    --  - Static_Only: Library Project Files are only supported for static
  77    --    libraries.
  78    --  - Full: Library Project Files are supported for static and dynamic
  79    --    (shared) libraries.
  80 
  81    type Yes_No_Unknown is (Yes, No, Unknown);
  82    --  Tri-state to decide if -lgnarl is needed when linking
  83 
  84    type Attribute_Default_Value is
  85      (Read_Only_Value,     --  For read only attributes (Name, Project_Dir)
  86       Empty_Value,         --  Empty string or empty string list
  87       Dot_Value,           --  "." or (".")
  88       Object_Dir_Value,    --  'Object_Dir
  89       Target_Value,        --  'Target (special rules)
  90       Runtime_Value);      --  'Runtime (special rules)
  91    --  Describe the default values of attributes that are referenced but not
  92    --  declared.
  93 
  94    pragma Warnings (Off);
  95    type Project_Qualifier is
  96      (Unspecified,
  97 
  98       --  The following clash with Standard is OK, and justified by the context
  99       --  which really wants to use the same set of qualifiers.
 100 
 101       Standard,
 102 
 103       Library,
 104       Configuration,
 105       Abstract_Project,
 106       Aggregate,
 107       Aggregate_Library);
 108    pragma Warnings (On);
 109    --  Qualifiers that can prefix the reserved word "project" in a project
 110    --  file:
 111    --    Standard:             standard project ...
 112    --    Library:              library project is ...
 113    --    Abstract_Project:     abstract project is
 114    --    Aggregate:            aggregate project is
 115    --    Aggregate_Library:    aggregate library project is ...
 116    --    Configuration:        configuration project is ...
 117 
 118    subtype Aggregate_Project is
 119      Project_Qualifier range Aggregate .. Aggregate_Library;
 120 
 121    All_Packages : constant String_List_Access;
 122    --  Default value of parameter Packages of procedures Parse, in Prj.Pars and
 123    --  Prj.Part, indicating that all packages should be checked.
 124 
 125    type Project_Tree_Data;
 126    type Project_Tree_Ref is access all Project_Tree_Data;
 127    --  Reference to a project tree. Several project trees may exist in memory
 128    --  at the same time.
 129 
 130    No_Project_Tree : constant Project_Tree_Ref;
 131 
 132    procedure Free (Tree : in out Project_Tree_Ref);
 133    --  Free memory associated with the tree
 134 
 135    Config_Project_File_Extension : String := ".cgpr";
 136    Project_File_Extension : String := ".gpr";
 137    --  The standard config and user project file name extensions. They are not
 138    --  constants, because Canonical_Case_File_Name is called on these variables
 139    --  in the body of Prj.
 140 
 141    function Empty_File   return File_Name_Type;
 142    function Empty_String return Name_Id;
 143    --  Return the id for an empty string ""
 144 
 145    function Dot_String return Name_Id;
 146    --  Return the id for "."
 147 
 148    type Path_Information is record
 149       Name         : Path_Name_Type := No_Path;
 150       Display_Name : Path_Name_Type := No_Path;
 151    end record;
 152    --  Directory names always end with a directory separator
 153 
 154    No_Path_Information : constant Path_Information := (No_Path, No_Path);
 155 
 156    type Project_Data;
 157    type Project_Id is access all Project_Data;
 158    No_Project : constant Project_Id := null;
 159    --  Id of a Project File
 160 
 161    type String_List_Id is new Nat;
 162    Nil_String : constant String_List_Id := 0;
 163    type String_Element is record
 164       Value         : Name_Id        := No_Name;
 165       Index         : Int            := 0;
 166       Display_Value : Name_Id        := No_Name;
 167       Location      : Source_Ptr     := No_Location;
 168       Flag          : Boolean        := False;
 169       Next          : String_List_Id := Nil_String;
 170    end record;
 171    --  To hold values for string list variables and array elements.
 172    --  Component Flag may be used for various purposes. For source
 173    --  directories, it indicates if the directory contains Ada source(s).
 174 
 175    package String_Element_Table is new GNAT.Dynamic_Tables
 176      (Table_Component_Type => String_Element,
 177       Table_Index_Type     => String_List_Id,
 178       Table_Low_Bound      => 1,
 179       Table_Initial        => 200,
 180       Table_Increment      => 100);
 181    --  The table for string elements in string lists
 182 
 183    type Variable_Kind is (Undefined, List, Single);
 184    --  Different kinds of variables
 185 
 186    subtype Defined_Variable_Kind is Variable_Kind range List .. Single;
 187    --  The defined kinds of variables
 188 
 189    Ignored : constant Variable_Kind;
 190    --  Used to indicate that a package declaration must be ignored while
 191    --  processing the project tree (unknown package name).
 192 
 193    type Variable_Value (Kind : Variable_Kind := Undefined) is record
 194       Project  : Project_Id := No_Project;
 195       Location : Source_Ptr := No_Location;
 196       Default  : Boolean    := False;
 197       case Kind is
 198          when Undefined =>
 199             null;
 200          when List =>
 201             Values : String_List_Id := Nil_String;
 202          when Single =>
 203             Value : Name_Id := No_Name;
 204             Index : Int     := 0;
 205       end case;
 206    end record;
 207    --  Values for variables and array elements. Default is True if the
 208    --  current value is the default one for the variable.
 209 
 210    Nil_Variable_Value : constant Variable_Value;
 211    --  Value of a non existing variable or array element
 212 
 213    type Variable_Id is new Nat;
 214    No_Variable : constant Variable_Id := 0;
 215    type Variable is record
 216       Next  : Variable_Id := No_Variable;
 217       Name  : Name_Id;
 218       Value : Variable_Value;
 219    end record;
 220    --  To hold the list of variables in a project file and in packages
 221 
 222    package Variable_Element_Table is new GNAT.Dynamic_Tables
 223      (Table_Component_Type => Variable,
 224       Table_Index_Type     => Variable_Id,
 225       Table_Low_Bound      => 1,
 226       Table_Initial        => 200,
 227       Table_Increment      => 100);
 228    --  The table of variable in list of variables
 229 
 230    type Array_Element_Id is new Nat;
 231    No_Array_Element : constant Array_Element_Id := 0;
 232    type Array_Element is record
 233       Index                : Name_Id;
 234       Restricted           : Boolean          := False;
 235       Src_Index            : Int              := 0;
 236       Index_Case_Sensitive : Boolean          := True;
 237       Value                : Variable_Value;
 238       Next                 : Array_Element_Id := No_Array_Element;
 239    end record;
 240    --  Each Array_Element represents an array element and is linked (Next)
 241    --  to the next array element, if any, in the array.
 242 
 243    package Array_Element_Table is new GNAT.Dynamic_Tables
 244      (Table_Component_Type => Array_Element,
 245       Table_Index_Type     => Array_Element_Id,
 246       Table_Low_Bound      => 1,
 247       Table_Initial        => 200,
 248       Table_Increment      => 100);
 249    --  The table that contains all array elements
 250 
 251    type Array_Id is new Nat;
 252    No_Array : constant Array_Id := 0;
 253    type Array_Data is record
 254       Name     : Name_Id          := No_Name;
 255       Location : Source_Ptr       := No_Location;
 256       Value    : Array_Element_Id := No_Array_Element;
 257       Next     : Array_Id         := No_Array;
 258    end record;
 259    --  Each Array_Data value represents an array.
 260    --  Value is the id of the first element.
 261    --  Next is the id of the next array in the project file or package.
 262 
 263    package Array_Table is new GNAT.Dynamic_Tables
 264      (Table_Component_Type => Array_Data,
 265       Table_Index_Type     => Array_Id,
 266       Table_Low_Bound      => 1,
 267       Table_Initial        => 200,
 268       Table_Increment      => 100);
 269    --  The table that contains all arrays
 270 
 271    type Package_Id is new Nat;
 272    No_Package : constant Package_Id := 0;
 273    type Declarations is record
 274       Variables  : Variable_Id := No_Variable;
 275       Attributes : Variable_Id := No_Variable;
 276       Arrays     : Array_Id    := No_Array;
 277       Packages   : Package_Id  := No_Package;
 278    end record;
 279    --  Contains the declarations (variables, single and array attributes,
 280    --  packages) for a project or a package in a project.
 281 
 282    No_Declarations : constant Declarations :=
 283                        (Variables  => No_Variable,
 284                         Attributes => No_Variable,
 285                         Arrays     => No_Array,
 286                         Packages   => No_Package);
 287    --  Default value of Declarations: used if there are no declarations
 288 
 289    type Package_Element is record
 290       Name   : Name_Id      := No_Name;
 291       Decl   : Declarations := No_Declarations;
 292       Parent : Package_Id   := No_Package;
 293       Next   : Package_Id   := No_Package;
 294    end record;
 295    --  A package (includes declarations that may include other packages)
 296 
 297    package Package_Table is new GNAT.Dynamic_Tables
 298      (Table_Component_Type => Package_Element,
 299       Table_Index_Type     => Package_Id,
 300       Table_Low_Bound      => 1,
 301       Table_Initial        => 100,
 302       Table_Increment      => 100);
 303    --  The table that contains all packages
 304 
 305    type Language_Data;
 306    type Language_Ptr is access all Language_Data;
 307    --  Index of language data
 308 
 309    No_Language_Index : constant Language_Ptr := null;
 310    --  Constant indicating that there is no language data
 311 
 312    function Get_Language_From_Name
 313      (Project : Project_Id;
 314       Name    : String) return Language_Ptr;
 315    --  Get a language from a project. This might return null if no such
 316    --  language exists in the project
 317 
 318    Max_Header_Num : constant := 6150;
 319    type Header_Num is range 0 .. Max_Header_Num;
 320    --  Size for hash table below. The upper bound is an arbitrary value, the
 321    --  value here was chosen after testing to determine a good compromise
 322    --  between speed of access and memory usage.
 323 
 324    function Hash (Name : Name_Id)        return Header_Num;
 325    function Hash (Name : File_Name_Type) return Header_Num;
 326    function Hash (Name : Path_Name_Type) return Header_Num;
 327    function Hash (Project : Project_Id)  return Header_Num;
 328    --  Used for computing hash values for names put into hash tables
 329 
 330    type Language_Kind is (File_Based, Unit_Based);
 331    --  Type for the kind of language. All languages are file based, except Ada
 332    --  which is unit based.
 333 
 334    --  Type of dependency to be checked
 335 
 336    type Dependency_File_Kind is
 337      (None,
 338       --  There is no dependency file, the source must always be recompiled
 339 
 340       Makefile,
 341       --  The dependency file is a Makefile fragment indicating all the files
 342       --  the source depends on. If the object file or the dependency file is
 343       --  more recent than any of these files, the source must be recompiled.
 344 
 345       ALI_File,
 346       --  The dependency file is an ALI file and the source must be recompiled
 347       --  if the object or ALI file is more recent than any of the sources
 348       --  listed in the D lines.
 349 
 350       ALI_Closure);
 351       --  The dependency file is an ALI file and the source must be recompiled
 352       --  if the object or ALI file is more recent than any source in the full
 353       --  closure.
 354 
 355    Makefile_Dependency_Suffix : constant String := ".d";
 356    ALI_Dependency_Suffix      : constant String := ".ali";
 357    Switches_Dependency_Suffix : constant String := ".cswi";
 358 
 359    Binder_Exchange_Suffix : constant String := ".bexch";
 360    --  Suffix for binder exchange files
 361 
 362    Library_Exchange_Suffix : constant String := ".lexch";
 363    --  Suffix for library exchange files
 364 
 365    type Name_List_Index is new Nat;
 366    No_Name_List : constant Name_List_Index := 0;
 367 
 368    type Name_Node is record
 369       Name : Name_Id         := No_Name;
 370       Next : Name_List_Index := No_Name_List;
 371    end record;
 372 
 373    package Name_List_Table is new GNAT.Dynamic_Tables
 374      (Table_Component_Type => Name_Node,
 375       Table_Index_Type     => Name_List_Index,
 376       Table_Low_Bound      => 1,
 377       Table_Initial        => 10,
 378       Table_Increment      => 100);
 379    --  The table for lists of names
 380 
 381    function Length
 382      (Table : Name_List_Table.Instance;
 383       List  : Name_List_Index) return Natural;
 384    --  Return the number of elements in specified list
 385 
 386    type Number_List_Index is new Nat;
 387    No_Number_List : constant Number_List_Index := 0;
 388 
 389    type Number_Node is record
 390       Number : Natural           := 0;
 391       Next   : Number_List_Index := No_Number_List;
 392    end record;
 393 
 394    package Number_List_Table is new GNAT.Dynamic_Tables
 395      (Table_Component_Type => Number_Node,
 396       Table_Index_Type     => Number_List_Index,
 397       Table_Low_Bound      => 1,
 398       Table_Initial        => 10,
 399       Table_Increment      => 100);
 400    --  The table for lists of numbers
 401 
 402    package Mapping_Files_Htable is new Simple_HTable
 403      (Header_Num => Header_Num,
 404       Element    => Path_Name_Type,
 405       No_Element => No_Path,
 406       Key        => Path_Name_Type,
 407       Hash       => Hash,
 408       Equal      => "=");
 409    --  A hash table to store the mapping files that are not used
 410 
 411    --  The following record ???
 412 
 413    type Lang_Naming_Data is record
 414       Dot_Replacement : File_Name_Type := No_File;
 415       --  The string to replace '.' in the source file name (for Ada)
 416 
 417       Casing : Casing_Type := All_Lower_Case;
 418       --  The casing of the source file name (for Ada)
 419 
 420       Separate_Suffix : File_Name_Type := No_File;
 421       --  String to append to unit name for source file name of an Ada subunit
 422 
 423       Spec_Suffix : File_Name_Type := No_File;
 424       --  The string to append to the unit name for the
 425       --  source file name of a spec.
 426 
 427       Body_Suffix : File_Name_Type := No_File;
 428       --  The string to append to the unit name for the
 429       --  source file name of a body.
 430    end record;
 431 
 432    No_Lang_Naming_Data : constant Lang_Naming_Data :=
 433                            (Dot_Replacement => No_File,
 434                             Casing          => All_Lower_Case,
 435                             Separate_Suffix => No_File,
 436                             Spec_Suffix     => No_File,
 437                             Body_Suffix     => No_File);
 438 
 439    function Is_Standard_GNAT_Naming (Naming : Lang_Naming_Data) return Boolean;
 440    --  True if the naming scheme is GNAT's default naming scheme. This
 441    --  is to take into account shortened names like "Ada." (a-), "System." (s-)
 442    --  and so on.
 443 
 444    type Source_Data;
 445    type Source_Id is access all Source_Data;
 446 
 447    function Is_Compilable (Source : Source_Id) return Boolean;
 448    pragma Inline (Is_Compilable);
 449    --  Return True if we know how to compile Source (i.e. if a compiler is
 450    --  defined). This doesn't indicate whether the source should be compiled.
 451 
 452    function Object_To_Global_Archive (Source : Source_Id) return Boolean;
 453    pragma Inline (Object_To_Global_Archive);
 454    --  Return True if the object file should be put in the global archive.
 455    --  This is for Ada, when only the closure of a main needs to be
 456    --  (re)compiled.
 457 
 458    function Other_Part (Source : Source_Id) return Source_Id;
 459    pragma Inline (Other_Part);
 460    --  Source ID for the other part, if any: for a spec, returns its body;
 461    --  for a body, returns its spec.
 462 
 463    No_Source : constant Source_Id := null;
 464 
 465    type Path_Syntax_Kind is
 466      (Canonical, -- Unix style
 467       Host);     -- Host specific syntax
 468 
 469    --  The following record describes the configuration of a language
 470 
 471    type Language_Config is record
 472       Kind : Language_Kind := File_Based;
 473       --  Kind of language. Most languages are file based. A few, such as Ada,
 474       --  are unit based.
 475 
 476       Naming_Data : Lang_Naming_Data;
 477       --  The naming data for the languages (prefixes, etc.)
 478 
 479       Include_Compatible_Languages : Name_List_Index := No_Name_List;
 480       --  List of languages that are "include compatible" with this language. A
 481       --  language B (for example "C") is "include compatible" with a language
 482       --  A (for example "C++") if it is expected that sources of language A
 483       --  may "include" header files from language B.
 484 
 485       Compiler_Driver : File_Name_Type := No_File;
 486       --  The name of the executable for the compiler of the language
 487 
 488       Compiler_Driver_Path : String_Access := null;
 489       --  The path name of the executable for the compiler of the language
 490 
 491       Compiler_Leading_Required_Switches : Name_List_Index := No_Name_List;
 492       --  The list of initial switches that are required as a minimum to invoke
 493       --  the compiler driver.
 494 
 495       Compiler_Trailing_Required_Switches : Name_List_Index := No_Name_List;
 496       --  The list of final switches that are required as a minimum to invoke
 497       --  the compiler driver.
 498 
 499       Multi_Unit_Switches : Name_List_Index := No_Name_List;
 500       --  The switch(es) to indicate the index of a unit in a multi-source file
 501 
 502       Multi_Unit_Object_Separator : Character := ' ';
 503       --  The string separating the base name of a source from the index of the
 504       --  unit in a multi-source file, in the object file name.
 505 
 506       Path_Syntax : Path_Syntax_Kind := Host;
 507       --  Value may be Canonical (Unix style) or Host (host syntax)
 508 
 509       Source_File_Switches : Name_List_Index := No_Name_List;
 510       --  Optional switches to be put before the source file. The source file
 511       --  path name is appended to the last switch in the list.
 512       --  Example: ("-i", "");
 513 
 514       Object_File_Suffix : Name_Id := No_Name;
 515       --  Optional alternate object file suffix
 516 
 517       Object_File_Switches : Name_List_Index := No_Name_List;
 518       --  Optional object file switches. When this is defined, the switches
 519       --  are used to specify the object file. The object file name is appended
 520       --  to the last switch in the list. Example: ("-o", "").
 521 
 522       Object_Path_Switches : Name_List_Index := No_Name_List;
 523       --  List of switches to specify to the compiler the path name of a
 524       --  temporary file containing the list of object directories in the
 525       --  correct order.
 526 
 527       Compilation_PIC_Option : Name_List_Index := No_Name_List;
 528       --  The option(s) to compile a source in Position Independent Code for
 529       --  shared libraries. Specified in the configuration. When not specified,
 530       --  there is no need for such switch.
 531 
 532       Object_Generated : Boolean := True;
 533       --  False if no object file is generated
 534 
 535       Objects_Linked : Boolean := True;
 536       --  False if object files are not use to link executables and build
 537       --  libraries.
 538 
 539       Runtime_Library_Dir : Name_Id := No_Name;
 540       --  Path name of the runtime library directory, if any
 541 
 542       Runtime_Source_Dir : Name_Id := No_Name;
 543       --  Path name of the runtime source directory, if any
 544 
 545       Mapping_File_Switches : Name_List_Index := No_Name_List;
 546       --  The option(s) to provide a mapping file to the compiler. Specified in
 547       --  the configuration. When value is No_Name_List, there is no mapping
 548       --  file.
 549 
 550       Mapping_Spec_Suffix : File_Name_Type := No_File;
 551       --  Placeholder representing the spec suffix in a mapping file
 552 
 553       Mapping_Body_Suffix : File_Name_Type := No_File;
 554       --  Placeholder representing the body suffix in a mapping file
 555 
 556       Config_File_Switches : Name_List_Index := No_Name_List;
 557       --  The option(s) to provide a config file to the compiler. Specified in
 558       --  the configuration. If value is No_Name_List there is no config file.
 559 
 560       Dependency_Kind : Dependency_File_Kind := None;
 561       --  The kind of dependency to be checked: none, Makefile fragment or
 562       --  ALI file (for Ada).
 563 
 564       Dependency_Option : Name_List_Index := No_Name_List;
 565       --  The option(s) to be used to create the dependency file. When value is
 566       --  No_Name_List, there is not such option(s).
 567 
 568       Compute_Dependency : Name_List_Index := No_Name_List;
 569       --  Hold the value of attribute Dependency_Driver, if declared for the
 570       --  language.
 571 
 572       Include_Option : Name_List_Index := No_Name_List;
 573       --  Hold the value of attribute Include_Switches, if declared for the
 574       --  language.
 575 
 576       Include_Path : Name_Id := No_Name;
 577       --  Name of environment variable declared by attribute Include_Path for
 578       --  the language.
 579 
 580       Include_Path_File : Name_Id := No_Name;
 581       --  Name of environment variable declared by attribute Include_Path_File
 582       --  for the language.
 583 
 584       Objects_Path : Name_Id := No_Name;
 585       --  Name of environment variable declared by attribute Objects_Path for
 586       --  the language.
 587 
 588       Objects_Path_File : Name_Id := No_Name;
 589       --  Name of environment variable declared by attribute Objects_Path_File
 590       --  for the language.
 591 
 592       Config_Body : Name_Id := No_Name;
 593       --  The template for a pragma Source_File_Name(_Project) for a specific
 594       --  file name of a body.
 595 
 596       Config_Body_Index : Name_Id := No_Name;
 597       --  The template for a pragma Source_File_Name(_Project) for a specific
 598       --  file name of a body in a multi-source file.
 599 
 600       Config_Body_Pattern : Name_Id := No_Name;
 601       --  The template for a pragma Source_File_Name(_Project) for a naming
 602       --  body pattern.
 603 
 604       Config_Spec : Name_Id := No_Name;
 605       --  The template for a pragma Source_File_Name(_Project) for a specific
 606       --  file name of a spec.
 607 
 608       Config_Spec_Index : Name_Id := No_Name;
 609       --  The template for a pragma Source_File_Name(_Project) for a specific
 610       --  file name of a spec in a multi-source file.
 611 
 612       Config_Spec_Pattern : Name_Id := No_Name;
 613       --  The template for a pragma Source_File_Name(_Project) for a naming
 614       --  spec pattern.
 615 
 616       Config_File_Unique : Boolean := False;
 617       --  True if the config file specified to the compiler needs to be unique.
 618       --  If it is unique, then all config files are concatenated into a temp
 619       --  config file.
 620 
 621       Binder_Driver : File_Name_Type := No_File;
 622       --  The name of the binder driver for the language, if any
 623 
 624       Binder_Driver_Path : Path_Name_Type := No_Path;
 625       --  The path name of the binder driver
 626 
 627       Binder_Required_Switches : Name_List_Index := No_Name_List;
 628       --  Hold the value of attribute Binder'Required_Switches for the language
 629 
 630       Binder_Prefix : Name_Id := No_Name;
 631       --  Hold the value of attribute Binder'Prefix for the language
 632 
 633       Toolchain_Version : Name_Id := No_Name;
 634       --  Hold the value of attribute Toolchain_Version for the language
 635 
 636       Toolchain_Description : Name_Id := No_Name;
 637       --  Hold the value of attribute Toolchain_Description for the language
 638 
 639       Clean_Object_Artifacts : Name_List_Index := No_Name_List;
 640       --  List of object artifact extensions to be deleted by gprclean
 641 
 642       Clean_Source_Artifacts : Name_List_Index := No_Name_List;
 643       --  List of source artifact extensions to be deleted by gprclean
 644 
 645    end record;
 646 
 647    No_Language_Config : constant Language_Config :=
 648                           (Kind                         => File_Based,
 649                            Naming_Data                  => No_Lang_Naming_Data,
 650                            Include_Compatible_Languages => No_Name_List,
 651                            Compiler_Driver              => No_File,
 652                            Compiler_Driver_Path         => null,
 653                            Compiler_Leading_Required_Switches
 654                                                         => No_Name_List,
 655                            Compiler_Trailing_Required_Switches
 656                                                         => No_Name_List,
 657                            Multi_Unit_Switches          => No_Name_List,
 658                            Multi_Unit_Object_Separator  => ' ',
 659                            Path_Syntax                  => Canonical,
 660                            Source_File_Switches         => No_Name_List,
 661                            Object_File_Suffix           => No_Name,
 662                            Object_File_Switches         => No_Name_List,
 663                            Object_Path_Switches         => No_Name_List,
 664                            Compilation_PIC_Option       => No_Name_List,
 665                            Object_Generated             => True,
 666                            Objects_Linked               => True,
 667                            Runtime_Library_Dir          => No_Name,
 668                            Runtime_Source_Dir           => No_Name,
 669                            Mapping_File_Switches        => No_Name_List,
 670                            Mapping_Spec_Suffix          => No_File,
 671                            Mapping_Body_Suffix          => No_File,
 672                            Config_File_Switches         => No_Name_List,
 673                            Dependency_Kind              => None,
 674                            Dependency_Option            => No_Name_List,
 675                            Compute_Dependency           => No_Name_List,
 676                            Include_Option               => No_Name_List,
 677                            Include_Path                 => No_Name,
 678                            Include_Path_File            => No_Name,
 679                            Objects_Path                 => No_Name,
 680                            Objects_Path_File            => No_Name,
 681                            Config_Body                  => No_Name,
 682                            Config_Body_Index            => No_Name,
 683                            Config_Body_Pattern          => No_Name,
 684                            Config_Spec                  => No_Name,
 685                            Config_Spec_Index            => No_Name,
 686                            Config_Spec_Pattern          => No_Name,
 687                            Config_File_Unique           => False,
 688                            Binder_Driver                => No_File,
 689                            Binder_Driver_Path           => No_Path,
 690                            Binder_Required_Switches     => No_Name_List,
 691                            Binder_Prefix                => No_Name,
 692                            Toolchain_Version            => No_Name,
 693                            Toolchain_Description        => No_Name,
 694                            Clean_Object_Artifacts       => No_Name_List,
 695                            Clean_Source_Artifacts       => No_Name_List);
 696 
 697    type Language_Data is record
 698       Name : Name_Id := No_Name;
 699       --  The name of the language in lower case
 700 
 701       Display_Name : Name_Id := No_Name;
 702       --  The name of the language, as found in attribute Languages
 703 
 704       Config : Language_Config := No_Language_Config;
 705       --  Configuration of the language
 706 
 707       First_Source : Source_Id := No_Source;
 708       --  Head of the list of sources of the language in the project
 709 
 710       Mapping_Files : Mapping_Files_Htable.Instance :=
 711                         Mapping_Files_Htable.Nil;
 712       --  Hash table containing the mapping of the sources to their path names
 713 
 714       Next : Language_Ptr := No_Language_Index;
 715       --  Next language of the project
 716 
 717    end record;
 718 
 719    No_Language_Data : constant Language_Data :=
 720                         (Name          => No_Name,
 721                          Display_Name  => No_Name,
 722                          Config        => No_Language_Config,
 723                          First_Source  => No_Source,
 724                          Mapping_Files => Mapping_Files_Htable.Nil,
 725                          Next          => No_Language_Index);
 726 
 727    type Language_List_Element;
 728    type Language_List is access all Language_List_Element;
 729    type Language_List_Element is record
 730       Language : Language_Ptr := No_Language_Index;
 731       Next     : Language_List;
 732    end record;
 733 
 734    type Source_Kind is (Spec, Impl, Sep);
 735    subtype Spec_Or_Body is Source_Kind range Spec .. Impl;
 736 
 737    --  The following declarations declare a structure used to store the Name
 738    --  and File and Path names of a unit, with a reference to its GNAT Project
 739    --  File(s). Some units might have neither Spec nor Impl when they were
 740    --  created for a "separate".
 741 
 742    type File_Names_Data is array (Spec_Or_Body) of Source_Id;
 743 
 744    type Unit_Data is record
 745       Name       : Name_Id := No_Name;
 746       File_Names : File_Names_Data;
 747    end record;
 748 
 749    type Unit_Index is access all Unit_Data;
 750 
 751    No_Unit_Index : constant Unit_Index := null;
 752    --  Used to indicate a null entry for no unit
 753 
 754    type Source_Roots;
 755    type Roots_Access is access Source_Roots;
 756    type Source_Roots is record
 757       Root : Source_Id;
 758       Next : Roots_Access;
 759    end record;
 760    --  A list to store the roots associated with a main unit. These are the
 761    --  files that need to linked along with the main (for instance a C file
 762    --  corresponding to an Ada file). In general, these are dependencies that
 763    --  cannot be computed automatically by the builder.
 764 
 765    type Naming_Exception_Type is (No, Yes, Inherited);
 766 
 767    --  Structure to define source data
 768 
 769    type Source_Data is record
 770       Initialized : Boolean := False;
 771       --  Set to True when Source_Data is completely initialized
 772 
 773       Project : Project_Id := No_Project;
 774       --  Project of the source
 775 
 776       Location : Source_Ptr := No_Location;
 777       --  Location in the project file of the declaration of the source in
 778       --  package Naming.
 779 
 780       Source_Dir_Rank : Natural := 0;
 781       --  The rank of the source directory in list declared with attribute
 782       --  Source_Dirs. Two source files with the same name cannot appears in
 783       --  different directory with the same rank. That can happen when the
 784       --  recursive notation <dir>/** is used in attribute Source_Dirs.
 785 
 786       Language : Language_Ptr := No_Language_Index;
 787       --  Language of the source
 788 
 789       In_Interfaces : Boolean := True;
 790       --  False when the source is not included in interfaces, when attribute
 791       --  Interfaces is declared.
 792 
 793       Declared_In_Interfaces : Boolean := False;
 794       --  True when source is declared in attribute Interfaces
 795 
 796       Alternate_Languages : Language_List := null;
 797       --  List of languages a header file may also be, in addition of language
 798       --  Language_Name.
 799 
 800       Kind : Source_Kind := Spec;
 801       --  Kind of the source: spec, body or subunit
 802 
 803       Unit : Unit_Index := No_Unit_Index;
 804       --  Name of the unit, if language is unit based. This is only set for
 805       --  those files that are part of the compilation set (for instance a
 806       --  file in an extended project that is overridden will not have this
 807       --  field set).
 808 
 809       Index : Int := 0;
 810       --  Index of the source in a multi unit source file (the same Source_Data
 811       --  is duplicated several times when there are several units in the same
 812       --  file). Index is 0 if there is either no unit or a single one, and
 813       --  starts at 1 when there are multiple units
 814 
 815       Compilable : Yes_No_Unknown := Unknown;
 816       --  Updated at the first call to Is_Compilable. Yes if source file is
 817       --  compilable.
 818 
 819       In_The_Queue : Boolean := False;
 820       --  True if the source has been put in the queue
 821 
 822       Locally_Removed : Boolean := False;
 823       --  True if the source has been "excluded"
 824 
 825       Suppressed : Boolean := False;
 826       --  True if the source is a locally removed direct source of the project.
 827       --  These sources should not be put in the mapping file.
 828 
 829       Replaced_By : Source_Id := No_Source;
 830       --  Source in an extending project that replaces the current source
 831 
 832       File : File_Name_Type := No_File;
 833       --  Canonical file name of the source
 834 
 835       Display_File : File_Name_Type := No_File;
 836       --  File name of the source, for display purposes
 837 
 838       Path : Path_Information := No_Path_Information;
 839       --  Path name of the source
 840 
 841       Source_TS : Time_Stamp_Type := Empty_Time_Stamp;
 842       --  Time stamp of the source file
 843 
 844       Object_Project : Project_Id := No_Project;
 845       --  Project where the object file is. This might be different from
 846       --  Project when using extending project files.
 847 
 848       Object : File_Name_Type := No_File;
 849       --  File name of the object file
 850 
 851       Current_Object_Path : Path_Name_Type := No_Path;
 852       --  Object path of an existing object file
 853 
 854       Object_Path : Path_Name_Type := No_Path;
 855       --  Object path of the real object file
 856 
 857       Object_TS : Time_Stamp_Type := Empty_Time_Stamp;
 858       --  Object file time stamp
 859 
 860       Dep_Name : File_Name_Type := No_File;
 861       --  Dependency file simple name
 862 
 863       Current_Dep_Path : Path_Name_Type := No_Path;
 864       --  Path name of an existing dependency file
 865 
 866       Dep_Path : Path_Name_Type := No_Path;
 867       --  Path name of the real dependency file
 868 
 869       Dep_TS : aliased Osint.File_Attributes := Osint.Unknown_Attributes;
 870       --  Dependency file time stamp
 871 
 872       Switches : File_Name_Type := No_File;
 873       --  File name of the switches file. For all languages, this is a file
 874       --  that ends with the .cswi extension.
 875 
 876       Switches_Path : Path_Name_Type := No_Path;
 877       --  Path name of the switches file
 878 
 879       Switches_TS : Time_Stamp_Type := Empty_Time_Stamp;
 880       --  Switches file time stamp
 881 
 882       Naming_Exception : Naming_Exception_Type := No;
 883       --  True if the source has an exceptional name
 884 
 885       Duplicate_Unit : Boolean := False;
 886       --  True when a duplicate unit has been reported for this source
 887 
 888       Next_In_Lang : Source_Id := No_Source;
 889       --  Link to another source of the same language in the same project
 890 
 891       Next_With_File_Name : Source_Id := No_Source;
 892       --  Link to another source with the same base file name
 893 
 894       Roots : Roots_Access := null;
 895       --  The roots for a main unit
 896 
 897    end record;
 898 
 899    No_Source_Data : constant Source_Data :=
 900                       (Initialized            => False,
 901                        Project                => No_Project,
 902                        Location               => No_Location,
 903                        Source_Dir_Rank        => 0,
 904                        Language               => No_Language_Index,
 905                        In_Interfaces          => True,
 906                        Declared_In_Interfaces => False,
 907                        Alternate_Languages    => null,
 908                        Kind                   => Spec,
 909                        Unit                   => No_Unit_Index,
 910                        Index                  => 0,
 911                        Locally_Removed        => False,
 912                        Suppressed             => False,
 913                        Compilable             => Unknown,
 914                        In_The_Queue           => False,
 915                        Replaced_By            => No_Source,
 916                        File                   => No_File,
 917                        Display_File           => No_File,
 918                        Path                   => No_Path_Information,
 919                        Source_TS              => Empty_Time_Stamp,
 920                        Object_Project         => No_Project,
 921                        Object                 => No_File,
 922                        Current_Object_Path    => No_Path,
 923                        Object_Path            => No_Path,
 924                        Object_TS              => Empty_Time_Stamp,
 925                        Dep_Name               => No_File,
 926                        Current_Dep_Path       => No_Path,
 927                        Dep_Path               => No_Path,
 928                        Dep_TS                 => Osint.Unknown_Attributes,
 929                        Switches               => No_File,
 930                        Switches_Path          => No_Path,
 931                        Switches_TS            => Empty_Time_Stamp,
 932                        Naming_Exception       => No,
 933                        Duplicate_Unit         => False,
 934                        Next_In_Lang           => No_Source,
 935                        Next_With_File_Name    => No_Source,
 936                        Roots                  => null);
 937 
 938    package Source_Files_Htable is new Simple_HTable
 939      (Header_Num => Header_Num,
 940       Element    => Source_Id,
 941       No_Element => No_Source,
 942       Key        => File_Name_Type,
 943       Hash       => Hash,
 944       Equal      => "=");
 945    --  Mapping of source file names to source ids
 946 
 947    package Source_Paths_Htable is new Simple_HTable
 948      (Header_Num => Header_Num,
 949       Element    => Source_Id,
 950       No_Element => No_Source,
 951       Key        => Path_Name_Type,
 952       Hash       => Hash,
 953       Equal      => "=");
 954    --  Mapping of source paths to source ids
 955 
 956    type Lib_Kind is (Static, Dynamic, Relocatable);
 957 
 958    type Policy is (Autonomous, Compliant, Controlled, Restricted, Direct);
 959    --  Type to specify the symbol policy, when symbol control is supported.
 960    --  See full explanation about this type in package Symbols.
 961    --    Autonomous: Create a symbol file without considering any reference
 962    --    Compliant:  Try to be as compatible as possible with an existing ref
 963    --    Controlled: Fail if symbols are not the same as those in the reference
 964    --    Restricted: Restrict the symbols to those in the symbol file
 965    --    Direct:     The symbol file is used as is
 966 
 967    type Symbol_Record is record
 968       Symbol_File   : Path_Name_Type := No_Path;
 969       Reference     : Path_Name_Type := No_Path;
 970       Symbol_Policy : Policy  := Autonomous;
 971    end record;
 972    --  Type to keep the symbol data to be used when building a shared library
 973 
 974    No_Symbols : constant Symbol_Record :=
 975      (Symbol_File   => No_Path,
 976       Reference     => No_Path,
 977       Symbol_Policy => Autonomous);
 978    --  The default value of the symbol data
 979 
 980    function Image (The_Casing : Casing_Type) return String;
 981    --  Similar to 'Image (but avoid use of this attribute in compiler)
 982 
 983    function Value (Image : String) return Casing_Type;
 984    --  Similar to 'Value (but avoid use of this attribute in compiler)
 985    --  Raises Constraint_Error if not a Casing_Type image.
 986 
 987    --  The following record contains data for a naming scheme
 988 
 989    function Get_Object_Directory
 990      (Project             : Project_Id;
 991       Including_Libraries : Boolean;
 992       Only_If_Ada         : Boolean := False) return Path_Name_Type;
 993    --  Return the object directory to use for the project. This depends on
 994    --  whether we have a library project or a standard project. This function
 995    --  might return No_Name when no directory applies. If the project is a
 996    --  library project file and Including_Libraries is True then the library
 997    --  ALI dir is returned instead of the object dir, except when there is no
 998    --  ALI files in the Library ALI dir and the object directory exists. If
 999    --  Only_If_Ada is True, then No_Name is returned when the project doesn't
1000    --  include any Ada source.
1001 
1002    procedure Compute_All_Imported_Projects
1003      (Root_Project : Project_Id;
1004       Tree         : Project_Tree_Ref);
1005    --  For all projects in the tree, compute the list of the projects imported
1006    --  directly or indirectly by project Root_Project. The result is stored in
1007    --  Project.All_Imported_Projects for each project
1008 
1009    function Ultimate_Extending_Project_Of
1010      (Proj : Project_Id) return Project_Id;
1011    --  Returns the ultimate extending project of project Proj. If project Proj
1012    --  is not extended, returns Proj.
1013 
1014    type Project_List_Element;
1015    type Project_List is access all Project_List_Element;
1016    type Project_List_Element is record
1017       Project               : Project_Id   := No_Project;
1018       From_Encapsulated_Lib : Boolean      := False;
1019       Next                  : Project_List := null;
1020    end record;
1021    --  A list of projects
1022 
1023    procedure Free_List
1024      (List         : in out Project_List;
1025       Free_Project : Boolean);
1026    --  Free the list of projects, if Free_Project, each project is also freed
1027 
1028    type Response_File_Format is
1029      (None,
1030       GNU,
1031       Object_List,
1032       Option_List,
1033       GCC,
1034       GCC_GNU,
1035       GCC_Object_List,
1036       GCC_Option_List);
1037    --  The format of the different response files
1038 
1039    type Project_Configuration is record
1040       Target : Name_Id := No_Name;
1041       --  The target of the configuration, when specified
1042 
1043       Run_Path_Option : Name_List_Index := No_Name_List;
1044       --  The option to use when linking to specify the path where to look for
1045       --  libraries.
1046 
1047       Run_Path_Origin : Name_Id := No_Name;
1048       --  Specify the string (such as "$ORIGIN") to indicate paths relative to
1049       --  the directory of the executable in the run path option.
1050 
1051       Library_Install_Name_Option : Name_Id := No_Name;
1052       --  When this is not an empty list, this option, followed by the single
1053       --  name of the shared library file is used when linking a shared
1054       --  library.
1055 
1056       Separate_Run_Path_Options : Boolean := False;
1057       --  True if each directory needs to be specified in a separate run path
1058       --  option.
1059 
1060       Executable_Suffix : Name_Id := No_Name;
1061       --  The suffix of executables, when specified in the configuration or in
1062       --  package Builder of the main project. When this is not specified, the
1063       --  executable suffix is the default for the platform.
1064 
1065       --  Linking
1066 
1067       Linker : Path_Name_Type := No_Path;
1068       --  Path name of the linker driver. Specified in the configuration or in
1069       --  the package Builder of the main project.
1070 
1071       Map_File_Option : Name_Id := No_Name;
1072       --  Option to use when invoking the linker to build a map file
1073 
1074       Trailing_Linker_Required_Switches : Name_List_Index := No_Name_List;
1075       --  The minimum options for the linker driver. Specified in the
1076       --  configuration.
1077 
1078       Linker_Executable_Option : Name_List_Index := No_Name_List;
1079       --  The option(s) to indicate the name of the executable in the linker
1080       --  command. Specified in the configuration. When not specified, default
1081       --  to -o <executable name>.
1082 
1083       Linker_Lib_Dir_Option : Name_Id := No_Name;
1084       --  The option to specify where to find a library for linking. Specified
1085       --  in the configuration. When not specified, defaults to "-L".
1086 
1087       Linker_Lib_Name_Option : Name_Id := No_Name;
1088       --  The option to specify the name of a library for linking. Specified in
1089       --  the configuration. When not specified, defaults to "-l".
1090 
1091       Max_Command_Line_Length : Natural := 0;
1092       --  When positive and when Resp_File_Format (see below) is not None,
1093       --  if the command line for the invocation of the linker would be greater
1094       --  than this value, a response file is used to invoke the linker.
1095 
1096       Resp_File_Format : Response_File_Format := None;
1097       --  The format of a response file, when linking with a response file is
1098       --  supported.
1099 
1100       Resp_File_Options : Name_List_Index := No_Name_List;
1101       --  The switches, if any, that precede the path name of the response
1102       --  file in the invocation of the linker.
1103 
1104       --  Libraries
1105 
1106       Library_Builder : Path_Name_Type  := No_Path;
1107       --  The executable to build library (specified in the configuration)
1108 
1109       Lib_Support : Library_Support := None;
1110       --  The level of library support. Specified in the configuration. Support
1111       --  is none, static libraries only or both static and shared libraries.
1112 
1113       Lib_Encapsulated_Supported : Boolean := False;
1114       --  True when building fully standalone libraries supported on the target
1115 
1116       Archive_Builder : Name_List_Index := No_Name_List;
1117       --  The name of the executable to build archives, with the minimum
1118       --  switches. Specified in the configuration.
1119 
1120       Archive_Builder_Append_Option : Name_List_Index := No_Name_List;
1121       --  The options to append object files to an archive
1122 
1123       Archive_Indexer : Name_List_Index := No_Name_List;
1124       --  The name of the executable to index archives, with the minimum
1125       --  switches. Specified in the configuration.
1126 
1127       Archive_Suffix : File_Name_Type := No_File;
1128       --  The suffix of archives. Specified in the configuration. When not
1129       --  specified, defaults to ".a".
1130 
1131       Lib_Partial_Linker : Name_List_Index := No_Name_List;
1132 
1133       --  Shared libraries
1134 
1135       Shared_Lib_Driver : File_Name_Type := No_File;
1136       --  The driver to link shared libraries. Set with attribute Library_GCC.
1137       --  Default to gcc.
1138 
1139       Shared_Lib_Prefix : File_Name_Type := No_File;
1140       --  Part of a shared library file name that precedes the name of the
1141       --  library. Specified in the configuration. When not specified, defaults
1142       --  to "lib".
1143 
1144       Shared_Lib_Suffix : File_Name_Type := No_File;
1145       --  Suffix of shared libraries, after the library name in the shared
1146       --  library name. Specified in the configuration. When not specified,
1147       --  default to ".so".
1148 
1149       Shared_Lib_Min_Options : Name_List_Index := No_Name_List;
1150       --  The minimum options to use when building a shared library
1151 
1152       Lib_Version_Options : Name_List_Index := No_Name_List;
1153       --  The options to use to specify a library version
1154 
1155       Symbolic_Link_Supported : Boolean := False;
1156       --  True if the platform supports symbolic link files
1157 
1158       Lib_Maj_Min_Id_Supported : Boolean := False;
1159       --  True if platform supports library major and minor options, such as
1160       --  libname.so -> libname.so.2 -> libname.so.2.4
1161 
1162       Auto_Init_Supported : Boolean := False;
1163       --  True if automatic initialisation is supported for shared stand-alone
1164       --  libraries.
1165 
1166       --  Cleaning
1167 
1168       Artifacts_In_Exec_Dir : Name_List_Index := No_Name_List;
1169       --  List of regexp file names to be cleaned in the exec directory of the
1170       --  main project.
1171 
1172       Artifacts_In_Object_Dir : Name_List_Index := No_Name_List;
1173       --  List of regexp file names to be cleaned in the object directory of
1174       --  all projects.
1175 
1176    end record;
1177 
1178    Default_Project_Config : constant Project_Configuration :=
1179                               (Target                         => No_Name,
1180                                Run_Path_Option                => No_Name_List,
1181                                Run_Path_Origin                => No_Name,
1182                                Library_Install_Name_Option    => No_Name,
1183                                Separate_Run_Path_Options      => False,
1184                                Executable_Suffix              => No_Name,
1185                                Linker                         => No_Path,
1186                                Map_File_Option                => No_Name,
1187                                Trailing_Linker_Required_Switches =>
1188                                  No_Name_List,
1189                                Linker_Executable_Option       => No_Name_List,
1190                                Linker_Lib_Dir_Option          => No_Name,
1191                                Linker_Lib_Name_Option         => No_Name,
1192                                Library_Builder                => No_Path,
1193                                Max_Command_Line_Length        => 0,
1194                                Resp_File_Format               => None,
1195                                Resp_File_Options              => No_Name_List,
1196                                Lib_Support                    => None,
1197                                Lib_Encapsulated_Supported     => False,
1198                                Archive_Builder                => No_Name_List,
1199                                Archive_Builder_Append_Option  => No_Name_List,
1200                                Archive_Indexer                => No_Name_List,
1201                                Archive_Suffix                 => No_File,
1202                                Lib_Partial_Linker             => No_Name_List,
1203                                Shared_Lib_Driver              => No_File,
1204                                Shared_Lib_Prefix              => No_File,
1205                                Shared_Lib_Suffix              => No_File,
1206                                Shared_Lib_Min_Options         => No_Name_List,
1207                                Lib_Version_Options            => No_Name_List,
1208                                Symbolic_Link_Supported        => False,
1209                                Lib_Maj_Min_Id_Supported       => False,
1210                                Auto_Init_Supported            => False,
1211                                Artifacts_In_Exec_Dir          => No_Name_List,
1212                                Artifacts_In_Object_Dir        => No_Name_List);
1213 
1214    -------------------------
1215    -- Aggregated projects --
1216    -------------------------
1217 
1218    type Aggregated_Project;
1219    type Aggregated_Project_List is access all Aggregated_Project;
1220    type Aggregated_Project is record
1221       Path    : Path_Name_Type;
1222       Tree    : Project_Tree_Ref;
1223       Project : Project_Id;
1224       Next    : Aggregated_Project_List;
1225    end record;
1226 
1227    procedure Free (List : in out Aggregated_Project_List);
1228    --  Free the memory used for List
1229 
1230    procedure Add_Aggregated_Project
1231      (Project : Project_Id;
1232       Path    : Path_Name_Type);
1233    --  Add a new aggregated project in Project.
1234    --  The aggregated project has not been processed yet. This procedure should
1235    --  the called while processing the aggregate project, and as a result
1236    --  Prj.Proc.Process will then automatically process the aggregated projects
1237 
1238    ------------------
1239    -- Project_Data --
1240    ------------------
1241 
1242    --  The following record describes a project file representation
1243 
1244    pragma Warnings (Off);
1245    type Standalone is
1246      (No,
1247 
1248       --  The following clash with Standard is OK, and justified by the context
1249       --  which really wants to use the same set of qualifiers.
1250 
1251       Standard,
1252 
1253       Encapsulated);
1254    pragma Warnings (On);
1255 
1256    type Project_Data (Qualifier : Project_Qualifier := Unspecified) is record
1257 
1258       -------------
1259       -- General --
1260       -------------
1261 
1262       Name : Name_Id := No_Name;
1263       --  The name of the project
1264 
1265       Display_Name : Name_Id := No_Name;
1266       --  The name of the project with the spelling of its declaration
1267 
1268       Externally_Built : Boolean := False;
1269       --  True if the project is externally built. In such case, the Project
1270       --  Manager will not modify anything in this project.
1271 
1272       Config : Project_Configuration;
1273 
1274       Path : Path_Information := No_Path_Information;
1275       --  The path name of the project file. This include base name of the
1276       --  project file.
1277 
1278       Virtual : Boolean := False;
1279       --  True for virtual extending projects
1280 
1281       Location : Source_Ptr := No_Location;
1282       --  The location in the project file source of the project name that
1283       --  immediately follows the reserved word "project".
1284 
1285       ---------------
1286       -- Languages --
1287       ---------------
1288 
1289       Languages : Language_Ptr := No_Language_Index;
1290       --  First index of the language data in the project. Traversing the list
1291       --  gives access to all the languages supported by the project.
1292 
1293       --------------
1294       -- Projects --
1295       --------------
1296 
1297       Mains : String_List_Id := Nil_String;
1298       --  List of mains specified by attribute Main
1299 
1300       Extends : Project_Id := No_Project;
1301       --  The reference of the project file, if any, that this project file
1302       --  extends.
1303 
1304       Extended_By : Project_Id := No_Project;
1305       --  The reference of the project file, if any, that extends this project
1306       --  file.
1307 
1308       Decl : Declarations := No_Declarations;
1309       --  The declarations (variables, attributes and packages) of this project
1310       --  file.
1311 
1312       Imported_Projects : Project_List := null;
1313       --  The list of all directly imported projects, if any
1314 
1315       All_Imported_Projects : Project_List := null;
1316       --  The list of all projects imported directly or indirectly, if any.
1317       --  This does not include the project itself.
1318 
1319       -----------------
1320       -- Directories --
1321       -----------------
1322 
1323       Directory : Path_Information := No_Path_Information;
1324       --  Path name of the directory where the project file resides
1325 
1326       Object_Directory : Path_Information := No_Path_Information;
1327       --  The path name of the object directory of this project file
1328 
1329       Exec_Directory : Path_Information := No_Path_Information;
1330       --  The path name of the exec directory of this project file. Default is
1331       --  equal to Object_Directory.
1332 
1333       Object_Path_File : Path_Name_Type := No_Path;
1334       --  Store the name of the temporary file that contains the list of object
1335       --  directories, when attribute Object_Path_Switches is declared.
1336 
1337       -------------
1338       -- Library --
1339       -------------
1340 
1341       Library : Boolean := False;
1342       --  True if this is a library project
1343 
1344       Library_Name : Name_Id := No_Name;
1345       --  If a library project, name of the library
1346 
1347       Library_Kind : Lib_Kind := Static;
1348       --  If a library project, kind of library
1349 
1350       Library_Dir : Path_Information := No_Path_Information;
1351       --  If a library project, path name of the directory where the library
1352       --  resides.
1353 
1354       Library_TS : Time_Stamp_Type := Empty_Time_Stamp;
1355       --  The timestamp of a library file in a library project
1356 
1357       Library_Src_Dir : Path_Information := No_Path_Information;
1358       --  If a Stand-Alone Library project, path name of the directory where
1359       --  the sources of the interfaces of the library are copied. By default,
1360       --  if attribute Library_Src_Dir is not specified, sources of the
1361       --  interfaces are not copied anywhere.
1362 
1363       Library_ALI_Dir : Path_Information := No_Path_Information;
1364       --  In a library project, path name of the directory where the ALI files
1365       --  are copied. If attribute Library_ALI_Dir is not specified, ALI files
1366       --  are copied in the Library_Dir.
1367 
1368       Lib_Internal_Name : Name_Id := No_Name;
1369       --  If a library project, internal name store inside the library
1370 
1371       Standalone_Library : Standalone := No;
1372       --  Indicate that this is a Standalone Library Project File
1373 
1374       Lib_Interface_ALIs : String_List_Id := Nil_String;
1375       --  For Standalone Library Project Files, list of Interface ALI files
1376 
1377       Other_Interfaces : String_List_Id := Nil_String;
1378       --  List of non unit based sources in attribute Interfaces
1379 
1380       Lib_Auto_Init : Boolean := False;
1381       --  For non static Stand-Alone Library Project Files, True if the library
1382       --  initialisation should be automatic.
1383 
1384       Symbol_Data : Symbol_Record := No_Symbols;
1385       --  Symbol file name, reference symbol file name, symbol policy
1386 
1387       Need_To_Build_Lib : Boolean := False;
1388       --  True if the library of a Library Project needs to be built or rebuilt
1389 
1390       -------------
1391       -- Sources --
1392       -------------
1393       --  The sources for all languages including Ada are accessible through
1394       --  the Source_Iterator type
1395 
1396       Interfaces_Defined : Boolean := False;
1397       --  True if attribute Interfaces is declared for the project or any
1398       --  project it extends.
1399 
1400       Include_Path_File : Path_Name_Type := No_Path;
1401       --  The path name of the of the source search directory file.
1402       --  This is only used by gnatmake
1403 
1404       Source_Dirs : String_List_Id := Nil_String;
1405       --  The list of all the source directories
1406 
1407       Source_Dir_Ranks : Number_List_Index := No_Number_List;
1408 
1409       Ada_Include_Path : String_Access := null;
1410       --  The cached value of source search path for this project file. Set by
1411       --  the first call to Prj.Env.Ada_Include_Path for the project. Do not
1412       --  use this field directly outside of the project manager, use
1413       --  Prj.Env.Ada_Include_Path instead.
1414 
1415       Has_Multi_Unit_Sources : Boolean := False;
1416       --  Whether there is at least one source file containing multiple units
1417 
1418       -------------------
1419       -- Miscellaneous --
1420       -------------------
1421 
1422       Ada_Objects_Path : String_Access := null;
1423       --  The cached value of ADA_OBJECTS_PATH for this project file, with
1424       --  library ALI directories for library projects instead of object
1425       --  directories. Do not use this field directly outside of the
1426       --  compiler, use Prj.Env.Ada_Objects_Path instead.
1427 
1428       Ada_Objects_Path_No_Libs : String_Access := null;
1429       --  The cached value of ADA_OBJECTS_PATH for this project file with all
1430       --  object directories (no library ALI dir for library projects).
1431 
1432       Libgnarl_Needed : Yes_No_Unknown := Unknown;
1433       --  Set to True when libgnarl is needed to link
1434 
1435       Objects_Path : String_Access := null;
1436       --  The cached value of the object dir path, used during the binding
1437       --  phase of gprbuild.
1438 
1439       Objects_Path_File_With_Libs : Path_Name_Type := No_Path;
1440       --  The cached value of the object path temp file (including library
1441       --  dirs) for this project file.
1442 
1443       Objects_Path_File_Without_Libs : Path_Name_Type := No_Path;
1444       --  The cached value of the object path temp file (excluding library
1445       --  dirs) for this project file.
1446 
1447       Config_File_Name : Path_Name_Type := No_Path;
1448       --  The path name of the configuration pragmas file, if any
1449 
1450       Config_File_Temp : Boolean := False;
1451       --  True if the configuration pragmas file is a temporary file that must
1452       --  be deleted at the end.
1453 
1454       Config_Checked : Boolean := False;
1455       --  A flag to avoid checking repetitively the configuration pragmas file
1456 
1457       Depth : Natural := 0;
1458       --  The maximum depth of a project in the project graph. Depth of main
1459       --  project is 0.
1460 
1461       Unkept_Comments : Boolean := False;
1462       --  True if there are comments in the project sources that cannot be kept
1463       --  in the project tree.
1464 
1465       -----------------------------
1466       -- Qualifier-Specific data --
1467       -----------------------------
1468 
1469       --  The following fields are only valid for specific types of projects
1470 
1471       case Qualifier is
1472          when Aggregate | Aggregate_Library =>
1473             Aggregated_Projects : Aggregated_Project_List := null;
1474             --  List of aggregated projects (which could themselves be
1475             --  aggregate projects).
1476 
1477          when others =>
1478             null;
1479       end case;
1480    end record;
1481 
1482    function Empty_Project (Qualifier : Project_Qualifier) return  Project_Data;
1483    --  Return the representation of an empty project
1484 
1485    function Is_Extending
1486      (Extending : Project_Id;
1487       Extended  : Project_Id) return Boolean;
1488    --  Return True if Extending is extending the Extended project
1489 
1490    function Is_Ext
1491      (Extending : Project_Id;
1492       Extended  : Project_Id) return Boolean renames Is_Extending;
1493 
1494    function Has_Ada_Sources (Data : Project_Id) return Boolean;
1495    --  Return True if the project has Ada sources
1496 
1497    Project_Error : exception;
1498    --  Raised by some subprograms in Prj.Attr
1499 
1500    package Units_Htable is new Simple_HTable
1501      (Header_Num => Header_Num,
1502       Element    => Unit_Index,
1503       No_Element => No_Unit_Index,
1504       Key        => Name_Id,
1505       Hash       => Hash,
1506       Equal      => "=");
1507    --  Mapping of unit names to indexes in the Units table
1508 
1509    ---------------------
1510    -- Source_Iterator --
1511    ---------------------
1512 
1513    type Source_Iterator is private;
1514 
1515    function For_Each_Source
1516      (In_Tree           : Project_Tree_Ref;
1517       Project           : Project_Id := No_Project;
1518       Language          : Name_Id    := No_Name;
1519       Encapsulated_Libs : Boolean    := True;
1520       Locally_Removed   : Boolean    := True) return Source_Iterator;
1521    --  Returns an iterator for all the sources of a project tree, or a specific
1522    --  project, or a specific language. Include sources from aggregated libs if
1523    --  Aggregated_Libs is True. If Locally_Removed is set to False the
1524    --  Locally_Removed files won't be reported.
1525 
1526    function Element (Iter : Source_Iterator) return Source_Id;
1527    --  Return the current source (or No_Source if there are no more sources)
1528 
1529    procedure Next (Iter : in out Source_Iterator);
1530    --  Move on to the next source
1531 
1532    function Find_Source
1533      (In_Tree          : Project_Tree_Ref;
1534       Project          : Project_Id;
1535       In_Imported_Only : Boolean := False;
1536       In_Extended_Only : Boolean := False;
1537       Base_Name        : File_Name_Type;
1538       Index            : Int := 0) return Source_Id;
1539    --  Find the first source file with the given name.
1540    --  If In_Extended_Only is True, it will search in project and the project
1541    --     it extends, but not in the imported projects.
1542    --  Elsif In_Imported_Only is True, it will search in project and the
1543    --     projects it imports, but not in the others or in aggregated projects.
1544    --  Else it searches in the whole tree.
1545    --  If Index is specified, this only search for a source with that index.
1546 
1547    type Source_Ids is array (Positive range <>) of Source_Id;
1548    No_Sources : constant Source_Ids := (1 .. 0 => No_Source);
1549 
1550    function Find_All_Sources
1551      (In_Tree          : Project_Tree_Ref;
1552       Project          : Project_Id;
1553       In_Imported_Only : Boolean := False;
1554       In_Extended_Only : Boolean := False;
1555       Base_Name        : File_Name_Type;
1556       Index            : Int     := 0) return Source_Ids;
1557    --  Find all source files with the given name:
1558    --
1559    --    If In_Extended_Only is True, it will search in project and the project
1560    --    it extends, but not in the imported projects.
1561    --
1562    --    If Extended_Only is False, and In_Imported_Only is True, it will
1563    --    search in project and the projects it imports, but not in the others
1564    --    or in aggregated projects.
1565    --
1566    --    If both Extended_Only and In_Imported_Only are False (the default)
1567    --    then it searches the whole tree.
1568    --
1569    --  If Index is specified, this only search for sources with that index.
1570 
1571    -----------------------
1572    -- Project_Tree_Data --
1573    -----------------------
1574 
1575    package Replaced_Source_HTable is new Simple_HTable
1576      (Header_Num => Header_Num,
1577       Element    => File_Name_Type,
1578       No_Element => No_File,
1579       Key        => File_Name_Type,
1580       Hash       => Hash,
1581       Equal      => "=");
1582 
1583    type Private_Project_Tree_Data is private;
1584    --  Data for a project tree that is used only by the Project Manager
1585 
1586    type Shared_Project_Tree_Data is record
1587       Name_Lists        : Name_List_Table.Instance;
1588       Number_Lists      : Number_List_Table.Instance;
1589       String_Elements   : String_Element_Table.Instance;
1590       Variable_Elements : Variable_Element_Table.Instance;
1591       Array_Elements    : Array_Element_Table.Instance;
1592       Arrays            : Array_Table.Instance;
1593       Packages          : Package_Table.Instance;
1594       Private_Part      : Private_Project_Tree_Data;
1595       Dot_String_List   : String_List_Id := Nil_String;
1596    end record;
1597    type Shared_Project_Tree_Data_Access is access all Shared_Project_Tree_Data;
1598    --  The data that is shared among multiple trees, when these trees are
1599    --  loaded through the same aggregate project.
1600    --  To avoid ambiguities, limit the number of parameters to the
1601    --  subprograms (we would have to parse the "root project tree" since this
1602    --  is where the configuration file was loaded, in addition to the project's
1603    --  own tree) and make the comparison of projects easier, all trees store
1604    --  the lists in the same tables.
1605 
1606    type Project_Tree_Appdata is tagged null record;
1607    type Project_Tree_Appdata_Access is access all Project_Tree_Appdata'Class;
1608    --  Application-specific data that can be associated with a project tree.
1609    --  We do not make the Project_Tree_Data itself tagged for several reasons:
1610    --    - it couldn't have a default value for its discriminant
1611    --    - it would require a "factory" to allocate such data, because trees
1612    --      are created automatically when parsing aggregate projects.
1613 
1614    procedure Free (Tree : in out Project_Tree_Appdata);
1615    --  Should be overridden if your derive your own data
1616 
1617    type Project_Tree_Data (Is_Root_Tree : Boolean := True) is record
1618       --  The root tree is the one loaded by the user from the command line.
1619       --  Is_Root_Tree is only false for projects aggregated within a root
1620       --  aggregate project.
1621 
1622       Projects : Project_List;
1623       --  List of projects in this tree
1624 
1625       Replaced_Sources : Replaced_Source_HTable.Instance;
1626       --  The list of sources that have been replaced by sources with
1627       --  different file names.
1628 
1629       Replaced_Source_Number : Natural := 0;
1630       --  The number of entries in Replaced_Sources
1631 
1632       Units_HT : Units_Htable.Instance;
1633       --  Unit name to Unit_Index (and from there to Source_Id)
1634 
1635       Source_Files_HT : Source_Files_Htable.Instance;
1636       --  Base source file names to Source_Id list
1637 
1638       Source_Paths_HT : Source_Paths_Htable.Instance;
1639       --  Full path to Source_Id
1640       --  ??? What is behavior for multi-unit source files, where there are
1641       --  several source_id per file ?
1642 
1643       Source_Info_File_Name : String_Access := null;
1644       --  The name of the source info file, if specified by the builder
1645 
1646       Source_Info_File_Exists : Boolean := False;
1647       --  True when a source info file has been successfully read
1648 
1649       Shared : Shared_Project_Tree_Data_Access;
1650       --  The shared data for this tree and all aggregated trees
1651 
1652       Appdata : Project_Tree_Appdata_Access;
1653       --  Application-specific data for this tree
1654 
1655       case Is_Root_Tree is
1656          when True =>
1657             Shared_Data : aliased Shared_Project_Tree_Data;
1658             --  Do not access directly, only through Shared
1659 
1660          when False =>
1661             null;
1662       end case;
1663    end record;
1664    --  Data for a project tree
1665 
1666    function Debug_Name (Tree : Project_Tree_Ref) return Name_Id;
1667    --  If debug traces are activated, return an identitier for the project
1668    --  tree. This modifies Name_Buffer.
1669 
1670    procedure Expect (The_Token : Token_Type; Token_Image : String);
1671    --  Check that the current token is The_Token. If it is not, then output
1672    --  an error message.
1673 
1674    procedure Initialize (Tree : Project_Tree_Ref);
1675    --  This procedure must be called before using any services from the Prj
1676    --  hierarchy. Namet.Initialize must be called before Prj.Initialize.
1677 
1678    procedure Reset (Tree : Project_Tree_Ref);
1679    --  This procedure resets all the tables that are used when processing a
1680    --  project file tree. Initialize must be called before the call to Reset.
1681 
1682    package Project_Boolean_Htable is new Simple_HTable
1683      (Header_Num => Header_Num,
1684       Element    => Boolean,
1685       No_Element => False,
1686       Key        => Project_Id,
1687       Hash       => Hash,
1688       Equal      => "=");
1689    --  A table that associates a project to a boolean. This is used to detect
1690    --  whether a project was already processed for instance.
1691 
1692    generic
1693       with procedure Action (Project : Project_Id; Tree : Project_Tree_Ref);
1694    procedure For_Project_And_Aggregated
1695      (Root_Project : Project_Id;
1696       Root_Tree    : Project_Tree_Ref);
1697    --  Execute Action for Root_Project and all its aggregated projects
1698    --  recursively.
1699 
1700    generic
1701       type State is limited private;
1702       with procedure Action
1703         (Project    : Project_Id;
1704          Tree       : Project_Tree_Ref;
1705          With_State : in out State);
1706    procedure For_Every_Project_Imported
1707      (By                 : Project_Id;
1708       Tree               : Project_Tree_Ref;
1709       With_State         : in out State;
1710       Include_Aggregated : Boolean := True;
1711       Imported_First     : Boolean := False);
1712    --  Call Action for each project imported directly or indirectly by project
1713    --  By, as well as extended projects.
1714    --
1715    --  The order of processing depends on Imported_First:
1716    --
1717    --    If False, Action is called according to the order of importation: if A
1718    --    imports B, directly or indirectly, Action will be called for A before
1719    --    it is called for B. If two projects import each other directly or
1720    --    indirectly (using at least one "limited with"), it is not specified
1721    --    for which of these two projects Action will be called first.
1722    --
1723    --    The order is reversed if Imported_First is True
1724    --
1725    --  With_State may be used by Action to choose a behavior or to report some
1726    --  global result.
1727    --
1728    --  If Include_Aggregated is True, then an aggregate project will recurse
1729    --  into the projects it aggregates. Otherwise, the latter are never
1730    --  returned.
1731    --
1732    --  In_Aggregate_Lib is True if the project is in an aggregate library
1733    --
1734    --  The Tree argument passed to the callback is required in the case of
1735    --  aggregated projects, since they might not be using the same tree as 'By'
1736 
1737    type Project_Context is record
1738       In_Aggregate_Lib : Boolean;
1739       --  True if the project is part of an aggregate library
1740 
1741       From_Encapsulated_Lib : Boolean;
1742       --  True if the project is imported from an encapsulated library
1743    end record;
1744 
1745    generic
1746       type State is limited private;
1747       with procedure Action
1748         (Project    : Project_Id;
1749          Tree       : Project_Tree_Ref;
1750          Context    : Project_Context;
1751          With_State : in out State);
1752    procedure For_Every_Project_Imported_Context
1753      (By                 : Project_Id;
1754       Tree               : Project_Tree_Ref;
1755       With_State         : in out State;
1756       Include_Aggregated : Boolean := True;
1757       Imported_First     : Boolean := False);
1758    --  As for For_Every_Project_Imported but with an associated context
1759 
1760    generic
1761       with procedure Action
1762         (Project : Project_Id;
1763          Tree    : Project_Tree_Ref;
1764          Context : Project_Context);
1765    procedure For_Project_And_Aggregated_Context
1766      (Root_Project : Project_Id;
1767       Root_Tree    : Project_Tree_Ref);
1768    --  As for For_Project_And_Aggregated but with an associated context
1769 
1770    function Extend_Name
1771      (File        : File_Name_Type;
1772       With_Suffix : String) return File_Name_Type;
1773    --  Replace the extension of File with With_Suffix
1774 
1775    function Object_Name
1776      (Source_File_Name   : File_Name_Type;
1777       Object_File_Suffix : Name_Id := No_Name) return File_Name_Type;
1778    --  Returns the object file name corresponding to a source file name
1779 
1780    function Object_Name
1781      (Source_File_Name   : File_Name_Type;
1782       Source_Index       : Int;
1783       Index_Separator    : Character;
1784       Object_File_Suffix : Name_Id := No_Name) return File_Name_Type;
1785    --  Returns the object file name corresponding to a unit in a multi-source
1786    --  file.
1787 
1788    function Dependency_Name
1789      (Source_File_Name : File_Name_Type;
1790       Dependency       : Dependency_File_Kind) return File_Name_Type;
1791    --  Returns the dependency file name corresponding to a source file name
1792 
1793    function Switches_Name
1794      (Source_File_Name : File_Name_Type) return File_Name_Type;
1795    --  Returns the switches file name corresponding to a source file name
1796 
1797    procedure Set_Path_File_Var (Name : String; Value : String);
1798    --  Call Setenv, after calling To_Host_File_Spec
1799 
1800    function Current_Source_Path_File_Of
1801      (Shared : Shared_Project_Tree_Data_Access) return Path_Name_Type;
1802    --  Get the current include path file name
1803 
1804    procedure Set_Current_Source_Path_File_Of
1805      (Shared : Shared_Project_Tree_Data_Access;
1806       To     : Path_Name_Type);
1807    --  Record the current include path file name
1808 
1809    function Current_Object_Path_File_Of
1810      (Shared : Shared_Project_Tree_Data_Access) return Path_Name_Type;
1811    --  Get the current object path file name
1812 
1813    procedure Set_Current_Object_Path_File_Of
1814      (Shared : Shared_Project_Tree_Data_Access;
1815       To     : Path_Name_Type);
1816    --  Record the current object path file name
1817 
1818    -----------
1819    -- Flags --
1820    -----------
1821 
1822    type Processing_Flags is private;
1823    --  Flags used while parsing and processing a project tree to configure the
1824    --  behavior of the parser, and indicate how to report error messages. This
1825    --  structure does not allocate memory and never needs to be freed
1826 
1827    type Error_Warning is (Silent, Warning, Error);
1828    --  Severity of some situations, such as: no Ada sources in a project where
1829    --  Ada is one of the language.
1830    --
1831    --  When the situation occurs, the behaviour depends on the setting:
1832    --
1833    --    - Silent:  no action
1834    --    - Warning: issue a warning, does not cause the tool to fail
1835    --    - Error:   issue an error, causes the tool to fail
1836 
1837    type Error_Handler is access procedure
1838      (Project    : Project_Id;
1839       Is_Warning : Boolean);
1840    --  This warns when an error was found when parsing a project. The error
1841    --  itself is handled through Prj.Err (and Prj.Err.Finalize should be called
1842    --  to actually print the error). This ensures that duplicate error messages
1843    --  are always correctly removed, that errors msgs are sorted, and that all
1844    --  tools will report the same error to the user.
1845 
1846    function Create_Flags
1847      (Report_Error               : Error_Handler;
1848       When_No_Sources            : Error_Warning;
1849       Require_Sources_Other_Lang : Boolean       := True;
1850       Allow_Duplicate_Basenames  : Boolean       := True;
1851       Compiler_Driver_Mandatory  : Boolean       := False;
1852       Error_On_Unknown_Language  : Boolean       := True;
1853       Require_Obj_Dirs           : Error_Warning := Error;
1854       Allow_Invalid_External     : Error_Warning := Error;
1855       Missing_Source_Files       : Error_Warning := Error;
1856       Ignore_Missing_With        : Boolean       := False)
1857       return Processing_Flags;
1858    --  Function used to create Processing_Flags structure
1859    --
1860    --  If Allow_Duplicate_Basenames, then files with the same base names are
1861    --  authorized within a project for source-based languages (never for unit
1862    --  based languages).
1863    --
1864    --  If Compiler_Driver_Mandatory is true, then a Compiler.Driver attribute
1865    --  for each language must be defined, or we will not look for its source
1866    --  files.
1867    --
1868    --  When_No_Sources indicates what should be done when no sources of a
1869    --  language are found in a project where this language is declared.
1870    --  If Require_Sources_Other_Lang is true, then all languages must have at
1871    --  least one source file, or an error is reported via When_No_Sources. If
1872    --  it is false, this is only required for Ada (and only if it is a language
1873    --  of the project). When this parameter is set to False, we do not check
1874    --  that a proper naming scheme is defined for languages other than Ada.
1875    --
1876    --  If Report_Error is null, use the standard error reporting mechanism
1877    --  (Errout). Otherwise, report errors using Report_Error.
1878    --
1879    --  If Error_On_Unknown_Language is true, an error is displayed if some of
1880    --  the source files listed in the project do not match any naming scheme
1881    --
1882    --  If Require_Obj_Dirs is true, then all object directories must exist
1883    --  (possibly after they have been created automatically if the appropriate
1884    --  switches were specified), or an error is raised.
1885    --
1886    --  If Allow_Invalid_External is Silent, then no error is reported when an
1887    --  invalid value is used for an external variable (and it doesn't match its
1888    --  type). Instead, the first possible value is used.
1889    --
1890    --  Missing_Source_Files indicates whether it is an error or a warning that
1891    --  a source file mentioned in the Source_Files attributes is not actually
1892    --  found in the source directories. This also impacts errors for missing
1893    --  source directories.
1894    --
1895    --  If Ignore_Missing_With is True, then a "with" statement that cannot be
1896    --  resolved will simply be ignored. However, in such a case, the flag
1897    --  Incomplete_With in the project tree will be set to True.
1898    --  This is meant for use by tools so that they can properly set the
1899    --  project path in such a case:
1900    --       * no "gnatls" found (so no default project path)
1901    --       * user project sets Project.IDE'gnatls attribute to a cross gnatls
1902    --       * user project also includes a "with" that can only be resolved
1903    --         once we have found the gnatls
1904 
1905    procedure Set_Ignore_Missing_With
1906      (Flags : in out Processing_Flags;
1907       Value : Boolean);
1908    --  Set the value of component Ignore_Missing_With in Flags to Value
1909 
1910    Gprbuild_Flags   : constant Processing_Flags;
1911    Gprinstall_Flags : constant Processing_Flags;
1912    Gprclean_Flags   : constant Processing_Flags;
1913    Gprexec_Flags    : constant Processing_Flags;
1914    Gnatmake_Flags   : constant Processing_Flags;
1915    --  Flags used by the various tools. They all display the error messages
1916    --  through Prj.Err.
1917 
1918    ----------------
1919    -- Temp Files --
1920    ----------------
1921 
1922    procedure Record_Temp_File
1923      (Shared : Shared_Project_Tree_Data_Access;
1924       Path   : Path_Name_Type);
1925    --  Record the path of a newly created temporary file, so that it can be
1926    --  deleted later.
1927 
1928    procedure Delete_All_Temp_Files
1929      (Shared : Shared_Project_Tree_Data_Access);
1930    --  Delete all recorded temporary files.
1931    --  Does nothing if Debug.Debug_Flag_N is set
1932 
1933    procedure Delete_Temp_Config_Files (Project_Tree : Project_Tree_Ref);
1934    --  Delete all temporary config files. Does nothing if Debug.Debug_Flag_N is
1935    --  set or if Project_Tree is null. This initially came from gnatmake
1936    --  ??? Should this be combined with Delete_All_Temp_Files above
1937 
1938    procedure Delete_Temporary_File
1939      (Shared : Shared_Project_Tree_Data_Access := null;
1940       Path   : Path_Name_Type);
1941    --  Delete a temporary file from the disk. The file is also removed from the
1942    --  list of temporary files to delete at the end of the program, in case
1943    --  another program running on the same machine has recreated it. Does
1944    --  nothing if Debug.Debug_Flag_N is set
1945 
1946    Virtual_Prefix : constant String := "v$";
1947    --  The prefix for virtual extending projects. Because of the '$', which is
1948    --  normally forbidden for project names, there cannot be any name clash.
1949 
1950    -----------
1951    -- Debug --
1952    -----------
1953 
1954    type Verbosity is (Default, Medium, High);
1955    pragma Ordered (Verbosity);
1956    --  Verbosity when parsing GNAT Project Files
1957    --    Default is default (very quiet, if no errors).
1958    --    Medium is more verbose.
1959    --    High is extremely verbose.
1960 
1961    Current_Verbosity : Verbosity := Default;
1962    --  The current value of the verbosity the project files are parsed with
1963 
1964    procedure Debug_Indent;
1965    --  Inserts a series of blanks depending on the current indentation level
1966 
1967    procedure Debug_Output (Str : String);
1968    procedure Debug_Output (Str : String; Str2 : Name_Id);
1969    --  If Current_Verbosity is not Default, outputs Str.
1970    --  This indents Str based on the current indentation level for traces
1971    --  Debug_Error is intended to be used to report an error in the traces.
1972 
1973    procedure Debug_Increase_Indent
1974      (Str : String := ""; Str2 : Name_Id := No_Name);
1975    procedure Debug_Decrease_Indent (Str : String := "");
1976    --  Increase or decrease the indentation level for debug traces. This
1977    --  indentation level only affects output done through Debug_Output.
1978 
1979 private
1980    All_Packages : constant String_List_Access := null;
1981 
1982    No_Project_Tree : constant Project_Tree_Ref := null;
1983 
1984    Ignored : constant Variable_Kind := Single;
1985 
1986    Nil_Variable_Value : constant Variable_Value :=
1987                           (Project  => No_Project,
1988                            Kind     => Undefined,
1989                            Location => No_Location,
1990                            Default  => False);
1991 
1992    type Source_Iterator is record
1993       In_Tree : Project_Tree_Ref;
1994 
1995       Project      : Project_List;
1996       All_Projects : Boolean;
1997       --  Current project and whether we should move on to the next
1998 
1999       Language : Language_Ptr;
2000       --  Current language processed
2001 
2002       Language_Name : Name_Id;
2003       --  Only sources of this language will be returned (or all if No_Name)
2004 
2005       Current : Source_Id;
2006 
2007       Encapsulated_Libs : Boolean;
2008       --  True if we want to include the sources from encapsulated libs
2009 
2010       Locally_Removed : Boolean;
2011    end record;
2012 
2013    procedure Add_To_Buffer
2014      (S    : String;
2015       To   : in out String_Access;
2016       Last : in out Natural);
2017    --  Append a String to the Buffer
2018 
2019    --  Table used to store the path name of all the created temporary files, so
2020    --  that they can be deleted at the end, or when the program is interrupted.
2021 
2022    package Temp_Files_Table is new GNAT.Dynamic_Tables
2023      (Table_Component_Type => Path_Name_Type,
2024       Table_Index_Type     => Integer,
2025       Table_Low_Bound      => 1,
2026       Table_Initial        => 10,
2027       Table_Increment      => 10);
2028 
2029    --  The following type is used to represent the part of a project tree which
2030    --  is private to the Project Manager.
2031 
2032    type Private_Project_Tree_Data is record
2033       Temp_Files   : Temp_Files_Table.Instance;
2034       --  Temporary files created as part of running tools (pragma files,
2035       --  mapping files,...)
2036 
2037       Current_Source_Path_File : Path_Name_Type := No_Path;
2038       --  Current value of project source path file env var. Used to avoid
2039       --  setting the env var to the same value. When different from No_Path,
2040       --  this indicates that environment variables were created and should be
2041       --  deassigned to avoid polluting the environment. For gnatmake only.
2042 
2043       Current_Object_Path_File : Path_Name_Type := No_Path;
2044       --  Current value of project object path file env var. Used to avoid
2045       --  setting the env var to the same value.
2046       --  gnatmake only
2047    end record;
2048 
2049    --  The following type is used to hold processing flags which show what
2050    --  functions are required for the various tools that are handled.
2051 
2052    type Processing_Flags is record
2053       Require_Sources_Other_Lang : Boolean;
2054       Report_Error               : Error_Handler;
2055       When_No_Sources            : Error_Warning;
2056       Allow_Duplicate_Basenames  : Boolean;
2057       Compiler_Driver_Mandatory  : Boolean;
2058       Error_On_Unknown_Language  : Boolean;
2059       Require_Obj_Dirs           : Error_Warning;
2060       Allow_Invalid_External     : Error_Warning;
2061       Missing_Source_Files       : Error_Warning;
2062       Ignore_Missing_With        : Boolean;
2063 
2064       Incomplete_Withs : Boolean := False;
2065       --  This flag is set to True when the projects are parsed while ignoring
2066       --  missing withed project and some withed projects are not found.
2067 
2068    end record;
2069 
2070    Gprbuild_Flags   : constant Processing_Flags :=
2071                         (Report_Error               => null,
2072                          When_No_Sources            => Warning,
2073                          Require_Sources_Other_Lang => True,
2074                          Allow_Duplicate_Basenames  => False,
2075                          Compiler_Driver_Mandatory  => True,
2076                          Error_On_Unknown_Language  => True,
2077                          Require_Obj_Dirs           => Error,
2078                          Allow_Invalid_External     => Error,
2079                          Missing_Source_Files       => Error,
2080                          Ignore_Missing_With        => False,
2081                          Incomplete_Withs           => False);
2082 
2083    Gprinstall_Flags : constant Processing_Flags :=
2084                         (Report_Error               => null,
2085                          When_No_Sources            => Warning,
2086                          Require_Sources_Other_Lang => True,
2087                          Allow_Duplicate_Basenames  => False,
2088                          Compiler_Driver_Mandatory  => True,
2089                          Error_On_Unknown_Language  => True,
2090                          Require_Obj_Dirs           => Silent,
2091                          Allow_Invalid_External     => Error,
2092                          Missing_Source_Files       => Error,
2093                          Ignore_Missing_With        => False,
2094                          Incomplete_Withs           => False);
2095 
2096    Gprclean_Flags   : constant Processing_Flags :=
2097                         (Report_Error               => null,
2098                          When_No_Sources            => Warning,
2099                          Require_Sources_Other_Lang => True,
2100                          Allow_Duplicate_Basenames  => False,
2101                          Compiler_Driver_Mandatory  => True,
2102                          Error_On_Unknown_Language  => True,
2103                          Require_Obj_Dirs           => Warning,
2104                          Allow_Invalid_External     => Error,
2105                          Missing_Source_Files       => Error,
2106                          Ignore_Missing_With        => False,
2107                          Incomplete_Withs           => False);
2108 
2109    Gprexec_Flags    : constant Processing_Flags :=
2110                         (Report_Error               => null,
2111                          When_No_Sources            => Silent,
2112                          Require_Sources_Other_Lang => False,
2113                          Allow_Duplicate_Basenames  => False,
2114                          Compiler_Driver_Mandatory  => False,
2115                          Error_On_Unknown_Language  => True,
2116                          Require_Obj_Dirs           => Silent,
2117                          Allow_Invalid_External     => Error,
2118                          Missing_Source_Files       => Silent,
2119                          Ignore_Missing_With        => False,
2120                          Incomplete_Withs           => False);
2121 
2122    Gnatmake_Flags   : constant Processing_Flags :=
2123                         (Report_Error               => null,
2124                          When_No_Sources            => Error,
2125                          Require_Sources_Other_Lang => False,
2126                          Allow_Duplicate_Basenames  => False,
2127                          Compiler_Driver_Mandatory  => False,
2128                          Error_On_Unknown_Language  => False,
2129                          Require_Obj_Dirs           => Error,
2130                          Allow_Invalid_External     => Error,
2131                          Missing_Source_Files       => Error,
2132                          Ignore_Missing_With        => False,
2133                          Incomplete_Withs           => False);
2134 
2135 end Prj;