simple visitor API and code to figure out scope and references

This commit is contained in:
Mihai Bazon
2012-08-19 15:57:50 +03:00
parent 4488758d48
commit 6c35135ace
6 changed files with 474 additions and 102 deletions

View File

@@ -12,8 +12,6 @@ function OutputStream(options) {
scope_style : "negate"
});
function noop() {};
var indentation = 0;
var current_col = 0;
var current_line = 0;
@@ -254,7 +252,7 @@ function OutputStream(options) {
// a function expression needs parens around it when it's provably
// the first token to appear in a statement.
PARENS(AST_Lambda, function(output){
PARENS(AST_Function, function(output){
return first_in_statement(output);
});
@@ -264,11 +262,6 @@ function OutputStream(options) {
return first_in_statement(output);
});
// Defun inherits from Lambda, but we don't want parens here.
PARENS(AST_Defun, function(){
return false;
});
PARENS(AST_Seq, function(output){
var p = output.parent();
return p instanceof AST_Call // (foo, bar)() —or— foo(1, (2, 3), 4)
@@ -377,12 +370,11 @@ function OutputStream(options) {
};
DEFPRINT(AST_Statement, function(self, output){
if (self.body instanceof AST_Node) {
self.body.print(output);
output.semicolon();
} else {
display_body(self.body, self instanceof AST_Toplevel, output);
}
self.body.print(output);
output.semicolon();
});
DEFPRINT(AST_Toplevel, function(self, output){
display_body(self.body, true, output);
});
DEFPRINT(AST_LabeledStatement, function(self, output){
self.label.print(output);
@@ -459,7 +451,9 @@ function OutputStream(options) {
} else {
self.name.print(output);
}
output.print(" in ");
output.space();
output.print("in");
output.space();
self.object.print(output);
});
output.space();
@@ -800,12 +794,12 @@ function OutputStream(options) {
DEFPRINT(AST_ObjectSetter, function(self, output){
output.print("set");
output.space();
self.func._do_print(output, true);
self.value._do_print(output, true);
});
DEFPRINT(AST_ObjectGetter, function(self, output){
output.print("get");
output.space();
self.func._do_print(output, true);
self.value._do_print(output, true);
});
DEFPRINT(AST_Symbol, function(self, output){
output.print_name(self.name);