summaryrefslogtreecommitdiffstats
path: root/gcc/ada/a-convec.adb
diff options
context:
space:
mode:
authorcharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>2011-12-12 11:28:03 +0000
committercharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>2011-12-12 11:28:03 +0000
commit309c3053481b62acea44176015e6ee2eea218a12 (patch)
treeb15c5e55f467d82c76370ae169645dc4f5e61bba /gcc/ada/a-convec.adb
parent0de83fa2c8a4b2ab39f00091f3b116e2e6bee685 (diff)
downloadppe42-gcc-309c3053481b62acea44176015e6ee2eea218a12.tar.gz
ppe42-gcc-309c3053481b62acea44176015e6ee2eea218a12.zip
2011-12-12 Tristan Gingold <gingold@adacore.com>
* mlib-tgt-specific-xi.adb: (Get_Target_Prefix): Simplify code. 2011-12-12 Thomas Quinot <quinot@adacore.com> * par_sco.adb: Adjust dominant marker for branches of CASE statements. 2011-12-12 Thomas Quinot <quinot@adacore.com> * gsocket.h, s-oscons-tmplt.c: Ensure we do not include any system header file prior to redefining FD_SETSIZE. 2011-12-12 Ed Schonberg <schonberg@adacore.com> * sem_ch13.adb (Check_Aspect_At_End_Of_Declarations): In a generic context the aspect expressions may not have been preanalyzed if there was no previous freeze point, so the expressions must be preanalyzed now, and there is no conformance to check for visibility changes. 2011-12-12 Matthew Heaney <heaney@adacore.com> * a-convec.adb, a-coinve.adb, a-cobove.adb (Iterator): Use subtype Index_Type'Base for Index component (Finalize): Remove unnecessary access check (First, Last): Cursor return value depends on iterator index value (Iterate): Use start position as iterator index value (Next, Previous): Forward to corresponding cursor-based operation. * a-cborma.adb (Iterate): Properly initialize iterator object (with 0 as node index). git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@182226 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/ada/a-convec.adb')
-rw-r--r--gcc/ada/a-convec.adb133
1 files changed, 107 insertions, 26 deletions
diff --git a/gcc/ada/a-convec.adb b/gcc/ada/a-convec.adb
index 980708d1f7e..c16c2f66edc 100644
--- a/gcc/ada/a-convec.adb
+++ b/gcc/ada/a-convec.adb
@@ -41,16 +41,18 @@ package body Ada.Containers.Vectors is
Vector_Iterator_Interfaces.Reversible_Iterator with
record
Container : Vector_Access;
- Index : Index_Type;
+ Index : Index_Type'Base;
end record;
overriding procedure Finalize (Object : in out Iterator);
overriding function First (Object : Iterator) return Cursor;
overriding function Last (Object : Iterator) return Cursor;
+
overriding function Next
- (Object : Iterator;
+ (Object : Iterator;
Position : Cursor) return Cursor;
+
overriding function Previous
(Object : Iterator;
Position : Cursor) return Cursor;
@@ -782,14 +784,9 @@ package body Ada.Containers.Vectors is
end Finalize;
procedure Finalize (Object : in out Iterator) is
+ B : Natural renames Object.Container.Busy;
begin
- if Object.Container /= null then
- declare
- B : Natural renames Object.Container.all.Busy;
- begin
- B := B - 1;
- end;
- end if;
+ B := B - 1;
end Finalize;
----------
@@ -855,10 +852,24 @@ package body Ada.Containers.Vectors is
function First (Object : Iterator) return Cursor is
begin
- if Is_Empty (Object.Container.all) then
- return No_Element;
+ -- The value of the iterator object's Index component influences the
+ -- behavior of the First (and Last) selector function.
+
+ -- When the Index component is No_Index, 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 Index component isn't No_Index, the iterator object was
+ -- constructed with a start expression, that specifies the position from
+ -- which the (forward) partial iteration begins.
+
+ if Object.Index = No_Index then
+ return First (Object.Container.all);
else
- return (Object.Container, Index_Type'First);
+ return Cursor'(Object.Container, Object.Index);
end if;
end First;
@@ -2124,13 +2135,24 @@ package body Ada.Containers.Vectors is
(Container : Vector)
return Vector_Iterator_Interfaces.Reversible_Iterator'Class
is
- B : Natural renames Container'Unrestricted_Access.all.Busy;
+ V : constant Vector_Access := Container'Unrestricted_Access;
+ B : Natural renames V.Busy;
begin
+ -- The value of its Index component influences the behavior of the First
+ -- and Last selector functions of the iterator object. When the Index
+ -- component is No_Index (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 It : constant Iterator :=
(Limited_Controlled with
- Container => Container'Unrestricted_Access,
- Index => Index_Type'First)
+ Container => V,
+ Index => No_Index)
do
B := B + 1;
end return;
@@ -2141,12 +2163,48 @@ package body Ada.Containers.Vectors is
Start : Cursor)
return Vector_Iterator_Interfaces.Reversible_Iterator'class
is
- B : Natural renames Container'Unrestricted_Access.all.Busy;
+ V : constant Vector_Access := Container'Unrestricted_Access;
+ B : Natural renames V.Busy;
begin
+ -- 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.Container = null then
+ raise Constraint_Error with
+ "Start position for iterator equals No_Element";
+ end if;
+
+ if Start.Container /= V then
+ raise Program_Error with
+ "Start cursor of Iterate designates wrong vector";
+ end if;
+
+ if Start.Index > V.Last then
+ raise Constraint_Error with
+ "Start position for iterator equals No_Element";
+ end if;
+
+ -- The value of its Index component influences the behavior of the First
+ -- and Last selector functions of the iterator object. When the Index
+ -- component is not No_Index (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 It : constant Iterator :=
(Limited_Controlled with
- Container => Container'Unrestricted_Access,
+ Container => V,
Index => Start.Index)
do
B := B + 1;
@@ -2168,10 +2226,23 @@ package body Ada.Containers.Vectors is
function Last (Object : Iterator) return Cursor is
begin
- if Is_Empty (Object.Container.all) then
- return No_Element;
+ -- The value of the iterator object's Index component influences the
+ -- behavior of the Last (and First) selector function.
+
+ -- When the Index component is No_Index, 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 Index component is not No_Index, the iterator object was
+ -- constructed with a start expression, that specifies the position from
+ -- which the (reverse) partial iteration begins.
+
+ if Object.Index = No_Index then
+ return Last (Object.Container.all);
else
- return (Object.Container, Object.Container.Last);
+ return Cursor'(Object.Container, Object.Index);
end if;
end Last;
@@ -2282,11 +2353,16 @@ package body Ada.Containers.Vectors is
function Next (Object : Iterator; Position : Cursor) return Cursor is
begin
- if Position.Index < Object.Container.Last then
- return (Object.Container, Position.Index + 1);
- else
+ 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 vector";
+ end if;
+
+ return Next (Position);
end Next;
procedure Next (Position : in out Cursor) is
@@ -2338,11 +2414,16 @@ package body Ada.Containers.Vectors is
function Previous (Object : Iterator; Position : Cursor) return Cursor is
begin
- if Position.Index > Index_Type'First then
- return (Object.Container, Position.Index - 1);
- else
+ 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 vector";
+ end if;
+
+ return Previous (Position);
end Previous;
procedure Previous (Position : in out Cursor) is
OpenPOWER on IntegriCloud