ソースを参照

More informative linker error when symbol is not found: say where it is used

Yentl Van Tendeloo 9 年 前
コミット
e3dbc65134
1 ファイル変更3 行追加1 行削除
  1. 3 1
      interface/HUTN/hutn_compiler/linker.py

+ 3 - 1
interface/HUTN/hutn_compiler/linker.py

@@ -5,6 +5,7 @@ import urllib2
 def link(username, objects, fast):
     # Read out all symbol tables that are to be linked
     definers = {}
+    users = {}
     if not fast:
         definers["main"] = None
         for obj in objects:
@@ -24,6 +25,7 @@ def link(username, objects, fast):
                             raise Exception("Double definition for symbol %s\nDefined in %s\nDefined in %s" % (name, definers[name], obj))
                         definers[name] = obj
                     else:
+                        users.setdefault(name, []).append(obj)
                         if name not in definers:
                             definers[name] = None
 
@@ -32,7 +34,7 @@ def link(username, objects, fast):
             if definers[symbol] is None:
                 if symbol not in ["input", "output"]:
                     # Some symbols are built-ins which only look like functions
-                    raise Exception("Undefined symbol %s" % symbol)
+                    raise Exception("Undefined symbol %s.\nUsed by modules:\n\t%s" % (symbol, "\n\t".join(users[symbol])))
 
     # Ok, we know that all symbols can be defined with this set of files, now link their initializers together
     initializers = []