OSDN Git Service

2003-10-22 Arnaud Charlet <charlet@act-europe.fr>
[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-2003 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,  59 Temple Place - Suite 330,  Boston, --
20 -- MA 02111-1307, 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.OS_Lib; use GNAT.OS_Lib;
39
40 package Prj is
41
42    Empty_Name : Name_Id;
43    --  Name_Id for an empty name (no characters).
44    --  Initialized by procedure Initialize.
45
46    All_Packages : constant String_List_Access := null;
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    Project_File_Extension : String := ".gpr";
51    --  The standard project file name extension.
52    --  It is not a constant, because Canonical_Case_File_Name is called
53    --  on this variable in the body of Prj.
54
55    Default_Ada_Spec_Suffix : Name_Id;
56    --  The Name_Id for the standard GNAT suffix for Ada spec source file
57    --  name ".ads". Initialized by Prj.Initialize.
58
59    Default_Ada_Body_Suffix : Name_Id;
60    --  The Name_Id for the standard GNAT suffix for Ada body source file
61    --  name ".adb". Initialized by Prj.Initialize.
62
63    Slash : Name_Id;
64    --  "/", used as the path of locally removed files
65
66    type Verbosity is (Default, Medium, High);
67    --  Verbosity when parsing GNAT Project Files
68    --    Default is default (very quiet, if no errors).
69    --    Medium is more verbose.
70    --    High is extremely verbose.
71
72    type Lib_Kind is (Static, Dynamic, Relocatable);
73
74    function Empty_String return Name_Id;
75
76    type String_List_Id is new Nat;
77    Nil_String : constant String_List_Id := 0;
78    type String_Element is record
79       Value    : Name_Id        := No_Name;
80       Display_Value : Name_Id   := No_Name;
81       Location : Source_Ptr     := No_Location;
82       Flag     : Boolean        := False;
83       Next     : String_List_Id := Nil_String;
84    end record;
85    --  To hold values for string list variables and array elements.
86    --  Component Flag may be used for various purposes. For source
87    --  directories, it indicates if the directory contains Ada source(s).
88
89    package String_Elements is new Table.Table
90      (Table_Component_Type => String_Element,
91       Table_Index_Type     => String_List_Id,
92       Table_Low_Bound      => 1,
93       Table_Initial        => 200,
94       Table_Increment      => 100,
95       Table_Name           => "Prj.String_Elements");
96    --  The table for string elements in string lists
97
98    type Variable_Kind is (Undefined, List, Single);
99    --  Different kinds of variables
100
101    Ignored : constant Variable_Kind := Single;
102    --  Used to indicate that a package declaration must be ignored
103    --  while processing the project tree (unknown package name).
104
105    type Variable_Value (Kind : Variable_Kind := Undefined) is record
106       Location : Source_Ptr := No_Location;
107       Default  : Boolean    := False;
108       case Kind is
109          when Undefined =>
110             null;
111          when List =>
112             Values : String_List_Id := Nil_String;
113          when Single =>
114             Value : Name_Id := No_Name;
115       end case;
116    end record;
117    --  Values for variables and array elements.
118    --  Default is True if the current value is the default one for the variable
119
120    Nil_Variable_Value : constant Variable_Value :=
121      (Kind     => Undefined,
122       Location => No_Location,
123       Default  => False);
124    --  Value of a non existing variable or array element
125
126    type Variable_Id is new Nat;
127    No_Variable : constant Variable_Id := 0;
128    type Variable is record
129       Next     : Variable_Id := No_Variable;
130       Name     : Name_Id;
131       Value    : Variable_Value;
132    end record;
133    --  To hold the list of variables in a project file and in packages
134
135    package Variable_Elements is new Table.Table
136      (Table_Component_Type => Variable,
137       Table_Index_Type     => Variable_Id,
138       Table_Low_Bound      => 1,
139       Table_Initial        => 200,
140       Table_Increment      => 100,
141       Table_Name           => "Prj.Variable_Elements");
142    --  The table of variable in list of variables
143
144    type Array_Element_Id is new Nat;
145    No_Array_Element : constant Array_Element_Id := 0;
146    type Array_Element is record
147       Index                : Name_Id;
148       Index_Case_Sensitive : Boolean := True;
149       Value                : Variable_Value;
150       Next                 : Array_Element_Id := No_Array_Element;
151    end record;
152    --  Each Array_Element represents an array element and is linked (Next)
153    --  to the next array element, if any, in the array.
154
155    package Array_Elements is new Table.Table
156      (Table_Component_Type => Array_Element,
157       Table_Index_Type     => Array_Element_Id,
158       Table_Low_Bound      => 1,
159       Table_Initial        => 200,
160       Table_Increment      => 100,
161       Table_Name           => "Prj.Array_Elements");
162    --  The table that contains all array elements
163
164    type Array_Id is new Nat;
165    No_Array : constant Array_Id := 0;
166    type Array_Data is record
167       Name  : Name_Id          := No_Name;
168       Value : Array_Element_Id := No_Array_Element;
169       Next  : Array_Id         := No_Array;
170    end record;
171    --  Each Array_Data value represents an array.
172    --  Value is the id of the first element.
173    --  Next is the id of the next array in the project file or package.
174
175    package Arrays is new Table.Table
176      (Table_Component_Type => Array_Data,
177       Table_Index_Type     => Array_Id,
178       Table_Low_Bound      => 1,
179       Table_Initial        => 200,
180       Table_Increment      => 100,
181       Table_Name           => "Prj.Arrays");
182    --  The table that contains all arrays
183
184    type Package_Id is new Nat;
185    No_Package : constant Package_Id := 0;
186    type Declarations is record
187       Variables  : Variable_Id := No_Variable;
188       Attributes : Variable_Id := No_Variable;
189       Arrays     : Array_Id    := No_Array;
190       Packages   : Package_Id  := No_Package;
191    end record;
192
193    No_Declarations : constant Declarations :=
194      (Variables  => No_Variable,
195       Attributes => No_Variable,
196       Arrays     => No_Array,
197       Packages   => No_Package);
198    --  Declarations. Used in project structures and packages (what for???)
199
200    type Package_Element is record
201       Name   : Name_Id      := No_Name;
202       Decl   : Declarations := No_Declarations;
203       Parent : Package_Id   := No_Package;
204       Next   : Package_Id   := No_Package;
205    end record;
206    --  A package. Includes declarations that may include other packages.
207
208    package Packages is new Table.Table
209      (Table_Component_Type => Package_Element,
210       Table_Index_Type     => Package_Id,
211       Table_Low_Bound      => 1,
212       Table_Initial        => 100,
213       Table_Increment      => 100,
214       Table_Name           => "Prj.Packages");
215    --  The table that contains all packages.
216
217    function Image (Casing : Casing_Type) return String;
218    --  Similar to 'Image (but avoid use of this attribute in compiler)
219
220    function Value (Image : String) return Casing_Type;
221    --  Similar to 'Value (but avoid use of this attribute in compiler)
222    --  Raises Constraint_Error if not a Casing_Type image.
223
224    --  The following record contains data for a naming scheme
225
226    type Naming_Data is record
227       Current_Language : Name_Id := No_Name;
228       --  The programming language being currently considered
229
230       Dot_Replacement : Name_Id := No_Name;
231       --  The string to replace '.' in the source file name (for Ada).
232
233       Dot_Repl_Loc : Source_Ptr := No_Location;
234       --  The position in the project file source where
235       --  Dot_Replacement is defined.
236
237       Casing : Casing_Type := All_Lower_Case;
238       --  The casing of the source file name (for Ada).
239
240       Spec_Suffix : Array_Element_Id := No_Array_Element;
241       --  The string to append to the unit name for the
242       --  source file name of a spec.
243       --  Indexed by the programming language.
244
245       Current_Spec_Suffix : Name_Id := No_Name;
246       --  The "spec" suffix of the current programming language
247
248       Spec_Suffix_Loc : Source_Ptr := No_Location;
249       --  The position in the project file source where
250       --  Current_Spec_Suffix is defined.
251
252       Body_Suffix : Array_Element_Id := No_Array_Element;
253       --  The string to append to the unit name for the
254       --  source file name of a body.
255       --  Indexed by the programming language.
256
257       Current_Body_Suffix : Name_Id := No_Name;
258       --  The "body" suffix of the current programming language
259
260       Body_Suffix_Loc : Source_Ptr := No_Location;
261       --  The position in the project file source where
262       --  Current_Body_Suffix is defined.
263
264       Separate_Suffix : Name_Id := No_Name;
265       --  The string to append to the unit name for the
266       --  source file name of an Ada subunit.
267
268       Sep_Suffix_Loc : Source_Ptr := No_Location;
269       --  The position in the project file source where
270       --  Separate_Suffix is defined.
271
272       Specs : Array_Element_Id := No_Array_Element;
273       --  An associative array mapping individual specs
274       --  to source file names. Specific to Ada.
275
276       Bodies : Array_Element_Id := No_Array_Element;
277       --  An associative array mapping individual bodies
278       --  to source file names. Specific to Ada.
279
280       Specification_Exceptions : Array_Element_Id := No_Array_Element;
281       --  An associative array listing spec file names that don't have the
282       --  spec suffix. Not used by Ada. Indexed by the programming language
283       --  name.
284
285       Implementation_Exceptions : Array_Element_Id := No_Array_Element;
286       --  An associative array listing body file names that don't have the
287       --  body suffix. Not used by Ada. Indexed by the programming language
288       --  name.
289
290    end record;
291
292    function Standard_Naming_Data return Naming_Data;
293    pragma Inline (Standard_Naming_Data);
294    --  The standard GNAT naming scheme.
295
296    function Same_Naming_Scheme
297      (Left, Right : Naming_Data)
298       return        Boolean;
299    --  Returns True if Left and Right are the same naming scheme
300    --  not considering Specs and Bodies.
301
302    type Project_Id is new Nat;
303    No_Project : constant Project_Id := 0;
304    --  Id of a Project File
305
306    type Project_List is new Nat;
307    Empty_Project_List : constant Project_List := 0;
308    --  A list of project files.
309
310    type Project_Element is record
311       Project : Project_Id   := No_Project;
312       Next    : Project_List := Empty_Project_List;
313    end record;
314    --  Element in a list of project file.
315    --  Next is the id of the next project file in the list.
316
317    package Project_Lists is new Table.Table
318      (Table_Component_Type => Project_Element,
319       Table_Index_Type     => Project_List,
320       Table_Low_Bound      => 1,
321       Table_Initial        => 100,
322       Table_Increment      => 100,
323       Table_Name           => "Prj.Project_Lists");
324    --  The table that contains the lists of project files.
325
326    --  The following record describes a project file representation
327
328    type Project_Data is record
329       First_Referred_By  : Project_Id := No_Project;
330       --  The project, if any, that was the first to be known
331       --  as importing or extending this project.
332       --  Set by Prj.Proc.Process.
333
334       Name : Name_Id := No_Name;
335       --  The name of the project.
336       --  Set by Prj.Proc.Process.
337
338       Path_Name : Name_Id := No_Name;
339       --  The path name of the project file.
340       --  Set by Prj.Proc.Process.
341
342       Display_Path_Name : Name_Id := No_Name;
343
344       Location : Source_Ptr := No_Location;
345       --  The location in the project file source of the
346       --  reserved word project.
347       --  Set by Prj.Proc.Process.
348
349       Mains : String_List_Id := Nil_String;
350       --  The list of mains as specified by attribute Main.
351       --  Set by Prj.Nmsc.Ada_Check.
352
353       Directory : Name_Id := No_Name;
354       --  The directory where the project file resides.
355       --  Set by Prj.Proc.Process.
356
357       Display_Directory : Name_Id := No_Name;
358
359       Dir_Path : String_Access;
360       --  Same as Directory, but as an access to String.
361       --  Set by Make.Compile_Sources.Collect_Arguments_And_Compile.
362
363       Library : Boolean := False;
364       --  True if this is a library project.
365       --  Set by Prj.Nmsc.Language_Independent_Check.
366
367       Library_Dir : Name_Id := No_Name;
368       --  If a library project, directory where resides the library
369       --  Set by Prj.Nmsc.Language_Independent_Check.
370
371       Display_Library_Dir : Name_Id := No_Name;
372
373       Library_Src_Dir : Name_Id := No_Name;
374       --  If a library project, directory where the sources and the ALI files
375       --  of the library are copied. By default, if attribute Library_Src_Dir
376       --  is not specified, sources are not copied anywhere and ALI files are
377       --  copied in the Library Directory.
378       --  Set by Prj.Nmsc.Language_Independent_Check.
379
380       Display_Library_Src_Dir : Name_Id := No_Name;
381
382       Library_Name : Name_Id := No_Name;
383       --  If a library project, name of the library
384       --  Set by Prj.Nmsc.Language_Independent_Check.
385
386       Library_Kind : Lib_Kind := Static;
387       --  If a library project, kind of library
388       --  Set by Prj.Nmsc.Language_Independent_Check.
389
390       Lib_Internal_Name : Name_Id := No_Name;
391       --  If a library project, internal name store inside the library
392       --  Set by Prj.Nmsc.Language_Independent_Check.
393
394       Lib_Elaboration : Boolean := False;
395       --  If a library project, indicate if <lib>init and <lib>final
396       --  procedures need to be defined.
397       --  Set by Prj.Nmsc.Language_Independent_Check.
398
399       Standalone_Library : Boolean := False;
400       --  Indicate that this is a Standalone Library Project File.
401       --  Set by Prj.Nmsc.Ada_Check.
402
403       Lib_Interface_ALIs : String_List_Id := Nil_String;
404       --  For Standalone Library Project Files, indicate the list
405       --  of Interface ALI files.
406       --  Set by Prj.Nmsc.Ada_Check.
407
408       Lib_Auto_Init  : Boolean := False;
409       --  For non static Standalone Library Project Files, indicate if
410       --  the library initialisation should be automatic.
411
412       Sources_Present : Boolean := True;
413       --  A flag that indicates if there are sources in this project file.
414       --  There are no sources if 1) Source_Dirs is specified as an
415       --  empty list, 2) Source_Files is specified as an empty list, or
416       --  3) the current language is not in the list of the specified
417       --  Languages.
418
419       Sources : String_List_Id := Nil_String;
420       --  The list of all the source file names.
421       --  Set by Prj.Nmsc.Check_Naming_Scheme.
422
423       Source_Dirs : String_List_Id := Nil_String;
424       --  The list of all the source directories.
425       --  Set by Prj.Nmsc.Check_Naming_Scheme.
426
427       Known_Order_Of_Source_Dirs : Boolean := True;
428       --  False, if there is any /** in the Source_Dirs, because in this case
429       --  the ordering of the source subdirs depend on the OS. If True,
430       --  duplicate file names in the same project file are allowed.
431
432       Object_Directory : Name_Id := No_Name;
433       --  The object directory of this project file.
434       --  Set by Prj.Nmsc.Check_Naming_Scheme.
435
436       Display_Object_Dir : Name_Id := No_Name;
437
438       Exec_Directory   : Name_Id := No_Name;
439       --  The exec directory of this project file.
440       --  Default is equal to Object_Directory.
441       --  Set by Prj.Nmsc.Check_Naming_Scheme.
442
443       Display_Exec_Dir : Name_Id := No_Name;
444
445       Extends : Project_Id := No_Project;
446       --  The reference of the project file, if any, that this
447       --  project file extends.
448       --  Set by Prj.Proc.Process.
449
450       Extended_By : Project_Id := No_Project;
451       --  The reference of the project file, if any, that
452       --  extends this project file.
453       --  Set by Prj.Proc.Process.
454
455       Naming : Naming_Data := Standard_Naming_Data;
456       --  The naming scheme of this project file.
457       --  Set by Prj.Nmsc.Check_Naming_Scheme.
458
459       Decl : Declarations := No_Declarations;
460       --  The declarations (variables, attributes and packages)
461       --  of this project file.
462       --  Set by Prj.Proc.Process.
463
464       Imported_Projects : Project_List := Empty_Project_List;
465       --  The list of all directly imported projects, if any.
466       --  Set by Prj.Proc.Process.
467
468       Ada_Include_Path  : String_Access := null;
469       --  The cached value of ADA_INCLUDE_PATH for this project file.
470       --  Do not use this field directly outside of the compiler, use
471       --  Prj.Env.Ada_Include_Path instead.
472       --  Set by Prj.Env.Ada_Include_Path.
473
474       Ada_Objects_Path  : String_Access := null;
475       --  The cached value of ADA_OBJECTS_PATH for this project file.
476       --  Do not use this field directly outside of the compiler, use
477       --  Prj.Env.Ada_Objects_Path instead.
478       --  Set by Prj.Env.Ada_Objects_Path
479
480       Include_Path_File : Name_Id := No_Name;
481       --  The cached value of the source path temp file for this project file.
482       --  Set by gnatmake (Prj.Env.Set_Ada_Paths).
483
484       Objects_Path_File_With_Libs : Name_Id := No_Name;
485       --  The cached value of the object path temp file (including library
486       --  dirs) for this project file.
487       --  Set by gnatmake (Prj.Env.Set_Ada_Paths).
488
489       Objects_Path_File_Without_Libs : Name_Id := No_Name;
490       --  The cached value of the object path temp file (excluding library
491       --  dirs) for this project file.
492       --  Set by gnatmake (Prj.Env.Set_Ada_Paths).
493
494       Config_File_Name : Name_Id := No_Name;
495       --  The name of the configuration pragmas file, if any.
496       --  Set by gnatmake (Prj.Env.Create_Config_Pragmas_File).
497
498       Config_File_Temp : Boolean := False;
499       --  An indication that the configuration pragmas file is
500       --  a temporary file that must be deleted at the end.
501       --  Set by gnatmake (Prj.Env.Create_Config_Pragmas_File).
502
503       Config_Checked : Boolean := False;
504       --  A flag to avoid checking repetitively the configuration pragmas file.
505       --  Set by gnatmake (Prj.Env.Create_Config_Pragmas_File).
506
507       Language_Independent_Checked : Boolean := False;
508       --  A flag that indicates that the project file has been checked
509       --  for language independent features: Object_Directory,
510       --  Source_Directories, Library, non empty Naming Suffixs.
511
512       Checked : Boolean := False;
513       --  A flag to avoid checking repetitively the naming scheme of
514       --  this project file.
515       --  Set by Prj.Nmsc.Check_Naming_Scheme.
516
517       Seen  : Boolean := False;
518       Flag1 : Boolean := False;
519       Flag2 : Boolean := False;
520       --  Various flags that are used in an ad hoc manner
521       --  That's really not a good enough comment ??? we need to know what
522       --  these flags are used for, and give them proper names. If Flag1
523       --  and Flag2 have multiple uses, then either we use multiple fields
524       --  or a renaming scheme.
525
526       Depth : Natural := 0;
527       --  The maximum depth of a project in the project graph.
528       --  Depth of main project is 0.
529
530    end record;
531
532    function Empty_Project return Project_Data;
533    --  Return the representation of an empty project.
534
535    package Projects is new Table.Table (
536      Table_Component_Type => Project_Data,
537      Table_Index_Type     => Project_Id,
538      Table_Low_Bound      => 1,
539      Table_Initial        => 100,
540      Table_Increment      => 100,
541      Table_Name           => "Prj.Projects");
542    --  The set of all project files.
543
544    type Put_Line_Access is access procedure
545      (Line    : String;
546       Project : Project_Id);
547    --  Use to customize error reporting in Prj.Proc and Prj.Nmsc.
548
549    procedure Expect (The_Token : Token_Type; Token_Image : String);
550    --  Check that the current token is The_Token. If it is not, then
551    --  output an error message.
552
553    procedure Initialize;
554    --  This procedure must be called before using any services from the Prj
555    --  hierarchy. Namet.Initialize must be called before Prj.Initialize.
556
557    procedure Reset;
558    --  This procedure resets all the tables that are used when processing a
559    --  project file tree. Initialize must be called before the call to Reset.
560
561    procedure Register_Default_Naming_Scheme
562      (Language : Name_Id;
563       Default_Spec_Suffix : Name_Id;
564       Default_Body_Suffix : Name_Id);
565    --  Register the default suffixs for a given language. These extensions
566    --  will be ignored if the user has specified a new naming scheme in a
567    --  project file.
568    --
569    --  Otherwise, this information will be automatically added to Naming_Data
570    --  when a project is processed, in the lists Spec_Suffix and Body_Suffix.
571
572    generic
573       type State is limited private;
574       with procedure Action
575         (Project    : Project_Id;
576          With_State : in out State);
577    procedure For_Every_Project_Imported
578      (By         : Project_Id;
579       With_State : in out State);
580    --  Call Action for each project imported directly or indirectly by project
581    --  By. Action is called according to the order of importation: if A
582    --  imports B, directly or indirectly, Action will be called for A before
583    --  it is called for B. With_State may be used by Action to choose a
584    --  behavior or to report some global result.
585
586    procedure Scan;
587    pragma Inline (Scan);
588    --  Scan a token. Change all operator symbols to literal strings.
589
590 private
591
592    Initial_Buffer_Size : constant := 100;
593
594    Buffer : String_Access := new String (1 .. Initial_Buffer_Size);
595    --  An extensible character buffer to store names. Used in Prj.Part and
596    --  Prj.Strt.
597
598    Buffer_Last : Natural := 0;
599    --  The index of the last character in the Buffer
600
601    Current_Packages_To_Check : String_List_Access := All_Packages;
602    --  Global variable, set by Prj.Part.Parse, used by Prj.Dect.
603
604    procedure Add_To_Buffer (S : String);
605    --  Append a String to the Buffer
606
607 end Prj;