public void renderHandWrittenRuntime(String name) throws IOException { AstRoot ast = parseRuntime(name); ast.visit(new StringConstantElimination()); AstWriter astWriter = new AstWriter(writer); astWriter.hoist(ast); astWriter.print(ast); }
/** * Sets comment list, and updates the parent of each entry to point * to this node. Replaces any existing comments. * @param comments comment list. can be {@code null}. */ public void setComments(SortedSet<Comment> comments) { if (comments == null) { this.comments = null; } else { if (this.comments != null) this.comments.clear(); for (Comment c : comments) addComment(c); } }
/** * Visits the AST nodes, then the comment nodes. * This method is equivalent to calling {@link #visit}, then * {@link #visitComments}. The return value * is ignored while visiting comment nodes. * @param visitor the callback object. */ public void visitAll(NodeVisitor visitor) { visit(visitor); visitComments(visitor); }
private AstRoot parse() throws IOException AstRoot root = new AstRoot(pos); currentScope = currentScriptOrFn = root; } else if (directive.equals("use strict")) { inUseStrictDirective = true; root.setInStrictMode(true); root.addChildToBack(n); n.setParent(root); end = Math.max(end, getNodeEnd(scannedComments.get(last))); for (Comment c : scannedComments) { root.addComment(c); root.setLength(end - pos); root.setSourceName(sourceURI); root.setBaseLineno(baseLineno); root.setEndLineno(ts.lineno); return root;
/** * A debug-printer that includes comments (at the end). */ @Override public String debugPrint() { DebugPrintVisitor dpv = new DebugPrintVisitor(new StringBuilder(1000)); visitAll(dpv); return dpv.toString(); }
if (root.getComments() != null && !root.getComments().isEmpty()) final String rawHeaderDocs = root.getComments().first().getValue(); jsDoc.set(JsDocParser.parse(getId(), rawHeaderDocs)); root.visitAll(new NodeVisitor()
private void transformCompilationUnit(ScriptNode tree) { loops = new ObjArray(); loopEnds = new ObjArray(); // to save against upchecks if no finally blocks are used. hasFinally = false; // Flatten all only if we are not using scope objects for block scope boolean createScopeObjects = tree.getType() != Token.FUNCTION || ((FunctionNode)tree).requiresActivation(); tree.flattenSymbolTable(!createScopeObjects); //uncomment to print tree before transformation if (Token.printTrees) System.out.println(tree.toStringTree(tree)); boolean inStrictMode = tree instanceof AstRoot && ((AstRoot)tree).isInStrictMode(); transformCompilationUnit_r(tree, tree, tree, createScopeObjects, inStrictMode); }
try { AstRoot ast = jsParser.parse(script, "script", 1); ast.getType(); ast.visitAll(new NodeVisitor() { @Override public boolean visit(AstNode node) { StringBuilder result = new StringBuilder(); result.append("var _returnValue;\n"); result.append(ast.toSource()); result.append("return _returnValue;\n"); return result.toString();
if (!(ast.getFirstChild() != null && ast.getFirstChild().getType() == Token.FUNCTION))
/** * Add a comment to the comment set. * @param comment the comment node. * @throws IllegalArgumentException if comment is {@code null} */ public void addComment(Comment comment) { assertNotNull(comment); if (comments == null) { comments = new TreeSet<Comment>(new AstNode.PositionComparator()); } comments.add(comment); comment.setParent(this); }
private AstRoot parse() throws IOException AstRoot root = new AstRoot(pos); currentScope = currentScriptOrFn = root; } else if (directive.equals("use strict")) { inUseStrictDirective = true; root.setInStrictMode(true); root.addChildToBack(n); n.setParent(root); end = Math.max(end, getNodeEnd(scannedComments.get(last))); for (Comment c : scannedComments) { root.addComment(c); root.setLength(end - pos); root.setSourceName(sourceURI); root.setBaseLineno(baseLineno); root.setEndLineno(ts.lineno); return root;
/** * Visits the AST nodes, then the comment nodes. * This method is equivalent to calling {@link #visit}, then * {@link #visitComments}. The return value * is ignored while visiting comment nodes. * @param visitor the callback object. */ public void visitAll(NodeVisitor visitor) { visit(visitor); visitComments(visitor); }
/** * A debug-printer that includes comments (at the end). */ @Override public String debugPrint() { DebugPrintVisitor dpv = new DebugPrintVisitor(new StringBuilder(1000)); visitAll(dpv); return dpv.toString(); }
private void transformCompilationUnit(ScriptNode tree) { loops = new ObjArray(); loopEnds = new ObjArray(); // to save against upchecks if no finally blocks are used. hasFinally = false; // Flatten all only if we are not using scope objects for block scope boolean createScopeObjects = tree.getType() != Token.FUNCTION || ((FunctionNode)tree).requiresActivation(); tree.flattenSymbolTable(!createScopeObjects); //uncomment to print tree before transformation if (Token.printTrees) System.out.println(tree.toStringTree(tree)); boolean inStrictMode = tree instanceof AstRoot && ((AstRoot)tree).isInStrictMode(); transformCompilationUnit_r(tree, tree, tree, createScopeObjects, inStrictMode); }
if (!(ast.getFirstChild() != null && ast.getFirstChild().getType() == Token.FUNCTION))
/** * Add a comment to the comment set. * @param comment the comment node. * @throws IllegalArgumentException if comment is {@code null} */ public void addComment(Comment comment) { assertNotNull(comment); if (comments == null) { comments = new TreeSet<Comment>(new AstNode.PositionComparator()); } comments.add(comment); comment.setParent(this); }
private AstRoot parse() throws IOException AstRoot root = new AstRoot(pos); currentScope = currentScriptOrFn = root; } else if (directive.equals("use strict")) { inUseStrictDirective = true; root.setInStrictMode(true); root.addChildToBack(n); n.setParent(root); end = Math.max(end, getNodeEnd(scannedComments.get(last))); for (Comment c : scannedComments) { root.addComment(c); root.setLength(end - pos); root.setSourceName(sourceURI); root.setBaseLineno(baseLineno); root.setEndLineno(ts.lineno); return root;
/** * Debugging function to check that the parser has set the parent * link for every node in the tree. * @throws IllegalStateException if a parent link is missing */ public void checkParentLinks() { this.visit(new NodeVisitor() { public boolean visit(AstNode node) { int type = node.getType(); if (type == Token.SCRIPT) return true; if (node.getParent() == null) throw new IllegalStateException ("No parent for node: " + node + "\n" + node.toSource(0)); return true; } }); } }
/** * Visits the AST nodes, then the comment nodes. * This method is equivalent to calling {@link #visit}, then * {@link #visitComments}. The return value * is ignored while visiting comment nodes. * @param visitor the callback object. */ public void visitAll(NodeVisitor visitor) { visit(visitor); visitComments(visitor); }
/** * A debug-printer that includes comments (at the end). */ @Override public String debugPrint() { DebugPrintVisitor dpv = new DebugPrintVisitor(new StringBuilder(1000)); visitAll(dpv); return dpv.toString(); }