warn about unreferenced symbols

This commit is contained in:
Mihai Bazon
2012-08-21 11:53:19 +03:00
parent 99456c6156
commit 159333f4c5
2 changed files with 22 additions and 6 deletions

View File

@@ -806,11 +806,8 @@ function OutputStream(options) {
output.print_name(self.name);
});
DEFPRINT(AST_SymbolDeclaration, function(self, output){
if (self.uniq) {
self.uniq.print(output);
} else {
output.print_name(self.mangled_name || self.name);
}
var def = self.definition();
output.print_name(def.mangled_name || def.name);
});
DEFPRINT(AST_SymbolRef, function(self, output){
var def = self.symbol;

View File

@@ -76,7 +76,8 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(){
AST_Toplevel.DEFMETHOD("scope_warnings", function(options){
options = defaults(options, {
undeclared : false,
undeclared : false, // this makes a lot of noise
unreferenced : true,
assign_to_global : true,
eval : true
});
@@ -114,6 +115,16 @@ AST_Toplevel.DEFMETHOD("scope_warnings", function(options){
&& node.name == "eval") {
AST_Node.warn("Eval is used [{line},{col}]", node.start);
}
if (options.unreferenced
&& node instanceof AST_SymbolDeclaration
&& node.unreferenced()) {
AST_Node.warn("{type} {name} is declared but not referenced [{line},{col}]", {
type: node instanceof AST_Label ? "Label" : "Symbol",
name: node.name,
line: node.start.line,
col: node.start.col
});
}
});
this.walk(tw);
});
@@ -207,6 +218,14 @@ AST_SymbolDeclaration.DEFMETHOD("mangle", function(){
}
});
AST_SymbolDeclaration.DEFMETHOD("unreferenced", function(){
return this.definition().references.length == 0;
});
AST_SymbolDeclaration.DEFMETHOD("definition", function(){
return this.uniq || this;
});
AST_Toplevel.DEFMETHOD("mangle_names", function(){
var tw = new TreeWalker(function(node){
// We only need to mangle declarations. Special logic wired