jdk.nashorn.internal.ir.TryNode Java Examples

The following examples show how to use jdk.nashorn.internal.ir.TryNode. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Lower.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private Block catchAllBlock(final TryNode tryNode) {
    final int  lineNumber = tryNode.getLineNumber();
    final long token      = tryNode.getToken();
    final int  finish     = tryNode.getFinish();

    final IdentNode exception = new IdentNode(token, finish, lc.getCurrentFunction().uniqueName("catch_all"));

    final Block catchBody = new Block(token, finish, new ThrowNode(lineNumber, token, finish, new IdentNode(exception), ThrowNode.IS_SYNTHETIC_RETHROW));
    assert catchBody.isTerminal(); //ends with throw, so terminal

    final CatchNode catchAllNode  = new CatchNode(lineNumber, token, finish, new IdentNode(exception), null, catchBody, CatchNode.IS_SYNTHETIC_RETHROW);
    final Block     catchAllBlock = new Block(token, finish, catchAllNode);

    //catchallblock -> catchallnode (catchnode) -> exception -> throw

    return (Block)catchAllBlock.accept(this); //not accepted. has to be accepted by lower
}
 
Example #2
Source File: Lower.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private Block catchAllBlock(final TryNode tryNode) {
    final int  lineNumber = tryNode.getLineNumber();
    final long token      = tryNode.getToken();
    final int  finish     = tryNode.getFinish();

    final IdentNode exception = new IdentNode(token, finish, lc.getCurrentFunction().uniqueName(CompilerConstants.EXCEPTION_PREFIX.symbolName()));

    final Block catchBody = new Block(token, finish, new ThrowNode(lineNumber, token, finish, new IdentNode(exception), true));
    assert catchBody.isTerminal(); //ends with throw, so terminal

    final CatchNode catchAllNode  = new CatchNode(lineNumber, token, finish, new IdentNode(exception), null, catchBody, true);
    final Block     catchAllBlock = new Block(token, finish, catchAllNode);

    //catchallblock -> catchallnode (catchnode) -> exception -> throw

    return (Block)catchAllBlock.accept(this); //not accepted. has to be accepted by lower
}
 
Example #3
Source File: Lower.java    From nashorn with GNU General Public License v2.0 6 votes vote down vote up
private Block catchAllBlock(final TryNode tryNode) {
    final int  lineNumber = tryNode.getLineNumber();
    final long token      = tryNode.getToken();
    final int  finish     = tryNode.getFinish();

    final IdentNode exception = new IdentNode(token, finish, lc.getCurrentFunction().uniqueName("catch_all"));

    final Block catchBody = new Block(token, finish, new ThrowNode(lineNumber, token, finish, new IdentNode(exception), ThrowNode.IS_SYNTHETIC_RETHROW));
    assert catchBody.isTerminal(); //ends with throw, so terminal

    final CatchNode catchAllNode  = new CatchNode(lineNumber, token, finish, new IdentNode(exception), null, catchBody, CatchNode.IS_SYNTHETIC_RETHROW);
    final Block     catchAllBlock = new Block(token, finish, catchAllNode);

    //catchallblock -> catchallnode (catchnode) -> exception -> throw

    return (Block)catchAllBlock.accept(this); //not accepted. has to be accepted by lower
}
 
Example #4
Source File: PrintVisitor.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterTryNode(final TryNode tryNode) {
    tryNode.toString(sb, printTypes);
    printLocalVariableConversion(tryNode);
    tryNode.getBody().accept(this);

    final List<Block> catchBlocks = tryNode.getCatchBlocks();

    for (final Block catchBlock : catchBlocks) {
        final CatchNode catchNode = (CatchNode)catchBlock.getStatements().get(0);
        catchNode.toString(sb, printTypes);
        catchNode.getBody().accept(this);
    }

    final Block finallyBody = tryNode.getFinallyBody();

    if (finallyBody != null) {
        sb.append(" finally ");
        finallyBody.accept(this);
    }

    for (final Block inlinedFinally : tryNode.getInlinedFinallies()) {
        inlinedFinally.accept(this);
    }
    return false;
}
 
Example #5
Source File: Lower.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private Block catchAllBlock(final TryNode tryNode) {
    final int  lineNumber = tryNode.getLineNumber();
    final long token      = tryNode.getToken();
    final int  finish     = tryNode.getFinish();

    final IdentNode exception = new IdentNode(token, finish, lc.getCurrentFunction().uniqueName(CompilerConstants.EXCEPTION_PREFIX.symbolName()));

    final Block catchBody = new Block(token, finish, new ThrowNode(lineNumber, token, finish, new IdentNode(exception), true));
    assert catchBody.isTerminal(); //ends with throw, so terminal

    final CatchNode catchAllNode  = new CatchNode(lineNumber, token, finish, new IdentNode(exception), null, catchBody, true);
    final Block     catchAllBlock = new Block(token, finish, catchAllNode);

    //catchallblock -> catchallnode (catchnode) -> exception -> throw

    return (Block)catchAllBlock.accept(this); //not accepted. has to be accepted by lower
}
 
Example #6
Source File: PrintVisitor.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterTryNode(final TryNode tryNode) {
    tryNode.toString(sb, printTypes);
    printLocalVariableConversion(tryNode);
    tryNode.getBody().accept(this);

    final List<Block> catchBlocks = tryNode.getCatchBlocks();

    for (final Block catchBlock : catchBlocks) {
        final CatchNode catchNode = (CatchNode)catchBlock.getStatements().get(0);
        catchNode.toString(sb, printTypes);
        catchNode.getBody().accept(this);
    }

    final Block finallyBody = tryNode.getFinallyBody();

    if (finallyBody != null) {
        sb.append(" finally ");
        finallyBody.accept(this);
    }

    for (final Block inlinedFinally : tryNode.getInlinedFinallies()) {
        inlinedFinally.accept(this);
    }
    return false;
}
 
Example #7
Source File: Lower.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private Block catchAllBlock(final TryNode tryNode) {
    final int  lineNumber = tryNode.getLineNumber();
    final long token      = tryNode.getToken();
    final int  finish     = tryNode.getFinish();

    final IdentNode exception = new IdentNode(token, finish, lc.getCurrentFunction().uniqueName(CompilerConstants.EXCEPTION_PREFIX.symbolName()));

    final Block catchBody = new Block(token, finish, new ThrowNode(lineNumber, token, finish, new IdentNode(exception), true));
    assert catchBody.isTerminal(); //ends with throw, so terminal

    final CatchNode catchAllNode  = new CatchNode(lineNumber, token, finish, new IdentNode(exception), null, catchBody, true);
    final Block     catchAllBlock = new Block(token, finish, catchAllNode);

    //catchallblock -> catchallnode (catchnode) -> exception -> throw

    return (Block)catchAllBlock.accept(this); //not accepted. has to be accepted by lower
}
 
Example #8
Source File: PrintVisitor.java    From nashorn with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterTryNode(final TryNode tryNode) {
    tryNode.toString(sb);
    tryNode.getBody().accept(this);

    final List<Block> catchBlocks = tryNode.getCatchBlocks();

    for (final Block catchBlock : catchBlocks) {
        final CatchNode catchNode = (CatchNode)catchBlock.getStatements().get(0);
        catchNode.toString(sb);
        catchNode.getBody().accept(this);
    }

    final Block finallyBody = tryNode.getFinallyBody();

    if (finallyBody != null) {
        sb.append(" finally ");
        finallyBody.accept(this);
    }

    return false;
}
 
Example #9
Source File: PrintVisitor.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterTryNode(final TryNode tryNode) {
    tryNode.toString(sb, printTypes);
    printLocalVariableConversion(tryNode);
    tryNode.getBody().accept(this);

    final List<Block> catchBlocks = tryNode.getCatchBlocks();

    for (final Block catchBlock : catchBlocks) {
        final CatchNode catchNode = (CatchNode)catchBlock.getStatements().get(0);
        catchNode.toString(sb, printTypes);
        catchNode.getBody().accept(this);
    }

    final Block finallyBody = tryNode.getFinallyBody();

    if (finallyBody != null) {
        sb.append(" finally ");
        finallyBody.accept(this);
    }

    for (final Block inlinedFinally : tryNode.getInlinedFinallies()) {
        inlinedFinally.accept(this);
    }
    return false;
}
 
Example #10
Source File: PrintVisitor.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterTryNode(final TryNode tryNode) {
    tryNode.toString(sb);
    tryNode.getBody().accept(this);

    final List<Block> catchBlocks = tryNode.getCatchBlocks();

    for (final Block catchBlock : catchBlocks) {
        final CatchNode catchNode = (CatchNode)catchBlock.getStatements().get(0);
        catchNode.toString(sb);
        catchNode.getBody().accept(this);
    }

    final Block finallyBody = tryNode.getFinallyBody();

    if (finallyBody != null) {
        sb.append(" finally ");
        finallyBody.accept(this);
    }

    return false;
}
 
Example #11
Source File: IRTranslator.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterTryNode(final TryNode tryNode) {
    final List<? extends CatchNode> catchNodes = tryNode.getCatches();
    final List<CatchTreeImpl> catchTrees = new ArrayList<>(catchNodes.size());
    for (final CatchNode catchNode : catchNodes) {
        catchTrees.add(new CatchTreeImpl(catchNode,
                translateExpr(catchNode.getException()),
                (BlockTree) translateBlock(catchNode.getBody()),
                translateExpr(catchNode.getExceptionCondition())));
    }

    curStat = new TryTreeImpl(tryNode,
            (BlockTree) translateBlock(tryNode.getBody()),
            catchTrees,
            (BlockTree) translateBlock(tryNode.getFinallyBody()));

    return false;
}
 
Example #12
Source File: PrintVisitor.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterTryNode(final TryNode tryNode) {
    tryNode.toString(sb, printTypes);
    printLocalVariableConversion(tryNode);
    tryNode.getBody().accept(this);

    final List<Block> catchBlocks = tryNode.getCatchBlocks();

    for (final Block catchBlock : catchBlocks) {
        final CatchNode catchNode = (CatchNode)catchBlock.getStatements().get(0);
        catchNode.toString(sb, printTypes);
        catchNode.getBody().accept(this);
    }

    final Block finallyBody = tryNode.getFinallyBody();

    if (finallyBody != null) {
        sb.append(" finally ");
        finallyBody.accept(this);
    }

    for (final Block inlinedFinally : tryNode.getInlinedFinallies()) {
        inlinedFinally.accept(this);
    }
    return false;
}
 
Example #13
Source File: Lower.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private Block catchAllBlock(final TryNode tryNode) {
    final int  lineNumber = tryNode.getLineNumber();
    final long token      = tryNode.getToken();
    final int  finish     = tryNode.getFinish();

    final IdentNode exception = new IdentNode(token, finish, lc.getCurrentFunction().uniqueName(CompilerConstants.EXCEPTION_PREFIX.symbolName()));

    final Block catchBody = new Block(token, finish, new ThrowNode(lineNumber, token, finish, new IdentNode(exception), true));
    assert catchBody.isTerminal(); //ends with throw, so terminal

    final CatchNode catchAllNode  = new CatchNode(lineNumber, token, finish, new IdentNode(exception), null, catchBody, true);
    final Block     catchAllBlock = new Block(token, finish, catchAllNode);

    //catchallblock -> catchallnode (catchnode) -> exception -> throw

    return (Block)catchAllBlock.accept(this); //not accepted. has to be accepted by lower
}
 
Example #14
Source File: Lower.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private Block catchAllBlock(final TryNode tryNode) {
    final int  lineNumber = tryNode.getLineNumber();
    final long token      = tryNode.getToken();
    final int  finish     = tryNode.getFinish();

    final IdentNode exception = new IdentNode(token, finish, lc.getCurrentFunction().uniqueName("catch_all"));

    final Block catchBody = new Block(token, finish, new ThrowNode(lineNumber, token, finish, new IdentNode(exception), ThrowNode.IS_SYNTHETIC_RETHROW));
    assert catchBody.isTerminal(); //ends with throw, so terminal

    final CatchNode catchAllNode  = new CatchNode(lineNumber, token, finish, new IdentNode(exception), null, catchBody, CatchNode.IS_SYNTHETIC_RETHROW);
    final Block     catchAllBlock = new Block(token, finish, catchAllNode);

    //catchallblock -> catchallnode (catchnode) -> exception -> throw

    return (Block)catchAllBlock.accept(this); //not accepted. has to be accepted by lower
}
 
Example #15
Source File: PrintVisitor.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean enterTryNode(final TryNode tryNode) {
    tryNode.toString(sb);
    tryNode.getBody().accept(this);

    final List<Block> catchBlocks = tryNode.getCatchBlocks();

    for (final Block catchBlock : catchBlocks) {
        final CatchNode catchNode = (CatchNode)catchBlock.getStatements().get(0);
        catchNode.toString(sb);
        catchNode.getBody().accept(this);
    }

    final Block finallyBody = tryNode.getFinallyBody();

    if (finallyBody != null) {
        sb.append(" finally ");
        finallyBody.accept(this);
    }

    return false;
}
 
Example #16
Source File: Lower.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private TryNode ensureUnconditionalCatch(final TryNode tryNode) {
    final List<CatchNode> catches = tryNode.getCatches();
    if(catches == null || catches.isEmpty() || catches.get(catches.size() - 1).getExceptionCondition() == null) {
        return tryNode;
    }
    // If the last catch block is conditional, add an unconditional rethrow block
    final List<Block> newCatchBlocks = new ArrayList<>(tryNode.getCatchBlocks());

    newCatchBlocks.add(catchAllBlock(tryNode));
    return tryNode.setCatchBlocks(lc, newCatchBlocks);
}
 
Example #17
Source File: MethodEmitter.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
void beforeTry(final TryNode tryNode, final Label recovery) {
    LocalVariableConversion next = tryNode.getLocalVariableConversion();
    while(next != null) {
        if(next.isLive()) {
            final Type to = emitLocalVariableConversion(next, false);
            recovery.getStack().onLocalStore(to, next.getSymbol().getSlot(to), true);
        }
        next = next.getNext();
    }
}
 
Example #18
Source File: MethodEmitter.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
void beforeTry(final TryNode tryNode, final Label recovery) {
    LocalVariableConversion next = tryNode.getLocalVariableConversion();
    while(next != null) {
        if(next.isLive()) {
            final Type to = emitLocalVariableConversion(next, false);
            recovery.getStack().onLocalStore(to, next.getSymbol().getSlot(to), true);
        }
        next = next.getNext();
    }
}
 
Example #19
Source File: AssignSymbols.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveTryNode(final TryNode tryNode) {
    assert tryNode.getFinallyBody() == null;

    end(tryNode);

    return tryNode.setException(lc, exceptionSymbol());
}
 
Example #20
Source File: AssignSymbols.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveTryNode(final TryNode tryNode) {
    assert tryNode.getFinallyBody() == null;

    end(tryNode);

    return tryNode.setException(lc, exceptionSymbol());
}
 
Example #21
Source File: Lower.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
private TryNode ensureUnconditionalCatch(final TryNode tryNode) {
    final List<CatchNode> catches = tryNode.getCatches();
    if(catches == null || catches.isEmpty() || catches.get(catches.size() - 1).getExceptionCondition() == null) {
        return tryNode;
    }
    // If the last catch block is conditional, add an unconditional rethrow block
    final List<Block> newCatchBlocks = new ArrayList<>(tryNode.getCatchBlocks());

    newCatchBlocks.add(catchAllBlock(tryNode));
    return tryNode.setCatchBlocks(lc, newCatchBlocks);
}
 
Example #22
Source File: Lower.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private TryNode ensureUnconditionalCatch(final TryNode tryNode) {
    final List<CatchNode> catches = tryNode.getCatches();
    if(catches == null || catches.isEmpty() || catches.get(catches.size() - 1).getExceptionCondition() == null) {
        return tryNode;
    }
    // If the last catch block is conditional, add an unconditional rethrow block
    final List<Block> newCatchBlocks = new ArrayList<>(tryNode.getCatchBlocks());

    newCatchBlocks.add(catchAllBlock(tryNode));
    return tryNode.setCatchBlocks(lc, newCatchBlocks);
}
 
Example #23
Source File: AssignSymbols.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveTryNode(final TryNode tryNode) {
    assert tryNode.getFinallyBody() == null;

    end(tryNode);

    return tryNode.setException(lc, exceptionSymbol());
}
 
Example #24
Source File: Attr.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveTryNode(final TryNode tryNode) {
    tryNode.setException(exceptionSymbol());

    if (tryNode.getFinallyBody() != null) {
        tryNode.setFinallyCatchAll(exceptionSymbol());
    }

    end(tryNode);

    return tryNode;
}
 
Example #25
Source File: MethodEmitter.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
void beforeTry(final TryNode tryNode, final Label recovery) {
    LocalVariableConversion next = tryNode.getLocalVariableConversion();
    while(next != null) {
        if(next.isLive()) {
            final Type to = emitLocalVariableConversion(next, false);
            recovery.getStack().onLocalStore(to, next.getSymbol().getSlot(to), true);
        }
        next = next.getNext();
    }
}
 
Example #26
Source File: MethodEmitter.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
void beforeTry(final TryNode tryNode, final Label recovery) {
    LocalVariableConversion next = tryNode.getLocalVariableConversion();
    while(next != null) {
        if(next.isLive()) {
            final Type to = emitLocalVariableConversion(next, false);
            recovery.getStack().onLocalStore(to, next.getSymbol().getSlot(to), true);
        }
        next = next.getNext();
    }
}
 
Example #27
Source File: AssignSymbols.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Node leaveTryNode(final TryNode tryNode) {
    assert tryNode.getFinallyBody() == null;

    end(tryNode);

    return tryNode.setException(lc, exceptionSymbol());
}
 
Example #28
Source File: TryTreeImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
TryTreeImpl(final TryNode node,
        final BlockTree block,
        final List<? extends CatchTree> catches,
        final BlockTree finallyBlock) {
    super(node);
    this.block = block;
    this.catches = catches;
    this.finallyBlock = finallyBlock;
}
 
Example #29
Source File: Lower.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private TryNode ensureUnconditionalCatch(final TryNode tryNode) {
    final List<CatchNode> catches = tryNode.getCatches();
    if(catches == null || catches.isEmpty() || catches.get(catches.size() - 1).getExceptionCondition() == null) {
        return tryNode;
    }
    // If the last catch block is conditional, add an unconditional rethrow block
    final List<Block> newCatchBlocks = new ArrayList<>(tryNode.getCatchBlocks());

    newCatchBlocks.add(catchAllBlock(tryNode));
    return tryNode.setCatchBlocks(lc, newCatchBlocks);
}
 
Example #30
Source File: Lower.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private TryNode ensureUnconditionalCatch(final TryNode tryNode) {
    final List<CatchNode> catches = tryNode.getCatches();
    if(catches == null || catches.isEmpty() || catches.get(catches.size() - 1).getExceptionCondition() == null) {
        return tryNode;
    }
    // If the last catch block is conditional, add an unconditional rethrow block
    final List<Block> newCatchBlocks = new ArrayList<>(tryNode.getCatchBlocks());

    newCatchBlocks.add(catchAllBlock(tryNode));
    return tryNode.setCatchBlocks(lc, newCatchBlocks);
}