1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2001-2008, 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 with Ada.Characters.Handling; use Ada.Characters.Handling;
29 with Output; use Output;
30 with Osint; use Osint;
33 with Prj.Err; use Prj.Err;
34 with Snames; use Snames;
35 with Uintp; use Uintp;
37 with System.Case_Util; use System.Case_Util;
41 Object_Suffix : constant String := Get_Target_Object_Suffix.all;
42 -- File suffix for object files
44 Initial_Buffer_Size : constant := 100;
45 -- Initial size for extensible buffer used in Add_To_Buffer
47 Current_Mode : Mode := Ada_Only;
49 Configuration_Mode : Boolean := False;
51 The_Empty_String : Name_Id;
53 Name_C_Plus_Plus : Name_Id;
55 Default_Ada_Spec_Suffix_Id : File_Name_Type;
56 Default_Ada_Body_Suffix_Id : File_Name_Type;
57 Slash_Id : Path_Name_Type;
58 -- Initialized in Prj.Initialize, then never modified
60 subtype Known_Casing is Casing_Type range All_Upper_Case .. Mixed_Case;
62 The_Casing_Images : constant array (Known_Casing) of String_Access :=
63 (All_Lower_Case => new String'("lowercase"),
64 All_Upper_Case => new String'("UPPERCASE"),
65 Mixed_Case => new String'("MixedCase"));
67 Initialized : Boolean := False;
69 Standard_Dot_Replacement : constant File_Name_Type :=
71 (First_Name_Id + Character'Pos ('-'));
73 Std_Naming_Data : constant Naming_Data :=
74 (Dot_Replacement => Standard_Dot_Replacement,
75 Dot_Repl_Loc => No_Location,
76 Casing => All_Lower_Case,
77 Spec_Suffix => No_Array_Element,
78 Ada_Spec_Suffix_Loc => No_Location,
79 Body_Suffix => No_Array_Element,
80 Ada_Body_Suffix_Loc => No_Location,
81 Separate_Suffix => No_File,
82 Sep_Suffix_Loc => No_Location,
83 Specs => No_Array_Element,
84 Bodies => No_Array_Element,
85 Specification_Exceptions => No_Array_Element,
86 Implementation_Exceptions => No_Array_Element,
87 Impl_Suffixes => No_Impl_Suffixes,
88 Supp_Suffixes => No_Supp_Language_Index);
90 Project_Empty : constant Project_Data :=
91 (Qualifier => Unspecified,
92 Externally_Built => False,
93 Config => Default_Project_Config,
94 Languages => No_Name_List,
95 First_Referred_By => No_Project,
97 Display_Name => No_Name,
98 Path => No_Path_Information,
100 Location => No_Location,
102 Directory => No_Path_Information,
105 Library_Dir => No_Path_Information,
106 Library_Src_Dir => No_Path_Information,
107 Library_ALI_Dir => No_Path_Information,
108 Library_Name => No_Name,
109 Library_Kind => Static,
110 Lib_Internal_Name => No_Name,
111 Standalone_Library => False,
112 Lib_Interface_ALIs => Nil_String,
113 Lib_Auto_Init => False,
114 Libgnarl_Needed => Unknown,
115 Symbol_Data => No_Symbols,
116 Ada_Sources => Nil_String,
117 Sources => Nil_String,
118 First_Source => No_Source,
119 Last_Source => No_Source,
120 Interfaces_Defined => False,
121 Unit_Based_Language_Name => No_Name,
122 Unit_Based_Language_Index => No_Language_Index,
123 Imported_Directories_Switches => null,
124 Include_Path => null,
125 Include_Data_Set => False,
126 Include_Language => No_Language_Index,
127 Source_Dirs => Nil_String,
128 Known_Order_Of_Source_Dirs => True,
129 Object_Directory => No_Path_Information,
130 Library_TS => Empty_Time_Stamp,
131 Exec_Directory => No_Path_Information,
132 Extends => No_Project,
133 Extended_By => No_Project,
134 Naming => Std_Naming_Data,
135 First_Language_Processing => No_Language_Index,
136 Decl => No_Declarations,
137 Imported_Projects => Empty_Project_List,
138 All_Imported_Projects => Empty_Project_List,
139 Ada_Include_Path => null,
140 Ada_Objects_Path => null,
141 Objects_Path => null,
142 Include_Path_File => No_Path,
143 Objects_Path_File_With_Libs => No_Path,
144 Objects_Path_File_Without_Libs => No_Path,
145 Config_File_Name => No_Path,
146 Config_File_Temp => False,
147 Linker_Name => No_File,
148 Linker_Path => No_Path,
149 Minimum_Linker_Options => No_Name_List,
150 Config_Checked => False,
153 Need_To_Build_Lib => False,
155 Unkept_Comments => False,
156 Langs => No_Languages,
157 Supp_Languages => No_Supp_Language_Index,
158 Ada_Sources_Present => True,
159 Other_Sources_Present => True,
160 First_Other_Source => No_Other_Source,
161 Last_Other_Source => No_Other_Source,
162 First_Lang_Processing =>
163 Default_First_Language_Processing_Data,
164 Supp_Language_Processing =>
165 No_Supp_Language_Index);
167 package Temp_Files is new Table.Table
168 (Table_Component_Type => Path_Name_Type,
169 Table_Index_Type => Integer,
170 Table_Low_Bound => 1,
172 Table_Increment => 100,
173 Table_Name => "Makegpr.Temp_Files");
174 -- Table to store the path name of all the created temporary files, so that
175 -- they can be deleted at the end, or when the program is interrupted.
177 -----------------------
178 -- Add_Language_Name --
179 -----------------------
181 procedure Add_Language_Name (Name : Name_Id) is
183 Last_Language_Index := Last_Language_Index + 1;
184 Language_Indexes.Set (Name, Last_Language_Index);
185 Language_Names.Increment_Last;
186 Language_Names.Table (Last_Language_Index) := Name;
187 end Add_Language_Name;
193 procedure Add_To_Buffer
195 To : in out String_Access;
196 Last : in out Natural)
200 To := new String (1 .. Initial_Buffer_Size);
204 -- If Buffer is too small, double its size
206 while Last + S'Length > To'Last loop
208 New_Buffer : constant String_Access :=
209 new String (1 .. 2 * Last);
212 New_Buffer (1 .. Last) := To (1 .. Last);
218 To (Last + 1 .. Last + S'Length) := S;
219 Last := Last + S'Length;
222 -----------------------
223 -- Body_Suffix_Id_Of --
224 -----------------------
226 function Body_Suffix_Id_Of
227 (In_Tree : Project_Tree_Ref;
229 Naming : Naming_Data) return File_Name_Type
231 Language_Id : Name_Id;
235 Add_Str_To_Name_Buffer (Language);
236 To_Lower (Name_Buffer (1 .. Name_Len));
237 Language_Id := Name_Find;
242 Language_Id => Language_Id,
244 end Body_Suffix_Id_Of;
246 -----------------------
247 -- Body_Suffix_Id_Of --
248 -----------------------
250 function Body_Suffix_Id_Of
251 (In_Tree : Project_Tree_Ref;
252 Language_Id : Name_Id;
253 Naming : Naming_Data) return File_Name_Type
255 Element_Id : Array_Element_Id;
256 Element : Array_Element;
257 Suffix : File_Name_Type := No_File;
258 Lang : Language_Index;
261 -- ??? This seems to be only for Ada_Only mode...
262 Element_Id := Naming.Body_Suffix;
263 while Element_Id /= No_Array_Element loop
264 Element := In_Tree.Array_Elements.Table (Element_Id);
266 if Element.Index = Language_Id then
267 return File_Name_Type (Element.Value.Value);
270 Element_Id := Element.Next;
273 if Current_Mode = Multi_Language then
274 Lang := In_Tree.First_Language;
275 while Lang /= No_Language_Index loop
276 if In_Tree.Languages_Data.Table (Lang).Name = Language_Id then
278 In_Tree.Languages_Data.Table
279 (Lang).Config.Naming_Data.Body_Suffix;
283 Lang := In_Tree.Languages_Data.Table (Lang).Next;
288 end Body_Suffix_Id_Of;
294 function Body_Suffix_Of
295 (In_Tree : Project_Tree_Ref;
297 Naming : Naming_Data) return String
299 Language_Id : Name_Id;
300 Element_Id : Array_Element_Id;
301 Element : Array_Element;
302 Suffix : File_Name_Type := No_File;
303 Lang : Language_Index;
307 Add_Str_To_Name_Buffer (Language);
308 To_Lower (Name_Buffer (1 .. Name_Len));
309 Language_Id := Name_Find;
311 Element_Id := Naming.Body_Suffix;
312 while Element_Id /= No_Array_Element loop
313 Element := In_Tree.Array_Elements.Table (Element_Id);
315 if Element.Index = Language_Id then
316 return Get_Name_String (Element.Value.Value);
319 Element_Id := Element.Next;
322 if Current_Mode = Multi_Language then
323 Lang := In_Tree.First_Language;
324 while Lang /= No_Language_Index loop
325 if In_Tree.Languages_Data.Table (Lang).Name = Language_Id then
328 (In_Tree.Languages_Data.Table
329 (Lang).Config.Naming_Data.Body_Suffix);
333 Lang := In_Tree.Languages_Data.Table (Lang).Next;
336 if Suffix /= No_File then
337 return Get_Name_String (Suffix);
344 function Body_Suffix_Of
345 (Language : Language_Index;
346 In_Project : Project_Data;
347 In_Tree : Project_Tree_Ref) return String
349 Suffix_Id : constant File_Name_Type :=
350 Suffix_Of (Language, In_Project, In_Tree);
352 if Suffix_Id /= No_File then
353 return Get_Name_String (Suffix_Id);
355 return "." & Get_Name_String (Language_Names.Table (Language));
359 -----------------------------
360 -- Default_Ada_Body_Suffix --
361 -----------------------------
363 function Default_Ada_Body_Suffix return File_Name_Type is
365 return Default_Ada_Body_Suffix_Id;
366 end Default_Ada_Body_Suffix;
368 -----------------------------
369 -- Default_Ada_Spec_Suffix --
370 -----------------------------
372 function Default_Ada_Spec_Suffix return File_Name_Type is
374 return Default_Ada_Spec_Suffix_Id;
375 end Default_Ada_Spec_Suffix;
377 ---------------------------
378 -- Delete_All_Temp_Files --
379 ---------------------------
381 procedure Delete_All_Temp_Files is
383 pragma Warnings (Off, Dont_Care);
385 if not Debug.Debug_Flag_N then
386 for Index in 1 .. Temp_Files.Last loop
388 (Get_Name_String (Temp_Files.Table (Index)), Dont_Care);
391 end Delete_All_Temp_Files;
393 ---------------------
394 -- Dependency_Name --
395 ---------------------
397 function Dependency_Name
398 (Source_File_Name : File_Name_Type;
399 Dependency : Dependency_File_Kind) return File_Name_Type
410 (Source_File_Name, Makefile_Dependency_Suffix));
416 (Source_File_Name, ALI_Dependency_Suffix));
420 ---------------------------
421 -- Display_Language_Name --
422 ---------------------------
424 procedure Display_Language_Name
425 (In_Tree : Project_Tree_Ref;
426 Language : Language_Index)
429 Get_Name_String (In_Tree.Languages_Data.Table (Language).Display_Name);
430 Write_Str (Name_Buffer (1 .. Name_Len));
431 end Display_Language_Name;
433 ---------------------------
434 -- Display_Language_Name --
435 ---------------------------
437 procedure Display_Language_Name (Language : Language_Index) is
439 Get_Name_String (Language_Names.Table (Language));
440 To_Upper (Name_Buffer (1 .. 1));
441 Write_Str (Name_Buffer (1 .. Name_Len));
442 end Display_Language_Name;
448 function Empty_File return File_Name_Type is
450 return File_Name_Type (The_Empty_String);
457 function Empty_Project (Tree : Project_Tree_Ref) return Project_Data is
458 Value : Project_Data;
461 Prj.Initialize (Tree => No_Project_Tree);
462 Value := Project_Empty;
463 Value.Naming := Tree.Private_Part.Default_Naming;
472 function Empty_String return Name_Id is
474 return The_Empty_String;
481 procedure Expect (The_Token : Token_Type; Token_Image : String) is
483 if Token /= The_Token then
484 Error_Msg (Token_Image & " expected", Token_Ptr);
493 (File : File_Name_Type;
494 With_Suffix : String) return File_Name_Type
499 Get_Name_String (File);
500 Last := Name_Len + 1;
502 while Name_Len /= 0 and then Name_Buffer (Name_Len) /= '.' loop
503 Name_Len := Name_Len - 1;
506 if Name_Len <= 1 then
510 for J in With_Suffix'Range loop
511 Name_Buffer (Name_Len) := With_Suffix (J);
512 Name_Len := Name_Len + 1;
515 Name_Len := Name_Len - 1;
520 --------------------------------
521 -- For_Every_Project_Imported --
522 --------------------------------
524 procedure For_Every_Project_Imported
526 In_Tree : Project_Tree_Ref;
527 With_State : in out State)
530 procedure Recursive_Check (Project : Project_Id);
531 -- Check if a project has already been seen. If not seen, mark it as
532 -- Seen, Call Action, and check all its imported projects.
534 ---------------------
535 -- Recursive_Check --
536 ---------------------
538 procedure Recursive_Check (Project : Project_Id) is
541 if not In_Tree.Projects.Table (Project).Seen then
542 In_Tree.Projects.Table (Project).Seen := True;
543 Action (Project, With_State);
545 List := In_Tree.Projects.Table (Project).Imported_Projects;
546 while List /= Empty_Project_List loop
547 Recursive_Check (In_Tree.Project_Lists.Table (List).Project);
548 List := In_Tree.Project_Lists.Table (List).Next;
553 -- Start of processing for For_Every_Project_Imported
556 for Project in Project_Table.First ..
557 Project_Table.Last (In_Tree.Projects)
559 In_Tree.Projects.Table (Project).Seen := False;
562 Recursive_Check (Project => By);
563 end For_Every_Project_Imported;
569 function Get_Mode return Mode is
578 function Hash is new System.HTable.Hash (Header_Num => Header_Num);
579 -- Used in implementation of other functions Hash below
581 function Hash (Name : File_Name_Type) return Header_Num is
583 return Hash (Get_Name_String (Name));
586 function Hash (Name : Name_Id) return Header_Num is
588 return Hash (Get_Name_String (Name));
591 function Hash (Name : Path_Name_Type) return Header_Num is
593 return Hash (Get_Name_String (Name));
596 function Hash (Project : Project_Id) return Header_Num is
598 return Header_Num (Project mod Max_Header_Num);
605 function Image (Casing : Casing_Type) return String is
607 return The_Casing_Images (Casing).all;
610 ----------------------
611 -- In_Configuration --
612 ----------------------
614 function In_Configuration return Boolean is
616 return Configuration_Mode;
617 end In_Configuration;
623 procedure Initialize (Tree : Project_Tree_Ref) is
625 if not Initialized then
629 The_Empty_String := Name_Find;
630 Empty_Name := The_Empty_String;
631 Empty_File_Name := File_Name_Type (The_Empty_String);
633 Name_Buffer (1 .. 4) := ".ads";
634 Default_Ada_Spec_Suffix_Id := Name_Find;
636 Name_Buffer (1 .. 4) := ".adb";
637 Default_Ada_Body_Suffix_Id := Name_Find;
639 Name_Buffer (1) := '/';
640 Slash_Id := Name_Find;
642 Name_Buffer (1 .. 3) := "c++";
643 Name_C_Plus_Plus := Name_Find;
647 Set_Name_Table_Byte (Name_Project, Token_Type'Pos (Tok_Project));
648 Set_Name_Table_Byte (Name_Extends, Token_Type'Pos (Tok_Extends));
649 Set_Name_Table_Byte (Name_External, Token_Type'Pos (Tok_External));
651 Language_Indexes.Reset;
652 Last_Language_Index := No_Language_Index;
654 Add_Language_Name (Name_Ada);
655 Add_Language_Name (Name_C);
656 Add_Language_Name (Name_C_Plus_Plus);
659 if Tree /= No_Project_Tree then
668 function Is_A_Language
669 (Tree : Project_Tree_Ref;
671 Language_Name : Name_Id) return Boolean
674 if Get_Mode = Ada_Only then
676 List : Name_List_Index := Data.Languages;
678 while List /= No_Name_List loop
679 if Tree.Name_Lists.Table (List).Name = Language_Name then
682 List := Tree.Name_Lists.Table (List).Next;
689 Lang_Ind : Language_Index := Data.First_Language_Processing;
690 Lang_Data : Language_Data;
693 while Lang_Ind /= No_Language_Index loop
694 Lang_Data := Tree.Languages_Data.Table (Lang_Ind);
696 if Lang_Data.Name = Language_Name then
700 Lang_Ind := Lang_Data.Next;
712 function Is_Extending
713 (Extending : Project_Id;
714 Extended : Project_Id;
715 In_Tree : Project_Tree_Ref) return Boolean
721 while Proj /= No_Project loop
722 if Proj = Extended then
726 Proj := In_Tree.Projects.Table (Proj).Extends;
737 (Language : Language_Index;
738 In_Project : Project_Data;
739 In_Tree : Project_Tree_Ref) return Boolean
743 when No_Language_Index =>
746 when First_Language_Indexes =>
747 return In_Project.Langs (Language);
751 Supp : Supp_Language;
752 Supp_Index : Supp_Language_Index;
755 Supp_Index := In_Project.Supp_Languages;
756 while Supp_Index /= No_Supp_Language_Index loop
757 Supp := In_Tree.Present_Languages.Table (Supp_Index);
759 if Supp.Index = Language then
763 Supp_Index := Supp.Next;
771 ---------------------------------
772 -- Language_Processing_Data_Of --
773 ---------------------------------
775 function Language_Processing_Data_Of
776 (Language : Language_Index;
777 In_Project : Project_Data;
778 In_Tree : Project_Tree_Ref) return Language_Processing_Data
782 when No_Language_Index =>
783 return Default_Language_Processing_Data;
785 when First_Language_Indexes =>
786 return In_Project.First_Lang_Processing (Language);
790 Supp : Supp_Language_Data;
791 Supp_Index : Supp_Language_Index;
794 Supp_Index := In_Project.Supp_Language_Processing;
795 while Supp_Index /= No_Supp_Language_Index loop
796 Supp := In_Tree.Supp_Languages.Table (Supp_Index);
798 if Supp.Index = Language then
802 Supp_Index := Supp.Next;
805 return Default_Language_Processing_Data;
808 end Language_Processing_Data_Of;
810 -----------------------
811 -- Objects_Exist_For --
812 -----------------------
814 function Objects_Exist_For
816 In_Tree : Project_Tree_Ref) return Boolean
818 Language_Id : Name_Id;
819 Lang : Language_Index;
822 if Current_Mode = Multi_Language then
824 Add_Str_To_Name_Buffer (Language);
825 To_Lower (Name_Buffer (1 .. Name_Len));
826 Language_Id := Name_Find;
828 Lang := In_Tree.First_Language;
829 while Lang /= No_Language_Index loop
830 if In_Tree.Languages_Data.Table (Lang).Name = Language_Id then
832 In_Tree.Languages_Data.Table
833 (Lang).Config.Objects_Generated;
836 Lang := In_Tree.Languages_Data.Table (Lang).Next;
841 end Objects_Exist_For;
848 (Source_File_Name : File_Name_Type)
849 return File_Name_Type
852 return Extend_Name (Source_File_Name, Object_Suffix);
855 ----------------------
856 -- Record_Temp_File --
857 ----------------------
859 procedure Record_Temp_File (Path : Path_Name_Type) is
861 Temp_Files.Increment_Last;
862 Temp_Files.Table (Temp_Files.Last) := Path;
863 end Record_Temp_File;
865 ------------------------------------
866 -- Register_Default_Naming_Scheme --
867 ------------------------------------
869 procedure Register_Default_Naming_Scheme
871 Default_Spec_Suffix : File_Name_Type;
872 Default_Body_Suffix : File_Name_Type;
873 In_Tree : Project_Tree_Ref)
876 Suffix : Array_Element_Id;
877 Found : Boolean := False;
878 Element : Array_Element;
881 -- Get the language name in small letters
883 Get_Name_String (Language);
884 Name_Buffer (1 .. Name_Len) := To_Lower (Name_Buffer (1 .. Name_Len));
887 -- Look for an element of the spec suffix array indexed by the language
888 -- name. If one is found, put the default value.
890 Suffix := In_Tree.Private_Part.Default_Naming.Spec_Suffix;
892 while Suffix /= No_Array_Element and then not Found loop
893 Element := In_Tree.Array_Elements.Table (Suffix);
895 if Element.Index = Lang then
897 Element.Value.Value := Name_Id (Default_Spec_Suffix);
898 In_Tree.Array_Elements.Table (Suffix) := Element;
901 Suffix := Element.Next;
905 -- If none can be found, create a new one
911 Index_Case_Sensitive => False,
912 Value => (Project => No_Project,
914 Location => No_Location,
916 Value => Name_Id (Default_Spec_Suffix),
918 Next => In_Tree.Private_Part.Default_Naming.Spec_Suffix);
919 Array_Element_Table.Increment_Last (In_Tree.Array_Elements);
920 In_Tree.Array_Elements.Table
921 (Array_Element_Table.Last (In_Tree.Array_Elements)) :=
923 In_Tree.Private_Part.Default_Naming.Spec_Suffix :=
924 Array_Element_Table.Last (In_Tree.Array_Elements);
927 -- Look for an element of the body suffix array indexed by the language
928 -- name. If one is found, put the default value.
930 Suffix := In_Tree.Private_Part.Default_Naming.Body_Suffix;
932 while Suffix /= No_Array_Element and then not Found loop
933 Element := In_Tree.Array_Elements.Table (Suffix);
935 if Element.Index = Lang then
937 Element.Value.Value := Name_Id (Default_Body_Suffix);
938 In_Tree.Array_Elements.Table (Suffix) := Element;
941 Suffix := Element.Next;
945 -- If none can be found, create a new one
951 Index_Case_Sensitive => False,
952 Value => (Project => No_Project,
954 Location => No_Location,
956 Value => Name_Id (Default_Body_Suffix),
958 Next => In_Tree.Private_Part.Default_Naming.Body_Suffix);
959 Array_Element_Table.Increment_Last
960 (In_Tree.Array_Elements);
961 In_Tree.Array_Elements.Table
962 (Array_Element_Table.Last (In_Tree.Array_Elements))
964 In_Tree.Private_Part.Default_Naming.Body_Suffix :=
965 Array_Element_Table.Last (In_Tree.Array_Elements);
967 end Register_Default_Naming_Scheme;
973 procedure Reset (Tree : Project_Tree_Ref) is
975 -- Def_Lang : constant Name_Node :=
976 -- (Name => Name_Ada,
977 -- Next => No_Name_List);
978 -- Why is the above commented out ???
985 Present_Language_Table.Init (Tree.Present_Languages);
986 Supp_Suffix_Table.Init (Tree.Supp_Suffixes);
987 Supp_Language_Table.Init (Tree.Supp_Languages);
988 Other_Source_Table.Init (Tree.Other_Sources);
992 Language_Data_Table.Init (Tree.Languages_Data);
993 Name_List_Table.Init (Tree.Name_Lists);
994 String_Element_Table.Init (Tree.String_Elements);
995 Variable_Element_Table.Init (Tree.Variable_Elements);
996 Array_Element_Table.Init (Tree.Array_Elements);
997 Array_Table.Init (Tree.Arrays);
998 Package_Table.Init (Tree.Packages);
999 Project_List_Table.Init (Tree.Project_Lists);
1000 Project_Table.Init (Tree.Projects);
1001 Source_Data_Table.Init (Tree.Sources);
1002 Alternate_Language_Table.Init (Tree.Alt_Langs);
1003 Unit_Table.Init (Tree.Units);
1004 Units_Htable.Reset (Tree.Units_HT);
1005 Files_Htable.Reset (Tree.Files_HT);
1006 Source_Paths_Htable.Reset (Tree.Source_Paths_HT);
1008 -- Private part table
1010 Naming_Table.Init (Tree.Private_Part.Namings);
1011 Naming_Table.Increment_Last (Tree.Private_Part.Namings);
1012 Tree.Private_Part.Namings.Table
1013 (Naming_Table.Last (Tree.Private_Part.Namings)) := Std_Naming_Data;
1014 Path_File_Table.Init (Tree.Private_Part.Path_Files);
1015 Source_Path_Table.Init (Tree.Private_Part.Source_Paths);
1016 Object_Path_Table.Init (Tree.Private_Part.Object_Paths);
1017 Tree.Private_Part.Default_Naming := Std_Naming_Data;
1019 if Current_Mode = Ada_Only then
1020 Register_Default_Naming_Scheme
1021 (Language => Name_Ada,
1022 Default_Spec_Suffix => Default_Ada_Spec_Suffix,
1023 Default_Body_Suffix => Default_Ada_Body_Suffix,
1025 Tree.Private_Part.Default_Naming.Separate_Suffix :=
1026 Default_Ada_Body_Suffix;
1030 ------------------------
1031 -- Same_Naming_Scheme --
1032 ------------------------
1034 function Same_Naming_Scheme
1035 (Left, Right : Naming_Data) return Boolean
1038 return Left.Dot_Replacement = Right.Dot_Replacement
1039 and then Left.Casing = Right.Casing
1040 and then Left.Separate_Suffix = Right.Separate_Suffix;
1041 end Same_Naming_Scheme;
1048 (Language : Language_Index;
1050 In_Project : in out Project_Data;
1051 In_Tree : Project_Tree_Ref)
1055 when No_Language_Index =>
1058 when First_Language_Indexes =>
1059 In_Project.Langs (Language) := Present;
1063 Supp : Supp_Language;
1064 Supp_Index : Supp_Language_Index;
1067 Supp_Index := In_Project.Supp_Languages;
1068 while Supp_Index /= No_Supp_Language_Index loop
1069 Supp := In_Tree.Present_Languages.Table (Supp_Index);
1071 if Supp.Index = Language then
1072 In_Tree.Present_Languages.Table (Supp_Index).Present :=
1077 Supp_Index := Supp.Next;
1080 Supp := (Index => Language, Present => Present,
1081 Next => In_Project.Supp_Languages);
1082 Present_Language_Table.Increment_Last
1083 (In_Tree.Present_Languages);
1085 Present_Language_Table.Last (In_Tree.Present_Languages);
1086 In_Tree.Present_Languages.Table (Supp_Index) :=
1088 In_Project.Supp_Languages := Supp_Index;
1094 (Language_Processing : Language_Processing_Data;
1095 For_Language : Language_Index;
1096 In_Project : in out Project_Data;
1097 In_Tree : Project_Tree_Ref)
1100 case For_Language is
1101 when No_Language_Index =>
1104 when First_Language_Indexes =>
1105 In_Project.First_Lang_Processing (For_Language) :=
1106 Language_Processing;
1110 Supp : Supp_Language_Data;
1111 Supp_Index : Supp_Language_Index;
1114 Supp_Index := In_Project.Supp_Language_Processing;
1115 while Supp_Index /= No_Supp_Language_Index loop
1116 Supp := In_Tree.Supp_Languages.Table (Supp_Index);
1118 if Supp.Index = For_Language then
1119 In_Tree.Supp_Languages.Table
1120 (Supp_Index).Data := Language_Processing;
1124 Supp_Index := Supp.Next;
1127 Supp := (Index => For_Language, Data => Language_Processing,
1128 Next => In_Project.Supp_Language_Processing);
1129 Supp_Language_Table.Increment_Last
1130 (In_Tree.Supp_Languages);
1131 Supp_Index := Supp_Language_Table.Last
1132 (In_Tree.Supp_Languages);
1133 In_Tree.Supp_Languages.Table (Supp_Index) := Supp;
1134 In_Project.Supp_Language_Processing := Supp_Index;
1140 (Suffix : File_Name_Type;
1141 For_Language : Language_Index;
1142 In_Project : in out Project_Data;
1143 In_Tree : Project_Tree_Ref)
1146 case For_Language is
1147 when No_Language_Index =>
1150 when First_Language_Indexes =>
1151 In_Project.Naming.Impl_Suffixes (For_Language) := Suffix;
1156 Supp_Index : Supp_Language_Index;
1159 Supp_Index := In_Project.Naming.Supp_Suffixes;
1160 while Supp_Index /= No_Supp_Language_Index loop
1161 Supp := In_Tree.Supp_Suffixes.Table (Supp_Index);
1163 if Supp.Index = For_Language then
1164 In_Tree.Supp_Suffixes.Table (Supp_Index).Suffix := Suffix;
1168 Supp_Index := Supp.Next;
1171 Supp := (Index => For_Language, Suffix => Suffix,
1172 Next => In_Project.Naming.Supp_Suffixes);
1173 Supp_Suffix_Table.Increment_Last (In_Tree.Supp_Suffixes);
1174 Supp_Index := Supp_Suffix_Table.Last (In_Tree.Supp_Suffixes);
1175 In_Tree.Supp_Suffixes.Table (Supp_Index) := Supp;
1176 In_Project.Naming.Supp_Suffixes := Supp_Index;
1181 ---------------------
1182 -- Set_Body_Suffix --
1183 ---------------------
1185 procedure Set_Body_Suffix
1186 (In_Tree : Project_Tree_Ref;
1188 Naming : in out Naming_Data;
1189 Suffix : File_Name_Type)
1191 Language_Id : Name_Id;
1192 Element : Array_Element;
1196 Add_Str_To_Name_Buffer (Language);
1197 To_Lower (Name_Buffer (1 .. Name_Len));
1198 Language_Id := Name_Find;
1201 (Index => Language_Id,
1203 Index_Case_Sensitive => False,
1206 Project => No_Project,
1207 Location => No_Location,
1209 Value => Name_Id (Suffix),
1211 Next => Naming.Body_Suffix);
1213 Array_Element_Table.Increment_Last (In_Tree.Array_Elements);
1214 Naming.Body_Suffix :=
1215 Array_Element_Table.Last (In_Tree.Array_Elements);
1216 In_Tree.Array_Elements.Table (Naming.Body_Suffix) := Element;
1217 end Set_Body_Suffix;
1219 --------------------------
1220 -- Set_In_Configuration --
1221 --------------------------
1223 procedure Set_In_Configuration (Value : Boolean) is
1225 Configuration_Mode := Value;
1226 end Set_In_Configuration;
1232 procedure Set_Mode (New_Mode : Mode) is
1234 Current_Mode := New_Mode;
1237 Default_Language_Is_Ada := True;
1238 Must_Check_Configuration := False;
1239 when Multi_Language =>
1240 Default_Language_Is_Ada := False;
1241 Must_Check_Configuration := True;
1245 ---------------------
1246 -- Set_Spec_Suffix --
1247 ---------------------
1249 procedure Set_Spec_Suffix
1250 (In_Tree : Project_Tree_Ref;
1252 Naming : in out Naming_Data;
1253 Suffix : File_Name_Type)
1255 Language_Id : Name_Id;
1256 Element : Array_Element;
1260 Add_Str_To_Name_Buffer (Language);
1261 To_Lower (Name_Buffer (1 .. Name_Len));
1262 Language_Id := Name_Find;
1265 (Index => Language_Id,
1267 Index_Case_Sensitive => False,
1270 Project => No_Project,
1271 Location => No_Location,
1273 Value => Name_Id (Suffix),
1275 Next => Naming.Spec_Suffix);
1277 Array_Element_Table.Increment_Last (In_Tree.Array_Elements);
1278 Naming.Spec_Suffix :=
1279 Array_Element_Table.Last (In_Tree.Array_Elements);
1280 In_Tree.Array_Elements.Table (Naming.Spec_Suffix) := Element;
1281 end Set_Spec_Suffix;
1287 function Slash return Path_Name_Type is
1292 -----------------------
1293 -- Spec_Suffix_Id_Of --
1294 -----------------------
1296 function Spec_Suffix_Id_Of
1297 (In_Tree : Project_Tree_Ref;
1299 Naming : Naming_Data) return File_Name_Type
1301 Language_Id : Name_Id;
1305 Add_Str_To_Name_Buffer (Language);
1306 To_Lower (Name_Buffer (1 .. Name_Len));
1307 Language_Id := Name_Find;
1311 (In_Tree => In_Tree,
1312 Language_Id => Language_Id,
1314 end Spec_Suffix_Id_Of;
1316 -----------------------
1317 -- Spec_Suffix_Id_Of --
1318 -----------------------
1320 function Spec_Suffix_Id_Of
1321 (In_Tree : Project_Tree_Ref;
1322 Language_Id : Name_Id;
1323 Naming : Naming_Data) return File_Name_Type
1325 Element_Id : Array_Element_Id;
1326 Element : Array_Element;
1327 Suffix : File_Name_Type := No_File;
1328 Lang : Language_Index;
1331 Element_Id := Naming.Spec_Suffix;
1332 while Element_Id /= No_Array_Element loop
1333 Element := In_Tree.Array_Elements.Table (Element_Id);
1335 if Element.Index = Language_Id then
1336 return File_Name_Type (Element.Value.Value);
1339 Element_Id := Element.Next;
1342 if Current_Mode = Multi_Language then
1343 Lang := In_Tree.First_Language;
1344 while Lang /= No_Language_Index loop
1345 if In_Tree.Languages_Data.Table (Lang).Name = Language_Id then
1347 In_Tree.Languages_Data.Table
1348 (Lang).Config.Naming_Data.Spec_Suffix;
1352 Lang := In_Tree.Languages_Data.Table (Lang).Next;
1357 end Spec_Suffix_Id_Of;
1359 --------------------
1360 -- Spec_Suffix_Of --
1361 --------------------
1363 function Spec_Suffix_Of
1364 (In_Tree : Project_Tree_Ref;
1366 Naming : Naming_Data) return String
1368 Language_Id : Name_Id;
1369 Element_Id : Array_Element_Id;
1370 Element : Array_Element;
1371 Suffix : File_Name_Type := No_File;
1372 Lang : Language_Index;
1376 Add_Str_To_Name_Buffer (Language);
1377 To_Lower (Name_Buffer (1 .. Name_Len));
1378 Language_Id := Name_Find;
1380 Element_Id := Naming.Spec_Suffix;
1381 while Element_Id /= No_Array_Element loop
1382 Element := In_Tree.Array_Elements.Table (Element_Id);
1384 if Element.Index = Language_Id then
1385 return Get_Name_String (Element.Value.Value);
1388 Element_Id := Element.Next;
1391 if Current_Mode = Multi_Language then
1392 Lang := In_Tree.First_Language;
1393 while Lang /= No_Language_Index loop
1394 if In_Tree.Languages_Data.Table (Lang).Name = Language_Id then
1397 (In_Tree.Languages_Data.Table
1398 (Lang).Config.Naming_Data.Spec_Suffix);
1402 Lang := In_Tree.Languages_Data.Table (Lang).Next;
1405 if Suffix /= No_File then
1406 return Get_Name_String (Suffix);
1413 --------------------------
1414 -- Standard_Naming_Data --
1415 --------------------------
1417 function Standard_Naming_Data
1418 (Tree : Project_Tree_Ref := No_Project_Tree) return Naming_Data
1421 if Tree = No_Project_Tree then
1422 Prj.Initialize (Tree => No_Project_Tree);
1423 return Std_Naming_Data;
1425 return Tree.Private_Part.Default_Naming;
1427 end Standard_Naming_Data;
1434 (Language : Language_Index;
1435 In_Project : Project_Data;
1436 In_Tree : Project_Tree_Ref) return File_Name_Type
1440 when No_Language_Index =>
1443 when First_Language_Indexes =>
1444 return In_Project.Naming.Impl_Suffixes (Language);
1449 Supp_Index : Supp_Language_Index;
1452 Supp_Index := In_Project.Naming.Supp_Suffixes;
1453 while Supp_Index /= No_Supp_Language_Index loop
1454 Supp := In_Tree.Supp_Suffixes.Table (Supp_Index);
1456 if Supp.Index = Language then
1460 Supp_Index := Supp.Next;
1472 function Switches_Name
1473 (Source_File_Name : File_Name_Type) return File_Name_Type
1476 return Extend_Name (Source_File_Name, Switches_Dependency_Suffix);
1479 ---------------------------
1480 -- There_Are_Ada_Sources --
1481 ---------------------------
1483 function There_Are_Ada_Sources
1484 (In_Tree : Project_Tree_Ref;
1485 Project : Project_Id) return Boolean
1491 while Prj /= No_Project loop
1492 if In_Tree.Projects.Table (Prj).Ada_Sources /= Nil_String then
1496 Prj := In_Tree.Projects.Table (Prj).Extends;
1500 end There_Are_Ada_Sources;
1506 function Value (Image : String) return Casing_Type is
1508 for Casing in The_Casing_Images'Range loop
1509 if To_Lower (Image) = To_Lower (The_Casing_Images (Casing).all) then
1514 raise Constraint_Error;
1518 -- Make sure that the standard config and user project file extensions are
1519 -- compatible with canonical case file naming.
1521 Canonical_Case_File_Name (Config_Project_File_Extension);
1522 Canonical_Case_File_Name (Project_File_Extension);