OSDN Git Service

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