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 type Project_Qualifier
is
79 -- Qualifiers that can prefix the reserved word "project" in a project
81 -- Standard: standard project ...
82 -- Library: library project is ...
83 -- Dry: abstract project is
84 -- Aggregate: aggregate project is
85 -- Aggregate_Library: aggregate library project is ...
86 -- Configuration: configuration project is ...
88 subtype Aggregate_Project
is
89 Project_Qualifier
range Aggregate
.. Aggregate_Library
;
91 All_Packages
: constant String_List_Access
;
92 -- Default value of parameter Packages of procedures Parse, in Prj.Pars and
93 -- Prj.Part, indicating that all packages should be checked.
95 type Project_Tree_Data
;
96 type Project_Tree_Ref
is access all Project_Tree_Data
;
97 -- Reference to a project tree. Several project trees may exist in memory
100 No_Project_Tree
: constant Project_Tree_Ref
;
102 procedure Free
(Tree
: in out Project_Tree_Ref
);
103 -- Free memory associated with the tree
105 Config_Project_File_Extension
: String := ".cgpr";
106 Project_File_Extension
: String := ".gpr";
107 -- The standard config and user project file name extensions. They are not
108 -- constants, because Canonical_Case_File_Name is called on these variables
109 -- in the body of Prj.
111 function Empty_File
return File_Name_Type
;
112 function Empty_String
return Name_Id
;
113 -- Return the id for an empty string ""
115 type Path_Information
is record
116 Name
: Path_Name_Type
:= No_Path
;
117 Display_Name
: Path_Name_Type
:= No_Path
;
119 -- Directory names always end with a directory separator
121 No_Path_Information
: constant Path_Information
:= (No_Path
, No_Path
);
124 type Project_Id
is access all Project_Data
;
125 No_Project
: constant Project_Id
:= null;
126 -- Id of a Project File
128 type String_List_Id
is new Nat
;
129 Nil_String
: constant String_List_Id
:= 0;
130 type String_Element
is record
131 Value
: Name_Id
:= No_Name
;
133 Display_Value
: Name_Id
:= No_Name
;
134 Location
: Source_Ptr
:= No_Location
;
135 Flag
: Boolean := False;
136 Next
: String_List_Id
:= Nil_String
;
138 -- To hold values for string list variables and array elements.
139 -- Component Flag may be used for various purposes. For source
140 -- directories, it indicates if the directory contains Ada source(s).
142 package String_Element_Table
is new GNAT
.Dynamic_Tables
143 (Table_Component_Type
=> String_Element
,
144 Table_Index_Type
=> String_List_Id
,
145 Table_Low_Bound
=> 1,
146 Table_Initial
=> 200,
147 Table_Increment
=> 100);
148 -- The table for string elements in string lists
150 type Variable_Kind
is (Undefined
, List
, Single
);
151 -- Different kinds of variables
153 subtype Defined_Variable_Kind
is Variable_Kind
range List
.. Single
;
154 -- The defined kinds of variables
156 Ignored
: constant Variable_Kind
;
157 -- Used to indicate that a package declaration must be ignored
158 -- while processing the project tree (unknown package name).
160 type Variable_Value
(Kind
: Variable_Kind
:= Undefined
) is record
161 Project
: Project_Id
:= No_Project
;
162 Location
: Source_Ptr
:= No_Location
;
163 Default
: Boolean := False;
168 Values
: String_List_Id
:= Nil_String
;
170 Value
: Name_Id
:= No_Name
;
174 -- Values for variables and array elements. Default is True if the
175 -- current value is the default one for the variable.
177 Nil_Variable_Value
: constant Variable_Value
;
178 -- Value of a non existing variable or array element
180 type Variable_Id
is new Nat
;
181 No_Variable
: constant Variable_Id
:= 0;
182 type Variable
is record
183 Next
: Variable_Id
:= No_Variable
;
185 Value
: Variable_Value
;
187 -- To hold the list of variables in a project file and in packages
189 package Variable_Element_Table
is new GNAT
.Dynamic_Tables
190 (Table_Component_Type
=> Variable
,
191 Table_Index_Type
=> Variable_Id
,
192 Table_Low_Bound
=> 1,
193 Table_Initial
=> 200,
194 Table_Increment
=> 100);
195 -- The table of variable in list of variables
197 type Array_Element_Id
is new Nat
;
198 No_Array_Element
: constant Array_Element_Id
:= 0;
199 type Array_Element
is record
201 Restricted
: Boolean := False;
202 Src_Index
: Int
:= 0;
203 Index_Case_Sensitive
: Boolean := True;
204 Value
: Variable_Value
;
205 Next
: Array_Element_Id
:= No_Array_Element
;
207 -- Each Array_Element represents an array element and is linked (Next)
208 -- to the next array element, if any, in the array.
210 package Array_Element_Table
is new GNAT
.Dynamic_Tables
211 (Table_Component_Type
=> Array_Element
,
212 Table_Index_Type
=> Array_Element_Id
,
213 Table_Low_Bound
=> 1,
214 Table_Initial
=> 200,
215 Table_Increment
=> 100);
216 -- The table that contains all array elements
218 type Array_Id
is new Nat
;
219 No_Array
: constant Array_Id
:= 0;
220 type Array_Data
is record
221 Name
: Name_Id
:= No_Name
;
222 Location
: Source_Ptr
:= No_Location
;
223 Value
: Array_Element_Id
:= No_Array_Element
;
224 Next
: Array_Id
:= No_Array
;
226 -- Each Array_Data value represents an array.
227 -- Value is the id of the first element.
228 -- Next is the id of the next array in the project file or package.
230 package Array_Table
is new GNAT
.Dynamic_Tables
231 (Table_Component_Type
=> Array_Data
,
232 Table_Index_Type
=> Array_Id
,
233 Table_Low_Bound
=> 1,
234 Table_Initial
=> 200,
235 Table_Increment
=> 100);
236 -- The table that contains all arrays
238 type Package_Id
is new Nat
;
239 No_Package
: constant Package_Id
:= 0;
240 type Declarations
is record
241 Variables
: Variable_Id
:= No_Variable
;
242 Attributes
: Variable_Id
:= No_Variable
;
243 Arrays
: Array_Id
:= No_Array
;
244 Packages
: Package_Id
:= No_Package
;
246 -- Contains the declarations (variables, single and array attributes,
247 -- packages) for a project or a package in a project.
249 No_Declarations
: constant Declarations
:=
250 (Variables
=> No_Variable
,
251 Attributes
=> No_Variable
,
253 Packages
=> No_Package
);
254 -- Default value of Declarations: indicates that there is no declarations
256 type Package_Element
is record
257 Name
: Name_Id
:= No_Name
;
258 Decl
: Declarations
:= No_Declarations
;
259 Parent
: Package_Id
:= No_Package
;
260 Next
: Package_Id
:= No_Package
;
262 -- A package (includes declarations that may include other packages)
264 package Package_Table
is new GNAT
.Dynamic_Tables
265 (Table_Component_Type
=> Package_Element
,
266 Table_Index_Type
=> Package_Id
,
267 Table_Low_Bound
=> 1,
268 Table_Initial
=> 100,
269 Table_Increment
=> 100);
270 -- The table that contains all packages
273 type Language_Ptr
is access all Language_Data
;
274 -- Index of language data
276 No_Language_Index
: constant Language_Ptr
:= null;
277 -- Constant indicating that there is no language data
279 function Get_Language_From_Name
280 (Project
: Project_Id
;
281 Name
: String) return Language_Ptr
;
282 -- Get a language from a project. This might return null if no such
283 -- language exists in the project
285 Max_Header_Num
: constant := 6150;
286 type Header_Num
is range 0 .. Max_Header_Num
;
287 -- Size for hash table below. The upper bound is an arbitrary value, the
288 -- value here was chosen after testing to determine a good compromise
289 -- between speed of access and memory usage.
291 function Hash
(Name
: Name_Id
) return Header_Num
;
292 function Hash
(Name
: File_Name_Type
) return Header_Num
;
293 function Hash
(Name
: Path_Name_Type
) return Header_Num
;
294 function Hash
(Project
: Project_Id
) return Header_Num
;
295 -- Used for computing hash values for names put into hash tables
297 type Language_Kind
is (File_Based
, Unit_Based
);
298 -- Type for the kind of language. All languages are file based, except Ada
299 -- which is unit based.
301 -- Type of dependency to be checked
303 type Dependency_File_Kind
is
305 -- There is no dependency file, the source must always be recompiled
308 -- The dependency file is a Makefile fragment indicating all the files
309 -- the source depends on. If the object file or the dependency file is
310 -- more recent than any of these files, the source must be recompiled.
313 -- The dependency file is an ALI file and the source must be recompiled
314 -- if the object or ALI file is more recent than any of the sources
315 -- listed in the D lines.
318 -- The dependency file is an ALI file and the source must be recompiled
319 -- if the object or ALI file is more recent than any source in the full
322 Makefile_Dependency_Suffix
: constant String := ".d";
323 ALI_Dependency_Suffix
: constant String := ".ali";
324 Switches_Dependency_Suffix
: constant String := ".cswi";
326 Binder_Exchange_Suffix
: constant String := ".bexch";
327 -- Suffix for binder exchange files
329 Library_Exchange_Suffix
: constant String := ".lexch";
330 -- Suffix for library exchange files
332 type Name_List_Index
is new Nat
;
333 No_Name_List
: constant Name_List_Index
:= 0;
335 type Name_Node
is record
336 Name
: Name_Id
:= No_Name
;
337 Next
: Name_List_Index
:= No_Name_List
;
340 package Name_List_Table
is new GNAT
.Dynamic_Tables
341 (Table_Component_Type
=> Name_Node
,
342 Table_Index_Type
=> Name_List_Index
,
343 Table_Low_Bound
=> 1,
345 Table_Increment
=> 100);
346 -- The table for lists of names
349 (Table
: Name_List_Table
.Instance
;
350 List
: Name_List_Index
) return Natural;
351 -- Return the number of elements in specified list
353 type Number_List_Index
is new Nat
;
354 No_Number_List
: constant Number_List_Index
:= 0;
356 type Number_Node
is record
357 Number
: Natural := 0;
358 Next
: Number_List_Index
:= No_Number_List
;
361 package Number_List_Table
is new GNAT
.Dynamic_Tables
362 (Table_Component_Type
=> Number_Node
,
363 Table_Index_Type
=> Number_List_Index
,
364 Table_Low_Bound
=> 1,
366 Table_Increment
=> 100);
367 -- The table for lists of numbers
369 package Mapping_Files_Htable
is new Simple_HTable
370 (Header_Num
=> Header_Num
,
371 Element
=> Path_Name_Type
,
372 No_Element
=> No_Path
,
373 Key
=> Path_Name_Type
,
376 -- A hash table to store the mapping files that are not used
378 -- The following record ???
380 type Lang_Naming_Data
is record
381 Dot_Replacement
: File_Name_Type
:= No_File
;
382 -- The string to replace '.' in the source file name (for Ada)
384 Casing
: Casing_Type
:= All_Lower_Case
;
385 -- The casing of the source file name (for Ada)
387 Separate_Suffix
: File_Name_Type
:= No_File
;
388 -- String to append to unit name for source file name of an Ada subunit
390 Spec_Suffix
: File_Name_Type
:= No_File
;
391 -- The string to append to the unit name for the
392 -- source file name of a spec.
394 Body_Suffix
: File_Name_Type
:= No_File
;
395 -- The string to append to the unit name for the
396 -- source file name of a body.
399 No_Lang_Naming_Data
: constant Lang_Naming_Data
:=
400 (Dot_Replacement
=> No_File
,
401 Casing
=> All_Lower_Case
,
402 Separate_Suffix
=> No_File
,
403 Spec_Suffix
=> No_File
,
404 Body_Suffix
=> No_File
);
406 function Is_Standard_GNAT_Naming
(Naming
: Lang_Naming_Data
) return Boolean;
407 -- True if the naming scheme is GNAT's default naming scheme. This
408 -- is to take into account shortened names like "Ada." (a-), "System." (s-)
412 type Source_Id
is access all Source_Data
;
414 function Is_Compilable
(Source
: Source_Id
) return Boolean;
415 pragma Inline
(Is_Compilable
);
416 -- Return True if we know how to compile Source (i.e. if a compiler is
417 -- defined). This doesn't indicate whether the source should be compiled.
419 function Object_To_Global_Archive
(Source
: Source_Id
) return Boolean;
420 pragma Inline
(Object_To_Global_Archive
);
421 -- Return True if the object file should be put in the global archive.
422 -- This is for Ada, when only the closure of a main needs to be
425 function Other_Part
(Source
: Source_Id
) return Source_Id
;
426 pragma Inline
(Other_Part
);
427 -- Source ID for the other part, if any: for a spec, indicates its body;
428 -- for a body, indicates its spec.
430 No_Source
: constant Source_Id
:= null;
432 type Path_Syntax_Kind
is
436 -- Host specific syntax, for example on VMS (the default)
438 -- The following record describes the configuration of a language
440 type Language_Config
is record
441 Kind
: Language_Kind
:= File_Based
;
442 -- Kind of language. Most languages are file based. A few, such as Ada,
445 Naming_Data
: Lang_Naming_Data
;
446 -- The naming data for the languages (prefixes, etc.)
448 Include_Compatible_Languages
: Name_List_Index
:= No_Name_List
;
449 -- List of languages that are "include compatible" with this language. A
450 -- language B (for example "C") is "include compatible" with a language
451 -- A (for example "C++") if it is expected that sources of language A
452 -- may "include" header files from language B.
454 Compiler_Driver
: File_Name_Type
:= No_File
;
455 -- The name of the executable for the compiler of the language
457 Compiler_Driver_Path
: String_Access
:= null;
458 -- The path name of the executable for the compiler of the language
460 Compiler_Leading_Required_Switches
: Name_List_Index
:= No_Name_List
;
461 -- The list of initial switches that are required as a minimum to invoke
462 -- the compiler driver.
464 Compiler_Trailing_Required_Switches
: Name_List_Index
:= No_Name_List
;
465 -- The list of final switches that are required as a minimum to invoke
466 -- the compiler driver.
468 Multi_Unit_Switches
: Name_List_Index
:= No_Name_List
;
469 -- The switch(es) to indicate the index of a unit in a multi-source file
471 Multi_Unit_Object_Separator
: Character := ' ';
472 -- The string separating the base name of a source from the index of the
473 -- unit in a multi-source file, in the object file name.
475 Path_Syntax
: Path_Syntax_Kind
:= Host
;
476 -- Value may be Canonical (Unix style) or Host (host syntax, for example
477 -- on VMS for DEC C).
479 Source_File_Switches
: Name_List_Index
:= No_Name_List
;
480 -- Optional switches to be put before the source file. The source file
481 -- path name is appended to the last switch in the list.
482 -- Example: ("-i", "");
484 Object_File_Suffix
: Name_Id
:= No_Name
;
485 -- Optional alternate object file suffix
487 Object_File_Switches
: Name_List_Index
:= No_Name_List
;
488 -- Optional object file switches. When this is defined, the switches
489 -- are used to specify the object file. The object file name is appended
490 -- to the last switch in the list. Example: ("-o", "").
492 Object_Path_Switches
: Name_List_Index
:= No_Name_List
;
493 -- List of switches to specify to the compiler the path name of a
494 -- temporary file containing the list of object directories in the
497 Compilation_PIC_Option
: Name_List_Index
:= No_Name_List
;
498 -- The option(s) to compile a source in Position Independent Code for
499 -- shared libraries. Specified in the configuration. When not specified,
500 -- there is no need for such switch.
502 Object_Generated
: Boolean := True;
503 -- False in no object file is generated
505 Objects_Linked
: Boolean := True;
506 -- False if object files are not use to link executables and build
509 Runtime_Library_Dir
: Name_Id
:= No_Name
;
510 -- Path name of the runtime library directory, if any
512 Runtime_Source_Dir
: Name_Id
:= No_Name
;
513 -- Path name of the runtime source directory, if any
515 Mapping_File_Switches
: Name_List_Index
:= No_Name_List
;
516 -- The option(s) to provide a mapping file to the compiler. Specified in
517 -- the configuration. When value is No_Name_List, there is no mapping
520 Mapping_Spec_Suffix
: File_Name_Type
:= No_File
;
521 -- Placeholder representing the spec suffix in a mapping file
523 Mapping_Body_Suffix
: File_Name_Type
:= No_File
;
524 -- Placeholder representing the body suffix in a mapping file
526 Config_File_Switches
: Name_List_Index
:= No_Name_List
;
527 -- The option(s) to provide a config file to the compiler. Specified in
528 -- the configuration. If value is No_Name_List there is no config file.
530 Dependency_Kind
: Dependency_File_Kind
:= None
;
531 -- The kind of dependency to be checked: none, Makefile fragment or
532 -- ALI file (for Ada).
534 Dependency_Option
: Name_List_Index
:= No_Name_List
;
535 -- The option(s) to be used to create the dependency file. When value is
536 -- No_Name_List, there is not such option(s).
538 Compute_Dependency
: Name_List_Index
:= No_Name_List
;
539 -- Hold the value of attribute Dependency_Driver, if declared for the
542 Include_Option
: Name_List_Index
:= No_Name_List
;
543 -- Hold the value of attribute Include_Switches, if declared for the
546 Include_Path
: Name_Id
:= No_Name
;
547 -- Name of environment variable declared by attribute Include_Path for
550 Include_Path_File
: Name_Id
:= No_Name
;
551 -- Name of environment variable declared by attribute Include_Path_File
554 Objects_Path
: Name_Id
:= No_Name
;
555 -- Name of environment variable declared by attribute Objects_Path for
558 Objects_Path_File
: Name_Id
:= No_Name
;
559 -- Name of environment variable declared by attribute Objects_Path_File
562 Config_Body
: Name_Id
:= No_Name
;
563 -- The template for a pragma Source_File_Name(_Project) for a specific
564 -- file name of a body.
566 Config_Body_Index
: Name_Id
:= No_Name
;
567 -- The template for a pragma Source_File_Name(_Project) for a specific
568 -- file name of a body in a multi-source file.
570 Config_Body_Pattern
: Name_Id
:= No_Name
;
571 -- The template for a pragma Source_File_Name(_Project) for a naming
574 Config_Spec
: Name_Id
:= No_Name
;
575 -- The template for a pragma Source_File_Name(_Project) for a specific
576 -- file name of a spec.
578 Config_Spec_Index
: Name_Id
:= No_Name
;
579 -- The template for a pragma Source_File_Name(_Project) for a specific
580 -- file name of a spec in a multi-source file.
582 Config_Spec_Pattern
: Name_Id
:= No_Name
;
583 -- The template for a pragma Source_File_Name(_Project) for a naming
586 Config_File_Unique
: Boolean := False;
587 -- Indicate if the config file specified to the compiler needs to be
588 -- unique. If it is unique, then all config files are concatenated into
589 -- a temp config file.
591 Binder_Driver
: File_Name_Type
:= No_File
;
592 -- The name of the binder driver for the language, if any
594 Binder_Driver_Path
: Path_Name_Type
:= No_Path
;
595 -- The path name of the binder driver
597 Binder_Required_Switches
: Name_List_Index
:= No_Name_List
;
598 -- Hold the value of attribute Binder'Required_Switches for the language
600 Binder_Prefix
: Name_Id
:= No_Name
;
601 -- Hold the value of attribute Binder'Prefix for the language
603 Toolchain_Version
: Name_Id
:= No_Name
;
604 -- Hold the value of attribute Toolchain_Version for the language
606 Toolchain_Description
: Name_Id
:= No_Name
;
607 -- Hold the value of attribute Toolchain_Description for the language
609 Clean_Object_Artifacts
: Name_List_Index
:= No_Name_List
;
610 -- List of object artifact extensions to be deleted by gprclean
612 Clean_Source_Artifacts
: Name_List_Index
:= No_Name_List
;
613 -- List of source artifact extensions to be deleted by gprclean
617 No_Language_Config
: constant Language_Config
:=
619 Naming_Data
=> No_Lang_Naming_Data
,
620 Include_Compatible_Languages
=> No_Name_List
,
621 Compiler_Driver
=> No_File
,
622 Compiler_Driver_Path
=> null,
623 Compiler_Leading_Required_Switches
625 Compiler_Trailing_Required_Switches
627 Multi_Unit_Switches
=> No_Name_List
,
628 Multi_Unit_Object_Separator
=> ' ',
629 Path_Syntax
=> Canonical
,
630 Source_File_Switches
=> No_Name_List
,
631 Object_File_Suffix
=> No_Name
,
632 Object_File_Switches
=> No_Name_List
,
633 Object_Path_Switches
=> No_Name_List
,
634 Compilation_PIC_Option
=> No_Name_List
,
635 Object_Generated
=> True,
636 Objects_Linked
=> True,
637 Runtime_Library_Dir
=> No_Name
,
638 Runtime_Source_Dir
=> No_Name
,
639 Mapping_File_Switches
=> No_Name_List
,
640 Mapping_Spec_Suffix
=> No_File
,
641 Mapping_Body_Suffix
=> No_File
,
642 Config_File_Switches
=> No_Name_List
,
643 Dependency_Kind
=> None
,
644 Dependency_Option
=> No_Name_List
,
645 Compute_Dependency
=> No_Name_List
,
646 Include_Option
=> No_Name_List
,
647 Include_Path
=> No_Name
,
648 Include_Path_File
=> No_Name
,
649 Objects_Path
=> No_Name
,
650 Objects_Path_File
=> No_Name
,
651 Config_Body
=> No_Name
,
652 Config_Body_Index
=> No_Name
,
653 Config_Body_Pattern
=> No_Name
,
654 Config_Spec
=> No_Name
,
655 Config_Spec_Index
=> No_Name
,
656 Config_Spec_Pattern
=> No_Name
,
657 Config_File_Unique
=> False,
658 Binder_Driver
=> No_File
,
659 Binder_Driver_Path
=> No_Path
,
660 Binder_Required_Switches
=> No_Name_List
,
661 Binder_Prefix
=> No_Name
,
662 Toolchain_Version
=> No_Name
,
663 Toolchain_Description
=> No_Name
,
664 Clean_Object_Artifacts
=> No_Name_List
,
665 Clean_Source_Artifacts
=> No_Name_List
);
667 -- The following record ???
669 type Language_Data
is record
670 Name
: Name_Id
:= No_Name
;
671 Display_Name
: Name_Id
:= No_Name
;
672 Config
: Language_Config
:= No_Language_Config
;
673 First_Source
: Source_Id
:= No_Source
;
674 Mapping_Files
: Mapping_Files_Htable
.Instance
:=
675 Mapping_Files_Htable
.Nil
;
676 Next
: Language_Ptr
:= No_Language_Index
;
679 No_Language_Data
: constant Language_Data
:=
681 Display_Name
=> No_Name
,
682 Config
=> No_Language_Config
,
683 First_Source
=> No_Source
,
684 Mapping_Files
=> Mapping_Files_Htable
.Nil
,
685 Next
=> No_Language_Index
);
687 type Language_List_Element
;
688 type Language_List
is access all Language_List_Element
;
689 type Language_List_Element
is record
690 Language
: Language_Ptr
:= No_Language_Index
;
691 Next
: Language_List
;
694 type Source_Kind
is (Spec
, Impl
, Sep
);
695 subtype Spec_Or_Body
is Source_Kind
range Spec
.. Impl
;
697 -- The following declarations declare a structure used to store the Name
698 -- and File and Path names of a unit, with a reference to its GNAT Project
699 -- File(s). Some units might have neither Spec nor Impl when they were
700 -- created for a "separate".
702 type File_Names_Data
is array (Spec_Or_Body
) of Source_Id
;
704 type Unit_Data
is record
705 Name
: Name_Id
:= No_Name
;
706 File_Names
: File_Names_Data
;
709 type Unit_Index
is access all Unit_Data
;
711 No_Unit_Index
: constant Unit_Index
:= null;
712 -- Used to indicate a null entry for no unit
715 type Roots_Access
is access Source_Roots
;
716 type Source_Roots
is record
720 -- A list to store the roots associated with a main unit. These are the
721 -- files that need to linked along with the main (for instance a C file
722 -- corresponding to an Ada file). In general, these are dependencies that
723 -- cannot be computed automatically by the builder.
725 type Naming_Exception_Type
is (No
, Yes
, Inherited
);
727 -- Structure to define source data
729 type Source_Data
is record
730 Initialized
: Boolean := False;
731 -- Set to True when Source_Data is completely initialized
733 Project
: Project_Id
:= No_Project
;
734 -- Project of the source
736 Location
: Source_Ptr
:= No_Location
;
737 -- Location in the project file of the declaration of the source in
740 Source_Dir_Rank
: Natural := 0;
741 -- The rank of the source directory in list declared with attribute
742 -- Source_Dirs. Two source files with the same name cannot appears in
743 -- different directory with the same rank. That can happen when the
744 -- recursive notation <dir>/** is used in attribute Source_Dirs.
746 Language
: Language_Ptr
:= No_Language_Index
;
747 -- Index of the language. This is an index into
748 -- Project_Tree.Languages_Data.
750 In_Interfaces
: Boolean := True;
751 -- False when the source is not included in interfaces, when attribute
752 -- Interfaces is declared.
754 Declared_In_Interfaces
: Boolean := False;
755 -- True when source is declared in attribute Interfaces
757 Alternate_Languages
: Language_List
:= null;
758 -- List of languages a header file may also be, in addition of language
761 Kind
: Source_Kind
:= Spec
;
762 -- Kind of the source: spec, body or subunit
764 Unit
: Unit_Index
:= No_Unit_Index
;
765 -- Name of the unit, if language is unit based. This is only set for
766 -- those files that are part of the compilation set (for instance a
767 -- file in an extended project that is overridden will not have this
771 -- Index of the source in a multi unit source file (the same Source_Data
772 -- is duplicated several times when there are several units in the same
773 -- file). Index is 0 if there is either no unit or a single one, and
774 -- starts at 1 when there are multiple units
776 Compilable
: Yes_No_Unknown
:= Unknown
;
777 -- Updated at the first call to Is_Compilable. Yes if source file is
780 In_The_Queue
: Boolean := False;
781 -- True if the source has been put in the queue
783 Locally_Removed
: Boolean := False;
784 -- True if the source has been "excluded"
786 Suppressed
: Boolean := False;
787 -- True if the source is a locally removed direct source of the project.
788 -- These sources should not be put in the mapping file.
790 Replaced_By
: Source_Id
:= No_Source
;
791 -- Source in an extending project that replaces the current source
793 File
: File_Name_Type
:= No_File
;
794 -- Canonical file name of the source
796 Display_File
: File_Name_Type
:= No_File
;
797 -- File name of the source, for display purposes
799 Path
: Path_Information
:= No_Path_Information
;
800 -- Path name of the source
802 Source_TS
: Time_Stamp_Type
:= Empty_Time_Stamp
;
803 -- Time stamp of the source file
805 Object_Project
: Project_Id
:= No_Project
;
806 -- Project where the object file is. This might be different from
807 -- Project when using extending project files.
809 Object
: File_Name_Type
:= No_File
;
810 -- File name of the object file
812 Current_Object_Path
: Path_Name_Type
:= No_Path
;
813 -- Object path of an existing object file
815 Object_Path
: Path_Name_Type
:= No_Path
;
816 -- Object path of the real object file
818 Object_TS
: Time_Stamp_Type
:= Empty_Time_Stamp
;
819 -- Object file time stamp
821 Dep_Name
: File_Name_Type
:= No_File
;
822 -- Dependency file simple name
824 Current_Dep_Path
: Path_Name_Type
:= No_Path
;
825 -- Path name of an existing dependency file
827 Dep_Path
: Path_Name_Type
:= No_Path
;
828 -- Path name of the real dependency file
830 Dep_TS
: aliased Osint
.File_Attributes
:= Osint
.Unknown_Attributes
;
831 -- Dependency file time stamp
833 Switches
: File_Name_Type
:= No_File
;
834 -- File name of the switches file. For all languages, this is a file
835 -- that ends with the .cswi extension.
837 Switches_Path
: Path_Name_Type
:= No_Path
;
838 -- Path name of the switches file
840 Switches_TS
: Time_Stamp_Type
:= Empty_Time_Stamp
;
841 -- Switches file time stamp
843 Naming_Exception
: Naming_Exception_Type
:= No
;
844 -- True if the source has an exceptional name
846 Duplicate_Unit
: Boolean := False;
847 -- True when a duplicate unit has been reported for this source
849 Next_In_Lang
: Source_Id
:= No_Source
;
850 -- Link to another source of the same language in the same project
852 Next_With_File_Name
: Source_Id
:= No_Source
;
853 -- Link to another source with the same base file name
855 Roots
: Roots_Access
:= null;
856 -- The roots for a main unit
860 No_Source_Data
: constant Source_Data
:=
861 (Initialized
=> False,
862 Project
=> No_Project
,
863 Location
=> No_Location
,
864 Source_Dir_Rank
=> 0,
865 Language
=> No_Language_Index
,
866 In_Interfaces
=> True,
867 Declared_In_Interfaces
=> False,
868 Alternate_Languages
=> null,
870 Unit
=> No_Unit_Index
,
872 Locally_Removed
=> False,
874 Compilable
=> Unknown
,
875 In_The_Queue
=> False,
876 Replaced_By
=> No_Source
,
878 Display_File
=> No_File
,
879 Path
=> No_Path_Information
,
880 Source_TS
=> Empty_Time_Stamp
,
881 Object_Project
=> No_Project
,
883 Current_Object_Path
=> No_Path
,
884 Object_Path
=> No_Path
,
885 Object_TS
=> Empty_Time_Stamp
,
887 Current_Dep_Path
=> No_Path
,
889 Dep_TS
=> Osint
.Unknown_Attributes
,
891 Switches_Path
=> No_Path
,
892 Switches_TS
=> Empty_Time_Stamp
,
893 Naming_Exception
=> No
,
894 Duplicate_Unit
=> False,
895 Next_In_Lang
=> No_Source
,
896 Next_With_File_Name
=> No_Source
,
899 package Source_Files_Htable
is new Simple_HTable
900 (Header_Num
=> Header_Num
,
901 Element
=> Source_Id
,
902 No_Element
=> No_Source
,
903 Key
=> File_Name_Type
,
906 -- Mapping of source file names to source ids
908 package Source_Paths_Htable
is new Simple_HTable
909 (Header_Num
=> Header_Num
,
910 Element
=> Source_Id
,
911 No_Element
=> No_Source
,
912 Key
=> Path_Name_Type
,
915 -- Mapping of source paths to source ids
917 type Lib_Kind
is (Static
, Dynamic
, Relocatable
);
919 type Policy
is (Autonomous
, Compliant
, Controlled
, Restricted
, Direct
);
920 -- Type to specify the symbol policy, when symbol control is supported.
921 -- See full explanation about this type in package Symbols.
922 -- Autonomous: Create a symbol file without considering any reference
923 -- Compliant: Try to be as compatible as possible with an existing ref
924 -- Controlled: Fail if symbols are not the same as those in the reference
925 -- Restricted: Restrict the symbols to those in the symbol file
926 -- Direct: The symbol file is used as is
928 type Symbol_Record
is record
929 Symbol_File
: Path_Name_Type
:= No_Path
;
930 Reference
: Path_Name_Type
:= No_Path
;
931 Symbol_Policy
: Policy
:= Autonomous
;
933 -- Type to keep the symbol data to be used when building a shared library
935 No_Symbols
: constant Symbol_Record
:=
936 (Symbol_File
=> No_Path
,
937 Reference
=> No_Path
,
938 Symbol_Policy
=> Autonomous
);
939 -- The default value of the symbol data
941 function Image
(The_Casing
: Casing_Type
) return String;
942 -- Similar to 'Image (but avoid use of this attribute in compiler)
944 function Value
(Image
: String) return Casing_Type
;
945 -- Similar to 'Value (but avoid use of this attribute in compiler)
946 -- Raises Constraint_Error if not a Casing_Type image.
948 -- The following record contains data for a naming scheme
950 function Get_Object_Directory
951 (Project
: Project_Id
;
952 Including_Libraries
: Boolean;
953 Only_If_Ada
: Boolean := False) return Path_Name_Type
;
954 -- Return the object directory to use for the project. This depends on
955 -- whether we have a library project or a standard project. This function
956 -- might return No_Name when no directory applies.
957 -- If we have a library project file and Including_Libraries is True then
958 -- the library dir is returned instead of the object dir.
959 -- If Only_If_Ada is True, then No_Name will be returned when the project
960 -- doesn't Ada sources.
962 procedure Compute_All_Imported_Projects
963 (Root_Project
: Project_Id
;
964 Tree
: Project_Tree_Ref
);
965 -- For all projects in the tree, compute the list of the projects imported
966 -- directly or indirectly by project Root_Project. The result is stored in
967 -- Project.All_Imported_Projects for each project
969 function Ultimate_Extending_Project_Of
970 (Proj
: Project_Id
) return Project_Id
;
971 -- Returns the ultimate extending project of project Proj. If project Proj
972 -- is not extended, returns Proj.
974 type Project_List_Element
;
975 type Project_List
is access all Project_List_Element
;
976 type Project_List_Element
is record
977 Project
: Project_Id
:= No_Project
;
978 From_Encapsulated_Lib
: Boolean := False;
979 Next
: Project_List
:= null;
981 -- A list of projects
984 (List
: in out Project_List
;
985 Free_Project
: Boolean);
986 -- Free the list of projects, if Free_Project, each project is also freed
988 type Response_File_Format
is
997 -- The format of the different response files
999 type Project_Configuration
is record
1000 Target
: Name_Id
:= No_Name
;
1001 -- The target of the configuration, when specified
1003 Run_Path_Option
: Name_List_Index
:= No_Name_List
;
1004 -- The option to use when linking to specify the path where to look for
1007 Run_Path_Origin
: Name_Id
:= No_Name
;
1008 -- Specify the string (such as "$ORIGIN") to indicate paths relative to
1009 -- the directory of the executable in the run path option.
1011 Library_Install_Name_Option
: Name_Id
:= No_Name
;
1012 -- When this is not an empty list, this option, followed by the single
1013 -- name of the shared library file is used when linking a shared
1016 Separate_Run_Path_Options
: Boolean := False;
1017 -- True if each directory needs to be specified in a separate run path
1020 Executable_Suffix
: Name_Id
:= No_Name
;
1021 -- The suffix of executables, when specified in the configuration or in
1022 -- package Builder of the main project. When this is not specified, the
1023 -- executable suffix is the default for the platform.
1027 Linker
: Path_Name_Type
:= No_Path
;
1028 -- Path name of the linker driver. Specified in the configuration or in
1029 -- the package Builder of the main project.
1031 Map_File_Option
: Name_Id
:= No_Name
;
1032 -- Option to use when invoking the linker to build a map file
1034 Trailing_Linker_Required_Switches
: Name_List_Index
:= No_Name_List
;
1035 -- The minimum options for the linker driver. Specified in the
1038 Linker_Executable_Option
: Name_List_Index
:= No_Name_List
;
1039 -- The option(s) to indicate the name of the executable in the linker
1040 -- command. Specified in the configuration. When not specified, default
1041 -- to -o <executable name>.
1043 Linker_Lib_Dir_Option
: Name_Id
:= No_Name
;
1044 -- The option to specify where to find a library for linking. Specified
1045 -- in the configuration. When not specified, defaults to "-L".
1047 Linker_Lib_Name_Option
: Name_Id
:= No_Name
;
1048 -- The option to specify the name of a library for linking. Specified in
1049 -- the configuration. When not specified, defaults to "-l".
1051 Max_Command_Line_Length
: Natural := 0;
1052 -- When positive and when Resp_File_Format (see below) is not None,
1053 -- if the command line for the invocation of the linker would be greater
1054 -- than this value, a response file is used to invoke the linker.
1056 Resp_File_Format
: Response_File_Format
:= None
;
1057 -- The format of a response file, when linking with a response file is
1060 Resp_File_Options
: Name_List_Index
:= No_Name_List
;
1061 -- The switches, if any, that precede the path name of the response
1062 -- file in the invocation of the linker.
1066 Library_Builder
: Path_Name_Type
:= No_Path
;
1067 -- The executable to build library (specified in the configuration)
1069 Lib_Support
: Library_Support
:= None
;
1070 -- The level of library support. Specified in the configuration. Support
1071 -- is none, static libraries only or both static and shared libraries.
1073 Lib_Encapsulated_Supported
: Boolean := False;
1074 -- True when building fully standalone libraries supported on the target
1076 Archive_Builder
: Name_List_Index
:= No_Name_List
;
1077 -- The name of the executable to build archives, with the minimum
1078 -- switches. Specified in the configuration.
1080 Archive_Builder_Append_Option
: Name_List_Index
:= No_Name_List
;
1081 -- The options to append object files to an archive
1083 Archive_Indexer
: Name_List_Index
:= No_Name_List
;
1084 -- The name of the executable to index archives, with the minimum
1085 -- switches. Specified in the configuration.
1087 Archive_Suffix
: File_Name_Type
:= No_File
;
1088 -- The suffix of archives. Specified in the configuration. When not
1089 -- specified, defaults to ".a".
1091 Lib_Partial_Linker
: Name_List_Index
:= No_Name_List
;
1095 Shared_Lib_Driver
: File_Name_Type
:= No_File
;
1096 -- The driver to link shared libraries. Set with attribute Library_GCC.
1099 Shared_Lib_Prefix
: File_Name_Type
:= No_File
;
1100 -- Part of a shared library file name that precedes the name of the
1101 -- library. Specified in the configuration. When not specified, defaults
1104 Shared_Lib_Suffix
: File_Name_Type
:= No_File
;
1105 -- Suffix of shared libraries, after the library name in the shared
1106 -- library name. Specified in the configuration. When not specified,
1107 -- default to ".so".
1109 Shared_Lib_Min_Options
: Name_List_Index
:= No_Name_List
;
1110 -- The minimum options to use when building a shared library
1112 Lib_Version_Options
: Name_List_Index
:= No_Name_List
;
1113 -- The options to use to specify a library version
1115 Symbolic_Link_Supported
: Boolean := False;
1116 -- True if the platform supports symbolic link files
1118 Lib_Maj_Min_Id_Supported
: Boolean := False;
1119 -- True if platform supports library major and minor options, such as
1120 -- libname.so -> libname.so.2 -> libname.so.2.4
1122 Auto_Init_Supported
: Boolean := False;
1123 -- True if automatic initialisation is supported for shared stand-alone
1127 Default_Project_Config
: constant Project_Configuration
:=
1129 Run_Path_Option
=> No_Name_List
,
1130 Run_Path_Origin
=> No_Name
,
1131 Library_Install_Name_Option
=> No_Name
,
1132 Separate_Run_Path_Options
=> False,
1133 Executable_Suffix
=> No_Name
,
1135 Map_File_Option
=> No_Name
,
1136 Trailing_Linker_Required_Switches
=>
1138 Linker_Executable_Option
=> No_Name_List
,
1139 Linker_Lib_Dir_Option
=> No_Name
,
1140 Linker_Lib_Name_Option
=> No_Name
,
1141 Library_Builder
=> No_Path
,
1142 Max_Command_Line_Length
=> 0,
1143 Resp_File_Format
=> None
,
1144 Resp_File_Options
=> No_Name_List
,
1145 Lib_Support
=> None
,
1146 Lib_Encapsulated_Supported
=> False,
1147 Archive_Builder
=> No_Name_List
,
1148 Archive_Builder_Append_Option
=> No_Name_List
,
1149 Archive_Indexer
=> No_Name_List
,
1150 Archive_Suffix
=> No_File
,
1151 Lib_Partial_Linker
=> No_Name_List
,
1152 Shared_Lib_Driver
=> No_File
,
1153 Shared_Lib_Prefix
=> No_File
,
1154 Shared_Lib_Suffix
=> No_File
,
1155 Shared_Lib_Min_Options
=> No_Name_List
,
1156 Lib_Version_Options
=> No_Name_List
,
1157 Symbolic_Link_Supported
=> False,
1158 Lib_Maj_Min_Id_Supported
=> False,
1159 Auto_Init_Supported
=> False);
1161 -------------------------
1162 -- Aggregated projects --
1163 -------------------------
1165 type Aggregated_Project
;
1166 type Aggregated_Project_List
is access all Aggregated_Project
;
1167 type Aggregated_Project
is record
1168 Path
: Path_Name_Type
;
1169 Tree
: Project_Tree_Ref
;
1170 Project
: Project_Id
;
1171 Next
: Aggregated_Project_List
;
1174 procedure Free
(List
: in out Aggregated_Project_List
);
1175 -- Free the memory used for List
1177 procedure Add_Aggregated_Project
1178 (Project
: Project_Id
;
1179 Path
: Path_Name_Type
);
1180 -- Add a new aggregated project in Project.
1181 -- The aggregated project has not been processed yet. This procedure should
1182 -- the called while processing the aggregate project, and as a result
1183 -- Prj.Proc.Process will then automatically process the aggregated projects
1189 -- The following record describes a project file representation
1191 type Standalone
is (No
, Standard
, Encapsulated
);
1193 type Project_Data
(Qualifier
: Project_Qualifier
:= Unspecified
) is record
1199 Name
: Name_Id
:= No_Name
;
1200 -- The name of the project
1202 Display_Name
: Name_Id
:= No_Name
;
1203 -- The name of the project with the spelling of its declaration
1205 Externally_Built
: Boolean := False;
1206 -- True if the project is externally built. In such case, the Project
1207 -- Manager will not modify anything in this project.
1209 Config
: Project_Configuration
;
1211 Path
: Path_Information
:= No_Path_Information
;
1212 -- The path name of the project file. This include base name of the
1215 Virtual
: Boolean := False;
1216 -- True for virtual extending projects
1218 Location
: Source_Ptr
:= No_Location
;
1219 -- The location in the project file source of the project name that
1220 -- immediately follows the reserved word "project".
1226 Languages
: Language_Ptr
:= No_Language_Index
;
1227 -- First index of the language data in the project.
1228 -- This is an index into the project_tree_data.languages_data.
1229 -- Traversing the list gives access to all the languages supported by
1236 Mains
: String_List_Id
:= Nil_String
;
1237 -- List of mains specified by attribute Main
1239 Extends
: Project_Id
:= No_Project
;
1240 -- The reference of the project file, if any, that this project file
1243 Extended_By
: Project_Id
:= No_Project
;
1244 -- The reference of the project file, if any, that extends this project
1247 Decl
: Declarations
:= No_Declarations
;
1248 -- The declarations (variables, attributes and packages) of this project
1251 Imported_Projects
: Project_List
:= null;
1252 -- The list of all directly imported projects, if any
1254 All_Imported_Projects
: Project_List
:= null;
1255 -- The list of all projects imported directly or indirectly, if any.
1256 -- This does not include the project itself.
1262 Directory
: Path_Information
:= No_Path_Information
;
1263 -- Path name of the directory where the project file resides
1265 Object_Directory
: Path_Information
:= No_Path_Information
;
1266 -- The path name of the object directory of this project file
1268 Exec_Directory
: Path_Information
:= No_Path_Information
;
1269 -- The path name of the exec directory of this project file. Default is
1270 -- equal to Object_Directory.
1272 Object_Path_File
: Path_Name_Type
:= No_Path
;
1273 -- Store the name of the temporary file that contains the list of object
1274 -- directories, when attribute Object_Path_Switches is declared.
1280 Library
: Boolean := False;
1281 -- True if this is a library project
1283 Library_Name
: Name_Id
:= No_Name
;
1284 -- If a library project, name of the library
1286 Library_Kind
: Lib_Kind
:= Static
;
1287 -- If a library project, kind of library
1289 Library_Dir
: Path_Information
:= No_Path_Information
;
1290 -- If a library project, path name of the directory where the library
1293 Library_TS
: Time_Stamp_Type
:= Empty_Time_Stamp
;
1294 -- The timestamp of a library file in a library project
1296 Library_Src_Dir
: Path_Information
:= No_Path_Information
;
1297 -- If a Stand-Alone Library project, path name of the directory where
1298 -- the sources of the interfaces of the library are copied. By default,
1299 -- if attribute Library_Src_Dir is not specified, sources of the
1300 -- interfaces are not copied anywhere.
1302 Library_ALI_Dir
: Path_Information
:= No_Path_Information
;
1303 -- In a library project, path name of the directory where the ALI files
1304 -- are copied. If attribute Library_ALI_Dir is not specified, ALI files
1305 -- are copied in the Library_Dir.
1307 Lib_Internal_Name
: Name_Id
:= No_Name
;
1308 -- If a library project, internal name store inside the library
1310 Standalone_Library
: Standalone
:= No
;
1311 -- Indicate that this is a Standalone Library Project File
1313 Lib_Interface_ALIs
: String_List_Id
:= Nil_String
;
1314 -- For Standalone Library Project Files, indicate the list of Interface
1317 Lib_Auto_Init
: Boolean := False;
1318 -- For non static Stand-Alone Library Project Files, indicate if
1319 -- the library initialisation should be automatic.
1321 Symbol_Data
: Symbol_Record
:= No_Symbols
;
1322 -- Symbol file name, reference symbol file name, symbol policy
1324 Need_To_Build_Lib
: Boolean := False;
1325 -- Indicates that the library of a Library Project needs to be built or
1331 -- The sources for all languages including Ada are accessible through
1332 -- the Source_Iterator type
1334 Interfaces_Defined
: Boolean := False;
1335 -- True if attribute Interfaces is declared for the project or any
1336 -- project it extends.
1338 Include_Path_File
: Path_Name_Type
:= No_Path
;
1339 -- The path name of the of the source search directory file.
1340 -- This is only used by gnatmake
1342 Source_Dirs
: String_List_Id
:= Nil_String
;
1343 -- The list of all the source directories
1345 Source_Dir_Ranks
: Number_List_Index
:= No_Number_List
;
1347 Ada_Include_Path
: String_Access
:= null;
1348 -- The cached value of source search path for this project file. Set by
1349 -- the first call to Prj.Env.Ada_Include_Path for the project. Do not
1350 -- use this field directly outside of the project manager, use
1351 -- Prj.Env.Ada_Include_Path instead.
1353 Has_Multi_Unit_Sources
: Boolean := False;
1354 -- Whether there is at least one source file containing multiple units
1360 Ada_Objects_Path
: String_Access
:= null;
1361 -- The cached value of ADA_OBJECTS_PATH for this project file. Do not
1362 -- use this field directly outside of the compiler, use
1363 -- Prj.Env.Ada_Objects_Path instead.
1365 Libgnarl_Needed
: Yes_No_Unknown
:= Unknown
;
1366 -- Set to True when libgnarl is needed to link
1368 Objects_Path
: String_Access
:= null;
1369 -- The cached value of the object dir path, used during the binding
1370 -- phase of gprbuild.
1372 Objects_Path_File_With_Libs
: Path_Name_Type
:= No_Path
;
1373 -- The cached value of the object path temp file (including library
1374 -- dirs) for this project file.
1376 Objects_Path_File_Without_Libs
: Path_Name_Type
:= No_Path
;
1377 -- The cached value of the object path temp file (excluding library
1378 -- dirs) for this project file.
1380 Config_File_Name
: Path_Name_Type
:= No_Path
;
1381 -- The path name of the configuration pragmas file, if any
1383 Config_File_Temp
: Boolean := False;
1384 -- An indication that the configuration pragmas file is a temporary file
1385 -- that must be deleted at the end.
1387 Config_Checked
: Boolean := False;
1388 -- A flag to avoid checking repetitively the configuration pragmas file
1390 Depth
: Natural := 0;
1391 -- The maximum depth of a project in the project graph. Depth of main
1394 Unkept_Comments
: Boolean := False;
1395 -- True if there are comments in the project sources that cannot be kept
1396 -- in the project tree.
1398 -----------------------------
1399 -- Qualifier-Specific data --
1400 -----------------------------
1402 -- The following fields are only valid for specific types of projects
1405 when Aggregate | Aggregate_Library
=>
1406 Aggregated_Projects
: Aggregated_Project_List
:= null;
1407 -- List of aggregated projects (which could themselves be
1408 -- aggregate projects).
1415 function Empty_Project
(Qualifier
: Project_Qualifier
) return Project_Data
;
1416 -- Return the representation of an empty project
1418 function Is_Extending
1419 (Extending
: Project_Id
;
1420 Extended
: Project_Id
) return Boolean;
1421 -- Return True if Extending is extending the Extended project
1424 (Extending
: Project_Id
;
1425 Extended
: Project_Id
) return Boolean renames Is_Extending
;
1427 function Has_Ada_Sources
(Data
: Project_Id
) return Boolean;
1428 -- Return True if the project has Ada sources
1430 Project_Error
: exception;
1431 -- Raised by some subprograms in Prj.Attr
1433 package Units_Htable
is new Simple_HTable
1434 (Header_Num
=> Header_Num
,
1435 Element
=> Unit_Index
,
1436 No_Element
=> No_Unit_Index
,
1440 -- Mapping of unit names to indexes in the Units table
1442 ---------------------
1443 -- Source_Iterator --
1444 ---------------------
1446 type Source_Iterator
is private;
1448 function For_Each_Source
1449 (In_Tree
: Project_Tree_Ref
;
1450 Project
: Project_Id
:= No_Project
;
1451 Language
: Name_Id
:= No_Name
;
1452 Encapsulated_Libs
: Boolean := True) return Source_Iterator
;
1453 -- Returns an iterator for all the sources of a project tree, or a specific
1454 -- project, or a specific language. Include sources from aggregated libs if
1455 -- Aggregated_Libs is True.
1457 function Element
(Iter
: Source_Iterator
) return Source_Id
;
1458 -- Return the current source (or No_Source if there are no more sources)
1460 procedure Next
(Iter
: in out Source_Iterator
);
1461 -- Move on to the next source
1463 function Find_Source
1464 (In_Tree
: Project_Tree_Ref
;
1465 Project
: Project_Id
;
1466 In_Imported_Only
: Boolean := False;
1467 In_Extended_Only
: Boolean := False;
1468 Base_Name
: File_Name_Type
;
1469 Index
: Int
:= 0) return Source_Id
;
1470 -- Find the first source file with the given name.
1471 -- If In_Extended_Only is True, it will search in project and the project
1472 -- it extends, but not in the imported projects.
1473 -- Elsif In_Imported_Only is True, it will search in project and the
1474 -- projects it imports, but not in the others or in aggregated projects.
1475 -- Else it searches in the whole tree.
1476 -- If Index is specified, this only search for a source with that index.
1478 -----------------------
1479 -- Project_Tree_Data --
1480 -----------------------
1482 package Replaced_Source_HTable
is new Simple_HTable
1483 (Header_Num
=> Header_Num
,
1484 Element
=> File_Name_Type
,
1485 No_Element
=> No_File
,
1486 Key
=> File_Name_Type
,
1490 type Private_Project_Tree_Data
is private;
1491 -- Data for a project tree that is used only by the Project Manager
1493 type Shared_Project_Tree_Data
is record
1494 Name_Lists
: Name_List_Table
.Instance
;
1495 Number_Lists
: Number_List_Table
.Instance
;
1496 String_Elements
: String_Element_Table
.Instance
;
1497 Variable_Elements
: Variable_Element_Table
.Instance
;
1498 Array_Elements
: Array_Element_Table
.Instance
;
1499 Arrays
: Array_Table
.Instance
;
1500 Packages
: Package_Table
.Instance
;
1501 Private_Part
: Private_Project_Tree_Data
;
1503 type Shared_Project_Tree_Data_Access
is access all Shared_Project_Tree_Data
;
1504 -- The data that is shared among multiple trees, when these trees are
1505 -- loaded through the same aggregate project.
1506 -- To avoid ambiguities, limit the number of parameters to the
1507 -- subprograms (we would have to parse the "root project tree" since this
1508 -- is where the configuration file was loaded, in addition to the project's
1509 -- own tree) and make the comparison of projects easier, all trees store
1510 -- the lists in the same tables.
1512 type Project_Tree_Appdata
is tagged null record;
1513 type Project_Tree_Appdata_Access
is access all Project_Tree_Appdata
'Class;
1514 -- Application-specific data that can be associated with a project tree.
1515 -- We do not make the Project_Tree_Data itself tagged for several reasons:
1516 -- - it couldn't have a default value for its discriminant
1517 -- - it would require a "factory" to allocate such data, because trees
1518 -- are created automatically when parsing aggregate projects.
1520 procedure Free
(Tree
: in out Project_Tree_Appdata
);
1521 -- Should be overridden if your derive your own data
1523 type Project_Tree_Data
(Is_Root_Tree
: Boolean := True) is record
1524 -- The root tree is the one loaded by the user from the command line.
1525 -- Is_Root_Tree is only false for projects aggregated within a root
1526 -- aggregate project.
1528 Projects
: Project_List
;
1529 -- List of projects in this tree
1531 Replaced_Sources
: Replaced_Source_HTable
.Instance
;
1532 -- The list of sources that have been replaced by sources with
1533 -- different file names.
1535 Replaced_Source_Number
: Natural := 0;
1536 -- The number of entries in Replaced_Sources
1538 Units_HT
: Units_Htable
.Instance
;
1539 -- Unit name to Unit_Index (and from there to Source_Id)
1541 Source_Files_HT
: Source_Files_Htable
.Instance
;
1542 -- Base source file names to Source_Id list
1544 Source_Paths_HT
: Source_Paths_Htable
.Instance
;
1545 -- Full path to Source_Id
1546 -- ??? What is behavior for multi-unit source files, where there are
1547 -- several source_id per file ?
1549 Source_Info_File_Name
: String_Access
:= null;
1550 -- The name of the source info file, if specified by the builder
1552 Source_Info_File_Exists
: Boolean := False;
1553 -- True when a source info file has been successfully read
1555 Shared
: Shared_Project_Tree_Data_Access
;
1556 -- The shared data for this tree and all aggregated trees
1558 Appdata
: Project_Tree_Appdata_Access
;
1559 -- Application-specific data for this tree
1561 case Is_Root_Tree
is
1563 Shared_Data
: aliased Shared_Project_Tree_Data
;
1564 -- Do not access directly, only through Shared
1570 -- Data for a project tree
1572 function Debug_Name
(Tree
: Project_Tree_Ref
) return Name_Id
;
1573 -- If debug traces are activated, return an identitier for the project
1574 -- tree. This modifies Name_Buffer.
1576 procedure Expect
(The_Token
: Token_Type
; Token_Image
: String);
1577 -- Check that the current token is The_Token. If it is not, then output
1578 -- an error message.
1580 procedure Initialize
(Tree
: Project_Tree_Ref
);
1581 -- This procedure must be called before using any services from the Prj
1582 -- hierarchy. Namet.Initialize must be called before Prj.Initialize.
1584 procedure Reset
(Tree
: Project_Tree_Ref
);
1585 -- This procedure resets all the tables that are used when processing a
1586 -- project file tree. Initialize must be called before the call to Reset.
1588 package Project_Boolean_Htable
is new Simple_HTable
1589 (Header_Num
=> Header_Num
,
1591 No_Element
=> False,
1595 -- A table that associates a project to a boolean. This is used to detect
1596 -- whether a project was already processed for instance.
1599 with procedure Action
(Project
: Project_Id
; Tree
: Project_Tree_Ref
);
1600 procedure For_Project_And_Aggregated
1601 (Root_Project
: Project_Id
;
1602 Root_Tree
: Project_Tree_Ref
);
1603 -- Execute Action for Root_Project and all its aggregated projects
1607 type State
is limited private;
1608 with procedure Action
1609 (Project
: Project_Id
;
1610 Tree
: Project_Tree_Ref
;
1611 With_State
: in out State
);
1612 procedure For_Every_Project_Imported
1614 Tree
: Project_Tree_Ref
;
1615 With_State
: in out State
;
1616 Include_Aggregated
: Boolean := True;
1617 Imported_First
: Boolean := False);
1618 -- Call Action for each project imported directly or indirectly by project
1619 -- By, as well as extended projects.
1621 -- The order of processing depends on Imported_First:
1623 -- If False, Action is called according to the order of importation: if A
1624 -- imports B, directly or indirectly, Action will be called for A before
1625 -- it is called for B. If two projects import each other directly or
1626 -- indirectly (using at least one "limited with"), it is not specified
1627 -- for which of these two projects Action will be called first.
1629 -- The order is reversed if Imported_First is True
1631 -- With_State may be used by Action to choose a behavior or to report some
1634 -- If Include_Aggregated is True, then an aggregate project will recurse
1635 -- into the projects it aggregates. Otherwise, the latter are never
1638 -- In_Aggregate_Lib is True if the project is in an aggregate library
1640 -- The Tree argument passed to the callback is required in the case of
1641 -- aggregated projects, since they might not be using the same tree as 'By'
1643 type Project_Context
is record
1644 In_Aggregate_Lib
: Boolean;
1645 -- True if the project is part of an aggregate library
1647 From_Encapsulated_Lib
: Boolean;
1648 -- True if the project is imported from an encapsulated library
1652 type State
is limited private;
1653 with procedure Action
1654 (Project
: Project_Id
;
1655 Tree
: Project_Tree_Ref
;
1656 Context
: Project_Context
;
1657 With_State
: in out State
);
1658 procedure For_Every_Project_Imported_Context
1660 Tree
: Project_Tree_Ref
;
1661 With_State
: in out State
;
1662 Include_Aggregated
: Boolean := True;
1663 Imported_First
: Boolean := False);
1664 -- As for For_Every_Project_Imported but with an associated context
1667 with procedure Action
1668 (Project
: Project_Id
;
1669 Tree
: Project_Tree_Ref
;
1670 Context
: Project_Context
);
1671 procedure For_Project_And_Aggregated_Context
1672 (Root_Project
: Project_Id
;
1673 Root_Tree
: Project_Tree_Ref
);
1674 -- As for For_Project_And_Aggregated but with an associated context
1676 function Extend_Name
1677 (File
: File_Name_Type
;
1678 With_Suffix
: String) return File_Name_Type
;
1679 -- Replace the extension of File with With_Suffix
1681 function Object_Name
1682 (Source_File_Name
: File_Name_Type
;
1683 Object_File_Suffix
: Name_Id
:= No_Name
) return File_Name_Type
;
1684 -- Returns the object file name corresponding to a source file name
1686 function Object_Name
1687 (Source_File_Name
: File_Name_Type
;
1689 Index_Separator
: Character;
1690 Object_File_Suffix
: Name_Id
:= No_Name
) return File_Name_Type
;
1691 -- Returns the object file name corresponding to a unit in a multi-source
1694 function Dependency_Name
1695 (Source_File_Name
: File_Name_Type
;
1696 Dependency
: Dependency_File_Kind
) return File_Name_Type
;
1697 -- Returns the dependency file name corresponding to a source file name
1699 function Switches_Name
1700 (Source_File_Name
: File_Name_Type
) return File_Name_Type
;
1701 -- Returns the switches file name corresponding to a source file name
1703 procedure Set_Path_File_Var
(Name
: String; Value
: String);
1704 -- Call Setenv, after calling To_Host_File_Spec
1706 function Current_Source_Path_File_Of
1707 (Shared
: Shared_Project_Tree_Data_Access
) return Path_Name_Type
;
1708 -- Get the current include path file name
1710 procedure Set_Current_Source_Path_File_Of
1711 (Shared
: Shared_Project_Tree_Data_Access
;
1712 To
: Path_Name_Type
);
1713 -- Record the current include path file name
1715 function Current_Object_Path_File_Of
1716 (Shared
: Shared_Project_Tree_Data_Access
) return Path_Name_Type
;
1717 -- Get the current object path file name
1719 procedure Set_Current_Object_Path_File_Of
1720 (Shared
: Shared_Project_Tree_Data_Access
;
1721 To
: Path_Name_Type
);
1722 -- Record the current object path file name
1728 type Processing_Flags
is private;
1729 -- Flags used while parsing and processing a project tree to configure the
1730 -- behavior of the parser, and indicate how to report error messages. This
1731 -- structure does not allocate memory and never needs to be freed
1733 type Error_Warning
is (Silent
, Warning
, Error
);
1734 -- Severity of some situations, such as: no Ada sources in a project where
1735 -- Ada is one of the language.
1737 -- When the situation occurs, the behaviour depends on the setting:
1739 -- - Silent: no action
1740 -- - Warning: issue a warning, does not cause the tool to fail
1741 -- - Error: issue an error, causes the tool to fail
1743 type Error_Handler
is access procedure
1744 (Project
: Project_Id
;
1745 Is_Warning
: Boolean);
1746 -- This warns when an error was found when parsing a project. The error
1747 -- itself is handled through Prj.Err (and Prj.Err.Finalize should be called
1748 -- to actually print the error). This ensures that duplicate error messages
1749 -- are always correctly removed, that errors msgs are sorted, and that all
1750 -- tools will report the same error to the user.
1752 function Create_Flags
1753 (Report_Error
: Error_Handler
;
1754 When_No_Sources
: Error_Warning
;
1755 Require_Sources_Other_Lang
: Boolean := True;
1756 Allow_Duplicate_Basenames
: Boolean := True;
1757 Compiler_Driver_Mandatory
: Boolean := False;
1758 Error_On_Unknown_Language
: Boolean := True;
1759 Require_Obj_Dirs
: Error_Warning
:= Error
;
1760 Allow_Invalid_External
: Error_Warning
:= Error
;
1761 Missing_Source_Files
: Error_Warning
:= Error
;
1762 Ignore_Missing_With
: Boolean := False)
1763 return Processing_Flags
;
1764 -- Function used to create Processing_Flags structure
1766 -- If Allow_Duplicate_Basenames, then files with the same base names are
1767 -- authorized within a project for source-based languages (never for unit
1768 -- based languages).
1770 -- If Compiler_Driver_Mandatory is true, then a Compiler.Driver attribute
1771 -- for each language must be defined, or we will not look for its source
1774 -- When_No_Sources indicates what should be done when no sources of a
1775 -- language are found in a project where this language is declared.
1776 -- If Require_Sources_Other_Lang is true, then all languages must have at
1777 -- least one source file, or an error is reported via When_No_Sources. If
1778 -- it is false, this is only required for Ada (and only if it is a language
1779 -- of the project). When this parameter is set to False, we do not check
1780 -- that a proper naming scheme is defined for languages other than Ada.
1782 -- If Report_Error is null, use the standard error reporting mechanism
1783 -- (Errout). Otherwise, report errors using Report_Error.
1785 -- If Error_On_Unknown_Language is true, an error is displayed if some of
1786 -- the source files listed in the project do not match any naming scheme
1788 -- If Require_Obj_Dirs is true, then all object directories must exist
1789 -- (possibly after they have been created automatically if the appropriate
1790 -- switches were specified), or an error is raised.
1792 -- If Allow_Invalid_External is Silent, then no error is reported when an
1793 -- invalid value is used for an external variable (and it doesn't match its
1794 -- type). Instead, the first possible value is used.
1796 -- Missing_Source_Files indicates whether it is an error or a warning that
1797 -- a source file mentioned in the Source_Files attributes is not actually
1798 -- found in the source directories. This also impacts errors for missing
1799 -- source directories.
1801 -- If Ignore_Missing_With is True, then a "with" statement that cannot be
1802 -- resolved will simply be ignored. However, in such a case, the flag
1803 -- Incomplete_With in the project tree will be set to True.
1804 -- This is meant for use by tools so that they can properly set the
1805 -- project path in such a case:
1806 -- * no "gnatls" found (so no default project path)
1807 -- * user project sets Project.IDE'gnatls attribute to a cross gnatls
1808 -- * user project also includes a "with" that can only be resolved
1809 -- once we have found the gnatls
1811 Gprbuild_Flags
: constant Processing_Flags
;
1812 Gprclean_Flags
: constant Processing_Flags
;
1813 Gnatmake_Flags
: constant Processing_Flags
;
1814 -- Flags used by the various tools. They all display the error messages
1821 procedure Record_Temp_File
1822 (Shared
: Shared_Project_Tree_Data_Access
;
1823 Path
: Path_Name_Type
);
1824 -- Record the path of a newly created temporary file, so that it can be
1827 procedure Delete_All_Temp_Files
1828 (Shared
: Shared_Project_Tree_Data_Access
);
1829 -- Delete all recorded temporary files.
1830 -- Does nothing if Debug.Debug_Flag_N is set
1832 procedure Delete_Temp_Config_Files
(Project_Tree
: Project_Tree_Ref
);
1833 -- Delete all temporary config files. Does nothing if Debug.Debug_Flag_N is
1834 -- set or if Project_Tree is null. This initially came from gnatmake
1835 -- ??? Should this be combined with Delete_All_Temp_Files above
1837 procedure Delete_Temporary_File
1838 (Shared
: Shared_Project_Tree_Data_Access
:= null;
1839 Path
: Path_Name_Type
);
1840 -- Delete a temporary file from the disk. The file is also removed from the
1841 -- list of temporary files to delete at the end of the program, in case
1842 -- another program running on the same machine has recreated it. Does
1843 -- nothing if Debug.Debug_Flag_N is set
1845 Virtual_Prefix
: constant String := "v$";
1846 -- The prefix for virtual extending projects. Because of the '$', which is
1847 -- normally forbidden for project names, there cannot be any name clash.
1853 type Verbosity
is (Default
, Medium
, High
);
1854 pragma Ordered
(Verbosity
);
1855 -- Verbosity when parsing GNAT Project Files
1856 -- Default is default (very quiet, if no errors).
1857 -- Medium is more verbose.
1858 -- High is extremely verbose.
1860 Current_Verbosity
: Verbosity
:= Default
;
1861 -- The current value of the verbosity the project files are parsed with
1863 procedure Debug_Indent
;
1864 -- Inserts a series of blanks depending on the current indentation level
1866 procedure Debug_Output
(Str
: String);
1867 procedure Debug_Output
(Str
: String; Str2
: Name_Id
);
1868 -- If Current_Verbosity is not Default, outputs Str.
1869 -- This indents Str based on the current indentation level for traces
1870 -- Debug_Error is intended to be used to report an error in the traces.
1872 procedure Debug_Increase_Indent
1873 (Str
: String := ""; Str2
: Name_Id
:= No_Name
);
1874 procedure Debug_Decrease_Indent
(Str
: String := "");
1875 -- Increase or decrease the indentation level for debug traces. This
1876 -- indentation level only affects output done through Debug_Output.
1880 All_Packages
: constant String_List_Access
:= null;
1882 No_Project_Tree
: constant Project_Tree_Ref
:= null;
1884 Ignored
: constant Variable_Kind
:= Single
;
1886 Nil_Variable_Value
: constant Variable_Value
:=
1887 (Project
=> No_Project
,
1889 Location
=> No_Location
,
1892 type Source_Iterator
is record
1893 In_Tree
: Project_Tree_Ref
;
1895 Project
: Project_List
;
1896 All_Projects
: Boolean;
1897 -- Current project and whether we should move on to the next
1899 Language
: Language_Ptr
;
1900 -- Current language processed
1902 Language_Name
: Name_Id
;
1903 -- Only sources of this language will be returned (or all if No_Name)
1905 Current
: Source_Id
;
1907 Encapsulated_Libs
: Boolean;
1908 -- True if we want to include the sources from encapsulated libs
1911 procedure Add_To_Buffer
1913 To
: in out String_Access
;
1914 Last
: in out Natural);
1915 -- Append a String to the Buffer
1917 package Temp_Files_Table
is new GNAT
.Dynamic_Tables
1918 (Table_Component_Type
=> Path_Name_Type
,
1919 Table_Index_Type
=> Integer,
1920 Table_Low_Bound
=> 1,
1921 Table_Initial
=> 10,
1922 Table_Increment
=> 10);
1923 -- Table to store the path name of all the created temporary files, so that
1924 -- they can be deleted at the end, or when the program is interrupted.
1926 type Private_Project_Tree_Data
is record
1927 Temp_Files
: Temp_Files_Table
.Instance
;
1928 -- Temporary files created as part of running tools (pragma files,
1929 -- mapping files,...)
1931 Current_Source_Path_File
: Path_Name_Type
:= No_Path
;
1932 -- Current value of project source path file env var. Used to avoid
1933 -- setting the env var to the same value. When different from No_Path,
1934 -- this indicates that logical names (VMS) or environment variables were
1935 -- created and should be deassigned to avoid polluting the environment
1939 Current_Object_Path_File
: Path_Name_Type
:= No_Path
;
1940 -- Current value of project object path file env var. Used to avoid
1941 -- setting the env var to the same value.
1945 -- Type to represent the part of a project tree which is private to the
1948 type Processing_Flags
is record
1949 Require_Sources_Other_Lang
: Boolean;
1950 Report_Error
: Error_Handler
;
1951 When_No_Sources
: Error_Warning
;
1952 Allow_Duplicate_Basenames
: Boolean;
1953 Compiler_Driver_Mandatory
: Boolean;
1954 Error_On_Unknown_Language
: Boolean;
1955 Require_Obj_Dirs
: Error_Warning
;
1956 Allow_Invalid_External
: Error_Warning
;
1957 Missing_Source_Files
: Error_Warning
;
1958 Ignore_Missing_With
: Boolean;
1961 Gprbuild_Flags
: constant Processing_Flags
:=
1962 (Report_Error
=> null,
1963 When_No_Sources
=> Warning
,
1964 Require_Sources_Other_Lang
=> True,
1965 Allow_Duplicate_Basenames
=> False,
1966 Compiler_Driver_Mandatory
=> True,
1967 Error_On_Unknown_Language
=> True,
1968 Require_Obj_Dirs
=> Error
,
1969 Allow_Invalid_External
=> Error
,
1970 Missing_Source_Files
=> Error
,
1971 Ignore_Missing_With
=> False);
1973 Gprclean_Flags
: constant Processing_Flags
:=
1974 (Report_Error
=> null,
1975 When_No_Sources
=> Warning
,
1976 Require_Sources_Other_Lang
=> True,
1977 Allow_Duplicate_Basenames
=> False,
1978 Compiler_Driver_Mandatory
=> True,
1979 Error_On_Unknown_Language
=> True,
1980 Require_Obj_Dirs
=> Warning
,
1981 Allow_Invalid_External
=> Error
,
1982 Missing_Source_Files
=> Error
,
1983 Ignore_Missing_With
=> False);
1985 Gnatmake_Flags
: constant Processing_Flags
:=
1986 (Report_Error
=> null,
1987 When_No_Sources
=> Error
,
1988 Require_Sources_Other_Lang
=> False,
1989 Allow_Duplicate_Basenames
=> False,
1990 Compiler_Driver_Mandatory
=> False,
1991 Error_On_Unknown_Language
=> False,
1992 Require_Obj_Dirs
=> Error
,
1993 Allow_Invalid_External
=> Error
,
1994 Missing_Source_Files
=> Error
,
1995 Ignore_Missing_With
=> False);