OSDN Git Service

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