comparison python/c3/builder.py @ 166:da0087b82fbe

Improved type checking
author Windel Bouwman
date Fri, 22 Mar 2013 16:15:31 +0100
parents 598d3888a11c
children 0b5b2ee6b435
comparison
equal deleted inserted replaced
165:598d3888a11c 166:da0087b82fbe
2 from . import Parser, Semantics, TypeChecker, Analyzer, CodeGenerator, AstPrinter 2 from . import Parser, Semantics, TypeChecker, Analyzer, CodeGenerator, AstPrinter
3 3
4 class Builder: 4 class Builder:
5 def __init__(self, diag): 5 def __init__(self, diag):
6 self.diag = diag 6 self.diag = diag
7 self.sema = Semantics(diag) 7 self.p = Parser(diag)
8 self.p = Parser(self.sema, diag)
9 self.tc = TypeChecker(diag) 8 self.tc = TypeChecker(diag)
10 self.al = Analyzer(diag) 9 self.al = Analyzer(diag)
11 self.cg = CodeGenerator() 10 self.cg = CodeGenerator()
12 self.ap = AstPrinter() 11 self.ap = AstPrinter()
13 def build(self, src): 12 def build(self, src):
14 # Store src for later: 13 # Store src for later:
15 self.src = src 14 self.src = src
16 print('[0] source:') 15 print('[0] source:')
17 print(src) 16 print(src)
18 print('[1] parsing') 17 print('[1] parsing')
19 self.p.parseSource(src) 18 self.pkg = self.p.parseSource(src)
20 ok = len(self.diag.diags) == 0 19 self.al.analyzePackage(self.pkg)
21 if not ok: 20 self.tc.checkPackage(self.pkg)
22 return
23 pkg = self.sema.mod
24 self.pkg = pkg
25 self.al.analyzePackage(pkg)
26 self.tc.checkPackage(pkg)
27 print('{0} errors'.format(len(self.diag.diags))) 21 print('{0} errors'.format(len(self.diag.diags)))
28
29 for d in self.diag.diags: 22 for d in self.diag.diags:
30 print('ERROR:') 23 print('ERROR:')
31 ppci.printError(src, d) 24 ppci.printError(src, d)
32 print('[2] ast:') 25 print('[2] ast:')
33 self.ap.printAst(pkg) 26 self.ap.printAst(self.pkg)
34
35 #printAst(sema.mod)
36 27
37 ok = len(self.diag.diags) == 0 28 ok = len(self.diag.diags) == 0
38 if ok: 29 if ok:
39 print('Generating ir-code') 30 print('Generating ir-code')
40 i = cg.gencode(pkg) 31 i = self.cg.gencode(self.pkg)
41 return i 32 return i
42 33