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 ------------------------------------------------------------------------------
28 with Osint
; use Osint
;
29 with Output
; use Output
;
32 with Prj
.Err
; use Prj
.Err
;
33 with Snames
; use Snames
;
34 with Uintp
; use Uintp
;
36 with Ada
.Characters
.Handling
; use Ada
.Characters
.Handling
;
37 with Ada
.Containers
.Ordered_Sets
;
38 with Ada
.Unchecked_Deallocation
;
40 with GNAT
.Case_Util
; use GNAT
.Case_Util
;
41 with GNAT
.Directory_Operations
; use GNAT
.Directory_Operations
;
47 type Restricted_Lang_Access
is access Restricted_Lang
;
48 type Restricted_Lang
is record
50 Next
: Restricted_Lang_Access
;
53 Restricted_Languages
: Restricted_Lang_Access
:= null;
54 -- When null, all languages are allowed, otherwise only the languages in
55 -- the list are allowed.
57 Object_Suffix
: constant String := Get_Target_Object_Suffix
.all;
58 -- File suffix for object files
60 Initial_Buffer_Size
: constant := 100;
61 -- Initial size for extensible buffer used in Add_To_Buffer
63 The_Empty_String
: Name_Id
:= No_Name
;
65 Debug_Level
: Integer := 0;
66 -- Current indentation level for debug traces
68 type Cst_String_Access
is access constant String;
70 All_Lower_Case_Image
: aliased constant String := "lowercase";
71 All_Upper_Case_Image
: aliased constant String := "UPPERCASE";
72 Mixed_Case_Image
: aliased constant String := "MixedCase";
74 The_Casing_Images
: constant array (Known_Casing
) of Cst_String_Access
:=
75 (All_Lower_Case
=> All_Lower_Case_Image
'Access,
76 All_Upper_Case
=> All_Upper_Case_Image
'Access,
77 Mixed_Case
=> Mixed_Case_Image
'Access);
79 procedure Free
(Project
: in out Project_Id
);
80 -- Free memory allocated for Project
82 procedure Free_List
(Languages
: in out Language_Ptr
);
83 procedure Free_List
(Source
: in out Source_Id
);
84 procedure Free_List
(Languages
: in out Language_List
);
85 -- Free memory allocated for the list of languages or sources
87 procedure Reset_Units_In_Table
(Table
: in out Units_Htable
.Instance
);
88 -- Resets all Units to No_Unit_Index Unit.File_Names (Spec).Unit &
89 -- Unit.File_Names (Impl).Unit in the given table.
91 procedure Free_Units
(Table
: in out Units_Htable
.Instance
);
92 -- Free memory allocated for unit information in the project
94 procedure Language_Changed
(Iter
: in out Source_Iterator
);
95 procedure Project_Changed
(Iter
: in out Source_Iterator
);
96 -- Called when a new project or language was selected for this iterator
98 function Contains_ALI_Files
(Dir
: Path_Name_Type
) return Boolean;
99 -- Return True if there is at least one ALI file in the directory Dir
101 -----------------------------
102 -- Add_Restricted_Language --
103 -----------------------------
105 procedure Add_Restricted_Language
(Name
: String) is
106 N
: String (1 .. Name
'Length) := Name
;
110 Add_Str_To_Name_Buffer
(N
);
111 Restricted_Languages
:=
112 new Restricted_Lang
'(Name => Name_Find, Next => Restricted_Languages);
113 end Add_Restricted_Language;
115 -------------------------------------
116 -- Remove_All_Restricted_Languages --
117 -------------------------------------
119 procedure Remove_All_Restricted_Languages is
121 Restricted_Languages := null;
122 end Remove_All_Restricted_Languages;
128 procedure Add_To_Buffer
130 To : in out String_Access;
131 Last : in out Natural)
135 To := new String (1 .. Initial_Buffer_Size);
139 -- If Buffer is too small, double its size
141 while Last + S'Length > To'Last loop
143 New_Buffer : constant String_Access :=
144 new String (1 .. 2 * Last);
147 New_Buffer (1 .. Last) := To (1 .. Last);
153 To (Last + 1 .. Last + S'Length) := S;
154 Last := Last + S'Length;
157 ---------------------------------
158 -- Current_Object_Path_File_Of --
159 ---------------------------------
161 function Current_Object_Path_File_Of
162 (Shared : Shared_Project_Tree_Data_Access) return Path_Name_Type
165 return Shared.Private_Part.Current_Object_Path_File;
166 end Current_Object_Path_File_Of;
168 ---------------------------------
169 -- Current_Source_Path_File_Of --
170 ---------------------------------
172 function Current_Source_Path_File_Of
173 (Shared : Shared_Project_Tree_Data_Access)
174 return Path_Name_Type is
176 return Shared.Private_Part.Current_Source_Path_File;
177 end Current_Source_Path_File_Of;
179 ---------------------------
180 -- Delete_Temporary_File --
181 ---------------------------
183 procedure Delete_Temporary_File
184 (Shared : Shared_Project_Tree_Data_Access := null;
185 Path : Path_Name_Type)
188 pragma Warnings (Off, Dont_Care);
191 if not Debug.Debug_Flag_N then
192 if Current_Verbosity = High then
193 Write_Line ("Removing temp file: " & Get_Name_String (Path));
196 Delete_File (Get_Name_String (Path), Dont_Care);
198 if Shared /= null then
200 1 .. Temp_Files_Table.Last (Shared.Private_Part.Temp_Files)
202 if Shared.Private_Part.Temp_Files.Table (Index) = Path then
203 Shared.Private_Part.Temp_Files.Table (Index) := No_Path;
208 end Delete_Temporary_File;
210 ------------------------------
211 -- Delete_Temp_Config_Files --
212 ------------------------------
214 procedure Delete_Temp_Config_Files (Project_Tree : Project_Tree_Ref) is
216 pragma Warnings (Off, Success);
221 if not Debug.Debug_Flag_N then
222 if Project_Tree /= null then
223 Proj := Project_Tree.Projects;
224 while Proj /= null loop
225 if Proj.Project.Config_File_Temp then
226 Delete_Temporary_File
227 (Project_Tree.Shared, Proj.Project.Config_File_Name);
229 -- Make sure that we don't have a config file for this
230 -- project, in case there are several mains. In this case,
231 -- we will recreate another config file: we cannot reuse the
232 -- one that we just deleted!
234 Proj.Project.Config_Checked := False;
235 Proj.Project.Config_File_Name := No_Path;
236 Proj.Project.Config_File_Temp := False;
243 end Delete_Temp_Config_Files;
245 ---------------------------
246 -- Delete_All_Temp_Files --
247 ---------------------------
249 procedure Delete_All_Temp_Files
250 (Shared : Shared_Project_Tree_Data_Access)
253 pragma Warnings (Off, Dont_Care);
255 Path : Path_Name_Type;
258 if not Debug.Debug_Flag_N then
260 1 .. Temp_Files_Table.Last (Shared.Private_Part.Temp_Files)
262 Path := Shared.Private_Part.Temp_Files.Table (Index);
264 if Path /= No_Path then
265 if Current_Verbosity = High then
266 Write_Line ("Removing temp file: "
267 & Get_Name_String (Path));
270 Delete_File (Get_Name_String (Path), Dont_Care);
274 Temp_Files_Table.Free (Shared.Private_Part.Temp_Files);
275 Temp_Files_Table.Init (Shared.Private_Part.Temp_Files);
278 -- If any of the environment variables ADA_PRJ_INCLUDE_FILE or
279 -- ADA_PRJ_OBJECTS_FILE has been set, then reset their value to
280 -- the empty string. On VMS, this has the effect of deassigning
281 -- the logical names.
283 if Shared.Private_Part.Current_Source_Path_File /= No_Path then
284 Setenv (Project_Include_Path_File, "");
287 if Shared.Private_Part.Current_Object_Path_File /= No_Path then
288 Setenv (Project_Objects_Path_File, "");
290 end Delete_All_Temp_Files;
292 ---------------------
293 -- Dependency_Name --
294 ---------------------
296 function Dependency_Name
297 (Source_File_Name : File_Name_Type;
298 Dependency : Dependency_File_Kind) return File_Name_Type
306 return Extend_Name (Source_File_Name, Makefile_Dependency_Suffix);
308 when ALI_File | ALI_Closure =>
309 return Extend_Name (Source_File_Name, ALI_Dependency_Suffix);
317 function Empty_File return File_Name_Type is
319 return File_Name_Type (The_Empty_String);
326 function Empty_Project
327 (Qualifier : Project_Qualifier) return Project_Data
330 Prj.Initialize (Tree => No_Project_Tree);
333 Data : Project_Data (Qualifier => Qualifier);
336 -- Only the fields for which no default value could be provided in
337 -- prj.ads are initialized below.
339 Data.Config := Default_Project_Config;
348 function Empty_String return Name_Id is
350 return The_Empty_String;
357 procedure Expect (The_Token : Token_Type; Token_Image : String) is
359 if Token /= The_Token then
361 -- ??? Should pass user flags here instead
363 Error_Msg (Gnatmake_Flags, Token_Image & " expected", Token_Ptr);
372 (File : File_Name_Type;
373 With_Suffix : String) return File_Name_Type
378 Get_Name_String (File);
379 Last := Name_Len + 1;
381 while Name_Len /= 0 and then Name_Buffer (Name_Len) /= '.' loop
382 Name_Len := Name_Len - 1;
385 if Name_Len <= 1 then
389 for J in With_Suffix'Range loop
390 Name_Buffer (Name_Len) := With_Suffix (J);
391 Name_Len := Name_Len + 1;
394 Name_Len := Name_Len - 1;
398 -------------------------
399 -- Is_Allowed_Language --
400 -------------------------
402 function Is_Allowed_Language (Name : Name_Id) return Boolean is
403 R : Restricted_Lang_Access := Restricted_Languages;
404 Lang : constant String := Get_Name_String (Name);
412 if Get_Name_String (R.Name) = Lang then
421 end Is_Allowed_Language;
423 ---------------------
424 -- Project_Changed --
425 ---------------------
427 procedure Project_Changed (Iter : in out Source_Iterator) is
429 if Iter.Project /= null then
430 Iter.Language := Iter.Project.Project.Languages;
431 Language_Changed (Iter);
435 ----------------------
436 -- Language_Changed --
437 ----------------------
439 procedure Language_Changed (Iter : in out Source_Iterator) is
441 Iter.Current := No_Source;
443 if Iter.Language_Name /= No_Name then
444 while Iter.Language /= null
445 and then Iter.Language.Name /= Iter.Language_Name
447 Iter.Language := Iter.Language.Next;
451 -- If there is no matching language in this project, move to next
453 if Iter.Language = No_Language_Index then
454 if Iter.All_Projects then
456 Iter.Project := Iter.Project.Next;
457 exit when Iter.Project = null
458 or else Iter.Encapsulated_Libs
459 or else not Iter.Project.From_Encapsulated_Lib;
462 Project_Changed (Iter);
464 Iter.Project := null;
468 Iter.Current := Iter.Language.First_Source;
470 if Iter.Current = No_Source then
471 Iter.Language := Iter.Language.Next;
472 Language_Changed (Iter);
474 elsif not Iter.Locally_Removed
475 and then Iter.Current.Locally_Removed
480 end Language_Changed;
482 ---------------------
483 -- For_Each_Source --
484 ---------------------
486 function For_Each_Source
487 (In_Tree : Project_Tree_Ref;
488 Project : Project_Id := No_Project;
489 Language : Name_Id := No_Name;
490 Encapsulated_Libs : Boolean := True;
491 Locally_Removed : Boolean := True) return Source_Iterator
493 Iter : Source_Iterator;
495 Iter := Source_Iterator'
497 Project
=> In_Tree
.Projects
,
498 All_Projects
=> Project
= No_Project
,
499 Language_Name
=> Language
,
500 Language
=> No_Language_Index
,
501 Current
=> No_Source
,
502 Encapsulated_Libs
=> Encapsulated_Libs
,
503 Locally_Removed
=> Locally_Removed
);
505 if Project
/= null then
506 while Iter
.Project
/= null
507 and then Iter
.Project
.Project
/= Project
509 Iter
.Project
:= Iter
.Project
.Next
;
513 while not Iter
.Encapsulated_Libs
514 and then Iter
.Project
.From_Encapsulated_Lib
516 Iter
.Project
:= Iter
.Project
.Next
;
520 Project_Changed
(Iter
);
529 function Element
(Iter
: Source_Iterator
) return Source_Id
is
538 procedure Next
(Iter
: in out Source_Iterator
) is
541 Iter
.Current
:= Iter
.Current
.Next_In_Lang
;
543 exit when Iter
.Locally_Removed
544 or else Iter
.Current
= No_Source
545 or else not Iter
.Current
.Locally_Removed
;
548 if Iter
.Current
= No_Source
then
549 Iter
.Language
:= Iter
.Language
.Next
;
550 Language_Changed
(Iter
);
554 --------------------------------
555 -- For_Every_Project_Imported --
556 --------------------------------
558 procedure For_Every_Project_Imported_Context
560 Tree
: Project_Tree_Ref
;
561 With_State
: in out State
;
562 Include_Aggregated
: Boolean := True;
563 Imported_First
: Boolean := False)
565 use Project_Boolean_Htable
;
567 procedure Recursive_Check_Context
568 (Project
: Project_Id
;
569 Tree
: Project_Tree_Ref
;
570 In_Aggregate_Lib
: Boolean;
571 From_Encapsulated_Lib
: Boolean);
572 -- Recursively handle the project tree creating a new context for
573 -- keeping track about already handled projects.
575 -----------------------------
576 -- Recursive_Check_Context --
577 -----------------------------
579 procedure Recursive_Check_Context
580 (Project
: Project_Id
;
581 Tree
: Project_Tree_Ref
;
582 In_Aggregate_Lib
: Boolean;
583 From_Encapsulated_Lib
: Boolean)
585 package Name_Id_Set
is
586 new Ada
.Containers
.Ordered_Sets
(Element_Type
=> Name_Id
);
588 Seen_Name
: Name_Id_Set
.Set
;
589 -- This set is needed to ensure that we do not handle the same
590 -- project twice in the context of aggregate libraries.
592 procedure Recursive_Check
593 (Project
: Project_Id
;
594 Tree
: Project_Tree_Ref
;
595 In_Aggregate_Lib
: Boolean;
596 From_Encapsulated_Lib
: Boolean);
597 -- Check if project has already been seen. If not, mark it as Seen,
598 -- Call Action, and check all its imported and aggregated projects.
600 ---------------------
601 -- Recursive_Check --
602 ---------------------
604 procedure Recursive_Check
605 (Project
: Project_Id
;
606 Tree
: Project_Tree_Ref
;
607 In_Aggregate_Lib
: Boolean;
608 From_Encapsulated_Lib
: Boolean)
611 function Has_Sources
(P
: Project_Id
) return Boolean;
612 -- Returns True if P has sources
614 function Get_From_Tree
(P
: Project_Id
) return Project_Id
;
615 -- Get project P from Tree. If P has no sources get another
616 -- instance of this project with sources. If P has sources,
623 function Has_Sources
(P
: Project_Id
) return Boolean is
628 while Lang
/= No_Language_Index
loop
629 if Lang
.First_Source
/= No_Source
then
643 function Get_From_Tree
(P
: Project_Id
) return Project_Id
is
644 List
: Project_List
:= Tree
.Projects
;
647 if not Has_Sources
(P
) then
648 while List
/= null loop
649 if List
.Project
.Name
= P
.Name
650 and then Has_Sources
(List
.Project
)
666 -- Start of processing for Recursive_Check
669 if not Seen_Name
.Contains
(Project
.Name
) then
671 -- Even if a project is aggregated multiple times in an
672 -- aggregated library, we will only return it once.
674 Seen_Name
.Include
(Project
.Name
);
676 if not Imported_First
then
678 (Get_From_Tree
(Project
),
680 Project_Context
'(In_Aggregate_Lib, From_Encapsulated_Lib),
684 -- Visit all extended projects
686 if Project.Extends /= No_Project then
688 (Project.Extends, Tree,
689 In_Aggregate_Lib, From_Encapsulated_Lib);
692 -- Visit all imported projects
694 List := Project.Imported_Projects;
695 while List /= null loop
699 From_Encapsulated_Lib
700 or else Project.Standalone_Library = Encapsulated);
704 -- Visit all aggregated projects
706 if Include_Aggregated
707 and then Project.Qualifier in Aggregate_Project
710 Agg : Aggregated_Project_List;
713 Agg := Project.Aggregated_Projects;
714 while Agg /= null loop
715 pragma Assert (Agg.Project /= No_Project);
717 -- For aggregated libraries, the tree must be the one
718 -- of the aggregate library.
720 if Project.Qualifier = Aggregate_Library then
724 From_Encapsulated_Lib
726 Project.Standalone_Library = Encapsulated);
729 -- Use a new context as we want to returns the same
730 -- project in different project tree for aggregated
733 Recursive_Check_Context
734 (Agg.Project, Agg.Tree, False, False);
742 if Imported_First then
744 (Get_From_Tree (Project),
746 Project_Context'(In_Aggregate_Lib
, From_Encapsulated_Lib
),
752 -- Start of processing for Recursive_Check_Context
756 (Project
, Tree
, In_Aggregate_Lib
, From_Encapsulated_Lib
);
757 end Recursive_Check_Context
;
759 -- Start of processing for For_Every_Project_Imported
762 Recursive_Check_Context
765 In_Aggregate_Lib
=> False,
766 From_Encapsulated_Lib
=> False);
767 end For_Every_Project_Imported_Context
;
769 procedure For_Every_Project_Imported
771 Tree
: Project_Tree_Ref
;
772 With_State
: in out State
;
773 Include_Aggregated
: Boolean := True;
774 Imported_First
: Boolean := False)
777 (Project
: Project_Id
;
778 Tree
: Project_Tree_Ref
;
779 Context
: Project_Context
;
780 With_State
: in out State
);
781 -- Action wrapper for handling the context
788 (Project
: Project_Id
;
789 Tree
: Project_Tree_Ref
;
790 Context
: Project_Context
;
791 With_State
: in out State
)
793 pragma Unreferenced
(Context
);
795 Action
(Project
, Tree
, With_State
);
798 procedure For_Projects
is
799 new For_Every_Project_Imported_Context
(State
, Internal
);
802 For_Projects
(By
, Tree
, With_State
, Include_Aggregated
, Imported_First
);
803 end For_Every_Project_Imported
;
810 (In_Tree
: Project_Tree_Ref
;
811 Project
: Project_Id
;
812 In_Imported_Only
: Boolean := False;
813 In_Extended_Only
: Boolean := False;
814 Base_Name
: File_Name_Type
;
815 Index
: Int
:= 0) return Source_Id
817 Result
: Source_Id
:= No_Source
;
819 procedure Look_For_Sources
821 Tree
: Project_Tree_Ref
;
822 Src
: in out Source_Id
);
823 -- Look for Base_Name in the sources of Proj
825 ----------------------
826 -- Look_For_Sources --
827 ----------------------
829 procedure Look_For_Sources
831 Tree
: Project_Tree_Ref
;
832 Src
: in out Source_Id
)
834 Iterator
: Source_Iterator
;
837 Iterator
:= For_Each_Source
(In_Tree
=> Tree
, Project
=> Proj
);
838 while Element
(Iterator
) /= No_Source
loop
839 if Element
(Iterator
).File
= Base_Name
840 and then (Index
= 0 or else Element
(Iterator
).Index
= Index
)
842 Src
:= Element
(Iterator
);
844 -- If the source has been excluded, continue looking. We will
845 -- get the excluded source only if there is no other source
846 -- with the same base name that is not locally removed.
848 if not Element
(Iterator
).Locally_Removed
then
855 end Look_For_Sources
;
857 procedure For_Imported_Projects
is new For_Every_Project_Imported
858 (State
=> Source_Id
, Action
=> Look_For_Sources
);
862 -- Start of processing for Find_Source
865 if In_Extended_Only
then
867 while Proj
/= No_Project
loop
868 Look_For_Sources
(Proj
, In_Tree
, Result
);
869 exit when Result
/= No_Source
;
871 Proj
:= Proj
.Extends
;
874 elsif In_Imported_Only
then
875 Look_For_Sources
(Project
, In_Tree
, Result
);
877 if Result
= No_Source
then
878 For_Imported_Projects
881 Include_Aggregated
=> False,
882 With_State
=> Result
);
886 Look_For_Sources
(No_Project
, In_Tree
, Result
);
896 function Hash
is new GNAT
.HTable
.Hash
(Header_Num
=> Header_Num
);
897 -- Used in implementation of other functions Hash below
899 function Hash
(Name
: File_Name_Type
) return Header_Num
is
901 return Hash
(Get_Name_String
(Name
));
904 function Hash
(Name
: Name_Id
) return Header_Num
is
906 return Hash
(Get_Name_String
(Name
));
909 function Hash
(Name
: Path_Name_Type
) return Header_Num
is
911 return Hash
(Get_Name_String
(Name
));
914 function Hash
(Project
: Project_Id
) return Header_Num
is
916 if Project
= No_Project
then
917 return Header_Num
'First;
919 return Hash
(Get_Name_String
(Project
.Name
));
927 function Image
(The_Casing
: Casing_Type
) return String is
929 return The_Casing_Images
(The_Casing
).all;
932 -----------------------------
933 -- Is_Standard_GNAT_Naming --
934 -----------------------------
936 function Is_Standard_GNAT_Naming
937 (Naming
: Lang_Naming_Data
) return Boolean
940 return Get_Name_String
(Naming
.Spec_Suffix
) = ".ads"
941 and then Get_Name_String
(Naming
.Body_Suffix
) = ".adb"
942 and then Get_Name_String
(Naming
.Dot_Replacement
) = "-";
943 end Is_Standard_GNAT_Naming
;
949 procedure Initialize
(Tree
: Project_Tree_Ref
) is
951 if The_Empty_String
= No_Name
then
954 The_Empty_String
:= Name_Find
;
958 -- Make sure that new reserved words after Ada 95 may be used as
961 Opt
.Ada_Version
:= Opt
.Ada_95
;
963 Set_Name_Table_Byte
(Name_Project
, Token_Type
'Pos (Tok_Project
));
964 Set_Name_Table_Byte
(Name_Extends
, Token_Type
'Pos (Tok_Extends
));
965 Set_Name_Table_Byte
(Name_External
, Token_Type
'Pos (Tok_External
));
967 (Name_External_As_List
, Token_Type
'Pos (Tok_External_As_List
));
970 if Tree
/= No_Project_Tree
then
979 function Is_Extending
980 (Extending
: Project_Id
;
981 Extended
: Project_Id
) return Boolean
987 while Proj
/= No_Project
loop
988 if Proj
= Extended
then
992 Proj
:= Proj
.Extends
;
1002 function Object_Name
1003 (Source_File_Name
: File_Name_Type
;
1004 Object_File_Suffix
: Name_Id
:= No_Name
) return File_Name_Type
1007 if Object_File_Suffix
= No_Name
then
1009 (Source_File_Name
, Object_Suffix
);
1012 (Source_File_Name
, Get_Name_String
(Object_File_Suffix
));
1016 function Object_Name
1017 (Source_File_Name
: File_Name_Type
;
1019 Index_Separator
: Character;
1020 Object_File_Suffix
: Name_Id
:= No_Name
) return File_Name_Type
1022 Index_Img
: constant String := Source_Index
'Img;
1026 Get_Name_String
(Source_File_Name
);
1029 while Last
> 1 and then Name_Buffer
(Last
) /= '.' loop
1034 Name_Len
:= Last
- 1;
1037 Add_Char_To_Name_Buffer
(Index_Separator
);
1038 Add_Str_To_Name_Buffer
(Index_Img
(2 .. Index_Img
'Last));
1040 if Object_File_Suffix
= No_Name
then
1041 Add_Str_To_Name_Buffer
(Object_Suffix
);
1043 Add_Str_To_Name_Buffer
(Get_Name_String
(Object_File_Suffix
));
1049 ----------------------
1050 -- Record_Temp_File --
1051 ----------------------
1053 procedure Record_Temp_File
1054 (Shared
: Shared_Project_Tree_Data_Access
;
1055 Path
: Path_Name_Type
)
1058 Temp_Files_Table
.Append
(Shared
.Private_Part
.Temp_Files
, Path
);
1059 end Record_Temp_File
;
1065 procedure Free
(List
: in out Aggregated_Project_List
) is
1066 procedure Unchecked_Free
is new Ada
.Unchecked_Deallocation
1067 (Aggregated_Project
, Aggregated_Project_List
);
1068 Tmp
: Aggregated_Project_List
;
1070 while List
/= null loop
1075 Unchecked_Free
(List
);
1080 ----------------------------
1081 -- Add_Aggregated_Project --
1082 ----------------------------
1084 procedure Add_Aggregated_Project
1085 (Project
: Project_Id
; Path
: Path_Name_Type
) is
1087 Project
.Aggregated_Projects
:= new Aggregated_Project
'
1089 Project => No_Project,
1091 Next => Project.Aggregated_Projects);
1092 end Add_Aggregated_Project;
1098 procedure Free (Project : in out Project_Id) is
1099 procedure Unchecked_Free is new Ada.Unchecked_Deallocation
1100 (Project_Data, Project_Id);
1103 if Project /= null then
1104 Free (Project.Ada_Include_Path);
1105 Free (Project.Objects_Path);
1106 Free (Project.Ada_Objects_Path);
1107 Free_List (Project.Imported_Projects, Free_Project => False);
1108 Free_List (Project.All_Imported_Projects, Free_Project => False);
1109 Free_List (Project.Languages);
1111 case Project.Qualifier is
1112 when Aggregate | Aggregate_Library =>
1113 Free (Project.Aggregated_Projects);
1119 Unchecked_Free (Project);
1127 procedure Free_List (Languages : in out Language_List) is
1128 procedure Unchecked_Free is new Ada.Unchecked_Deallocation
1129 (Language_List_Element, Language_List);
1130 Tmp : Language_List;
1132 while Languages /= null loop
1133 Tmp := Languages.Next;
1134 Unchecked_Free (Languages);
1143 procedure Free_List (Source : in out Source_Id) is
1144 procedure Unchecked_Free is new
1145 Ada.Unchecked_Deallocation (Source_Data, Source_Id);
1150 while Source /= No_Source loop
1151 Tmp := Source.Next_In_Lang;
1152 Free_List (Source.Alternate_Languages);
1154 if Source.Unit /= null
1155 and then Source.Kind in Spec_Or_Body
1157 Source.Unit.File_Names (Source.Kind) := null;
1160 Unchecked_Free (Source);
1170 (List : in out Project_List;
1171 Free_Project : Boolean)
1173 procedure Unchecked_Free is new
1174 Ada.Unchecked_Deallocation (Project_List_Element, Project_List);
1179 while List /= null loop
1182 if Free_Project then
1183 Free (List.Project);
1186 Unchecked_Free (List);
1195 procedure Free_List (Languages : in out Language_Ptr) is
1196 procedure Unchecked_Free is new
1197 Ada.Unchecked_Deallocation (Language_Data, Language_Ptr);
1202 while Languages /= null loop
1203 Tmp := Languages.Next;
1204 Free_List (Languages.First_Source);
1205 Unchecked_Free (Languages);
1210 --------------------------
1211 -- Reset_Units_In_Table --
1212 --------------------------
1214 procedure Reset_Units_In_Table (Table : in out Units_Htable.Instance) is
1218 Unit := Units_Htable.Get_First (Table);
1219 while Unit /= No_Unit_Index loop
1220 if Unit.File_Names (Spec) /= null then
1221 Unit.File_Names (Spec).Unit := No_Unit_Index;
1224 if Unit.File_Names (Impl) /= null then
1225 Unit.File_Names (Impl).Unit := No_Unit_Index;
1228 Unit := Units_Htable.Get_Next (Table);
1230 end Reset_Units_In_Table;
1236 procedure Free_Units (Table : in out Units_Htable.Instance) is
1237 procedure Unchecked_Free is new
1238 Ada.Unchecked_Deallocation (Unit_Data, Unit_Index);
1243 Unit := Units_Htable.Get_First (Table);
1244 while Unit /= No_Unit_Index loop
1246 -- We cannot reset Unit.File_Names (Impl or Spec).Unit here as
1247 -- Source_Data buffer is freed by the following instruction
1248 -- Free_List (Tree.Projects, Free_Project => True);
1250 Unchecked_Free (Unit);
1251 Unit := Units_Htable.Get_Next (Table);
1254 Units_Htable.Reset (Table);
1261 procedure Free (Tree : in out Project_Tree_Ref) is
1262 procedure Unchecked_Free is new
1263 Ada.Unchecked_Deallocation
1264 (Project_Tree_Data, Project_Tree_Ref);
1266 procedure Unchecked_Free is new
1267 Ada.Unchecked_Deallocation
1268 (Project_Tree_Appdata'Class, Project_Tree_Appdata_Access);
1271 if Tree /= null then
1272 if Tree.Is_Root_Tree then
1273 Name_List_Table.Free (Tree.Shared.Name_Lists);
1274 Number_List_Table.Free (Tree.Shared.Number_Lists);
1275 String_Element_Table.Free (Tree.Shared.String_Elements);
1276 Variable_Element_Table.Free (Tree.Shared.Variable_Elements);
1277 Array_Element_Table.Free (Tree.Shared.Array_Elements);
1278 Array_Table.Free (Tree.Shared.Arrays);
1279 Package_Table.Free (Tree.Shared.Packages);
1280 Temp_Files_Table.Free (Tree.Shared.Private_Part.Temp_Files);
1283 if Tree.Appdata /= null then
1284 Free (Tree.Appdata.all);
1285 Unchecked_Free (Tree.Appdata);
1288 Source_Paths_Htable.Reset (Tree.Source_Paths_HT);
1289 Source_Files_Htable.Reset (Tree.Source_Files_HT);
1291 Reset_Units_In_Table (Tree.Units_HT);
1292 Free_List (Tree.Projects, Free_Project => True);
1293 Free_Units (Tree.Units_HT);
1295 Unchecked_Free (Tree);
1303 procedure Reset (Tree : Project_Tree_Ref) is
1307 if Tree.Is_Root_Tree then
1309 -- We cannot use 'Access here
:
1310 -- "illegal attribute for discriminant-dependent component"
1311 -- However, we know this is valid since Shared and Shared_Data have
1312 -- the same lifetime and will always exist concurrently.
1314 Tree
.Shared
:= Tree
.Shared_Data
'Unrestricted_Access;
1315 Name_List_Table
.Init
(Tree
.Shared
.Name_Lists
);
1316 Number_List_Table
.Init
(Tree
.Shared
.Number_Lists
);
1317 String_Element_Table
.Init
(Tree
.Shared
.String_Elements
);
1318 Variable_Element_Table
.Init
(Tree
.Shared
.Variable_Elements
);
1319 Array_Element_Table
.Init
(Tree
.Shared
.Array_Elements
);
1320 Array_Table
.Init
(Tree
.Shared
.Arrays
);
1321 Package_Table
.Init
(Tree
.Shared
.Packages
);
1323 -- Private part table
1325 Temp_Files_Table
.Init
(Tree
.Shared
.Private_Part
.Temp_Files
);
1327 Tree
.Shared
.Private_Part
.Current_Source_Path_File
:= No_Path
;
1328 Tree
.Shared
.Private_Part
.Current_Object_Path_File
:= No_Path
;
1331 Source_Paths_Htable
.Reset
(Tree
.Source_Paths_HT
);
1332 Source_Files_Htable
.Reset
(Tree
.Source_Files_HT
);
1333 Replaced_Source_HTable
.Reset
(Tree
.Replaced_Sources
);
1335 Tree
.Replaced_Source_Number
:= 0;
1337 Reset_Units_In_Table
(Tree
.Units_HT
);
1338 Free_List
(Tree
.Projects
, Free_Project
=> True);
1339 Free_Units
(Tree
.Units_HT
);
1342 -------------------------------------
1343 -- Set_Current_Object_Path_File_Of --
1344 -------------------------------------
1346 procedure Set_Current_Object_Path_File_Of
1347 (Shared
: Shared_Project_Tree_Data_Access
;
1348 To
: Path_Name_Type
)
1351 Shared
.Private_Part
.Current_Object_Path_File
:= To
;
1352 end Set_Current_Object_Path_File_Of
;
1354 -------------------------------------
1355 -- Set_Current_Source_Path_File_Of --
1356 -------------------------------------
1358 procedure Set_Current_Source_Path_File_Of
1359 (Shared
: Shared_Project_Tree_Data_Access
;
1360 To
: Path_Name_Type
)
1363 Shared
.Private_Part
.Current_Source_Path_File
:= To
;
1364 end Set_Current_Source_Path_File_Of
;
1366 -----------------------
1367 -- Set_Path_File_Var --
1368 -----------------------
1370 procedure Set_Path_File_Var
(Name
: String; Value
: String) is
1371 Host_Spec
: String_Access
:= To_Host_File_Spec
(Value
);
1373 if Host_Spec
= null then
1375 ("could not convert file name """ & Value
& """ to host spec");
1377 Setenv
(Name
, Host_Spec
.all);
1380 end Set_Path_File_Var
;
1386 function Switches_Name
1387 (Source_File_Name
: File_Name_Type
) return File_Name_Type
1390 return Extend_Name
(Source_File_Name
, Switches_Dependency_Suffix
);
1397 function Value
(Image
: String) return Casing_Type
is
1399 for Casing
in The_Casing_Images
'Range loop
1400 if To_Lower
(Image
) = To_Lower
(The_Casing_Images
(Casing
).all) then
1405 raise Constraint_Error
;
1408 ---------------------
1409 -- Has_Ada_Sources --
1410 ---------------------
1412 function Has_Ada_Sources
(Data
: Project_Id
) return Boolean is
1413 Lang
: Language_Ptr
;
1416 Lang
:= Data
.Languages
;
1417 while Lang
/= No_Language_Index
loop
1418 if Lang
.Name
= Name_Ada
then
1419 return Lang
.First_Source
/= No_Source
;
1425 end Has_Ada_Sources
;
1427 ------------------------
1428 -- Contains_ALI_Files --
1429 ------------------------
1431 function Contains_ALI_Files
(Dir
: Path_Name_Type
) return Boolean is
1432 Dir_Name
: constant String := Get_Name_String
(Dir
);
1434 Name
: String (1 .. 1_000
);
1436 Result
: Boolean := False;
1439 Open
(Direct
, Dir_Name
);
1441 -- For each file in the directory, check if it is an ALI file
1444 Read
(Direct
, Name
, Last
);
1446 Canonical_Case_File_Name
(Name
(1 .. Last
));
1447 Result
:= Last
>= 5 and then Name
(Last
- 3 .. Last
) = ".ali";
1455 -- If there is any problem, close the directory if open and return True.
1456 -- The library directory will be added to the path.
1459 if Is_Open
(Direct
) then
1464 end Contains_ALI_Files
;
1466 --------------------------
1467 -- Get_Object_Directory --
1468 --------------------------
1470 function Get_Object_Directory
1471 (Project
: Project_Id
;
1472 Including_Libraries
: Boolean;
1473 Only_If_Ada
: Boolean := False) return Path_Name_Type
1476 if (Project
.Library
and then Including_Libraries
)
1478 (Project
.Object_Directory
/= No_Path_Information
1479 and then (not Including_Libraries
or else not Project
.Library
))
1481 -- For a library project, add the library ALI directory if there is
1482 -- no object directory or if the library ALI directory contains ALI
1483 -- files; otherwise add the object directory.
1485 if Project
.Library
then
1486 if Project
.Object_Directory
= No_Path_Information
1487 or else Contains_ALI_Files
(Project
.Library_ALI_Dir
.Display_Name
)
1489 return Project
.Library_ALI_Dir
.Display_Name
;
1491 return Project
.Object_Directory
.Display_Name
;
1494 -- For a non-library project, add object directory if it is not a
1495 -- virtual project, and if there are Ada sources in the project or
1496 -- one of the projects it extends. If there are no Ada sources,
1497 -- adding the object directory could disrupt the order of the
1498 -- object dirs in the path.
1500 elsif not Project
.Virtual
then
1502 Add_Object_Dir
: Boolean;
1506 Add_Object_Dir
:= not Only_If_Ada
;
1508 while not Add_Object_Dir
and then Prj
/= No_Project
loop
1509 if Has_Ada_Sources
(Prj
) then
1510 Add_Object_Dir
:= True;
1516 if Add_Object_Dir
then
1517 return Project
.Object_Directory
.Display_Name
;
1524 end Get_Object_Directory
;
1526 -----------------------------------
1527 -- Ultimate_Extending_Project_Of --
1528 -----------------------------------
1530 function Ultimate_Extending_Project_Of
1531 (Proj
: Project_Id
) return Project_Id
1537 while Prj
/= null and then Prj
.Extended_By
/= No_Project
loop
1538 Prj
:= Prj
.Extended_By
;
1542 end Ultimate_Extending_Project_Of
;
1544 -----------------------------------
1545 -- Compute_All_Imported_Projects --
1546 -----------------------------------
1548 procedure Compute_All_Imported_Projects
1549 (Root_Project
: Project_Id
;
1550 Tree
: Project_Tree_Ref
)
1552 procedure Analyze_Tree
1553 (Local_Root
: Project_Id
;
1554 Local_Tree
: Project_Tree_Ref
;
1555 Context
: Project_Context
);
1556 -- Process Project and all its aggregated project to analyze their own
1557 -- imported projects.
1563 procedure Analyze_Tree
1564 (Local_Root
: Project_Id
;
1565 Local_Tree
: Project_Tree_Ref
;
1566 Context
: Project_Context
)
1568 pragma Unreferenced
(Local_Root
);
1570 Project
: Project_Id
;
1572 procedure Recursive_Add
1574 Tree
: Project_Tree_Ref
;
1575 Context
: Project_Context
;
1576 Dummy
: in out Boolean);
1577 -- Recursively add the projects imported by project Project, but not
1578 -- those that are extended.
1584 procedure Recursive_Add
1586 Tree
: Project_Tree_Ref
;
1587 Context
: Project_Context
;
1588 Dummy
: in out Boolean)
1590 pragma Unreferenced
(Dummy
, Tree
);
1592 List
: Project_List
;
1596 -- A project is not importing itself
1598 Prj2
:= Ultimate_Extending_Project_Of
(Prj
);
1600 if Project
/= Prj2
then
1602 -- Check that the project is not already in the list. We know
1603 -- the one passed to Recursive_Add have never been visited
1604 -- before, but the one passed it are the extended projects.
1606 List
:= Project
.All_Imported_Projects
;
1607 while List
/= null loop
1608 if List
.Project
= Prj2
then
1615 -- Add it to the list
1617 Project
.All_Imported_Projects
:=
1618 new Project_List_Element
'
1620 From_Encapsulated_Lib =>
1621 Context.From_Encapsulated_Lib
1622 or else Analyze_Tree.Context.From_Encapsulated_Lib,
1623 Next => Project.All_Imported_Projects);
1627 procedure For_All_Projects is
1628 new For_Every_Project_Imported_Context (Boolean, Recursive_Add);
1630 Dummy : Boolean := False;
1631 List : Project_List;
1634 List := Local_Tree.Projects;
1635 while List /= null loop
1636 Project := List.Project;
1638 (Project.All_Imported_Projects, Free_Project => False);
1640 (Project, Local_Tree, Dummy, Include_Aggregated => False);
1645 procedure For_Aggregates is
1646 new For_Project_And_Aggregated_Context (Analyze_Tree);
1648 -- Start of processing for Compute_All_Imported_Projects
1651 For_Aggregates (Root_Project, Tree);
1652 end Compute_All_Imported_Projects;
1658 function Is_Compilable (Source : Source_Id) return Boolean is
1660 case Source.Compilable is
1662 if Source.Language.Config.Compiler_Driver /= No_File
1664 Length_Of_Name (Source.Language.Config.Compiler_Driver) /= 0
1665 and then not Source.Locally_Removed
1666 and then (Source.Language.Config.Kind /= File_Based
1667 or else Source.Kind /= Spec)
1669 -- Do not modify Source.Compilable before the source record
1670 -- has been initialized.
1672 if Source.Source_TS /= Empty_Time_Stamp then
1673 Source.Compilable := Yes;
1679 if Source.Source_TS /= Empty_Time_Stamp then
1680 Source.Compilable := No;
1694 ------------------------------
1695 -- Object_To_Global_Archive --
1696 ------------------------------
1698 function Object_To_Global_Archive (Source : Source_Id) return Boolean is
1700 return Source.Language.Config.Kind = File_Based
1701 and then Source.Kind = Impl
1702 and then Source.Language.Config.Objects_Linked
1703 and then Is_Compilable (Source)
1704 and then Source.Language.Config.Object_Generated;
1705 end Object_To_Global_Archive;
1707 ----------------------------
1708 -- Get_Language_From_Name --
1709 ----------------------------
1711 function Get_Language_From_Name
1712 (Project : Project_Id;
1713 Name : String) return Language_Ptr
1716 Result : Language_Ptr;
1719 Name_Len := Name'Length;
1720 Name_Buffer (1 .. Name_Len) := Name;
1721 To_Lower (Name_Buffer (1 .. Name_Len));
1724 Result := Project.Languages;
1725 while Result /= No_Language_Index loop
1726 if Result.Name = N then
1730 Result := Result.Next;
1733 return No_Language_Index;
1734 end Get_Language_From_Name;
1740 function Other_Part (Source : Source_Id) return Source_Id is
1742 if Source.Unit /= No_Unit_Index then
1745 return Source.Unit.File_Names (Spec);
1747 return Source.Unit.File_Names (Impl);
1760 function Create_Flags
1761 (Report_Error : Error_Handler;
1762 When_No_Sources : Error_Warning;
1763 Require_Sources_Other_Lang : Boolean := True;
1764 Allow_Duplicate_Basenames : Boolean := True;
1765 Compiler_Driver_Mandatory : Boolean := False;
1766 Error_On_Unknown_Language : Boolean := True;
1767 Require_Obj_Dirs : Error_Warning := Error;
1768 Allow_Invalid_External : Error_Warning := Error;
1769 Missing_Source_Files : Error_Warning := Error;
1770 Ignore_Missing_With : Boolean := False)
1771 return Processing_Flags
1774 return Processing_Flags'
1775 (Report_Error
=> Report_Error
,
1776 When_No_Sources
=> When_No_Sources
,
1777 Require_Sources_Other_Lang
=> Require_Sources_Other_Lang
,
1778 Allow_Duplicate_Basenames
=> Allow_Duplicate_Basenames
,
1779 Error_On_Unknown_Language
=> Error_On_Unknown_Language
,
1780 Compiler_Driver_Mandatory
=> Compiler_Driver_Mandatory
,
1781 Require_Obj_Dirs
=> Require_Obj_Dirs
,
1782 Allow_Invalid_External
=> Allow_Invalid_External
,
1783 Missing_Source_Files
=> Missing_Source_Files
,
1784 Ignore_Missing_With
=> Ignore_Missing_With
);
1792 (Table
: Name_List_Table
.Instance
;
1793 List
: Name_List_Index
) return Natural
1795 Count
: Natural := 0;
1796 Tmp
: Name_List_Index
;
1800 while Tmp
/= No_Name_List
loop
1802 Tmp
:= Table
.Table
(Tmp
).Next
;
1812 procedure Debug_Output
(Str
: String) is
1814 if Current_Verbosity
> Default
then
1816 Write_Line
((1 .. Debug_Level
* 2 => ' ') & Str
);
1817 Set_Standard_Output
;
1825 procedure Debug_Indent
is
1827 if Current_Verbosity
= High
then
1829 Write_Str
((1 .. Debug_Level
* 2 => ' '));
1830 Set_Standard_Output
;
1838 procedure Debug_Output
(Str
: String; Str2
: Name_Id
) is
1840 if Current_Verbosity
= High
then
1845 if Str2
= No_Name
then
1846 Write_Line
(" <no_name>");
1848 Write_Line
(" """ & Get_Name_String
(Str2
) & '"');
1851 Set_Standard_Output
;
1855 ---------------------------
1856 -- Debug_Increase_Indent --
1857 ---------------------------
1859 procedure Debug_Increase_Indent
1860 (Str
: String := ""; Str2
: Name_Id
:= No_Name
)
1863 if Str2
/= No_Name
then
1864 Debug_Output
(Str
, Str2
);
1868 Debug_Level
:= Debug_Level
+ 1;
1869 end Debug_Increase_Indent
;
1871 ---------------------------
1872 -- Debug_Decrease_Indent --
1873 ---------------------------
1875 procedure Debug_Decrease_Indent
(Str
: String := "") is
1877 if Debug_Level
> 0 then
1878 Debug_Level
:= Debug_Level
- 1;
1884 end Debug_Decrease_Indent
;
1890 function Debug_Name
(Tree
: Project_Tree_Ref
) return Name_Id
is
1895 Add_Str_To_Name_Buffer
("Tree [");
1898 while P
/= null loop
1899 if P
/= Tree
.Projects
then
1900 Add_Char_To_Name_Buffer
(',');
1903 Add_Str_To_Name_Buffer
(Get_Name_String
(P
.Project
.Name
));
1908 Add_Char_To_Name_Buffer
(']');
1917 procedure Free
(Tree
: in out Project_Tree_Appdata
) is
1918 pragma Unreferenced
(Tree
);
1923 --------------------------------
1924 -- For_Project_And_Aggregated --
1925 --------------------------------
1927 procedure For_Project_And_Aggregated
1928 (Root_Project
: Project_Id
;
1929 Root_Tree
: Project_Tree_Ref
)
1931 Agg
: Aggregated_Project_List
;
1934 Action
(Root_Project
, Root_Tree
);
1936 if Root_Project
.Qualifier
in Aggregate_Project
then
1937 Agg
:= Root_Project
.Aggregated_Projects
;
1938 while Agg
/= null loop
1939 For_Project_And_Aggregated
(Agg
.Project
, Agg
.Tree
);
1943 end For_Project_And_Aggregated
;
1945 ----------------------------------------
1946 -- For_Project_And_Aggregated_Context --
1947 ----------------------------------------
1949 procedure For_Project_And_Aggregated_Context
1950 (Root_Project
: Project_Id
;
1951 Root_Tree
: Project_Tree_Ref
)
1954 procedure Recursive_Process
1955 (Project
: Project_Id
;
1956 Tree
: Project_Tree_Ref
;
1957 Context
: Project_Context
);
1958 -- Process Project and all aggregated projects recursively
1960 -----------------------
1961 -- Recursive_Process --
1962 -----------------------
1964 procedure Recursive_Process
1965 (Project
: Project_Id
;
1966 Tree
: Project_Tree_Ref
;
1967 Context
: Project_Context
)
1969 Agg
: Aggregated_Project_List
;
1970 Ctx
: Project_Context
;
1973 Action
(Project
, Tree
, Context
);
1975 if Project
.Qualifier
in Aggregate_Project
then
1977 (In_Aggregate_Lib
=> True,
1978 From_Encapsulated_Lib
=>
1979 Context
.From_Encapsulated_Lib
1980 or else Project
.Standalone_Library
= Encapsulated
);
1982 Agg
:= Project
.Aggregated_Projects
;
1983 while Agg
/= null loop
1984 Recursive_Process
(Agg
.Project
, Agg
.Tree
, Ctx
);
1988 end Recursive_Process
;
1990 -- Start of processing for For_Project_And_Aggregated_Context
1994 (Root_Project
, Root_Tree
, Project_Context
'(False, False));
1995 end For_Project_And_Aggregated_Context;
1997 -- Package initialization for Prj
2000 -- Make sure that the standard config and user project file extensions are
2001 -- compatible with canonical case file naming.
2003 Canonical_Case_File_Name (Config_Project_File_Extension);
2004 Canonical_Case_File_Name (Project_File_Extension);