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------------------------------------------------------------------------------ 25 26with Err_Vars; use Err_Vars; 27with Opt; use Opt; 28with Output; use Output; 29 30package body Warnsw is 31 32 -- Local Subprograms 33 34 procedure All_Warnings (Setting : Boolean); 35 -- Sets all warnings off if Setting = False, and on if Setting = True 36 37 procedure WA_Warnings; 38 -- Turn on all warnings set by -gnatwa (also used by -gnatw.g) 39 40 ------------------ 41 -- All_Warnings -- 42 ------------------ 43 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; 91 92 ---------------------- 93 -- Restore_Warnings -- 94 ---------------------- 95 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; 191 192 ------------------- 193 -- Save_Warnings -- 194 ------------------- 195 196 function Save_Warnings return Warning_Record is 197 W : Warning_Record; 198 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; 294 295 ---------------------------- 296 -- Set_Dot_Warning_Switch -- 297 ---------------------------- 298 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; 304 305 when 'A' => 306 Warn_On_Assertion_Failure := False; 307 308 when 'b' => 309 Warn_On_Biased_Representation := True; 310 311 when 'B' => 312 Warn_On_Biased_Representation := False; 313 314 when 'c' => 315 Warn_On_Unrepped_Components := True; 316 317 when 'C' => 318 Warn_On_Unrepped_Components := False; 319 320 when 'd' => 321 Warning_Doc_Switch := True; 322 323 when 'D' => 324 Warning_Doc_Switch := False; 325 326 when 'e' => 327 All_Warnings (True); 328 329 when 'f' => 330 Warn_On_Elab_Access := True; 331 332 when 'F' => 333 Warn_On_Elab_Access := False; 334 335 when 'g' => 336 Set_GNAT_Mode_Warnings; 337 338 when 'h' => 339 Warn_On_Record_Holes := True; 340 341 when 'H' => 342 Warn_On_Record_Holes := False; 343 344 when 'i' => 345 Warn_On_Overlap := True; 346 347 when 'I' => 348 Warn_On_Overlap := False; 349 350 when 'k' => 351 Warn_On_Standard_Redefinition := True; 352 353 when 'K' => 354 Warn_On_Standard_Redefinition := False; 355 356 when 'l' => 357 List_Inherited_Aspects := True; 358 359 when 'L' => 360 List_Inherited_Aspects := False; 361 362 when 'm' => 363 Warn_On_Suspicious_Modulus_Value := True; 364 365 when 'M' => 366 Warn_On_Suspicious_Modulus_Value := False; 367 368 when 'n' => 369 Warn_On_Atomic_Synchronization := True; 370 371 when 'N' => 372 Warn_On_Atomic_Synchronization := False; 373 374 when 'o' => 375 Warn_On_All_Unread_Out_Parameters := True; 376 377 when 'O' => 378 Warn_On_All_Unread_Out_Parameters := False; 379 380 when 'p' => 381 Warn_On_Parameter_Order := True; 382 383 when 'P' => 384 Warn_On_Parameter_Order := False; 385 386 when 'r' => 387 Warn_On_Object_Renames_Function := True; 388 389 when 'R' => 390 Warn_On_Object_Renames_Function := False; 391 392 when 's' => 393 Warn_On_Overridden_Size := True; 394 395 when 'S' => 396 Warn_On_Overridden_Size := False; 397 398 when 't' => 399 Warn_On_Suspicious_Contract := True; 400 401 when 'T' => 402 Warn_On_Suspicious_Contract := False; 403 404 when 'u' => 405 Warn_On_Unordered_Enumeration_Type := True; 406 407 when 'U' => 408 Warn_On_Unordered_Enumeration_Type := False; 409 410 when 'v' => 411 Warn_On_Reverse_Bit_Order := True; 412 413 when 'V' => 414 Warn_On_Reverse_Bit_Order := False; 415 416 when 'w' => 417 Warn_On_Warnings_Off := True; 418 419 when 'W' => 420 Warn_On_Warnings_Off := False; 421 422 when 'x' => 423 Warn_On_Non_Local_Exception := True; 424 425 when 'X' => 426 Warn_On_Non_Local_Exception := False; 427 No_Warn_On_Non_Local_Exception := True; 428 429 when 'y' => 430 List_Body_Required_Info := True; 431 432 when 'Y' => 433 List_Body_Required_Info := False; 434 435 when 'z' => 436 Warn_On_Size_Alignment := True; 437 438 when 'Z' => 439 Warn_On_Size_Alignment := False; 440 441 when others => 442 if Ignore_Unrecognized_VWY_Switches then 443 Write_Line ("unrecognized switch -gnatw." & C & " ignored"); 444 else 445 return False; 446 end if; 447 end case; 448 449 return True; 450 end Set_Dot_Warning_Switch; 451 452 ---------------------------- 453 -- Set_GNAT_Mode_Warnings -- 454 ---------------------------- 455 456 procedure Set_GNAT_Mode_Warnings is 457 begin 458 -- Set -gnatwa warnings and no others 459 460 All_Warnings (False); 461 WA_Warnings; 462 463 -- These warnings are added to the -gnatwa set 464 465 Address_Clause_Overlay_Warnings := True; 466 Warn_On_Overridden_Size := True; 467 468 -- These warnings are removed from the -gnatwa set 469 470 Implementation_Unit_Warnings := False; 471 Warn_On_Non_Local_Exception := False; 472 No_Warn_On_Non_Local_Exception := True; 473 Warn_On_Reverse_Bit_Order := False; 474 Warn_On_Size_Alignment := False; 475 Warn_On_Unrepped_Components := False; 476 end Set_GNAT_Mode_Warnings; 477 478 ------------------------ 479 -- Set_Warning_Switch -- 480 ------------------------ 481 482 function Set_Warning_Switch (C : Character) return Boolean is 483 begin 484 case C is 485 when 'a' => 486 WA_Warnings; 487 488 when 'A' => 489 All_Warnings (False); 490 No_Warn_On_Non_Local_Exception := True; 491 492 when 'b' => 493 Warn_On_Bad_Fixed_Value := True; 494 495 when 'B' => 496 Warn_On_Bad_Fixed_Value := False; 497 498 when 'c' => 499 Constant_Condition_Warnings := True; 500 501 when 'C' => 502 Constant_Condition_Warnings := False; 503 504 when 'd' => 505 Warn_On_Dereference := True; 506 507 when 'D' => 508 Warn_On_Dereference := False; 509 510 when 'e' => 511 Warning_Mode := Treat_As_Error; 512 513 when 'f' => 514 Check_Unreferenced_Formals := True; 515 516 when 'F' => 517 Check_Unreferenced_Formals := False; 518 519 when 'g' => 520 Warn_On_Unrecognized_Pragma := True; 521 522 when 'G' => 523 Warn_On_Unrecognized_Pragma := False; 524 525 when 'h' => 526 Warn_On_Hiding := True; 527 528 when 'H' => 529 Warn_On_Hiding := False; 530 531 when 'i' => 532 Implementation_Unit_Warnings := True; 533 534 when 'I' => 535 Implementation_Unit_Warnings := False; 536 537 when 'j' => 538 Warn_On_Obsolescent_Feature := True; 539 540 when 'J' => 541 Warn_On_Obsolescent_Feature := False; 542 543 when 'k' => 544 Warn_On_Constant := True; 545 546 when 'K' => 547 Warn_On_Constant := False; 548 549 when 'l' => 550 Elab_Warnings := True; 551 552 when 'L' => 553 Elab_Warnings := False; 554 555 when 'm' => 556 Warn_On_Modified_Unread := True; 557 558 when 'M' => 559 Warn_On_Modified_Unread := False; 560 561 when 'n' => 562 Warning_Mode := Normal; 563 564 when 'o' => 565 Address_Clause_Overlay_Warnings := True; 566 567 when 'O' => 568 Address_Clause_Overlay_Warnings := False; 569 570 when 'p' => 571 Ineffective_Inline_Warnings := True; 572 573 when 'P' => 574 Ineffective_Inline_Warnings := False; 575 576 when 'q' => 577 Warn_On_Questionable_Missing_Parens := True; 578 579 when 'Q' => 580 Warn_On_Questionable_Missing_Parens := False; 581 582 when 'r' => 583 Warn_On_Redundant_Constructs := True; 584 585 when 'R' => 586 Warn_On_Redundant_Constructs := False; 587 588 when 's' => 589 Warning_Mode := Suppress; 590 591 when 't' => 592 Warn_On_Deleted_Code := True; 593 594 when 'T' => 595 Warn_On_Deleted_Code := False; 596 597 when 'u' => 598 Check_Unreferenced := True; 599 Check_Withs := True; 600 Check_Unreferenced_Formals := True; 601 602 when 'U' => 603 Check_Unreferenced := False; 604 Check_Withs := False; 605 Check_Unreferenced_Formals := False; 606 607 when 'v' => 608 Warn_On_No_Value_Assigned := True; 609 610 when 'V' => 611 Warn_On_No_Value_Assigned := False; 612 613 when 'w' => 614 Warn_On_Assumed_Low_Bound := True; 615 616 when 'W' => 617 Warn_On_Assumed_Low_Bound := False; 618 619 when 'x' => 620 Warn_On_Export_Import := True; 621 622 when 'X' => 623 Warn_On_Export_Import := False; 624 625 when 'y' => 626 Warn_On_Ada_2005_Compatibility := True; 627 Warn_On_Ada_2012_Compatibility := True; 628 629 when 'Y' => 630 Warn_On_Ada_2005_Compatibility := False; 631 Warn_On_Ada_2012_Compatibility := False; 632 633 when 'z' => 634 Warn_On_Unchecked_Conversion := True; 635 636 when 'Z' => 637 Warn_On_Unchecked_Conversion := False; 638 639 when others => 640 if Ignore_Unrecognized_VWY_Switches then 641 Write_Line ("unrecognized switch -gnatw" & C & " ignored"); 642 else 643 return False; 644 end if; 645 end case; 646 647 return True; 648 end Set_Warning_Switch; 649 650 ----------------- 651 -- WA_Warnings -- 652 ----------------- 653 654 procedure WA_Warnings is 655 begin 656 Check_Unreferenced := True; -- -gnatwf/-gnatwu 657 Check_Unreferenced_Formals := True; -- -gnatwf/-gnatwu 658 Check_Withs := True; -- -gnatwu 659 Constant_Condition_Warnings := True; -- -gnatwc 660 Implementation_Unit_Warnings := True; -- -gnatwi 661 Ineffective_Inline_Warnings := True; -- -gnatwp 662 Warn_On_Ada_2005_Compatibility := True; -- -gnatwy 663 Warn_On_Ada_2012_Compatibility := True; -- -gnatwy 664 Warn_On_Assertion_Failure := True; -- -gnatw.a 665 Warn_On_Assumed_Low_Bound := True; -- -gnatww 666 Warn_On_Bad_Fixed_Value := True; -- -gnatwb 667 Warn_On_Biased_Representation := True; -- -gnatw.b 668 Warn_On_Constant := True; -- -gnatwk 669 Warn_On_Export_Import := True; -- -gnatwx 670 Warn_On_Modified_Unread := True; -- -gnatwm 671 Warn_On_No_Value_Assigned := True; -- -gnatwv 672 Warn_On_Non_Local_Exception := True; -- -gnatw.x 673 Warn_On_Object_Renames_Function := True; -- -gnatw.r 674 Warn_On_Obsolescent_Feature := True; -- -gnatwj 675 Warn_On_Overlap := True; -- -gnatw.i 676 Warn_On_Parameter_Order := True; -- -gnatw.p 677 Warn_On_Questionable_Missing_Parens := True; -- -gnatwq 678 Warn_On_Redundant_Constructs := True; -- -gnatwr 679 Warn_On_Reverse_Bit_Order := True; -- -gnatw.v 680 Warn_On_Size_Alignment := True; -- -gnatw.z 681 Warn_On_Suspicious_Contract := True; -- -gnatw.t 682 Warn_On_Suspicious_Modulus_Value := True; -- -gnatw.m 683 Warn_On_Unchecked_Conversion := True; -- -gnatwz 684 Warn_On_Unrecognized_Pragma := True; -- -gnatwg 685 Warn_On_Unrepped_Components := True; -- -gnatw.c 686 end WA_Warnings; 687 688end Warnsw; 689