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,
99 Display_Path_Name => No_Path,
101 Location => No_Location,
103 Directory => No_Path,
104 Display_Directory => No_Path,
107 Library_Dir => No_Path,
108 Display_Library_Dir => No_Path,
109 Library_Src_Dir => No_Path,
110 Display_Library_Src_Dir => No_Path,
111 Library_ALI_Dir => No_Path,
112 Display_Library_ALI_Dir => No_Path,
113 Library_Name => No_Name,
114 Library_Kind => Static,
115 Lib_Internal_Name => No_Name,
116 Standalone_Library => False,
117 Lib_Interface_ALIs => Nil_String,
118 Lib_Auto_Init => False,
119 Libgnarl_Needed => Unknown,
120 Symbol_Data => No_Symbols,
121 Ada_Sources => Nil_String,
122 Sources => Nil_String,
123 First_Source => No_Source,
124 Last_Source => No_Source,
125 Unit_Based_Language_Name => No_Name,
126 Unit_Based_Language_Index => No_Language_Index,
127 Imported_Directories_Switches => null,
128 Include_Path => null,
129 Include_Data_Set => False,
130 Include_Language => No_Language_Index,
131 Source_Dirs => Nil_String,
132 Known_Order_Of_Source_Dirs => True,
133 Object_Directory => No_Path,
134 Display_Object_Dir => No_Path,
135 Library_TS => Empty_Time_Stamp,
136 Exec_Directory => No_Path,
137 Display_Exec_Dir => No_Path,
138 Extends => No_Project,
139 Extended_By => No_Project,
140 Naming => Std_Naming_Data,
141 First_Language_Processing => No_Language_Index,
142 Decl => No_Declarations,
143 Imported_Projects => Empty_Project_List,
144 All_Imported_Projects => Empty_Project_List,
145 Ada_Include_Path => null,
146 Ada_Objects_Path => null,
147 Objects_Path => null,
148 Include_Path_File => No_Path,
149 Objects_Path_File_With_Libs => No_Path,
150 Objects_Path_File_Without_Libs => No_Path,
151 Config_File_Name => No_Path,
152 Config_File_Temp => False,
153 Linker_Name => No_File,
154 Linker_Path => No_Path,
155 Minimum_Linker_Options => No_Name_List,
156 Config_Checked => False,
159 Need_To_Build_Lib => False,
161 Unkept_Comments => False,
162 Langs => No_Languages,
163 Supp_Languages => No_Supp_Language_Index,
164 Ada_Sources_Present => True,
165 Other_Sources_Present => True,
166 First_Other_Source => No_Other_Source,
167 Last_Other_Source => No_Other_Source,
168 First_Lang_Processing =>
169 Default_First_Language_Processing_Data,
170 Supp_Language_Processing =>
171 No_Supp_Language_Index);
173 package Temp_Files is new Table.Table
174 (Table_Component_Type => Path_Name_Type,
175 Table_Index_Type => Integer,
176 Table_Low_Bound => 1,
178 Table_Increment => 100,
179 Table_Name => "Makegpr.Temp_Files");
180 -- Table to store the path name of all the created temporary files, so that
181 -- they can be deleted at the end, or when the program is interrupted.
183 -----------------------
184 -- Add_Language_Name --
185 -----------------------
187 procedure Add_Language_Name (Name : Name_Id) is
189 Last_Language_Index := Last_Language_Index + 1;
190 Language_Indexes.Set (Name, Last_Language_Index);
191 Language_Names.Increment_Last;
192 Language_Names.Table (Last_Language_Index) := Name;
193 end Add_Language_Name;
199 procedure Add_To_Buffer
201 To : in out String_Access;
202 Last : in out Natural)
206 To := new String (1 .. Initial_Buffer_Size);
210 -- If Buffer is too small, double its size
212 while Last + S'Length > To'Last loop
214 New_Buffer : constant String_Access :=
215 new String (1 .. 2 * Last);
218 New_Buffer (1 .. Last) := To (1 .. Last);
224 To (Last + 1 .. Last + S'Length) := S;
225 Last := Last + S'Length;
228 -----------------------
229 -- Body_Suffix_Id_Of --
230 -----------------------
232 function Body_Suffix_Id_Of
233 (In_Tree : Project_Tree_Ref;
235 Naming : Naming_Data) return File_Name_Type
237 Language_Id : Name_Id;
241 Add_Str_To_Name_Buffer (Language);
242 To_Lower (Name_Buffer (1 .. Name_Len));
243 Language_Id := Name_Find;
248 Language_Id => Language_Id,
250 end Body_Suffix_Id_Of;
252 -----------------------
253 -- Body_Suffix_Id_Of --
254 -----------------------
256 function Body_Suffix_Id_Of
257 (In_Tree : Project_Tree_Ref;
258 Language_Id : Name_Id;
259 Naming : Naming_Data) return File_Name_Type
261 Element_Id : Array_Element_Id;
262 Element : Array_Element;
263 Suffix : File_Name_Type := No_File;
264 Lang : Language_Index;
267 -- ??? This seems to be only for Ada_Only mode...
268 Element_Id := Naming.Body_Suffix;
269 while Element_Id /= No_Array_Element loop
270 Element := In_Tree.Array_Elements.Table (Element_Id);
272 if Element.Index = Language_Id then
273 return File_Name_Type (Element.Value.Value);
276 Element_Id := Element.Next;
279 if Current_Mode = Multi_Language then
280 Lang := In_Tree.First_Language;
281 while Lang /= No_Language_Index loop
282 if In_Tree.Languages_Data.Table (Lang).Name = Language_Id then
284 In_Tree.Languages_Data.Table
285 (Lang).Config.Naming_Data.Body_Suffix;
289 Lang := In_Tree.Languages_Data.Table (Lang).Next;
294 end Body_Suffix_Id_Of;
300 function Body_Suffix_Of
301 (In_Tree : Project_Tree_Ref;
303 Naming : Naming_Data) return String
305 Language_Id : Name_Id;
306 Element_Id : Array_Element_Id;
307 Element : Array_Element;
308 Suffix : File_Name_Type := No_File;
309 Lang : Language_Index;
313 Add_Str_To_Name_Buffer (Language);
314 To_Lower (Name_Buffer (1 .. Name_Len));
315 Language_Id := Name_Find;
317 Element_Id := Naming.Body_Suffix;
318 while Element_Id /= No_Array_Element loop
319 Element := In_Tree.Array_Elements.Table (Element_Id);
321 if Element.Index = Language_Id then
322 return Get_Name_String (Element.Value.Value);
325 Element_Id := Element.Next;
328 if Current_Mode = Multi_Language then
329 Lang := In_Tree.First_Language;
330 while Lang /= No_Language_Index loop
331 if In_Tree.Languages_Data.Table (Lang).Name = Language_Id then
334 (In_Tree.Languages_Data.Table
335 (Lang).Config.Naming_Data.Body_Suffix);
339 Lang := In_Tree.Languages_Data.Table (Lang).Next;
342 if Suffix /= No_File then
343 return Get_Name_String (Suffix);
350 function Body_Suffix_Of
351 (Language : Language_Index;
352 In_Project : Project_Data;
353 In_Tree : Project_Tree_Ref) return String
355 Suffix_Id : constant File_Name_Type :=
356 Suffix_Of (Language, In_Project, In_Tree);
358 if Suffix_Id /= No_File then
359 return Get_Name_String (Suffix_Id);
361 return "." & Get_Name_String (Language_Names.Table (Language));
365 -----------------------------
366 -- Default_Ada_Body_Suffix --
367 -----------------------------
369 function Default_Ada_Body_Suffix return File_Name_Type is
371 return Default_Ada_Body_Suffix_Id;
372 end Default_Ada_Body_Suffix;
374 -----------------------------
375 -- Default_Ada_Spec_Suffix --
376 -----------------------------
378 function Default_Ada_Spec_Suffix return File_Name_Type is
380 return Default_Ada_Spec_Suffix_Id;
381 end Default_Ada_Spec_Suffix;
383 ---------------------------
384 -- Delete_All_Temp_Files --
385 ---------------------------
387 procedure Delete_All_Temp_Files is
389 pragma Warnings (Off, Dont_Care);
391 if not Debug.Debug_Flag_N then
392 for Index in 1 .. Temp_Files.Last loop
394 (Get_Name_String (Temp_Files.Table (Index)), Dont_Care);
397 end Delete_All_Temp_Files;
399 ---------------------
400 -- Dependency_Name --
401 ---------------------
403 function Dependency_Name
404 (Source_File_Name : File_Name_Type;
405 Dependency : Dependency_File_Kind) return File_Name_Type
416 (Source_File_Name, Makefile_Dependency_Suffix));
422 (Source_File_Name, ALI_Dependency_Suffix));
426 ---------------------------
427 -- Display_Language_Name --
428 ---------------------------
430 procedure Display_Language_Name
431 (In_Tree : Project_Tree_Ref;
432 Language : Language_Index)
435 Get_Name_String (In_Tree.Languages_Data.Table (Language).Display_Name);
436 Write_Str (Name_Buffer (1 .. Name_Len));
437 end Display_Language_Name;
439 ---------------------------
440 -- Display_Language_Name --
441 ---------------------------
443 procedure Display_Language_Name (Language : Language_Index) is
445 Get_Name_String (Language_Names.Table (Language));
446 To_Upper (Name_Buffer (1 .. 1));
447 Write_Str (Name_Buffer (1 .. Name_Len));
448 end Display_Language_Name;
454 function Empty_File return File_Name_Type is
456 return File_Name_Type (The_Empty_String);
463 function Empty_Project (Tree : Project_Tree_Ref) return Project_Data is
464 Value : Project_Data;
467 Prj.Initialize (Tree => No_Project_Tree);
468 Value := Project_Empty;
469 Value.Naming := Tree.Private_Part.Default_Naming;
478 function Empty_String return Name_Id is
480 return The_Empty_String;
487 procedure Expect (The_Token : Token_Type; Token_Image : String) is
489 if Token /= The_Token then
490 Error_Msg (Token_Image & " expected", Token_Ptr);
499 (File : File_Name_Type;
500 With_Suffix : String) return File_Name_Type
505 Get_Name_String (File);
506 Last := Name_Len + 1;
508 while Name_Len /= 0 and then Name_Buffer (Name_Len) /= '.' loop
509 Name_Len := Name_Len - 1;
512 if Name_Len <= 1 then
516 for J in With_Suffix'Range loop
517 Name_Buffer (Name_Len) := With_Suffix (J);
518 Name_Len := Name_Len + 1;
521 Name_Len := Name_Len - 1;
526 --------------------------------
527 -- For_Every_Project_Imported --
528 --------------------------------
530 procedure For_Every_Project_Imported
532 In_Tree : Project_Tree_Ref;
533 With_State : in out State)
536 procedure Recursive_Check (Project : Project_Id);
537 -- Check if a project has already been seen. If not seen, mark it as
538 -- Seen, Call Action, and check all its imported projects.
540 ---------------------
541 -- Recursive_Check --
542 ---------------------
544 procedure Recursive_Check (Project : Project_Id) is
547 if not In_Tree.Projects.Table (Project).Seen then
548 In_Tree.Projects.Table (Project).Seen := True;
549 Action (Project, With_State);
551 List := In_Tree.Projects.Table (Project).Imported_Projects;
552 while List /= Empty_Project_List loop
553 Recursive_Check (In_Tree.Project_Lists.Table (List).Project);
554 List := In_Tree.Project_Lists.Table (List).Next;
559 -- Start of processing for For_Every_Project_Imported
562 for Project in Project_Table.First ..
563 Project_Table.Last (In_Tree.Projects)
565 In_Tree.Projects.Table (Project).Seen := False;
568 Recursive_Check (Project => By);
569 end For_Every_Project_Imported;
575 function Get_Mode return Mode is
584 function Hash is new System.HTable.Hash (Header_Num => Header_Num);
585 -- Used in implementation of other functions Hash below
587 function Hash (Name : File_Name_Type) return Header_Num is
589 return Hash (Get_Name_String (Name));
592 function Hash (Name : Name_Id) return Header_Num is
594 return Hash (Get_Name_String (Name));
597 function Hash (Name : Path_Name_Type) return Header_Num is
599 return Hash (Get_Name_String (Name));
606 function Image (Casing : Casing_Type) return String is
608 return The_Casing_Images (Casing).all;
611 ----------------------
612 -- In_Configuration --
613 ----------------------
615 function In_Configuration return Boolean is
617 return Configuration_Mode;
618 end In_Configuration;
624 procedure Initialize (Tree : Project_Tree_Ref) is
626 if not Initialized then
630 The_Empty_String := Name_Find;
631 Empty_Name := The_Empty_String;
632 Empty_File_Name := File_Name_Type (The_Empty_String);
634 Name_Buffer (1 .. 4) := ".ads";
635 Default_Ada_Spec_Suffix_Id := Name_Find;
637 Name_Buffer (1 .. 4) := ".adb";
638 Default_Ada_Body_Suffix_Id := Name_Find;
640 Name_Buffer (1) := '/';
641 Slash_Id := Name_Find;
643 Name_Buffer (1 .. 3) := "c++";
644 Name_C_Plus_Plus := Name_Find;
648 Set_Name_Table_Byte (Name_Project, Token_Type'Pos (Tok_Project));
649 Set_Name_Table_Byte (Name_Extends, Token_Type'Pos (Tok_Extends));
650 Set_Name_Table_Byte (Name_External, Token_Type'Pos (Tok_External));
652 Language_Indexes.Reset;
653 Last_Language_Index := No_Language_Index;
655 Add_Language_Name (Name_Ada);
656 Add_Language_Name (Name_C);
657 Add_Language_Name (Name_C_Plus_Plus);
660 if Tree /= No_Project_Tree then
669 function Is_A_Language
670 (Tree : Project_Tree_Ref;
672 Language_Name : Name_Id) return Boolean
675 if Get_Mode = Ada_Only then
677 List : Name_List_Index := Data.Languages;
679 while List /= No_Name_List loop
680 if Tree.Name_Lists.Table (List).Name = Language_Name then
683 List := Tree.Name_Lists.Table (List).Next;
690 Lang_Ind : Language_Index := Data.First_Language_Processing;
691 Lang_Data : Language_Data;
694 while Lang_Ind /= No_Language_Index loop
695 Lang_Data := Tree.Languages_Data.Table (Lang_Ind);
697 if Lang_Data.Name = Language_Name then
701 Lang_Ind := Lang_Data.Next;
713 function Is_Extending
714 (Extending : Project_Id;
715 Extended : Project_Id;
716 In_Tree : Project_Tree_Ref) return Boolean
722 while Proj /= No_Project loop
723 if Proj = Extended then
727 Proj := In_Tree.Projects.Table (Proj).Extends;
738 (Language : Language_Index;
739 In_Project : Project_Data;
740 In_Tree : Project_Tree_Ref) return Boolean
744 when No_Language_Index =>
747 when First_Language_Indexes =>
748 return In_Project.Langs (Language);
752 Supp : Supp_Language;
753 Supp_Index : Supp_Language_Index;
756 Supp_Index := In_Project.Supp_Languages;
757 while Supp_Index /= No_Supp_Language_Index loop
758 Supp := In_Tree.Present_Languages.Table (Supp_Index);
760 if Supp.Index = Language then
764 Supp_Index := Supp.Next;
772 ---------------------------------
773 -- Language_Processing_Data_Of --
774 ---------------------------------
776 function Language_Processing_Data_Of
777 (Language : Language_Index;
778 In_Project : Project_Data;
779 In_Tree : Project_Tree_Ref) return Language_Processing_Data
783 when No_Language_Index =>
784 return Default_Language_Processing_Data;
786 when First_Language_Indexes =>
787 return In_Project.First_Lang_Processing (Language);
791 Supp : Supp_Language_Data;
792 Supp_Index : Supp_Language_Index;
795 Supp_Index := In_Project.Supp_Language_Processing;
796 while Supp_Index /= No_Supp_Language_Index loop
797 Supp := In_Tree.Supp_Languages.Table (Supp_Index);
799 if Supp.Index = Language then
803 Supp_Index := Supp.Next;
806 return Default_Language_Processing_Data;
809 end Language_Processing_Data_Of;
811 -----------------------
812 -- Objects_Exist_For --
813 -----------------------
815 function Objects_Exist_For
817 In_Tree : Project_Tree_Ref) return Boolean
819 Language_Id : Name_Id;
820 Lang : Language_Index;
823 if Current_Mode = Multi_Language then
825 Add_Str_To_Name_Buffer (Language);
826 To_Lower (Name_Buffer (1 .. Name_Len));
827 Language_Id := Name_Find;
829 Lang := In_Tree.First_Language;
830 while Lang /= No_Language_Index loop
831 if In_Tree.Languages_Data.Table (Lang).Name = Language_Id then
833 In_Tree.Languages_Data.Table
834 (Lang).Config.Objects_Generated;
837 Lang := In_Tree.Languages_Data.Table (Lang).Next;
842 end Objects_Exist_For;
849 (Source_File_Name : File_Name_Type)
850 return File_Name_Type
853 return Extend_Name (Source_File_Name, Object_Suffix);
856 ----------------------
857 -- Record_Temp_File --
858 ----------------------
860 procedure Record_Temp_File (Path : Path_Name_Type) is
862 Temp_Files.Increment_Last;
863 Temp_Files.Table (Temp_Files.Last) := Path;
864 end Record_Temp_File;
866 ------------------------------------
867 -- Register_Default_Naming_Scheme --
868 ------------------------------------
870 procedure Register_Default_Naming_Scheme
872 Default_Spec_Suffix : File_Name_Type;
873 Default_Body_Suffix : File_Name_Type;
874 In_Tree : Project_Tree_Ref)
877 Suffix : Array_Element_Id;
878 Found : Boolean := False;
879 Element : Array_Element;
882 -- Get the language name in small letters
884 Get_Name_String (Language);
885 Name_Buffer (1 .. Name_Len) := To_Lower (Name_Buffer (1 .. Name_Len));
888 -- Look for an element of the spec suffix array indexed by the language
889 -- name. If one is found, put the default value.
891 Suffix := In_Tree.Private_Part.Default_Naming.Spec_Suffix;
893 while Suffix /= No_Array_Element and then not Found loop
894 Element := In_Tree.Array_Elements.Table (Suffix);
896 if Element.Index = Lang then
898 Element.Value.Value := Name_Id (Default_Spec_Suffix);
899 In_Tree.Array_Elements.Table (Suffix) := Element;
902 Suffix := Element.Next;
906 -- If none can be found, create a new one
912 Index_Case_Sensitive => False,
913 Value => (Project => No_Project,
915 Location => No_Location,
917 Value => Name_Id (Default_Spec_Suffix),
919 Next => In_Tree.Private_Part.Default_Naming.Spec_Suffix);
920 Array_Element_Table.Increment_Last (In_Tree.Array_Elements);
921 In_Tree.Array_Elements.Table
922 (Array_Element_Table.Last (In_Tree.Array_Elements)) :=
924 In_Tree.Private_Part.Default_Naming.Spec_Suffix :=
925 Array_Element_Table.Last (In_Tree.Array_Elements);
928 -- Look for an element of the body suffix array indexed by the language
929 -- name. If one is found, put the default value.
931 Suffix := In_Tree.Private_Part.Default_Naming.Body_Suffix;
933 while Suffix /= No_Array_Element and then not Found loop
934 Element := In_Tree.Array_Elements.Table (Suffix);
936 if Element.Index = Lang then
938 Element.Value.Value := Name_Id (Default_Body_Suffix);
939 In_Tree.Array_Elements.Table (Suffix) := Element;
942 Suffix := Element.Next;
946 -- If none can be found, create a new one
952 Index_Case_Sensitive => False,
953 Value => (Project => No_Project,
955 Location => No_Location,
957 Value => Name_Id (Default_Body_Suffix),
959 Next => In_Tree.Private_Part.Default_Naming.Body_Suffix);
960 Array_Element_Table.Increment_Last
961 (In_Tree.Array_Elements);
962 In_Tree.Array_Elements.Table
963 (Array_Element_Table.Last (In_Tree.Array_Elements))
965 In_Tree.Private_Part.Default_Naming.Body_Suffix :=
966 Array_Element_Table.Last (In_Tree.Array_Elements);
968 end Register_Default_Naming_Scheme;
974 procedure Reset (Tree : Project_Tree_Ref) is
976 -- Def_Lang : constant Name_Node :=
977 -- (Name => Name_Ada,
978 -- Next => No_Name_List);
979 -- Why is the above commented out ???
986 Present_Language_Table.Init (Tree.Present_Languages);
987 Supp_Suffix_Table.Init (Tree.Supp_Suffixes);
988 Supp_Language_Table.Init (Tree.Supp_Languages);
989 Other_Source_Table.Init (Tree.Other_Sources);
993 Language_Data_Table.Init (Tree.Languages_Data);
994 Name_List_Table.Init (Tree.Name_Lists);
995 String_Element_Table.Init (Tree.String_Elements);
996 Variable_Element_Table.Init (Tree.Variable_Elements);
997 Array_Element_Table.Init (Tree.Array_Elements);
998 Array_Table.Init (Tree.Arrays);
999 Package_Table.Init (Tree.Packages);
1000 Project_List_Table.Init (Tree.Project_Lists);
1001 Project_Table.Init (Tree.Projects);
1002 Source_Data_Table.Init (Tree.Sources);
1003 Alternate_Language_Table.Init (Tree.Alt_Langs);
1004 Unit_Table.Init (Tree.Units);
1005 Units_Htable.Reset (Tree.Units_HT);
1006 Files_Htable.Reset (Tree.Files_HT);
1007 Source_Paths_Htable.Reset (Tree.Source_Paths_HT);
1009 -- Private part table
1011 Naming_Table.Init (Tree.Private_Part.Namings);
1012 Naming_Table.Increment_Last (Tree.Private_Part.Namings);
1013 Tree.Private_Part.Namings.Table
1014 (Naming_Table.Last (Tree.Private_Part.Namings)) := Std_Naming_Data;
1015 Path_File_Table.Init (Tree.Private_Part.Path_Files);
1016 Source_Path_Table.Init (Tree.Private_Part.Source_Paths);
1017 Object_Path_Table.Init (Tree.Private_Part.Object_Paths);
1018 Tree.Private_Part.Default_Naming := Std_Naming_Data;
1020 if Current_Mode = Ada_Only then
1021 Register_Default_Naming_Scheme
1022 (Language => Name_Ada,
1023 Default_Spec_Suffix => Default_Ada_Spec_Suffix,
1024 Default_Body_Suffix => Default_Ada_Body_Suffix,
1026 Tree.Private_Part.Default_Naming.Separate_Suffix :=
1027 Default_Ada_Body_Suffix;
1031 ------------------------
1032 -- Same_Naming_Scheme --
1033 ------------------------
1035 function Same_Naming_Scheme
1036 (Left, Right : Naming_Data) return Boolean
1039 return Left.Dot_Replacement = Right.Dot_Replacement
1040 and then Left.Casing = Right.Casing
1041 and then Left.Separate_Suffix = Right.Separate_Suffix;
1042 end Same_Naming_Scheme;
1049 (Language : Language_Index;
1051 In_Project : in out Project_Data;
1052 In_Tree : Project_Tree_Ref)
1056 when No_Language_Index =>
1059 when First_Language_Indexes =>
1060 In_Project.Langs (Language) := Present;
1064 Supp : Supp_Language;
1065 Supp_Index : Supp_Language_Index;
1068 Supp_Index := In_Project.Supp_Languages;
1069 while Supp_Index /= No_Supp_Language_Index loop
1070 Supp := In_Tree.Present_Languages.Table (Supp_Index);
1072 if Supp.Index = Language then
1073 In_Tree.Present_Languages.Table (Supp_Index).Present :=
1078 Supp_Index := Supp.Next;
1081 Supp := (Index => Language, Present => Present,
1082 Next => In_Project.Supp_Languages);
1083 Present_Language_Table.Increment_Last
1084 (In_Tree.Present_Languages);
1086 Present_Language_Table.Last (In_Tree.Present_Languages);
1087 In_Tree.Present_Languages.Table (Supp_Index) :=
1089 In_Project.Supp_Languages := Supp_Index;
1095 (Language_Processing : Language_Processing_Data;
1096 For_Language : Language_Index;
1097 In_Project : in out Project_Data;
1098 In_Tree : Project_Tree_Ref)
1101 case For_Language is
1102 when No_Language_Index =>
1105 when First_Language_Indexes =>
1106 In_Project.First_Lang_Processing (For_Language) :=
1107 Language_Processing;
1111 Supp : Supp_Language_Data;
1112 Supp_Index : Supp_Language_Index;
1115 Supp_Index := In_Project.Supp_Language_Processing;
1116 while Supp_Index /= No_Supp_Language_Index loop
1117 Supp := In_Tree.Supp_Languages.Table (Supp_Index);
1119 if Supp.Index = For_Language then
1120 In_Tree.Supp_Languages.Table
1121 (Supp_Index).Data := Language_Processing;
1125 Supp_Index := Supp.Next;
1128 Supp := (Index => For_Language, Data => Language_Processing,
1129 Next => In_Project.Supp_Language_Processing);
1130 Supp_Language_Table.Increment_Last
1131 (In_Tree.Supp_Languages);
1132 Supp_Index := Supp_Language_Table.Last
1133 (In_Tree.Supp_Languages);
1134 In_Tree.Supp_Languages.Table (Supp_Index) := Supp;
1135 In_Project.Supp_Language_Processing := Supp_Index;
1141 (Suffix : File_Name_Type;
1142 For_Language : Language_Index;
1143 In_Project : in out Project_Data;
1144 In_Tree : Project_Tree_Ref)
1147 case For_Language is
1148 when No_Language_Index =>
1151 when First_Language_Indexes =>
1152 In_Project.Naming.Impl_Suffixes (For_Language) := Suffix;
1157 Supp_Index : Supp_Language_Index;
1160 Supp_Index := In_Project.Naming.Supp_Suffixes;
1161 while Supp_Index /= No_Supp_Language_Index loop
1162 Supp := In_Tree.Supp_Suffixes.Table (Supp_Index);
1164 if Supp.Index = For_Language then
1165 In_Tree.Supp_Suffixes.Table (Supp_Index).Suffix := Suffix;
1169 Supp_Index := Supp.Next;
1172 Supp := (Index => For_Language, Suffix => Suffix,
1173 Next => In_Project.Naming.Supp_Suffixes);
1174 Supp_Suffix_Table.Increment_Last (In_Tree.Supp_Suffixes);
1175 Supp_Index := Supp_Suffix_Table.Last (In_Tree.Supp_Suffixes);
1176 In_Tree.Supp_Suffixes.Table (Supp_Index) := Supp;
1177 In_Project.Naming.Supp_Suffixes := Supp_Index;
1182 ---------------------
1183 -- Set_Body_Suffix --
1184 ---------------------
1186 procedure Set_Body_Suffix
1187 (In_Tree : Project_Tree_Ref;
1189 Naming : in out Naming_Data;
1190 Suffix : File_Name_Type)
1192 Language_Id : Name_Id;
1193 Element : Array_Element;
1197 Add_Str_To_Name_Buffer (Language);
1198 To_Lower (Name_Buffer (1 .. Name_Len));
1199 Language_Id := Name_Find;
1202 (Index => Language_Id,
1204 Index_Case_Sensitive => False,
1207 Project => No_Project,
1208 Location => No_Location,
1210 Value => Name_Id (Suffix),
1212 Next => Naming.Body_Suffix);
1214 Array_Element_Table.Increment_Last (In_Tree.Array_Elements);
1215 Naming.Body_Suffix :=
1216 Array_Element_Table.Last (In_Tree.Array_Elements);
1217 In_Tree.Array_Elements.Table (Naming.Body_Suffix) := Element;
1218 end Set_Body_Suffix;
1220 --------------------------
1221 -- Set_In_Configuration --
1222 --------------------------
1224 procedure Set_In_Configuration (Value : Boolean) is
1226 Configuration_Mode := Value;
1227 end Set_In_Configuration;
1233 procedure Set_Mode (New_Mode : Mode) is
1235 Current_Mode := New_Mode;
1238 Default_Language_Is_Ada := True;
1239 Must_Check_Configuration := False;
1240 when Multi_Language =>
1241 Default_Language_Is_Ada := False;
1242 Must_Check_Configuration := True;
1246 ---------------------
1247 -- Set_Spec_Suffix --
1248 ---------------------
1250 procedure Set_Spec_Suffix
1251 (In_Tree : Project_Tree_Ref;
1253 Naming : in out Naming_Data;
1254 Suffix : File_Name_Type)
1256 Language_Id : Name_Id;
1257 Element : Array_Element;
1261 Add_Str_To_Name_Buffer (Language);
1262 To_Lower (Name_Buffer (1 .. Name_Len));
1263 Language_Id := Name_Find;
1266 (Index => Language_Id,
1268 Index_Case_Sensitive => False,
1271 Project => No_Project,
1272 Location => No_Location,
1274 Value => Name_Id (Suffix),
1276 Next => Naming.Spec_Suffix);
1278 Array_Element_Table.Increment_Last (In_Tree.Array_Elements);
1279 Naming.Spec_Suffix :=
1280 Array_Element_Table.Last (In_Tree.Array_Elements);
1281 In_Tree.Array_Elements.Table (Naming.Spec_Suffix) := Element;
1282 end Set_Spec_Suffix;
1288 function Slash return Path_Name_Type is
1293 -----------------------
1294 -- Spec_Suffix_Id_Of --
1295 -----------------------
1297 function Spec_Suffix_Id_Of
1298 (In_Tree : Project_Tree_Ref;
1300 Naming : Naming_Data) return File_Name_Type
1302 Language_Id : Name_Id;
1306 Add_Str_To_Name_Buffer (Language);
1307 To_Lower (Name_Buffer (1 .. Name_Len));
1308 Language_Id := Name_Find;
1312 (In_Tree => In_Tree,
1313 Language_Id => Language_Id,
1315 end Spec_Suffix_Id_Of;
1317 -----------------------
1318 -- Spec_Suffix_Id_Of --
1319 -----------------------
1321 function Spec_Suffix_Id_Of
1322 (In_Tree : Project_Tree_Ref;
1323 Language_Id : Name_Id;
1324 Naming : Naming_Data) return File_Name_Type
1326 Element_Id : Array_Element_Id;
1327 Element : Array_Element;
1328 Suffix : File_Name_Type := No_File;
1329 Lang : Language_Index;
1332 Element_Id := Naming.Spec_Suffix;
1333 while Element_Id /= No_Array_Element loop
1334 Element := In_Tree.Array_Elements.Table (Element_Id);
1336 if Element.Index = Language_Id then
1337 return File_Name_Type (Element.Value.Value);
1340 Element_Id := Element.Next;
1343 if Current_Mode = Multi_Language then
1344 Lang := In_Tree.First_Language;
1345 while Lang /= No_Language_Index loop
1346 if In_Tree.Languages_Data.Table (Lang).Name = Language_Id then
1348 In_Tree.Languages_Data.Table
1349 (Lang).Config.Naming_Data.Spec_Suffix;
1353 Lang := In_Tree.Languages_Data.Table (Lang).Next;
1358 end Spec_Suffix_Id_Of;
1360 --------------------
1361 -- Spec_Suffix_Of --
1362 --------------------
1364 function Spec_Suffix_Of
1365 (In_Tree : Project_Tree_Ref;
1367 Naming : Naming_Data) return String
1369 Language_Id : Name_Id;
1370 Element_Id : Array_Element_Id;
1371 Element : Array_Element;
1372 Suffix : File_Name_Type := No_File;
1373 Lang : Language_Index;
1377 Add_Str_To_Name_Buffer (Language);
1378 To_Lower (Name_Buffer (1 .. Name_Len));
1379 Language_Id := Name_Find;
1381 Element_Id := Naming.Spec_Suffix;
1382 while Element_Id /= No_Array_Element loop
1383 Element := In_Tree.Array_Elements.Table (Element_Id);
1385 if Element.Index = Language_Id then
1386 return Get_Name_String (Element.Value.Value);
1389 Element_Id := Element.Next;
1392 if Current_Mode = Multi_Language then
1393 Lang := In_Tree.First_Language;
1394 while Lang /= No_Language_Index loop
1395 if In_Tree.Languages_Data.Table (Lang).Name = Language_Id then
1398 (In_Tree.Languages_Data.Table
1399 (Lang).Config.Naming_Data.Spec_Suffix);
1403 Lang := In_Tree.Languages_Data.Table (Lang).Next;
1406 if Suffix /= No_File then
1407 return Get_Name_String (Suffix);
1414 --------------------------
1415 -- Standard_Naming_Data --
1416 --------------------------
1418 function Standard_Naming_Data
1419 (Tree : Project_Tree_Ref := No_Project_Tree) return Naming_Data
1422 if Tree = No_Project_Tree then
1423 Prj.Initialize (Tree => No_Project_Tree);
1424 return Std_Naming_Data;
1426 return Tree.Private_Part.Default_Naming;
1428 end Standard_Naming_Data;
1435 (Language : Language_Index;
1436 In_Project : Project_Data;
1437 In_Tree : Project_Tree_Ref) return File_Name_Type
1441 when No_Language_Index =>
1444 when First_Language_Indexes =>
1445 return In_Project.Naming.Impl_Suffixes (Language);
1450 Supp_Index : Supp_Language_Index;
1453 Supp_Index := In_Project.Naming.Supp_Suffixes;
1454 while Supp_Index /= No_Supp_Language_Index loop
1455 Supp := In_Tree.Supp_Suffixes.Table (Supp_Index);
1457 if Supp.Index = Language then
1461 Supp_Index := Supp.Next;
1473 function Switches_Name
1474 (Source_File_Name : File_Name_Type) return File_Name_Type
1477 return Extend_Name (Source_File_Name, Switches_Dependency_Suffix);
1480 ---------------------------
1481 -- There_Are_Ada_Sources --
1482 ---------------------------
1484 function There_Are_Ada_Sources
1485 (In_Tree : Project_Tree_Ref;
1486 Project : Project_Id) return Boolean
1492 while Prj /= No_Project loop
1493 if In_Tree.Projects.Table (Prj).Ada_Sources /= Nil_String then
1497 Prj := In_Tree.Projects.Table (Prj).Extends;
1501 end There_Are_Ada_Sources;
1507 function Value (Image : String) return Casing_Type is
1509 for Casing in The_Casing_Images'Range loop
1510 if To_Lower (Image) = To_Lower (The_Casing_Images (Casing).all) then
1515 raise Constraint_Error;
1519 -- Make sure that the standard config and user project file extensions are
1520 -- compatible with canonical case file naming.
1522 Canonical_Case_File_Name (Config_Project_File_Extension);
1523 Canonical_Case_File_Name (Project_File_Extension);