2014-12-12 Marc Glisse <marc.glisse@inria.fr>
[official-gcc.git] / gcc / ada / warnsw.adb
blob10b60a8f779935b8ae74470184febe433bfb9ee4
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-2014, 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 Err_Vars; use Err_Vars;
27 with Opt; use Opt;
28 with Output; use Output;
30 package body Warnsw is
32 -- Local Subprograms
34 procedure All_Warnings (Setting : Boolean);
35 -- Sets all warnings off if Setting = False, and on if Setting = True
37 procedure WA_Warnings;
38 -- Turn on all warnings set by -gnatwa (also used by -gnatw.g)
40 ------------------
41 -- All_Warnings --
42 ------------------
44 procedure All_Warnings (Setting : Boolean) is
45 begin
46 Address_Clause_Overlay_Warnings := Setting;
47 Check_Unreferenced := Setting;
48 Check_Unreferenced_Formals := Setting;
49 Check_Withs := Setting;
50 Constant_Condition_Warnings := Setting;
51 Elab_Warnings := Setting;
52 Implementation_Unit_Warnings := Setting;
53 Ineffective_Inline_Warnings := Setting;
54 List_Body_Required_Info := Setting;
55 List_Inherited_Aspects := Setting;
56 Warn_On_Ada_2005_Compatibility := Setting;
57 Warn_On_Ada_2012_Compatibility := Setting;
58 Warn_On_All_Unread_Out_Parameters := Setting;
59 Warn_On_Assertion_Failure := Setting;
60 Warn_On_Assumed_Low_Bound := Setting;
61 Warn_On_Atomic_Synchronization := Setting;
62 Warn_On_Bad_Fixed_Value := Setting;
63 Warn_On_Biased_Representation := Setting;
64 Warn_On_Constant := Setting;
65 Warn_On_Deleted_Code := Setting;
66 Warn_On_Dereference := Setting;
67 Warn_On_Export_Import := Setting;
68 Warn_On_Hiding := Setting;
69 Warn_On_Modified_Unread := Setting;
70 Warn_On_No_Value_Assigned := Setting;
71 Warn_On_Non_Local_Exception := Setting;
72 Warn_On_Object_Renames_Function := Setting;
73 Warn_On_Obsolescent_Feature := Setting;
74 Warn_On_Overlap := Setting;
75 Warn_On_Overridden_Size := Setting;
76 Warn_On_Parameter_Order := Setting;
77 Warn_On_Questionable_Missing_Parens := Setting;
78 Warn_On_Record_Holes := Setting;
79 Warn_On_Redundant_Constructs := Setting;
80 Warn_On_Reverse_Bit_Order := Setting;
81 Warn_On_Size_Alignment := Setting;
82 Warn_On_Standard_Redefinition := Setting;
83 Warn_On_Suspicious_Contract := Setting;
84 Warn_On_Suspicious_Modulus_Value := Setting;
85 Warn_On_Unchecked_Conversion := Setting;
86 Warn_On_Unordered_Enumeration_Type := Setting;
87 Warn_On_Unrecognized_Pragma := Setting;
88 Warn_On_Unrepped_Components := Setting;
89 Warn_On_Warnings_Off := Setting;
90 end All_Warnings;
92 ----------------------
93 -- Restore_Warnings --
94 ----------------------
96 procedure Restore_Warnings (W : Warning_Record) is
97 begin
98 Address_Clause_Overlay_Warnings :=
99 W.Address_Clause_Overlay_Warnings;
100 Check_Unreferenced :=
101 W.Check_Unreferenced;
102 Check_Unreferenced_Formals :=
103 W.Check_Unreferenced_Formals;
104 Check_Withs :=
105 W.Check_Withs;
106 Constant_Condition_Warnings :=
107 W.Constant_Condition_Warnings;
108 Elab_Warnings :=
109 W.Elab_Warnings;
110 Elab_Info_Messages :=
111 W.Elab_Info_Messages;
112 Implementation_Unit_Warnings :=
113 W.Implementation_Unit_Warnings;
114 Ineffective_Inline_Warnings :=
115 W.Ineffective_Inline_Warnings;
116 List_Body_Required_Info :=
117 W.List_Body_Required_Info;
118 List_Inherited_Aspects :=
119 W.List_Inherited_Aspects;
120 No_Warn_On_Non_Local_Exception :=
121 W.No_Warn_On_Non_Local_Exception;
122 Warning_Doc_Switch :=
123 W.Warning_Doc_Switch;
124 Warn_On_Ada_2005_Compatibility :=
125 W.Warn_On_Ada_2005_Compatibility;
126 Warn_On_Ada_2012_Compatibility :=
127 W.Warn_On_Ada_2012_Compatibility;
128 Warn_On_All_Unread_Out_Parameters :=
129 W.Warn_On_All_Unread_Out_Parameters;
130 Warn_On_Assertion_Failure :=
131 W.Warn_On_Assertion_Failure;
132 Warn_On_Assumed_Low_Bound :=
133 W.Warn_On_Assumed_Low_Bound;
134 Warn_On_Atomic_Synchronization :=
135 W.Warn_On_Atomic_Synchronization;
136 Warn_On_Bad_Fixed_Value :=
137 W.Warn_On_Bad_Fixed_Value;
138 Warn_On_Biased_Representation :=
139 W.Warn_On_Biased_Representation;
140 Warn_On_Constant :=
141 W.Warn_On_Constant;
142 Warn_On_Deleted_Code :=
143 W.Warn_On_Deleted_Code;
144 Warn_On_Dereference :=
145 W.Warn_On_Dereference;
146 Warn_On_Export_Import :=
147 W.Warn_On_Export_Import;
148 Warn_On_Hiding :=
149 W.Warn_On_Hiding;
150 Warn_On_Modified_Unread :=
151 W.Warn_On_Modified_Unread;
152 Warn_On_No_Value_Assigned :=
153 W.Warn_On_No_Value_Assigned;
154 Warn_On_Non_Local_Exception :=
155 W.Warn_On_Non_Local_Exception;
156 Warn_On_Object_Renames_Function :=
157 W.Warn_On_Object_Renames_Function;
158 Warn_On_Obsolescent_Feature :=
159 W.Warn_On_Obsolescent_Feature;
160 Warn_On_Overlap :=
161 W.Warn_On_Overlap;
162 Warn_On_Overridden_Size :=
163 W.Warn_On_Overridden_Size;
164 Warn_On_Parameter_Order :=
165 W.Warn_On_Parameter_Order;
166 Warn_On_Questionable_Missing_Parens :=
167 W.Warn_On_Questionable_Missing_Parens;
168 Warn_On_Record_Holes :=
169 W.Warn_On_Record_Holes;
170 Warn_On_Redundant_Constructs :=
171 W.Warn_On_Redundant_Constructs;
172 Warn_On_Reverse_Bit_Order :=
173 W.Warn_On_Reverse_Bit_Order;
174 Warn_On_Size_Alignment :=
175 W.Warn_On_Size_Alignment;
176 Warn_On_Standard_Redefinition :=
177 W.Warn_On_Standard_Redefinition;
178 Warn_On_Suspicious_Contract :=
179 W.Warn_On_Suspicious_Contract;
180 Warn_On_Unchecked_Conversion :=
181 W.Warn_On_Unchecked_Conversion;
182 Warn_On_Unordered_Enumeration_Type :=
183 W.Warn_On_Unordered_Enumeration_Type;
184 Warn_On_Unrecognized_Pragma :=
185 W.Warn_On_Unrecognized_Pragma;
186 Warn_On_Unrepped_Components :=
187 W.Warn_On_Unrepped_Components;
188 Warn_On_Warnings_Off :=
189 W.Warn_On_Warnings_Off;
190 end Restore_Warnings;
192 -------------------
193 -- Save_Warnings --
194 -------------------
196 function Save_Warnings return Warning_Record is
197 W : Warning_Record;
199 begin
200 W.Address_Clause_Overlay_Warnings :=
201 Address_Clause_Overlay_Warnings;
202 W.Check_Unreferenced :=
203 Check_Unreferenced;
204 W.Check_Unreferenced_Formals :=
205 Check_Unreferenced_Formals;
206 W.Check_Withs :=
207 Check_Withs;
208 W.Constant_Condition_Warnings :=
209 Constant_Condition_Warnings;
210 W.Elab_Info_Messages :=
211 Elab_Info_Messages;
212 W.Elab_Warnings :=
213 Elab_Warnings;
214 W.Implementation_Unit_Warnings :=
215 Implementation_Unit_Warnings;
216 W.Ineffective_Inline_Warnings :=
217 Ineffective_Inline_Warnings;
218 W.List_Body_Required_Info :=
219 List_Body_Required_Info;
220 W.List_Inherited_Aspects :=
221 List_Inherited_Aspects;
222 W.No_Warn_On_Non_Local_Exception :=
223 No_Warn_On_Non_Local_Exception;
224 W.Warning_Doc_Switch :=
225 Warning_Doc_Switch;
226 W.Warn_On_Ada_2005_Compatibility :=
227 Warn_On_Ada_2005_Compatibility;
228 W.Warn_On_Ada_2012_Compatibility :=
229 Warn_On_Ada_2012_Compatibility;
230 W.Warn_On_All_Unread_Out_Parameters :=
231 Warn_On_All_Unread_Out_Parameters;
232 W.Warn_On_Assertion_Failure :=
233 Warn_On_Assertion_Failure;
234 W.Warn_On_Assumed_Low_Bound :=
235 Warn_On_Assumed_Low_Bound;
236 W.Warn_On_Atomic_Synchronization :=
237 Warn_On_Atomic_Synchronization;
238 W.Warn_On_Bad_Fixed_Value :=
239 Warn_On_Bad_Fixed_Value;
240 W.Warn_On_Biased_Representation :=
241 Warn_On_Biased_Representation;
242 W.Warn_On_Constant :=
243 Warn_On_Constant;
244 W.Warn_On_Deleted_Code :=
245 Warn_On_Deleted_Code;
246 W.Warn_On_Dereference :=
247 Warn_On_Dereference;
248 W.Warn_On_Export_Import :=
249 Warn_On_Export_Import;
250 W.Warn_On_Hiding :=
251 Warn_On_Hiding;
252 W.Warn_On_Modified_Unread :=
253 Warn_On_Modified_Unread;
254 W.Warn_On_No_Value_Assigned :=
255 Warn_On_No_Value_Assigned;
256 W.Warn_On_Non_Local_Exception :=
257 Warn_On_Non_Local_Exception;
258 W.Warn_On_Object_Renames_Function :=
259 Warn_On_Object_Renames_Function;
260 W.Warn_On_Obsolescent_Feature :=
261 Warn_On_Obsolescent_Feature;
262 W.Warn_On_Overlap :=
263 Warn_On_Overlap;
264 W.Warn_On_Overridden_Size :=
265 Warn_On_Overridden_Size;
266 W.Warn_On_Parameter_Order :=
267 Warn_On_Parameter_Order;
268 W.Warn_On_Questionable_Missing_Parens :=
269 Warn_On_Questionable_Missing_Parens;
270 W.Warn_On_Record_Holes :=
271 Warn_On_Record_Holes;
272 W.Warn_On_Redundant_Constructs :=
273 Warn_On_Redundant_Constructs;
274 W.Warn_On_Reverse_Bit_Order :=
275 Warn_On_Reverse_Bit_Order;
276 W.Warn_On_Size_Alignment :=
277 Warn_On_Size_Alignment;
278 W.Warn_On_Standard_Redefinition :=
279 Warn_On_Standard_Redefinition;
280 W.Warn_On_Suspicious_Contract :=
281 Warn_On_Suspicious_Contract;
282 W.Warn_On_Unchecked_Conversion :=
283 Warn_On_Unchecked_Conversion;
284 W.Warn_On_Unordered_Enumeration_Type :=
285 Warn_On_Unordered_Enumeration_Type;
286 W.Warn_On_Unrecognized_Pragma :=
287 Warn_On_Unrecognized_Pragma;
288 W.Warn_On_Unrepped_Components :=
289 Warn_On_Unrepped_Components;
290 W.Warn_On_Warnings_Off :=
291 Warn_On_Warnings_Off;
292 return W;
293 end Save_Warnings;
295 ----------------------------
296 -- Set_Dot_Warning_Switch --
297 ----------------------------
299 function Set_Dot_Warning_Switch (C : Character) return Boolean is
300 begin
301 case C is
302 when 'a' =>
303 Warn_On_Assertion_Failure := True;
305 when 'A' =>
306 Warn_On_Assertion_Failure := False;
308 when 'b' =>
309 Warn_On_Biased_Representation := True;
311 when 'B' =>
312 Warn_On_Biased_Representation := False;
314 when 'c' =>
315 Warn_On_Unrepped_Components := True;
317 when 'C' =>
318 Warn_On_Unrepped_Components := False;
320 when 'd' =>
321 Warning_Doc_Switch := True;
323 when 'D' =>
324 Warning_Doc_Switch := False;
326 when 'e' =>
327 All_Warnings (True);
329 when 'g' =>
330 Set_GNAT_Mode_Warnings;
332 when 'h' =>
333 Warn_On_Record_Holes := True;
335 when 'H' =>
336 Warn_On_Record_Holes := False;
338 when 'i' =>
339 Warn_On_Overlap := True;
341 when 'I' =>
342 Warn_On_Overlap := False;
344 when 'k' =>
345 Warn_On_Standard_Redefinition := True;
347 when 'K' =>
348 Warn_On_Standard_Redefinition := False;
350 when 'l' =>
351 List_Inherited_Aspects := True;
353 when 'L' =>
354 List_Inherited_Aspects := False;
356 when 'm' =>
357 Warn_On_Suspicious_Modulus_Value := True;
359 when 'M' =>
360 Warn_On_Suspicious_Modulus_Value := False;
362 when 'n' =>
363 Warn_On_Atomic_Synchronization := True;
365 when 'N' =>
366 Warn_On_Atomic_Synchronization := False;
368 when 'o' =>
369 Warn_On_All_Unread_Out_Parameters := True;
371 when 'O' =>
372 Warn_On_All_Unread_Out_Parameters := False;
374 when 'p' =>
375 Warn_On_Parameter_Order := True;
377 when 'P' =>
378 Warn_On_Parameter_Order := False;
380 when 'r' =>
381 Warn_On_Object_Renames_Function := True;
383 when 'R' =>
384 Warn_On_Object_Renames_Function := False;
386 when 's' =>
387 Warn_On_Overridden_Size := True;
389 when 'S' =>
390 Warn_On_Overridden_Size := False;
392 when 't' =>
393 Warn_On_Suspicious_Contract := True;
395 when 'T' =>
396 Warn_On_Suspicious_Contract := False;
398 when 'u' =>
399 Warn_On_Unordered_Enumeration_Type := True;
401 when 'U' =>
402 Warn_On_Unordered_Enumeration_Type := False;
404 when 'v' =>
405 Warn_On_Reverse_Bit_Order := True;
407 when 'V' =>
408 Warn_On_Reverse_Bit_Order := False;
410 when 'w' =>
411 Warn_On_Warnings_Off := True;
413 when 'W' =>
414 Warn_On_Warnings_Off := False;
416 when 'x' =>
417 Warn_On_Non_Local_Exception := True;
419 when 'X' =>
420 Warn_On_Non_Local_Exception := False;
421 No_Warn_On_Non_Local_Exception := True;
423 when 'y' =>
424 List_Body_Required_Info := True;
426 when 'Y' =>
427 List_Body_Required_Info := False;
429 when 'z' =>
430 Warn_On_Size_Alignment := True;
432 when 'Z' =>
433 Warn_On_Size_Alignment := False;
435 when others =>
436 if Ignore_Unrecognized_VWY_Switches then
437 Write_Line ("unrecognized switch -gnatw." & C & " ignored");
438 else
439 return False;
440 end if;
441 end case;
443 return True;
444 end Set_Dot_Warning_Switch;
446 ----------------------------
447 -- Set_GNAT_Mode_Warnings --
448 ----------------------------
450 procedure Set_GNAT_Mode_Warnings is
451 begin
452 -- Set -gnatwa warnings and no others
454 All_Warnings (False);
455 WA_Warnings;
457 -- These warnings are added to the -gnatwa set
459 Address_Clause_Overlay_Warnings := True;
460 Warn_On_Overridden_Size := True;
462 -- These warnings are removed from the -gnatwa set
464 Implementation_Unit_Warnings := False;
465 Warn_On_Non_Local_Exception := False;
466 No_Warn_On_Non_Local_Exception := True;
467 Warn_On_Reverse_Bit_Order := False;
468 Warn_On_Size_Alignment := False;
469 Warn_On_Unrepped_Components := False;
470 end Set_GNAT_Mode_Warnings;
472 ------------------------
473 -- Set_Warning_Switch --
474 ------------------------
476 function Set_Warning_Switch (C : Character) return Boolean is
477 begin
478 case C is
479 when 'a' =>
480 WA_Warnings;
482 when 'A' =>
483 All_Warnings (False);
484 No_Warn_On_Non_Local_Exception := True;
486 when 'b' =>
487 Warn_On_Bad_Fixed_Value := True;
489 when 'B' =>
490 Warn_On_Bad_Fixed_Value := False;
492 when 'c' =>
493 Constant_Condition_Warnings := True;
495 when 'C' =>
496 Constant_Condition_Warnings := False;
498 when 'd' =>
499 Warn_On_Dereference := True;
501 when 'D' =>
502 Warn_On_Dereference := False;
504 when 'e' =>
505 Warning_Mode := Treat_As_Error;
507 when 'f' =>
508 Check_Unreferenced_Formals := True;
510 when 'F' =>
511 Check_Unreferenced_Formals := False;
513 when 'g' =>
514 Warn_On_Unrecognized_Pragma := True;
516 when 'G' =>
517 Warn_On_Unrecognized_Pragma := False;
519 when 'h' =>
520 Warn_On_Hiding := True;
522 when 'H' =>
523 Warn_On_Hiding := False;
525 when 'i' =>
526 Implementation_Unit_Warnings := True;
528 when 'I' =>
529 Implementation_Unit_Warnings := False;
531 when 'j' =>
532 Warn_On_Obsolescent_Feature := True;
534 when 'J' =>
535 Warn_On_Obsolescent_Feature := False;
537 when 'k' =>
538 Warn_On_Constant := True;
540 when 'K' =>
541 Warn_On_Constant := False;
543 when 'l' =>
544 Elab_Warnings := True;
546 when 'L' =>
547 Elab_Warnings := False;
549 when 'm' =>
550 Warn_On_Modified_Unread := True;
552 when 'M' =>
553 Warn_On_Modified_Unread := False;
555 when 'n' =>
556 Warning_Mode := Normal;
558 when 'o' =>
559 Address_Clause_Overlay_Warnings := True;
561 when 'O' =>
562 Address_Clause_Overlay_Warnings := False;
564 when 'p' =>
565 Ineffective_Inline_Warnings := True;
567 when 'P' =>
568 Ineffective_Inline_Warnings := False;
570 when 'q' =>
571 Warn_On_Questionable_Missing_Parens := True;
573 when 'Q' =>
574 Warn_On_Questionable_Missing_Parens := False;
576 when 'r' =>
577 Warn_On_Redundant_Constructs := True;
579 when 'R' =>
580 Warn_On_Redundant_Constructs := False;
582 when 's' =>
583 Warning_Mode := Suppress;
585 when 't' =>
586 Warn_On_Deleted_Code := True;
588 when 'T' =>
589 Warn_On_Deleted_Code := False;
591 when 'u' =>
592 Check_Unreferenced := True;
593 Check_Withs := True;
594 Check_Unreferenced_Formals := True;
596 when 'U' =>
597 Check_Unreferenced := False;
598 Check_Withs := False;
599 Check_Unreferenced_Formals := False;
601 when 'v' =>
602 Warn_On_No_Value_Assigned := True;
604 when 'V' =>
605 Warn_On_No_Value_Assigned := False;
607 when 'w' =>
608 Warn_On_Assumed_Low_Bound := True;
610 when 'W' =>
611 Warn_On_Assumed_Low_Bound := False;
613 when 'x' =>
614 Warn_On_Export_Import := True;
616 when 'X' =>
617 Warn_On_Export_Import := False;
619 when 'y' =>
620 Warn_On_Ada_2005_Compatibility := True;
621 Warn_On_Ada_2012_Compatibility := True;
623 when 'Y' =>
624 Warn_On_Ada_2005_Compatibility := False;
625 Warn_On_Ada_2012_Compatibility := False;
627 when 'z' =>
628 Warn_On_Unchecked_Conversion := True;
630 when 'Z' =>
631 Warn_On_Unchecked_Conversion := False;
633 when others =>
634 if Ignore_Unrecognized_VWY_Switches then
635 Write_Line ("unrecognized switch -gnatw" & C & " ignored");
636 else
637 return False;
638 end if;
639 end case;
641 return True;
642 end Set_Warning_Switch;
644 -----------------
645 -- WA_Warnings --
646 -----------------
648 procedure WA_Warnings is
649 begin
650 Check_Unreferenced := True; -- -gnatwf/-gnatwu
651 Check_Unreferenced_Formals := True; -- -gnatwf/-gnatwu
652 Check_Withs := True; -- -gnatwu
653 Constant_Condition_Warnings := True; -- -gnatwc
654 Implementation_Unit_Warnings := True; -- -gnatwi
655 Ineffective_Inline_Warnings := True; -- -gnatwp
656 Warn_On_Ada_2005_Compatibility := True; -- -gnatwy
657 Warn_On_Ada_2012_Compatibility := True; -- -gnatwy
658 Warn_On_Assertion_Failure := True; -- -gnatw.a
659 Warn_On_Assumed_Low_Bound := True; -- -gnatww
660 Warn_On_Bad_Fixed_Value := True; -- -gnatwb
661 Warn_On_Biased_Representation := True; -- -gnatw.b
662 Warn_On_Constant := True; -- -gnatwk
663 Warn_On_Export_Import := True; -- -gnatwx
664 Warn_On_Modified_Unread := True; -- -gnatwm
665 Warn_On_No_Value_Assigned := True; -- -gnatwv
666 Warn_On_Non_Local_Exception := True; -- -gnatw.x
667 Warn_On_Object_Renames_Function := True; -- -gnatw.r
668 Warn_On_Obsolescent_Feature := True; -- -gnatwj
669 Warn_On_Overlap := True; -- -gnatw.i
670 Warn_On_Parameter_Order := True; -- -gnatw.p
671 Warn_On_Questionable_Missing_Parens := True; -- -gnatwq
672 Warn_On_Redundant_Constructs := True; -- -gnatwr
673 Warn_On_Reverse_Bit_Order := True; -- -gnatw.v
674 Warn_On_Size_Alignment := True; -- -gnatw.z
675 Warn_On_Suspicious_Contract := True; -- -gnatw.t
676 Warn_On_Suspicious_Modulus_Value := True; -- -gnatw.m
677 Warn_On_Unchecked_Conversion := True; -- -gnatwz
678 Warn_On_Unrecognized_Pragma := True; -- -gnatwg
679 Warn_On_Unrepped_Components := True; -- -gnatw.c
680 end WA_Warnings;
682 end Warnsw;