--- /dev/null
+-- { dg-do compile }
+-- { dg-options "-O -gnatn" }
+
+with Ada.Text_IO; use Ada.Text_IO;
+with Controlled6_Pkg;
+with Controlled6_Pkg.Iterators;
+
+procedure Controlled6 is
+
+ type String_Access is access String;
+
+ package My_Q is new Controlled6_Pkg (String_Access);
+ package My_Iterators is new My_Q.Iterators (0);
+ use My_Iterators;
+
+ Iterator : Iterator_Type := Find;
+
+begin
+ loop
+ exit when Is_Null (Iterator);
+ Put (Current (Iterator).all & ' ');
+ Find_Next (Iterator);
+ end loop;
+end;
--- /dev/null
+package body Controlled6_Pkg.Iterators is
+
+ function Find return Iterator_Type is
+ Iterator : Iterator_Type;
+ begin
+ return Iterator;
+ end Find;
+
+ function Current (Iterator : in Iterator_Type) return T is begin
+ return Iterator.Current.Item;
+ end Current;
+
+ procedure Find_Next (Iterator : in out Iterator_Type) is begin
+ Iterator.Current := null;
+ end Find_Next;
+
+ function Is_Null (Iterator : in Iterator_Type) return Boolean is begin
+ return Iterator.Current = null;
+ end Is_Null;
+
+end Controlled6_Pkg.Iterators;
--- /dev/null
+with Ada.Finalization;
+
+generic
+
+ I : Integer;
+
+package Controlled6_Pkg.Iterators is
+
+ type Iterator_Type is new Ada.Finalization.Controlled with record
+ Current : Node_Access_Type;
+ end record;
+
+ function Find return Iterator_Type;
+
+ function Current (Iterator : in Iterator_Type) return T;
+ pragma Inline (Current);
+
+ procedure Find_Next (Iterator : in out Iterator_Type);
+
+ function Is_Null (Iterator : in Iterator_Type) return Boolean;
+
+end Controlled6_Pkg.Iterators;
Miscellaneous helpers
---------------------------------------------------------------------------*/
+/* Return true if T, a GIMPLE_CALL, can make an abnormal transfer of control
+ flow. Transfers of control flow associated with EH are excluded. */
+
+static bool
+call_can_make_abnormal_goto (gimple t)
+{
+ /* If the function has no non-local labels, then a call cannot make an
+ abnormal transfer of control. */
+ if (!cfun->has_nonlocal_label)
+ return false;
+
+ /* Likewise if the call has no side effects. */
+ if (!gimple_has_side_effects (t))
+ return false;
+
+ /* Likewise if the called function is leaf. */
+ if (gimple_call_flags (t) & ECF_LEAF)
+ return false;
+
+ return true;
+}
+
+
+/* Return true if T can make an abnormal transfer of control flow.
+ Transfers of control flow associated with EH are excluded. */
+
+bool
+stmt_can_make_abnormal_goto (gimple t)
+{
+ if (computed_goto_p (t))
+ return true;
+ if (is_gimple_call (t))
+ return call_can_make_abnormal_goto (t);
+ return false;
+}
+
+
/* Return true if T represents a stmt that always transfers control. */
bool
{
int flags = gimple_call_flags (t);
- /* A non-pure/const call alters flow control if the current
- function has nonlocal labels. */
- if (!(flags & (ECF_CONST | ECF_PURE | ECF_LEAF))
- && cfun->has_nonlocal_label)
+ /* A call alters control flow if it can make an abnormal goto. */
+ if (call_can_make_abnormal_goto (t))
return true;
/* A call also alters control flow if it does not return. */
}
-/* Return true if T can make an abnormal transfer of control flow.
- Transfers of control flow associated with EH are excluded. */
-
-bool
-stmt_can_make_abnormal_goto (gimple t)
-{
- if (computed_goto_p (t))
- return true;
- if (is_gimple_call (t))
- return (gimple_has_side_effects (t) && cfun->has_nonlocal_label
- && !(gimple_call_flags (t) & ECF_LEAF));
- return false;
-}
-
-
/* Return true if STMT should start a new basic block. PREV_STMT is
the statement preceding STMT. It is used when STMT is a label or a
case label. Labels should only start a new basic block if their