aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorViljar Indus <indus@adacore.com>2024-08-30 14:22:16 +0300
committerMarc Poulhiès <dkm@gcc.gnu.org>2024-09-10 09:44:10 +0200
commit5b701ee737c41cd0ca54f1343620170d92344e6a (patch)
tree39fe4ff7f1b32335c52db57a6e686631acc13ad0 /gcc
parentac957a621cf1e9beeb52695250b7600ed066448f (diff)
downloadgcc-5b701ee737c41cd0ca54f1343620170d92344e6a.zip
gcc-5b701ee737c41cd0ca54f1343620170d92344e6a.tar.gz
gcc-5b701ee737c41cd0ca54f1343620170d92344e6a.tar.bz2
ada: Normalize span generation on different platforms
The total number of characters on a source code line is different on Windows and Linux based systems (CRLF vs LF endings). Use the last non line change character to adjust printing the spans that go over the end of line. gcc/ada/ * diagnostics-pretty_emitter.adb (Get_Last_Line_Char): New. Get the last non line change character. Write_Span_Labels use the adjusted line end pointer to calculate the length of the span.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ada/diagnostics-pretty_emitter.adb30
1 files changed, 27 insertions, 3 deletions
diff --git a/gcc/ada/diagnostics-pretty_emitter.adb b/gcc/ada/diagnostics-pretty_emitter.adb
index 927e505..389be8a 100644
--- a/gcc/ada/diagnostics-pretty_emitter.adb
+++ b/gcc/ada/diagnostics-pretty_emitter.adb
@@ -165,7 +165,7 @@ package body Diagnostics.Pretty_Emitter is
function Get_Line_End
(Buf : Source_Buffer_Ptr;
Loc : Source_Ptr) return Source_Ptr;
- -- Get the source location for the end of the line in Buf for Loc. If
+ -- Get the source location for the end of the line (LF) in Buf for Loc. If
-- Loc is past the end of Buf already, return Buf'Last.
function Get_Line_Start
@@ -177,6 +177,10 @@ package body Diagnostics.Pretty_Emitter is
(Buf : Source_Buffer_Ptr; Loc : Source_Ptr) return Source_Ptr;
-- Get first non-space character in the line containing Loc
+ function Get_Last_Line_Char
+ (Buf : Source_Buffer_Ptr; Loc : Source_Ptr) return Source_Ptr;
+ -- Get last non line end [LF, CR] character in the line containing Loc
+
function Image (X : Positive; Width : Positive) return String;
-- Output number X over Width characters, with whitespace padding.
-- Only output the low-order Width digits of X, if X is larger than
@@ -314,6 +318,25 @@ package body Diagnostics.Pretty_Emitter is
return Cur_Loc;
end Get_First_Line_Char;
+ ------------------------
+ -- Get_Last_Line_Char --
+ ------------------------
+
+ function Get_Last_Line_Char
+ (Buf : Source_Buffer_Ptr; Loc : Source_Ptr) return Source_Ptr
+ is
+ Cur_Loc : Source_Ptr := Get_Line_End (Buf, Loc);
+ begin
+
+ while Cur_Loc > Buf'First
+ and then Buf (Cur_Loc) in ASCII.LF | ASCII.CR
+ loop
+ Cur_Loc := Cur_Loc - 1;
+ end loop;
+
+ return Cur_Loc;
+ end Get_Last_Line_Char;
+
-----------
-- Image --
-----------
@@ -720,8 +743,9 @@ package body Diagnostics.Pretty_Emitter is
Source_Text (Get_Source_File_Index (L.First));
Col_L_Fst : constant Natural := Natural
- (Get_Column_Number (Get_First_Line_Char (Buf, L.First)));
- Col_L_Lst : constant Natural := Natural (Get_Column_Number (L.Last));
+ (Get_Column_Number (Get_First_Line_Char (Buf, L.First)));
+ Col_L_Lst : constant Natural := Natural
+ (Get_Column_Number (Get_Last_Line_Char (Buf, L.Last)));
-- Carret positions
Ptr : constant Source_Ptr := Loc.Span.Ptr;