]> git.unchartedbackwaters.co.uk Git - francis/ofc.git/commitdiff
More work on fixing loop hierarchy.
authorFrancis Russell <francis@unchartedbackwaters.co.uk>
Thu, 2 Feb 2012 19:44:18 +0000 (19:44 +0000)
committerFrancis Russell <francis@unchartedbackwaters.co.uk>
Thu, 2 Feb 2012 19:44:18 +0000 (19:44 +0000)
src/ofc/generators/onetep/LoopTree.scala

index 3d340435ec6325f8099826ec6bd4d5a7e15cdcb6..c711a5ab675101fd2fea786b75d5430758d493b8 100644 (file)
@@ -16,7 +16,6 @@ object LoopTree {
       val indices = space.getIndices
       val localSortedIndices = sortedIndices filter (indices.contains(_))
       base.addIterationSpace(localSortedIndices, space)
-      println(localSortedIndices.toString + " -> "+space)
     }
 
     println(base)
@@ -48,13 +47,17 @@ case class LoopTree private(localIndex: Option[Index]) {
   private def getEndLoop(index: Index) : LoopTree = {
     def newTree = { val tree = new LoopTree(Some(index)); subItems += Right(tree); tree} 
 
-    if (subItems.isEmpty) 
-      newTree
-    else
-      subItems.last match {
-        case Right(tree) => if (tree.getLocalIndex == Some(index)) tree else newTree
-        case _ => newTree
-      }
+    var destination : Option[LoopTree]= None
+    for(item <- subItems)
+      item  match {
+      case Right(tree) => if (tree.getLocalIndex == Some(index)) destination = Some(tree)
+      case _ =>
+    }
+
+    destination match {
+      case Some(tree) => tree
+      case None => newTree
+    }
   }
 
   private def getLocalIndex = localIndex