diff options
| author | Tristan Gingold <tgingold@free.fr> | 2019-11-06 19:25:48 +0100 | 
|---|---|---|
| committer | Tristan Gingold <tgingold@free.fr> | 2019-11-06 19:25:48 +0100 | 
| commit | 3a49c7ff29374c6f085e2d9dc46b200afbfc9a2c (patch) | |
| tree | ce3a3827b3a75f9a4114323c7f9dfc9e8d004204 | |
| parent | e1696a45ccf414f0c22d64176a71f8f64472a1d6 (diff) | |
| download | ghdl-3a49c7ff29374c6f085e2d9dc46b200afbfc9a2c.tar.gz ghdl-3a49c7ff29374c6f085e2d9dc46b200afbfc9a2c.tar.bz2 ghdl-3a49c7ff29374c6f085e2d9dc46b200afbfc9a2c.zip  | |
files_map-editor: turn Replace_Text to a function.
| -rw-r--r-- | python/libghdl/thin/files_map_editor.py | 4 | ||||
| -rw-r--r-- | src/files_map-editor.adb | 36 | ||||
| -rw-r--r-- | src/files_map-editor.ads | 29 | 
3 files changed, 39 insertions, 30 deletions
diff --git a/python/libghdl/thin/files_map_editor.py b/python/libghdl/thin/files_map_editor.py index e19317d0e..7fc1b64c3 100644 --- a/python/libghdl/thin/files_map_editor.py +++ b/python/libghdl/thin/files_map_editor.py @@ -1,6 +1,10 @@ +from ctypes import c_int32, c_char_p, c_bool  from libghdl import libghdl  Replace_Text = libghdl.files_map__editor__replace_text_ptr +Replace_Text.argstype = [c_int32, c_int32, c_int32, c_int32, c_char_p, c_int32] +Replace_Text.restype = c_bool +  Fill_Text = libghdl.files_map__editor__fill_text_ptr  Check_Buffer_Content = libghdl.files_map__editor__check_buffer_content diff --git a/src/files_map-editor.adb b/src/files_map-editor.adb index fb5721a47..1324ef62c 100644 --- a/src/files_map-editor.adb +++ b/src/files_map-editor.adb @@ -248,12 +248,12 @@ package body Files_Map.Editor is        return Res;     end Count_Newlines; -   procedure Replace_Text (File : Source_File_Entry; -                           Start_Line : Positive; -                           Start_Off  : Natural; -                           End_Line   : Positive; -                           End_Off    : Natural; -                           Text       : File_Buffer) +   function Replace_Text (File : Source_File_Entry; +                          Start_Line : Positive; +                          Start_Off  : Natural; +                          End_Line   : Positive; +                          End_Off    : Natural; +                          Text       : File_Buffer) return Boolean     is        pragma Assert (File <= Source_Files.Last);        F : Source_File_Record renames Source_Files.Table (File); @@ -276,7 +276,7 @@ package body Files_Map.Editor is           --  Check there is enough space.           if Text_Len > Gap_Size + Range_Size then -            raise Constraint_Error; +            return False;           end if;           --  Replace text, handle new lines. @@ -323,7 +323,7 @@ package body Files_Map.Editor is           begin              --  No change in newlines.              if Text_Lines = 0 and then Orig_Lines = 0 then -               return; +               return True;              end if;              --  Make room for lines table. @@ -359,18 +359,20 @@ package body Files_Map.Editor is              Check_Buffer_Lines (File);           end;        end; + +      return True;     end Replace_Text; -   procedure Replace_Text_Ptr (File : Source_File_Entry; -                               Start_Line : Positive; -                               Start_Off  : Natural; -                               End_Line   : Positive; -                               End_Off    : Natural; -                               Text_Ptr   : File_Buffer_Ptr; -                               Text_Len   : Source_Ptr) is +   function Replace_Text_Ptr (File : Source_File_Entry; +                              Start_Line : Positive; +                              Start_Off  : Natural; +                              End_Line   : Positive; +                              End_Off    : Natural; +                              Text_Ptr   : File_Buffer_Ptr; +                              Text_Len   : Source_Ptr) return Boolean is     begin -      Replace_Text (File, Start_Line, Start_Off, End_Line, End_Off, -                    Text_Ptr (0 .. Text_Len - 1)); +      return Replace_Text (File, Start_Line, Start_Off, End_Line, End_Off, +                           Text_Ptr (0 .. Text_Len - 1));     end Replace_Text_Ptr;     procedure Set_Gap (File : Source_File_Entry; diff --git a/src/files_map-editor.ads b/src/files_map-editor.ads index a2e3175e1..d45e83c45 100644 --- a/src/files_map-editor.ads +++ b/src/files_map-editor.ads @@ -17,20 +17,23 @@  --  02111-1307, USA.  package Files_Map.Editor is -   procedure Replace_Text (File : Source_File_Entry; -                           Start_Line : Positive; -                           Start_Off  : Natural; -                           End_Line   : Positive; -                           End_Off    : Natural; -                           Text       : File_Buffer); +   --  Replace [START; END) by TEXT.  Return True in case of success, False +   --  in case of failure (the gap is too small). +   function Replace_Text (File : Source_File_Entry; +                          Start_Line : Positive; +                          Start_Off  : Natural; +                          End_Line   : Positive; +                          End_Off    : Natural; +                          Text       : File_Buffer) return Boolean; -   procedure Replace_Text_Ptr (File : Source_File_Entry; -                               Start_Line : Positive; -                               Start_Off  : Natural; -                               End_Line   : Positive; -                               End_Off    : Natural; -                               Text_Ptr   : File_Buffer_Ptr; -                               Text_Len   : Source_Ptr); +   --  Likewise, but with pointer + length string. +   function Replace_Text_Ptr (File : Source_File_Entry; +                              Start_Line : Positive; +                              Start_Off  : Natural; +                              End_Line   : Positive; +                              End_Off    : Natural; +                              Text_Ptr   : File_Buffer_Ptr; +                              Text_Len   : Source_Ptr) return Boolean;     --  Replace the content of FILE with TEXT.     procedure Fill_Text_Ptr (File : Source_File_Entry;  | 
