Compiler: rework dataflow iterator.

This cl addresses comments from 278630 - rework DatflowIterator
to be a parent class for the various iteration modes.

Change-Id: Ic16c093597e2d754761b4fdfa47f665d8b315542
diff --git a/src/compiler/dex/dataflow_iterator.cc b/src/compiler/dex/dataflow_iterator.cc
index 6a3975e..514eeba 100644
--- a/src/compiler/dex/dataflow_iterator.cc
+++ b/src/compiler/dex/dataflow_iterator.cc
@@ -18,69 +18,10 @@
 
 namespace art {
 
-  DataflowIterator::DataflowIterator(MIRGraph* mir_graph, DataFlowAnalysisMode dfa_mode, bool is_iterative)
-      : mir_graph_(mir_graph),
-        mode_(dfa_mode),
-        is_iterative_(is_iterative),
-        changed_(false) {
-    switch(mode_) {
-      case kAllNodes:
-        GrowableListIteratorInit(mir_graph_->GetBlockList(), &all_nodes_iterator_);
-        break;
-
-      case kReachableNodes:
-      case kPreOrderDFSTraversal:
-        start_idx_ = 0;
-        end_idx_ = mir_graph_->GetNumReachableBlocks();
-        idx_ = start_idx_;
-        block_id_list_ = mir_graph_->GetDfsOrder();
-        reverse_ = false;
-        break;
-
-      case kPostOrderDFSTraversal:
-        start_idx_ = mir_graph_->GetNumReachableBlocks() - 1;
-        end_idx_ = 0;
-        idx_ = start_idx_;
-        block_id_list_ = mir_graph_->GetDfsOrder();
-        reverse_ = true;
-        break;
-
-      case kPostOrderDOMTraversal:
-        start_idx_ = 0;
-        end_idx_ = mir_graph_->GetNumReachableBlocks();
-        idx_ = start_idx_;
-        block_id_list_ = mir_graph_->GetDomPostOrder();
-        reverse_ = false;
-        break;
-
-      case kReversePostOrderTraversal:
-        start_idx_ = mir_graph_->GetNumReachableBlocks() - 1;
-        end_idx_ = 0;
-        idx_ = start_idx_;
-        block_id_list_ = mir_graph_->GetDfsPostOrder();
-        reverse_ = true;
-        break;
-      default:
-        LOG(FATAL) << "Unknown traversal mode: " << dfa_mode;
-    }
-  }
-
-  BasicBlock* DataflowIterator::NextBody(bool had_change)
-  {
+  BasicBlock* DataflowIterator::NextBody(bool had_change) {
     changed_ |= had_change;
     BasicBlock* res = NULL;
-    if (mode_ == kAllNodes) {
-      bool keep_looking = true;
-      while (keep_looking) {
-        res = reinterpret_cast<BasicBlock*>(GrowableListIteratorNext(&all_nodes_iterator_));
-        if (is_iterative_ && changed_ && (res == NULL)) {
-          GrowableListIteratorInit(mir_graph_->GetBlockList(), &all_nodes_iterator_);
-          changed_ = false;
-        } else if ((res == NULL) || (!res->hidden)) {
-          keep_looking = false;
-        }
-      }
-    } else if (reverse_) {
+    if (reverse_) {
       if (is_iterative_ && changed_ && (idx_ < 0)) {
         idx_ = start_idx_;
         changed_ = false;
@@ -102,16 +43,21 @@
     return res;
   }
 
-  BasicBlock* DataflowIterator::Next(bool had_change)
-  {
-    DCHECK(is_iterative_);
-    return NextBody(had_change);
-  }
-
-  BasicBlock* DataflowIterator::Next()
-  {
-    DCHECK(!is_iterative_);
-    return NextBody(false);
+  // AllNodes uses the existing GrowableList iterator, so use different NextBody().
+  BasicBlock* AllNodesIterator::NextBody(bool had_change) {
+    changed_ |= had_change;
+    BasicBlock* res = NULL;
+    bool keep_looking = true;
+    while (keep_looking) {
+      res = reinterpret_cast<BasicBlock*>(GrowableListIteratorNext(&all_nodes_iterator_));
+      if (is_iterative_ && changed_ && (res == NULL)) {
+        GrowableListIteratorInit(mir_graph_->GetBlockList(), &all_nodes_iterator_);
+        changed_ = false;
+      } else if ((res == NULL) || (!res->hidden)) {
+        keep_looking = false;
+      }
+    }
+    return res;
   }
 
 }  // namespace art