Package com.strobel.assembler.ir

Examples of com.strobel.assembler.ir.ExceptionHandler


                        final ControlFlowNode handlerBlock = findInnermostHandlerBlock(end.getOffset());
                        ControlFlowNode finallyBlock = findInnermostFinallyHandlerNode(end.getOffset());

                        if (handlerBlock != finallyBlock) {
                            final ExceptionHandler handler = handlerBlock.getExceptionHandler();
                            final ControlFlowNode adjacentFinally = findInnermostFinallyHandlerNode(handler.getTryBlock().getLastInstruction().getOffset());

                            if (finallyBlock.getNodeType() != ControlFlowNodeType.FinallyHandler || finallyBlock != adjacentFinally) {
                                finallyBlock = adjacentFinally;
                            }
                        }
View Full Code Here


    private ControlFlowNode findParentExceptionHandlerNode(final ControlFlowNode node) {
        assert node.getNodeType() == ControlFlowNodeType.CatchHandler ||
               node.getNodeType() == ControlFlowNodeType.FinallyHandler;

        ControlFlowNode result = null;
        ExceptionHandler resultHandler = null;

        final int offset = node.getExceptionHandler().getHandlerBlock().getFirstInstruction().getOffset();

        for (int i = 0, n = _nodes.size(); i < n; i++) {
            final ControlFlowNode currentNode = _nodes.get(i);
            final ExceptionHandler handler = currentNode.getExceptionHandler();

            if (handler != null &&
                handler.getTryBlock().getFirstInstruction().getOffset() <= offset &&
                offset < handler.getTryBlock().getLastInstruction().getEndOffset() &&
                (resultHandler == null || isNarrower(handler, resultHandler))) {

                result = currentNode;
                resultHandler = handler;
            }
View Full Code Here

        return result != null ? result : _exceptionalExit;
    }

    private ControlFlowNode findInnermostExceptionHandlerNode(final int offset) {
        final ExceptionHandler handler = findInnermostExceptionHandler(offset);

        if (handler == null) {
            return _exceptionalExit;
        }
View Full Code Here

        throw new IllegalStateException("Could not find node for exception handler!");
    }

    private ControlFlowNode findInnermostFinallyHandlerNode(final int offset) {
        final ExceptionHandler handler = findInnermostFinallyHandler(offset);

        if (handler == null) {
            return _exceptionalExit;
        }
View Full Code Here

        return null;
    }

    private ExceptionHandler findInnermostExceptionHandler(final int offsetInTryBlock) {
        ExceptionHandler result = null;

        for (final ExceptionHandler handler : _exceptionHandlers) {
            final InstructionBlock tryBlock = handler.getTryBlock();

            if (tryBlock.getFirstInstruction().getOffset() <= offsetInTryBlock &&
View Full Code Here

        return result;
    }

    private ExceptionHandler findInnermostFinallyHandler(final int offsetInTryBlock) {
        ExceptionHandler result = null;

        for (final ExceptionHandler handler : _exceptionHandlers) {
            if (!handler.isFinally()) {
                continue;
            }
View Full Code Here

    private ControlFlowNode findInnermostFinallyBlock(final int instructionOffset) {
        return findInnermostHandlerBlock(instructionOffset, true);
    }

    private ControlFlowNode findInnermostHandlerBlock(final int instructionOffset, final boolean finallyOnly) {
        ExceptionHandler result = null;
        InstructionBlock resultBlock = null;

        for (final ExceptionHandler handler : _exceptionHandlers) {
            if (finallyOnly && handler.isCatch()) {
                continue;
            }

            final InstructionBlock handlerBlock = handler.getHandlerBlock();

            if (handlerBlock.getFirstInstruction().getOffset() <= instructionOffset &&
                instructionOffset < handlerBlock.getLastInstruction().getEndOffset() &&
                (resultBlock == null || isNarrower(handler.getHandlerBlock(), resultBlock))) {

                result = handler;
                resultBlock = handlerBlock;
            }
        }

        final ControlFlowNode innerMost = finallyOnly ? findInnermostExceptionHandlerNode(instructionOffset)
                                                      : findInnermostFinallyHandlerNode(instructionOffset);

        final ExceptionHandler innerHandler = innerMost.getExceptionHandler();
        final InstructionBlock innerBlock = innerHandler != null ? innerHandler.getTryBlock() : null;

        if (innerBlock != null && (resultBlock == null || isNarrower(innerBlock, resultBlock))) {
            result = innerHandler;
        }
View Full Code Here

        final InstructionCollection instructions = _instructions;

        for (int i = 0, n = instructions.size(); i < n; i++) {
            final Instruction blockStart = instructions.get(i);
            final ExceptionHandler blockStartExceptionHandler = findInnermostExceptionHandler(blockStart.getOffset());

            //
            // See how big we can make that block...
            //
            for (; i + 1 < n; i++) {
                final Instruction instruction = instructions.get(i);
                final OpCode opCode = instruction.getOpCode();

                if (opCode.isBranch() && !opCode.isJumpToSubroutine() /*|| opCode.canThrow()*/ || _hasIncomingJumps[i + 1]) {
                    break;
                }

                final Instruction next = instruction.getNext();

                if (next != null) {
                    //
                    // Ensure that blocks never contain instructions from different try blocks.
                    //
                    final ExceptionHandler innermostExceptionHandler = findInnermostExceptionHandler(next.getOffset());

                    if (innermostExceptionHandler != blockStartExceptionHandler) {
                        break;
                    }
                }
View Full Code Here

        //

        for (final ControlFlowNode node : _nodes) {
            if (node.getNodeType() == ControlFlowNodeType.Normal) {
                final Instruction end = node.getEnd();
                final ExceptionHandler innermostHandler = findInnermostExceptionHandler(node.getEnd().getOffset());

                if (innermostHandler != null) {
                    for (final ExceptionHandler other : _handlerPlaceholders) {
                        if (other.getTryBlock().equals(innermostHandler.getTryBlock())) {
                            final ControlFlowNode handlerNode = firstOrDefault(
                                _nodes,
                                new Predicate<ControlFlowNode>() {
                                    @Override
                                    public boolean test(final ControlFlowNode node) {
                                        return node.getExceptionHandler() == other;
                                    }
                                }
                            );

                            if (node != handlerNode) {
                                createEdge(node, handlerNode, JumpType.JumpToExceptionHandler);
                            }
                        }
                    }
                }
                else if (end.getOpCode() == OpCode.ATHROW) {
                    createEdge(node, _exceptionalExit, JumpType.JumpToExceptionHandler);
                }
            }

            final ExceptionHandler exceptionHandler = node.getExceptionHandler();

            if (exceptionHandler != null) {
                final ControlFlowNode parentHandler = findParentExceptionHandlerNode(node);

                if (parentHandler.getNodeType() != ControlFlowNodeType.ExceptionalExit) {
                    for (final ExceptionHandler other : _handlerPlaceholders) {
                        if (Comparer.equals(other.getTryBlock(), parentHandler.getExceptionHandler().getTryBlock())) {
                            final ControlFlowNode handlerNode = firstOrDefault(
                                _nodes,
                                new Predicate<ControlFlowNode>() {
                                    @Override
                                    public boolean test(final ControlFlowNode node) {
                                        return node.getExceptionHandler() == other;
                                    }
                                }
                            );

                            if (handlerNode != node) {
                                createEdge(node, handlerNode, JumpType.JumpToExceptionHandler);
                            }
                        }
                    }
                }

                createEdge(
                    node,
                    exceptionHandler.getHandlerBlock().getFirstInstruction(),
                    JumpType.Normal
                );
            }
        }
    }
View Full Code Here

            }
        }
    }

    private static ControlFlowNode findInnermostExceptionHandlerNode(final ControlFlowGraph cfg, final int offsetInTryBlock) {
        ExceptionHandler result = null;
        ControlFlowNode resultNode = null;

        final List<ControlFlowNode> nodes = cfg.getNodes();

        for (int i = nodes.size() - 1; i >= 0; i--) {
            final ControlFlowNode node = nodes.get(i);
            final ExceptionHandler handler = node.getExceptionHandler();

            if (handler == null) {
                break;
            }

            final InstructionBlock tryBlock = handler.getTryBlock();

            if (tryBlock.getFirstInstruction().getOffset() <= offsetInTryBlock &&
                offsetInTryBlock < tryBlock.getLastInstruction().getEndOffset() &&
                isNarrower(handler, result)) {
View Full Code Here

TOP

Related Classes of com.strobel.assembler.ir.ExceptionHandler

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.