Package org.candle.decompiler.intermediate.graph

Source Code of org.candle.decompiler.intermediate.graph.GraphIntermediateVisitor

package org.candle.decompiler.intermediate.graph;

import java.util.HashSet;
import java.util.Set;

import org.candle.decompiler.intermediate.code.AbstractIntermediate;
import org.candle.decompiler.intermediate.code.IntermediateComparator;
import org.candle.decompiler.intermediate.graph.context.GraphUpdatedListener;
import org.candle.decompiler.intermediate.graph.context.IntermediateGraphContext;
import org.candle.decompiler.intermediate.visitor.EmptyIntermediateVisitor;

public abstract class GraphIntermediateVisitor extends EmptyIntermediateVisitor {

  protected final IntermediateComparator comparator = new IntermediateComparator();
  protected final IntermediateGraphContext igc;
  protected final boolean listenForUpdates;
 
  public GraphIntermediateVisitor(IntermediateGraphContext igc) {
    this(igc, false);
  }
 
  public GraphIntermediateVisitor(IntermediateGraphContext igc, boolean listenForUpdates) {
    this.igc = igc;
    this.listenForUpdates = listenForUpdates;
  }
 
  public void process() {

    GraphUpdatedListener gul = new GraphUpdatedListener();
    if(listenForUpdates) {
      igc.getGraph().addGraphListener(gul);
    }
    while(true) {
      Set<AbstractIntermediate> snapshot = new HashSet<AbstractIntermediate>();
      snapshot.addAll(igc.getGraph().vertexSet());
     
      for(AbstractIntermediate vertex : snapshot) {
        if(igc.getGraph().containsVertex(vertex)) {
          vertex.accept(this);
        }
      }
      //reset the update listener.
      if(!gul.isUpdated()) {
        break;
      }
      else {
        gul.reset();
      }
    }
    igc.getGraph().removeGraphListener(gul);
  }
}
TOP

Related Classes of org.candle.decompiler.intermediate.graph.GraphIntermediateVisitor

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.