diff options
author | charlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4> | 2009-07-22 10:25:57 +0000 |
---|---|---|
committer | charlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4> | 2009-07-22 10:25:57 +0000 |
commit | e28b1a69bf0e8c09becaecda2ae29a85bec27d6f (patch) | |
tree | eadd181009b4822e6ce92897aef59201db5cab36 /gcc/ada/styleg.adb | |
parent | fbc89b916a7a004f25857943a4795a618a460ea4 (diff) | |
download | gcc-e28b1a69bf0e8c09becaecda2ae29a85bec27d6f.tar.gz |
2009-07-22 Robert Dewar <dewar@adacore.com>
* sem_res.adb (Check_No_Direct_Boolean_Operators): Add check for -gnatyB
* style.ads, styleg.adb, styleg.ads (Check_Boolean_Operator): New
procedure.
* usage.adb, stylesw.ads, stylesw.adb: Add handling of -gnatyB switch
* gnat_ugn.texi: Add documentation of -gnatyB
* vms_data.ads: Add entry for -gnatyB (STYLE=BOOLEAN_OPERATORS)
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@149923 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/ada/styleg.adb')
-rw-r--r-- | gcc/ada/styleg.adb | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/gcc/ada/styleg.adb b/gcc/ada/styleg.adb index c92231d60b3..8bd9f2ee2bd 100644 --- a/gcc/ada/styleg.adb +++ b/gcc/ada/styleg.adb @@ -27,11 +27,14 @@ -- checking rules. For documentation of these rules, see comments on the -- individual procedures. +with Atree; use Atree; with Casing; use Casing; with Csets; use Csets; +with Einfo; use Einfo; with Err_Vars; use Err_Vars; with Opt; use Opt; with Scans; use Scans; +with Sinfo; use Sinfo; with Sinput; use Sinput; with Stylesw; use Stylesw; @@ -166,6 +169,84 @@ package body Styleg is end if; end Check_Binary_Operator; + ---------------------------- + -- Check_Boolean_Operator -- + ---------------------------- + + procedure Check_Boolean_Operator (Node : Node_Id) is + + function OK_Boolean_Operand (N : Node_Id) return Boolean; + -- Returns True for simple variable, or "not X1" or "X1 and X2" or + -- "X1 or X2" where X1, X2 are recursively OK_Boolean_Operand's. + + ------------------------ + -- OK_Boolean_Operand -- + ------------------------ + + function OK_Boolean_Operand (N : Node_Id) return Boolean is + begin + if Nkind_In (N, N_Identifier, N_Expanded_Name) then + return True; + + elsif Nkind (N) = N_Op_Not then + return OK_Boolean_Operand (Original_Node (Right_Opnd (N))); + + elsif Nkind_In (N, N_Op_And, N_Op_Or) then + return OK_Boolean_Operand (Original_Node (Left_Opnd (N))) + and then + OK_Boolean_Operand (Original_Node (Right_Opnd (N))); + + else + return False; + end if; + end OK_Boolean_Operand; + + -- Start of processig for Check_Boolean_Operator + begin + if Style_Check_Boolean_And_Or + and then Comes_From_Source (Node) + then + declare + Orig : constant Node_Id := Original_Node (Node); + + begin + if Nkind_In (Orig, N_Op_And, N_Op_Or) then + declare + L : constant Node_Id := Original_Node (Left_Opnd (Orig)); + R : constant Node_Id := Original_Node (Right_Opnd (Orig)); + + begin + -- First OK case, simple boolean constants/identifiers + + if OK_Boolean_Operand (L) + and then + OK_Boolean_Operand (R) + then + return; + + -- Second OK case, modular types + + elsif Is_Modular_Integer_Type (Etype (Node)) then + return; + + -- Third OK case, array types + + elsif Is_Array_Type (Etype (Node)) then + return; + + -- Otherwise we have an error + + elsif Nkind (Orig) = N_Op_And then + Error_Msg ("(style) `AND THEN` required", Sloc (Orig)); + else + Error_Msg ("(style) `OR ELSE` required", Sloc (Orig)); + end if; + end; + end if; + end; + end if; + end Check_Boolean_Operator; + --------------- -- Check_Box -- --------------- |