aboutsummaryrefslogtreecommitdiffstats
path: root/src/files_map.adb
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2017-03-15 06:17:30 +0100
committerTristan Gingold <tgingold@free.fr>2017-03-15 06:17:30 +0100
commitabfab06bb7620314f636bf5dd2854399e54062d0 (patch)
treeba826224f2d527539fa0705e7858816770060df7 /src/files_map.adb
parent173ec2e3096a6f7f5c9274d567c42511cf908386 (diff)
downloadghdl-abfab06bb7620314f636bf5dd2854399e54062d0.tar.gz
ghdl-abfab06bb7620314f636bf5dd2854399e54062d0.tar.bz2
ghdl-abfab06bb7620314f636bf5dd2854399e54062d0.zip
Add extract_expanded_line.
Diffstat (limited to 'src/files_map.adb')
-rw-r--r--src/files_map.adb68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/files_map.adb b/src/files_map.adb
index 66b3a1087..2b6fc7e56 100644
--- a/src/files_map.adb
+++ b/src/files_map.adb
@@ -1019,6 +1019,74 @@ package body Files_Map is
end;
end Image;
+ -- Compute the length of line that starts at START. Tabs are expanded to
+ -- compute the length.
+ function Compute_Expanded_Line_Length (File : Source_File_Entry;
+ Start : Source_Ptr) return Natural
+ is
+ Buf : constant File_Buffer_Acc := Get_File_Source (File);
+ Pos : Source_Ptr;
+ Len : Natural;
+ C : Character;
+ begin
+ -- Compute line length.
+ Pos := Start;
+ Len := 0;
+ loop
+ C := Buf (Pos);
+ Pos := Pos + 1;
+ exit when C = ASCII.CR or C = ASCII.LF or C = ASCII.EOT;
+ if C = ASCII.HT then
+ -- Expand tab.
+ Len := Len + (Tab_Stop - Len mod Tab_Stop);
+ else
+ Len := Len + 1;
+ end if;
+ end loop;
+ return Len;
+ end Compute_Expanded_Line_Length;
+
+ -- Return the line that starts at START in FILE. This is slow.
+ function Extract_Expanded_Line (File : Source_File_Entry;
+ Start : Source_Ptr) return String
+ is
+ Buf : constant File_Buffer_Acc := Get_File_Source (File);
+ Len : constant Natural := Compute_Expanded_Line_Length (File, Start);
+ Res : String (1 .. Len);
+ P : Natural;
+ Pos : Source_Ptr;
+ C : Character;
+ begin
+ Pos := Start;
+ P := 0;
+ loop
+ C := Buf (Pos);
+ Pos := Pos + 1;
+ exit when C = ASCII.CR or C = ASCII.LF or C = ASCII.EOT;
+ if C = ASCII.HT then
+ -- Expand tab.
+ loop
+ P := P + 1;
+ Res (P) := ' ';
+ exit when P mod Tab_Stop = 0;
+ end loop;
+ else
+ P := P + 1;
+ Res (P) := C;
+ end if;
+ end loop;
+ pragma Assert (P = Res'Last);
+ return Res;
+ end Extract_Expanded_Line;
+
+ function Extract_Expanded_Line (File : Source_File_Entry;
+ Line : Natural) return String
+ is
+ Start : constant Source_Ptr := Line_To_Position (File, Line);
+ begin
+ return Extract_Expanded_Line (File, Start);
+ end Extract_Expanded_Line;
+
-- Debug procedures.
procedure Debug_Source_Lines (File: Source_File_Entry);
pragma Unreferenced (Debug_Source_Lines);