# HG changeset patch # User Paul Boddie # Date 1473352778 -7200 # Node ID 4e9d8939478738eecc945b8dc5d283b1de740728 # Parent 1c505a028b7eaba98a1c8e65dbe9bd2d22320a5b Moved missing name recording into the importer, testing for name identification failure in the main program. diff -r 1c505a028b7e -r 4e9d89394787 importer.py --- a/importer.py Thu Sep 08 18:34:23 2016 +0200 +++ b/importer.py Thu Sep 08 18:39:38 2016 +0200 @@ -50,14 +50,21 @@ self.cache = cache self.verbose = verbose + # Module importing queue, required modules, removed modules and active + # modules in the final program. + self.to_import = set() self.required = set(["__main__"]) self.removed = {} + self.modules = {} - self.modules = {} + # Module relationships and invalidated cached modules. + self.accessing_modules = {} self.invalidated = set() + # Basic program information. + self.objects = {} self.classes = {} self.function_parameters = {} @@ -65,6 +72,10 @@ self.function_targets = {} self.function_arguments = {} + # Unresolved names. + + self.missing = set() + # Derived information. self.subclasses = {} @@ -322,7 +333,13 @@ def finalise(self): - "Finalise the inspected program." + """ + Finalise the inspected program, returning whether the program could be + finalised. + """ + + if self.missing: + return False self.finalise_classes() self.to_cache() @@ -330,6 +347,8 @@ self.define_instantiators() self.collect_constants() + return True + # Supporting operations. def resolve(self): @@ -345,7 +364,7 @@ for ref in module.deferred: found = self.find_dependency(ref) if not found: - print >>sys.stderr, "Module %s references an unknown object: %s" % (module.name, ref.get_origin()) + self.missing.add((module.name, ref.get_origin())) # Record the resolved names and identify required modules. diff -r 1c505a028b7e -r 4e9d89394787 lplc --- a/lplc Thu Sep 08 18:34:23 2016 +0200 +++ b/lplc Thu Sep 08 18:39:38 2016 +0200 @@ -18,6 +18,12 @@ return i.load_from_file(path, module_name) return None +def show_missing(missing): + missing = list(missing) + missing.sort() + for module_name, name in missing: + print >>sys.stderr, "Module %s references an unknown object: %s" % (module_name, name) + def stopwatch(activity, now): print >>sys.stderr, "%s took %.2f seconds" % (activity, time() - now) return time() @@ -41,10 +47,19 @@ i = importer.Importer(path, "_cache", verbose) m = i.initialise(filename, reset) - i.finalise() + success = i.finalise() now = stopwatch("Inspection", now) + # Check for success, indicating missing references otherwise. + + if not success: + show_missing(i.missing) + if "-exit" in args: + sys.exit(1) + else: + sys.exit(0) + # Report any errors. except ProcessingError, exc: