OSDN Git Service

2011-08-29 Yannick Moy <moy@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-2011, 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 Osint;
35 with Scans;  use Scans;
36 with Types;  use Types;
37
38 with GNAT.Dynamic_HTables; use GNAT.Dynamic_HTables;
39 with GNAT.Dynamic_Tables;
40 with GNAT.OS_Lib;          use GNAT.OS_Lib;
41
42 package Prj is
43
44    All_Other_Names : constant Name_Id := Names_High_Bound;
45    --  Name used to replace others as an index of an associative array
46    --  attribute in situations where this is allowed.
47
48    Subdirs : String_Ptr := null;
49    --  The value after the equal sign in switch --subdirs=...
50    --  Contains the relative subdirectory.
51
52    type Library_Support is (None, Static_Only, Full);
53    --  Support for Library Project File.
54    --  - None: Library Project Files are not supported at all
55    --  - Static_Only: Library Project Files are only supported for static
56    --    libraries.
57    --  - Full: Library Project Files are supported for static and dynamic
58    --    (shared) libraries.
59
60    type Yes_No_Unknown is (Yes, No, Unknown);
61    --  Tri-state to decide if -lgnarl is needed when linking
62
63    type Project_Qualifier is
64      (Unspecified,
65       Standard,
66       Library,
67       Configuration,
68       Dry,
69       Aggregate,
70       Aggregate_Library);
71    --  Qualifiers that can prefix the reserved word "project" in a project
72    --  file:
73    --    Standard:             standard project ...
74    --    Library:              library project is ...
75    --    Dry:                  abstract project is
76    --    Aggregate:            aggregate project is
77    --    Aggregate_Library:    aggregate library project is ...
78    --    Configuration:        configuration project is ...
79
80    All_Packages : constant String_List_Access;
81    --  Default value of parameter Packages of procedures Parse, in Prj.Pars and
82    --  Prj.Part, indicating that all packages should be checked.
83
84    type Project_Tree_Data;
85    type Project_Tree_Ref is access all Project_Tree_Data;
86    --  Reference to a project tree. Several project trees may exist in memory
87    --  at the same time.
88
89    No_Project_Tree : constant Project_Tree_Ref;
90
91    procedure Free (Tree : in out Project_Tree_Ref);
92    --  Free memory associated with the tree
93
94    Config_Project_File_Extension : String := ".cgpr";
95    Project_File_Extension : String := ".gpr";
96    --  The standard config and user project file name extensions. They are not
97    --  constants, because Canonical_Case_File_Name is called on these variables
98    --  in the body of Prj.
99
100    function Empty_File   return File_Name_Type;
101    function Empty_String return Name_Id;
102    --  Return the id for an empty string ""
103
104    type Path_Information is record
105       Name         : Path_Name_Type := No_Path;
106       Display_Name : Path_Name_Type := No_Path;
107    end record;
108    --  Directory names always end with a directory separator
109
110    No_Path_Information : constant Path_Information := (No_Path, No_Path);
111
112    type Project_Data;
113    type Project_Id is access all Project_Data;
114    No_Project : constant Project_Id := null;
115    --  Id of a Project File
116
117    type String_List_Id is new Nat;
118    Nil_String : constant String_List_Id := 0;
119    type String_Element is record
120       Value         : Name_Id        := No_Name;
121       Index         : Int            := 0;
122       Display_Value : Name_Id        := No_Name;
123       Location      : Source_Ptr     := No_Location;
124       Flag          : Boolean        := False;
125       Next          : String_List_Id := Nil_String;
126    end record;
127    --  To hold values for string list variables and array elements.
128    --  Component Flag may be used for various purposes. For source
129    --  directories, it indicates if the directory contains Ada source(s).
130
131    package String_Element_Table is new GNAT.Dynamic_Tables
132      (Table_Component_Type => String_Element,
133       Table_Index_Type     => String_List_Id,
134       Table_Low_Bound      => 1,
135       Table_Initial        => 200,
136       Table_Increment      => 100);
137    --  The table for string elements in string lists
138
139    type Variable_Kind is (Undefined, List, Single);
140    --  Different kinds of variables
141
142    subtype Defined_Variable_Kind is Variable_Kind range List .. Single;
143    --  The defined kinds of variables
144
145    Ignored : constant Variable_Kind;
146    --  Used to indicate that a package declaration must be ignored
147    --  while processing the project tree (unknown package name).
148
149    type Variable_Value (Kind : Variable_Kind := Undefined) is record
150       Project  : Project_Id := No_Project;
151       Location : Source_Ptr := No_Location;
152       Default  : Boolean    := False;
153       case Kind is
154          when Undefined =>
155             null;
156          when List =>
157             Values : String_List_Id := Nil_String;
158          when Single =>
159             Value : Name_Id := No_Name;
160             Index : Int     := 0;
161       end case;
162    end record;
163    --  Values for variables and array elements. Default is True if the
164    --  current value is the default one for the variable.
165
166    Nil_Variable_Value : constant Variable_Value;
167    --  Value of a non existing variable or array element
168
169    type Variable_Id is new Nat;
170    No_Variable : constant Variable_Id := 0;
171    type Variable is record
172       Next  : Variable_Id := No_Variable;
173       Name  : Name_Id;
174       Value : Variable_Value;
175    end record;
176    --  To hold the list of variables in a project file and in packages
177
178    package Variable_Element_Table is new GNAT.Dynamic_Tables
179      (Table_Component_Type => Variable,
180       Table_Index_Type     => Variable_Id,
181       Table_Low_Bound      => 1,
182       Table_Initial        => 200,
183       Table_Increment      => 100);
184    --  The table of variable in list of variables
185
186    type Array_Element_Id is new Nat;
187    No_Array_Element : constant Array_Element_Id := 0;
188    type Array_Element is record
189       Index                : Name_Id;
190       Src_Index            : Int := 0;
191       Index_Case_Sensitive : Boolean := True;
192       Value                : Variable_Value;
193       Next                 : Array_Element_Id := No_Array_Element;
194    end record;
195    --  Each Array_Element represents an array element and is linked (Next)
196    --  to the next array element, if any, in the array.
197
198    package Array_Element_Table is new GNAT.Dynamic_Tables
199      (Table_Component_Type => Array_Element,
200       Table_Index_Type     => Array_Element_Id,
201       Table_Low_Bound      => 1,
202       Table_Initial        => 200,
203       Table_Increment      => 100);
204    --  The table that contains all array elements
205
206    type Array_Id is new Nat;
207    No_Array : constant Array_Id := 0;
208    type Array_Data is record
209       Name     : Name_Id          := No_Name;
210       Location : Source_Ptr       := No_Location;
211       Value    : Array_Element_Id := No_Array_Element;
212       Next     : Array_Id         := No_Array;
213    end record;
214    --  Each Array_Data value represents an array.
215    --  Value is the id of the first element.
216    --  Next is the id of the next array in the project file or package.
217
218    package Array_Table is new GNAT.Dynamic_Tables
219      (Table_Component_Type => Array_Data,
220       Table_Index_Type     => Array_Id,
221       Table_Low_Bound      => 1,
222       Table_Initial        => 200,
223       Table_Increment      => 100);
224    --  The table that contains all arrays
225
226    type Package_Id is new Nat;
227    No_Package : constant Package_Id := 0;
228    type Declarations is record
229       Variables  : Variable_Id := No_Variable;
230       Attributes : Variable_Id := No_Variable;
231       Arrays     : Array_Id    := No_Array;
232       Packages   : Package_Id  := No_Package;
233    end record;
234    --  Contains the declarations (variables, single and array attributes,
235    --  packages) for a project or a package in a project.
236
237    No_Declarations : constant Declarations :=
238      (Variables  => No_Variable,
239       Attributes => No_Variable,
240       Arrays     => No_Array,
241       Packages   => No_Package);
242    --  Default value of Declarations: indicates that there is no declarations
243
244    type Package_Element is record
245       Name   : Name_Id      := No_Name;
246       Decl   : Declarations := No_Declarations;
247       Parent : Package_Id   := No_Package;
248       Next   : Package_Id   := No_Package;
249    end record;
250    --  A package (includes declarations that may include other packages)
251
252    package Package_Table is new GNAT.Dynamic_Tables
253      (Table_Component_Type => Package_Element,
254       Table_Index_Type     => Package_Id,
255       Table_Low_Bound      => 1,
256       Table_Initial        => 100,
257       Table_Increment      => 100);
258    --  The table that contains all packages
259
260    type Language_Data;
261    type Language_Ptr is access all Language_Data;
262    --  Index of language data
263
264    No_Language_Index : constant Language_Ptr := null;
265    --  Constant indicating that there is no language data
266
267    function Get_Language_From_Name
268      (Project : Project_Id;
269       Name    : String) return Language_Ptr;
270    --  Get a language from a project. This might return null if no such
271    --  language exists in the project
272
273    Max_Header_Num : constant := 6150;
274    type Header_Num is range 0 .. Max_Header_Num;
275    --  Size for hash table below. The upper bound is an arbitrary value, the
276    --  value here was chosen after testing to determine a good compromise
277    --  between speed of access and memory usage.
278
279    function Hash (Name : Name_Id)        return Header_Num;
280    function Hash (Name : File_Name_Type) return Header_Num;
281    function Hash (Name : Path_Name_Type) return Header_Num;
282    function Hash (Project : Project_Id)  return Header_Num;
283    --  Used for computing hash values for names put into hash tables
284
285    type Language_Kind is (File_Based, Unit_Based);
286    --  Type for the kind of language. All languages are file based, except Ada
287    --  which is unit based.
288
289    type Dependency_File_Kind is (None, Makefile, ALI_File);
290    --  Type of dependency to be checked: no dependency file, Makefile fragment
291    --  or ALI file (for Ada).
292
293    Makefile_Dependency_Suffix : constant String := ".d";
294    ALI_Dependency_Suffix      : constant String := ".ali";
295    Switches_Dependency_Suffix : constant String := ".cswi";
296
297    Binder_Exchange_Suffix : constant String := ".bexch";
298    --  Suffix for binder exchange files
299
300    Library_Exchange_Suffix : constant String := ".lexch";
301    --  Suffix for library exchange files
302
303    type Name_List_Index is new Nat;
304    No_Name_List : constant Name_List_Index := 0;
305
306    type Name_Node is record
307       Name : Name_Id         := No_Name;
308       Next : Name_List_Index := No_Name_List;
309    end record;
310
311    package Name_List_Table is new GNAT.Dynamic_Tables
312      (Table_Component_Type => Name_Node,
313       Table_Index_Type     => Name_List_Index,
314       Table_Low_Bound      => 1,
315       Table_Initial        => 10,
316       Table_Increment      => 100);
317    --  The table for lists of names
318
319    function Length
320      (Table : Name_List_Table.Instance;
321       List  : Name_List_Index) return Natural;
322    --  Return the number of elements in specified list
323
324    type Number_List_Index is new Nat;
325    No_Number_List : constant Number_List_Index := 0;
326
327    type Number_Node is record
328       Number : Natural           := 0;
329       Next   : Number_List_Index := No_Number_List;
330    end record;
331
332    package Number_List_Table is new GNAT.Dynamic_Tables
333      (Table_Component_Type => Number_Node,
334       Table_Index_Type     => Number_List_Index,
335       Table_Low_Bound      => 1,
336       Table_Initial        => 10,
337       Table_Increment      => 100);
338    --  The table for lists of numbers
339
340    package Mapping_Files_Htable is new Simple_HTable
341      (Header_Num => Header_Num,
342       Element    => Path_Name_Type,
343       No_Element => No_Path,
344       Key        => Path_Name_Type,
345       Hash       => Hash,
346       Equal      => "=");
347    --  A hash table to store the mapping files that are not used
348
349    --  The following record ???
350
351    type Lang_Naming_Data is record
352       Dot_Replacement : File_Name_Type := No_File;
353       --  The string to replace '.' in the source file name (for Ada)
354
355       Casing : Casing_Type := All_Lower_Case;
356       --  The casing of the source file name (for Ada)
357
358       Separate_Suffix : File_Name_Type := No_File;
359       --  String to append to unit name for source file name of an Ada subunit
360
361       Spec_Suffix : File_Name_Type := No_File;
362       --  The string to append to the unit name for the
363       --  source file name of a spec.
364
365       Body_Suffix : File_Name_Type := No_File;
366       --  The string to append to the unit name for the
367       --  source file name of a body.
368    end record;
369
370    No_Lang_Naming_Data : constant Lang_Naming_Data :=
371                            (Dot_Replacement => No_File,
372                             Casing          => All_Lower_Case,
373                             Separate_Suffix => No_File,
374                             Spec_Suffix     => No_File,
375                             Body_Suffix     => No_File);
376
377    function Is_Standard_GNAT_Naming (Naming : Lang_Naming_Data) return Boolean;
378    --  True if the naming scheme is GNAT's default naming scheme. This
379    --  is to take into account shortened names like "Ada." (a-), "System." (s-)
380    --  and so on.
381
382    type Source_Data;
383    type Source_Id is access all Source_Data;
384
385    function Is_Compilable (Source : Source_Id) return Boolean;
386    pragma Inline (Is_Compilable);
387    --  Return True if we know how to compile Source (i.e. if a compiler is
388    --  defined). This doesn't indicate whether the source should be compiled.
389
390    function Object_To_Global_Archive (Source : Source_Id) return Boolean;
391    pragma Inline (Object_To_Global_Archive);
392    --  Return True if the object file should be put in the global archive.
393    --  This is for Ada, when only the closure of a main needs to be
394    --  (re)compiled.
395
396    function Other_Part (Source : Source_Id) return Source_Id;
397    pragma Inline (Other_Part);
398    --  Source ID for the other part, if any: for a spec, indicates its body;
399    --  for a body, indicates its spec.
400
401    No_Source : constant Source_Id := null;
402
403    type Path_Syntax_Kind is
404      (Canonical,
405       --  Unix style
406       Host);
407       --  Host specific syntax, for example on VMS (the default)
408
409    --  The following record describes the configuration of a language
410
411    type Language_Config is record
412       Kind : Language_Kind := File_Based;
413       --  Kind of language. Most languages are file based. A few, such as Ada,
414       --  are unit based.
415
416       Naming_Data : Lang_Naming_Data;
417       --  The naming data for the languages (prefixes, etc.)
418
419       Include_Compatible_Languages : Name_List_Index := No_Name_List;
420       --  List of languages that are "include compatible" with this language. A
421       --  language B (for example "C") is "include compatible" with a language
422       --  A (for example "C++") if it is expected that sources of language A
423       --  may "include" header files from language B.
424
425       Compiler_Driver : File_Name_Type := No_File;
426       --  The name of the executable for the compiler of the language
427
428       Compiler_Driver_Path : String_Access := null;
429       --  The path name of the executable for the compiler of the language
430
431       Compiler_Leading_Required_Switches : Name_List_Index := No_Name_List;
432       --  The list of initial switches that are required as a minimum to invoke
433       --  the compiler driver.
434
435       Compiler_Trailing_Required_Switches : Name_List_Index := No_Name_List;
436       --  The list of final switches that are required as a minimum to invoke
437       --  the compiler driver.
438
439       Multi_Unit_Switches : Name_List_Index := No_Name_List;
440       --  The switch(es) to indicate the index of a unit in a multi-source file
441
442       Multi_Unit_Object_Separator : Character := ' ';
443       --  The string separating the base name of a source from the index of the
444       --  unit in a multi-source file, in the object file name.
445
446       Path_Syntax : Path_Syntax_Kind := Host;
447       --  Value may be Canonical (Unix style) or Host (host syntax, for example
448       --  on VMS for DEC C).
449
450       Object_File_Suffix : Name_Id := No_Name;
451       --  Optional alternate object file suffix
452
453       Object_File_Switches : Name_List_Index := No_Name_List;
454       --  Optional object file switches. When this is defined, the switches
455       --  are used to specify the object file. The object file name is appended
456       --  to the last switch in the list. Example: ("-o", "").
457
458       Compilation_PIC_Option : Name_List_Index := No_Name_List;
459       --  The option(s) to compile a source in Position Independent Code for
460       --  shared libraries. Specified in the configuration. When not specified,
461       --  there is no need for such switch.
462
463       Object_Generated : Boolean := True;
464       --  False in no object file is generated
465
466       Objects_Linked : Boolean := True;
467       --  False if object files are not use to link executables and build
468       --  libraries.
469
470       Runtime_Library_Dir : Name_Id := No_Name;
471       --  Path name of the runtime library directory, if any
472
473       Runtime_Source_Dir : Name_Id := No_Name;
474       --  Path name of the runtime source directory, if any
475
476       Mapping_File_Switches : Name_List_Index := No_Name_List;
477       --  The option(s) to provide a mapping file to the compiler. Specified in
478       --  the configuration. When value is No_Name_List, there is no mapping
479       --  file.
480
481       Mapping_Spec_Suffix : File_Name_Type := No_File;
482       --  Placeholder representing the spec suffix in a mapping file
483
484       Mapping_Body_Suffix : File_Name_Type := No_File;
485       --  Placeholder representing the body suffix in a mapping file
486
487       Config_File_Switches : Name_List_Index := No_Name_List;
488       --  The option(s) to provide a config file to the compiler. Specified in
489       --  the configuration. If value is No_Name_List there is no config file.
490
491       Dependency_Kind : Dependency_File_Kind := None;
492       --  The kind of dependency to be checked: none, Makefile fragment or
493       --  ALI file (for Ada).
494
495       Dependency_Option : Name_List_Index := No_Name_List;
496       --  The option(s) to be used to create the dependency file. When value is
497       --  No_Name_List, there is not such option(s).
498
499       Compute_Dependency : Name_List_Index := No_Name_List;
500       --  Hold the value of attribute Dependency_Driver, if declared for the
501       --  language.
502
503       Include_Option : Name_List_Index := No_Name_List;
504       --  Hold the value of attribute Include_Switches, if declared for the
505       --  language.
506
507       Include_Path : Name_Id := No_Name;
508       --  Name of environment variable declared by attribute Include_Path for
509       --  the language.
510
511       Include_Path_File : Name_Id := No_Name;
512       --  Name of environment variable declared by attribute Include_Path_File
513       --  for the language.
514
515       Objects_Path : Name_Id := No_Name;
516       --  Name of environment variable declared by attribute Objects_Path for
517       --  the language.
518
519       Objects_Path_File : Name_Id := No_Name;
520       --  Name of environment variable declared by attribute Objects_Path_File
521       --  for the language.
522
523       Config_Body : Name_Id := No_Name;
524       --  The template for a pragma Source_File_Name(_Project) for a specific
525       --  file name of a body.
526
527       Config_Body_Index : Name_Id := No_Name;
528       --  The template for a pragma Source_File_Name(_Project) for a specific
529       --  file name of a body in a multi-source file.
530
531       Config_Body_Pattern : Name_Id := No_Name;
532       --  The template for a pragma Source_File_Name(_Project) for a naming
533       --  body pattern.
534
535       Config_Spec : Name_Id := No_Name;
536       --  The template for a pragma Source_File_Name(_Project) for a specific
537       --  file name of a spec.
538
539       Config_Spec_Index : Name_Id := No_Name;
540       --  The template for a pragma Source_File_Name(_Project) for a specific
541       --  file name of a spec in a multi-source file.
542
543       Config_Spec_Pattern : Name_Id := No_Name;
544       --  The template for a pragma Source_File_Name(_Project) for a naming
545       --  spec pattern.
546
547       Config_File_Unique : Boolean := False;
548       --  Indicate if the config file specified to the compiler needs to be
549       --  unique. If it is unique, then all config files are concatenated into
550       --  a temp config file.
551
552       Binder_Driver : File_Name_Type := No_File;
553       --  The name of the binder driver for the language, if any
554
555       Binder_Driver_Path : Path_Name_Type := No_Path;
556       --  The path name of the binder driver
557
558       Binder_Required_Switches : Name_List_Index := No_Name_List;
559       --  Hold the value of attribute Binder'Required_Switches for the language
560
561       Binder_Prefix : Name_Id := No_Name;
562       --  Hold the value of attribute Binder'Prefix for the language
563
564       Toolchain_Version : Name_Id := No_Name;
565       --  Hold the value of attribute Toolchain_Version for the language
566
567       Toolchain_Description : Name_Id := No_Name;
568       --  Hold the value of attribute Toolchain_Description for the language
569
570    end record;
571
572    No_Language_Config : constant Language_Config :=
573                           (Kind                         => File_Based,
574                            Naming_Data                  => No_Lang_Naming_Data,
575                            Include_Compatible_Languages => No_Name_List,
576                            Compiler_Driver              => No_File,
577                            Compiler_Driver_Path         => null,
578                            Compiler_Leading_Required_Switches  => No_Name_List,
579                            Compiler_Trailing_Required_Switches => No_Name_List,
580                            Multi_Unit_Switches          => No_Name_List,
581                            Multi_Unit_Object_Separator  => ' ',
582                            Path_Syntax                  => Canonical,
583                            Object_File_Suffix           => No_Name,
584                            Object_File_Switches         => No_Name_List,
585                            Compilation_PIC_Option       => No_Name_List,
586                            Object_Generated             => True,
587                            Objects_Linked               => True,
588                            Runtime_Library_Dir          => No_Name,
589                            Runtime_Source_Dir           => No_Name,
590                            Mapping_File_Switches        => No_Name_List,
591                            Mapping_Spec_Suffix          => No_File,
592                            Mapping_Body_Suffix          => No_File,
593                            Config_File_Switches         => No_Name_List,
594                            Dependency_Kind              => None,
595                            Dependency_Option            => No_Name_List,
596                            Compute_Dependency           => No_Name_List,
597                            Include_Option               => No_Name_List,
598                            Include_Path                 => No_Name,
599                            Include_Path_File            => No_Name,
600                            Objects_Path                 => No_Name,
601                            Objects_Path_File            => No_Name,
602                            Config_Body                  => No_Name,
603                            Config_Body_Index            => No_Name,
604                            Config_Body_Pattern          => No_Name,
605                            Config_Spec                  => No_Name,
606                            Config_Spec_Index            => No_Name,
607                            Config_Spec_Pattern          => No_Name,
608                            Config_File_Unique           => False,
609                            Binder_Driver                => No_File,
610                            Binder_Driver_Path           => No_Path,
611                            Binder_Required_Switches     => No_Name_List,
612                            Binder_Prefix                => No_Name,
613                            Toolchain_Version            => No_Name,
614                            Toolchain_Description        => No_Name);
615
616    --  The following record ???
617
618    type Language_Data is record
619       Name          : Name_Id         := No_Name;
620       Display_Name  : Name_Id         := No_Name;
621       Config        : Language_Config := No_Language_Config;
622       First_Source  : Source_Id       := No_Source;
623       Mapping_Files : Mapping_Files_Htable.Instance :=
624                         Mapping_Files_Htable.Nil;
625       Next          : Language_Ptr  := No_Language_Index;
626    end record;
627
628    No_Language_Data : constant Language_Data :=
629                         (Name          => No_Name,
630                          Display_Name  => No_Name,
631                          Config        => No_Language_Config,
632                          First_Source  => No_Source,
633                          Mapping_Files => Mapping_Files_Htable.Nil,
634                          Next          => No_Language_Index);
635
636    type Language_List_Element;
637    type Language_List is access all Language_List_Element;
638    type Language_List_Element is record
639       Language : Language_Ptr := No_Language_Index;
640       Next     : Language_List;
641    end record;
642
643    type Source_Kind is (Spec, Impl, Sep);
644    subtype Spec_Or_Body is Source_Kind range Spec .. Impl;
645
646    --  The following declarations declare a structure used to store the Name
647    --  and File and Path names of a unit, with a reference to its GNAT Project
648    --  File(s). Some units might have neither Spec nor Impl when they were
649    --  created for a "separate".
650
651    type File_Names_Data is array (Spec_Or_Body) of Source_Id;
652
653    type Unit_Data is record
654       Name       : Name_Id := No_Name;
655       File_Names : File_Names_Data;
656    end record;
657
658    type Unit_Index is access all Unit_Data;
659
660    No_Unit_Index : constant Unit_Index := null;
661    --  Used to indicate a null entry for no unit
662
663    type Source_Roots;
664    type Roots_Access is access Source_Roots;
665    type Source_Roots is record
666       Root : Source_Id;
667       Next : Roots_Access;
668    end record;
669    --  A list to store the roots associated with a main unit. These are the
670    --  files that need to linked along with the main (for instance a C file
671    --  corresponding to an Ada file). In general, these are dependencies that
672    --  cannot be computed automatically by the builder.
673
674    --  Structure to define source data
675
676    type Source_Data is record
677       Initialized : Boolean := False;
678       --  Set to True when Source_Data is completely initialized
679
680       Project : Project_Id := No_Project;
681       --  Project of the source
682
683       Location : Source_Ptr := No_Location;
684       --  Location in the project file of the declaration of the source in
685       --  package Naming.
686
687       Source_Dir_Rank : Natural := 0;
688       --  The rank of the source directory in list declared with attribute
689       --  Source_Dirs. Two source files with the same name cannot appears in
690       --  different directory with the same rank. That can happen when the
691       --  recursive notation <dir>/** is used in attribute Source_Dirs.
692
693       Language : Language_Ptr := No_Language_Index;
694       --  Index of the language. This is an index into
695       --  Project_Tree.Languages_Data.
696
697       In_Interfaces : Boolean := True;
698       --  False when the source is not included in interfaces, when attribute
699       --  Interfaces is declared.
700
701       Declared_In_Interfaces : Boolean := False;
702       --  True when source is declared in attribute Interfaces
703
704       Alternate_Languages : Language_List := null;
705       --  List of languages a header file may also be, in addition of language
706       --  Language_Name.
707
708       Kind : Source_Kind := Spec;
709       --  Kind of the source: spec, body or subunit
710
711       Unit : Unit_Index := No_Unit_Index;
712       --  Name of the unit, if language is unit based. This is only set for
713       --  those files that are part of the compilation set (for instance a
714       --  file in an extended project that is overridden will not have this
715       --  field set).
716
717       Index : Int := 0;
718       --  Index of the source in a multi unit source file (the same Source_Data
719       --  is duplicated several times when there are several units in the same
720       --  file). Index is 0 if there is either no unit or a single one, and
721       --  starts at 1 when there are multiple units
722
723       Compilable : Yes_No_Unknown := Unknown;
724       --  Updated at the first call to Is_Compilable. Yes if source file is
725       --  compilable.
726
727       In_The_Queue : Boolean := False;
728       --  True if the source has been put in the queue
729
730       Locally_Removed : Boolean := False;
731       --  True if the source has been "excluded"
732
733       Replaced_By : Source_Id := No_Source;
734       --  Missing comment ???
735
736       File : File_Name_Type := No_File;
737       --  Canonical file name of the source
738
739       Display_File : File_Name_Type := No_File;
740       --  File name of the source, for display purposes
741
742       Path : Path_Information := No_Path_Information;
743       --  Path name of the source
744
745       Source_TS : Time_Stamp_Type := Empty_Time_Stamp;
746       --  Time stamp of the source file
747
748       Object_Project : Project_Id := No_Project;
749       --  Project where the object file is. This might be different from
750       --  Project when using extending project files.
751
752       Object : File_Name_Type := No_File;
753       --  File name of the object file
754
755       Current_Object_Path : Path_Name_Type := No_Path;
756       --  Object path of an existing object file
757
758       Object_Path : Path_Name_Type := No_Path;
759       --  Object path of the real object file
760
761       Object_TS : Time_Stamp_Type := Empty_Time_Stamp;
762       --  Object file time stamp
763
764       Dep_Name : File_Name_Type := No_File;
765       --  Dependency file simple name
766
767       Current_Dep_Path : Path_Name_Type := No_Path;
768       --  Path name of an existing dependency file
769
770       Dep_Path : Path_Name_Type := No_Path;
771       --  Path name of the real dependency file
772
773       Dep_TS : aliased Osint.File_Attributes := Osint.Unknown_Attributes;
774       --  Dependency file time stamp
775
776       Switches : File_Name_Type := No_File;
777       --  File name of the switches file. For all languages, this is a file
778       --  that ends with the .cswi extension.
779
780       Switches_Path : Path_Name_Type := No_Path;
781       --  Path name of the switches file
782
783       Switches_TS : Time_Stamp_Type := Empty_Time_Stamp;
784       --  Switches file time stamp
785
786       Naming_Exception : Boolean := False;
787       --  True if the source has an exceptional name
788
789       Duplicate_Unit : Boolean := False;
790       --  True when a duplicate unit has been reported for this source
791
792       Next_In_Lang : Source_Id := No_Source;
793       --  Link to another source of the same language in the same project
794
795       Next_With_File_Name : Source_Id := No_Source;
796       --  Link to another source with the same base file name
797
798       Roots : Roots_Access := null;
799       --  The roots for a main unit
800
801    end record;
802
803    No_Source_Data : constant Source_Data :=
804                       (Initialized            => False,
805                        Project                => No_Project,
806                        Location               => No_Location,
807                        Source_Dir_Rank        => 0,
808                        Language               => No_Language_Index,
809                        In_Interfaces          => True,
810                        Declared_In_Interfaces => False,
811                        Alternate_Languages    => null,
812                        Kind                   => Spec,
813                        Unit                   => No_Unit_Index,
814                        Index                  => 0,
815                        Locally_Removed        => False,
816                        Compilable             => Unknown,
817                        In_The_Queue           => False,
818                        Replaced_By            => No_Source,
819                        File                   => No_File,
820                        Display_File           => No_File,
821                        Path                   => No_Path_Information,
822                        Source_TS              => Empty_Time_Stamp,
823                        Object_Project         => No_Project,
824                        Object                 => No_File,
825                        Current_Object_Path    => No_Path,
826                        Object_Path            => No_Path,
827                        Object_TS              => Empty_Time_Stamp,
828                        Dep_Name               => No_File,
829                        Current_Dep_Path       => No_Path,
830                        Dep_Path               => No_Path,
831                        Dep_TS                 => Osint.Unknown_Attributes,
832                        Switches               => No_File,
833                        Switches_Path          => No_Path,
834                        Switches_TS            => Empty_Time_Stamp,
835                        Naming_Exception       => False,
836                        Duplicate_Unit         => False,
837                        Next_In_Lang           => No_Source,
838                        Next_With_File_Name    => No_Source,
839                        Roots                  => null);
840
841    package Source_Files_Htable is new Simple_HTable
842      (Header_Num => Header_Num,
843       Element    => Source_Id,
844       No_Element => No_Source,
845       Key        => File_Name_Type,
846       Hash       => Hash,
847       Equal      => "=");
848    --  Mapping of source file names to source ids
849
850    package Source_Paths_Htable is new Simple_HTable
851      (Header_Num => Header_Num,
852       Element    => Source_Id,
853       No_Element => No_Source,
854       Key        => Path_Name_Type,
855       Hash       => Hash,
856       Equal      => "=");
857    --  Mapping of source paths to source ids
858
859    package Unit_Sources_Htable is new Simple_HTable
860      (Header_Num => Header_Num,
861       Element    => Source_Id,
862       No_Element => No_Source,
863       Key        => Name_Id,
864       Hash       => Hash,
865       Equal      => "=");
866
867    type Lib_Kind is (Static, Dynamic, Relocatable);
868
869    type Policy is (Autonomous, Compliant, Controlled, Restricted, Direct);
870    --  Type to specify the symbol policy, when symbol control is supported.
871    --  See full explanation about this type in package Symbols.
872    --    Autonomous: Create a symbol file without considering any reference
873    --    Compliant:  Try to be as compatible as possible with an existing ref
874    --    Controlled: Fail if symbols are not the same as those in the reference
875    --    Restricted: Restrict the symbols to those in the symbol file
876    --    Direct:     The symbol file is used as is
877
878    type Symbol_Record is record
879       Symbol_File   : Path_Name_Type := No_Path;
880       Reference     : Path_Name_Type := No_Path;
881       Symbol_Policy : Policy  := Autonomous;
882    end record;
883    --  Type to keep the symbol data to be used when building a shared library
884
885    No_Symbols : constant Symbol_Record :=
886      (Symbol_File   => No_Path,
887       Reference     => No_Path,
888       Symbol_Policy => Autonomous);
889    --  The default value of the symbol data
890
891    function Image (The_Casing : Casing_Type) return String;
892    --  Similar to 'Image (but avoid use of this attribute in compiler)
893
894    function Value (Image : String) return Casing_Type;
895    --  Similar to 'Value (but avoid use of this attribute in compiler)
896    --  Raises Constraint_Error if not a Casing_Type image.
897
898    --  The following record contains data for a naming scheme
899
900    function Get_Object_Directory
901      (Project             : Project_Id;
902       Including_Libraries : Boolean;
903       Only_If_Ada         : Boolean := False) return Path_Name_Type;
904    --  Return the object directory to use for the project. This depends on
905    --  whether we have a library project or a standard project. This function
906    --  might return No_Name when no directory applies.
907    --  If we have a library project file and Including_Libraries is True then
908    --  the library dir is returned instead of the object dir.
909    --  If Only_If_Ada is True, then No_Name will be returned when the project
910    --  doesn't Ada sources.
911
912    procedure Compute_All_Imported_Projects (Tree : Project_Tree_Ref);
913    --  For all projects in the tree, compute the list of the projects imported
914    --  directly or indirectly by project Project. The result is stored in
915    --  Project.All_Imported_Projects for each project
916
917    function Ultimate_Extending_Project_Of
918      (Proj : Project_Id) return Project_Id;
919    --  Returns the ultimate extending project of project Proj. If project Proj
920    --  is not extended, returns Proj.
921
922    type Project_List_Element;
923    type Project_List is access all Project_List_Element;
924    type Project_List_Element is record
925       Project : Project_Id   := No_Project;
926       Next    : Project_List := null;
927    end record;
928    --  A list of projects
929
930    procedure Free_List
931      (List         : in out Project_List;
932       Free_Project : Boolean);
933    --  Free the list of projects, if Free_Project, each project is also freed
934
935    type Response_File_Format is
936      (None,
937       GNU,
938       Object_List,
939       Option_List,
940       GCC,
941       GCC_GNU,
942       GCC_Object_List,
943       GCC_Option_List);
944    --  The format of the different response files
945
946    type Project_Configuration is record
947       Target : Name_Id := No_Name;
948       --  The target of the configuration, when specified
949
950       Run_Path_Option : Name_List_Index := No_Name_List;
951       --  The option to use when linking to specify the path where to look for
952       --  libraries.
953
954       Run_Path_Origin : Name_Id := No_Name;
955       --  Specify the string (such as "$ORIGIN") to indicate paths relative to
956       --  the directory of the executable in the run path option.
957
958       Library_Install_Name_Option : Name_Id := No_Name;
959       --  When this is not an empty list, this option, followed by the single
960       --  name of the shared library file is used when linking a shared
961       --  library.
962
963       Separate_Run_Path_Options : Boolean := False;
964       --  True if each directory needs to be specified in a separate run path
965       --  option.
966
967       Executable_Suffix : Name_Id := No_Name;
968       --  The suffix of executables, when specified in the configuration or in
969       --  package Builder of the main project. When this is not specified, the
970       --  executable suffix is the default for the platform.
971
972       --  Linking
973
974       Linker : Path_Name_Type := No_Path;
975       --  Path name of the linker driver. Specified in the configuration or in
976       --  the package Builder of the main project.
977
978       Map_File_Option : Name_Id := No_Name;
979       --  Option to use when invoking the linker to build a map file
980
981       Trailing_Linker_Required_Switches : Name_List_Index := No_Name_List;
982       --  The minimum options for the linker driver. Specified in the
983       --  configuration.
984
985       Linker_Executable_Option : Name_List_Index := No_Name_List;
986       --  The option(s) to indicate the name of the executable in the linker
987       --  command. Specified in the configuration. When not specified, default
988       --  to -o <executable name>.
989
990       Linker_Lib_Dir_Option : Name_Id := No_Name;
991       --  The option to specify where to find a library for linking. Specified
992       --  in the configuration. When not specified, defaults to "-L".
993
994       Linker_Lib_Name_Option : Name_Id := No_Name;
995       --  The option to specify the name of a library for linking. Specified in
996       --  the configuration. When not specified, defaults to "-l".
997
998       Max_Command_Line_Length : Natural := 0;
999       --  When positive and when Resp_File_Format (see below) is not None,
1000       --  if the command line for the invocation of the linker would be greater
1001       --  than this value, a response file is used to invoke the linker.
1002
1003       Resp_File_Format : Response_File_Format := None;
1004       --  The format of a response file, when linking with a response file is
1005       --  supported.
1006
1007       Resp_File_Options : Name_List_Index := No_Name_List;
1008       --  The switches, if any, that precede the path name of the response
1009       --  file in the invocation of the linker.
1010
1011       --  Libraries
1012
1013       Library_Builder : Path_Name_Type  := No_Path;
1014       --  The executable to build library (specified in the configuration)
1015
1016       Lib_Support : Library_Support := None;
1017       --  The level of library support. Specified in the configuration. Support
1018       --  is none, static libraries only or both static and shared libraries.
1019
1020       Archive_Builder : Name_List_Index := No_Name_List;
1021       --  The name of the executable to build archives, with the minimum
1022       --  switches. Specified in the configuration.
1023
1024       Archive_Builder_Append_Option : Name_List_Index := No_Name_List;
1025       --  The options to append object files to an archive
1026
1027       Archive_Indexer : Name_List_Index := No_Name_List;
1028       --  The name of the executable to index archives, with the minimum
1029       --  switches. Specified in the configuration.
1030
1031       Archive_Suffix : File_Name_Type := No_File;
1032       --  The suffix of archives. Specified in the configuration. When not
1033       --  specified, defaults to ".a".
1034
1035       Lib_Partial_Linker : Name_List_Index := No_Name_List;
1036
1037       --  Shared libraries
1038
1039       Shared_Lib_Driver : File_Name_Type := No_File;
1040       --  The driver to link shared libraries. Set with attribute Library_GCC.
1041       --  Default to gcc.
1042
1043       Shared_Lib_Prefix : File_Name_Type := No_File;
1044       --  Part of a shared library file name that precedes the name of the
1045       --  library. Specified in the configuration. When not specified, defaults
1046       --  to "lib".
1047
1048       Shared_Lib_Suffix : File_Name_Type := No_File;
1049       --  Suffix of shared libraries, after the library name in the shared
1050       --  library name. Specified in the configuration. When not specified,
1051       --  default to ".so".
1052
1053       Shared_Lib_Min_Options : Name_List_Index := No_Name_List;
1054       --  The minimum options to use when building a shared library
1055
1056       Lib_Version_Options : Name_List_Index := No_Name_List;
1057       --  The options to use to specify a library version
1058
1059       Symbolic_Link_Supported : Boolean := False;
1060       --  True if the platform supports symbolic link files
1061
1062       Lib_Maj_Min_Id_Supported : Boolean := False;
1063       --  True if platform supports library major and minor options, such as
1064       --  libname.so -> libname.so.2 -> libname.so.2.4
1065
1066       Auto_Init_Supported : Boolean := False;
1067       --  True if automatic initialisation is supported for shared stand-alone
1068       --  libraries.
1069    end record;
1070
1071    Default_Project_Config : constant Project_Configuration :=
1072                               (Target                        => No_Name,
1073                                Run_Path_Option               => No_Name_List,
1074                                Run_Path_Origin               => No_Name,
1075                                Library_Install_Name_Option   => No_Name,
1076                                Separate_Run_Path_Options     => False,
1077                                Executable_Suffix             => No_Name,
1078                                Linker                        => No_Path,
1079                                Map_File_Option               => No_Name,
1080                                Trailing_Linker_Required_Switches =>
1081                                  No_Name_List,
1082                                Linker_Executable_Option      => No_Name_List,
1083                                Linker_Lib_Dir_Option         => No_Name,
1084                                Linker_Lib_Name_Option        => No_Name,
1085                                Library_Builder               => No_Path,
1086                                Max_Command_Line_Length       => 0,
1087                                Resp_File_Format              => None,
1088                                Resp_File_Options             => No_Name_List,
1089                                Lib_Support                   => None,
1090                                Archive_Builder               => No_Name_List,
1091                                Archive_Builder_Append_Option => No_Name_List,
1092                                Archive_Indexer               => No_Name_List,
1093                                Archive_Suffix                => No_File,
1094                                Lib_Partial_Linker            => No_Name_List,
1095                                Shared_Lib_Driver             => No_File,
1096                                Shared_Lib_Prefix             => No_File,
1097                                Shared_Lib_Suffix             => No_File,
1098                                Shared_Lib_Min_Options        => No_Name_List,
1099                                Lib_Version_Options           => No_Name_List,
1100                                Symbolic_Link_Supported       => False,
1101                                Lib_Maj_Min_Id_Supported      => False,
1102                                Auto_Init_Supported           => False);
1103
1104    -------------------------
1105    -- Aggregated projects --
1106    -------------------------
1107
1108    type Aggregated_Project;
1109    type Aggregated_Project_List is access all Aggregated_Project;
1110    type Aggregated_Project is record
1111       Path    : Path_Name_Type;
1112       Tree    : Project_Tree_Ref;
1113       Project : Project_Id;
1114       Next    : Aggregated_Project_List;
1115    end record;
1116
1117    procedure Free (List : in out Aggregated_Project_List);
1118    --  Free the memory used for List
1119
1120    procedure Add_Aggregated_Project
1121      (Project : Project_Id;
1122       Path    : Path_Name_Type);
1123    --  Add a new aggregated project in Project.
1124    --  The aggregated project has not been processed yet. This procedure should
1125    --  the called while processing the aggregate project, and as a result
1126    --  Prj.Proc.Process will then automatically process the aggregated projects
1127
1128    ------------------
1129    -- Project_Data --
1130    ------------------
1131
1132    --  The following record describes a project file representation
1133
1134    type Project_Data (Qualifier : Project_Qualifier := Unspecified) is record
1135
1136       -------------
1137       -- General --
1138       -------------
1139
1140       Name : Name_Id := No_Name;
1141       --  The name of the project
1142
1143       Display_Name : Name_Id := No_Name;
1144       --  The name of the project with the spelling of its declaration
1145
1146       Externally_Built : Boolean := False;
1147       --  True if the project is externally built. In such case, the Project
1148       --  Manager will not modify anything in this project.
1149
1150       Config : Project_Configuration;
1151
1152       Path : Path_Information := No_Path_Information;
1153       --  The path name of the project file. This include base name of the
1154       --  project file.
1155
1156       Virtual : Boolean := False;
1157       --  True for virtual extending projects
1158
1159       Location : Source_Ptr := No_Location;
1160       --  The location in the project file source of the reserved word project
1161
1162       ---------------
1163       -- Languages --
1164       ---------------
1165
1166       Languages : Language_Ptr := No_Language_Index;
1167       --  First index of the language data in the project.
1168       --  This is an index into the project_tree_data.languages_data.
1169       --  Traversing the list gives access to all the languages supported by
1170       --  the project.
1171
1172       --------------
1173       -- Projects --
1174       --------------
1175
1176       Mains : String_List_Id := Nil_String;
1177       --  List of mains specified by attribute Main
1178
1179       Extends : Project_Id := No_Project;
1180       --  The reference of the project file, if any, that this project file
1181       --  extends.
1182
1183       Extended_By : Project_Id := No_Project;
1184       --  The reference of the project file, if any, that extends this project
1185       --  file.
1186
1187       Decl : Declarations := No_Declarations;
1188       --  The declarations (variables, attributes and packages) of this project
1189       --  file.
1190
1191       Imported_Projects : Project_List := null;
1192       --  The list of all directly imported projects, if any
1193
1194       All_Imported_Projects : Project_List := null;
1195       --  The list of all projects imported directly or indirectly, if any.
1196       --  This does not include the project itself.
1197
1198       -----------------
1199       -- Directories --
1200       -----------------
1201
1202       Directory : Path_Information := No_Path_Information;
1203       --  Path name of the directory where the project file resides
1204
1205       Object_Directory : Path_Information := No_Path_Information;
1206       --  The path name of the object directory of this project file
1207
1208       Exec_Directory : Path_Information := No_Path_Information;
1209       --  The path name of the exec directory of this project file. Default is
1210       --  equal to Object_Directory.
1211
1212       -------------
1213       -- Library --
1214       -------------
1215
1216       Library : Boolean := False;
1217       --  True if this is a library project
1218
1219       Library_Name : Name_Id := No_Name;
1220       --  If a library project, name of the library
1221
1222       Library_Kind : Lib_Kind := Static;
1223       --  If a library project, kind of library
1224
1225       Library_Dir : Path_Information := No_Path_Information;
1226       --  If a library project, path name of the directory where the library
1227       --  resides.
1228
1229       Library_TS : Time_Stamp_Type := Empty_Time_Stamp;
1230       --  The timestamp of a library file in a library project
1231
1232       Library_Src_Dir : Path_Information := No_Path_Information;
1233       --  If a Stand-Alone Library project, path name of the directory where
1234       --  the sources of the interfaces of the library are copied. By default,
1235       --  if attribute Library_Src_Dir is not specified, sources of the
1236       --  interfaces are not copied anywhere.
1237
1238       Library_ALI_Dir : Path_Information := No_Path_Information;
1239       --  In a library project, path name of the directory where the ALI files
1240       --  are copied. If attribute Library_ALI_Dir is not specified, ALI files
1241       --  are copied in the Library_Dir.
1242
1243       Lib_Internal_Name : Name_Id := No_Name;
1244       --  If a library project, internal name store inside the library
1245
1246       Standalone_Library : Boolean := False;
1247       --  Indicate that this is a Standalone Library Project File
1248
1249       Lib_Interface_ALIs : String_List_Id := Nil_String;
1250       --  For Standalone Library Project Files, indicate the list of Interface
1251       --  ALI files.
1252
1253       Lib_Auto_Init : Boolean := False;
1254       --  For non static Stand-Alone Library Project Files, indicate if
1255       --  the library initialisation should be automatic.
1256
1257       Symbol_Data : Symbol_Record := No_Symbols;
1258       --  Symbol file name, reference symbol file name, symbol policy
1259
1260       Need_To_Build_Lib : Boolean := False;
1261       --  Indicates that the library of a Library Project needs to be built or
1262       --  rebuilt.
1263
1264       -------------
1265       -- Sources --
1266       -------------
1267       --  The sources for all languages including Ada are accessible through
1268       --  the Source_Iterator type
1269
1270       Interfaces_Defined : Boolean := False;
1271       --  True if attribute Interfaces is declared for the project or any
1272       --  project it extends.
1273
1274       Include_Path_File : Path_Name_Type := No_Path;
1275       --  The path name of the of the source search directory file.
1276       --  This is only used by gnatmake
1277
1278       Source_Dirs : String_List_Id := Nil_String;
1279       --  The list of all the source directories
1280
1281       Source_Dir_Ranks : Number_List_Index := No_Number_List;
1282
1283       Ada_Include_Path : String_Access := null;
1284       --  The cached value of source search path for this project file. Set by
1285       --  the first call to Prj.Env.Ada_Include_Path for the project. Do not
1286       --  use this field directly outside of the project manager, use
1287       --  Prj.Env.Ada_Include_Path instead.
1288
1289       Has_Multi_Unit_Sources : Boolean := False;
1290       --  Whether there is at least one source file containing multiple units
1291
1292       -------------------
1293       -- Miscellaneous --
1294       -------------------
1295
1296       Ada_Objects_Path : String_Access := null;
1297       --  The cached value of ADA_OBJECTS_PATH for this project file. Do not
1298       --  use this field directly outside of the compiler, use
1299       --  Prj.Env.Ada_Objects_Path instead.
1300
1301       Libgnarl_Needed : Yes_No_Unknown := Unknown;
1302       --  Set to True when libgnarl is needed to link
1303
1304       Objects_Path : String_Access := null;
1305       --  The cached value of the object dir path, used during the binding
1306       --  phase of gprbuild.
1307
1308       Objects_Path_File_With_Libs : Path_Name_Type := No_Path;
1309       --  The cached value of the object path temp file (including library
1310       --  dirs) for this project file.
1311
1312       Objects_Path_File_Without_Libs : Path_Name_Type := No_Path;
1313       --  The cached value of the object path temp file (excluding library
1314       --  dirs) for this project file.
1315
1316       Config_File_Name : Path_Name_Type := No_Path;
1317       --  The path name of the configuration pragmas file, if any
1318
1319       Config_File_Temp : Boolean := False;
1320       --  An indication that the configuration pragmas file is a temporary file
1321       --  that must be deleted at the end.
1322
1323       Config_Checked : Boolean := False;
1324       --  A flag to avoid checking repetitively the configuration pragmas file
1325
1326       Depth : Natural := 0;
1327       --  The maximum depth of a project in the project graph. Depth of main
1328       --  project is 0.
1329
1330       Unkept_Comments : Boolean := False;
1331       --  True if there are comments in the project sources that cannot be kept
1332       --  in the project tree.
1333
1334       -----------------------------
1335       -- Qualifier-Specific data --
1336       -----------------------------
1337
1338       --  The following fields are only valid for specific types of projects
1339
1340       case Qualifier is
1341          when Aggregate =>
1342             Aggregated_Projects : Aggregated_Project_List := null;
1343             --  List of aggregated projects (which could themselves be
1344             --  aggregate projects).
1345
1346          when others =>
1347             null;
1348       end case;
1349    end record;
1350
1351    function Empty_Project (Qualifier : Project_Qualifier) return  Project_Data;
1352    --  Return the representation of an empty project
1353
1354    function Is_Extending
1355      (Extending : Project_Id;
1356       Extended  : Project_Id) return Boolean;
1357    --  Return True if Extending is extending the Extended project
1358
1359    function Has_Ada_Sources (Data : Project_Id) return Boolean;
1360    --  Return True if the project has Ada sources
1361
1362    Project_Error : exception;
1363    --  Raised by some subprograms in Prj.Attr
1364
1365    package Units_Htable is new Simple_HTable
1366      (Header_Num => Header_Num,
1367       Element    => Unit_Index,
1368       No_Element => No_Unit_Index,
1369       Key        => Name_Id,
1370       Hash       => Hash,
1371       Equal      => "=");
1372    --  Mapping of unit names to indexes in the Units table
1373
1374    ---------------------
1375    -- Source_Iterator --
1376    ---------------------
1377
1378    type Source_Iterator is private;
1379
1380    function For_Each_Source
1381      (In_Tree  : Project_Tree_Ref;
1382       Project  : Project_Id := No_Project;
1383       Language : Name_Id := No_Name) return Source_Iterator;
1384    --  Returns an iterator for all the sources of a project tree, or a specific
1385    --  project, or a specific language.
1386
1387    function Element (Iter : Source_Iterator) return Source_Id;
1388    --  Return the current source (or No_Source if there are no more sources)
1389
1390    procedure Next (Iter : in out Source_Iterator);
1391    --  Move on to the next source
1392
1393    function Find_Source
1394      (In_Tree          : Project_Tree_Ref;
1395       Project          : Project_Id;
1396       In_Imported_Only : Boolean := False;
1397       In_Extended_Only : Boolean := False;
1398       Base_Name        : File_Name_Type;
1399       Index            : Int := 0) return Source_Id;
1400    --  Find the first source file with the given name.
1401    --  If In_Extended_Only is True, it will search in project and the project
1402    --     it extends, but not in the imported projects.
1403    --  Elsif In_Imported_Only is True, it will search in project and the
1404    --     projects it imports, but not in the others or in aggregated projects.
1405    --  Else it searches in the whole tree.
1406    --  If Index is specified, this only search for a source with that index.
1407
1408    -----------------------
1409    -- Project_Tree_Data --
1410    -----------------------
1411
1412    package Replaced_Source_HTable is new Simple_HTable
1413      (Header_Num => Header_Num,
1414       Element    => File_Name_Type,
1415       No_Element => No_File,
1416       Key        => File_Name_Type,
1417       Hash       => Hash,
1418       Equal      => "=");
1419
1420    type Private_Project_Tree_Data is private;
1421    --  Data for a project tree that is used only by the Project Manager
1422
1423    type Shared_Project_Tree_Data is record
1424       Name_Lists        : Name_List_Table.Instance;
1425       Number_Lists      : Number_List_Table.Instance;
1426       String_Elements   : String_Element_Table.Instance;
1427       Variable_Elements : Variable_Element_Table.Instance;
1428       Array_Elements    : Array_Element_Table.Instance;
1429       Arrays            : Array_Table.Instance;
1430       Packages          : Package_Table.Instance;
1431       Private_Part      : Private_Project_Tree_Data;
1432    end record;
1433    type Shared_Project_Tree_Data_Access is access all Shared_Project_Tree_Data;
1434    --  The data that is shared among multiple trees, when these trees are
1435    --  loaded through the same aggregate project.
1436    --  To avoid ambiguities, limit the number of parameters to the
1437    --  subprograms (we would have to parse the "root project tree" since this
1438    --  is where the configuration file was loaded, in addition to the project's
1439    --  own tree) and make the comparison of projects easier, all trees store
1440    --  the lists in the same tables.
1441
1442    type Project_Tree_Appdata is tagged null record;
1443    type Project_Tree_Appdata_Access is access all Project_Tree_Appdata'Class;
1444    --  Application-specific data that can be associated with a project tree.
1445    --  We do not make the Project_Tree_Data itself tagged for several reasons:
1446    --    - it couldn't have a default value for its discriminant
1447    --    - it would require a "factory" to allocate such data, because trees
1448    --      are created automatically when parsing aggregate projects.
1449
1450    procedure Free (Tree : in out Project_Tree_Appdata);
1451    --  Should be overridden if your derive your own data
1452
1453    type Project_Tree_Data (Is_Root_Tree : Boolean := True) is record
1454       --  The root tree is the one loaded by the user from the command line.
1455       --  Is_Root_Tree is only false for projects aggregated within a root
1456       --  aggregate project.
1457
1458       Projects : Project_List;
1459       --  List of projects in this tree
1460
1461       Replaced_Sources : Replaced_Source_HTable.Instance;
1462       --  The list of sources that have been replaced by sources with
1463       --  different file names.
1464
1465       Replaced_Source_Number : Natural := 0;
1466       --  The number of entries in Replaced_Sources
1467
1468       Units_HT : Units_Htable.Instance;
1469       --  Unit name to Unit_Index (and from there to Source_Id)
1470
1471       Source_Files_HT : Source_Files_Htable.Instance;
1472       --  Base source file names to Source_Id list.
1473
1474       Source_Paths_HT : Source_Paths_Htable.Instance;
1475       --  Full path to Source_Id
1476       --  ??? What is behavior for multi-unit source files, where there are
1477       --  several source_id per file ?
1478
1479       Source_Info_File_Name : String_Access := null;
1480       --  The name of the source info file, if specified by the builder
1481
1482       Source_Info_File_Exists : Boolean := False;
1483       --  True when a source info file has been successfully read
1484
1485       Shared : Shared_Project_Tree_Data_Access;
1486       --  The shared data for this tree and all aggregated trees.
1487
1488       Appdata : Project_Tree_Appdata_Access;
1489       --  Application-specific data for this tree
1490
1491       case Is_Root_Tree is
1492          when True =>
1493             Shared_Data : aliased Shared_Project_Tree_Data;
1494             --  Do not access directly, only through Shared.
1495
1496          when False =>
1497             null;
1498       end case;
1499    end record;
1500    --  Data for a project tree
1501
1502    function Debug_Name (Tree : Project_Tree_Ref) return Name_Id;
1503    --  If debug traces are activated, return an identitier for the project
1504    --  tree. This modifies Name_Buffer.
1505
1506    procedure Expect (The_Token : Token_Type; Token_Image : String);
1507    --  Check that the current token is The_Token. If it is not, then output
1508    --  an error message.
1509
1510    procedure Initialize (Tree : Project_Tree_Ref);
1511    --  This procedure must be called before using any services from the Prj
1512    --  hierarchy. Namet.Initialize must be called before Prj.Initialize.
1513
1514    procedure Reset (Tree : Project_Tree_Ref);
1515    --  This procedure resets all the tables that are used when processing a
1516    --  project file tree. Initialize must be called before the call to Reset.
1517
1518    package Project_Boolean_Htable is new Simple_HTable
1519      (Header_Num => Header_Num,
1520       Element    => Boolean,
1521       No_Element => False,
1522       Key        => Project_Id,
1523       Hash       => Hash,
1524       Equal      => "=");
1525    --  A table that associates a project to a boolean. This is used to detect
1526    --  whether a project was already processed for instance.
1527
1528    generic
1529       with procedure Action (Project : Project_Id; Tree : Project_Tree_Ref);
1530    procedure For_Project_And_Aggregated
1531      (Root_Project : Project_Id;
1532       Root_Tree    : Project_Tree_Ref);
1533    --  Execute Action for Root_Project and all its aggregated projects
1534    --  recursively.
1535
1536    generic
1537       type State is limited private;
1538       with procedure Action
1539         (Project    : Project_Id;
1540          Tree       : Project_Tree_Ref;
1541          With_State : in out State);
1542    procedure For_Every_Project_Imported
1543      (By                 : Project_Id;
1544       Tree               : Project_Tree_Ref;
1545       With_State         : in out State;
1546       Include_Aggregated : Boolean := True;
1547       Imported_First     : Boolean := False);
1548    --  Call Action for each project imported directly or indirectly by project
1549    --  By, as well as extended projects.
1550    --
1551    --  The order of processing depends on Imported_First:
1552    --
1553    --    If False, Action is called according to the order of importation: if A
1554    --    imports B, directly or indirectly, Action will be called for A before
1555    --    it is called for B. If two projects import each other directly or
1556    --    indirectly (using at least one "limited with"), it is not specified
1557    --    for which of these two projects Action will be called first.
1558    --
1559    --    The order is reversed if Imported_First is True
1560    --
1561    --  With_State may be used by Action to choose a behavior or to report some
1562    --  global result.
1563    --
1564    --  If Include_Aggregated is True, then an aggregate project will recurse
1565    --  into the projects it aggregates. Otherwise, the latter are never
1566    --  returned
1567    --
1568    --  The Tree argument passed to the callback is required in the case of
1569    --  aggregated projects, since they might not be using the same tree as 'By'
1570
1571    function Extend_Name
1572      (File        : File_Name_Type;
1573       With_Suffix : String) return File_Name_Type;
1574    --  Replace the extension of File with With_Suffix
1575
1576    function Object_Name
1577      (Source_File_Name   : File_Name_Type;
1578       Object_File_Suffix : Name_Id := No_Name) return File_Name_Type;
1579    --  Returns the object file name corresponding to a source file name
1580
1581    function Object_Name
1582      (Source_File_Name   : File_Name_Type;
1583       Source_Index       : Int;
1584       Index_Separator    : Character;
1585       Object_File_Suffix : Name_Id := No_Name) return File_Name_Type;
1586    --  Returns the object file name corresponding to a unit in a multi-source
1587    --  file.
1588
1589    function Dependency_Name
1590      (Source_File_Name : File_Name_Type;
1591       Dependency       : Dependency_File_Kind) return File_Name_Type;
1592    --  Returns the dependency file name corresponding to a source file name
1593
1594    function Switches_Name
1595      (Source_File_Name : File_Name_Type) return File_Name_Type;
1596    --  Returns the switches file name corresponding to a source file name
1597
1598    -----------
1599    -- Flags --
1600    -----------
1601
1602    type Processing_Flags is private;
1603    --  Flags used while parsing and processing a project tree to configure the
1604    --  behavior of the parser, and indicate how to report error messages. This
1605    --  structure does not allocate memory and never needs to be freed
1606
1607    type Error_Warning is (Silent, Warning, Error);
1608    --  Severity of some situations, such as: no Ada sources in a project where
1609    --  Ada is one of the language.
1610    --
1611    --  When the situation occurs, the behaviour depends on the setting:
1612    --
1613    --    - Silent:  no action
1614    --    - Warning: issue a warning, does not cause the tool to fail
1615    --    - Error:   issue an error, causes the tool to fail
1616
1617    type Error_Handler is access procedure
1618      (Project    : Project_Id;
1619       Is_Warning : Boolean);
1620    --  This warns when an error was found when parsing a project. The error
1621    --  itself is handled through Prj.Err (and Prj.Err.Finalize should be called
1622    --  to actually print the error). This ensures that duplicate error messages
1623    --  are always correctly removed, that errors msgs are sorted, and that all
1624    --  tools will report the same error to the user.
1625
1626    function Create_Flags
1627      (Report_Error               : Error_Handler;
1628       When_No_Sources            : Error_Warning;
1629       Require_Sources_Other_Lang : Boolean       := True;
1630       Allow_Duplicate_Basenames  : Boolean       := True;
1631       Compiler_Driver_Mandatory  : Boolean       := False;
1632       Error_On_Unknown_Language  : Boolean       := True;
1633       Require_Obj_Dirs           : Error_Warning := Error;
1634       Allow_Invalid_External     : Error_Warning := Error;
1635       Missing_Source_Files       : Error_Warning := Error;
1636       Ignore_Missing_With        : Boolean       := False)
1637       return Processing_Flags;
1638    --  Function used to create Processing_Flags structure
1639    --
1640    --  If Allow_Duplicate_Basenames, then files with the same base names are
1641    --  authorized within a project for source-based languages (never for unit
1642    --  based languages).
1643    --
1644    --  If Compiler_Driver_Mandatory is true, then a Compiler.Driver attribute
1645    --  for each language must be defined, or we will not look for its source
1646    --  files.
1647    --
1648    --  When_No_Sources indicates what should be done when no sources of a
1649    --  language are found in a project where this language is declared.
1650    --  If Require_Sources_Other_Lang is true, then all languages must have at
1651    --  least one source file, or an error is reported via When_No_Sources. If
1652    --  it is false, this is only required for Ada (and only if it is a language
1653    --  of the project). When this parameter is set to False, we do not check
1654    --  that a proper naming scheme is defined for languages other than Ada.
1655    --
1656    --  If Report_Error is null, use the standard error reporting mechanism
1657    --  (Errout). Otherwise, report errors using Report_Error.
1658    --
1659    --  If Error_On_Unknown_Language is true, an error is displayed if some of
1660    --  the source files listed in the project do not match any naming scheme
1661    --
1662    --  If Require_Obj_Dirs is true, then all object directories must exist
1663    --  (possibly after they have been created automatically if the appropriate
1664    --  switches were specified), or an error is raised.
1665    --
1666    --  If Allow_Invalid_External is Silent, then no error is reported when an
1667    --  invalid value is used for an external variable (and it doesn't match its
1668    --  type). Instead, the first possible value is used.
1669    --
1670    --  Missing_Source_Files indicates whether it is an error or a warning that
1671    --  a source file mentioned in the Source_Files attributes is not actually
1672    --  found in the source directories. This also impacts errors for missing
1673    --  source directories.
1674    --
1675    --  If Ignore_Missing_With is True, then a "with" statement that cannot be
1676    --  resolved will simply be ignored. However, in such a case, the flag
1677    --  Incomplete_With in the project tree will be set to True.
1678    --  This is meant for use by tools so that they can properly set the
1679    --  project path in such a case:
1680    --       * no "gnatls" found (so no default project path)
1681    --       * user project sets Project.IDE'gnatls attribute to a cross gnatls
1682    --       * user project also includes a "with" that can only be resolved
1683    --         once we have found the gnatls
1684
1685    Gprbuild_Flags : constant Processing_Flags;
1686    Gprclean_Flags : constant Processing_Flags;
1687    Gnatmake_Flags : constant Processing_Flags;
1688    --  Flags used by the various tools. They all display the error messages
1689    --  through Prj.Err.
1690
1691    ----------------
1692    -- Temp Files --
1693    ----------------
1694
1695    procedure Record_Temp_File
1696      (Shared : Shared_Project_Tree_Data_Access;
1697       Path   : Path_Name_Type);
1698    --  Record the path of a newly created temporary file, so that it can be
1699    --  deleted later.
1700
1701    procedure Delete_All_Temp_Files
1702      (Shared : Shared_Project_Tree_Data_Access);
1703    --  Delete all recorded temporary files.
1704    --  Does nothing if Debug.Debug_Flag_N is set
1705
1706    procedure Delete_Temp_Config_Files (Project_Tree : Project_Tree_Ref);
1707    --  Delete all temporary config files. Does nothing if Debug.Debug_Flag_N is
1708    --  set or if Project_Tree is null. This initially came from gnatmake
1709    --  ??? Should this be combined with Delete_All_Temp_Files above
1710
1711    procedure Delete_Temporary_File
1712      (Shared : Shared_Project_Tree_Data_Access := null;
1713       Path   : Path_Name_Type);
1714    --  Delete a temporary file from the disk. The file is also removed from the
1715    --  list of temporary files to delete at the end of the program, in case
1716    --  another program running on the same machine has recreated it. Does
1717    --  nothing if Debug.Debug_Flag_N is set
1718
1719    Virtual_Prefix : constant String := "v$";
1720    --  The prefix for virtual extending projects. Because of the '$', which is
1721    --  normally forbidden for project names, there cannot be any name clash.
1722
1723    -----------
1724    -- Debug --
1725    -----------
1726
1727    type Verbosity is (Default, Medium, High);
1728    pragma Ordered (Verbosity);
1729    --  Verbosity when parsing GNAT Project Files
1730    --    Default is default (very quiet, if no errors).
1731    --    Medium is more verbose.
1732    --    High is extremely verbose.
1733
1734    Current_Verbosity : Verbosity := Default;
1735    --  The current value of the verbosity the project files are parsed with
1736
1737    procedure Debug_Indent;
1738    --  Inserts a series of blanks depending on the current indentation level
1739
1740    procedure Debug_Output (Str : String);
1741    procedure Debug_Output (Str : String; Str2 : Name_Id);
1742    --  If Current_Verbosity is not Default, outputs Str.
1743    --  This indents Str based on the current indentation level for traces
1744    --  Debug_Error is intended to be used to report an error in the traces.
1745
1746    procedure Debug_Increase_Indent
1747      (Str : String := ""; Str2 : Name_Id := No_Name);
1748    procedure Debug_Decrease_Indent (Str : String := "");
1749    --  Increase or decrease the indentation level for debug traces. This
1750    --  indentation level only affects output done through Debug_Output.
1751
1752 private
1753
1754    All_Packages : constant String_List_Access := null;
1755
1756    No_Project_Tree : constant Project_Tree_Ref := null;
1757
1758    Ignored : constant Variable_Kind := Single;
1759
1760    Nil_Variable_Value : constant Variable_Value :=
1761                           (Project  => No_Project,
1762                            Kind     => Undefined,
1763                            Location => No_Location,
1764                            Default  => False);
1765
1766    type Source_Iterator is record
1767       In_Tree : Project_Tree_Ref;
1768
1769       Project      : Project_List;
1770       All_Projects : Boolean;
1771       --  Current project and whether we should move on to the next
1772
1773       Language : Language_Ptr;
1774       --  Current language processed
1775
1776       Language_Name : Name_Id;
1777       --  Only sources of this language will be returned (or all if No_Name)
1778
1779       Current : Source_Id;
1780    end record;
1781
1782    procedure Add_To_Buffer
1783      (S    : String;
1784       To   : in out String_Access;
1785       Last : in out Natural);
1786    --  Append a String to the Buffer
1787
1788    package Temp_Files_Table is new GNAT.Dynamic_Tables
1789      (Table_Component_Type => Path_Name_Type,
1790       Table_Index_Type     => Integer,
1791       Table_Low_Bound      => 1,
1792       Table_Initial        => 10,
1793       Table_Increment      => 10);
1794    --  Table to store the path name of all the created temporary files, so that
1795    --  they can be deleted at the end, or when the program is interrupted.
1796
1797    type Private_Project_Tree_Data is record
1798       Temp_Files   : Temp_Files_Table.Instance;
1799       --  Temporary files created as part of running tools (pragma files,
1800       --  mapping files,...)
1801
1802       Current_Source_Path_File : Path_Name_Type := No_Path;
1803       --  Current value of project source path file env var. Used to avoid
1804       --  setting the env var to the same value. When different from No_Path,
1805       --  this indicates that logical names (VMS) or environment variables were
1806       --  created and should be deassigned to avoid polluting the environment
1807       --  on VMS.
1808       --  gnatmake only
1809
1810       Current_Object_Path_File : Path_Name_Type := No_Path;
1811       --  Current value of project object path file env var. Used to avoid
1812       --  setting the env var to the same value.
1813       --  gnatmake only
1814
1815    end record;
1816    --  Type to represent the part of a project tree which is private to the
1817    --  Project Manager.
1818
1819    type Processing_Flags is record
1820       Require_Sources_Other_Lang : Boolean;
1821       Report_Error               : Error_Handler;
1822       When_No_Sources            : Error_Warning;
1823       Allow_Duplicate_Basenames  : Boolean;
1824       Compiler_Driver_Mandatory  : Boolean;
1825       Error_On_Unknown_Language  : Boolean;
1826       Require_Obj_Dirs           : Error_Warning;
1827       Allow_Invalid_External     : Error_Warning;
1828       Missing_Source_Files       : Error_Warning;
1829       Ignore_Missing_With        : Boolean;
1830    end record;
1831
1832    Gprbuild_Flags : constant Processing_Flags :=
1833      (Report_Error               => null,
1834       When_No_Sources            => Warning,
1835       Require_Sources_Other_Lang => True,
1836       Allow_Duplicate_Basenames  => False,
1837       Compiler_Driver_Mandatory  => True,
1838       Error_On_Unknown_Language  => True,
1839       Require_Obj_Dirs           => Error,
1840       Allow_Invalid_External     => Error,
1841       Missing_Source_Files       => Error,
1842       Ignore_Missing_With        => False);
1843
1844    Gprclean_Flags : constant Processing_Flags :=
1845      (Report_Error               => null,
1846       When_No_Sources            => Warning,
1847       Require_Sources_Other_Lang => True,
1848       Allow_Duplicate_Basenames  => False,
1849       Compiler_Driver_Mandatory  => True,
1850       Error_On_Unknown_Language  => True,
1851       Require_Obj_Dirs           => Warning,
1852       Allow_Invalid_External     => Error,
1853       Missing_Source_Files       => Error,
1854       Ignore_Missing_With        => False);
1855
1856    Gnatmake_Flags : constant Processing_Flags :=
1857      (Report_Error               => null,
1858       When_No_Sources            => Error,
1859       Require_Sources_Other_Lang => False,
1860       Allow_Duplicate_Basenames  => False,
1861       Compiler_Driver_Mandatory  => False,
1862       Error_On_Unknown_Language  => False,
1863       Require_Obj_Dirs           => Error,
1864       Allow_Invalid_External     => Error,
1865       Missing_Source_Files       => Error,
1866       Ignore_Missing_With        => False);
1867
1868 end Prj;