1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2009, 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;
34 with Scans; use Scans;
35 with Types; use Types;
37 with GNAT.Dynamic_HTables; use GNAT.Dynamic_HTables;
38 with GNAT.Dynamic_Tables;
39 with GNAT.OS_Lib; use GNAT.OS_Lib;
43 All_Other_Names : constant Name_Id := Names_High_Bound;
44 -- Name used to replace others as an index of an associative array
45 -- attribute in situations where this is allowed.
47 Subdirs_Option : constant String := "--subdirs=";
48 -- Switch used to indicate that the real directories (object, exec,
49 -- library, ...) are subdirectories of those in the project file.
51 Subdirs : String_Ptr := null;
52 -- The value after the equal sign in switch --subdirs=...
53 -- Contains the relative subdirectory.
55 type Library_Support is (None, Static_Only, Full);
56 -- Support for Library Project File.
57 -- - None: Library Project Files are not supported at all
58 -- - Static_Only: Library Project Files are only supported for static
60 -- - Full: Library Project Files are supported for static and dynamic
61 -- (shared) libraries.
63 type Yes_No_Unknown is (Yes, No, Unknown);
64 -- Tri-state to decide if -lgnarl is needed when linking
66 type Mode is (Multi_Language, Ada_Only);
67 -- Ada_Only: mode for gnatmake, gnatclean, gnatname, the GNAT driver
68 -- Multi_Language: mode for gprbuild, gprclean
70 type Project_Qualifier is
77 -- Qualifiers that can prefix the reserved word "project" in a project
79 -- Standard: standard project ...
80 -- Library: library project is ...
81 -- Dry: abstract project is
82 -- Aggregate: aggregate project is
83 -- Aggregate_Library: aggregate library project is ...
85 function Get_Mode return Mode;
86 pragma Inline (Get_Mode);
88 procedure Set_Mode (New_Mode : Mode);
89 pragma Inline (Set_Mode);
91 Default_Language_Is_Ada : Boolean := True;
92 -- If no language was defined in the project or the configuration file, it
93 -- is an error, unless this variable is True, in which case it defaults to
94 -- Ada. Calling Set_Mode will reset this variable, default is for Ada_Only.
96 Must_Check_Configuration : Boolean := False;
97 -- True when the contents of the configuration file must be checked. This
98 -- is in general only needed by gprbuild itself, since other applications
99 -- can ignore such errors when they don't need to build directly. Calling
100 -- Set_Mode will reset this variable, default is for Ada_Only.
102 All_Packages : constant String_List_Access;
103 -- Default value of parameter Packages of procedures Parse, in Prj.Pars and
104 -- Prj.Part, indicating that all packages should be checked.
106 type Project_Tree_Data;
107 type Project_Tree_Ref is access all Project_Tree_Data;
108 -- Reference to a project tree. Several project trees may exist in memory
111 No_Project_Tree : constant Project_Tree_Ref;
113 procedure Free (Tree : in out Project_Tree_Ref);
114 -- Free memory associated with the tree
116 function Default_Ada_Spec_Suffix return File_Name_Type;
117 pragma Inline (Default_Ada_Spec_Suffix);
118 -- The name for the standard GNAT suffix for Ada spec source file name
119 -- ".ads". Initialized by Prj.Initialize.
121 function Default_Ada_Body_Suffix return File_Name_Type;
122 pragma Inline (Default_Ada_Body_Suffix);
123 -- The name for the standard GNAT suffix for Ada body source file name
124 -- ".adb". Initialized by Prj.Initialize.
126 function Slash return Path_Name_Type;
127 pragma Inline (Slash);
128 -- "/", used as the path of locally removed files
130 Config_Project_File_Extension : String := ".cgpr";
131 Project_File_Extension : String := ".gpr";
132 -- The standard config and user project file name extensions. They are not
133 -- constants, because Canonical_Case_File_Name is called on these variables
134 -- in the body of Prj.
136 type Error_Warning is (Silent, Warning, Error);
137 -- Severity of some situations, such as: no Ada sources in a project where
138 -- Ada is one of the language.
140 -- When the situation occurs, the behaviour depends on the setting:
142 -- - Silent: no action
143 -- - Warning: issue a warning, does not cause the tool to fail
144 -- - Error: issue an error, causes the tool to fail
146 function Empty_File return File_Name_Type;
147 function Empty_String return Name_Id;
148 -- Return the id for an empty string ""
150 type Path_Information is record
151 Name : Path_Name_Type := No_Path;
152 Display_Name : Path_Name_Type := No_Path;
155 No_Path_Information : constant Path_Information := (No_Path, No_Path);
158 type Project_Id is access all Project_Data;
159 No_Project : constant Project_Id := null;
160 -- Id of a Project File
162 type String_List_Id is new Nat;
163 Nil_String : constant String_List_Id := 0;
164 type String_Element is record
165 Value : Name_Id := No_Name;
167 Display_Value : Name_Id := No_Name;
168 Location : Source_Ptr := No_Location;
169 Flag : Boolean := False;
170 Next : String_List_Id := Nil_String;
172 -- To hold values for string list variables and array elements.
173 -- Component Flag may be used for various purposes. For source
174 -- directories, it indicates if the directory contains Ada source(s).
176 package String_Element_Table is new GNAT.Dynamic_Tables
177 (Table_Component_Type => String_Element,
178 Table_Index_Type => String_List_Id,
179 Table_Low_Bound => 1,
180 Table_Initial => 200,
181 Table_Increment => 100);
182 -- The table for string elements in string lists
184 type Variable_Kind is (Undefined, List, Single);
185 -- Different kinds of variables
187 subtype Defined_Variable_Kind is Variable_Kind range List .. Single;
188 -- The defined kinds of variables
190 Ignored : constant Variable_Kind;
191 -- Used to indicate that a package declaration must be ignored
192 -- while processing the project tree (unknown package name).
194 type Variable_Value (Kind : Variable_Kind := Undefined) is record
195 Project : Project_Id := No_Project;
196 Location : Source_Ptr := No_Location;
197 Default : Boolean := False;
202 Values : String_List_Id := Nil_String;
204 Value : Name_Id := No_Name;
208 -- Values for variables and array elements. Default is True if the
209 -- current value is the default one for the variable
211 Nil_Variable_Value : constant Variable_Value;
212 -- Value of a non existing variable or array element
214 type Variable_Id is new Nat;
215 No_Variable : constant Variable_Id := 0;
216 type Variable is record
217 Next : Variable_Id := No_Variable;
219 Value : Variable_Value;
221 -- To hold the list of variables in a project file and in packages
223 package Variable_Element_Table is new GNAT.Dynamic_Tables
224 (Table_Component_Type => Variable,
225 Table_Index_Type => Variable_Id,
226 Table_Low_Bound => 1,
227 Table_Initial => 200,
228 Table_Increment => 100);
229 -- The table of variable in list of variables
231 type Array_Element_Id is new Nat;
232 No_Array_Element : constant Array_Element_Id := 0;
233 type Array_Element is record
235 Src_Index : Int := 0;
236 Index_Case_Sensitive : Boolean := True;
237 Value : Variable_Value;
238 Next : Array_Element_Id := No_Array_Element;
240 -- Each Array_Element represents an array element and is linked (Next)
241 -- to the next array element, if any, in the array.
243 package Array_Element_Table is new GNAT.Dynamic_Tables
244 (Table_Component_Type => Array_Element,
245 Table_Index_Type => Array_Element_Id,
246 Table_Low_Bound => 1,
247 Table_Initial => 200,
248 Table_Increment => 100);
249 -- The table that contains all array elements
251 type Array_Id is new Nat;
252 No_Array : constant Array_Id := 0;
253 type Array_Data is record
254 Name : Name_Id := No_Name;
255 Location : Source_Ptr := No_Location;
256 Value : Array_Element_Id := No_Array_Element;
257 Next : Array_Id := No_Array;
259 -- Each Array_Data value represents an array.
260 -- Value is the id of the first element.
261 -- Next is the id of the next array in the project file or package.
263 package Array_Table is new GNAT.Dynamic_Tables
264 (Table_Component_Type => Array_Data,
265 Table_Index_Type => Array_Id,
266 Table_Low_Bound => 1,
267 Table_Initial => 200,
268 Table_Increment => 100);
269 -- The table that contains all arrays
271 type Package_Id is new Nat;
272 No_Package : constant Package_Id := 0;
273 type Declarations is record
274 Variables : Variable_Id := No_Variable;
275 Attributes : Variable_Id := No_Variable;
276 Arrays : Array_Id := No_Array;
277 Packages : Package_Id := No_Package;
279 -- Contains the declarations (variables, single and array attributes,
280 -- packages) for a project or a package in a project.
282 No_Declarations : constant Declarations :=
283 (Variables => No_Variable,
284 Attributes => No_Variable,
286 Packages => No_Package);
287 -- Default value of Declarations: indicates that there is no declarations
289 type Package_Element is record
290 Name : Name_Id := No_Name;
291 Decl : Declarations := No_Declarations;
292 Parent : Package_Id := No_Package;
293 Next : Package_Id := No_Package;
295 -- A package (includes declarations that may include other packages)
297 package Package_Table is new GNAT.Dynamic_Tables
298 (Table_Component_Type => Package_Element,
299 Table_Index_Type => Package_Id,
300 Table_Low_Bound => 1,
301 Table_Initial => 100,
302 Table_Increment => 100);
303 -- The table that contains all packages
306 type Language_Ptr is access all Language_Data;
307 -- Index of language data
309 No_Language_Index : constant Language_Ptr := null;
310 -- Constant indicating that there is no language data
312 Max_Header_Num : constant := 6150;
313 type Header_Num is range 0 .. Max_Header_Num;
314 -- Size for hash table below. The upper bound is an arbitrary value, the
315 -- value here was chosen after testing to determine a good compromise
316 -- between speed of access and memory usage.
318 function Hash (Name : Name_Id) return Header_Num;
319 function Hash (Name : File_Name_Type) return Header_Num;
320 function Hash (Name : Path_Name_Type) return Header_Num;
321 function Hash (Project : Project_Id) return Header_Num;
322 -- Used for computing hash values for names put into above hash table
324 type Language_Kind is (File_Based, Unit_Based);
325 -- Type for the kind of language. All languages are file based, except Ada
326 -- which is unit based.
328 type Dependency_File_Kind is (None, Makefile, ALI_File);
329 -- Type of dependency to be checked: no dependency file, Makefile fragment
330 -- or ALI file (for Ada).
332 Makefile_Dependency_Suffix : constant String := ".d";
333 ALI_Dependency_Suffix : constant String := ".ali";
335 Switches_Dependency_Suffix : constant String := ".cswi";
337 Binder_Exchange_Suffix : constant String := ".bexch";
338 -- Suffix for binder exchange files
340 Library_Exchange_Suffix : constant String := ".lexch";
341 -- Suffix for library exchange files
343 type Name_List_Index is new Nat;
344 No_Name_List : constant Name_List_Index := 0;
346 type Name_Node is record
347 Name : Name_Id := No_Name;
348 Next : Name_List_Index := No_Name_List;
351 package Name_List_Table is new GNAT.Dynamic_Tables
352 (Table_Component_Type => Name_Node,
353 Table_Index_Type => Name_List_Index,
354 Table_Low_Bound => 1,
356 Table_Increment => 100);
357 -- The table for lists of names used in package Language_Processing
359 package Mapping_Files_Htable is new Simple_HTable
360 (Header_Num => Header_Num,
361 Element => Path_Name_Type,
362 No_Element => No_Path,
363 Key => Path_Name_Type,
366 -- A hash table to store the mapping files that are not used
368 type Lang_Naming_Data is record
369 Dot_Replacement : File_Name_Type := No_File;
370 -- The string to replace '.' in the source file name (for Ada)
372 Casing : Casing_Type := All_Lower_Case;
373 -- The casing of the source file name (for Ada)
375 Separate_Suffix : File_Name_Type := No_File;
376 -- String to append to unit name for source file name of an Ada subunit
378 Spec_Suffix : File_Name_Type := No_File;
379 -- The string to append to the unit name for the
380 -- source file name of a spec.
382 Body_Suffix : File_Name_Type := No_File;
383 -- The string to append to the unit name for the
384 -- source file name of a body.
387 No_Lang_Naming_Data : constant Lang_Naming_Data :=
388 (Dot_Replacement => No_File,
389 Casing => All_Lower_Case,
390 Separate_Suffix => No_File,
391 Spec_Suffix => No_File,
392 Body_Suffix => No_File);
395 type Source_Id is access all Source_Data;
397 No_Source : constant Source_Id := null;
399 type Path_Syntax_Kind is
404 -- Host specific syntax, for example on VMS (the default)
406 type Language_Config is record
407 Kind : Language_Kind := File_Based;
408 -- Kind of language. All languages are file based, except Ada which is
411 Naming_Data : Lang_Naming_Data;
412 -- The naming data for the languages (prefixes, etc.)
414 Include_Compatible_Languages : Name_List_Index := No_Name_List;
415 -- The list of languages that are "include compatible" with this
416 -- language. A language B (for example "C") is "include compatible" with
417 -- a language A (for example "C++") if it is expected that sources of
418 -- language A may "include" header files from language B.
420 Compiler_Driver : File_Name_Type := No_File;
421 -- The name of the executable for the compiler of the language
423 Compiler_Driver_Path : String_Access := null;
424 -- The path name of the executable for the compiler of the language
426 Compiler_Required_Switches : Name_List_Index := No_Name_List;
427 -- The list of switches that are required as a minimum to invoke the
430 Path_Syntax : Path_Syntax_Kind := Host;
431 -- Value may be Canonical (Unix style) or Host (host syntax, for example
432 -- on VMS for DEC C).
434 Object_File_Suffix : Name_Id := No_Name;
436 Compilation_PIC_Option : Name_List_Index := No_Name_List;
437 -- The option(s) to compile a source in Position Independent Code for
438 -- shared libraries. Specified in the configuration. When not specified,
439 -- there is no need for such switch.
441 Object_Generated : Boolean := True;
442 -- False in no object file is generated
444 Objects_Linked : Boolean := True;
445 -- False if object files are not use to link executables and build
448 Runtime_Library_Dir : Name_Id := No_Name;
449 -- Path name of the runtime library directory, if any
451 Runtime_Source_Dir : Name_Id := No_Name;
452 -- Path name of the runtime source directory, if any
454 Mapping_File_Switches : Name_List_Index := No_Name_List;
455 -- The option(s) to provide a mapping file to the compiler. Specified in
456 -- the configuration. When value is No_Name_List, there is no mapping
459 Mapping_Spec_Suffix : File_Name_Type := No_File;
460 -- Placeholder representing the spec suffix in a mapping file
462 Mapping_Body_Suffix : File_Name_Type := No_File;
463 -- Placeholder representing the body suffix in a mapping file
465 Config_File_Switches : Name_List_Index := No_Name_List;
466 -- The option(s) to provide a config file to the compiler. Specified in
467 -- the configuration. When value is No_Name_List, there is no config
470 Dependency_Kind : Dependency_File_Kind := None;
471 -- The kind of dependency to be checked: none, Makefile fragment or
472 -- ALI file (for Ada).
474 Dependency_Option : Name_List_Index := No_Name_List;
475 -- The option(s) to be used to create the dependency file. When value is
476 -- No_Name_List, there is not such option(s).
478 Compute_Dependency : Name_List_Index := No_Name_List;
479 -- Hold the value of attribute Dependency_Driver, if declared for the
482 Include_Option : Name_List_Index := No_Name_List;
483 -- Hold the value of attribute Include_Switches, if declared for the
486 Include_Path : Name_Id := No_Name;
487 -- Name of environment variable declared by attribute Include_Path for
490 Include_Path_File : Name_Id := No_Name;
491 -- Name of environment variable declared by attribute Include_Path_File
494 Objects_Path : Name_Id := No_Name;
495 -- Name of environment variable declared by attribute Objects_Path for
498 Objects_Path_File : Name_Id := No_Name;
499 -- Name of environment variable declared by attribute Objects_Path_File
502 Config_Body : Name_Id := No_Name;
503 -- The template for a pragma Source_File_Name(_Project) for a specific
504 -- file name of a body.
506 Config_Spec : Name_Id := No_Name;
507 -- The template for a pragma Source_File_Name(_Project) for a specific
508 -- file name of a spec.
510 Config_Body_Pattern : Name_Id := No_Name;
511 -- The template for a pragma Source_File_Name(_Project) for a naming
514 Config_Spec_Pattern : Name_Id := No_Name;
515 -- The template for a pragma Source_File_Name(_Project) for a naming
518 Config_File_Unique : Boolean := False;
519 -- Indicate if the config file specified to the compiler needs to be
520 -- unique. If it is unique, then all config files are concatenated into
521 -- a temp config file.
523 Binder_Driver : File_Name_Type := No_File;
524 -- The name of the binder driver for the language, if any
526 Binder_Driver_Path : Path_Name_Type := No_Path;
527 -- The path name of the binder driver
529 Binder_Required_Switches : Name_List_Index := No_Name_List;
530 -- Hold the value of attribute Binder'Required_Switches for the language
532 Binder_Prefix : Name_Id := No_Name;
533 -- Hold the value of attribute Binder'Prefix for the language
535 Toolchain_Version : Name_Id := No_Name;
536 -- Hold the value of attribute Toolchain_Version for the language
538 Toolchain_Description : Name_Id := No_Name;
539 -- Hold the value of attribute Toolchain_Description for the language
542 -- Record describing the configuration of a language
544 No_Language_Config : constant Language_Config :=
546 Naming_Data => No_Lang_Naming_Data,
547 Include_Compatible_Languages => No_Name_List,
548 Compiler_Driver => No_File,
549 Compiler_Driver_Path => null,
550 Compiler_Required_Switches => No_Name_List,
551 Path_Syntax => Canonical,
552 Object_File_Suffix => No_Name,
553 Compilation_PIC_Option => No_Name_List,
554 Object_Generated => True,
555 Objects_Linked => True,
556 Runtime_Library_Dir => No_Name,
557 Runtime_Source_Dir => No_Name,
558 Mapping_File_Switches => No_Name_List,
559 Mapping_Spec_Suffix => No_File,
560 Mapping_Body_Suffix => No_File,
561 Config_File_Switches => No_Name_List,
562 Dependency_Kind => Makefile,
563 Dependency_Option => No_Name_List,
564 Compute_Dependency => No_Name_List,
565 Include_Option => No_Name_List,
566 Include_Path => No_Name,
567 Include_Path_File => No_Name,
568 Objects_Path => No_Name,
569 Objects_Path_File => No_Name,
570 Config_Body => No_Name,
571 Config_Spec => No_Name,
572 Config_Body_Pattern => No_Name,
573 Config_Spec_Pattern => No_Name,
574 Config_File_Unique => False,
575 Binder_Driver => No_File,
576 Binder_Driver_Path => No_Path,
577 Binder_Required_Switches => No_Name_List,
578 Binder_Prefix => No_Name,
579 Toolchain_Version => No_Name,
580 Toolchain_Description => No_Name);
582 type Language_Data is record
583 Name : Name_Id := No_Name;
584 Display_Name : Name_Id := No_Name;
585 Config : Language_Config := No_Language_Config;
586 First_Source : Source_Id := No_Source;
587 Mapping_Files : Mapping_Files_Htable.Instance :=
588 Mapping_Files_Htable.Nil;
589 Next : Language_Ptr := No_Language_Index;
592 No_Language_Data : constant Language_Data :=
594 Display_Name => No_Name,
595 Config => No_Language_Config,
596 First_Source => No_Source,
597 Mapping_Files => Mapping_Files_Htable.Nil,
598 Next => No_Language_Index);
600 type Language_List_Element;
601 type Language_List is access all Language_List_Element;
602 type Language_List_Element is record
603 Language : Language_Ptr := No_Language_Index;
604 Next : Language_List;
607 type Source_Kind is (Spec, Impl, Sep);
609 type Source_Data is record
610 Project : Project_Id := No_Project;
611 -- Project of the source
613 Language : Language_Ptr := No_Language_Index;
614 -- Index of the language. This is an index into
615 -- Project_Tree.Languages_Data.
617 Lang_Kind : Language_Kind := File_Based;
618 -- Kind of the language
620 Compiled : Boolean := True;
621 -- False when there is no compiler for the language
623 In_Interfaces : Boolean := True;
624 -- False when the source is not included in interfaces, when attribute
625 -- Interfaces is declared.
627 Declared_In_Interfaces : Boolean := False;
628 -- True when source is declared in attribute Interfaces
630 Alternate_Languages : Language_List;
631 -- List of languages a header file may also be, in addition of language
634 Kind : Source_Kind := Spec;
635 -- Kind of the source: spec, body or subunit
637 Dependency : Dependency_File_Kind := None;
638 -- Kind of dependency: none, Makefile fragment or ALI file
640 Other_Part : Source_Id := No_Source;
641 -- Source ID for the other part, if any: for a spec, indicates its body;
642 -- for a body, indicates its spec.
644 Unit : Name_Id := No_Name;
645 -- Name of the unit, if language is unit based
648 -- Index of the source in a multi unit source file
650 Locally_Removed : Boolean := False;
651 -- True if the source has been "excluded"
653 Get_Object : Boolean := False;
654 -- Indicates that the object of the source should be put in the global
655 -- archive. This is for Ada, when only the closure of a main needs to
656 -- be compiled/recompiled.
658 Replaced_By : Source_Id := No_Source;
660 File : File_Name_Type := No_File;
661 -- Canonical file name of the source
663 Display_File : File_Name_Type := No_File;
664 -- File name of the source, for display purposes
666 Path : Path_Information := No_Path_Information;
667 -- Path name of the source
669 Source_TS : Time_Stamp_Type := Empty_Time_Stamp;
670 -- Time stamp of the source file
672 Object_Project : Project_Id := No_Project;
673 -- Project where the object file is. This might be different from
674 -- Project when using extending project files.
676 Object_Exists : Boolean := True;
677 -- True if an object file exists
679 Object_Linked : Boolean := True;
680 -- False if the object file is not use to link executables or included
683 Object : File_Name_Type := No_File;
684 -- File name of the object file
686 Current_Object_Path : Path_Name_Type := No_Path;
687 -- Object path of an existing object file
689 Object_Path : Path_Name_Type := No_Path;
690 -- Object path of the real object file
692 Object_TS : Time_Stamp_Type := Empty_Time_Stamp;
693 -- Object file time stamp
695 Dep_Name : File_Name_Type := No_File;
696 -- Dependency file simple name
698 Current_Dep_Path : Path_Name_Type := No_Path;
699 -- Path name of an existing dependency file
701 Dep_Path : Path_Name_Type := No_Path;
702 -- Path name of the real dependency file
704 Dep_TS : Time_Stamp_Type := Empty_Time_Stamp;
705 -- Dependency file time stamp
707 Switches : File_Name_Type := No_File;
708 -- File name of the switches file. For all languages, this is a file
709 -- that ends with the .cswi extension.
711 Switches_Path : Path_Name_Type := No_Path;
712 -- Path name of the switches file
714 Switches_TS : Time_Stamp_Type := Empty_Time_Stamp;
715 -- Switches file time stamp
717 Naming_Exception : Boolean := False;
718 -- True if the source has an exceptional name
720 Next_In_Lang : Source_Id := No_Source;
721 -- Link to another source of the same language in the same project
724 No_Source_Data : constant Source_Data :=
725 (Project => No_Project,
726 Language => No_Language_Index,
727 Lang_Kind => File_Based,
729 In_Interfaces => True,
730 Declared_In_Interfaces => False,
731 Alternate_Languages => null,
734 Other_Part => No_Source,
737 Locally_Removed => False,
739 Replaced_By => No_Source,
741 Display_File => No_File,
742 Path => No_Path_Information,
743 Source_TS => Empty_Time_Stamp,
744 Object_Project => No_Project,
745 Object_Exists => True,
746 Object_Linked => True,
748 Current_Object_Path => No_Path,
749 Object_Path => No_Path,
750 Object_TS => Empty_Time_Stamp,
752 Current_Dep_Path => No_Path,
754 Dep_TS => Empty_Time_Stamp,
756 Switches_Path => No_Path,
757 Switches_TS => Empty_Time_Stamp,
758 Naming_Exception => False,
759 Next_In_Lang => No_Source);
761 package Source_Paths_Htable is new Simple_HTable
762 (Header_Num => Header_Num,
763 Element => Source_Id,
764 No_Element => No_Source,
765 Key => Path_Name_Type,
768 -- Mapping of source paths to source ids
770 package Unit_Sources_Htable is new Simple_HTable
771 (Header_Num => Header_Num,
772 Element => Source_Id,
773 No_Element => No_Source,
778 type Verbosity is (Default, Medium, High);
779 -- Verbosity when parsing GNAT Project Files
780 -- Default is default (very quiet, if no errors).
781 -- Medium is more verbose.
782 -- High is extremely verbose.
784 Current_Verbosity : Verbosity := Default;
785 -- The current value of the verbosity the project files are parsed with
787 type Lib_Kind is (Static, Dynamic, Relocatable);
789 type Policy is (Autonomous, Compliant, Controlled, Restricted, Direct);
790 -- Type to specify the symbol policy, when symbol control is supported.
791 -- See full explanation about this type in package Symbols.
792 -- Autonomous: Create a symbol file without considering any reference
793 -- Compliant: Try to be as compatible as possible with an existing ref
794 -- Controlled: Fail if symbols are not the same as those in the reference
795 -- Restricted: Restrict the symbols to those in the symbol file
796 -- Direct: The symbol file is used as is
798 type Symbol_Record is record
799 Symbol_File : Path_Name_Type := No_Path;
800 Reference : Path_Name_Type := No_Path;
801 Symbol_Policy : Policy := Autonomous;
803 -- Type to keep the symbol data to be used when building a shared library
805 No_Symbols : constant Symbol_Record :=
806 (Symbol_File => No_Path,
807 Reference => No_Path,
808 Symbol_Policy => Autonomous);
809 -- The default value of the symbol data
811 function Image (Casing : Casing_Type) return String;
812 -- Similar to 'Image (but avoid use of this attribute in compiler)
814 function Value (Image : String) return Casing_Type;
815 -- Similar to 'Value (but avoid use of this attribute in compiler)
816 -- Raises Constraint_Error if not a Casing_Type image.
818 -- The following record contains data for a naming scheme
820 type Naming_Data is record
822 Dot_Replacement : File_Name_Type := No_File;
823 -- The string to replace '.' in the source file name (for Ada)
825 Casing : Casing_Type := All_Lower_Case;
826 -- The casing of the source file name (for Ada)
828 Spec_Suffix : Array_Element_Id := No_Array_Element;
829 -- The string to append to the unit name for the
830 -- source file name of a spec.
831 -- Indexed by the programming language.
833 Body_Suffix : Array_Element_Id := No_Array_Element;
834 -- The string to append to the unit name for the
835 -- source file name of a body.
836 -- Indexed by the programming language.
838 Separate_Suffix : File_Name_Type := No_File;
839 -- String to append to unit name for source file name of an Ada subunit
841 Specs : Array_Element_Id := No_Array_Element;
842 -- An associative array mapping individual specs to source file names
843 -- This is specific to unit-based languages.
845 Bodies : Array_Element_Id := No_Array_Element;
846 -- An associative array mapping individual bodies to source file names
847 -- This is specific to unit-based languages.
849 Specification_Exceptions : Array_Element_Id := No_Array_Element;
850 -- An associative array listing spec file names that do not have the
851 -- spec suffix. Not used by Ada. Indexed by programming language name.
853 Implementation_Exceptions : Array_Element_Id := No_Array_Element;
854 -- An associative array listing body file names that do not have the
855 -- body suffix. Not used by Ada. Indexed by programming language name.
859 function Spec_Suffix_Of
860 (In_Tree : Project_Tree_Ref;
862 Naming : Naming_Data) return String;
864 function Spec_Suffix_Id_Of
865 (In_Tree : Project_Tree_Ref;
866 Language_Id : Name_Id;
867 Naming : Naming_Data) return File_Name_Type;
869 procedure Set_Spec_Suffix
870 (In_Tree : Project_Tree_Ref;
872 Naming : in out Naming_Data;
873 Suffix : File_Name_Type);
875 function Body_Suffix_Id_Of
876 (In_Tree : Project_Tree_Ref;
877 Language_Id : Name_Id;
878 Naming : Naming_Data) return File_Name_Type;
880 function Body_Suffix_Of
881 (In_Tree : Project_Tree_Ref;
883 Naming : Naming_Data) return String;
885 procedure Set_Body_Suffix
886 (In_Tree : Project_Tree_Ref;
888 Naming : in out Naming_Data;
889 Suffix : File_Name_Type);
891 function Get_Object_Directory
892 (Project : Project_Id;
893 Including_Libraries : Boolean;
894 Only_If_Ada : Boolean := False) return Path_Name_Type;
895 -- Return the object directory to use for the project. This depends on
896 -- whether we have a library project or a standard project. This function
897 -- might return No_Name when no directory applies.
898 -- If we have a a library project file and Including_Libraries is True then
899 -- the library dir is returned instead of the object dir.
900 -- If Only_If_Ada is True, then No_Name will be returned when the project
901 -- doesn't Ada sources.
903 procedure Compute_All_Imported_Projects (Project : Project_Id);
904 -- Compute, the list of the projects imported directly or indirectly by
905 -- project Project. The result is stored in Project.All_Imported_Projects
907 function Ultimate_Extending_Project_Of
908 (Proj : Project_Id) return Project_Id;
909 -- Returns the ultimate extending project of project Proj. If project Proj
910 -- is not extended, returns Proj.
912 function Standard_Naming_Data
913 (Tree : Project_Tree_Ref := No_Project_Tree) return Naming_Data;
914 pragma Inline (Standard_Naming_Data);
915 -- The standard GNAT naming scheme when Tree is No_Project_Tree.
916 -- Otherwise, return the default naming scheme for the project tree Tree,
917 -- which must have been Initialized.
919 function Same_Naming_Scheme
920 (Left, Right : Naming_Data) return Boolean;
921 -- Returns True if Left and Right are the same naming scheme
922 -- not considering Specs and Bodies.
924 type Project_List_Element;
925 type Project_List is access all Project_List_Element;
926 type Project_List_Element is record
927 Project : Project_Id := No_Project;
928 Next : Project_List := null;
930 -- A list of projects
933 (List : in out Project_List;
934 Free_Project : Boolean);
935 -- Free the list of projects, if Free_Project, each project is also freed
937 type Response_File_Format is
942 -- The format of the different response files
944 type Project_Configuration is record
945 Target : Name_Id := No_Name;
946 -- The target of the configuration, when specified
948 Run_Path_Option : Name_List_Index := No_Name_List;
949 -- The option to use when linking to specify the path where to look for
952 Separate_Run_Path_Options : Boolean := False;
953 -- True if each directory needs to be specified in a separate run path
956 Executable_Suffix : Name_Id := No_Name;
957 -- The suffix of executables, when specified in the configuration or in
958 -- package Builder of the main project. When this is not specified, the
959 -- executable suffix is the default for the platform.
963 Linker : Path_Name_Type := No_Path;
964 -- Path name of the linker driver. Specified in the configuration or in
965 -- the package Builder of the main project.
967 Map_File_Option : Name_Id := No_Name;
968 -- Option to use when invoking the linker to build a map file
970 Minimum_Linker_Options : Name_List_Index := No_Name_List;
971 -- The minimum options for the linker driver. Specified in the
974 Linker_Executable_Option : Name_List_Index := No_Name_List;
975 -- The option(s) to indicate the name of the executable in the linker
976 -- command. Specified in the configuration. When not specified, default
977 -- to -o <executable name>.
979 Linker_Lib_Dir_Option : Name_Id := No_Name;
980 -- The option to specify where to find a library for linking. Specified
981 -- in the configuration. When not specified, defaults to "-L".
983 Linker_Lib_Name_Option : Name_Id := No_Name;
984 -- The option to specify the name of a library for linking. Specified in
985 -- the configuration. When not specified, defaults to "-l".
987 Max_Command_Line_Length : Natural := 0;
988 -- When positive and when Resp_File_Format (see below) is not None,
989 -- if the command line for the invocation of the linker would be greater
990 -- than this value, a response file is used to invoke the linker.
992 Resp_File_Format : Response_File_Format := None;
993 -- The format of a response file, when linking with a response file is
996 Resp_File_Options : Name_List_Index := No_Name_List;
997 -- The switches, if any, that precede the path name of the response
998 -- file in the invocation of the linker.
1002 Library_Builder : Path_Name_Type := No_Path;
1003 -- The executable to build library (specified in the configuration)
1005 Lib_Support : Library_Support := None;
1006 -- The level of library support. Specified in the configuration. Support
1007 -- is none, static libraries only or both static and shared libraries.
1009 Archive_Builder : Name_List_Index := No_Name_List;
1010 -- The name of the executable to build archives, with the minimum
1011 -- switches. Specified in the configuration.
1013 Archive_Builder_Append_Option : Name_List_Index := No_Name_List;
1014 -- The options to append object files to an archive
1016 Archive_Indexer : Name_List_Index := No_Name_List;
1017 -- The name of the executable to index archives, with the minimum
1018 -- switches. Specified in the configuration.
1020 Archive_Suffix : File_Name_Type := No_File;
1021 -- The suffix of archives. Specified in the configuration. When not
1022 -- specified, defaults to ".a".
1024 Lib_Partial_Linker : Name_List_Index := No_Name_List;
1028 Shared_Lib_Driver : File_Name_Type := No_File;
1029 -- The driver to link shared libraries. Set with attribute Library_GCC.
1032 Shared_Lib_Prefix : File_Name_Type := No_File;
1033 -- Part of a shared library file name that precedes the name of the
1034 -- library. Specified in the configuration. When not specified, defaults
1037 Shared_Lib_Suffix : File_Name_Type := No_File;
1038 -- Suffix of shared libraries, after the library name in the shared
1039 -- library name. Specified in the configuration. When not specified,
1040 -- default to ".so".
1042 Shared_Lib_Min_Options : Name_List_Index := No_Name_List;
1043 -- The minimum options to use when building a shared library
1045 Lib_Version_Options : Name_List_Index := No_Name_List;
1046 -- The options to use to specify a library version
1048 Symbolic_Link_Supported : Boolean := False;
1049 -- True if the platform supports symbolic link files
1051 Lib_Maj_Min_Id_Supported : Boolean := False;
1052 -- True if platform supports library major and minor options, such as
1053 -- libname.so -> libname.so.2 -> libname.so.2.4
1055 Auto_Init_Supported : Boolean := False;
1056 -- True if automatic initialisation is supported for shared stand-alone
1060 Default_Project_Config : constant Project_Configuration :=
1062 Run_Path_Option => No_Name_List,
1063 Separate_Run_Path_Options => False,
1064 Executable_Suffix => No_Name,
1066 Map_File_Option => No_Name,
1067 Minimum_Linker_Options => No_Name_List,
1068 Linker_Executable_Option => No_Name_List,
1069 Linker_Lib_Dir_Option => No_Name,
1070 Linker_Lib_Name_Option => No_Name,
1071 Library_Builder => No_Path,
1072 Max_Command_Line_Length => 0,
1073 Resp_File_Format => None,
1074 Resp_File_Options => No_Name_List,
1075 Lib_Support => None,
1076 Archive_Builder => No_Name_List,
1077 Archive_Builder_Append_Option => No_Name_List,
1078 Archive_Indexer => No_Name_List,
1079 Archive_Suffix => No_File,
1080 Lib_Partial_Linker => No_Name_List,
1081 Shared_Lib_Driver => No_File,
1082 Shared_Lib_Prefix => No_File,
1083 Shared_Lib_Suffix => No_File,
1084 Shared_Lib_Min_Options => No_Name_List,
1085 Lib_Version_Options => No_Name_List,
1086 Symbolic_Link_Supported => False,
1087 Lib_Maj_Min_Id_Supported => False,
1088 Auto_Init_Supported => False);
1090 -- The following record describes a project file representation
1092 -- Note that it is not specified if the path names of directories (source,
1093 -- object, library or exec directories) end with or without a directory
1096 type Project_Data is record
1102 Name : Name_Id := No_Name;
1103 -- The name of the project
1105 Display_Name : Name_Id := No_Name;
1106 -- The name of the project with the spelling of its declaration
1108 Qualifier : Project_Qualifier := Unspecified;
1109 -- The eventual qualifier for this project
1111 Externally_Built : Boolean := False;
1112 -- True if the project is externally built. In such case, the Project
1113 -- Manager will not modify anything in this project.
1115 Config : Project_Configuration;
1117 Path : Path_Information := No_Path_Information;
1118 -- The path name of the project file. This include base name of the
1121 Virtual : Boolean := False;
1122 -- True for virtual extending projects
1124 Location : Source_Ptr := No_Location;
1125 -- The location in the project file source of the reserved word project
1127 Naming : Naming_Data := Standard_Naming_Data;
1128 -- The naming scheme of this project file
1134 Languages : Language_Ptr := No_Language_Index;
1135 -- First index of the language data in the project.
1136 -- This is an index into the project_tree_data.languages_data.
1137 -- Traversing the list gives access to all the languages supported by
1144 Mains : String_List_Id := Nil_String;
1145 -- List of mains specified by attribute Main
1147 Extends : Project_Id := No_Project;
1148 -- The reference of the project file, if any, that this project file
1151 Extended_By : Project_Id := No_Project;
1152 -- The reference of the project file, if any, that extends this project
1155 Decl : Declarations := No_Declarations;
1156 -- The declarations (variables, attributes and packages) of this project
1159 Imported_Projects : Project_List;
1160 -- The list of all directly imported projects, if any
1162 All_Imported_Projects : Project_List;
1163 -- The list of all projects imported directly or indirectly, if any
1169 Directory : Path_Information := No_Path_Information;
1170 -- Path name of the directory where the project file resides
1172 Object_Directory : Path_Information := No_Path_Information;
1173 -- The path name of the object directory of this project file
1175 Exec_Directory : Path_Information := No_Path_Information;
1176 -- The path name of the exec directory of this project file. Default is
1177 -- equal to Object_Directory.
1183 Library : Boolean := False;
1184 -- True if this is a library project
1186 Library_Name : Name_Id := No_Name;
1187 -- If a library project, name of the library
1189 Library_Kind : Lib_Kind := Static;
1190 -- If a library project, kind of library
1192 Library_Dir : Path_Information := No_Path_Information;
1193 -- If a library project, path name of the directory where the library
1196 Library_TS : Time_Stamp_Type := Empty_Time_Stamp;
1197 -- The timestamp of a library file in a library project
1199 Library_Src_Dir : Path_Information := No_Path_Information;
1200 -- If a Stand-Alone Library project, path name of the directory where
1201 -- the sources of the interfaces of the library are copied. By default,
1202 -- if attribute Library_Src_Dir is not specified, sources of the
1203 -- interfaces are not copied anywhere.
1205 Library_ALI_Dir : Path_Information := No_Path_Information;
1206 -- In a library project, path name of the directory where the ALI files
1207 -- are copied. If attribute Library_ALI_Dir is not specified, ALI files
1208 -- are copied in the Library_Dir.
1210 Lib_Internal_Name : Name_Id := No_Name;
1211 -- If a library project, internal name store inside the library
1213 Standalone_Library : Boolean := False;
1214 -- Indicate that this is a Standalone Library Project File
1216 Lib_Interface_ALIs : String_List_Id := Nil_String;
1217 -- For Standalone Library Project Files, indicate the list of Interface
1220 Lib_Auto_Init : Boolean := False;
1221 -- For non static Stand-Alone Library Project Files, indicate if
1222 -- the library initialisation should be automatic.
1224 Symbol_Data : Symbol_Record := No_Symbols;
1225 -- Symbol file name, reference symbol file name, symbol policy
1227 Need_To_Build_Lib : Boolean := False;
1228 -- Indicates that the library of a Library Project needs to be built or
1234 -- The sources for all languages including Ada are accessible through
1235 -- the Source_Iterator type
1237 Interfaces_Defined : Boolean := False;
1238 -- True if attribute Interfaces is declared for the project or any
1239 -- project it extends.
1241 Include_Path : String_Access := null;
1242 -- The search source path for the project. Used as the value for an
1243 -- environment variable, specified by attribute Include_Path
1244 -- (<language>). The names of the environment variables are in component
1245 -- Include_Path of the records Language_Config.
1247 Include_Path_File : Path_Name_Type := No_Path;
1248 -- The path name of the of the source search directory file
1250 Include_Data_Set : Boolean := False;
1251 -- Set True when Imported_Directories_Switches or Include_Path are set
1253 Source_Dirs : String_List_Id := Nil_String;
1254 -- The list of all the source directories
1256 Known_Order_Of_Source_Dirs : Boolean := True;
1257 -- False, if there is any /** in the Source_Dirs, because in this case
1258 -- the ordering of the source subdirs depend on the OS. If True,
1259 -- duplicate file names in the same project file are allowed.
1261 Ada_Include_Path : String_Access := null;
1262 -- The cached value of source search path for this project file. Set by
1263 -- the first call to Prj.Env.Ada_Include_Path for the project. Do not
1264 -- use this field directly outside of the project manager, use
1265 -- Prj.Env.Ada_Include_Path instead.
1271 Ada_Objects_Path : String_Access := null;
1272 -- The cached value of ADA_OBJECTS_PATH for this project file. Do not
1273 -- use this field directly outside of the compiler, use
1274 -- Prj.Env.Ada_Objects_Path instead.
1276 Libgnarl_Needed : Yes_No_Unknown := Unknown;
1277 -- Set to True when libgnarl is needed to link
1279 Objects_Path : String_Access := null;
1280 -- The cached value of the object dir path, used during the binding
1281 -- phase of gprbuild.
1283 Objects_Path_File_With_Libs : Path_Name_Type := No_Path;
1284 -- The cached value of the object path temp file (including library
1285 -- dirs) for this project file.
1287 Objects_Path_File_Without_Libs : Path_Name_Type := No_Path;
1288 -- The cached value of the object path temp file (excluding library
1289 -- dirs) for this project file.
1291 Config_File_Name : Path_Name_Type := No_Path;
1292 -- The path name of the configuration pragmas file, if any
1294 Config_File_Temp : Boolean := False;
1295 -- An indication that the configuration pragmas file is a temporary file
1296 -- that must be deleted at the end.
1298 Config_Checked : Boolean := False;
1299 -- A flag to avoid checking repetitively the configuration pragmas file
1301 Depth : Natural := 0;
1302 -- The maximum depth of a project in the project graph. Depth of main
1305 Unkept_Comments : Boolean := False;
1306 -- True if there are comments in the project sources that cannot be kept
1307 -- in the project tree.
1311 function Empty_Project (Tree : Project_Tree_Ref) return Project_Data;
1312 -- Return the representation of an empty project in project Tree tree.
1313 -- The project tree Tree must have been Initialized and/or Reset.
1315 function Is_Extending
1316 (Extending : Project_Id;
1317 Extended : Project_Id) return Boolean;
1318 -- Return True if Extending is extending the Extended project
1320 function Is_A_Language
1321 (Project : Project_Id;
1322 Language_Name : Name_Id) return Boolean;
1323 -- Return True when Language_Name (which must be lower case) is one of the
1324 -- languages used for the project.
1326 function Has_Ada_Sources (Data : Project_Id) return Boolean;
1327 -- Return True if the project has Ada sources
1329 function Has_Foreign_Sources (Data : Project_Id) return Boolean;
1330 -- Return True if the project has foreign sources
1332 Project_Error : exception;
1333 -- Raised by some subprograms in Prj.Attr
1335 type Spec_Or_Body is (Specification, Body_Part);
1337 type File_Name_Data is record
1338 Name : File_Name_Type := No_File;
1340 Display_Name : File_Name_Type := No_File;
1341 Path : Path_Information := No_Path_Information;
1342 Project : Project_Id := No_Project;
1343 Needs_Pragma : Boolean := False;
1345 -- File and Path name of a spec or body
1347 type File_Names_Data is array (Spec_Or_Body) of File_Name_Data;
1349 type Unit_Index is new Nat;
1350 No_Unit_Index : constant Unit_Index := 0;
1351 type Unit_Data is record
1352 Name : Name_Id := No_Name;
1353 File_Names : File_Names_Data;
1355 -- Name and File and Path names of a unit, with a reference to its
1356 -- GNAT Project File(s).
1358 package Unit_Table is new GNAT.Dynamic_Tables
1359 (Table_Component_Type => Unit_Data,
1360 Table_Index_Type => Unit_Index,
1361 Table_Low_Bound => 1,
1362 Table_Initial => 100,
1363 Table_Increment => 100);
1364 -- Table of all units in a project tree
1366 package Units_Htable is new Simple_HTable
1367 (Header_Num => Header_Num,
1368 Element => Unit_Index,
1369 No_Element => No_Unit_Index,
1373 -- Mapping of unit names to indexes in the Units table
1375 package Files_Htable is new Simple_HTable
1376 (Header_Num => Header_Num,
1377 Element => Project_Id,
1378 No_Element => No_Project,
1379 Key => File_Name_Type,
1382 -- Mapping of file names to indexes in the Units table
1384 ---------------------
1385 -- Source_Iterator --
1386 ---------------------
1388 type Source_Iterator is private;
1390 function For_Each_Source
1391 (In_Tree : Project_Tree_Ref;
1392 Project : Project_Id := No_Project;
1393 Language : Name_Id := No_Name) return Source_Iterator;
1394 -- Returns an iterator for all the sources of a project tree, or a specific
1395 -- project, or a specific language.
1397 function Element (Iter : Source_Iterator) return Source_Id;
1398 -- Return the current source (or No_Source if there are no more sources)
1400 procedure Next (Iter : in out Source_Iterator);
1401 -- Move on to the next source
1403 -----------------------
1404 -- Project_Tree_Data --
1405 -----------------------
1407 type Private_Project_Tree_Data is private;
1408 -- Data for a project tree that is used only by the Project Manager
1410 type Project_Tree_Data is
1412 Name_Lists : Name_List_Table.Instance;
1413 String_Elements : String_Element_Table.Instance;
1414 Variable_Elements : Variable_Element_Table.Instance;
1415 Array_Elements : Array_Element_Table.Instance;
1416 Arrays : Array_Table.Instance;
1417 Packages : Package_Table.Instance;
1418 Projects : Project_List;
1419 Units : Unit_Table.Instance;
1420 Units_HT : Units_Htable.Instance;
1421 Source_Paths_HT : Source_Paths_Htable.Instance;
1422 Unit_Sources_HT : Unit_Sources_Htable.Instance;
1426 Private_Part : Private_Project_Tree_Data;
1428 -- Data for a project tree
1430 type Put_Line_Access is access procedure
1432 Project : Project_Id;
1433 In_Tree : Project_Tree_Ref);
1434 -- Use to customize error reporting in Prj.Proc and Prj.Nmsc
1436 procedure Expect (The_Token : Token_Type; Token_Image : String);
1437 -- Check that the current token is The_Token. If it is not, then output
1438 -- an error message.
1440 procedure Initialize (Tree : Project_Tree_Ref);
1441 -- This procedure must be called before using any services from the Prj
1442 -- hierarchy. Namet.Initialize must be called before Prj.Initialize.
1444 procedure Reset (Tree : Project_Tree_Ref);
1445 -- This procedure resets all the tables that are used when processing a
1446 -- project file tree. Initialize must be called before the call to Reset.
1448 procedure Register_Default_Naming_Scheme
1449 (Language : Name_Id;
1450 Default_Spec_Suffix : File_Name_Type;
1451 Default_Body_Suffix : File_Name_Type;
1452 In_Tree : Project_Tree_Ref);
1453 -- Register the default suffixes for a given language. These extensions
1454 -- will be ignored if the user has specified a new naming scheme in a
1457 -- Otherwise, this information will be automatically added to Naming_Data
1458 -- when a project is processed, in the lists Spec_Suffix and Body_Suffix.
1460 package Project_Boolean_Htable is new Simple_HTable
1461 (Header_Num => Header_Num,
1463 No_Element => False,
1467 -- A table that associates a project to a boolean. This is used to detect
1468 -- whether a project was already processed for instance.
1471 type State is limited private;
1472 with procedure Action
1473 (Project : Project_Id;
1474 With_State : in out State);
1475 procedure For_Every_Project_Imported
1477 With_State : in out State;
1478 Imported_First : Boolean := False);
1479 -- Call Action for each project imported directly or indirectly by project
1480 -- By, as well as extended projects.
1481 -- The order of processing depends on Imported_First:
1482 -- If False, Action is called according to the order of importation: if A
1483 -- imports B, directly or indirectly, Action will be called for A before
1484 -- it is called for B. If two projects import each other directly or
1485 -- indirectly (using at least one "limited with"), it is not specified
1486 -- for which of these two projects Action will be called first.
1487 -- The order is reversed if Imported_First is True.
1488 -- With_State may be used by Action to choose a behavior or to report some
1491 function Extend_Name
1492 (File : File_Name_Type;
1493 With_Suffix : String) return File_Name_Type;
1494 -- Replace the extension of File with With_Suffix
1496 function Object_Name
1497 (Source_File_Name : File_Name_Type;
1498 Object_File_Suffix : Name_Id := No_Name) return File_Name_Type;
1499 -- Returns the object file name corresponding to a source file name
1501 function Dependency_Name
1502 (Source_File_Name : File_Name_Type;
1503 Dependency : Dependency_File_Kind) return File_Name_Type;
1504 -- Returns the dependency file name corresponding to a source file name
1506 function Switches_Name
1507 (Source_File_Name : File_Name_Type) return File_Name_Type;
1508 -- Returns the switches file name corresponding to a source file name
1514 procedure Record_Temp_File (Path : Path_Name_Type);
1515 -- Record the path of a newly created temporary file, so that it can be
1518 procedure Delete_All_Temp_Files;
1519 -- Delete all recorded temporary files
1523 All_Packages : constant String_List_Access := null;
1525 No_Project_Tree : constant Project_Tree_Ref := null;
1527 Ignored : constant Variable_Kind := Single;
1529 Nil_Variable_Value : constant Variable_Value :=
1530 (Project => No_Project,
1532 Location => No_Location,
1535 Virtual_Prefix : constant String := "v$";
1536 -- The prefix for virtual extending projects. Because of the '$', which is
1537 -- normally forbidden for project names, there cannot be any name clash.
1539 Empty_Name : Name_Id;
1540 -- Name_Id for an empty name (no characters). Initialized in procedure
1543 Empty_File_Name : File_Name_Type;
1544 -- Empty File_Name_Type (no characters). Initialized in procedure
1547 type Source_Iterator is record
1548 In_Tree : Project_Tree_Ref;
1550 Project : Project_List;
1551 All_Projects : Boolean;
1552 -- Current project and whether we should move on to the next
1554 Language : Language_Ptr;
1555 -- Current language processed
1557 Language_Name : Name_Id;
1558 -- Only sources of this language will be returned (or all if No_Name)
1560 Current : Source_Id;
1563 procedure Add_To_Buffer
1565 To : in out String_Access;
1566 Last : in out Natural);
1567 -- Append a String to the Buffer
1569 type Naming_Id is new Nat;
1571 package Naming_Table is new GNAT.Dynamic_Tables
1572 (Table_Component_Type => Naming_Data,
1573 Table_Index_Type => Naming_Id,
1574 Table_Low_Bound => 1,
1576 Table_Increment => 100);
1577 -- Table storing the naming data for gnatmake/gprmake
1579 package Path_File_Table is new GNAT.Dynamic_Tables
1580 (Table_Component_Type => Path_Name_Type,
1581 Table_Index_Type => Natural,
1582 Table_Low_Bound => 1,
1583 Table_Initial => 50,
1584 Table_Increment => 100);
1585 -- Table storing all the temp path file names.
1586 -- Used by Delete_All_Path_Files.
1588 package Source_Path_Table is new GNAT.Dynamic_Tables
1589 (Table_Component_Type => Name_Id,
1590 Table_Index_Type => Natural,
1591 Table_Low_Bound => 1,
1592 Table_Initial => 50,
1593 Table_Increment => 100);
1594 -- A table to store the source dirs before creating the source path file
1596 package Object_Path_Table is new GNAT.Dynamic_Tables
1597 (Table_Component_Type => Path_Name_Type,
1598 Table_Index_Type => Natural,
1599 Table_Low_Bound => 1,
1600 Table_Initial => 50,
1601 Table_Increment => 100);
1602 -- A table to store the object dirs, before creating the object path file
1604 type Private_Project_Tree_Data is record
1605 Namings : Naming_Table.Instance;
1606 Path_Files : Path_File_Table.Instance;
1607 Source_Paths : Source_Path_Table.Instance;
1608 Object_Paths : Object_Path_Table.Instance;
1609 Default_Naming : Naming_Data;
1611 Current_Source_Path_File : Path_Name_Type := No_Path;
1612 -- Current value of project source path file env var. Used to avoid
1613 -- setting the env var to the same value.
1615 Current_Object_Path_File : Path_Name_Type := No_Path;
1616 -- Current value of project object path file env var. Used to avoid
1617 -- setting the env var to the same value.
1619 Ada_Path_Buffer : String_Access := new String (1 .. 1024);
1620 -- A buffer where values for ADA_INCLUDE_PATH and ADA_OBJECTS_PATH are
1623 Ada_Path_Length : Natural := 0;
1624 -- Index of the last valid character in Ada_Path_Buffer
1626 Ada_Prj_Include_File_Set : Boolean := False;
1627 Ada_Prj_Objects_File_Set : Boolean := False;
1628 -- These flags are set to True when the corresponding environment
1629 -- variables are set and are used to give these environment variables an
1630 -- empty string value at the end of the program. This has no practical
1631 -- effect on most platforms, except on VMS where the logical names are
1632 -- deassigned, thus avoiding the pollution of the environment of the
1635 Fill_Mapping_File : Boolean := True;
1638 -- Type to represent the part of a project tree which is private to the