OSDN Git Service

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