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 -- Extensive contributions were provided by Ada Core Technologies Inc. --
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 Default_Ada_Spec_Suffix
: Name_Id
;
44 -- The Name_Id for the standard GNAT suffix for Ada spec source file
45 -- name ".ads". Initialized by Prj.Initialize.
47 Default_Ada_Impl_Suffix
: Name_Id
;
48 -- The Name_Id for the standard GNAT suffix for Ada body source file
49 -- name ".adb". Initialized by Prj.Initialize.
51 type Put_Line_Access
is access procedure (Line
: String);
52 -- Use to customize error reporting in Prj.Proc and Prj.Nmsc.
54 type Verbosity
is (Default
, Medium
, High
);
55 -- Verbosity when parsing GNAT Project Files
56 -- Default is default (very quiet, if no errors).
57 -- Medium is more verbose.
58 -- High is extremely verbose.
60 type Lib_Kind
is (Static
, Dynamic
, Relocatable
);
62 function Empty_String
return String_Id
;
64 type String_List_Id
is new Nat
;
65 Nil_String
: constant String_List_Id
:= 0;
66 type String_Element
is record
67 Value
: String_Id
:= No_String
;
68 Location
: Source_Ptr
:= No_Location
;
69 Next
: String_List_Id
:= Nil_String
;
71 -- To hold values for string list variables and array elements
73 package String_Elements
is new Table
.Table
74 (Table_Component_Type
=> String_Element
,
75 Table_Index_Type
=> String_List_Id
,
78 Table_Increment
=> 100,
79 Table_Name
=> "Prj.String_Elements");
80 -- The table for string elements in string lists
82 type Variable_Kind
is (Undefined
, List
, Single
);
83 -- Different kinds of variables
85 type Variable_Value
(Kind
: Variable_Kind
:= Undefined
) is record
86 Location
: Source_Ptr
:= No_Location
;
87 Default
: Boolean := False;
92 Values
: String_List_Id
:= Nil_String
;
94 Value
: String_Id
:= No_String
;
97 -- Values for variables and array elements.
98 -- Default is True if the current value is the default one for the variable
100 Nil_Variable_Value
: constant Variable_Value
:=
102 Location
=> No_Location
,
104 -- Value of a non existing variable or array element
106 type Variable_Id
is new Nat
;
107 No_Variable
: constant Variable_Id
:= 0;
108 type Variable
is record
109 Next
: Variable_Id
:= No_Variable
;
111 Value
: Variable_Value
;
113 -- To hold the list of variables in a project file and in packages
115 package Variable_Elements
is new Table
.Table
116 (Table_Component_Type
=> Variable
,
117 Table_Index_Type
=> Variable_Id
,
118 Table_Low_Bound
=> 1,
119 Table_Initial
=> 200,
120 Table_Increment
=> 100,
121 Table_Name
=> "Prj.Variable_Elements");
122 -- The table of variable in list of variables
124 type Array_Element_Id
is new Nat
;
125 No_Array_Element
: constant Array_Element_Id
:= 0;
126 type Array_Element
is record
128 Value
: Variable_Value
;
129 Next
: Array_Element_Id
:= No_Array_Element
;
131 -- Each Array_Element represents an array element and is linked (Next)
132 -- to the next array element, if any, in the array.
134 package Array_Elements
is new Table
.Table
135 (Table_Component_Type
=> Array_Element
,
136 Table_Index_Type
=> Array_Element_Id
,
137 Table_Low_Bound
=> 1,
138 Table_Initial
=> 200,
139 Table_Increment
=> 100,
140 Table_Name
=> "Prj.Array_Elements");
141 -- The table that contains all array elements
143 type Array_Id
is new Nat
;
144 No_Array
: constant Array_Id
:= 0;
145 type Array_Data
is record
146 Name
: Name_Id
:= No_Name
;
147 Value
: Array_Element_Id
:= No_Array_Element
;
148 Next
: Array_Id
:= No_Array
;
150 -- Each Array_Data value represents an array.
151 -- Value is the id of the first element.
152 -- Next is the id of the next array in the project file or package.
154 package Arrays
is new Table
.Table
155 (Table_Component_Type
=> Array_Data
,
156 Table_Index_Type
=> Array_Id
,
157 Table_Low_Bound
=> 1,
158 Table_Initial
=> 200,
159 Table_Increment
=> 100,
160 Table_Name
=> "Prj.Arrays");
161 -- The table that contains all arrays
163 type Package_Id
is new Nat
;
164 No_Package
: constant Package_Id
:= 0;
165 type Declarations
is record
166 Variables
: Variable_Id
:= No_Variable
;
167 Attributes
: Variable_Id
:= No_Variable
;
168 Arrays
: Array_Id
:= No_Array
;
169 Packages
: Package_Id
:= No_Package
;
172 No_Declarations
: constant Declarations
:=
173 (Variables
=> No_Variable
,
174 Attributes
=> No_Variable
,
176 Packages
=> No_Package
);
177 -- Declarations. Used in project structures and packages (what for???)
179 type Package_Element
is record
180 Name
: Name_Id
:= No_Name
;
181 Decl
: Declarations
:= No_Declarations
;
182 Parent
: Package_Id
:= No_Package
;
183 Next
: Package_Id
:= No_Package
;
185 -- A package. Includes declarations that may include other packages.
187 package Packages
is new Table
.Table
188 (Table_Component_Type
=> Package_Element
,
189 Table_Index_Type
=> Package_Id
,
190 Table_Low_Bound
=> 1,
191 Table_Initial
=> 100,
192 Table_Increment
=> 100,
193 Table_Name
=> "Prj.Packages");
194 -- The table that contains all packages.
196 function Image
(Casing
: Casing_Type
) return String;
197 -- Similar to 'Image (but avoid use of this attribute in compiler)
199 function Value
(Image
: String) return Casing_Type
;
200 -- Similar to 'Value (but avoid use of this attribute in compiler)
201 -- Raises Constraint_Error if not a Casing_Type image.
203 type Naming_Data
is record
204 Current_Language
: Name_Id
:= No_Name
;
205 -- The programming language being currently considered
207 Dot_Replacement
: Name_Id
:= No_Name
;
208 -- The string to replace '.' in the source file name (for Ada).
210 Dot_Repl_Loc
: Source_Ptr
:= No_Location
;
211 -- The position in the project file source where
212 -- Dot_Replacement is defined.
214 Casing
: Casing_Type
:= All_Lower_Case
;
215 -- The casing of the source file name (for Ada).
217 Specification_Suffix
: Array_Element_Id
:= No_Array_Element
;
218 -- The string to append to the unit name for the
219 -- source file name of a specification.
220 -- Indexed by the programming language.
222 Current_Spec_Suffix
: Name_Id
:= No_Name
;
223 -- The specification suffix of the current programming language
225 Spec_Suffix_Loc
: Source_Ptr
:= No_Location
;
226 -- The position in the project file source where
227 -- Current_Spec_Suffix is defined.
229 Implementation_Suffix
: Array_Element_Id
:= No_Array_Element
;
230 -- The string to append to the unit name for the
231 -- source file name of a body.
232 -- Indexed by the programming language.
234 Current_Impl_Suffix
: Name_Id
:= No_Name
;
235 -- The implementation suffix of the current programming language
237 Impl_Suffix_Loc
: Source_Ptr
:= No_Location
;
238 -- The position in the project file source where
239 -- Current_Impl_Suffix is defined.
241 Separate_Suffix
: Name_Id
:= No_Name
;
242 -- The string to append to the unit name for the
243 -- source file name of an Ada subunit.
245 Sep_Suffix_Loc
: Source_Ptr
:= No_Location
;
246 -- The position in the project file source where
247 -- Separate_Suffix is defined.
249 Specifications
: Array_Element_Id
:= No_Array_Element
;
250 -- An associative array mapping individual specifications
251 -- to source file names. Specific to Ada.
253 Bodies
: Array_Element_Id
:= No_Array_Element
;
254 -- An associative array mapping individual bodies
255 -- to source file names. Specific to Ada.
257 Specification_Exceptions
: Array_Element_Id
:= No_Array_Element
;
258 -- An associative array mapping individual specifications
259 -- to source file names. Indexed by the programming language name.
261 Implementation_Exceptions
: Array_Element_Id
:= No_Array_Element
;
262 -- An associative array mapping individual bodies
263 -- to source file names. Indexed by the programming language name.
268 function Standard_Naming_Data
return Naming_Data
;
269 pragma Inline
(Standard_Naming_Data
);
270 -- The standard GNAT naming scheme.
272 function Same_Naming_Scheme
273 (Left
, Right
: Naming_Data
)
275 -- Returns True if Left and Right are the same naming scheme
276 -- not considering Specifications and Bodies.
278 type Project_Id
is new Nat
;
279 No_Project
: constant Project_Id
:= 0;
280 -- Id of a Project File
282 type Project_List
is new Nat
;
283 Empty_Project_List
: constant Project_List
:= 0;
284 -- A list of project files.
286 type Project_Element
is record
287 Project
: Project_Id
:= No_Project
;
288 Next
: Project_List
:= Empty_Project_List
;
290 -- Element in a list of project file.
291 -- Next is the id of the next project file in the list.
293 package Project_Lists
is new Table
.Table
294 (Table_Component_Type
=> Project_Element
,
295 Table_Index_Type
=> Project_List
,
296 Table_Low_Bound
=> 1,
297 Table_Initial
=> 100,
298 Table_Increment
=> 100,
299 Table_Name
=> "Prj.Project_Lists");
300 -- The table that contains the lists of project files.
302 type Project_Data
is record
303 First_Referred_By
: Project_Id
:= No_Project
;
304 -- The project, if any, that was the first to be known
305 -- as importing or extending this project.
306 -- Set by Prj.Proc.Process.
308 Name
: Name_Id
:= No_Name
;
309 -- The name of the project.
310 -- Set by Prj.Proc.Process.
312 Path_Name
: Name_Id
:= No_Name
;
313 -- The path name of the project file.
314 -- Set by Prj.Proc.Process.
316 Location
: Source_Ptr
:= No_Location
;
317 -- The location in the project file source of the
318 -- reserved word project.
319 -- Set by Prj.Proc.Process.
321 Directory
: Name_Id
:= No_Name
;
322 -- The directory where the project file resides.
323 -- Set by Prj.Proc.Process.
325 Library
: Boolean := False;
326 -- True if this is a library project.
327 -- Set by Prj.Nmsc.Check_Naming_Scheme.
329 Library_Dir
: Name_Id
:= No_Name
;
330 -- If a library project, directory where resides the library
331 -- Set by Prj.Nmsc.Check_Naming_Scheme.
333 Library_Name
: Name_Id
:= No_Name
;
334 -- If a library project, name of the library
335 -- Set by Prj.Nmsc.Check_Naming_Scheme.
337 Library_Kind
: Lib_Kind
:= Static
;
338 -- If a library project, kind of library
339 -- Set by Prj.Nmsc.Check_Naming_Scheme.
341 Lib_Internal_Name
: Name_Id
:= No_Name
;
342 -- If a library project, internal name store inside the library
343 -- Set by Prj.Nmsc.Check_Naming_Scheme.
345 Lib_Elaboration
: Boolean := False;
346 -- If a library project, indicate if <lib>init and <lib>final
347 -- procedures need to be defined.
348 -- Set by Prj.Nmsc.Check_Naming_Scheme.
350 Sources_Present
: Boolean := True;
351 -- A flag that indicates if there are sources in this project file.
352 -- There are no sources if 1) Source_Dirs is specified as an
353 -- empty list, 2) Source_Files is specified as an empty list, or
354 -- 3) the current language is not in the list of the specified
357 Sources
: String_List_Id
:= Nil_String
;
358 -- The list of all the source file names.
359 -- Set by Prj.Nmsc.Check_Naming_Scheme.
361 Source_Dirs
: String_List_Id
:= Nil_String
;
362 -- The list of all the source directories.
363 -- Set by Prj.Nmsc.Check_Naming_Scheme.
365 Object_Directory
: Name_Id
:= No_Name
;
366 -- The object directory of this project file.
367 -- Set by Prj.Nmsc.Check_Naming_Scheme.
369 Exec_Directory
: Name_Id
:= No_Name
;
370 -- The exec directory of this project file.
371 -- Default is equal to Object_Directory.
372 -- Set by Prj.Nmsc.Check_Naming_Scheme.
374 Modifies
: Project_Id
:= No_Project
;
375 -- The reference of the project file, if any, that this
376 -- project file modifies.
377 -- Set by Prj.Proc.Process.
379 Modified_By
: Project_Id
:= No_Project
;
380 -- The reference of the project file, if any, that
381 -- modifies this project file.
382 -- Set by Prj.Proc.Process.
384 Naming
: Naming_Data
:= Standard_Naming_Data
;
385 -- The naming scheme of this project file.
386 -- Set by Prj.Nmsc.Check_Naming_Scheme.
388 Decl
: Declarations
:= No_Declarations
;
389 -- The declarations (variables, attributes and packages)
390 -- of this project file.
391 -- Set by Prj.Proc.Process.
393 Imported_Projects
: Project_List
:= Empty_Project_List
;
394 -- The list of all directly imported projects, if any.
395 -- Set by Prj.Proc.Process.
397 Include_Path
: String_Access
:= null;
398 -- The cached value of ADA_INCLUDE_PATH for this project file.
399 -- Set by gnatmake (prj.Env.Set_Ada_Paths).
400 -- Do not use this field directly outside of the compiler, use
401 -- Prj.Env.Ada_Source_Path instead.
403 Objects_Path
: String_Access
:= null;
404 -- The cached value of ADA_OBJECTS_PATH for this project file.
405 -- Set by gnatmake (prj.Env.Set_Ada_Paths).
406 -- Do not use this field directly outside of the compiler, use
407 -- Prj.Env.Ada_Source_Path instead.
409 Config_File_Name
: Name_Id
:= No_Name
;
410 -- The name of the configuration pragmas file, if any.
411 -- Set by gnatmage (Prj.Env.Create_Config_Pragmas_File).
413 Config_File_Temp
: Boolean := False;
414 -- An indication that the configuration pragmas file is
415 -- a temporary file that must be deleted at the end.
416 -- Set by gnatmage (Prj.Env.Create_Config_Pragmas_File).
418 Config_Checked
: Boolean := False;
419 -- A flag to avoid checking repetitively the configuration pragmas file.
420 -- Set by gnatmage (Prj.Env.Create_Config_Pragmas_File).
422 Language_Independent_Checked
: Boolean := False;
423 -- A flag that indicates that the project file has been checked
424 -- for language independent features: Object_Directory,
425 -- Source_Directories, Library, non empty Naming Suffixs.
427 Checked
: Boolean := False;
428 -- A flag to avoid checking repetitively the naming scheme of
429 -- this project file.
430 -- Set by Prj.Nmsc.Check_Naming_Scheme.
432 Seen
: Boolean := False;
433 Flag1
: Boolean := False;
434 Flag2
: Boolean := False;
435 -- Various flags that are used in an ad hoc manner
436 -- That's really not a good enough comment ??? we need to know what
437 -- these flags are used for, and give them proper names. If Flag1
438 -- and Flag2 have multiple uses, then either we use multiple fields
439 -- or a renaming scheme.
442 -- Project File representation.
444 function Empty_Project
return Project_Data
;
445 -- Return the representation of an empty project.
447 package Projects
is new Table
.Table
(
448 Table_Component_Type
=> Project_Data
,
449 Table_Index_Type
=> Project_Id
,
450 Table_Low_Bound
=> 1,
451 Table_Initial
=> 100,
452 Table_Increment
=> 100,
453 Table_Name
=> "Prj.Projects");
454 -- The set of all project files.
456 procedure Expect
(The_Token
: Token_Type
; Token_Image
: String);
457 -- Check that the current token is The_Token. If it is not, then
458 -- output an error message.
460 procedure Initialize
;
461 -- This procedure must be called before using any services from the Prj
462 -- hierarchy. Namet.Initialize must be called before Prj.Initialize.
465 -- This procedure resets all the tables that are used when processing a
466 -- project file tree. Initialize must be called before the call to Reset.
469 type State
is limited private;
470 with procedure Action
471 (Project
: Project_Id
;
472 With_State
: in out State
);
473 procedure For_Every_Project_Imported
475 With_State
: in out State
);
476 -- Call Action for each project imported directly or indirectly by project
477 -- By. Action is called according to the order of importation: if A
478 -- imports B, directly or indirectly, Action will be called for A before
479 -- it is called for B. With_State may be used by Action to choose a
480 -- behavior or to report some global result.
485 -- Calls Scn.Scan and change any Operator_Symbol to String_Literal