aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/styleg.adb
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/ada/styleg.adb')
-rw-r--r--gcc/ada/styleg.adb47
1 files changed, 45 insertions, 2 deletions
diff --git a/gcc/ada/styleg.adb b/gcc/ada/styleg.adb
index 04634d1..6e4a442 100644
--- a/gcc/ada/styleg.adb
+++ b/gcc/ada/styleg.adb
@@ -351,7 +351,9 @@ package body Styleg is
-- 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.
+ -- or the indentation must match that of the next non-blank line,
+ -- or must match the indentation of the immediately preciding line
+ -- if it is non-blank.
procedure Check_Comment is
S : Source_Ptr;
@@ -369,6 +371,12 @@ package body Styleg is
-- matches that of the next non-blank line in the source, then True is
-- returned, otherwise False.
+ function Same_Column_As_Previous_Line return Boolean;
+ -- Called for a full line comment. If the previous line is blank, then
+ -- returns False. Otherwise, if the indentation of this comment matches
+ -- that of the previous line in the source, then True is returned,
+ -- otherwise False.
+
--------------------
-- Is_Box_Comment --
--------------------
@@ -429,6 +437,39 @@ package body Styleg is
return Get_Column_Number (Scan_Ptr) = Get_Column_Number (P);
end Same_Column_As_Next_Non_Blank_Line;
+ ----------------------------------
+ -- Same_Column_As_Previous_Line --
+ ----------------------------------
+
+ function Same_Column_As_Previous_Line return Boolean is
+ S, P : Source_Ptr;
+
+ begin
+ -- Point S to start of this line, and P to start of previous line
+
+ S := Line_Start (Scan_Ptr);
+ P := S;
+ Backup_Line (P);
+
+ -- Step P to first non-blank character on line
+
+ loop
+ -- If we get back to start of current line, then the previous line
+ -- was blank, and we always return False in that situation.
+
+ if P = S then
+ return False;
+ end if;
+
+ exit when Source (P) /= ' ' and then Source (P) /= ASCII.HT;
+ P := P + 1;
+ end loop;
+
+ -- Compare columns
+
+ return Get_Column_Number (Scan_Ptr) = Get_Column_Number (P);
+ end Same_Column_As_Previous_Line;
+
-- Start of processing for Check_Comment
begin
@@ -466,7 +507,9 @@ package body Styleg is
if Style_Check_Indentation /= 0 then
if Start_Column rem Style_Check_Indentation /= 0 then
- if not Same_Column_As_Next_Non_Blank_Line then
+ if not Same_Column_As_Next_Non_Blank_Line
+ and then not Same_Column_As_Previous_Line
+ then
Error_Msg_S -- CODEFIX
("(style) bad column");
end if;