2008-07-31 Vincent Celier <celier@adacore.com>
[gcc.git] / gcc / ada / prj.adb
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- P R J --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 2001-2008, Free Software Foundation, Inc. --
10 -- --
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. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
25
26 with Ada.Characters.Handling; use Ada.Characters.Handling;
27
28 with Debug;
29 with Output; use Output;
30 with Osint; use Osint;
31 with Prj.Attr;
32 with Prj.Env;
33 with Prj.Err; use Prj.Err;
34 with Snames; use Snames;
35 with Table;
36 with Uintp; use Uintp;
37
38 with System.Case_Util; use System.Case_Util;
39 with System.HTable;
40
41 package body Prj is
42
43 Object_Suffix : constant String := Get_Target_Object_Suffix.all;
44 -- File suffix for object files
45
46 Initial_Buffer_Size : constant := 100;
47 -- Initial size for extensible buffer used in Add_To_Buffer
48
49 Current_Mode : Mode := Ada_Only;
50
51 Configuration_Mode : Boolean := False;
52
53 The_Empty_String : Name_Id;
54
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
59
60 subtype Known_Casing is Casing_Type range All_Upper_Case .. Mixed_Case;
61
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"));
66
67 Initialized : Boolean := False;
68
69 Standard_Dot_Replacement : constant File_Name_Type :=
70 File_Name_Type
71 (First_Name_Id + Character'Pos ('-'));
72
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
88 Project_Empty : constant Project_Data :=
89 (Qualifier => Unspecified,
90 Externally_Built => False,
91 Config => Default_Project_Config,
92 Languages => No_Name_List,
93 First_Referred_By => No_Project,
94 Name => No_Name,
95 Display_Name => No_Name,
96 Path => No_Path_Information,
97 Virtual => False,
98 Location => No_Location,
99 Mains => Nil_String,
100 Directory => No_Path_Information,
101 Dir_Path => null,
102 Library => False,
103 Library_Dir => No_Path_Information,
104 Library_Src_Dir => No_Path_Information,
105 Library_ALI_Dir => No_Path_Information,
106 Library_Name => No_Name,
107 Library_Kind => Static,
108 Lib_Internal_Name => No_Name,
109 Standalone_Library => False,
110 Lib_Interface_ALIs => Nil_String,
111 Lib_Auto_Init => False,
112 Libgnarl_Needed => Unknown,
113 Symbol_Data => No_Symbols,
114 Ada_Sources_Present => True,
115 Other_Sources_Present => True,
116 Ada_Sources => Nil_String,
117 First_Source => No_Source,
118 Last_Source => No_Source,
119 Interfaces_Defined => False,
120 Unit_Based_Language_Name => No_Name,
121 Unit_Based_Language_Index => No_Language_Index,
122 Imported_Directories_Switches => null,
123 Include_Path => null,
124 Include_Data_Set => False,
125 Include_Language => No_Language_Index,
126 Source_Dirs => Nil_String,
127 Known_Order_Of_Source_Dirs => True,
128 Object_Directory => No_Path_Information,
129 Library_TS => Empty_Time_Stamp,
130 Exec_Directory => No_Path_Information,
131 Extends => No_Project,
132 Extended_By => No_Project,
133 Naming => Std_Naming_Data,
134 First_Language_Processing => No_Language_Index,
135 Decl => No_Declarations,
136 Imported_Projects => Empty_Project_List,
137 All_Imported_Projects => Empty_Project_List,
138 Ada_Include_Path => null,
139 Ada_Objects_Path => null,
140 Objects_Path => null,
141 Include_Path_File => No_Path,
142 Objects_Path_File_With_Libs => No_Path,
143 Objects_Path_File_Without_Libs => No_Path,
144 Config_File_Name => No_Path,
145 Config_File_Temp => False,
146 Linker_Name => No_File,
147 Linker_Path => No_Path,
148 Minimum_Linker_Options => No_Name_List,
149 Config_Checked => False,
150 Checked => False,
151 Seen => False,
152 Need_To_Build_Lib => False,
153 Depth => 0,
154 Unkept_Comments => False);
155
156 package Temp_Files is new Table.Table
157 (Table_Component_Type => Path_Name_Type,
158 Table_Index_Type => Integer,
159 Table_Low_Bound => 1,
160 Table_Initial => 20,
161 Table_Increment => 100,
162 Table_Name => "Makegpr.Temp_Files");
163 -- Table to store the path name of all the created temporary files, so that
164 -- they can be deleted at the end, or when the program is interrupted.
165
166 -------------------
167 -- Add_To_Buffer --
168 -------------------
169
170 procedure Add_To_Buffer
171 (S : String;
172 To : in out String_Access;
173 Last : in out Natural)
174 is
175 begin
176 if To = null then
177 To := new String (1 .. Initial_Buffer_Size);
178 Last := 0;
179 end if;
180
181 -- If Buffer is too small, double its size
182
183 while Last + S'Length > To'Last loop
184 declare
185 New_Buffer : constant String_Access :=
186 new String (1 .. 2 * Last);
187
188 begin
189 New_Buffer (1 .. Last) := To (1 .. Last);
190 Free (To);
191 To := New_Buffer;
192 end;
193 end loop;
194
195 To (Last + 1 .. Last + S'Length) := S;
196 Last := Last + S'Length;
197 end Add_To_Buffer;
198
199 -----------------------
200 -- Body_Suffix_Id_Of --
201 -----------------------
202
203 function Body_Suffix_Id_Of
204 (In_Tree : Project_Tree_Ref;
205 Language : String;
206 Naming : Naming_Data) return File_Name_Type
207 is
208 Language_Id : Name_Id;
209
210 begin
211 Name_Len := 0;
212 Add_Str_To_Name_Buffer (Language);
213 To_Lower (Name_Buffer (1 .. Name_Len));
214 Language_Id := Name_Find;
215
216 return
217 Body_Suffix_Id_Of
218 (In_Tree => In_Tree,
219 Language_Id => Language_Id,
220 Naming => Naming);
221 end Body_Suffix_Id_Of;
222
223 -----------------------
224 -- Body_Suffix_Id_Of --
225 -----------------------
226
227 function Body_Suffix_Id_Of
228 (In_Tree : Project_Tree_Ref;
229 Language_Id : Name_Id;
230 Naming : Naming_Data) return File_Name_Type
231 is
232 Element_Id : Array_Element_Id;
233 Element : Array_Element;
234 Suffix : File_Name_Type := No_File;
235 Lang : Language_Index;
236
237 begin
238 -- ??? This seems to be only for Ada_Only mode...
239 Element_Id := Naming.Body_Suffix;
240 while Element_Id /= No_Array_Element loop
241 Element := In_Tree.Array_Elements.Table (Element_Id);
242
243 if Element.Index = Language_Id then
244 return File_Name_Type (Element.Value.Value);
245 end if;
246
247 Element_Id := Element.Next;
248 end loop;
249
250 if Current_Mode = Multi_Language then
251 Lang := In_Tree.First_Language;
252 while Lang /= No_Language_Index loop
253 if In_Tree.Languages_Data.Table (Lang).Name = Language_Id then
254 Suffix :=
255 In_Tree.Languages_Data.Table
256 (Lang).Config.Naming_Data.Body_Suffix;
257 exit;
258 end if;
259
260 Lang := In_Tree.Languages_Data.Table (Lang).Next;
261 end loop;
262 end if;
263
264 return Suffix;
265 end Body_Suffix_Id_Of;
266
267 --------------------
268 -- Body_Suffix_Of --
269 --------------------
270
271 function Body_Suffix_Of
272 (In_Tree : Project_Tree_Ref;
273 Language : String;
274 Naming : Naming_Data) return String
275 is
276 Language_Id : Name_Id;
277 Element_Id : Array_Element_Id;
278 Element : Array_Element;
279 Suffix : File_Name_Type := No_File;
280 Lang : Language_Index;
281
282 begin
283 Name_Len := 0;
284 Add_Str_To_Name_Buffer (Language);
285 To_Lower (Name_Buffer (1 .. Name_Len));
286 Language_Id := Name_Find;
287
288 Element_Id := Naming.Body_Suffix;
289 while Element_Id /= No_Array_Element loop
290 Element := In_Tree.Array_Elements.Table (Element_Id);
291
292 if Element.Index = Language_Id then
293 return Get_Name_String (Element.Value.Value);
294 end if;
295
296 Element_Id := Element.Next;
297 end loop;
298
299 if Current_Mode = Multi_Language then
300 Lang := In_Tree.First_Language;
301 while Lang /= No_Language_Index loop
302 if In_Tree.Languages_Data.Table (Lang).Name = Language_Id then
303 Suffix :=
304 File_Name_Type
305 (In_Tree.Languages_Data.Table
306 (Lang).Config.Naming_Data.Body_Suffix);
307 exit;
308 end if;
309
310 Lang := In_Tree.Languages_Data.Table (Lang).Next;
311 end loop;
312
313 if Suffix /= No_File then
314 return Get_Name_String (Suffix);
315 end if;
316 end if;
317
318 return "";
319 end Body_Suffix_Of;
320
321 -----------------------------
322 -- Default_Ada_Body_Suffix --
323 -----------------------------
324
325 function Default_Ada_Body_Suffix return File_Name_Type is
326 begin
327 return Default_Ada_Body_Suffix_Id;
328 end Default_Ada_Body_Suffix;
329
330 -----------------------------
331 -- Default_Ada_Spec_Suffix --
332 -----------------------------
333
334 function Default_Ada_Spec_Suffix return File_Name_Type is
335 begin
336 return Default_Ada_Spec_Suffix_Id;
337 end Default_Ada_Spec_Suffix;
338
339 ---------------------------
340 -- Delete_All_Temp_Files --
341 ---------------------------
342
343 procedure Delete_All_Temp_Files is
344 Dont_Care : Boolean;
345 pragma Warnings (Off, Dont_Care);
346 begin
347 if not Debug.Debug_Flag_N then
348 for Index in 1 .. Temp_Files.Last loop
349 Delete_File
350 (Get_Name_String (Temp_Files.Table (Index)), Dont_Care);
351 end loop;
352 end if;
353 end Delete_All_Temp_Files;
354
355 ---------------------
356 -- Dependency_Name --
357 ---------------------
358
359 function Dependency_Name
360 (Source_File_Name : File_Name_Type;
361 Dependency : Dependency_File_Kind) return File_Name_Type
362 is
363 begin
364 case Dependency is
365 when None =>
366 return No_File;
367
368 when Makefile =>
369 return
370 File_Name_Type
371 (Extend_Name
372 (Source_File_Name, Makefile_Dependency_Suffix));
373
374 when ALI_File =>
375 return
376 File_Name_Type
377 (Extend_Name
378 (Source_File_Name, ALI_Dependency_Suffix));
379 end case;
380 end Dependency_Name;
381
382 ---------------------------
383 -- Display_Language_Name --
384 ---------------------------
385
386 procedure Display_Language_Name
387 (In_Tree : Project_Tree_Ref;
388 Language : Language_Index)
389 is
390 begin
391 Get_Name_String (In_Tree.Languages_Data.Table (Language).Display_Name);
392 Write_Str (Name_Buffer (1 .. Name_Len));
393 end Display_Language_Name;
394
395 ----------------
396 -- Empty_File --
397 ----------------
398
399 function Empty_File return File_Name_Type is
400 begin
401 return File_Name_Type (The_Empty_String);
402 end Empty_File;
403
404 -------------------
405 -- Empty_Project --
406 -------------------
407
408 function Empty_Project (Tree : Project_Tree_Ref) return Project_Data is
409 Value : Project_Data;
410
411 begin
412 Prj.Initialize (Tree => No_Project_Tree);
413 Value := Project_Empty;
414 Value.Naming := Tree.Private_Part.Default_Naming;
415
416 return Value;
417 end Empty_Project;
418
419 ------------------
420 -- Empty_String --
421 ------------------
422
423 function Empty_String return Name_Id is
424 begin
425 return The_Empty_String;
426 end Empty_String;
427
428 ------------
429 -- Expect --
430 ------------
431
432 procedure Expect (The_Token : Token_Type; Token_Image : String) is
433 begin
434 if Token /= The_Token then
435 Error_Msg (Token_Image & " expected", Token_Ptr);
436 end if;
437 end Expect;
438
439 -----------------
440 -- Extend_Name --
441 -----------------
442
443 function Extend_Name
444 (File : File_Name_Type;
445 With_Suffix : String) return File_Name_Type
446 is
447 Last : Positive;
448
449 begin
450 Get_Name_String (File);
451 Last := Name_Len + 1;
452
453 while Name_Len /= 0 and then Name_Buffer (Name_Len) /= '.' loop
454 Name_Len := Name_Len - 1;
455 end loop;
456
457 if Name_Len <= 1 then
458 Name_Len := Last;
459 end if;
460
461 for J in With_Suffix'Range loop
462 Name_Buffer (Name_Len) := With_Suffix (J);
463 Name_Len := Name_Len + 1;
464 end loop;
465
466 Name_Len := Name_Len - 1;
467 return Name_Find;
468
469 end Extend_Name;
470
471 --------------------------------
472 -- For_Every_Project_Imported --
473 --------------------------------
474
475 procedure For_Every_Project_Imported
476 (By : Project_Id;
477 In_Tree : Project_Tree_Ref;
478 With_State : in out State)
479 is
480
481 procedure Recursive_Check (Project : Project_Id);
482 -- Check if a project has already been seen. If not seen, mark it as
483 -- Seen, Call Action, and check all its imported projects.
484
485 ---------------------
486 -- Recursive_Check --
487 ---------------------
488
489 procedure Recursive_Check (Project : Project_Id) is
490 List : Project_List;
491 begin
492 if not In_Tree.Projects.Table (Project).Seen then
493 In_Tree.Projects.Table (Project).Seen := True;
494 Action (Project, With_State);
495
496 List := In_Tree.Projects.Table (Project).Imported_Projects;
497 while List /= Empty_Project_List loop
498 Recursive_Check (In_Tree.Project_Lists.Table (List).Project);
499 List := In_Tree.Project_Lists.Table (List).Next;
500 end loop;
501 end if;
502 end Recursive_Check;
503
504 -- Start of processing for For_Every_Project_Imported
505
506 begin
507 for Project in Project_Table.First ..
508 Project_Table.Last (In_Tree.Projects)
509 loop
510 In_Tree.Projects.Table (Project).Seen := False;
511 end loop;
512
513 Recursive_Check (Project => By);
514 end For_Every_Project_Imported;
515
516 --------------
517 -- Get_Mode --
518 --------------
519
520 function Get_Mode return Mode is
521 begin
522 return Current_Mode;
523 end Get_Mode;
524
525 ----------
526 -- Hash --
527 ----------
528
529 function Hash is new System.HTable.Hash (Header_Num => Header_Num);
530 -- Used in implementation of other functions Hash below
531
532 function Hash (Name : File_Name_Type) return Header_Num is
533 begin
534 return Hash (Get_Name_String (Name));
535 end Hash;
536
537 function Hash (Name : Name_Id) return Header_Num is
538 begin
539 return Hash (Get_Name_String (Name));
540 end Hash;
541
542 function Hash (Name : Path_Name_Type) return Header_Num is
543 begin
544 return Hash (Get_Name_String (Name));
545 end Hash;
546
547 function Hash (Project : Project_Id) return Header_Num is
548 begin
549 return Header_Num (Project mod Max_Header_Num);
550 end Hash;
551
552 -----------
553 -- Image --
554 -----------
555
556 function Image (Casing : Casing_Type) return String is
557 begin
558 return The_Casing_Images (Casing).all;
559 end Image;
560
561 ----------------------
562 -- In_Configuration --
563 ----------------------
564
565 function In_Configuration return Boolean is
566 begin
567 return Configuration_Mode;
568 end In_Configuration;
569
570 ----------------
571 -- Initialize --
572 ----------------
573
574 procedure Initialize (Tree : Project_Tree_Ref) is
575 begin
576 if not Initialized then
577 Initialized := True;
578 Uintp.Initialize;
579 Name_Len := 0;
580 The_Empty_String := Name_Find;
581 Empty_Name := The_Empty_String;
582 Empty_File_Name := File_Name_Type (The_Empty_String);
583 Name_Len := 4;
584 Name_Buffer (1 .. 4) := ".ads";
585 Default_Ada_Spec_Suffix_Id := Name_Find;
586 Name_Len := 4;
587 Name_Buffer (1 .. 4) := ".adb";
588 Default_Ada_Body_Suffix_Id := Name_Find;
589 Name_Len := 1;
590 Name_Buffer (1) := '/';
591 Slash_Id := Name_Find;
592
593 Prj.Env.Initialize;
594 Prj.Attr.Initialize;
595 Set_Name_Table_Byte (Name_Project, Token_Type'Pos (Tok_Project));
596 Set_Name_Table_Byte (Name_Extends, Token_Type'Pos (Tok_Extends));
597 Set_Name_Table_Byte (Name_External, Token_Type'Pos (Tok_External));
598 end if;
599
600 if Tree /= No_Project_Tree then
601 Reset (Tree);
602 end if;
603 end Initialize;
604
605 -------------------
606 -- Is_A_Language --
607 -------------------
608
609 function Is_A_Language
610 (Tree : Project_Tree_Ref;
611 Data : Project_Data;
612 Language_Name : Name_Id) return Boolean
613 is
614 begin
615 if Get_Mode = Ada_Only then
616 declare
617 List : Name_List_Index := Data.Languages;
618 begin
619 while List /= No_Name_List loop
620 if Tree.Name_Lists.Table (List).Name = Language_Name then
621 return True;
622 else
623 List := Tree.Name_Lists.Table (List).Next;
624 end if;
625 end loop;
626 end;
627
628 else
629 declare
630 Lang_Ind : Language_Index := Data.First_Language_Processing;
631 Lang_Data : Language_Data;
632
633 begin
634 while Lang_Ind /= No_Language_Index loop
635 Lang_Data := Tree.Languages_Data.Table (Lang_Ind);
636
637 if Lang_Data.Name = Language_Name then
638 return True;
639 end if;
640
641 Lang_Ind := Lang_Data.Next;
642 end loop;
643 end;
644 end if;
645
646 return False;
647 end Is_A_Language;
648
649 ------------------
650 -- Is_Extending --
651 ------------------
652
653 function Is_Extending
654 (Extending : Project_Id;
655 Extended : Project_Id;
656 In_Tree : Project_Tree_Ref) return Boolean
657 is
658 Proj : Project_Id;
659
660 begin
661 Proj := Extending;
662 while Proj /= No_Project loop
663 if Proj = Extended then
664 return True;
665 end if;
666
667 Proj := In_Tree.Projects.Table (Proj).Extends;
668 end loop;
669
670 return False;
671 end Is_Extending;
672
673 -----------------------
674 -- Objects_Exist_For --
675 -----------------------
676
677 function Objects_Exist_For
678 (Language : String;
679 In_Tree : Project_Tree_Ref) return Boolean
680 is
681 Language_Id : Name_Id;
682 Lang : Language_Index;
683
684 begin
685 if Current_Mode = Multi_Language then
686 Name_Len := 0;
687 Add_Str_To_Name_Buffer (Language);
688 To_Lower (Name_Buffer (1 .. Name_Len));
689 Language_Id := Name_Find;
690
691 Lang := In_Tree.First_Language;
692 while Lang /= No_Language_Index loop
693 if In_Tree.Languages_Data.Table (Lang).Name = Language_Id then
694 return
695 In_Tree.Languages_Data.Table
696 (Lang).Config.Objects_Generated;
697 end if;
698
699 Lang := In_Tree.Languages_Data.Table (Lang).Next;
700 end loop;
701 end if;
702
703 return True;
704 end Objects_Exist_For;
705
706 -----------------
707 -- Object_Name --
708 -----------------
709
710 function Object_Name
711 (Source_File_Name : File_Name_Type)
712 return File_Name_Type
713 is
714 begin
715 return Extend_Name (Source_File_Name, Object_Suffix);
716 end Object_Name;
717
718 ----------------------
719 -- Record_Temp_File --
720 ----------------------
721
722 procedure Record_Temp_File (Path : Path_Name_Type) is
723 begin
724 Temp_Files.Increment_Last;
725 Temp_Files.Table (Temp_Files.Last) := Path;
726 end Record_Temp_File;
727
728 ------------------------------------
729 -- Register_Default_Naming_Scheme --
730 ------------------------------------
731
732 procedure Register_Default_Naming_Scheme
733 (Language : Name_Id;
734 Default_Spec_Suffix : File_Name_Type;
735 Default_Body_Suffix : File_Name_Type;
736 In_Tree : Project_Tree_Ref)
737 is
738 Lang : Name_Id;
739 Suffix : Array_Element_Id;
740 Found : Boolean := False;
741 Element : Array_Element;
742
743 begin
744 -- Get the language name in small letters
745
746 Get_Name_String (Language);
747 Name_Buffer (1 .. Name_Len) := To_Lower (Name_Buffer (1 .. Name_Len));
748 Lang := Name_Find;
749
750 -- Look for an element of the spec suffix array indexed by the language
751 -- name. If one is found, put the default value.
752
753 Suffix := In_Tree.Private_Part.Default_Naming.Spec_Suffix;
754 Found := False;
755 while Suffix /= No_Array_Element and then not Found loop
756 Element := In_Tree.Array_Elements.Table (Suffix);
757
758 if Element.Index = Lang then
759 Found := True;
760 Element.Value.Value := Name_Id (Default_Spec_Suffix);
761 In_Tree.Array_Elements.Table (Suffix) := Element;
762
763 else
764 Suffix := Element.Next;
765 end if;
766 end loop;
767
768 -- If none can be found, create a new one
769
770 if not Found then
771 Element :=
772 (Index => Lang,
773 Src_Index => 0,
774 Index_Case_Sensitive => False,
775 Value => (Project => No_Project,
776 Kind => Single,
777 Location => No_Location,
778 Default => False,
779 Value => Name_Id (Default_Spec_Suffix),
780 Index => 0),
781 Next => In_Tree.Private_Part.Default_Naming.Spec_Suffix);
782 Array_Element_Table.Increment_Last (In_Tree.Array_Elements);
783 In_Tree.Array_Elements.Table
784 (Array_Element_Table.Last (In_Tree.Array_Elements)) :=
785 Element;
786 In_Tree.Private_Part.Default_Naming.Spec_Suffix :=
787 Array_Element_Table.Last (In_Tree.Array_Elements);
788 end if;
789
790 -- Look for an element of the body suffix array indexed by the language
791 -- name. If one is found, put the default value.
792
793 Suffix := In_Tree.Private_Part.Default_Naming.Body_Suffix;
794 Found := False;
795 while Suffix /= No_Array_Element and then not Found loop
796 Element := In_Tree.Array_Elements.Table (Suffix);
797
798 if Element.Index = Lang then
799 Found := True;
800 Element.Value.Value := Name_Id (Default_Body_Suffix);
801 In_Tree.Array_Elements.Table (Suffix) := Element;
802
803 else
804 Suffix := Element.Next;
805 end if;
806 end loop;
807
808 -- If none can be found, create a new one
809
810 if not Found then
811 Element :=
812 (Index => Lang,
813 Src_Index => 0,
814 Index_Case_Sensitive => False,
815 Value => (Project => No_Project,
816 Kind => Single,
817 Location => No_Location,
818 Default => False,
819 Value => Name_Id (Default_Body_Suffix),
820 Index => 0),
821 Next => In_Tree.Private_Part.Default_Naming.Body_Suffix);
822 Array_Element_Table.Increment_Last
823 (In_Tree.Array_Elements);
824 In_Tree.Array_Elements.Table
825 (Array_Element_Table.Last (In_Tree.Array_Elements))
826 := Element;
827 In_Tree.Private_Part.Default_Naming.Body_Suffix :=
828 Array_Element_Table.Last (In_Tree.Array_Elements);
829 end if;
830 end Register_Default_Naming_Scheme;
831
832 -----------
833 -- Reset --
834 -----------
835
836 procedure Reset (Tree : Project_Tree_Ref) is
837
838 -- Def_Lang : constant Name_Node :=
839 -- (Name => Name_Ada,
840 -- Next => No_Name_List);
841 -- Why is the above commented out ???
842
843 begin
844 Prj.Env.Initialize;
845
846 -- Visible tables
847
848 Language_Data_Table.Init (Tree.Languages_Data);
849 Name_List_Table.Init (Tree.Name_Lists);
850 String_Element_Table.Init (Tree.String_Elements);
851 Variable_Element_Table.Init (Tree.Variable_Elements);
852 Array_Element_Table.Init (Tree.Array_Elements);
853 Array_Table.Init (Tree.Arrays);
854 Package_Table.Init (Tree.Packages);
855 Project_List_Table.Init (Tree.Project_Lists);
856 Project_Table.Init (Tree.Projects);
857 Source_Data_Table.Init (Tree.Sources);
858 Alternate_Language_Table.Init (Tree.Alt_Langs);
859 Unit_Table.Init (Tree.Units);
860 Units_Htable.Reset (Tree.Units_HT);
861 Files_Htable.Reset (Tree.Files_HT);
862 Source_Paths_Htable.Reset (Tree.Source_Paths_HT);
863
864 -- Private part table
865
866 Naming_Table.Init (Tree.Private_Part.Namings);
867 Naming_Table.Increment_Last (Tree.Private_Part.Namings);
868 Tree.Private_Part.Namings.Table
869 (Naming_Table.Last (Tree.Private_Part.Namings)) := Std_Naming_Data;
870 Path_File_Table.Init (Tree.Private_Part.Path_Files);
871 Source_Path_Table.Init (Tree.Private_Part.Source_Paths);
872 Object_Path_Table.Init (Tree.Private_Part.Object_Paths);
873 Tree.Private_Part.Default_Naming := Std_Naming_Data;
874
875 if Current_Mode = Ada_Only then
876 Register_Default_Naming_Scheme
877 (Language => Name_Ada,
878 Default_Spec_Suffix => Default_Ada_Spec_Suffix,
879 Default_Body_Suffix => Default_Ada_Body_Suffix,
880 In_Tree => Tree);
881 Tree.Private_Part.Default_Naming.Separate_Suffix :=
882 Default_Ada_Body_Suffix;
883 end if;
884 end Reset;
885
886 ------------------------
887 -- Same_Naming_Scheme --
888 ------------------------
889
890 function Same_Naming_Scheme
891 (Left, Right : Naming_Data) return Boolean
892 is
893 begin
894 return Left.Dot_Replacement = Right.Dot_Replacement
895 and then Left.Casing = Right.Casing
896 and then Left.Separate_Suffix = Right.Separate_Suffix;
897 end Same_Naming_Scheme;
898
899 ---------------------
900 -- Set_Body_Suffix --
901 ---------------------
902
903 procedure Set_Body_Suffix
904 (In_Tree : Project_Tree_Ref;
905 Language : String;
906 Naming : in out Naming_Data;
907 Suffix : File_Name_Type)
908 is
909 Language_Id : Name_Id;
910 Element : Array_Element;
911
912 begin
913 Name_Len := 0;
914 Add_Str_To_Name_Buffer (Language);
915 To_Lower (Name_Buffer (1 .. Name_Len));
916 Language_Id := Name_Find;
917
918 Element :=
919 (Index => Language_Id,
920 Src_Index => 0,
921 Index_Case_Sensitive => False,
922 Value =>
923 (Kind => Single,
924 Project => No_Project,
925 Location => No_Location,
926 Default => False,
927 Value => Name_Id (Suffix),
928 Index => 0),
929 Next => Naming.Body_Suffix);
930
931 Array_Element_Table.Increment_Last (In_Tree.Array_Elements);
932 Naming.Body_Suffix :=
933 Array_Element_Table.Last (In_Tree.Array_Elements);
934 In_Tree.Array_Elements.Table (Naming.Body_Suffix) := Element;
935 end Set_Body_Suffix;
936
937 --------------------------
938 -- Set_In_Configuration --
939 --------------------------
940
941 procedure Set_In_Configuration (Value : Boolean) is
942 begin
943 Configuration_Mode := Value;
944 end Set_In_Configuration;
945
946 --------------
947 -- Set_Mode --
948 --------------
949
950 procedure Set_Mode (New_Mode : Mode) is
951 begin
952 Current_Mode := New_Mode;
953 case New_Mode is
954 when Ada_Only =>
955 Default_Language_Is_Ada := True;
956 Must_Check_Configuration := False;
957 when Multi_Language =>
958 Default_Language_Is_Ada := False;
959 Must_Check_Configuration := True;
960 end case;
961 end Set_Mode;
962
963 ---------------------
964 -- Set_Spec_Suffix --
965 ---------------------
966
967 procedure Set_Spec_Suffix
968 (In_Tree : Project_Tree_Ref;
969 Language : String;
970 Naming : in out Naming_Data;
971 Suffix : File_Name_Type)
972 is
973 Language_Id : Name_Id;
974 Element : Array_Element;
975
976 begin
977 Name_Len := 0;
978 Add_Str_To_Name_Buffer (Language);
979 To_Lower (Name_Buffer (1 .. Name_Len));
980 Language_Id := Name_Find;
981
982 Element :=
983 (Index => Language_Id,
984 Src_Index => 0,
985 Index_Case_Sensitive => False,
986 Value =>
987 (Kind => Single,
988 Project => No_Project,
989 Location => No_Location,
990 Default => False,
991 Value => Name_Id (Suffix),
992 Index => 0),
993 Next => Naming.Spec_Suffix);
994
995 Array_Element_Table.Increment_Last (In_Tree.Array_Elements);
996 Naming.Spec_Suffix :=
997 Array_Element_Table.Last (In_Tree.Array_Elements);
998 In_Tree.Array_Elements.Table (Naming.Spec_Suffix) := Element;
999 end Set_Spec_Suffix;
1000
1001 -----------
1002 -- Slash --
1003 -----------
1004
1005 function Slash return Path_Name_Type is
1006 begin
1007 return Slash_Id;
1008 end Slash;
1009
1010 -----------------------
1011 -- Spec_Suffix_Id_Of --
1012 -----------------------
1013
1014 function Spec_Suffix_Id_Of
1015 (In_Tree : Project_Tree_Ref;
1016 Language : String;
1017 Naming : Naming_Data) return File_Name_Type
1018 is
1019 Language_Id : Name_Id;
1020
1021 begin
1022 Name_Len := 0;
1023 Add_Str_To_Name_Buffer (Language);
1024 To_Lower (Name_Buffer (1 .. Name_Len));
1025 Language_Id := Name_Find;
1026
1027 return
1028 Spec_Suffix_Id_Of
1029 (In_Tree => In_Tree,
1030 Language_Id => Language_Id,
1031 Naming => Naming);
1032 end Spec_Suffix_Id_Of;
1033
1034 -----------------------
1035 -- Spec_Suffix_Id_Of --
1036 -----------------------
1037
1038 function Spec_Suffix_Id_Of
1039 (In_Tree : Project_Tree_Ref;
1040 Language_Id : Name_Id;
1041 Naming : Naming_Data) return File_Name_Type
1042 is
1043 Element_Id : Array_Element_Id;
1044 Element : Array_Element;
1045 Suffix : File_Name_Type := No_File;
1046 Lang : Language_Index;
1047
1048 begin
1049 Element_Id := Naming.Spec_Suffix;
1050 while Element_Id /= No_Array_Element loop
1051 Element := In_Tree.Array_Elements.Table (Element_Id);
1052
1053 if Element.Index = Language_Id then
1054 return File_Name_Type (Element.Value.Value);
1055 end if;
1056
1057 Element_Id := Element.Next;
1058 end loop;
1059
1060 if Current_Mode = Multi_Language then
1061 Lang := In_Tree.First_Language;
1062 while Lang /= No_Language_Index loop
1063 if In_Tree.Languages_Data.Table (Lang).Name = Language_Id then
1064 Suffix :=
1065 In_Tree.Languages_Data.Table
1066 (Lang).Config.Naming_Data.Spec_Suffix;
1067 exit;
1068 end if;
1069
1070 Lang := In_Tree.Languages_Data.Table (Lang).Next;
1071 end loop;
1072 end if;
1073
1074 return Suffix;
1075 end Spec_Suffix_Id_Of;
1076
1077 --------------------
1078 -- Spec_Suffix_Of --
1079 --------------------
1080
1081 function Spec_Suffix_Of
1082 (In_Tree : Project_Tree_Ref;
1083 Language : String;
1084 Naming : Naming_Data) return String
1085 is
1086 Language_Id : Name_Id;
1087 Element_Id : Array_Element_Id;
1088 Element : Array_Element;
1089 Suffix : File_Name_Type := No_File;
1090 Lang : Language_Index;
1091
1092 begin
1093 Name_Len := 0;
1094 Add_Str_To_Name_Buffer (Language);
1095 To_Lower (Name_Buffer (1 .. Name_Len));
1096 Language_Id := Name_Find;
1097
1098 Element_Id := Naming.Spec_Suffix;
1099 while Element_Id /= No_Array_Element loop
1100 Element := In_Tree.Array_Elements.Table (Element_Id);
1101
1102 if Element.Index = Language_Id then
1103 return Get_Name_String (Element.Value.Value);
1104 end if;
1105
1106 Element_Id := Element.Next;
1107 end loop;
1108
1109 if Current_Mode = Multi_Language then
1110 Lang := In_Tree.First_Language;
1111 while Lang /= No_Language_Index loop
1112 if In_Tree.Languages_Data.Table (Lang).Name = Language_Id then
1113 Suffix :=
1114 File_Name_Type
1115 (In_Tree.Languages_Data.Table
1116 (Lang).Config.Naming_Data.Spec_Suffix);
1117 exit;
1118 end if;
1119
1120 Lang := In_Tree.Languages_Data.Table (Lang).Next;
1121 end loop;
1122
1123 if Suffix /= No_File then
1124 return Get_Name_String (Suffix);
1125 end if;
1126 end if;
1127
1128 return "";
1129 end Spec_Suffix_Of;
1130
1131 --------------------------
1132 -- Standard_Naming_Data --
1133 --------------------------
1134
1135 function Standard_Naming_Data
1136 (Tree : Project_Tree_Ref := No_Project_Tree) return Naming_Data
1137 is
1138 begin
1139 if Tree = No_Project_Tree then
1140 Prj.Initialize (Tree => No_Project_Tree);
1141 return Std_Naming_Data;
1142 else
1143 return Tree.Private_Part.Default_Naming;
1144 end if;
1145 end Standard_Naming_Data;
1146
1147 -------------------
1148 -- Switches_Name --
1149 -------------------
1150
1151 function Switches_Name
1152 (Source_File_Name : File_Name_Type) return File_Name_Type
1153 is
1154 begin
1155 return Extend_Name (Source_File_Name, Switches_Dependency_Suffix);
1156 end Switches_Name;
1157
1158 ---------------------------
1159 -- There_Are_Ada_Sources --
1160 ---------------------------
1161
1162 function There_Are_Ada_Sources
1163 (In_Tree : Project_Tree_Ref;
1164 Project : Project_Id) return Boolean
1165 is
1166 Prj : Project_Id;
1167
1168 begin
1169 Prj := Project;
1170 while Prj /= No_Project loop
1171 if In_Tree.Projects.Table (Prj).Ada_Sources /= Nil_String then
1172 return True;
1173 end if;
1174
1175 Prj := In_Tree.Projects.Table (Prj).Extends;
1176 end loop;
1177
1178 return False;
1179 end There_Are_Ada_Sources;
1180
1181 -----------
1182 -- Value --
1183 -----------
1184
1185 function Value (Image : String) return Casing_Type is
1186 begin
1187 for Casing in The_Casing_Images'Range loop
1188 if To_Lower (Image) = To_Lower (The_Casing_Images (Casing).all) then
1189 return Casing;
1190 end if;
1191 end loop;
1192
1193 raise Constraint_Error;
1194 end Value;
1195
1196 begin
1197 -- Make sure that the standard config and user project file extensions are
1198 -- compatible with canonical case file naming.
1199
1200 Canonical_Case_File_Name (Config_Project_File_Extension);
1201 Canonical_Case_File_Name (Project_File_Extension);
1202 end Prj;