diff python/c3/builder.py @ 293:6aa721e7b10b

Try to improve build sequence
author Windel Bouwman
date Thu, 28 Nov 2013 20:39:37 +0100
parents bd2593de3ff8
children 917eab04b8b7
line wrap: on
line diff
--- a/python/c3/builder.py	Wed Nov 27 08:06:42 2013 +0100
+++ b/python/c3/builder.py	Thu Nov 28 20:39:37 2013 +0100
@@ -19,39 +19,38 @@
 
     def checkSource(self, srcs, imps=[]):
         """ Performs syntax and type check. """
-        packages = {}
-        s_pkgs = []
-        for src in srcs:
-            pkg = self.parser.parseSource(src)
-            if not pkg:
-                self.ok = False
-                continue
-            # Store for later use:
-            packages[pkg.name] = pkg
-            s_pkgs.append(pkg)
-        if imps:
-            for src in imps:
+        iter(srcs)
+        iter(imps)
+        def doParse(srcs):
+            for src in srcs:
                 pkg = self.parser.parseSource(src)
-                if not pkg:
+                if pkg:
+                    yield pkg
+                else:
                     self.ok = False
-                    continue
-                # Store for later use:
-                packages[pkg.name] = pkg
+        s_pkgs = set(doParse(srcs))
+        print(s_pkgs)
+        i_pkgs = set(doParse(imps))
+        all_pkgs = s_pkgs | i_pkgs
         # Fix scopes:
-        for pkg in packages.values():
-            if not AddScope(self.diag).addScope(pkg):
-                self.ok = False
+        def doF(f, pkgs):
+            for pkg in pkgs:
+                if f(pkg):
+                    yield pkg
+                else:
+                    self.ok = False
+        all_pkgs = set(doF(AddScope(self.diag).addScope, all_pkgs))
         # TODO: fix error handling better
-        for pkg in packages.values():
-            if not self.al.analyzePackage(pkg, packages):
-                self.ok = False
-                continue
-        for pkg in packages.values():
-            if not self.tc.checkPackage(pkg):
-                self.ok = False
-                continue
-        for pkg in s_pkgs:
-            yield pkg
+        def doA(pkgs):
+            packages = {pkg.name: pkg for pkg in pkgs}
+            for pkg in pkgs:
+                if self.al.analyzePackage(pkg, packages):
+                    yield pkg
+                else:
+                    self.ok = False
+        all_pkgs = set(doA(all_pkgs))
+        all_pkgs = set(doF(self.tc.checkPackage, all_pkgs))
+        return all_pkgs & s_pkgs
 
     def build(self, srcs, imps=[]):
         """ Create IR-code from sources """