aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada
diff options
context:
space:
mode:
authorRichard Wai <richard@annexi-strayline.com>2021-03-15 06:24:00 -0400
committerPierre-Marie de Rodat <derodat@adacore.com>2021-04-28 05:37:52 -0400
commit5b4b66291f2086f56dc3a1d7df494f901cd0b63e (patch)
tree91443a88a83b517dc2d0d808f76c79033c8b35f8 /gcc/ada
parentfccc47dddc2ee605dd7fce5c1d1711404e19cd7f (diff)
downloadgcc-5b4b66291f2086f56dc3a1d7df494f901cd0b63e.zip
gcc-5b4b66291f2086f56dc3a1d7df494f901cd0b63e.tar.gz
gcc-5b4b66291f2086f56dc3a1d7df494f901cd0b63e.tar.bz2
[Ada] Hashed container Cursor type predefined equality non-conformance
gcc/ada/ * libgnat/a-cohase.ads (Cursor): Synchronize comments for the Cursor type definition to be consistent with identical definitions in other container packages. Add additional comments regarding the importance of maintaining the "Position" component for predefined equality. * libgnat/a-cohama.ads (Cursor): Likewise. * libgnat/a-cihama.ads (Cursor): Likewise. * libgnat/a-cohase.adb (Find, Insert): Ensure that Cursor objects always have their "Position" component set to ensure predefined equality works as required. * libgnat/a-cohama.adb (Find, Insert): Likewise. * libgnat/a-cihama.adb (Find, Insert): Likewise. gcc/testsuite/ * gnat.dg/containers2.adb: New test.
Diffstat (limited to 'gcc/ada')
-rw-r--r--gcc/ada/libgnat/a-cihama.adb4
-rw-r--r--gcc/ada/libgnat/a-cihama.ads14
-rw-r--r--gcc/ada/libgnat/a-cohama.adb5
-rw-r--r--gcc/ada/libgnat/a-cohama.ads10
-rw-r--r--gcc/ada/libgnat/a-cohase.adb8
-rw-r--r--gcc/ada/libgnat/a-cohase.ads14
6 files changed, 49 insertions, 6 deletions
diff --git a/gcc/ada/libgnat/a-cihama.adb b/gcc/ada/libgnat/a-cihama.adb
index 7a490d5..50adea1 100644
--- a/gcc/ada/libgnat/a-cihama.adb
+++ b/gcc/ada/libgnat/a-cihama.adb
@@ -522,7 +522,8 @@ is
return No_Element;
end if;
- return Cursor'(Container'Unrestricted_Access, Node, Hash_Type'Last);
+ return Cursor'
+ (Container'Unrestricted_Access, Node, HT_Ops.Index (HT, Node));
end Find;
--------------------
@@ -748,6 +749,7 @@ is
end if;
Position.Container := Container'Unchecked_Access;
+ Position.Position := HT_Ops.Index (HT, Position.Node);
end Insert;
procedure Insert
diff --git a/gcc/ada/libgnat/a-cihama.ads b/gcc/ada/libgnat/a-cihama.ads
index ccf5f4e..f896167 100644
--- a/gcc/ada/libgnat/a-cihama.ads
+++ b/gcc/ada/libgnat/a-cihama.ads
@@ -363,8 +363,22 @@ private
type Cursor is record
Container : Map_Access;
+ -- Access to this cursor's container
+
Node : Node_Access;
+ -- Access to the node pointed to by this cursor
+
Position : Hash_Type := Hash_Type'Last;
+ -- Position of the node in the buckets of the container. If this is
+ -- equal to Hash_Type'Last, then it will not be used. Position is
+ -- not requried by the implementation, but improves the efficiency
+ -- of various operations.
+ --
+ -- However, this value must be maintained so that the predefined
+ -- equality operation acts as required by RM A.18.4-18/2, which
+ -- states: "The predefined "=" operator for type Cursor returns True
+ -- if both cursors are No_Element, or designate the same element
+ -- in the same container."
end record;
procedure Write
diff --git a/gcc/ada/libgnat/a-cohama.adb b/gcc/ada/libgnat/a-cohama.adb
index 9c4e51a..fb46e07 100644
--- a/gcc/ada/libgnat/a-cohama.adb
+++ b/gcc/ada/libgnat/a-cohama.adb
@@ -478,7 +478,8 @@ is
return No_Element;
end if;
- return Cursor'(Container'Unrestricted_Access, Node, Hash_Type'Last);
+ return Cursor'
+ (Container'Unrestricted_Access, Node, HT_Ops.Index (HT, Node));
end Find;
--------------------
@@ -635,6 +636,7 @@ is
end if;
Position.Container := Container'Unrestricted_Access;
+ Position.Position := HT_Ops.Index (HT, Position.Node);
end Insert;
procedure Insert
@@ -677,6 +679,7 @@ is
end if;
Position.Container := Container'Unrestricted_Access;
+ Position.Position := HT_Ops.Index (HT, Position.Node);
end Insert;
procedure Insert
diff --git a/gcc/ada/libgnat/a-cohama.ads b/gcc/ada/libgnat/a-cohama.ads
index 21b6935..c6e377c 100644
--- a/gcc/ada/libgnat/a-cohama.ads
+++ b/gcc/ada/libgnat/a-cohama.ads
@@ -465,7 +465,15 @@ private
Position : Hash_Type := Hash_Type'Last;
-- Position of the node in the buckets of the container. If this is
- -- equal to Hash_Type'Last, then it will not be used.
+ -- equal to Hash_Type'Last, then it will not be used. Position is
+ -- not requried by the implementation, but improves the efficiency
+ -- of various operations.
+ --
+ -- However, this value must be maintained so that the predefined
+ -- equality operation acts as required by RM A.18.4-18/2, which
+ -- states: "The predefined "=" operator for type Cursor returns True
+ -- if both cursors are No_Element, or designate the same element
+ -- in the same container."
end record;
procedure Read
diff --git a/gcc/ada/libgnat/a-cohase.adb b/gcc/ada/libgnat/a-cohase.adb
index 0131f73..aac5b1b 100644
--- a/gcc/ada/libgnat/a-cohase.adb
+++ b/gcc/ada/libgnat/a-cohase.adb
@@ -605,13 +605,13 @@ is
is
HT : Hash_Table_Type renames Container'Unrestricted_Access.HT;
Node : constant Node_Access := Element_Keys.Find (HT, Item);
-
begin
if Node = null then
return No_Element;
end if;
- return Cursor'(Container'Unrestricted_Access, Node, Hash_Type'Last);
+ return Cursor'
+ (Container'Unrestricted_Access, Node, HT_Ops.Index (HT, Node));
end Find;
--------------------
@@ -763,9 +763,11 @@ is
Position : out Cursor;
Inserted : out Boolean)
is
+ HT : Hash_Table_Type renames Container'Unrestricted_Access.HT;
begin
Insert (Container.HT, New_Item, Position.Node, Inserted);
Position.Container := Container'Unchecked_Access;
+ Position.Position := HT_Ops.Index (HT, Position.Node);
end Insert;
procedure Insert
@@ -1998,7 +2000,7 @@ is
return No_Element;
else
return Cursor'
- (Container'Unrestricted_Access, Node, Hash_Type'Last);
+ (Container'Unrestricted_Access, Node, HT_Ops.Index (HT, Node));
end if;
end Find;
diff --git a/gcc/ada/libgnat/a-cohase.ads b/gcc/ada/libgnat/a-cohase.ads
index a0aca52..c1415b5 100644
--- a/gcc/ada/libgnat/a-cohase.ads
+++ b/gcc/ada/libgnat/a-cohase.ads
@@ -537,8 +537,22 @@ private
type Cursor is record
Container : Set_Access;
+ -- Access to this cursor's container
+
Node : Node_Access;
+ -- Access to the node pointed to by this cursor
+
Position : Hash_Type := Hash_Type'Last;
+ -- Position of the node in the buckets of the container. If this is
+ -- equal to Hash_Type'Last, then it will not be used. Position is
+ -- not requried by the implementation, but improves the efficiency
+ -- of various operations.
+ --
+ -- However, this value must be maintained so that the predefined
+ -- equality operation acts as required by RM A.18.7-17/2, which
+ -- states: "The predefined "=" operator for type Cursor returns True
+ -- if both cursors are No_Element, or designate the same element
+ -- in the same container."
end record;
procedure Write