OSDN Git Service

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