OSDN Git Service

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