1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2013, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 -- The following package declares the data types for GNAT project.
27 -- These data types may be used by GNAT Project-aware tools.
29 -- Children of these package implements various services on these data types.
30 -- See in particular Prj.Pars and Prj.Env.
32 with Casing; use Casing;
33 with Namet; use Namet;
35 with Scans; use Scans;
36 with Types; use Types;
38 with GNAT.Dynamic_HTables; use GNAT.Dynamic_HTables;
39 with GNAT.Dynamic_Tables;
40 with GNAT.OS_Lib; use GNAT.OS_Lib;
44 procedure Add_Restricted_Language (Name : String);
45 -- Call by gprbuild for each language specify by switch
46 -- --restricted-to-languages=.
48 procedure Remove_All_Restricted_Languages;
49 -- Call by gprbuild in CodePeer mode to ignore switches
50 -- --restricted-to-languages=.
52 function Is_Allowed_Language (Name : Name_Id) return Boolean;
53 -- Returns True if --restricted-to-languages= is not used or if Name
54 -- is one of the restricted languages.
56 All_Other_Names : constant Name_Id := Names_High_Bound;
57 -- Name used to replace others as an index of an associative array
58 -- attribute in situations where this is allowed.
60 Subdirs : String_Ptr := null;
61 -- The value after the equal sign in switch --subdirs=...
62 -- Contains the relative subdirectory.
64 type Library_Support is (None, Static_Only, Full);
65 -- Support for Library Project File.
66 -- - None: Library Project Files are not supported at all
67 -- - Static_Only: Library Project Files are only supported for static
69 -- - Full: Library Project Files are supported for static and dynamic
70 -- (shared) libraries.
72 type Yes_No_Unknown is (Yes, No, Unknown);
73 -- Tri-state to decide if -lgnarl is needed when linking
75 pragma Warnings (Off);
76 type Project_Qualifier is
79 -- The following clash with Standard is OK, and justified by the context
80 -- which really wants to use the same set of qualifiers.
90 -- Qualifiers that can prefix the reserved word "project" in a project
92 -- Standard: standard project ...
93 -- Library: library project is ...
94 -- Dry: abstract project is
95 -- Aggregate: aggregate project is
96 -- Aggregate_Library: aggregate library project is ...
97 -- Configuration: configuration project is ...
99 subtype Aggregate_Project is
100 Project_Qualifier range Aggregate .. Aggregate_Library;
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 Config_Project_File_Extension : String := ".cgpr";
117 Project_File_Extension : String := ".gpr";
118 -- The standard config and user project file name extensions. They are not
119 -- constants, because Canonical_Case_File_Name is called on these variables
120 -- in the body of Prj.
122 function Empty_File return File_Name_Type;
123 function Empty_String return Name_Id;
124 -- Return the id for an empty string ""
126 type Path_Information is record
127 Name : Path_Name_Type := No_Path;
128 Display_Name : Path_Name_Type := No_Path;
130 -- Directory names always end with a directory separator
132 No_Path_Information : constant Path_Information := (No_Path, No_Path);
135 type Project_Id is access all Project_Data;
136 No_Project : constant Project_Id := null;
137 -- Id of a Project File
139 type String_List_Id is new Nat;
140 Nil_String : constant String_List_Id := 0;
141 type String_Element is record
142 Value : Name_Id := No_Name;
144 Display_Value : Name_Id := No_Name;
145 Location : Source_Ptr := No_Location;
146 Flag : Boolean := False;
147 Next : String_List_Id := Nil_String;
149 -- To hold values for string list variables and array elements.
150 -- Component Flag may be used for various purposes. For source
151 -- directories, it indicates if the directory contains Ada source(s).
153 package String_Element_Table is new GNAT.Dynamic_Tables
154 (Table_Component_Type => String_Element,
155 Table_Index_Type => String_List_Id,
156 Table_Low_Bound => 1,
157 Table_Initial => 200,
158 Table_Increment => 100);
159 -- The table for string elements in string lists
161 type Variable_Kind is (Undefined, List, Single);
162 -- Different kinds of variables
164 subtype Defined_Variable_Kind is Variable_Kind range List .. Single;
165 -- The defined kinds of variables
167 Ignored : constant Variable_Kind;
168 -- Used to indicate that a package declaration must be ignored while
169 -- processing the project tree (unknown package name).
171 type Variable_Value (Kind : Variable_Kind := Undefined) is record
172 Project : Project_Id := No_Project;
173 Location : Source_Ptr := No_Location;
174 Default : Boolean := False;
179 Values : String_List_Id := Nil_String;
181 Value : Name_Id := No_Name;
185 -- Values for variables and array elements. Default is True if the
186 -- current value is the default one for the variable.
188 Nil_Variable_Value : constant Variable_Value;
189 -- Value of a non existing variable or array element
191 type Variable_Id is new Nat;
192 No_Variable : constant Variable_Id := 0;
193 type Variable is record
194 Next : Variable_Id := No_Variable;
196 Value : Variable_Value;
198 -- To hold the list of variables in a project file and in packages
200 package Variable_Element_Table is new GNAT.Dynamic_Tables
201 (Table_Component_Type => Variable,
202 Table_Index_Type => Variable_Id,
203 Table_Low_Bound => 1,
204 Table_Initial => 200,
205 Table_Increment => 100);
206 -- The table of variable in list of variables
208 type Array_Element_Id is new Nat;
209 No_Array_Element : constant Array_Element_Id := 0;
210 type Array_Element is record
212 Restricted : Boolean := False;
213 Src_Index : Int := 0;
214 Index_Case_Sensitive : Boolean := True;
215 Value : Variable_Value;
216 Next : Array_Element_Id := No_Array_Element;
218 -- Each Array_Element represents an array element and is linked (Next)
219 -- to the next array element, if any, in the array.
221 package Array_Element_Table is new GNAT.Dynamic_Tables
222 (Table_Component_Type => Array_Element,
223 Table_Index_Type => Array_Element_Id,
224 Table_Low_Bound => 1,
225 Table_Initial => 200,
226 Table_Increment => 100);
227 -- The table that contains all array elements
229 type Array_Id is new Nat;
230 No_Array : constant Array_Id := 0;
231 type Array_Data is record
232 Name : Name_Id := No_Name;
233 Location : Source_Ptr := No_Location;
234 Value : Array_Element_Id := No_Array_Element;
235 Next : Array_Id := No_Array;
237 -- Each Array_Data value represents an array.
238 -- Value is the id of the first element.
239 -- Next is the id of the next array in the project file or package.
241 package Array_Table is new GNAT.Dynamic_Tables
242 (Table_Component_Type => Array_Data,
243 Table_Index_Type => Array_Id,
244 Table_Low_Bound => 1,
245 Table_Initial => 200,
246 Table_Increment => 100);
247 -- The table that contains all arrays
249 type Package_Id is new Nat;
250 No_Package : constant Package_Id := 0;
251 type Declarations is record
252 Variables : Variable_Id := No_Variable;
253 Attributes : Variable_Id := No_Variable;
254 Arrays : Array_Id := No_Array;
255 Packages : Package_Id := No_Package;
257 -- Contains the declarations (variables, single and array attributes,
258 -- packages) for a project or a package in a project.
260 No_Declarations : constant Declarations :=
261 (Variables => No_Variable,
262 Attributes => No_Variable,
264 Packages => No_Package);
265 -- Default value of Declarations: used if there are no declarations
267 type Package_Element is record
268 Name : Name_Id := No_Name;
269 Decl : Declarations := No_Declarations;
270 Parent : Package_Id := No_Package;
271 Next : Package_Id := No_Package;
273 -- A package (includes declarations that may include other packages)
275 package Package_Table is new GNAT.Dynamic_Tables
276 (Table_Component_Type => Package_Element,
277 Table_Index_Type => Package_Id,
278 Table_Low_Bound => 1,
279 Table_Initial => 100,
280 Table_Increment => 100);
281 -- The table that contains all packages
284 type Language_Ptr is access all Language_Data;
285 -- Index of language data
287 No_Language_Index : constant Language_Ptr := null;
288 -- Constant indicating that there is no language data
290 function Get_Language_From_Name
291 (Project : Project_Id;
292 Name : String) return Language_Ptr;
293 -- Get a language from a project. This might return null if no such
294 -- language exists in the project
296 Max_Header_Num : constant := 6150;
297 type Header_Num is range 0 .. Max_Header_Num;
298 -- Size for hash table below. The upper bound is an arbitrary value, the
299 -- value here was chosen after testing to determine a good compromise
300 -- between speed of access and memory usage.
302 function Hash (Name : Name_Id) return Header_Num;
303 function Hash (Name : File_Name_Type) return Header_Num;
304 function Hash (Name : Path_Name_Type) return Header_Num;
305 function Hash (Project : Project_Id) return Header_Num;
306 -- Used for computing hash values for names put into hash tables
308 type Language_Kind is (File_Based, Unit_Based);
309 -- Type for the kind of language. All languages are file based, except Ada
310 -- which is unit based.
312 -- Type of dependency to be checked
314 type Dependency_File_Kind is
316 -- There is no dependency file, the source must always be recompiled
319 -- The dependency file is a Makefile fragment indicating all the files
320 -- the source depends on. If the object file or the dependency file is
321 -- more recent than any of these files, the source must be recompiled.
324 -- The dependency file is an ALI file and the source must be recompiled
325 -- if the object or ALI file is more recent than any of the sources
326 -- listed in the D lines.
329 -- The dependency file is an ALI file and the source must be recompiled
330 -- if the object or ALI file is more recent than any source in the full
333 Makefile_Dependency_Suffix : constant String := ".d";
334 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
360 (Table : Name_List_Table.Instance;
361 List : Name_List_Index) return Natural;
362 -- Return the number of elements in specified list
364 type Number_List_Index is new Nat;
365 No_Number_List : constant Number_List_Index := 0;
367 type Number_Node is record
368 Number : Natural := 0;
369 Next : Number_List_Index := No_Number_List;
372 package Number_List_Table is new GNAT.Dynamic_Tables
373 (Table_Component_Type => Number_Node,
374 Table_Index_Type => Number_List_Index,
375 Table_Low_Bound => 1,
377 Table_Increment => 100);
378 -- The table for lists of numbers
380 package Mapping_Files_Htable is new Simple_HTable
381 (Header_Num => Header_Num,
382 Element => Path_Name_Type,
383 No_Element => No_Path,
384 Key => Path_Name_Type,
387 -- A hash table to store the mapping files that are not used
389 -- The following record ???
391 type Lang_Naming_Data is record
392 Dot_Replacement : File_Name_Type := No_File;
393 -- The string to replace '.' in the source file name (for Ada)
395 Casing : Casing_Type := All_Lower_Case;
396 -- The casing of the source file name (for Ada)
398 Separate_Suffix : File_Name_Type := No_File;
399 -- String to append to unit name for source file name of an Ada subunit
401 Spec_Suffix : File_Name_Type := No_File;
402 -- The string to append to the unit name for the
403 -- source file name of a spec.
405 Body_Suffix : File_Name_Type := No_File;
406 -- The string to append to the unit name for the
407 -- source file name of a body.
410 No_Lang_Naming_Data : constant Lang_Naming_Data :=
411 (Dot_Replacement => No_File,
412 Casing => All_Lower_Case,
413 Separate_Suffix => No_File,
414 Spec_Suffix => No_File,
415 Body_Suffix => No_File);
417 function Is_Standard_GNAT_Naming (Naming : Lang_Naming_Data) return Boolean;
418 -- True if the naming scheme is GNAT's default naming scheme. This
419 -- is to take into account shortened names like "Ada." (a-), "System." (s-)
423 type Source_Id is access all Source_Data;
425 function Is_Compilable (Source : Source_Id) return Boolean;
426 pragma Inline (Is_Compilable);
427 -- Return True if we know how to compile Source (i.e. if a compiler is
428 -- defined). This doesn't indicate whether the source should be compiled.
430 function Object_To_Global_Archive (Source : Source_Id) return Boolean;
431 pragma Inline (Object_To_Global_Archive);
432 -- Return True if the object file should be put in the global archive.
433 -- This is for Ada, when only the closure of a main needs to be
436 function Other_Part (Source : Source_Id) return Source_Id;
437 pragma Inline (Other_Part);
438 -- Source ID for the other part, if any: for a spec, returns its body;
439 -- for a body, returns its spec.
441 No_Source : constant Source_Id := null;
443 type Path_Syntax_Kind is
447 -- Host specific syntax, for example on VMS (the default)
449 -- The following record describes the configuration of a language
451 type Language_Config is record
452 Kind : Language_Kind := File_Based;
453 -- Kind of language. Most languages are file based. A few, such as Ada,
456 Naming_Data : Lang_Naming_Data;
457 -- The naming data for the languages (prefixes, etc.)
459 Include_Compatible_Languages : Name_List_Index := No_Name_List;
460 -- List of languages that are "include compatible" with this language. A
461 -- language B (for example "C") is "include compatible" with a language
462 -- A (for example "C++") if it is expected that sources of language A
463 -- may "include" header files from language B.
465 Compiler_Driver : File_Name_Type := No_File;
466 -- The name of the executable for the compiler of the language
468 Compiler_Driver_Path : String_Access := null;
469 -- The path name of the executable for the compiler of the language
471 Compiler_Leading_Required_Switches : Name_List_Index := No_Name_List;
472 -- The list of initial switches that are required as a minimum to invoke
473 -- the compiler driver.
475 Compiler_Trailing_Required_Switches : Name_List_Index := No_Name_List;
476 -- The list of final switches that are required as a minimum to invoke
477 -- the compiler driver.
479 Multi_Unit_Switches : Name_List_Index := No_Name_List;
480 -- The switch(es) to indicate the index of a unit in a multi-source file
482 Multi_Unit_Object_Separator : Character := ' ';
483 -- The string separating the base name of a source from the index of the
484 -- unit in a multi-source file, in the object file name.
486 Path_Syntax : Path_Syntax_Kind := Host;
487 -- Value may be Canonical (Unix style) or Host (host syntax, for example
488 -- on VMS for DEC C).
490 Source_File_Switches : Name_List_Index := No_Name_List;
491 -- Optional switches to be put before the source file. The source file
492 -- path name is appended to the last switch in the list.
493 -- Example: ("-i", "");
495 Object_File_Suffix : Name_Id := No_Name;
496 -- Optional alternate object file suffix
498 Object_File_Switches : Name_List_Index := No_Name_List;
499 -- Optional object file switches. When this is defined, the switches
500 -- are used to specify the object file. The object file name is appended
501 -- to the last switch in the list. Example: ("-o", "").
503 Object_Path_Switches : Name_List_Index := No_Name_List;
504 -- List of switches to specify to the compiler the path name of a
505 -- temporary file containing the list of object directories in the
508 Compilation_PIC_Option : Name_List_Index := No_Name_List;
509 -- The option(s) to compile a source in Position Independent Code for
510 -- shared libraries. Specified in the configuration. When not specified,
511 -- there is no need for such switch.
513 Object_Generated : Boolean := True;
514 -- False in no object file is generated
516 Objects_Linked : Boolean := True;
517 -- False if object files are not use to link executables and build
520 Runtime_Library_Dir : Name_Id := No_Name;
521 -- Path name of the runtime library directory, if any
523 Runtime_Source_Dir : Name_Id := No_Name;
524 -- Path name of the runtime source directory, if any
526 Mapping_File_Switches : Name_List_Index := No_Name_List;
527 -- The option(s) to provide a mapping file to the compiler. Specified in
528 -- the configuration. When value is No_Name_List, there is no mapping
531 Mapping_Spec_Suffix : File_Name_Type := No_File;
532 -- Placeholder representing the spec suffix in a mapping file
534 Mapping_Body_Suffix : File_Name_Type := No_File;
535 -- Placeholder representing the body suffix in a mapping file
537 Config_File_Switches : Name_List_Index := No_Name_List;
538 -- The option(s) to provide a config file to the compiler. Specified in
539 -- the configuration. If value is No_Name_List there is no config file.
541 Dependency_Kind : Dependency_File_Kind := None;
542 -- The kind of dependency to be checked: none, Makefile fragment or
543 -- ALI file (for Ada).
545 Dependency_Option : Name_List_Index := No_Name_List;
546 -- The option(s) to be used to create the dependency file. When value is
547 -- No_Name_List, there is not such option(s).
549 Compute_Dependency : Name_List_Index := No_Name_List;
550 -- Hold the value of attribute Dependency_Driver, if declared for the
553 Include_Option : Name_List_Index := No_Name_List;
554 -- Hold the value of attribute Include_Switches, if declared for the
557 Include_Path : Name_Id := No_Name;
558 -- Name of environment variable declared by attribute Include_Path for
561 Include_Path_File : Name_Id := No_Name;
562 -- Name of environment variable declared by attribute Include_Path_File
565 Objects_Path : Name_Id := No_Name;
566 -- Name of environment variable declared by attribute Objects_Path for
569 Objects_Path_File : Name_Id := No_Name;
570 -- Name of environment variable declared by attribute Objects_Path_File
573 Config_Body : Name_Id := No_Name;
574 -- The template for a pragma Source_File_Name(_Project) for a specific
575 -- file name of a body.
577 Config_Body_Index : Name_Id := No_Name;
578 -- The template for a pragma Source_File_Name(_Project) for a specific
579 -- file name of a body in a multi-source file.
581 Config_Body_Pattern : Name_Id := No_Name;
582 -- The template for a pragma Source_File_Name(_Project) for a naming
585 Config_Spec : Name_Id := No_Name;
586 -- The template for a pragma Source_File_Name(_Project) for a specific
587 -- file name of a spec.
589 Config_Spec_Index : Name_Id := No_Name;
590 -- The template for a pragma Source_File_Name(_Project) for a specific
591 -- file name of a spec in a multi-source file.
593 Config_Spec_Pattern : Name_Id := No_Name;
594 -- The template for a pragma Source_File_Name(_Project) for a naming
597 Config_File_Unique : Boolean := False;
598 -- True if the config file specified to the compiler needs to be unique.
599 -- If it is unique, then all config files are concatenated into a temp
602 Binder_Driver : File_Name_Type := No_File;
603 -- The name of the binder driver for the language, if any
605 Binder_Driver_Path : Path_Name_Type := No_Path;
606 -- The path name of the binder driver
608 Binder_Required_Switches : Name_List_Index := No_Name_List;
609 -- Hold the value of attribute Binder'Required_Switches for the language
611 Binder_Prefix : Name_Id := No_Name;
612 -- Hold the value of attribute Binder'Prefix for the language
614 Toolchain_Version : Name_Id := No_Name;
615 -- Hold the value of attribute Toolchain_Version for the language
617 Toolchain_Description : Name_Id := No_Name;
618 -- Hold the value of attribute Toolchain_Description for the language
620 Clean_Object_Artifacts : Name_List_Index := No_Name_List;
621 -- List of object artifact extensions to be deleted by gprclean
623 Clean_Source_Artifacts : Name_List_Index := No_Name_List;
624 -- List of source artifact extensions to be deleted by gprclean
628 No_Language_Config : constant Language_Config :=
630 Naming_Data => No_Lang_Naming_Data,
631 Include_Compatible_Languages => No_Name_List,
632 Compiler_Driver => No_File,
633 Compiler_Driver_Path => null,
634 Compiler_Leading_Required_Switches
636 Compiler_Trailing_Required_Switches
638 Multi_Unit_Switches => No_Name_List,
639 Multi_Unit_Object_Separator => ' ',
640 Path_Syntax => Canonical,
641 Source_File_Switches => No_Name_List,
642 Object_File_Suffix => No_Name,
643 Object_File_Switches => No_Name_List,
644 Object_Path_Switches => No_Name_List,
645 Compilation_PIC_Option => No_Name_List,
646 Object_Generated => True,
647 Objects_Linked => True,
648 Runtime_Library_Dir => No_Name,
649 Runtime_Source_Dir => No_Name,
650 Mapping_File_Switches => No_Name_List,
651 Mapping_Spec_Suffix => No_File,
652 Mapping_Body_Suffix => No_File,
653 Config_File_Switches => No_Name_List,
654 Dependency_Kind => None,
655 Dependency_Option => No_Name_List,
656 Compute_Dependency => No_Name_List,
657 Include_Option => No_Name_List,
658 Include_Path => No_Name,
659 Include_Path_File => No_Name,
660 Objects_Path => No_Name,
661 Objects_Path_File => No_Name,
662 Config_Body => No_Name,
663 Config_Body_Index => No_Name,
664 Config_Body_Pattern => No_Name,
665 Config_Spec => No_Name,
666 Config_Spec_Index => No_Name,
667 Config_Spec_Pattern => No_Name,
668 Config_File_Unique => False,
669 Binder_Driver => No_File,
670 Binder_Driver_Path => No_Path,
671 Binder_Required_Switches => No_Name_List,
672 Binder_Prefix => No_Name,
673 Toolchain_Version => No_Name,
674 Toolchain_Description => No_Name,
675 Clean_Object_Artifacts => No_Name_List,
676 Clean_Source_Artifacts => No_Name_List);
678 type Language_Data is record
679 Name : Name_Id := No_Name;
680 -- The name of the language in lower case
682 Display_Name : Name_Id := No_Name;
683 -- The name of the language, as found in attribute Languages
685 Config : Language_Config := No_Language_Config;
686 -- Configuration of the language
688 First_Source : Source_Id := No_Source;
689 -- Head of the list of sources of the language in the project
691 Mapping_Files : Mapping_Files_Htable.Instance :=
692 Mapping_Files_Htable.Nil;
693 -- Hash table containing the mapping of the sources to their path names
695 Next : Language_Ptr := No_Language_Index;
696 -- Next language of the project
700 No_Language_Data : constant Language_Data :=
702 Display_Name => No_Name,
703 Config => No_Language_Config,
704 First_Source => No_Source,
705 Mapping_Files => Mapping_Files_Htable.Nil,
706 Next => No_Language_Index);
708 type Language_List_Element;
709 type Language_List is access all Language_List_Element;
710 type Language_List_Element is record
711 Language : Language_Ptr := No_Language_Index;
712 Next : Language_List;
715 type Source_Kind is (Spec, Impl, Sep);
716 subtype Spec_Or_Body is Source_Kind range Spec .. Impl;
718 -- The following declarations declare a structure used to store the Name
719 -- and File and Path names of a unit, with a reference to its GNAT Project
720 -- File(s). Some units might have neither Spec nor Impl when they were
721 -- created for a "separate".
723 type File_Names_Data is array (Spec_Or_Body) of Source_Id;
725 type Unit_Data is record
726 Name : Name_Id := No_Name;
727 File_Names : File_Names_Data;
730 type Unit_Index is access all Unit_Data;
732 No_Unit_Index : constant Unit_Index := null;
733 -- Used to indicate a null entry for no unit
736 type Roots_Access is access Source_Roots;
737 type Source_Roots is record
741 -- A list to store the roots associated with a main unit. These are the
742 -- files that need to linked along with the main (for instance a C file
743 -- corresponding to an Ada file). In general, these are dependencies that
744 -- cannot be computed automatically by the builder.
746 type Naming_Exception_Type is (No, Yes, Inherited);
748 -- Structure to define source data
750 type Source_Data is record
751 Initialized : Boolean := False;
752 -- Set to True when Source_Data is completely initialized
754 Project : Project_Id := No_Project;
755 -- Project of the source
757 Location : Source_Ptr := No_Location;
758 -- Location in the project file of the declaration of the source in
761 Source_Dir_Rank : Natural := 0;
762 -- The rank of the source directory in list declared with attribute
763 -- Source_Dirs. Two source files with the same name cannot appears in
764 -- different directory with the same rank. That can happen when the
765 -- recursive notation <dir>/** is used in attribute Source_Dirs.
767 Language : Language_Ptr := No_Language_Index;
768 -- Language of the source
770 In_Interfaces : Boolean := True;
771 -- False when the source is not included in interfaces, when attribute
772 -- Interfaces is declared.
774 Declared_In_Interfaces : Boolean := False;
775 -- True when source is declared in attribute Interfaces
777 Alternate_Languages : Language_List := null;
778 -- List of languages a header file may also be, in addition of language
781 Kind : Source_Kind := Spec;
782 -- Kind of the source: spec, body or subunit
784 Unit : Unit_Index := No_Unit_Index;
785 -- Name of the unit, if language is unit based. This is only set for
786 -- those files that are part of the compilation set (for instance a
787 -- file in an extended project that is overridden will not have this
791 -- Index of the source in a multi unit source file (the same Source_Data
792 -- is duplicated several times when there are several units in the same
793 -- file). Index is 0 if there is either no unit or a single one, and
794 -- starts at 1 when there are multiple units
796 Compilable : Yes_No_Unknown := Unknown;
797 -- Updated at the first call to Is_Compilable. Yes if source file is
800 In_The_Queue : Boolean := False;
801 -- True if the source has been put in the queue
803 Locally_Removed : Boolean := False;
804 -- True if the source has been "excluded"
806 Suppressed : Boolean := False;
807 -- True if the source is a locally removed direct source of the project.
808 -- These sources should not be put in the mapping file.
810 Replaced_By : Source_Id := No_Source;
811 -- Source in an extending project that replaces the current source
813 File : File_Name_Type := No_File;
814 -- Canonical file name of the source
816 Display_File : File_Name_Type := No_File;
817 -- File name of the source, for display purposes
819 Path : Path_Information := No_Path_Information;
820 -- Path name of the source
822 Source_TS : Time_Stamp_Type := Empty_Time_Stamp;
823 -- Time stamp of the source file
825 Object_Project : Project_Id := No_Project;
826 -- Project where the object file is. This might be different from
827 -- Project when using extending project files.
829 Object : File_Name_Type := No_File;
830 -- File name of the object file
832 Current_Object_Path : Path_Name_Type := No_Path;
833 -- Object path of an existing object file
835 Object_Path : Path_Name_Type := No_Path;
836 -- Object path of the real object file
838 Object_TS : Time_Stamp_Type := Empty_Time_Stamp;
839 -- Object file time stamp
841 Dep_Name : File_Name_Type := No_File;
842 -- Dependency file simple name
844 Current_Dep_Path : Path_Name_Type := No_Path;
845 -- Path name of an existing dependency file
847 Dep_Path : Path_Name_Type := No_Path;
848 -- Path name of the real dependency file
850 Dep_TS : aliased Osint.File_Attributes := Osint.Unknown_Attributes;
851 -- Dependency file time stamp
853 Switches : File_Name_Type := No_File;
854 -- File name of the switches file. For all languages, this is a file
855 -- that ends with the .cswi extension.
857 Switches_Path : Path_Name_Type := No_Path;
858 -- Path name of the switches file
860 Switches_TS : Time_Stamp_Type := Empty_Time_Stamp;
861 -- Switches file time stamp
863 Naming_Exception : Naming_Exception_Type := No;
864 -- True if the source has an exceptional name
866 Duplicate_Unit : Boolean := False;
867 -- True when a duplicate unit has been reported for this source
869 Next_In_Lang : Source_Id := No_Source;
870 -- Link to another source of the same language in the same project
872 Next_With_File_Name : Source_Id := No_Source;
873 -- Link to another source with the same base file name
875 Roots : Roots_Access := null;
876 -- The roots for a main unit
880 No_Source_Data : constant Source_Data :=
881 (Initialized => False,
882 Project => No_Project,
883 Location => No_Location,
884 Source_Dir_Rank => 0,
885 Language => No_Language_Index,
886 In_Interfaces => True,
887 Declared_In_Interfaces => False,
888 Alternate_Languages => null,
890 Unit => No_Unit_Index,
892 Locally_Removed => False,
894 Compilable => Unknown,
895 In_The_Queue => False,
896 Replaced_By => No_Source,
898 Display_File => No_File,
899 Path => No_Path_Information,
900 Source_TS => Empty_Time_Stamp,
901 Object_Project => No_Project,
903 Current_Object_Path => No_Path,
904 Object_Path => No_Path,
905 Object_TS => Empty_Time_Stamp,
907 Current_Dep_Path => No_Path,
909 Dep_TS => Osint.Unknown_Attributes,
911 Switches_Path => No_Path,
912 Switches_TS => Empty_Time_Stamp,
913 Naming_Exception => No,
914 Duplicate_Unit => False,
915 Next_In_Lang => No_Source,
916 Next_With_File_Name => No_Source,
919 package Source_Files_Htable is new Simple_HTable
920 (Header_Num => Header_Num,
921 Element => Source_Id,
922 No_Element => No_Source,
923 Key => File_Name_Type,
926 -- Mapping of source file names to source ids
928 package Source_Paths_Htable is new Simple_HTable
929 (Header_Num => Header_Num,
930 Element => Source_Id,
931 No_Element => No_Source,
932 Key => Path_Name_Type,
935 -- Mapping of source paths to source ids
937 type Lib_Kind is (Static, Dynamic, Relocatable);
939 type Policy is (Autonomous, Compliant, Controlled, Restricted, Direct);
940 -- Type to specify the symbol policy, when symbol control is supported.
941 -- See full explanation about this type in package Symbols.
942 -- Autonomous: Create a symbol file without considering any reference
943 -- Compliant: Try to be as compatible as possible with an existing ref
944 -- Controlled: Fail if symbols are not the same as those in the reference
945 -- Restricted: Restrict the symbols to those in the symbol file
946 -- Direct: The symbol file is used as is
948 type Symbol_Record is record
949 Symbol_File : Path_Name_Type := No_Path;
950 Reference : Path_Name_Type := No_Path;
951 Symbol_Policy : Policy := Autonomous;
953 -- Type to keep the symbol data to be used when building a shared library
955 No_Symbols : constant Symbol_Record :=
956 (Symbol_File => No_Path,
957 Reference => No_Path,
958 Symbol_Policy => Autonomous);
959 -- The default value of the symbol data
961 function Image (The_Casing : Casing_Type) return String;
962 -- Similar to 'Image (but avoid use of this attribute in compiler)
964 function Value (Image : String) return Casing_Type;
965 -- Similar to 'Value (but avoid use of this attribute in compiler)
966 -- Raises Constraint_Error if not a Casing_Type image.
968 -- The following record contains data for a naming scheme
970 function Get_Object_Directory
971 (Project : Project_Id;
972 Including_Libraries : Boolean;
973 Only_If_Ada : Boolean := False) return Path_Name_Type;
974 -- Return the object directory to use for the project. This depends on
975 -- whether we have a library project or a standard project. This function
976 -- might return No_Name when no directory applies.
977 -- If we have a library project file and Including_Libraries is True then
978 -- the library dir is returned instead of the object dir.
979 -- If Only_If_Ada is True, then No_Name will be returned when the project
980 -- doesn't Ada sources.
982 procedure Compute_All_Imported_Projects
983 (Root_Project : Project_Id;
984 Tree : Project_Tree_Ref);
985 -- For all projects in the tree, compute the list of the projects imported
986 -- directly or indirectly by project Root_Project. The result is stored in
987 -- Project.All_Imported_Projects for each project
989 function Ultimate_Extending_Project_Of
990 (Proj : Project_Id) return Project_Id;
991 -- Returns the ultimate extending project of project Proj. If project Proj
992 -- is not extended, returns Proj.
994 type Project_List_Element;
995 type Project_List is access all Project_List_Element;
996 type Project_List_Element is record
997 Project : Project_Id := No_Project;
998 From_Encapsulated_Lib : Boolean := False;
999 Next : Project_List := null;
1001 -- A list of projects
1004 (List : in out Project_List;
1005 Free_Project : Boolean);
1006 -- Free the list of projects, if Free_Project, each project is also freed
1008 type Response_File_Format is
1017 -- The format of the different response files
1019 type Project_Configuration is record
1020 Target : Name_Id := No_Name;
1021 -- The target of the configuration, when specified
1023 Run_Path_Option : Name_List_Index := No_Name_List;
1024 -- The option to use when linking to specify the path where to look for
1027 Run_Path_Origin : Name_Id := No_Name;
1028 -- Specify the string (such as "$ORIGIN") to indicate paths relative to
1029 -- the directory of the executable in the run path option.
1031 Library_Install_Name_Option : Name_Id := No_Name;
1032 -- When this is not an empty list, this option, followed by the single
1033 -- name of the shared library file is used when linking a shared
1036 Separate_Run_Path_Options : Boolean := False;
1037 -- True if each directory needs to be specified in a separate run path
1040 Executable_Suffix : Name_Id := No_Name;
1041 -- The suffix of executables, when specified in the configuration or in
1042 -- package Builder of the main project. When this is not specified, the
1043 -- executable suffix is the default for the platform.
1047 Linker : Path_Name_Type := No_Path;
1048 -- Path name of the linker driver. Specified in the configuration or in
1049 -- the package Builder of the main project.
1051 Map_File_Option : Name_Id := No_Name;
1052 -- Option to use when invoking the linker to build a map file
1054 Trailing_Linker_Required_Switches : Name_List_Index := No_Name_List;
1055 -- The minimum options for the linker driver. Specified in the
1058 Linker_Executable_Option : Name_List_Index := No_Name_List;
1059 -- The option(s) to indicate the name of the executable in the linker
1060 -- command. Specified in the configuration. When not specified, default
1061 -- to -o <executable name>.
1063 Linker_Lib_Dir_Option : Name_Id := No_Name;
1064 -- The option to specify where to find a library for linking. Specified
1065 -- in the configuration. When not specified, defaults to "-L".
1067 Linker_Lib_Name_Option : Name_Id := No_Name;
1068 -- The option to specify the name of a library for linking. Specified in
1069 -- the configuration. When not specified, defaults to "-l".
1071 Max_Command_Line_Length : Natural := 0;
1072 -- When positive and when Resp_File_Format (see below) is not None,
1073 -- if the command line for the invocation of the linker would be greater
1074 -- than this value, a response file is used to invoke the linker.
1076 Resp_File_Format : Response_File_Format := None;
1077 -- The format of a response file, when linking with a response file is
1080 Resp_File_Options : Name_List_Index := No_Name_List;
1081 -- The switches, if any, that precede the path name of the response
1082 -- file in the invocation of the linker.
1086 Library_Builder : Path_Name_Type := No_Path;
1087 -- The executable to build library (specified in the configuration)
1089 Lib_Support : Library_Support := None;
1090 -- The level of library support. Specified in the configuration. Support
1091 -- is none, static libraries only or both static and shared libraries.
1093 Lib_Encapsulated_Supported : Boolean := False;
1094 -- True when building fully standalone libraries supported on the target
1096 Archive_Builder : Name_List_Index := No_Name_List;
1097 -- The name of the executable to build archives, with the minimum
1098 -- switches. Specified in the configuration.
1100 Archive_Builder_Append_Option : Name_List_Index := No_Name_List;
1101 -- The options to append object files to an archive
1103 Archive_Indexer : Name_List_Index := No_Name_List;
1104 -- The name of the executable to index archives, with the minimum
1105 -- switches. Specified in the configuration.
1107 Archive_Suffix : File_Name_Type := No_File;
1108 -- The suffix of archives. Specified in the configuration. When not
1109 -- specified, defaults to ".a".
1111 Lib_Partial_Linker : Name_List_Index := No_Name_List;
1115 Shared_Lib_Driver : File_Name_Type := No_File;
1116 -- The driver to link shared libraries. Set with attribute Library_GCC.
1119 Shared_Lib_Prefix : File_Name_Type := No_File;
1120 -- Part of a shared library file name that precedes the name of the
1121 -- library. Specified in the configuration. When not specified, defaults
1124 Shared_Lib_Suffix : File_Name_Type := No_File;
1125 -- Suffix of shared libraries, after the library name in the shared
1126 -- library name. Specified in the configuration. When not specified,
1127 -- default to ".so".
1129 Shared_Lib_Min_Options : Name_List_Index := No_Name_List;
1130 -- The minimum options to use when building a shared library
1132 Lib_Version_Options : Name_List_Index := No_Name_List;
1133 -- The options to use to specify a library version
1135 Symbolic_Link_Supported : Boolean := False;
1136 -- True if the platform supports symbolic link files
1138 Lib_Maj_Min_Id_Supported : Boolean := False;
1139 -- True if platform supports library major and minor options, such as
1140 -- libname.so -> libname.so.2 -> libname.so.2.4
1142 Auto_Init_Supported : Boolean := False;
1143 -- True if automatic initialisation is supported for shared stand-alone
1148 Artifacts_In_Exec_Dir : Name_List_Index := No_Name_List;
1149 -- List of regexp file names to be cleaned in the exec directory of the
1152 Artifacts_In_Object_Dir : Name_List_Index := No_Name_List;
1153 -- List of regexp file names to be cleaned in the object directory of
1158 Default_Project_Config : constant Project_Configuration :=
1160 Run_Path_Option => No_Name_List,
1161 Run_Path_Origin => No_Name,
1162 Library_Install_Name_Option => No_Name,
1163 Separate_Run_Path_Options => False,
1164 Executable_Suffix => No_Name,
1166 Map_File_Option => No_Name,
1167 Trailing_Linker_Required_Switches =>
1169 Linker_Executable_Option => No_Name_List,
1170 Linker_Lib_Dir_Option => No_Name,
1171 Linker_Lib_Name_Option => No_Name,
1172 Library_Builder => No_Path,
1173 Max_Command_Line_Length => 0,
1174 Resp_File_Format => None,
1175 Resp_File_Options => No_Name_List,
1176 Lib_Support => None,
1177 Lib_Encapsulated_Supported => False,
1178 Archive_Builder => No_Name_List,
1179 Archive_Builder_Append_Option => No_Name_List,
1180 Archive_Indexer => No_Name_List,
1181 Archive_Suffix => No_File,
1182 Lib_Partial_Linker => No_Name_List,
1183 Shared_Lib_Driver => No_File,
1184 Shared_Lib_Prefix => No_File,
1185 Shared_Lib_Suffix => No_File,
1186 Shared_Lib_Min_Options => No_Name_List,
1187 Lib_Version_Options => No_Name_List,
1188 Symbolic_Link_Supported => False,
1189 Lib_Maj_Min_Id_Supported => False,
1190 Auto_Init_Supported => False,
1191 Artifacts_In_Exec_Dir => No_Name_List,
1192 Artifacts_In_Object_Dir => No_Name_List);
1194 -------------------------
1195 -- Aggregated projects --
1196 -------------------------
1198 type Aggregated_Project;
1199 type Aggregated_Project_List is access all Aggregated_Project;
1200 type Aggregated_Project is record
1201 Path : Path_Name_Type;
1202 Tree : Project_Tree_Ref;
1203 Project : Project_Id;
1204 Next : Aggregated_Project_List;
1207 procedure Free (List : in out Aggregated_Project_List);
1208 -- Free the memory used for List
1210 procedure Add_Aggregated_Project
1211 (Project : Project_Id;
1212 Path : Path_Name_Type);
1213 -- Add a new aggregated project in Project.
1214 -- The aggregated project has not been processed yet. This procedure should
1215 -- the called while processing the aggregate project, and as a result
1216 -- Prj.Proc.Process will then automatically process the aggregated projects
1222 -- The following record describes a project file representation
1224 pragma Warnings (Off);
1228 -- The following clash with Standard is OK, and justified by the context
1229 -- which really wants to use the same set of qualifiers.
1234 pragma Warnings (On);
1236 type Project_Data (Qualifier : Project_Qualifier := Unspecified) is record
1242 Name : Name_Id := No_Name;
1243 -- The name of the project
1245 Display_Name : Name_Id := No_Name;
1246 -- The name of the project with the spelling of its declaration
1248 Externally_Built : Boolean := False;
1249 -- True if the project is externally built. In such case, the Project
1250 -- Manager will not modify anything in this project.
1252 Config : Project_Configuration;
1254 Path : Path_Information := No_Path_Information;
1255 -- The path name of the project file. This include base name of the
1258 Virtual : Boolean := False;
1259 -- True for virtual extending projects
1261 Location : Source_Ptr := No_Location;
1262 -- The location in the project file source of the project name that
1263 -- immediately follows the reserved word "project".
1269 Languages : Language_Ptr := No_Language_Index;
1270 -- First index of the language data in the project.
1271 -- Traversing the list gives access to all the languages supported by
1278 Mains : String_List_Id := Nil_String;
1279 -- List of mains specified by attribute Main
1281 Extends : Project_Id := No_Project;
1282 -- The reference of the project file, if any, that this project file
1285 Extended_By : Project_Id := No_Project;
1286 -- The reference of the project file, if any, that extends this project
1289 Decl : Declarations := No_Declarations;
1290 -- The declarations (variables, attributes and packages) of this project
1293 Imported_Projects : Project_List := null;
1294 -- The list of all directly imported projects, if any
1296 All_Imported_Projects : Project_List := null;
1297 -- The list of all projects imported directly or indirectly, if any.
1298 -- This does not include the project itself.
1304 Directory : Path_Information := No_Path_Information;
1305 -- Path name of the directory where the project file resides
1307 Object_Directory : Path_Information := No_Path_Information;
1308 -- The path name of the object directory of this project file
1310 Exec_Directory : Path_Information := No_Path_Information;
1311 -- The path name of the exec directory of this project file. Default is
1312 -- equal to Object_Directory.
1314 Object_Path_File : Path_Name_Type := No_Path;
1315 -- Store the name of the temporary file that contains the list of object
1316 -- directories, when attribute Object_Path_Switches is declared.
1322 Library : Boolean := False;
1323 -- True if this is a library project
1325 Library_Name : Name_Id := No_Name;
1326 -- If a library project, name of the library
1328 Library_Kind : Lib_Kind := Static;
1329 -- If a library project, kind of library
1331 Library_Dir : Path_Information := No_Path_Information;
1332 -- If a library project, path name of the directory where the library
1335 Library_TS : Time_Stamp_Type := Empty_Time_Stamp;
1336 -- The timestamp of a library file in a library project
1338 Library_Src_Dir : Path_Information := No_Path_Information;
1339 -- If a Stand-Alone Library project, path name of the directory where
1340 -- the sources of the interfaces of the library are copied. By default,
1341 -- if attribute Library_Src_Dir is not specified, sources of the
1342 -- interfaces are not copied anywhere.
1344 Library_ALI_Dir : Path_Information := No_Path_Information;
1345 -- In a library project, path name of the directory where the ALI files
1346 -- are copied. If attribute Library_ALI_Dir is not specified, ALI files
1347 -- are copied in the Library_Dir.
1349 Lib_Internal_Name : Name_Id := No_Name;
1350 -- If a library project, internal name store inside the library
1352 Standalone_Library : Standalone := No;
1353 -- Indicate that this is a Standalone Library Project File
1355 Lib_Interface_ALIs : String_List_Id := Nil_String;
1356 -- For Standalone Library Project Files, list of Interface ALI files.
1358 Other_Interfaces : String_List_Id := Nil_String;
1359 -- List of non unit based sources in attribute Interfaces
1361 Lib_Auto_Init : Boolean := False;
1362 -- For non static Stand-Alone Library Project Files, True if the library
1363 -- initialisation should be automatic.
1365 Symbol_Data : Symbol_Record := No_Symbols;
1366 -- Symbol file name, reference symbol file name, symbol policy
1368 Need_To_Build_Lib : Boolean := False;
1369 -- True if the library of a Library Project needs to be built or rebuilt
1374 -- The sources for all languages including Ada are accessible through
1375 -- the Source_Iterator type
1377 Interfaces_Defined : Boolean := False;
1378 -- True if attribute Interfaces is declared for the project or any
1379 -- project it extends.
1381 Include_Path_File : Path_Name_Type := No_Path;
1382 -- The path name of the of the source search directory file.
1383 -- This is only used by gnatmake
1385 Source_Dirs : String_List_Id := Nil_String;
1386 -- The list of all the source directories
1388 Source_Dir_Ranks : Number_List_Index := No_Number_List;
1390 Ada_Include_Path : String_Access := null;
1391 -- The cached value of source search path for this project file. Set by
1392 -- the first call to Prj.Env.Ada_Include_Path for the project. Do not
1393 -- use this field directly outside of the project manager, use
1394 -- Prj.Env.Ada_Include_Path instead.
1396 Has_Multi_Unit_Sources : Boolean := False;
1397 -- Whether there is at least one source file containing multiple units
1403 Ada_Objects_Path : String_Access := null;
1404 -- The cached value of ADA_OBJECTS_PATH for this project file. Do not
1405 -- use this field directly outside of the compiler, use
1406 -- Prj.Env.Ada_Objects_Path instead.
1408 Libgnarl_Needed : Yes_No_Unknown := Unknown;
1409 -- Set to True when libgnarl is needed to link
1411 Objects_Path : String_Access := null;
1412 -- The cached value of the object dir path, used during the binding
1413 -- phase of gprbuild.
1415 Objects_Path_File_With_Libs : Path_Name_Type := No_Path;
1416 -- The cached value of the object path temp file (including library
1417 -- dirs) for this project file.
1419 Objects_Path_File_Without_Libs : Path_Name_Type := No_Path;
1420 -- The cached value of the object path temp file (excluding library
1421 -- dirs) for this project file.
1423 Config_File_Name : Path_Name_Type := No_Path;
1424 -- The path name of the configuration pragmas file, if any
1426 Config_File_Temp : Boolean := False;
1427 -- True if the configuration pragmas file is a temporary file that must
1428 -- be deleted at the end.
1430 Config_Checked : Boolean := False;
1431 -- A flag to avoid checking repetitively the configuration pragmas file
1433 Depth : Natural := 0;
1434 -- The maximum depth of a project in the project graph. Depth of main
1437 Unkept_Comments : Boolean := False;
1438 -- True if there are comments in the project sources that cannot be kept
1439 -- in the project tree.
1441 -----------------------------
1442 -- Qualifier-Specific data --
1443 -----------------------------
1445 -- The following fields are only valid for specific types of projects
1448 when Aggregate | Aggregate_Library =>
1449 Aggregated_Projects : Aggregated_Project_List := null;
1450 -- List of aggregated projects (which could themselves be
1451 -- aggregate projects).
1458 function Empty_Project (Qualifier : Project_Qualifier) return Project_Data;
1459 -- Return the representation of an empty project
1461 function Is_Extending
1462 (Extending : Project_Id;
1463 Extended : Project_Id) return Boolean;
1464 -- Return True if Extending is extending the Extended project
1467 (Extending : Project_Id;
1468 Extended : Project_Id) return Boolean renames Is_Extending;
1470 function Has_Ada_Sources (Data : Project_Id) return Boolean;
1471 -- Return True if the project has Ada sources
1473 Project_Error : exception;
1474 -- Raised by some subprograms in Prj.Attr
1476 package Units_Htable is new Simple_HTable
1477 (Header_Num => Header_Num,
1478 Element => Unit_Index,
1479 No_Element => No_Unit_Index,
1483 -- Mapping of unit names to indexes in the Units table
1485 ---------------------
1486 -- Source_Iterator --
1487 ---------------------
1489 type Source_Iterator is private;
1491 function For_Each_Source
1492 (In_Tree : Project_Tree_Ref;
1493 Project : Project_Id := No_Project;
1494 Language : Name_Id := No_Name;
1495 Encapsulated_Libs : Boolean := True;
1496 Locally_Removed : Boolean := True) return Source_Iterator;
1497 -- Returns an iterator for all the sources of a project tree, or a specific
1498 -- project, or a specific language. Include sources from aggregated libs if
1499 -- Aggregated_Libs is True. If Locally_Removed is set to False the
1500 -- Locally_Removed files won't be reported.
1502 function Element (Iter : Source_Iterator) return Source_Id;
1503 -- Return the current source (or No_Source if there are no more sources)
1505 procedure Next (Iter : in out Source_Iterator);
1506 -- Move on to the next source
1508 function Find_Source
1509 (In_Tree : Project_Tree_Ref;
1510 Project : Project_Id;
1511 In_Imported_Only : Boolean := False;
1512 In_Extended_Only : Boolean := False;
1513 Base_Name : File_Name_Type;
1514 Index : Int := 0) return Source_Id;
1515 -- Find the first source file with the given name.
1516 -- If In_Extended_Only is True, it will search in project and the project
1517 -- it extends, but not in the imported projects.
1518 -- Elsif In_Imported_Only is True, it will search in project and the
1519 -- projects it imports, but not in the others or in aggregated projects.
1520 -- Else it searches in the whole tree.
1521 -- If Index is specified, this only search for a source with that index.
1523 -----------------------
1524 -- Project_Tree_Data --
1525 -----------------------
1527 package Replaced_Source_HTable is new Simple_HTable
1528 (Header_Num => Header_Num,
1529 Element => File_Name_Type,
1530 No_Element => No_File,
1531 Key => File_Name_Type,
1535 type Private_Project_Tree_Data is private;
1536 -- Data for a project tree that is used only by the Project Manager
1538 type Shared_Project_Tree_Data is record
1539 Name_Lists : Name_List_Table.Instance;
1540 Number_Lists : Number_List_Table.Instance;
1541 String_Elements : String_Element_Table.Instance;
1542 Variable_Elements : Variable_Element_Table.Instance;
1543 Array_Elements : Array_Element_Table.Instance;
1544 Arrays : Array_Table.Instance;
1545 Packages : Package_Table.Instance;
1546 Private_Part : Private_Project_Tree_Data;
1548 type Shared_Project_Tree_Data_Access is access all Shared_Project_Tree_Data;
1549 -- The data that is shared among multiple trees, when these trees are
1550 -- loaded through the same aggregate project.
1551 -- To avoid ambiguities, limit the number of parameters to the
1552 -- subprograms (we would have to parse the "root project tree" since this
1553 -- is where the configuration file was loaded, in addition to the project's
1554 -- own tree) and make the comparison of projects easier, all trees store
1555 -- the lists in the same tables.
1557 type Project_Tree_Appdata is tagged null record;
1558 type Project_Tree_Appdata_Access is access all Project_Tree_Appdata'Class;
1559 -- Application-specific data that can be associated with a project tree.
1560 -- We do not make the Project_Tree_Data itself tagged for several reasons:
1561 -- - it couldn't have a default value for its discriminant
1562 -- - it would require a "factory" to allocate such data, because trees
1563 -- are created automatically when parsing aggregate projects.
1565 procedure Free (Tree : in out Project_Tree_Appdata);
1566 -- Should be overridden if your derive your own data
1568 type Project_Tree_Data (Is_Root_Tree : Boolean := True) is record
1569 -- The root tree is the one loaded by the user from the command line.
1570 -- Is_Root_Tree is only false for projects aggregated within a root
1571 -- aggregate project.
1573 Projects : Project_List;
1574 -- List of projects in this tree
1576 Replaced_Sources : Replaced_Source_HTable.Instance;
1577 -- The list of sources that have been replaced by sources with
1578 -- different file names.
1580 Replaced_Source_Number : Natural := 0;
1581 -- The number of entries in Replaced_Sources
1583 Units_HT : Units_Htable.Instance;
1584 -- Unit name to Unit_Index (and from there to Source_Id)
1586 Source_Files_HT : Source_Files_Htable.Instance;
1587 -- Base source file names to Source_Id list
1589 Source_Paths_HT : Source_Paths_Htable.Instance;
1590 -- Full path to Source_Id
1591 -- ??? What is behavior for multi-unit source files, where there are
1592 -- several source_id per file ?
1594 Source_Info_File_Name : String_Access := null;
1595 -- The name of the source info file, if specified by the builder
1597 Source_Info_File_Exists : Boolean := False;
1598 -- True when a source info file has been successfully read
1600 Shared : Shared_Project_Tree_Data_Access;
1601 -- The shared data for this tree and all aggregated trees
1603 Appdata : Project_Tree_Appdata_Access;
1604 -- Application-specific data for this tree
1606 case Is_Root_Tree is
1608 Shared_Data : aliased Shared_Project_Tree_Data;
1609 -- Do not access directly, only through Shared
1615 -- Data for a project tree
1617 function Debug_Name (Tree : Project_Tree_Ref) return Name_Id;
1618 -- If debug traces are activated, return an identitier for the project
1619 -- tree. This modifies Name_Buffer.
1621 procedure Expect (The_Token : Token_Type; Token_Image : String);
1622 -- Check that the current token is The_Token. If it is not, then output
1623 -- an error message.
1625 procedure Initialize (Tree : Project_Tree_Ref);
1626 -- This procedure must be called before using any services from the Prj
1627 -- hierarchy. Namet.Initialize must be called before Prj.Initialize.
1629 procedure Reset (Tree : Project_Tree_Ref);
1630 -- This procedure resets all the tables that are used when processing a
1631 -- project file tree. Initialize must be called before the call to Reset.
1633 package Project_Boolean_Htable is new Simple_HTable
1634 (Header_Num => Header_Num,
1636 No_Element => False,
1640 -- A table that associates a project to a boolean. This is used to detect
1641 -- whether a project was already processed for instance.
1644 with procedure Action (Project : Project_Id; Tree : Project_Tree_Ref);
1645 procedure For_Project_And_Aggregated
1646 (Root_Project : Project_Id;
1647 Root_Tree : Project_Tree_Ref);
1648 -- Execute Action for Root_Project and all its aggregated projects
1652 type State is limited private;
1653 with procedure Action
1654 (Project : Project_Id;
1655 Tree : Project_Tree_Ref;
1656 With_State : in out State);
1657 procedure For_Every_Project_Imported
1659 Tree : Project_Tree_Ref;
1660 With_State : in out State;
1661 Include_Aggregated : Boolean := True;
1662 Imported_First : Boolean := False);
1663 -- Call Action for each project imported directly or indirectly by project
1664 -- By, as well as extended projects.
1666 -- The order of processing depends on Imported_First:
1668 -- If False, Action is called according to the order of importation: if A
1669 -- imports B, directly or indirectly, Action will be called for A before
1670 -- it is called for B. If two projects import each other directly or
1671 -- indirectly (using at least one "limited with"), it is not specified
1672 -- for which of these two projects Action will be called first.
1674 -- The order is reversed if Imported_First is True
1676 -- With_State may be used by Action to choose a behavior or to report some
1679 -- If Include_Aggregated is True, then an aggregate project will recurse
1680 -- into the projects it aggregates. Otherwise, the latter are never
1683 -- In_Aggregate_Lib is True if the project is in an aggregate library
1685 -- The Tree argument passed to the callback is required in the case of
1686 -- aggregated projects, since they might not be using the same tree as 'By'
1688 type Project_Context is record
1689 In_Aggregate_Lib : Boolean;
1690 -- True if the project is part of an aggregate library
1692 From_Encapsulated_Lib : Boolean;
1693 -- True if the project is imported from an encapsulated library
1697 type State is limited private;
1698 with procedure Action
1699 (Project : Project_Id;
1700 Tree : Project_Tree_Ref;
1701 Context : Project_Context;
1702 With_State : in out State);
1703 procedure For_Every_Project_Imported_Context
1705 Tree : Project_Tree_Ref;
1706 With_State : in out State;
1707 Include_Aggregated : Boolean := True;
1708 Imported_First : Boolean := False);
1709 -- As for For_Every_Project_Imported but with an associated context
1712 with procedure Action
1713 (Project : Project_Id;
1714 Tree : Project_Tree_Ref;
1715 Context : Project_Context);
1716 procedure For_Project_And_Aggregated_Context
1717 (Root_Project : Project_Id;
1718 Root_Tree : Project_Tree_Ref);
1719 -- As for For_Project_And_Aggregated but with an associated context
1721 function Extend_Name
1722 (File : File_Name_Type;
1723 With_Suffix : String) return File_Name_Type;
1724 -- Replace the extension of File with With_Suffix
1726 function Object_Name
1727 (Source_File_Name : File_Name_Type;
1728 Object_File_Suffix : Name_Id := No_Name) return File_Name_Type;
1729 -- Returns the object file name corresponding to a source file name
1731 function Object_Name
1732 (Source_File_Name : File_Name_Type;
1734 Index_Separator : Character;
1735 Object_File_Suffix : Name_Id := No_Name) return File_Name_Type;
1736 -- Returns the object file name corresponding to a unit in a multi-source
1739 function Dependency_Name
1740 (Source_File_Name : File_Name_Type;
1741 Dependency : Dependency_File_Kind) return File_Name_Type;
1742 -- Returns the dependency file name corresponding to a source file name
1744 function Switches_Name
1745 (Source_File_Name : File_Name_Type) return File_Name_Type;
1746 -- Returns the switches file name corresponding to a source file name
1748 procedure Set_Path_File_Var (Name : String; Value : String);
1749 -- Call Setenv, after calling To_Host_File_Spec
1751 function Current_Source_Path_File_Of
1752 (Shared : Shared_Project_Tree_Data_Access) return Path_Name_Type;
1753 -- Get the current include path file name
1755 procedure Set_Current_Source_Path_File_Of
1756 (Shared : Shared_Project_Tree_Data_Access;
1757 To : Path_Name_Type);
1758 -- Record the current include path file name
1760 function Current_Object_Path_File_Of
1761 (Shared : Shared_Project_Tree_Data_Access) return Path_Name_Type;
1762 -- Get the current object path file name
1764 procedure Set_Current_Object_Path_File_Of
1765 (Shared : Shared_Project_Tree_Data_Access;
1766 To : Path_Name_Type);
1767 -- Record the current object path file name
1773 type Processing_Flags is private;
1774 -- Flags used while parsing and processing a project tree to configure the
1775 -- behavior of the parser, and indicate how to report error messages. This
1776 -- structure does not allocate memory and never needs to be freed
1778 type Error_Warning is (Silent, Warning, Error);
1779 -- Severity of some situations, such as: no Ada sources in a project where
1780 -- Ada is one of the language.
1782 -- When the situation occurs, the behaviour depends on the setting:
1784 -- - Silent: no action
1785 -- - Warning: issue a warning, does not cause the tool to fail
1786 -- - Error: issue an error, causes the tool to fail
1788 type Error_Handler is access procedure
1789 (Project : Project_Id;
1790 Is_Warning : Boolean);
1791 -- This warns when an error was found when parsing a project. The error
1792 -- itself is handled through Prj.Err (and Prj.Err.Finalize should be called
1793 -- to actually print the error). This ensures that duplicate error messages
1794 -- are always correctly removed, that errors msgs are sorted, and that all
1795 -- tools will report the same error to the user.
1797 function Create_Flags
1798 (Report_Error : Error_Handler;
1799 When_No_Sources : Error_Warning;
1800 Require_Sources_Other_Lang : Boolean := True;
1801 Allow_Duplicate_Basenames : Boolean := True;
1802 Compiler_Driver_Mandatory : Boolean := False;
1803 Error_On_Unknown_Language : Boolean := True;
1804 Require_Obj_Dirs : Error_Warning := Error;
1805 Allow_Invalid_External : Error_Warning := Error;
1806 Missing_Source_Files : Error_Warning := Error;
1807 Ignore_Missing_With : Boolean := False)
1808 return Processing_Flags;
1809 -- Function used to create Processing_Flags structure
1811 -- If Allow_Duplicate_Basenames, then files with the same base names are
1812 -- authorized within a project for source-based languages (never for unit
1813 -- based languages).
1815 -- If Compiler_Driver_Mandatory is true, then a Compiler.Driver attribute
1816 -- for each language must be defined, or we will not look for its source
1819 -- When_No_Sources indicates what should be done when no sources of a
1820 -- language are found in a project where this language is declared.
1821 -- If Require_Sources_Other_Lang is true, then all languages must have at
1822 -- least one source file, or an error is reported via When_No_Sources. If
1823 -- it is false, this is only required for Ada (and only if it is a language
1824 -- of the project). When this parameter is set to False, we do not check
1825 -- that a proper naming scheme is defined for languages other than Ada.
1827 -- If Report_Error is null, use the standard error reporting mechanism
1828 -- (Errout). Otherwise, report errors using Report_Error.
1830 -- If Error_On_Unknown_Language is true, an error is displayed if some of
1831 -- the source files listed in the project do not match any naming scheme
1833 -- If Require_Obj_Dirs is true, then all object directories must exist
1834 -- (possibly after they have been created automatically if the appropriate
1835 -- switches were specified), or an error is raised.
1837 -- If Allow_Invalid_External is Silent, then no error is reported when an
1838 -- invalid value is used for an external variable (and it doesn't match its
1839 -- type). Instead, the first possible value is used.
1841 -- Missing_Source_Files indicates whether it is an error or a warning that
1842 -- a source file mentioned in the Source_Files attributes is not actually
1843 -- found in the source directories. This also impacts errors for missing
1844 -- source directories.
1846 -- If Ignore_Missing_With is True, then a "with" statement that cannot be
1847 -- resolved will simply be ignored. However, in such a case, the flag
1848 -- Incomplete_With in the project tree will be set to True.
1849 -- This is meant for use by tools so that they can properly set the
1850 -- project path in such a case:
1851 -- * no "gnatls" found (so no default project path)
1852 -- * user project sets Project.IDE'gnatls attribute to a cross gnatls
1853 -- * user project also includes a "with" that can only be resolved
1854 -- once we have found the gnatls
1856 Gprbuild_Flags : constant Processing_Flags;
1857 Gprclean_Flags : constant Processing_Flags;
1858 Gprexec_Flags : constant Processing_Flags;
1859 Gnatmake_Flags : constant Processing_Flags;
1860 -- Flags used by the various tools. They all display the error messages
1867 procedure Record_Temp_File
1868 (Shared : Shared_Project_Tree_Data_Access;
1869 Path : Path_Name_Type);
1870 -- Record the path of a newly created temporary file, so that it can be
1873 procedure Delete_All_Temp_Files
1874 (Shared : Shared_Project_Tree_Data_Access);
1875 -- Delete all recorded temporary files.
1876 -- Does nothing if Debug.Debug_Flag_N is set
1878 procedure Delete_Temp_Config_Files (Project_Tree : Project_Tree_Ref);
1879 -- Delete all temporary config files. Does nothing if Debug.Debug_Flag_N is
1880 -- set or if Project_Tree is null. This initially came from gnatmake
1881 -- ??? Should this be combined with Delete_All_Temp_Files above
1883 procedure Delete_Temporary_File
1884 (Shared : Shared_Project_Tree_Data_Access := null;
1885 Path : Path_Name_Type);
1886 -- Delete a temporary file from the disk. The file is also removed from the
1887 -- list of temporary files to delete at the end of the program, in case
1888 -- another program running on the same machine has recreated it. Does
1889 -- nothing if Debug.Debug_Flag_N is set
1891 Virtual_Prefix : constant String := "v$";
1892 -- The prefix for virtual extending projects. Because of the '$', which is
1893 -- normally forbidden for project names, there cannot be any name clash.
1899 type Verbosity is (Default, Medium, High);
1900 pragma Ordered (Verbosity);
1901 -- Verbosity when parsing GNAT Project Files
1902 -- Default is default (very quiet, if no errors).
1903 -- Medium is more verbose.
1904 -- High is extremely verbose.
1906 Current_Verbosity : Verbosity := Default;
1907 -- The current value of the verbosity the project files are parsed with
1909 procedure Debug_Indent;
1910 -- Inserts a series of blanks depending on the current indentation level
1912 procedure Debug_Output (Str : String);
1913 procedure Debug_Output (Str : String; Str2 : Name_Id);
1914 -- If Current_Verbosity is not Default, outputs Str.
1915 -- This indents Str based on the current indentation level for traces
1916 -- Debug_Error is intended to be used to report an error in the traces.
1918 procedure Debug_Increase_Indent
1919 (Str : String := ""; Str2 : Name_Id := No_Name);
1920 procedure Debug_Decrease_Indent (Str : String := "");
1921 -- Increase or decrease the indentation level for debug traces. This
1922 -- indentation level only affects output done through Debug_Output.
1926 All_Packages : constant String_List_Access := null;
1928 No_Project_Tree : constant Project_Tree_Ref := null;
1930 Ignored : constant Variable_Kind := Single;
1932 Nil_Variable_Value : constant Variable_Value :=
1933 (Project => No_Project,
1935 Location => No_Location,
1938 type Source_Iterator is record
1939 In_Tree : Project_Tree_Ref;
1941 Project : Project_List;
1942 All_Projects : Boolean;
1943 -- Current project and whether we should move on to the next
1945 Language : Language_Ptr;
1946 -- Current language processed
1948 Language_Name : Name_Id;
1949 -- Only sources of this language will be returned (or all if No_Name)
1951 Current : Source_Id;
1953 Encapsulated_Libs : Boolean;
1954 -- True if we want to include the sources from encapsulated libs
1956 Locally_Removed : Boolean;
1959 procedure Add_To_Buffer
1961 To : in out String_Access;
1962 Last : in out Natural);
1963 -- Append a String to the Buffer
1965 package Temp_Files_Table is new GNAT.Dynamic_Tables
1966 (Table_Component_Type => Path_Name_Type,
1967 Table_Index_Type => Integer,
1968 Table_Low_Bound => 1,
1969 Table_Initial => 10,
1970 Table_Increment => 10);
1971 -- Table to store the path name of all the created temporary files, so that
1972 -- they can be deleted at the end, or when the program is interrupted.
1974 type Private_Project_Tree_Data is record
1975 Temp_Files : Temp_Files_Table.Instance;
1976 -- Temporary files created as part of running tools (pragma files,
1977 -- mapping files,...)
1979 Current_Source_Path_File : Path_Name_Type := No_Path;
1980 -- Current value of project source path file env var. Used to avoid
1981 -- setting the env var to the same value. When different from No_Path,
1982 -- this indicates that logical names (VMS) or environment variables were
1983 -- created and should be deassigned to avoid polluting the environment
1984 -- on VMS. This is for gnatmake only.
1986 Current_Object_Path_File : Path_Name_Type := No_Path;
1987 -- Current value of project object path file env var. Used to avoid
1988 -- setting the env var to the same value.
1992 -- Type to represent the part of a project tree which is private to the
1995 type Processing_Flags is record
1996 Require_Sources_Other_Lang : Boolean;
1997 Report_Error : Error_Handler;
1998 When_No_Sources : Error_Warning;
1999 Allow_Duplicate_Basenames : Boolean;
2000 Compiler_Driver_Mandatory : Boolean;
2001 Error_On_Unknown_Language : Boolean;
2002 Require_Obj_Dirs : Error_Warning;
2003 Allow_Invalid_External : Error_Warning;
2004 Missing_Source_Files : Error_Warning;
2005 Ignore_Missing_With : Boolean;
2008 Gprbuild_Flags : constant Processing_Flags :=
2009 (Report_Error => null,
2010 When_No_Sources => Warning,
2011 Require_Sources_Other_Lang => True,
2012 Allow_Duplicate_Basenames => False,
2013 Compiler_Driver_Mandatory => True,
2014 Error_On_Unknown_Language => True,
2015 Require_Obj_Dirs => Error,
2016 Allow_Invalid_External => Error,
2017 Missing_Source_Files => Error,
2018 Ignore_Missing_With => False);
2020 Gprclean_Flags : constant Processing_Flags :=
2021 (Report_Error => null,
2022 When_No_Sources => Warning,
2023 Require_Sources_Other_Lang => True,
2024 Allow_Duplicate_Basenames => False,
2025 Compiler_Driver_Mandatory => True,
2026 Error_On_Unknown_Language => True,
2027 Require_Obj_Dirs => Warning,
2028 Allow_Invalid_External => Error,
2029 Missing_Source_Files => Error,
2030 Ignore_Missing_With => False);
2032 Gprexec_Flags : constant Processing_Flags :=
2033 (Report_Error => null,
2034 When_No_Sources => Silent,
2035 Require_Sources_Other_Lang => False,
2036 Allow_Duplicate_Basenames => False,
2037 Compiler_Driver_Mandatory => False,
2038 Error_On_Unknown_Language => True,
2039 Require_Obj_Dirs => Silent,
2040 Allow_Invalid_External => Error,
2041 Missing_Source_Files => Silent,
2042 Ignore_Missing_With => False);
2044 Gnatmake_Flags : constant Processing_Flags :=
2045 (Report_Error => null,
2046 When_No_Sources => Error,
2047 Require_Sources_Other_Lang => False,
2048 Allow_Duplicate_Basenames => False,
2049 Compiler_Driver_Mandatory => False,
2050 Error_On_Unknown_Language => False,
2051 Require_Obj_Dirs => Error,
2052 Allow_Invalid_External => Error,
2053 Missing_Source_Files => Error,
2054 Ignore_Missing_With => False);