comparison python/c3/typecheck.py @ 155:b28a11c01dbe

Simplified IR classes
author Windel Bouwman
date Sun, 03 Mar 2013 13:20:03 +0100
parents b73bc14a3aa3
children 8104fc8b5e90
comparison
equal deleted inserted replaced
154:81e08e2e7777 155:b28a11c01dbe
1 from .astnodes import BaseType, Variable, Designator, Function 1 from .astnodes import BaseType, Variable, Designator, Function
2 from .astnodes import CompoundStatement, Assignment, VariableUse 2 from .astnodes import CompoundStatement, Assignment, VariableUse
3 from .astnodes import Binop, Unop, Constant 3 from .astnodes import Binop, Unop, Constant
4 from .astnodes import IfStatement, WhileStatement, ReturnStatement 4 from .astnodes import IfStatement, WhileStatement, ReturnStatement, ProcedureCall
5 from .astnodes import FunctionType, BaseType 5 from .astnodes import FunctionType, BaseType
6 from . import astnodes 6 from . import astnodes
7 from .scope import topScope 7 from .scope import topScope
8 8
9 class TypeChecker: 9 class TypeChecker:
30 elif type(sym) is CompoundStatement: 30 elif type(sym) is CompoundStatement:
31 for s in sym.statements: 31 for s in sym.statements:
32 self.check(s) 32 self.check(s)
33 elif type(sym) is IfStatement: 33 elif type(sym) is IfStatement:
34 self.check(sym.condition) 34 self.check(sym.condition)
35 print(sym.condition)
36 self.check(sym.truestatement) 35 self.check(sym.truestatement)
37 self.check(sym.falsestatement) 36 self.check(sym.falsestatement)
38 elif type(sym) is VariableUse: 37 elif type(sym) is VariableUse:
39 if type(sym.target) is Designator: 38 if type(sym.target) is Designator:
40 sym.target = self.resolveDesignator(sym.target) 39 sym.target = self.resolveDesignator(sym.target)
40 elif type(sym) is ProcedureCall:
41 if type(sym.proc) is Designator:
42 sym.proc = self.resolveDesignator(sym.proc)
41 elif type(sym) is Assignment: 43 elif type(sym) is Assignment:
42 self.check(sym.lval) 44 self.check(sym.lval)
43 self.check(sym.rval) 45 self.check(sym.rval)
44 elif type(sym) is ReturnStatement: 46 elif type(sym) is ReturnStatement:
45 self.check(sym.expr) 47 self.check(sym.expr)