OSDN Git Service

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