]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
styleg.adb (Check_Comment): More liberal rules for comment placement
authorRobert Dewar <dewar@adacore.com>
Thu, 13 Dec 2007 10:36:06 +0000 (11:36 +0100)
committerArnaud Charlet <charlet@gcc.gnu.org>
Thu, 13 Dec 2007 10:36:06 +0000 (11:36 +0100)
2007-12-06  Robert Dewar  <dewar@adacore.com>

* styleg.adb (Check_Comment): More liberal rules for comment placement

From-SVN: r130866

gcc/ada/styleg.adb

index ba478c0bd0a7ebd5dace6556787b294d19d12c84..853788f307689f18926b77c2ada6b62d66a44ef0 100644 (file)
@@ -256,11 +256,16 @@ package body Styleg is
    --       range 16#21#..16#2F# or 16#3A#..16#3F#. This allows special
    --       comments, such as those generated by gnatprep, or those that
    --       appear in the SPARK annotation language to be accepted.
-   --
+
    --       Note: for GNAT internal files (-gnatg switch set on for the
    --       compilation), the only special sequence recognized and allowed
    --       is --! as generated by gnatprep.
 
+   --    6. In addition, the comment must be properly indented if comment
+   --       indentation checking is active (Style_Check_Indentation non-zero).
+   --       Either the start column must be a multiple of this indentation,
+   --       or the indentation must match that of the next non-blank line.
+
    procedure Check_Comment is
       S : Source_Ptr;
       C : Character;
@@ -269,6 +274,11 @@ package body Styleg is
       --  Returns True if the last two characters on the line are -- which
       --  characterizes a box comment (as for example follows this spec).
 
+      function Same_Column_As_Next_Non_Blank_Line return Boolean;
+      --  Called for a full line comment. If the indentation of this commment
+      --  matches that of the next non-blank line in the source, then True is
+      --  returned, otherwise False.
+
       --------------------
       -- Is_Box_Comment --
       --------------------
@@ -287,6 +297,32 @@ package body Styleg is
          return Source (S - 1) = '-' and then Source (S - 2) = '-';
       end Is_Box_Comment;
 
+      ----------------------------------------
+      -- Same_Column_As_Next_Non_Blank_Line --
+      ----------------------------------------
+
+      function Same_Column_As_Next_Non_Blank_Line return Boolean is
+         P : Source_Ptr;
+
+      begin
+         --  Step to end of line
+
+         P := Scan_Ptr + 2;
+         while Source (P) not in Line_Terminator loop
+            P := P + 1;
+         end loop;
+
+         --  Step past blanks, and line terminators (UTF_32 case???)
+
+         while Source (P) <= ' ' and then Source (P) /= EOF loop
+            P := P + 1;
+         end loop;
+
+         --  Compare columns
+
+         return Get_Column_Number (Scan_Ptr) = Get_Column_Number (P);
+      end Same_Column_As_Next_Non_Blank_Line;
+
    --  Start of processing for Check_Comment
 
    begin
@@ -320,12 +356,15 @@ package body Styleg is
 
          if Style_Check_Indentation /= 0 then
             if Start_Column rem Style_Check_Indentation /= 0 then
-               Error_Msg_S ("(style) bad column");
+               if not Same_Column_As_Next_Non_Blank_Line then
+                  Error_Msg_S ("(style) bad column");
+               end if;
+
                return;
             end if;
          end if;
 
-         --  If we are not checking comments, nothing to do
+         --  If we are not checking comments, nothing more to do
 
          if not Style_Check_Comments then
             return;