Package org.candle.decompiler.intermediate.code

Examples of org.candle.decompiler.intermediate.code.AbstractIntermediate


  protected void processBoolean(Block block, BooleanBranchIntermediate bbi) {
    List<AbstractIntermediate> successors = getUnseenSuccessors(bbi);
    //assign true... and go through true.
   
   
    AbstractIntermediate trueOutcome = igc.getTrueTarget(bbi);
    AbstractIntermediate falseOutcome = igc.getFalseTarget(bbi);
    /*for(AbstractIntermediate successor : successors) {
      if(successor instanceof BooleanBranchOutcome) {
        if(((BooleanBranchOutcome) successor).getExpressionOutcome() == Boolean.TRUE) {
          trueOutcome = (BooleanBranchOutcome)successor;
        }
        else {
          falseOutcome = (BooleanBranchOutcome)successor;
        }
      }
      else {
        throw new IllegalStateException("Outcome of If expected to be boolean.");
      }
    }*/
   
    trueOutcome.accept(this);
   
    //now, go back to if...
    this.current = block;
    falseOutcome.accept(this);

    if(this.current == block) {
      moveUp();
    }
  }
View Full Code Here


    this.current = tryBlock;
   
    //now, get the nested blocks...
    List<AbstractIntermediate> successors = getUnseenSuccessors(line);
   
    AbstractIntermediate inner = null;
    List<AbstractIntermediate> catchBlocks = new LinkedList<AbstractIntermediate>();
    AbstractIntermediate finallyIntermediate = null;
   
    //find the non-catch/finally...
    for(AbstractIntermediate successor : successors) {
      if(successor instanceof CatchIntermediate) {
        catchBlocks.add(successor);
      }
      else if(successor instanceof FinallyIntermediate) {
        finallyIntermediate = successor;
      }
      else {
        if(inner != null) {
          throw new IllegalStateException("Inner direction already set.");
        }
        inner = successor;
      }
    }
    Collections.sort(catchBlocks, new IntermediateComparator());
   
    if(inner == null) {
      throw new IllegalStateException("Inner is not set.");
    }
   
    inner.accept(this);
   
    //set the current up.
    moveUp();
    for(AbstractIntermediate catchBlock : catchBlocks) {
      current = tryBlock;
      catchBlock.accept(this);
    }
   
    if(finallyIntermediate != null) {
      current = tryBlock;
      finallyIntermediate.accept(this);
    }
  }
View Full Code Here

    this.current = elseIfBlock;
   
    List<AbstractIntermediate> successors = getUnseenSuccessors(line);
    //assign true... and go through true.
   
    AbstractIntermediate trueOutcome = igc.getTrueTarget(line);
    AbstractIntermediate falseOutcome = igc.getFalseTarget(line);
   
    /*
    for(AbstractIntermediate successor : successors) {
      if(successor instanceof BooleanBranchOutcome) {
        if(((BooleanBranchOutcome) successor).getExpressionOutcome() == Boolean.TRUE) {
          trueOutcome = (BooleanBranchOutcome)successor;
        }
        else {
          falseOutcome = (BooleanBranchOutcome)successor;
        }
      }
      else {
        throw new IllegalStateException("Outcome of If expected to be boolean.");
      }
    }*/
   
    trueOutcome.accept(this);
   
    //now, go back to if...
    this.current = elseIfBlock;
    falseOutcome.accept(this);

    if(this.current == elseIfBlock) {
      moveUp();
    }
   
View Full Code Here

    this.current = ifBlock;
   
    List<AbstractIntermediate> successors = getUnseenSuccessors(line);
    //assign true... and go through true.
   
    AbstractIntermediate trueOutcome = igc.getTrueTarget(line);
    AbstractIntermediate falseOutcome = igc.getFalseTarget(line);
    /*
    for(AbstractIntermediate successor : successors) {
      if(successor instanceof BooleanBranchOutcome) {
        if(((BooleanBranchOutcome) successor).getExpressionOutcome() == Boolean.TRUE) {
          trueOutcome = (BooleanBranchOutcome)successor;
        }
        else {
          falseOutcome = (BooleanBranchOutcome)successor;
        }
      }
      else {
        throw new IllegalStateException("Outcome of If expected to be boolean.");
      }
    }*/
   
    trueOutcome.accept(this);
   
    //now, go back to if...
    this.current = ifBlock;
    falseOutcome.accept(this);

    if(this.current == ifBlock) {
      moveUp();
    }
   
View Full Code Here

    ListenableDirectedGraph<AbstractIntermediate, IntermediateEdge> intermediateGraph = new ListenableDirectedGraph<AbstractIntermediate, IntermediateEdge>(IntermediateEdge.class);
   
    //walk the instruction graph and generate the intermediate graph.  start by walking and adding all vertices.  Then, add the connections between the vertices.
    for(InstructionHandle ih : igc.getGraph().vertexSet()) {
      if(igc.hasIntermediate(ih)) {
        AbstractIntermediate vertex = igc.getIntermediateFromInstruction(ih);
        intermediateGraph.addVertex(vertex);
        nodeMapping.put(ih, vertex);
      }
    }
   
    //now, add the links.
    for(InstructionHandle ih : igc.getGraph().vertexSet()) {
      AbstractIntermediate nodeIntermediate = nodeMapping.get(ih);
     
      if(nodeIntermediate == null) {
        LOG.warn("This shouldn't be...");
        continue;
      }
     
      List<InstructionHandle> predecessors = igc.getPredecessors(ih);
      List<InstructionHandle> successors = igc.getSuccessors(ih);
     
      for(InstructionHandle predecessor : predecessors) {
        //find it's AbstractIntermediate.
        AbstractIntermediate predIntermediate = nodeMapping.get(predecessor);
       
       
        if(predIntermediate == null) {
          //then something is wrong.
          LOG.warn("This shouldn't be...");
          continue;
        }
       
        IntermediateEdge insEdge = igc.getGraph().getEdge(predecessor, ih);
       
        //add an edge to the intermediate graph.
        if(intermediateGraph.containsEdge(predIntermediate, nodeIntermediate)) {
          continue;
        }
         
        intermediateGraph.addEdge(predIntermediate, nodeIntermediate, (IntermediateEdge)insEdge.clone());
      }
     
      for(InstructionHandle successor : successors) {
        //find it's AbstractIntermediate.
        AbstractIntermediate successorIntermediate = nodeMapping.get(successor);
       
        if(successorIntermediate == null) {
          LOG.warn("This shouldn't be...");
          continue
        }
View Full Code Here

      BlockRange tryRange = new BlockRange();
      tryRange.setStart(min);
      tryRange.setEnd(max);
     
     
      AbstractIntermediate handle = igc.findNextNode(ceg.getHandlerPC());
      LOG.debug("RANGE: "+ceg);
      LOG.debug("Range: "+tryRange+" , Target: "+handle.getInstruction().getPosition()+" , Handle: "+handle.getInstruction());
     
     
      if(ceg.getCatchType() == null) {
        if(!tryRangeFinally.containsKey(ceg.getHandlerPC())) {
          tryRangeFinally.put(ceg.getHandlerPC(), new LinkedList<CodeExceptionGen>());
        }
        tryRangeFinally.get(ceg.getHandlerPC()).add(ceg);
        continue;
      }
     
      tryBlock.add(tryRange);

      if(!tryRangeGen.containsKey(tryRange)) {
        tryRangeGen.put(tryRange, new LinkedList<CodeExceptionGen>());
      }       
      tryRangeGen.get(tryRange).add(ceg);
    }
   
   
    for(BlockRange tryRange : tryBlock) {
      //create try block... create each catch block... link the two together for graph sake.
      //look up block...
      InstructionHandle start = tryRange.getStart();
      TryIntermediate tryIntermediate = new TryIntermediate(start);
      tryIntermediate.getBlockRange().setStart(tryRange.getStart());
      tryIntermediate.getBlockRange().setEnd(tryRange.getEnd());
     
     
      igc.getGraph().addVertex(tryIntermediate);
     
      //add line between try and node.
      AbstractIntermediate tryFirst = igc.findNextNode(start);
      igc.redirectPredecessors(tryFirst, tryIntermediate);
      igc.getGraph().addEdge(tryIntermediate, tryFirst);
     
     
      if(tryRangeGen.containsKey(tryRange)) {
        //create catch statements...
        for(CodeExceptionGen ceg : tryRangeGen.get(tryRange)) {
          generateCatch(tryIntermediate, ceg);
        }
      }
    }
   
   
    //create a finally node for each handle of finally & link
    for(InstructionHandle finallyTargetHandle : tryRangeFinally.keySet()) {
      //get reference to target...
      AbstractIntermediate finallyTargetNode = igc.findNextNode(finallyTargetHandle);
     
      //change the instruction to a finally...
      FinallyIntermediate finallyIntermediate = new FinallyIntermediate(finallyTargetNode.getInstruction(), new HashSet<CodeExceptionGen>(tryRangeFinally.get(finallyTargetHandle)));
      igc.getGraph().addVertex(finallyIntermediate);
     
      //now, we need to redirect from the existing throws to finally.
      igc.redirectSuccessors(finallyTargetNode, finallyIntermediate);
      //retract existing.
View Full Code Here

  private void generateCatch(TryIntermediate tryIntermediate, CodeExceptionGen ceg) {
    LOG.debug("CEG: "+ceg);
   
   
    //convert the node to catch blocks...
    AbstractIntermediate catchDeclaration = igc.getOrderedIntermediate().ceiling(new NullIntermediate(ceg.getHandlerPC()));
   
    LOG.debug("Catch Declaration:"+catchDeclaration);
   
    if(catchDeclaration instanceof StatementIntermediate) {
      StatementIntermediate declarationStatement = (StatementIntermediate)catchDeclaration;
View Full Code Here

 
  @Override
  public void visitSwitchIntermediate(SwitchIntermediate line) {

    if(line.getDefaultCase()!=null) {
      AbstractIntermediate defaultNode = igc.findNextNode(line.getDefaultCase().getTarget());
      TreeSet<AbstractIntermediate> elements = (TreeSet<AbstractIntermediate>)igc.getOrderedIntermediate().subSet(line, true, defaultNode, false);
     
      int position = defaultNode.getInstruction().getPosition();
     
      //look for goto statements...
      for(AbstractIntermediate element : elements) {
        if(element instanceof GoToIntermediate) {
          GoToIntermediate gti = (GoToIntermediate)element;
View Full Code Here

    return igc;
  }
 
  @Override
  public void visitStatementIntermediate(StatementIntermediate line) {
    AbstractIntermediate next = ilc.getNext(line);
   
    //check to see if it is a return statement.
    if(line.getExpression() instanceof Return) {
      //don't add a line to next.
      return;
    }
    if(line.getExpression() instanceof Throw) {
      //don't add a line to next.
      return;
    }
   
    if(next != null) {
      //find how that actually maps to the abstract line..
      AbstractIntermediate intermediate = next;
     
      //now, we just add this into the graph.
      igc.getGraph().addVertex(intermediate);
      igc.getGraph().addEdge(line, intermediate);
    }
View Full Code Here

  @Override
  public void visitGoToIntermediate(GoToIntermediate line) {
   
    //find how that actually maps to the abstract line..
    AbstractIntermediate intermediate = ilc.getNext(line);
    igc.getGraph().addVertex(intermediate);
    //line.setTarget(intermediate);
   
    //now, we just add this into the graph.
    igc.getGraph().addEdge(line, intermediate);
View Full Code Here

TOP

Related Classes of org.candle.decompiler.intermediate.code.AbstractIntermediate

Copyright © 2018 www.massapicom. 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.