aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2017-10-02 20:45:43 +0200
committerTristan Gingold <tgingold@free.fr>2017-10-02 20:49:37 +0200
commit255fb07204db93a302305795c2220901cf7a883e (patch)
tree095d97ded9e57a481fb8ab93ab69b5caee3bf999 /src
parentd97fd3b7db69c4268bf49b5b82fa00656020375a (diff)
downloadghdl-255fb07204db93a302305795c2220901cf7a883e.tar.gz
ghdl-255fb07204db93a302305795c2220901cf7a883e.tar.bz2
ghdl-255fb07204db93a302305795c2220901cf7a883e.zip
Add subprograms in Files_Map and Name_Table for interfacing.
Renames Fat_String_Acc to Thin_String_Ptr.
Diffstat (limited to 'src')
-rw-r--r--src/files_map.adb37
-rw-r--r--src/files_map.ads12
-rw-r--r--src/name_table.adb16
-rw-r--r--src/name_table.ads2
-rw-r--r--src/types.ads13
5 files changed, 58 insertions, 22 deletions
diff --git a/src/files_map.adb b/src/files_map.adb
index 3a8fa071c..afd0d9a6f 100644
--- a/src/files_map.adb
+++ b/src/files_map.adb
@@ -127,9 +127,8 @@ package body Files_Map is
return Home_Dir;
end Get_Home_Directory;
- procedure Location_To_File_Pos (Location : Location_Type;
- File : out Source_File_Entry;
- Pos : out Source_Ptr) is
+ function Location_To_File (Location : Location_Type)
+ return Source_File_Entry is
begin
-- FIXME: use a cache
-- FIXME: dicotomy
@@ -140,14 +139,29 @@ package body Files_Map is
if Location >= F.First_Location
and then Location <= F.Last_Location
then
- File := I;
- Pos := Source_Ptr (Location - F.First_Location);
- return;
+ return I;
end if;
end;
end loop;
- -- File not found, location must be bad...
- raise Internal_Error;
+ return No_Source_File_Entry;
+ end Location_To_File;
+
+ function Location_File_To_Pos
+ (Location : Location_Type; File : Source_File_Entry) return Source_Ptr is
+ begin
+ return Source_Ptr (Location - Source_Files.Table (File).First_Location);
+ end Location_File_To_Pos;
+
+ procedure Location_To_File_Pos (Location : Location_Type;
+ File : out Source_File_Entry;
+ Pos : out Source_Ptr) is
+ begin
+ File := Location_To_File (Location);
+ if File = No_Source_File_Entry then
+ -- File not found, location must be correct.
+ raise Internal_Error;
+ end if;
+ Pos := Location_File_To_Pos (Location, File);
end Location_To_File_Pos;
function File_Pos_To_Location (File : Source_File_Entry; Pos : Source_Ptr)
@@ -874,6 +888,13 @@ package body Files_Map is
return Source_Files.Table (File).Source;
end Get_File_Source;
+ function Get_File_Buffer (File : Source_File_Entry)
+ return File_Buffer_Ptr is
+ begin
+ return To_File_Buffer_Ptr
+ (Source_Files.Table (File).Source (Source_Ptr_Org)'Address);
+ end Get_File_Buffer;
+
-- Return the length of the file (which is the size of the file buffer).
function Get_File_Length (File: Source_File_Entry) return Source_Ptr is
begin
diff --git a/src/files_map.ads b/src/files_map.ads
index b3fa5b7fe..c7c5da447 100644
--- a/src/files_map.ads
+++ b/src/files_map.ads
@@ -88,6 +88,9 @@ package Files_Map is
-- Return a buffer (access to the contents of the file) for a file entry.
function Get_File_Source (File : Source_File_Entry) return File_Buffer_Acc;
+ -- Likewise but return a pointer. To be used only from non-Ada code.
+ function Get_File_Buffer (File : Source_File_Entry) return File_Buffer_Ptr;
+
-- Return the length of the file (which is the size of the file buffer).
function Get_File_Length (File : Source_File_Entry) return Source_Ptr;
@@ -129,6 +132,15 @@ package Files_Map is
procedure File_Add_Line_Number
(File : Source_File_Entry; Line : Natural; Pos : Source_Ptr);
+ -- Convert LOCATION to a source file. Return No_Source_File_Entry if
+ -- LOCATION is incorrect.
+ function Location_To_File (Location : Location_Type)
+ return Source_File_Entry;
+
+ -- Convert LOCATION and FILE to a position (offset) into the source file.
+ function Location_File_To_Pos
+ (Location : Location_Type; File : Source_File_Entry) return Source_Ptr;
+
-- Convert LOCATION into a source file FILE and an offset POS in the
-- file.
procedure Location_To_File_Pos (Location : Location_Type;
diff --git a/src/name_table.adb b/src/name_table.adb
index 3332f755b..7e5413415 100644
--- a/src/name_table.adb
+++ b/src/name_table.adb
@@ -79,7 +79,7 @@ package body Name_Table is
-- Allocate place in the strings_table, and store the name_buffer into it.
-- Also append a NUL.
- function Store (Str : Fat_String_Acc; Len : Natural) return Natural
+ function Store (Str : Thin_String_Ptr; Len : Natural) return Natural
is
Res: Natural;
begin
@@ -146,7 +146,7 @@ package body Name_Table is
-- Compute the hash value of a string. In case of algorithm change, check
-- the performance using Disp_Stats.
- function Compute_Hash (Str : Fat_String_Acc; Len : Natural)
+ function Compute_Hash (Str : Thin_String_Ptr; Len : Natural)
return Hash_Value_Type
is
use Interfaces;
@@ -239,7 +239,7 @@ package body Name_Table is
-- Compare ID with Str / Len. Length of ID must be equal to Len.
function Compare_Name_Buffer_With_Name
- (Id : Name_Id; Str : Fat_String_Acc; Len : Natural) return Boolean
+ (Id : Name_Id; Str : Thin_String_Ptr; Len : Natural) return Boolean
is
Ne: Identifier renames Names_Table.Table (Id);
begin
@@ -280,7 +280,7 @@ package body Name_Table is
end Expand;
-- Get or create an entry in the name table.
- function Get_Identifier_With_Len (Str : Fat_String_Acc; Len : Natural)
+ function Get_Identifier_With_Len (Str : Thin_String_Ptr; Len : Natural)
return Name_Id
is
Hash_Value : Hash_Value_Type;
@@ -324,11 +324,11 @@ package body Name_Table is
function Get_Identifier return Name_Id is
begin
return Get_Identifier_With_Len
- (To_Fat_String_Acc (Nam_Buffer'Address), Nam_Length);
+ (To_Thin_String_Ptr (Nam_Buffer'Address), Nam_Length);
end Get_Identifier;
function Get_Identifier_No_Create_With_Len
- (Str : Fat_String_Acc; Len : Natural) return Name_Id
+ (Str : Thin_String_Ptr; Len : Natural) return Name_Id
is
Hash_Value : Hash_Value_Type;
Hash_Index : Hash_Value_Type;
@@ -353,14 +353,14 @@ package body Name_Table is
function Get_Identifier_No_Create (Str : String) return Name_Id is
begin
return Get_Identifier_No_Create_With_Len
- (To_Fat_String_Acc (Str'Address), Str'Length);
+ (To_Thin_String_Ptr (Str'Address), Str'Length);
end Get_Identifier_No_Create;
-- Get or create an entry in the name table.
function Get_Identifier (Str : String) return Name_Id is
begin
return Get_Identifier_With_Len
- (To_Fat_String_Acc (Str'Address), Str'Length);
+ (To_Thin_String_Ptr (Str'Address), Str'Length);
end Get_Identifier;
function Get_Identifier (Char : Character) return Name_Id is
diff --git a/src/name_table.ads b/src/name_table.ads
index 2eb5f06b9..16bfc2bcd 100644
--- a/src/name_table.ads
+++ b/src/name_table.ads
@@ -73,7 +73,7 @@ package Name_Table is
-- is not found (and do not create an entry for it).
function Get_Identifier_No_Create (Str : String) return Name_Id;
function Get_Identifier_No_Create_With_Len
- (Str : Fat_String_Acc; Len : Natural) return Name_Id;
+ (Str : Thin_String_Ptr; Len : Natural) return Name_Id;
-- Get and set the info field associated with each identifier.
-- Used to store interpretations of the name.
diff --git a/src/types.ads b/src/types.ads
index 8a53d112e..2b1b056db 100644
--- a/src/types.ads
+++ b/src/types.ads
@@ -57,11 +57,10 @@ package Types is
type String_Acc_Array is array (Natural range <>) of String_Acc;
-- Fat strings, for compatibility with C.
- subtype Fat_String is String (Positive);
- type Fat_String_Acc is access Fat_String;
- pragma Convention (C, Fat_String_Acc);
- function To_Fat_String_Acc is new Ada.Unchecked_Conversion
- (System.Address, Fat_String_Acc);
+ type Thin_String_Ptr is access String (Positive);
+ pragma Convention (C, Thin_String_Ptr);
+ function To_Thin_String_Ptr is new Ada.Unchecked_Conversion
+ (System.Address, Thin_String_Ptr);
-- The name table is defined in Name_Table package. This is an hash table
-- that associate a uniq Name_Id to a string. Name_Id are allocated in
@@ -108,6 +107,10 @@ package Types is
-- Type of a file buffer.
type File_Buffer is array (Source_Ptr range <>) of Character;
type File_Buffer_Acc is access File_Buffer;
+ type File_Buffer_Ptr is access File_Buffer (Source_Ptr);
+
+ function To_File_Buffer_Ptr is new Ada.Unchecked_Conversion
+ (System.Address, File_Buffer_Ptr);
-- This type contains everything necessary to get a file name, a line
-- number and a column number.