diff options
Diffstat (limited to 'pyGHDL/libghdl/files_map.py')
| -rw-r--r-- | pyGHDL/libghdl/files_map.py | 73 | 
1 files changed, 34 insertions, 39 deletions
| diff --git a/pyGHDL/libghdl/files_map.py b/pyGHDL/libghdl/files_map.py index 72c14793e..7e2ae0abc 100644 --- a/pyGHDL/libghdl/files_map.py +++ b/pyGHDL/libghdl/files_map.py @@ -6,9 +6,9 @@  # | .__/ \__, |\____|_| |_|____/|_____(_)_|_|_.__/ \__, |_| |_|\__,_|_|  # |_|    |___/                                     |___/  # ============================================================================= -#  Authors: -#    Tristan Gingold -#    Patrick Lehmann +# Authors: +#   Tristan Gingold +#   Patrick Lehmann  #  # Package package:  Python binding and low-level API for shared library 'libghdl'.  # @@ -32,12 +32,10 @@  # SPDX-License-Identifier: GPL-2.0-or-later  # ============================================================================ -from ctypes import c_void_p -  from pydecor import export -from pyGHDL.libghdl import libghdl -from pyGHDL.libghdl._types import NameId, SourceFileEntry +from pyGHDL.libghdl._decorator import BindToLibGHDL +from pyGHDL.libghdl._types import NameId, SourceFileEntry, Location_Type  __all__ = [      "EOT", @@ -53,18 +51,19 @@ No_Location = 0  @export -def Location_To_File(Location) -> SourceFileEntry: +@BindToLibGHDL("files_map__location_to_file") +def Location_To_File(Location: Location_Type) -> SourceFileEntry:      """      Convert :obj:`Location` to a source file.      :param Location: Location      :return:         Source file. Return ``No_Source_File_Entry`` if location is incorrect.      """ -    return libghdl.files_map__location_to_file(Location)  @export -def Location_File_To_Pos(Location, File: SourceFileEntry) -> int: +@BindToLibGHDL("files_map__location_file_to_pos") +def Location_File_To_Pos(Location: Location_Type, File: SourceFileEntry) -> int:      """      Convert :obj:`Location` and :obj:`File` to a position (offset) into the source file. @@ -72,11 +71,11 @@ def Location_File_To_Pos(Location, File: SourceFileEntry) -> int:      :param File:     Source file      :return:         Offset      """ -    return libghdl.files_map__location_file_to_pos(Location, File)  @export -def Location_File_To_Line(Location, File: SourceFileEntry) -> int: +@BindToLibGHDL("files_map__location_file_to_line") +def Location_File_To_Line(Location: Location_Type, File: SourceFileEntry) -> int:      """      Convert :obj:`Location` and :obj:`File` to a line number. @@ -84,11 +83,11 @@ def Location_File_To_Line(Location, File: SourceFileEntry) -> int:      :param File:     Source file      :return:         Line number      """ -    return libghdl.files_map__location_file_to_line(Location, File)  @export -def Location_File_Line_To_Offset(Location, File: SourceFileEntry, Line: int) -> int: +@BindToLibGHDL("files_map__location_file_line_to_offset") +def Location_File_Line_To_Offset(Location: Location_Type, File: SourceFileEntry, Line: int) -> int:      """      Get the offset in :obj:`Line` of :obj:`Location`. @@ -97,11 +96,11 @@ def Location_File_Line_To_Offset(Location, File: SourceFileEntry, Line: int) ->      :param Line:     Line number      :return:         Offset      """ -    return libghdl.files_map__location_file_line_to_offset(Location, File, Line)  @export -def Location_File_Line_To_Col(Location, File: SourceFileEntry, Line: int) -> int: +@BindToLibGHDL("files_map__location_file_line_to_col") +def Location_File_Line_To_Col(Location: Location_Type, File: SourceFileEntry, Line: int) -> int:      """      Get logical column (with HT expanded) from :obj:`Location`, :obj:`File` and      :obj:`Line`. @@ -111,32 +110,32 @@ def Location_File_Line_To_Col(Location, File: SourceFileEntry, Line: int) -> int      :param Line:     Line number      :return:         logical column (horizontal tabs are expanded)      """ -    return libghdl.files_map__location_file_line_to_col(Location, File, Line)  @export -def File_To_Location(File: SourceFileEntry): +@BindToLibGHDL("files_map__file_to_location") +def File_To_Location(File: SourceFileEntry) -> Location_Type:      """Convert a :obj:`File` into a location.      :param File: Source file -    :return:     Location. Type: ``Location_Type`` +    :return:     Location.      """ -    return libghdl.files_map__file_to_location(File)  @export -def File_Pos_To_Location(File: SourceFileEntry, Pos: int): +@BindToLibGHDL("files_map__file_pos_to_location") +def File_Pos_To_Location(File: SourceFileEntry, Pos: int) -> Location_Type:      """      Convert a :obj:`File` and an offset :obj:`Pos` in the file into a location.      :param File: Source file      :param Pos:  Offset in the file -    :return:     Location. Type: ``Location_Type`` +    :return:     Location.      """ -    return libghdl.files_map__file_pos_to_location(File, Pos)  @export +@BindToLibGHDL("files_map__file_line_to_position")  def File_Line_To_Position(File: SourceFileEntry, Line: int) -> int:      """      Convert a :obj:`File` and :obj:`Line` into a position. @@ -145,10 +144,10 @@ def File_Line_To_Position(File: SourceFileEntry, Line: int) -> int:      :param Line: Line number      :return:     Return ``Source_Ptr_Bad`` in case of error (:obj:`Line` out of bounds).      """ -    return libghdl.files_map__file_line_to_position(File, Line)  @export +@BindToLibGHDL("files_map__get_file_name")  def Get_File_Name(File: SourceFileEntry) -> NameId:      """      Return the name of the file. @@ -156,10 +155,10 @@ def Get_File_Name(File: SourceFileEntry) -> NameId:      :param File: Source file to get the filename from.      :return:     NameId for the filename.      """ -    return libghdl.files_map__get_file_name(File)  @export +@BindToLibGHDL("files_map__get_directory_name")  def Get_Directory_Name(File: SourceFileEntry) -> NameId:      """      Return the directory of the file. @@ -167,10 +166,10 @@ def Get_Directory_Name(File: SourceFileEntry) -> NameId:      :param File: Source file to get the directory name from.      :return:     NameId for the directory.      """ -    return libghdl.files_map__get_directory_name(File)  @export +@BindToLibGHDL("files_map__get_file_buffer")  def Get_File_Buffer(File: SourceFileEntry) -> bytes:      """      Return a buffer (access to the contents of the file) for a file entry. @@ -178,13 +177,10 @@ def Get_File_Buffer(File: SourceFileEntry) -> bytes:      :param File: Source file to get the buffer from.      :return:     Type: ``File_Buffer_Ptr``      """ -    func = libghdl.files_map__get_file_buffer -    func.restype = c_void_p - -    return func(File)  @export +@BindToLibGHDL("files_map__get_file_length")  def Get_File_Length(File: SourceFileEntry) -> int:      """      Get the position of the first EOT character. @@ -192,10 +188,10 @@ def Get_File_Length(File: SourceFileEntry) -> int:      :param File: Source file      :return:     Type: ``Source_Ptr``      """ -    return libghdl.files_map__get_file_length(File)  @export +@BindToLibGHDL("files_map__set_file_length")  def Set_File_Length(File: SourceFileEntry, Length: int) -> None:      """      Set the length of the file (which is less than the size of the file buffer). @@ -205,10 +201,10 @@ def Set_File_Length(File: SourceFileEntry, Length: int) -> None:      :param File:   Source file      :param Length: Length for the file. Type: ``Source_Ptr``      """ -    libghdl.files_map__set_file_length(File, Length) -@export +# @export +@BindToLibGHDL("files_map__read_source_file")  def Read_Source_File(Directory: NameId, Name: NameId) -> SourceFileEntry:      """      Return an entry for a filename. @@ -219,11 +215,11 @@ def Read_Source_File(Directory: NameId, Name: NameId) -> SourceFileEntry:      :param Name:      File name      :return:          Return ``No_Source_File_Entry``, if the file does not exist.      """ -    return libghdl.files_map__read_source_file(Directory, Name)  @export -def Reserve_Source_File(Directory: NameId, Name: NameId, Length) -> SourceFileEntry: +@BindToLibGHDL("files_map__reserve_source_file") +def Reserve_Source_File(Directory: NameId, Name: NameId, Length: int) -> SourceFileEntry:      """      Reserve an entry, but do not read any file. @@ -234,10 +230,10 @@ def Reserve_Source_File(Directory: NameId, Name: NameId, Length) -> SourceFileEn      :param Length:    Length to reserve. Type: ``Source_Ptr``      :return:          SourceFile      """ -    return libghdl.files_map__reserve_source_file(Directory, Name, Length)  @export +@BindToLibGHDL("files_map__discard_source_file")  def Discard_Source_File(File: SourceFileEntry) -> None:      """      Mark :obj:`File` as unavailable: clear the name and directory. @@ -246,10 +242,10 @@ def Discard_Source_File(File: SourceFileEntry) -> None:      :param File: Source file to discard.      """ -    libghdl.files_map__discard_source_file(File)  @export +@BindToLibGHDL("files_map__free_source_file")  def Free_Source_File(File: SourceFileEntry) -> None:      """      Free resources used by :obj:`File`, but keep the entry. @@ -258,10 +254,10 @@ def Free_Source_File(File: SourceFileEntry) -> None:      :param File: Source file to free.      """ -    libghdl.files_map__free_source_file(File)  @export +@BindToLibGHDL("files_map__get_last_source_file_entry")  def Get_Last_Source_File_Entry() -> SourceFileEntry:      """      Returns the entry of the last known file. @@ -270,4 +266,3 @@ def Get_Last_Source_File_Entry() -> SourceFileEntry:      :return: Last SourceFileEntry. Type: ``SourceFileEntry``      """ -    return libghdl.files_map__get_last_source_file_entry() | 
