annotate python/c3/typecheck.py @ 240:6259856841a0

Remove project
author Windel Bouwman
date Mon, 22 Jul 2013 22:37:33 +0200
parents e621e3ba78d2
children c4370696ccc7
rev   line source
163
8104fc8b5e90 Added visitor to c3
Windel Bouwman
parents: 155
diff changeset
1 from .astnodes import *
8104fc8b5e90 Added visitor to c3
Windel Bouwman
parents: 155
diff changeset
2 from .scope import *
8104fc8b5e90 Added visitor to c3
Windel Bouwman
parents: 155
diff changeset
3 from .visitor import Visitor
8104fc8b5e90 Added visitor to c3
Windel Bouwman
parents: 155
diff changeset
4
231
521567d17388 simplify blink.c3
Windel Bouwman
parents: 230
diff changeset
5 def theType(t):
521567d17388 simplify blink.c3
Windel Bouwman
parents: 230
diff changeset
6 """
521567d17388 simplify blink.c3
Windel Bouwman
parents: 230
diff changeset
7 Recurse until a 'real' type is found
521567d17388 simplify blink.c3
Windel Bouwman
parents: 230
diff changeset
8 """
230
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
9 if type(t) is DefinedType:
231
521567d17388 simplify blink.c3
Windel Bouwman
parents: 230
diff changeset
10 return theType(t.typ)
230
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
11 return t
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
12
163
8104fc8b5e90 Added visitor to c3
Windel Bouwman
parents: 155
diff changeset
13 def equalTypes(a, b):
230
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
14 """
228
7f18ed9b6b7e Removal of emptystatement class
Windel Bouwman
parents: 227
diff changeset
15 Compare types a and b for equality.
7f18ed9b6b7e Removal of emptystatement class
Windel Bouwman
parents: 227
diff changeset
16 Not equal until proven otherwise.
7f18ed9b6b7e Removal of emptystatement class
Windel Bouwman
parents: 227
diff changeset
17 """
226
240111e0456f Work on named types
Windel Bouwman
parents: 225
diff changeset
18 # Recurse into named types:
231
521567d17388 simplify blink.c3
Windel Bouwman
parents: 230
diff changeset
19 a = theType(a)
521567d17388 simplify blink.c3
Windel Bouwman
parents: 230
diff changeset
20 b = theType(b)
230
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
21
226
240111e0456f Work on named types
Windel Bouwman
parents: 225
diff changeset
22 # Compare for structural equivalence:
240111e0456f Work on named types
Windel Bouwman
parents: 225
diff changeset
23 if type(a) is type(b):
240111e0456f Work on named types
Windel Bouwman
parents: 225
diff changeset
24 if type(a) is BaseType:
240111e0456f Work on named types
Windel Bouwman
parents: 225
diff changeset
25 return a.name == b.name
240111e0456f Work on named types
Windel Bouwman
parents: 225
diff changeset
26 elif type(a) is PointerType:
240111e0456f Work on named types
Windel Bouwman
parents: 225
diff changeset
27 return equalTypes(a.ptype, b.ptype)
227
82dfe6a32717 Fixed tests
Windel Bouwman
parents: 226
diff changeset
28 elif type(a) is StructureType:
82dfe6a32717 Fixed tests
Windel Bouwman
parents: 226
diff changeset
29 if len(a.mems) != len(b.mems):
82dfe6a32717 Fixed tests
Windel Bouwman
parents: 226
diff changeset
30 return False
82dfe6a32717 Fixed tests
Windel Bouwman
parents: 226
diff changeset
31 for amem, bmem in zip(a.mems, b.mems):
82dfe6a32717 Fixed tests
Windel Bouwman
parents: 226
diff changeset
32 if not equalTypes(amem.typ, bmem.typ):
82dfe6a32717 Fixed tests
Windel Bouwman
parents: 226
diff changeset
33 return False
82dfe6a32717 Fixed tests
Windel Bouwman
parents: 226
diff changeset
34 return True
82dfe6a32717 Fixed tests
Windel Bouwman
parents: 226
diff changeset
35 else:
82dfe6a32717 Fixed tests
Windel Bouwman
parents: 226
diff changeset
36 raise Exception('Type compare not implemented')
226
240111e0456f Work on named types
Windel Bouwman
parents: 225
diff changeset
37 return False
150
4ae0e02599de Added type check start and analyze phase
Windel Bouwman
parents:
diff changeset
38
222
c3f1ce8b638f Fixup of parser
Windel Bouwman
parents: 221
diff changeset
39 def canCast(fromT, toT):
231
521567d17388 simplify blink.c3
Windel Bouwman
parents: 230
diff changeset
40 fromT = theType(fromT)
521567d17388 simplify blink.c3
Windel Bouwman
parents: 230
diff changeset
41 toT = theType(toT)
222
c3f1ce8b638f Fixup of parser
Windel Bouwman
parents: 221
diff changeset
42 if isinstance(fromT, PointerType) and isinstance(toT, PointerType):
c3f1ce8b638f Fixup of parser
Windel Bouwman
parents: 221
diff changeset
43 return True
c3f1ce8b638f Fixup of parser
Windel Bouwman
parents: 221
diff changeset
44 elif fromT is intType and isinstance(toT, PointerType):
c3f1ce8b638f Fixup of parser
Windel Bouwman
parents: 221
diff changeset
45 return True
c3f1ce8b638f Fixup of parser
Windel Bouwman
parents: 221
diff changeset
46 return False
c3f1ce8b638f Fixup of parser
Windel Bouwman
parents: 221
diff changeset
47
230
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
48 def expectRval(s):
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
49 # TODO: solve this better
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
50 s.expect_rvalue = True
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
51
150
4ae0e02599de Added type check start and analyze phase
Windel Bouwman
parents:
diff changeset
52 class TypeChecker:
220
3f6c30a5d234 Major change in expression parsing to enable pointers and structs
Windel Bouwman
parents: 215
diff changeset
53 def __init__(self, diag):
3f6c30a5d234 Major change in expression parsing to enable pointers and structs
Windel Bouwman
parents: 215
diff changeset
54 self.diag = diag
3f6c30a5d234 Major change in expression parsing to enable pointers and structs
Windel Bouwman
parents: 215
diff changeset
55
3f6c30a5d234 Major change in expression parsing to enable pointers and structs
Windel Bouwman
parents: 215
diff changeset
56 def error(self, msg, loc):
230
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
57 """
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
58 Wrapper that registers the message and marks the result invalid
228
7f18ed9b6b7e Removal of emptystatement class
Windel Bouwman
parents: 227
diff changeset
59 """
186
46d62dadd61b Improved testsuite
Windel Bouwman
parents: 170
diff changeset
60 self.diag.error(msg, loc)
46d62dadd61b Improved testsuite
Windel Bouwman
parents: 170
diff changeset
61 self.ok = False
220
3f6c30a5d234 Major change in expression parsing to enable pointers and structs
Windel Bouwman
parents: 215
diff changeset
62
3f6c30a5d234 Major change in expression parsing to enable pointers and structs
Windel Bouwman
parents: 215
diff changeset
63 def checkPackage(self, pkg):
186
46d62dadd61b Improved testsuite
Windel Bouwman
parents: 170
diff changeset
64 self.ok = True
215
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 186
diff changeset
65 visitor = Visitor()
c1ccb1cb4cef Major changes in c3 frontend
Windel Bouwman
parents: 186
diff changeset
66 visitor.visit(pkg, f_post=self.check2)
186
46d62dadd61b Improved testsuite
Windel Bouwman
parents: 170
diff changeset
67 return self.ok
220
3f6c30a5d234 Major change in expression parsing to enable pointers and structs
Windel Bouwman
parents: 215
diff changeset
68
3f6c30a5d234 Major change in expression parsing to enable pointers and structs
Windel Bouwman
parents: 215
diff changeset
69 def check2(self, sym):
225
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 222
diff changeset
70 if type(sym) in [IfStatement, WhileStatement]:
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 222
diff changeset
71 if not equalTypes(sym.condition.typ, boolType):
230
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
72 msg = 'Condition must be of type {}'.format(boolType)
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
73 self.error(msg, sym.condition.loc)
225
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 222
diff changeset
74 elif type(sym) is Assignment:
230
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
75 l, r = sym.lval, sym.rval
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
76 if not equalTypes(l.typ, r.typ):
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
77 msg = 'Cannot assign {} to {}'.format(r.typ, l.typ)
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
78 self.error(msg, sym.loc)
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
79 if not l.lvalue:
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
80 self.error('No valid lvalue {}'.format(l), l.loc)
221
848c4b15fd0b pointers
Windel Bouwman
parents: 220
diff changeset
81 #if sym.rval.lvalue:
848c4b15fd0b pointers
Windel Bouwman
parents: 220
diff changeset
82 # self.error('Right hand side must be an rvalue', sym.rval.loc)
230
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
83 expectRval(sym.rval)
225
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 222
diff changeset
84 elif type(sym) is ReturnStatement:
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 222
diff changeset
85 pass
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 222
diff changeset
86 elif type(sym) is FunctionCall:
167
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
87 # Check arguments:
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
88 ngiv = len(sym.args)
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
89 ptypes = sym.proc.typ.parametertypes
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
90 nreq = len(ptypes)
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
91 if ngiv != nreq:
186
46d62dadd61b Improved testsuite
Windel Bouwman
parents: 170
diff changeset
92 self.error('Function {2}: {0} arguments required, {1} given'.format(nreq, ngiv, sym.proc.name), sym.loc)
167
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
93 else:
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
94 for a, at in zip(sym.args, ptypes):
230
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
95 expectRval(a)
167
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
96 if not equalTypes(a.typ, at):
186
46d62dadd61b Improved testsuite
Windel Bouwman
parents: 170
diff changeset
97 self.error('Got {0}, expected {1}'.format(a.typ, at), a.loc)
167
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
98 # determine return type:
0b5b2ee6b435 Added 2 unit tests
Windel Bouwman
parents: 166
diff changeset
99 sym.typ = sym.proc.typ.returntype
225
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 222
diff changeset
100 elif type(sym) is VariableUse:
221
848c4b15fd0b pointers
Windel Bouwman
parents: 220
diff changeset
101 sym.lvalue = True
225
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 222
diff changeset
102 if type(sym.target) is Variable:
221
848c4b15fd0b pointers
Windel Bouwman
parents: 220
diff changeset
103 sym.typ = sym.target.typ
848c4b15fd0b pointers
Windel Bouwman
parents: 220
diff changeset
104 else:
225
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 222
diff changeset
105 print('warning {} has no target, defaulting to int'.format(sym))
221
848c4b15fd0b pointers
Windel Bouwman
parents: 220
diff changeset
106 sym.typ = intType
225
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 222
diff changeset
107 elif type(sym) is Literal:
221
848c4b15fd0b pointers
Windel Bouwman
parents: 220
diff changeset
108 sym.lvalue = False
848c4b15fd0b pointers
Windel Bouwman
parents: 220
diff changeset
109 if type(sym.val) is int:
848c4b15fd0b pointers
Windel Bouwman
parents: 220
diff changeset
110 sym.typ = intType
848c4b15fd0b pointers
Windel Bouwman
parents: 220
diff changeset
111 elif type(sym.val) is float:
848c4b15fd0b pointers
Windel Bouwman
parents: 220
diff changeset
112 sym.typ = doubleType
848c4b15fd0b pointers
Windel Bouwman
parents: 220
diff changeset
113 elif type(sym.val) is bool:
848c4b15fd0b pointers
Windel Bouwman
parents: 220
diff changeset
114 sym.typ = boolType
848c4b15fd0b pointers
Windel Bouwman
parents: 220
diff changeset
115 else:
225
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 222
diff changeset
116 raise Exception('Unknown literal type'.format(sym.val))
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 222
diff changeset
117 elif type(sym) is Unop:
220
3f6c30a5d234 Major change in expression parsing to enable pointers and structs
Windel Bouwman
parents: 215
diff changeset
118 if sym.op == '&':
3f6c30a5d234 Major change in expression parsing to enable pointers and structs
Windel Bouwman
parents: 215
diff changeset
119 sym.typ = PointerType(sym.a.typ)
221
848c4b15fd0b pointers
Windel Bouwman
parents: 220
diff changeset
120 sym.lvalue = False
225
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 222
diff changeset
121 else:
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 222
diff changeset
122 raise Exception('Unknown unop {0}'.format(sym.op))
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 222
diff changeset
123 elif type(sym) is Deref:
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 222
diff changeset
124 # pointer deref
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 222
diff changeset
125 sym.lvalue = True
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 222
diff changeset
126 # check if the to be dereferenced variable is a pointer type:
231
521567d17388 simplify blink.c3
Windel Bouwman
parents: 230
diff changeset
127 ptype = theType(sym.ptr.typ)
226
240111e0456f Work on named types
Windel Bouwman
parents: 225
diff changeset
128 if type(ptype) is PointerType:
240111e0456f Work on named types
Windel Bouwman
parents: 225
diff changeset
129 sym.typ = ptype.ptype
225
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 222
diff changeset
130 else:
226
240111e0456f Work on named types
Windel Bouwman
parents: 225
diff changeset
131 self.error('Cannot dereference non-pointer type {}'.format(ptype), sym.loc)
225
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 222
diff changeset
132 sym.typ = intType
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 222
diff changeset
133 elif type(sym) is FieldRef:
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 222
diff changeset
134 basetype = sym.base.typ
230
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
135 sym.lvalue = sym.base.lvalue
231
521567d17388 simplify blink.c3
Windel Bouwman
parents: 230
diff changeset
136 basetype = theType(basetype)
225
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 222
diff changeset
137 if type(basetype) is StructureType:
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 222
diff changeset
138 if basetype.hasField(sym.field):
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 222
diff changeset
139 sym.typ = basetype.fieldType(sym.field)
220
3f6c30a5d234 Major change in expression parsing to enable pointers and structs
Windel Bouwman
parents: 215
diff changeset
140 else:
226
240111e0456f Work on named types
Windel Bouwman
parents: 225
diff changeset
141 self.error('{} does not contain field {}'.format(basetype, sym.field), sym.loc)
221
848c4b15fd0b pointers
Windel Bouwman
parents: 220
diff changeset
142 sym.typ = intType
220
3f6c30a5d234 Major change in expression parsing to enable pointers and structs
Windel Bouwman
parents: 215
diff changeset
143 else:
225
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 222
diff changeset
144 self.error('Cannot select field {} of non-structure type {}'.format(sym.field, basetype), sym.loc)
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 222
diff changeset
145 sym.typ = intType
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 222
diff changeset
146 elif type(sym) is Binop:
227
82dfe6a32717 Fixed tests
Windel Bouwman
parents: 226
diff changeset
147 sym.lvalue = False
232
e621e3ba78d2 Added left shift instruction
Windel Bouwman
parents: 231
diff changeset
148 if sym.op in ['+', '-', '*', '/', '<<', '>>', '|', '&']:
230
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
149 expectRval(sym.a)
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
150 expectRval(sym.b)
227
82dfe6a32717 Fixed tests
Windel Bouwman
parents: 226
diff changeset
151 if equalTypes(sym.a.typ, sym.b.typ):
82dfe6a32717 Fixed tests
Windel Bouwman
parents: 226
diff changeset
152 if equalTypes(sym.a.typ, intType):
82dfe6a32717 Fixed tests
Windel Bouwman
parents: 226
diff changeset
153 sym.typ = sym.a.typ
82dfe6a32717 Fixed tests
Windel Bouwman
parents: 226
diff changeset
154 else:
82dfe6a32717 Fixed tests
Windel Bouwman
parents: 226
diff changeset
155 self.error('Can only add integers', sym.loc)
82dfe6a32717 Fixed tests
Windel Bouwman
parents: 226
diff changeset
156 sym.typ = intType
82dfe6a32717 Fixed tests
Windel Bouwman
parents: 226
diff changeset
157 else:
82dfe6a32717 Fixed tests
Windel Bouwman
parents: 226
diff changeset
158 # assume void here? TODO: throw exception!
82dfe6a32717 Fixed tests
Windel Bouwman
parents: 226
diff changeset
159 sym.typ = intType
82dfe6a32717 Fixed tests
Windel Bouwman
parents: 226
diff changeset
160 self.error('Types unequal {} != {}'.format(sym.a.typ, sym.b.typ), sym.loc)
82dfe6a32717 Fixed tests
Windel Bouwman
parents: 226
diff changeset
161 elif sym.op in ['>', '<', '==', '<=', '>=']:
82dfe6a32717 Fixed tests
Windel Bouwman
parents: 226
diff changeset
162 sym.typ = boolType
82dfe6a32717 Fixed tests
Windel Bouwman
parents: 226
diff changeset
163 if not equalTypes(sym.a.typ, sym.b.typ):
82dfe6a32717 Fixed tests
Windel Bouwman
parents: 226
diff changeset
164 self.error('Types unequal {} != {}'.format(sym.a.typ, sym.b.typ), sym.loc)
82dfe6a32717 Fixed tests
Windel Bouwman
parents: 226
diff changeset
165 elif sym.op in ['or', 'and']:
82dfe6a32717 Fixed tests
Windel Bouwman
parents: 226
diff changeset
166 sym.typ = boolType
82dfe6a32717 Fixed tests
Windel Bouwman
parents: 226
diff changeset
167 if not equalTypes(sym.a.typ, boolType):
82dfe6a32717 Fixed tests
Windel Bouwman
parents: 226
diff changeset
168 self.error('Must be {0}'.format(boolType), sym.a.loc)
82dfe6a32717 Fixed tests
Windel Bouwman
parents: 226
diff changeset
169 if not equalTypes(sym.b.typ, boolType):
82dfe6a32717 Fixed tests
Windel Bouwman
parents: 226
diff changeset
170 self.error('Must be {0}'.format(boolType), sym.b.loc)
163
8104fc8b5e90 Added visitor to c3
Windel Bouwman
parents: 155
diff changeset
171 else:
227
82dfe6a32717 Fixed tests
Windel Bouwman
parents: 226
diff changeset
172 raise Exception('Unknown binop {0}'.format(sym.op))
225
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 222
diff changeset
173 elif type(sym) is Variable:
231
521567d17388 simplify blink.c3
Windel Bouwman
parents: 230
diff changeset
174 # check initial value type:
521567d17388 simplify blink.c3
Windel Bouwman
parents: 230
diff changeset
175 # TODO
521567d17388 simplify blink.c3
Windel Bouwman
parents: 230
diff changeset
176 pass
225
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 222
diff changeset
177 elif type(sym) is TypeCast:
222
c3f1ce8b638f Fixup of parser
Windel Bouwman
parents: 221
diff changeset
178 if canCast(sym.a.typ, sym.to_type):
c3f1ce8b638f Fixup of parser
Windel Bouwman
parents: 221
diff changeset
179 sym.typ = sym.to_type
c3f1ce8b638f Fixup of parser
Windel Bouwman
parents: 221
diff changeset
180 else:
230
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
181 self.error('Cannot cast {} to {}'.format(sym.a.typ, sym.to_type), sym.loc)
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
182 sym.typ = intType
225
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 222
diff changeset
183 elif type(sym) is Constant:
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 222
diff changeset
184 if not equalTypes(sym.typ, sym.value.typ):
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 222
diff changeset
185 self.error('Cannot assign {0} to {1}'.format(sym.value.typ, sym.typ), sym.loc)
228
7f18ed9b6b7e Removal of emptystatement class
Windel Bouwman
parents: 227
diff changeset
186 elif type(sym) in [CompoundStatement, Package, Function, FunctionType, ExpressionStatement, DefinedType]:
230
88a1e0baef65 Added some tests for IR-code
Windel Bouwman
parents: 228
diff changeset
187 pass
225
1c7364bd74c7 Fixed pointer deref
Windel Bouwman
parents: 222
diff changeset
188 else:
186
46d62dadd61b Improved testsuite
Windel Bouwman
parents: 170
diff changeset
189 raise Exception('Unknown type check {0}'.format(sym))
150
4ae0e02599de Added type check start and analyze phase
Windel Bouwman
parents:
diff changeset
190