aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMihai Bazon <mihai@bazon.net>2012-09-18 19:26:46 +0300
committerMihai Bazon <mihai@bazon.net>2012-09-18 19:26:46 +0300
commita4d2340c7325ff864d2ca3937d8556eb4cbd7437 (patch)
tree2b38cfeda77ae81be3158809441e442c78615458 /lib
parent669874d46b42a6241f271c57d8f731ba0a2ca61a (diff)
downloadtracifyjs-a4d2340c7325ff864d2ca3937d8556eb4cbd7437.tar.gz
tracifyjs-a4d2340c7325ff864d2ca3937d8556eb4cbd7437.zip
fixed label scope/mangling
Diffstat (limited to 'lib')
-rw-r--r--lib/ast.js2
-rw-r--r--lib/scope.js18
2 files changed, 14 insertions, 6 deletions
diff --git a/lib/ast.js b/lib/ast.js
index 5c4b7e6a..6e05a396 100644
--- a/lib/ast.js
+++ b/lib/ast.js
@@ -614,7 +614,7 @@ var AST_SymbolCatch = DEFNODE("SymbolCatch", null, {
$documentation: "Symbol naming the exception in catch",
}, AST_SymbolDeclaration);
-var AST_Label = DEFNODE("Label", "label_target", {
+var AST_Label = DEFNODE("Label", "references label_target", {
$documentation: "Symbol naming a label (declaration)",
}, AST_SymbolDeclaration);
diff --git a/lib/scope.js b/lib/scope.js
index f8d3ac5e..0e615eb8 100644
--- a/lib/scope.js
+++ b/lib/scope.js
@@ -105,6 +105,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(){
node.scope = scope;
}
if (node instanceof AST_Label) {
+ node.thedef = node;
node.init_scope_vars();
var p = tw.parent(); // AST_LabeledStatement
var block = p.body;
@@ -152,8 +153,12 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(){
}
if (node instanceof AST_LabelRef) {
var sym = labels[node.name];
- if (!sym) throw new Error("Undefined label " + node.name);
- node.reference(sym);
+ if (!sym) throw new Error(string_template("Undefined label {name} [{line},{col}]", {
+ name: node.name,
+ line: node.start.line,
+ col: node.start.col
+ }));
+ node.thedef = sym;
}
});
self.walk(tw);
@@ -169,6 +174,10 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(){
func = prev_func;
return true;
}
+ if (node instanceof AST_LabelRef) {
+ node.reference();
+ return true;
+ }
if (node instanceof AST_SymbolRef) {
var name = node.name;
var sym = node.scope.find_variable(name);
@@ -227,9 +236,8 @@ AST_Label.DEFMETHOD("init_scope_vars", function(){
this.references = [];
});
-AST_LabelRef.DEFMETHOD("reference", function(def){
- this.thedef = def;
- def.references.push(this);
+AST_LabelRef.DEFMETHOD("reference", function(){
+ this.thedef.references.push(this);
});
AST_Scope.DEFMETHOD("find_variable", function(name){