Restoring toStringTreeHelper functionality to print nested functions as a part of the tree. The regression was caused by changes to store function reference as index and not function node.

This commit is contained in:
igor%mir2.org 2003-04-28 09:44:19 +00:00
Родитель 3ffd21db41
Коммит 76c1153fdd
2 изменённых файлов: 21 добавлений и 18 удалений

Просмотреть файл

@ -1899,7 +1899,7 @@ public class Context {
tree = compiler.transform(this, irf, tree); tree = compiler.transform(this, irf, tree);
if (printTrees) { System.out.println(tree.toStringTree()); } if (printTrees) { System.out.println(tree.toStringTree(tree)); }
if (returnFunction) { if (returnFunction) {
int functionCount = tree.getFunctionCount(); int functionCount = tree.getFunctionCount();

Просмотреть файл

@ -507,33 +507,36 @@ public class Node implements Cloneable {
return null; return null;
} }
public String toStringTree() { public String toStringTree(ScriptOrFnNode treeTop) {
return toStringTreeHelper(0); if (Context.printTrees) {
StringBuffer sb = new StringBuffer();
toStringTreeHelper(treeTop, this, 0, sb);
return sb.toString();
}
return null;
} }
private static void toStringTreeHelper(ScriptOrFnNode treeTop, Node n,
private String toStringTreeHelper(int level) { int level, StringBuffer sb)
{
if (Context.printTrees) { if (Context.printTrees) {
StringBuffer s = new StringBuffer(); for (int i = 0; i != level; ++i) {
for (int i=0; i < level; i++) { sb.append(" ");
s.append(" ");
} }
s.append(toString()); sb.append(n.toString());
s.append('\n'); sb.append('\n');
for (Node cursor = getFirstChild(); cursor != null; for (Node cursor = n.getFirstChild(); cursor != null;
cursor = cursor.getNext()) cursor = cursor.getNext())
{ {
Node n = cursor;
if (cursor.getType() == TokenStream.FUNCTION) { if (cursor.getType() == TokenStream.FUNCTION) {
Node p = (Node) cursor.getProp(Node.FUNCTION_PROP); int fnIndex = cursor.getExistingIntProp(Node.FUNCTION_PROP);
if (p != null) FunctionNode fn = treeTop.getFunctionNode(fnIndex);
n = p; toStringTreeHelper(fn, fn, level + 1, sb);
} else {
toStringTreeHelper(treeTop, cursor, level + 1, sb);
} }
s.append(n.toStringTreeHelper(level+1));
} }
return s.toString();
} }
return "";
} }
int type; // type of the node; TokenStream.NAME for example int type; // type of the node; TokenStream.NAME for example