OSDN Git Service

Delete all lines containing "$Revision:".
[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 --                                                                          --
10 --          Copyright (C) 2001-2002 Free Software Foundation, Inc.          --
11 --                                                                          --
12 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
13 -- terms of the  GNU General Public License as published  by the Free Soft- --
14 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
15 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
18 -- for  more details.  You should have  received  a copy of the GNU General --
19 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
20 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
21 -- MA 02111-1307, USA.                                                      --
22 --                                                                          --
23 -- GNAT was originally developed  by the GNAT team at  New York University. --
24 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
25 --                                                                          --
26 ------------------------------------------------------------------------------
27
28 --  The following package declares the data types for GNAT project.
29 --  These data types may be used by GNAT Project-aware tools.
30
31 --  Children of these package implements various services on these data types.
32 --  See in particular Prj.Pars and Prj.Env.
33
34 with Casing;      use Casing;
35 with GNAT.OS_Lib; use GNAT.OS_Lib;
36 with Scans;       use Scans;
37 with Table;
38 with Types;       use Types;
39
40 package Prj is
41
42    Project_File_Extension : String := ".gpr";
43    --  The standard project file name extension.
44    --  It is not a constant, because Canonical_Case_File_Name is called
45    --  on this variable in the body of Prj.
46
47    Default_Ada_Spec_Suffix : Name_Id;
48    --  The Name_Id for the standard GNAT suffix for Ada spec source file
49    --  name ".ads". Initialized by Prj.Initialize.
50
51    Default_Ada_Impl_Suffix : Name_Id;
52    --  The Name_Id for the standard GNAT suffix for Ada body source file
53    --  name ".adb". Initialized by Prj.Initialize.
54
55    type Verbosity is (Default, Medium, High);
56    --  Verbosity when parsing GNAT Project Files
57    --    Default is default (very quiet, if no errors).
58    --    Medium is more verbose.
59    --    High is extremely verbose.
60
61    type Lib_Kind is (Static, Dynamic, Relocatable);
62
63    function Empty_String return String_Id;
64
65    type String_List_Id is new Nat;
66    Nil_String : constant String_List_Id := 0;
67    type String_Element is record
68       Value    : String_Id      := No_String;
69       Location : Source_Ptr     := No_Location;
70       Next     : String_List_Id := Nil_String;
71    end record;
72    --  To hold values for string list variables and array elements
73
74    package String_Elements is new Table.Table
75      (Table_Component_Type => String_Element,
76       Table_Index_Type     => String_List_Id,
77       Table_Low_Bound      => 1,
78       Table_Initial        => 200,
79       Table_Increment      => 100,
80       Table_Name           => "Prj.String_Elements");
81    --  The table for string elements in string lists
82
83    type Variable_Kind is (Undefined, List, Single);
84    --  Different kinds of variables
85
86    type Variable_Value (Kind : Variable_Kind := Undefined) is record
87       Location : Source_Ptr := No_Location;
88       Default  : Boolean    := False;
89       case Kind is
90          when Undefined =>
91             null;
92          when List =>
93             Values : String_List_Id := Nil_String;
94          when Single =>
95             Value : String_Id := No_String;
96       end case;
97    end record;
98    --  Values for variables and array elements.
99    --  Default is True if the current value is the default one for the variable
100
101    Nil_Variable_Value : constant Variable_Value :=
102      (Kind     => Undefined,
103       Location => No_Location,
104       Default  => False);
105    --  Value of a non existing variable or array element
106
107    type Variable_Id is new Nat;
108    No_Variable : constant Variable_Id := 0;
109    type Variable is record
110       Next     : Variable_Id := No_Variable;
111       Name     : Name_Id;
112       Value    : Variable_Value;
113    end record;
114    --  To hold the list of variables in a project file and in packages
115
116    package Variable_Elements is new Table.Table
117      (Table_Component_Type => Variable,
118       Table_Index_Type     => Variable_Id,
119       Table_Low_Bound      => 1,
120       Table_Initial        => 200,
121       Table_Increment      => 100,
122       Table_Name           => "Prj.Variable_Elements");
123    --  The table of variable in list of variables
124
125    type Array_Element_Id is new Nat;
126    No_Array_Element : constant Array_Element_Id := 0;
127    type Array_Element is record
128       Index    : Name_Id;
129       Value    : Variable_Value;
130       Next     : Array_Element_Id := No_Array_Element;
131    end record;
132    --  Each Array_Element represents an array element and is linked (Next)
133    --  to the next array element, if any, in the array.
134
135    package Array_Elements is new Table.Table
136      (Table_Component_Type => Array_Element,
137       Table_Index_Type     => Array_Element_Id,
138       Table_Low_Bound      => 1,
139       Table_Initial        => 200,
140       Table_Increment      => 100,
141       Table_Name           => "Prj.Array_Elements");
142    --  The table that contains all array elements
143
144    type Array_Id is new Nat;
145    No_Array : constant Array_Id := 0;
146    type Array_Data is record
147       Name  : Name_Id          := No_Name;
148       Value : Array_Element_Id := No_Array_Element;
149       Next  : Array_Id         := No_Array;
150    end record;
151    --  Each Array_Data value represents an array.
152    --  Value is the id of the first element.
153    --  Next is the id of the next array in the project file or package.
154
155    package Arrays is new Table.Table
156      (Table_Component_Type => Array_Data,
157       Table_Index_Type     => Array_Id,
158       Table_Low_Bound      => 1,
159       Table_Initial        => 200,
160       Table_Increment      => 100,
161       Table_Name           => "Prj.Arrays");
162    --  The table that contains all arrays
163
164    type Package_Id is new Nat;
165    No_Package : constant Package_Id := 0;
166    type Declarations is record
167       Variables  : Variable_Id := No_Variable;
168       Attributes : Variable_Id := No_Variable;
169       Arrays     : Array_Id    := No_Array;
170       Packages   : Package_Id  := No_Package;
171    end record;
172
173    No_Declarations : constant Declarations :=
174      (Variables  => No_Variable,
175       Attributes => No_Variable,
176       Arrays     => No_Array,
177       Packages   => No_Package);
178    --  Declarations. Used in project structures and packages (what for???)
179
180    type Package_Element is record
181       Name   : Name_Id      := No_Name;
182       Decl   : Declarations := No_Declarations;
183       Parent : Package_Id   := No_Package;
184       Next   : Package_Id   := No_Package;
185    end record;
186    --  A package. Includes declarations that may include other packages.
187
188    package Packages is new Table.Table
189      (Table_Component_Type => Package_Element,
190       Table_Index_Type     => Package_Id,
191       Table_Low_Bound      => 1,
192       Table_Initial        => 100,
193       Table_Increment      => 100,
194       Table_Name           => "Prj.Packages");
195    --  The table that contains all packages.
196
197    function Image (Casing : Casing_Type) return String;
198    --  Similar to 'Image (but avoid use of this attribute in compiler)
199
200    function Value (Image : String) return Casing_Type;
201    --  Similar to 'Value (but avoid use of this attribute in compiler)
202    --  Raises Constraint_Error if not a Casing_Type image.
203
204    type Naming_Data is record
205       Current_Language : Name_Id := No_Name;
206       --  The programming language being currently considered
207
208       Dot_Replacement : Name_Id := No_Name;
209       --  The string to replace '.' in the source file name (for Ada).
210
211       Dot_Repl_Loc : Source_Ptr := No_Location;
212       --  The position in the project file source where
213       --  Dot_Replacement is defined.
214
215       Casing : Casing_Type := All_Lower_Case;
216       --  The casing of the source file name (for Ada).
217
218       Specification_Suffix : Array_Element_Id := No_Array_Element;
219       --  The string to append to the unit name for the
220       --  source file name of a specification.
221       --  Indexed by the programming language.
222
223       Current_Spec_Suffix : Name_Id := No_Name;
224       --  The specification suffix of the current programming language
225
226       Spec_Suffix_Loc : Source_Ptr := No_Location;
227       --  The position in the project file source where
228       --  Current_Spec_Suffix is defined.
229
230       Implementation_Suffix : Array_Element_Id := No_Array_Element;
231       --  The string to append to the unit name for the
232       --  source file name of a body.
233       --  Indexed by the programming language.
234
235       Current_Impl_Suffix : Name_Id := No_Name;
236       --  The implementation suffix of the current programming language
237
238       Impl_Suffix_Loc : Source_Ptr := No_Location;
239       --  The position in the project file source where
240       --  Current_Impl_Suffix is defined.
241
242       Separate_Suffix : Name_Id := No_Name;
243       --  The string to append to the unit name for the
244       --  source file name of an Ada subunit.
245
246       Sep_Suffix_Loc : Source_Ptr := No_Location;
247       --  The position in the project file source where
248       --  Separate_Suffix is defined.
249
250       Specifications : Array_Element_Id := No_Array_Element;
251       --  An associative array mapping individual specifications
252       --  to source file names. Specific to Ada.
253
254       Bodies : Array_Element_Id := No_Array_Element;
255       --  An associative array mapping individual bodies
256       --  to source file names. Specific to Ada.
257
258       Specification_Exceptions : Array_Element_Id := No_Array_Element;
259       --  An associative array mapping individual specifications
260       --  to source file names. Indexed by the programming language name.
261
262       Implementation_Exceptions : Array_Element_Id := No_Array_Element;
263       --  An associative array mapping individual bodies
264       --  to source file names. Indexed by the programming language name.
265
266    end record;
267    --  A naming scheme.
268
269    function Standard_Naming_Data return Naming_Data;
270    pragma Inline (Standard_Naming_Data);
271    --  The standard GNAT naming scheme.
272
273    function Same_Naming_Scheme
274      (Left, Right : Naming_Data)
275       return        Boolean;
276    --  Returns True if Left and Right are the same naming scheme
277    --  not considering Specifications and Bodies.
278
279    type Project_Id is new Nat;
280    No_Project : constant Project_Id := 0;
281    --  Id of a Project File
282
283    type Project_List is new Nat;
284    Empty_Project_List : constant Project_List := 0;
285    --  A list of project files.
286
287    type Project_Element is record
288       Project : Project_Id   := No_Project;
289       Next    : Project_List := Empty_Project_List;
290    end record;
291    --  Element in a list of project file.
292    --  Next is the id of the next project file in the list.
293
294    package Project_Lists is new Table.Table
295      (Table_Component_Type => Project_Element,
296       Table_Index_Type     => Project_List,
297       Table_Low_Bound      => 1,
298       Table_Initial        => 100,
299       Table_Increment      => 100,
300       Table_Name           => "Prj.Project_Lists");
301    --  The table that contains the lists of project files.
302
303    type Project_Data is record
304       First_Referred_By  : Project_Id := No_Project;
305       --  The project, if any, that was the first to be known
306       --  as importing or extending this project.
307       --  Set by Prj.Proc.Process.
308
309       Name : Name_Id := No_Name;
310       --  The name of the project.
311       --  Set by Prj.Proc.Process.
312
313       Path_Name : Name_Id := No_Name;
314       --  The path name of the project file.
315       --  Set by Prj.Proc.Process.
316
317       Location : Source_Ptr := No_Location;
318       --  The location in the project file source of the
319       --  reserved word project.
320       --  Set by Prj.Proc.Process.
321
322       Directory : Name_Id := No_Name;
323       --  The directory where the project file resides.
324       --  Set by Prj.Proc.Process.
325
326       Library : Boolean := False;
327       --  True if this is a library project.
328       --  Set by Prj.Nmsc.Check_Naming_Scheme.
329
330       Library_Dir : Name_Id := No_Name;
331       --  If a library project, directory where resides the library
332       --  Set by Prj.Nmsc.Check_Naming_Scheme.
333
334       Library_Name : Name_Id := No_Name;
335       --  If a library project, name of the library
336       --  Set by Prj.Nmsc.Check_Naming_Scheme.
337
338       Library_Kind : Lib_Kind := Static;
339       --  If a library project, kind of library
340       --  Set by Prj.Nmsc.Check_Naming_Scheme.
341
342       Lib_Internal_Name : Name_Id := No_Name;
343       --  If a library project, internal name store inside the library
344       --  Set by Prj.Nmsc.Check_Naming_Scheme.
345
346       Lib_Elaboration : Boolean := False;
347       --  If a library project, indicate if <lib>init and <lib>final
348       --  procedures need to be defined.
349       --  Set by Prj.Nmsc.Check_Naming_Scheme.
350
351       Sources_Present : Boolean := True;
352       --  A flag that indicates if there are sources in this project file.
353       --  There are no sources if 1) Source_Dirs is specified as an
354       --  empty list, 2) Source_Files is specified as an empty list, or
355       --  3) the current language is not in the list of the specified
356       --  Languages.
357
358       Sources : String_List_Id := Nil_String;
359       --  The list of all the source file names.
360       --  Set by Prj.Nmsc.Check_Naming_Scheme.
361
362       Source_Dirs : String_List_Id := Nil_String;
363       --  The list of all the source directories.
364       --  Set by Prj.Nmsc.Check_Naming_Scheme.
365
366       Object_Directory : Name_Id := No_Name;
367       --  The object directory of this project file.
368       --  Set by Prj.Nmsc.Check_Naming_Scheme.
369
370       Exec_Directory   : Name_Id := No_Name;
371       --  The exec directory of this project file.
372       --  Default is equal to Object_Directory.
373       --  Set by Prj.Nmsc.Check_Naming_Scheme.
374
375       Modifies : Project_Id := No_Project;
376       --  The reference of the project file, if any, that this
377       --  project file modifies.
378       --  Set by Prj.Proc.Process.
379
380       Modified_By : Project_Id := No_Project;
381       --  The reference of the project file, if any, that
382       --  modifies this project file.
383       --  Set by Prj.Proc.Process.
384
385       Naming : Naming_Data := Standard_Naming_Data;
386       --  The naming scheme of this project file.
387       --  Set by Prj.Nmsc.Check_Naming_Scheme.
388
389       Decl : Declarations := No_Declarations;
390       --  The declarations (variables, attributes and packages)
391       --  of this project file.
392       --  Set by Prj.Proc.Process.
393
394       Imported_Projects : Project_List := Empty_Project_List;
395       --  The list of all directly imported projects, if any.
396       --  Set by Prj.Proc.Process.
397
398       Include_Path : String_Access := null;
399       --  The cached value of ADA_INCLUDE_PATH for this project file.
400       --  Set by gnatmake (Prj.Env.Set_Ada_Paths).
401       --  Do not use this field directly outside of the compiler, use
402       --  Prj.Env.Ada_Source_Path instead.
403
404       Objects_Path : String_Access := null;
405       --  The cached value of ADA_OBJECTS_PATH for this project file.
406       --  Set by gnatmake (Prj.Env.Set_Ada_Paths).
407       --  Do not use this field directly outside of the compiler, use
408       --  Prj.Env.Ada_Objects_Path instead.
409
410       Config_File_Name : Name_Id := No_Name;
411       --  The name of the configuration pragmas file, if any.
412       --  Set by gnatmake (Prj.Env.Create_Config_Pragmas_File).
413
414       Config_File_Temp : Boolean := False;
415       --  An indication that the configuration pragmas file is
416       --  a temporary file that must be deleted at the end.
417       --  Set by gnatmake (Prj.Env.Create_Config_Pragmas_File).
418
419       Config_Checked : Boolean := False;
420       --  A flag to avoid checking repetitively the configuration pragmas file.
421       --  Set by gnatmake (Prj.Env.Create_Config_Pragmas_File).
422
423       Language_Independent_Checked : Boolean := False;
424       --  A flag that indicates that the project file has been checked
425       --  for language independent features: Object_Directory,
426       --  Source_Directories, Library, non empty Naming Suffixs.
427
428       Checked : Boolean := False;
429       --  A flag to avoid checking repetitively the naming scheme of
430       --  this project file.
431       --  Set by Prj.Nmsc.Check_Naming_Scheme.
432
433       Seen  : Boolean := False;
434       Flag1 : Boolean := False;
435       Flag2 : Boolean := False;
436       --  Various flags that are used in an ad hoc manner
437       --  That's really not a good enough comment ??? we need to know what
438       --  these flags are used for, and give them proper names. If Flag1
439       --  and Flag2 have multiple uses, then either we use multiple fields
440       --  or a renaming scheme.
441
442    end record;
443    --  Project File representation.
444
445    function Empty_Project return Project_Data;
446    --  Return the representation of an empty project.
447
448    package Projects is new Table.Table (
449      Table_Component_Type => Project_Data,
450      Table_Index_Type     => Project_Id,
451      Table_Low_Bound      => 1,
452      Table_Initial        => 100,
453      Table_Increment      => 100,
454      Table_Name           => "Prj.Projects");
455    --  The set of all project files.
456
457    type Put_Line_Access is access procedure
458      (Line    : String;
459       Project : Project_Id);
460    --  Use to customize error reporting in Prj.Proc and Prj.Nmsc.
461
462    procedure Expect (The_Token : Token_Type; Token_Image : String);
463    --  Check that the current token is The_Token. If it is not, then
464    --  output an error message.
465
466    procedure Initialize;
467    --  This procedure must be called before using any services from the Prj
468    --  hierarchy. Namet.Initialize must be called before Prj.Initialize.
469
470    procedure Reset;
471    --  This procedure resets all the tables that are used when processing a
472    --  project file tree. Initialize must be called before the call to Reset.
473
474    procedure Register_Default_Naming_Scheme
475      (Language : Name_Id;
476       Default_Spec_Suffix : Name_Id;
477       Default_Impl_Suffix : Name_Id);
478    --  Register the default suffixs for a given language. These extensions
479    --  will be ignored if the user has specified a new naming scheme in a
480    --  project file.
481    --  Otherwise, this information will be automatically added to Naming_Data
482    --  when a project is processed, in the lists Specification_Suffix and
483    --  Implementation_Suffix.
484
485    generic
486       type State is limited private;
487       with procedure Action
488         (Project    : Project_Id;
489          With_State : in out State);
490    procedure For_Every_Project_Imported
491      (By         : Project_Id;
492       With_State : in out State);
493    --  Call Action for each project imported directly or indirectly by project
494    --  By. Action is called according to the order of importation: if A
495    --  imports B, directly or indirectly, Action will be called for A before
496    --  it is called for B. With_State may be used by Action to choose a
497    --  behavior or to report some global result.
498
499 private
500
501    procedure Scan;
502    --  Calls Scn.Scan and change any Operator_Symbol to String_Literal
503
504 end Prj;