jdk.nashorn.internal.ir.Node Java Examples
The following examples show how to use
jdk.nashorn.internal.ir.Node.
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: JSONWriter.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
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(); }
Example #2
Source File: AssignSymbols.java From jdk8u_nashorn with GNU General Public License v2.0 | 6 votes |
@Override public Node leaveFunctionNode(final FunctionNode functionNode) { final FunctionNode finalizedFunction; if (isUnparsedFunction(functionNode)) { finalizedFunction = functionNode; } else { finalizedFunction = markProgramBlock( removeUnusedSlots( createSyntheticInitializers( finalizeParameters( lc.applyTopFlags(functionNode)))) .setThisProperties(lc, thisProperties.pop().size())); } return finalizedFunction; }
Example #3
Source File: SplitIntoFunctions.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
@Override public Node leaveBlock(final Block block) { if (!artificialBlock) { if (lc.isFunctionBody()) { // Prepend declaration-only var statements to the top of the statement list. lc.prependStatements(getCurrentFunctionState().varStatements); } else if (lc.isSplitBody()) { appendSplitReturn(FALLTHROUGH_STATE, NO_LINE_NUMBER); if (getCurrentFunctionState().fn.isProgram()) { // If we're splitting the program, make sure every shard ends with "return :return" and // begins with ":return = :return-in;". lc.prependStatement(new ExpressionStatement(NO_LINE_NUMBER, NO_TOKEN, NO_FINISH, new BinaryNode(Token.toDesc(TokenType.ASSIGN, 0, 0), createReturnIdent(), createReturnParamIdent()))); } } } return block; }
Example #4
Source File: JSONWriter.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
@Override public boolean enterCaseNode(final CaseNode caseNode) { enterDefault(caseNode); type("SwitchCase"); comma(); final Node test = caseNode.getTest(); property("test"); if (test != null) { test.accept(this); } else { nullValue(); } comma(); array("consequent", caseNode.getBody().getStatements()); return leave(); }
Example #5
Source File: JSONWriter.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
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(); }
Example #6
Source File: FinalizeTypes.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
@Override public Node leaveForNode(final ForNode forNode) { if (forNode.isForIn()) { return forNode; } final Expression init = forNode.getInit(); final Expression test = forNode.getTest(); final Expression modify = forNode.getModify(); assert test != null || forNode.hasGoto() : "forNode " + forNode + " needs goto and is missing it in " + lc.getCurrentFunction(); return forNode. setInit(lc, init == null ? null : discard(init)). setModify(lc, modify == null ? null : discard(modify)); }
Example #7
Source File: JSONWriter.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
@Override public boolean enterIfNode(final IfNode ifNode) { enterDefault(ifNode); type("IfStatement"); comma(); property("test"); ifNode.getTest().accept(this); comma(); property("consequent"); ifNode.getPass().accept(this); final Node elsePart = ifNode.getFail(); comma(); property("alternate"); if (elsePart != null) { elsePart.accept(this); } else { nullValue(); } return leave(); }
Example #8
Source File: JSONWriter.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
@Override public boolean enterCatchNode(final CatchNode catchNode) { enterDefault(catchNode); type("CatchClause"); comma(); property("param"); catchNode.getException().accept(this); comma(); final Node guard = catchNode.getExceptionCondition(); if (guard != null) { property("guard"); guard.accept(this); comma(); } property("body"); catchNode.getBody().accept(this); return leave(); }
Example #9
Source File: CodeGeneratorLexicalContext.java From hottub with GNU General Public License v2.0 | 6 votes |
@Override public <T extends Node> T pop(final T node) { final T popped = super.pop(node); if (isWithBoundary(node)) { dynamicScopeCount--; assert dynamicScopeCount >= 0; } else if (node instanceof FunctionNode) { if (((FunctionNode)node).inDynamicContext()) { dynamicScopeCount--; assert dynamicScopeCount >= 0; } assert splitNodes.peek() == 0; splitNodes.pop(); } return popped; }
Example #10
Source File: Attr.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * Add is a special binary, as it works not only on arithmetic, but for * strings etc as well. */ @Override public Node leaveADD(final BinaryNode binaryNode) { final Expression lhs = binaryNode.lhs(); final Expression rhs = binaryNode.rhs(); ensureTypeNotUnknown(lhs); ensureTypeNotUnknown(rhs); //even if we are adding two known types, this can overflow. i.e. //int and number -> number. //int and int are also number though. //something and object is object return end(ensureSymbol(Type.widest(arithType(), Type.widest(lhs.getType(), rhs.getType())), binaryNode)); }
Example #11
Source File: AssignSymbols.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
private <T extends Node> T end(final T node, final boolean printNode) { if (debug) { final StringBuilder sb = new StringBuilder(); sb.append("[LEAVE "). append(name(node)). append("] "). append(printNode ? node.toString() : ""). append(" in '"). append(lc.getCurrentFunction().getName()). append('\''); if (node instanceof IdentNode) { final Symbol symbol = ((IdentNode)node).getSymbol(); if (symbol == null) { sb.append(" <NO SYMBOL>"); } else { sb.append(" <symbol=").append(symbol).append('>'); } } log.unindent(); log.info(sb); } return node; }
Example #12
Source File: ReplaceCompileUnits.java From hottub with GNU General Public License v2.0 | 5 votes |
@Override public Node leaveObjectNode(final ObjectNode objectNode) { final List<Splittable.SplitRange> ranges = objectNode.getSplitRanges(); if (ranges != null) { final List<Splittable.SplitRange> newRanges = new ArrayList<>(); for (final Splittable.SplitRange range : ranges) { newRanges.add(new Splittable.SplitRange(getExistingReplacement(range), range.getLow(), range.getHigh())); } return objectNode.setSplitRanges(lc, newRanges); } return super.leaveObjectNode(objectNode); }
Example #13
Source File: OptimisticTypesCalculator.java From jdk8u_nashorn with GNU General Public License v2.0 | 5 votes |
@Override protected Node leaveDefault(final Node node) { if(node instanceof Optimistic) { return leaveOptimistic((Optimistic)node); } return node; }
Example #14
Source File: Attr.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
@Override public Node leaveAccessNode(final AccessNode accessNode) { //While Object type is assigned here, Access Specialization in FinalizeTypes may narrow this, that //is why we can't set the access node base to be an object here, that will ruin access specialization //for example for a.x | 17. return end(ensureSymbol(Type.OBJECT, accessNode)); }
Example #15
Source File: Lower.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
@Override public Node leaveVarNode(final VarNode varNode) { addStatement(varNode); if (varNode.getFlag(VarNode.IS_LAST_FUNCTION_DECLARATION) && lc.getCurrentFunction().isProgram()) { new ExpressionStatement(varNode.getLineNumber(), varNode.getToken(), varNode.getFinish(), new IdentNode(varNode.getName())).accept(this); } return varNode; }
Example #16
Source File: SplitIntoFunctions.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override public Node leaveReturnNode(final ReturnNode returnNode) { if(inSplitNode()) { appendStatement(new SetSplitState(RETURN_STATE, returnNode.getLineNumber())); getCurrentSplitState().hasReturn = true; } appendStatement(returnNode); return returnNode; }
Example #17
Source File: CompilationPhase.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override FunctionNode transform(final Compiler compiler, final CompilationPhases phases, final FunctionNode fn) { final Set<CompileUnit> unitSet = CompileUnit.createCompileUnitSet(); final Map<CompileUnit, CompileUnit> unitMap = new HashMap<>(); // Ensure that the FunctionNode's compile unit is the first in the list of new units. Install phase // will use that as the root class. createCompileUnit(fn.getCompileUnit(), unitSet, unitMap, compiler, phases); final FunctionNode newFn = transformFunction(fn, new ReplaceCompileUnits() { @Override CompileUnit getReplacement(final CompileUnit oldUnit) { final CompileUnit existing = unitMap.get(oldUnit); if (existing != null) { return existing; } return createCompileUnit(oldUnit, unitSet, unitMap, compiler, phases); } @Override public Node leaveFunctionNode(final FunctionNode fn2) { return super.leaveFunctionNode( // restore flags for deserialized nested function nodes compiler.getScriptFunctionData(fn2.getId()).restoreFlags(lc, fn2)); }; }); compiler.replaceCompileUnits(unitSet); return newFn; }
Example #18
Source File: Attr.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
@Override public Node leaveASSIGN_ADD(final BinaryNode binaryNode) { final Expression lhs = binaryNode.lhs(); final Expression rhs = binaryNode.rhs(); final Type widest = Type.widest(lhs.getType(), rhs.getType()); //Type.NUMBER if we can't prove that the add doesn't overflow. todo return leaveSelfModifyingAssignmentNode(binaryNode, widest.isNumeric() ? Type.NUMBER : Type.OBJECT); }
Example #19
Source File: WeighNodes.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings("rawtypes") @Override public boolean enterLiteralNode(final LiteralNode literalNode) { weight += LITERAL_WEIGHT; if (literalNode instanceof ArrayLiteralNode) { final ArrayLiteralNode arrayLiteralNode = (ArrayLiteralNode)literalNode; final Node[] value = arrayLiteralNode.getValue(); final int[] postsets = arrayLiteralNode.getPostsets(); final List<ArrayUnit> units = arrayLiteralNode.getUnits(); if (units == null) { for (final int postset : postsets) { weight += AASTORE_WEIGHT; final Node element = value[postset]; if (element != null) { element.accept(this); } } } return false; } return true; }
Example #20
Source File: WeighNodes.java From nashorn with GNU General Public License v2.0 | 4 votes |
@Override public Node leaveDECINC(final UnaryNode unaryNode) { return unaryNodeWeight(unaryNode); }
Example #21
Source File: Lower.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
private Node addStatement(final Statement statement) { lc.appendStatement(statement); return statement; }
Example #22
Source File: Lower.java From jdk8u_nashorn with GNU General Public License v2.0 | 4 votes |
@Override public Node leaveFunctionNode(final FunctionNode functionNode) { log.info("END FunctionNode: ", functionNode.getName()); return functionNode; }
Example #23
Source File: AssignSymbols.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
private boolean start(final Node node) { return start(node, true); }
Example #24
Source File: FindScopeDepths.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
@Override public Node leaveFunctionNode(final FunctionNode functionNode) { final String name = functionNode.getName(); FunctionNode newFunctionNode = functionNode.setState(lc, CompilationState.SCOPE_DEPTHS_COMPUTED); if (compiler.isOnDemandCompilation()) { final RecompilableScriptFunctionData data = compiler.getScriptFunctionData(newFunctionNode.getId()); if (data.inDynamicContext()) { log.fine("Reviving scriptfunction ", quote(name), " as defined in previous (now lost) dynamic scope."); newFunctionNode = newFunctionNode.setInDynamicContext(lc); } return newFunctionNode; } if (inDynamicScope()) { log.fine("Tagging ", quote(name), " as defined in dynamic scope"); newFunctionNode = newFunctionNode.setInDynamicContext(lc); } //create recompilable scriptfunctiondata final int fnId = newFunctionNode.getId(); final Map<Integer, RecompilableScriptFunctionData> nestedFunctions = fnIdToNestedFunctions.remove(fnId); assert nestedFunctions != null; // Generate the object class and property map in case this function is ever used as constructor final RecompilableScriptFunctionData data = new RecompilableScriptFunctionData( newFunctionNode, compiler.getCodeInstaller(), ObjectClassGenerator.createAllocationStrategy(newFunctionNode.getThisProperties(), compiler.getContext().useDualFields()), nestedFunctions, externalSymbolDepths.get(fnId), internalSymbols.get(fnId), compiler.removeSerializedAst(fnId)); if (lc.getOutermostFunction() != newFunctionNode) { final FunctionNode parentFn = lc.getParentFunction(newFunctionNode); if (parentFn != null) { fnIdToNestedFunctions.get(parentFn.getId()).put(fnId, data); } } else { compiler.setData(data); } if (isDynamicScopeBoundary(functionNode)) { decreaseDynamicScopeCount(functionNode); } return newFunctionNode; }
Example #25
Source File: Attr.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
@Override public Node leaveObjectNode(final ObjectNode objectNode) { return end(ensureSymbol(Type.OBJECT, objectNode)); }
Example #26
Source File: CodeGeneratorLexicalContext.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
Node getCurrentDiscard() { return discard.peek(); }
Example #27
Source File: WeighNodes.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
@Override public Node leaveASSIGN_SUB(final BinaryNode binaryNode) { return binaryNodeWeight(binaryNode); }
Example #28
Source File: Attr.java From nashorn with GNU General Public License v2.0 | 4 votes |
private Node leaveBinaryArithmetic(final BinaryNode binaryNode) { assert !Compiler.shouldUseIntegerArithmetic(); return end(coerce(binaryNode, Type.NUMBER)); }
Example #29
Source File: WeighNodes.java From nashorn with GNU General Public License v2.0 | 4 votes |
@Override public Node leaveASSIGN_BIT_AND(final BinaryNode binaryNode) { return binaryNodeWeight(binaryNode); }
Example #30
Source File: PrintVisitor.java From jdk8u_nashorn with GNU General Public License v2.0 | 4 votes |
@Override public boolean enterDefault(final Node node) { node.toString(sb, printTypes); return false; }