OSDN Git Service

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