aboutsummaryrefslogtreecommitdiff
path: root/lib/ast.js
diff options
context:
space:
mode:
authorMihai Bazon <mihai@bazon.net>2012-09-26 12:16:16 +0300
committerMihai Bazon <mihai@bazon.net>2012-09-26 12:16:16 +0300
commita24e7ee976787915c4d8f232bc980174674edb0b (patch)
tree89f847bca0d76f416feb2c0cc0cac336b16bb2c0 /lib/ast.js
parente979d01f048a7d1e0fe80e782af107a54ec0c5d0 (diff)
downloadtracifyjs-a24e7ee976787915c4d8f232bc980174674edb0b.tar.gz
tracifyjs-a24e7ee976787915c4d8f232bc980174674edb0b.zip
checkpoint (refactoring, WIP)
Diffstat (limited to 'lib/ast.js')
-rw-r--r--lib/ast.js36
1 files changed, 35 insertions, 1 deletions
diff --git a/lib/ast.js b/lib/ast.js
index 3291ed83..3e6e1771 100644
--- a/lib/ast.js
+++ b/lib/ast.js
@@ -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;
+ }
+ },
};