aboutsummaryrefslogtreecommitdiffstats
path: root/src/name_table.adb
diff options
context:
space:
mode:
authorTristan Gingold <tgingold@free.fr>2016-10-31 06:21:50 +0100
committerTristan Gingold <tgingold@free.fr>2016-11-01 21:36:54 +0100
commitbbe42c9fa216335dd56424014bda666a5d6717de (patch)
treecb19303410706351a059f2e65f73d7a4f2d28b85 /src/name_table.adb
parentb869a4acb52358fe8ca5decaac826af056bfdfca (diff)
downloadghdl-bbe42c9fa216335dd56424014bda666a5d6717de.tar.gz
ghdl-bbe42c9fa216335dd56424014bda666a5d6717de.tar.bz2
ghdl-bbe42c9fa216335dd56424014bda666a5d6717de.zip
name_table: auto-initialize.
Diffstat (limited to 'src/name_table.adb')
-rw-r--r--src/name_table.adb23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/name_table.adb b/src/name_table.adb
index b4bc24ca4..3d0010bce 100644
--- a/src/name_table.adb
+++ b/src/name_table.adb
@@ -1,5 +1,5 @@
-- Name table.
--- Copyright (C) 2002, 2003, 2004, 2005 Tristan Gingold
+-- Copyright (C) 2002 - 2016 Tristan Gingold
--
-- GHDL is free software; you can redistribute it and/or modify it under
-- the terms of the GNU General Public License as published by the Free
@@ -52,6 +52,9 @@ package body Name_Table is
type Hash_Array is array (Hash_Value_Type range <>) of Name_Id;
type Hash_Array_Acc is access Hash_Array;
+ procedure Deallocate is new Ada.Unchecked_Deallocation
+ (Hash_Array, Hash_Array_Acc);
+
-- Hash table. Lower bound is always 0, upper bound is always
-- Hash_Table_Size - 1.
Hash_Table: Hash_Array_Acc;
@@ -107,7 +110,7 @@ package body Name_Table is
Strings_Table.Append (NUL);
- -- Reserve entry 0.
+ -- Reserve entry 0 for Null_Identifier.
Strings_Table.Append (NUL);
Names_Table.Append ((Hash => 0,
Name => Strings_Table.Last,
@@ -128,10 +131,19 @@ package body Name_Table is
Append_Terminator;
+ -- Allocate the Hash_Table.
+ Hash_Table_Size := 1024;
Hash_Table :=
new Hash_Array'(0 .. Hash_Table_Size - 1 => Null_Identifier);
end Initialize;
+ procedure Finalize is
+ begin
+ Strings_Table.Free;
+ Names_Table.Free;
+ Deallocate (Hash_Table);
+ end Finalize;
+
-- Compute the hash value of a string. In case of algorithm change, check
-- the performance using Disp_Stats.
function Hash return Hash_Value_Type
@@ -238,9 +250,6 @@ package body Name_Table is
-- Expand the hash table (double the size).
procedure Expand
is
- procedure Deallocate is new Ada.Unchecked_Deallocation
- (Hash_Array, Hash_Array_Acc);
-
Old_Hash_Table : Hash_Array_Acc;
Id : Name_Id;
begin
@@ -309,8 +318,6 @@ package body Name_Table is
Hash_Table (Hash_Index) := Res;
Append_Terminator;
- --Put_Line ("created");
-
return Res;
end Get_Identifier;
@@ -442,4 +449,6 @@ package body Name_Table is
end loop;
end;
end Disp_Stats;
+begin
+ Initialize;
end Name_Table;