comparison test/testc3.py @ 308:2e7f55319858

Merged analyse into codegenerator
author Windel Bouwman
date Fri, 13 Dec 2013 11:53:29 +0100
parents e609d5296ee9
children ff665880a6b0
comparison
equal deleted inserted replaced
307:e609d5296ee9 308:2e7f55319858
235 return b; 235 return b;
236 } 236 }
237 """ 237 """
238 self.expectOK(snippet) 238 self.expectOK(snippet)
239 239
240 def testAndCondition(self):
241 snippet = """
242 module tst;
243 function void t() {
244 if (4 > 3 and 1 < 10) {
245 }
246 }
247 """
248 self.expectOK(snippet)
249
250 def testOrCondition(self):
251 snippet = """
252 module tst;
253 function void t() {
254 if (3 > 4 or 3 < 10) {
255 }
256 }
257 """
258 self.expectOK(snippet)
259
260 def testNonBoolCondition(self):
261 snippet = """
262 module tst;
263 function void t() {
264 if (3) {
265 }
266 }
267 """
268 self.expectErrors(snippet, [4])
269
240 def testTypeDef(self): 270 def testTypeDef(self):
241 snippet = """ 271 snippet = """
242 module testtypedef; 272 module testtypedef;
243 type int my_int; 273 type int my_int;
244 function void t() 274 function void t()
282 a.y = a.x + 2; 312 a.y = a.x + 2;
283 } 313 }
284 """ 314 """
285 self.expectOK(snippet) 315 self.expectOK(snippet)
286 316
317 def testStruct2(self):
318 """ Select struct member from non struct type """
319 snippet = """
320 module teststruct1;
321 function void t() {
322 var int a;
323 a.z = 2;
324 }
325 """
326 self.expectErrors(snippet, [5])
327
287 def testStructCall(self): 328 def testStructCall(self):
288 snippet = """ 329 snippet = """
289 module teststruct1; 330 module teststruct1;
290 function void t() 331 function void t()
291 { 332 {
292 var struct {int x, y;} a; 333 var struct {int x, y;} a;
293 a.x(9); 334 a.x(9);
294 } 335 }
295 """ 336 """
296 self.expectOK(snippet) 337 self.expectErrors(snippet, [6])
297 338
298 def testPointerType1(self): 339 def testPointerType1(self):
299 snippet = """ 340 snippet = """
300 module testpointer1; 341 module testpointer1;
301 var int* pa; 342 var int* pa;
302 function void t() 343 function void t()
303 { 344 {
304 var int a; 345 var int a;
305 pa = &a; 346 pa = &a;
306 *pa = 22; 347 *pa = 22;
348 a = *pa + *pa * 8;
307 } 349 }
308 """ 350 """
309 self.expectOK(snippet) 351 self.expectOK(snippet)
310 352
311 def testPointerType(self): 353 def testPointerType(self):
372 { 414 {
373 var gpio a; 415 var gpio a;
374 *cast<gpio>(*a); 416 *cast<gpio>(*a);
375 } 417 }
376 """ 418 """
377 self.expectErrors(snippet, [7, 7]) 419 self.expectErrors(snippet, [7])
378 420
379 def testComplexType(self): 421 def testComplexType(self):
380 snippet = """ 422 snippet = """
381 module testpointer; 423 module testpointer;
382 type int my_int; 424 type int my_int;