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 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 ContextLevel level=1 scope=1 begin=2 end=37\n" |
281 " 1 CurrentCtx scope=0 begin=0 end=0" | 281 " 1 CurrentCtx scope=0 begin=0 end=0" |
282 " name=:current_context_var\n" | 282 " name=:current_context_var\n" |
283 " 2 ContextVar level=1 begin=7 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" |
293 " var value = 11;\n" | 293 " var value = 11;\n" |
(...skipping 20 matching lines...) Expand all Loading... |
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 ContextLevel level=1 scope=1 begin=8 end=38\n" |
322 " 1 CurrentCtx scope=0 begin=0 end=0" | 322 " 1 CurrentCtx scope=0 begin=0 end=0" |
323 " name=:current_context_var\n" | 323 " name=:current_context_var\n" |
324 " 2 ContextVar level=1 begin=13 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 |
334 // don't save the entry context if the function has no captured | 334 // don't save the entry context if the function has no captured |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 ContextLevel level=1 scope=1 begin=20 end=50\n" |
381 " 1 CurrentCtx scope=0 begin=0 end=0" | 381 " 1 CurrentCtx scope=0 begin=0 end=0" |
382 " name=:current_context_var\n" | 382 " name=:current_context_var\n" |
383 " 2 ContextVar level=1 begin=25 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 ContextLevel level=1 scope=1 begin=2 end=68\n" |
408 " 1 CurrentCtx scope=0 begin=0 end=0" | 408 " 1 CurrentCtx scope=0 begin=0 end=0" |
409 " name=:current_context_var\n" | 409 " name=:current_context_var\n" |
410 " 2 ContextVar level=1 begin=7 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 |
420 // save the entry context instead of chaining to the parent context. | 420 // save the entry context instead of chaining to the parent context. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 | 457 |
458 "X.onX\n" | 458 "X.onX\n" |
459 " 0 StackVar scope=1 begin=0 end=0 name=this\n" | 459 " 0 StackVar scope=1 begin=0 end=0 name=this\n" |
460 " 1 CurrentCtx scope=0 begin=0 end=0" | 460 " 1 CurrentCtx scope=0 begin=0 end=0" |
461 " name=:current_context_var\n" | 461 " name=:current_context_var\n" |
462 | 462 |
463 // No context is saved here since no vars are captured. | 463 // No context is saved here since no vars are captured. |
464 "doIt\n" | 464 "doIt\n" |
465 " 0 CurrentCtx scope=0 begin=0 end=0" | 465 " 0 CurrentCtx scope=0 begin=0 end=0" |
466 " name=:current_context_var\n" | 466 " name=:current_context_var\n" |
467 " 1 StackVar scope=2 begin=29 end=77 name=x\n", | 467 " 1 StackVar scope=2 begin=35 end=77 name=x\n", |
468 CaptureVarsAtLine(lib, "doIt", 12)); | 468 CaptureVarsAtLine(lib, "doIt", 12)); |
469 } | 469 } |
470 | 470 |
471 | 471 |
472 TEST_CASE(Parser_AllocateVariables_CaptureLoopVar) { | 472 TEST_CASE(Parser_AllocateVariables_CaptureLoopVar) { |
473 // This test verifies that... | 473 // This test verifies that... |
474 // | 474 // |
475 // https://code.google.com/p/dart/issues/detail?id=18561 | 475 // https://code.google.com/p/dart/issues/detail?id=18561 |
476 // | 476 // |
477 // ...stays fixed. | 477 // ...stays fixed. |
(...skipping 20 matching lines...) Expand all Loading... |
498 "_FunctionImpl.call\n" | 498 "_FunctionImpl.call\n" |
499 " 0 StackVar scope=1 begin=0 end=4 name=this\n" | 499 " 0 StackVar scope=1 begin=0 end=4 name=this\n" |
500 " 1 CurrentCtx scope=0 begin=0 end=0" | 500 " 1 CurrentCtx scope=0 begin=0 end=0" |
501 " name=:current_context_var\n" | 501 " name=:current_context_var\n" |
502 | 502 |
503 // The outer function saves the entry context, even though the | 503 // The outer function saves the entry context, even though the |
504 // captured variable is in a loop. Good. | 504 // captured variable is in a loop. Good. |
505 "outer\n" | 505 "outer\n" |
506 " 0 CurrentCtx scope=0 begin=0 end=0" | 506 " 0 CurrentCtx scope=0 begin=0 end=0" |
507 " name=:current_context_var\n" | 507 " name=:current_context_var\n" |
508 " 1 StackVar scope=3 begin=9 end=50 name=i\n" | 508 " 1 StackVar scope=3 begin=12 end=50 name=i\n" |
509 " 2 ContextLevel level=1 scope=4 begin=20 end=50\n" | 509 " 2 ContextLevel level=1 scope=4 begin=20 end=50\n" |
510 " 3 ContextVar level=1 begin=23 end=50 name=value\n" | 510 " 3 ContextVar level=1 begin=28 end=50 name=value\n" |
511 " 4 StackVar scope=4 begin=30 end=50 name=inner\n", | 511 " 4 StackVar scope=4 begin=30 end=50 name=inner\n", |
512 CaptureVarsAtLine(lib, "outer", 5)); | 512 CaptureVarsAtLine(lib, "outer", 5)); |
513 } | 513 } |
514 | 514 |
515 TEST_CASE(Parser_AllocateVariables_MiddleChain) { | 515 TEST_CASE(Parser_AllocateVariables_MiddleChain) { |
516 const char* kScriptChars = | 516 const char* kScriptChars = |
517 "a() {\n" | 517 "a() {\n" |
518 " int x = 11;\n" | 518 " int x = 11;\n" |
519 " b() {\n" | 519 " b() {\n" |
520 " for (int i = 0; i < 1; i++) {\n" | 520 " for (int i = 0; i < 1; i++) {\n" |
(...skipping 20 matching lines...) Expand all Loading... |
541 " 1 CurrentCtx scope=0 begin=0 end=0" | 541 " 1 CurrentCtx scope=0 begin=0 end=0" |
542 " name=:current_context_var\n" | 542 " name=:current_context_var\n" |
543 | 543 |
544 // Doesn't save the entry context. Chains to parent instead. | 544 // Doesn't save the entry context. Chains to parent instead. |
545 "a.b\n" | 545 "a.b\n" |
546 " 0 ContextVar level=0 begin=12 end=68 name=x\n" | 546 " 0 ContextVar level=0 begin=12 end=68 name=x\n" |
547 " 1 CurrentCtx scope=0 begin=0 end=0" | 547 " 1 CurrentCtx scope=0 begin=0 end=0" |
548 " name=:current_context_var\n" | 548 " name=:current_context_var\n" |
549 " 2 StackVar scope=2 begin=46 end=68 name=c\n" | 549 " 2 StackVar scope=2 begin=46 end=68 name=c\n" |
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=19 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 ContextLevel level=1 scope=1 begin=1 end=76\n" |
561 " 1 CurrentCtx scope=0 begin=0 end=0" | 561 " 1 CurrentCtx scope=0 begin=0 end=0" |
562 " name=:current_context_var\n" | 562 " name=:current_context_var\n" |
563 " 2 ContextVar level=1 begin=6 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 |