private void handle(AstNode block) { Node child = block.getFirstChild(); while (child != null) { Node next = child.getNext(); if (child instanceof ExpressionStatement) { ExpressionStatement statement = (ExpressionStatement) child; if (statement.getExpression() instanceof StringLiteral) { block.removeChild(child); } } child = next; } } }
private void print(Scope node) throws IOException { writer.append('{').softNewLine().indent(); for (Node child = node.getFirstChild(); child != null; child = child.getNext()) { print((AstNode) child); writer.softNewLine(); } writer.outdent().append('}'); }
private void print(Block node) throws IOException { writer.append('{').softNewLine().indent(); for (Node child = node.getFirstChild(); child != null; child = child.getNext()) { print((AstNode) child); writer.softNewLine(); } writer.outdent().append('}'); }
/** * Returns a copy of the child list, with each child cast to an * {@link AstNode}. * @throws ClassCastException if any non-{@code AstNode} objects are * in the child list, e.g. if this method is called after the code * generator begins the tree transformation. */ public List<AstNode> getStatements() { List<AstNode> stmts = new ArrayList<AstNode>(); Node n = getFirstChild(); while (n != null) { stmts.add((AstNode)n); n = n.getNext(); } return stmts; }
/** * Returns a copy of the child list, with each child cast to an * {@link AstNode}. * @throws ClassCastException if any non-{@code AstNode} objects are * in the child list, e.g. if this method is called after the code * generator begins the tree transformation. */ public List<AstNode> getStatements() { List<AstNode> stmts = new ArrayList<AstNode>(); Node n = getFirstChild(); while (n != null) { stmts.add((AstNode)n); n = n.getNext(); } return stmts; }
/** * Returns a copy of the child list, with each child cast to an * {@link AstNode}. * @throws ClassCastException if any non-{@code AstNode} objects are * in the child list, e.g. if this method is called after the code * generator begins the tree transformation. */ public List<AstNode> getStatements() { List<AstNode> stmts = new ArrayList<AstNode>(); Node n = getFirstChild(); while (n != null) { stmts.add((AstNode)n); n = n.getNext(); } return stmts; }
/** * Returns a copy of the child list, with each child cast to an * {@link AstNode}. * @throws ClassCastException if any non-{@code AstNode} objects are * in the child list, e.g. if this method is called after the code * generator begins the tree transformation. */ public List<AstNode> getStatements() { List<AstNode> stmts = new ArrayList<AstNode>(); Node n = getFirstChild(); while (n != null) { stmts.add((AstNode)n); n = n.getNext(); } return stmts; }
private static Node addBeforeCurrent(Node parent, Node previous, Node current, Node toAdd) { if (previous == null) { if (!(current == parent.getFirstChild())) Kit.codeBug(); parent.addChildToFront(toAdd); } else { if (!(current == previous.getNext())) Kit.codeBug(); parent.addChildAfter(toAdd, previous); } return toAdd; }
private static void buildStatementList_r(Node node, ObjArray statements) { int type = node.getType(); if (type == Token.BLOCK || type == Token.LOCAL_BLOCK || type == Token.LOOP || type == Token.FUNCTION) { Node child = node.getFirstChild(); while (child != null) { buildStatementList_r(child, statements); child = child.getNext(); } } else { statements.add(node); } }
private static Node addBeforeCurrent(Node parent, Node previous, Node current, Node toAdd) { if (previous == null) { if (!(current == parent.getFirstChild())) Kit.codeBug(); parent.addChildToFront(toAdd); } else { if (!(current == previous.getNext())) Kit.codeBug(); parent.addChildAfter(toAdd, previous); } return toAdd; }
private static Node addBeforeCurrent(Node parent, Node previous, Node current, Node toAdd) { if (previous == null) { if (!(current == parent.getFirstChild())) Kit.codeBug(); parent.addChildToFront(toAdd); } else { if (!(current == previous.getNext())) Kit.codeBug(); parent.addChildAfter(toAdd, previous); } return toAdd; }
private static Node addBeforeCurrent(Node parent, Node previous, Node current, Node toAdd) { if (previous == null) { if (!(current == parent.getFirstChild())) Kit.codeBug(); parent.addChildToFront(toAdd); } else { if (!(current == previous.getNext())) Kit.codeBug(); parent.addChildAfter(toAdd, previous); } return toAdd; }
private static Node addBeforeCurrent(Node parent, Node previous, Node current, Node toAdd) { if (previous == null) { if (!(current == parent.getFirstChild())) Kit.codeBug(); parent.addChildToFront(toAdd); } else { if (!(current == previous.getNext())) Kit.codeBug(); parent.addChildAfter(toAdd, previous); } return toAdd; }
private static Node addBeforeCurrent(Node parent, Node previous, Node current, Node toAdd) { if (previous == null) { if (!(current == parent.getFirstChild())) Kit.codeBug(); parent.addChildToFront(toAdd); } else { if (!(current == previous.getNext())) Kit.codeBug(); parent.addChildAfter(toAdd, previous); } return toAdd; }
private void visitSetConst(Node node, Node child) { String name = node.getFirstChild().getString(); while (child != null) { generateExpression(child, node); child = child.getNext(); } cfw.addALoad(contextLocal); cfw.addPush(name); addScriptRuntimeInvoke( "setConst", "(Lorg/mozilla/javascript/Scriptable;" +"Ljava/lang/Object;" +"Lorg/mozilla/javascript/Context;" +"Ljava/lang/String;" +")Ljava/lang/Object;"); }
private void visitSetConst(Node node, Node child) { String name = node.getFirstChild().getString(); while (child != null) { generateExpression(child, node); child = child.getNext(); } cfw.addALoad(contextLocal); cfw.addPush(name); addScriptRuntimeInvoke( "setConst", "(Lorg/mozilla/javascript/Scriptable;" +"Ljava/lang/Object;" +"Lorg/mozilla/javascript/Context;" +"Ljava/lang/String;" +")Ljava/lang/Object;"); }
private static AstNode isSingleStatement(AstNode ast) { if (ast.getFirstChild() == null || ast.getFirstChild().getNext() != null) { return null; } if (ast.getFirstChild().getType() == Token.BLOCK) { return isSingleStatement((AstNode) ast.getFirstChild()); } return (AstNode) ast.getFirstChild(); }
private void print(Block node) throws IOException { writer.append('{').softNewLine().indent(); for (Node child = node.getFirstChild(); child != null; child = child.getNext()) { print((AstNode) child); writer.softNewLine(); } writer.outdent().append('}'); }
private void print(Scope node) throws IOException { writer.append('{').softNewLine().indent(); for (Node child = node.getFirstChild(); child != null; child = child.getNext()) { print((AstNode) child); writer.softNewLine(); } writer.outdent().append('}'); }
private void visitStandardNew(Node node, Node child) { if (node.getType() != Token.NEW) throw Codegen.badTree(); Node firstArgChild = child.getNext(); generateExpression(child, node); // stack: ... functionObj cfw.addALoad(contextLocal); cfw.addALoad(variableObjectLocal); // stack: ... functionObj cx scope generateCallArgArray(node, firstArgChild, false); addScriptRuntimeInvoke( "newObject", "(Ljava/lang/Object;" +"Lorg/mozilla/javascript/Context;" +"Lorg/mozilla/javascript/Scriptable;" +"[Ljava/lang/Object;" +")Lorg/mozilla/javascript/Scriptable;"); }