OSDN Git Service

2009-11-30 Robert Dewar <dewar@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / prj.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                                  P R J                                   --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --          Copyright (C) 2001-2009, 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 Scans;  use Scans;
35 with Types;  use Types;
36
37 with GNAT.Dynamic_HTables; use GNAT.Dynamic_HTables;
38 with GNAT.Dynamic_Tables;
39 with GNAT.OS_Lib;          use GNAT.OS_Lib;
40
41 package Prj is
42
43    All_Other_Names : constant Name_Id := Names_High_Bound;
44    --  Name used to replace others as an index of an associative array
45    --  attribute in situations where this is allowed.
46
47    Subdirs : String_Ptr := null;
48    --  The value after the equal sign in switch --subdirs=...
49    --  Contains the relative subdirectory.
50
51    type Library_Support is (None, Static_Only, Full);
52    --  Support for Library Project File.
53    --  - None: Library Project Files are not supported at all
54    --  - Static_Only: Library Project Files are only supported for static
55    --    libraries.
56    --  - Full: Library Project Files are supported for static and dynamic
57    --    (shared) libraries.
58
59    type Yes_No_Unknown is (Yes, No, Unknown);
60    --  Tri-state to decide if -lgnarl is needed when linking
61
62    type Project_Qualifier is
63      (Unspecified,
64       Standard,
65       Library,
66       Configuration,
67       Dry,
68       Aggregate,
69       Aggregate_Library);
70    --  Qualifiers that can prefix the reserved word "project" in a project
71    --  file:
72    --    Standard:             standard project ...
73    --    Library:              library project is ...
74    --    Dry:                  abstract project is
75    --    Aggregate:            aggregate project is
76    --    Aggregate_Library:    aggregate library project is ...
77    --    Configuration:        configuration project is ...
78
79    All_Packages : constant String_List_Access;
80    --  Default value of parameter Packages of procedures Parse, in Prj.Pars and
81    --  Prj.Part, indicating that all packages should be checked.
82
83    type Project_Tree_Data;
84    type Project_Tree_Ref is access all Project_Tree_Data;
85    --  Reference to a project tree. Several project trees may exist in memory
86    --  at the same time.
87
88    No_Project_Tree : constant Project_Tree_Ref;
89
90    procedure Free (Tree : in out Project_Tree_Ref);
91    --  Free memory associated with the tree
92
93    Config_Project_File_Extension : String := ".cgpr";
94    Project_File_Extension : String := ".gpr";
95    --  The standard config and user project file name extensions. They are not
96    --  constants, because Canonical_Case_File_Name is called on these variables
97    --  in the body of Prj.
98
99    function Empty_File   return File_Name_Type;
100    function Empty_String return Name_Id;
101    --  Return the id for an empty string ""
102
103    type Path_Information is record
104       Name         : Path_Name_Type := No_Path;
105       Display_Name : Path_Name_Type := No_Path;
106    end record;
107    --  Directory names always end with a directory separator
108
109    No_Path_Information : constant Path_Information := (No_Path, No_Path);
110
111    type Project_Data;
112    type Project_Id is access all Project_Data;
113    No_Project : constant Project_Id := null;
114    --  Id of a Project File
115
116    type String_List_Id is new Nat;
117    Nil_String : constant String_List_Id := 0;
118    type String_Element is record
119       Value         : Name_Id        := No_Name;
120       Index         : Int            := 0;
121       Display_Value : Name_Id        := No_Name;
122       Location      : Source_Ptr     := No_Location;
123       Flag          : Boolean        := False;
124       Next          : String_List_Id := Nil_String;
125    end record;
126    --  To hold values for string list variables and array elements.
127    --  Component Flag may be used for various purposes. For source
128    --  directories, it indicates if the directory contains Ada source(s).
129
130    package String_Element_Table is new GNAT.Dynamic_Tables
131      (Table_Component_Type => String_Element,
132       Table_Index_Type     => String_List_Id,
133       Table_Low_Bound      => 1,
134       Table_Initial        => 200,
135       Table_Increment      => 100);
136    --  The table for string elements in string lists
137
138    type Variable_Kind is (Undefined, List, Single);
139    --  Different kinds of variables
140
141    subtype Defined_Variable_Kind is Variable_Kind range List .. Single;
142    --  The defined kinds of variables
143
144    Ignored : constant Variable_Kind;
145    --  Used to indicate that a package declaration must be ignored
146    --  while processing the project tree (unknown package name).
147
148    type Variable_Value (Kind : Variable_Kind := Undefined) is record
149       Project  : Project_Id := No_Project;
150       Location : Source_Ptr := No_Location;
151       Default  : Boolean    := False;
152       case Kind is
153          when Undefined =>
154             null;
155          when List =>
156             Values : String_List_Id := Nil_String;
157          when Single =>
158             Value : Name_Id := No_Name;
159             Index : Int     := 0;
160       end case;
161    end record;
162    --  Values for variables and array elements. Default is True if the
163    --  current value is the default one for the variable
164
165    Nil_Variable_Value : constant Variable_Value;
166    --  Value of a non existing variable or array element
167
168    type Variable_Id is new Nat;
169    No_Variable : constant Variable_Id := 0;
170    type Variable is record
171       Next  : Variable_Id := No_Variable;
172       Name  : Name_Id;
173       Value : Variable_Value;
174    end record;
175    --  To hold the list of variables in a project file and in packages
176
177    package Variable_Element_Table is new GNAT.Dynamic_Tables
178      (Table_Component_Type => Variable,
179       Table_Index_Type     => Variable_Id,
180       Table_Low_Bound      => 1,
181       Table_Initial        => 200,
182       Table_Increment      => 100);
183    --  The table of variable in list of variables
184
185    type Array_Element_Id is new Nat;
186    No_Array_Element : constant Array_Element_Id := 0;
187    type Array_Element is record
188       Index                : Name_Id;
189       Src_Index            : Int := 0;
190       Index_Case_Sensitive : Boolean := True;
191       Value                : Variable_Value;
192       Next                 : Array_Element_Id := No_Array_Element;
193    end record;
194    --  Each Array_Element represents an array element and is linked (Next)
195    --  to the next array element, if any, in the array.
196
197    package Array_Element_Table is new GNAT.Dynamic_Tables
198      (Table_Component_Type => Array_Element,
199       Table_Index_Type     => Array_Element_Id,
200       Table_Low_Bound      => 1,
201       Table_Initial        => 200,
202       Table_Increment      => 100);
203    --  The table that contains all array elements
204
205    type Array_Id is new Nat;
206    No_Array : constant Array_Id := 0;
207    type Array_Data is record
208       Name     : Name_Id          := No_Name;
209       Location : Source_Ptr       := No_Location;
210       Value    : Array_Element_Id := No_Array_Element;
211       Next     : Array_Id         := No_Array;
212    end record;
213    --  Each Array_Data value represents an array.
214    --  Value is the id of the first element.
215    --  Next is the id of the next array in the project file or package.
216
217    package Array_Table is new GNAT.Dynamic_Tables
218      (Table_Component_Type => Array_Data,
219       Table_Index_Type     => Array_Id,
220       Table_Low_Bound      => 1,
221       Table_Initial        => 200,
222       Table_Increment      => 100);
223    --  The table that contains all arrays
224
225    type Package_Id is new Nat;
226    No_Package : constant Package_Id := 0;
227    type Declarations is record
228       Variables  : Variable_Id := No_Variable;
229       Attributes : Variable_Id := No_Variable;
230       Arrays     : Array_Id    := No_Array;
231       Packages   : Package_Id  := No_Package;
232    end record;
233    --  Contains the declarations (variables, single and array attributes,
234    --  packages) for a project or a package in a project.
235
236    No_Declarations : constant Declarations :=
237      (Variables  => No_Variable,
238       Attributes => No_Variable,
239       Arrays     => No_Array,
240       Packages   => No_Package);
241    --  Default value of Declarations: indicates that there is no declarations
242
243    type Package_Element is record
244       Name   : Name_Id      := No_Name;
245       Decl   : Declarations := No_Declarations;
246       Parent : Package_Id   := No_Package;
247       Next   : Package_Id   := No_Package;
248    end record;
249    --  A package (includes declarations that may include other packages)
250
251    package Package_Table is new GNAT.Dynamic_Tables
252      (Table_Component_Type => Package_Element,
253       Table_Index_Type     => Package_Id,
254       Table_Low_Bound      => 1,
255       Table_Initial        => 100,
256       Table_Increment      => 100);
257    --  The table that contains all packages
258
259    type Language_Data;
260    type Language_Ptr is access all Language_Data;
261    --  Index of language data
262
263    No_Language_Index : constant Language_Ptr := null;
264    --  Constant indicating that there is no language data
265
266    function Get_Language_From_Name
267      (Project : Project_Id;
268       Name    : String) return Language_Ptr;
269    --  Get a language from a project. This might return null if no such
270    --  language exists in the project
271
272    Max_Header_Num : constant := 6150;
273    type Header_Num is range 0 .. Max_Header_Num;
274    --  Size for hash table below. The upper bound is an arbitrary value, the
275    --  value here was chosen after testing to determine a good compromise
276    --  between speed of access and memory usage.
277
278    function Hash (Name : Name_Id)        return Header_Num;
279    function Hash (Name : File_Name_Type) return Header_Num;
280    function Hash (Name : Path_Name_Type) return Header_Num;
281    function Hash (Project : Project_Id) return Header_Num;
282    --  Used for computing hash values for names put into above hash table
283
284    type Language_Kind is (File_Based, Unit_Based);
285    --  Type for the kind of language. All languages are file based, except Ada
286    --  which is unit based.
287
288    type Dependency_File_Kind is (None, Makefile, ALI_File);
289    --  Type of dependency to be checked: no dependency file, Makefile fragment
290    --  or ALI file (for Ada).
291
292    Makefile_Dependency_Suffix : constant String := ".d";
293    ALI_Dependency_Suffix      : constant String := ".ali";
294
295    Switches_Dependency_Suffix : constant String := ".cswi";
296
297    Binder_Exchange_Suffix     : constant String := ".bexch";
298    --  Suffix for binder exchange files
299
300    Library_Exchange_Suffix     : constant String := ".lexch";
301    --  Suffix for library exchange files
302
303    type Name_List_Index is new Nat;
304    No_Name_List            : constant Name_List_Index := 0;
305
306    type Name_Node is record
307       Name : Name_Id         := No_Name;
308       Next : Name_List_Index := No_Name_List;
309    end record;
310
311    package Name_List_Table is new GNAT.Dynamic_Tables
312      (Table_Component_Type => Name_Node,
313       Table_Index_Type     => Name_List_Index,
314       Table_Low_Bound      => 1,
315       Table_Initial        => 10,
316       Table_Increment      => 100);
317    --  The table for lists of names
318
319    function Length
320      (Table : Name_List_Table.Instance; List : Name_List_Index) return Natural;
321    --  Return the number of elements in that list
322
323    type Number_List_Index is new Nat;
324    No_Number_List : constant Number_List_Index := 0;
325
326    type Number_Node is record
327       Number : Natural           := 0;
328       Next   : Number_List_Index := No_Number_List;
329    end record;
330
331    package Number_List_Table is new GNAT.Dynamic_Tables
332      (Table_Component_Type => Number_Node,
333       Table_Index_Type     => Number_List_Index,
334       Table_Low_Bound      => 1,
335       Table_Initial        => 10,
336       Table_Increment      => 100);
337    --  The table for lists of numbers
338
339    package Mapping_Files_Htable is new Simple_HTable
340      (Header_Num => Header_Num,
341       Element    => Path_Name_Type,
342       No_Element => No_Path,
343       Key        => Path_Name_Type,
344       Hash       => Hash,
345       Equal      => "=");
346    --  A hash table to store the mapping files that are not used
347
348    type Lang_Naming_Data is record
349       Dot_Replacement : File_Name_Type := No_File;
350       --  The string to replace '.' in the source file name (for Ada)
351
352       Casing : Casing_Type := All_Lower_Case;
353       --  The casing of the source file name (for Ada)
354
355       Separate_Suffix : File_Name_Type := No_File;
356       --  String to append to unit name for source file name of an Ada subunit
357
358       Spec_Suffix : File_Name_Type := No_File;
359       --  The string to append to the unit name for the
360       --  source file name of a spec.
361
362       Body_Suffix : File_Name_Type := No_File;
363       --  The string to append to the unit name for the
364       --  source file name of a body.
365    end record;
366
367    No_Lang_Naming_Data : constant Lang_Naming_Data :=
368                            (Dot_Replacement => No_File,
369                             Casing          => All_Lower_Case,
370                             Separate_Suffix => No_File,
371                             Spec_Suffix     => No_File,
372                             Body_Suffix     => No_File);
373
374    function Is_Standard_GNAT_Naming (Naming : Lang_Naming_Data) return Boolean;
375    --  True if the naming scheme is GNAT's default naming scheme. This
376    --  is to take into account shortened names like "Ada." (a-), "System." (s-)
377    --  and so on.
378
379    type Source_Data;
380    type Source_Id is access all Source_Data;
381
382    function Is_Compilable (Source : Source_Id) return Boolean;
383    pragma Inline (Is_Compilable);
384    --  Return True if we know how to compile Source (i.e. if a compiler is
385    --  defined). This doesn't indicate whether the source should be compiled.
386
387    function Object_To_Global_Archive (Source : Source_Id) return Boolean;
388    pragma Inline (Object_To_Global_Archive);
389    --  Return True if the object file should be put in the global archive.
390    --  This is for Ada, when only the closure of a main needs to be
391    --  (re)compiled.
392
393    function Other_Part (Source : Source_Id) return Source_Id;
394    pragma Inline (Other_Part);
395    --  Source ID for the other part, if any: for a spec, indicates its body;
396    --  for a body, indicates its spec.
397
398    No_Source : constant Source_Id := null;
399
400    type Path_Syntax_Kind is
401      (Canonical,
402       --  Unix style
403
404       Host);
405       --  Host specific syntax, for example on VMS (the default)
406
407    type Language_Config is record
408       Kind : Language_Kind := File_Based;
409       --  Kind of language. All languages are file based, except Ada which is
410       --  unit based.
411
412       Naming_Data : Lang_Naming_Data;
413       --  The naming data for the languages (prefixes, etc.)
414
415       Include_Compatible_Languages : Name_List_Index := No_Name_List;
416       --  The list of languages that are "include compatible" with this
417       --  language. A language B (for example "C") is "include compatible" with
418       --  a language A (for example "C++") if it is expected that sources of
419       --  language A may "include" header files from language B.
420
421       Compiler_Driver : File_Name_Type := No_File;
422       --  The name of the executable for the compiler of the language
423
424       Compiler_Driver_Path : String_Access := null;
425       --  The path name of the executable for the compiler of the language
426
427       Compiler_Leading_Required_Switches : Name_List_Index := No_Name_List;
428       --  The list of initial switches that are required as a minimum to invoke
429       --  the compiler driver.
430
431       Compiler_Trailing_Required_Switches : Name_List_Index := No_Name_List;
432       --  The list of final switches that are required as a minimum to invoke
433       --  the compiler driver.
434
435       Path_Syntax                  : Path_Syntax_Kind := Host;
436       --  Value may be Canonical (Unix style) or Host (host syntax, for example
437       --  on VMS for DEC C).
438
439       Object_File_Suffix                 : Name_Id := No_Name;
440       --  Optional alternate object file suffix
441
442       Object_File_Switches               : Name_List_Index := No_Name_List;
443       --  Optional object file switches. When this is defined, the switches
444       --  are used to specify the object file. The object file name is appended
445       --  to the last switch in the list. Example: ("-o", "").
446
447       Compilation_PIC_Option : Name_List_Index := No_Name_List;
448       --  The option(s) to compile a source in Position Independent Code for
449       --  shared libraries. Specified in the configuration. When not specified,
450       --  there is no need for such switch.
451
452       Object_Generated             : Boolean := True;
453       --  False in no object file is generated
454
455       Objects_Linked               : Boolean := True;
456       --  False if object files are not use to link executables and build
457       --  libraries.
458
459       Runtime_Library_Dir        : Name_Id := No_Name;
460       --  Path name of the runtime library directory, if any
461
462       Runtime_Source_Dir        : Name_Id := No_Name;
463       --  Path name of the runtime source directory, if any
464
465       Mapping_File_Switches  : Name_List_Index := No_Name_List;
466       --  The option(s) to provide a mapping file to the compiler. Specified in
467       --  the configuration. When value is No_Name_List, there is no mapping
468       --  file.
469
470       Mapping_Spec_Suffix        : File_Name_Type       := No_File;
471       --  Placeholder representing the spec suffix in a mapping file
472
473       Mapping_Body_Suffix        : File_Name_Type       := No_File;
474       --  Placeholder representing the body suffix in a mapping file
475
476       Config_File_Switches       : Name_List_Index      := No_Name_List;
477       --  The option(s) to provide a config file to the compiler. Specified in
478       --  the configuration. When value is No_Name_List, there is no config
479       --  file.
480
481       Dependency_Kind            : Dependency_File_Kind := None;
482       --  The kind of dependency to be checked: none, Makefile fragment or
483       --  ALI file (for Ada).
484
485       Dependency_Option          : Name_List_Index      := No_Name_List;
486       --  The option(s) to be used to create the dependency file. When value is
487       --  No_Name_List, there is not such option(s).
488
489       Compute_Dependency         : Name_List_Index      := No_Name_List;
490       --  Hold the value of attribute Dependency_Driver, if declared for the
491       --  language.
492
493       Include_Option             : Name_List_Index      := No_Name_List;
494       --  Hold the value of attribute Include_Switches, if declared for the
495       --  language.
496
497       Include_Path : Name_Id := No_Name;
498       --  Name of environment variable declared by attribute Include_Path for
499       --  the language.
500
501       Include_Path_File : Name_Id := No_Name;
502       --  Name of environment variable declared by attribute Include_Path_File
503       --  for the language.
504
505       Objects_Path : Name_Id := No_Name;
506       --  Name of environment variable declared by attribute Objects_Path for
507       --  the language.
508
509       Objects_Path_File : Name_Id := No_Name;
510       --  Name of environment variable declared by attribute Objects_Path_File
511       --  for the language.
512
513       Config_Body                : Name_Id         := No_Name;
514       --  The template for a pragma Source_File_Name(_Project) for a specific
515       --  file name of a body.
516
517       Config_Spec           : Name_Id         := No_Name;
518       --  The template for a pragma Source_File_Name(_Project) for a specific
519       --  file name of a spec.
520
521       Config_Body_Pattern   : Name_Id         := No_Name;
522       --  The template for a pragma Source_File_Name(_Project) for a naming
523       --  body pattern.
524
525       Config_Spec_Pattern   : Name_Id         := No_Name;
526       --  The template for a pragma Source_File_Name(_Project) for a naming
527       --  spec pattern.
528
529       Config_File_Unique         : Boolean         := False;
530       --  Indicate if the config file specified to the compiler needs to be
531       --  unique. If it is unique, then all config files are concatenated into
532       --  a temp config file.
533
534       Binder_Driver              : File_Name_Type  := No_File;
535       --  The name of the binder driver for the language, if any
536
537       Binder_Driver_Path         : Path_Name_Type  := No_Path;
538       --  The path name of the binder driver
539
540       Binder_Required_Switches   : Name_List_Index      := No_Name_List;
541       --  Hold the value of attribute Binder'Required_Switches for the language
542
543       Binder_Prefix              : Name_Id         := No_Name;
544       --  Hold the value of attribute Binder'Prefix for the language
545
546       Toolchain_Version          : Name_Id         := No_Name;
547       --  Hold the value of attribute Toolchain_Version for the language
548
549       Toolchain_Description      : Name_Id         := No_Name;
550       --  Hold the value of attribute Toolchain_Description for the language
551
552    end record;
553    --  Record describing the configuration of a language
554
555    No_Language_Config : constant Language_Config :=
556                           (Kind                         => File_Based,
557                            Naming_Data                  => No_Lang_Naming_Data,
558                            Include_Compatible_Languages => No_Name_List,
559                            Compiler_Driver              => No_File,
560                            Compiler_Driver_Path         => null,
561                            Compiler_Leading_Required_Switches  => No_Name_List,
562                            Compiler_Trailing_Required_Switches => No_Name_List,
563                            Path_Syntax                  => Canonical,
564                            Object_File_Suffix           => No_Name,
565                            Object_File_Switches         => No_Name_List,
566                            Compilation_PIC_Option       => No_Name_List,
567                            Object_Generated             => True,
568                            Objects_Linked               => True,
569                            Runtime_Library_Dir          => No_Name,
570                            Runtime_Source_Dir           => No_Name,
571                            Mapping_File_Switches        => No_Name_List,
572                            Mapping_Spec_Suffix          => No_File,
573                            Mapping_Body_Suffix          => No_File,
574                            Config_File_Switches         => No_Name_List,
575                            Dependency_Kind              => None,
576                            Dependency_Option            => No_Name_List,
577                            Compute_Dependency           => No_Name_List,
578                            Include_Option               => No_Name_List,
579                            Include_Path                 => No_Name,
580                            Include_Path_File            => No_Name,
581                            Objects_Path                 => No_Name,
582                            Objects_Path_File            => No_Name,
583                            Config_Body                  => No_Name,
584                            Config_Spec                  => No_Name,
585                            Config_Body_Pattern          => No_Name,
586                            Config_Spec_Pattern          => No_Name,
587                            Config_File_Unique           => False,
588                            Binder_Driver                => No_File,
589                            Binder_Driver_Path           => No_Path,
590                            Binder_Required_Switches     => No_Name_List,
591                            Binder_Prefix                => No_Name,
592                            Toolchain_Version            => No_Name,
593                            Toolchain_Description        => No_Name);
594
595    type Language_Data is record
596       Name          : Name_Id         := No_Name;
597       Display_Name  : Name_Id         := No_Name;
598       Config        : Language_Config := No_Language_Config;
599       First_Source  : Source_Id       := No_Source;
600       Mapping_Files : Mapping_Files_Htable.Instance :=
601                         Mapping_Files_Htable.Nil;
602       Next          : Language_Ptr  := No_Language_Index;
603    end record;
604
605    No_Language_Data : constant Language_Data :=
606                         (Name          => No_Name,
607                          Display_Name  => No_Name,
608                          Config        => No_Language_Config,
609                          First_Source  => No_Source,
610                          Mapping_Files => Mapping_Files_Htable.Nil,
611                          Next          => No_Language_Index);
612
613    type Language_List_Element;
614    type Language_List is access all Language_List_Element;
615    type Language_List_Element is record
616       Language : Language_Ptr := No_Language_Index;
617       Next     : Language_List;
618    end record;
619
620    type Source_Kind is (Spec, Impl, Sep);
621    subtype Spec_Or_Body is Source_Kind range Spec .. Impl;
622
623    --  The following declarations declare a structure used to store the Name
624    --  and File and Path names of a unit, with a reference to its GNAT Project
625    --  File(s). Some units might have neither Spec nor Impl when they were
626    --  created for a "separate".
627
628    type File_Names_Data is array (Spec_Or_Body) of Source_Id;
629
630    type Unit_Data is record
631       Name       : Name_Id := No_Name;
632       File_Names : File_Names_Data;
633    end record;
634
635    type Unit_Index is access all Unit_Data;
636
637    No_Unit_Index : constant Unit_Index := null;
638    --  Used to indicate a null entry for no unit
639
640    --  Structure to define source data
641
642    type Source_Data is record
643       Project                : Project_Id          := No_Project;
644       --  Project of the source
645
646       Source_Dir_Rank        : Natural             := 0;
647       --  The rank of the source directory in list declared with attribute
648       --  Source_Dirs. Two source files with the same name cannot appears in
649       --  different directory with the same rank. That can happen when the
650       --  recursive notation <dir>/** is used in attribute Source_Dirs.
651
652       Language               : Language_Ptr        := No_Language_Index;
653       --  Index of the language. This is an index into
654       --  Project_Tree.Languages_Data.
655
656       In_Interfaces          : Boolean             := True;
657       --  False when the source is not included in interfaces, when attribute
658       --  Interfaces is declared.
659
660       Declared_In_Interfaces : Boolean             := False;
661       --  True when source is declared in attribute Interfaces
662
663       Alternate_Languages    : Language_List       := null;
664       --  List of languages a header file may also be, in addition of language
665       --  Language_Name.
666
667       Kind                   : Source_Kind         := Spec;
668       --  Kind of the source: spec, body or subunit
669
670       Unit                   : Unit_Index          := No_Unit_Index;
671       --  Name of the unit, if language is unit based. This is only set for
672       --  those files that are part of the compilation set (for instance a
673       --  file in an extended project that is overridden will not have this
674       --  field set).
675
676       Index                  : Int                 := 0;
677       --  Index of the source in a multi unit source file (the same Source_Data
678       --  is duplicated several times when there are several units in the same
679       --  file). Index is 0 if there is either no unit or a single one, and
680       --  starts at 1 when there are multiple units
681
682       Locally_Removed        : Boolean             := False;
683       --  True if the source has been "excluded"
684
685       Replaced_By            : Source_Id           := No_Source;
686
687       File                   : File_Name_Type      := No_File;
688       --  Canonical file name of the source
689
690       Display_File           : File_Name_Type      := No_File;
691       --  File name of the source, for display purposes
692
693       Path                   : Path_Information    := No_Path_Information;
694       --  Path name of the source
695
696       Source_TS              : Time_Stamp_Type     := Empty_Time_Stamp;
697       --  Time stamp of the source file
698
699       Object_Project         : Project_Id          := No_Project;
700       --  Project where the object file is. This might be different from
701       --  Project when using extending project files.
702
703       Object                 : File_Name_Type      := No_File;
704       --  File name of the object file
705
706       Current_Object_Path    : Path_Name_Type      := No_Path;
707       --  Object path of an existing object file
708
709       Object_Path            : Path_Name_Type      := No_Path;
710       --  Object path of the real object file
711
712       Object_TS              : Time_Stamp_Type     := Empty_Time_Stamp;
713       --  Object file time stamp
714
715       Dep_Name               : File_Name_Type      := No_File;
716       --  Dependency file simple name
717
718       Current_Dep_Path       : Path_Name_Type      := No_Path;
719       --  Path name of an existing dependency file
720
721       Dep_Path               : Path_Name_Type      := No_Path;
722       --  Path name of the real dependency file
723
724       Dep_TS                 : Time_Stamp_Type     := Empty_Time_Stamp;
725       --  Dependency file time stamp
726
727       Switches               : File_Name_Type      := No_File;
728       --  File name of the switches file. For all languages, this is a file
729       --  that ends with the .cswi extension.
730
731       Switches_Path          : Path_Name_Type      := No_Path;
732       --  Path name of the switches file
733
734       Switches_TS            : Time_Stamp_Type     := Empty_Time_Stamp;
735       --  Switches file time stamp
736
737       Naming_Exception       : Boolean             := False;
738       --  True if the source has an exceptional name
739
740       Next_In_Lang           : Source_Id           := No_Source;
741       --  Link to another source of the same language in the same project
742    end record;
743
744    No_Source_Data : constant Source_Data :=
745                       (Project                => No_Project,
746                        Source_Dir_Rank        => 0,
747                        Language               => No_Language_Index,
748                        In_Interfaces          => True,
749                        Declared_In_Interfaces => False,
750                        Alternate_Languages    => null,
751                        Kind                   => Spec,
752                        Unit                   => No_Unit_Index,
753                        Index                  => 0,
754                        Locally_Removed        => False,
755                        Replaced_By            => No_Source,
756                        File                   => No_File,
757                        Display_File           => No_File,
758                        Path                   => No_Path_Information,
759                        Source_TS              => Empty_Time_Stamp,
760                        Object_Project         => No_Project,
761                        Object                 => No_File,
762                        Current_Object_Path    => No_Path,
763                        Object_Path            => No_Path,
764                        Object_TS              => Empty_Time_Stamp,
765                        Dep_Name               => No_File,
766                        Current_Dep_Path       => No_Path,
767                        Dep_Path               => No_Path,
768                        Dep_TS                 => Empty_Time_Stamp,
769                        Switches               => No_File,
770                        Switches_Path          => No_Path,
771                        Switches_TS            => Empty_Time_Stamp,
772                        Naming_Exception       => False,
773                        Next_In_Lang           => No_Source);
774
775    package Source_Paths_Htable is new Simple_HTable
776      (Header_Num => Header_Num,
777       Element    => Source_Id,
778       No_Element => No_Source,
779       Key        => Path_Name_Type,
780       Hash       => Hash,
781       Equal      => "=");
782    --  Mapping of source paths to source ids
783
784    package Unit_Sources_Htable is new Simple_HTable
785      (Header_Num => Header_Num,
786       Element    => Source_Id,
787       No_Element => No_Source,
788       Key        => Name_Id,
789       Hash       => Hash,
790       Equal      => "=");
791
792    type Verbosity is (Default, Medium, High);
793    --  Verbosity when parsing GNAT Project Files
794    --    Default is default (very quiet, if no errors).
795    --    Medium is more verbose.
796    --    High is extremely verbose.
797
798    Current_Verbosity : Verbosity := Default;
799    --  The current value of the verbosity the project files are parsed with
800
801    type Lib_Kind is (Static, Dynamic, Relocatable);
802
803    type Policy is (Autonomous, Compliant, Controlled, Restricted, Direct);
804    --  Type to specify the symbol policy, when symbol control is supported.
805    --  See full explanation about this type in package Symbols.
806    --    Autonomous: Create a symbol file without considering any reference
807    --    Compliant:  Try to be as compatible as possible with an existing ref
808    --    Controlled: Fail if symbols are not the same as those in the reference
809    --    Restricted: Restrict the symbols to those in the symbol file
810    --    Direct:     The symbol file is used as is
811
812    type Symbol_Record is record
813       Symbol_File   : Path_Name_Type := No_Path;
814       Reference     : Path_Name_Type := No_Path;
815       Symbol_Policy : Policy  := Autonomous;
816    end record;
817    --  Type to keep the symbol data to be used when building a shared library
818
819    No_Symbols : constant Symbol_Record :=
820      (Symbol_File   => No_Path,
821       Reference     => No_Path,
822       Symbol_Policy => Autonomous);
823    --  The default value of the symbol data
824
825    function Image (The_Casing : Casing_Type) return String;
826    --  Similar to 'Image (but avoid use of this attribute in compiler)
827
828    function Value (Image : String) return Casing_Type;
829    --  Similar to 'Value (but avoid use of this attribute in compiler)
830    --  Raises Constraint_Error if not a Casing_Type image.
831
832    --  The following record contains data for a naming scheme
833
834    function Get_Object_Directory
835      (Project             : Project_Id;
836       Including_Libraries : Boolean;
837       Only_If_Ada         : Boolean := False) return Path_Name_Type;
838    --  Return the object directory to use for the project. This depends on
839    --  whether we have a library project or a standard project. This function
840    --  might return No_Name when no directory applies.
841    --  If we have a a library project file and Including_Libraries is True then
842    --  the library dir is returned instead of the object dir.
843    --  If Only_If_Ada is True, then No_Name will be returned when the project
844    --  doesn't Ada sources.
845
846    procedure Compute_All_Imported_Projects (Tree : Project_Tree_Ref);
847    --  For all projects in the tree, compute the list of the projects imported
848    --  directly or indirectly by project Project. The result is stored in
849    --  Project.All_Imported_Projects for each project
850
851    function Ultimate_Extending_Project_Of
852      (Proj : Project_Id) return Project_Id;
853    --  Returns the ultimate extending project of project Proj. If project Proj
854    --  is not extended, returns Proj.
855
856    type Project_List_Element;
857    type Project_List is access all Project_List_Element;
858    type Project_List_Element is record
859       Project : Project_Id   := No_Project;
860       Next    : Project_List := null;
861    end record;
862    --  A list of projects
863
864    procedure Free_List
865      (List         : in out Project_List;
866       Free_Project : Boolean);
867    --  Free the list of projects, if Free_Project, each project is also freed
868
869    type Response_File_Format is
870      (None,
871       GNU,
872       Object_List,
873       Option_List);
874    --  The format of the different response files
875
876    type Project_Configuration is record
877       Target                        : Name_Id         := No_Name;
878       --  The target of the configuration, when specified
879
880       Run_Path_Option               : Name_List_Index := No_Name_List;
881       --  The option to use when linking to specify the path where to look for
882       --  libraries.
883
884       Separate_Run_Path_Options     : Boolean := False;
885       --  True if each directory needs to be specified in a separate run path
886       --  option.
887
888       Executable_Suffix             : Name_Id         := No_Name;
889       --  The suffix of executables, when specified in the configuration or in
890       --  package Builder of the main project. When this is not specified, the
891       --  executable suffix is the default for the platform.
892
893       --  Linking
894
895       Linker                        : Path_Name_Type  := No_Path;
896       --  Path name of the linker driver. Specified in the configuration or in
897       --  the package Builder of the main project.
898
899       Map_File_Option               : Name_Id := No_Name;
900       --  Option to use when invoking the linker to build a map file
901
902       Minimum_Linker_Options        : Name_List_Index := No_Name_List;
903       --  The minimum options for the linker driver. Specified in the
904       --  configuration.
905
906       Linker_Executable_Option      : Name_List_Index := No_Name_List;
907       --  The option(s) to indicate the name of the executable in the linker
908       --  command. Specified in the configuration. When not specified, default
909       --  to -o <executable name>.
910
911       Linker_Lib_Dir_Option         : Name_Id         := No_Name;
912       --  The option to specify where to find a library for linking. Specified
913       --  in the configuration. When not specified, defaults to "-L".
914
915       Linker_Lib_Name_Option        : Name_Id         := No_Name;
916       --  The option to specify the name of a library for linking. Specified in
917       --  the configuration. When not specified, defaults to "-l".
918
919       Max_Command_Line_Length       : Natural         := 0;
920       --  When positive and when Resp_File_Format (see below) is not None,
921       --  if the command line for the invocation of the linker would be greater
922       --  than this value, a response file is used to invoke the linker.
923
924       Resp_File_Format              : Response_File_Format := None;
925       --  The format of a response file, when linking with a response file is
926       --  supported.
927
928       Resp_File_Options             : Name_List_Index := No_Name_List;
929       --  The switches, if any, that precede the path name of the response
930       --  file in the invocation of the linker.
931
932       --  Libraries
933
934       Library_Builder               : Path_Name_Type  := No_Path;
935       --  The executable to build library (specified in the configuration)
936
937       Lib_Support                   : Library_Support := None;
938       --  The level of library support. Specified in the configuration. Support
939       --  is none, static libraries only or both static and shared libraries.
940
941       Archive_Builder               : Name_List_Index := No_Name_List;
942       --  The name of the executable to build archives, with the minimum
943       --  switches. Specified in the configuration.
944
945       Archive_Builder_Append_Option : Name_List_Index := No_Name_List;
946       --  The options to append object files to an archive
947
948       Archive_Indexer               : Name_List_Index := No_Name_List;
949       --  The name of the executable to index archives, with the minimum
950       --  switches. Specified in the configuration.
951
952       Archive_Suffix                : File_Name_Type  := No_File;
953       --  The suffix of archives. Specified in the configuration. When not
954       --  specified, defaults to ".a".
955
956       Lib_Partial_Linker            : Name_List_Index := No_Name_List;
957
958       --  Shared libraries
959
960       Shared_Lib_Driver             : File_Name_Type  := No_File;
961       --  The driver to link shared libraries. Set with attribute Library_GCC.
962       --  Default to gcc.
963
964       Shared_Lib_Prefix             : File_Name_Type  := No_File;
965       --  Part of a shared library file name that precedes the name of the
966       --  library. Specified in the configuration. When not specified, defaults
967       --  to "lib".
968
969       Shared_Lib_Suffix             : File_Name_Type  := No_File;
970       --  Suffix of shared libraries, after the library name in the shared
971       --  library name. Specified in the configuration. When not specified,
972       --  default to ".so".
973
974       Shared_Lib_Min_Options        : Name_List_Index := No_Name_List;
975       --  The minimum options to use when building a shared library
976
977       Lib_Version_Options           : Name_List_Index := No_Name_List;
978       --  The options to use to specify a library version
979
980       Symbolic_Link_Supported       : Boolean         := False;
981       --  True if the platform supports symbolic link files
982
983       Lib_Maj_Min_Id_Supported      : Boolean         := False;
984       --  True if platform supports library major and minor options, such as
985       --  libname.so -> libname.so.2 -> libname.so.2.4
986
987       Auto_Init_Supported           : Boolean         := False;
988       --  True if automatic initialisation is supported for shared stand-alone
989       --  libraries.
990    end record;
991
992    Default_Project_Config : constant Project_Configuration :=
993                               (Target                        => No_Name,
994                                Run_Path_Option               => No_Name_List,
995                                Separate_Run_Path_Options     => False,
996                                Executable_Suffix             => No_Name,
997                                Linker                        => No_Path,
998                                Map_File_Option               => No_Name,
999                                Minimum_Linker_Options        => No_Name_List,
1000                                Linker_Executable_Option      => No_Name_List,
1001                                Linker_Lib_Dir_Option         => No_Name,
1002                                Linker_Lib_Name_Option        => No_Name,
1003                                Library_Builder               => No_Path,
1004                                Max_Command_Line_Length       => 0,
1005                                Resp_File_Format              => None,
1006                                Resp_File_Options             => No_Name_List,
1007                                Lib_Support                   => None,
1008                                Archive_Builder               => No_Name_List,
1009                                Archive_Builder_Append_Option => No_Name_List,
1010                                Archive_Indexer               => No_Name_List,
1011                                Archive_Suffix                => No_File,
1012                                Lib_Partial_Linker            => No_Name_List,
1013                                Shared_Lib_Driver             => No_File,
1014                                Shared_Lib_Prefix             => No_File,
1015                                Shared_Lib_Suffix             => No_File,
1016                                Shared_Lib_Min_Options        => No_Name_List,
1017                                Lib_Version_Options           => No_Name_List,
1018                                Symbolic_Link_Supported       => False,
1019                                Lib_Maj_Min_Id_Supported      => False,
1020                                Auto_Init_Supported           => False);
1021
1022    --  The following record describes a project file representation
1023
1024    --  Note that it is not specified if the path names of directories (source,
1025    --  object, library or exec directories) end with or without a directory
1026    --  separator.
1027
1028    type Project_Data is record
1029
1030       -------------
1031       -- General --
1032       -------------
1033
1034       Name : Name_Id := No_Name;
1035       --  The name of the project
1036
1037       Display_Name : Name_Id := No_Name;
1038       --  The name of the project with the spelling of its declaration
1039
1040       Qualifier : Project_Qualifier := Unspecified;
1041       --  The eventual qualifier for this project
1042
1043       Externally_Built : Boolean := False;
1044       --  True if the project is externally built. In such case, the Project
1045       --  Manager will not modify anything in this project.
1046
1047       Config : Project_Configuration;
1048
1049       Path : Path_Information := No_Path_Information;
1050       --  The path name of the project file. This include base name of the
1051       --  project file.
1052
1053       Virtual : Boolean := False;
1054       --  True for virtual extending projects
1055
1056       Location : Source_Ptr := No_Location;
1057       --  The location in the project file source of the reserved word project
1058
1059       ---------------
1060       -- Languages --
1061       ---------------
1062
1063       Languages : Language_Ptr := No_Language_Index;
1064       --  First index of the language data in the project.
1065       --  This is an index into the project_tree_data.languages_data.
1066       --  Traversing the list gives access to all the languages supported by
1067       --  the project.
1068
1069       --------------
1070       -- Projects --
1071       --------------
1072
1073       Mains : String_List_Id := Nil_String;
1074       --  List of mains specified by attribute Main
1075
1076       Extends : Project_Id := No_Project;
1077       --  The reference of the project file, if any, that this project file
1078       --  extends.
1079
1080       Extended_By : Project_Id := No_Project;
1081       --  The reference of the project file, if any, that extends this project
1082       --  file.
1083
1084       Decl : Declarations := No_Declarations;
1085       --  The declarations (variables, attributes and packages) of this project
1086       --  file.
1087
1088       Imported_Projects : Project_List;
1089       --  The list of all directly imported projects, if any
1090
1091       All_Imported_Projects : Project_List;
1092       --  The list of all projects imported directly or indirectly, if any.
1093       --  This does not include the project itself.
1094
1095       -----------------
1096       -- Directories --
1097       -----------------
1098
1099       Directory : Path_Information := No_Path_Information;
1100       --  Path name of the directory where the project file resides
1101
1102       Object_Directory : Path_Information := No_Path_Information;
1103       --  The path name of the object directory of this project file
1104
1105       Exec_Directory : Path_Information := No_Path_Information;
1106       --  The path name of the exec directory of this project file. Default is
1107       --  equal to Object_Directory.
1108
1109       -------------
1110       -- Library --
1111       -------------
1112
1113       Library : Boolean := False;
1114       --  True if this is a library project
1115
1116       Library_Name : Name_Id := No_Name;
1117       --  If a library project, name of the library
1118
1119       Library_Kind : Lib_Kind := Static;
1120       --  If a library project, kind of library
1121
1122       Library_Dir : Path_Information := No_Path_Information;
1123       --  If a library project, path name of the directory where the library
1124       --  resides.
1125
1126       Library_TS : Time_Stamp_Type := Empty_Time_Stamp;
1127       --  The timestamp of a library file in a library project
1128
1129       Library_Src_Dir : Path_Information := No_Path_Information;
1130       --  If a Stand-Alone Library project, path name of the directory where
1131       --  the sources of the interfaces of the library are copied. By default,
1132       --  if attribute Library_Src_Dir is not specified, sources of the
1133       --  interfaces are not copied anywhere.
1134
1135       Library_ALI_Dir : Path_Information := No_Path_Information;
1136       --  In a library project, path name of the directory where the ALI files
1137       --  are copied. If attribute Library_ALI_Dir is not specified, ALI files
1138       --  are copied in the Library_Dir.
1139
1140       Lib_Internal_Name : Name_Id := No_Name;
1141       --  If a library project, internal name store inside the library
1142
1143       Standalone_Library : Boolean := False;
1144       --  Indicate that this is a Standalone Library Project File
1145
1146       Lib_Interface_ALIs : String_List_Id := Nil_String;
1147       --  For Standalone Library Project Files, indicate the list of Interface
1148       --  ALI files.
1149
1150       Lib_Auto_Init : Boolean := False;
1151       --  For non static Stand-Alone Library Project Files, indicate if
1152       --  the library initialisation should be automatic.
1153
1154       Symbol_Data : Symbol_Record := No_Symbols;
1155       --  Symbol file name, reference symbol file name, symbol policy
1156
1157       Need_To_Build_Lib : Boolean := False;
1158       --  Indicates that the library of a Library Project needs to be built or
1159       --  rebuilt.
1160
1161       -------------
1162       -- Sources --
1163       -------------
1164       --  The sources for all languages including Ada are accessible through
1165       --  the Source_Iterator type
1166
1167       Interfaces_Defined      : Boolean := False;
1168       --  True if attribute Interfaces is declared for the project or any
1169       --  project it extends.
1170
1171       Include_Path_File : Path_Name_Type := No_Path;
1172       --  The path name of the of the source search directory file.
1173       --  This is only used by gnatmake
1174
1175       Source_Dirs : String_List_Id := Nil_String;
1176       --  The list of all the source directories
1177
1178       Source_Dir_Ranks : Number_List_Index := No_Number_List;
1179
1180       Ada_Include_Path : String_Access := null;
1181       --  The cached value of source search path for this project file. Set by
1182       --  the first call to Prj.Env.Ada_Include_Path for the project. Do not
1183       --  use this field directly outside of the project manager, use
1184       --  Prj.Env.Ada_Include_Path instead.
1185
1186       -------------------
1187       -- Miscellaneous --
1188       -------------------
1189
1190       Ada_Objects_Path : String_Access := null;
1191       --  The cached value of ADA_OBJECTS_PATH for this project file. Do not
1192       --  use this field directly outside of the compiler, use
1193       --  Prj.Env.Ada_Objects_Path instead.
1194
1195       Libgnarl_Needed : Yes_No_Unknown := Unknown;
1196       --  Set to True when libgnarl is needed to link
1197
1198       Objects_Path : String_Access := null;
1199       --  The cached value of the object dir path, used during the binding
1200       --  phase of gprbuild.
1201
1202       Objects_Path_File_With_Libs : Path_Name_Type := No_Path;
1203       --  The cached value of the object path temp file (including library
1204       --  dirs) for this project file.
1205
1206       Objects_Path_File_Without_Libs : Path_Name_Type := No_Path;
1207       --  The cached value of the object path temp file (excluding library
1208       --  dirs) for this project file.
1209
1210       Config_File_Name : Path_Name_Type := No_Path;
1211       --  The path name of the configuration pragmas file, if any
1212
1213       Config_File_Temp : Boolean := False;
1214       --  An indication that the configuration pragmas file is a temporary file
1215       --  that must be deleted at the end.
1216
1217       Config_Checked : Boolean := False;
1218       --  A flag to avoid checking repetitively the configuration pragmas file
1219
1220       Depth : Natural := 0;
1221       --  The maximum depth of a project in the project graph. Depth of main
1222       --  project is 0.
1223
1224       Unkept_Comments : Boolean := False;
1225       --  True if there are comments in the project sources that cannot be kept
1226       --  in the project tree.
1227
1228    end record;
1229
1230    function Empty_Project return Project_Data;
1231    --  Return the representation of an empty project
1232
1233    function Is_Extending
1234      (Extending : Project_Id;
1235       Extended  : Project_Id) return Boolean;
1236    --  Return True if Extending is extending the Extended project
1237
1238    function Has_Ada_Sources (Data : Project_Id) return Boolean;
1239    --  Return True if the project has Ada sources
1240
1241    Project_Error : exception;
1242    --  Raised by some subprograms in Prj.Attr
1243
1244    package Units_Htable is new Simple_HTable
1245      (Header_Num => Header_Num,
1246       Element    => Unit_Index,
1247       No_Element => No_Unit_Index,
1248       Key        => Name_Id,
1249       Hash       => Hash,
1250       Equal      => "=");
1251    --  Mapping of unit names to indexes in the Units table
1252
1253    ---------------------
1254    -- Source_Iterator --
1255    ---------------------
1256
1257    type Source_Iterator is private;
1258
1259    function For_Each_Source
1260      (In_Tree  : Project_Tree_Ref;
1261       Project  : Project_Id := No_Project;
1262       Language : Name_Id := No_Name) return Source_Iterator;
1263    --  Returns an iterator for all the sources of a project tree, or a specific
1264    --  project, or a specific language.
1265
1266    function Element (Iter : Source_Iterator) return Source_Id;
1267    --  Return the current source (or No_Source if there are no more sources)
1268
1269    procedure Next (Iter : in out Source_Iterator);
1270    --  Move on to the next source
1271
1272    function Find_Source
1273      (In_Tree          : Project_Tree_Ref;
1274       Project          : Project_Id;
1275       In_Imported_Only : Boolean := False;
1276       In_Extended_Only : Boolean := False;
1277       Base_Name        : File_Name_Type) return Source_Id;
1278    --  Find the first source file with the given name either in the whole tree
1279    --  (if In_Imported_Only is False) or in the projects imported or extended
1280    --  by Project otherwise. In_Extended_Only implies In_Imported_Only, and
1281    --  will only look in Project and the projects it extends
1282
1283    -----------------------
1284    -- Project_Tree_Data --
1285    -----------------------
1286
1287    type Private_Project_Tree_Data is private;
1288    --  Data for a project tree that is used only by the Project Manager
1289
1290    type Project_Tree_Data is
1291       record
1292          Name_Lists        : Name_List_Table.Instance;
1293          Number_Lists      : Number_List_Table.Instance;
1294          String_Elements   : String_Element_Table.Instance;
1295          Variable_Elements : Variable_Element_Table.Instance;
1296          Array_Elements    : Array_Element_Table.Instance;
1297          Arrays            : Array_Table.Instance;
1298          Packages          : Package_Table.Instance;
1299          Projects          : Project_List;
1300
1301          Units_HT          : Units_Htable.Instance;
1302          --  Unit name to Unit_Index (and from there so Source_Id)
1303
1304          Source_Paths_HT   : Source_Paths_Htable.Instance;
1305          --  Full path to Source_Id
1306
1307          Private_Part      : Private_Project_Tree_Data;
1308       end record;
1309    --  Data for a project tree
1310
1311    procedure Expect (The_Token : Token_Type; Token_Image : String);
1312    --  Check that the current token is The_Token. If it is not, then output
1313    --  an error message.
1314
1315    procedure Initialize (Tree : Project_Tree_Ref);
1316    --  This procedure must be called before using any services from the Prj
1317    --  hierarchy. Namet.Initialize must be called before Prj.Initialize.
1318
1319    procedure Reset (Tree : Project_Tree_Ref);
1320    --  This procedure resets all the tables that are used when processing a
1321    --  project file tree. Initialize must be called before the call to Reset.
1322
1323    package Project_Boolean_Htable is new Simple_HTable
1324      (Header_Num => Header_Num,
1325       Element    => Boolean,
1326       No_Element => False,
1327       Key        => Project_Id,
1328       Hash       => Hash,
1329       Equal      => "=");
1330    --  A table that associates a project to a boolean. This is used to detect
1331    --  whether a project was already processed for instance.
1332
1333    generic
1334       type State is limited private;
1335       with procedure Action
1336         (Project    : Project_Id;
1337          With_State : in out State);
1338    procedure For_Every_Project_Imported
1339      (By             : Project_Id;
1340       With_State     : in out State;
1341       Imported_First : Boolean := False);
1342    --  Call Action for each project imported directly or indirectly by project
1343    --  By, as well as extended projects.
1344    --  The order of processing depends on Imported_First:
1345    --  If False, Action is called according to the order of importation: if A
1346    --  imports B, directly or indirectly, Action will be called for A before
1347    --  it is called for B. If two projects import each other directly or
1348    --  indirectly (using at least one "limited with"), it is not specified
1349    --  for which of these two projects Action will be called first.
1350    --  The order is reversed if Imported_First is True.
1351    --  With_State may be used by Action to choose a behavior or to report some
1352    --  global result.
1353
1354    function Extend_Name
1355      (File        : File_Name_Type;
1356       With_Suffix : String) return File_Name_Type;
1357    --  Replace the extension of File with With_Suffix
1358
1359    function Object_Name
1360      (Source_File_Name   : File_Name_Type;
1361       Object_File_Suffix : Name_Id := No_Name) return File_Name_Type;
1362    --  Returns the object file name corresponding to a source file name
1363
1364    function Dependency_Name
1365      (Source_File_Name : File_Name_Type;
1366       Dependency       : Dependency_File_Kind) return File_Name_Type;
1367    --  Returns the dependency file name corresponding to a source file name
1368
1369    function Switches_Name
1370      (Source_File_Name : File_Name_Type) return File_Name_Type;
1371    --  Returns the switches file name corresponding to a source file name
1372
1373    -----------
1374    -- Flags --
1375    -----------
1376
1377    type Processing_Flags is private;
1378    --  Flags used while parsing and processing a project tree to configure the
1379    --  behavior of the parser, and indicate how to report error messages. This
1380    --  structure does not allocate memory and never needs to be freed
1381
1382    type Error_Warning is (Silent, Warning, Error);
1383    --  Severity of some situations, such as: no Ada sources in a project where
1384    --  Ada is one of the language.
1385    --
1386    --  When the situation occurs, the behaviour depends on the setting:
1387    --
1388    --    - Silent:  no action
1389    --    - Warning: issue a warning, does not cause the tool to fail
1390    --    - Error:   issue an error, causes the tool to fail
1391
1392    type Error_Handler is access procedure
1393      (Project    : Project_Id;
1394       Is_Warning : Boolean);
1395    --  This warngs when an error was found when parsing a project. The error
1396    --  itself is handled through Prj.Err (and Prj.Err.Finalize should be called
1397    --  to actually print the error). This ensures that duplicate error messages
1398    --  are always correctly removed, that errors msgs are sorted, and that all
1399    --  tools will report the same error to the user.
1400
1401    function Create_Flags
1402      (Report_Error               : Error_Handler;
1403       When_No_Sources            : Error_Warning;
1404       Require_Sources_Other_Lang : Boolean := True;
1405       Allow_Duplicate_Basenames  : Boolean := True;
1406       Compiler_Driver_Mandatory  : Boolean := False;
1407       Error_On_Unknown_Language  : Boolean := True;
1408       Require_Obj_Dirs           : Error_Warning := Error)
1409       return Processing_Flags;
1410    --  Function used to create Processing_Flags structure
1411    --
1412    --  If Allow_Duplicate_Basenames, then files with the same base names are
1413    --  authorized within a project for source-based languages (never for unit
1414    --  based languages).
1415    --
1416    --  If Compiler_Driver_Mandatory is true, then a Compiler.Driver attribute
1417    --  for each language must be defined, or we will not look for its source
1418    --  files.
1419    --
1420    --  When_No_Sources indicates what should be done when no sources of a
1421    --  language are found in a project where this language is declared.
1422    --  If Require_Sources_Other_Lang is true, then all languages must have at
1423    --  least one source file, or an error is reported via When_No_Sources. If
1424    --  it is false, this is only required for Ada (and only if it is a language
1425    --  of the project). When this parameter is set to False, we do not check
1426    --  that a proper naming scheme is defined for languages other than Ada.
1427    --
1428    --  If Report_Error is null, use the standard error reporting mechanism
1429    --  (Errout). Otherwise, report errors using Report_Error.
1430    --
1431    --  If Error_On_Unknown_Language is true, an error is displayed if some of
1432    --  the source files listed in the project do not match any naming scheme
1433    --
1434    --  If Require_Obj_Dirs is true, then all object directories must exist
1435    --  (possibly after they have been created automatically if the appropriate
1436    --  switches were specified), or an error is raised.
1437
1438    Gprbuild_Flags : constant Processing_Flags;
1439    Gprclean_Flags : constant Processing_Flags;
1440    Gnatmake_Flags : constant Processing_Flags;
1441    --  Flags used by the various tools. They all display the error messages
1442    --  through Prj.Err.
1443
1444    ----------------
1445    -- Temp Files --
1446    ----------------
1447
1448    procedure Record_Temp_File
1449      (Tree : Project_Tree_Ref;
1450       Path : Path_Name_Type);
1451    --  Record the path of a newly created temporary file, so that it can be
1452    --  deleted later.
1453
1454    procedure Delete_All_Temp_Files (Tree : Project_Tree_Ref);
1455    --  Delete all recorded temporary files.
1456    --  Does nothing if Debug.Debug_Flag_N is set
1457
1458    procedure Delete_Temporary_File
1459      (Tree : Project_Tree_Ref;
1460       Path : Path_Name_Type);
1461    --  Delete a temporary file from the disk. The file is also removed from the
1462    --  list of temporary files to delete at the end of the program, in case
1463    --  another program running on the same machine has recreated it.
1464    --  Does nothing if Debug.Debug_Flag_N is set
1465
1466 private
1467
1468    All_Packages : constant String_List_Access := null;
1469
1470    No_Project_Tree : constant Project_Tree_Ref := null;
1471
1472    Ignored : constant Variable_Kind := Single;
1473
1474    Nil_Variable_Value : constant Variable_Value :=
1475                           (Project  => No_Project,
1476                            Kind     => Undefined,
1477                            Location => No_Location,
1478                            Default  => False);
1479
1480    Virtual_Prefix : constant String := "v$";
1481    --  The prefix for virtual extending projects. Because of the '$', which is
1482    --  normally forbidden for project names, there cannot be any name clash.
1483
1484    type Source_Iterator is record
1485       In_Tree : Project_Tree_Ref;
1486
1487       Project      : Project_List;
1488       All_Projects : Boolean;
1489       --  Current project and whether we should move on to the next
1490
1491       Language : Language_Ptr;
1492       --  Current language processed
1493
1494       Language_Name : Name_Id;
1495       --  Only sources of this language will be returned (or all if No_Name)
1496
1497       Current : Source_Id;
1498    end record;
1499
1500    procedure Add_To_Buffer
1501      (S    : String;
1502       To   : in out String_Access;
1503       Last : in out Natural);
1504    --  Append a String to the Buffer
1505
1506    package Temp_Files_Table is new GNAT.Dynamic_Tables
1507      (Table_Component_Type => Path_Name_Type,
1508       Table_Index_Type     => Integer,
1509       Table_Low_Bound      => 1,
1510       Table_Initial        => 10,
1511       Table_Increment      => 10);
1512    --  Table to store the path name of all the created temporary files, so that
1513    --  they can be deleted at the end, or when the program is interrupted.
1514
1515    type Private_Project_Tree_Data is record
1516       Temp_Files   : Temp_Files_Table.Instance;
1517       --  Temporary files created as part of running tools (pragma files,
1518       --  mapping files,...)
1519
1520       Current_Source_Path_File : Path_Name_Type := No_Path;
1521       --  Current value of project source path file env var. Used to avoid
1522       --  setting the env var to the same value. When different from No_Path,
1523       --  this indicates that logical names (VMS) or environment variables were
1524       --  created and should be deassigned to avoid polluting the environment
1525       --  on VMS.
1526       --  gnatmake only
1527
1528       Current_Object_Path_File : Path_Name_Type := No_Path;
1529       --  Current value of project object path file env var. Used to avoid
1530       --  setting the env var to the same value.
1531       --  gnatmake only
1532
1533    end record;
1534    --  Type to represent the part of a project tree which is private to the
1535    --  Project Manager.
1536
1537    type Processing_Flags is record
1538       Require_Sources_Other_Lang : Boolean;
1539       Report_Error               : Error_Handler;
1540       When_No_Sources            : Error_Warning;
1541       Allow_Duplicate_Basenames  : Boolean;
1542       Compiler_Driver_Mandatory  : Boolean;
1543       Error_On_Unknown_Language  : Boolean;
1544       Require_Obj_Dirs           : Error_Warning;
1545    end record;
1546
1547    Gprbuild_Flags : constant Processing_Flags :=
1548      (Report_Error               => null,
1549       When_No_Sources            => Warning,
1550       Require_Sources_Other_Lang => True,
1551       Allow_Duplicate_Basenames  => False,
1552       Compiler_Driver_Mandatory  => True,
1553       Error_On_Unknown_Language  => True,
1554       Require_Obj_Dirs           => Error);
1555
1556    Gprclean_Flags : constant Processing_Flags :=
1557      (Report_Error               => null,
1558       When_No_Sources            => Warning,
1559       Require_Sources_Other_Lang => True,
1560       Allow_Duplicate_Basenames  => False,
1561       Compiler_Driver_Mandatory  => True,
1562       Error_On_Unknown_Language  => True,
1563       Require_Obj_Dirs           => Warning);
1564
1565    Gnatmake_Flags : constant Processing_Flags :=
1566      (Report_Error               => null,
1567       When_No_Sources            => Error,
1568       Require_Sources_Other_Lang => False,
1569       Allow_Duplicate_Basenames  => False,
1570       Compiler_Driver_Mandatory  => False,
1571       Error_On_Unknown_Language  => False,
1572       Require_Obj_Dirs           => Error);
1573
1574 end Prj;