diff options
author | Robert Dewar <dewar@adacore.com> | 2007-12-13 11:36:06 +0100 |
---|---|---|
committer | Arnaud Charlet <charlet@gcc.gnu.org> | 2007-12-13 11:36:06 +0100 |
commit | 46edcdb100403f15510c2263d5b821546b8a482d (patch) | |
tree | 16bdb5bcdc7cfdd4912a2d284a61aea55c4dddd8 /gcc | |
parent | 31eee11b7cf2f550581949d87443b688232bd2a6 (diff) | |
download | gcc-46edcdb100403f15510c2263d5b821546b8a482d.zip gcc-46edcdb100403f15510c2263d5b821546b8a482d.tar.gz gcc-46edcdb100403f15510c2263d5b821546b8a482d.tar.bz2 |
styleg.adb (Check_Comment): More liberal rules for comment placement
2007-12-06 Robert Dewar <dewar@adacore.com>
* styleg.adb (Check_Comment): More liberal rules for comment placement
From-SVN: r130866
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ada/styleg.adb | 45 |
1 files changed, 42 insertions, 3 deletions
diff --git a/gcc/ada/styleg.adb b/gcc/ada/styleg.adb index ba478c0..853788f 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; |