1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2011, 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 All_Other_Names : constant Name_Id := Names_High_Bound;
45 -- Name used to replace others as an index of an associative array
46 -- attribute in situations where this is allowed.
48 Subdirs : String_Ptr := null;
49 -- The value after the equal sign in switch --subdirs=...
50 -- Contains the relative subdirectory.
52 type Library_Support is (None, Static_Only, Full);
53 -- Support for Library Project File.
54 -- - None: Library Project Files are not supported at all
55 -- - Static_Only: Library Project Files are only supported for static
57 -- - Full: Library Project Files are supported for static and dynamic
58 -- (shared) libraries.
60 type Yes_No_Unknown is (Yes, No, Unknown);
61 -- Tri-state to decide if -lgnarl is needed when linking
63 type Project_Qualifier is
71 -- Qualifiers that can prefix the reserved word "project" in a project
73 -- Standard: standard project ...
74 -- Library: library project is ...
75 -- Dry: abstract project is
76 -- Aggregate: aggregate project is
77 -- Aggregate_Library: aggregate library project is ...
78 -- Configuration: configuration project is ...
80 subtype Aggregate_Project is
81 Project_Qualifier range Aggregate .. Aggregate_Library;
83 All_Packages : constant String_List_Access;
84 -- Default value of parameter Packages of procedures Parse, in Prj.Pars and
85 -- Prj.Part, indicating that all packages should be checked.
87 type Project_Tree_Data;
88 type Project_Tree_Ref is access all Project_Tree_Data;
89 -- Reference to a project tree. Several project trees may exist in memory
92 No_Project_Tree : constant Project_Tree_Ref;
94 procedure Free (Tree : in out Project_Tree_Ref);
95 -- Free memory associated with the tree
97 Config_Project_File_Extension : String := ".cgpr";
98 Project_File_Extension : String := ".gpr";
99 -- The standard config and user project file name extensions. They are not
100 -- constants, because Canonical_Case_File_Name is called on these variables
101 -- in the body of Prj.
103 function Empty_File return File_Name_Type;
104 function Empty_String return Name_Id;
105 -- Return the id for an empty string ""
107 type Path_Information is record
108 Name : Path_Name_Type := No_Path;
109 Display_Name : Path_Name_Type := No_Path;
111 -- Directory names always end with a directory separator
113 No_Path_Information : constant Path_Information := (No_Path, No_Path);
116 type Project_Id is access all Project_Data;
117 No_Project : constant Project_Id := null;
118 -- Id of a Project File
120 type String_List_Id is new Nat;
121 Nil_String : constant String_List_Id := 0;
122 type String_Element is record
123 Value : Name_Id := No_Name;
125 Display_Value : Name_Id := No_Name;
126 Location : Source_Ptr := No_Location;
127 Flag : Boolean := False;
128 Next : String_List_Id := Nil_String;
130 -- To hold values for string list variables and array elements.
131 -- Component Flag may be used for various purposes. For source
132 -- directories, it indicates if the directory contains Ada source(s).
134 package String_Element_Table is new GNAT.Dynamic_Tables
135 (Table_Component_Type => String_Element,
136 Table_Index_Type => String_List_Id,
137 Table_Low_Bound => 1,
138 Table_Initial => 200,
139 Table_Increment => 100);
140 -- The table for string elements in string lists
142 type Variable_Kind is (Undefined, List, Single);
143 -- Different kinds of variables
145 subtype Defined_Variable_Kind is Variable_Kind range List .. Single;
146 -- The defined kinds of variables
148 Ignored : constant Variable_Kind;
149 -- Used to indicate that a package declaration must be ignored
150 -- while processing the project tree (unknown package name).
152 type Variable_Value (Kind : Variable_Kind := Undefined) is record
153 Project : Project_Id := No_Project;
154 Location : Source_Ptr := No_Location;
155 Default : Boolean := False;
160 Values : String_List_Id := Nil_String;
162 Value : Name_Id := No_Name;
166 -- Values for variables and array elements. Default is True if the
167 -- current value is the default one for the variable.
169 Nil_Variable_Value : constant Variable_Value;
170 -- Value of a non existing variable or array element
172 type Variable_Id is new Nat;
173 No_Variable : constant Variable_Id := 0;
174 type Variable is record
175 Next : Variable_Id := No_Variable;
177 Value : Variable_Value;
179 -- To hold the list of variables in a project file and in packages
181 package Variable_Element_Table is new GNAT.Dynamic_Tables
182 (Table_Component_Type => Variable,
183 Table_Index_Type => Variable_Id,
184 Table_Low_Bound => 1,
185 Table_Initial => 200,
186 Table_Increment => 100);
187 -- The table of variable in list of variables
189 type Array_Element_Id is new Nat;
190 No_Array_Element : constant Array_Element_Id := 0;
191 type Array_Element is record
193 Restricted : Boolean := False;
194 Src_Index : Int := 0;
195 Index_Case_Sensitive : Boolean := True;
196 Value : Variable_Value;
197 Next : Array_Element_Id := No_Array_Element;
199 -- Each Array_Element represents an array element and is linked (Next)
200 -- to the next array element, if any, in the array.
202 package Array_Element_Table is new GNAT.Dynamic_Tables
203 (Table_Component_Type => Array_Element,
204 Table_Index_Type => Array_Element_Id,
205 Table_Low_Bound => 1,
206 Table_Initial => 200,
207 Table_Increment => 100);
208 -- The table that contains all array elements
210 type Array_Id is new Nat;
211 No_Array : constant Array_Id := 0;
212 type Array_Data is record
213 Name : Name_Id := No_Name;
214 Location : Source_Ptr := No_Location;
215 Value : Array_Element_Id := No_Array_Element;
216 Next : Array_Id := No_Array;
218 -- Each Array_Data value represents an array.
219 -- Value is the id of the first element.
220 -- Next is the id of the next array in the project file or package.
222 package Array_Table is new GNAT.Dynamic_Tables
223 (Table_Component_Type => Array_Data,
224 Table_Index_Type => Array_Id,
225 Table_Low_Bound => 1,
226 Table_Initial => 200,
227 Table_Increment => 100);
228 -- The table that contains all arrays
230 type Package_Id is new Nat;
231 No_Package : constant Package_Id := 0;
232 type Declarations is record
233 Variables : Variable_Id := No_Variable;
234 Attributes : Variable_Id := No_Variable;
235 Arrays : Array_Id := No_Array;
236 Packages : Package_Id := No_Package;
238 -- Contains the declarations (variables, single and array attributes,
239 -- packages) for a project or a package in a project.
241 No_Declarations : constant Declarations :=
242 (Variables => No_Variable,
243 Attributes => No_Variable,
245 Packages => No_Package);
246 -- Default value of Declarations: indicates that there is no declarations
248 type Package_Element is record
249 Name : Name_Id := No_Name;
250 Decl : Declarations := No_Declarations;
251 Parent : Package_Id := No_Package;
252 Next : Package_Id := No_Package;
254 -- A package (includes declarations that may include other packages)
256 package Package_Table is new GNAT.Dynamic_Tables
257 (Table_Component_Type => Package_Element,
258 Table_Index_Type => Package_Id,
259 Table_Low_Bound => 1,
260 Table_Initial => 100,
261 Table_Increment => 100);
262 -- The table that contains all packages
265 type Language_Ptr is access all Language_Data;
266 -- Index of language data
268 No_Language_Index : constant Language_Ptr := null;
269 -- Constant indicating that there is no language data
271 function Get_Language_From_Name
272 (Project : Project_Id;
273 Name : String) return Language_Ptr;
274 -- Get a language from a project. This might return null if no such
275 -- language exists in the project
277 Max_Header_Num : constant := 6150;
278 type Header_Num is range 0 .. Max_Header_Num;
279 -- Size for hash table below. The upper bound is an arbitrary value, the
280 -- value here was chosen after testing to determine a good compromise
281 -- between speed of access and memory usage.
283 function Hash (Name : Name_Id) return Header_Num;
284 function Hash (Name : File_Name_Type) return Header_Num;
285 function Hash (Name : Path_Name_Type) return Header_Num;
286 function Hash (Project : Project_Id) return Header_Num;
287 -- Used for computing hash values for names put into hash tables
289 type Language_Kind is (File_Based, Unit_Based);
290 -- Type for the kind of language. All languages are file based, except Ada
291 -- which is unit based.
293 type Dependency_File_Kind is (None, Makefile, ALI_File);
294 -- Type of dependency to be checked: no dependency file, Makefile fragment
295 -- or ALI file (for Ada).
297 Makefile_Dependency_Suffix : constant String := ".d";
298 ALI_Dependency_Suffix : constant String := ".ali";
299 Switches_Dependency_Suffix : constant String := ".cswi";
301 Binder_Exchange_Suffix : constant String := ".bexch";
302 -- Suffix for binder exchange files
304 Library_Exchange_Suffix : constant String := ".lexch";
305 -- Suffix for library exchange files
307 type Name_List_Index is new Nat;
308 No_Name_List : constant Name_List_Index := 0;
310 type Name_Node is record
311 Name : Name_Id := No_Name;
312 Next : Name_List_Index := No_Name_List;
315 package Name_List_Table is new GNAT.Dynamic_Tables
316 (Table_Component_Type => Name_Node,
317 Table_Index_Type => Name_List_Index,
318 Table_Low_Bound => 1,
320 Table_Increment => 100);
321 -- The table for lists of names
324 (Table : Name_List_Table.Instance;
325 List : Name_List_Index) return Natural;
326 -- Return the number of elements in specified list
328 type Number_List_Index is new Nat;
329 No_Number_List : constant Number_List_Index := 0;
331 type Number_Node is record
332 Number : Natural := 0;
333 Next : Number_List_Index := No_Number_List;
336 package Number_List_Table is new GNAT.Dynamic_Tables
337 (Table_Component_Type => Number_Node,
338 Table_Index_Type => Number_List_Index,
339 Table_Low_Bound => 1,
341 Table_Increment => 100);
342 -- The table for lists of numbers
344 package Mapping_Files_Htable is new Simple_HTable
345 (Header_Num => Header_Num,
346 Element => Path_Name_Type,
347 No_Element => No_Path,
348 Key => Path_Name_Type,
351 -- A hash table to store the mapping files that are not used
353 -- The following record ???
355 type Lang_Naming_Data is record
356 Dot_Replacement : File_Name_Type := No_File;
357 -- The string to replace '.' in the source file name (for Ada)
359 Casing : Casing_Type := All_Lower_Case;
360 -- The casing of the source file name (for Ada)
362 Separate_Suffix : File_Name_Type := No_File;
363 -- String to append to unit name for source file name of an Ada subunit
365 Spec_Suffix : File_Name_Type := No_File;
366 -- The string to append to the unit name for the
367 -- source file name of a spec.
369 Body_Suffix : File_Name_Type := No_File;
370 -- The string to append to the unit name for the
371 -- source file name of a body.
374 No_Lang_Naming_Data : constant Lang_Naming_Data :=
375 (Dot_Replacement => No_File,
376 Casing => All_Lower_Case,
377 Separate_Suffix => No_File,
378 Spec_Suffix => No_File,
379 Body_Suffix => No_File);
381 function Is_Standard_GNAT_Naming (Naming : Lang_Naming_Data) return Boolean;
382 -- True if the naming scheme is GNAT's default naming scheme. This
383 -- is to take into account shortened names like "Ada." (a-), "System." (s-)
387 type Source_Id is access all Source_Data;
389 function Is_Compilable (Source : Source_Id) return Boolean;
390 pragma Inline (Is_Compilable);
391 -- Return True if we know how to compile Source (i.e. if a compiler is
392 -- defined). This doesn't indicate whether the source should be compiled.
394 function Object_To_Global_Archive (Source : Source_Id) return Boolean;
395 pragma Inline (Object_To_Global_Archive);
396 -- Return True if the object file should be put in the global archive.
397 -- This is for Ada, when only the closure of a main needs to be
400 function Other_Part (Source : Source_Id) return Source_Id;
401 pragma Inline (Other_Part);
402 -- Source ID for the other part, if any: for a spec, indicates its body;
403 -- for a body, indicates its spec.
405 No_Source : constant Source_Id := null;
407 type Path_Syntax_Kind is
411 -- Host specific syntax, for example on VMS (the default)
413 -- The following record describes the configuration of a language
415 type Language_Config is record
416 Kind : Language_Kind := File_Based;
417 -- Kind of language. Most languages are file based. A few, such as Ada,
420 Naming_Data : Lang_Naming_Data;
421 -- The naming data for the languages (prefixes, etc.)
423 Include_Compatible_Languages : Name_List_Index := No_Name_List;
424 -- List of languages that are "include compatible" with this language. A
425 -- language B (for example "C") is "include compatible" with a language
426 -- A (for example "C++") if it is expected that sources of language A
427 -- may "include" header files from language B.
429 Compiler_Driver : File_Name_Type := No_File;
430 -- The name of the executable for the compiler of the language
432 Compiler_Driver_Path : String_Access := null;
433 -- The path name of the executable for the compiler of the language
435 Compiler_Leading_Required_Switches : Name_List_Index := No_Name_List;
436 -- The list of initial switches that are required as a minimum to invoke
437 -- the compiler driver.
439 Compiler_Trailing_Required_Switches : Name_List_Index := No_Name_List;
440 -- The list of final switches that are required as a minimum to invoke
441 -- the compiler driver.
443 Multi_Unit_Switches : Name_List_Index := No_Name_List;
444 -- The switch(es) to indicate the index of a unit in a multi-source file
446 Multi_Unit_Object_Separator : Character := ' ';
447 -- The string separating the base name of a source from the index of the
448 -- unit in a multi-source file, in the object file name.
450 Path_Syntax : Path_Syntax_Kind := Host;
451 -- Value may be Canonical (Unix style) or Host (host syntax, for example
452 -- on VMS for DEC C).
454 Source_File_Switches : Name_List_Index := No_Name_List;
455 -- Optional switches to be put before the source file. The source file
456 -- path name is appended to the last switch in the list.
457 -- Example: ("-i", "");
459 Object_File_Suffix : Name_Id := No_Name;
460 -- Optional alternate object file suffix
462 Object_File_Switches : Name_List_Index := No_Name_List;
463 -- Optional object file switches. When this is defined, the switches
464 -- are used to specify the object file. The object file name is appended
465 -- to the last switch in the list. Example: ("-o", "").
467 Compilation_PIC_Option : Name_List_Index := No_Name_List;
468 -- The option(s) to compile a source in Position Independent Code for
469 -- shared libraries. Specified in the configuration. When not specified,
470 -- there is no need for such switch.
472 Object_Generated : Boolean := True;
473 -- False in no object file is generated
475 Objects_Linked : Boolean := True;
476 -- False if object files are not use to link executables and build
479 Runtime_Library_Dir : Name_Id := No_Name;
480 -- Path name of the runtime library directory, if any
482 Runtime_Source_Dir : Name_Id := No_Name;
483 -- Path name of the runtime source directory, if any
485 Mapping_File_Switches : Name_List_Index := No_Name_List;
486 -- The option(s) to provide a mapping file to the compiler. Specified in
487 -- the configuration. When value is No_Name_List, there is no mapping
490 Mapping_Spec_Suffix : File_Name_Type := No_File;
491 -- Placeholder representing the spec suffix in a mapping file
493 Mapping_Body_Suffix : File_Name_Type := No_File;
494 -- Placeholder representing the body suffix in a mapping file
496 Config_File_Switches : Name_List_Index := No_Name_List;
497 -- The option(s) to provide a config file to the compiler. Specified in
498 -- the configuration. If value is No_Name_List there is no config file.
500 Dependency_Kind : Dependency_File_Kind := None;
501 -- The kind of dependency to be checked: none, Makefile fragment or
502 -- ALI file (for Ada).
504 Dependency_Option : Name_List_Index := No_Name_List;
505 -- The option(s) to be used to create the dependency file. When value is
506 -- No_Name_List, there is not such option(s).
508 Compute_Dependency : Name_List_Index := No_Name_List;
509 -- Hold the value of attribute Dependency_Driver, if declared for the
512 Include_Option : Name_List_Index := No_Name_List;
513 -- Hold the value of attribute Include_Switches, if declared for the
516 Include_Path : Name_Id := No_Name;
517 -- Name of environment variable declared by attribute Include_Path for
520 Include_Path_File : Name_Id := No_Name;
521 -- Name of environment variable declared by attribute Include_Path_File
524 Objects_Path : Name_Id := No_Name;
525 -- Name of environment variable declared by attribute Objects_Path for
528 Objects_Path_File : Name_Id := No_Name;
529 -- Name of environment variable declared by attribute Objects_Path_File
532 Config_Body : Name_Id := No_Name;
533 -- The template for a pragma Source_File_Name(_Project) for a specific
534 -- file name of a body.
536 Config_Body_Index : Name_Id := No_Name;
537 -- The template for a pragma Source_File_Name(_Project) for a specific
538 -- file name of a body in a multi-source file.
540 Config_Body_Pattern : Name_Id := No_Name;
541 -- The template for a pragma Source_File_Name(_Project) for a naming
544 Config_Spec : Name_Id := No_Name;
545 -- The template for a pragma Source_File_Name(_Project) for a specific
546 -- file name of a spec.
548 Config_Spec_Index : Name_Id := No_Name;
549 -- The template for a pragma Source_File_Name(_Project) for a specific
550 -- file name of a spec in a multi-source file.
552 Config_Spec_Pattern : Name_Id := No_Name;
553 -- The template for a pragma Source_File_Name(_Project) for a naming
556 Config_File_Unique : Boolean := False;
557 -- Indicate if the config file specified to the compiler needs to be
558 -- unique. If it is unique, then all config files are concatenated into
559 -- a temp config file.
561 Binder_Driver : File_Name_Type := No_File;
562 -- The name of the binder driver for the language, if any
564 Binder_Driver_Path : Path_Name_Type := No_Path;
565 -- The path name of the binder driver
567 Binder_Required_Switches : Name_List_Index := No_Name_List;
568 -- Hold the value of attribute Binder'Required_Switches for the language
570 Binder_Prefix : Name_Id := No_Name;
571 -- Hold the value of attribute Binder'Prefix for the language
573 Toolchain_Version : Name_Id := No_Name;
574 -- Hold the value of attribute Toolchain_Version for the language
576 Toolchain_Description : Name_Id := No_Name;
577 -- Hold the value of attribute Toolchain_Description for the language
581 No_Language_Config : constant Language_Config :=
583 Naming_Data => No_Lang_Naming_Data,
584 Include_Compatible_Languages => No_Name_List,
585 Compiler_Driver => No_File,
586 Compiler_Driver_Path => null,
587 Compiler_Leading_Required_Switches
589 Compiler_Trailing_Required_Switches
591 Multi_Unit_Switches => No_Name_List,
592 Multi_Unit_Object_Separator => ' ',
593 Path_Syntax => Canonical,
594 Source_File_Switches => No_Name_List,
595 Object_File_Suffix => No_Name,
596 Object_File_Switches => No_Name_List,
597 Compilation_PIC_Option => No_Name_List,
598 Object_Generated => True,
599 Objects_Linked => True,
600 Runtime_Library_Dir => No_Name,
601 Runtime_Source_Dir => No_Name,
602 Mapping_File_Switches => No_Name_List,
603 Mapping_Spec_Suffix => No_File,
604 Mapping_Body_Suffix => No_File,
605 Config_File_Switches => No_Name_List,
606 Dependency_Kind => None,
607 Dependency_Option => No_Name_List,
608 Compute_Dependency => No_Name_List,
609 Include_Option => No_Name_List,
610 Include_Path => No_Name,
611 Include_Path_File => No_Name,
612 Objects_Path => No_Name,
613 Objects_Path_File => No_Name,
614 Config_Body => No_Name,
615 Config_Body_Index => No_Name,
616 Config_Body_Pattern => No_Name,
617 Config_Spec => No_Name,
618 Config_Spec_Index => No_Name,
619 Config_Spec_Pattern => No_Name,
620 Config_File_Unique => False,
621 Binder_Driver => No_File,
622 Binder_Driver_Path => No_Path,
623 Binder_Required_Switches => No_Name_List,
624 Binder_Prefix => No_Name,
625 Toolchain_Version => No_Name,
626 Toolchain_Description => No_Name);
628 -- The following record ???
630 type Language_Data is record
631 Name : Name_Id := No_Name;
632 Display_Name : Name_Id := No_Name;
633 Config : Language_Config := No_Language_Config;
634 First_Source : Source_Id := No_Source;
635 Mapping_Files : Mapping_Files_Htable.Instance :=
636 Mapping_Files_Htable.Nil;
637 Next : Language_Ptr := No_Language_Index;
640 No_Language_Data : constant Language_Data :=
642 Display_Name => No_Name,
643 Config => No_Language_Config,
644 First_Source => No_Source,
645 Mapping_Files => Mapping_Files_Htable.Nil,
646 Next => No_Language_Index);
648 type Language_List_Element;
649 type Language_List is access all Language_List_Element;
650 type Language_List_Element is record
651 Language : Language_Ptr := No_Language_Index;
652 Next : Language_List;
655 type Source_Kind is (Spec, Impl, Sep);
656 subtype Spec_Or_Body is Source_Kind range Spec .. Impl;
658 -- The following declarations declare a structure used to store the Name
659 -- and File and Path names of a unit, with a reference to its GNAT Project
660 -- File(s). Some units might have neither Spec nor Impl when they were
661 -- created for a "separate".
663 type File_Names_Data is array (Spec_Or_Body) of Source_Id;
665 type Unit_Data is record
666 Name : Name_Id := No_Name;
667 File_Names : File_Names_Data;
670 type Unit_Index is access all Unit_Data;
672 No_Unit_Index : constant Unit_Index := null;
673 -- Used to indicate a null entry for no unit
676 type Roots_Access is access Source_Roots;
677 type Source_Roots is record
681 -- A list to store the roots associated with a main unit. These are the
682 -- files that need to linked along with the main (for instance a C file
683 -- corresponding to an Ada file). In general, these are dependencies that
684 -- cannot be computed automatically by the builder.
686 type Naming_Exception_Type is (No, Yes, Inherited);
688 -- Structure to define source data
690 type Source_Data is record
691 Initialized : Boolean := False;
692 -- Set to True when Source_Data is completely initialized
694 Project : Project_Id := No_Project;
695 -- Project of the source
697 Location : Source_Ptr := No_Location;
698 -- Location in the project file of the declaration of the source in
701 Source_Dir_Rank : Natural := 0;
702 -- The rank of the source directory in list declared with attribute
703 -- Source_Dirs. Two source files with the same name cannot appears in
704 -- different directory with the same rank. That can happen when the
705 -- recursive notation <dir>/** is used in attribute Source_Dirs.
707 Language : Language_Ptr := No_Language_Index;
708 -- Index of the language. This is an index into
709 -- Project_Tree.Languages_Data.
711 In_Interfaces : Boolean := True;
712 -- False when the source is not included in interfaces, when attribute
713 -- Interfaces is declared.
715 Declared_In_Interfaces : Boolean := False;
716 -- True when source is declared in attribute Interfaces
718 Alternate_Languages : Language_List := null;
719 -- List of languages a header file may also be, in addition of language
722 Kind : Source_Kind := Spec;
723 -- Kind of the source: spec, body or subunit
725 Unit : Unit_Index := No_Unit_Index;
726 -- Name of the unit, if language is unit based. This is only set for
727 -- those files that are part of the compilation set (for instance a
728 -- file in an extended project that is overridden will not have this
732 -- Index of the source in a multi unit source file (the same Source_Data
733 -- is duplicated several times when there are several units in the same
734 -- file). Index is 0 if there is either no unit or a single one, and
735 -- starts at 1 when there are multiple units
737 Compilable : Yes_No_Unknown := Unknown;
738 -- Updated at the first call to Is_Compilable. Yes if source file is
741 In_The_Queue : Boolean := False;
742 -- True if the source has been put in the queue
744 Locally_Removed : Boolean := False;
745 -- True if the source has been "excluded"
747 Replaced_By : Source_Id := No_Source;
748 -- Missing comment ???
750 File : File_Name_Type := No_File;
751 -- Canonical file name of the source
753 Display_File : File_Name_Type := No_File;
754 -- File name of the source, for display purposes
756 Path : Path_Information := No_Path_Information;
757 -- Path name of the source
759 Source_TS : Time_Stamp_Type := Empty_Time_Stamp;
760 -- Time stamp of the source file
762 Object_Project : Project_Id := No_Project;
763 -- Project where the object file is. This might be different from
764 -- Project when using extending project files.
766 Object : File_Name_Type := No_File;
767 -- File name of the object file
769 Current_Object_Path : Path_Name_Type := No_Path;
770 -- Object path of an existing object file
772 Object_Path : Path_Name_Type := No_Path;
773 -- Object path of the real object file
775 Object_TS : Time_Stamp_Type := Empty_Time_Stamp;
776 -- Object file time stamp
778 Dep_Name : File_Name_Type := No_File;
779 -- Dependency file simple name
781 Current_Dep_Path : Path_Name_Type := No_Path;
782 -- Path name of an existing dependency file
784 Dep_Path : Path_Name_Type := No_Path;
785 -- Path name of the real dependency file
787 Dep_TS : aliased Osint.File_Attributes := Osint.Unknown_Attributes;
788 -- Dependency file time stamp
790 Switches : File_Name_Type := No_File;
791 -- File name of the switches file. For all languages, this is a file
792 -- that ends with the .cswi extension.
794 Switches_Path : Path_Name_Type := No_Path;
795 -- Path name of the switches file
797 Switches_TS : Time_Stamp_Type := Empty_Time_Stamp;
798 -- Switches file time stamp
800 Naming_Exception : Naming_Exception_Type := No;
801 -- True if the source has an exceptional name
803 Duplicate_Unit : Boolean := False;
804 -- True when a duplicate unit has been reported for this source
806 Next_In_Lang : Source_Id := No_Source;
807 -- Link to another source of the same language in the same project
809 Next_With_File_Name : Source_Id := No_Source;
810 -- Link to another source with the same base file name
812 Roots : Roots_Access := null;
813 -- The roots for a main unit
817 No_Source_Data : constant Source_Data :=
818 (Initialized => False,
819 Project => No_Project,
820 Location => No_Location,
821 Source_Dir_Rank => 0,
822 Language => No_Language_Index,
823 In_Interfaces => True,
824 Declared_In_Interfaces => False,
825 Alternate_Languages => null,
827 Unit => No_Unit_Index,
829 Locally_Removed => False,
830 Compilable => Unknown,
831 In_The_Queue => False,
832 Replaced_By => No_Source,
834 Display_File => No_File,
835 Path => No_Path_Information,
836 Source_TS => Empty_Time_Stamp,
837 Object_Project => No_Project,
839 Current_Object_Path => No_Path,
840 Object_Path => No_Path,
841 Object_TS => Empty_Time_Stamp,
843 Current_Dep_Path => No_Path,
845 Dep_TS => Osint.Unknown_Attributes,
847 Switches_Path => No_Path,
848 Switches_TS => Empty_Time_Stamp,
849 Naming_Exception => No,
850 Duplicate_Unit => False,
851 Next_In_Lang => No_Source,
852 Next_With_File_Name => No_Source,
855 package Source_Files_Htable is new Simple_HTable
856 (Header_Num => Header_Num,
857 Element => Source_Id,
858 No_Element => No_Source,
859 Key => File_Name_Type,
862 -- Mapping of source file names to source ids
864 package Source_Paths_Htable is new Simple_HTable
865 (Header_Num => Header_Num,
866 Element => Source_Id,
867 No_Element => No_Source,
868 Key => Path_Name_Type,
871 -- Mapping of source paths to source ids
873 type Lib_Kind is (Static, Dynamic, Relocatable);
875 type Policy is (Autonomous, Compliant, Controlled, Restricted, Direct);
876 -- Type to specify the symbol policy, when symbol control is supported.
877 -- See full explanation about this type in package Symbols.
878 -- Autonomous: Create a symbol file without considering any reference
879 -- Compliant: Try to be as compatible as possible with an existing ref
880 -- Controlled: Fail if symbols are not the same as those in the reference
881 -- Restricted: Restrict the symbols to those in the symbol file
882 -- Direct: The symbol file is used as is
884 type Symbol_Record is record
885 Symbol_File : Path_Name_Type := No_Path;
886 Reference : Path_Name_Type := No_Path;
887 Symbol_Policy : Policy := Autonomous;
889 -- Type to keep the symbol data to be used when building a shared library
891 No_Symbols : constant Symbol_Record :=
892 (Symbol_File => No_Path,
893 Reference => No_Path,
894 Symbol_Policy => Autonomous);
895 -- The default value of the symbol data
897 function Image (The_Casing : Casing_Type) return String;
898 -- Similar to 'Image (but avoid use of this attribute in compiler)
900 function Value (Image : String) return Casing_Type;
901 -- Similar to 'Value (but avoid use of this attribute in compiler)
902 -- Raises Constraint_Error if not a Casing_Type image.
904 -- The following record contains data for a naming scheme
906 function Get_Object_Directory
907 (Project : Project_Id;
908 Including_Libraries : Boolean;
909 Only_If_Ada : Boolean := False) return Path_Name_Type;
910 -- Return the object directory to use for the project. This depends on
911 -- whether we have a library project or a standard project. This function
912 -- might return No_Name when no directory applies.
913 -- If we have a library project file and Including_Libraries is True then
914 -- the library dir is returned instead of the object dir.
915 -- If Only_If_Ada is True, then No_Name will be returned when the project
916 -- doesn't Ada sources.
918 procedure Compute_All_Imported_Projects
919 (Root_Project : Project_Id;
920 Tree : Project_Tree_Ref);
921 -- For all projects in the tree, compute the list of the projects imported
922 -- directly or indirectly by project Root_Project. The result is stored in
923 -- Project.All_Imported_Projects for each project
925 function Ultimate_Extending_Project_Of
926 (Proj : Project_Id) return Project_Id;
927 -- Returns the ultimate extending project of project Proj. If project Proj
928 -- is not extended, returns Proj.
930 type Project_List_Element;
931 type Project_List is access all Project_List_Element;
932 type Project_List_Element is record
933 Project : Project_Id := No_Project;
934 Next : Project_List := null;
936 -- A list of projects
939 (List : in out Project_List;
940 Free_Project : Boolean);
941 -- Free the list of projects, if Free_Project, each project is also freed
943 type Response_File_Format is
952 -- The format of the different response files
954 type Project_Configuration is record
955 Target : Name_Id := No_Name;
956 -- The target of the configuration, when specified
958 Run_Path_Option : Name_List_Index := No_Name_List;
959 -- The option to use when linking to specify the path where to look for
962 Run_Path_Origin : Name_Id := No_Name;
963 -- Specify the string (such as "$ORIGIN") to indicate paths relative to
964 -- the directory of the executable in the run path option.
966 Library_Install_Name_Option : Name_Id := No_Name;
967 -- When this is not an empty list, this option, followed by the single
968 -- name of the shared library file is used when linking a shared
971 Separate_Run_Path_Options : Boolean := False;
972 -- True if each directory needs to be specified in a separate run path
975 Executable_Suffix : Name_Id := No_Name;
976 -- The suffix of executables, when specified in the configuration or in
977 -- package Builder of the main project. When this is not specified, the
978 -- executable suffix is the default for the platform.
982 Linker : Path_Name_Type := No_Path;
983 -- Path name of the linker driver. Specified in the configuration or in
984 -- the package Builder of the main project.
986 Map_File_Option : Name_Id := No_Name;
987 -- Option to use when invoking the linker to build a map file
989 Trailing_Linker_Required_Switches : Name_List_Index := No_Name_List;
990 -- The minimum options for the linker driver. Specified in the
993 Linker_Executable_Option : Name_List_Index := No_Name_List;
994 -- The option(s) to indicate the name of the executable in the linker
995 -- command. Specified in the configuration. When not specified, default
996 -- to -o <executable name>.
998 Linker_Lib_Dir_Option : Name_Id := No_Name;
999 -- The option to specify where to find a library for linking. Specified
1000 -- in the configuration. When not specified, defaults to "-L".
1002 Linker_Lib_Name_Option : Name_Id := No_Name;
1003 -- The option to specify the name of a library for linking. Specified in
1004 -- the configuration. When not specified, defaults to "-l".
1006 Max_Command_Line_Length : Natural := 0;
1007 -- When positive and when Resp_File_Format (see below) is not None,
1008 -- if the command line for the invocation of the linker would be greater
1009 -- than this value, a response file is used to invoke the linker.
1011 Resp_File_Format : Response_File_Format := None;
1012 -- The format of a response file, when linking with a response file is
1015 Resp_File_Options : Name_List_Index := No_Name_List;
1016 -- The switches, if any, that precede the path name of the response
1017 -- file in the invocation of the linker.
1021 Library_Builder : Path_Name_Type := No_Path;
1022 -- The executable to build library (specified in the configuration)
1024 Lib_Support : Library_Support := None;
1025 -- The level of library support. Specified in the configuration. Support
1026 -- is none, static libraries only or both static and shared libraries.
1028 Archive_Builder : Name_List_Index := No_Name_List;
1029 -- The name of the executable to build archives, with the minimum
1030 -- switches. Specified in the configuration.
1032 Archive_Builder_Append_Option : Name_List_Index := No_Name_List;
1033 -- The options to append object files to an archive
1035 Archive_Indexer : Name_List_Index := No_Name_List;
1036 -- The name of the executable to index archives, with the minimum
1037 -- switches. Specified in the configuration.
1039 Archive_Suffix : File_Name_Type := No_File;
1040 -- The suffix of archives. Specified in the configuration. When not
1041 -- specified, defaults to ".a".
1043 Lib_Partial_Linker : Name_List_Index := No_Name_List;
1047 Shared_Lib_Driver : File_Name_Type := No_File;
1048 -- The driver to link shared libraries. Set with attribute Library_GCC.
1051 Shared_Lib_Prefix : File_Name_Type := No_File;
1052 -- Part of a shared library file name that precedes the name of the
1053 -- library. Specified in the configuration. When not specified, defaults
1056 Shared_Lib_Suffix : File_Name_Type := No_File;
1057 -- Suffix of shared libraries, after the library name in the shared
1058 -- library name. Specified in the configuration. When not specified,
1059 -- default to ".so".
1061 Shared_Lib_Min_Options : Name_List_Index := No_Name_List;
1062 -- The minimum options to use when building a shared library
1064 Lib_Version_Options : Name_List_Index := No_Name_List;
1065 -- The options to use to specify a library version
1067 Symbolic_Link_Supported : Boolean := False;
1068 -- True if the platform supports symbolic link files
1070 Lib_Maj_Min_Id_Supported : Boolean := False;
1071 -- True if platform supports library major and minor options, such as
1072 -- libname.so -> libname.so.2 -> libname.so.2.4
1074 Auto_Init_Supported : Boolean := False;
1075 -- True if automatic initialisation is supported for shared stand-alone
1079 Default_Project_Config : constant Project_Configuration :=
1081 Run_Path_Option => No_Name_List,
1082 Run_Path_Origin => No_Name,
1083 Library_Install_Name_Option => No_Name,
1084 Separate_Run_Path_Options => False,
1085 Executable_Suffix => No_Name,
1087 Map_File_Option => No_Name,
1088 Trailing_Linker_Required_Switches =>
1090 Linker_Executable_Option => No_Name_List,
1091 Linker_Lib_Dir_Option => No_Name,
1092 Linker_Lib_Name_Option => No_Name,
1093 Library_Builder => No_Path,
1094 Max_Command_Line_Length => 0,
1095 Resp_File_Format => None,
1096 Resp_File_Options => No_Name_List,
1097 Lib_Support => None,
1098 Archive_Builder => No_Name_List,
1099 Archive_Builder_Append_Option => No_Name_List,
1100 Archive_Indexer => No_Name_List,
1101 Archive_Suffix => No_File,
1102 Lib_Partial_Linker => No_Name_List,
1103 Shared_Lib_Driver => No_File,
1104 Shared_Lib_Prefix => No_File,
1105 Shared_Lib_Suffix => No_File,
1106 Shared_Lib_Min_Options => No_Name_List,
1107 Lib_Version_Options => No_Name_List,
1108 Symbolic_Link_Supported => False,
1109 Lib_Maj_Min_Id_Supported => False,
1110 Auto_Init_Supported => False);
1112 -------------------------
1113 -- Aggregated projects --
1114 -------------------------
1116 type Aggregated_Project;
1117 type Aggregated_Project_List is access all Aggregated_Project;
1118 type Aggregated_Project is record
1119 Path : Path_Name_Type;
1120 Tree : Project_Tree_Ref;
1121 Project : Project_Id;
1122 Next : Aggregated_Project_List;
1125 procedure Free (List : in out Aggregated_Project_List);
1126 -- Free the memory used for List
1128 procedure Add_Aggregated_Project
1129 (Project : Project_Id;
1130 Path : Path_Name_Type);
1131 -- Add a new aggregated project in Project.
1132 -- The aggregated project has not been processed yet. This procedure should
1133 -- the called while processing the aggregate project, and as a result
1134 -- Prj.Proc.Process will then automatically process the aggregated projects
1140 -- The following record describes a project file representation
1142 type Project_Data (Qualifier : Project_Qualifier := Unspecified) is record
1148 Name : Name_Id := No_Name;
1149 -- The name of the project
1151 Display_Name : Name_Id := No_Name;
1152 -- The name of the project with the spelling of its declaration
1154 Externally_Built : Boolean := False;
1155 -- True if the project is externally built. In such case, the Project
1156 -- Manager will not modify anything in this project.
1158 Config : Project_Configuration;
1160 Path : Path_Information := No_Path_Information;
1161 -- The path name of the project file. This include base name of the
1164 Virtual : Boolean := False;
1165 -- True for virtual extending projects
1167 Location : Source_Ptr := No_Location;
1168 -- The location in the project file source of the reserved word project
1174 Languages : Language_Ptr := No_Language_Index;
1175 -- First index of the language data in the project.
1176 -- This is an index into the project_tree_data.languages_data.
1177 -- Traversing the list gives access to all the languages supported by
1184 Mains : String_List_Id := Nil_String;
1185 -- List of mains specified by attribute Main
1187 Extends : Project_Id := No_Project;
1188 -- The reference of the project file, if any, that this project file
1191 Extended_By : Project_Id := No_Project;
1192 -- The reference of the project file, if any, that extends this project
1195 Decl : Declarations := No_Declarations;
1196 -- The declarations (variables, attributes and packages) of this project
1199 Imported_Projects : Project_List := null;
1200 -- The list of all directly imported projects, if any
1202 All_Imported_Projects : Project_List := null;
1203 -- The list of all projects imported directly or indirectly, if any.
1204 -- This does not include the project itself.
1210 Directory : Path_Information := No_Path_Information;
1211 -- Path name of the directory where the project file resides
1213 Object_Directory : Path_Information := No_Path_Information;
1214 -- The path name of the object directory of this project file
1216 Exec_Directory : Path_Information := No_Path_Information;
1217 -- The path name of the exec directory of this project file. Default is
1218 -- equal to Object_Directory.
1224 Library : Boolean := False;
1225 -- True if this is a library project
1227 Library_Name : Name_Id := No_Name;
1228 -- If a library project, name of the library
1230 Library_Kind : Lib_Kind := Static;
1231 -- If a library project, kind of library
1233 Library_Dir : Path_Information := No_Path_Information;
1234 -- If a library project, path name of the directory where the library
1237 Library_TS : Time_Stamp_Type := Empty_Time_Stamp;
1238 -- The timestamp of a library file in a library project
1240 Library_Src_Dir : Path_Information := No_Path_Information;
1241 -- If a Stand-Alone Library project, path name of the directory where
1242 -- the sources of the interfaces of the library are copied. By default,
1243 -- if attribute Library_Src_Dir is not specified, sources of the
1244 -- interfaces are not copied anywhere.
1246 Library_ALI_Dir : Path_Information := No_Path_Information;
1247 -- In a library project, path name of the directory where the ALI files
1248 -- are copied. If attribute Library_ALI_Dir is not specified, ALI files
1249 -- are copied in the Library_Dir.
1251 Lib_Internal_Name : Name_Id := No_Name;
1252 -- If a library project, internal name store inside the library
1254 Standalone_Library : Boolean := False;
1255 -- Indicate that this is a Standalone Library Project File
1257 Lib_Interface_ALIs : String_List_Id := Nil_String;
1258 -- For Standalone Library Project Files, indicate the list of Interface
1261 Lib_Auto_Init : Boolean := False;
1262 -- For non static Stand-Alone Library Project Files, indicate if
1263 -- the library initialisation should be automatic.
1265 Symbol_Data : Symbol_Record := No_Symbols;
1266 -- Symbol file name, reference symbol file name, symbol policy
1268 Need_To_Build_Lib : Boolean := False;
1269 -- Indicates that the library of a Library Project needs to be built or
1275 -- The sources for all languages including Ada are accessible through
1276 -- the Source_Iterator type
1278 Interfaces_Defined : Boolean := False;
1279 -- True if attribute Interfaces is declared for the project or any
1280 -- project it extends.
1282 Include_Path_File : Path_Name_Type := No_Path;
1283 -- The path name of the of the source search directory file.
1284 -- This is only used by gnatmake
1286 Source_Dirs : String_List_Id := Nil_String;
1287 -- The list of all the source directories
1289 Source_Dir_Ranks : Number_List_Index := No_Number_List;
1291 Ada_Include_Path : String_Access := null;
1292 -- The cached value of source search path for this project file. Set by
1293 -- the first call to Prj.Env.Ada_Include_Path for the project. Do not
1294 -- use this field directly outside of the project manager, use
1295 -- Prj.Env.Ada_Include_Path instead.
1297 Has_Multi_Unit_Sources : Boolean := False;
1298 -- Whether there is at least one source file containing multiple units
1304 Ada_Objects_Path : String_Access := null;
1305 -- The cached value of ADA_OBJECTS_PATH for this project file. Do not
1306 -- use this field directly outside of the compiler, use
1307 -- Prj.Env.Ada_Objects_Path instead.
1309 Libgnarl_Needed : Yes_No_Unknown := Unknown;
1310 -- Set to True when libgnarl is needed to link
1312 Objects_Path : String_Access := null;
1313 -- The cached value of the object dir path, used during the binding
1314 -- phase of gprbuild.
1316 Objects_Path_File_With_Libs : Path_Name_Type := No_Path;
1317 -- The cached value of the object path temp file (including library
1318 -- dirs) for this project file.
1320 Objects_Path_File_Without_Libs : Path_Name_Type := No_Path;
1321 -- The cached value of the object path temp file (excluding library
1322 -- dirs) for this project file.
1324 Config_File_Name : Path_Name_Type := No_Path;
1325 -- The path name of the configuration pragmas file, if any
1327 Config_File_Temp : Boolean := False;
1328 -- An indication that the configuration pragmas file is a temporary file
1329 -- that must be deleted at the end.
1331 Config_Checked : Boolean := False;
1332 -- A flag to avoid checking repetitively the configuration pragmas file
1334 Depth : Natural := 0;
1335 -- The maximum depth of a project in the project graph. Depth of main
1338 Unkept_Comments : Boolean := False;
1339 -- True if there are comments in the project sources that cannot be kept
1340 -- in the project tree.
1342 -----------------------------
1343 -- Qualifier-Specific data --
1344 -----------------------------
1346 -- The following fields are only valid for specific types of projects
1349 when Aggregate | Aggregate_Library =>
1350 Aggregated_Projects : Aggregated_Project_List := null;
1351 -- List of aggregated projects (which could themselves be
1352 -- aggregate projects).
1359 function Empty_Project (Qualifier : Project_Qualifier) return Project_Data;
1360 -- Return the representation of an empty project
1362 function Is_Extending
1363 (Extending : Project_Id;
1364 Extended : Project_Id) return Boolean;
1365 -- Return True if Extending is extending the Extended project
1367 function Has_Ada_Sources (Data : Project_Id) return Boolean;
1368 -- Return True if the project has Ada sources
1370 Project_Error : exception;
1371 -- Raised by some subprograms in Prj.Attr
1373 package Units_Htable is new Simple_HTable
1374 (Header_Num => Header_Num,
1375 Element => Unit_Index,
1376 No_Element => No_Unit_Index,
1380 -- Mapping of unit names to indexes in the Units table
1382 ---------------------
1383 -- Source_Iterator --
1384 ---------------------
1386 type Source_Iterator is private;
1388 function For_Each_Source
1389 (In_Tree : Project_Tree_Ref;
1390 Project : Project_Id := No_Project;
1391 Language : Name_Id := No_Name) return Source_Iterator;
1392 -- Returns an iterator for all the sources of a project tree, or a specific
1393 -- project, or a specific language.
1395 function Element (Iter : Source_Iterator) return Source_Id;
1396 -- Return the current source (or No_Source if there are no more sources)
1398 procedure Next (Iter : in out Source_Iterator);
1399 -- Move on to the next source
1401 function Find_Source
1402 (In_Tree : Project_Tree_Ref;
1403 Project : Project_Id;
1404 In_Imported_Only : Boolean := False;
1405 In_Extended_Only : Boolean := False;
1406 Base_Name : File_Name_Type;
1407 Index : Int := 0) return Source_Id;
1408 -- Find the first source file with the given name.
1409 -- If In_Extended_Only is True, it will search in project and the project
1410 -- it extends, but not in the imported projects.
1411 -- Elsif In_Imported_Only is True, it will search in project and the
1412 -- projects it imports, but not in the others or in aggregated projects.
1413 -- Else it searches in the whole tree.
1414 -- If Index is specified, this only search for a source with that index.
1416 -----------------------
1417 -- Project_Tree_Data --
1418 -----------------------
1420 package Replaced_Source_HTable is new Simple_HTable
1421 (Header_Num => Header_Num,
1422 Element => File_Name_Type,
1423 No_Element => No_File,
1424 Key => File_Name_Type,
1428 type Private_Project_Tree_Data is private;
1429 -- Data for a project tree that is used only by the Project Manager
1431 type Shared_Project_Tree_Data is record
1432 Name_Lists : Name_List_Table.Instance;
1433 Number_Lists : Number_List_Table.Instance;
1434 String_Elements : String_Element_Table.Instance;
1435 Variable_Elements : Variable_Element_Table.Instance;
1436 Array_Elements : Array_Element_Table.Instance;
1437 Arrays : Array_Table.Instance;
1438 Packages : Package_Table.Instance;
1439 Private_Part : Private_Project_Tree_Data;
1441 type Shared_Project_Tree_Data_Access is access all Shared_Project_Tree_Data;
1442 -- The data that is shared among multiple trees, when these trees are
1443 -- loaded through the same aggregate project.
1444 -- To avoid ambiguities, limit the number of parameters to the
1445 -- subprograms (we would have to parse the "root project tree" since this
1446 -- is where the configuration file was loaded, in addition to the project's
1447 -- own tree) and make the comparison of projects easier, all trees store
1448 -- the lists in the same tables.
1450 type Project_Tree_Appdata is tagged null record;
1451 type Project_Tree_Appdata_Access is access all Project_Tree_Appdata'Class;
1452 -- Application-specific data that can be associated with a project tree.
1453 -- We do not make the Project_Tree_Data itself tagged for several reasons:
1454 -- - it couldn't have a default value for its discriminant
1455 -- - it would require a "factory" to allocate such data, because trees
1456 -- are created automatically when parsing aggregate projects.
1458 procedure Free (Tree : in out Project_Tree_Appdata);
1459 -- Should be overridden if your derive your own data
1461 type Project_Tree_Data (Is_Root_Tree : Boolean := True) is record
1462 -- The root tree is the one loaded by the user from the command line.
1463 -- Is_Root_Tree is only false for projects aggregated within a root
1464 -- aggregate project.
1466 Projects : Project_List;
1467 -- List of projects in this tree
1469 Replaced_Sources : Replaced_Source_HTable.Instance;
1470 -- The list of sources that have been replaced by sources with
1471 -- different file names.
1473 Replaced_Source_Number : Natural := 0;
1474 -- The number of entries in Replaced_Sources
1476 Units_HT : Units_Htable.Instance;
1477 -- Unit name to Unit_Index (and from there to Source_Id)
1479 Source_Files_HT : Source_Files_Htable.Instance;
1480 -- Base source file names to Source_Id list
1482 Source_Paths_HT : Source_Paths_Htable.Instance;
1483 -- Full path to Source_Id
1484 -- ??? What is behavior for multi-unit source files, where there are
1485 -- several source_id per file ?
1487 Source_Info_File_Name : String_Access := null;
1488 -- The name of the source info file, if specified by the builder
1490 Source_Info_File_Exists : Boolean := False;
1491 -- True when a source info file has been successfully read
1493 Shared : Shared_Project_Tree_Data_Access;
1494 -- The shared data for this tree and all aggregated trees
1496 Appdata : Project_Tree_Appdata_Access;
1497 -- Application-specific data for this tree
1499 case Is_Root_Tree is
1501 Shared_Data : aliased Shared_Project_Tree_Data;
1502 -- Do not access directly, only through Shared
1508 -- Data for a project tree
1510 function Debug_Name (Tree : Project_Tree_Ref) return Name_Id;
1511 -- If debug traces are activated, return an identitier for the project
1512 -- tree. This modifies Name_Buffer.
1514 procedure Expect (The_Token : Token_Type; Token_Image : String);
1515 -- Check that the current token is The_Token. If it is not, then output
1516 -- an error message.
1518 procedure Initialize (Tree : Project_Tree_Ref);
1519 -- This procedure must be called before using any services from the Prj
1520 -- hierarchy. Namet.Initialize must be called before Prj.Initialize.
1522 procedure Reset (Tree : Project_Tree_Ref);
1523 -- This procedure resets all the tables that are used when processing a
1524 -- project file tree. Initialize must be called before the call to Reset.
1526 package Project_Boolean_Htable is new Simple_HTable
1527 (Header_Num => Header_Num,
1529 No_Element => False,
1533 -- A table that associates a project to a boolean. This is used to detect
1534 -- whether a project was already processed for instance.
1537 with procedure Action (Project : Project_Id; Tree : Project_Tree_Ref);
1538 procedure For_Project_And_Aggregated
1539 (Root_Project : Project_Id;
1540 Root_Tree : Project_Tree_Ref);
1541 -- Execute Action for Root_Project and all its aggregated projects
1545 type State is limited private;
1546 with procedure Action
1547 (Project : Project_Id;
1548 Tree : Project_Tree_Ref;
1549 With_State : in out State);
1550 procedure For_Every_Project_Imported
1552 Tree : Project_Tree_Ref;
1553 With_State : in out State;
1554 Include_Aggregated : Boolean := True;
1555 Imported_First : Boolean := False);
1556 -- Call Action for each project imported directly or indirectly by project
1557 -- By, as well as extended projects.
1559 -- The order of processing depends on Imported_First:
1561 -- If False, Action is called according to the order of importation: if A
1562 -- imports B, directly or indirectly, Action will be called for A before
1563 -- it is called for B. If two projects import each other directly or
1564 -- indirectly (using at least one "limited with"), it is not specified
1565 -- for which of these two projects Action will be called first.
1567 -- The order is reversed if Imported_First is True
1569 -- With_State may be used by Action to choose a behavior or to report some
1572 -- If Include_Aggregated is True, then an aggregate project will recurse
1573 -- into the projects it aggregates. Otherwise, the latter are never
1576 -- The Tree argument passed to the callback is required in the case of
1577 -- aggregated projects, since they might not be using the same tree as 'By'
1579 function Extend_Name
1580 (File : File_Name_Type;
1581 With_Suffix : String) return File_Name_Type;
1582 -- Replace the extension of File with With_Suffix
1584 function Object_Name
1585 (Source_File_Name : File_Name_Type;
1586 Object_File_Suffix : Name_Id := No_Name) return File_Name_Type;
1587 -- Returns the object file name corresponding to a source file name
1589 function Object_Name
1590 (Source_File_Name : File_Name_Type;
1592 Index_Separator : Character;
1593 Object_File_Suffix : Name_Id := No_Name) return File_Name_Type;
1594 -- Returns the object file name corresponding to a unit in a multi-source
1597 function Dependency_Name
1598 (Source_File_Name : File_Name_Type;
1599 Dependency : Dependency_File_Kind) return File_Name_Type;
1600 -- Returns the dependency file name corresponding to a source file name
1602 function Switches_Name
1603 (Source_File_Name : File_Name_Type) return File_Name_Type;
1604 -- Returns the switches file name corresponding to a source file name
1606 procedure Set_Path_File_Var (Name : String; Value : String);
1607 -- Call Setenv, after calling To_Host_File_Spec
1609 function Current_Source_Path_File_Of
1610 (Shared : Shared_Project_Tree_Data_Access) return Path_Name_Type;
1611 -- Get the current include path file name
1613 procedure Set_Current_Source_Path_File_Of
1614 (Shared : Shared_Project_Tree_Data_Access;
1615 To : Path_Name_Type);
1616 -- Record the current include path file name
1618 function Current_Object_Path_File_Of
1619 (Shared : Shared_Project_Tree_Data_Access) return Path_Name_Type;
1620 -- Get the current object path file name
1622 procedure Set_Current_Object_Path_File_Of
1623 (Shared : Shared_Project_Tree_Data_Access;
1624 To : Path_Name_Type);
1625 -- Record the current object path file name
1631 type Processing_Flags is private;
1632 -- Flags used while parsing and processing a project tree to configure the
1633 -- behavior of the parser, and indicate how to report error messages. This
1634 -- structure does not allocate memory and never needs to be freed
1636 type Error_Warning is (Silent, Warning, Error);
1637 -- Severity of some situations, such as: no Ada sources in a project where
1638 -- Ada is one of the language.
1640 -- When the situation occurs, the behaviour depends on the setting:
1642 -- - Silent: no action
1643 -- - Warning: issue a warning, does not cause the tool to fail
1644 -- - Error: issue an error, causes the tool to fail
1646 type Error_Handler is access procedure
1647 (Project : Project_Id;
1648 Is_Warning : Boolean);
1649 -- This warns when an error was found when parsing a project. The error
1650 -- itself is handled through Prj.Err (and Prj.Err.Finalize should be called
1651 -- to actually print the error). This ensures that duplicate error messages
1652 -- are always correctly removed, that errors msgs are sorted, and that all
1653 -- tools will report the same error to the user.
1655 function Create_Flags
1656 (Report_Error : Error_Handler;
1657 When_No_Sources : Error_Warning;
1658 Require_Sources_Other_Lang : Boolean := True;
1659 Allow_Duplicate_Basenames : Boolean := True;
1660 Compiler_Driver_Mandatory : Boolean := False;
1661 Error_On_Unknown_Language : Boolean := True;
1662 Require_Obj_Dirs : Error_Warning := Error;
1663 Allow_Invalid_External : Error_Warning := Error;
1664 Missing_Source_Files : Error_Warning := Error;
1665 Ignore_Missing_With : Boolean := False)
1666 return Processing_Flags;
1667 -- Function used to create Processing_Flags structure
1669 -- If Allow_Duplicate_Basenames, then files with the same base names are
1670 -- authorized within a project for source-based languages (never for unit
1671 -- based languages).
1673 -- If Compiler_Driver_Mandatory is true, then a Compiler.Driver attribute
1674 -- for each language must be defined, or we will not look for its source
1677 -- When_No_Sources indicates what should be done when no sources of a
1678 -- language are found in a project where this language is declared.
1679 -- If Require_Sources_Other_Lang is true, then all languages must have at
1680 -- least one source file, or an error is reported via When_No_Sources. If
1681 -- it is false, this is only required for Ada (and only if it is a language
1682 -- of the project). When this parameter is set to False, we do not check
1683 -- that a proper naming scheme is defined for languages other than Ada.
1685 -- If Report_Error is null, use the standard error reporting mechanism
1686 -- (Errout). Otherwise, report errors using Report_Error.
1688 -- If Error_On_Unknown_Language is true, an error is displayed if some of
1689 -- the source files listed in the project do not match any naming scheme
1691 -- If Require_Obj_Dirs is true, then all object directories must exist
1692 -- (possibly after they have been created automatically if the appropriate
1693 -- switches were specified), or an error is raised.
1695 -- If Allow_Invalid_External is Silent, then no error is reported when an
1696 -- invalid value is used for an external variable (and it doesn't match its
1697 -- type). Instead, the first possible value is used.
1699 -- Missing_Source_Files indicates whether it is an error or a warning that
1700 -- a source file mentioned in the Source_Files attributes is not actually
1701 -- found in the source directories. This also impacts errors for missing
1702 -- source directories.
1704 -- If Ignore_Missing_With is True, then a "with" statement that cannot be
1705 -- resolved will simply be ignored. However, in such a case, the flag
1706 -- Incomplete_With in the project tree will be set to True.
1707 -- This is meant for use by tools so that they can properly set the
1708 -- project path in such a case:
1709 -- * no "gnatls" found (so no default project path)
1710 -- * user project sets Project.IDE'gnatls attribute to a cross gnatls
1711 -- * user project also includes a "with" that can only be resolved
1712 -- once we have found the gnatls
1714 Gprbuild_Flags : constant Processing_Flags;
1715 Gprclean_Flags : constant Processing_Flags;
1716 Gnatmake_Flags : constant Processing_Flags;
1717 -- Flags used by the various tools. They all display the error messages
1724 procedure Record_Temp_File
1725 (Shared : Shared_Project_Tree_Data_Access;
1726 Path : Path_Name_Type);
1727 -- Record the path of a newly created temporary file, so that it can be
1730 procedure Delete_All_Temp_Files
1731 (Shared : Shared_Project_Tree_Data_Access);
1732 -- Delete all recorded temporary files.
1733 -- Does nothing if Debug.Debug_Flag_N is set
1735 procedure Delete_Temp_Config_Files (Project_Tree : Project_Tree_Ref);
1736 -- Delete all temporary config files. Does nothing if Debug.Debug_Flag_N is
1737 -- set or if Project_Tree is null. This initially came from gnatmake
1738 -- ??? Should this be combined with Delete_All_Temp_Files above
1740 procedure Delete_Temporary_File
1741 (Shared : Shared_Project_Tree_Data_Access := null;
1742 Path : Path_Name_Type);
1743 -- Delete a temporary file from the disk. The file is also removed from the
1744 -- list of temporary files to delete at the end of the program, in case
1745 -- another program running on the same machine has recreated it. Does
1746 -- nothing if Debug.Debug_Flag_N is set
1748 Virtual_Prefix : constant String := "v$";
1749 -- The prefix for virtual extending projects. Because of the '$', which is
1750 -- normally forbidden for project names, there cannot be any name clash.
1756 type Verbosity is (Default, Medium, High);
1757 pragma Ordered (Verbosity);
1758 -- Verbosity when parsing GNAT Project Files
1759 -- Default is default (very quiet, if no errors).
1760 -- Medium is more verbose.
1761 -- High is extremely verbose.
1763 Current_Verbosity : Verbosity := Default;
1764 -- The current value of the verbosity the project files are parsed with
1766 procedure Debug_Indent;
1767 -- Inserts a series of blanks depending on the current indentation level
1769 procedure Debug_Output (Str : String);
1770 procedure Debug_Output (Str : String; Str2 : Name_Id);
1771 -- If Current_Verbosity is not Default, outputs Str.
1772 -- This indents Str based on the current indentation level for traces
1773 -- Debug_Error is intended to be used to report an error in the traces.
1775 procedure Debug_Increase_Indent
1776 (Str : String := ""; Str2 : Name_Id := No_Name);
1777 procedure Debug_Decrease_Indent (Str : String := "");
1778 -- Increase or decrease the indentation level for debug traces. This
1779 -- indentation level only affects output done through Debug_Output.
1783 All_Packages : constant String_List_Access := null;
1785 No_Project_Tree : constant Project_Tree_Ref := null;
1787 Ignored : constant Variable_Kind := Single;
1789 Nil_Variable_Value : constant Variable_Value :=
1790 (Project => No_Project,
1792 Location => No_Location,
1795 type Source_Iterator is record
1796 In_Tree : Project_Tree_Ref;
1798 Project : Project_List;
1799 All_Projects : Boolean;
1800 -- Current project and whether we should move on to the next
1802 Language : Language_Ptr;
1803 -- Current language processed
1805 Language_Name : Name_Id;
1806 -- Only sources of this language will be returned (or all if No_Name)
1808 Current : Source_Id;
1811 procedure Add_To_Buffer
1813 To : in out String_Access;
1814 Last : in out Natural);
1815 -- Append a String to the Buffer
1817 package Temp_Files_Table is new GNAT.Dynamic_Tables
1818 (Table_Component_Type => Path_Name_Type,
1819 Table_Index_Type => Integer,
1820 Table_Low_Bound => 1,
1821 Table_Initial => 10,
1822 Table_Increment => 10);
1823 -- Table to store the path name of all the created temporary files, so that
1824 -- they can be deleted at the end, or when the program is interrupted.
1826 type Private_Project_Tree_Data is record
1827 Temp_Files : Temp_Files_Table.Instance;
1828 -- Temporary files created as part of running tools (pragma files,
1829 -- mapping files,...)
1831 Current_Source_Path_File : Path_Name_Type := No_Path;
1832 -- Current value of project source path file env var. Used to avoid
1833 -- setting the env var to the same value. When different from No_Path,
1834 -- this indicates that logical names (VMS) or environment variables were
1835 -- created and should be deassigned to avoid polluting the environment
1839 Current_Object_Path_File : Path_Name_Type := No_Path;
1840 -- Current value of project object path file env var. Used to avoid
1841 -- setting the env var to the same value.
1845 -- Type to represent the part of a project tree which is private to the
1848 type Processing_Flags is record
1849 Require_Sources_Other_Lang : Boolean;
1850 Report_Error : Error_Handler;
1851 When_No_Sources : Error_Warning;
1852 Allow_Duplicate_Basenames : Boolean;
1853 Compiler_Driver_Mandatory : Boolean;
1854 Error_On_Unknown_Language : Boolean;
1855 Require_Obj_Dirs : Error_Warning;
1856 Allow_Invalid_External : Error_Warning;
1857 Missing_Source_Files : Error_Warning;
1858 Ignore_Missing_With : Boolean;
1861 Gprbuild_Flags : constant Processing_Flags :=
1862 (Report_Error => null,
1863 When_No_Sources => Warning,
1864 Require_Sources_Other_Lang => True,
1865 Allow_Duplicate_Basenames => False,
1866 Compiler_Driver_Mandatory => True,
1867 Error_On_Unknown_Language => True,
1868 Require_Obj_Dirs => Error,
1869 Allow_Invalid_External => Error,
1870 Missing_Source_Files => Error,
1871 Ignore_Missing_With => False);
1873 Gprclean_Flags : constant Processing_Flags :=
1874 (Report_Error => null,
1875 When_No_Sources => Warning,
1876 Require_Sources_Other_Lang => True,
1877 Allow_Duplicate_Basenames => False,
1878 Compiler_Driver_Mandatory => True,
1879 Error_On_Unknown_Language => True,
1880 Require_Obj_Dirs => Warning,
1881 Allow_Invalid_External => Error,
1882 Missing_Source_Files => Error,
1883 Ignore_Missing_With => False);
1885 Gnatmake_Flags : constant Processing_Flags :=
1886 (Report_Error => null,
1887 When_No_Sources => Error,
1888 Require_Sources_Other_Lang => False,
1889 Allow_Duplicate_Basenames => False,
1890 Compiler_Driver_Mandatory => False,
1891 Error_On_Unknown_Language => False,
1892 Require_Obj_Dirs => Error,
1893 Allow_Invalid_External => Error,
1894 Missing_Source_Files => Error,
1895 Ignore_Missing_With => False);