summaryrefslogtreecommitdiff
path: root/gcc/ada/a-comutr.adb
diff options
context:
space:
mode:
authorcharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>2011-08-05 15:10:50 +0000
committercharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>2011-08-05 15:10:50 +0000
commit651a38ec1da7e653b99f6a8dd0ffe393eada459f (patch)
treedbf7d77eccd6d83effd5cc41a4d0d61e74a759c3 /gcc/ada/a-comutr.adb
parent5d740b7e88bc2248d26f2d9923665e7a76857e30 (diff)
downloadgcc-651a38ec1da7e653b99f6a8dd0ffe393eada459f.tar.gz
2011-08-05 Robert Dewar <dewar@adacore.com>
* par_sco.adb, sem_ch3.adb, scos.ads, a-iteint.ads, sem_ch12.adb, a-cimutr.adb, a-cimutr.ads, sem_util.ads, sem_res.adb, a-fihema.adb, sem_ch4.adb, lib-xref-alfa.adb, exp_disp.adb, a-comutr.adb, a-comutr.ads, lib-xref.adb: Minor reformatting. 2011-08-05 Robert Dewar <dewar@adacore.com> * sem_ch11.adb (Analyze_Raise_Statement): Kill assignment to formal warning if there is an exception handler present. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@177451 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/ada/a-comutr.adb')
-rw-r--r--gcc/ada/a-comutr.adb308
1 files changed, 151 insertions, 157 deletions
diff --git a/gcc/ada/a-comutr.adb b/gcc/ada/a-comutr.adb
index d2250dec5f1..7c7661d7e4f 100644
--- a/gcc/ada/a-comutr.adb
+++ b/gcc/ada/a-comutr.adb
@@ -133,25 +133,24 @@ package body Ada.Containers.Multiway_Trees is
Target_Count : Count_Type;
begin
- -- We first restore the target container to its
- -- default-initialized state, before we attempt any
- -- allocation, to ensure that invariants are preserved
- -- in the event that the allocation fails.
+ -- We first restore the target container to its default-initialized
+ -- state, before we attempt any allocation, to ensure that invariants
+ -- are preserved in the event that the allocation fails.
Container.Root.Children := Children_Type'(others => null);
Container.Busy := 0;
Container.Lock := 0;
Container.Count := 0;
- -- Copy_Children returns a count of the number of nodes
- -- that it allocates, but it works by incrementing the
- -- value that is passed in. We must therefore initialize
- -- the count value before calling Copy_Children.
+ -- Copy_Children returns a count of the number of nodes that it
+ -- allocates, but it works by incrementing the value that is passed
+ -- in. We must therefore initialize the count value before calling
+ -- Copy_Children.
Target_Count := 0;
- -- Now we attempt the allocation of subtrees. The invariants
- -- are satisfied even if the allocation fails.
+ -- Now we attempt the allocation of subtrees. The invariants are
+ -- satisfied even if the allocation fails.
Copy_Children (Source, Root_Node (Container), Target_Count);
pragma Assert (Target_Count = Source_Count);
@@ -180,11 +179,10 @@ package body Ada.Containers.Multiway_Trees is
raise Program_Error with "Position cursor not in container";
end if;
- -- AI-0136 says to raise PE if Position equals the root node.
- -- This does not seem correct, as this value is just the limiting
- -- condition of the search. For now we omit this check,
- -- pending a ruling from the ARG. ???
- --
+ -- AI-0136 says to raise PE if Position equals the root node. This does
+ -- not seem correct, as this value is just the limiting condition of the
+ -- search. For now we omit this check, pending a ruling from the ARG.???
+
-- if Is_Root (Position) then
-- raise Program_Error with "Position cursor designates root";
-- end if;
@@ -238,7 +236,9 @@ package body Ada.Containers.Multiway_Trees is
Last := First;
for J in Count_Type'(2) .. Count loop
+
-- Reclaim other nodes if Storage_Error. ???
+
Last.Next := new Tree_Node_Type'(Parent => Parent.Node,
Prev => Last,
Element => New_Item,
@@ -253,10 +253,9 @@ package body Ada.Containers.Multiway_Trees is
Parent => Parent.Node,
Before => null); -- null means "insert at end of list"
- -- In order for operation Node_Count to complete
- -- in O(1) time, we cache the count value. Here we
- -- increment the total count by the number of nodes
- -- we just inserted.
+ -- In order for operation Node_Count to complete in O(1) time, we cache
+ -- the count value. Here we increment the total count by the number of
+ -- nodes we just inserted.
Container.Count := Container.Count + Count;
end Append_Child;
@@ -276,16 +275,15 @@ package body Ada.Containers.Multiway_Trees is
Target.Clear; -- checks busy bit
- -- Copy_Children returns the number of nodes that it allocates,
- -- but it does this by incrementing the count value passed in,
- -- so we must initialize the count before calling Copy_Children.
+ -- Copy_Children returns the number of nodes that it allocates, but it
+ -- does this by incrementing the count value passed in, so we must
+ -- initialize the count before calling Copy_Children.
Target_Count := 0;
- -- Note that Copy_Children inserts the newly-allocated children
- -- into their parent list only after the allocation of all the
- -- children has succeeded. This preserves invariants even if
- -- the allocation fails.
+ -- Note that Copy_Children inserts the newly-allocated children into
+ -- their parent list only after the allocation of all the children has
+ -- succeeded. This preserves invariants even if the allocation fails.
Copy_Children (Source.Root.Children, Root_Node (Target), Target_Count);
pragma Assert (Target_Count = Source_Count);
@@ -306,28 +304,25 @@ package body Ada.Containers.Multiway_Trees is
with "attempt to tamper with cursors (tree is busy)";
end if;
- -- We first set the container count to 0, in order to
- -- preserve invariants in case the deallocation fails.
- -- (This works because Deallocate_Children immediately
- -- removes the children from their parent, and then
- -- does the actual deallocation.)
+ -- We first set the container count to 0, in order to preserve
+ -- invariants in case the deallocation fails. (This works because
+ -- Deallocate_Children immediately removes the children from their
+ -- parent, and then does the actual deallocation.)
Container_Count := Container.Count;
Container.Count := 0;
- -- Deallocate_Children returns the number of nodes that
- -- it deallocates, but it does this by incrementing the
- -- count value that is passed in, so we must first initialize
- -- the count return value before calling it.
+ -- Deallocate_Children returns the number of nodes that it deallocates,
+ -- but it does this by incrementing the count value that is passed in,
+ -- so we must first initialize the count return value before calling it.
Children_Count := 0;
- -- See comment above. Deallocate_Children immediately
- -- removes the children list from their parent node (here,
- -- the root of the tree), and only after that does it
- -- attempt the actual deallocation. So even if the
- -- deallocation fails, the representation invariants
- -- for the tree are preserved.
+ -- See comment above. Deallocate_Children immediately removes the
+ -- children list from their parent node (here, the root of the tree),
+ -- and only after that does it attempt the actual deallocation. So even
+ -- if the deallocation fails, the representation invariants for the tree
+ -- are preserved.
Deallocate_Children (Root_Node (Container), Children_Count);
pragma Assert (Children_Count = Container_Count);
@@ -378,9 +373,8 @@ package body Ada.Containers.Multiway_Trees is
C : Tree_Node_Access;
begin
- -- We special-case the first allocation, in order
- -- to establish the representation invariants
- -- for type Children_Type.
+ -- We special-case the first allocation, in order to establish the
+ -- representation invariants for type Children_Type.
C := Source.First;
@@ -396,9 +390,8 @@ package body Ada.Containers.Multiway_Trees is
CC.Last := CC.First;
- -- The representation invariants for the Children_Type
- -- list have been established, so we can now copy
- -- the remaining children of Source.
+ -- The representation invariants for the Children_Type list have been
+ -- established, so we can now copy the remaining children of Source.
C := C.Next;
while C /= null loop
@@ -414,9 +407,8 @@ package body Ada.Containers.Multiway_Trees is
C := C.Next;
end loop;
- -- We add the newly-allocated children to their parent list
- -- only after the allocation has succeeded, in order to
- -- preserve invariants of the parent.
+ -- Add the newly-allocated children to their parent list only after the
+ -- allocation has succeeded, so as to preserve invariants of the parent.
Parent.Children := CC;
end Copy_Children;
@@ -445,6 +437,7 @@ package body Ada.Containers.Multiway_Trees is
Result := Result + 1;
Node := Node.Next;
end loop;
+
return Result;
end Child_Count;
@@ -479,6 +472,7 @@ package body Ada.Containers.Multiway_Trees is
raise Program_Error with "Parent is not ancestor of Child";
end if;
end loop;
+
return Result;
end Child_Depth;
@@ -522,10 +516,10 @@ package body Ada.Containers.Multiway_Trees is
raise Constraint_Error with "Source cursor designates root";
end if;
- -- Copy_Subtree returns a count of the number of nodes
- -- that it allocates, but it works by incrementing the
- -- value that is passed in. We must therefore initialize
- -- the count value before calling Copy_Subtree.
+ -- Copy_Subtree returns a count of the number of nodes that it
+ -- allocates, but it works by incrementing the value that is passed
+ -- in. We must therefore initialize the count value before calling
+ -- Copy_Subtree.
Target_Count := 0;
@@ -544,10 +538,9 @@ package body Ada.Containers.Multiway_Trees is
Parent => Parent.Node,
Before => Before.Node);
- -- In order for operation Node_Count to complete
- -- in O(1) time, we cache the count value. Here we
- -- increment the total count by the number of nodes
- -- we just inserted.
+ -- In order for operation Node_Count to complete in O(1) time, we cache
+ -- the count value. Here we increment the total count by the number of
+ -- nodes we just inserted.
Target.Count := Target.Count + Target_Count;
end Copy_Subtree;
@@ -585,9 +578,8 @@ package body Ada.Containers.Multiway_Trees is
C : Tree_Node_Access;
begin
- -- We immediately remove the children from their
- -- parent, in order to preserve invariants in case
- -- the deallocation fails.
+ -- We immediately remove the children from their parent, in order to
+ -- preserve invariants in case the deallocation fails.
Subtree.Children := Children_Type'(others => null);
@@ -637,10 +629,10 @@ package body Ada.Containers.Multiway_Trees is
with "attempt to tamper with cursors (tree is busy)";
end if;
- -- Deallocate_Children returns a count of the number of nodes
- -- that it deallocates, but it works by incrementing the
- -- value that is passed in. We must therefore initialize
- -- the count value before calling Deallocate_Children.
+ -- Deallocate_Children returns a count of the number of nodes that it
+ -- deallocates, but it works by incrementing the value that is passed
+ -- in. We must therefore initialize the count value before calling
+ -- Deallocate_Children.
Count := 0;
@@ -685,16 +677,15 @@ package body Ada.Containers.Multiway_Trees is
X := Position.Node;
Position := No_Element;
- -- Restore represention invariants before attempting the
- -- actual deallocation.
+ -- Restore represention invariants before attempting the actual
+ -- deallocation.
Remove_Subtree (X);
Container.Count := Container.Count - 1;
- -- It is now safe to attempt the deallocation. This leaf
- -- node has been disassociated from the tree, so even if
- -- the deallocation fails, representation invariants
- -- will remain satisfied.
+ -- It is now safe to attempt the deallocation. This leaf node has been
+ -- disassociated from the tree, so even if the deallocation fails,
+ -- representation invariants will remain satisfied.
Deallocate_Node (X);
end Delete_Leaf;
@@ -731,38 +722,35 @@ package body Ada.Containers.Multiway_Trees is
X := Position.Node;
Position := No_Element;
- -- Here is one case where a deallocation failure can
- -- result in the violation of a representation invariant.
- -- We disassociate the subtree from the tree now, but we
- -- only decrement the total node count after we attempt
- -- the deallocation. However, if the deallocation fails,
- -- the total node count will not get decremented.
- --
- -- One way around this dilemma is to count the nodes
- -- in the subtree before attempt to delete the subtree,
- -- but that is an O(n) operation, so it does not seem
- -- worth it.
- --
- -- Perhaps this is much ado about nothing, since the
- -- only way deallocation can fail is if Controlled
- -- Finalization fails: this propagates Program_Error
- -- so all bets are off anyway. ???
+ -- Here is one case where a deallocation failure can result in the
+ -- violation of a representation invariant. We disassociate the subtree
+ -- from the tree now, but we only decrement the total node count after
+ -- we attempt the deallocation. However, if the deallocation fails, the
+ -- total node count will not get decremented.
+
+ -- One way around this dilemma is to count the nodes in the subtree
+ -- before attempt to delete the subtree, but that is an O(n) operation,
+ -- so it does not seem worth it.
+
+ -- Perhaps this is much ado about nothing, since the only way
+ -- deallocation can fail is if Controlled Finalization fails: this
+ -- propagates Program_Error so all bets are off anyway. ???
Remove_Subtree (X);
- -- Deallocate_Subtree returns a count of the number of nodes
- -- that it deallocates, but it works by incrementing the
- -- value that is passed in. We must therefore initialize
- -- the count value before calling Deallocate_Subtree.
+ -- Deallocate_Subtree returns a count of the number of nodes that it
+ -- deallocates, but it works by incrementing the value that is passed
+ -- in. We must therefore initialize the count value before calling
+ -- Deallocate_Subtree.
Count := 0;
Deallocate_Subtree (X, Count);
pragma Assert (Count <= Container.Count);
- -- See comments above. We would prefer to do this
- -- sooner, but there's no way to satisfy that goal
- -- without an potentially severe execution penalty.
+ -- See comments above. We would prefer to do this sooner, but there's no
+ -- way to satisfy that goal without a potentially severe execution
+ -- penalty.
Container.Count := Container.Count - Count;
end Delete_Subtree;
@@ -782,6 +770,7 @@ package body Ada.Containers.Multiway_Trees is
N := N.Parent;
Result := Result + 1;
end loop;
+
return Result;
end Depth;
@@ -1080,7 +1069,9 @@ package body Ada.Containers.Multiway_Trees is
Last := Position.Node;
for J in Count_Type'(2) .. Count loop
+
-- Reclaim other nodes if Storage_Error. ???
+
Last.Next := new Tree_Node_Type'(Parent => Parent.Node,
Prev => Last,
Element => New_Item,
@@ -1095,10 +1086,9 @@ package body Ada.Containers.Multiway_Trees is
Parent => Parent.Node,
Before => Before.Node);
- -- In order for operation Node_Count to complete
- -- in O(1) time, we cache the count value. Here we
- -- increment the total count by the number of nodes
- -- we just inserted.
+ -- In order for operation Node_Count to complete in O(1) time, we cache
+ -- the count value. Here we increment the total count by the number of
+ -- nodes we just inserted.
Container.Count := Container.Count + Count;
end Insert_Child;
@@ -1149,7 +1139,9 @@ package body Ada.Containers.Multiway_Trees is
Last := Position.Node;
for J in Count_Type'(2) .. Count loop
+
-- Reclaim other nodes if Storage_Error. ???
+
Last.Next := new Tree_Node_Type'(Parent => Parent.Node,
Prev => Last,
Element => <>,
@@ -1164,10 +1156,9 @@ package body Ada.Containers.Multiway_Trees is
Parent => Parent.Node,
Before => Before.Node);
- -- In order for operation Node_Count to complete
- -- in O(1) time, we cache the count value. Here we
- -- increment the total count by the number of nodes
- -- we just inserted.
+ -- In order for operation Node_Count to complete in O(1) time, we cache
+ -- the count value. Here we increment the total count by the number of
+ -- nodes we just inserted.
Container.Count := Container.Count + Count;
end Insert_Child;
@@ -1186,11 +1177,10 @@ package body Ada.Containers.Multiway_Trees is
C : Children_Type renames Parent.Children;
begin
- -- This is a simple utility operation to
- -- insert a list of nodes (from First..Last)
- -- as children of Parent. The Before node
- -- specifies where the new children should be
- -- inserted relative to the existing children.
+ -- This is a simple utility operation to insert a list of nodes (from
+ -- First..Last) as children of Parent. The Before node specifies where
+ -- the new children should be inserted relative to the existing
+ -- children.
if First = null then
pragma Assert (Last = null);
@@ -1236,8 +1226,8 @@ package body Ada.Containers.Multiway_Trees is
Before : Tree_Node_Access)
is
begin
- -- This is a simple wrapper operation to insert
- -- a single child into the Parent's children list.
+ -- This is a simple wrapper operation to insert a single child into the
+ -- Parent's children list.
Insert_Subtree_List
(First => Subtree,
@@ -1324,6 +1314,7 @@ package body Ada.Containers.Multiway_Trees is
Process => Process);
B := B - 1;
+
exception
when others =>
B := B - 1;
@@ -1357,6 +1348,7 @@ package body Ada.Containers.Multiway_Trees is
end loop;
B := B - 1;
+
exception
when others =>
B := B - 1;
@@ -1372,13 +1364,11 @@ package body Ada.Containers.Multiway_Trees is
Node : Tree_Node_Access;
begin
- -- This is a helper function to recursively iterate over
- -- all the nodes in a subtree, in depth-first fashion.
- -- This particular helper just visits the children of this
- -- subtree, not the root of the subtree node itself. This
- -- is useful when starting from the ultimate root of the
- -- entire tree (see Iterate), as that root does not have
- -- an element.
+ -- This is a helper function to recursively iterate over all the nodes
+ -- in a subtree, in depth-first fashion. This particular helper just
+ -- visits the children of this subtree, not the root of the subtree node
+ -- itself. This is useful when starting from the ultimate root of the
+ -- entire tree (see Iterate), as that root does not have an element.
Node := Subtree.Children.First;
while Node /= null loop
@@ -1414,6 +1404,7 @@ package body Ada.Containers.Multiway_Trees is
end if;
B := B - 1;
+
exception
when others =>
B := B - 1;
@@ -1427,10 +1418,9 @@ package body Ada.Containers.Multiway_Trees is
Process : not null access procedure (Position : Cursor))
is
begin
- -- This is a helper function to recursively iterate over
- -- all the nodes in a subtree, in depth-first fashion.
- -- It first visits the root of the subtree, then visits
- -- its children.
+ -- This is a helper function to recursively iterate over all the nodes
+ -- in a subtree, in depth-first fashion. It first visits the root of the
+ -- subtree, then visits its children.
Process (Cursor'(Container, Subtree));
Iterate_Children (Container, Subtree, Process);
@@ -1526,17 +1516,15 @@ package body Ada.Containers.Multiway_Trees is
function Node_Count (Container : Tree) return Count_Type is
begin
- -- Container.Count is the number of nodes we have actually
- -- allocated. We cache the value specifically so this Node_Count
- -- operation can execute in O(1) time, which makes it behave
- -- similarly to how the Length selector function behaves
- -- for other containers.
- --
- -- The cached node count value only describes the nodes
- -- we have allocated; the root node itself is not included
- -- in that count. The Node_Count operation returns a value
- -- that includes the root node (because the RM says so), so we
- -- must add 1 to our cached value.
+ -- Container.Count is the number of nodes we have actually allocated. We
+ -- cache the value specifically so this Node_Count operation can execute
+ -- in O(1) time, which makes it behave similarly to how the Length
+ -- selector function behaves for other containers.
+
+ -- The cached node count value only describes the nodes we have
+ -- allocated; the root node itself is not included in that count. The
+ -- Node_Count operation returns a value that includes the root node
+ -- (because the RM says so), so we must add 1 to our cached value.
return 1 + Container.Count;
end Node_Count;
@@ -1595,7 +1583,9 @@ package body Ada.Containers.Multiway_Trees is
Last := First;
for J in Count_Type'(2) .. Count loop
+
-- Reclaim other nodes if Storage_Error. ???
+
Last.Next := new Tree_Node_Type'(Parent => Parent.Node,
Prev => Last,
Element => New_Item,
@@ -1610,10 +1600,9 @@ package body Ada.Containers.Multiway_Trees is
Parent => Parent.Node,
Before => Parent.Node.Children.First);
- -- In order for operation Node_Count to complete
- -- in O(1) time, we cache the count value. Here we
- -- increment the total count by the number of nodes
- -- we just inserted.
+ -- In order for operation Node_Count to complete in O(1) time, we cache
+ -- the count value. Here we increment the total count by the number of
+ -- nodes we just inserted.
Container.Count := Container.Count + Count;
end Prepend_Child;
@@ -1670,6 +1659,7 @@ package body Ada.Containers.Multiway_Trees is
L := L - 1;
B := B - 1;
+
exception
when others =>
L := L - 1;
@@ -1725,8 +1715,8 @@ package body Ada.Containers.Multiway_Trees is
C.Last := C.Last.Next;
end loop;
- -- Now that the allocation and reads have completed successfully,
- -- it is safe to link the children to their parent.
+ -- Now that the allocation and reads have completed successfully, it
+ -- is safe to link the children to their parent.
Subtree.Children := C;
end Read_Children;
@@ -1878,6 +1868,7 @@ package body Ada.Containers.Multiway_Trees is
end loop;
B := B - 1;
+
exception
when others =>
B := B - 1;
@@ -1909,11 +1900,11 @@ package body Ada.Containers.Multiway_Trees is
-- Start of processing for Root_Node
begin
- -- This is a utility function for converting from an access type
- -- that designates the distinguished root node to an access type
- -- designating a non-root node. The representation of a root node
- -- does not have an element, but is otherwise identical to a
- -- non-root node, so the conversion itself is safe.
+ -- This is a utility function for converting from an access type that
+ -- designates the distinguished root node to an access type designating
+ -- a non-root node. The representation of a root node does not have an
+ -- element, but is otherwise identical to a non-root node, so the
+ -- conversion itself is safe.
return To_Tree_Node_Access (Container.Root'Unrestricted_Access);
end Root_Node;
@@ -1997,10 +1988,10 @@ package body Ada.Containers.Multiway_Trees is
with "attempt to tamper with cursors (Source tree is busy)";
end if;
- -- We cache the count of the nodes we have allocated, so that
- -- operation Node_Count can execute in O(1) time. But that means
- -- we must count the nodes in the subtree we remove from Source
- -- and insert into Target, in order to keep the count accurate.
+ -- We cache the count of the nodes we have allocated, so that operation
+ -- Node_Count can execute in O(1) time. But that means we must count the
+ -- nodes in the subtree we remove from Source and insert into Target, in
+ -- order to keep the count accurate.
Count := Subtree_Node_Count (Source_Parent.Node);
pragma Assert (Count >= 1);
@@ -2183,17 +2174,16 @@ package body Ada.Containers.Multiway_Trees is
with "attempt to tamper with cursors (Source tree is busy)";
end if;
- -- This is an unfortunate feature of this API: we must count
- -- the nodes in the subtree that we remove from the source tree,
- -- which is an O(n) operation. It would have been better if
- -- the Tree container did not have a Node_Count selector; a
- -- user that wants the number of nodes in the tree could
- -- simply call Subtree_Node_Count, with the understanding that
- -- such an operation is O(n).
- --
- -- Of course, we could choose to implement the Node_Count selector
- -- as an O(n) operation, which would turn this splice operation
- -- into an O(1) operation. ???
+ -- This is an unfortunate feature of this API: we must count the nodes
+ -- in the subtree that we remove from the source tree, which is an O(n)
+ -- operation. It would have been better if the Tree container did not
+ -- have a Node_Count selector; a user that wants the number of nodes in
+ -- the tree could simply call Subtree_Node_Count, with the understanding
+ -- that such an operation is O(n).
+
+ -- Of course, we could choose to implement the Node_Count selector as an
+ -- O(n) operation, which would turn this splice operation into an O(1)
+ -- operation. ???
Subtree_Count := Subtree_Node_Count (Position.Node);
pragma Assert (Subtree_Count <= Source.Count);
@@ -2243,7 +2233,9 @@ package body Ada.Containers.Multiway_Trees is
end if;
if Is_Root (Position) then
+
-- Should this be PE instead? Need ARG confirmation. ???
+
raise Constraint_Error with "Position cursor designates root";
end if;
@@ -2294,6 +2286,7 @@ package body Ada.Containers.Multiway_Trees is
Result := Result + Subtree_Node_Count (Node);
Node := Node.Next;
end loop;
+
return Result;
end Subtree_Node_Count;
@@ -2383,6 +2376,7 @@ package body Ada.Containers.Multiway_Trees is
L := L - 1;
B := B - 1;
+
exception
when others =>
L := L - 1;