+2019-07-01 Hristian Kirtchev <kirtchev@adacore.com>
+
+ * libgnat/g-lists.adb: Use type Doubly_Linked_List rather than
+ Instance in various routines.
+ * libgnat/g-lists.ads: Change type Instance to
+ Doubly_Linked_List. Update various routines that mention the
+ type.
+
2019-07-01 Hristian Kirtchev <kirtchev@adacore.com>
* libgnat/g-dynhta.adb: Use type Dynamic_Hash_Table rather than
package body GNAT.Lists is
- package body Doubly_Linked_List is
- procedure Delete_Node (L : Instance; Nod : Node_Ptr);
+ package body Doubly_Linked_Lists is
+ procedure Delete_Node
+ (L : Doubly_Linked_List;
+ Nod : Node_Ptr);
pragma Inline (Delete_Node);
-- Detach and delete node Nod from list L
pragma Inline (Ensure_Circular);
-- Ensure that dummy head Head is circular with respect to itself
- procedure Ensure_Created (L : Instance);
+ procedure Ensure_Created (L : Doubly_Linked_List);
pragma Inline (Ensure_Created);
-- Verify that list L is created. Raise Not_Created if this is not the
-- case.
- procedure Ensure_Full (L : Instance);
+ procedure Ensure_Full (L : Doubly_Linked_List);
pragma Inline (Ensure_Full);
-- Verify that list L contains at least one element. Raise List_Empty if
-- this is not the case.
- procedure Ensure_Unlocked (L : Instance);
+ procedure Ensure_Unlocked (L : Doubly_Linked_List);
pragma Inline (Ensure_Unlocked);
-- Verify that list L is unlocked. Raise Iterated if this is not the
-- case.
-- exists a node with element Elem. If such a node exists, return it,
-- otherwise return null;
- procedure Free is new Ada.Unchecked_Deallocation (Linked_List, Instance);
+ procedure Free is
+ new Ada.Unchecked_Deallocation
+ (Doubly_Linked_List_Attributes, Doubly_Linked_List);
procedure Free is new Ada.Unchecked_Deallocation (Node, Node_Ptr);
procedure Insert_Between
- (L : Instance;
+ (L : Doubly_Linked_List;
Elem : Element_Type;
Left : Node_Ptr;
Right : Node_Ptr);
pragma Inline (Is_Valid);
-- Determine whether iterator Iter refers to a valid element
- function Is_Valid (Nod : Node_Ptr; Head : Node_Ptr) return Boolean;
+ function Is_Valid
+ (Nod : Node_Ptr;
+ Head : Node_Ptr) return Boolean;
pragma Inline (Is_Valid);
-- Determine whether node Nod is non-null and does not refer to dummy
-- head Head, thus making it valid.
- procedure Lock (L : Instance);
+ procedure Lock (L : Doubly_Linked_List);
pragma Inline (Lock);
-- Lock all mutation functionality of list L
pragma Inline (Present);
-- Determine whether node Nod exists
- procedure Unlock (L : Instance);
+ procedure Unlock (L : Doubly_Linked_List);
pragma Inline (Unlock);
-- Unlock all mutation functionality of list L
-- Append --
------------
- procedure Append (L : Instance; Elem : Element_Type) is
+ procedure Append
+ (L : Doubly_Linked_List;
+ Elem : Element_Type)
+ is
Head : Node_Ptr;
begin
-- Create --
------------
- function Create return Instance is
+ function Create return Doubly_Linked_List is
begin
- return new Linked_List;
+ return new Doubly_Linked_List_Attributes;
end Create;
--------------
-- Contains --
--------------
- function Contains (L : Instance; Elem : Element_Type) return Boolean is
+ function Contains
+ (L : Doubly_Linked_List;
+ Elem : Element_Type) return Boolean
+ is
Head : Node_Ptr;
Nod : Node_Ptr;
-- Delete --
------------
- procedure Delete (L : Instance; Elem : Element_Type) is
+ procedure Delete
+ (L : Doubly_Linked_List;
+ Elem : Element_Type)
+ is
Head : Node_Ptr;
Nod : Node_Ptr;
-- Delete_First --
------------------
- procedure Delete_First (L : Instance) is
+ procedure Delete_First (L : Doubly_Linked_List) is
Head : Node_Ptr;
Nod : Node_Ptr;
-- Delete_Last --
-----------------
- procedure Delete_Last (L : Instance) is
+ procedure Delete_Last (L : Doubly_Linked_List) is
Head : Node_Ptr;
Nod : Node_Ptr;
-- Delete_Node --
-----------------
- procedure Delete_Node (L : Instance; Nod : Node_Ptr) is
+ procedure Delete_Node
+ (L : Doubly_Linked_List;
+ Nod : Node_Ptr)
+ is
Ref : Node_Ptr := Nod;
pragma Assert (Present (Ref));
-- Destroy --
-------------
- procedure Destroy (L : in out Instance) is
+ procedure Destroy (L : in out Doubly_Linked_List) is
Head : Node_Ptr;
begin
-- Ensure_Created --
--------------------
- procedure Ensure_Created (L : Instance) is
+ procedure Ensure_Created (L : Doubly_Linked_List) is
begin
if not Present (L) then
raise Not_Created;
-- Ensure_Full --
-----------------
- procedure Ensure_Full (L : Instance) is
+ procedure Ensure_Full (L : Doubly_Linked_List) is
begin
pragma Assert (Present (L));
-- Ensure_Unlocked --
---------------------
- procedure Ensure_Unlocked (L : Instance) is
+ procedure Ensure_Unlocked (L : Doubly_Linked_List) is
begin
pragma Assert (Present (L));
-- First --
-----------
- function First (L : Instance) return Element_Type is
+ function First (L : Doubly_Linked_List) return Element_Type is
begin
Ensure_Created (L);
Ensure_Full (L);
------------------
procedure Insert_After
- (L : Instance;
+ (L : Doubly_Linked_List;
After : Element_Type;
Elem : Element_Type)
is
-------------------
procedure Insert_Before
- (L : Instance;
+ (L : Doubly_Linked_List;
Before : Element_Type;
Elem : Element_Type)
is
--------------------
procedure Insert_Between
- (L : Instance;
+ (L : Doubly_Linked_List;
Elem : Element_Type;
Left : Node_Ptr;
Right : Node_Ptr)
-- Is_Empty --
--------------
- function Is_Empty (L : Instance) return Boolean is
+ function Is_Empty (L : Doubly_Linked_List) return Boolean is
begin
Ensure_Created (L);
-- Is_Valid --
--------------
- function Is_Valid (Nod : Node_Ptr; Head : Node_Ptr) return Boolean is
+ function Is_Valid
+ (Nod : Node_Ptr;
+ Head : Node_Ptr) return Boolean
+ is
begin
-- A node is valid if it is non-null, and does not refer to the dummy
-- head of some list.
-- Iterate --
-------------
- function Iterate (L : Instance) return Iterator is
+ function Iterate (L : Doubly_Linked_List) return Iterator is
begin
Ensure_Created (L);
-- Last --
----------
- function Last (L : Instance) return Element_Type is
+ function Last (L : Doubly_Linked_List) return Element_Type is
begin
Ensure_Created (L);
Ensure_Full (L);
-- Lock --
----------
- procedure Lock (L : Instance) is
+ procedure Lock (L : Doubly_Linked_List) is
begin
pragma Assert (Present (L));
-- Next --
----------
- procedure Next (Iter : in out Iterator; Elem : out Element_Type) is
+ procedure Next
+ (Iter : in out Iterator;
+ Elem : out Element_Type)
+ is
Is_OK : constant Boolean := Is_Valid (Iter);
Saved : constant Node_Ptr := Iter.Curr_Nod;
-- Prepend --
-------------
- procedure Prepend (L : Instance; Elem : Element_Type) is
+ procedure Prepend
+ (L : Doubly_Linked_List;
+ Elem : Element_Type)
+ is
Head : Node_Ptr;
begin
-- Present --
-------------
- function Present (L : Instance) return Boolean is
+ function Present (L : Doubly_Linked_List) return Boolean is
begin
return L /= Nil;
end Present;
-------------
procedure Replace
- (L : Instance;
+ (L : Doubly_Linked_List;
Old_Elem : Element_Type;
New_Elem : Element_Type)
is
-- Size --
----------
- function Size (L : Instance) return Natural is
+ function Size (L : Doubly_Linked_List) return Natural is
begin
Ensure_Created (L);
-- Unlock --
------------
- procedure Unlock (L : Instance) is
+ procedure Unlock (L : Doubly_Linked_List) is
begin
pragma Assert (Present (L));
L.Iterators := L.Iterators - 1;
end Unlock;
- end Doubly_Linked_List;
+ end Doubly_Linked_Lists;
end GNAT.Lists;
--
-- The following use pattern must be employed with this list:
--
- -- List : Instance := Create;
+ -- List : Doubly_Linked_List := Create;
--
-- <various operations>
--
with procedure Destroy_Element (Elem : in out Element_Type);
-- Element destructor
- package Doubly_Linked_List is
+ package Doubly_Linked_Lists is
---------------------
-- List operations --
---------------------
- type Instance is private;
- Nil : constant Instance;
+ type Doubly_Linked_List is private;
+ Nil : constant Doubly_Linked_List;
-- The following exception is raised when the list is empty, and an
-- attempt is made to delete an element from it.
List_Empty : exception;
- procedure Append (L : Instance; Elem : Element_Type);
+ procedure Append
+ (L : Doubly_Linked_List;
+ Elem : Element_Type);
-- Insert element Elem at the end of list L. This action will raise
-- Iterated if the list has outstanding iterators.
- function Contains (L : Instance; Elem : Element_Type) return Boolean;
+ function Contains
+ (L : Doubly_Linked_List;
+ Elem : Element_Type) return Boolean;
-- Determine whether list L contains element Elem
- function Create return Instance;
+ function Create return Doubly_Linked_List;
-- Create a new list
- procedure Delete (L : Instance; Elem : Element_Type);
+ procedure Delete
+ (L : Doubly_Linked_List;
+ Elem : Element_Type);
-- Delete element Elem from list L. The routine has no effect if Elem is
-- not present. This action will raise
--
-- * List_Empty if the list is empty.
-- * Iterated if the list has outstanding iterators.
- procedure Delete_First (L : Instance);
+ procedure Delete_First (L : Doubly_Linked_List);
-- Delete an element from the start of list L. This action will raise
--
-- * List_Empty if the list is empty.
-- * Iterated if the list has outstanding iterators.
- procedure Delete_Last (L : Instance);
+ procedure Delete_Last (L : Doubly_Linked_List);
-- Delete an element from the end of list L. This action will raise
--
-- * List_Empty if the list is empty.
-- * Iterated if the list has outstanding iterators.
- procedure Destroy (L : in out Instance);
+ procedure Destroy (L : in out Doubly_Linked_List);
-- Destroy the contents of list L. This routine must be called at the
-- end of a list's lifetime. This action will raise Iterated if the
-- list has outstanding iterators.
- function First (L : Instance) return Element_Type;
+ function First (L : Doubly_Linked_List) return Element_Type;
-- Obtain an element from the start of list L. This action will raise
-- List_Empty if the list is empty.
procedure Insert_After
- (L : Instance;
+ (L : Doubly_Linked_List;
After : Element_Type;
Elem : Element_Type);
-- Insert new element Elem after element After in list L. The routine
-- Iterated if the list has outstanding iterators.
procedure Insert_Before
- (L : Instance;
+ (L : Doubly_Linked_List;
Before : Element_Type;
Elem : Element_Type);
-- Insert new element Elem before element Before in list L. The routine
-- has no effect if After is not present. This action will raise
-- Iterated if the list has outstanding iterators.
- function Is_Empty (L : Instance) return Boolean;
+ function Is_Empty (L : Doubly_Linked_List) return Boolean;
-- Determine whether list L is empty
- function Last (L : Instance) return Element_Type;
+ function Last (L : Doubly_Linked_List) return Element_Type;
-- Obtain an element from the end of list L. This action will raise
-- List_Empty if the list is empty.
- procedure Prepend (L : Instance; Elem : Element_Type);
+ procedure Prepend
+ (L : Doubly_Linked_List;
+ Elem : Element_Type);
-- Insert element Elem at the start of list L. This action will raise
-- Iterated if the list has outstanding iterators.
- function Present (L : Instance) return Boolean;
+ function Present (L : Doubly_Linked_List) return Boolean;
-- Determine whether list L exists
procedure Replace
- (L : Instance;
+ (L : Doubly_Linked_List;
Old_Elem : Element_Type;
New_Elem : Element_Type);
-- Replace old element Old_Elem with new element New_Elem in list L. The
-- routine has no effect if Old_Elem is not present. This action will
-- raise Iterated if the list has outstanding iterators.
- function Size (L : Instance) return Natural;
+ function Size (L : Doubly_Linked_List) return Natural;
-- Obtain the number of elements in list L
-------------------------
-- iterator has been exhausted, restore all mutation functionality of
-- the associated list.
- function Iterate (L : Instance) return Iterator;
+ function Iterate (L : Doubly_Linked_List) return Iterator;
-- Obtain an iterator over the elements of list L. This action locks all
-- mutation functionality of the associated list.
- procedure Next (Iter : in out Iterator; Elem : out Element_Type);
+ procedure Next
+ (Iter : in out Iterator;
+ Elem : out Element_Type);
-- Return the current element referenced by iterator Iter and advance
-- to the next available element. If the iterator has been exhausted
-- and further attempts are made to advance it, this routine restores
-- The following type represents a list
- type Linked_List is record
+ type Doubly_Linked_List_Attributes is record
Elements : Natural := 0;
-- The number of elements in the list
-- The dummy head of the list
end record;
- type Instance is access all Linked_List;
- Nil : constant Instance := null;
+ type Doubly_Linked_List is access all Doubly_Linked_List_Attributes;
+ Nil : constant Doubly_Linked_List := null;
-- The following type represents an element iterator
-- iterator requires that this field always points to a valid node. A
-- value of null indicates that the iterator is exhausted.
- List : Instance := null;
+ List : Doubly_Linked_List := null;
-- Reference to the associated list
end record;
- end Doubly_Linked_List;
+ end Doubly_Linked_Lists;
end GNAT.Lists;
+2019-07-01 Hristian Kirtchev <kirtchev@adacore.com>
+
+ * gnat.dg/linkedlist.adb: Update.
+
2019-07-01 Hristian Kirtchev <kirtchev@adacore.com>
* gnat.dg/dynhash.adb, gnat.dg/dynhash1.adb: Update.
with GNAT.Lists; use GNAT.Lists;
procedure Linkedlist is
- package Integer_Lists is new Doubly_Linked_List
- (Element_Type => Integer,
- "=" => "=");
+ procedure Destroy (Val : in out Integer) is null;
+
+ package Integer_Lists is new Doubly_Linked_Lists
+ (Element_Type => Integer,
+ "=" => "=",
+ Destroy_Element => Destroy);
use Integer_Lists;
procedure Check_Empty
(Caller : String;
- L : Instance;
+ L : Doubly_Linked_List;
Low_Elem : Integer;
High_Elem : Integer);
-- Ensure that none of the elements in the range Low_Elem .. High_Elem are
-- present in list L, and that the list's length is 0.
- procedure Check_Locked_Mutations (Caller : String; L : in out Instance);
+ procedure Check_Locked_Mutations
+ (Caller : String;
+ L : in out Doubly_Linked_List);
-- Ensure that all mutation operations of list L are locked
procedure Check_Present
(Caller : String;
- L : Instance;
+ L : Doubly_Linked_List;
Low_Elem : Integer;
High_Elem : Integer);
-- Ensure that all elements in the range Low_Elem .. High_Elem are present
-- in list L.
- procedure Check_Unlocked_Mutations (Caller : String; L : in out Instance);
+ procedure Check_Unlocked_Mutations
+ (Caller : String;
+ L : in out Doubly_Linked_List);
-- Ensure that all mutation operations of list L are unlocked
procedure Populate_With_Append
- (L : Instance;
+ (L : Doubly_Linked_List;
Low_Elem : Integer;
High_Elem : Integer);
-- Add elements in the range Low_Elem .. High_Elem in that order in list L
procedure Check_Empty
(Caller : String;
- L : Instance;
+ L : Doubly_Linked_List;
Low_Elem : Integer;
High_Elem : Integer)
is
-- Check_Locked_Mutations --
----------------------------
- procedure Check_Locked_Mutations (Caller : String; L : in out Instance) is
+ procedure Check_Locked_Mutations
+ (Caller : String;
+ L : in out Doubly_Linked_List) is
begin
begin
Append (L, 1);
procedure Check_Present
(Caller : String;
- L : Instance;
+ L : Doubly_Linked_List;
Low_Elem : Integer;
High_Elem : Integer)
is
-- Check_Unlocked_Mutations --
------------------------------
- procedure Check_Unlocked_Mutations (Caller : String; L : in out Instance) is
+ procedure Check_Unlocked_Mutations
+ (Caller : String;
+ L : in out Doubly_Linked_List)
+ is
begin
Append (L, 1);
Append (L, 2);
--------------------------
procedure Populate_With_Append
- (L : Instance;
+ (L : Doubly_Linked_List;
Low_Elem : Integer;
High_Elem : Integer)
is
-----------------
procedure Test_Append is
- L : Instance := Create;
+ L : Doubly_Linked_List := Create;
begin
Append (L, 1);
Low_Bogus : constant Integer := Low_Elem - 1;
High_Bogus : constant Integer := High_Elem + 1;
- L : Instance := Create;
+ L : Doubly_Linked_List := Create;
begin
Populate_With_Append (L, Low_Elem, High_Elem);
Count : Natural;
Flag : Boolean;
Iter : Iterator;
- L : Instance;
+ L : Doubly_Linked_List;
Val : Integer;
begin
High_Elem : Integer)
is
Iter : Iterator;
- L : Instance := Create;
+ L : Doubly_Linked_List := Create;
begin
Populate_With_Append (L, Low_Elem, High_Elem);
(Low_Elem : Integer;
High_Elem : Integer)
is
- L : Instance := Create;
+ L : Doubly_Linked_List := Create;
begin
Populate_With_Append (L, Low_Elem, High_Elem);
(Low_Elem : Integer;
High_Elem : Integer)
is
- L : Instance := Create;
+ L : Doubly_Linked_List := Create;
begin
Populate_With_Append (L, Low_Elem, High_Elem);
procedure Test_First is
Elem : Integer;
- L : Instance := Create;
+ L : Doubly_Linked_List := Create;
begin
-- Try to obtain the head. This operation should raise List_Empty.
-----------------------
procedure Test_Insert_After is
- L : Instance := Create;
+ L : Doubly_Linked_List := Create;
begin
-- Try to insert after a non-inserted element, in an empty list
------------------------
procedure Test_Insert_Before is
- L : Instance := Create;
+ L : Doubly_Linked_List := Create;
begin
-- Try to insert before a non-inserted element, in an empty list
-------------------
procedure Test_Is_Empty is
- L : Instance := Create;
+ L : Doubly_Linked_List := Create;
begin
if not Is_Empty (L) then
Elem : Integer;
Iter_1 : Iterator;
Iter_2 : Iterator;
- L : Instance := Create;
+ L : Doubly_Linked_List := Create;
begin
Populate_With_Append (L, 1, 5);
procedure Test_Iterate_Empty is
Elem : Integer;
Iter : Iterator;
- L : Instance := Create;
+ L : Doubly_Linked_List := Create;
begin
-- Obtain an iterator. This action must lock all mutation operations of
is
Elem : Integer;
Iter : Iterator;
- L : Instance := Create;
+ L : Doubly_Linked_List := Create;
begin
Populate_With_Append (L, Low_Elem, High_Elem);
procedure Test_Last is
Elem : Integer;
- L : Instance := Create;
+ L : Doubly_Linked_List := Create;
begin
-- Try to obtain the tail. This operation should raise List_Empty.
------------------
procedure Test_Prepend is
- L : Instance := Create;
+ L : Doubly_Linked_List := Create;
begin
Prepend (L, 5);
------------------
procedure Test_Replace is
- L : Instance := Create;
+ L : Doubly_Linked_List := Create;
begin
Populate_With_Append (L, 1, 5);
---------------
procedure Test_Size is
- L : Instance := Create;
+ L : Doubly_Linked_List := Create;
S : Natural;
begin