diff options
-rw-r--r-- | src/files_map-editor.adb | 29 | ||||
-rw-r--r-- | src/files_map-editor.ads | 8 | ||||
-rw-r--r-- | src/vhdl/python/libghdl/thin/files_map_editor.py | 2 |
3 files changed, 34 insertions, 5 deletions
diff --git a/src/files_map-editor.adb b/src/files_map-editor.adb index 06b5d3385..6253d1cf7 100644 --- a/src/files_map-editor.adb +++ b/src/files_map-editor.adb @@ -373,6 +373,35 @@ package body Files_Map.Editor is Text_Ptr (0 .. Text_Len - 1)); end Replace_Text_Ptr; + procedure Fill_Text_Ptr (File : Source_File_Entry; + Text_Ptr : File_Buffer_Ptr; + Text_Len : Source_Ptr) + is + pragma Assert (File <= Source_Files.Last); + F : Source_File_Record renames Source_Files.Table (File); + Buf_Len : constant Source_Ptr := Get_Buffer_Length (File); + begin + if Text_Len + 2 > Buf_Len then + raise Constraint_Error; + end if; + + if Text_Len > 0 then + F.Source (Source_Ptr_Org .. Source_Ptr_Org + Text_Len - 1) := + Text_Ptr (Source_Ptr_Org .. Source_Ptr_Org + Text_Len - 1); + end if; + Set_File_Length (File, Text_Len); + Set_Gap (File, Text_Len + 2, Buf_Len - 1); + + -- Clear cache. + F.Cache_Line := 1; + F.Cache_Pos := Source_Ptr_Org; + + -- Reset line table. + Lines_Tables.Free (F.Lines); + Lines_Tables.Init (F.Lines); + File_Add_Line_Number (File, 1, Source_Ptr_Org); + end Fill_Text_Ptr; + procedure Set_Gap (File : Source_File_Entry; First : Source_Ptr; Last : Source_Ptr) diff --git a/src/files_map-editor.ads b/src/files_map-editor.ads index 5e2cb21e7..a2e3175e1 100644 --- a/src/files_map-editor.ads +++ b/src/files_map-editor.ads @@ -32,10 +32,10 @@ package Files_Map.Editor is Text_Ptr : File_Buffer_Ptr; Text_Len : Source_Ptr); - -- Set the position of the GAP in FILE. - procedure Set_Gap (File : Source_File_Entry; - First : Source_Ptr; - Last : Source_Ptr); + -- Replace the content of FILE with TEXT. + procedure Fill_Text_Ptr (File : Source_File_Entry; + Text_Ptr : File_Buffer_Ptr; + Text_Len : Source_Ptr); -- Recompute lines number. procedure Compute_Lines (File : Source_File_Entry); diff --git a/src/vhdl/python/libghdl/thin/files_map_editor.py b/src/vhdl/python/libghdl/thin/files_map_editor.py index 27ea6feda..e19317d0e 100644 --- a/src/vhdl/python/libghdl/thin/files_map_editor.py +++ b/src/vhdl/python/libghdl/thin/files_map_editor.py @@ -1,6 +1,6 @@ from libghdl import libghdl -Set_Gap = libghdl.files_map__editor__set_gap Replace_Text = libghdl.files_map__editor__replace_text_ptr +Fill_Text = libghdl.files_map__editor__fill_text_ptr Check_Buffer_Content = libghdl.files_map__editor__check_buffer_content |