diff options
Diffstat (limited to 'pyGHDL/libghdl/files_map.py')
-rw-r--r-- | pyGHDL/libghdl/files_map.py | 255 |
1 files changed, 128 insertions, 127 deletions
diff --git a/pyGHDL/libghdl/files_map.py b/pyGHDL/libghdl/files_map.py index 71ed32e9e..72c14793e 100644 --- a/pyGHDL/libghdl/files_map.py +++ b/pyGHDL/libghdl/files_map.py @@ -40,9 +40,9 @@ from pyGHDL.libghdl import libghdl from pyGHDL.libghdl._types import NameId, SourceFileEntry __all__ = [ - 'EOT', - 'No_Source_File_Entry', - 'No_Location', + "EOT", + "No_Source_File_Entry", + "No_Location", ] EOT = b"\x04" @@ -54,219 +54,220 @@ No_Location = 0 @export def Location_To_File(Location) -> SourceFileEntry: - """ - Convert :obj:`Location` to a source file. + """ + 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) + :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: - """ - Convert :obj:`Location` and :obj:`File` to a position (offset) into the source file. + """ + Convert :obj:`Location` and :obj:`File` to a position (offset) into the source file. - :param Location: Location - :param File: Source file - :return: Offset - """ - return libghdl.files_map__location_file_to_pos(Location, File) + :param Location: Location + :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: - """ - Convert :obj:`Location` and :obj:`File` to a line number. + """ + Convert :obj:`Location` and :obj:`File` to a line number. - :param Location: Location - :param File: Source file - :return: Line number - """ - return libghdl.files_map__location_file_to_line(Location, File) + :param Location: Location + :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: - """ - Get the offset in :obj:`Line` of :obj:`Location`. + """ + Get the offset in :obj:`Line` of :obj:`Location`. - :param Location: Location - :param File: Source file - :param Line: Line number - :return: Offset - """ - return libghdl.files_map__location_file_line_to_offset(Location, File, Line) + :param Location: Location + :param File: Source file + :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: - """ - Get logical column (with HT expanded) from :obj:`Location`, :obj:`File` and - :obj:`Line`. + """ + Get logical column (with HT expanded) from :obj:`Location`, :obj:`File` and + :obj:`Line`. - :param Location: Location - :param File: Source file - :param Line: Line number - :return: logical column (horizontal tabs are expanded) - """ - return libghdl.files_map__location_file_line_to_col(Location, File, Line) + :param Location: Location + :param File: Source file + :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): - """Convert a :obj:`File` into a location. + """Convert a :obj:`File` into a location. - :param File: Source file - :return: Location. Type: ``Location_Type`` - """ - return libghdl.files_map__file_to_location(File) + :param File: Source file + :return: Location. Type: ``Location_Type`` + """ + return libghdl.files_map__file_to_location(File) @export def File_Pos_To_Location(File: SourceFileEntry, Pos: int): - """ - Convert a :obj:`File` and an offset :obj:`Pos` in the file into a location. + """ + 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 libghdl.files_map__file_pos_to_location(File, Pos) + :param File: Source file + :param Pos: Offset in the file + :return: Location. Type: ``Location_Type`` + """ + return libghdl.files_map__file_pos_to_location(File, Pos) @export def File_Line_To_Position(File: SourceFileEntry, Line: int) -> int: - """ - Convert a :obj:`File` and :obj:`Line` into a position. + """ + Convert a :obj:`File` and :obj:`Line` into a position. - :param File: Source file - :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) + :param File: Source file + :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 def Get_File_Name(File: SourceFileEntry) -> NameId: - """ - Return the name of the file. + """ + Return the name of the file. - :param File: Source file to get the filename from. - :return: NameId for the filename. - """ - return libghdl.files_map__get_file_name(File) + :param File: Source file to get the filename from. + :return: NameId for the filename. + """ + return libghdl.files_map__get_file_name(File) @export def Get_Directory_Name(File: SourceFileEntry) -> NameId: - """ - Return the directory of the file. + """ + Return the directory of the file. - :param File: Source file to get the directory name from. - :return: NameId for the directory. - """ - return libghdl.files_map__get_directory_name(File) + :param File: Source file to get the directory name from. + :return: NameId for the directory. + """ + return libghdl.files_map__get_directory_name(File) @export def Get_File_Buffer(File: SourceFileEntry) -> bytes: - """ - Return a buffer (access to the contents of the file) for a file entry. + """ + Return a buffer (access to the contents of the file) for a file entry. - :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 + :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) + return func(File) @export def Get_File_Length(File: SourceFileEntry) -> int: - """ - Get the position of the first EOT character. + """ + Get the position of the first EOT character. - :param File: Source file - :return: Type: ``Source_Ptr`` - """ - return libghdl.files_map__get_file_length(File) + :param File: Source file + :return: Type: ``Source_Ptr`` + """ + return libghdl.files_map__get_file_length(File) @export 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). + """ + Set the length of the file (which is less than the size of the file buffer). - Set also append two EOT at the end of the file. + Set also append two EOT at the end of the file. - :param File: Source file - :param Length: Length for the file. Type: ``Source_Ptr`` - """ - libghdl.files_map__set_file_length(File, Length) + :param File: Source file + :param Length: Length for the file. Type: ``Source_Ptr`` + """ + libghdl.files_map__set_file_length(File, Length) @export def Read_Source_File(Directory: NameId, Name: NameId) -> SourceFileEntry: - """ - Return an entry for a filename. + """ + Return an entry for a filename. - Load the filename if necessary. + Load the filename if necessary. - :param Directory: ``Null_Identifier`` for :obj:`DirectoryId` means current directory. - :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) + :param Directory: ``Null_Identifier`` for :obj:`DirectoryId` means current directory. + :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: - """ - Reserve an entry, but do not read any file. + """ + Reserve an entry, but do not read any file. - The length should includes the two terminal EOT. + The length should includes the two terminal EOT. + + :param Directory: Directory name + :param Name: File name + :param Length: Length to reserve. Type: ``Source_Ptr`` + :return: SourceFile + """ + return libghdl.files_map__reserve_source_file(Directory, Name, Length) - :param Directory: Directory name - :param Name: File name - :param Length: Length to reserve. Type: ``Source_Ptr`` - :return: SourceFile - """ - return libghdl.files_map__reserve_source_file(Directory, Name, Length) @export def Discard_Source_File(File: SourceFileEntry) -> None: - """ - Mark :obj:`File` as unavailable: clear the name and directory. + """ + Mark :obj:`File` as unavailable: clear the name and directory. - .. hint:: This is needed before creating a new source file with the same name. + .. hint:: This is needed before creating a new source file with the same name. - :param File: Source file to discard. - """ - libghdl.files_map__discard_source_file(File) + :param File: Source file to discard. + """ + libghdl.files_map__discard_source_file(File) @export def Free_Source_File(File: SourceFileEntry) -> None: - """ - Free resources used by :obj:`File`, but keep the entry. + """ + Free resources used by :obj:`File`, but keep the entry. - .. note:: It could be recycled for files that could fit - not implemented. + .. note:: It could be recycled for files that could fit - not implemented. - :param File: Source file to free. - """ - libghdl.files_map__free_source_file(File) + :param File: Source file to free. + """ + libghdl.files_map__free_source_file(File) @export def Get_Last_Source_File_Entry() -> SourceFileEntry: - """ - Returns the entry of the last known file. + """ + Returns the entry of the last known file. - .. hint:: This allows creating a table of ``SourceFileEntry``. + .. hint:: This allows creating a table of ``SourceFileEntry``. - :return: Last SourceFileEntry. Type: ``SourceFileEntry`` - """ - return libghdl.files_map__get_last_source_file_entry() + :return: Last SourceFileEntry. Type: ``SourceFileEntry`` + """ + return libghdl.files_map__get_last_source_file_entry() |