OSDN Git Service

2009-07-22 Robert Dewar <dewar@adacore.com>
authorcharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 22 Jul 2009 10:25:57 +0000 (10:25 +0000)
committercharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 22 Jul 2009 10:25:57 +0000 (10:25 +0000)
* 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

gcc/ada/ChangeLog
gcc/ada/gnat_ugn.texi
gcc/ada/sem_res.adb
gcc/ada/style.ads
gcc/ada/styleg.adb
gcc/ada/styleg.ads
gcc/ada/stylesw.adb
gcc/ada/stylesw.ads
gcc/ada/usage.adb
gcc/ada/vms_data.ads

index 1249036..e6e5f8d 100644 (file)
@@ -1,5 +1,14 @@
 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)
+
+2009-07-22  Robert Dewar  <dewar@adacore.com>
+
        * s-stchop.adb, a-direct.adb, a-ztexio.adb, gnatchop.adb, prj-proc.adb,
        make.adb, s-regpat.adb, ali-util.adb, a-ngcefu.adb, prep.adb,
        s-tassta.adb, a-tifiio.adb, a-textio.adb, prj.adb, uintp.adb,
index 0816237..24e7867 100644 (file)
@@ -6118,6 +6118,12 @@ Trailing blanks are not allowed at the end of statements. The purpose of this
 rule, together with h (no horizontal tabs), is to enforce a canonical format
 for the use of blanks to separate source tokens.
 
+@item ^B^BOOLEAN_OPERATORS^
+@emph{Check Boolean operators.}
+The use of AND/OR operators is not permitted except in the cases of modular
+operands, array operands, and simple stand-alone boolean variables or
+boolean constants. In all other cases AND THEN/OR ELSE are required.
+
 @item ^c^COMMENTS^
 @emph{Check comments.}
 Comments must meet the following set of rules:
@@ -22616,6 +22622,11 @@ Same as @option{^-gnatyM^/MAX_LINE_LENGTH=^@var{n}}
 Avoind raising PROGRAM_ERROR in the generated bodies of program unit stubs.
 This is not always possible for function stubs.
 
+@item ^--no-local-header^/NO_LOCAL_HEADER^
+@cindex @option{^--no-local-header^/NO_LOCAL_HEADER^} (@command{gnatstub})
+Do not place local comment header with unit name before body stub for a
+unit.
+
 @item ^-o ^/BODY=^@var{body-name}
 @cindex @option{^-o^/BODY^} (@command{gnatstub})
 Body file name.  This should be set if the argument file name does not
index b8235e5..ca478bd 100644 (file)
@@ -122,7 +122,8 @@ package body Sem_Res is
    procedure Check_No_Direct_Boolean_Operators (N : Node_Id);
    --  N is the node for a logical operator. If the operator is predefined, and
    --  the root type of the operands is Standard.Boolean, then a check is made
-   --  for restriction No_Direct_Boolean_Operators.
+   --  for restriction No_Direct_Boolean_Operators. This procedure also handles
+   --  the style check for Style_Check_Boolean_And_Or.
 
    function Is_Definite_Access_Type (E : Entity_Id) return Boolean;
    --  Determine whether E is an access type declared by an access
@@ -947,6 +948,10 @@ package body Sem_Res is
             Check_Restriction (No_Direct_Boolean_Operators, N);
          end if;
       end if;
+
+      if Style_Check then
+         Check_Boolean_Operator (N);
+      end if;
    end Check_No_Direct_Boolean_Operators;
 
    ------------------------------
index 4e84a48..b61cd08 100644 (file)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                 S p e c                                  --
 --                                                                          --
---          Copyright (C) 1992-2008, Free Software Foundation, Inc.         --
+--          Copyright (C) 1992-2009, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -90,6 +90,10 @@ package Style is
    --  designator is a reserved word (access, digits, delta or range) to allow
    --  differing rules for the two cases.
 
+   procedure Check_Boolean_Operator (Node : Node_Id)
+     renames Style_Inst.Check_Boolean_Operator;
+   --  Called after resolving AND or OR node to check short circuit rules
+
    procedure Check_Box
      renames Style_Inst.Check_Box;
    --  Called after scanning out a box to check spacing
index c92231d..8bd9f2e 100644 (file)
 --  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 --
    ---------------
index 64fd51e..91c90d2 100644 (file)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                 S p e c                                  --
 --                                                                          --
---          Copyright (C) 1992-2008, Free Software Foundation, Inc.         --
+--          Copyright (C) 1992-2009, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -61,6 +61,10 @@ package Styleg is
    --  the attribute designator is a reserved word (access, digits,
    --  delta or range) to allow differing rules for the two cases.
 
+   procedure Check_Boolean_Operator (Node : Node_Id);
+   --  Node is a node for an AND or OR operator. Check that the usage meets
+   --  the style rules.
+
    procedure Check_Box;
    --  Called after scanning out a box to check spacing
 
index 8adb741..41275b7 100644 (file)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 1992-2008, Free Software Foundation, Inc.         --
+--          Copyright (C) 1992-2009, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -39,6 +39,7 @@ package body Stylesw is
       Style_Check_Attribute_Casing      := False;
       Style_Check_Blanks_At_End         := False;
       Style_Check_Blank_Lines           := False;
+      Style_Check_Boolean_And_Or        := False;
       Style_Check_Comments              := False;
       Style_Check_DOS_Line_Terminator   := False;
       Style_Check_End_Labels            := False;
@@ -122,6 +123,7 @@ package body Stylesw is
       Add ('a', Style_Check_Attribute_Casing);
       Add ('A', Style_Check_Array_Attribute_Index);
       Add ('b', Style_Check_Blanks_At_End);
+      Add ('B', Style_Check_Boolean_And_Or);
       Add ('c', Style_Check_Comments);
       Add ('d', Style_Check_DOS_Line_Terminator);
       Add ('e', Style_Check_End_Labels);
@@ -279,6 +281,9 @@ package body Stylesw is
             when 'b' =>
                Style_Check_Blanks_At_End         := True;
 
+            when 'B' =>
+               Style_Check_Boolean_And_Or        := True;
+
             when 'c' =>
                Style_Check_Comments              := True;
 
@@ -440,6 +445,9 @@ package body Stylesw is
             when 'b' =>
                Style_Check_Blanks_At_End         := False;
 
+            when 'B' =>
+               Style_Check_Boolean_And_Or        := False;
+
             when 'c' =>
                Style_Check_Comments              := False;
 
index 37154c0..7447063 100644 (file)
@@ -67,6 +67,15 @@ package Stylesw is
    --  multiple blank lines are not permitted, and there may not be a blank
    --  line at the end of the file.
 
+   Style_Check_Boolean_And_Or : Boolean := False;
+   --  This can be set True by using the -gnatyB switch. If it is True, then
+   --  the use of AND THEN/OR ELSE rather than AND/OR is required except for
+   --  the following cases:
+   --
+   --     a) Both operands are simple Boolean constants or variables
+   --     b) Both operands are of a modular type
+   --     c) Both operands are of an array type
+
    Style_Check_Comments : Boolean := False;
    --  This can be set True by using the -gnatyc switch. If it is True, then
    --  comments are style checked as follows:
index 6b87db9..0d6e9cc 100644 (file)
@@ -524,6 +524,7 @@ begin
    Write_Line ("        a    check attribute casing");
    Write_Line ("        A    check array attribute indexes");
    Write_Line ("        b    check no blanks at end of lines");
+   Write_Line ("        B    check no use of AND/OR for boolean expressions");
    Write_Line ("        c    check comment format");
    Write_Line ("        d    check no DOS line terminators");
    Write_Line ("        e    check end/exit labels present");
index 37e876e..eae2058 100644 (file)
@@ -2222,6 +2222,8 @@ package VMS_Data is
                                                "-gnaty-A "                 &
                                             "BLANKS "                      &
                                                "-gnatyb "                  &
+                                            "BOOLEAN_OPERATORS "           &
+                                               "-gnatyB "                  &
                                             "NOBLANKS "                    &
                                                "-gnaty-b "                 &
                                             "COMMENTS "                    &