OSDN Git Service

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