OSDN Git Service

2009-07-28 Robert Dewar <dewar@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / makeutl.adb
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-2009, 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 ALI;      use ALI;
27 with Debug;
28 with Osint;    use Osint;
29 with Output;   use Output;
30 with Opt;      use Opt;
31 with Prj.Ext;
32 with Prj.Util;
33 with Snames;   use Snames;
34 with Table;
35
36 with Ada.Command_Line;  use Ada.Command_Line;
37
38 with GNAT.Directory_Operations; use GNAT.Directory_Operations;
39
40 with System.Case_Util; use System.Case_Util;
41 with System.HTable;
42
43 package body Makeutl is
44
45    type Mark_Key is record
46       File  : File_Name_Type;
47       Index : Int;
48    end record;
49    --  Identify either a mono-unit source (when Index = 0) or a specific unit
50    --  (index = 1's origin index of unit) in a multi-unit source.
51
52    --  There follow many global undocumented declarations, comments needed ???
53
54    Max_Mask_Num : constant := 2048;
55
56    subtype Mark_Num is Union_Id range 0 .. Max_Mask_Num - 1;
57
58    function Hash (Key : Mark_Key) return Mark_Num;
59
60    package Marks is new System.HTable.Simple_HTable
61      (Header_Num => Mark_Num,
62       Element    => Boolean,
63       No_Element => False,
64       Key        => Mark_Key,
65       Hash       => Hash,
66       Equal      => "=");
67    --  A hash table to keep tracks of the marked units
68
69    type Linker_Options_Data is record
70       Project : Project_Id;
71       Options : String_List_Id;
72    end record;
73
74    Linker_Option_Initial_Count : constant := 20;
75
76    Linker_Options_Buffer : String_List_Access :=
77      new String_List (1 .. Linker_Option_Initial_Count);
78
79    Last_Linker_Option : Natural := 0;
80
81    package Linker_Opts is new Table.Table (
82      Table_Component_Type => Linker_Options_Data,
83      Table_Index_Type     => Integer,
84      Table_Low_Bound      => 1,
85      Table_Initial        => 10,
86      Table_Increment      => 100,
87      Table_Name           => "Make.Linker_Opts");
88
89    procedure Add_Linker_Option (Option : String);
90
91    ---------
92    -- Add --
93    ---------
94
95    procedure Add
96      (Option : String_Access;
97       To     : in out String_List_Access;
98       Last   : in out Natural)
99    is
100    begin
101       if Last = To'Last then
102          declare
103             New_Options : constant String_List_Access :=
104                             new String_List (1 .. To'Last * 2);
105
106          begin
107             New_Options (To'Range) := To.all;
108
109             --  Set all elements of the original options to null to avoid
110             --  deallocation of copies.
111
112             To.all := (others => null);
113
114             Free (To);
115             To := New_Options;
116          end;
117       end if;
118
119       Last := Last + 1;
120       To (Last) := Option;
121    end Add;
122
123    procedure Add
124      (Option : String;
125       To     : in out String_List_Access;
126       Last   : in out Natural)
127    is
128    begin
129       Add (Option => new String'(Option), To => To, Last => Last);
130    end Add;
131
132    -----------------------
133    -- Add_Linker_Option --
134    -----------------------
135
136    procedure Add_Linker_Option (Option : String) is
137    begin
138       if Option'Length > 0 then
139          if Last_Linker_Option = Linker_Options_Buffer'Last then
140             declare
141                New_Buffer : constant String_List_Access :=
142                               new String_List
143                                 (1 .. Linker_Options_Buffer'Last +
144                                         Linker_Option_Initial_Count);
145             begin
146                New_Buffer (Linker_Options_Buffer'Range) :=
147                  Linker_Options_Buffer.all;
148                Linker_Options_Buffer.all := (others => null);
149                Free (Linker_Options_Buffer);
150                Linker_Options_Buffer := New_Buffer;
151             end;
152          end if;
153
154          Last_Linker_Option := Last_Linker_Option + 1;
155          Linker_Options_Buffer (Last_Linker_Option) := new String'(Option);
156       end if;
157    end Add_Linker_Option;
158
159    ------------------------------
160    -- Check_Source_Info_In_ALI --
161    ------------------------------
162
163    function Check_Source_Info_In_ALI (The_ALI : ALI_Id) return Boolean is
164       Unit_Name : Name_Id;
165
166    begin
167       --  Loop through units
168
169       for U in ALIs.Table (The_ALI).First_Unit ..
170                ALIs.Table (The_ALI).Last_Unit
171       loop
172          --  Check if the file name is one of the source of the unit
173
174          Get_Name_String (Units.Table (U).Uname);
175          Name_Len  := Name_Len - 2;
176          Unit_Name := Name_Find;
177
178          if File_Not_A_Source_Of (Unit_Name, Units.Table (U).Sfile) then
179             return False;
180          end if;
181
182          --  Loop to do same check for each of the withed units
183
184          for W in Units.Table (U).First_With .. Units.Table (U).Last_With loop
185             declare
186                WR : ALI.With_Record renames Withs.Table (W);
187
188             begin
189                if WR.Sfile /= No_File then
190                   Get_Name_String (WR.Uname);
191                   Name_Len  := Name_Len - 2;
192                   Unit_Name := Name_Find;
193
194                   if File_Not_A_Source_Of (Unit_Name, WR.Sfile) then
195                      return False;
196                   end if;
197                end if;
198             end;
199          end loop;
200       end loop;
201
202       --  Loop to check subunits
203
204       for D in ALIs.Table (The_ALI).First_Sdep ..
205                ALIs.Table (The_ALI).Last_Sdep
206       loop
207          declare
208             SD : Sdep_Record renames Sdep.Table (D);
209
210          begin
211             Unit_Name := SD.Subunit_Name;
212
213             if Unit_Name /= No_Name then
214
215                --  For separates, the file is no longer associated with the
216                --  unit ("proc-sep.adb" is not associated with unit "proc.sep".
217                --  So we need to check whether the source file still exists in
218                --  the source tree: it will if it matches the naming scheme
219                --  (and then will be for the same unit).
220
221                if Find_Source
222                  (In_Tree => Project_Tree,
223                   Project => No_Project,
224                   Base_Name => SD.Sfile) = No_Source
225                then
226                   --  If this is not a runtime file (when using -a) ? Otherwise
227                   --  we get complaints about a-except.adb, which uses
228                   --  separates.
229
230                   if not Check_Readonly_Files
231                     or else Find_File (SD.Sfile, Osint.Source) = No_File
232                   then
233                      if Verbose_Mode then
234                         Write_Line
235                           ("While parsing ALI file: Sdep associates "
236                            & Get_Name_String (SD.Sfile)
237                            & " with unit " & Get_Name_String (Unit_Name)
238                            & " but this does not match what was found while"
239                            & " parsing the project. Will recompile");
240                      end if;
241                      return False;
242                   end if;
243                end if;
244             end if;
245          end;
246       end loop;
247
248       return True;
249    end Check_Source_Info_In_ALI;
250
251    -----------------
252    -- Create_Name --
253    -----------------
254
255    function Create_Name (Name : String) return File_Name_Type is
256    begin
257       Name_Len := 0;
258       Add_Str_To_Name_Buffer (Name);
259       return Name_Find;
260    end Create_Name;
261
262    function Create_Name (Name : String) return Name_Id is
263    begin
264       Name_Len := 0;
265       Add_Str_To_Name_Buffer (Name);
266       return Name_Find;
267    end Create_Name;
268
269    function Create_Name (Name : String) return Path_Name_Type is
270    begin
271       Name_Len := 0;
272       Add_Str_To_Name_Buffer (Name);
273       return Name_Find;
274    end Create_Name;
275
276    ----------------------
277    -- Delete_All_Marks --
278    ----------------------
279
280    procedure Delete_All_Marks is
281    begin
282       Marks.Reset;
283    end Delete_All_Marks;
284
285    ----------------------------
286    -- Executable_Prefix_Path --
287    ----------------------------
288
289    function Executable_Prefix_Path return String is
290       Exec_Name : constant String := Command_Name;
291
292       function Get_Install_Dir (S : String) return String;
293       --  S is the executable name preceded by the absolute or relative path,
294       --  e.g. "c:\usr\bin\gcc.exe". Returns the absolute directory where "bin"
295       --  lies (in the example "C:\usr"). If the executable is not in a "bin"
296       --  directory, return "".
297
298       ---------------------
299       -- Get_Install_Dir --
300       ---------------------
301
302       function Get_Install_Dir (S : String) return String is
303          Exec      : String  := S;
304          Path_Last : Integer := 0;
305
306       begin
307          for J in reverse Exec'Range loop
308             if Exec (J) = Directory_Separator then
309                Path_Last := J - 1;
310                exit;
311             end if;
312          end loop;
313
314          if Path_Last >= Exec'First + 2 then
315             To_Lower (Exec (Path_Last - 2 .. Path_Last));
316          end if;
317
318          if Path_Last < Exec'First + 2
319            or else Exec (Path_Last - 2 .. Path_Last) /= "bin"
320            or else (Path_Last - 3 >= Exec'First
321                      and then Exec (Path_Last - 3) /= Directory_Separator)
322          then
323             return "";
324          end if;
325
326          return Normalize_Pathname (Exec (Exec'First .. Path_Last - 4))
327            & Directory_Separator;
328       end Get_Install_Dir;
329
330    --  Beginning of Executable_Prefix_Path
331
332    begin
333       --  First determine if a path prefix was placed in front of the
334       --  executable name.
335
336       for J in reverse Exec_Name'Range loop
337          if Exec_Name (J) = Directory_Separator then
338             return Get_Install_Dir (Exec_Name);
339          end if;
340       end loop;
341
342       --  If we get here, the user has typed the executable name with no
343       --  directory prefix.
344
345       declare
346          Path : String_Access := Locate_Exec_On_Path (Exec_Name);
347       begin
348          if Path = null then
349             return "";
350          else
351             declare
352                Dir : constant String := Get_Install_Dir (Path.all);
353             begin
354                Free (Path);
355                return Dir;
356             end;
357          end if;
358       end;
359    end Executable_Prefix_Path;
360
361    --------------------------
362    -- File_Not_A_Source_Of --
363    --------------------------
364
365    function File_Not_A_Source_Of
366      (Uname : Name_Id;
367       Sfile : File_Name_Type) return Boolean
368    is
369       Unit : constant Unit_Index :=
370                Units_Htable.Get (Project_Tree.Units_HT, Uname);
371
372       At_Least_One_File : Boolean := False;
373
374    begin
375       if Unit /= No_Unit_Index then
376          for F in Unit.File_Names'Range loop
377             if Unit.File_Names (F) /= null then
378                At_Least_One_File := True;
379                if Unit.File_Names (F).File = Sfile then
380                   return False;
381                end if;
382             end if;
383          end loop;
384
385          if not At_Least_One_File then
386
387             --  The unit was probably created initially for a separate unit
388             --  (which are initially created as IMPL when both suffixes are the
389             --  same). Later on, Override_Kind changed the type of the file,
390             --  and the unit is no longer valid in fact.
391
392             return False;
393          end if;
394
395          Verbose_Msg (Uname, "sources do not include ", Name_Id (Sfile));
396          return True;
397       end if;
398
399       return False;
400    end File_Not_A_Source_Of;
401
402    ----------
403    -- Hash --
404    ----------
405
406    function Hash (Key : Mark_Key) return Mark_Num is
407    begin
408       return Union_Id (Key.File) mod Max_Mask_Num;
409    end Hash;
410
411    ------------
412    -- Inform --
413    ------------
414
415    procedure Inform (N : File_Name_Type; Msg : String) is
416    begin
417       Inform (Name_Id (N), Msg);
418    end Inform;
419
420    procedure Inform (N : Name_Id := No_Name; Msg : String) is
421    begin
422       Osint.Write_Program_Name;
423
424       Write_Str (": ");
425
426       if N /= No_Name then
427          Write_Str ("""");
428
429          declare
430             Name : constant String := Get_Name_String (N);
431          begin
432             if Debug.Debug_Flag_F and then Is_Absolute_Path (Name) then
433                Write_Str (File_Name (Name));
434             else
435                Write_Str (Name);
436             end if;
437          end;
438
439          Write_Str (""" ");
440       end if;
441
442       Write_Str (Msg);
443       Write_Eol;
444    end Inform;
445
446    ----------------------------
447    -- Is_External_Assignment --
448    ----------------------------
449
450    function Is_External_Assignment (Argv : String) return Boolean is
451       Start     : Positive := 3;
452       Finish    : Natural := Argv'Last;
453       Equal_Pos : Natural;
454
455       pragma Assert (Argv'First = 1);
456       pragma Assert (Argv (1 .. 2) = "-X");
457
458    begin
459       if Argv'Last < 5 then
460          return False;
461
462       elsif Argv (3) = '"' then
463          if Argv (Argv'Last) /= '"' or else Argv'Last < 7 then
464             return False;
465          else
466             Start := 4;
467             Finish := Argv'Last - 1;
468          end if;
469       end if;
470
471       Equal_Pos := Start;
472
473       while Equal_Pos <= Finish and then Argv (Equal_Pos) /= '=' loop
474          Equal_Pos := Equal_Pos + 1;
475       end loop;
476
477       if Equal_Pos = Start or else Equal_Pos > Finish then
478          return False;
479       else
480          Prj.Ext.Add
481            (External_Name => Argv (Start .. Equal_Pos - 1),
482             Value         => Argv (Equal_Pos + 1 .. Finish));
483          return True;
484       end if;
485    end Is_External_Assignment;
486
487    ---------------
488    -- Is_Marked --
489    ---------------
490
491    function Is_Marked
492      (Source_File : File_Name_Type;
493       Index       : Int := 0) return Boolean
494    is
495    begin
496       return Marks.Get (K => (File => Source_File, Index => Index));
497    end Is_Marked;
498
499    -----------------------------
500    -- Linker_Options_Switches --
501    -----------------------------
502
503    function Linker_Options_Switches
504      (Project  : Project_Id;
505       In_Tree  : Project_Tree_Ref) return String_List
506    is
507       procedure Recursive_Add (Proj : Project_Id; Dummy : in out Boolean);
508       --  The recursive routine used to add linker options
509
510       -------------------
511       -- Recursive_Add --
512       -------------------
513
514       procedure Recursive_Add (Proj : Project_Id; Dummy : in out Boolean) is
515          pragma Unreferenced (Dummy);
516
517          Linker_Package : Package_Id;
518          Options        : Variable_Value;
519
520       begin
521          Linker_Package :=
522            Prj.Util.Value_Of
523              (Name        => Name_Linker,
524               In_Packages => Proj.Decl.Packages,
525               In_Tree     => In_Tree);
526
527          Options :=
528            Prj.Util.Value_Of
529              (Name                    => Name_Ada,
530               Index                   => 0,
531               Attribute_Or_Array_Name => Name_Linker_Options,
532               In_Package              => Linker_Package,
533               In_Tree                 => In_Tree);
534
535          --  If attribute is present, add the project with
536          --  the attribute to table Linker_Opts.
537
538          if Options /= Nil_Variable_Value then
539             Linker_Opts.Increment_Last;
540             Linker_Opts.Table (Linker_Opts.Last) :=
541               (Project => Proj, Options => Options.Values);
542          end if;
543       end Recursive_Add;
544
545       procedure For_All_Projects is
546         new For_Every_Project_Imported (Boolean, Recursive_Add);
547
548       Dummy : Boolean := False;
549
550    --  Start of processing for Linker_Options_Switches
551
552    begin
553       Linker_Opts.Init;
554
555       For_All_Projects (Project, Dummy, Imported_First => True);
556
557       Last_Linker_Option := 0;
558
559       for Index in reverse 1 .. Linker_Opts.Last loop
560          declare
561             Options : String_List_Id;
562             Proj    : constant Project_Id :=
563                         Linker_Opts.Table (Index).Project;
564             Option  : Name_Id;
565             Dir_Path : constant String :=
566                          Get_Name_String (Proj.Directory.Name);
567
568          begin
569             Options := Linker_Opts.Table (Index).Options;
570             while Options /= Nil_String loop
571                Option := In_Tree.String_Elements.Table (Options).Value;
572                Get_Name_String (Option);
573
574                --  Do not consider empty linker options
575
576                if Name_Len /= 0 then
577                   Add_Linker_Option (Name_Buffer (1 .. Name_Len));
578
579                   --  Object files and -L switches specified with relative
580                   --  paths must be converted to absolute paths.
581
582                   Test_If_Relative_Path
583                     (Switch => Linker_Options_Buffer (Last_Linker_Option),
584                      Parent => Dir_Path,
585                      Including_L_Switch => True);
586                end if;
587
588                Options := In_Tree.String_Elements.Table (Options).Next;
589             end loop;
590          end;
591       end loop;
592
593       return Linker_Options_Buffer (1 .. Last_Linker_Option);
594    end Linker_Options_Switches;
595
596    -----------
597    -- Mains --
598    -----------
599
600    package body Mains is
601
602       type File_And_Loc is record
603          File_Name : File_Name_Type;
604          Location  : Source_Ptr := No_Location;
605       end record;
606
607       package Names is new Table.Table
608         (Table_Component_Type => File_And_Loc,
609          Table_Index_Type     => Integer,
610          Table_Low_Bound      => 1,
611          Table_Initial        => 10,
612          Table_Increment      => 100,
613          Table_Name           => "Makeutl.Mains.Names");
614       --  The table that stores the mains
615
616       Current : Natural := 0;
617       --  The index of the last main retrieved from the table
618
619       --------------
620       -- Add_Main --
621       --------------
622
623       procedure Add_Main (Name : String) is
624       begin
625          Name_Len := 0;
626          Add_Str_To_Name_Buffer (Name);
627          Names.Increment_Last;
628          Names.Table (Names.Last) := (Name_Find, No_Location);
629       end Add_Main;
630
631       ------------
632       -- Delete --
633       ------------
634
635       procedure Delete is
636       begin
637          Names.Set_Last (0);
638          Mains.Reset;
639       end Delete;
640
641       ------------------
642       -- Get_Location --
643       ------------------
644
645       function Get_Location return Source_Ptr is
646       begin
647          if Current in Names.First .. Names.Last then
648             return Names.Table (Current).Location;
649          else
650             return No_Location;
651          end if;
652       end Get_Location;
653
654       ---------------
655       -- Next_Main --
656       ---------------
657
658       function Next_Main return String is
659       begin
660          if Current >= Names.Last then
661             return "";
662          else
663             Current := Current + 1;
664             return Get_Name_String (Names.Table (Current).File_Name);
665          end if;
666       end Next_Main;
667
668       ---------------------
669       -- Number_Of_Mains --
670       ---------------------
671
672       function Number_Of_Mains return Natural is
673       begin
674          return Names.Last;
675       end Number_Of_Mains;
676
677       -----------
678       -- Reset --
679       -----------
680
681       procedure Reset is
682       begin
683          Current := 0;
684       end Reset;
685
686       ------------------
687       -- Set_Location --
688       ------------------
689
690       procedure Set_Location (Location : Source_Ptr) is
691       begin
692          if Names.Last > 0 then
693             Names.Table (Names.Last).Location := Location;
694          end if;
695       end Set_Location;
696
697       -----------------
698       -- Update_Main --
699       -----------------
700
701       procedure Update_Main (Name : String) is
702       begin
703          if Current in Names.First .. Names.Last then
704             Name_Len := 0;
705             Add_Str_To_Name_Buffer (Name);
706             Names.Table (Current).File_Name := Name_Find;
707          end if;
708       end Update_Main;
709    end Mains;
710
711    ----------
712    -- Mark --
713    ----------
714
715    procedure Mark (Source_File : File_Name_Type; Index : Int := 0) is
716    begin
717       Marks.Set (K => (File => Source_File, Index => Index), E => True);
718    end Mark;
719
720    -----------------------
721    -- Path_Or_File_Name --
722    -----------------------
723
724    function Path_Or_File_Name (Path : Path_Name_Type) return String is
725       Path_Name : constant String := Get_Name_String (Path);
726    begin
727       if Debug.Debug_Flag_F then
728          return File_Name (Path_Name);
729       else
730          return Path_Name;
731       end if;
732    end Path_Or_File_Name;
733
734    ---------------------------
735    -- Test_If_Relative_Path --
736    ---------------------------
737
738    procedure Test_If_Relative_Path
739      (Switch               : in out String_Access;
740       Parent               : String;
741       Including_L_Switch   : Boolean := True;
742       Including_Non_Switch : Boolean := True;
743       Including_RTS        : Boolean := False)
744    is
745    begin
746       if Switch /= null then
747          declare
748             Sw    : String (1 .. Switch'Length);
749             Start : Positive;
750
751          begin
752             Sw := Switch.all;
753
754             if Sw (1) = '-' then
755                if Sw'Length >= 3
756                  and then (Sw (2) = 'A'
757                             or else Sw (2) = 'I'
758                             or else (Including_L_Switch and then Sw (2) = 'L'))
759                then
760                   Start := 3;
761
762                   if Sw = "-I-" then
763                      return;
764                   end if;
765
766                elsif Sw'Length >= 4
767                  and then (Sw (2 .. 3) = "aL"
768                             or else Sw (2 .. 3) = "aO"
769                             or else Sw (2 .. 3) = "aI")
770                then
771                   Start := 4;
772
773                elsif Including_RTS
774                  and then Sw'Length >= 7
775                  and then Sw (2 .. 6) = "-RTS="
776                then
777                   Start := 7;
778
779                else
780                   return;
781                end if;
782
783                --  Because relative path arguments to --RTS= may be relative
784                --  to the search directory prefix, those relative path
785                --  arguments are converted only when they include directory
786                --  information.
787
788                if not Is_Absolute_Path (Sw (Start .. Sw'Last)) then
789                   if Parent'Length = 0 then
790                      Do_Fail
791                        ("relative search path switches ("""
792                         & Sw
793                         & """) are not allowed");
794
795                   elsif Including_RTS then
796                      for J in Start .. Sw'Last loop
797                         if Sw (J) = Directory_Separator then
798                            Switch :=
799                              new String'
800                                (Sw (1 .. Start - 1) &
801                                 Parent &
802                                 Directory_Separator &
803                                 Sw (Start .. Sw'Last));
804                            return;
805                         end if;
806                      end loop;
807
808                   else
809                      Switch :=
810                        new String'
811                          (Sw (1 .. Start - 1) &
812                           Parent &
813                           Directory_Separator &
814                           Sw (Start .. Sw'Last));
815                   end if;
816                end if;
817
818             elsif Including_Non_Switch then
819                if not Is_Absolute_Path (Sw) then
820                   if Parent'Length = 0 then
821                      Do_Fail
822                        ("relative paths (""" & Sw & """) are not allowed");
823                   else
824                      Switch := new String'(Parent & Directory_Separator & Sw);
825                   end if;
826                end if;
827             end if;
828          end;
829       end if;
830    end Test_If_Relative_Path;
831
832    -------------------
833    -- Unit_Index_Of --
834    -------------------
835
836    function Unit_Index_Of (ALI_File : File_Name_Type) return Int is
837       Start  : Natural;
838       Finish : Natural;
839       Result : Int := 0;
840
841    begin
842       Get_Name_String (ALI_File);
843
844       --  First, find the last dot
845
846       Finish := Name_Len;
847
848       while Finish >= 1 and then Name_Buffer (Finish) /= '.' loop
849          Finish := Finish - 1;
850       end loop;
851
852       if Finish = 1 then
853          return 0;
854       end if;
855
856       --  Now check that the dot is preceded by digits
857
858       Start := Finish;
859       Finish := Finish - 1;
860
861       while Start >= 1 and then Name_Buffer (Start - 1) in '0' .. '9' loop
862          Start := Start - 1;
863       end loop;
864
865       --  If there are no digits, or if the digits are not preceded by the
866       --  character that precedes a unit index, this is not the ALI file of
867       --  a unit in a multi-unit source.
868
869       if Start > Finish
870         or else Start = 1
871         or else Name_Buffer (Start - 1) /= Multi_Unit_Index_Character
872       then
873          return 0;
874       end if;
875
876       --  Build the index from the digit(s)
877
878       while Start <= Finish loop
879          Result := Result * 10 +
880                      Character'Pos (Name_Buffer (Start)) - Character'Pos ('0');
881          Start := Start + 1;
882       end loop;
883
884       return Result;
885    end Unit_Index_Of;
886
887    -----------------
888    -- Verbose_Msg --
889    -----------------
890
891    procedure Verbose_Msg
892      (N1                : Name_Id;
893       S1                : String;
894       N2                : Name_Id := No_Name;
895       S2                : String  := "";
896       Prefix            : String := "  -> ";
897       Minimum_Verbosity : Opt.Verbosity_Level_Type := Opt.Low)
898    is
899    begin
900       if not Opt.Verbose_Mode
901         or else Minimum_Verbosity > Opt.Verbosity_Level
902       then
903          return;
904       end if;
905
906       Write_Str (Prefix);
907       Write_Str ("""");
908       Write_Name (N1);
909       Write_Str (""" ");
910       Write_Str (S1);
911
912       if N2 /= No_Name then
913          Write_Str (" """);
914          Write_Name (N2);
915          Write_Str (""" ");
916       end if;
917
918       Write_Str (S2);
919       Write_Eol;
920    end Verbose_Msg;
921
922    procedure Verbose_Msg
923      (N1                : File_Name_Type;
924       S1                : String;
925       N2                : File_Name_Type := No_File;
926       S2                : String  := "";
927       Prefix            : String := "  -> ";
928       Minimum_Verbosity : Opt.Verbosity_Level_Type := Opt.Low)
929    is
930    begin
931       Verbose_Msg
932         (Name_Id (N1), S1, Name_Id (N2), S2, Prefix, Minimum_Verbosity);
933    end Verbose_Msg;
934
935 end Makeutl;