OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 | 5 |
6 #include "vm/ast_printer.h" | 6 #include "vm/ast_printer.h" |
7 #include "vm/class_finalizer.h" | 7 #include "vm/class_finalizer.h" |
8 #include "vm/debugger.h" | 8 #include "vm/debugger.h" |
9 #include "vm/longjump.h" | 9 #include "vm/longjump.h" |
10 #include "vm/object.h" | 10 #include "vm/object.h" |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 " name=:current_context_var\n" | 270 " name=:current_context_var\n" |
271 | 271 |
272 // Closure call saves current context. | 272 // Closure call saves current context. |
273 "_FunctionImpl.call\n" | 273 "_FunctionImpl.call\n" |
274 " 0 StackVar scope=1 begin=0 end=4 name=this\n" | 274 " 0 StackVar scope=1 begin=0 end=4 name=this\n" |
275 " 1 CurrentCtx scope=0 begin=0 end=0" | 275 " 1 CurrentCtx scope=0 begin=0 end=0" |
276 " name=:current_context_var\n" | 276 " name=:current_context_var\n" |
277 | 277 |
278 // function main uses one ctx var at (1); saves caller ctx. | 278 // function main uses one ctx var at (1); saves caller ctx. |
279 "main\n" | 279 "main\n" |
280 " 0 ContextLevel level=1 scope=1 begin=2 end=37\n" | 280 " 0 CurrentCtx scope=0 begin=0 end=0" |
281 " 1 CurrentCtx scope=0 begin=0 end=0" | |
282 " name=:current_context_var\n" | 281 " name=:current_context_var\n" |
| 282 " 1 ContextLevel level=1 scope=2 begin=4 end=37\n" |
283 " 2 ContextVar level=1 begin=10 end=37 name=value\n" | 283 " 2 ContextVar level=1 begin=10 end=37 name=value\n" |
284 " 3 StackVar scope=2 begin=12 end=37 name=f\n", | 284 " 3 StackVar scope=2 begin=12 end=37 name=f\n", |
285 CaptureVarsAtLine(lib, "main", 4)); | 285 CaptureVarsAtLine(lib, "main", 4)); |
286 } | 286 } |
287 | 287 |
288 | 288 |
289 TEST_CASE(Parser_AllocateVariables_NestedCapturedVar) { | 289 TEST_CASE(Parser_AllocateVariables_NestedCapturedVar) { |
290 const char* kScriptChars = | 290 const char* kScriptChars = |
291 "int a() {\n" | 291 "int a() {\n" |
292 " int b() {\n" | 292 " int b() {\n" |
(...skipping 18 matching lines...) Expand all Loading... |
311 // Closure call saves current context. | 311 // Closure call saves current context. |
312 "_FunctionImpl.call\n" | 312 "_FunctionImpl.call\n" |
313 " 0 StackVar scope=1 begin=0 end=4 name=this\n" | 313 " 0 StackVar scope=1 begin=0 end=4 name=this\n" |
314 " 1 CurrentCtx scope=0 begin=0 end=0" | 314 " 1 CurrentCtx scope=0 begin=0 end=0" |
315 " name=:current_context_var\n" | 315 " name=:current_context_var\n" |
316 | 316 |
317 // Middle function saves the entry context. Notice that this | 317 // Middle function saves the entry context. Notice that this |
318 // happens here and not in the outermost function. We always | 318 // happens here and not in the outermost function. We always |
319 // save the entry context at the last possible moment. | 319 // save the entry context at the last possible moment. |
320 "a.b\n" | 320 "a.b\n" |
321 " 0 ContextLevel level=1 scope=1 begin=8 end=38\n" | 321 " 0 CurrentCtx scope=0 begin=0 end=0" |
322 " 1 CurrentCtx scope=0 begin=0 end=0" | |
323 " name=:current_context_var\n" | 322 " name=:current_context_var\n" |
| 323 " 1 ContextLevel level=1 scope=2 begin=10 end=38\n" |
324 " 2 ContextVar level=1 begin=16 end=38 name=value\n" | 324 " 2 ContextVar level=1 begin=16 end=38 name=value\n" |
325 " 3 StackVar scope=2 begin=18 end=38 name=c\n" | 325 " 3 StackVar scope=2 begin=18 end=38 name=c\n" |
326 | 326 |
327 // Closure call saves current context. | 327 // Closure call saves current context. |
328 "_FunctionImpl.call\n" | 328 "_FunctionImpl.call\n" |
329 " 0 StackVar scope=1 begin=0 end=4 name=this\n" | 329 " 0 StackVar scope=1 begin=0 end=4 name=this\n" |
330 " 1 CurrentCtx scope=0 begin=0 end=0" | 330 " 1 CurrentCtx scope=0 begin=0 end=0" |
331 " name=:current_context_var\n" | 331 " name=:current_context_var\n" |
332 | 332 |
333 // Outermost function neglects to save the entry context. We | 333 // Outermost function neglects to save the entry context. We |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 // Closure call saves current context. | 370 // Closure call saves current context. |
371 "_FunctionImpl.call\n" | 371 "_FunctionImpl.call\n" |
372 " 0 StackVar scope=1 begin=0 end=4 name=this\n" | 372 " 0 StackVar scope=1 begin=0 end=4 name=this\n" |
373 " 1 CurrentCtx scope=0 begin=0 end=0" | 373 " 1 CurrentCtx scope=0 begin=0 end=0" |
374 " name=:current_context_var\n" | 374 " name=:current_context_var\n" |
375 | 375 |
376 // aa shares value2. Notice that we save the entry ctx instead | 376 // aa shares value2. Notice that we save the entry ctx instead |
377 // of chaining from b. This keeps us from holding onto closures | 377 // of chaining from b. This keeps us from holding onto closures |
378 // that we would never access. | 378 // that we would never access. |
379 "a.b.aa\n" | 379 "a.b.aa\n" |
380 " 0 ContextLevel level=1 scope=1 begin=20 end=50\n" | 380 " 0 CurrentCtx scope=0 begin=0 end=0" |
381 " 1 CurrentCtx scope=0 begin=0 end=0" | |
382 " name=:current_context_var\n" | 381 " name=:current_context_var\n" |
| 382 " 1 ContextLevel level=1 scope=2 begin=22 end=50\n" |
383 " 2 ContextVar level=1 begin=28 end=50 name=value2\n" | 383 " 2 ContextVar level=1 begin=28 end=50 name=value2\n" |
384 " 3 StackVar scope=2 begin=30 end=50 name=bb\n" | 384 " 3 StackVar scope=2 begin=30 end=50 name=bb\n" |
385 | 385 |
386 // Closure call saves current context. | 386 // Closure call saves current context. |
387 "_FunctionImpl.call\n" | 387 "_FunctionImpl.call\n" |
388 " 0 StackVar scope=1 begin=0 end=4 name=this\n" | 388 " 0 StackVar scope=1 begin=0 end=4 name=this\n" |
389 " 1 CurrentCtx scope=0 begin=0 end=0" | 389 " 1 CurrentCtx scope=0 begin=0 end=0" |
390 " name=:current_context_var\n" | 390 " name=:current_context_var\n" |
391 | 391 |
392 // b captures value1 from a. | 392 // b captures value1 from a. |
393 "a.b\n" | 393 "a.b\n" |
394 " 0 ContextVar level=0 begin=14 end=60 name=value1\n" | 394 " 0 ContextVar level=0 begin=14 end=60 name=value1\n" |
395 " 1 CurrentCtx scope=0 begin=0 end=0" | 395 " 1 CurrentCtx scope=0 begin=0 end=0" |
396 " name=:current_context_var\n" | 396 " name=:current_context_var\n" |
397 " 2 StackVar scope=2 begin=18 end=60 name=aa\n" | 397 " 2 StackVar scope=2 begin=18 end=60 name=aa\n" |
398 | 398 |
399 // Closure call saves current context. | 399 // Closure call saves current context. |
400 "_FunctionImpl.call\n" | 400 "_FunctionImpl.call\n" |
401 " 0 StackVar scope=1 begin=0 end=4 name=this\n" | 401 " 0 StackVar scope=1 begin=0 end=4 name=this\n" |
402 " 1 CurrentCtx scope=0 begin=0 end=0" | 402 " 1 CurrentCtx scope=0 begin=0 end=0" |
403 " name=:current_context_var\n" | 403 " name=:current_context_var\n" |
404 | 404 |
405 // a shares value1, saves entry ctx. | 405 // a shares value1, saves entry ctx. |
406 "a\n" | 406 "a\n" |
407 " 0 ContextLevel level=1 scope=1 begin=2 end=68\n" | 407 " 0 CurrentCtx scope=0 begin=0 end=0" |
408 " 1 CurrentCtx scope=0 begin=0 end=0" | |
409 " name=:current_context_var\n" | 408 " name=:current_context_var\n" |
| 409 " 1 ContextLevel level=1 scope=2 begin=4 end=68\n" |
410 " 2 ContextVar level=1 begin=10 end=68 name=value1\n" | 410 " 2 ContextVar level=1 begin=10 end=68 name=value1\n" |
411 " 3 StackVar scope=2 begin=12 end=68 name=b\n", | 411 " 3 StackVar scope=2 begin=12 end=68 name=b\n", |
412 CaptureVarsAtLine(lib, "a", 7)); | 412 CaptureVarsAtLine(lib, "a", 7)); |
413 } | 413 } |
414 | 414 |
415 | 415 |
416 TEST_CASE(Parser_AllocateVariables_Issue7681) { | 416 TEST_CASE(Parser_AllocateVariables_Issue7681) { |
417 // This is a distilled version of the program from Issue 7681. | 417 // This is a distilled version of the program from Issue 7681. |
418 // | 418 // |
419 // When we create the closure at line 11, we need to make sure to | 419 // When we create the closure at line 11, we need to make sure to |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 " 3 ContextLevel level=1 scope=3 begin=18 end=46\n" | 550 " 3 ContextLevel level=1 scope=3 begin=18 end=46\n" |
551 " 4 ContextVar level=1 begin=22 end=46 name=i\n" | 551 " 4 ContextVar level=1 begin=22 end=46 name=i\n" |
552 " 5 StackVar scope=4 begin=32 end=46 name=d\n" | 552 " 5 StackVar scope=4 begin=32 end=46 name=d\n" |
553 | 553 |
554 "_FunctionImpl.call\n" | 554 "_FunctionImpl.call\n" |
555 " 0 StackVar scope=1 begin=0 end=4 name=this\n" | 555 " 0 StackVar scope=1 begin=0 end=4 name=this\n" |
556 " 1 CurrentCtx scope=0 begin=0 end=0" | 556 " 1 CurrentCtx scope=0 begin=0 end=0" |
557 " name=:current_context_var\n" | 557 " name=:current_context_var\n" |
558 | 558 |
559 "a\n" | 559 "a\n" |
560 " 0 ContextLevel level=1 scope=1 begin=1 end=76\n" | 560 " 0 CurrentCtx scope=0 begin=0 end=0" |
561 " 1 CurrentCtx scope=0 begin=0 end=0" | |
562 " name=:current_context_var\n" | 561 " name=:current_context_var\n" |
| 562 " 1 ContextLevel level=1 scope=2 begin=3 end=76\n" |
563 " 2 ContextVar level=1 begin=9 end=76 name=x\n" | 563 " 2 ContextVar level=1 begin=9 end=76 name=x\n" |
564 " 3 StackVar scope=2 begin=11 end=76 name=b\n", | 564 " 3 StackVar scope=2 begin=11 end=76 name=b\n", |
565 CaptureVarsAtLine(lib, "a", 10)); | 565 CaptureVarsAtLine(lib, "a", 10)); |
566 } | 566 } |
567 | 567 |
568 } // namespace dart | 568 } // namespace dart |
OLD | NEW |