Package org.candle.decompiler.intermediate.graph.enhancer

Source Code of org.candle.decompiler.intermediate.graph.enhancer.ElseIf

package org.candle.decompiler.intermediate.graph.enhancer;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.candle.decompiler.intermediate.code.AbstractIntermediate;
import org.candle.decompiler.intermediate.code.BooleanBranchIntermediate;
import org.candle.decompiler.intermediate.code.conditional.ElseIfIntermediate;
import org.candle.decompiler.intermediate.code.conditional.IfIntermediate;
import org.candle.decompiler.intermediate.graph.GraphIntermediateVisitor;
import org.candle.decompiler.intermediate.graph.context.IntermediateGraphContext;
import org.jgrapht.Graphs;

public class ElseIf extends GraphIntermediateVisitor {

  private static final Log LOG = LogFactory.getLog(ElseIf.class);
 
  public ElseIf(IntermediateGraphContext igc) {
    super(igc, false);
  }
 
  @Override
  public void visitIfIntermediate(IfIntermediate line) {
    //check to see if the predecessor is an if block.
    List<AbstractIntermediate> predecessors = Graphs.predecessorListOf(igc.getGraph(), line);
   
    if(predecessors.size() != 1) {
      return;
    }
   
    //otherwise, see if it is another IF.
    if(predecessors.get(0) instanceof BooleanBranchIntermediate) {
     
      //check to see whether it is on the ELSE side.
      BooleanBranchIntermediate parent = (BooleanBranchIntermediate)predecessors.get(0);
      LOG.debug(parent.getClass());
      if(!(parent instanceof IfIntermediate)) {
        return;
      }
     
     
      if(igc.getFalseTarget(parent) == line) {
        //then this could be an IF block.
        ElseIfIntermediate eii = new ElseIfIntermediate(line.getInstruction(), line.getExpression());
        igc.getGraph().addVertex(eii);
       
        igc.redirectPredecessors(line, eii);
        igc.redirectSuccessors(line, eii);
       
        igc.getGraph().removeVertex(line);
      }
    }
   
  }

}
TOP

Related Classes of org.candle.decompiler.intermediate.graph.enhancer.ElseIf

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.