OSDN Git Service

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