/** Create a node for an empty result expression: "void 0" */ public static Node newUndefinedNode(Node srcReferenceNode) { Node node = IR.voidNode(IR.number(0)); if (srcReferenceNode != null) { node.useSourceInfoFromForTree(srcReferenceNode); } return node; }
/** Writes a Node that should be placed at the end of finally block. */ void leaveFinallyBlock(Case endCase, Node sourceNode) { ArrayList<Node> args = new ArrayList<>(); args.add(endCase.getNumber(sourceNode)); if (--nestedFinallyBlockCount != 0) { args.add(IR.number(nestedFinallyBlockCount).useSourceInfoFrom(sourceNode)); } writeGeneratedNodeAndBreak( callContextMethodResult(sourceNode, "leaveFinallyBlock", args.toArray(new Node[0]))); }
public Node buildLineAndConditionInitialisation(String uri, int lineNo, int conditionNo, int position, int length) { Node indexLineNumber = buildLineDeclaration(uri, lineNo); Node conditionNumberLiteral = IR.number(conditionNo); Node indexConditionNumber = IR.getelem(indexLineNumber, conditionNumberLiteral); Node positionLiteral = IR.number(position); Node lengthLiteral = IR.number(length); Node initCall = IR.string("init"); Node propertyName = IR.getprop(indexConditionNumber, initCall); Node fnCall = IR.call(propertyName, positionLiteral, lengthLiteral); return IR.exprResult(fnCall); }
private static Node makeGeneratorMarker(int i) { Node n = IR.exprResult(IR.number(i)); n.setGeneratorMarker(true); return n; }
public Node buildLineAndConditionInitialisation(String uri, int lineNo, int conditionNo, int position, int length) { Node indexLineNumber = buildLineDeclaration(uri, lineNo); Node conditionNumberLiteral = IR.number(conditionNo); Node indexConditionNumber = IR.getelem(indexLineNumber, conditionNumberLiteral); Node positionLiteral = IR.number(position); Node lengthLiteral = IR.number(length); Node initCall = IR.string("init"); Node propertyName = IR.getprop(indexConditionNumber, initCall); Node fnCall = IR.call(propertyName, positionLiteral, lengthLiteral); return IR.exprResult(fnCall); }
/** Returns the number node of the case section and increments a reference counter. */ Node getNumber(Node sourceNode) { if (jumpTo != null) { return jumpTo.getNumber(sourceNode); } Node node = withType(IR.number(id), numberType).useSourceInfoFrom(sourceNode); references.add(node); return node; }
private static void removeStringKeyValue(Node stringKey) { Node value = stringKey.getOnlyChild(); Node replacementValue = IR.number(0).srcrefTree(value); stringKey.replaceChild(value, replacementValue); }
Node createNumber(double value) { Node result = IR.number(value); if (isAddingTypes()) { result.setJSType(getNativeType(JSTypeNative.NUMBER_TYPE)); } return result; }
public Node buildConditionalStatement(int startLine, int endLine, String fileName) { Node indexLineNumber = buildLineNumberExpression(startLine, fileName, "conditionals"); Node lineNumberLiteral = IR.number(endLine); Node assignment = IR.assign(indexLineNumber, lineNumberLiteral); return IR.exprResult(assignment); }
public Node buildConditionalStatement(int startLine, int endLine, String fileName) { Node indexLineNumber = buildLineNumberExpression(startLine, fileName, "conditionals"); Node lineNumberLiteral = IR.number(endLine); Node assignment = IR.assign(indexLineNumber, lineNumberLiteral); return IR.exprResult(assignment); }
Node createCaseNode() { return IR.caseNode( withType(IR.number(id), numberType).useSourceInfoFrom(caseBlock), caseBlock) .useSourceInfoFrom(caseBlock); }
private static void replaceRhsWithUnknown(Node rhs) { rhs.replaceWith(IR.cast(IR.number(0), JsdocUtil.getQmarkTypeJSDoc()).srcrefTree(rhs)); }
@Override public void remove() { Preconditions.checkState(node.isCall()); Node parent = getParent(); if (parent.isExprResult()) { changeProxy.removeChild(getGrandparent(), parent); } else { changeProxy.replaceWith(parent, node, IR.voidNode(IR.number(0))); } } }
Node buildLineNumberExpression(int lineNumber, String fileName, String identifier) { Node coverVar = IR.name("_$jscoverage"); Node path = IR.string(fileName); Node getURI = IR.getelem(coverVar, path); Node prop = IR.string(identifier); Node propGet = IR.getprop(getURI, prop); Node number = IR.number(lineNumber); return IR.getelem(propGet, number); }
private Node tryReduceVoid(Node n) { Node child = n.getFirstChild(); if ((!child.isNumber() || child.getDouble() != 0.0) && !mayHaveSideEffects(n)) { n.replaceChild(child, IR.number(0)); reportChangeToEnclosingScope(n); } return n; }
private Node newReportFunctionExitNode(Node infoNode, Node returnRhs) { Node call = IR.call( IR.name(reportFunctionExitName), IR.number(functionId), (returnRhs != null) ? returnRhs : IR.name("undefined"), IR.string(functionName)); call.putBooleanProp(Node.FREE_CALL, true); call.useSourceInfoFromForTree(infoNode); return call; }
private Node tryReduceVoid(Node n) { Node child = n.getFirstChild(); if ((!child.isNumber() || child.getDouble() != 0.0) && !mayHaveSideEffects(n)) { n.replaceChild(child, IR.number(0)); reportCodeChange(); } return n; }
public Node buildLineAndConditionCall(String uri, int lineNo, int conditionNo) { Node indexLineNumber = buildLineDeclaration(uri, lineNo); Node conditionNumberLiteral = IR.number(conditionNo); Node indexConditionNumber = IR.getelem(indexLineNumber, conditionNumberLiteral); Node initCall = IR.string("ranCondition"); Node propertyName = IR.getprop(indexConditionNumber, initCall); Node result = IR.name("result"); Node fnCall = IR.call(propertyName, result); return IR.exprResult(fnCall); }
public Node buildLineAndConditionCall(String uri, int lineNo, int conditionNo) { Node indexLineNumber = buildLineDeclaration(uri, lineNo); Node conditionNumberLiteral = IR.number(conditionNo); Node indexConditionNumber = IR.getelem(indexLineNumber, conditionNumberLiteral); Node initCall = IR.string("ranCondition"); Node propertyName = IR.getprop(indexConditionNumber, initCall); Node result = IR.name("result"); Node fnCall = IR.call(propertyName, result); return IR.exprResult(fnCall); }
private static Node createFinallyJumpBlock(Node finallyName, int finallyStartState) { int jumpPoint = generatorCaseCount++; Node setReturnState = IR.exprResult(IR.assign(finallyName.cloneTree(), IR.number(jumpPoint))); Node toFinally = createStateUpdate(finallyStartState); Node returnPoint = makeGeneratorMarker(jumpPoint); Node returnBlock = IR.block(setReturnState, toFinally, createSafeBreak()); returnBlock.addChildToBack(returnPoint); return returnBlock; }