aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/styleg.adb
diff options
context:
space:
mode:
authorArnaud Charlet <charlet@adacore.com>2023-02-06 08:50:42 +0000
committerMarc Poulhiès <poulhies@adacore.com>2023-05-22 10:44:09 +0200
commit86bcf5d5d369cd78ebd99989978432f8cdb73bb4 (patch)
treefb68ec904ee4b674460a6ece7de3c154ac03f243 /gcc/ada/styleg.adb
parent8f563162db870d42d7306551a9dda51201ad9862 (diff)
downloadgcc-86bcf5d5d369cd78ebd99989978432f8cdb73bb4.zip
gcc-86bcf5d5d369cd78ebd99989978432f8cdb73bb4.tar.gz
gcc-86bcf5d5d369cd78ebd99989978432f8cdb73bb4.tar.bz2
ada: Improve -gnatyx style check
Check redundant parentheses in many more places, for now only under -gnatdQ, while pending violations are fixed. gcc/ada/ * par-ch3.adb, sem_ch4.adb (P_Discrete_Range, Analyze_Logical_Op, Analyze_Short_Circuit): Add calls to Check_Xtra_Parentheses. * par-ch5.adb (P_Condition): Move logic to Check_Xtra_Parentheses. * style.ads, styleg.adb, styleg.ads (Check_Xtra_Parens): Move logic related to expressions requiring parentheses here.
Diffstat (limited to 'gcc/ada/styleg.adb')
-rw-r--r--gcc/ada/styleg.adb20
1 files changed, 17 insertions, 3 deletions
diff --git a/gcc/ada/styleg.adb b/gcc/ada/styleg.adb
index 0bb406f..01a650a 100644
--- a/gcc/ada/styleg.adb
+++ b/gcc/ada/styleg.adb
@@ -33,6 +33,7 @@ with Csets; use Csets;
with Einfo; use Einfo;
with Einfo.Utils; use Einfo.Utils;
with Err_Vars; use Err_Vars;
+with Errout;
with Opt; use Opt;
with Scans; use Scans;
with Sinfo; use Sinfo;
@@ -1118,11 +1119,24 @@ package body Styleg is
-- Check_Xtra_Parens --
-----------------------
- procedure Check_Xtra_Parens (Loc : Source_Ptr) is
+ procedure Check_Xtra_Parens (N : Node_Id; Enable : Boolean) is
begin
- if Style_Check_Xtra_Parens then
+ -- Do not emit messages about expressions that may require parentheses
+
+ if Style_Check_Xtra_Parens
+ and then Enable
+ and then
+ Paren_Count (N) >
+ (if Nkind (N) in N_Case_Expression
+ | N_Expression_With_Actions
+ | N_If_Expression
+ | N_Quantified_Expression
+ | N_Raise_Expression
+ then 1
+ else 0)
+ then
Error_Msg -- CODEFIX
- ("(style) redundant parentheses?x?", Loc);
+ ("(style) redundant parentheses?x?", Errout.First_Sloc (N));
end if;
end Check_Xtra_Parens;