diff options
author | Mihai Bazon <mihai@bazon.net> | 2012-09-26 12:16:16 +0300 |
---|---|---|
committer | Mihai Bazon <mihai@bazon.net> | 2012-09-26 12:16:16 +0300 |
commit | a24e7ee976787915c4d8f232bc980174674edb0b (patch) | |
tree | 89f847bca0d76f416feb2c0cc0cac336b16bb2c0 /lib/ast.js | |
parent | e979d01f048a7d1e0fe80e782af107a54ec0c5d0 (diff) | |
download | tracifyjs-a24e7ee976787915c4d8f232bc980174674edb0b.tar.gz tracifyjs-a24e7ee976787915c4d8f232bc980174674edb0b.zip |
checkpoint (refactoring, WIP)
Diffstat (limited to 'lib/ast.js')
-rw-r--r-- | lib/ast.js | 36 |
1 files changed, 35 insertions, 1 deletions
@@ -709,5 +709,39 @@ TreeWalker.prototype = { }, parent: function(n) { return this.stack[this.stack.length - 2 - (n || 0)]; - } + }, + push: function (node) { + this.stack.push(node); + }, + pop: function() { + return this.stack.pop(); + }, + self: function() { + return this.stack[this.stack.length - 1]; + }, + find_parent: function(type) { + var stack = this.stack; + for (var i = stack.length; --i >= 0;) { + var x = stack[i]; + if (x instanceof type) return x; + } + }, + in_boolean_context: function() { + var stack = this.stack; + var i = stack.length, self = stack[--i]; + while (i > 0) { + var p = stack[--i]; + if ((p instanceof AST_If && p.condition === self) || + (p instanceof AST_Conditional && p.condition === self) || + (p instanceof AST_DWLoop && p.condition === self) || + (p instanceof AST_For && p.condition === self) || + (p instanceof AST_UnaryPrefix && p.operator == "!" && p.expression === self)) + { + return true; + } + if (!(p instanceof AST_Binary && (p.operator == "&&" || p.operator == "||"))) + return false; + self = p; + } + }, }; |