Mercurial > lcfOS
diff python/c3/typecheck.py @ 165:598d3888a11c
Added front class and fided AST view
author | Windel Bouwman |
---|---|
date | Fri, 22 Mar 2013 15:12:38 +0100 |
parents | e023d3ce1d63 |
children | da0087b82fbe |
line wrap: on
line diff
--- a/python/c3/typecheck.py Mon Mar 18 22:15:57 2013 +0100 +++ b/python/c3/typecheck.py Fri Mar 22 15:12:38 2013 +0100 @@ -20,8 +20,7 @@ def check2(self, sym): if type(sym) is Function: pass - elif type(sym) is IfStatement: - print(sym.condition) + elif type(sym) in [IfStatement, WhileStatement]: if not equalTypes(sym.condition.typ, boolType): self.diag.error('Condition must be a boolean expression', sym.condition.loc) elif type(sym) is Assignment: @@ -38,7 +37,7 @@ if sym.target: sym.typ = sym.target.typ else: - sym.typ = voidType + sym.typ = intType elif type(sym) is Literal: if type(sym.val) is int: sym.typ = intType @@ -51,18 +50,22 @@ if equalTypes(sym.a.typ, sym.b.typ): sym.typ = sym.a.typ else: - # assume void here? - sym.typ = voidType + # assume void here? TODO: throw exception! + sym.typ = intType self.diag.error('Types unequal', sym.loc) elif sym.op in ['>', '<']: - if equalTypes(sym.a.typ, sym.b.typ): - sym.typ = boolType - else: - sym.typ = voidType + sym.typ = boolType + if not equalTypes(sym.a.typ, sym.b.typ): self.diag.error('Types unequal', sym.loc) else: sym.typ = voidType print('unknown binop', sym.op) + elif type(sym) is Variable: + # check initial value type: + # TODO + pass + elif type(sym) in [EmptyStatement, CompoundStatement, Package]: + pass else: print('Unknown type check', sym)