1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
11 -- Copyright (C) 2001 Free Software Foundation, Inc. --
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. --
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). --
27 ------------------------------------------------------------------------------
29 -- The following package declares the data types for GNAT project.
30 -- These data types may be used by GNAT Project-aware tools.
32 -- Children of these package implements various services on these data types.
33 -- See in particular Prj.Pars and Prj.Env.
35 with Casing; use Casing;
36 with GNAT.OS_Lib; use GNAT.OS_Lib;
37 with Scans; use Scans;
39 with Types; use Types;
43 type Put_Line_Access is access procedure (Line : String);
44 -- Use to customize error reporting in Prj.Proc and Prj.Nmsc.
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.
52 type Lib_Kind is (Static, Dynamic, Relocatable);
54 function Empty_String return String_Id;
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;
63 -- To hold values for string list variables and array elements.
65 package String_Elements is new Table.Table
66 (Table_Component_Type => String_Element,
67 Table_Index_Type => String_List_Id,
70 Table_Increment => 100,
71 Table_Name => "Prj.String_Elements");
72 -- The table for string elements in string lists.
74 type Variable_Kind is (Undefined, List, Single);
75 -- Different kinds of variables
77 type Variable_Value (Kind : Variable_Kind := Undefined) is record
78 Location : Source_Ptr := No_Location;
79 Default : Boolean := False;
84 Values : String_List_Id := Nil_String;
86 Value : String_Id := No_String;
89 -- Values for variables and array elements
91 Nil_Variable_Value : constant Variable_Value :=
93 Location => No_Location,
95 -- Value of a non existing variable or array element.
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;
102 Value : Variable_Value;
104 -- To hold the list of variables in a project file and in packages.
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.
115 type Array_Element_Id is new Nat;
116 No_Array_Element : constant Array_Element_Id := 0;
117 type Array_Element is record
119 Value : Variable_Value;
120 Next : Array_Element_Id := No_Array_Element;
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.
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
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;
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.
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
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;
164 No_Declarations : constant Declarations :=
165 (Variables => No_Variable,
166 Attributes => No_Variable,
168 Packages => No_Package);
169 -- Declarations. Used in project structures and packages.
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;
177 -- A package. Includes declarations that may include
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.
189 function Image (Casing : Casing_Type) return String;
192 function Value (Image : String) return Casing_Type;
194 -- This is to avoid s-valenu in the closure of the tools
195 -- Raises Constraint_Error if not a Casing_Type image.
197 type Naming_Data is record
198 Current_Language : Name_Id := No_Name;
199 -- The programming language being currently considered
201 Dot_Replacement : Name_Id := No_Name;
202 -- The string to replace '.' in the source file name (for Ada).
204 Dot_Repl_Loc : Source_Ptr := No_Location;
205 -- The position in the project file source where
206 -- Dot_Replacement is defined.
208 Casing : Casing_Type := All_Lower_Case;
209 -- The casing of the source file name (for Ada).
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.
216 Current_Spec_Suffix : Name_Id := No_Name;
217 -- The specification suffix of the current programming language
219 Spec_Suffix_Loc : Source_Ptr := No_Location;
220 -- The position in the project file source where
221 -- Current_Spec_Suffix is defined.
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.
228 Current_Impl_Suffix : Name_Id := No_Name;
229 -- The implementation suffix of the current programming language
231 Impl_Suffix_Loc : Source_Ptr := No_Location;
232 -- The position in the project file source where
233 -- Current_Impl_Suffix is defined.
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.
239 Sep_Suffix_Loc : Source_Ptr := No_Location;
240 -- The position in the project file source where
241 -- Separate_Suffix is defined.
243 Specifications : Array_Element_Id := No_Array_Element;
244 -- An associative array mapping individual specifications
245 -- to source file names. Specific to Ada.
247 Bodies : Array_Element_Id := No_Array_Element;
248 -- An associative array mapping individual bodies
249 -- to source file names. Specific to Ada.
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.
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.
262 function Standard_Naming_Data return Naming_Data;
263 pragma Inline (Standard_Naming_Data);
264 -- The standard GNAT naming scheme.
266 function Same_Naming_Scheme
267 (Left, Right : Naming_Data)
269 -- Returns True if Left and Right are the same naming scheme
270 -- not considering Specifications and Bodies.
272 type Project_Id is new Nat;
273 No_Project : constant Project_Id := 0;
274 -- Id of a Project File
276 type Project_List is new Nat;
277 Empty_Project_List : constant Project_List := 0;
278 -- A list of project files.
280 type Project_Element is record
281 Project : Project_Id := No_Project;
282 Next : Project_List := Empty_Project_List;
284 -- Element in a list of project file.
285 -- Next is the id of the next project file in the list.
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.
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.
302 Name : Name_Id := No_Name;
303 -- The name of the project.
304 -- Set by Prj.Proc.Process.
306 Path_Name : Name_Id := No_Name;
307 -- The path name of the project file.
308 -- Set by Prj.Proc.Process.
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.
315 Directory : Name_Id := No_Name;
316 -- The directory where the project file resides.
317 -- Set by Prj.Proc.Process.
319 Library : Boolean := False;
320 -- True if this is a library project.
321 -- Set by Prj.Nmsc.Check_Naming_Scheme.
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.
327 Library_Name : Name_Id := No_Name;
328 -- If a library project, name of the library
329 -- Set by Prj.Nmsc.Check_Naming_Scheme.
331 Library_Kind : Lib_Kind := Static;
332 -- If a library project, kind of library
333 -- Set by Prj.Nmsc.Check_Naming_Scheme.
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.
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.
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
351 Sources : String_List_Id := Nil_String;
352 -- The list of all the source file names.
353 -- Set by Prj.Nmsc.Check_Naming_Scheme.
355 Source_Dirs : String_List_Id := Nil_String;
356 -- The list of all the source directories.
357 -- Set by Prj.Nmsc.Check_Naming_Scheme.
359 Object_Directory : Name_Id := No_Name;
360 -- The object directory of this project file.
361 -- Set by Prj.Nmsc.Check_Naming_Scheme.
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.
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.
373 Naming : Naming_Data := Standard_Naming_Data;
374 -- The naming scheme of this project file.
375 -- Set by Prj.Nmsc.Check_Naming_Scheme.
377 Decl : Declarations := No_Declarations;
378 -- The declarations (variables, attributes and packages)
379 -- of this project file.
380 -- Set by Prj.Proc.Process.
382 Imported_Projects : Project_List := Empty_Project_List;
383 -- The list of all directly imported projects, if any.
384 -- Set by Prj.Proc.Process.
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).
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).
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).
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).
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).
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.
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.
417 -- Various flags that are used in an ad hoc manner
419 Seen : Boolean := False;
420 Flag1 : Boolean := False;
421 Flag2 : Boolean := False;
424 -- Project File representation.
426 function Empty_Project return Project_Data;
427 -- Return the representation of an empty project.
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.
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.
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.
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.
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
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.
464 function Ada_Default_Spec_Suffix return Name_Id;
465 -- Return the Name_Id for the standard GNAT suffix for Ada spec source
468 function Ada_Default_Impl_Suffix return Name_Id;
469 -- Return the Name_Id for the standard GNAT suffix for Ada body source
475 -- Calls Scn.Scan and change any Operator_Symbol to String_Literal