Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: utils/dumpast.js

Issue 29350140: Issue 4353 - Remove non standard for each syntax (Closed)
Patch Set: Removed unused code Created Aug. 24, 2016, 2:40 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « utils/comments.js ('k') | utils/jstypes.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /**
2 * Dumps the tree of the ast rooted at the given point.
3 */
4 function dump_ast(ast, prefix) {
5 if (ast == null)
6 return;
7 if (!prefix)
8 prefix = "";
9 let str = prefix + "+ ";
10 for (let key in ast) {
11 if (key == 'column' || key == 'line' || key == 'kids')
12 continue;
13 let val = (key == 'op' ? decode_op(ast[key]) :
14 key == 'type' ? decode_type(ast[key]) :
15 key == 'flags' ? ('0x' + ast[key].toString(16)) : ast[key]);
16 str += key + ": " + val + "; ";
17 }
18 str += ast.line + ":" + ast.column;
19 _print(str);
20 prefix += " ";
21 for each (let kid in ast.kids) {
22 dump_ast(kid, prefix);
23 }
24 }
25
26 var global = this;
27 var optable = null, toktable;
28 function decode_op(opcode) {
29 if (!optable) {
30 optable = [];
31 for (let key in global) {
32 if (key.indexOf("JSOP_") == 0) {
33 optable[global[key]] = key;
34 }
35 }
36 }
37 if (opcode in optable)
38 return optable[opcode];
39 return opcode;
40 }
41 function decode_type(opcode) {
42 if (!toktable) {
43 toktable = [];
44 for (let key in global) {
45 if (key.indexOf("TOK_") == 0) {
46 toktable[global[key]] = key;
47 }
48 }
49 }
50 if (opcode in toktable)
51 return toktable[opcode];
52 return opcode;
53 }
54
55 function dump_trueast(ast, prefix) {
56 if (ast == null)
57 return;
58 if (!prefix)
59 prefix = "";
60 let str = prefix + "+ ";
61 _print(prefix + ast.type + " @ " + ast.location + ":");
62 for (let key in ast) {
63 if (key == 'type' || key == 'location' || key == 'visit')
64 continue;
65 let val = ast[key];
66 if (val instanceof Array) {
67 _print(prefix + " + " + key + ": [");
68 for each (let kind in val) {
69 dump_trueast(kind, prefix + " ");
70 }
71 _print(prefix + " ]");
72 } else if (val instanceof Object && "type" in val) {
73 _print(prefix + " + " + key + ":");
74 dump_trueast(val, prefix + " ");
75 } else {
76 _print(prefix + " + " + key + ": " + val);
77 }
78 }
79 }
OLDNEW
« no previous file with comments | « utils/comments.js ('k') | utils/jstypes.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld