diff python/c3/builder.py @ 186:46d62dadd61b

Improved testsuite
author Windel Bouwman
date Sat, 25 May 2013 14:26:25 +0200
parents 49f1ab80d040
children b01429a5d695
line wrap: on
line diff
--- a/python/c3/builder.py	Fri May 24 20:45:03 2013 +0200
+++ b/python/c3/builder.py	Sat May 25 14:26:25 2013 +0200
@@ -2,21 +2,26 @@
 from . import Parser, Semantics, TypeChecker, Analyzer, CodeGenerator, AstPrinter
 
 class Builder:
-   def __init__(self, diag):
+    """ 
+        Generates IR-code from c3 source.
+        Reports errors to the diagnostics system
+    """
+    def __init__(self, diag):
       self.diag = diag
-      self.p = Parser(diag)
+      self.parser = Parser(diag)
       self.tc = TypeChecker(diag)
       self.al = Analyzer(diag)
       self.cg = CodeGenerator()
       self.ap = AstPrinter()
-   def build(self, src):
-      # Store src for later:
-      self.src = src
-      self.pkg = self.p.parseSource(src)
-      self.al.analyzePackage(self.pkg)
-      self.tc.checkPackage(self.pkg)
-      ok = len(self.diag.diags) == 0
-      if ok:
-         i = self.cg.gencode(self.pkg)
-         return i
+    def build(self, src):
+      """ Create IR-code from sources """
+      pkg = self.parser.parseSource(src)
+      if not pkg:
+            return
+      if not self.al.analyzePackage(pkg):
+            return
+      if not self.tc.checkPackage(pkg):
+            return
+      ircode = self.cg.gencode(pkg)
+      return ircode