Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /* Soot - a J*va Optimization Framework
   * Copyright (C) 2007 Eric Bodden
   * This library is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * Lesser General Public License for more details.
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the
  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  * Boston, MA 02111-1307, USA.
 package soot.toolkits.graph;
 import soot.Body;
A loop nesting tree, implemented as a tree-map. Loops are represented by pairs of head-statements and the respective loop. The iterator over this collection returns the loop in such an order that a loop l will always returned before a loop m if l is an inner loop of m.

Eric Bodden
 public class LoopNestTree extends TreeSet<Loop> {

Comparator, stating that a loop l1 is smaller than a loop l2 if l2 contains all statements of l1.

Eric Bodden
 	private static class LoopNestTreeComparator implements Comparator<Loop> {
 		public int compare(Loop loop1Loop loop2) {
 			Collection<Stmtstmts1 = loop1.getLoopStatements();
             Collection<Stmtstmts2 = loop2.getLoopStatements();
 			if(stmts1.equals(stmts2)) {
 				assert loop1.getHead().equals(loop2.getHead()); //should really have the same head then
 				//equal (same) loops
 				return 0;
 			} else if(stmts1.containsAll(stmts2)) {
 				//1 superset of 2
 				return 1;
 			} else if(stmts2.containsAll(stmts1)) {
 				//1 subset of 2
 				return -1;
 			//overlap (?) or disjoint: order does not matter;
 			//however we must *not* return 0 as this would only keep one of the two loops;
 			//hence, return 1
 			return 1;

Builds a loop nest tree from a method body using soot.jimple.toolkits.annotation.logic.LoopFinder.
 	public LoopNestTree(Body b) {

Builds a loop nest tree from a mapping from loop headers to statements in the loop.
 	public LoopNestTree(Collection<Looploops) {
 		super(new LoopNestTreeComparator());
 	private static Collection<LoopcomputeLoops(Body b) {
 		LoopFinder loopFinder = new LoopFinder();
 		Collection<Looploops = loopFinder.loops();
 		return loops;
     public boolean hasNestedLoops() {
         //TODO could be speeded up by just comparing two consecutive
         //loops returned by the iterator
         LoopNestTreeComparator comp = new LoopNestTreeComparator();
         for (Loop loop1 : this) {
             for (Loop loop2 : this) {
                 if(!=0) {
                     return true;
        return false;
New to GrepCode? Check out our FAQ X