/** @see org.mozilla.javascript.Node#toStringTree() */ public String toStringInner() { final StringBuffer sb = new StringBuffer(); if (Token.printTrees) { sb.append(head.getNode().toStringTree((ScriptOrFnNode) head.getNode())); } else { sb.append("AST (no details)"); } return sb.toString(); }
/** @return */ private void toStringTree(final AstNode n, final StringBuffer sb) { for (int i = 0; i < n.getDepth(); i++) { sb.append(" "); } sb.append(n.toString()); sb.append("\n"); for (final AstNode child : n.getChilds()) { toStringTree(child, sb); } }
/** * @param n * @return */ public static String getPositionInfo(final AstNode n) { String position = null; try { position = "(" + n.getScope().getAsScriptOrFn().getSourceName() + ":" + n.getLineStart() + ")"; } catch (final WinkAstException e) { position = "(unknown position)"; } return position; }
/** * Visits this node, the target, and each argument. If there is a trailing initializer node, * visits that last. */ @Override public void visit(NodeVisitor v) { if (v.visit(this)) { target.visit(v); for (AstNode arg : getArguments()) { arg.visit(v); } if (initializer != null) { initializer.visit(v); } } }
/** * Return the expression used to compute the receiver of the invocation. If this invocation is not * part of a cascade expression, then this is the same as {@link #getTarget()}. If this invocation * is part of a cascade expression, then the target stored with the cascade expression is * returned. * * @return the expression used to compute the receiver of the invocation * @see #getTarget() */ public Expression getRealTarget() { if (isCascaded()) { AstNode ancestor = getParent(); while (!(ancestor instanceof CascadeExpression)) { if (ancestor == null) { return target; } ancestor = ancestor.getParent(); } return ((CascadeExpression) ancestor).getTarget(); } return target; }
/** * @param top * @param type * @param depth * @return */ public static List<AstNode> getNodesByType(final AstNode top, final int type, final int depth) { final List<AstNode> result = new ArrayList<AstNode>(); for (final AstNode an : top.getChilds()) { getNodesByTypeR(an, type, depth, 1, result); } return result; }
/** * @param top * @param type * @param depth * @param currentDepth * @param result */ private static void getNodesByTypeR( final AstNode top, final int type, final int depth, final int currentDepth, final List<AstNode> result) { if (depth != -1 && currentDepth > depth) { return; } if (type == -1 || top.getNode().getType() == type) { result.add(top); } for (final AstNode an : top.getChilds()) { getNodesByTypeR(an, type, depth, currentDepth + 1, result); } }
public static AST_Imports MakeAST(String in) { try { Parser parser = Parser.getInstance(new StringReader(in)); return (AST_Imports) parser.parse("AST_Imports"); } catch (ParseException pe) { AstNode.fatalError("string-to-ast parse error: " + in); return null; } }
T createRootGenerator(AstNode node, String name, Generator.Block block) throws Exception { ClassVisitor type_builder = defineClass(Opcodes.ACC_FINAL | Opcodes.ACC_PUBLIC, name, Computation.class); type_builder.visitSource(node.getFileName(), null); RootGenerator generator = new RootGenerator(node, this, type_builder, name); block.invoke(generator); generator.generateSwitchBlock(true); return doMagic(name); }
public void writeNode(AstNode n) throws IOException { if (n == null) { writeNullObj(); } else { writeInt(ASTNODE_ID); writeClassName(n); n.serializeTo(this); } }
private FunctionGenerator createFunctionGenerator( AstNode node, String name, boolean has_original, String root_prefix, Set<String> owner_externals) throws NoSuchMethodException, NoSuchFieldException, SecurityException { ClassVisitor type_builder = defineClass(Opcodes.ACC_FINAL, name, Computation.class); type_builder.visitSource(node.getFileName(), null); return new FunctionGenerator( node, this, type_builder, has_original, name, root_prefix, owner_externals); }
@SuppressWarnings({"rawtypes", "unchecked"}) private static boolean addTextIntern(ArrayList list, int index, AstStringNode text) { if (text.getContent().isEmpty()) { return false; } else { if (index > 0 && !text.hasAttributes()) { AstNode prev = (AstNode) list.get(index - 1); if (prev.getNodeType() == AstNode.NT_TEXT && !prev.hasAttributes()) { try { list.set(index - 1, mergeTextNodes((AstStringNode) prev, text)); return true; } catch (CloneNotSupportedException e) { // Just add, don't merge } } } list.add(index, text); return true; } }
public void compose(AstNode etree) { // Step 1: do standard checking. etree is of type Ute if (!(etree instanceof Ute)) AstNode.fatalError(tok[0], "Extension of state machine is not of type UmodSmExt"); UmodSmExt e = (UmodSmExt) etree.arg[0]; kernelConstants.globals().compclass.isBaseAClass = true; bname = arg[0].tok[0].tokenName(); ename = e.arg[0].tok[0].tokenName(); if (!bname.equals(ename)) AstNode.fatalError( tok[0], "trying to compose state machines with different names: " + bname + " " + ename); // Step 2: if the state machine extends another state machine // then there cannot be a root clause otherwise // there must be a root clause. SmExtendsClause ec = (SmExtendsClause) arg[1].arg[0]; if (ec != null && ec instanceof SmExtends) { // there is an extends clause (i.e., the state machine // is extending another state machine). This means that // a root clause is optional. (in future versions, // root clauses will be mandatory). } else { // the state machine is the root of an extension hierarchy. // it must have a root clause if (arg[3].arg[0].arg[0] == null) AstNode.error(tok[0], "state machine " + bname + " must have a root clause"); } // Step 3: now compose implements clause, and then class body arg[2].compose(e.arg[1]); arg[3].compose(e.arg[2]); }
T createReplGenerator(AstNode node, String name, ReplGenerator.Block block) throws Exception { ClassVisitor type_builder = defineClass(Opcodes.ACC_FINAL | Opcodes.ACC_PUBLIC, name, Computation.class); type_builder.visitSource(node.getFileName(), null); ReplGenerator generator = new ReplGenerator(node, this, type_builder, name); block.invoke( generator, generator.getRootFrame(), generator.getCurrentFrame(), generator.getUpdateCurrent(), generator.getEscapeValue(), generator.getPrintValue()); generator.generateSwitchBlock(true); return doMagic(name); }
public Selection find(AstNode node) { Selection result = null; while (result == null) { if (node instanceof MethodInvocation) { MethodInvocation invocation = (MethodInvocation) node; String name = invocation.name(); AstNode parent = invocation.parent(); if (name.equals("in") && scopeSet.contains(parent.name())) { String testName = getTestNameBottomUp(invocation); result = testName != null ? new Selection(invocation.className(), testName, new String[] {testName}) : null; if (testName == null) { if (node.parent() != null) { node = node.parent(); } else break; } } else if (scopeSet.contains(name)) { String displayName = getDisplayNameBottomUp(invocation); List<String> testNames = getTestNamesTopDown(invocation); result = new Selection( invocation.className(), displayName, testNames.toArray(new String[testNames.size()])); } } if (result == null) { if (node.parent() != null) node = node.parent(); else break; } } return result; }
/* */ public void setExpression(AstNode paramAstNode) /* */ { /* 81 */ assertNotNull(paramAstNode); /* 82 */ this.expression = paramAstNode; /* 83 */ paramAstNode.setParent(this); /* */ }
/** @throws WinkAstException */ public void expand() throws WinkAstException { head.expand(); }
public void execute(int stage) { AstNode.fatalError("AstListNode.execute() method should not be called"); }
/* */ public void setIncrement(AstNode paramAstNode) /* */ { /* 129 */ assertNotNull(paramAstNode); /* 130 */ this.increment = paramAstNode; /* 131 */ paramAstNode.setParent(this); /* */ }
/* */ public void setCondition(AstNode paramAstNode) /* */ { /* 109 */ assertNotNull(paramAstNode); /* 110 */ this.condition = paramAstNode; /* 111 */ paramAstNode.setParent(this); /* */ }
private static String getClassName(AstNode node) { String fullName = node.getClass().getName(); return fullName.substring(fullName.lastIndexOf('.') + 1); }
public void reduce2ast(AstProperties props) { AstNode.escapeNotSupported(tok[0]); }
private void writeClassName(AstNode n) throws IOException { writeCached(n.getClass().getName()); }
/* */ public void setInitializer(AstNode paramAstNode) /* */ { /* 90 */ assertNotNull(paramAstNode); /* 91 */ this.initializer = paramAstNode; /* 92 */ paramAstNode.setParent(this); /* */ }
private void prop(String name, AstNode node) { printer.print(name + ": "); node.accept(this); }