From eafaf3aa01f7043364951a1a1b451f4b2104b1ea Mon Sep 17 00:00:00 2001 From: charlet Date: Thu, 13 Dec 2007 10:36:06 +0000 Subject: [PATCH] 2007-12-06 Robert Dewar * styleg.adb (Check_Comment): More liberal rules for comment placement git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@130866 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ada/styleg.adb | 45 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/gcc/ada/styleg.adb b/gcc/ada/styleg.adb index ba478c0bd0a..853788f3076 100644 --- a/gcc/ada/styleg.adb +++ b/gcc/ada/styleg.adb @@ -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; -- 2.11.0