Package org.apache.bcel.generic

Examples of org.apache.bcel.generic.InstructionHandle


    //and upper bound of Catch matches upper bound of Finally Handler.
   
    //first, match the Try block that applies...
   
    //get lowest bound.
    InstructionHandle min = getLowestBound(line.getCodeExceptions());
    InstructionHandle max = getHighestBound(line.getCodeExceptions());
   
    LOG.debug("Finally Range: "+min.getPosition() + " -> "+max.getPosition());
   
    TryIntermediate matched = matchTryBlock(min, max);
    if(matched != null) {
      final Set<Integer> offsets = collectOffsets(line);
      //ok, now we need to eliminate finally blocks from this try and all of the catches.  thanks Java!
      List<CatchIntermediate> catchClauses = igc.getCatchClauses(matched);
      //for each catch clause...
      for(CatchIntermediate catchClause : catchClauses) {
        processCatch(catchClause, line, offsets);
      }
     
      processTry(matched, line, offsets);
    }
   
    //now, add the edge between end of FINALLY and the next statement.
    InstructionHandle finallyEnd = line.getBlockRange().getEnd();
    //get the next.. then search for next node in graph.
   
    AbstractIntermediate finallyLast = igc.findNextNode(finallyEnd);
    AbstractIntermediate afterFinally = igc.findNextNode(finallyEnd.getNext());
   
    igc.redirectPredecessors(finallyLast, afterFinally);
    igc.getGraph().removeVertex(finallyLast);
  }
View Full Code Here


    igc.getGraph().removeVertex(finallyLast);
  }
 
  protected void processTry(TryIntermediate tryIntermediate, FinallyIntermediate finallyIntermediate, Set<Integer> offsets) {
    //ok, now let's handle the try...
    InstructionHandle end = tryIntermediate.getBlockRange().getEnd();
    //next should be GOTO.
    AbstractIntermediate tryEndNode = igc.findNextNode(end);
   
    AbstractIntermediate gotoIntermediate = null;
    //check to see if this is loop...
View Full Code Here

   
    return offsets;
  }
 
  protected void eliminateNode(AbstractIntermediate first, Set<Integer> offsets) {
    InstructionHandle ih = first.getInstruction();
    int position = first.getInstruction().getPosition();
 
    for(Integer offset : offsets) {
      int target = position + offset;
     
View Full Code Here

   
    return null;
  }

  protected InstructionHandle getHighestBound(Collection<CodeExceptionGen> cegs) {
    InstructionHandle highest = null;
    for(CodeExceptionGen ceg : cegs) {
      if(highest != null) {
        if(ceg.getEndPC().getPosition() > highest.getPosition()) {
          highest = ceg.getEndPC();
        }
      }
      else {
        highest = ceg.getEndPC();
View Full Code Here

   
    return highest;
  }
 
  protected InstructionHandle getLowestBound(Collection<CodeExceptionGen> cegs) {
    InstructionHandle lowest = null;
    for(CodeExceptionGen ceg : cegs) {
      if(lowest != null) {
        if(ceg.getStartPC().getPosition() < lowest.getPosition()) {
          lowest = ceg.getStartPC();
        }
      }
      else {
        lowest = ceg.getStartPC();
View Full Code Here

    public static VariableIndex createFromInstructionHandle(InstructionHandle ih, int index) {
      //read ahead.
      int start = ih.getPosition();
      int end = start;
      while(!(ih instanceof BranchHandle)) {
        InstructionHandle next = ih.getNext();
        if(next == null) {
          break;
        }
        if(LOG.isDebugEnabled()) {
          LOG.debug("Skipping forward: "+next);
        }
        ih = next;
      }
      //check ih.
      if(ih instanceof BranchHandle)
      {
        //get the max... either branch.
        int t1 = ih.getPosition();
       
        InstructionHandle t2handle = ((BranchHandle) ih).getTarget();
        if(t2handle.getNext() != null) {
          t2handle = t2handle.getNext();
        }
       
        int t2 = t2handle.getPosition();
        if(LOG.isDebugEnabled()) {
          LOG.debug("Skipping forward: "+t2);
        }
        end = t1 > t2 ? t1 : t2;
      }
View Full Code Here

    public static VariableIndex createFromInstructionHandle(InstructionHandle ih, int index) {
      //read ahead.
      int start = ih.getPosition();
      int end = start;
      while(!(ih instanceof BranchHandle)) {
        InstructionHandle next = ih.getNext();
        if(next == null) {
          break;
        }
        if(LOG.isDebugEnabled()) {
          LOG.debug("Skipping forward: "+next);
        }
        ih = next;
      }
      //check ih.
      if(ih instanceof BranchHandle)
      {
        //get the max... either branch.
        int t1 = ih.getPosition();
       
        InstructionHandle t2handle = ((BranchHandle) ih).getTarget();
        if(t2handle.getNext() != null) {
          t2handle = t2handle.getNext();
        }
       
        int t2 = t2handle.getPosition();
        if(LOG.isDebugEnabled()) {
          LOG.debug("Skipping forward: "+t2);
        }
        end = t1 > t2 ? t1 : t2;
      }
View Full Code Here

     */
    private ExceptionSet computeThrownExceptionTypes(BasicBlock basicBlock) throws
    DataflowAnalysisException {

        ExceptionSet exceptionTypeSet = exceptionSetFactory.createExceptionSet();
        InstructionHandle pei = basicBlock.getExceptionThrower();
        Instruction ins = pei.getInstruction();

        // Get the exceptions that BCEL knows about.
        // Note that all of these are unchecked.
        ExceptionThrower exceptionThrower = (ExceptionThrower) ins;
        Class<?>[] exceptionList = exceptionThrower.getExceptions();
View Full Code Here

        @Override
        public InstructionHandle next() {
            if (!hasNext()) {
                throw new NoSuchElementException();
            }
            InstructionHandle result = next;
            next = (result == last) ? null : next.getNext();
            return result;
        }
View Full Code Here

        @Override
        public InstructionHandle next() throws NoSuchElementException {
            if (!hasNext()) {
                throw new NoSuchElementException();
            }
            InstructionHandle result = next;
            next = (result == first) ? null : next.getPrev();
            return result;
        }
View Full Code Here

TOP

Related Classes of org.apache.bcel.generic.InstructionHandle

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.