OSDN Git Service

2011-08-05 Yannick Moy <moy@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / warnsw.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                               W A R N S W                                --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --          Copyright (C) 1999-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 ------------------------------------------------------------------------------
25
26 with Opt; use Opt;
27
28 package body Warnsw is
29
30    ----------------------------
31    -- Set_Dot_Warning_Switch --
32    ----------------------------
33
34    function Set_Dot_Warning_Switch (C : Character) return Boolean is
35    begin
36       case C is
37          when 'a' =>
38             Warn_On_Assertion_Failure           := True;
39
40          when 'A' =>
41             Warn_On_Assertion_Failure           := False;
42
43          when 'b' =>
44             Warn_On_Biased_Representation       := True;
45
46          when 'B' =>
47             Warn_On_Biased_Representation       := False;
48
49          when 'c' =>
50             Warn_On_Unrepped_Components         := True;
51
52          when 'C' =>
53             Warn_On_Unrepped_Components         := False;
54
55          when 'e' =>
56             Address_Clause_Overlay_Warnings     := True;
57             Check_Unreferenced                  := True;
58             Check_Unreferenced_Formals          := True;
59             Check_Withs                         := True;
60             Constant_Condition_Warnings         := True;
61             Elab_Warnings                       := True;
62             Implementation_Unit_Warnings        := True;
63             Ineffective_Inline_Warnings         := True;
64             List_Inherited_Aspects              := True;
65             Warn_On_Ada_2005_Compatibility      := True;
66             Warn_On_Ada_2012_Compatibility      := True;
67             Warn_On_All_Unread_Out_Parameters   := True;
68             Warn_On_Assertion_Failure           := True;
69             Warn_On_Assumed_Low_Bound           := True;
70             Warn_On_Bad_Fixed_Value             := True;
71             Warn_On_Biased_Representation       := True;
72             Warn_On_Constant                    := True;
73             Warn_On_Deleted_Code                := True;
74             Warn_On_Dereference                 := True;
75             Warn_On_Export_Import               := True;
76             Warn_On_Hiding                      := True;
77             Warn_On_Modified_Unread             := True;
78             Warn_On_No_Value_Assigned           := True;
79             Warn_On_Non_Local_Exception         := True;
80             Warn_On_Object_Renames_Function     := True;
81             Warn_On_Obsolescent_Feature         := True;
82             Warn_On_Overlap                     := True;
83             Warn_On_Overridden_Size             := True;
84             Warn_On_Parameter_Order             := True;
85             Warn_On_Questionable_Missing_Parens := True;
86             Warn_On_Record_Holes                := True;
87             Warn_On_Redundant_Constructs        := True;
88             Warn_On_Reverse_Bit_Order           := True;
89             Warn_On_Unchecked_Conversion        := True;
90             Warn_On_Unordered_Enumeration_Type  := True;
91             Warn_On_Unrecognized_Pragma         := True;
92             Warn_On_Unrepped_Components         := True;
93             Warn_On_Warnings_Off                := True;
94
95          when 'g' =>
96             Set_GNAT_Mode_Warnings;
97
98          when 'h' =>
99             Warn_On_Record_Holes                := True;
100
101          when 'H' =>
102             Warn_On_Record_Holes                := False;
103
104          when 'i' =>
105             Warn_On_Overlap                     := True;
106
107          when 'I' =>
108             Warn_On_Overlap                     := False;
109
110          when 'l' =>
111             List_Inherited_Aspects              := True;
112
113          when 'L' =>
114             List_Inherited_Aspects              := False;
115
116          when 'm' =>
117             Warn_On_Suspicious_Modulus_Value    := True;
118
119          when 'M' =>
120             Warn_On_Suspicious_Modulus_Value    := False;
121
122          when 'o' =>
123             Warn_On_All_Unread_Out_Parameters   := True;
124
125          when 'O' =>
126             Warn_On_All_Unread_Out_Parameters   := False;
127
128          when 'p' =>
129             Warn_On_Parameter_Order             := True;
130
131          when 'P' =>
132             Warn_On_Parameter_Order             := False;
133
134          when 'r' =>
135             Warn_On_Object_Renames_Function     := True;
136
137          when 'R' =>
138             Warn_On_Object_Renames_Function     := False;
139
140          when 's' =>
141             Warn_On_Overridden_Size             := True;
142
143          when 'S' =>
144             Warn_On_Overridden_Size             := False;
145
146          when 'u' =>
147             Warn_On_Unordered_Enumeration_Type  := True;
148
149          when 'U' =>
150             Warn_On_Unordered_Enumeration_Type  := False;
151
152          when 'v' =>
153             Warn_On_Reverse_Bit_Order           := True;
154
155          when 'V' =>
156             Warn_On_Reverse_Bit_Order           := False;
157
158          when 'w' =>
159             Warn_On_Warnings_Off                := True;
160
161          when 'W' =>
162             Warn_On_Warnings_Off                := False;
163
164          when 'x' =>
165             Warn_On_Non_Local_Exception         := True;
166
167          when 'X' =>
168             Warn_On_Non_Local_Exception         := False;
169             No_Warn_On_Non_Local_Exception      := True;
170
171          when others =>
172             return False;
173       end case;
174
175       return True;
176    end Set_Dot_Warning_Switch;
177
178    ----------------------------
179    -- Set_GNAT_Mode_Warnings --
180    ----------------------------
181
182    procedure Set_GNAT_Mode_Warnings is
183    begin
184       Address_Clause_Overlay_Warnings     := True;
185       Check_Unreferenced                  := True;
186       Check_Unreferenced_Formals          := True;
187       Check_Withs                         := True;
188       Constant_Condition_Warnings         := True;
189       Elab_Warnings                       := False;
190       Implementation_Unit_Warnings        := False;
191       Ineffective_Inline_Warnings         := True;
192       List_Inherited_Aspects              := False;
193       Warn_On_Ada_2005_Compatibility      := True;
194       Warn_On_Ada_2012_Compatibility      := True;
195       Warn_On_All_Unread_Out_Parameters   := False;
196       Warn_On_Assertion_Failure           := True;
197       Warn_On_Assumed_Low_Bound           := True;
198       Warn_On_Bad_Fixed_Value             := True;
199       Warn_On_Biased_Representation       := True;
200       Warn_On_Constant                    := True;
201       Warn_On_Deleted_Code                := False;
202       Warn_On_Dereference                 := False;
203       Warn_On_Export_Import               := True;
204       Warn_On_Hiding                      := False;
205       Warn_On_Modified_Unread             := True;
206       Warn_On_No_Value_Assigned           := True;
207       Warn_On_Non_Local_Exception         := False;
208       Warn_On_Object_Renames_Function     := False;
209       Warn_On_Obsolescent_Feature         := True;
210       Warn_On_Questionable_Missing_Parens := True;
211       Warn_On_Redundant_Constructs        := True;
212       Warn_On_Reverse_Bit_Order           := False;
213       Warn_On_Object_Renames_Function     := True;
214       Warn_On_Unchecked_Conversion        := True;
215       Warn_On_Unordered_Enumeration_Type  := False;
216       Warn_On_Unrecognized_Pragma         := True;
217       Warn_On_Unrepped_Components         := False;
218       Warn_On_Warnings_Off                := False;
219    end Set_GNAT_Mode_Warnings;
220
221    ------------------------
222    -- Set_Warning_Switch --
223    ------------------------
224
225    function Set_Warning_Switch (C : Character) return Boolean is
226    begin
227       case C is
228          when 'a' =>
229             Check_Unreferenced                  := True;
230             Check_Unreferenced_Formals          := True;
231             Check_Withs                         := True;
232             Constant_Condition_Warnings         := True;
233             Implementation_Unit_Warnings        := True;
234             Ineffective_Inline_Warnings         := True;
235             List_Inherited_Aspects              := True;
236             Warn_On_Ada_2005_Compatibility      := True;
237             Warn_On_Ada_2012_Compatibility      := True;
238             Warn_On_Assertion_Failure           := True;
239             Warn_On_Assumed_Low_Bound           := True;
240             Warn_On_Bad_Fixed_Value             := True;
241             Warn_On_Biased_Representation       := True;
242             Warn_On_Constant                    := True;
243             Warn_On_Export_Import               := True;
244             Warn_On_Modified_Unread             := True;
245             Warn_On_No_Value_Assigned           := True;
246             Warn_On_Non_Local_Exception         := True;
247             Warn_On_Object_Renames_Function     := True;
248             Warn_On_Obsolescent_Feature         := True;
249             Warn_On_Parameter_Order             := True;
250             Warn_On_Questionable_Missing_Parens := True;
251             Warn_On_Redundant_Constructs        := True;
252             Warn_On_Reverse_Bit_Order           := True;
253             Warn_On_Unchecked_Conversion        := True;
254             Warn_On_Unrecognized_Pragma         := True;
255             Warn_On_Unrepped_Components         := True;
256
257          when 'A' =>
258             Address_Clause_Overlay_Warnings     := False;
259             Check_Unreferenced                  := False;
260             Check_Unreferenced_Formals          := False;
261             Check_Withs                         := False;
262             Constant_Condition_Warnings         := False;
263             Elab_Warnings                       := False;
264             Implementation_Unit_Warnings        := False;
265             Ineffective_Inline_Warnings         := False;
266             List_Inherited_Aspects              := False;
267             Warn_On_Ada_2005_Compatibility      := False;
268             Warn_On_Ada_2012_Compatibility      := False;
269             Warn_On_All_Unread_Out_Parameters   := False;
270             Warn_On_Assertion_Failure           := False;
271             Warn_On_Assumed_Low_Bound           := False;
272             Warn_On_Bad_Fixed_Value             := False;
273             Warn_On_Biased_Representation       := False;
274             Warn_On_Constant                    := False;
275             Warn_On_Deleted_Code                := False;
276             Warn_On_Dereference                 := False;
277             Warn_On_Export_Import               := False;
278             Warn_On_Hiding                      := False;
279             Warn_On_Modified_Unread             := False;
280             Warn_On_No_Value_Assigned           := False;
281             Warn_On_Non_Local_Exception         := False;
282             Warn_On_Object_Renames_Function     := False;
283             Warn_On_Obsolescent_Feature         := False;
284             Warn_On_Overlap                     := False;
285             Warn_On_Overridden_Size             := False;
286             Warn_On_Parameter_Order             := False;
287             Warn_On_Record_Holes                := False;
288             Warn_On_Questionable_Missing_Parens := False;
289             Warn_On_Redundant_Constructs        := False;
290             Warn_On_Reverse_Bit_Order           := False;
291             Warn_On_Unchecked_Conversion        := False;
292             Warn_On_Unordered_Enumeration_Type  := False;
293             Warn_On_Unrecognized_Pragma         := False;
294             Warn_On_Unrepped_Components         := False;
295             Warn_On_Warnings_Off                := False;
296
297             No_Warn_On_Non_Local_Exception      := True;
298
299          when 'b' =>
300             Warn_On_Bad_Fixed_Value             := True;
301
302          when 'B' =>
303             Warn_On_Bad_Fixed_Value             := False;
304
305          when 'c' =>
306             Constant_Condition_Warnings         := True;
307
308          when 'C' =>
309             Constant_Condition_Warnings         := False;
310
311          when 'd' =>
312             Warn_On_Dereference                 := True;
313
314          when 'D' =>
315             Warn_On_Dereference                 := False;
316
317          when 'e' =>
318             Warning_Mode                        := Treat_As_Error;
319
320          when 'f' =>
321             Check_Unreferenced_Formals          := True;
322
323          when 'F' =>
324             Check_Unreferenced_Formals          := False;
325
326          when 'g' =>
327             Warn_On_Unrecognized_Pragma         := True;
328
329          when 'G' =>
330             Warn_On_Unrecognized_Pragma         := False;
331
332          when 'h' =>
333             Warn_On_Hiding                      := True;
334
335          when 'H' =>
336             Warn_On_Hiding                      := False;
337
338          when 'i' =>
339             Implementation_Unit_Warnings        := True;
340
341          when 'I' =>
342             Implementation_Unit_Warnings        := False;
343
344          when 'j' =>
345             Warn_On_Obsolescent_Feature         := True;
346
347          when 'J' =>
348             Warn_On_Obsolescent_Feature         := False;
349
350          when 'k' =>
351             Warn_On_Constant                    := True;
352
353          when 'K' =>
354             Warn_On_Constant                    := False;
355
356          when 'l' =>
357             Elab_Warnings                       := True;
358
359          when 'L' =>
360             Elab_Warnings                       := False;
361
362          when 'm' =>
363             Warn_On_Modified_Unread             := True;
364
365          when 'M' =>
366             Warn_On_Modified_Unread             := False;
367
368          when 'n' =>
369             Warning_Mode                        := Normal;
370
371          when 'o' =>
372             Address_Clause_Overlay_Warnings     := True;
373
374          when 'O' =>
375             Address_Clause_Overlay_Warnings     := False;
376
377          when 'p' =>
378             Ineffective_Inline_Warnings         := True;
379
380          when 'P' =>
381             Ineffective_Inline_Warnings         := False;
382
383          when 'q' =>
384             Warn_On_Questionable_Missing_Parens := True;
385
386          when 'Q' =>
387             Warn_On_Questionable_Missing_Parens := False;
388
389          when 'r' =>
390             Warn_On_Redundant_Constructs        := True;
391
392          when 'R' =>
393             Warn_On_Redundant_Constructs        := False;
394
395          when 's' =>
396             Warning_Mode                        := Suppress;
397
398          when 't' =>
399             Warn_On_Deleted_Code                := True;
400
401          when 'T' =>
402             Warn_On_Deleted_Code                := False;
403
404          when 'u' =>
405             Check_Unreferenced                  := True;
406             Check_Withs                         := True;
407             Check_Unreferenced_Formals          := True;
408
409          when 'U' =>
410             Check_Unreferenced                  := False;
411             Check_Withs                         := False;
412             Check_Unreferenced_Formals          := False;
413
414          when 'v' =>
415             Warn_On_No_Value_Assigned           := True;
416
417          when 'V' =>
418             Warn_On_No_Value_Assigned           := False;
419
420          when 'w' =>
421             Warn_On_Assumed_Low_Bound           := True;
422
423          when 'W' =>
424             Warn_On_Assumed_Low_Bound           := False;
425
426          when 'x' =>
427             Warn_On_Export_Import               := True;
428
429          when 'X' =>
430             Warn_On_Export_Import               := False;
431
432          when 'y' =>
433             Warn_On_Ada_2005_Compatibility      := True;
434             Warn_On_Ada_2012_Compatibility      := True;
435
436          when 'Y' =>
437             Warn_On_Ada_2005_Compatibility      := False;
438             Warn_On_Ada_2012_Compatibility      := False;
439
440          when 'z' =>
441             Warn_On_Unchecked_Conversion        := True;
442
443          when 'Z' =>
444             Warn_On_Unchecked_Conversion        := False;
445
446          when others =>
447             return False;
448       end case;
449
450       return True;
451    end Set_Warning_Switch;
452
453 end Warnsw;