Java 类jdk.nashorn.internal.ir.Statement 实例源码

项目:OpenJSharp    文件:JSONWriter.java   
private boolean emitProgram(final FunctionNode functionNode) {
    enterDefault(functionNode);
    type("Program");
    comma();

    // body consists of nested functions and statements
    final List<Statement> stats = functionNode.getBody().getStatements();
    final int size = stats.size();
    int idx = 0;
    arrayStart("body");

    for (final Node stat : stats) {
        stat.accept(this);
        if (idx != (size - 1)) {
            comma();
        }
        idx++;
    }
    arrayEnd();

    return leave();
}
项目:OpenJSharp    文件:FoldConstants.java   
@Override
public Node leaveIfNode(final IfNode ifNode) {
    final Node test = ifNode.getTest();
    if (test instanceof LiteralNode.PrimitiveLiteralNode) {
        final boolean isTrue = ((LiteralNode.PrimitiveLiteralNode<?>)test).isTrue();
        final Block executed = isTrue ? ifNode.getPass() : ifNode.getFail();
        final Block dropped  = isTrue ? ifNode.getFail() : ifNode.getPass();
        final List<Statement> statements = new ArrayList<>();

        if (executed != null) {
            statements.addAll(executed.getStatements()); // Get statements form executed branch
        }
        if (dropped != null) {
            extractVarNodes(dropped, statements); // Get var-nodes from non-executed branch
        }
        if (statements.isEmpty()) {
            return new EmptyNode(ifNode);
        }
        return BlockStatement.createReplacement(ifNode, ifNode.getFinish(), statements);
    }
    return ifNode;
}
项目:openjdk-jdk10    文件:IRTranslator.java   
private boolean handleBlock(final Block block, final boolean sortStats) {
    // FIXME: revisit this!
    if (block.isSynthetic()) {
        final int statCount = block.getStatementCount();
        switch (statCount) {
            case 0: {
                final EmptyNode emptyNode = new EmptyNode(-1, block.getToken(), block.getFinish());
                curStat = new EmptyStatementTreeImpl(emptyNode);
                return false;
            }
            case 1: {
                curStat = translateStat(block.getStatements().get(0));
                return false;
            }
            default: {
                // fall through
                break;
            }
        }
    }

    final List<? extends Statement> stats = block.getStatements();
    curStat = new BlockTreeImpl(block,
        translateStats(sortStats? getOrderedStatements(stats) : stats));
    return false;
}
项目:openjdk-jdk10    文件:Parser.java   
private void markEvalInArrowParameterList(final ParserContextBlockNode parameterBlock) {
    final Iterator<ParserContextFunctionNode> iter = lc.getFunctions();
    final ParserContextFunctionNode current = iter.next();
    final ParserContextFunctionNode parent = iter.next();

    if (parent.getFlag(FunctionNode.HAS_EVAL) != 0) {
        // we might have flagged has-eval in the parent function during parsing the parameter list,
        // if the parameter list contains eval; must tag arrow function as has-eval.
        for (final Statement st : parameterBlock.getStatements()) {
            st.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
                @Override
                public boolean enterCallNode(final CallNode callNode) {
                    if (callNode.getFunction() instanceof IdentNode && ((IdentNode) callNode.getFunction()).getName().equals("eval")) {
                        current.setFlag(FunctionNode.HAS_EVAL);
                    }
                    return true;
                }
            });
        }
        // TODO: function containing the arrow function should not be flagged has-eval
    }
}
项目:openjdk-jdk10    文件:JSONWriter.java   
private boolean emitProgram(final FunctionNode functionNode) {
    enterDefault(functionNode);
    type("Program");
    comma();

    // body consists of nested functions and statements
    final List<Statement> stats = functionNode.getBody().getStatements();
    final int size = stats.size();
    int idx = 0;
    arrayStart("body");

    for (final Node stat : stats) {
        stat.accept(this);
        if (idx != (size - 1)) {
            comma();
        }
        idx++;
    }
    arrayEnd();

    return leave();
}
项目:openjdk-jdk10    文件:FoldConstants.java   
@Override
public Node leaveIfNode(final IfNode ifNode) {
    final Node test = ifNode.getTest();
    if (test instanceof LiteralNode.PrimitiveLiteralNode) {
        final boolean isTrue = ((LiteralNode.PrimitiveLiteralNode<?>)test).isTrue();
        final Block executed = isTrue ? ifNode.getPass() : ifNode.getFail();
        final Block dropped  = isTrue ? ifNode.getFail() : ifNode.getPass();
        final List<Statement> statements = new ArrayList<>();

        if (executed != null) {
            statements.addAll(executed.getStatements()); // Get statements form executed branch
        }
        if (dropped != null) {
            extractVarNodesFromDeadCode(dropped, statements); // Get var-nodes from non-executed branch
        }
        if (statements.isEmpty()) {
            return new EmptyNode(ifNode);
        }
        return BlockStatement.createReplacement(ifNode, ifNode.getFinish(), statements);
    }
    return ifNode;
}
项目:openjdk-jdk10    文件:FoldConstants.java   
/**
 * When we eliminate dead code, we must preserve var declarations as they are scoped to the whole
 * function. This method gathers var nodes from code passed to it, removing their initializers.
 *
 * @param deadCodeRoot the root node of eliminated dead code
 * @param statements a list that will be receiving the var nodes from the dead code, with their
 * initializers removed.
 */
static void extractVarNodesFromDeadCode(final Node deadCodeRoot, final List<Statement> statements) {
    deadCodeRoot.accept(new SimpleNodeVisitor() {
        @Override
        public boolean enterVarNode(final VarNode varNode) {
            statements.add(varNode.setInit(null));
            return false;
        }

        @Override
        public boolean enterFunctionNode(final FunctionNode functionNode) {
            // Don't descend into nested functions
            return false;
        }
    });
}
项目:openjdk9    文件:IRTranslator.java   
private boolean handleBlock(final Block block, final boolean sortStats) {
    // FIXME: revisit this!
    if (block.isSynthetic()) {
        final int statCount = block.getStatementCount();
        switch (statCount) {
            case 0: {
                final EmptyNode emptyNode = new EmptyNode(-1, block.getToken(), block.getFinish());
                curStat = new EmptyStatementTreeImpl(emptyNode);
                return false;
            }
            case 1: {
                curStat = translateStat(block.getStatements().get(0));
                return false;
            }
            default: {
                // fall through
                break;
            }
        }
    }

    final List<? extends Statement> stats = block.getStatements();
    curStat = new BlockTreeImpl(block,
        translateStats(sortStats? getOrderedStatements(stats) : stats));
    return false;
}
项目:openjdk9    文件:Parser.java   
private void markEvalInArrowParameterList(final ParserContextBlockNode parameterBlock) {
    final Iterator<ParserContextFunctionNode> iter = lc.getFunctions();
    final ParserContextFunctionNode current = iter.next();
    final ParserContextFunctionNode parent = iter.next();

    if (parent.getFlag(FunctionNode.HAS_EVAL) != 0) {
        // we might have flagged has-eval in the parent function during parsing the parameter list,
        // if the parameter list contains eval; must tag arrow function as has-eval.
        for (final Statement st : parameterBlock.getStatements()) {
            st.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
                @Override
                public boolean enterCallNode(final CallNode callNode) {
                    if (callNode.getFunction() instanceof IdentNode && ((IdentNode) callNode.getFunction()).getName().equals("eval")) {
                        current.setFlag(FunctionNode.HAS_EVAL);
                    }
                    return true;
                }
            });
        }
        // TODO: function containing the arrow function should not be flagged has-eval
    }
}
项目:openjdk9    文件:JSONWriter.java   
private boolean emitProgram(final FunctionNode functionNode) {
    enterDefault(functionNode);
    type("Program");
    comma();

    // body consists of nested functions and statements
    final List<Statement> stats = functionNode.getBody().getStatements();
    final int size = stats.size();
    int idx = 0;
    arrayStart("body");

    for (final Node stat : stats) {
        stat.accept(this);
        if (idx != (size - 1)) {
            comma();
        }
        idx++;
    }
    arrayEnd();

    return leave();
}
项目:openjdk9    文件:FoldConstants.java   
@Override
public Node leaveIfNode(final IfNode ifNode) {
    final Node test = ifNode.getTest();
    if (test instanceof LiteralNode.PrimitiveLiteralNode) {
        final boolean isTrue = ((LiteralNode.PrimitiveLiteralNode<?>)test).isTrue();
        final Block executed = isTrue ? ifNode.getPass() : ifNode.getFail();
        final Block dropped  = isTrue ? ifNode.getFail() : ifNode.getPass();
        final List<Statement> statements = new ArrayList<>();

        if (executed != null) {
            statements.addAll(executed.getStatements()); // Get statements form executed branch
        }
        if (dropped != null) {
            extractVarNodesFromDeadCode(dropped, statements); // Get var-nodes from non-executed branch
        }
        if (statements.isEmpty()) {
            return new EmptyNode(ifNode);
        }
        return BlockStatement.createReplacement(ifNode, ifNode.getFinish(), statements);
    }
    return ifNode;
}
项目:openjdk9    文件:FoldConstants.java   
/**
 * When we eliminate dead code, we must preserve var declarations as they are scoped to the whole
 * function. This method gathers var nodes from code passed to it, removing their initializers.
 *
 * @param deadCodeRoot the root node of eliminated dead code
 * @param statements a list that will be receiving the var nodes from the dead code, with their
 * initializers removed.
 */
static void extractVarNodesFromDeadCode(final Node deadCodeRoot, final List<Statement> statements) {
    deadCodeRoot.accept(new SimpleNodeVisitor() {
        @Override
        public boolean enterVarNode(final VarNode varNode) {
            statements.add(varNode.setInit(null));
            return false;
        }

        @Override
        public boolean enterFunctionNode(final FunctionNode functionNode) {
            // Don't descend into nested functions
            return false;
        }
    });
}
项目:kaziranga    文件:JSONWriter.java   
private boolean emitProgram(final FunctionNode functionNode) {
    enterDefault(functionNode);
    type("Program");
    comma();

    // body consists of nested functions and statements
    final List<Statement> stats = functionNode.getBody().getStatements();
    final int size = stats.size();
    int idx = 0;
    arrayStart("body");

    for (final Node stat : stats) {
        stat.accept(this);
        if (idx != (size - 1)) {
            comma();
        }
        idx++;
    }
    arrayEnd();

    return leave();
}
项目:kaziranga    文件:FoldConstants.java   
@Override
public Node leaveIfNode(final IfNode ifNode) {
    final Node test = ifNode.getTest();
    if (test instanceof LiteralNode.PrimitiveLiteralNode) {
        final boolean isTrue = ((LiteralNode.PrimitiveLiteralNode<?>)test).isTrue();
        final Block executed = isTrue ? ifNode.getPass() : ifNode.getFail();
        final Block dropped  = isTrue ? ifNode.getFail() : ifNode.getPass();
        final List<Statement> statements = new ArrayList<>();

        if (executed != null) {
            statements.addAll(executed.getStatements()); // Get statements form executed branch
        }
        if (dropped != null) {
            extractVarNodes(dropped, statements); // Get var-nodes from non-executed branch
        }
        if (statements.isEmpty()) {
            return new EmptyNode(ifNode);
        }
        return BlockStatement.createReplacement(ifNode, ifNode.getFinish(), statements);
    }
    return ifNode;
}
项目:lookaside_java-1.8.0-openjdk    文件:JSONWriter.java   
private boolean emitProgram(final FunctionNode functionNode) {
    enterDefault(functionNode);
    type("Program");
    comma();

    // body consists of nested functions and statements
    final List<Statement> stats = functionNode.getBody().getStatements();
    final int size = stats.size();
    int idx = 0;
    arrayStart("body");

    for (final Node stat : stats) {
        stat.accept(this);
        if (idx != (size - 1)) {
            comma();
        }
        idx++;
    }
    arrayEnd();

    return leave();
}
项目:lookaside_java-1.8.0-openjdk    文件:FoldConstants.java   
@Override
public Node leaveIfNode(final IfNode ifNode) {
    final Node test = ifNode.getTest();
    if (test instanceof LiteralNode.PrimitiveLiteralNode) {
        final boolean isTrue = ((LiteralNode.PrimitiveLiteralNode<?>)test).isTrue();
        final Block executed = isTrue ? ifNode.getPass() : ifNode.getFail();
        final Block dropped  = isTrue ? ifNode.getFail() : ifNode.getPass();
        final List<Statement> statements = new ArrayList<>();

        if (executed != null) {
            statements.addAll(executed.getStatements()); // Get statements form executed branch
        }
        if (dropped != null) {
            extractVarNodesFromDeadCode(dropped, statements); // Get var-nodes from non-executed branch
        }
        if (statements.isEmpty()) {
            return new EmptyNode(ifNode);
        }
        return BlockStatement.createReplacement(ifNode, ifNode.getFinish(), statements);
    }
    return ifNode;
}
项目:lookaside_java-1.8.0-openjdk    文件:FoldConstants.java   
/**
 * When we eliminate dead code, we must preserve var declarations as they are scoped to the whole
 * function. This method gathers var nodes from code passed to it, removing their initializers.
 *
 * @param deadCodeRoot the root node of eliminated dead code
 * @param statements a list that will be receiving the var nodes from the dead code, with their
 * initializers removed.
 */
static void extractVarNodesFromDeadCode(final Node deadCodeRoot, final List<Statement> statements) {
    deadCodeRoot.accept(new SimpleNodeVisitor() {
        @Override
        public boolean enterVarNode(final VarNode varNode) {
            statements.add(varNode.setInit(null));
            return false;
        }

        @Override
        public boolean enterFunctionNode(final FunctionNode functionNode) {
            // Don't descend into nested functions
            return false;
        }
    });
}
项目:jdk8u_nashorn    文件:JSONWriter.java   
private boolean emitProgram(final FunctionNode functionNode) {
    enterDefault(functionNode);
    type("Program");
    comma();

    // body consists of nested functions and statements
    final List<Statement> stats = functionNode.getBody().getStatements();
    final int size = stats.size();
    int idx = 0;
    arrayStart("body");

    for (final Node stat : stats) {
        stat.accept(this);
        if (idx != (size - 1)) {
            comma();
        }
        idx++;
    }
    arrayEnd();

    return leave();
}
项目:jdk8u_nashorn    文件:FoldConstants.java   
@Override
public Node leaveIfNode(final IfNode ifNode) {
    final Node test = ifNode.getTest();
    if (test instanceof LiteralNode.PrimitiveLiteralNode) {
        final boolean isTrue = ((LiteralNode.PrimitiveLiteralNode<?>)test).isTrue();
        final Block executed = isTrue ? ifNode.getPass() : ifNode.getFail();
        final Block dropped  = isTrue ? ifNode.getFail() : ifNode.getPass();
        final List<Statement> statements = new ArrayList<>();

        if (executed != null) {
            statements.addAll(executed.getStatements()); // Get statements form executed branch
        }
        if (dropped != null) {
            extractVarNodesFromDeadCode(dropped, statements); // Get var-nodes from non-executed branch
        }
        if (statements.isEmpty()) {
            return new EmptyNode(ifNode);
        }
        return BlockStatement.createReplacement(ifNode, ifNode.getFinish(), statements);
    }
    return ifNode;
}
项目:jdk8u_nashorn    文件:FoldConstants.java   
/**
 * When we eliminate dead code, we must preserve var declarations as they are scoped to the whole
 * function. This method gathers var nodes from code passed to it, removing their initializers.
 *
 * @param deadCodeRoot the root node of eliminated dead code
 * @param statements a list that will be receiving the var nodes from the dead code, with their
 * initializers removed.
 */
static void extractVarNodesFromDeadCode(final Node deadCodeRoot, final List<Statement> statements) {
    deadCodeRoot.accept(new SimpleNodeVisitor() {
        @Override
        public boolean enterVarNode(final VarNode varNode) {
            statements.add(varNode.setInit(null));
            return false;
        }

        @Override
        public boolean enterFunctionNode(final FunctionNode functionNode) {
            // Don't descend into nested functions
            return false;
        }
    });
}
项目:orbis-lps2ima-dev    文件:DatabaseRequest.java   
public final void insert(String table, String[] parameters){
  try {
       Statement select = ds.createStatement();
       select.executeUpdate(" ");
  } catch (SQLException sqle) { 
   System.out.println("Erreur : "+sqle.getMessage());
  }
}
项目:orbis-lps2ima-dev    文件:DatabaseRequest.java   
public void remove(String table, String idName, String idValue){
   try {
       Statement select = ds.createStatement();
       select.executeUpdate("delete from "+table+" where id_name = "+idName+" and id_value = "+idValue);
   } catch (SQLException sqle) { 
    System.out.println("Erreur : "+sqle.getMessage());
   }
}
项目:orbis-lps2ima-dev    文件:DatabaseRequest.java   
public void update(String table, HashMap<Integer, Integer> parameters){
   try {
       Statement select = ds.createStatement();
       select.executeUpdate(" ");
   } catch (SQLException sqle) {  
    System.out.println("Erreur : "+sqle.getMessage());
   }
}
项目:OpenJSharp    文件:Parser.java   
private void addFunctionDeclarations(final FunctionNode functionNode) {
    VarNode lastDecl = null;
    for (int i = functionDeclarations.size() - 1; i >= 0; i--) {
        Statement decl = functionDeclarations.get(i);
        if (lastDecl == null && decl instanceof VarNode) {
            decl = lastDecl = ((VarNode)decl).setFlag(VarNode.IS_LAST_FUNCTION_DECLARATION);
            lc.setFlag(functionNode, FunctionNode.HAS_FUNCTION_DECLARATIONS);
        }
        prependStatement(decl);
    }
}
项目:OpenJSharp    文件:AssignSymbols.java   
private FunctionNode createSyntheticInitializers(final FunctionNode functionNode) {
    final List<VarNode> syntheticInitializers = new ArrayList<>(2);

    // Must visit the new var nodes in the context of the body. We could also just set the new statements into the
    // block and then revisit the entire block, but that seems to be too much double work.
    final Block body = functionNode.getBody();
    lc.push(body);
    try {
        if (functionNode.usesSelfSymbol()) {
            // "var fn = :callee"
            syntheticInitializers.add(createSyntheticInitializer(functionNode.getIdent(), CALLEE, functionNode));
        }

        if (functionNode.needsArguments()) {
            // "var arguments = :arguments"
            syntheticInitializers.add(createSyntheticInitializer(createImplicitIdentifier(ARGUMENTS_VAR.symbolName()),
                    ARGUMENTS, functionNode));
        }

        if (syntheticInitializers.isEmpty()) {
            return functionNode;
        }

        for(final ListIterator<VarNode> it = syntheticInitializers.listIterator(); it.hasNext();) {
            it.set((VarNode)it.next().accept(this));
        }
    } finally {
        lc.pop(body);
    }

    final List<Statement> stmts = body.getStatements();
    final List<Statement> newStatements = new ArrayList<>(stmts.size() + syntheticInitializers.size());
    newStatements.addAll(syntheticInitializers);
    newStatements.addAll(stmts);
    return functionNode.setBody(lc, body.setStatements(lc, newStatements));
}
项目:OpenJSharp    文件:FoldConstants.java   
private static void extractVarNodes(final Block block, final List<Statement> statements) {
    final LexicalContext lc = new LexicalContext();
    block.accept(lc, new NodeVisitor<LexicalContext>(lc) {
        @Override
        public boolean enterVarNode(final VarNode varNode) {
            statements.add(varNode.setInit(null));
            return false;
        }
    });
}
项目:OpenJSharp    文件:Lower.java   
private static List<Statement> copyFinally(final Block finallyBody) {
    final List<Statement> newStatements = new ArrayList<>();
    for (final Statement statement : finallyBody.getStatements()) {
        newStatements.add((Statement)ensureUniqueNamesIn(statement));
        if (statement.hasTerminalFlags()) {
            return newStatements;
        }
    }
    return newStatements;
}
项目:OpenJSharp    文件:Lower.java   
private void addStatementEnclosedInBlock(final Statement stmt) {
    BlockStatement b = BlockStatement.createReplacement(stmt, Collections.<Statement>singletonList(stmt));
    if(stmt.isTerminal()) {
        b = b.setBlock(b.getBlock().setIsTerminal(null, true));
    }
    addStatement(b);
}
项目:OpenJSharp    文件:AstSerializer.java   
private static FunctionNode removeInnerFunctionBodies(final FunctionNode fn) {
    return (FunctionNode)fn.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
        @Override
        public Node leaveBlock(final Block block) {
            if (lc.isFunctionBody() && lc.getFunction(block) != lc.getOutermostFunction()) {
                return block.setStatements(lc, Collections.<Statement>emptyList());
            }
            return super.leaveBlock(block);
        }
    });
}
项目:OpenJSharp    文件:Splitter.java   
/**
 * Split a block into sub methods.
 *
 * @param block Block or function to split.
 *
 * @return new weight for the resulting block.
 */
private Block splitBlock(final Block block, final FunctionNode function) {

    final List<Statement> splits = new ArrayList<>();
    List<Statement> statements = new ArrayList<>();
    long statementsWeight = 0;

    for (final Statement statement : block.getStatements()) {
        final long weight = WeighNodes.weigh(statement, weightCache);

        if (statementsWeight + weight >= SPLIT_THRESHOLD || statement.isTerminal()) {
            if (!statements.isEmpty()) {
                splits.add(createBlockSplitNode(block, function, statements, statementsWeight));
                statements = new ArrayList<>();
                statementsWeight = 0;
            }
        }

        if (statement.isTerminal()) {
            splits.add(statement);
        } else {
            statements.add(statement);
            statementsWeight += weight;
        }
    }

    if (!statements.isEmpty()) {
        splits.add(createBlockSplitNode(block, function, statements, statementsWeight));
    }

    return block.setStatements(lc, splits);
}
项目:OpenJSharp    文件:Splitter.java   
/**
 * Create a new split node from statements contained in a parent block.
 *
 * @param parent     Parent block.
 * @param statements Statements to include.
 *
 * @return New split node.
 */
private SplitNode createBlockSplitNode(final Block parent, final FunctionNode function, final List<Statement> statements, final long weight) {
    final long   token      = parent.getToken();
    final int    finish     = parent.getFinish();
    final String name       = function.uniqueName(SPLIT_PREFIX.symbolName());

    final Block newBlock = new Block(token, finish, statements);

    return new SplitNode(name, newBlock, compiler.findUnit(weight + WeighNodes.FUNCTION_WEIGHT));
}
项目:OpenJSharp    文件:SplitIntoFunctions.java   
@Override
protected Node leaveDefault(final Node node) {
    if (node instanceof Statement) {
        appendStatement((Statement)node);
    }
    return node;
}
项目:OpenJSharp    文件:SplitIntoFunctions.java   
private static IfNode makeIfStateEquals(final int lineNumber, final long token, final int finish,
        final int value, final Block pass, final Statement fail) {
    return new IfNode(lineNumber, token, finish,
            new BinaryNode(Token.recast(token, TokenType.EQ_STRICT),
                    GetSplitState.INSTANCE, intLiteral(value)),
            pass,
            fail == null ? null : new Block(NO_TOKEN, NO_FINISH, fail));
}
项目:OpenJSharp    文件:LocalVariableTypesCalculator.java   
private void createSyntheticReturn(final Block body) {
    final FunctionNode functionNode = lc.getCurrentFunction();
    final long token = functionNode.getToken();
    final int finish = functionNode.getFinish();
    final List<Statement> statements = body.getStatements();
    final int lineNumber = statements.isEmpty() ? functionNode.getLineNumber() : statements.get(statements.size() - 1).getLineNumber();
    final IdentNode returnExpr;
    if(functionNode.isProgram()) {
        returnExpr = new IdentNode(token, finish, RETURN.symbolName()).setSymbol(getCompilerConstantSymbol(functionNode, RETURN));
    } else {
        returnExpr = null;
    }
    syntheticReturn = new ReturnNode(lineNumber, token, finish, returnExpr);
    syntheticReturn.accept(this);
}
项目:openjdk-jdk10    文件:IRTranslator.java   
private List<? extends StatementTree> translateStats(final List<? extends Statement> stats) {
    if (stats == null) {
        return null;
    }
    final List<StatementTreeImpl> statTrees = new ArrayList<>(stats.size());
    for (final Statement stat : stats) {
        curStat = null;
        stat.accept(this);
        assert curStat != null;
        statTrees.add(curStat);
    }
    return statTrees;
}
项目:openjdk-jdk10    文件:IRTranslator.java   
private StatementTreeImpl translateStat(final Statement stat) {
    if (stat == null) {
        return null;
    }

    curStat = null;
    stat.accept(this);
    assert curStat != null : "null for " + stat;
    return curStat;
}
项目:openjdk-jdk10    文件:ParserContext.java   
/**
 * The last statement added to the context
 * @return The last statement added to the context
 */
public Statement getLastStatement() {
    if (sp == 0) {
        return null;
    }
    final ParserContextNode top = stack[sp - 1];
    final int s = top.getStatements().size();
    return s == 0 ? null : top.getStatements().get(s - 1);
}
项目:openjdk-jdk10    文件:Parser.java   
private void addFunctionDeclarations(final ParserContextFunctionNode functionNode) {
    VarNode lastDecl = null;
    for (int i = functionDeclarations.size() - 1; i >= 0; i--) {
        Statement decl = functionDeclarations.get(i);
        if (lastDecl == null && decl instanceof VarNode) {
            decl = lastDecl = ((VarNode)decl).setFlag(VarNode.IS_LAST_FUNCTION_DECLARATION);
            functionNode.setFlag(FunctionNode.HAS_FUNCTION_DECLARATIONS);
        }
        prependStatement(decl);
    }
}
项目:openjdk-jdk10    文件:AssignSymbols.java   
private FunctionNode createSyntheticInitializers(final FunctionNode functionNode) {
    final List<VarNode> syntheticInitializers = new ArrayList<>(2);

    // Must visit the new var nodes in the context of the body. We could also just set the new statements into the
    // block and then revisit the entire block, but that seems to be too much double work.
    final Block body = functionNode.getBody();
    lc.push(body);
    try {
        if (functionNode.usesSelfSymbol()) {
            // "var fn = :callee"
            syntheticInitializers.add(createSyntheticInitializer(functionNode.getIdent(), CALLEE, functionNode));
        }

        if (functionNode.needsArguments()) {
            // "var arguments = :arguments"
            syntheticInitializers.add(createSyntheticInitializer(createImplicitIdentifier(ARGUMENTS_VAR.symbolName()),
                    ARGUMENTS, functionNode));
        }

        if (syntheticInitializers.isEmpty()) {
            return functionNode;
        }

        for(final ListIterator<VarNode> it = syntheticInitializers.listIterator(); it.hasNext();) {
            it.set((VarNode)it.next().accept(this));
        }
    } finally {
        lc.pop(body);
    }

    final List<Statement> stmts = body.getStatements();
    final List<Statement> newStatements = new ArrayList<>(stmts.size() + syntheticInitializers.size());
    newStatements.addAll(syntheticInitializers);
    newStatements.addAll(stmts);
    return functionNode.setBody(lc, body.setStatements(lc, newStatements));
}
项目:openjdk-jdk10    文件:Lower.java   
private static Block createFinallyBlock(final Block finallyBody) {
    final List<Statement> newStatements = new ArrayList<>();
    for (final Statement statement : finallyBody.getStatements()) {
        newStatements.add(statement);
        if (statement.hasTerminalFlags()) {
            break;
        }
    }
    return finallyBody.setStatements(null, newStatements);
}