本文整理汇总了Java中jdk.nashorn.internal.ir.VarNode类的典型用法代码示例。如果您正苦于以下问题:Java VarNode类的具体用法?Java VarNode怎么用?Java VarNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
VarNode类属于jdk.nashorn.internal.ir包,在下文中一共展示了VarNode类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: enterVarNode
import jdk.nashorn.internal.ir.VarNode; //导入依赖的package包/类
@Override
public boolean enterVarNode(VarNode varNode) {
if (!inSplitNode()) {
return super.enterVarNode(varNode);
}
assert !varNode.isBlockScoped(); //TODO: we must handle these too, but we currently don't
final Expression init = varNode.getInit();
if (varNode.isAnonymousFunctionDeclaration()) {
// We ain't moving anonymous function declarations.
return super.enterVarNode(varNode);
}
// Move a declaration-only var statement to the top of the outermost function.
getCurrentFunctionState().varStatements.add(varNode.setInit(null));
// If it had an initializer, replace it with an assignment expression statement. Note that "var" is a
// statement, so it doesn't contribute to :return of the programs, therefore we are _not_ adding a
// ":return = ..." assignment around the original assignment.
if (init != null) {
final long token = Token.recast(varNode.getToken(), TokenType.ASSIGN);
new ExpressionStatement(varNode.getLineNumber(), token, varNode.getFinish(),
new BinaryNode(token, varNode.getName(), varNode.getInit())).accept(this);
}
return false;
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:27,代码来源:SplitIntoFunctions.java
示例2: enterVarNode
import jdk.nashorn.internal.ir.VarNode; //导入依赖的package包/类
@Override
public boolean enterVarNode(final VarNode varNode) {
final Expression initNode = varNode.getInit();
if (initNode instanceof FunctionNode && ((FunctionNode)initNode).isDeclared()) {
final FunctionNode funcNode = (FunctionNode) initNode;
final List<? extends ExpressionTree> paramTrees = translateParameters(funcNode);
final BlockTree blockTree = (BlockTree) translateBlock(funcNode.getBody(), true);
curStat = new FunctionDeclarationTreeImpl(varNode, paramTrees, blockTree);
} else if (initNode instanceof ClassNode && ((ClassNode)initNode).isStatement()) {
final ClassNode classNode = (ClassNode) initNode;
curStat = new ClassDeclarationTreeImpl(varNode,
translateIdent(classNode.getIdent()),
translateExpr(classNode.getClassHeritage()),
translateProperty(classNode.getConstructor()),
translateProperties(classNode.getClassElements()));
} else {
curStat = new VariableTreeImpl(varNode, translateIdent(varNode.getName()), translateExpr(initNode));
}
return false;
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:IRTranslator.java
示例3: verifyDestructuringParameterBindingPattern
import jdk.nashorn.internal.ir.VarNode; //导入依赖的package包/类
private void verifyDestructuringParameterBindingPattern(final Expression pattern, final long paramToken, final int paramLine, final String contextString) {
verifyDestructuringBindingPattern(pattern, new Consumer<IdentNode>() {
public void accept(final IdentNode identNode) {
verifyIdent(identNode, contextString);
final ParserContextFunctionNode currentFunction = lc.getCurrentFunction();
if (currentFunction != null) {
// declare function-scope variables for destructuring bindings
if (!env._parse_only) {
lc.getFunctionBody(currentFunction).appendStatement(new VarNode(paramLine, Token.recast(paramToken, VAR), pattern.getFinish(), identNode, null));
}
// detect duplicate bounds names in parameter list
currentFunction.addParameterBinding(identNode);
currentFunction.setSimpleParameterList(false);
}
}
});
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:Parser.java
示例4: extractVarNodesFromDeadCode
import jdk.nashorn.internal.ir.VarNode; //导入依赖的package包/类
/**
* 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;
}
});
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:FoldConstants.java
示例5: enterVarNode
import jdk.nashorn.internal.ir.VarNode; //导入依赖的package包/类
@Override
public boolean enterVarNode(final VarNode varNode) {
if (!inSplitNode()) {
return super.enterVarNode(varNode);
}
assert !varNode.isBlockScoped(); //TODO: we must handle these too, but we currently don't
final Expression init = varNode.getInit();
// Move a declaration-only var statement to the top of the outermost function.
getCurrentFunctionState().varStatements.add(varNode.setInit(null));
// If it had an initializer, replace it with an assignment expression statement. Note that "var" is a
// statement, so it doesn't contribute to :return of the programs, therefore we are _not_ adding a
// ":return = ..." assignment around the original assignment.
if (init != null) {
final long token = Token.recast(varNode.getToken(), TokenType.ASSIGN);
new ExpressionStatement(varNode.getLineNumber(), token, varNode.getFinish(),
new BinaryNode(token, varNode.getName(), varNode.getInit())).accept(this);
}
return false;
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:SplitIntoFunctions.java
示例6: enterVarNode
import jdk.nashorn.internal.ir.VarNode; //导入依赖的package包/类
@Override
public boolean enterVarNode(final VarNode varNode) {
final Expression initNode = varNode.getInit();
if (initNode instanceof FunctionNode && ((FunctionNode)initNode).isDeclared()) {
final FunctionNode funcNode = (FunctionNode) initNode;
final List<? extends ExpressionTree> paramTrees
= translateExprs(funcNode.getParameters());
final BlockTree blockTree = (BlockTree) translateBlock(funcNode.getBody(), true);
curStat = new FunctionDeclarationTreeImpl(varNode, paramTrees, blockTree);
} else {
curStat = new VariableTreeImpl(varNode, translateExpr(initNode));
}
return false;
}
开发者ID:campolake,项目名称:openjdk9,代码行数:17,代码来源:IRTranslator.java
示例7: verifyDestructuringParameterBindingPattern
import jdk.nashorn.internal.ir.VarNode; //导入依赖的package包/类
private void verifyDestructuringParameterBindingPattern(final Expression pattern, final long paramToken, final int paramLine, final String contextString) {
verifyDestructuringBindingPattern(pattern, new Consumer<IdentNode>() {
public void accept(IdentNode identNode) {
verifyIdent(identNode, contextString);
ParserContextFunctionNode currentFunction = lc.getCurrentFunction();
if (currentFunction != null) {
// declare function-scope variables for destructuring bindings
lc.getFunctionBody(currentFunction).appendStatement(new VarNode(paramLine, Token.recast(paramToken, VAR), pattern.getFinish(), identNode, null));
// detect duplicate bounds names in parameter list
currentFunction.addParameterBinding(identNode);
currentFunction.setSimpleParameterList(false);
}
}
});
}
开发者ID:campolake,项目名称:openjdk9,代码行数:17,代码来源:Parser.java
示例8: enterVarNode
import jdk.nashorn.internal.ir.VarNode; //导入依赖的package包/类
@Override
public boolean enterVarNode(final VarNode varNode) {
if (!inSplitNode()) {
return super.enterVarNode(varNode);
}
assert !varNode.isBlockScoped(); //TODO: we must handle these too, but we currently don't
final Expression init = varNode.getInit();
if (varNode.isAnonymousFunctionDeclaration()) {
// We ain't moving anonymous function declarations.
return super.enterVarNode(varNode);
}
// Move a declaration-only var statement to the top of the outermost function.
getCurrentFunctionState().varStatements.add(varNode.setInit(null));
// If it had an initializer, replace it with an assignment expression statement. Note that "var" is a
// statement, so it doesn't contribute to :return of the programs, therefore we are _not_ adding a
// ":return = ..." assignment around the original assignment.
if (init != null) {
final long token = Token.recast(varNode.getToken(), TokenType.ASSIGN);
new ExpressionStatement(varNode.getLineNumber(), token, varNode.getFinish(),
new BinaryNode(token, varNode.getName(), varNode.getInit())).accept(this);
}
return false;
}
开发者ID:malaporte,项目名称:kaziranga,代码行数:27,代码来源:SplitIntoFunctions.java
示例9: enterVarNode
import jdk.nashorn.internal.ir.VarNode; //导入依赖的package包/类
@Override
public boolean enterVarNode(final VarNode varNode) {
start(varNode);
final IdentNode ident = varNode.getName();
final String name = ident.getName();
final Symbol symbol = defineSymbol(lc.getCurrentBlock(), name, IS_VAR);
assert symbol != null;
// NASHORN-467 - use before definition of vars - conservative
if (isLocalUse(ident.getName())) {
newType(symbol, Type.OBJECT);
symbol.setCanBeUndefined();
}
return true;
}
开发者ID:RedlineResearch,项目名称:OLD-OpenJDK8,代码行数:19,代码来源:Attr.java
示例10: leaveVarNode
import jdk.nashorn.internal.ir.VarNode; //导入依赖的package包/类
@Override
public Node leaveVarNode(final VarNode varNode) {
final Expression init = varNode.getInit();
if (init != null) {
final SpecializedNode specialized = specialize(varNode);
final VarNode specVarNode = (VarNode)specialized.node;
Type destType = specialized.type;
if (destType == null) {
destType = specVarNode.getName().getType();
}
assert specVarNode.getName().hasType() : specVarNode + " doesn't have a type";
final Expression convertedInit = convert(init, destType);
temporarySymbols.reuse();
return specVarNode.setInit(convertedInit);
}
temporarySymbols.reuse();
return varNode;
}
开发者ID:wro4j,项目名称:nashorn-backport,代码行数:19,代码来源:FinalizeTypes.java
示例11: addFunctionDeclarations
import jdk.nashorn.internal.ir.VarNode; //导入依赖的package包/类
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);
}
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:12,代码来源:Parser.java
示例12: enterVarNode
import jdk.nashorn.internal.ir.VarNode; //导入依赖的package包/类
@Override
public boolean enterVarNode(final VarNode varNode) {
sb.append("var ");
varNode.getName().toString(sb, printTypes);
printLocalVariableConversion(varNode.getName());
final Node init = varNode.getInit();
if (init != null) {
sb.append(" = ");
init.accept(this);
}
return false;
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:14,代码来源:PrintVisitor.java
示例13: acceptDeclarations
import jdk.nashorn.internal.ir.VarNode; //导入依赖的package包/类
/**
* Define symbols for all variable declarations at the top of the function scope. This way we can get around
* problems like
*
* while (true) {
* break;
* if (true) {
* var s;
* }
* }
*
* to an arbitrary nesting depth.
*
* see NASHORN-73
*
* @param functionNode the FunctionNode we are entering
* @param body the body of the FunctionNode we are entering
*/
private void acceptDeclarations(final FunctionNode functionNode, final Block body) {
// This visitor will assign symbol to all declared variables.
body.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
@Override
protected boolean enterDefault(final Node node) {
// Don't bother visiting expressions; var is a statement, it can't be inside an expression.
// This will also prevent visiting nested functions (as FunctionNode is an expression).
return !(node instanceof Expression);
}
@Override
public Node leaveVarNode(final VarNode varNode) {
final IdentNode ident = varNode.getName();
final boolean blockScoped = varNode.isBlockScoped();
if (blockScoped && lc.inUnprotectedSwitchContext()) {
throwUnprotectedSwitchError(varNode);
}
final Block block = blockScoped ? lc.getCurrentBlock() : body;
final Symbol symbol = defineSymbol(block, ident.getName(), ident, varNode.getSymbolFlags());
if (varNode.isFunctionDeclaration()) {
symbol.setIsFunctionDeclaration();
}
return varNode.setName(ident.setSymbol(symbol));
}
});
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:45,代码来源:AssignSymbols.java
示例14: createSyntheticInitializer
import jdk.nashorn.internal.ir.VarNode; //导入依赖的package包/类
/**
* Creates a synthetic initializer for a variable (a var statement that doesn't occur in the source code). Typically
* used to create assignmnent of {@code :callee} to the function name symbol in self-referential function
* expressions as well as for assignment of {@code :arguments} to {@code arguments}.
*
* @param name the ident node identifying the variable to initialize
* @param initConstant the compiler constant it is initialized to
* @param fn the function node the assignment is for
* @return a var node with the appropriate assignment
*/
private VarNode createSyntheticInitializer(final IdentNode name, final CompilerConstants initConstant, final FunctionNode fn) {
final IdentNode init = compilerConstantIdentifier(initConstant);
assert init.getSymbol() != null && init.getSymbol().isBytecodeLocal();
final VarNode synthVar = new VarNode(fn.getLineNumber(), fn.getToken(), fn.getFinish(), name, init);
final Symbol nameSymbol = fn.getBody().getExistingSymbol(name.getName());
assert nameSymbol != null;
return (VarNode)synthVar.setName(name.setSymbol(nameSymbol)).accept(this);
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:22,代码来源:AssignSymbols.java
示例15: createSyntheticInitializers
import jdk.nashorn.internal.ir.VarNode; //导入依赖的package包/类
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));
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:37,代码来源:AssignSymbols.java
示例16: enterVarNode
import jdk.nashorn.internal.ir.VarNode; //导入依赖的package包/类
@Override
public boolean enterVarNode(final VarNode varNode) {
start(varNode);
// Normally, a symbol assigned in a var statement is not live for its RHS. Since we also represent function
// declarations as VarNodes, they are exception to the rule, as they need to have the symbol visible to the
// body of the declared function for self-reference.
if (varNode.isFunctionDeclaration()) {
defineVarIdent(varNode);
}
return true;
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:12,代码来源:AssignSymbols.java
示例17: leaveVarNode
import jdk.nashorn.internal.ir.VarNode; //导入依赖的package包/类
@Override
public Node leaveVarNode(final VarNode varNode) {
if (!varNode.isFunctionDeclaration()) {
defineVarIdent(varNode);
}
return super.leaveVarNode(varNode);
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:8,代码来源:AssignSymbols.java
示例18: defineVarIdent
import jdk.nashorn.internal.ir.VarNode; //导入依赖的package包/类
private void defineVarIdent(final VarNode varNode) {
final IdentNode ident = varNode.getName();
final int flags;
if (varNode.isAnonymousFunctionDeclaration()) {
flags = IS_INTERNAL;
} else if (!varNode.isBlockScoped() && lc.getCurrentFunction().isProgram()) {
flags = IS_SCOPE;
} else {
flags = 0;
}
defineSymbol(lc.getCurrentBlock(), ident.getName(), ident, varNode.getSymbolFlags() | flags);
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:13,代码来源:AssignSymbols.java
示例19: throwUnprotectedSwitchError
import jdk.nashorn.internal.ir.VarNode; //导入依赖的package包/类
private void throwUnprotectedSwitchError(final VarNode varNode) {
// Block scoped declarations in switch statements without explicit blocks should be declared
// in a common block that contains all the case clauses. We cannot support this without a
// fundamental rewrite of how switch statements are handled (case nodes contain blocks and are
// directly contained by switch node). As a temporary solution we throw a reference error here.
final String msg = ECMAErrors.getMessage("syntax.error.unprotected.switch.declaration", varNode.isLet() ? "let" : "const");
throwParserException(msg, varNode);
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:9,代码来源:AssignSymbols.java
示例20: extractVarNodes
import jdk.nashorn.internal.ir.VarNode; //导入依赖的package包/类
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;
}
});
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:11,代码来源:FoldConstants.java
注:本文中的jdk.nashorn.internal.ir.VarNode类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论