diff options
-rw-r--r-- | gcc/ada/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/ada/libgnat/g-dynhta.adb | 93 | ||||
-rw-r--r-- | gcc/ada/libgnat/g-dynhta.ads | 51 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/gnat.dg/dynhash.adb | 41 | ||||
-rw-r--r-- | gcc/testsuite/gnat.dg/dynhash1.adb | 8 |
6 files changed, 128 insertions, 77 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index 95b52b6..c527b80 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,5 +1,13 @@ 2019-07-01 Hristian Kirtchev <kirtchev@adacore.com> + * libgnat/g-dynhta.adb: Use type Dynamic_Hash_Table rather than + Instance in various routines. + * libgnat/g-dynhta.ads: Change type Instance to + Dynamic_Hash_Table. Update various routines that mention the + type. + +2019-07-01 Hristian Kirtchev <kirtchev@adacore.com> + * exp_attr.adb, exp_ch7.adb, exp_unst.adb, sem_ch3.adb, sem_util.adb, uintp.adb, uintp.ads: Minor reformatting. diff --git a/gcc/ada/libgnat/g-dynhta.adb b/gcc/ada/libgnat/g-dynhta.adb index 31b77de..6cb4182 100644 --- a/gcc/ada/libgnat/g-dynhta.adb +++ b/gcc/ada/libgnat/g-dynhta.adb @@ -364,11 +364,11 @@ package body GNAT.Dynamic_HTables is end Set_Next; end Simple_HTable; - -------------------- - -- Dynamic_HTable -- - -------------------- + ------------------------- + -- Dynamic_Hash_Tables -- + ------------------------- - package body Dynamic_HTable is + package body Dynamic_Hash_Tables is Minimum_Size : constant Bucket_Range_Type := 8; -- Minimum size of the buckets @@ -382,7 +382,9 @@ package body GNAT.Dynamic_HTables is -- Maximum safe size for hash table expansion. Beyond this size, an -- expansion will overflow the buckets. - procedure Delete_Node (T : Instance; Nod : Node_Ptr); + procedure Delete_Node + (T : Dynamic_Hash_Table; + Nod : Node_Ptr); pragma Inline (Delete_Node); -- Detach and delete node Nod from table T @@ -398,12 +400,12 @@ package body GNAT.Dynamic_HTables is pragma Inline (Ensure_Circular); -- Ensure that dummy head Head is circular with respect to itself - procedure Ensure_Created (T : Instance); + procedure Ensure_Created (T : Dynamic_Hash_Table); pragma Inline (Ensure_Created); -- Verify that hash table T is created. Raise Not_Created if this is not -- the case. - procedure Ensure_Unlocked (T : Instance); + procedure Ensure_Unlocked (T : Dynamic_Hash_Table); pragma Inline (Ensure_Unlocked); -- Verify that hash table T is unlocked. Raise Iterated if this is not -- the case. @@ -422,7 +424,7 @@ package body GNAT.Dynamic_HTables is -- otherwise return null. procedure First_Valid_Node - (T : Instance; + (T : Dynamic_Hash_Table; Low_Bkt : Bucket_Range_Type; High_Bkt : Bucket_Range_Type; Idx : out Bucket_Range_Type; @@ -437,7 +439,8 @@ package body GNAT.Dynamic_HTables is new Ada.Unchecked_Deallocation (Bucket_Table, Bucket_Table_Ptr); procedure Free is - new Ada.Unchecked_Deallocation (Hash_Table, Instance); + new Ada.Unchecked_Deallocation + (Dynamic_Hash_Table_Attributes, Dynamic_Hash_Table); procedure Free is new Ada.Unchecked_Deallocation (Node, Node_Ptr); @@ -451,15 +454,17 @@ package body GNAT.Dynamic_HTables is -- Determine whether node Nod is non-null and does not refer to dummy -- head Head, thus making it valid. - function Load_Factor (T : Instance) return Threshold_Type; + function Load_Factor (T : Dynamic_Hash_Table) return Threshold_Type; pragma Inline (Load_Factor); -- Calculate the load factor of hash table T - procedure Lock (T : Instance); + procedure Lock (T : Dynamic_Hash_Table); pragma Inline (Lock); -- Lock all mutation functionality of hash table T - procedure Mutate_And_Rehash (T : Instance; Size : Bucket_Range_Type); + procedure Mutate_And_Rehash + (T : Dynamic_Hash_Table; + Size : Bucket_Range_Type); pragma Inline (Mutate_And_Rehash); -- Replace the buckets of hash table T with a new set of buckets of size -- Size. Rehash all key-value pairs from the old to the new buckets. @@ -476,7 +481,7 @@ package body GNAT.Dynamic_HTables is pragma Inline (Present); -- Determine whether node Nod exists - procedure Unlock (T : Instance); + procedure Unlock (T : Dynamic_Hash_Table); pragma Inline (Unlock); -- Unlock all mutation functionality of hash table T @@ -484,13 +489,13 @@ package body GNAT.Dynamic_HTables is -- Create -- ------------ - function Create (Initial_Size : Positive) return Instance is + function Create (Initial_Size : Positive) return Dynamic_Hash_Table is Size : constant Bucket_Range_Type := Bucket_Range_Type'Max (Bucket_Range_Type (Initial_Size), Minimum_Size); -- Ensure that the buckets meet a minimum size - T : constant Instance := new Hash_Table; + T : constant Dynamic_Hash_Table := new Dynamic_Hash_Table_Attributes; begin T.Buckets := new Bucket_Table (0 .. Size - 1); @@ -503,7 +508,10 @@ package body GNAT.Dynamic_HTables is -- Delete -- ------------ - procedure Delete (T : Instance; Key : Key_Type) is + procedure Delete + (T : Dynamic_Hash_Table; + Key : Key_Type) + is Head : Node_Ptr; Nod : Node_Ptr; @@ -531,7 +539,10 @@ package body GNAT.Dynamic_HTables is -- Delete_Node -- ----------------- - procedure Delete_Node (T : Instance; Nod : Node_Ptr) is + procedure Delete_Node + (T : Dynamic_Hash_Table; + Nod : Node_Ptr) + is procedure Compress; pragma Inline (Compress); -- Determine whether hash table T requires compression, and if so, @@ -586,7 +597,7 @@ package body GNAT.Dynamic_HTables is -- Destroy -- ------------- - procedure Destroy (T : in out Instance) is + procedure Destroy (T : in out Dynamic_Hash_Table) is begin Ensure_Created (T); Ensure_Unlocked (T); @@ -678,7 +689,7 @@ package body GNAT.Dynamic_HTables is -- Ensure_Created -- -------------------- - procedure Ensure_Created (T : Instance) is + procedure Ensure_Created (T : Dynamic_Hash_Table) is begin if not Present (T) then raise Not_Created; @@ -689,7 +700,7 @@ package body GNAT.Dynamic_HTables is -- Ensure_Unlocked -- --------------------- - procedure Ensure_Unlocked (T : Instance) is + procedure Ensure_Unlocked (T : Dynamic_Hash_Table) is begin pragma Assert (Present (T)); @@ -746,7 +757,7 @@ package body GNAT.Dynamic_HTables is ---------------------- procedure First_Valid_Node - (T : Instance; + (T : Dynamic_Hash_Table; Low_Bkt : Bucket_Range_Type; High_Bkt : Bucket_Range_Type; Idx : out Bucket_Range_Type; @@ -784,7 +795,10 @@ package body GNAT.Dynamic_HTables is -- Get -- --------- - function Get (T : Instance; Key : Key_Type) return Value_Type is + function Get + (T : Dynamic_Hash_Table; + Key : Key_Type) return Value_Type + is Head : Node_Ptr; Nod : Node_Ptr; @@ -814,8 +828,8 @@ package body GNAT.Dynamic_HTables is -------------- function Has_Next (Iter : Iterator) return Boolean is - Is_OK : constant Boolean := Is_Valid (Iter); - T : constant Instance := Iter.Table; + Is_OK : constant Boolean := Is_Valid (Iter); + T : constant Dynamic_Hash_Table := Iter.Table; begin pragma Assert (Present (T)); @@ -835,7 +849,7 @@ package body GNAT.Dynamic_HTables is -- Is_Empty -- -------------- - function Is_Empty (T : Instance) return Boolean is + function Is_Empty (T : Dynamic_Hash_Table) return Boolean is begin Ensure_Created (T); @@ -870,7 +884,7 @@ package body GNAT.Dynamic_HTables is -- Iterate -- ------------- - function Iterate (T : Instance) return Iterator is + function Iterate (T : Dynamic_Hash_Table) return Iterator is Iter : Iterator; begin @@ -906,7 +920,7 @@ package body GNAT.Dynamic_HTables is -- Load_Factor -- ----------------- - function Load_Factor (T : Instance) return Threshold_Type is + function Load_Factor (T : Dynamic_Hash_Table) return Threshold_Type is pragma Assert (Present (T)); pragma Assert (Present (T.Buckets)); @@ -920,7 +934,7 @@ package body GNAT.Dynamic_HTables is -- Lock -- ---------- - procedure Lock (T : Instance) is + procedure Lock (T : Dynamic_Hash_Table) is begin -- The hash table may be locked multiple times if multiple iterators -- are operating over it. @@ -932,7 +946,10 @@ package body GNAT.Dynamic_HTables is -- Mutate_And_Rehash -- ----------------------- - procedure Mutate_And_Rehash (T : Instance; Size : Bucket_Range_Type) is + procedure Mutate_And_Rehash + (T : Dynamic_Hash_Table; + Size : Bucket_Range_Type) + is procedure Rehash (From : Bucket_Table_Ptr; To : Bucket_Table_Ptr); pragma Inline (Rehash); -- Remove all nodes from buckets From and rehash them into buckets To @@ -1031,7 +1048,7 @@ package body GNAT.Dynamic_HTables is procedure Next (Iter : in out Iterator; Key : out Key_Type) is Is_OK : constant Boolean := Is_Valid (Iter); Saved : constant Node_Ptr := Iter.Curr_Nod; - T : constant Instance := Iter.Table; + T : constant Dynamic_Hash_Table := Iter.Table; Head : Node_Ptr; begin @@ -1109,7 +1126,7 @@ package body GNAT.Dynamic_HTables is -- Present -- ------------- - function Present (T : Instance) return Boolean is + function Present (T : Dynamic_Hash_Table) return Boolean is begin return T /= Nil; end Present; @@ -1118,7 +1135,11 @@ package body GNAT.Dynamic_HTables is -- Put -- --------- - procedure Put (T : Instance; Key : Key_Type; Value : Value_Type) is + procedure Put + (T : Dynamic_Hash_Table; + Key : Key_Type; + Value : Value_Type) + is procedure Expand; pragma Inline (Expand); -- Determine whether hash table T requires expansion, and if so, @@ -1223,7 +1244,7 @@ package body GNAT.Dynamic_HTables is -- Reset -- ----------- - procedure Reset (T : Instance) is + procedure Reset (T : Dynamic_Hash_Table) is begin Ensure_Created (T); Ensure_Unlocked (T); @@ -1243,7 +1264,7 @@ package body GNAT.Dynamic_HTables is -- Size -- ---------- - function Size (T : Instance) return Natural is + function Size (T : Dynamic_Hash_Table) return Natural is begin Ensure_Created (T); @@ -1254,13 +1275,13 @@ package body GNAT.Dynamic_HTables is -- Unlock -- ------------ - procedure Unlock (T : Instance) is + procedure Unlock (T : Dynamic_Hash_Table) is begin -- The hash table may be locked multiple times if multiple iterators -- are operating over it. T.Iterators := T.Iterators - 1; end Unlock; - end Dynamic_HTable; + end Dynamic_Hash_Tables; end GNAT.Dynamic_HTables; diff --git a/gcc/ada/libgnat/g-dynhta.ads b/gcc/ada/libgnat/g-dynhta.ads index 7b8d1d8..6c19f0f 100644 --- a/gcc/ada/libgnat/g-dynhta.ads +++ b/gcc/ada/libgnat/g-dynhta.ads @@ -258,9 +258,9 @@ package GNAT.Dynamic_HTables is Nil : constant Instance := Instance (Tab.Nil); end Simple_HTable; - -------------------- - -- Dynamic_HTable -- - -------------------- + ------------------------- + -- Dynamic_Hash_Tables -- + ------------------------- -- The following package offers a hash table abstraction with the following -- characteristics: @@ -275,7 +275,7 @@ package GNAT.Dynamic_HTables is -- -- The following use pattern must be employed when operating this table: -- - -- Table : Instance := Create (<some size>); + -- Table : Dynamic_Hash_Table := Create (<some size>); -- -- <various operations> -- @@ -333,7 +333,7 @@ package GNAT.Dynamic_HTables is with function Hash (Key : Key_Type) return Bucket_Range_Type; -- Map an arbitrary key into the range of buckets - package Dynamic_HTable is + package Dynamic_Hash_Tables is ---------------------- -- Table operations -- @@ -342,37 +342,44 @@ package GNAT.Dynamic_HTables is -- The following type denotes a hash table handle. Each instance must be -- created using routine Create. - type Instance is private; - Nil : constant Instance; + type Dynamic_Hash_Table is private; + Nil : constant Dynamic_Hash_Table; - function Create (Initial_Size : Positive) return Instance; + function Create (Initial_Size : Positive) return Dynamic_Hash_Table; -- Create a new table with bucket capacity Initial_Size. This routine -- must be called at the start of a hash table's lifetime. - procedure Delete (T : Instance; Key : Key_Type); + procedure Delete + (T : Dynamic_Hash_Table; + Key : Key_Type); -- Delete the value which corresponds to key Key from hash table T. The -- routine has no effect if the value is not present in the hash table. -- This action will raise Iterated if the hash table has outstanding -- iterators. If the load factor drops below Compression_Threshold, the -- size of the buckets is decreased by Copression_Factor. - procedure Destroy (T : in out Instance); + procedure Destroy (T : in out Dynamic_Hash_Table); -- Destroy the contents of hash table T, rendering it unusable. This -- routine must be called at the end of a hash table's lifetime. This -- action will raise Iterated if the hash table has outstanding -- iterators. - function Get (T : Instance; Key : Key_Type) return Value_Type; + function Get + (T : Dynamic_Hash_Table; + Key : Key_Type) return Value_Type; -- Obtain the value which corresponds to key Key from hash table T. If -- the value does not exist, return No_Value. - function Is_Empty (T : Instance) return Boolean; + function Is_Empty (T : Dynamic_Hash_Table) return Boolean; -- Determine whether hash table T is empty - function Present (T : Instance) return Boolean; + function Present (T : Dynamic_Hash_Table) return Boolean; -- Determine whether hash table T exists - procedure Put (T : Instance; Key : Key_Type; Value : Value_Type); + procedure Put + (T : Dynamic_Hash_Table; + Key : Key_Type; + Value : Value_Type); -- Associate value Value with key Key in hash table T. If the table -- already contains a mapping of the same key to a previous value, the -- previous value is overwritten. This action will raise Iterated if @@ -380,12 +387,12 @@ package GNAT.Dynamic_HTables is -- over Expansion_Threshold, the size of the buckets is increased by -- Expansion_Factor. - procedure Reset (T : Instance); + procedure Reset (T : Dynamic_Hash_Table); -- Destroy the contents of hash table T, and reset it to its initial -- created state. This action will raise Iterated if the hash table -- has outstanding iterators. - function Size (T : Instance) return Natural; + function Size (T : Dynamic_Hash_Table) return Natural; -- Obtain the number of key-value pairs in hash table T ------------------------- @@ -412,7 +419,7 @@ package GNAT.Dynamic_HTables is -- iterator has been exhausted, restore all mutation functionality of -- the associated hash table. - function Iterate (T : Instance) return Iterator; + function Iterate (T : Dynamic_Hash_Table) return Iterator; -- Obtain an iterator over the keys of hash table T. This action locks -- all mutation functionality of the associated hash table. @@ -461,7 +468,7 @@ package GNAT.Dynamic_HTables is -- The following type represents a hash table - type Hash_Table is record + type Dynamic_Hash_Table_Attributes is record Buckets : Bucket_Table_Ptr := null; -- Reference to the compressing / expanding buckets @@ -475,8 +482,8 @@ package GNAT.Dynamic_HTables is -- Number of key-value pairs in the buckets end record; - type Instance is access Hash_Table; - Nil : constant Instance := null; + type Dynamic_Hash_Table is access Dynamic_Hash_Table_Attributes; + Nil : constant Dynamic_Hash_Table := null; -- The following type represents a key iterator @@ -491,9 +498,9 @@ package GNAT.Dynamic_HTables is -- always point to a valid node. A value of null indicates that the -- iterator is exhausted. - Table : Instance := null; + Table : Dynamic_Hash_Table := null; -- Reference to the associated hash table end record; - end Dynamic_HTable; + end Dynamic_Hash_Tables; end GNAT.Dynamic_HTables; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a64cb52..edc2bd6 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,9 @@ 2019-07-01 Hristian Kirtchev <kirtchev@adacore.com> + * gnat.dg/dynhash.adb, gnat.dg/dynhash1.adb: Update. + +2019-07-01 Hristian Kirtchev <kirtchev@adacore.com> + * gnat.dg/freezing1.adb, gnat.dg/freezing1.ads, gnat.dg/freezing1_pack.adb, gnat.dg/freezing1_pack.ads: New testcase. diff --git a/gcc/testsuite/gnat.dg/dynhash.adb b/gcc/testsuite/gnat.dg/dynhash.adb index c51e6e2..8b229c4 100644 --- a/gcc/testsuite/gnat.dg/dynhash.adb +++ b/gcc/testsuite/gnat.dg/dynhash.adb @@ -5,9 +5,10 @@ with GNAT; use GNAT; with GNAT.Dynamic_HTables; use GNAT.Dynamic_HTables; procedure Dynhash is + procedure Destroy (Val : in out Integer) is null; function Hash (Key : Integer) return Bucket_Range_Type; - package DHT is new Dynamic_HTable + package DHT is new Dynamic_Hash_Tables (Key_Type => Integer, Value_Type => Integer, No_Value => 0, @@ -16,20 +17,21 @@ procedure Dynhash is Compression_Threshold => 0.3, Compression_Factor => 2, "=" => "=", + Destroy_Value => Destroy, Hash => Hash); use DHT; function Create_And_Populate (Low_Key : Integer; High_Key : Integer; - Init_Size : Positive) return Instance; + Init_Size : Positive) return Dynamic_Hash_Table; -- Create a hash table with initial size Init_Size and populate it with -- key-value pairs where both keys and values are in the range Low_Key -- .. High_Key. procedure Check_Empty (Caller : String; - T : Instance; + T : Dynamic_Hash_Table; Low_Key : Integer; High_Key : Integer); -- Ensure that @@ -45,12 +47,14 @@ procedure Dynhash is -- Ensure that iterator Iter visits every key in the range Low_Key .. -- High_Key exactly once. - procedure Check_Locked_Mutations (Caller : String; T : in out Instance); + procedure Check_Locked_Mutations + (Caller : String; + T : in out Dynamic_Hash_Table); -- Ensure that all mutation operations of hash table T are locked procedure Check_Size (Caller : String; - T : Instance; + T : Dynamic_Hash_Table; Exp_Count : Natural); -- Ensure that the count of key-value pairs of hash table T matches -- expected count Exp_Count. Emit an error if this is not the case. @@ -134,9 +138,9 @@ procedure Dynhash is function Create_And_Populate (Low_Key : Integer; High_Key : Integer; - Init_Size : Positive) return Instance + Init_Size : Positive) return Dynamic_Hash_Table is - T : Instance; + T : Dynamic_Hash_Table; begin T := Create (Init_Size); @@ -154,7 +158,7 @@ procedure Dynhash is procedure Check_Empty (Caller : String; - T : Instance; + T : Dynamic_Hash_Table; Low_Key : Integer; High_Key : Integer) is @@ -227,7 +231,10 @@ procedure Dynhash is -- Check_Locked_Mutations -- ---------------------------- - procedure Check_Locked_Mutations (Caller : String; T : in out Instance) is + procedure Check_Locked_Mutations + (Caller : String; + T : in out Dynamic_Hash_Table) + is begin begin Delete (T, 1); @@ -276,7 +283,7 @@ procedure Dynhash is procedure Check_Size (Caller : String; - T : Instance; + T : Dynamic_Hash_Table; Exp_Count : Natural) is Count : constant Natural := Size (T); @@ -305,7 +312,7 @@ procedure Dynhash is procedure Test_Create (Init_Size : Positive) is Count : Natural; Iter : Iterator; - T : Instance; + T : Dynamic_Hash_Table; Val : Integer; begin @@ -402,7 +409,7 @@ procedure Dynhash is Init_Size : Positive) is Exp_Val : Integer; - T : Instance; + T : Dynamic_Hash_Table; Val : Integer; begin @@ -483,7 +490,7 @@ procedure Dynhash is is Iter_1 : Iterator; Iter_2 : Iterator; - T : Instance; + T : Dynamic_Hash_Table; begin T := Create_And_Populate (Low_Key, High_Key, Init_Size); @@ -552,7 +559,7 @@ procedure Dynhash is procedure Test_Iterate_Empty (Init_Size : Positive) is Iter : Iterator; Key : Integer; - T : Instance; + T : Dynamic_Hash_Table; begin T := Create_And_Populate (0, -1, Init_Size); @@ -599,7 +606,7 @@ procedure Dynhash is is Iter : Iterator; Key : Integer; - T : Instance; + T : Dynamic_Hash_Table; begin T := Create_And_Populate (Low_Key, High_Key, Init_Size); @@ -653,7 +660,7 @@ procedure Dynhash is Init_Size : Positive) is Key : constant Integer := 1; - T : Instance; + T : Dynamic_Hash_Table; Val : Integer; begin @@ -687,7 +694,7 @@ procedure Dynhash is High_Key : Integer; Init_Size : Positive) is - T : Instance; + T : Dynamic_Hash_Table; begin T := Create_And_Populate (Low_Key, High_Key, Init_Size); diff --git a/gcc/testsuite/gnat.dg/dynhash1.adb b/gcc/testsuite/gnat.dg/dynhash1.adb index cbe241a..e2010de 100644 --- a/gcc/testsuite/gnat.dg/dynhash1.adb +++ b/gcc/testsuite/gnat.dg/dynhash1.adb @@ -1,14 +1,17 @@ +-- { dg-do run } + with Ada.Text_IO; use Ada.Text_IO; with GNAT; use GNAT; with GNAT.Dynamic_HTables; use GNAT.Dynamic_HTables; procedure Dynhash1 is + procedure Destroy (Val : in out Integer) is null; function Hash (Key : Integer) return Bucket_Range_Type is begin return Bucket_Range_Type (Key); end Hash; - package Integer_Hash_Tables is new Dynamic_HTable + package Integer_Hash_Tables is new Dynamic_Hash_Tables (Key_Type => Integer, Value_Type => Integer, No_Value => 0, @@ -17,11 +20,12 @@ procedure Dynhash1 is Compression_Threshold => 0.3, Compression_Factor => 2, "=" => "=", + Destroy_Value => Destroy, Hash => Hash); use Integer_Hash_Tables; Siz : Natural; - T : Instance; + T : Dynamic_Hash_Table; begin T := Create (8); |