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 and is linked (Next)
123 -- to the next array element, if any, in the array.
125 package Array_Elements is new Table.Table
126 (Table_Component_Type => Array_Element,
127 Table_Index_Type => Array_Element_Id,
128 Table_Low_Bound => 1,
129 Table_Initial => 200,
130 Table_Increment => 100,
131 Table_Name => "Prj.Array_Elements");
132 -- The table that contains all array elements
134 type Array_Id is new Nat;
135 No_Array : constant Array_Id := 0;
136 type Array_Data is record
137 Name : Name_Id := No_Name;
138 Value : Array_Element_Id := No_Array_Element;
139 Next : Array_Id := No_Array;
141 -- Each Array_Data value represents an array.
142 -- Value is the id of the first element.
143 -- Next is the id of the next array in the project file or package.
145 package Arrays is new Table.Table
146 (Table_Component_Type => Array_Data,
147 Table_Index_Type => Array_Id,
148 Table_Low_Bound => 1,
149 Table_Initial => 200,
150 Table_Increment => 100,
151 Table_Name => "Prj.Arrays");
152 -- The table that contains all arrays
154 type Package_Id is new Nat;
155 No_Package : constant Package_Id := 0;
156 type Declarations is record
157 Variables : Variable_Id := No_Variable;
158 Attributes : Variable_Id := No_Variable;
159 Arrays : Array_Id := No_Array;
160 Packages : Package_Id := No_Package;
163 No_Declarations : constant Declarations :=
164 (Variables => No_Variable,
165 Attributes => No_Variable,
167 Packages => No_Package);
168 -- Declarations. Used in project structures and packages (what for???)
170 type Package_Element is record
171 Name : Name_Id := No_Name;
172 Decl : Declarations := No_Declarations;
173 Parent : Package_Id := No_Package;
174 Next : Package_Id := No_Package;
176 -- A package. Includes declarations that may include other packages.
178 package Packages is new Table.Table
179 (Table_Component_Type => Package_Element,
180 Table_Index_Type => Package_Id,
181 Table_Low_Bound => 1,
182 Table_Initial => 100,
183 Table_Increment => 100,
184 Table_Name => "Prj.Packages");
185 -- The table that contains all packages.
187 function Image (Casing : Casing_Type) return String;
188 -- Similar to 'Image (but avoid use of this attribute in compiler)
190 function Value (Image : String) return Casing_Type;
191 -- Similar to 'Value (but avoid use of this attribute in compiler)
192 -- Raises Constraint_Error if not a Casing_Type image.
194 type Naming_Data is record
195 Current_Language : Name_Id := No_Name;
196 -- The programming language being currently considered
198 Dot_Replacement : Name_Id := No_Name;
199 -- The string to replace '.' in the source file name (for Ada).
201 Dot_Repl_Loc : Source_Ptr := No_Location;
202 -- The position in the project file source where
203 -- Dot_Replacement is defined.
205 Casing : Casing_Type := All_Lower_Case;
206 -- The casing of the source file name (for Ada).
208 Specification_Suffix : Array_Element_Id := No_Array_Element;
209 -- The string to append to the unit name for the
210 -- source file name of a specification.
211 -- Indexed by the programming language.
213 Current_Spec_Suffix : Name_Id := No_Name;
214 -- The specification suffix of the current programming language
216 Spec_Suffix_Loc : Source_Ptr := No_Location;
217 -- The position in the project file source where
218 -- Current_Spec_Suffix is defined.
220 Implementation_Suffix : Array_Element_Id := No_Array_Element;
221 -- The string to append to the unit name for the
222 -- source file name of a body.
223 -- Indexed by the programming language.
225 Current_Impl_Suffix : Name_Id := No_Name;
226 -- The implementation suffix of the current programming language
228 Impl_Suffix_Loc : Source_Ptr := No_Location;
229 -- The position in the project file source where
230 -- Current_Impl_Suffix is defined.
232 Separate_Suffix : Name_Id := No_Name;
233 -- The string to append to the unit name for the
234 -- source file name of an Ada subunit.
236 Sep_Suffix_Loc : Source_Ptr := No_Location;
237 -- The position in the project file source where
238 -- Separate_Suffix is defined.
240 Specifications : Array_Element_Id := No_Array_Element;
241 -- An associative array mapping individual specifications
242 -- to source file names. Specific to Ada.
244 Bodies : Array_Element_Id := No_Array_Element;
245 -- An associative array mapping individual bodies
246 -- to source file names. Specific to Ada.
248 Specification_Exceptions : Array_Element_Id := No_Array_Element;
249 -- An associative array mapping individual specifications
250 -- to source file names. Indexed by the programming language name.
252 Implementation_Exceptions : Array_Element_Id := No_Array_Element;
253 -- An associative array mapping individual bodies
254 -- to source file names. Indexed by the programming language name.
259 function Standard_Naming_Data return Naming_Data;
260 pragma Inline (Standard_Naming_Data);
261 -- The standard GNAT naming scheme.
263 function Same_Naming_Scheme
264 (Left, Right : Naming_Data)
266 -- Returns True if Left and Right are the same naming scheme
267 -- not considering Specifications and Bodies.
269 type Project_Id is new Nat;
270 No_Project : constant Project_Id := 0;
271 -- Id of a Project File
273 type Project_List is new Nat;
274 Empty_Project_List : constant Project_List := 0;
275 -- A list of project files.
277 type Project_Element is record
278 Project : Project_Id := No_Project;
279 Next : Project_List := Empty_Project_List;
281 -- Element in a list of project file.
282 -- Next is the id of the next project file in the list.
284 package Project_Lists is new Table.Table
285 (Table_Component_Type => Project_Element,
286 Table_Index_Type => Project_List,
287 Table_Low_Bound => 1,
288 Table_Initial => 100,
289 Table_Increment => 100,
290 Table_Name => "Prj.Project_Lists");
291 -- The table that contains the lists of project files.
293 type Project_Data is record
294 First_Referred_By : Project_Id := No_Project;
295 -- The project, if any, that was the first to be known
296 -- as importing or extending this project.
297 -- Set by Prj.Proc.Process.
299 Name : Name_Id := No_Name;
300 -- The name of the project.
301 -- Set by Prj.Proc.Process.
303 Path_Name : Name_Id := No_Name;
304 -- The path name of the project file.
305 -- Set by Prj.Proc.Process.
307 Location : Source_Ptr := No_Location;
308 -- The location in the project file source of the
309 -- reserved word project.
310 -- Set by Prj.Proc.Process.
312 Directory : Name_Id := No_Name;
313 -- The directory where the project file resides.
314 -- Set by Prj.Proc.Process.
316 Library : Boolean := False;
317 -- True if this is a library project.
318 -- Set by Prj.Nmsc.Check_Naming_Scheme.
320 Library_Dir : Name_Id := No_Name;
321 -- If a library project, directory where resides the library
322 -- Set by Prj.Nmsc.Check_Naming_Scheme.
324 Library_Name : Name_Id := No_Name;
325 -- If a library project, name of the library
326 -- Set by Prj.Nmsc.Check_Naming_Scheme.
328 Library_Kind : Lib_Kind := Static;
329 -- If a library project, kind of library
330 -- Set by Prj.Nmsc.Check_Naming_Scheme.
332 Lib_Internal_Name : Name_Id := No_Name;
333 -- If a library project, internal name store inside the library
334 -- Set by Prj.Nmsc.Check_Naming_Scheme.
336 Lib_Elaboration : Boolean := False;
337 -- If a library project, indicate if <lib>init and <lib>final
338 -- procedures need to be defined.
339 -- Set by Prj.Nmsc.Check_Naming_Scheme.
341 Sources_Present : Boolean := True;
342 -- A flag that indicates if there are sources in this project file.
343 -- There are no sources if 1) Source_Dirs is specified as an
344 -- empty list, 2) Source_Files is specified as an empty list, or
345 -- 3) the current language is not in the list of the specified
348 Sources : String_List_Id := Nil_String;
349 -- The list of all the source file names.
350 -- Set by Prj.Nmsc.Check_Naming_Scheme.
352 Source_Dirs : String_List_Id := Nil_String;
353 -- The list of all the source directories.
354 -- Set by Prj.Nmsc.Check_Naming_Scheme.
356 Object_Directory : Name_Id := No_Name;
357 -- The object directory of this project file.
358 -- Set by Prj.Nmsc.Check_Naming_Scheme.
360 Modifies : Project_Id := No_Project;
361 -- The reference of the project file, if any, that this
362 -- project file modifies.
363 -- Set by Prj.Proc.Process.
365 Modified_By : Project_Id := No_Project;
366 -- The reference of the project file, if any, that
367 -- modifies this project file.
368 -- Set by Prj.Proc.Process.
370 Naming : Naming_Data := Standard_Naming_Data;
371 -- The naming scheme of this project file.
372 -- Set by Prj.Nmsc.Check_Naming_Scheme.
374 Decl : Declarations := No_Declarations;
375 -- The declarations (variables, attributes and packages)
376 -- of this project file.
377 -- Set by Prj.Proc.Process.
379 Imported_Projects : Project_List := Empty_Project_List;
380 -- The list of all directly imported projects, if any.
381 -- Set by Prj.Proc.Process.
383 Include_Path : String_Access := null;
384 -- The cached value of ADA_INCLUDE_PATH for this project file.
385 -- Set by gnatmake (prj.Env.Set_Ada_Paths).
387 Objects_Path : String_Access := null;
388 -- The cached value of ADA_OBJECTS_PATH for this project file.
389 -- Set by gnatmake (prj.Env.Set_Ada_Paths).
391 Config_File_Name : Name_Id := No_Name;
392 -- The name of the configuration pragmas file, if any.
393 -- Set by gnatmage (Prj.Env.Create_Config_Pragmas_File).
395 Config_File_Temp : Boolean := False;
396 -- An indication that the configuration pragmas file is
397 -- a temporary file that must be deleted at the end.
398 -- Set by gnatmage (Prj.Env.Create_Config_Pragmas_File).
400 Config_Checked : Boolean := False;
401 -- A flag to avoid checking repetitively the configuration pragmas file.
402 -- Set by gnatmage (Prj.Env.Create_Config_Pragmas_File).
404 Language_Independent_Checked : Boolean := False;
405 -- A flag that indicates that the project file has been checked
406 -- for language independent features: Object_Directory,
407 -- Source_Directories, Library, non empty Naming Suffixs.
409 Checked : Boolean := False;
410 -- A flag to avoid checking repetitively the naming scheme of
411 -- this project file.
412 -- Set by Prj.Nmsc.Check_Naming_Scheme.
414 Seen : Boolean := False;
415 Flag1 : Boolean := False;
416 Flag2 : Boolean := False;
417 -- Various flags that are used in an ad hoc manner
418 -- That's really not a good enough comment ??? we need to know what
419 -- these flags are used for, and give them proper names. If Flag1
420 -- and Flag2 have multiple uses, then either we use multiple fields
421 -- or a renaming scheme.
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