Mercurial > lcfOS
comparison python/testc3.py @ 225:1c7364bd74c7
Fixed pointer deref
author | Windel Bouwman |
---|---|
date | Thu, 11 Jul 2013 07:42:30 +0200 |
parents | 848c4b15fd0b |
children | 82dfe6a32717 |
comparison
equal
deleted
inserted
replaced
224:5af52987f5bd | 225:1c7364bd74c7 |
---|---|
203 | 203 |
204 return b; | 204 return b; |
205 } | 205 } |
206 """ | 206 """ |
207 self.expectOK(snippet) | 207 self.expectOK(snippet) |
208 | |
209 def testTypeDef(self): | |
210 snippet = """ | |
211 package testtypedef; | |
212 type int my_int; | |
213 function void t() | |
214 { | |
215 var my_int a; | |
216 var int b; | |
217 a = 2; | |
218 b = a + 2; | |
219 } | |
220 """ | |
221 self.expectOK(snippet) | |
222 | |
208 | 223 |
224 def testPointerType1(self): | |
225 snippet = """ | |
226 package testpointer1; | |
227 var int* pa; | |
228 function void t() | |
229 { | |
230 var int a; | |
231 pa = &a; | |
232 *pa = 22; | |
233 } | |
234 """ | |
235 self.expectOK(snippet) | |
236 | |
209 def testPointerType(self): | 237 def testPointerType(self): |
210 snippet = """ | 238 snippet = """ |
211 package testpointer; | 239 package testpointer; |
212 var int* pa; | 240 var int* pa, pb; |
213 function void t(int a, double b) | 241 function void t(int a, double b) |
214 { | 242 { |
215 pa = &a; | 243 pa = &a; |
244 pb = pa; | |
216 *pa = 22; | 245 *pa = 22; |
217 } | 246 } |
218 """ | 247 """ |
219 self.expectOK(snippet) | 248 self.expectOK(snippet) |
220 | 249 |
232 **pa = 22; // Cannot deref int | 261 **pa = 22; // Cannot deref int |
233 } | 262 } |
234 """ | 263 """ |
235 self.expectErrors(snippet, [6, 9, 9, 10, 11]) | 264 self.expectErrors(snippet, [6, 9, 9, 10, 11]) |
236 | 265 |
237 @unittest.skip | |
238 def testComplexType(self): | 266 def testComplexType(self): |
239 snippet = """ | 267 snippet = """ |
240 package testpointer; | 268 package testpointer; |
241 type int my_int; | 269 type int my_int; |
242 | 270 |
249 int memb2; | 277 int memb2; |
250 point P1; | 278 point P1; |
251 } my_struct; | 279 } my_struct; |
252 | 280 |
253 type my_struct* my_sptr; | 281 type my_struct* my_sptr; |
282 var int* pa; | |
254 | 283 |
255 function void t(int a, double b, my_sptr x) | 284 function void t(int a, double b, my_sptr x) |
256 { | 285 { |
257 var my_struct *msp; | 286 var my_struct *msp; |
258 | 287 |
288 var my_struct u, v; | |
289 var point *pt; | |
290 | |
291 pt = &msp->P1; | |
259 msp = x; | 292 msp = x; |
260 *pa = 22; | 293 *pa = 22 + u.mem1 * v.memb2 - u.P1.x; |
261 x->memb2 = *pa + a * b; | 294 x->memb2 = *pa + a * b; |
262 | 295 |
263 mxp->P1.x = a * x->P1.y; | 296 msp->P1.x = a * x->P1.y; |
264 } | 297 } |
265 """ | 298 """ |
266 self.expectOK(snippet) | 299 self.expectOK(snippet) |
267 | 300 |
268 def testExamples(self): | 301 def testExamples(self): |