summaryrefslogtreecommitdiffstats
path: root/gcc/ada/a-coorse.adb
diff options
context:
space:
mode:
authorcharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>2011-11-23 13:32:44 +0000
committercharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>2011-11-23 13:32:44 +0000
commit2b89c55cc599a0c13e3514eeabd20d4893b235b2 (patch)
treee4cb2a009b5464c65617b77964d5b5b7ae9ba450 /gcc/ada/a-coorse.adb
parent4f5c3083fc525ff07099de9eb76a25986ca95762 (diff)
downloadppe42-gcc-2b89c55cc599a0c13e3514eeabd20d4893b235b2.tar.gz
ppe42-gcc-2b89c55cc599a0c13e3514eeabd20d4893b235b2.zip
2011-11-23 Matthew Heaney <heaney@adacore.com>
* a-coorse.ads, a-ciorse.ads, a-cborse.ads (Set_Iterator_Interfaces): Renamed from Ordered_Set_Iterator_Interfaces. * a-coorse.adb, a-ciorse.adb, a-cborse.adb (Iterator): Declared Iterator type as limited (First, Last): Cursor return value depends on iterator node value (Iterate): Use start position as iterator node value (Next, Previous): Forward to corresponding cursor-based operation. * a-cohase.ads, a-cohase.adb: Implemented forward iterator. * a-cihase.adb, a-cbhase.adb (Iterator): Removed unnecessary node component (First, Next): Forward call to corresponding cursor-based operation (Iterate): Representation of iterator no longer has node component 2011-11-23 Hristian Kirtchev <kirtchev@adacore.com> * exp_intr.adb (Expand_Unc_Deallocation): Ensure that the dereference has a proper type before the side effect removal mechanism kicks in. * sem_ch3.adb (Analyze_Subtype_Declaration): Handle a rare case where the base type of the subtype is a private itype created to act as the partial view of a constrained record type. This scenario manifests with equivalent class-wide types for records with unknown discriminants. 2011-11-23 Jerome Guitton <guitton@adacore.com> * s-osprim-vxworks.adb (Clock): Use Clock_RT_Ada. 2011-11-23 Thomas Quinot <quinot@adacore.com> * s-oscons-tmplt.c: Fix unbalanced preprocessor directives Minor reformatting/reorganization. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@181666 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/ada/a-coorse.adb')
-rw-r--r--gcc/ada/a-coorse.adb124
1 files changed, 104 insertions, 20 deletions
diff --git a/gcc/ada/a-coorse.adb b/gcc/ada/a-coorse.adb
index 4c6476864b8..ce004e2d737 100644
--- a/gcc/ada/a-coorse.adb
+++ b/gcc/ada/a-coorse.adb
@@ -42,9 +42,9 @@ with System; use type System.Address;
package body Ada.Containers.Ordered_Sets is
- type Iterator is new
- Ordered_Set_Iterator_Interfaces.Reversible_Iterator with record
- Container : access constant Set;
+ type Iterator is limited new
+ Set_Iterator_Interfaces.Reversible_Iterator with record
+ Container : Set_Access;
Node : Node_Access;
end record;
@@ -537,9 +537,24 @@ package body Ada.Containers.Ordered_Sets is
function First (Object : Iterator) return Cursor is
begin
- return (if Object.Container = null then No_Element
- else Cursor'(Object.Container.all'Unrestricted_Access,
- Object.Container.Tree.First));
+ -- The value of the iterator object's Node component influences the
+ -- behavior of the First (and Last) selector function.
+
+ -- When the Node component is null, this means the iterator object was
+ -- constructed without a start expression, in which case the (forward)
+ -- iteration starts from the (logical) beginning of the entire sequence
+ -- of items (corresponding to Container.First, for a forward iterator).
+
+ -- Otherwise, this is iteration over a partial sequence of items. When
+ -- the Node component is non-null, the iterator object was constructed
+ -- with a start expression, that specifies the position from which the
+ -- (forward) partial iteration begins.
+
+ if Object.Node = null then
+ return Object.Container.First;
+ else
+ return Cursor'(Object.Container, Object.Node);
+ end if;
end First;
-------------------
@@ -1165,22 +1180,60 @@ package body Ada.Containers.Ordered_Sets is
end Iterate;
function Iterate (Container : Set)
- return Ordered_Set_Iterator_Interfaces.Reversible_Iterator'class
+ return Set_Iterator_Interfaces.Reversible_Iterator'Class
is
begin
- if Container.Length = 0 then
- return Iterator'(null, null);
- else
- return Iterator'(Container'Unchecked_Access, Container.Tree.First);
- end if;
+ -- The value of the Node component influences the behavior of the First
+ -- and Last selector functions of the iterator object. When the Node
+ -- component is null (as is the case here), this means the iterator
+ -- object was constructed without a start expression. This is a complete
+ -- iterator, meaning that the iteration starts from the (logical)
+ -- beginning of the sequence of items.
+
+ -- Note: For a forward iterator, Container.First is the beginning, and
+ -- for a reverse iterator, Container.Last is the beginning.
+
+ return Iterator'(Container'Unrestricted_Access, Node => null);
end Iterate;
function Iterate (Container : Set; Start : Cursor)
- return Ordered_Set_Iterator_Interfaces.Reversible_Iterator'class
+ return Set_Iterator_Interfaces.Reversible_Iterator'Class
is
- It : constant Iterator := (Container'Unchecked_Access, Start.Node);
begin
- return It;
+ -- It was formerly the case that when Start = No_Element, the partial
+ -- iterator was defined to behave the same as for a complete iterator,
+ -- and iterate over the entire sequence of items. However, those
+ -- semantics were unintuitive and arguably error-prone (it is too easy
+ -- to accidentally create an endless loop), and so they were changed,
+ -- per the ARG meeting in Denver on 2011/11. However, there was no
+ -- consensus about what positive meaning this corner case should have,
+ -- and so it was decided to simply raise an exception. This does imply,
+ -- however, that it is not possible to use a partial iterator to specify
+ -- an empty sequence of items.
+
+ if Start = No_Element then
+ raise Constraint_Error with
+ "Start position for iterator equals No_Element";
+ end if;
+
+ if Start.Container /= Container'Unrestricted_Access then
+ raise Program_Error with
+ "Start cursor of Iterate designates wrong set";
+ end if;
+
+ pragma Assert (Vet (Container.Tree, Start.Node),
+ "Start cursor of Iterate is bad");
+
+ -- The value of the Node component influences the behavior of the First
+ -- and Last selector functions of the iterator object. When the Node
+ -- component is non-null (as is the case here), it means that this is a
+ -- partial iteration, over a subset of the complete sequence of
+ -- items. The iterator object was constructed with a start expression,
+ -- indicating the position from which the iteration begins. Note that
+ -- the start position has the same value irrespective of whether this is
+ -- a forward or reverse iteration.
+
+ return Iterator'(Container'Unrestricted_Access, Node => Start.Node);
end Iterate;
----------
@@ -1196,9 +1249,24 @@ package body Ada.Containers.Ordered_Sets is
function Last (Object : Iterator) return Cursor is
begin
- return (if Object.Container = null then No_Element
- else Cursor'(Object.Container.all'Unrestricted_Access,
- Object.Container.Tree.Last));
+ -- The value of the iterator object's Node component influences the
+ -- behavior of the Last (and First) selector function.
+
+ -- When the Node component is null, this means the iterator object was
+ -- constructed without a start expression, in which case the (reverse)
+ -- iteration starts from the (logical) beginning of the entire sequence
+ -- (corresponding to Container.Last, for a reverse iterator).
+
+ -- Otherwise, this is iteration over a partial sequence of items. When
+ -- the Node component is non-null, the iterator object was constructed
+ -- with a start expression, that specifies the position from which the
+ -- (reverse) partial iteration begins.
+
+ if Object.Node = null then
+ return Object.Container.Last;
+ else
+ return Cursor'(Object.Container, Object.Node);
+ end if;
end Last;
------------------
@@ -1271,8 +1339,16 @@ package body Ada.Containers.Ordered_Sets is
end Next;
function Next (Object : Iterator; Position : Cursor) return Cursor is
- pragma Unreferenced (Object);
begin
+ if Position.Container = null then
+ return No_Element;
+ end if;
+
+ if Position.Container /= Object.Container then
+ raise Program_Error with
+ "Position cursor of Next designates wrong set";
+ end if;
+
return Next (Position);
end Next;
@@ -1322,8 +1398,16 @@ package body Ada.Containers.Ordered_Sets is
end Previous;
function Previous (Object : Iterator; Position : Cursor) return Cursor is
- pragma Unreferenced (Object);
begin
+ if Position.Container = null then
+ return No_Element;
+ end if;
+
+ if Position.Container /= Object.Container then
+ raise Program_Error with
+ "Position cursor of Previous designates wrong set";
+ end if;
+
return Previous (Position);
end Previous;
OpenPOWER on IntegriCloud