diff python/c3/builder.py @ 288:a747a45dcd78

Various styling work
author Windel Bouwman
date Thu, 21 Nov 2013 14:26:13 +0100
parents 1c7c1e619be8
children bd2593de3ff8
line wrap: on
line diff
--- a/python/c3/builder.py	Thu Nov 21 11:57:27 2013 +0100
+++ b/python/c3/builder.py	Thu Nov 21 14:26:13 2013 +0100
@@ -1,12 +1,10 @@
 import logging
 import ppci
 from . import Parser, TypeChecker, Analyzer, CodeGenerator
-from . astprinter import AstPrinter
-import glob
 
 
 class Builder:
-    """ 
+    """
         Generates IR-code from c3 source.
         Reports errors to the diagnostics system
     """
@@ -17,35 +15,42 @@
         self.tc = TypeChecker(diag)
         self.al = Analyzer(diag)
         self.cg = CodeGenerator()
-        self.packages = {}
-
-    def getPackage(self, pname):
-        """ package provider for use when analyzing """
-        if pname in self.packages:
-            return self.packages[pname]
 
     def checkSource(self, srcs, imps=[]):
         """ Performs syntax and type check. """
-        # Parse source:
+        packages = {}
+        s_pkgs = []
         for src in srcs:
             pkg = self.parser.parseSource(src)
-            src.close()
             if not pkg:
-                return
+                self.ok = False
+                continue
             # Store for later use:
-            self.packages[pkg.name] = pkg
-
-        for pkg in self.packages.values():
-            # Only return ircode when everything is OK
+            packages[pkg.name] = pkg
+            s_pkgs.append(pkg)
+        if imps:
+            for src in imps:
+                pkg = self.parser.parseSource(src)
+                if not pkg:
+                    self.ok = False
+                    continue
+                # Store for later use:
+                packages[pkg.name] = pkg
+        for pkg in packages.values():
             # TODO: merge the two below?
-            if not self.al.analyzePackage(pkg, self):
-                return
+            if not self.al.analyzePackage(pkg, packages):
+                self.ok = False
+                continue
             if not self.tc.checkPackage(pkg):
-                return
+                self.ok = False
+                continue
+        for pkg in s_pkgs:
             yield pkg
 
     def build(self, srcs, imps=[]):
         """ Create IR-code from sources """
+        self.ok = True
         for pkg in self.checkSource(srcs, imps):
-            yield self.cg.gencode(pkg)
-
+            # Only return ircode when everything is OK
+            if self.ok:
+                yield self.cg.gencode(pkg)