Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(248)

Side by Side Diff: runtime/vm/parser_test.cc

Issue 2625823004: Support covariant keyword in the VM parser (Closed)
Patch Set: Fix tests that rely on token position Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/parser.cc ('k') | runtime/vm/token.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 " }\n" 368 " }\n"
369 " return b();\n" 369 " return b();\n"
370 "}\n"; 370 "}\n";
371 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 371 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
372 EXPECT_VALID(lib); 372 EXPECT_VALID(lib);
373 373
374 char* vars = CaptureVarsAtLine(lib, "a", 7); 374 char* vars = CaptureVarsAtLine(lib, "a", 7);
375 EXPECT_STREQ( 375 EXPECT_STREQ(
376 // bb captures only value2 from aa. No others. 376 // bb captures only value2 from aa. No others.
377 "a.b.aa.bb\n" 377 "a.b.aa.bb\n"
378 " 0 ContextVar level=0 begin=33 end=43 name=value2\n" 378 " 0 ContextVar level=0 begin=34 end=44 name=value2\n"
379 " 1 CurrentCtx scope=0 begin=0 end=0" 379 " 1 CurrentCtx scope=0 begin=0 end=0"
380 " name=:current_context_var\n" 380 " name=:current_context_var\n"
381 381
382 // Closure call saves current context. 382 // Closure call saves current context.
383 "_Closure.call\n" 383 "_Closure.call\n"
384 " 0 StackVar scope=1 begin=0 end=4 name=this\n" 384 " 0 StackVar scope=1 begin=0 end=4 name=this\n"
385 " 1 CurrentCtx scope=0 begin=0 end=0" 385 " 1 CurrentCtx scope=0 begin=0 end=0"
386 " name=:current_context_var\n" 386 " name=:current_context_var\n"
387 387
388 // aa shares value2. Notice that we save the entry ctx instead 388 // aa shares value2. Notice that we save the entry ctx instead
389 // of chaining from b. This keeps us from holding onto closures 389 // of chaining from b. This keeps us from holding onto closures
390 // that we would never access. 390 // that we would never access.
391 "a.b.aa\n" 391 "a.b.aa\n"
392 " 0 CurrentCtx scope=0 begin=0 end=0" 392 " 0 CurrentCtx scope=0 begin=0 end=0"
393 " name=:current_context_var\n" 393 " name=:current_context_var\n"
394 " 1 ContextLevel level=1 scope=2 begin=22 end=52\n" 394 " 1 ContextLevel level=1 scope=2 begin=22 end=53\n"
395 " 2 ContextVar level=1 begin=28 end=52 name=value2\n" 395 " 2 ContextVar level=1 begin=29 end=53 name=value2\n"
396 " 3 StackVar scope=2 begin=30 end=52 name=bb\n" 396 " 3 StackVar scope=2 begin=31 end=53 name=bb\n"
397 397
398 // Closure call saves current context. 398 // Closure call saves current context.
399 "_Closure.call\n" 399 "_Closure.call\n"
400 " 0 StackVar scope=1 begin=0 end=4 name=this\n" 400 " 0 StackVar scope=1 begin=0 end=4 name=this\n"
401 " 1 CurrentCtx scope=0 begin=0 end=0" 401 " 1 CurrentCtx scope=0 begin=0 end=0"
402 " name=:current_context_var\n" 402 " name=:current_context_var\n"
403 403
404 // b captures value1 from a. 404 // b captures value1 from a.
405 "a.b\n" 405 "a.b\n"
406 " 0 ContextVar level=0 begin=14 end=62 name=value1\n" 406 " 0 ContextVar level=0 begin=14 end=63 name=value1\n"
407 " 1 CurrentCtx scope=0 begin=0 end=0" 407 " 1 CurrentCtx scope=0 begin=0 end=0"
408 " name=:current_context_var\n" 408 " name=:current_context_var\n"
409 " 2 StackVar scope=2 begin=18 end=62 name=aa\n" 409 " 2 StackVar scope=2 begin=18 end=63 name=aa\n"
410 410
411 // Closure call saves current context. 411 // Closure call saves current context.
412 "_Closure.call\n" 412 "_Closure.call\n"
413 " 0 StackVar scope=1 begin=0 end=4 name=this\n" 413 " 0 StackVar scope=1 begin=0 end=4 name=this\n"
414 " 1 CurrentCtx scope=0 begin=0 end=0" 414 " 1 CurrentCtx scope=0 begin=0 end=0"
415 " name=:current_context_var\n" 415 " name=:current_context_var\n"
416 416
417 // a shares value1, saves entry ctx. 417 // a shares value1, saves entry ctx.
418 "a\n" 418 "a\n"
419 " 0 CurrentCtx scope=0 begin=0 end=0" 419 " 0 CurrentCtx scope=0 begin=0 end=0"
420 " name=:current_context_var\n" 420 " name=:current_context_var\n"
421 " 1 ContextLevel level=1 scope=2 begin=4 end=70\n" 421 " 1 ContextLevel level=1 scope=2 begin=4 end=71\n"
422 " 2 ContextVar level=1 begin=10 end=70 name=value1\n" 422 " 2 ContextVar level=1 begin=10 end=71 name=value1\n"
423 " 3 StackVar scope=2 begin=12 end=70 name=b\n", 423 " 3 StackVar scope=2 begin=12 end=71 name=b\n",
424 vars); 424 vars);
425 free(vars); 425 free(vars);
426 } 426 }
427 427
428 428
429 TEST_CASE(Parser_AllocateVariables_Issue7681) { 429 TEST_CASE(Parser_AllocateVariables_Issue7681) {
430 // This is a distilled version of the program from Issue 7681. 430 // This is a distilled version of the program from Issue 7681.
431 // 431 //
432 // When we create the closure at line 11, we need to make sure to 432 // When we create the closure at line 11, we need to make sure to
433 // save the entry context instead of chaining to the parent context. 433 // save the entry context instead of chaining to the parent context.
(...skipping 17 matching lines...) Expand all
451 " };\n" 451 " };\n"
452 " };\n" 452 " };\n"
453 " x.onX(new Y());\n" 453 " x.onX(new Y());\n"
454 "}\n"; 454 "}\n";
455 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 455 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
456 EXPECT_VALID(lib); 456 EXPECT_VALID(lib);
457 char* vars = CaptureVarsAtLine(lib, "doIt", 12); 457 char* vars = CaptureVarsAtLine(lib, "doIt", 12);
458 EXPECT_STREQ( 458 EXPECT_STREQ(
459 // This frame saves the entry context instead of chaining. Good. 459 // This frame saves the entry context instead of chaining. Good.
460 "doIt.<anonymous closure>\n" 460 "doIt.<anonymous closure>\n"
461 " 0 ContextLevel level=1 scope=1 begin=41 end=62\n" 461 " 0 ContextLevel level=1 scope=1 begin=41 end=65\n"
462 " 1 ContextVar level=1 begin=42 end=62 name=y\n" 462 " 1 ContextVar level=1 begin=42 end=65 name=y\n"
463 " 2 CurrentCtx scope=0 begin=0 end=0" 463 " 2 CurrentCtx scope=0 begin=0 end=0"
464 " name=:current_context_var\n" 464 " name=:current_context_var\n"
465 465
466 // Closure call saves current context. 466 // Closure call saves current context.
467 "_Closure.call\n" 467 "_Closure.call\n"
468 " 0 StackVar scope=1 begin=0 end=4 name=this\n" 468 " 0 StackVar scope=1 begin=0 end=4 name=this\n"
469 " 1 CurrentCtx scope=0 begin=0 end=0" 469 " 1 CurrentCtx scope=0 begin=0 end=0"
470 " name=:current_context_var\n" 470 " name=:current_context_var\n"
471 471
472 "X.onX\n" 472 "X.onX\n"
473 " 0 StackVar scope=1 begin=0 end=0 name=this\n" 473 " 0 StackVar scope=1 begin=0 end=0 name=this\n"
474 " 1 CurrentCtx scope=0 begin=0 end=0" 474 " 1 CurrentCtx scope=0 begin=0 end=0"
475 " name=:current_context_var\n" 475 " name=:current_context_var\n"
476 476
477 // No context is saved here since no vars are captured. 477 // No context is saved here since no vars are captured.
478 "doIt\n" 478 "doIt\n"
479 " 0 CurrentCtx scope=0 begin=0 end=0" 479 " 0 CurrentCtx scope=0 begin=0 end=0"
480 " name=:current_context_var\n" 480 " name=:current_context_var\n"
481 " 1 StackVar scope=2 begin=35 end=77 name=x\n", 481 " 1 StackVar scope=2 begin=35 end=80 name=x\n",
482 vars); 482 vars);
483 free(vars); 483 free(vars);
484 } 484 }
485 485
486 486
487 TEST_CASE(Parser_AllocateVariables_CaptureLoopVar) { 487 TEST_CASE(Parser_AllocateVariables_CaptureLoopVar) {
488 // This test verifies that... 488 // This test verifies that...
489 // 489 //
490 // https://code.google.com/p/dart/issues/detail?id=18561 490 // https://code.google.com/p/dart/issues/detail?id=18561
491 // 491 //
492 // ...stays fixed. 492 // ...stays fixed.
493 const char* kScriptChars = 493 const char* kScriptChars =
494 "int outer() {\n" 494 "int outer() {\n"
495 " for(int i = 0; i < 1; i++) {\n" 495 " for(int i = 0; i < 1; i++) {\n"
496 " var value = 11 + i;\n" 496 " var value = 11 + i;\n"
497 " int inner() {\n" 497 " int inner() {\n"
498 " return value;\n" // line 5 498 " return value;\n" // line 5
499 " }\n" 499 " }\n"
500 " return inner();\n" 500 " return inner();\n"
501 " }\n" 501 " }\n"
502 "}\n"; 502 "}\n";
503 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 503 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
504 EXPECT_VALID(lib); 504 EXPECT_VALID(lib);
505 char* vars = CaptureVarsAtLine(lib, "outer", 5); 505 char* vars = CaptureVarsAtLine(lib, "outer", 5);
506 EXPECT_STREQ( 506 EXPECT_STREQ(
507 // inner function captures variable value. That's fine. 507 // inner function captures variable value. That's fine.
508 "outer.inner\n" 508 "outer.inner\n"
509 " 0 ContextVar level=0 begin=32 end=42 name=value\n" 509 " 0 ContextVar level=0 begin=33 end=43 name=value\n"
510 " 1 CurrentCtx scope=0 begin=0 end=0" 510 " 1 CurrentCtx scope=0 begin=0 end=0"
511 " name=:current_context_var\n" 511 " name=:current_context_var\n"
512 512
513 // Closure call saves current context. 513 // Closure call saves current context.
514 "_Closure.call\n" 514 "_Closure.call\n"
515 " 0 StackVar scope=1 begin=0 end=4 name=this\n" 515 " 0 StackVar scope=1 begin=0 end=4 name=this\n"
516 " 1 CurrentCtx scope=0 begin=0 end=0" 516 " 1 CurrentCtx scope=0 begin=0 end=0"
517 " name=:current_context_var\n" 517 " name=:current_context_var\n"
518 518
519 // The outer function saves the entry context, even though the 519 // The outer function saves the entry context, even though the
520 // captured variable is in a loop. Good. 520 // captured variable is in a loop. Good.
521 "outer\n" 521 "outer\n"
522 " 0 CurrentCtx scope=0 begin=0 end=0" 522 " 0 CurrentCtx scope=0 begin=0 end=0"
523 " name=:current_context_var\n" 523 " name=:current_context_var\n"
524 " 1 StackVar scope=3 begin=12 end=50 name=i\n" 524 " 1 StackVar scope=3 begin=12 end=52 name=i\n"
525 " 2 ContextLevel level=1 scope=4 begin=20 end=50\n" 525 " 2 ContextLevel level=1 scope=4 begin=20 end=52\n"
526 " 3 ContextVar level=1 begin=28 end=50 name=value\n" 526 " 3 ContextVar level=1 begin=28 end=52 name=value\n"
527 " 4 StackVar scope=4 begin=30 end=50 name=inner\n", 527 " 4 StackVar scope=4 begin=30 end=52 name=inner\n",
528 vars); 528 vars);
529 free(vars); 529 free(vars);
530 } 530 }
531 531
532 TEST_CASE(Parser_AllocateVariables_MiddleChain) { 532 TEST_CASE(Parser_AllocateVariables_MiddleChain) {
533 const char* kScriptChars = 533 const char* kScriptChars =
534 "a() {\n" 534 "a() {\n"
535 " int x = 11;\n" 535 " int x = 11;\n"
536 " b() {\n" 536 " b() {\n"
537 " for (int i = 0; i < 1; i++) {\n" 537 " for (int i = 0; i < 1; i++) {\n"
538 " int d() {\n" 538 " int d() {\n"
539 " return i;\n" 539 " return i;\n"
540 " }\n" 540 " }\n"
541 " }\n" 541 " }\n"
542 " int c() {\n" 542 " int c() {\n"
543 " return x + 1;\n" // line 10 543 " return x + 1;\n" // line 10
544 " }\n" 544 " }\n"
545 " return c();\n" 545 " return c();\n"
546 " }\n" 546 " }\n"
547 " return b();\n" 547 " return b();\n"
548 "}\n"; 548 "}\n";
549 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 549 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
550 EXPECT_VALID(lib); 550 EXPECT_VALID(lib);
551 char* vars = CaptureVarsAtLine(lib, "a", 10); 551 char* vars = CaptureVarsAtLine(lib, "a", 10);
552 EXPECT_STREQ( 552 EXPECT_STREQ(
553 "a.b.c\n" 553 "a.b.c\n"
554 " 0 ContextVar level=0 begin=50 end=62 name=x\n" 554 " 0 ContextVar level=0 begin=51 end=64 name=x\n"
555 " 1 CurrentCtx scope=0 begin=0 end=0" 555 " 1 CurrentCtx scope=0 begin=0 end=0"
556 " name=:current_context_var\n" 556 " name=:current_context_var\n"
557 "_Closure.call\n" 557 "_Closure.call\n"
558 " 0 StackVar scope=1 begin=0 end=4 name=this\n" 558 " 0 StackVar scope=1 begin=0 end=4 name=this\n"
559 " 1 CurrentCtx scope=0 begin=0 end=0" 559 " 1 CurrentCtx scope=0 begin=0 end=0"
560 " name=:current_context_var\n" 560 " name=:current_context_var\n"
561 561
562 // Doesn't save the entry context. Chains to parent instead. 562 // Doesn't save the entry context. Chains to parent instead.
563 "a.b\n" 563 "a.b\n"
564 " 0 ContextVar level=0 begin=12 end=71 name=x\n" 564 " 0 ContextVar level=0 begin=12 end=73 name=x\n"
565 " 1 CurrentCtx scope=0 begin=0 end=0" 565 " 1 CurrentCtx scope=0 begin=0 end=0"
566 " name=:current_context_var\n" 566 " name=:current_context_var\n"
567 " 2 StackVar scope=2 begin=47 end=71 name=c\n" 567 " 2 StackVar scope=2 begin=48 end=73 name=c\n"
568 " 3 ContextLevel level=1 scope=3 begin=18 end=47\n" 568 " 3 ContextLevel level=1 scope=3 begin=18 end=48\n"
569 " 4 ContextVar level=1 begin=22 end=47 name=i\n" 569 " 4 ContextVar level=1 begin=22 end=48 name=i\n"
570 " 5 StackVar scope=4 begin=32 end=47 name=d\n" 570 " 5 StackVar scope=4 begin=33 end=48 name=d\n"
571 571
572 "_Closure.call\n" 572 "_Closure.call\n"
573 " 0 StackVar scope=1 begin=0 end=4 name=this\n" 573 " 0 StackVar scope=1 begin=0 end=4 name=this\n"
574 " 1 CurrentCtx scope=0 begin=0 end=0" 574 " 1 CurrentCtx scope=0 begin=0 end=0"
575 " name=:current_context_var\n" 575 " name=:current_context_var\n"
576 576
577 "a\n" 577 "a\n"
578 " 0 CurrentCtx scope=0 begin=0 end=0" 578 " 0 CurrentCtx scope=0 begin=0 end=0"
579 " name=:current_context_var\n" 579 " name=:current_context_var\n"
580 " 1 ContextLevel level=1 scope=2 begin=3 end=79\n" 580 " 1 ContextLevel level=1 scope=2 begin=3 end=81\n"
581 " 2 ContextVar level=1 begin=9 end=79 name=x\n" 581 " 2 ContextVar level=1 begin=9 end=81 name=x\n"
582 " 3 StackVar scope=2 begin=11 end=79 name=b\n", 582 " 3 StackVar scope=2 begin=11 end=81 name=b\n",
583 vars); 583 vars);
584 free(vars); 584 free(vars);
585 } 585 }
586 586
587 #endif // !PRODUCT 587 #endif // !PRODUCT
588 588
589 } // namespace dart 589 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/parser.cc ('k') | runtime/vm/token.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698