OSDN Git Service

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