diff options
author | Arnaud Charlet <charlet@adacore.com> | 2023-02-06 09:06:28 +0000 |
---|---|---|
committer | Marc Poulhiès <poulhies@adacore.com> | 2023-05-23 09:59:06 +0200 |
commit | 375299752727a8b3d5a360905fade38122d82681 (patch) | |
tree | 308cf9a8ea9761b8a12d8dac6109ec5305f406b6 /gcc/ada/styleg.adb | |
parent | a0cc548a8a1b2176bf2f51d1831a4ac6cc255b64 (diff) | |
download | gcc-375299752727a8b3d5a360905fade38122d82681.zip gcc-375299752727a8b3d5a360905fade38122d82681.tar.gz gcc-375299752727a8b3d5a360905fade38122d82681.tar.bz2 |
ada: Add new switch -gnatyz
Improve -gnatyx to check additional complete conditions,
and introduce a new switch -gnatyz to check for unnecessary
parentheses according to operator precedence rules.
Enable -gnatyz as part of -gnatyg.
gcc/ada/
* par-ch5.adb, style.ads, styleg.adb, styleg.ads
(Check_Xtra_Parens): Remove extra parameter Enable.
(Check_Xtra_Parens_Precedence): New.
(P_Case_Statement): Add -gnatyx style check.
* sem_ch4.adb: Replace calls to Check_Xtra_Parens by
Check_Xtra_Parens_Precedence.
* stylesw.ads, stylesw.adb, usage.adb: Add support for
-gnatyz.
* doc/gnat_ugn/building_executable_programs_with_gnat.rst:
Update -gnatyxzg doc.
* sem_prag.adb, libgnat/s-regpat.adb,
libgnarl/s-interr__hwint.adb, libgnarl/s-interr__vxworks.adb:
Remove extra parens.
* par-ch3.adb (P_Discrete_Range): Do not emit a style check if
the expression is not a simple expression.
* gnat_ugn.texi: Regenerate.
Diffstat (limited to 'gcc/ada/styleg.adb')
-rw-r--r-- | gcc/ada/styleg.adb | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/gcc/ada/styleg.adb b/gcc/ada/styleg.adb index 01a650a..a7524ec 100644 --- a/gcc/ada/styleg.adb +++ b/gcc/ada/styleg.adb @@ -1119,12 +1119,9 @@ package body Styleg is -- Check_Xtra_Parens -- ----------------------- - procedure Check_Xtra_Parens (N : Node_Id; Enable : Boolean) is + procedure Check_Xtra_Parens (N : Node_Id) is begin - -- 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 @@ -1140,6 +1137,28 @@ package body Styleg is end if; end Check_Xtra_Parens; + ---------------------------------- + -- Check_Xtra_Parens_Precedence -- + ---------------------------------- + + procedure Check_Xtra_Parens_Precedence (N : Node_Id) is + begin + if Style_Check_Xtra_Parens_Precedence + 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?z?", Errout.First_Sloc (N)); + end if; + end Check_Xtra_Parens_Precedence; + ---------------------------- -- Determine_Token_Casing -- ---------------------------- |