PR testsuite/44195
[official-gcc.git] / gcc / ada / makeutl.adb
blobe07bebbad6b0774702e661f794f05c148ec80fd0
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- M A K E U T L --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 2004-2010, 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 ------------------------------------------------------------------------------
26 with ALI; use ALI;
27 with Debug;
28 with Fname;
29 with Hostparm;
30 with Osint; use Osint;
31 with Output; use Output;
32 with Opt; use Opt;
33 with Prj.Ext;
34 with Prj.Util;
35 with Snames; use Snames;
36 with Table;
38 with Ada.Command_Line; use Ada.Command_Line;
40 with GNAT.Directory_Operations; use GNAT.Directory_Operations;
42 with GNAT.Case_Util; use GNAT.Case_Util;
43 with GNAT.HTable;
45 package body Makeutl is
47 type Mark_Key is record
48 File : File_Name_Type;
49 Index : Int;
50 end record;
51 -- Identify either a mono-unit source (when Index = 0) or a specific unit
52 -- (index = 1's origin index of unit) in a multi-unit source.
54 -- There follow many global undocumented declarations, comments needed ???
56 Max_Mask_Num : constant := 2048;
58 subtype Mark_Num is Union_Id range 0 .. Max_Mask_Num - 1;
60 function Hash (Key : Mark_Key) return Mark_Num;
62 package Marks is new GNAT.HTable.Simple_HTable
63 (Header_Num => Mark_Num,
64 Element => Boolean,
65 No_Element => False,
66 Key => Mark_Key,
67 Hash => Hash,
68 Equal => "=");
69 -- A hash table to keep tracks of the marked units
71 type Linker_Options_Data is record
72 Project : Project_Id;
73 Options : String_List_Id;
74 end record;
76 Linker_Option_Initial_Count : constant := 20;
78 Linker_Options_Buffer : String_List_Access :=
79 new String_List (1 .. Linker_Option_Initial_Count);
81 Last_Linker_Option : Natural := 0;
83 package Linker_Opts is new Table.Table (
84 Table_Component_Type => Linker_Options_Data,
85 Table_Index_Type => Integer,
86 Table_Low_Bound => 1,
87 Table_Initial => 10,
88 Table_Increment => 100,
89 Table_Name => "Make.Linker_Opts");
91 procedure Add_Linker_Option (Option : String);
93 ---------
94 -- Add --
95 ---------
97 procedure Add
98 (Option : String_Access;
99 To : in out String_List_Access;
100 Last : in out Natural)
102 begin
103 if Last = To'Last then
104 declare
105 New_Options : constant String_List_Access :=
106 new String_List (1 .. To'Last * 2);
108 begin
109 New_Options (To'Range) := To.all;
111 -- Set all elements of the original options to null to avoid
112 -- deallocation of copies.
114 To.all := (others => null);
116 Free (To);
117 To := New_Options;
118 end;
119 end if;
121 Last := Last + 1;
122 To (Last) := Option;
123 end Add;
125 procedure Add
126 (Option : String;
127 To : in out String_List_Access;
128 Last : in out Natural)
130 begin
131 Add (Option => new String'(Option), To => To, Last => Last);
132 end Add;
134 -----------------------
135 -- Add_Linker_Option --
136 -----------------------
138 procedure Add_Linker_Option (Option : String) is
139 begin
140 if Option'Length > 0 then
141 if Last_Linker_Option = Linker_Options_Buffer'Last then
142 declare
143 New_Buffer : constant String_List_Access :=
144 new String_List
145 (1 .. Linker_Options_Buffer'Last +
146 Linker_Option_Initial_Count);
147 begin
148 New_Buffer (Linker_Options_Buffer'Range) :=
149 Linker_Options_Buffer.all;
150 Linker_Options_Buffer.all := (others => null);
151 Free (Linker_Options_Buffer);
152 Linker_Options_Buffer := New_Buffer;
153 end;
154 end if;
156 Last_Linker_Option := Last_Linker_Option + 1;
157 Linker_Options_Buffer (Last_Linker_Option) := new String'(Option);
158 end if;
159 end Add_Linker_Option;
161 -------------------------
162 -- Base_Name_Index_For --
163 -------------------------
165 function Base_Name_Index_For
166 (Main : String;
167 Main_Index : Int;
168 Index_Separator : Character) return File_Name_Type
170 Result : File_Name_Type;
172 begin
173 Name_Len := 0;
174 Add_Str_To_Name_Buffer (Base_Name (Main));
176 -- Remove the extension, if any, that is the last part of the base name
177 -- starting with a dot and following some characters.
179 for J in reverse 2 .. Name_Len loop
180 if Name_Buffer (J) = '.' then
181 Name_Len := J - 1;
182 exit;
183 end if;
184 end loop;
186 -- Add the index info, if index is different from 0
188 if Main_Index > 0 then
189 Add_Char_To_Name_Buffer (Index_Separator);
191 declare
192 Img : constant String := Main_Index'Img;
193 begin
194 Add_Str_To_Name_Buffer (Img (2 .. Img'Last));
195 end;
196 end if;
198 Result := Name_Find;
199 return Result;
200 end Base_Name_Index_For;
202 ------------------------------
203 -- Check_Source_Info_In_ALI --
204 ------------------------------
206 function Check_Source_Info_In_ALI (The_ALI : ALI_Id) return Boolean is
207 Unit_Name : Name_Id;
209 begin
210 -- Loop through units
212 for U in ALIs.Table (The_ALI).First_Unit ..
213 ALIs.Table (The_ALI).Last_Unit
214 loop
215 -- Check if the file name is one of the source of the unit
217 Get_Name_String (Units.Table (U).Uname);
218 Name_Len := Name_Len - 2;
219 Unit_Name := Name_Find;
221 if File_Not_A_Source_Of (Unit_Name, Units.Table (U).Sfile) then
222 return False;
223 end if;
225 -- Loop to do same check for each of the withed units
227 for W in Units.Table (U).First_With .. Units.Table (U).Last_With loop
228 declare
229 WR : ALI.With_Record renames Withs.Table (W);
231 begin
232 if WR.Sfile /= No_File then
233 Get_Name_String (WR.Uname);
234 Name_Len := Name_Len - 2;
235 Unit_Name := Name_Find;
237 if File_Not_A_Source_Of (Unit_Name, WR.Sfile) then
238 return False;
239 end if;
240 end if;
241 end;
242 end loop;
243 end loop;
245 -- Loop to check subunits
247 for D in ALIs.Table (The_ALI).First_Sdep ..
248 ALIs.Table (The_ALI).Last_Sdep
249 loop
250 declare
251 SD : Sdep_Record renames Sdep.Table (D);
253 begin
254 Unit_Name := SD.Subunit_Name;
256 if Unit_Name /= No_Name then
258 -- For separates, the file is no longer associated with the
259 -- unit ("proc-sep.adb" is not associated with unit "proc.sep")
260 -- so we need to check whether the source file still exists in
261 -- the source tree: it will if it matches the naming scheme
262 -- (and then will be for the same unit).
264 if Find_Source
265 (In_Tree => Project_Tree,
266 Project => No_Project,
267 Base_Name => SD.Sfile) = No_Source
268 then
269 -- If this is not a runtime file or if, when gnatmake switch
270 -- -a is used, we are not able to find this subunit in the
271 -- source directories, then recompilation is needed.
273 if not Fname.Is_Internal_File_Name (SD.Sfile)
274 or else
275 (Check_Readonly_Files
276 and then Full_Source_Name (SD.Sfile) = No_File)
277 then
278 if Verbose_Mode then
279 Write_Line
280 ("While parsing ALI file, file "
281 & Get_Name_String (SD.Sfile)
282 & " is indicated as containing subunit "
283 & Get_Name_String (Unit_Name)
284 & " but this does not match what was found while"
285 & " parsing the project. Will recompile");
286 end if;
288 return False;
289 end if;
290 end if;
291 end if;
292 end;
293 end loop;
295 return True;
296 end Check_Source_Info_In_ALI;
298 -----------------
299 -- Create_Name --
300 -----------------
302 function Create_Name (Name : String) return File_Name_Type is
303 begin
304 Name_Len := 0;
305 Add_Str_To_Name_Buffer (Name);
306 return Name_Find;
307 end Create_Name;
309 function Create_Name (Name : String) return Name_Id is
310 begin
311 Name_Len := 0;
312 Add_Str_To_Name_Buffer (Name);
313 return Name_Find;
314 end Create_Name;
316 function Create_Name (Name : String) return Path_Name_Type is
317 begin
318 Name_Len := 0;
319 Add_Str_To_Name_Buffer (Name);
320 return Name_Find;
321 end Create_Name;
323 ----------------------
324 -- Delete_All_Marks --
325 ----------------------
327 procedure Delete_All_Marks is
328 begin
329 Marks.Reset;
330 end Delete_All_Marks;
332 ----------------------------
333 -- Executable_Prefix_Path --
334 ----------------------------
336 function Executable_Prefix_Path return String is
337 Exec_Name : constant String := Command_Name;
339 function Get_Install_Dir (S : String) return String;
340 -- S is the executable name preceded by the absolute or relative path,
341 -- e.g. "c:\usr\bin\gcc.exe". Returns the absolute directory where "bin"
342 -- lies (in the example "C:\usr"). If the executable is not in a "bin"
343 -- directory, return "".
345 ---------------------
346 -- Get_Install_Dir --
347 ---------------------
349 function Get_Install_Dir (S : String) return String is
350 Exec : String := S;
351 Path_Last : Integer := 0;
353 begin
354 for J in reverse Exec'Range loop
355 if Exec (J) = Directory_Separator then
356 Path_Last := J - 1;
357 exit;
358 end if;
359 end loop;
361 if Path_Last >= Exec'First + 2 then
362 To_Lower (Exec (Path_Last - 2 .. Path_Last));
363 end if;
365 if Path_Last < Exec'First + 2
366 or else Exec (Path_Last - 2 .. Path_Last) /= "bin"
367 or else (Path_Last - 3 >= Exec'First
368 and then Exec (Path_Last - 3) /= Directory_Separator)
369 then
370 return "";
371 end if;
373 return Normalize_Pathname
374 (Exec (Exec'First .. Path_Last - 4),
375 Resolve_Links => Opt.Follow_Links_For_Dirs)
376 & Directory_Separator;
377 end Get_Install_Dir;
379 -- Beginning of Executable_Prefix_Path
381 begin
382 -- For VMS, the path returned is always /gnu/
384 if Hostparm.OpenVMS then
385 return "/gnu/";
386 end if;
388 -- First determine if a path prefix was placed in front of the
389 -- executable name.
391 for J in reverse Exec_Name'Range loop
392 if Exec_Name (J) = Directory_Separator then
393 return Get_Install_Dir (Exec_Name);
394 end if;
395 end loop;
397 -- If we get here, the user has typed the executable name with no
398 -- directory prefix.
400 declare
401 Path : String_Access := Locate_Exec_On_Path (Exec_Name);
402 begin
403 if Path = null then
404 return "";
405 else
406 declare
407 Dir : constant String := Get_Install_Dir (Path.all);
408 begin
409 Free (Path);
410 return Dir;
411 end;
412 end if;
413 end;
414 end Executable_Prefix_Path;
416 --------------------------
417 -- File_Not_A_Source_Of --
418 --------------------------
420 function File_Not_A_Source_Of
421 (Uname : Name_Id;
422 Sfile : File_Name_Type) return Boolean
424 Unit : constant Unit_Index :=
425 Units_Htable.Get (Project_Tree.Units_HT, Uname);
427 At_Least_One_File : Boolean := False;
429 begin
430 if Unit /= No_Unit_Index then
431 for F in Unit.File_Names'Range loop
432 if Unit.File_Names (F) /= null then
433 At_Least_One_File := True;
434 if Unit.File_Names (F).File = Sfile then
435 return False;
436 end if;
437 end if;
438 end loop;
440 if not At_Least_One_File then
442 -- The unit was probably created initially for a separate unit
443 -- (which are initially created as IMPL when both suffixes are the
444 -- same). Later on, Override_Kind changed the type of the file,
445 -- and the unit is no longer valid in fact.
447 return False;
448 end if;
450 Verbose_Msg (Uname, "sources do not include ", Name_Id (Sfile));
451 return True;
452 end if;
454 return False;
455 end File_Not_A_Source_Of;
457 ----------
458 -- Hash --
459 ----------
461 function Hash (Key : Mark_Key) return Mark_Num is
462 begin
463 return Union_Id (Key.File) mod Max_Mask_Num;
464 end Hash;
466 ------------
467 -- Inform --
468 ------------
470 procedure Inform (N : File_Name_Type; Msg : String) is
471 begin
472 Inform (Name_Id (N), Msg);
473 end Inform;
475 procedure Inform (N : Name_Id := No_Name; Msg : String) is
476 begin
477 Osint.Write_Program_Name;
479 Write_Str (": ");
481 if N /= No_Name then
482 Write_Str ("""");
484 declare
485 Name : constant String := Get_Name_String (N);
486 begin
487 if Debug.Debug_Flag_F and then Is_Absolute_Path (Name) then
488 Write_Str (File_Name (Name));
489 else
490 Write_Str (Name);
491 end if;
492 end;
494 Write_Str (""" ");
495 end if;
497 Write_Str (Msg);
498 Write_Eol;
499 end Inform;
501 ----------------------------
502 -- Is_External_Assignment --
503 ----------------------------
505 function Is_External_Assignment
506 (Tree : Prj.Tree.Project_Node_Tree_Ref;
507 Argv : String) return Boolean
509 Start : Positive := 3;
510 Finish : Natural := Argv'Last;
512 pragma Assert (Argv'First = 1);
513 pragma Assert (Argv (1 .. 2) = "-X");
515 begin
516 if Argv'Last < 5 then
517 return False;
519 elsif Argv (3) = '"' then
520 if Argv (Argv'Last) /= '"' or else Argv'Last < 7 then
521 return False;
522 else
523 Start := 4;
524 Finish := Argv'Last - 1;
525 end if;
526 end if;
528 return Prj.Ext.Check
529 (Tree => Tree,
530 Declaration => Argv (Start .. Finish));
531 end Is_External_Assignment;
533 ---------------
534 -- Is_Marked --
535 ---------------
537 function Is_Marked
538 (Source_File : File_Name_Type;
539 Index : Int := 0) return Boolean
541 begin
542 return Marks.Get (K => (File => Source_File, Index => Index));
543 end Is_Marked;
545 -----------------------------
546 -- Linker_Options_Switches --
547 -----------------------------
549 function Linker_Options_Switches
550 (Project : Project_Id;
551 In_Tree : Project_Tree_Ref) return String_List
553 procedure Recursive_Add (Proj : Project_Id; Dummy : in out Boolean);
554 -- The recursive routine used to add linker options
556 -------------------
557 -- Recursive_Add --
558 -------------------
560 procedure Recursive_Add (Proj : Project_Id; Dummy : in out Boolean) is
561 pragma Unreferenced (Dummy);
563 Linker_Package : Package_Id;
564 Options : Variable_Value;
566 begin
567 Linker_Package :=
568 Prj.Util.Value_Of
569 (Name => Name_Linker,
570 In_Packages => Proj.Decl.Packages,
571 In_Tree => In_Tree);
573 Options :=
574 Prj.Util.Value_Of
575 (Name => Name_Ada,
576 Index => 0,
577 Attribute_Or_Array_Name => Name_Linker_Options,
578 In_Package => Linker_Package,
579 In_Tree => In_Tree);
581 -- If attribute is present, add the project with
582 -- the attribute to table Linker_Opts.
584 if Options /= Nil_Variable_Value then
585 Linker_Opts.Increment_Last;
586 Linker_Opts.Table (Linker_Opts.Last) :=
587 (Project => Proj, Options => Options.Values);
588 end if;
589 end Recursive_Add;
591 procedure For_All_Projects is
592 new For_Every_Project_Imported (Boolean, Recursive_Add);
594 Dummy : Boolean := False;
596 -- Start of processing for Linker_Options_Switches
598 begin
599 Linker_Opts.Init;
601 For_All_Projects (Project, Dummy, Imported_First => True);
603 Last_Linker_Option := 0;
605 for Index in reverse 1 .. Linker_Opts.Last loop
606 declare
607 Options : String_List_Id;
608 Proj : constant Project_Id :=
609 Linker_Opts.Table (Index).Project;
610 Option : Name_Id;
611 Dir_Path : constant String :=
612 Get_Name_String (Proj.Directory.Name);
614 begin
615 Options := Linker_Opts.Table (Index).Options;
616 while Options /= Nil_String loop
617 Option := In_Tree.String_Elements.Table (Options).Value;
618 Get_Name_String (Option);
620 -- Do not consider empty linker options
622 if Name_Len /= 0 then
623 Add_Linker_Option (Name_Buffer (1 .. Name_Len));
625 -- Object files and -L switches specified with relative
626 -- paths must be converted to absolute paths.
628 Test_If_Relative_Path
629 (Switch => Linker_Options_Buffer (Last_Linker_Option),
630 Parent => Dir_Path,
631 Including_L_Switch => True);
632 end if;
634 Options := In_Tree.String_Elements.Table (Options).Next;
635 end loop;
636 end;
637 end loop;
639 return Linker_Options_Buffer (1 .. Last_Linker_Option);
640 end Linker_Options_Switches;
642 -----------
643 -- Mains --
644 -----------
646 package body Mains is
648 type File_And_Loc is record
649 File_Name : File_Name_Type;
650 Index : Int := 0;
651 Location : Source_Ptr := No_Location;
652 end record;
654 package Names is new Table.Table
655 (Table_Component_Type => File_And_Loc,
656 Table_Index_Type => Integer,
657 Table_Low_Bound => 1,
658 Table_Initial => 10,
659 Table_Increment => 100,
660 Table_Name => "Makeutl.Mains.Names");
661 -- The table that stores the mains
663 Current : Natural := 0;
664 -- The index of the last main retrieved from the table
666 --------------
667 -- Add_Main --
668 --------------
670 procedure Add_Main (Name : String) is
671 begin
672 Name_Len := 0;
673 Add_Str_To_Name_Buffer (Name);
674 Names.Increment_Last;
675 Names.Table (Names.Last) := (Name_Find, 0, No_Location);
676 end Add_Main;
678 ------------
679 -- Delete --
680 ------------
682 procedure Delete is
683 begin
684 Names.Set_Last (0);
685 Mains.Reset;
686 end Delete;
688 ---------------
689 -- Get_Index --
690 ---------------
692 function Get_Index return Int is
693 begin
694 if Current in Names.First .. Names.Last then
695 return Names.Table (Current).Index;
696 else
697 return 0;
698 end if;
699 end Get_Index;
701 ------------------
702 -- Get_Location --
703 ------------------
705 function Get_Location return Source_Ptr is
706 begin
707 if Current in Names.First .. Names.Last then
708 return Names.Table (Current).Location;
709 else
710 return No_Location;
711 end if;
712 end Get_Location;
714 ---------------
715 -- Next_Main --
716 ---------------
718 function Next_Main return String is
719 begin
720 if Current >= Names.Last then
721 return "";
722 else
723 Current := Current + 1;
724 return Get_Name_String (Names.Table (Current).File_Name);
725 end if;
726 end Next_Main;
728 ---------------------
729 -- Number_Of_Mains --
730 ---------------------
732 function Number_Of_Mains return Natural is
733 begin
734 return Names.Last;
735 end Number_Of_Mains;
737 -----------
738 -- Reset --
739 -----------
741 procedure Reset is
742 begin
743 Current := 0;
744 end Reset;
746 ---------------
747 -- Set_Index --
748 ---------------
750 procedure Set_Index (Index : Int) is
751 begin
752 if Names.Last > 0 then
753 Names.Table (Names.Last).Index := Index;
754 end if;
755 end Set_Index;
757 ------------------
758 -- Set_Location --
759 ------------------
761 procedure Set_Location (Location : Source_Ptr) is
762 begin
763 if Names.Last > 0 then
764 Names.Table (Names.Last).Location := Location;
765 end if;
766 end Set_Location;
768 -----------------
769 -- Update_Main --
770 -----------------
772 procedure Update_Main (Name : String) is
773 begin
774 if Current in Names.First .. Names.Last then
775 Name_Len := 0;
776 Add_Str_To_Name_Buffer (Name);
777 Names.Table (Current).File_Name := Name_Find;
778 end if;
779 end Update_Main;
780 end Mains;
782 ----------
783 -- Mark --
784 ----------
786 procedure Mark (Source_File : File_Name_Type; Index : Int := 0) is
787 begin
788 Marks.Set (K => (File => Source_File, Index => Index), E => True);
789 end Mark;
791 -----------------------
792 -- Path_Or_File_Name --
793 -----------------------
795 function Path_Or_File_Name (Path : Path_Name_Type) return String is
796 Path_Name : constant String := Get_Name_String (Path);
797 begin
798 if Debug.Debug_Flag_F then
799 return File_Name (Path_Name);
800 else
801 return Path_Name;
802 end if;
803 end Path_Or_File_Name;
805 ---------------------------
806 -- Test_If_Relative_Path --
807 ---------------------------
809 procedure Test_If_Relative_Path
810 (Switch : in out String_Access;
811 Parent : String;
812 Including_L_Switch : Boolean := True;
813 Including_Non_Switch : Boolean := True;
814 Including_RTS : Boolean := False)
816 begin
817 if Switch /= null then
818 declare
819 Sw : String (1 .. Switch'Length);
820 Start : Positive;
822 begin
823 Sw := Switch.all;
825 if Sw (1) = '-' then
826 if Sw'Length >= 3
827 and then (Sw (2) = 'A'
828 or else Sw (2) = 'I'
829 or else (Including_L_Switch and then Sw (2) = 'L'))
830 then
831 Start := 3;
833 if Sw = "-I-" then
834 return;
835 end if;
837 elsif Sw'Length >= 4
838 and then (Sw (2 .. 3) = "aL"
839 or else Sw (2 .. 3) = "aO"
840 or else Sw (2 .. 3) = "aI")
841 then
842 Start := 4;
844 elsif Including_RTS
845 and then Sw'Length >= 7
846 and then Sw (2 .. 6) = "-RTS="
847 then
848 Start := 7;
850 else
851 return;
852 end if;
854 -- Because relative path arguments to --RTS= may be relative
855 -- to the search directory prefix, those relative path
856 -- arguments are converted only when they include directory
857 -- information.
859 if not Is_Absolute_Path (Sw (Start .. Sw'Last)) then
860 if Parent'Length = 0 then
861 Do_Fail
862 ("relative search path switches ("""
863 & Sw
864 & """) are not allowed");
866 elsif Including_RTS then
867 for J in Start .. Sw'Last loop
868 if Sw (J) = Directory_Separator then
869 Switch :=
870 new String'
871 (Sw (1 .. Start - 1) &
872 Parent &
873 Directory_Separator &
874 Sw (Start .. Sw'Last));
875 return;
876 end if;
877 end loop;
879 else
880 Switch :=
881 new String'
882 (Sw (1 .. Start - 1) &
883 Parent &
884 Directory_Separator &
885 Sw (Start .. Sw'Last));
886 end if;
887 end if;
889 elsif Including_Non_Switch then
890 if not Is_Absolute_Path (Sw) then
891 if Parent'Length = 0 then
892 Do_Fail
893 ("relative paths (""" & Sw & """) are not allowed");
894 else
895 Switch := new String'(Parent & Directory_Separator & Sw);
896 end if;
897 end if;
898 end if;
899 end;
900 end if;
901 end Test_If_Relative_Path;
903 -------------------
904 -- Unit_Index_Of --
905 -------------------
907 function Unit_Index_Of (ALI_File : File_Name_Type) return Int is
908 Start : Natural;
909 Finish : Natural;
910 Result : Int := 0;
912 begin
913 Get_Name_String (ALI_File);
915 -- First, find the last dot
917 Finish := Name_Len;
919 while Finish >= 1 and then Name_Buffer (Finish) /= '.' loop
920 Finish := Finish - 1;
921 end loop;
923 if Finish = 1 then
924 return 0;
925 end if;
927 -- Now check that the dot is preceded by digits
929 Start := Finish;
930 Finish := Finish - 1;
932 while Start >= 1 and then Name_Buffer (Start - 1) in '0' .. '9' loop
933 Start := Start - 1;
934 end loop;
936 -- If there are no digits, or if the digits are not preceded by the
937 -- character that precedes a unit index, this is not the ALI file of
938 -- a unit in a multi-unit source.
940 if Start > Finish
941 or else Start = 1
942 or else Name_Buffer (Start - 1) /= Multi_Unit_Index_Character
943 then
944 return 0;
945 end if;
947 -- Build the index from the digit(s)
949 while Start <= Finish loop
950 Result := Result * 10 +
951 Character'Pos (Name_Buffer (Start)) - Character'Pos ('0');
952 Start := Start + 1;
953 end loop;
955 return Result;
956 end Unit_Index_Of;
958 -----------------
959 -- Verbose_Msg --
960 -----------------
962 procedure Verbose_Msg
963 (N1 : Name_Id;
964 S1 : String;
965 N2 : Name_Id := No_Name;
966 S2 : String := "";
967 Prefix : String := " -> ";
968 Minimum_Verbosity : Opt.Verbosity_Level_Type := Opt.Low)
970 begin
971 if not Opt.Verbose_Mode
972 or else Minimum_Verbosity > Opt.Verbosity_Level
973 then
974 return;
975 end if;
977 Write_Str (Prefix);
978 Write_Str ("""");
979 Write_Name (N1);
980 Write_Str (""" ");
981 Write_Str (S1);
983 if N2 /= No_Name then
984 Write_Str (" """);
985 Write_Name (N2);
986 Write_Str (""" ");
987 end if;
989 Write_Str (S2);
990 Write_Eol;
991 end Verbose_Msg;
993 procedure Verbose_Msg
994 (N1 : File_Name_Type;
995 S1 : String;
996 N2 : File_Name_Type := No_File;
997 S2 : String := "";
998 Prefix : String := " -> ";
999 Minimum_Verbosity : Opt.Verbosity_Level_Type := Opt.Low)
1001 begin
1002 Verbose_Msg
1003 (Name_Id (N1), S1, Name_Id (N2), S2, Prefix, Minimum_Verbosity);
1004 end Verbose_Msg;
1006 end Makeutl;