1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2009, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 -- The following package declares the data types for GNAT project.
27 -- These data types may be used by GNAT Project-aware tools.
29 -- Children of these package implements various services on these data types.
30 -- See in particular Prj.Pars and Prj.Env.
32 with Casing
; use Casing
;
33 with Namet
; use Namet
;
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 All_Packages
: constant String_List_Access
;
81 -- Default value of parameter Packages of procedures Parse, in Prj.Pars and
82 -- Prj.Part, indicating that all packages should be checked.
84 type Project_Tree_Data
;
85 type Project_Tree_Ref
is access all Project_Tree_Data
;
86 -- Reference to a project tree. Several project trees may exist in memory
89 No_Project_Tree
: constant Project_Tree_Ref
;
91 procedure Free
(Tree
: in out Project_Tree_Ref
);
92 -- Free memory associated with the tree
94 Config_Project_File_Extension
: String := ".cgpr";
95 Project_File_Extension
: String := ".gpr";
96 -- The standard config and user project file name extensions. They are not
97 -- constants, because Canonical_Case_File_Name is called on these variables
98 -- in the body of Prj.
100 function Empty_File
return File_Name_Type
;
101 function Empty_String
return Name_Id
;
102 -- Return the id for an empty string ""
104 type Path_Information
is record
105 Name
: Path_Name_Type
:= No_Path
;
106 Display_Name
: Path_Name_Type
:= No_Path
;
108 -- Directory names always end with a directory separator
110 No_Path_Information
: constant Path_Information
:= (No_Path
, No_Path
);
113 type Project_Id
is access all Project_Data
;
114 No_Project
: constant Project_Id
:= null;
115 -- Id of a Project File
117 type String_List_Id
is new Nat
;
118 Nil_String
: constant String_List_Id
:= 0;
119 type String_Element
is record
120 Value
: Name_Id
:= No_Name
;
122 Display_Value
: Name_Id
:= No_Name
;
123 Location
: Source_Ptr
:= No_Location
;
124 Flag
: Boolean := False;
125 Next
: String_List_Id
:= Nil_String
;
127 -- To hold values for string list variables and array elements.
128 -- Component Flag may be used for various purposes. For source
129 -- directories, it indicates if the directory contains Ada source(s).
131 package String_Element_Table
is new GNAT
.Dynamic_Tables
132 (Table_Component_Type
=> String_Element
,
133 Table_Index_Type
=> String_List_Id
,
134 Table_Low_Bound
=> 1,
135 Table_Initial
=> 200,
136 Table_Increment
=> 100);
137 -- The table for string elements in string lists
139 type Variable_Kind
is (Undefined
, List
, Single
);
140 -- Different kinds of variables
142 subtype Defined_Variable_Kind
is Variable_Kind
range List
.. Single
;
143 -- The defined kinds of variables
145 Ignored
: constant Variable_Kind
;
146 -- Used to indicate that a package declaration must be ignored
147 -- while processing the project tree (unknown package name).
149 type Variable_Value
(Kind
: Variable_Kind
:= Undefined
) is record
150 Project
: Project_Id
:= No_Project
;
151 Location
: Source_Ptr
:= No_Location
;
152 Default
: Boolean := False;
157 Values
: String_List_Id
:= Nil_String
;
159 Value
: Name_Id
:= No_Name
;
163 -- Values for variables and array elements. Default is True if the
164 -- current value is the default one for the variable.
166 Nil_Variable_Value
: constant Variable_Value
;
167 -- Value of a non existing variable or array element
169 type Variable_Id
is new Nat
;
170 No_Variable
: constant Variable_Id
:= 0;
171 type Variable
is record
172 Next
: Variable_Id
:= No_Variable
;
174 Value
: Variable_Value
;
176 -- To hold the list of variables in a project file and in packages
178 package Variable_Element_Table
is new GNAT
.Dynamic_Tables
179 (Table_Component_Type
=> Variable
,
180 Table_Index_Type
=> Variable_Id
,
181 Table_Low_Bound
=> 1,
182 Table_Initial
=> 200,
183 Table_Increment
=> 100);
184 -- The table of variable in list of variables
186 type Array_Element_Id
is new Nat
;
187 No_Array_Element
: constant Array_Element_Id
:= 0;
188 type Array_Element
is record
190 Src_Index
: Int
:= 0;
191 Index_Case_Sensitive
: Boolean := True;
192 Value
: Variable_Value
;
193 Next
: Array_Element_Id
:= No_Array_Element
;
195 -- Each Array_Element represents an array element and is linked (Next)
196 -- to the next array element, if any, in the array.
198 package Array_Element_Table
is new GNAT
.Dynamic_Tables
199 (Table_Component_Type
=> Array_Element
,
200 Table_Index_Type
=> Array_Element_Id
,
201 Table_Low_Bound
=> 1,
202 Table_Initial
=> 200,
203 Table_Increment
=> 100);
204 -- The table that contains all array elements
206 type Array_Id
is new Nat
;
207 No_Array
: constant Array_Id
:= 0;
208 type Array_Data
is record
209 Name
: Name_Id
:= No_Name
;
210 Location
: Source_Ptr
:= No_Location
;
211 Value
: Array_Element_Id
:= No_Array_Element
;
212 Next
: Array_Id
:= No_Array
;
214 -- Each Array_Data value represents an array.
215 -- Value is the id of the first element.
216 -- Next is the id of the next array in the project file or package.
218 package Array_Table
is new GNAT
.Dynamic_Tables
219 (Table_Component_Type
=> Array_Data
,
220 Table_Index_Type
=> Array_Id
,
221 Table_Low_Bound
=> 1,
222 Table_Initial
=> 200,
223 Table_Increment
=> 100);
224 -- The table that contains all arrays
226 type Package_Id
is new Nat
;
227 No_Package
: constant Package_Id
:= 0;
228 type Declarations
is record
229 Variables
: Variable_Id
:= No_Variable
;
230 Attributes
: Variable_Id
:= No_Variable
;
231 Arrays
: Array_Id
:= No_Array
;
232 Packages
: Package_Id
:= No_Package
;
234 -- Contains the declarations (variables, single and array attributes,
235 -- packages) for a project or a package in a project.
237 No_Declarations
: constant Declarations
:=
238 (Variables
=> No_Variable
,
239 Attributes
=> No_Variable
,
241 Packages
=> No_Package
);
242 -- Default value of Declarations: indicates that there is no declarations
244 type Package_Element
is record
245 Name
: Name_Id
:= No_Name
;
246 Decl
: Declarations
:= No_Declarations
;
247 Parent
: Package_Id
:= No_Package
;
248 Next
: Package_Id
:= No_Package
;
250 -- A package (includes declarations that may include other packages)
252 package Package_Table
is new GNAT
.Dynamic_Tables
253 (Table_Component_Type
=> Package_Element
,
254 Table_Index_Type
=> Package_Id
,
255 Table_Low_Bound
=> 1,
256 Table_Initial
=> 100,
257 Table_Increment
=> 100);
258 -- The table that contains all packages
261 type Language_Ptr
is access all Language_Data
;
262 -- Index of language data
264 No_Language_Index
: constant Language_Ptr
:= null;
265 -- Constant indicating that there is no language data
267 function Get_Language_From_Name
268 (Project
: Project_Id
;
269 Name
: String) return Language_Ptr
;
270 -- Get a language from a project. This might return null if no such
271 -- language exists in the project
273 Max_Header_Num
: constant := 6150;
274 type Header_Num
is range 0 .. Max_Header_Num
;
275 -- Size for hash table below. The upper bound is an arbitrary value, the
276 -- value here was chosen after testing to determine a good compromise
277 -- between speed of access and memory usage.
279 function Hash
(Name
: Name_Id
) return Header_Num
;
280 function Hash
(Name
: File_Name_Type
) return Header_Num
;
281 function Hash
(Name
: Path_Name_Type
) return Header_Num
;
282 function Hash
(Project
: Project_Id
) return Header_Num
;
283 -- Used for computing hash values for names put into hash tables
285 type Language_Kind
is (File_Based
, Unit_Based
);
286 -- Type for the kind of language. All languages are file based, except Ada
287 -- which is unit based.
289 type Dependency_File_Kind
is (None
, Makefile
, ALI_File
);
290 -- Type of dependency to be checked: no dependency file, Makefile fragment
291 -- or ALI file (for Ada).
293 Makefile_Dependency_Suffix
: constant String := ".d";
294 ALI_Dependency_Suffix
: constant String := ".ali";
296 Switches_Dependency_Suffix
: constant String := ".cswi";
298 Binder_Exchange_Suffix
: constant String := ".bexch";
299 -- Suffix for binder exchange files
301 Library_Exchange_Suffix
: constant String := ".lexch";
302 -- Suffix for library exchange files
304 type Name_List_Index
is new Nat
;
305 No_Name_List
: constant Name_List_Index
:= 0;
307 type Name_Node
is record
308 Name
: Name_Id
:= No_Name
;
309 Next
: Name_List_Index
:= No_Name_List
;
312 package Name_List_Table
is new GNAT
.Dynamic_Tables
313 (Table_Component_Type
=> Name_Node
,
314 Table_Index_Type
=> Name_List_Index
,
315 Table_Low_Bound
=> 1,
317 Table_Increment
=> 100);
318 -- The table for lists of names
321 (Table
: Name_List_Table
.Instance
;
322 List
: Name_List_Index
) return Natural;
323 -- Return the number of elements in specified list
325 type Number_List_Index
is new Nat
;
326 No_Number_List
: constant Number_List_Index
:= 0;
328 type Number_Node
is record
329 Number
: Natural := 0;
330 Next
: Number_List_Index
:= No_Number_List
;
333 package Number_List_Table
is new GNAT
.Dynamic_Tables
334 (Table_Component_Type
=> Number_Node
,
335 Table_Index_Type
=> Number_List_Index
,
336 Table_Low_Bound
=> 1,
338 Table_Increment
=> 100);
339 -- The table for lists of numbers
341 package Mapping_Files_Htable
is new Simple_HTable
342 (Header_Num
=> Header_Num
,
343 Element
=> Path_Name_Type
,
344 No_Element
=> No_Path
,
345 Key
=> Path_Name_Type
,
348 -- A hash table to store the mapping files that are not used
350 -- The following record ???
352 type Lang_Naming_Data
is record
353 Dot_Replacement
: File_Name_Type
:= No_File
;
354 -- The string to replace '.' in the source file name (for Ada)
356 Casing
: Casing_Type
:= All_Lower_Case
;
357 -- The casing of the source file name (for Ada)
359 Separate_Suffix
: File_Name_Type
:= No_File
;
360 -- String to append to unit name for source file name of an Ada subunit
362 Spec_Suffix
: File_Name_Type
:= No_File
;
363 -- The string to append to the unit name for the
364 -- source file name of a spec.
366 Body_Suffix
: File_Name_Type
:= No_File
;
367 -- The string to append to the unit name for the
368 -- source file name of a body.
371 No_Lang_Naming_Data
: constant Lang_Naming_Data
:=
372 (Dot_Replacement
=> No_File
,
373 Casing
=> All_Lower_Case
,
374 Separate_Suffix
=> No_File
,
375 Spec_Suffix
=> No_File
,
376 Body_Suffix
=> No_File
);
378 function Is_Standard_GNAT_Naming
(Naming
: Lang_Naming_Data
) return Boolean;
379 -- True if the naming scheme is GNAT's default naming scheme. This
380 -- is to take into account shortened names like "Ada." (a-), "System." (s-)
384 type Source_Id
is access all Source_Data
;
386 function Is_Compilable
(Source
: Source_Id
) return Boolean;
387 pragma Inline
(Is_Compilable
);
388 -- Return True if we know how to compile Source (i.e. if a compiler is
389 -- defined). This doesn't indicate whether the source should be compiled.
391 function Object_To_Global_Archive
(Source
: Source_Id
) return Boolean;
392 pragma Inline
(Object_To_Global_Archive
);
393 -- Return True if the object file should be put in the global archive.
394 -- This is for Ada, when only the closure of a main needs to be
397 function Other_Part
(Source
: Source_Id
) return Source_Id
;
398 pragma Inline
(Other_Part
);
399 -- Source ID for the other part, if any: for a spec, indicates its body;
400 -- for a body, indicates its spec.
402 No_Source
: constant Source_Id
:= null;
404 type Path_Syntax_Kind
is
408 -- Host specific syntax, for example on VMS (the default)
410 -- The following record describes the configuration of a language
412 type Language_Config
is record
413 Kind
: Language_Kind
:= File_Based
;
414 -- Kind of language. All languages are file based, except Ada which is
417 Naming_Data
: Lang_Naming_Data
;
418 -- The naming data for the languages (prefixes, etc.)
420 Include_Compatible_Languages
: Name_List_Index
:= No_Name_List
;
421 -- List of languages that are "include compatible" with this language. A
422 -- language B (for example "C") is "include compatible" with a language
423 -- A (for example "C++") if it is expected that sources of language A
424 -- may "include" header files from language B.
426 Compiler_Driver
: File_Name_Type
:= No_File
;
427 -- The name of the executable for the compiler of the language
429 Compiler_Driver_Path
: String_Access
:= null;
430 -- The path name of the executable for the compiler of the language
432 Compiler_Leading_Required_Switches
: Name_List_Index
:= No_Name_List
;
433 -- The list of initial switches that are required as a minimum to invoke
434 -- the compiler driver.
436 Compiler_Trailing_Required_Switches
: Name_List_Index
:= No_Name_List
;
437 -- The list of final switches that are required as a minimum to invoke
438 -- the compiler driver.
440 Multi_Unit_Switches
: Name_List_Index
:= No_Name_List
;
441 -- The switch(es) to indicate the index of a unit in a multi-source file
443 Multi_Unit_Object_Separator
: Character := ' ';
444 -- The string separating the base name of a source from the index of the
445 -- unit in a multi-source file, in the object file name.
447 Path_Syntax
: Path_Syntax_Kind
:= Host
;
448 -- Value may be Canonical (Unix style) or Host (host syntax, for example
449 -- on VMS for DEC C).
451 Object_File_Suffix
: Name_Id
:= No_Name
;
452 -- Optional alternate object file suffix
454 Object_File_Switches
: Name_List_Index
:= No_Name_List
;
455 -- Optional object file switches. When this is defined, the switches
456 -- are used to specify the object file. The object file name is appended
457 -- to the last switch in the list. Example: ("-o", "").
459 Compilation_PIC_Option
: Name_List_Index
:= No_Name_List
;
460 -- The option(s) to compile a source in Position Independent Code for
461 -- shared libraries. Specified in the configuration. When not specified,
462 -- there is no need for such switch.
464 Object_Generated
: Boolean := True;
465 -- False in no object file is generated
467 Objects_Linked
: Boolean := True;
468 -- False if object files are not use to link executables and build
471 Runtime_Library_Dir
: Name_Id
:= No_Name
;
472 -- Path name of the runtime library directory, if any
474 Runtime_Source_Dir
: Name_Id
:= No_Name
;
475 -- Path name of the runtime source directory, if any
477 Mapping_File_Switches
: Name_List_Index
:= No_Name_List
;
478 -- The option(s) to provide a mapping file to the compiler. Specified in
479 -- the configuration. When value is No_Name_List, there is no mapping
482 Mapping_Spec_Suffix
: File_Name_Type
:= No_File
;
483 -- Placeholder representing the spec suffix in a mapping file
485 Mapping_Body_Suffix
: File_Name_Type
:= No_File
;
486 -- Placeholder representing the body suffix in a mapping file
488 Config_File_Switches
: Name_List_Index
:= No_Name_List
;
489 -- The option(s) to provide a config file to the compiler. Specified in
490 -- the configuration. If value is No_Name_List there is no config file.
492 Dependency_Kind
: Dependency_File_Kind
:= None
;
493 -- The kind of dependency to be checked: none, Makefile fragment or
494 -- ALI file (for Ada).
496 Dependency_Option
: Name_List_Index
:= No_Name_List
;
497 -- The option(s) to be used to create the dependency file. When value is
498 -- No_Name_List, there is not such option(s).
500 Compute_Dependency
: Name_List_Index
:= No_Name_List
;
501 -- Hold the value of attribute Dependency_Driver, if declared for the
504 Include_Option
: Name_List_Index
:= No_Name_List
;
505 -- Hold the value of attribute Include_Switches, if declared for the
508 Include_Path
: Name_Id
:= No_Name
;
509 -- Name of environment variable declared by attribute Include_Path for
512 Include_Path_File
: Name_Id
:= No_Name
;
513 -- Name of environment variable declared by attribute Include_Path_File
516 Objects_Path
: Name_Id
:= No_Name
;
517 -- Name of environment variable declared by attribute Objects_Path for
520 Objects_Path_File
: Name_Id
:= No_Name
;
521 -- Name of environment variable declared by attribute Objects_Path_File
524 Config_Body
: Name_Id
:= No_Name
;
525 -- The template for a pragma Source_File_Name(_Project) for a specific
526 -- file name of a body.
528 Config_Body_Index
: Name_Id
:= No_Name
;
529 -- The template for a pragma Source_File_Name(_Project) for a specific
530 -- file name of a body in a multi-source file.
532 Config_Body_Pattern
: Name_Id
:= No_Name
;
533 -- The template for a pragma Source_File_Name(_Project) for a naming
536 Config_Spec
: Name_Id
:= No_Name
;
537 -- The template for a pragma Source_File_Name(_Project) for a specific
538 -- file name of a spec.
540 Config_Spec_Index
: Name_Id
:= No_Name
;
541 -- The template for a pragma Source_File_Name(_Project) for a specific
542 -- file name of a spec in a multi-source file.
544 Config_Spec_Pattern
: Name_Id
:= No_Name
;
545 -- The template for a pragma Source_File_Name(_Project) for a naming
548 Config_File_Unique
: Boolean := False;
549 -- Indicate if the config file specified to the compiler needs to be
550 -- unique. If it is unique, then all config files are concatenated into
551 -- a temp config file.
553 Binder_Driver
: File_Name_Type
:= No_File
;
554 -- The name of the binder driver for the language, if any
556 Binder_Driver_Path
: Path_Name_Type
:= No_Path
;
557 -- The path name of the binder driver
559 Binder_Required_Switches
: Name_List_Index
:= No_Name_List
;
560 -- Hold the value of attribute Binder'Required_Switches for the language
562 Binder_Prefix
: Name_Id
:= No_Name
;
563 -- Hold the value of attribute Binder'Prefix for the language
565 Toolchain_Version
: Name_Id
:= No_Name
;
566 -- Hold the value of attribute Toolchain_Version for the language
568 Toolchain_Description
: Name_Id
:= No_Name
;
569 -- Hold the value of attribute Toolchain_Description for the language
573 No_Language_Config
: constant Language_Config
:=
575 Naming_Data
=> No_Lang_Naming_Data
,
576 Include_Compatible_Languages
=> No_Name_List
,
577 Compiler_Driver
=> No_File
,
578 Compiler_Driver_Path
=> null,
579 Compiler_Leading_Required_Switches
=> No_Name_List
,
580 Compiler_Trailing_Required_Switches
=> No_Name_List
,
581 Multi_Unit_Switches
=> No_Name_List
,
582 Multi_Unit_Object_Separator
=> ' ',
583 Path_Syntax
=> Canonical
,
584 Object_File_Suffix
=> No_Name
,
585 Object_File_Switches
=> No_Name_List
,
586 Compilation_PIC_Option
=> No_Name_List
,
587 Object_Generated
=> True,
588 Objects_Linked
=> True,
589 Runtime_Library_Dir
=> No_Name
,
590 Runtime_Source_Dir
=> No_Name
,
591 Mapping_File_Switches
=> No_Name_List
,
592 Mapping_Spec_Suffix
=> No_File
,
593 Mapping_Body_Suffix
=> No_File
,
594 Config_File_Switches
=> No_Name_List
,
595 Dependency_Kind
=> None
,
596 Dependency_Option
=> No_Name_List
,
597 Compute_Dependency
=> No_Name_List
,
598 Include_Option
=> No_Name_List
,
599 Include_Path
=> No_Name
,
600 Include_Path_File
=> No_Name
,
601 Objects_Path
=> No_Name
,
602 Objects_Path_File
=> No_Name
,
603 Config_Body
=> No_Name
,
604 Config_Body_Index
=> No_Name
,
605 Config_Body_Pattern
=> No_Name
,
606 Config_Spec
=> No_Name
,
607 Config_Spec_Index
=> No_Name
,
608 Config_Spec_Pattern
=> No_Name
,
609 Config_File_Unique
=> False,
610 Binder_Driver
=> No_File
,
611 Binder_Driver_Path
=> No_Path
,
612 Binder_Required_Switches
=> No_Name_List
,
613 Binder_Prefix
=> No_Name
,
614 Toolchain_Version
=> No_Name
,
615 Toolchain_Description
=> No_Name
);
617 -- The following record ???
619 type Language_Data
is record
620 Name
: Name_Id
:= No_Name
;
621 Display_Name
: Name_Id
:= No_Name
;
622 Config
: Language_Config
:= No_Language_Config
;
623 First_Source
: Source_Id
:= No_Source
;
624 Mapping_Files
: Mapping_Files_Htable
.Instance
:=
625 Mapping_Files_Htable
.Nil
;
626 Next
: Language_Ptr
:= No_Language_Index
;
629 No_Language_Data
: constant Language_Data
:=
631 Display_Name
=> No_Name
,
632 Config
=> No_Language_Config
,
633 First_Source
=> No_Source
,
634 Mapping_Files
=> Mapping_Files_Htable
.Nil
,
635 Next
=> No_Language_Index
);
637 type Language_List_Element
;
638 type Language_List
is access all Language_List_Element
;
639 type Language_List_Element
is record
640 Language
: Language_Ptr
:= No_Language_Index
;
641 Next
: Language_List
;
644 type Source_Kind
is (Spec
, Impl
, Sep
);
645 subtype Spec_Or_Body
is Source_Kind
range Spec
.. Impl
;
647 -- The following declarations declare a structure used to store the Name
648 -- and File and Path names of a unit, with a reference to its GNAT Project
649 -- File(s). Some units might have neither Spec nor Impl when they were
650 -- created for a "separate".
652 type File_Names_Data
is array (Spec_Or_Body
) of Source_Id
;
654 type Unit_Data
is record
655 Name
: Name_Id
:= No_Name
;
656 File_Names
: File_Names_Data
;
659 type Unit_Index
is access all Unit_Data
;
661 No_Unit_Index
: constant Unit_Index
:= null;
662 -- Used to indicate a null entry for no unit
664 -- Structure to define source data
666 type Source_Data
is record
667 Project
: Project_Id
:= No_Project
;
668 -- Project of the source
670 Source_Dir_Rank
: Natural := 0;
671 -- The rank of the source directory in list declared with attribute
672 -- Source_Dirs. Two source files with the same name cannot appears in
673 -- different directory with the same rank. That can happen when the
674 -- recursive notation <dir>/** is used in attribute Source_Dirs.
676 Language
: Language_Ptr
:= No_Language_Index
;
677 -- Index of the language. This is an index into
678 -- Project_Tree.Languages_Data.
680 In_Interfaces
: Boolean := True;
681 -- False when the source is not included in interfaces, when attribute
682 -- Interfaces is declared.
684 Declared_In_Interfaces
: Boolean := False;
685 -- True when source is declared in attribute Interfaces
687 Alternate_Languages
: Language_List
:= null;
688 -- List of languages a header file may also be, in addition of language
691 Kind
: Source_Kind
:= Spec
;
692 -- Kind of the source: spec, body or subunit
694 Unit
: Unit_Index
:= No_Unit_Index
;
695 -- Name of the unit, if language is unit based. This is only set for
696 -- those files that are part of the compilation set (for instance a
697 -- file in an extended project that is overridden will not have this
701 -- Index of the source in a multi unit source file (the same Source_Data
702 -- is duplicated several times when there are several units in the same
703 -- file). Index is 0 if there is either no unit or a single one, and
704 -- starts at 1 when there are multiple units
706 Locally_Removed
: Boolean := False;
707 -- True if the source has been "excluded"
709 Replaced_By
: Source_Id
:= No_Source
;
710 -- Missing comment ???
712 File
: File_Name_Type
:= No_File
;
713 -- Canonical file name of the source
715 Display_File
: File_Name_Type
:= No_File
;
716 -- File name of the source, for display purposes
718 Path
: Path_Information
:= No_Path_Information
;
719 -- Path name of the source
721 Source_TS
: Time_Stamp_Type
:= Empty_Time_Stamp
;
722 -- Time stamp of the source file
724 Object_Project
: Project_Id
:= No_Project
;
725 -- Project where the object file is. This might be different from
726 -- Project when using extending project files.
728 Object
: File_Name_Type
:= No_File
;
729 -- File name of the object file
731 Current_Object_Path
: Path_Name_Type
:= No_Path
;
732 -- Object path of an existing object file
734 Object_Path
: Path_Name_Type
:= No_Path
;
735 -- Object path of the real object file
737 Object_TS
: Time_Stamp_Type
:= Empty_Time_Stamp
;
738 -- Object file time stamp
740 Dep_Name
: File_Name_Type
:= No_File
;
741 -- Dependency file simple name
743 Current_Dep_Path
: Path_Name_Type
:= No_Path
;
744 -- Path name of an existing dependency file
746 Dep_Path
: Path_Name_Type
:= No_Path
;
747 -- Path name of the real dependency file
749 Dep_TS
: aliased Osint
.File_Attributes
:= Osint
.Unknown_Attributes
;
750 -- Dependency file time stamp
752 Switches
: File_Name_Type
:= No_File
;
753 -- File name of the switches file. For all languages, this is a file
754 -- that ends with the .cswi extension.
756 Switches_Path
: Path_Name_Type
:= No_Path
;
757 -- Path name of the switches file
759 Switches_TS
: Time_Stamp_Type
:= Empty_Time_Stamp
;
760 -- Switches file time stamp
762 Naming_Exception
: Boolean := False;
763 -- True if the source has an exceptional name
765 Next_In_Lang
: Source_Id
:= No_Source
;
766 -- Link to another source of the same language in the same project
769 No_Source_Data
: constant Source_Data
:=
770 (Project
=> No_Project
,
771 Source_Dir_Rank
=> 0,
772 Language
=> No_Language_Index
,
773 In_Interfaces
=> True,
774 Declared_In_Interfaces
=> False,
775 Alternate_Languages
=> null,
777 Unit
=> No_Unit_Index
,
779 Locally_Removed
=> False,
780 Replaced_By
=> No_Source
,
782 Display_File
=> No_File
,
783 Path
=> No_Path_Information
,
784 Source_TS
=> Empty_Time_Stamp
,
785 Object_Project
=> No_Project
,
787 Current_Object_Path
=> No_Path
,
788 Object_Path
=> No_Path
,
789 Object_TS
=> Empty_Time_Stamp
,
791 Current_Dep_Path
=> No_Path
,
793 Dep_TS
=> Osint
.Unknown_Attributes
,
795 Switches_Path
=> No_Path
,
796 Switches_TS
=> Empty_Time_Stamp
,
797 Naming_Exception
=> False,
798 Next_In_Lang
=> No_Source
);
800 package Source_Paths_Htable
is new Simple_HTable
801 (Header_Num
=> Header_Num
,
802 Element
=> Source_Id
,
803 No_Element
=> No_Source
,
804 Key
=> Path_Name_Type
,
807 -- Mapping of source paths to source ids
809 package Unit_Sources_Htable
is new Simple_HTable
810 (Header_Num
=> Header_Num
,
811 Element
=> Source_Id
,
812 No_Element
=> No_Source
,
817 type Verbosity
is (Default
, Medium
, High
);
818 -- Verbosity when parsing GNAT Project Files
819 -- Default is default (very quiet, if no errors).
820 -- Medium is more verbose.
821 -- High is extremely verbose.
823 Current_Verbosity
: Verbosity
:= Default
;
824 -- The current value of the verbosity the project files are parsed with
826 type Lib_Kind
is (Static
, Dynamic
, Relocatable
);
828 type Policy
is (Autonomous
, Compliant
, Controlled
, Restricted
, Direct
);
829 -- Type to specify the symbol policy, when symbol control is supported.
830 -- See full explanation about this type in package Symbols.
831 -- Autonomous: Create a symbol file without considering any reference
832 -- Compliant: Try to be as compatible as possible with an existing ref
833 -- Controlled: Fail if symbols are not the same as those in the reference
834 -- Restricted: Restrict the symbols to those in the symbol file
835 -- Direct: The symbol file is used as is
837 type Symbol_Record
is record
838 Symbol_File
: Path_Name_Type
:= No_Path
;
839 Reference
: Path_Name_Type
:= No_Path
;
840 Symbol_Policy
: Policy
:= Autonomous
;
842 -- Type to keep the symbol data to be used when building a shared library
844 No_Symbols
: constant Symbol_Record
:=
845 (Symbol_File
=> No_Path
,
846 Reference
=> No_Path
,
847 Symbol_Policy
=> Autonomous
);
848 -- The default value of the symbol data
850 function Image
(The_Casing
: Casing_Type
) return String;
851 -- Similar to 'Image (but avoid use of this attribute in compiler)
853 function Value
(Image
: String) return Casing_Type
;
854 -- Similar to 'Value (but avoid use of this attribute in compiler)
855 -- Raises Constraint_Error if not a Casing_Type image.
857 -- The following record contains data for a naming scheme
859 function Get_Object_Directory
860 (Project
: Project_Id
;
861 Including_Libraries
: Boolean;
862 Only_If_Ada
: Boolean := False) return Path_Name_Type
;
863 -- Return the object directory to use for the project. This depends on
864 -- whether we have a library project or a standard project. This function
865 -- might return No_Name when no directory applies.
866 -- If we have a a library project file and Including_Libraries is True then
867 -- the library dir is returned instead of the object dir.
868 -- If Only_If_Ada is True, then No_Name will be returned when the project
869 -- doesn't Ada sources.
871 procedure Compute_All_Imported_Projects
(Tree
: Project_Tree_Ref
);
872 -- For all projects in the tree, compute the list of the projects imported
873 -- directly or indirectly by project Project. The result is stored in
874 -- Project.All_Imported_Projects for each project
876 function Ultimate_Extending_Project_Of
877 (Proj
: Project_Id
) return Project_Id
;
878 -- Returns the ultimate extending project of project Proj. If project Proj
879 -- is not extended, returns Proj.
881 type Project_List_Element
;
882 type Project_List
is access all Project_List_Element
;
883 type Project_List_Element
is record
884 Project
: Project_Id
:= No_Project
;
885 Next
: Project_List
:= null;
887 -- A list of projects
890 (List
: in out Project_List
;
891 Free_Project
: Boolean);
892 -- Free the list of projects, if Free_Project, each project is also freed
894 type Response_File_Format
is
899 -- The format of the different response files
901 type Project_Configuration
is record
902 Target
: Name_Id
:= No_Name
;
903 -- The target of the configuration, when specified
905 Run_Path_Option
: Name_List_Index
:= No_Name_List
;
906 -- The option to use when linking to specify the path where to look for
909 Separate_Run_Path_Options
: Boolean := False;
910 -- True if each directory needs to be specified in a separate run path
913 Executable_Suffix
: Name_Id
:= No_Name
;
914 -- The suffix of executables, when specified in the configuration or in
915 -- package Builder of the main project. When this is not specified, the
916 -- executable suffix is the default for the platform.
920 Linker
: Path_Name_Type
:= No_Path
;
921 -- Path name of the linker driver. Specified in the configuration or in
922 -- the package Builder of the main project.
924 Map_File_Option
: Name_Id
:= No_Name
;
925 -- Option to use when invoking the linker to build a map file
927 Minimum_Linker_Options
: Name_List_Index
:= No_Name_List
;
928 -- The minimum options for the linker driver. Specified in the
931 Linker_Executable_Option
: Name_List_Index
:= No_Name_List
;
932 -- The option(s) to indicate the name of the executable in the linker
933 -- command. Specified in the configuration. When not specified, default
934 -- to -o <executable name>.
936 Linker_Lib_Dir_Option
: Name_Id
:= No_Name
;
937 -- The option to specify where to find a library for linking. Specified
938 -- in the configuration. When not specified, defaults to "-L".
940 Linker_Lib_Name_Option
: Name_Id
:= No_Name
;
941 -- The option to specify the name of a library for linking. Specified in
942 -- the configuration. When not specified, defaults to "-l".
944 Max_Command_Line_Length
: Natural := 0;
945 -- When positive and when Resp_File_Format (see below) is not None,
946 -- if the command line for the invocation of the linker would be greater
947 -- than this value, a response file is used to invoke the linker.
949 Resp_File_Format
: Response_File_Format
:= None
;
950 -- The format of a response file, when linking with a response file is
953 Resp_File_Options
: Name_List_Index
:= No_Name_List
;
954 -- The switches, if any, that precede the path name of the response
955 -- file in the invocation of the linker.
959 Library_Builder
: Path_Name_Type
:= No_Path
;
960 -- The executable to build library (specified in the configuration)
962 Lib_Support
: Library_Support
:= None
;
963 -- The level of library support. Specified in the configuration. Support
964 -- is none, static libraries only or both static and shared libraries.
966 Archive_Builder
: Name_List_Index
:= No_Name_List
;
967 -- The name of the executable to build archives, with the minimum
968 -- switches. Specified in the configuration.
970 Archive_Builder_Append_Option
: Name_List_Index
:= No_Name_List
;
971 -- The options to append object files to an archive
973 Archive_Indexer
: Name_List_Index
:= No_Name_List
;
974 -- The name of the executable to index archives, with the minimum
975 -- switches. Specified in the configuration.
977 Archive_Suffix
: File_Name_Type
:= No_File
;
978 -- The suffix of archives. Specified in the configuration. When not
979 -- specified, defaults to ".a".
981 Lib_Partial_Linker
: Name_List_Index
:= No_Name_List
;
985 Shared_Lib_Driver
: File_Name_Type
:= No_File
;
986 -- The driver to link shared libraries. Set with attribute Library_GCC.
989 Shared_Lib_Prefix
: File_Name_Type
:= No_File
;
990 -- Part of a shared library file name that precedes the name of the
991 -- library. Specified in the configuration. When not specified, defaults
994 Shared_Lib_Suffix
: File_Name_Type
:= No_File
;
995 -- Suffix of shared libraries, after the library name in the shared
996 -- library name. Specified in the configuration. When not specified,
999 Shared_Lib_Min_Options
: Name_List_Index
:= No_Name_List
;
1000 -- The minimum options to use when building a shared library
1002 Lib_Version_Options
: Name_List_Index
:= No_Name_List
;
1003 -- The options to use to specify a library version
1005 Symbolic_Link_Supported
: Boolean := False;
1006 -- True if the platform supports symbolic link files
1008 Lib_Maj_Min_Id_Supported
: Boolean := False;
1009 -- True if platform supports library major and minor options, such as
1010 -- libname.so -> libname.so.2 -> libname.so.2.4
1012 Auto_Init_Supported
: Boolean := False;
1013 -- True if automatic initialisation is supported for shared stand-alone
1017 Default_Project_Config
: constant Project_Configuration
:=
1019 Run_Path_Option
=> No_Name_List
,
1020 Separate_Run_Path_Options
=> False,
1021 Executable_Suffix
=> No_Name
,
1023 Map_File_Option
=> No_Name
,
1024 Minimum_Linker_Options
=> No_Name_List
,
1025 Linker_Executable_Option
=> No_Name_List
,
1026 Linker_Lib_Dir_Option
=> No_Name
,
1027 Linker_Lib_Name_Option
=> No_Name
,
1028 Library_Builder
=> No_Path
,
1029 Max_Command_Line_Length
=> 0,
1030 Resp_File_Format
=> None
,
1031 Resp_File_Options
=> No_Name_List
,
1032 Lib_Support
=> None
,
1033 Archive_Builder
=> No_Name_List
,
1034 Archive_Builder_Append_Option
=> No_Name_List
,
1035 Archive_Indexer
=> No_Name_List
,
1036 Archive_Suffix
=> No_File
,
1037 Lib_Partial_Linker
=> No_Name_List
,
1038 Shared_Lib_Driver
=> No_File
,
1039 Shared_Lib_Prefix
=> No_File
,
1040 Shared_Lib_Suffix
=> No_File
,
1041 Shared_Lib_Min_Options
=> No_Name_List
,
1042 Lib_Version_Options
=> No_Name_List
,
1043 Symbolic_Link_Supported
=> False,
1044 Lib_Maj_Min_Id_Supported
=> False,
1045 Auto_Init_Supported
=> False);
1047 -- The following record describes a project file representation
1049 -- Note that it is not specified if the path names of directories (source,
1050 -- object, library or exec directories) end with or without a directory
1053 type Project_Data
is record
1059 Name
: Name_Id
:= No_Name
;
1060 -- The name of the project
1062 Display_Name
: Name_Id
:= No_Name
;
1063 -- The name of the project with the spelling of its declaration
1065 Qualifier
: Project_Qualifier
:= Unspecified
;
1066 -- The eventual qualifier for this project
1068 Externally_Built
: Boolean := False;
1069 -- True if the project is externally built. In such case, the Project
1070 -- Manager will not modify anything in this project.
1072 Config
: Project_Configuration
;
1074 Path
: Path_Information
:= No_Path_Information
;
1075 -- The path name of the project file. This include base name of the
1078 Virtual
: Boolean := False;
1079 -- True for virtual extending projects
1081 Location
: Source_Ptr
:= No_Location
;
1082 -- The location in the project file source of the reserved word project
1088 Languages
: Language_Ptr
:= No_Language_Index
;
1089 -- First index of the language data in the project.
1090 -- This is an index into the project_tree_data.languages_data.
1091 -- Traversing the list gives access to all the languages supported by
1098 Mains
: String_List_Id
:= Nil_String
;
1099 -- List of mains specified by attribute Main
1101 Extends
: Project_Id
:= No_Project
;
1102 -- The reference of the project file, if any, that this project file
1105 Extended_By
: Project_Id
:= No_Project
;
1106 -- The reference of the project file, if any, that extends this project
1109 Decl
: Declarations
:= No_Declarations
;
1110 -- The declarations (variables, attributes and packages) of this project
1113 Imported_Projects
: Project_List
;
1114 -- The list of all directly imported projects, if any
1116 All_Imported_Projects
: Project_List
;
1117 -- The list of all projects imported directly or indirectly, if any.
1118 -- This does not include the project itself.
1124 Directory
: Path_Information
:= No_Path_Information
;
1125 -- Path name of the directory where the project file resides
1127 Object_Directory
: Path_Information
:= No_Path_Information
;
1128 -- The path name of the object directory of this project file
1130 Exec_Directory
: Path_Information
:= No_Path_Information
;
1131 -- The path name of the exec directory of this project file. Default is
1132 -- equal to Object_Directory.
1138 Library
: Boolean := False;
1139 -- True if this is a library project
1141 Library_Name
: Name_Id
:= No_Name
;
1142 -- If a library project, name of the library
1144 Library_Kind
: Lib_Kind
:= Static
;
1145 -- If a library project, kind of library
1147 Library_Dir
: Path_Information
:= No_Path_Information
;
1148 -- If a library project, path name of the directory where the library
1151 Library_TS
: Time_Stamp_Type
:= Empty_Time_Stamp
;
1152 -- The timestamp of a library file in a library project
1154 Library_Src_Dir
: Path_Information
:= No_Path_Information
;
1155 -- If a Stand-Alone Library project, path name of the directory where
1156 -- the sources of the interfaces of the library are copied. By default,
1157 -- if attribute Library_Src_Dir is not specified, sources of the
1158 -- interfaces are not copied anywhere.
1160 Library_ALI_Dir
: Path_Information
:= No_Path_Information
;
1161 -- In a library project, path name of the directory where the ALI files
1162 -- are copied. If attribute Library_ALI_Dir is not specified, ALI files
1163 -- are copied in the Library_Dir.
1165 Lib_Internal_Name
: Name_Id
:= No_Name
;
1166 -- If a library project, internal name store inside the library
1168 Standalone_Library
: Boolean := False;
1169 -- Indicate that this is a Standalone Library Project File
1171 Lib_Interface_ALIs
: String_List_Id
:= Nil_String
;
1172 -- For Standalone Library Project Files, indicate the list of Interface
1175 Lib_Auto_Init
: Boolean := False;
1176 -- For non static Stand-Alone Library Project Files, indicate if
1177 -- the library initialisation should be automatic.
1179 Symbol_Data
: Symbol_Record
:= No_Symbols
;
1180 -- Symbol file name, reference symbol file name, symbol policy
1182 Need_To_Build_Lib
: Boolean := False;
1183 -- Indicates that the library of a Library Project needs to be built or
1189 -- The sources for all languages including Ada are accessible through
1190 -- the Source_Iterator type
1192 Interfaces_Defined
: Boolean := False;
1193 -- True if attribute Interfaces is declared for the project or any
1194 -- project it extends.
1196 Include_Path_File
: Path_Name_Type
:= No_Path
;
1197 -- The path name of the of the source search directory file.
1198 -- This is only used by gnatmake
1200 Source_Dirs
: String_List_Id
:= Nil_String
;
1201 -- The list of all the source directories
1203 Source_Dir_Ranks
: Number_List_Index
:= No_Number_List
;
1205 Ada_Include_Path
: String_Access
:= null;
1206 -- The cached value of source search path for this project file. Set by
1207 -- the first call to Prj.Env.Ada_Include_Path for the project. Do not
1208 -- use this field directly outside of the project manager, use
1209 -- Prj.Env.Ada_Include_Path instead.
1211 Has_Multi_Unit_Sources
: Boolean := False;
1212 -- Whether there is at least one source file containing multiple units
1218 Ada_Objects_Path
: String_Access
:= null;
1219 -- The cached value of ADA_OBJECTS_PATH for this project file. Do not
1220 -- use this field directly outside of the compiler, use
1221 -- Prj.Env.Ada_Objects_Path instead.
1223 Libgnarl_Needed
: Yes_No_Unknown
:= Unknown
;
1224 -- Set to True when libgnarl is needed to link
1226 Objects_Path
: String_Access
:= null;
1227 -- The cached value of the object dir path, used during the binding
1228 -- phase of gprbuild.
1230 Objects_Path_File_With_Libs
: Path_Name_Type
:= No_Path
;
1231 -- The cached value of the object path temp file (including library
1232 -- dirs) for this project file.
1234 Objects_Path_File_Without_Libs
: Path_Name_Type
:= No_Path
;
1235 -- The cached value of the object path temp file (excluding library
1236 -- dirs) for this project file.
1238 Config_File_Name
: Path_Name_Type
:= No_Path
;
1239 -- The path name of the configuration pragmas file, if any
1241 Config_File_Temp
: Boolean := False;
1242 -- An indication that the configuration pragmas file is a temporary file
1243 -- that must be deleted at the end.
1245 Config_Checked
: Boolean := False;
1246 -- A flag to avoid checking repetitively the configuration pragmas file
1248 Depth
: Natural := 0;
1249 -- The maximum depth of a project in the project graph. Depth of main
1252 Unkept_Comments
: Boolean := False;
1253 -- True if there are comments in the project sources that cannot be kept
1254 -- in the project tree.
1258 function Empty_Project
return Project_Data
;
1259 -- Return the representation of an empty project
1261 function Is_Extending
1262 (Extending
: Project_Id
;
1263 Extended
: Project_Id
) return Boolean;
1264 -- Return True if Extending is extending the Extended project
1266 function Has_Ada_Sources
(Data
: Project_Id
) return Boolean;
1267 -- Return True if the project has Ada sources
1269 Project_Error
: exception;
1270 -- Raised by some subprograms in Prj.Attr
1272 package Units_Htable
is new Simple_HTable
1273 (Header_Num
=> Header_Num
,
1274 Element
=> Unit_Index
,
1275 No_Element
=> No_Unit_Index
,
1279 -- Mapping of unit names to indexes in the Units table
1281 ---------------------
1282 -- Source_Iterator --
1283 ---------------------
1285 type Source_Iterator
is private;
1287 function For_Each_Source
1288 (In_Tree
: Project_Tree_Ref
;
1289 Project
: Project_Id
:= No_Project
;
1290 Language
: Name_Id
:= No_Name
) return Source_Iterator
;
1291 -- Returns an iterator for all the sources of a project tree, or a specific
1292 -- project, or a specific language.
1294 function Element
(Iter
: Source_Iterator
) return Source_Id
;
1295 -- Return the current source (or No_Source if there are no more sources)
1297 procedure Next
(Iter
: in out Source_Iterator
);
1298 -- Move on to the next source
1300 function Find_Source
1301 (In_Tree
: Project_Tree_Ref
;
1302 Project
: Project_Id
;
1303 In_Imported_Only
: Boolean := False;
1304 In_Extended_Only
: Boolean := False;
1305 Base_Name
: File_Name_Type
) return Source_Id
;
1306 -- Find the first source file with the given name either in the whole tree
1307 -- (if In_Imported_Only is False) or in the projects imported or extended
1308 -- by Project otherwise. In_Extended_Only implies In_Imported_Only, and
1309 -- will only look in Project and the projects it extends
1311 -----------------------
1312 -- Project_Tree_Data --
1313 -----------------------
1315 type Private_Project_Tree_Data
is private;
1316 -- Data for a project tree that is used only by the Project Manager
1318 type Project_Tree_Data
is
1320 Name_Lists
: Name_List_Table
.Instance
;
1321 Number_Lists
: Number_List_Table
.Instance
;
1322 String_Elements
: String_Element_Table
.Instance
;
1323 Variable_Elements
: Variable_Element_Table
.Instance
;
1324 Array_Elements
: Array_Element_Table
.Instance
;
1325 Arrays
: Array_Table
.Instance
;
1326 Packages
: Package_Table
.Instance
;
1327 Projects
: Project_List
;
1329 Units_HT
: Units_Htable
.Instance
;
1330 -- Unit name to Unit_Index (and from there so Source_Id)
1332 Source_Paths_HT
: Source_Paths_Htable
.Instance
;
1333 -- Full path to Source_Id
1335 Private_Part
: Private_Project_Tree_Data
;
1337 -- Data for a project tree
1339 procedure Expect
(The_Token
: Token_Type
; Token_Image
: String);
1340 -- Check that the current token is The_Token. If it is not, then output
1341 -- an error message.
1343 procedure Initialize
(Tree
: Project_Tree_Ref
);
1344 -- This procedure must be called before using any services from the Prj
1345 -- hierarchy. Namet.Initialize must be called before Prj.Initialize.
1347 procedure Reset
(Tree
: Project_Tree_Ref
);
1348 -- This procedure resets all the tables that are used when processing a
1349 -- project file tree. Initialize must be called before the call to Reset.
1351 package Project_Boolean_Htable
is new Simple_HTable
1352 (Header_Num
=> Header_Num
,
1354 No_Element
=> False,
1358 -- A table that associates a project to a boolean. This is used to detect
1359 -- whether a project was already processed for instance.
1362 type State
is limited private;
1363 with procedure Action
1364 (Project
: Project_Id
;
1365 With_State
: in out State
);
1366 procedure For_Every_Project_Imported
1368 With_State
: in out State
;
1369 Imported_First
: Boolean := False);
1370 -- Call Action for each project imported directly or indirectly by project
1371 -- By, as well as extended projects.
1372 -- The order of processing depends on Imported_First:
1373 -- If False, Action is called according to the order of importation: if A
1374 -- imports B, directly or indirectly, Action will be called for A before
1375 -- it is called for B. If two projects import each other directly or
1376 -- indirectly (using at least one "limited with"), it is not specified
1377 -- for which of these two projects Action will be called first.
1378 -- The order is reversed if Imported_First is True.
1379 -- With_State may be used by Action to choose a behavior or to report some
1382 function Extend_Name
1383 (File
: File_Name_Type
;
1384 With_Suffix
: String) return File_Name_Type
;
1385 -- Replace the extension of File with With_Suffix
1387 function Object_Name
1388 (Source_File_Name
: File_Name_Type
;
1389 Object_File_Suffix
: Name_Id
:= No_Name
) return File_Name_Type
;
1390 -- Returns the object file name corresponding to a source file name
1392 function Object_Name
1393 (Source_File_Name
: File_Name_Type
;
1395 Index_Separator
: Character;
1396 Object_File_Suffix
: Name_Id
:= No_Name
) return File_Name_Type
;
1397 -- Returns the object file name corresponding to a unit in a multi-source
1400 function Dependency_Name
1401 (Source_File_Name
: File_Name_Type
;
1402 Dependency
: Dependency_File_Kind
) return File_Name_Type
;
1403 -- Returns the dependency file name corresponding to a source file name
1405 function Switches_Name
1406 (Source_File_Name
: File_Name_Type
) return File_Name_Type
;
1407 -- Returns the switches file name corresponding to a source file name
1413 type Processing_Flags
is private;
1414 -- Flags used while parsing and processing a project tree to configure the
1415 -- behavior of the parser, and indicate how to report error messages. This
1416 -- structure does not allocate memory and never needs to be freed
1418 type Error_Warning
is (Silent
, Warning
, Error
);
1419 -- Severity of some situations, such as: no Ada sources in a project where
1420 -- Ada is one of the language.
1422 -- When the situation occurs, the behaviour depends on the setting:
1424 -- - Silent: no action
1425 -- - Warning: issue a warning, does not cause the tool to fail
1426 -- - Error: issue an error, causes the tool to fail
1428 type Error_Handler
is access procedure
1429 (Project
: Project_Id
;
1430 Is_Warning
: Boolean);
1431 -- This warngs when an error was found when parsing a project. The error
1432 -- itself is handled through Prj.Err (and Prj.Err.Finalize should be called
1433 -- to actually print the error). This ensures that duplicate error messages
1434 -- are always correctly removed, that errors msgs are sorted, and that all
1435 -- tools will report the same error to the user.
1437 function Create_Flags
1438 (Report_Error
: Error_Handler
;
1439 When_No_Sources
: Error_Warning
;
1440 Require_Sources_Other_Lang
: Boolean := True;
1441 Allow_Duplicate_Basenames
: Boolean := True;
1442 Compiler_Driver_Mandatory
: Boolean := False;
1443 Error_On_Unknown_Language
: Boolean := True;
1444 Require_Obj_Dirs
: Error_Warning
:= Error
)
1445 return Processing_Flags
;
1446 -- Function used to create Processing_Flags structure
1448 -- If Allow_Duplicate_Basenames, then files with the same base names are
1449 -- authorized within a project for source-based languages (never for unit
1450 -- based languages).
1452 -- If Compiler_Driver_Mandatory is true, then a Compiler.Driver attribute
1453 -- for each language must be defined, or we will not look for its source
1456 -- When_No_Sources indicates what should be done when no sources of a
1457 -- language are found in a project where this language is declared.
1458 -- If Require_Sources_Other_Lang is true, then all languages must have at
1459 -- least one source file, or an error is reported via When_No_Sources. If
1460 -- it is false, this is only required for Ada (and only if it is a language
1461 -- of the project). When this parameter is set to False, we do not check
1462 -- that a proper naming scheme is defined for languages other than Ada.
1464 -- If Report_Error is null, use the standard error reporting mechanism
1465 -- (Errout). Otherwise, report errors using Report_Error.
1467 -- If Error_On_Unknown_Language is true, an error is displayed if some of
1468 -- the source files listed in the project do not match any naming scheme
1470 -- If Require_Obj_Dirs is true, then all object directories must exist
1471 -- (possibly after they have been created automatically if the appropriate
1472 -- switches were specified), or an error is raised.
1474 Gprbuild_Flags
: constant Processing_Flags
;
1475 Gprclean_Flags
: constant Processing_Flags
;
1476 Gnatmake_Flags
: constant Processing_Flags
;
1477 -- Flags used by the various tools. They all display the error messages
1484 procedure Record_Temp_File
1485 (Tree
: Project_Tree_Ref
;
1486 Path
: Path_Name_Type
);
1487 -- Record the path of a newly created temporary file, so that it can be
1490 procedure Delete_All_Temp_Files
(Tree
: Project_Tree_Ref
);
1491 -- Delete all recorded temporary files.
1492 -- Does nothing if Debug.Debug_Flag_N is set
1494 procedure Delete_Temporary_File
1495 (Tree
: Project_Tree_Ref
;
1496 Path
: Path_Name_Type
);
1497 -- Delete a temporary file from the disk. The file is also removed from the
1498 -- list of temporary files to delete at the end of the program, in case
1499 -- another program running on the same machine has recreated it.
1500 -- Does nothing if Debug.Debug_Flag_N is set
1504 All_Packages
: constant String_List_Access
:= null;
1506 No_Project_Tree
: constant Project_Tree_Ref
:= null;
1508 Ignored
: constant Variable_Kind
:= Single
;
1510 Nil_Variable_Value
: constant Variable_Value
:=
1511 (Project
=> No_Project
,
1513 Location
=> No_Location
,
1516 Virtual_Prefix
: constant String := "v$";
1517 -- The prefix for virtual extending projects. Because of the '$', which is
1518 -- normally forbidden for project names, there cannot be any name clash.
1520 type Source_Iterator
is record
1521 In_Tree
: Project_Tree_Ref
;
1523 Project
: Project_List
;
1524 All_Projects
: Boolean;
1525 -- Current project and whether we should move on to the next
1527 Language
: Language_Ptr
;
1528 -- Current language processed
1530 Language_Name
: Name_Id
;
1531 -- Only sources of this language will be returned (or all if No_Name)
1533 Current
: Source_Id
;
1536 procedure Add_To_Buffer
1538 To
: in out String_Access
;
1539 Last
: in out Natural);
1540 -- Append a String to the Buffer
1542 package Temp_Files_Table
is new GNAT
.Dynamic_Tables
1543 (Table_Component_Type
=> Path_Name_Type
,
1544 Table_Index_Type
=> Integer,
1545 Table_Low_Bound
=> 1,
1546 Table_Initial
=> 10,
1547 Table_Increment
=> 10);
1548 -- Table to store the path name of all the created temporary files, so that
1549 -- they can be deleted at the end, or when the program is interrupted.
1551 type Private_Project_Tree_Data
is record
1552 Temp_Files
: Temp_Files_Table
.Instance
;
1553 -- Temporary files created as part of running tools (pragma files,
1554 -- mapping files,...)
1556 Current_Source_Path_File
: Path_Name_Type
:= No_Path
;
1557 -- Current value of project source path file env var. Used to avoid
1558 -- setting the env var to the same value. When different from No_Path,
1559 -- this indicates that logical names (VMS) or environment variables were
1560 -- created and should be deassigned to avoid polluting the environment
1564 Current_Object_Path_File
: Path_Name_Type
:= No_Path
;
1565 -- Current value of project object path file env var. Used to avoid
1566 -- setting the env var to the same value.
1570 -- Type to represent the part of a project tree which is private to the
1573 type Processing_Flags
is record
1574 Require_Sources_Other_Lang
: Boolean;
1575 Report_Error
: Error_Handler
;
1576 When_No_Sources
: Error_Warning
;
1577 Allow_Duplicate_Basenames
: Boolean;
1578 Compiler_Driver_Mandatory
: Boolean;
1579 Error_On_Unknown_Language
: Boolean;
1580 Require_Obj_Dirs
: Error_Warning
;
1583 Gprbuild_Flags
: constant Processing_Flags
:=
1584 (Report_Error
=> null,
1585 When_No_Sources
=> Warning
,
1586 Require_Sources_Other_Lang
=> True,
1587 Allow_Duplicate_Basenames
=> False,
1588 Compiler_Driver_Mandatory
=> True,
1589 Error_On_Unknown_Language
=> True,
1590 Require_Obj_Dirs
=> Error
);
1592 Gprclean_Flags
: constant Processing_Flags
:=
1593 (Report_Error
=> null,
1594 When_No_Sources
=> Warning
,
1595 Require_Sources_Other_Lang
=> True,
1596 Allow_Duplicate_Basenames
=> False,
1597 Compiler_Driver_Mandatory
=> True,
1598 Error_On_Unknown_Language
=> True,
1599 Require_Obj_Dirs
=> Warning
);
1601 Gnatmake_Flags
: constant Processing_Flags
:=
1602 (Report_Error
=> null,
1603 When_No_Sources
=> Error
,
1604 Require_Sources_Other_Lang
=> False,
1605 Allow_Duplicate_Basenames
=> False,
1606 Compiler_Driver_Mandatory
=> False,
1607 Error_On_Unknown_Language
=> False,
1608 Require_Obj_Dirs
=> Error
);