1.1 --- a/importer.py Thu Sep 08 18:34:23 2016 +0200
1.2 +++ b/importer.py Thu Sep 08 18:39:38 2016 +0200
1.3 @@ -50,14 +50,21 @@
1.4 self.cache = cache
1.5 self.verbose = verbose
1.6
1.7 + # Module importing queue, required modules, removed modules and active
1.8 + # modules in the final program.
1.9 +
1.10 self.to_import = set()
1.11 self.required = set(["__main__"])
1.12 self.removed = {}
1.13 + self.modules = {}
1.14
1.15 - self.modules = {}
1.16 + # Module relationships and invalidated cached modules.
1.17 +
1.18 self.accessing_modules = {}
1.19 self.invalidated = set()
1.20
1.21 + # Basic program information.
1.22 +
1.23 self.objects = {}
1.24 self.classes = {}
1.25 self.function_parameters = {}
1.26 @@ -65,6 +72,10 @@
1.27 self.function_targets = {}
1.28 self.function_arguments = {}
1.29
1.30 + # Unresolved names.
1.31 +
1.32 + self.missing = set()
1.33 +
1.34 # Derived information.
1.35
1.36 self.subclasses = {}
1.37 @@ -322,7 +333,13 @@
1.38
1.39 def finalise(self):
1.40
1.41 - "Finalise the inspected program."
1.42 + """
1.43 + Finalise the inspected program, returning whether the program could be
1.44 + finalised.
1.45 + """
1.46 +
1.47 + if self.missing:
1.48 + return False
1.49
1.50 self.finalise_classes()
1.51 self.to_cache()
1.52 @@ -330,6 +347,8 @@
1.53 self.define_instantiators()
1.54 self.collect_constants()
1.55
1.56 + return True
1.57 +
1.58 # Supporting operations.
1.59
1.60 def resolve(self):
1.61 @@ -345,7 +364,7 @@
1.62 for ref in module.deferred:
1.63 found = self.find_dependency(ref)
1.64 if not found:
1.65 - print >>sys.stderr, "Module %s references an unknown object: %s" % (module.name, ref.get_origin())
1.66 + self.missing.add((module.name, ref.get_origin()))
1.67
1.68 # Record the resolved names and identify required modules.
1.69
2.1 --- a/lplc Thu Sep 08 18:34:23 2016 +0200
2.2 +++ b/lplc Thu Sep 08 18:39:38 2016 +0200
2.3 @@ -18,6 +18,12 @@
2.4 return i.load_from_file(path, module_name)
2.5 return None
2.6
2.7 +def show_missing(missing):
2.8 + missing = list(missing)
2.9 + missing.sort()
2.10 + for module_name, name in missing:
2.11 + print >>sys.stderr, "Module %s references an unknown object: %s" % (module_name, name)
2.12 +
2.13 def stopwatch(activity, now):
2.14 print >>sys.stderr, "%s took %.2f seconds" % (activity, time() - now)
2.15 return time()
2.16 @@ -41,10 +47,19 @@
2.17
2.18 i = importer.Importer(path, "_cache", verbose)
2.19 m = i.initialise(filename, reset)
2.20 - i.finalise()
2.21 + success = i.finalise()
2.22
2.23 now = stopwatch("Inspection", now)
2.24
2.25 + # Check for success, indicating missing references otherwise.
2.26 +
2.27 + if not success:
2.28 + show_missing(i.missing)
2.29 + if "-exit" in args:
2.30 + sys.exit(1)
2.31 + else:
2.32 + sys.exit(0)
2.33 +
2.34 # Report any errors.
2.35
2.36 except ProcessingError, exc: