1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
10 -- Copyright (C) 2001-2002 Free Software Foundation, Inc. --
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. --
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). --
26 ------------------------------------------------------------------------------
28 -- The following package declares the data types for GNAT project.
29 -- These data types may be used by GNAT Project-aware tools.
31 -- Children of these package implements various services on these data types.
32 -- See in particular Prj.Pars and Prj.Env.
34 with Casing; use Casing;
35 with GNAT.OS_Lib; use GNAT.OS_Lib;
36 with Scans; use Scans;
38 with Types; use Types;
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.
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.
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.
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.
61 type Lib_Kind is (Static, Dynamic, Relocatable);
63 function Empty_String return String_Id;
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;
72 -- To hold values for string list variables and array elements
74 package String_Elements is new Table.Table
75 (Table_Component_Type => String_Element,
76 Table_Index_Type => String_List_Id,
79 Table_Increment => 100,
80 Table_Name => "Prj.String_Elements");
81 -- The table for string elements in string lists
83 type Variable_Kind is (Undefined, List, Single);
84 -- Different kinds of variables
86 type Variable_Value (Kind : Variable_Kind := Undefined) is record
87 Location : Source_Ptr := No_Location;
88 Default : Boolean := False;
93 Values : String_List_Id := Nil_String;
95 Value : String_Id := No_String;
98 -- Values for variables and array elements.
99 -- Default is True if the current value is the default one for the variable
101 Nil_Variable_Value : constant Variable_Value :=
103 Location => No_Location,
105 -- Value of a non existing variable or array element
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;
112 Value : Variable_Value;
114 -- To hold the list of variables in a project file and in packages
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
125 type Array_Element_Id is new Nat;
126 No_Array_Element : constant Array_Element_Id := 0;
127 type Array_Element is record
129 Value : Variable_Value;
130 Next : Array_Element_Id := No_Array_Element;
132 -- Each Array_Element represents an array element and is linked (Next)
133 -- to the next array element, if any, in the array.
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
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;
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.
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
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;
173 No_Declarations : constant Declarations :=
174 (Variables => No_Variable,
175 Attributes => No_Variable,
177 Packages => No_Package);
178 -- Declarations. Used in project structures and packages (what for???)
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;
186 -- A package. Includes declarations that may include other packages.
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.
197 function Image (Casing : Casing_Type) return String;
198 -- Similar to 'Image (but avoid use of this attribute in compiler)
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.
204 type Naming_Data is record
205 Current_Language : Name_Id := No_Name;
206 -- The programming language being currently considered
208 Dot_Replacement : Name_Id := No_Name;
209 -- The string to replace '.' in the source file name (for Ada).
211 Dot_Repl_Loc : Source_Ptr := No_Location;
212 -- The position in the project file source where
213 -- Dot_Replacement is defined.
215 Casing : Casing_Type := All_Lower_Case;
216 -- The casing of the source file name (for Ada).
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.
223 Current_Spec_Suffix : Name_Id := No_Name;
224 -- The specification suffix of the current programming language
226 Spec_Suffix_Loc : Source_Ptr := No_Location;
227 -- The position in the project file source where
228 -- Current_Spec_Suffix is defined.
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.
235 Current_Impl_Suffix : Name_Id := No_Name;
236 -- The implementation suffix of the current programming language
238 Impl_Suffix_Loc : Source_Ptr := No_Location;
239 -- The position in the project file source where
240 -- Current_Impl_Suffix is defined.
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.
246 Sep_Suffix_Loc : Source_Ptr := No_Location;
247 -- The position in the project file source where
248 -- Separate_Suffix is defined.
250 Specifications : Array_Element_Id := No_Array_Element;
251 -- An associative array mapping individual specifications
252 -- to source file names. Specific to Ada.
254 Bodies : Array_Element_Id := No_Array_Element;
255 -- An associative array mapping individual bodies
256 -- to source file names. Specific to Ada.
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.
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.
269 function Standard_Naming_Data return Naming_Data;
270 pragma Inline (Standard_Naming_Data);
271 -- The standard GNAT naming scheme.
273 function Same_Naming_Scheme
274 (Left, Right : Naming_Data)
276 -- Returns True if Left and Right are the same naming scheme
277 -- not considering Specifications and Bodies.
279 type Project_Id is new Nat;
280 No_Project : constant Project_Id := 0;
281 -- Id of a Project File
283 type Project_List is new Nat;
284 Empty_Project_List : constant Project_List := 0;
285 -- A list of project files.
287 type Project_Element is record
288 Project : Project_Id := No_Project;
289 Next : Project_List := Empty_Project_List;
291 -- Element in a list of project file.
292 -- Next is the id of the next project file in the list.
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.
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.
309 Name : Name_Id := No_Name;
310 -- The name of the project.
311 -- Set by Prj.Proc.Process.
313 Path_Name : Name_Id := No_Name;
314 -- The path name of the project file.
315 -- Set by Prj.Proc.Process.
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.
322 Directory : Name_Id := No_Name;
323 -- The directory where the project file resides.
324 -- Set by Prj.Proc.Process.
326 Library : Boolean := False;
327 -- True if this is a library project.
328 -- Set by Prj.Nmsc.Check_Naming_Scheme.
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.
334 Library_Name : Name_Id := No_Name;
335 -- If a library project, name of the library
336 -- Set by Prj.Nmsc.Check_Naming_Scheme.
338 Library_Kind : Lib_Kind := Static;
339 -- If a library project, kind of library
340 -- Set by Prj.Nmsc.Check_Naming_Scheme.
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.
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.
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
358 Sources : String_List_Id := Nil_String;
359 -- The list of all the source file names.
360 -- Set by Prj.Nmsc.Check_Naming_Scheme.
362 Source_Dirs : String_List_Id := Nil_String;
363 -- The list of all the source directories.
364 -- Set by Prj.Nmsc.Check_Naming_Scheme.
366 Object_Directory : Name_Id := No_Name;
367 -- The object directory of this project file.
368 -- Set by Prj.Nmsc.Check_Naming_Scheme.
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.
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.
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.
385 Naming : Naming_Data := Standard_Naming_Data;
386 -- The naming scheme of this project file.
387 -- Set by Prj.Nmsc.Check_Naming_Scheme.
389 Decl : Declarations := No_Declarations;
390 -- The declarations (variables, attributes and packages)
391 -- of this project file.
392 -- Set by Prj.Proc.Process.
394 Imported_Projects : Project_List := Empty_Project_List;
395 -- The list of all directly imported projects, if any.
396 -- Set by Prj.Proc.Process.
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.
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.
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).
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).
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).
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.
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.
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.
443 -- Project File representation.
445 function Empty_Project return Project_Data;
446 -- Return the representation of an empty project.
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.
457 type Put_Line_Access is access procedure
459 Project : Project_Id);
460 -- Use to customize error reporting in Prj.Proc and Prj.Nmsc.
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.
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.
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.
474 procedure Register_Default_Naming_Scheme
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
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.
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
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.
502 -- Calls Scn.Scan and change any Operator_Symbol to String_Literal