* ChangeLog: Repair from previous update.
[platform/upstream/gcc.git] / gcc / ada / binderr.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                              B I N D E R R                               --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --                            $Revision: 1.22 $
10 --                                                                          --
11 --          Copyright (C) 1992-2000 Free Software Foundation, Inc.          --
12 --                                                                          --
13 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
14 -- terms of the  GNU General Public License as published  by the Free Soft- --
15 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
16 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
19 -- for  more details.  You should have  received  a copy of the GNU General --
20 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
21 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
22 -- MA 02111-1307, USA.                                                      --
23 --                                                                          --
24 -- GNAT was originally developed  by the GNAT team at  New York University. --
25 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
26 --                                                                          --
27 ------------------------------------------------------------------------------
28
29 with Butil;   use Butil;
30 with Namet;   use Namet;
31 with Opt;     use Opt;
32 with Output;  use Output;
33
34 package body Binderr is
35
36    ---------------
37    -- Error_Msg --
38    ---------------
39
40    procedure Error_Msg (Msg : String) is
41    begin
42       if Msg (Msg'First) = '?' then
43          if Warning_Mode = Suppress then
44             return;
45          end if;
46
47          if Warning_Mode = Treat_As_Error then
48             Errors_Detected := Errors_Detected + 1;
49          else
50             Warnings_Detected := Warnings_Detected + 1;
51          end if;
52
53       else
54          Errors_Detected := Errors_Detected + 1;
55       end if;
56
57       if Brief_Output or else (not Verbose_Mode) then
58          Set_Standard_Error;
59          Error_Msg_Output (Msg, Info => False);
60          Set_Standard_Output;
61       end if;
62
63       if Verbose_Mode then
64          if Errors_Detected + Warnings_Detected = 0 then
65             Write_Eol;
66          end if;
67
68          Error_Msg_Output (Msg, Info => False);
69       end if;
70
71       if Warnings_Detected + Errors_Detected > Maximum_Errors then
72          raise Unrecoverable_Error;
73       end if;
74
75    end Error_Msg;
76
77    --------------------
78    -- Error_Msg_Info --
79    --------------------
80
81    procedure Error_Msg_Info (Msg : String) is
82    begin
83       if Brief_Output or else (not Verbose_Mode) then
84          Set_Standard_Error;
85          Error_Msg_Output (Msg, Info => True);
86          Set_Standard_Output;
87       end if;
88
89       if Verbose_Mode then
90          Error_Msg_Output (Msg, Info => True);
91       end if;
92
93    end Error_Msg_Info;
94
95    ----------------------
96    -- Error_Msg_Output --
97    ----------------------
98
99    procedure Error_Msg_Output (Msg : String; Info : Boolean) is
100       Use_Second_Name : Boolean := False;
101
102    begin
103       if Warnings_Detected + Errors_Detected > Maximum_Errors then
104          Write_Str ("error: maximum errors exceeded");
105          Write_Eol;
106          return;
107       end if;
108
109       if Msg (Msg'First) = '?' then
110          Write_Str ("warning: ");
111       elsif Info then
112          if not Info_Prefix_Suppress then
113             Write_Str ("info:  ");
114          end if;
115       else
116          Write_Str ("error: ");
117       end if;
118
119       for I in Msg'Range loop
120          if Msg (I) = '%' then
121
122             if Use_Second_Name then
123                Get_Name_String (Error_Msg_Name_2);
124             else
125                Use_Second_Name := True;
126                Get_Name_String (Error_Msg_Name_1);
127             end if;
128
129             Write_Char ('"');
130             Write_Str (Name_Buffer (1 .. Name_Len));
131             Write_Char ('"');
132
133          elsif Msg (I) = '&' then
134             Write_Char ('"');
135
136             if Use_Second_Name then
137                Write_Unit_Name (Error_Msg_Name_2);
138             else
139                Use_Second_Name := True;
140                Write_Unit_Name (Error_Msg_Name_1);
141             end if;
142
143             Write_Char ('"');
144
145          elsif Msg (I) /= '?' then
146             Write_Char (Msg (I));
147          end if;
148       end loop;
149
150       Write_Eol;
151    end Error_Msg_Output;
152
153    ----------------------
154    -- Finalize_Binderr --
155    ----------------------
156
157    procedure Finalize_Binderr is
158    begin
159       --  Message giving number of errors detected (verbose mode only)
160
161       if Verbose_Mode then
162          Write_Eol;
163
164          if Errors_Detected = 0 then
165             Write_Str ("No errors");
166
167          elsif Errors_Detected = 1 then
168             Write_Str ("1 error");
169
170          else
171             Write_Int (Errors_Detected);
172             Write_Str (" errors");
173          end if;
174
175          if Warnings_Detected = 1 then
176             Write_Str (", 1 warning");
177
178          elsif Warnings_Detected > 1 then
179             Write_Str (", ");
180             Write_Int (Warnings_Detected);
181             Write_Str (" warnings");
182          end if;
183
184          Write_Eol;
185       end if;
186    end Finalize_Binderr;
187
188    ------------------------
189    -- Initialize_Binderr --
190    ------------------------
191
192    procedure Initialize_Binderr is
193    begin
194       Errors_Detected := 0;
195       Warnings_Detected := 0;
196    end Initialize_Binderr;
197
198 end Binderr;