OSDN Git Service

2005-11-14 Vincent Celier <celier@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-2005, 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 2,  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 COPYING.  If not, write --
19 -- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
20 -- Boston, MA 02110-1301, USA.                                              --
21 --                                                                          --
22 -- GNAT was originally developed  by the GNAT team at  New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
24 --                                                                          --
25 ------------------------------------------------------------------------------
26
27 --  The following package declares the data types for GNAT project.
28 --  These data types may be used by GNAT Project-aware tools.
29
30 --  Children of these package implements various services on these data types.
31 --  See in particular Prj.Pars and Prj.Env.
32
33 with Casing; use Casing;
34 with Scans;  use Scans;
35 with Table;
36 with Types;  use Types;
37
38 with GNAT.Dynamic_HTables; use GNAT.Dynamic_HTables;
39 with GNAT.Dynamic_Tables;
40 with GNAT.OS_Lib;           use GNAT.OS_Lib;
41
42 with System.HTable;
43
44 package Prj is
45
46    All_Packages : constant String_List_Access;
47    --  Default value of parameter Packages of procedures Parse, in Prj.Pars and
48    --  Prj.Part, indicating that all packages should be checked.
49
50    type Project_Tree_Data;
51    type Project_Tree_Ref is access all Project_Tree_Data;
52    --  Reference to a project tree.
53    --  Several project trees may exist in memory at the same time.
54
55    No_Project_Tree : constant Project_Tree_Ref;
56
57    function Default_Ada_Spec_Suffix return Name_Id;
58    pragma Inline (Default_Ada_Spec_Suffix);
59    --  The Name_Id for the standard GNAT suffix for Ada spec source file
60    --  name ".ads". Initialized by Prj.Initialize.
61
62    function Default_Ada_Body_Suffix return Name_Id;
63    pragma Inline (Default_Ada_Body_Suffix);
64    --  The Name_Id for the standard GNAT suffix for Ada body source file
65    --  name ".adb". Initialized by Prj.Initialize.
66
67    function Slash return Name_Id;
68    pragma Inline (Slash);
69    --  "/", used as the path of locally removed files
70
71    Project_File_Extension : String := ".gpr";
72    --  The standard project file name extension. It is not a constant, because
73    --  Canonical_Case_File_Name is called on this variable in the body of Prj.
74
75    -----------------------------------------------------
76    -- Multi-language Stuff That Will be Modified Soon --
77    -----------------------------------------------------
78
79    --  Still should be properly commented ???
80
81    type Language_Index is new Nat;
82
83    No_Language_Index           : constant Language_Index := 0;
84    First_Language_Index        : constant Language_Index := 1;
85    First_Language_Indexes_Last : constant Language_Index := 5;
86
87    Ada_Language_Index         : constant Language_Index :=
88                                   First_Language_Index;
89    C_Language_Index           : constant Language_Index :=
90                                   Ada_Language_Index + 1;
91    C_Plus_Plus_Language_Index : constant Language_Index :=
92                                   C_Language_Index + 1;
93
94    Last_Language_Index : Language_Index := No_Language_Index;
95
96    subtype First_Language_Indexes is Language_Index
97       range First_Language_Index .. First_Language_Indexes_Last;
98
99    type Header_Num is range 0 .. 2047;
100
101    function Hash is new System.HTable.Hash (Header_Num => Header_Num);
102
103    function Hash (Name : Name_Id) return Header_Num;
104
105    package Language_Indexes is new System.HTable.Simple_HTable
106      (Header_Num => Header_Num,
107       Element    => Language_Index,
108       No_Element => No_Language_Index,
109       Key        => Name_Id,
110       Hash       => Hash,
111       Equal      => "=");
112    --  Mapping of language names to language indexes
113
114    package Language_Names is new Table.Table
115      (Table_Component_Type => Name_Id,
116       Table_Index_Type     => Language_Index,
117       Table_Low_Bound      => 1,
118       Table_Initial        => 4,
119       Table_Increment      => 100,
120       Table_Name           => "Prj.Language_Names");
121    --  The table for the name of programming languages
122
123    procedure Add_Language_Name (Name : Name_Id);
124
125    procedure Display_Language_Name (Language : Language_Index);
126
127    type Languages_In_Project is array (First_Language_Indexes) of Boolean;
128    --  Set of supported languages used in a project
129
130    No_Languages : constant Languages_In_Project := (others => False);
131    --  No supported languages are used
132
133    type Supp_Language_Index is new Nat;
134    No_Supp_Language_Index  : constant Supp_Language_Index := 0;
135
136    type Supp_Language is record
137       Index   : Language_Index := No_Language_Index;
138       Present : Boolean := False;
139       Next    : Supp_Language_Index := No_Supp_Language_Index;
140    end record;
141
142    package Present_Language_Table is new GNAT.Dynamic_Tables
143      (Table_Component_Type => Supp_Language,
144       Table_Index_Type     => Supp_Language_Index,
145       Table_Low_Bound      => 1,
146       Table_Initial        => 4,
147       Table_Increment      => 100);
148    --  The table for the presence of languages with an index that is outside
149    --  of First_Language_Indexes.
150
151    type Impl_Suffix_Array is array (First_Language_Indexes) of Name_Id;
152    --  Suffixes for the non spec sources of the different supported languages
153    --  in a project.
154
155    No_Impl_Suffixes : constant Impl_Suffix_Array := (others => No_Name);
156    --  A default value for the non spec source suffixes
157
158    type Supp_Suffix is record
159       Index   : Language_Index := No_Language_Index;
160       Suffix  : Name_Id := No_Name;
161       Next    : Supp_Language_Index := No_Supp_Language_Index;
162    end record;
163
164    package Supp_Suffix_Table is new GNAT.Dynamic_Tables
165      (Table_Component_Type => Supp_Suffix,
166       Table_Index_Type     => Supp_Language_Index,
167       Table_Low_Bound      => 1,
168       Table_Initial        => 4,
169       Table_Increment      => 100);
170    --  The table for the presence of languages with an index that is outside
171    --  of First_Language_Indexes.
172
173    type Language_Kind is (GNU, other);
174
175    type Name_List_Index is new Nat;
176    No_Name_List            : constant Name_List_Index := 0;
177
178    type Name_Node is record
179       Name : Name_Id         := No_Name;
180       Next : Name_List_Index := No_Name_List;
181    end record;
182
183    package Name_List_Table is new GNAT.Dynamic_Tables
184      (Table_Component_Type => Name_Node,
185       Table_Index_Type     => Name_List_Index,
186       Table_Low_Bound      => 1,
187       Table_Initial        => 10,
188       Table_Increment      => 100);
189    --  The table for lists of names used in package Language_Processing
190
191    type Language_Processing_Data is record
192       Compiler_Drivers     : Name_List_Index := No_Name_List;
193       Compiler_Paths       : Name_Id         := No_Name;
194       Compiler_Kinds       : Language_Kind   := GNU;
195       Dependency_Options   : Name_List_Index := No_Name_List;
196       Compute_Dependencies : Name_List_Index := No_Name_List;
197       Include_Options      : Name_List_Index := No_Name_List;
198       Binder_Drivers       : Name_Id         := No_Name;
199       Binder_Driver_Paths  : Name_Id         := No_Name;
200    end record;
201
202    Default_Language_Processing_Data :
203      constant Language_Processing_Data :=
204        (Compiler_Drivers     => No_Name_List,
205         Compiler_Paths       => No_Name,
206         Compiler_Kinds       => GNU,
207         Dependency_Options   => No_Name_List,
208         Compute_Dependencies => No_Name_List,
209         Include_Options      => No_Name_List,
210         Binder_Drivers       => No_Name,
211         Binder_Driver_Paths  => No_Name);
212
213    type First_Language_Processing_Data is
214      array (First_Language_Indexes) of Language_Processing_Data;
215
216    Default_First_Language_Processing_Data :
217       constant First_Language_Processing_Data :=
218                  (others => Default_Language_Processing_Data);
219
220    type Supp_Language_Data is record
221       Index : Language_Index := No_Language_Index;
222       Data  : Language_Processing_Data := Default_Language_Processing_Data;
223       Next  : Supp_Language_Index := No_Supp_Language_Index;
224    end record;
225
226    package Supp_Language_Table is new GNAT.Dynamic_Tables
227      (Table_Component_Type => Supp_Language_Data,
228       Table_Index_Type     => Supp_Language_Index,
229       Table_Low_Bound      => 1,
230       Table_Initial        => 4,
231       Table_Increment      => 100);
232    --  The table for language data when there are more languages than
233    --  in First_Language_Indexes.
234
235    type Other_Source_Id is new Nat;
236    No_Other_Source : constant Other_Source_Id := 0;
237
238    type Other_Source is record
239       Language         : Language_Index;       --  language of the source
240       File_Name        : Name_Id;              --  source file simple name
241       Path_Name        : Name_Id;              --  source full path name
242       Source_TS        : Time_Stamp_Type;      --  source file time stamp
243       Object_Name      : Name_Id;              --  object file simple name
244       Object_Path      : Name_Id;              --  object full path name
245       Object_TS        : Time_Stamp_Type;      --  object file time stamp
246       Dep_Name         : Name_Id;              --  dependency file simple name
247       Dep_Path         : Name_Id;              --  dependency full path name
248       Dep_TS           : Time_Stamp_Type;      --  dependency file time stamp
249       Naming_Exception : Boolean := False;     --  True if a naming exception
250       Next             : Other_Source_Id := No_Other_Source;
251    end record;
252    --  Data for a source in a language other than Ada
253
254    package Other_Source_Table is new GNAT.Dynamic_Tables
255      (Table_Component_Type => Other_Source,
256       Table_Index_Type     => Other_Source_Id,
257       Table_Low_Bound      => 1,
258       Table_Initial        => 200,
259       Table_Increment      => 100);
260    --  The table for sources of languages other than Ada
261
262    ----------------------------------
263    --  End of multi-language stuff --
264    ----------------------------------
265
266    type Verbosity is (Default, Medium, High);
267    --  Verbosity when parsing GNAT Project Files
268    --    Default is default (very quiet, if no errors).
269    --    Medium is more verbose.
270    --    High is extremely verbose.
271
272    Current_Verbosity : Verbosity := Default;
273    --  The current value of the verbosity the project files are parsed with
274
275    type Lib_Kind is (Static, Dynamic, Relocatable);
276    type Policy is (Autonomous, Compliant, Controlled, Restricted);
277    --  Type to specify the symbol policy, when symbol control is supported.
278    --  See full explanation about this type in package Symbols.
279    --    Autonomous: Create a symbol file without considering any reference
280    --    Compliant:  Try to be as compatible as possible with an existing ref
281    --    Controlled: Fail if symbols are not the same as those in the reference
282    --    Restricted: Restrict the symbols to those in the symbol file
283
284    type Symbol_Record is record
285       Symbol_File   : Name_Id := No_Name;
286       Reference     : Name_Id := No_Name;
287       Symbol_Policy : Policy  := Autonomous;
288    end record;
289    --  Type to keep the symbol data to be used when building a shared library
290
291    No_Symbols : constant Symbol_Record :=
292      (Symbol_File   => No_Name,
293       Reference     => No_Name,
294       Symbol_Policy => Autonomous);
295    --  The default value of the symbol data
296
297    function Empty_String return Name_Id;
298    --  Return the Name_Id for an empty string ""
299
300    type Project_Id is new Nat;
301    No_Project : constant Project_Id := 0;
302    --  Id of a Project File
303
304    type String_List_Id is new Nat;
305    Nil_String : constant String_List_Id := 0;
306    type String_Element is record
307       Value         : Name_Id        := No_Name;
308       Index         : Int            := 0;
309       Display_Value : Name_Id   := No_Name;
310       Location      : Source_Ptr     := No_Location;
311       Flag          : Boolean        := False;
312       Next          : String_List_Id := Nil_String;
313    end record;
314    --  To hold values for string list variables and array elements.
315    --  Component Flag may be used for various purposes. For source
316    --  directories, it indicates if the directory contains Ada source(s).
317
318    package String_Element_Table is new GNAT.Dynamic_Tables
319      (Table_Component_Type => String_Element,
320       Table_Index_Type     => String_List_Id,
321       Table_Low_Bound      => 1,
322       Table_Initial        => 200,
323       Table_Increment      => 100);
324    --  The table for string elements in string lists
325
326    type Variable_Kind is (Undefined, List, Single);
327    --  Different kinds of variables
328
329    subtype Defined_Variable_Kind is Variable_Kind range List .. Single;
330    --  The defined kinds of variables
331
332    Ignored : constant Variable_Kind;
333    --  Used to indicate that a package declaration must be ignored
334    --  while processing the project tree (unknown package name).
335
336    type Variable_Value (Kind : Variable_Kind := Undefined) is record
337       Project  : Project_Id := No_Project;
338       Location : Source_Ptr := No_Location;
339       Default  : Boolean    := False;
340       case Kind is
341          when Undefined =>
342             null;
343          when List =>
344             Values : String_List_Id := Nil_String;
345          when Single =>
346             Value : Name_Id := No_Name;
347             Index : Int     := 0;
348       end case;
349    end record;
350    --  Values for variables and array elements. Default is True if the
351    --  current value is the default one for the variable
352
353    Nil_Variable_Value : constant Variable_Value;
354    --  Value of a non existing variable or array element
355
356    type Variable_Id is new Nat;
357    No_Variable : constant Variable_Id := 0;
358    type Variable is record
359       Next  : Variable_Id := No_Variable;
360       Name  : Name_Id;
361       Value : Variable_Value;
362    end record;
363    --  To hold the list of variables in a project file and in packages
364
365    package Variable_Element_Table is new GNAT.Dynamic_Tables
366      (Table_Component_Type => Variable,
367       Table_Index_Type     => Variable_Id,
368       Table_Low_Bound      => 1,
369       Table_Initial        => 200,
370       Table_Increment      => 100);
371    --  The table of variable in list of variables
372
373    type Array_Element_Id is new Nat;
374    No_Array_Element : constant Array_Element_Id := 0;
375    type Array_Element is record
376       Index                : Name_Id;
377       Src_Index            : Int := 0;
378       Index_Case_Sensitive : Boolean := True;
379       Value                : Variable_Value;
380       Next                 : Array_Element_Id := No_Array_Element;
381    end record;
382    --  Each Array_Element represents an array element and is linked (Next)
383    --  to the next array element, if any, in the array.
384
385    package Array_Element_Table is new GNAT.Dynamic_Tables
386      (Table_Component_Type => Array_Element,
387       Table_Index_Type     => Array_Element_Id,
388       Table_Low_Bound      => 1,
389       Table_Initial        => 200,
390       Table_Increment      => 100);
391    --  The table that contains all array elements
392
393    type Array_Id is new Nat;
394    No_Array : constant Array_Id := 0;
395    type Array_Data is record
396       Name  : Name_Id          := No_Name;
397       Value : Array_Element_Id := No_Array_Element;
398       Next  : Array_Id         := No_Array;
399    end record;
400    --  Each Array_Data value represents an array.
401    --  Value is the id of the first element.
402    --  Next is the id of the next array in the project file or package.
403
404    package Array_Table is new GNAT.Dynamic_Tables
405      (Table_Component_Type => Array_Data,
406       Table_Index_Type     => Array_Id,
407       Table_Low_Bound      => 1,
408       Table_Initial        => 200,
409       Table_Increment      => 100);
410    --  The table that contains all arrays
411
412    type Package_Id is new Nat;
413    No_Package : constant Package_Id := 0;
414    type Declarations is record
415       Variables  : Variable_Id := No_Variable;
416       Attributes : Variable_Id := No_Variable;
417       Arrays     : Array_Id    := No_Array;
418       Packages   : Package_Id  := No_Package;
419    end record;
420    --  Contains the declarations (variables, single and array attributes,
421    --  packages) for a project or a package in a project.
422
423    No_Declarations : constant Declarations :=
424      (Variables  => No_Variable,
425       Attributes => No_Variable,
426       Arrays     => No_Array,
427       Packages   => No_Package);
428    --  Default value of Declarations: indicates that there is no declarations
429
430    type Package_Element is record
431       Name   : Name_Id      := No_Name;
432       Decl   : Declarations := No_Declarations;
433       Parent : Package_Id   := No_Package;
434       Next   : Package_Id   := No_Package;
435    end record;
436    --  A package (includes declarations that may include other packages)
437
438    package Package_Table is new GNAT.Dynamic_Tables
439      (Table_Component_Type => Package_Element,
440       Table_Index_Type     => Package_Id,
441       Table_Low_Bound      => 1,
442       Table_Initial        => 100,
443       Table_Increment      => 100);
444    --  The table that contains all packages
445
446    function Image (Casing : Casing_Type) return String;
447    --  Similar to 'Image (but avoid use of this attribute in compiler)
448
449    function Value (Image : String) return Casing_Type;
450    --  Similar to 'Value (but avoid use of this attribute in compiler)
451    --  Raises Constraint_Error if not a Casing_Type image.
452
453    --  The following record contains data for a naming scheme
454
455    type Naming_Data is record
456
457       Dot_Replacement : Name_Id := No_Name;
458       --  The string to replace '.' in the source file name (for Ada)
459
460       Dot_Repl_Loc : Source_Ptr := No_Location;
461       --  The position in the project file source where Dot_Replacement is
462       --  defined.
463
464       Casing : Casing_Type := All_Lower_Case;
465       --  The casing of the source file name (for Ada)
466
467       Spec_Suffix : Array_Element_Id := No_Array_Element;
468       --  The string to append to the unit name for the
469       --  source file name of a spec.
470       --  Indexed by the programming language.
471
472       Ada_Spec_Suffix : Name_Id := No_Name;
473       --  The suffix of the Ada spec sources
474
475       Spec_Suffix_Loc : Source_Ptr := No_Location;
476       --  The position in the project file source where
477       --  Ada_Spec_Suffix is defined.
478
479       Impl_Suffixes : Impl_Suffix_Array   := No_Impl_Suffixes;
480       Supp_Suffixes : Supp_Language_Index := No_Supp_Language_Index;
481       --  The source suffixes of the different languages
482
483       Body_Suffix : Array_Element_Id := No_Array_Element;
484       --  The string to append to the unit name for the
485       --  source file name of a body.
486       --  Indexed by the programming language.
487
488       Ada_Body_Suffix : Name_Id := No_Name;
489       --  The suffix of the Ada body sources
490
491       Body_Suffix_Loc : Source_Ptr := No_Location;
492       --  The position in the project file source where
493       --  Ada_Body_Suffix is defined.
494
495       Separate_Suffix : Name_Id := No_Name;
496       --  String to append to unit name for source file name of an Ada subunit
497
498       Sep_Suffix_Loc : Source_Ptr := No_Location;
499       --  Position in the project file source where Separate_Suffix is defined
500
501       Specs : Array_Element_Id := No_Array_Element;
502       --  An associative array mapping individual specs to source file names
503       --  This is specific to Ada.
504
505       Bodies : Array_Element_Id := No_Array_Element;
506       --  An associative array mapping individual bodies to source file names
507       --  This is specific to Ada.
508
509       Specification_Exceptions : Array_Element_Id := No_Array_Element;
510       --  An associative array listing spec file names that do not have the
511       --  spec suffix. Not used by Ada. Indexed by programming language name.
512
513       Implementation_Exceptions : Array_Element_Id := No_Array_Element;
514       --  An associative array listing body file names that do not have the
515       --  body suffix. Not used by Ada. Indexed by programming language name.
516
517    end record;
518
519    function Standard_Naming_Data
520      (Tree : Project_Tree_Ref := No_Project_Tree) return Naming_Data;
521    pragma Inline (Standard_Naming_Data);
522    --  The standard GNAT naming scheme when Tree is No_Project_Tree.
523    --  Otherwise, return the default naming scheme for the project tree Tree,
524    --  which must have been Initialized.
525
526    function Same_Naming_Scheme
527      (Left, Right : Naming_Data) return Boolean;
528    --  Returns True if Left and Right are the same naming scheme
529    --  not considering Specs and Bodies.
530
531    type Project_List is new Nat;
532    Empty_Project_List : constant Project_List := 0;
533    --  A list of project files
534
535    type Project_Element is record
536       Project : Project_Id   := No_Project;
537       Next    : Project_List := Empty_Project_List;
538    end record;
539    --  Element in a list of project files. Next is the id of the next
540    --  project file in the list.
541
542    package Project_List_Table is new GNAT.Dynamic_Tables
543      (Table_Component_Type => Project_Element,
544       Table_Index_Type     => Project_List,
545       Table_Low_Bound      => 1,
546       Table_Initial        => 100,
547       Table_Increment      => 100);
548    --  The table that contains the lists of project files
549
550    --  The following record describes a project file representation
551
552    type Project_Data is record
553       Externally_Built : Boolean := False;
554
555       Languages      : Languages_In_Project := No_Languages;
556       Supp_Languages : Supp_Language_Index  := No_Supp_Language_Index;
557       --  Indicate the different languages of the source of this project
558
559       First_Referred_By : Project_Id := No_Project;
560       --  The project, if any, that was the first to be known as importing or
561       --  extending this project. Set by Prj.Proc.Process.
562
563       Name : Name_Id := No_Name;
564       --  The name of the project. Set by Prj.Proc.Process
565
566       Display_Name : Name_Id := No_Name;
567       --  The name of the project with the spelling of its declaration.
568       --  Set by Prj.Proc.Process.
569
570       Path_Name : Name_Id := No_Name;
571       --  The path name of the project file. Set by Prj.Proc.Process
572
573       Display_Path_Name : Name_Id := No_Name;
574       --  The path name used for display purposes. May be different from
575       --  Path_Name for platforms where the file names are case-insensitive.
576
577       Virtual : Boolean := False;
578       --  True for virtual extending projects
579
580       Location : Source_Ptr := No_Location;
581       --  The location in the project file source of the reserved word
582       --  project. Set by Prj.Proc.Process.
583
584       Mains : String_List_Id := Nil_String;
585       --  List of mains specified by attribute Main. Set by Prj.Nmsc.Check
586
587       Directory : Name_Id := No_Name;
588       --  Directory where the project file resides. Set by Prj.Proc.Process
589
590       Display_Directory : Name_Id := No_Name;
591       --  comment ???
592
593       Dir_Path : String_Access;
594       --  Same as Directory, but as an access to String. Set by
595       --  Make.Compile_Sources.Collect_Arguments_And_Compile.
596
597       Library : Boolean := False;
598       --  True if this is a library project. Set by
599       --  Prj.Nmsc.Language_Independent_Check.
600
601       Library_Dir : Name_Id := No_Name;
602       --  If a library project, directory where resides the library Set by
603       --  Prj.Nmsc.Language_Independent_Check.
604
605       Display_Library_Dir : Name_Id := No_Name;
606       --  The name of the library directory, for display purposes. May be
607       --  different from Library_Dir for platforms where the file names are
608       --  case-insensitive.
609
610       Library_TS : Time_Stamp_Type := Empty_Time_Stamp;
611       --  The timestamp of a library file in a library project.
612       --  Set by MLib.Prj.Check_Library.
613
614       Library_Src_Dir : Name_Id := No_Name;
615       --  If a Stand-Alone Library project, directory where the sources
616       --  of the interfaces of the library are copied. By default, if
617       --  attribute Library_Src_Dir is not specified, sources of the interfaces
618       --  are not copied anywhere. Set by Prj.Nmsc.Check_Stand_Alone_Library.
619
620       Display_Library_Src_Dir : Name_Id := No_Name;
621       --  The name of the library source directory, for display purposes.
622       --  May be different from Library_Src_Dir for platforms where the file
623       --  names are case-insensitive.
624
625       Library_ALI_Dir : Name_Id := No_Name;
626       --  In a library project, directory where the ALI files are copied.
627       --  If attribute Library_ALI_Dir is not specified, ALI files are
628       --  copied in the Library_Dir. Set by Prj.Nmsc.Check_Library_Attributes.
629
630       Display_Library_ALI_Dir : Name_Id := No_Name;
631       --  The name of the library ALI directory, for display purposes. May be
632       --  different from Library_ALI_Dir for platforms where the file names are
633       --  case-insensitive.
634
635       Library_Name : Name_Id := No_Name;
636       --  If a library project, name of the library
637       --  Set by Prj.Nmsc.Language_Independent_Check.
638
639       Library_Kind : Lib_Kind := Static;
640       --  If a library project, kind of library
641       --  Set by Prj.Nmsc.Language_Independent_Check.
642
643       Lib_Internal_Name : Name_Id := No_Name;
644       --  If a library project, internal name store inside the library Set by
645       --  Prj.Nmsc.Language_Independent_Check.
646
647       Standalone_Library : Boolean := False;
648       --  Indicate that this is a Standalone Library Project File. Set by
649       --  Prj.Nmsc.Check.
650
651       Lib_Interface_ALIs : String_List_Id := Nil_String;
652       --  For Standalone Library Project Files, indicate the list of Interface
653       --  ALI files. Set by Prj.Nmsc.Check.
654
655       Lib_Auto_Init : Boolean := False;
656       --  For non static Standalone Library Project Files, indicate if
657       --  the library initialisation should be automatic.
658
659       Symbol_Data : Symbol_Record := No_Symbols;
660       --  Symbol file name, reference symbol file name, symbol policy
661
662       Ada_Sources_Present : Boolean := True;
663       --  A flag that indicates if there are Ada sources in this project file.
664       --  There are no sources if any of the following is true:
665       --    1) Source_Dirs is specified as an empty list
666       --    2) Source_Files is specified as an empty list
667       --    3) Ada is not in the list of the specified Languages
668
669       Other_Sources_Present : Boolean := True;
670       --  A flag that indicates that there are non-Ada sources in this project
671
672       Sources : String_List_Id := Nil_String;
673       --  The list of all the source file names.
674       --  Set by Prj.Nmsc.Check_Ada_Naming_Scheme.
675
676       First_Other_Source : Other_Source_Id := No_Other_Source;
677       Last_Other_Source  : Other_Source_Id := No_Other_Source;
678       --  Head and tail of the list of sources of languages other than Ada
679
680       Imported_Directories_Switches : Argument_List_Access := null;
681       --  List of the -I switches to be used when compiling sources of
682       --  languages other than Ada.
683
684       Include_Path : String_Access := null;
685       --  Value to be used as CPATH, when using a GCC, instead of a list of
686       --  -I switches.
687
688       Include_Data_Set : Boolean := False;
689       --  Set True when Imported_Directories_Switches or Include_Path are set
690
691       Source_Dirs : String_List_Id := Nil_String;
692       --  The list of all the source directories.
693       --  Set by Prj.Nmsc.Language_Independent_Check.
694
695       Known_Order_Of_Source_Dirs : Boolean := True;
696       --  False, if there is any /** in the Source_Dirs, because in this case
697       --  the ordering of the source subdirs depend on the OS. If True,
698       --  duplicate file names in the same project file are allowed.
699
700       Object_Directory : Name_Id := No_Name;
701       --  The object directory of this project file.
702       --  Set by Prj.Nmsc.Language_Independent_Check.
703
704       Display_Object_Dir : Name_Id := No_Name;
705       --  The name of the object directory, for display purposes.
706       --  May be different from Object_Directory for platforms where the file
707       --  names are case-insensitive.
708
709       Exec_Directory : Name_Id := No_Name;
710       --  The exec directory of this project file. Default is equal to
711       --  Object_Directory. Set by Prj.Nmsc.Language_Independent_Check.
712
713       Display_Exec_Dir : Name_Id := No_Name;
714       --  The name of the exec directory, for display purposes. May be
715       --  different from Exec_Directory for platforms where the file names are
716       --  case-insensitive.
717
718       Extends : Project_Id := No_Project;
719       --  The reference of the project file, if any, that this project file
720       --  extends. Set by Prj.Proc.Process.
721
722       Extended_By : Project_Id := No_Project;
723       --  The reference of the project file, if any, that extends this project
724       --  file. Set by Prj.Proc.Process.
725
726       Naming : Naming_Data := Standard_Naming_Data;
727       --  The naming scheme of this project file.
728       --  Set by Prj.Nmsc.Check_Naming_Scheme.
729
730       First_Language_Processing : First_Language_Processing_Data :=
731                                     Default_First_Language_Processing_Data;
732       --  Comment needed ???
733
734       Supp_Language_Processing : Supp_Language_Index := No_Supp_Language_Index;
735       --  Comment needed
736
737       Default_Linker      : Name_Id := No_Name;
738       Default_Linker_Path : Name_Id := No_Name;
739
740       Decl : Declarations := No_Declarations;
741       --  The declarations (variables, attributes and packages) of this
742       --  project file. Set by Prj.Proc.Process.
743
744       Imported_Projects : Project_List := Empty_Project_List;
745       --  The list of all directly imported projects, if any. Set by
746       --  Prj.Proc.Process.
747
748       All_Imported_Projects : Project_List := Empty_Project_List;
749       --  The list of all projects imported directly or indirectly, if any.
750       --  Set by Make.Initialize.
751
752       Ada_Include_Path : String_Access := null;
753       --  The cached value of ADA_INCLUDE_PATH for this project file. Do not
754       --  use this field directly outside of the compiler, use
755       --  Prj.Env.Ada_Include_Path instead. Set by Prj.Env.Ada_Include_Path.
756
757       Ada_Objects_Path : String_Access := null;
758       --  The cached value of ADA_OBJECTS_PATH for this project file. Do not
759       --  use this field directly outside of the compiler, use
760       --  Prj.Env.Ada_Objects_Path instead. Set by Prj.Env.Ada_Objects_Path
761
762       Include_Path_File : Name_Id := No_Name;
763       --  The cached value of the source path temp file for this project file.
764       --  Set by gnatmake (Prj.Env.Set_Ada_Paths).
765
766       Objects_Path_File_With_Libs : Name_Id := No_Name;
767       --  The cached value of the object path temp file (including library
768       --  dirs) for this project file. Set by gnatmake (Prj.Env.Set_Ada_Paths).
769
770       Objects_Path_File_Without_Libs : Name_Id := No_Name;
771       --  The cached value of the object path temp file (excluding library
772       --  dirs) for this project file. Set by gnatmake (Prj.Env.Set_Ada_Paths).
773
774       Config_File_Name : Name_Id := No_Name;
775       --  The name of the configuration pragmas file, if any.
776       --  Set by gnatmake (Prj.Env.Create_Config_Pragmas_File).
777
778       Config_File_Temp : Boolean := False;
779       --  An indication that the configuration pragmas file is
780       --  a temporary file that must be deleted at the end.
781       --  Set by gnatmake (Prj.Env.Create_Config_Pragmas_File).
782
783       Config_Checked : Boolean := False;
784       --  A flag to avoid checking repetitively the configuration pragmas file.
785       --  Set by gnatmake (Prj.Env.Create_Config_Pragmas_File).
786
787       Language_Independent_Checked : Boolean := False;
788       --  A flag that indicates that the project file has been checked
789       --  for language independent features: Object_Directory,
790       --  Source_Directories, Library, non empty Naming Suffixes.
791
792       Checked : Boolean := False;
793       --  A flag to avoid checking repetitively the naming scheme of
794       --  this project file. Set by Prj.Nmsc.Check_Ada_Naming_Scheme.
795
796       Seen : Boolean := False;
797       --  A flag to mark a project as "visited" to avoid processing the same
798       --  project several time.
799
800       Need_To_Build_Lib : Boolean := False;
801       --  Indicates that the library of a Library Project needs to be built or
802       --  rebuilt.
803
804       Depth : Natural := 0;
805       --  The maximum depth of a project in the project graph.
806       --  Depth of main project is 0.
807
808       Unkept_Comments : Boolean := False;
809       --  True if there are comments in the project sources that cannot
810       --  be kept in the project tree.
811
812    end record;
813
814    function Empty_Project (Tree : Project_Tree_Ref) return Project_Data;
815    --  Return the representation of an empty project in project Tree tree.
816    --  The project tree Tree must have been Initialized and/or Reset.
817
818    Project_Error : exception;
819    --  Raised by some subprograms in Prj.Attr
820
821    package Project_Table is new GNAT.Dynamic_Tables (
822      Table_Component_Type => Project_Data,
823      Table_Index_Type     => Project_Id,
824      Table_Low_Bound      => 1,
825      Table_Initial        => 100,
826      Table_Increment      => 100);
827    --  The set of all project files
828
829    type Spec_Or_Body is
830      (Specification, Body_Part);
831
832    type File_Name_Data is record
833       Name         : Name_Id := No_Name;
834       Index        : Int     := 0;
835       Display_Name : Name_Id := No_Name;
836       Path         : Name_Id := No_Name;
837       Display_Path : Name_Id := No_Name;
838       Project      : Project_Id := No_Project;
839       Needs_Pragma : Boolean := False;
840    end record;
841    --  File and Path name of a spec or body
842
843    type File_Names_Data is array (Spec_Or_Body) of File_Name_Data;
844
845    type Unit_Id is new Nat;
846    No_Unit : constant Unit_Id := 0;
847    type Unit_Data is record
848       Name       : Name_Id    := No_Name;
849       File_Names : File_Names_Data;
850    end record;
851    --  Name and File and Path names of a unit, with a reference to its
852    --  GNAT Project File(s).
853
854    package Unit_Table is new GNAT.Dynamic_Tables
855      (Table_Component_Type => Unit_Data,
856       Table_Index_Type     => Unit_Id,
857       Table_Low_Bound      => 1,
858       Table_Initial        => 100,
859       Table_Increment      => 100);
860    --  Table of all units in a project tree
861
862    package Units_Htable is new Simple_HTable
863      (Header_Num => Header_Num,
864       Element    => Unit_Id,
865       No_Element => No_Unit,
866       Key        => Name_Id,
867       Hash       => Hash,
868       Equal      => "=");
869    --  Mapping of unit names to indexes in the Units table
870
871    type Unit_Project is record
872       Unit    : Unit_Id    := No_Unit;
873       Project : Project_Id := No_Project;
874    end record;
875
876    No_Unit_Project : constant Unit_Project := (No_Unit, No_Project);
877
878    package Files_Htable is new Simple_HTable
879      (Header_Num => Header_Num,
880       Element    => Unit_Project,
881       No_Element => No_Unit_Project,
882       Key        => Name_Id,
883       Hash       => Hash,
884       Equal      => "=");
885    --  Mapping of file names to indexes in the Units table
886
887    type Private_Project_Tree_Data is private;
888    --  Data for a project tree that is used only by the Project Manager
889
890    type Project_Tree_Data is
891       record
892          Present_Languages : Present_Language_Table.Instance;
893          Supp_Suffixes     : Supp_Suffix_Table.Instance;
894          Name_Lists        : Name_List_Table.Instance;
895          Supp_Languages    : Supp_Language_Table.Instance;
896          Other_Sources     : Other_Source_Table.Instance;
897          String_Elements   : String_Element_Table.Instance;
898          Variable_Elements : Variable_Element_Table.Instance;
899          Array_Elements    : Array_Element_Table.Instance;
900          Arrays            : Array_Table.Instance;
901          Packages          : Package_Table.Instance;
902          Project_Lists     : Project_List_Table.Instance;
903          Projects          : Project_Table.Instance;
904          Units             : Unit_Table.Instance;
905          Units_HT          : Units_Htable.Instance;
906          Files_HT          : Files_Htable.Instance;
907          Private_Part      : Private_Project_Tree_Data;
908       end record;
909    --  Data for a project tree
910
911    type Put_Line_Access is access procedure
912      (Line    : String;
913       Project : Project_Id;
914       In_Tree : Project_Tree_Ref);
915    --  Use to customize error reporting in Prj.Proc and Prj.Nmsc
916
917    procedure Expect (The_Token : Token_Type; Token_Image : String);
918    --  Check that the current token is The_Token. If it is not, then
919    --  output an error message.
920
921    procedure Initialize (Tree : Project_Tree_Ref);
922    --  This procedure must be called before using any services from the Prj
923    --  hierarchy. Namet.Initialize must be called before Prj.Initialize.
924
925    procedure Reset (Tree : Project_Tree_Ref);
926    --  This procedure resets all the tables that are used when processing a
927    --  project file tree. Initialize must be called before the call to Reset.
928
929    procedure Register_Default_Naming_Scheme
930      (Language            : Name_Id;
931       Default_Spec_Suffix : Name_Id;
932       Default_Body_Suffix : Name_Id;
933       In_Tree             : Project_Tree_Ref);
934    --  Register the default suffixes for a given language. These extensions
935    --  will be ignored if the user has specified a new naming scheme in a
936    --  project file.
937    --
938    --  Otherwise, this information will be automatically added to Naming_Data
939    --  when a project is processed, in the lists Spec_Suffix and Body_Suffix.
940
941    generic
942       type State is limited private;
943       with procedure Action
944         (Project    : Project_Id;
945          With_State : in out State);
946    procedure For_Every_Project_Imported
947      (By         : Project_Id;
948       In_Tree    : Project_Tree_Ref;
949       With_State : in out State);
950    --  Call Action for each project imported directly or indirectly by project
951    --  By. Action is called according to the order of importation: if A
952    --  imports B, directly or indirectly, Action will be called for A before
953    --  it is called for B. If two projects import each other directly or
954    --  indirectly (using at least one "limited with"), it is not specified
955    --  for which of these two projects Action will be called first. Projects
956    --  that are extended by other projects are not considered. With_State may
957    --  be used by Action to choose a behavior or to report some global result.
958
959    ----------------------------------------------------------
960    -- Other multi-language stuff that may be modified soon --
961    ----------------------------------------------------------
962
963    function Is_Present
964      (Language   : Language_Index;
965       In_Project : Project_Data;
966       In_Tree    : Project_Tree_Ref) return Boolean;
967    --  Return True when Language is one of the languages used in
968    --  project In_Project.
969
970    procedure Set
971      (Language   : Language_Index;
972       Present    : Boolean;
973       In_Project : in out Project_Data;
974       In_Tree    : Project_Tree_Ref);
975    --  Indicate if Language is or not a language used in project In_Project
976
977    function Language_Processing_Data_Of
978      (Language   : Language_Index;
979       In_Project : Project_Data;
980       In_Tree    : Project_Tree_Ref) return Language_Processing_Data;
981    --  Return the Language_Processing_Data for language Language in project
982    --  In_Project. Return the default when no Language_Processing_Data are
983    --  defined for the language.
984
985    procedure Set
986      (Language_Processing : Language_Processing_Data;
987       For_Language        : Language_Index;
988       In_Project          : in out Project_Data;
989       In_Tree             : Project_Tree_Ref);
990    --  Set the Language_Processing_Data for language Language in project
991    --  In_Project.
992
993    function Suffix_Of
994      (Language   : Language_Index;
995       In_Project : Project_Data;
996       In_Tree    : Project_Tree_Ref) return Name_Id;
997    --  Return the suffix for language Language in project In_Project. Return
998    --  No_Name when no suffix is defined for the language.
999
1000    procedure Set
1001      (Suffix       : Name_Id;
1002       For_Language : Language_Index;
1003       In_Project   : in out Project_Data;
1004       In_Tree      : Project_Tree_Ref);
1005    --  Set the suffix for language Language in project In_Project
1006
1007 private
1008
1009    All_Packages : constant String_List_Access := null;
1010
1011    No_Project_Tree : constant Project_Tree_Ref := null;
1012
1013    Ignored : constant Variable_Kind := Single;
1014
1015    Nil_Variable_Value : constant Variable_Value :=
1016      (Project  => No_Project,
1017       Kind     => Undefined,
1018       Location => No_Location,
1019       Default  => False);
1020
1021    Virtual_Prefix : constant String := "v$";
1022    --  The prefix for virtual extending projects. Because of the '$', which is
1023    --  normally forbidden for project names, there cannot be any name clash.
1024
1025    Empty_Name : Name_Id;
1026    --  Name_Id for an empty name (no characters). Initialized by the call
1027    --  to procedure Initialize.
1028
1029    procedure Add_To_Buffer
1030      (S    : String;
1031       To   : in out String_Access;
1032       Last : in out Natural);
1033    --  Append a String to the Buffer
1034
1035    type Naming_Id is new Nat;
1036
1037    package Naming_Table is new GNAT.Dynamic_Tables
1038      (Table_Component_Type => Naming_Data,
1039       Table_Index_Type     => Naming_Id,
1040       Table_Low_Bound      => 1,
1041       Table_Initial        => 5,
1042       Table_Increment      => 100);
1043    --  Comment ???
1044
1045    package Path_File_Table is new GNAT.Dynamic_Tables
1046      (Table_Component_Type => Name_Id,
1047       Table_Index_Type     => Natural,
1048       Table_Low_Bound      => 1,
1049       Table_Initial        => 50,
1050       Table_Increment      => 50);
1051    --  Table storing all the temp path file names.
1052    --  Used by Delete_All_Path_Files.
1053
1054    package Source_Path_Table is new GNAT.Dynamic_Tables
1055      (Table_Component_Type => Name_Id,
1056       Table_Index_Type     => Natural,
1057       Table_Low_Bound      => 1,
1058       Table_Initial        => 50,
1059       Table_Increment      => 50);
1060    --  A table to store the source dirs before creating the source path file
1061
1062    package Object_Path_Table is new GNAT.Dynamic_Tables
1063      (Table_Component_Type => Name_Id,
1064       Table_Index_Type     => Natural,
1065       Table_Low_Bound      => 1,
1066       Table_Initial        => 50,
1067       Table_Increment      => 50);
1068    --  A table to store the object dirs, before creating the object path file
1069
1070    type Private_Project_Tree_Data is record
1071       Namings        : Naming_Table.Instance;
1072       Path_Files     : Path_File_Table.Instance;
1073       Source_Paths   : Source_Path_Table.Instance;
1074       Object_Paths   : Object_Path_Table.Instance;
1075       Default_Naming : Naming_Data;
1076    end record;
1077    --  Comment ???
1078 end Prj;