diff mbox

[Ada] Add style check for NOT IN

Message ID 20121002082302.GA7675@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet Oct. 2, 2012, 8:23 a.m. UTC
This patch adds a new style check for the layout of the NOT IN operation.
If the token check style flag is set, then there must be exactly one space
(and no other white space) between the NOT and the IN. The following is
compiled with -gnaty:

     1. package StyleNotIn is
     2.    x : Integer := 4;
     3.    y : Boolean := x not  in 1 .. 10;
                                |
        >>> (style) single space must separate "not" and "in"

     4. end StyleNotIn;

2012-10-02  Robert Dewar  <dewar@adacore.com>

	* stylesw.ads, gnat_ugn.texi: Document new style rule for NOT IN.
	* par-ch4.adb (P_Relational_Operator): Add style check for NOT IN.
	* style.ads, styleg.adb, styleg.ads (Check_Not_In): New procedure.
diff mbox

Patch

Index: gnat_ugn.texi
===================================================================
--- gnat_ugn.texi	(revision 191960)
+++ gnat_ugn.texi	(working copy)
@@ -6730,6 +6730,10 @@ 
 A vertical bar must be surrounded by spaces.
 @end itemize
 
+@item
+Exactly one blank (and no other white space) must appear between
+a @code{not} token and a following @code{in} token.
+
 @item ^u^UNNECESSARY_BLANK_LINES^
 @emph{Check unnecessary blank lines.}
 Unnecessary blank lines are not allowed. A blank line is considered
Index: par-ch4.adb
===================================================================
--- par-ch4.adb	(revision 191888)
+++ par-ch4.adb	(working copy)
@@ -2706,7 +2706,16 @@ 
 
       Scan; -- past operator token
 
+      --  Deal with NOT IN, if previous token was NOT, we must have IN now
+
       if Prev_Token = Tok_Not then
+
+         --  Style check, for NOT IN, we require one space between NOT and IN
+
+         if Style_Check and then Token = Tok_In then
+            Style.Check_Not_In;
+         end if;
+
          T_In;
       end if;
 
Index: style.ads
===================================================================
--- style.ads	(revision 191888)
+++ style.ads	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 S p e c                                  --
 --                                                                          --
---          Copyright (C) 1992-2010, Free Software Foundation, Inc.         --
+--          Copyright (C) 1992-2012, 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- --
@@ -155,6 +155,11 @@ 
    --  check the line length (Len is the length of the current line). Note that
    --  the terminator may be the EOF character.
 
+   procedure Check_Not_In
+     renames Style_Inst.Check_Not_In;
+   --  Called with Scan_Ptr pointing to an IN token, and Prev_Token_Ptr
+   --  pointing to a NOT token. Used to check proper layout of NOT IN.
+
    procedure Check_Pragma_Name
      renames Style_Inst.Check_Pragma_Name;
    --  The current token is a pragma identifier. Check that it is spelled
Index: styleg.adb
===================================================================
--- styleg.adb	(revision 191888)
+++ styleg.adb	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 1992-2011, Free Software Foundation, Inc.         --
+--          Copyright (C) 1992-2012, 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- --
@@ -764,6 +764,24 @@ 
       end if;
    end Check_Line_Terminator;
 
+   ------------------
+   -- Check_Not_In --
+   ------------------
+
+   --  In check tokens mode, only one space between NOT and IN
+
+   procedure Check_Not_In is
+   begin
+      if Style_Check_Tokens then
+         if Source (Token_Ptr - 1) /= ' '
+           or else Token_Ptr - Prev_Token_Ptr /= 4
+         then -- CODEFIX?
+            Error_Msg
+              ("(style) single space must separate NOT and IN", Token_Ptr - 1);
+         end if;
+      end if;
+   end Check_Not_In;
+
    --------------------------
    -- Check_No_Space_After --
    --------------------------
Index: styleg.ads
===================================================================
--- styleg.ads	(revision 191888)
+++ styleg.ads	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 S p e c                                  --
 --                                                                          --
---          Copyright (C) 1992-2010, Free Software Foundation, Inc.         --
+--          Copyright (C) 1992-2012, 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- --
@@ -117,6 +117,10 @@ 
    --  the current line, used to check for appropriate line terminator usage.
    --  The parameter Len is the length of the current line.
 
+   procedure Check_Not_In;
+   --  Called with Scan_Ptr pointing to an IN token, and Prev_Token_Ptr
+   --  pointing to a NOT token. Used to check proper layout of NOT IN.
+
    procedure Check_Pragma_Name;
    --  The current token is a pragma identifier. Check that it is spelled
    --  properly (i.e. with an appropriate casing convention).
Index: stylesw.ads
===================================================================
--- stylesw.ads	(revision 191888)
+++ stylesw.ads	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 S p e c                                  --
 --                                                                          --
---          Copyright (C) 1992-2011, Free Software Foundation, Inc.         --
+--          Copyright (C) 1992-2012, 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- --
@@ -255,6 +255,8 @@ 
    --
    --    A unary plus or minus may not be followed by a space
    --
+   --    There must be one blank (and no other white space) between NOT and IN
+   --
    --    A vertical bar must be surrounded by spaces
    --
    --  Note that a requirement that a token be preceded by a space is met by