1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2012, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 -- The following package declares the data types for GNAT project.
27 -- These data types may be used by GNAT Project-aware tools.
29 -- Children of these package implements various services on these data types.
30 -- See in particular Prj.Pars and Prj.Env.
32 with Casing
; use Casing
;
33 with Namet
; use Namet
;
35 with Scans
; use Scans
;
36 with Types
; use Types
;
38 with GNAT
.Dynamic_HTables
; use GNAT
.Dynamic_HTables
;
39 with GNAT
.Dynamic_Tables
;
40 with GNAT
.OS_Lib
; use GNAT
.OS_Lib
;
44 procedure Add_Restricted_Language
(Name
: String);
45 -- Call by gprbuild for each language specify by switch
46 -- --restricted-to-languages=.
48 function Is_Allowed_Language
(Name
: Name_Id
) return Boolean;
49 -- Returns True if --restricted-to-languages= is not used or if Name
50 -- is one of the restricted languages.
52 All_Other_Names
: constant Name_Id
:= Names_High_Bound
;
53 -- Name used to replace others as an index of an associative array
54 -- attribute in situations where this is allowed.
56 Subdirs
: String_Ptr
:= null;
57 -- The value after the equal sign in switch --subdirs=...
58 -- Contains the relative subdirectory.
60 type Library_Support
is (None
, Static_Only
, Full
);
61 -- Support for Library Project File.
62 -- - None: Library Project Files are not supported at all
63 -- - Static_Only: Library Project Files are only supported for static
65 -- - Full: Library Project Files are supported for static and dynamic
66 -- (shared) libraries.
68 type Yes_No_Unknown
is (Yes
, No
, Unknown
);
69 -- Tri-state to decide if -lgnarl is needed when linking
71 pragma Warnings
(Off
);
72 type Project_Qualifier
is
75 -- The following clash with Standard is OK, and justified by the context
76 -- which really wants to use the same set of qualifiers.
86 -- Qualifiers that can prefix the reserved word "project" in a project
88 -- Standard: standard project ...
89 -- Library: library project is ...
90 -- Dry: abstract project is
91 -- Aggregate: aggregate project is
92 -- Aggregate_Library: aggregate library project is ...
93 -- Configuration: configuration project is ...
95 subtype Aggregate_Project
is
96 Project_Qualifier
range Aggregate
.. Aggregate_Library
;
98 All_Packages
: constant String_List_Access
;
99 -- Default value of parameter Packages of procedures Parse, in Prj.Pars and
100 -- Prj.Part, indicating that all packages should be checked.
102 type Project_Tree_Data
;
103 type Project_Tree_Ref
is access all Project_Tree_Data
;
104 -- Reference to a project tree. Several project trees may exist in memory
107 No_Project_Tree
: constant Project_Tree_Ref
;
109 procedure Free
(Tree
: in out Project_Tree_Ref
);
110 -- Free memory associated with the tree
112 Config_Project_File_Extension
: String := ".cgpr";
113 Project_File_Extension
: String := ".gpr";
114 -- The standard config and user project file name extensions. They are not
115 -- constants, because Canonical_Case_File_Name is called on these variables
116 -- in the body of Prj.
118 function Empty_File
return File_Name_Type
;
119 function Empty_String
return Name_Id
;
120 -- Return the id for an empty string ""
122 type Path_Information
is record
123 Name
: Path_Name_Type
:= No_Path
;
124 Display_Name
: Path_Name_Type
:= No_Path
;
126 -- Directory names always end with a directory separator
128 No_Path_Information
: constant Path_Information
:= (No_Path
, No_Path
);
131 type Project_Id
is access all Project_Data
;
132 No_Project
: constant Project_Id
:= null;
133 -- Id of a Project File
135 type String_List_Id
is new Nat
;
136 Nil_String
: constant String_List_Id
:= 0;
137 type String_Element
is record
138 Value
: Name_Id
:= No_Name
;
140 Display_Value
: Name_Id
:= No_Name
;
141 Location
: Source_Ptr
:= No_Location
;
142 Flag
: Boolean := False;
143 Next
: String_List_Id
:= Nil_String
;
145 -- To hold values for string list variables and array elements.
146 -- Component Flag may be used for various purposes. For source
147 -- directories, it indicates if the directory contains Ada source(s).
149 package String_Element_Table
is new GNAT
.Dynamic_Tables
150 (Table_Component_Type
=> String_Element
,
151 Table_Index_Type
=> String_List_Id
,
152 Table_Low_Bound
=> 1,
153 Table_Initial
=> 200,
154 Table_Increment
=> 100);
155 -- The table for string elements in string lists
157 type Variable_Kind
is (Undefined
, List
, Single
);
158 -- Different kinds of variables
160 subtype Defined_Variable_Kind
is Variable_Kind
range List
.. Single
;
161 -- The defined kinds of variables
163 Ignored
: constant Variable_Kind
;
164 -- Used to indicate that a package declaration must be ignored
165 -- while processing the project tree (unknown package name).
167 type Variable_Value
(Kind
: Variable_Kind
:= Undefined
) is record
168 Project
: Project_Id
:= No_Project
;
169 Location
: Source_Ptr
:= No_Location
;
170 Default
: Boolean := False;
175 Values
: String_List_Id
:= Nil_String
;
177 Value
: Name_Id
:= No_Name
;
181 -- Values for variables and array elements. Default is True if the
182 -- current value is the default one for the variable.
184 Nil_Variable_Value
: constant Variable_Value
;
185 -- Value of a non existing variable or array element
187 type Variable_Id
is new Nat
;
188 No_Variable
: constant Variable_Id
:= 0;
189 type Variable
is record
190 Next
: Variable_Id
:= No_Variable
;
192 Value
: Variable_Value
;
194 -- To hold the list of variables in a project file and in packages
196 package Variable_Element_Table
is new GNAT
.Dynamic_Tables
197 (Table_Component_Type
=> Variable
,
198 Table_Index_Type
=> Variable_Id
,
199 Table_Low_Bound
=> 1,
200 Table_Initial
=> 200,
201 Table_Increment
=> 100);
202 -- The table of variable in list of variables
204 type Array_Element_Id
is new Nat
;
205 No_Array_Element
: constant Array_Element_Id
:= 0;
206 type Array_Element
is record
208 Restricted
: Boolean := False;
209 Src_Index
: Int
:= 0;
210 Index_Case_Sensitive
: Boolean := True;
211 Value
: Variable_Value
;
212 Next
: Array_Element_Id
:= No_Array_Element
;
214 -- Each Array_Element represents an array element and is linked (Next)
215 -- to the next array element, if any, in the array.
217 package Array_Element_Table
is new GNAT
.Dynamic_Tables
218 (Table_Component_Type
=> Array_Element
,
219 Table_Index_Type
=> Array_Element_Id
,
220 Table_Low_Bound
=> 1,
221 Table_Initial
=> 200,
222 Table_Increment
=> 100);
223 -- The table that contains all array elements
225 type Array_Id
is new Nat
;
226 No_Array
: constant Array_Id
:= 0;
227 type Array_Data
is record
228 Name
: Name_Id
:= No_Name
;
229 Location
: Source_Ptr
:= No_Location
;
230 Value
: Array_Element_Id
:= No_Array_Element
;
231 Next
: Array_Id
:= No_Array
;
233 -- Each Array_Data value represents an array.
234 -- Value is the id of the first element.
235 -- Next is the id of the next array in the project file or package.
237 package Array_Table
is new GNAT
.Dynamic_Tables
238 (Table_Component_Type
=> Array_Data
,
239 Table_Index_Type
=> Array_Id
,
240 Table_Low_Bound
=> 1,
241 Table_Initial
=> 200,
242 Table_Increment
=> 100);
243 -- The table that contains all arrays
245 type Package_Id
is new Nat
;
246 No_Package
: constant Package_Id
:= 0;
247 type Declarations
is record
248 Variables
: Variable_Id
:= No_Variable
;
249 Attributes
: Variable_Id
:= No_Variable
;
250 Arrays
: Array_Id
:= No_Array
;
251 Packages
: Package_Id
:= No_Package
;
253 -- Contains the declarations (variables, single and array attributes,
254 -- packages) for a project or a package in a project.
256 No_Declarations
: constant Declarations
:=
257 (Variables
=> No_Variable
,
258 Attributes
=> No_Variable
,
260 Packages
=> No_Package
);
261 -- Default value of Declarations: indicates that there is no declarations
263 type Package_Element
is record
264 Name
: Name_Id
:= No_Name
;
265 Decl
: Declarations
:= No_Declarations
;
266 Parent
: Package_Id
:= No_Package
;
267 Next
: Package_Id
:= No_Package
;
269 -- A package (includes declarations that may include other packages)
271 package Package_Table
is new GNAT
.Dynamic_Tables
272 (Table_Component_Type
=> Package_Element
,
273 Table_Index_Type
=> Package_Id
,
274 Table_Low_Bound
=> 1,
275 Table_Initial
=> 100,
276 Table_Increment
=> 100);
277 -- The table that contains all packages
280 type Language_Ptr
is access all Language_Data
;
281 -- Index of language data
283 No_Language_Index
: constant Language_Ptr
:= null;
284 -- Constant indicating that there is no language data
286 function Get_Language_From_Name
287 (Project
: Project_Id
;
288 Name
: String) return Language_Ptr
;
289 -- Get a language from a project. This might return null if no such
290 -- language exists in the project
292 Max_Header_Num
: constant := 6150;
293 type Header_Num
is range 0 .. Max_Header_Num
;
294 -- Size for hash table below. The upper bound is an arbitrary value, the
295 -- value here was chosen after testing to determine a good compromise
296 -- between speed of access and memory usage.
298 function Hash
(Name
: Name_Id
) return Header_Num
;
299 function Hash
(Name
: File_Name_Type
) return Header_Num
;
300 function Hash
(Name
: Path_Name_Type
) return Header_Num
;
301 function Hash
(Project
: Project_Id
) return Header_Num
;
302 -- Used for computing hash values for names put into hash tables
304 type Language_Kind
is (File_Based
, Unit_Based
);
305 -- Type for the kind of language. All languages are file based, except Ada
306 -- which is unit based.
308 -- Type of dependency to be checked
310 type Dependency_File_Kind
is
312 -- There is no dependency file, the source must always be recompiled
315 -- The dependency file is a Makefile fragment indicating all the files
316 -- the source depends on. If the object file or the dependency file is
317 -- more recent than any of these files, the source must be recompiled.
320 -- The dependency file is an ALI file and the source must be recompiled
321 -- if the object or ALI file is more recent than any of the sources
322 -- listed in the D lines.
325 -- The dependency file is an ALI file and the source must be recompiled
326 -- if the object or ALI file is more recent than any source in the full
329 Makefile_Dependency_Suffix
: constant String := ".d";
330 ALI_Dependency_Suffix
: constant String := ".ali";
331 Switches_Dependency_Suffix
: constant String := ".cswi";
333 Binder_Exchange_Suffix
: constant String := ".bexch";
334 -- Suffix for binder exchange files
336 Library_Exchange_Suffix
: constant String := ".lexch";
337 -- Suffix for library exchange files
339 type Name_List_Index
is new Nat
;
340 No_Name_List
: constant Name_List_Index
:= 0;
342 type Name_Node
is record
343 Name
: Name_Id
:= No_Name
;
344 Next
: Name_List_Index
:= No_Name_List
;
347 package Name_List_Table
is new GNAT
.Dynamic_Tables
348 (Table_Component_Type
=> Name_Node
,
349 Table_Index_Type
=> Name_List_Index
,
350 Table_Low_Bound
=> 1,
352 Table_Increment
=> 100);
353 -- The table for lists of names
356 (Table
: Name_List_Table
.Instance
;
357 List
: Name_List_Index
) return Natural;
358 -- Return the number of elements in specified list
360 type Number_List_Index
is new Nat
;
361 No_Number_List
: constant Number_List_Index
:= 0;
363 type Number_Node
is record
364 Number
: Natural := 0;
365 Next
: Number_List_Index
:= No_Number_List
;
368 package Number_List_Table
is new GNAT
.Dynamic_Tables
369 (Table_Component_Type
=> Number_Node
,
370 Table_Index_Type
=> Number_List_Index
,
371 Table_Low_Bound
=> 1,
373 Table_Increment
=> 100);
374 -- The table for lists of numbers
376 package Mapping_Files_Htable
is new Simple_HTable
377 (Header_Num
=> Header_Num
,
378 Element
=> Path_Name_Type
,
379 No_Element
=> No_Path
,
380 Key
=> Path_Name_Type
,
383 -- A hash table to store the mapping files that are not used
385 -- The following record ???
387 type Lang_Naming_Data
is record
388 Dot_Replacement
: File_Name_Type
:= No_File
;
389 -- The string to replace '.' in the source file name (for Ada)
391 Casing
: Casing_Type
:= All_Lower_Case
;
392 -- The casing of the source file name (for Ada)
394 Separate_Suffix
: File_Name_Type
:= No_File
;
395 -- String to append to unit name for source file name of an Ada subunit
397 Spec_Suffix
: File_Name_Type
:= No_File
;
398 -- The string to append to the unit name for the
399 -- source file name of a spec.
401 Body_Suffix
: File_Name_Type
:= No_File
;
402 -- The string to append to the unit name for the
403 -- source file name of a body.
406 No_Lang_Naming_Data
: constant Lang_Naming_Data
:=
407 (Dot_Replacement
=> No_File
,
408 Casing
=> All_Lower_Case
,
409 Separate_Suffix
=> No_File
,
410 Spec_Suffix
=> No_File
,
411 Body_Suffix
=> No_File
);
413 function Is_Standard_GNAT_Naming
(Naming
: Lang_Naming_Data
) return Boolean;
414 -- True if the naming scheme is GNAT's default naming scheme. This
415 -- is to take into account shortened names like "Ada." (a-), "System." (s-)
419 type Source_Id
is access all Source_Data
;
421 function Is_Compilable
(Source
: Source_Id
) return Boolean;
422 pragma Inline
(Is_Compilable
);
423 -- Return True if we know how to compile Source (i.e. if a compiler is
424 -- defined). This doesn't indicate whether the source should be compiled.
426 function Object_To_Global_Archive
(Source
: Source_Id
) return Boolean;
427 pragma Inline
(Object_To_Global_Archive
);
428 -- Return True if the object file should be put in the global archive.
429 -- This is for Ada, when only the closure of a main needs to be
432 function Other_Part
(Source
: Source_Id
) return Source_Id
;
433 pragma Inline
(Other_Part
);
434 -- Source ID for the other part, if any: for a spec, indicates its body;
435 -- for a body, indicates its spec.
437 No_Source
: constant Source_Id
:= null;
439 type Path_Syntax_Kind
is
443 -- Host specific syntax, for example on VMS (the default)
445 -- The following record describes the configuration of a language
447 type Language_Config
is record
448 Kind
: Language_Kind
:= File_Based
;
449 -- Kind of language. Most languages are file based. A few, such as Ada,
452 Naming_Data
: Lang_Naming_Data
;
453 -- The naming data for the languages (prefixes, etc.)
455 Include_Compatible_Languages
: Name_List_Index
:= No_Name_List
;
456 -- List of languages that are "include compatible" with this language. A
457 -- language B (for example "C") is "include compatible" with a language
458 -- A (for example "C++") if it is expected that sources of language A
459 -- may "include" header files from language B.
461 Compiler_Driver
: File_Name_Type
:= No_File
;
462 -- The name of the executable for the compiler of the language
464 Compiler_Driver_Path
: String_Access
:= null;
465 -- The path name of the executable for the compiler of the language
467 Compiler_Leading_Required_Switches
: Name_List_Index
:= No_Name_List
;
468 -- The list of initial switches that are required as a minimum to invoke
469 -- the compiler driver.
471 Compiler_Trailing_Required_Switches
: Name_List_Index
:= No_Name_List
;
472 -- The list of final switches that are required as a minimum to invoke
473 -- the compiler driver.
475 Multi_Unit_Switches
: Name_List_Index
:= No_Name_List
;
476 -- The switch(es) to indicate the index of a unit in a multi-source file
478 Multi_Unit_Object_Separator
: Character := ' ';
479 -- The string separating the base name of a source from the index of the
480 -- unit in a multi-source file, in the object file name.
482 Path_Syntax
: Path_Syntax_Kind
:= Host
;
483 -- Value may be Canonical (Unix style) or Host (host syntax, for example
484 -- on VMS for DEC C).
486 Source_File_Switches
: Name_List_Index
:= No_Name_List
;
487 -- Optional switches to be put before the source file. The source file
488 -- path name is appended to the last switch in the list.
489 -- Example: ("-i", "");
491 Object_File_Suffix
: Name_Id
:= No_Name
;
492 -- Optional alternate object file suffix
494 Object_File_Switches
: Name_List_Index
:= No_Name_List
;
495 -- Optional object file switches. When this is defined, the switches
496 -- are used to specify the object file. The object file name is appended
497 -- to the last switch in the list. Example: ("-o", "").
499 Object_Path_Switches
: Name_List_Index
:= No_Name_List
;
500 -- List of switches to specify to the compiler the path name of a
501 -- temporary file containing the list of object directories in the
504 Compilation_PIC_Option
: Name_List_Index
:= No_Name_List
;
505 -- The option(s) to compile a source in Position Independent Code for
506 -- shared libraries. Specified in the configuration. When not specified,
507 -- there is no need for such switch.
509 Object_Generated
: Boolean := True;
510 -- False in no object file is generated
512 Objects_Linked
: Boolean := True;
513 -- False if object files are not use to link executables and build
516 Runtime_Library_Dir
: Name_Id
:= No_Name
;
517 -- Path name of the runtime library directory, if any
519 Runtime_Source_Dir
: Name_Id
:= No_Name
;
520 -- Path name of the runtime source directory, if any
522 Mapping_File_Switches
: Name_List_Index
:= No_Name_List
;
523 -- The option(s) to provide a mapping file to the compiler. Specified in
524 -- the configuration. When value is No_Name_List, there is no mapping
527 Mapping_Spec_Suffix
: File_Name_Type
:= No_File
;
528 -- Placeholder representing the spec suffix in a mapping file
530 Mapping_Body_Suffix
: File_Name_Type
:= No_File
;
531 -- Placeholder representing the body suffix in a mapping file
533 Config_File_Switches
: Name_List_Index
:= No_Name_List
;
534 -- The option(s) to provide a config file to the compiler. Specified in
535 -- the configuration. If value is No_Name_List there is no config file.
537 Dependency_Kind
: Dependency_File_Kind
:= None
;
538 -- The kind of dependency to be checked: none, Makefile fragment or
539 -- ALI file (for Ada).
541 Dependency_Option
: Name_List_Index
:= No_Name_List
;
542 -- The option(s) to be used to create the dependency file. When value is
543 -- No_Name_List, there is not such option(s).
545 Compute_Dependency
: Name_List_Index
:= No_Name_List
;
546 -- Hold the value of attribute Dependency_Driver, if declared for the
549 Include_Option
: Name_List_Index
:= No_Name_List
;
550 -- Hold the value of attribute Include_Switches, if declared for the
553 Include_Path
: Name_Id
:= No_Name
;
554 -- Name of environment variable declared by attribute Include_Path for
557 Include_Path_File
: Name_Id
:= No_Name
;
558 -- Name of environment variable declared by attribute Include_Path_File
561 Objects_Path
: Name_Id
:= No_Name
;
562 -- Name of environment variable declared by attribute Objects_Path for
565 Objects_Path_File
: Name_Id
:= No_Name
;
566 -- Name of environment variable declared by attribute Objects_Path_File
569 Config_Body
: Name_Id
:= No_Name
;
570 -- The template for a pragma Source_File_Name(_Project) for a specific
571 -- file name of a body.
573 Config_Body_Index
: Name_Id
:= No_Name
;
574 -- The template for a pragma Source_File_Name(_Project) for a specific
575 -- file name of a body in a multi-source file.
577 Config_Body_Pattern
: Name_Id
:= No_Name
;
578 -- The template for a pragma Source_File_Name(_Project) for a naming
581 Config_Spec
: Name_Id
:= No_Name
;
582 -- The template for a pragma Source_File_Name(_Project) for a specific
583 -- file name of a spec.
585 Config_Spec_Index
: Name_Id
:= No_Name
;
586 -- The template for a pragma Source_File_Name(_Project) for a specific
587 -- file name of a spec in a multi-source file.
589 Config_Spec_Pattern
: Name_Id
:= No_Name
;
590 -- The template for a pragma Source_File_Name(_Project) for a naming
593 Config_File_Unique
: Boolean := False;
594 -- Indicate if the config file specified to the compiler needs to be
595 -- unique. If it is unique, then all config files are concatenated into
596 -- a temp config file.
598 Binder_Driver
: File_Name_Type
:= No_File
;
599 -- The name of the binder driver for the language, if any
601 Binder_Driver_Path
: Path_Name_Type
:= No_Path
;
602 -- The path name of the binder driver
604 Binder_Required_Switches
: Name_List_Index
:= No_Name_List
;
605 -- Hold the value of attribute Binder'Required_Switches for the language
607 Binder_Prefix
: Name_Id
:= No_Name
;
608 -- Hold the value of attribute Binder'Prefix for the language
610 Toolchain_Version
: Name_Id
:= No_Name
;
611 -- Hold the value of attribute Toolchain_Version for the language
613 Toolchain_Description
: Name_Id
:= No_Name
;
614 -- Hold the value of attribute Toolchain_Description for the language
616 Clean_Object_Artifacts
: Name_List_Index
:= No_Name_List
;
617 -- List of object artifact extensions to be deleted by gprclean
619 Clean_Source_Artifacts
: Name_List_Index
:= No_Name_List
;
620 -- List of source artifact extensions to be deleted by gprclean
624 No_Language_Config
: constant Language_Config
:=
626 Naming_Data
=> No_Lang_Naming_Data
,
627 Include_Compatible_Languages
=> No_Name_List
,
628 Compiler_Driver
=> No_File
,
629 Compiler_Driver_Path
=> null,
630 Compiler_Leading_Required_Switches
632 Compiler_Trailing_Required_Switches
634 Multi_Unit_Switches
=> No_Name_List
,
635 Multi_Unit_Object_Separator
=> ' ',
636 Path_Syntax
=> Canonical
,
637 Source_File_Switches
=> No_Name_List
,
638 Object_File_Suffix
=> No_Name
,
639 Object_File_Switches
=> No_Name_List
,
640 Object_Path_Switches
=> No_Name_List
,
641 Compilation_PIC_Option
=> No_Name_List
,
642 Object_Generated
=> True,
643 Objects_Linked
=> True,
644 Runtime_Library_Dir
=> No_Name
,
645 Runtime_Source_Dir
=> No_Name
,
646 Mapping_File_Switches
=> No_Name_List
,
647 Mapping_Spec_Suffix
=> No_File
,
648 Mapping_Body_Suffix
=> No_File
,
649 Config_File_Switches
=> No_Name_List
,
650 Dependency_Kind
=> None
,
651 Dependency_Option
=> No_Name_List
,
652 Compute_Dependency
=> No_Name_List
,
653 Include_Option
=> No_Name_List
,
654 Include_Path
=> No_Name
,
655 Include_Path_File
=> No_Name
,
656 Objects_Path
=> No_Name
,
657 Objects_Path_File
=> No_Name
,
658 Config_Body
=> No_Name
,
659 Config_Body_Index
=> No_Name
,
660 Config_Body_Pattern
=> No_Name
,
661 Config_Spec
=> No_Name
,
662 Config_Spec_Index
=> No_Name
,
663 Config_Spec_Pattern
=> No_Name
,
664 Config_File_Unique
=> False,
665 Binder_Driver
=> No_File
,
666 Binder_Driver_Path
=> No_Path
,
667 Binder_Required_Switches
=> No_Name_List
,
668 Binder_Prefix
=> No_Name
,
669 Toolchain_Version
=> No_Name
,
670 Toolchain_Description
=> No_Name
,
671 Clean_Object_Artifacts
=> No_Name_List
,
672 Clean_Source_Artifacts
=> No_Name_List
);
674 -- The following record ???
676 type Language_Data
is record
677 Name
: Name_Id
:= No_Name
;
678 Display_Name
: Name_Id
:= No_Name
;
679 Config
: Language_Config
:= No_Language_Config
;
680 First_Source
: Source_Id
:= No_Source
;
681 Mapping_Files
: Mapping_Files_Htable
.Instance
:=
682 Mapping_Files_Htable
.Nil
;
683 Next
: Language_Ptr
:= No_Language_Index
;
686 No_Language_Data
: constant Language_Data
:=
688 Display_Name
=> No_Name
,
689 Config
=> No_Language_Config
,
690 First_Source
=> No_Source
,
691 Mapping_Files
=> Mapping_Files_Htable
.Nil
,
692 Next
=> No_Language_Index
);
694 type Language_List_Element
;
695 type Language_List
is access all Language_List_Element
;
696 type Language_List_Element
is record
697 Language
: Language_Ptr
:= No_Language_Index
;
698 Next
: Language_List
;
701 type Source_Kind
is (Spec
, Impl
, Sep
);
702 subtype Spec_Or_Body
is Source_Kind
range Spec
.. Impl
;
704 -- The following declarations declare a structure used to store the Name
705 -- and File and Path names of a unit, with a reference to its GNAT Project
706 -- File(s). Some units might have neither Spec nor Impl when they were
707 -- created for a "separate".
709 type File_Names_Data
is array (Spec_Or_Body
) of Source_Id
;
711 type Unit_Data
is record
712 Name
: Name_Id
:= No_Name
;
713 File_Names
: File_Names_Data
;
716 type Unit_Index
is access all Unit_Data
;
718 No_Unit_Index
: constant Unit_Index
:= null;
719 -- Used to indicate a null entry for no unit
722 type Roots_Access
is access Source_Roots
;
723 type Source_Roots
is record
727 -- A list to store the roots associated with a main unit. These are the
728 -- files that need to linked along with the main (for instance a C file
729 -- corresponding to an Ada file). In general, these are dependencies that
730 -- cannot be computed automatically by the builder.
732 type Naming_Exception_Type
is (No
, Yes
, Inherited
);
734 -- Structure to define source data
736 type Source_Data
is record
737 Initialized
: Boolean := False;
738 -- Set to True when Source_Data is completely initialized
740 Project
: Project_Id
:= No_Project
;
741 -- Project of the source
743 Location
: Source_Ptr
:= No_Location
;
744 -- Location in the project file of the declaration of the source in
747 Source_Dir_Rank
: Natural := 0;
748 -- The rank of the source directory in list declared with attribute
749 -- Source_Dirs. Two source files with the same name cannot appears in
750 -- different directory with the same rank. That can happen when the
751 -- recursive notation <dir>/** is used in attribute Source_Dirs.
753 Language
: Language_Ptr
:= No_Language_Index
;
754 -- Index of the language. This is an index into
755 -- Project_Tree.Languages_Data.
757 In_Interfaces
: Boolean := True;
758 -- False when the source is not included in interfaces, when attribute
759 -- Interfaces is declared.
761 Declared_In_Interfaces
: Boolean := False;
762 -- True when source is declared in attribute Interfaces
764 Alternate_Languages
: Language_List
:= null;
765 -- List of languages a header file may also be, in addition of language
768 Kind
: Source_Kind
:= Spec
;
769 -- Kind of the source: spec, body or subunit
771 Unit
: Unit_Index
:= No_Unit_Index
;
772 -- Name of the unit, if language is unit based. This is only set for
773 -- those files that are part of the compilation set (for instance a
774 -- file in an extended project that is overridden will not have this
778 -- Index of the source in a multi unit source file (the same Source_Data
779 -- is duplicated several times when there are several units in the same
780 -- file). Index is 0 if there is either no unit or a single one, and
781 -- starts at 1 when there are multiple units
783 Compilable
: Yes_No_Unknown
:= Unknown
;
784 -- Updated at the first call to Is_Compilable. Yes if source file is
787 In_The_Queue
: Boolean := False;
788 -- True if the source has been put in the queue
790 Locally_Removed
: Boolean := False;
791 -- True if the source has been "excluded"
793 Suppressed
: Boolean := False;
794 -- True if the source is a locally removed direct source of the project.
795 -- These sources should not be put in the mapping file.
797 Replaced_By
: Source_Id
:= No_Source
;
798 -- Source in an extending project that replaces the current source
800 File
: File_Name_Type
:= No_File
;
801 -- Canonical file name of the source
803 Display_File
: File_Name_Type
:= No_File
;
804 -- File name of the source, for display purposes
806 Path
: Path_Information
:= No_Path_Information
;
807 -- Path name of the source
809 Source_TS
: Time_Stamp_Type
:= Empty_Time_Stamp
;
810 -- Time stamp of the source file
812 Object_Project
: Project_Id
:= No_Project
;
813 -- Project where the object file is. This might be different from
814 -- Project when using extending project files.
816 Object
: File_Name_Type
:= No_File
;
817 -- File name of the object file
819 Current_Object_Path
: Path_Name_Type
:= No_Path
;
820 -- Object path of an existing object file
822 Object_Path
: Path_Name_Type
:= No_Path
;
823 -- Object path of the real object file
825 Object_TS
: Time_Stamp_Type
:= Empty_Time_Stamp
;
826 -- Object file time stamp
828 Dep_Name
: File_Name_Type
:= No_File
;
829 -- Dependency file simple name
831 Current_Dep_Path
: Path_Name_Type
:= No_Path
;
832 -- Path name of an existing dependency file
834 Dep_Path
: Path_Name_Type
:= No_Path
;
835 -- Path name of the real dependency file
837 Dep_TS
: aliased Osint
.File_Attributes
:= Osint
.Unknown_Attributes
;
838 -- Dependency file time stamp
840 Switches
: File_Name_Type
:= No_File
;
841 -- File name of the switches file. For all languages, this is a file
842 -- that ends with the .cswi extension.
844 Switches_Path
: Path_Name_Type
:= No_Path
;
845 -- Path name of the switches file
847 Switches_TS
: Time_Stamp_Type
:= Empty_Time_Stamp
;
848 -- Switches file time stamp
850 Naming_Exception
: Naming_Exception_Type
:= No
;
851 -- True if the source has an exceptional name
853 Duplicate_Unit
: Boolean := False;
854 -- True when a duplicate unit has been reported for this source
856 Next_In_Lang
: Source_Id
:= No_Source
;
857 -- Link to another source of the same language in the same project
859 Next_With_File_Name
: Source_Id
:= No_Source
;
860 -- Link to another source with the same base file name
862 Roots
: Roots_Access
:= null;
863 -- The roots for a main unit
867 No_Source_Data
: constant Source_Data
:=
868 (Initialized
=> False,
869 Project
=> No_Project
,
870 Location
=> No_Location
,
871 Source_Dir_Rank
=> 0,
872 Language
=> No_Language_Index
,
873 In_Interfaces
=> True,
874 Declared_In_Interfaces
=> False,
875 Alternate_Languages
=> null,
877 Unit
=> No_Unit_Index
,
879 Locally_Removed
=> False,
881 Compilable
=> Unknown
,
882 In_The_Queue
=> False,
883 Replaced_By
=> No_Source
,
885 Display_File
=> No_File
,
886 Path
=> No_Path_Information
,
887 Source_TS
=> Empty_Time_Stamp
,
888 Object_Project
=> No_Project
,
890 Current_Object_Path
=> No_Path
,
891 Object_Path
=> No_Path
,
892 Object_TS
=> Empty_Time_Stamp
,
894 Current_Dep_Path
=> No_Path
,
896 Dep_TS
=> Osint
.Unknown_Attributes
,
898 Switches_Path
=> No_Path
,
899 Switches_TS
=> Empty_Time_Stamp
,
900 Naming_Exception
=> No
,
901 Duplicate_Unit
=> False,
902 Next_In_Lang
=> No_Source
,
903 Next_With_File_Name
=> No_Source
,
906 package Source_Files_Htable
is new Simple_HTable
907 (Header_Num
=> Header_Num
,
908 Element
=> Source_Id
,
909 No_Element
=> No_Source
,
910 Key
=> File_Name_Type
,
913 -- Mapping of source file names to source ids
915 package Source_Paths_Htable
is new Simple_HTable
916 (Header_Num
=> Header_Num
,
917 Element
=> Source_Id
,
918 No_Element
=> No_Source
,
919 Key
=> Path_Name_Type
,
922 -- Mapping of source paths to source ids
924 type Lib_Kind
is (Static
, Dynamic
, Relocatable
);
926 type Policy
is (Autonomous
, Compliant
, Controlled
, Restricted
, Direct
);
927 -- Type to specify the symbol policy, when symbol control is supported.
928 -- See full explanation about this type in package Symbols.
929 -- Autonomous: Create a symbol file without considering any reference
930 -- Compliant: Try to be as compatible as possible with an existing ref
931 -- Controlled: Fail if symbols are not the same as those in the reference
932 -- Restricted: Restrict the symbols to those in the symbol file
933 -- Direct: The symbol file is used as is
935 type Symbol_Record
is record
936 Symbol_File
: Path_Name_Type
:= No_Path
;
937 Reference
: Path_Name_Type
:= No_Path
;
938 Symbol_Policy
: Policy
:= Autonomous
;
940 -- Type to keep the symbol data to be used when building a shared library
942 No_Symbols
: constant Symbol_Record
:=
943 (Symbol_File
=> No_Path
,
944 Reference
=> No_Path
,
945 Symbol_Policy
=> Autonomous
);
946 -- The default value of the symbol data
948 function Image
(The_Casing
: Casing_Type
) return String;
949 -- Similar to 'Image (but avoid use of this attribute in compiler)
951 function Value
(Image
: String) return Casing_Type
;
952 -- Similar to 'Value (but avoid use of this attribute in compiler)
953 -- Raises Constraint_Error if not a Casing_Type image.
955 -- The following record contains data for a naming scheme
957 function Get_Object_Directory
958 (Project
: Project_Id
;
959 Including_Libraries
: Boolean;
960 Only_If_Ada
: Boolean := False) return Path_Name_Type
;
961 -- Return the object directory to use for the project. This depends on
962 -- whether we have a library project or a standard project. This function
963 -- might return No_Name when no directory applies.
964 -- If we have a library project file and Including_Libraries is True then
965 -- the library dir is returned instead of the object dir.
966 -- If Only_If_Ada is True, then No_Name will be returned when the project
967 -- doesn't Ada sources.
969 procedure Compute_All_Imported_Projects
970 (Root_Project
: Project_Id
;
971 Tree
: Project_Tree_Ref
);
972 -- For all projects in the tree, compute the list of the projects imported
973 -- directly or indirectly by project Root_Project. The result is stored in
974 -- Project.All_Imported_Projects for each project
976 function Ultimate_Extending_Project_Of
977 (Proj
: Project_Id
) return Project_Id
;
978 -- Returns the ultimate extending project of project Proj. If project Proj
979 -- is not extended, returns Proj.
981 type Project_List_Element
;
982 type Project_List
is access all Project_List_Element
;
983 type Project_List_Element
is record
984 Project
: Project_Id
:= No_Project
;
985 From_Encapsulated_Lib
: Boolean := False;
986 Next
: Project_List
:= null;
988 -- A list of projects
991 (List
: in out Project_List
;
992 Free_Project
: Boolean);
993 -- Free the list of projects, if Free_Project, each project is also freed
995 type Response_File_Format
is
1004 -- The format of the different response files
1006 type Project_Configuration
is record
1007 Target
: Name_Id
:= No_Name
;
1008 -- The target of the configuration, when specified
1010 Run_Path_Option
: Name_List_Index
:= No_Name_List
;
1011 -- The option to use when linking to specify the path where to look for
1014 Run_Path_Origin
: Name_Id
:= No_Name
;
1015 -- Specify the string (such as "$ORIGIN") to indicate paths relative to
1016 -- the directory of the executable in the run path option.
1018 Library_Install_Name_Option
: Name_Id
:= No_Name
;
1019 -- When this is not an empty list, this option, followed by the single
1020 -- name of the shared library file is used when linking a shared
1023 Separate_Run_Path_Options
: Boolean := False;
1024 -- True if each directory needs to be specified in a separate run path
1027 Executable_Suffix
: Name_Id
:= No_Name
;
1028 -- The suffix of executables, when specified in the configuration or in
1029 -- package Builder of the main project. When this is not specified, the
1030 -- executable suffix is the default for the platform.
1034 Linker
: Path_Name_Type
:= No_Path
;
1035 -- Path name of the linker driver. Specified in the configuration or in
1036 -- the package Builder of the main project.
1038 Map_File_Option
: Name_Id
:= No_Name
;
1039 -- Option to use when invoking the linker to build a map file
1041 Trailing_Linker_Required_Switches
: Name_List_Index
:= No_Name_List
;
1042 -- The minimum options for the linker driver. Specified in the
1045 Linker_Executable_Option
: Name_List_Index
:= No_Name_List
;
1046 -- The option(s) to indicate the name of the executable in the linker
1047 -- command. Specified in the configuration. When not specified, default
1048 -- to -o <executable name>.
1050 Linker_Lib_Dir_Option
: Name_Id
:= No_Name
;
1051 -- The option to specify where to find a library for linking. Specified
1052 -- in the configuration. When not specified, defaults to "-L".
1054 Linker_Lib_Name_Option
: Name_Id
:= No_Name
;
1055 -- The option to specify the name of a library for linking. Specified in
1056 -- the configuration. When not specified, defaults to "-l".
1058 Max_Command_Line_Length
: Natural := 0;
1059 -- When positive and when Resp_File_Format (see below) is not None,
1060 -- if the command line for the invocation of the linker would be greater
1061 -- than this value, a response file is used to invoke the linker.
1063 Resp_File_Format
: Response_File_Format
:= None
;
1064 -- The format of a response file, when linking with a response file is
1067 Resp_File_Options
: Name_List_Index
:= No_Name_List
;
1068 -- The switches, if any, that precede the path name of the response
1069 -- file in the invocation of the linker.
1073 Library_Builder
: Path_Name_Type
:= No_Path
;
1074 -- The executable to build library (specified in the configuration)
1076 Lib_Support
: Library_Support
:= None
;
1077 -- The level of library support. Specified in the configuration. Support
1078 -- is none, static libraries only or both static and shared libraries.
1080 Lib_Encapsulated_Supported
: Boolean := False;
1081 -- True when building fully standalone libraries supported on the target
1083 Archive_Builder
: Name_List_Index
:= No_Name_List
;
1084 -- The name of the executable to build archives, with the minimum
1085 -- switches. Specified in the configuration.
1087 Archive_Builder_Append_Option
: Name_List_Index
:= No_Name_List
;
1088 -- The options to append object files to an archive
1090 Archive_Indexer
: Name_List_Index
:= No_Name_List
;
1091 -- The name of the executable to index archives, with the minimum
1092 -- switches. Specified in the configuration.
1094 Archive_Suffix
: File_Name_Type
:= No_File
;
1095 -- The suffix of archives. Specified in the configuration. When not
1096 -- specified, defaults to ".a".
1098 Lib_Partial_Linker
: Name_List_Index
:= No_Name_List
;
1102 Shared_Lib_Driver
: File_Name_Type
:= No_File
;
1103 -- The driver to link shared libraries. Set with attribute Library_GCC.
1106 Shared_Lib_Prefix
: File_Name_Type
:= No_File
;
1107 -- Part of a shared library file name that precedes the name of the
1108 -- library. Specified in the configuration. When not specified, defaults
1111 Shared_Lib_Suffix
: File_Name_Type
:= No_File
;
1112 -- Suffix of shared libraries, after the library name in the shared
1113 -- library name. Specified in the configuration. When not specified,
1114 -- default to ".so".
1116 Shared_Lib_Min_Options
: Name_List_Index
:= No_Name_List
;
1117 -- The minimum options to use when building a shared library
1119 Lib_Version_Options
: Name_List_Index
:= No_Name_List
;
1120 -- The options to use to specify a library version
1122 Symbolic_Link_Supported
: Boolean := False;
1123 -- True if the platform supports symbolic link files
1125 Lib_Maj_Min_Id_Supported
: Boolean := False;
1126 -- True if platform supports library major and minor options, such as
1127 -- libname.so -> libname.so.2 -> libname.so.2.4
1129 Auto_Init_Supported
: Boolean := False;
1130 -- True if automatic initialisation is supported for shared stand-alone
1134 Default_Project_Config
: constant Project_Configuration
:=
1136 Run_Path_Option
=> No_Name_List
,
1137 Run_Path_Origin
=> No_Name
,
1138 Library_Install_Name_Option
=> No_Name
,
1139 Separate_Run_Path_Options
=> False,
1140 Executable_Suffix
=> No_Name
,
1142 Map_File_Option
=> No_Name
,
1143 Trailing_Linker_Required_Switches
=>
1145 Linker_Executable_Option
=> No_Name_List
,
1146 Linker_Lib_Dir_Option
=> No_Name
,
1147 Linker_Lib_Name_Option
=> No_Name
,
1148 Library_Builder
=> No_Path
,
1149 Max_Command_Line_Length
=> 0,
1150 Resp_File_Format
=> None
,
1151 Resp_File_Options
=> No_Name_List
,
1152 Lib_Support
=> None
,
1153 Lib_Encapsulated_Supported
=> False,
1154 Archive_Builder
=> No_Name_List
,
1155 Archive_Builder_Append_Option
=> No_Name_List
,
1156 Archive_Indexer
=> No_Name_List
,
1157 Archive_Suffix
=> No_File
,
1158 Lib_Partial_Linker
=> No_Name_List
,
1159 Shared_Lib_Driver
=> No_File
,
1160 Shared_Lib_Prefix
=> No_File
,
1161 Shared_Lib_Suffix
=> No_File
,
1162 Shared_Lib_Min_Options
=> No_Name_List
,
1163 Lib_Version_Options
=> No_Name_List
,
1164 Symbolic_Link_Supported
=> False,
1165 Lib_Maj_Min_Id_Supported
=> False,
1166 Auto_Init_Supported
=> False);
1168 -------------------------
1169 -- Aggregated projects --
1170 -------------------------
1172 type Aggregated_Project
;
1173 type Aggregated_Project_List
is access all Aggregated_Project
;
1174 type Aggregated_Project
is record
1175 Path
: Path_Name_Type
;
1176 Tree
: Project_Tree_Ref
;
1177 Project
: Project_Id
;
1178 Next
: Aggregated_Project_List
;
1181 procedure Free
(List
: in out Aggregated_Project_List
);
1182 -- Free the memory used for List
1184 procedure Add_Aggregated_Project
1185 (Project
: Project_Id
;
1186 Path
: Path_Name_Type
);
1187 -- Add a new aggregated project in Project.
1188 -- The aggregated project has not been processed yet. This procedure should
1189 -- the called while processing the aggregate project, and as a result
1190 -- Prj.Proc.Process will then automatically process the aggregated projects
1196 -- The following record describes a project file representation
1198 pragma Warnings
(Off
);
1202 -- The following clash with Standard is OK, and justified by the context
1203 -- which really wants to use the same set of qualifiers.
1208 pragma Warnings
(On
);
1210 type Project_Data
(Qualifier
: Project_Qualifier
:= Unspecified
) is record
1216 Name
: Name_Id
:= No_Name
;
1217 -- The name of the project
1219 Display_Name
: Name_Id
:= No_Name
;
1220 -- The name of the project with the spelling of its declaration
1222 Externally_Built
: Boolean := False;
1223 -- True if the project is externally built. In such case, the Project
1224 -- Manager will not modify anything in this project.
1226 Config
: Project_Configuration
;
1228 Path
: Path_Information
:= No_Path_Information
;
1229 -- The path name of the project file. This include base name of the
1232 Virtual
: Boolean := False;
1233 -- True for virtual extending projects
1235 Location
: Source_Ptr
:= No_Location
;
1236 -- The location in the project file source of the project name that
1237 -- immediately follows the reserved word "project".
1243 Languages
: Language_Ptr
:= No_Language_Index
;
1244 -- First index of the language data in the project.
1245 -- This is an index into the project_tree_data.languages_data.
1246 -- Traversing the list gives access to all the languages supported by
1253 Mains
: String_List_Id
:= Nil_String
;
1254 -- List of mains specified by attribute Main
1256 Extends
: Project_Id
:= No_Project
;
1257 -- The reference of the project file, if any, that this project file
1260 Extended_By
: Project_Id
:= No_Project
;
1261 -- The reference of the project file, if any, that extends this project
1264 Decl
: Declarations
:= No_Declarations
;
1265 -- The declarations (variables, attributes and packages) of this project
1268 Imported_Projects
: Project_List
:= null;
1269 -- The list of all directly imported projects, if any
1271 All_Imported_Projects
: Project_List
:= null;
1272 -- The list of all projects imported directly or indirectly, if any.
1273 -- This does not include the project itself.
1279 Directory
: Path_Information
:= No_Path_Information
;
1280 -- Path name of the directory where the project file resides
1282 Object_Directory
: Path_Information
:= No_Path_Information
;
1283 -- The path name of the object directory of this project file
1285 Exec_Directory
: Path_Information
:= No_Path_Information
;
1286 -- The path name of the exec directory of this project file. Default is
1287 -- equal to Object_Directory.
1289 Object_Path_File
: Path_Name_Type
:= No_Path
;
1290 -- Store the name of the temporary file that contains the list of object
1291 -- directories, when attribute Object_Path_Switches is declared.
1297 Library
: Boolean := False;
1298 -- True if this is a library project
1300 Library_Name
: Name_Id
:= No_Name
;
1301 -- If a library project, name of the library
1303 Library_Kind
: Lib_Kind
:= Static
;
1304 -- If a library project, kind of library
1306 Library_Dir
: Path_Information
:= No_Path_Information
;
1307 -- If a library project, path name of the directory where the library
1310 Library_TS
: Time_Stamp_Type
:= Empty_Time_Stamp
;
1311 -- The timestamp of a library file in a library project
1313 Library_Src_Dir
: Path_Information
:= No_Path_Information
;
1314 -- If a Stand-Alone Library project, path name of the directory where
1315 -- the sources of the interfaces of the library are copied. By default,
1316 -- if attribute Library_Src_Dir is not specified, sources of the
1317 -- interfaces are not copied anywhere.
1319 Library_ALI_Dir
: Path_Information
:= No_Path_Information
;
1320 -- In a library project, path name of the directory where the ALI files
1321 -- are copied. If attribute Library_ALI_Dir is not specified, ALI files
1322 -- are copied in the Library_Dir.
1324 Lib_Internal_Name
: Name_Id
:= No_Name
;
1325 -- If a library project, internal name store inside the library
1327 Standalone_Library
: Standalone
:= No
;
1328 -- Indicate that this is a Standalone Library Project File
1330 Lib_Interface_ALIs
: String_List_Id
:= Nil_String
;
1331 -- For Standalone Library Project Files, indicate the list of Interface
1334 Lib_Auto_Init
: Boolean := False;
1335 -- For non static Stand-Alone Library Project Files, indicate if
1336 -- the library initialisation should be automatic.
1338 Symbol_Data
: Symbol_Record
:= No_Symbols
;
1339 -- Symbol file name, reference symbol file name, symbol policy
1341 Need_To_Build_Lib
: Boolean := False;
1342 -- Indicates that the library of a Library Project needs to be built or
1348 -- The sources for all languages including Ada are accessible through
1349 -- the Source_Iterator type
1351 Interfaces_Defined
: Boolean := False;
1352 -- True if attribute Interfaces is declared for the project or any
1353 -- project it extends.
1355 Include_Path_File
: Path_Name_Type
:= No_Path
;
1356 -- The path name of the of the source search directory file.
1357 -- This is only used by gnatmake
1359 Source_Dirs
: String_List_Id
:= Nil_String
;
1360 -- The list of all the source directories
1362 Source_Dir_Ranks
: Number_List_Index
:= No_Number_List
;
1364 Ada_Include_Path
: String_Access
:= null;
1365 -- The cached value of source search path for this project file. Set by
1366 -- the first call to Prj.Env.Ada_Include_Path for the project. Do not
1367 -- use this field directly outside of the project manager, use
1368 -- Prj.Env.Ada_Include_Path instead.
1370 Has_Multi_Unit_Sources
: Boolean := False;
1371 -- Whether there is at least one source file containing multiple units
1377 Ada_Objects_Path
: String_Access
:= null;
1378 -- The cached value of ADA_OBJECTS_PATH for this project file. Do not
1379 -- use this field directly outside of the compiler, use
1380 -- Prj.Env.Ada_Objects_Path instead.
1382 Libgnarl_Needed
: Yes_No_Unknown
:= Unknown
;
1383 -- Set to True when libgnarl is needed to link
1385 Objects_Path
: String_Access
:= null;
1386 -- The cached value of the object dir path, used during the binding
1387 -- phase of gprbuild.
1389 Objects_Path_File_With_Libs
: Path_Name_Type
:= No_Path
;
1390 -- The cached value of the object path temp file (including library
1391 -- dirs) for this project file.
1393 Objects_Path_File_Without_Libs
: Path_Name_Type
:= No_Path
;
1394 -- The cached value of the object path temp file (excluding library
1395 -- dirs) for this project file.
1397 Config_File_Name
: Path_Name_Type
:= No_Path
;
1398 -- The path name of the configuration pragmas file, if any
1400 Config_File_Temp
: Boolean := False;
1401 -- An indication that the configuration pragmas file is a temporary file
1402 -- that must be deleted at the end.
1404 Config_Checked
: Boolean := False;
1405 -- A flag to avoid checking repetitively the configuration pragmas file
1407 Depth
: Natural := 0;
1408 -- The maximum depth of a project in the project graph. Depth of main
1411 Unkept_Comments
: Boolean := False;
1412 -- True if there are comments in the project sources that cannot be kept
1413 -- in the project tree.
1415 -----------------------------
1416 -- Qualifier-Specific data --
1417 -----------------------------
1419 -- The following fields are only valid for specific types of projects
1422 when Aggregate | Aggregate_Library
=>
1423 Aggregated_Projects
: Aggregated_Project_List
:= null;
1424 -- List of aggregated projects (which could themselves be
1425 -- aggregate projects).
1432 function Empty_Project
(Qualifier
: Project_Qualifier
) return Project_Data
;
1433 -- Return the representation of an empty project
1435 function Is_Extending
1436 (Extending
: Project_Id
;
1437 Extended
: Project_Id
) return Boolean;
1438 -- Return True if Extending is extending the Extended project
1441 (Extending
: Project_Id
;
1442 Extended
: Project_Id
) return Boolean renames Is_Extending
;
1444 function Has_Ada_Sources
(Data
: Project_Id
) return Boolean;
1445 -- Return True if the project has Ada sources
1447 Project_Error
: exception;
1448 -- Raised by some subprograms in Prj.Attr
1450 package Units_Htable
is new Simple_HTable
1451 (Header_Num
=> Header_Num
,
1452 Element
=> Unit_Index
,
1453 No_Element
=> No_Unit_Index
,
1457 -- Mapping of unit names to indexes in the Units table
1459 ---------------------
1460 -- Source_Iterator --
1461 ---------------------
1463 type Source_Iterator
is private;
1465 function For_Each_Source
1466 (In_Tree
: Project_Tree_Ref
;
1467 Project
: Project_Id
:= No_Project
;
1468 Language
: Name_Id
:= No_Name
;
1469 Encapsulated_Libs
: Boolean := True;
1470 Locally_Removed
: Boolean := True) return Source_Iterator
;
1471 -- Returns an iterator for all the sources of a project tree, or a specific
1472 -- project, or a specific language. Include sources from aggregated libs if
1473 -- Aggregated_Libs is True. If Locally_Removed is set to False the
1474 -- Locally_Removed files won't be reported.
1476 function Element
(Iter
: Source_Iterator
) return Source_Id
;
1477 -- Return the current source (or No_Source if there are no more sources)
1479 procedure Next
(Iter
: in out Source_Iterator
);
1480 -- Move on to the next source
1482 function Find_Source
1483 (In_Tree
: Project_Tree_Ref
;
1484 Project
: Project_Id
;
1485 In_Imported_Only
: Boolean := False;
1486 In_Extended_Only
: Boolean := False;
1487 Base_Name
: File_Name_Type
;
1488 Index
: Int
:= 0) return Source_Id
;
1489 -- Find the first source file with the given name.
1490 -- If In_Extended_Only is True, it will search in project and the project
1491 -- it extends, but not in the imported projects.
1492 -- Elsif In_Imported_Only is True, it will search in project and the
1493 -- projects it imports, but not in the others or in aggregated projects.
1494 -- Else it searches in the whole tree.
1495 -- If Index is specified, this only search for a source with that index.
1497 -----------------------
1498 -- Project_Tree_Data --
1499 -----------------------
1501 package Replaced_Source_HTable
is new Simple_HTable
1502 (Header_Num
=> Header_Num
,
1503 Element
=> File_Name_Type
,
1504 No_Element
=> No_File
,
1505 Key
=> File_Name_Type
,
1509 type Private_Project_Tree_Data
is private;
1510 -- Data for a project tree that is used only by the Project Manager
1512 type Shared_Project_Tree_Data
is record
1513 Name_Lists
: Name_List_Table
.Instance
;
1514 Number_Lists
: Number_List_Table
.Instance
;
1515 String_Elements
: String_Element_Table
.Instance
;
1516 Variable_Elements
: Variable_Element_Table
.Instance
;
1517 Array_Elements
: Array_Element_Table
.Instance
;
1518 Arrays
: Array_Table
.Instance
;
1519 Packages
: Package_Table
.Instance
;
1520 Private_Part
: Private_Project_Tree_Data
;
1522 type Shared_Project_Tree_Data_Access
is access all Shared_Project_Tree_Data
;
1523 -- The data that is shared among multiple trees, when these trees are
1524 -- loaded through the same aggregate project.
1525 -- To avoid ambiguities, limit the number of parameters to the
1526 -- subprograms (we would have to parse the "root project tree" since this
1527 -- is where the configuration file was loaded, in addition to the project's
1528 -- own tree) and make the comparison of projects easier, all trees store
1529 -- the lists in the same tables.
1531 type Project_Tree_Appdata
is tagged null record;
1532 type Project_Tree_Appdata_Access
is access all Project_Tree_Appdata
'Class;
1533 -- Application-specific data that can be associated with a project tree.
1534 -- We do not make the Project_Tree_Data itself tagged for several reasons:
1535 -- - it couldn't have a default value for its discriminant
1536 -- - it would require a "factory" to allocate such data, because trees
1537 -- are created automatically when parsing aggregate projects.
1539 procedure Free
(Tree
: in out Project_Tree_Appdata
);
1540 -- Should be overridden if your derive your own data
1542 type Project_Tree_Data
(Is_Root_Tree
: Boolean := True) is record
1543 -- The root tree is the one loaded by the user from the command line.
1544 -- Is_Root_Tree is only false for projects aggregated within a root
1545 -- aggregate project.
1547 Projects
: Project_List
;
1548 -- List of projects in this tree
1550 Replaced_Sources
: Replaced_Source_HTable
.Instance
;
1551 -- The list of sources that have been replaced by sources with
1552 -- different file names.
1554 Replaced_Source_Number
: Natural := 0;
1555 -- The number of entries in Replaced_Sources
1557 Units_HT
: Units_Htable
.Instance
;
1558 -- Unit name to Unit_Index (and from there to Source_Id)
1560 Source_Files_HT
: Source_Files_Htable
.Instance
;
1561 -- Base source file names to Source_Id list
1563 Source_Paths_HT
: Source_Paths_Htable
.Instance
;
1564 -- Full path to Source_Id
1565 -- ??? What is behavior for multi-unit source files, where there are
1566 -- several source_id per file ?
1568 Source_Info_File_Name
: String_Access
:= null;
1569 -- The name of the source info file, if specified by the builder
1571 Source_Info_File_Exists
: Boolean := False;
1572 -- True when a source info file has been successfully read
1574 Shared
: Shared_Project_Tree_Data_Access
;
1575 -- The shared data for this tree and all aggregated trees
1577 Appdata
: Project_Tree_Appdata_Access
;
1578 -- Application-specific data for this tree
1580 case Is_Root_Tree
is
1582 Shared_Data
: aliased Shared_Project_Tree_Data
;
1583 -- Do not access directly, only through Shared
1589 -- Data for a project tree
1591 function Debug_Name
(Tree
: Project_Tree_Ref
) return Name_Id
;
1592 -- If debug traces are activated, return an identitier for the project
1593 -- tree. This modifies Name_Buffer.
1595 procedure Expect
(The_Token
: Token_Type
; Token_Image
: String);
1596 -- Check that the current token is The_Token. If it is not, then output
1597 -- an error message.
1599 procedure Initialize
(Tree
: Project_Tree_Ref
);
1600 -- This procedure must be called before using any services from the Prj
1601 -- hierarchy. Namet.Initialize must be called before Prj.Initialize.
1603 procedure Reset
(Tree
: Project_Tree_Ref
);
1604 -- This procedure resets all the tables that are used when processing a
1605 -- project file tree. Initialize must be called before the call to Reset.
1607 package Project_Boolean_Htable
is new Simple_HTable
1608 (Header_Num
=> Header_Num
,
1610 No_Element
=> False,
1614 -- A table that associates a project to a boolean. This is used to detect
1615 -- whether a project was already processed for instance.
1618 with procedure Action
(Project
: Project_Id
; Tree
: Project_Tree_Ref
);
1619 procedure For_Project_And_Aggregated
1620 (Root_Project
: Project_Id
;
1621 Root_Tree
: Project_Tree_Ref
);
1622 -- Execute Action for Root_Project and all its aggregated projects
1626 type State
is limited private;
1627 with procedure Action
1628 (Project
: Project_Id
;
1629 Tree
: Project_Tree_Ref
;
1630 With_State
: in out State
);
1631 procedure For_Every_Project_Imported
1633 Tree
: Project_Tree_Ref
;
1634 With_State
: in out State
;
1635 Include_Aggregated
: Boolean := True;
1636 Imported_First
: Boolean := False);
1637 -- Call Action for each project imported directly or indirectly by project
1638 -- By, as well as extended projects.
1640 -- The order of processing depends on Imported_First:
1642 -- If False, Action is called according to the order of importation: if A
1643 -- imports B, directly or indirectly, Action will be called for A before
1644 -- it is called for B. If two projects import each other directly or
1645 -- indirectly (using at least one "limited with"), it is not specified
1646 -- for which of these two projects Action will be called first.
1648 -- The order is reversed if Imported_First is True
1650 -- With_State may be used by Action to choose a behavior or to report some
1653 -- If Include_Aggregated is True, then an aggregate project will recurse
1654 -- into the projects it aggregates. Otherwise, the latter are never
1657 -- In_Aggregate_Lib is True if the project is in an aggregate library
1659 -- The Tree argument passed to the callback is required in the case of
1660 -- aggregated projects, since they might not be using the same tree as 'By'
1662 type Project_Context
is record
1663 In_Aggregate_Lib
: Boolean;
1664 -- True if the project is part of an aggregate library
1666 From_Encapsulated_Lib
: Boolean;
1667 -- True if the project is imported from an encapsulated library
1671 type State
is limited private;
1672 with procedure Action
1673 (Project
: Project_Id
;
1674 Tree
: Project_Tree_Ref
;
1675 Context
: Project_Context
;
1676 With_State
: in out State
);
1677 procedure For_Every_Project_Imported_Context
1679 Tree
: Project_Tree_Ref
;
1680 With_State
: in out State
;
1681 Include_Aggregated
: Boolean := True;
1682 Imported_First
: Boolean := False);
1683 -- As for For_Every_Project_Imported but with an associated context
1686 with procedure Action
1687 (Project
: Project_Id
;
1688 Tree
: Project_Tree_Ref
;
1689 Context
: Project_Context
);
1690 procedure For_Project_And_Aggregated_Context
1691 (Root_Project
: Project_Id
;
1692 Root_Tree
: Project_Tree_Ref
);
1693 -- As for For_Project_And_Aggregated but with an associated context
1695 function Extend_Name
1696 (File
: File_Name_Type
;
1697 With_Suffix
: String) return File_Name_Type
;
1698 -- Replace the extension of File with With_Suffix
1700 function Object_Name
1701 (Source_File_Name
: File_Name_Type
;
1702 Object_File_Suffix
: Name_Id
:= No_Name
) return File_Name_Type
;
1703 -- Returns the object file name corresponding to a source file name
1705 function Object_Name
1706 (Source_File_Name
: File_Name_Type
;
1708 Index_Separator
: Character;
1709 Object_File_Suffix
: Name_Id
:= No_Name
) return File_Name_Type
;
1710 -- Returns the object file name corresponding to a unit in a multi-source
1713 function Dependency_Name
1714 (Source_File_Name
: File_Name_Type
;
1715 Dependency
: Dependency_File_Kind
) return File_Name_Type
;
1716 -- Returns the dependency file name corresponding to a source file name
1718 function Switches_Name
1719 (Source_File_Name
: File_Name_Type
) return File_Name_Type
;
1720 -- Returns the switches file name corresponding to a source file name
1722 procedure Set_Path_File_Var
(Name
: String; Value
: String);
1723 -- Call Setenv, after calling To_Host_File_Spec
1725 function Current_Source_Path_File_Of
1726 (Shared
: Shared_Project_Tree_Data_Access
) return Path_Name_Type
;
1727 -- Get the current include path file name
1729 procedure Set_Current_Source_Path_File_Of
1730 (Shared
: Shared_Project_Tree_Data_Access
;
1731 To
: Path_Name_Type
);
1732 -- Record the current include path file name
1734 function Current_Object_Path_File_Of
1735 (Shared
: Shared_Project_Tree_Data_Access
) return Path_Name_Type
;
1736 -- Get the current object path file name
1738 procedure Set_Current_Object_Path_File_Of
1739 (Shared
: Shared_Project_Tree_Data_Access
;
1740 To
: Path_Name_Type
);
1741 -- Record the current object path file name
1747 type Processing_Flags
is private;
1748 -- Flags used while parsing and processing a project tree to configure the
1749 -- behavior of the parser, and indicate how to report error messages. This
1750 -- structure does not allocate memory and never needs to be freed
1752 type Error_Warning
is (Silent
, Warning
, Error
);
1753 -- Severity of some situations, such as: no Ada sources in a project where
1754 -- Ada is one of the language.
1756 -- When the situation occurs, the behaviour depends on the setting:
1758 -- - Silent: no action
1759 -- - Warning: issue a warning, does not cause the tool to fail
1760 -- - Error: issue an error, causes the tool to fail
1762 type Error_Handler
is access procedure
1763 (Project
: Project_Id
;
1764 Is_Warning
: Boolean);
1765 -- This warns when an error was found when parsing a project. The error
1766 -- itself is handled through Prj.Err (and Prj.Err.Finalize should be called
1767 -- to actually print the error). This ensures that duplicate error messages
1768 -- are always correctly removed, that errors msgs are sorted, and that all
1769 -- tools will report the same error to the user.
1771 function Create_Flags
1772 (Report_Error
: Error_Handler
;
1773 When_No_Sources
: Error_Warning
;
1774 Require_Sources_Other_Lang
: Boolean := True;
1775 Allow_Duplicate_Basenames
: Boolean := True;
1776 Compiler_Driver_Mandatory
: Boolean := False;
1777 Error_On_Unknown_Language
: Boolean := True;
1778 Require_Obj_Dirs
: Error_Warning
:= Error
;
1779 Allow_Invalid_External
: Error_Warning
:= Error
;
1780 Missing_Source_Files
: Error_Warning
:= Error
;
1781 Ignore_Missing_With
: Boolean := False)
1782 return Processing_Flags
;
1783 -- Function used to create Processing_Flags structure
1785 -- If Allow_Duplicate_Basenames, then files with the same base names are
1786 -- authorized within a project for source-based languages (never for unit
1787 -- based languages).
1789 -- If Compiler_Driver_Mandatory is true, then a Compiler.Driver attribute
1790 -- for each language must be defined, or we will not look for its source
1793 -- When_No_Sources indicates what should be done when no sources of a
1794 -- language are found in a project where this language is declared.
1795 -- If Require_Sources_Other_Lang is true, then all languages must have at
1796 -- least one source file, or an error is reported via When_No_Sources. If
1797 -- it is false, this is only required for Ada (and only if it is a language
1798 -- of the project). When this parameter is set to False, we do not check
1799 -- that a proper naming scheme is defined for languages other than Ada.
1801 -- If Report_Error is null, use the standard error reporting mechanism
1802 -- (Errout). Otherwise, report errors using Report_Error.
1804 -- If Error_On_Unknown_Language is true, an error is displayed if some of
1805 -- the source files listed in the project do not match any naming scheme
1807 -- If Require_Obj_Dirs is true, then all object directories must exist
1808 -- (possibly after they have been created automatically if the appropriate
1809 -- switches were specified), or an error is raised.
1811 -- If Allow_Invalid_External is Silent, then no error is reported when an
1812 -- invalid value is used for an external variable (and it doesn't match its
1813 -- type). Instead, the first possible value is used.
1815 -- Missing_Source_Files indicates whether it is an error or a warning that
1816 -- a source file mentioned in the Source_Files attributes is not actually
1817 -- found in the source directories. This also impacts errors for missing
1818 -- source directories.
1820 -- If Ignore_Missing_With is True, then a "with" statement that cannot be
1821 -- resolved will simply be ignored. However, in such a case, the flag
1822 -- Incomplete_With in the project tree will be set to True.
1823 -- This is meant for use by tools so that they can properly set the
1824 -- project path in such a case:
1825 -- * no "gnatls" found (so no default project path)
1826 -- * user project sets Project.IDE'gnatls attribute to a cross gnatls
1827 -- * user project also includes a "with" that can only be resolved
1828 -- once we have found the gnatls
1830 Gprbuild_Flags
: constant Processing_Flags
;
1831 Gprclean_Flags
: constant Processing_Flags
;
1832 Gnatmake_Flags
: constant Processing_Flags
;
1833 -- Flags used by the various tools. They all display the error messages
1840 procedure Record_Temp_File
1841 (Shared
: Shared_Project_Tree_Data_Access
;
1842 Path
: Path_Name_Type
);
1843 -- Record the path of a newly created temporary file, so that it can be
1846 procedure Delete_All_Temp_Files
1847 (Shared
: Shared_Project_Tree_Data_Access
);
1848 -- Delete all recorded temporary files.
1849 -- Does nothing if Debug.Debug_Flag_N is set
1851 procedure Delete_Temp_Config_Files
(Project_Tree
: Project_Tree_Ref
);
1852 -- Delete all temporary config files. Does nothing if Debug.Debug_Flag_N is
1853 -- set or if Project_Tree is null. This initially came from gnatmake
1854 -- ??? Should this be combined with Delete_All_Temp_Files above
1856 procedure Delete_Temporary_File
1857 (Shared
: Shared_Project_Tree_Data_Access
:= null;
1858 Path
: Path_Name_Type
);
1859 -- Delete a temporary file from the disk. The file is also removed from the
1860 -- list of temporary files to delete at the end of the program, in case
1861 -- another program running on the same machine has recreated it. Does
1862 -- nothing if Debug.Debug_Flag_N is set
1864 Virtual_Prefix
: constant String := "v$";
1865 -- The prefix for virtual extending projects. Because of the '$', which is
1866 -- normally forbidden for project names, there cannot be any name clash.
1872 type Verbosity
is (Default
, Medium
, High
);
1873 pragma Ordered
(Verbosity
);
1874 -- Verbosity when parsing GNAT Project Files
1875 -- Default is default (very quiet, if no errors).
1876 -- Medium is more verbose.
1877 -- High is extremely verbose.
1879 Current_Verbosity
: Verbosity
:= Default
;
1880 -- The current value of the verbosity the project files are parsed with
1882 procedure Debug_Indent
;
1883 -- Inserts a series of blanks depending on the current indentation level
1885 procedure Debug_Output
(Str
: String);
1886 procedure Debug_Output
(Str
: String; Str2
: Name_Id
);
1887 -- If Current_Verbosity is not Default, outputs Str.
1888 -- This indents Str based on the current indentation level for traces
1889 -- Debug_Error is intended to be used to report an error in the traces.
1891 procedure Debug_Increase_Indent
1892 (Str
: String := ""; Str2
: Name_Id
:= No_Name
);
1893 procedure Debug_Decrease_Indent
(Str
: String := "");
1894 -- Increase or decrease the indentation level for debug traces. This
1895 -- indentation level only affects output done through Debug_Output.
1899 All_Packages
: constant String_List_Access
:= null;
1901 No_Project_Tree
: constant Project_Tree_Ref
:= null;
1903 Ignored
: constant Variable_Kind
:= Single
;
1905 Nil_Variable_Value
: constant Variable_Value
:=
1906 (Project
=> No_Project
,
1908 Location
=> No_Location
,
1911 type Source_Iterator
is record
1912 In_Tree
: Project_Tree_Ref
;
1914 Project
: Project_List
;
1915 All_Projects
: Boolean;
1916 -- Current project and whether we should move on to the next
1918 Language
: Language_Ptr
;
1919 -- Current language processed
1921 Language_Name
: Name_Id
;
1922 -- Only sources of this language will be returned (or all if No_Name)
1924 Current
: Source_Id
;
1926 Encapsulated_Libs
: Boolean;
1927 -- True if we want to include the sources from encapsulated libs
1929 Locally_Removed
: Boolean;
1932 procedure Add_To_Buffer
1934 To
: in out String_Access
;
1935 Last
: in out Natural);
1936 -- Append a String to the Buffer
1938 package Temp_Files_Table
is new GNAT
.Dynamic_Tables
1939 (Table_Component_Type
=> Path_Name_Type
,
1940 Table_Index_Type
=> Integer,
1941 Table_Low_Bound
=> 1,
1942 Table_Initial
=> 10,
1943 Table_Increment
=> 10);
1944 -- Table to store the path name of all the created temporary files, so that
1945 -- they can be deleted at the end, or when the program is interrupted.
1947 type Private_Project_Tree_Data
is record
1948 Temp_Files
: Temp_Files_Table
.Instance
;
1949 -- Temporary files created as part of running tools (pragma files,
1950 -- mapping files,...)
1952 Current_Source_Path_File
: Path_Name_Type
:= No_Path
;
1953 -- Current value of project source path file env var. Used to avoid
1954 -- setting the env var to the same value. When different from No_Path,
1955 -- this indicates that logical names (VMS) or environment variables were
1956 -- created and should be deassigned to avoid polluting the environment
1960 Current_Object_Path_File
: Path_Name_Type
:= No_Path
;
1961 -- Current value of project object path file env var. Used to avoid
1962 -- setting the env var to the same value.
1966 -- Type to represent the part of a project tree which is private to the
1969 type Processing_Flags
is record
1970 Require_Sources_Other_Lang
: Boolean;
1971 Report_Error
: Error_Handler
;
1972 When_No_Sources
: Error_Warning
;
1973 Allow_Duplicate_Basenames
: Boolean;
1974 Compiler_Driver_Mandatory
: Boolean;
1975 Error_On_Unknown_Language
: Boolean;
1976 Require_Obj_Dirs
: Error_Warning
;
1977 Allow_Invalid_External
: Error_Warning
;
1978 Missing_Source_Files
: Error_Warning
;
1979 Ignore_Missing_With
: Boolean;
1982 Gprbuild_Flags
: constant Processing_Flags
:=
1983 (Report_Error
=> null,
1984 When_No_Sources
=> Warning
,
1985 Require_Sources_Other_Lang
=> True,
1986 Allow_Duplicate_Basenames
=> False,
1987 Compiler_Driver_Mandatory
=> True,
1988 Error_On_Unknown_Language
=> True,
1989 Require_Obj_Dirs
=> Error
,
1990 Allow_Invalid_External
=> Error
,
1991 Missing_Source_Files
=> Error
,
1992 Ignore_Missing_With
=> False);
1994 Gprclean_Flags
: constant Processing_Flags
:=
1995 (Report_Error
=> null,
1996 When_No_Sources
=> Warning
,
1997 Require_Sources_Other_Lang
=> True,
1998 Allow_Duplicate_Basenames
=> False,
1999 Compiler_Driver_Mandatory
=> True,
2000 Error_On_Unknown_Language
=> True,
2001 Require_Obj_Dirs
=> Warning
,
2002 Allow_Invalid_External
=> Error
,
2003 Missing_Source_Files
=> Error
,
2004 Ignore_Missing_With
=> False);
2006 Gnatmake_Flags
: constant Processing_Flags
:=
2007 (Report_Error
=> null,
2008 When_No_Sources
=> Error
,
2009 Require_Sources_Other_Lang
=> False,
2010 Allow_Duplicate_Basenames
=> False,
2011 Compiler_Driver_Mandatory
=> False,
2012 Error_On_Unknown_Language
=> False,
2013 Require_Obj_Dirs
=> Error
,
2014 Allow_Invalid_External
=> Error
,
2015 Missing_Source_Files
=> Error
,
2016 Ignore_Missing_With
=> False);