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

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

Issue 2974233002: VM: Re-format to use at most one newline between functions (Closed)
Patch Set: Rebase and merge Created 3 years, 5 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/flow_graph_builder.cc ('k') | runtime/vm/flow_graph_compiler.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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 #include "vm/flow_graph_builder.h"
5 #include "vm/compiler.h" 6 #include "vm/compiler.h"
6 #include "vm/dart_api_impl.h" 7 #include "vm/dart_api_impl.h"
7 #include "vm/dart_entry.h" 8 #include "vm/dart_entry.h"
8 #include "vm/flow_graph_builder.h"
9 #include "vm/intermediate_language.h" 9 #include "vm/intermediate_language.h"
10 #include "vm/unit_test.h" 10 #include "vm/unit_test.h"
11 11
12 namespace dart { 12 namespace dart {
13 13
14 #ifndef PRODUCT 14 #ifndef PRODUCT
15 15
16 #define DUMP_ASSERT(condition) \ 16 #define DUMP_ASSERT(condition) \
17 if (!(condition)) { \ 17 if (!(condition)) { \
18 dart::Expect(__FILE__, __LINE__).Fail("expected: %s", #condition); \ 18 dart::Expect(__FILE__, __LINE__).Fail("expected: %s", #condition); \
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 Thread* thread_; 273 Thread* thread_;
274 Isolate* isolate_; 274 Isolate* isolate_;
275 const char* script_; 275 const char* script_;
276 Library& root_lib_; 276 Library& root_lib_;
277 Script& root_script_; 277 Script& root_script_;
278 const char* graph_name_; 278 const char* graph_name_;
279 FlowGraph* graph_; 279 FlowGraph* graph_;
280 GrowableArray<BlockEntryInstr*>* blocks_; 280 GrowableArray<BlockEntryInstr*>* blocks_;
281 }; 281 };
282 282
283
284 TEST_CASE(SourcePosition_InstanceCalls) { 283 TEST_CASE(SourcePosition_InstanceCalls) {
285 const char* kScript = 284 const char* kScript =
286 "var x = 5;\n" 285 "var x = 5;\n"
287 "var y = 5;\n" 286 "var y = 5;\n"
288 "main() {\n" 287 "main() {\n"
289 " var z = x + y;\n" 288 " var z = x + y;\n"
290 " return z;\n" 289 " return z;\n"
291 "}\n"; 290 "}\n";
292 291
293 SourcePositionTest spt(thread, kScript); 292 SourcePositionTest spt(thread, kScript);
294 spt.BuildGraphFor("main"); 293 spt.BuildGraphFor("main");
295 spt.FuzzyInstructionMatchAt("DebugStepCheck", 3, 5); 294 spt.FuzzyInstructionMatchAt("DebugStepCheck", 3, 5);
296 spt.FuzzyInstructionMatchAt("CheckStackOverflow", 3, 5); 295 spt.FuzzyInstructionMatchAt("CheckStackOverflow", 3, 5);
297 spt.InstanceCallAt(4, 13, Token::kADD); 296 spt.InstanceCallAt(4, 13, Token::kADD);
298 spt.FuzzyInstructionMatchAt("DebugStepCheck", 5, 3); 297 spt.FuzzyInstructionMatchAt("DebugStepCheck", 5, 3);
299 spt.FuzzyInstructionMatchAt("Return", 5, 3); 298 spt.FuzzyInstructionMatchAt("Return", 5, 3);
300 299
301 spt.EnsureSourcePositions(); 300 spt.EnsureSourcePositions();
302 } 301 }
303 302
304
305 TEST_CASE(SourcePosition_If) { 303 TEST_CASE(SourcePosition_If) {
306 const char* kScript = 304 const char* kScript =
307 "var x = 5;\n" 305 "var x = 5;\n"
308 "var y = 5;\n" 306 "var y = 5;\n"
309 "main() {\n" 307 "main() {\n"
310 " if (x != 0) {\n" 308 " if (x != 0) {\n"
311 " return x;\n" 309 " return x;\n"
312 " }\n" 310 " }\n"
313 " return y;\n" 311 " return y;\n"
314 "}\n"; 312 "}\n";
315 313
316 SourcePositionTest spt(thread, kScript); 314 SourcePositionTest spt(thread, kScript);
317 spt.BuildGraphFor("main"); 315 spt.BuildGraphFor("main");
318 spt.FuzzyInstructionMatchAt("DebugStepCheck", 3, 5); 316 spt.FuzzyInstructionMatchAt("DebugStepCheck", 3, 5);
319 spt.FuzzyInstructionMatchAt("CheckStackOverflow", 3, 5); 317 spt.FuzzyInstructionMatchAt("CheckStackOverflow", 3, 5);
320 spt.FuzzyInstructionMatchAt("LoadStaticField", 4, 7); 318 spt.FuzzyInstructionMatchAt("LoadStaticField", 4, 7);
321 spt.InstanceCallAt(4, 9, Token::kEQ); 319 spt.InstanceCallAt(4, 9, Token::kEQ);
322 spt.FuzzyInstructionMatchAt("Branch if StrictCompare", 4, 9); 320 spt.FuzzyInstructionMatchAt("Branch if StrictCompare", 4, 9);
323 spt.FuzzyInstructionMatchAt("LoadStaticField", 5, 12); 321 spt.FuzzyInstructionMatchAt("LoadStaticField", 5, 12);
324 spt.FuzzyInstructionMatchAt("DebugStepCheck", 5, 5); 322 spt.FuzzyInstructionMatchAt("DebugStepCheck", 5, 5);
325 spt.FuzzyInstructionMatchAt("Return", 5, 5); 323 spt.FuzzyInstructionMatchAt("Return", 5, 5);
326 spt.FuzzyInstructionMatchAt("LoadStaticField", 7, 10); 324 spt.FuzzyInstructionMatchAt("LoadStaticField", 7, 10);
327 spt.FuzzyInstructionMatchAt("DebugStepCheck", 7, 3); 325 spt.FuzzyInstructionMatchAt("DebugStepCheck", 7, 3);
328 spt.FuzzyInstructionMatchAt("Return", 7, 3); 326 spt.FuzzyInstructionMatchAt("Return", 7, 3);
329 327
330 spt.EnsureSourcePositions(); 328 spt.EnsureSourcePositions();
331 } 329 }
332 330
333
334 TEST_CASE(SourcePosition_ForLoop) { 331 TEST_CASE(SourcePosition_ForLoop) {
335 const char* kScript = 332 const char* kScript =
336 "var x = 0;\n" 333 "var x = 0;\n"
337 "var y = 5;\n" 334 "var y = 5;\n"
338 "main() {\n" 335 "main() {\n"
339 " for (var i = 0; i < 10; i++) {\n" 336 " for (var i = 0; i < 10; i++) {\n"
340 " x += i;\n" 337 " x += i;\n"
341 " }\n" 338 " }\n"
342 " return x;\n" 339 " return x;\n"
343 "}\n"; 340 "}\n";
(...skipping 10 matching lines...) Expand all
354 spt.FuzzyInstructionMatchAt("StoreStaticField", 5, 5); 351 spt.FuzzyInstructionMatchAt("StoreStaticField", 5, 5);
355 spt.InstanceCallAt(5, 7, Token::kADD); 352 spt.InstanceCallAt(5, 7, Token::kADD);
356 spt.FuzzyInstructionMatchAt("LoadLocal", 5, 10); 353 spt.FuzzyInstructionMatchAt("LoadLocal", 5, 10);
357 spt.FuzzyInstructionMatchAt("LoadStaticField", 7, 10); 354 spt.FuzzyInstructionMatchAt("LoadStaticField", 7, 10);
358 spt.FuzzyInstructionMatchAt("DebugStepCheck", 7, 3); 355 spt.FuzzyInstructionMatchAt("DebugStepCheck", 7, 3);
359 spt.FuzzyInstructionMatchAt("Return", 7, 3); 356 spt.FuzzyInstructionMatchAt("Return", 7, 3);
360 357
361 spt.EnsureSourcePositions(); 358 spt.EnsureSourcePositions();
362 } 359 }
363 360
364
365 TEST_CASE(SourcePosition_While) { 361 TEST_CASE(SourcePosition_While) {
366 const char* kScript = 362 const char* kScript =
367 "var x = 0;\n" 363 "var x = 0;\n"
368 "var y = 5;\n" 364 "var y = 5;\n"
369 "main() {\n" 365 "main() {\n"
370 " while (x < 10) {\n" 366 " while (x < 10) {\n"
371 " if (y == 5) {\n" 367 " if (y == 5) {\n"
372 " return y;\n" 368 " return y;\n"
373 " }\n" 369 " }\n"
374 " x++;\n" 370 " x++;\n"
(...skipping 28 matching lines...) Expand all
403 spt.InstanceCallAt(8, 6, Token::kADD); 399 spt.InstanceCallAt(8, 6, Token::kADD);
404 spt.FuzzyInstructionMatchAt("StoreStaticField", 8, 5); 400 spt.FuzzyInstructionMatchAt("StoreStaticField", 8, 5);
405 401
406 spt.FuzzyInstructionMatchAt("LoadStaticField", 10, 10); 402 spt.FuzzyInstructionMatchAt("LoadStaticField", 10, 10);
407 spt.FuzzyInstructionMatchAt("DebugStepCheck", 10, 3); 403 spt.FuzzyInstructionMatchAt("DebugStepCheck", 10, 3);
408 spt.FuzzyInstructionMatchAt("Return", 10, 3); 404 spt.FuzzyInstructionMatchAt("Return", 10, 3);
409 405
410 spt.EnsureSourcePositions(); 406 spt.EnsureSourcePositions();
411 } 407 }
412 408
413
414 TEST_CASE(SourcePosition_WhileContinueBreak) { 409 TEST_CASE(SourcePosition_WhileContinueBreak) {
415 const char* kScript = 410 const char* kScript =
416 "var x = 0;\n" 411 "var x = 0;\n"
417 "var y = 5;\n" 412 "var y = 5;\n"
418 "main() {\n" 413 "main() {\n"
419 " while (x < 10) {\n" 414 " while (x < 10) {\n"
420 " if (y == 5) {\n" 415 " if (y == 5) {\n"
421 " continue;\n" 416 " continue;\n"
422 " }\n" 417 " }\n"
423 " break;\n" 418 " break;\n"
(...skipping 19 matching lines...) Expand all
443 spt.InstanceCallAt(5, 11, Token::kEQ); 438 spt.InstanceCallAt(5, 11, Token::kEQ);
444 spt.FuzzyInstructionMatchAt("Branch if StrictCompare", 5, 11); 439 spt.FuzzyInstructionMatchAt("Branch if StrictCompare", 5, 11);
445 440
446 spt.FuzzyInstructionMatchAt("LoadStaticField", 10, 10); 441 spt.FuzzyInstructionMatchAt("LoadStaticField", 10, 10);
447 spt.FuzzyInstructionMatchAt("DebugStepCheck", 10, 3); 442 spt.FuzzyInstructionMatchAt("DebugStepCheck", 10, 3);
448 spt.FuzzyInstructionMatchAt("Return", 10, 3); 443 spt.FuzzyInstructionMatchAt("Return", 10, 3);
449 444
450 spt.EnsureSourcePositions(); 445 spt.EnsureSourcePositions();
451 } 446 }
452 447
453
454 TEST_CASE(SourcePosition_LoadIndexed) { 448 TEST_CASE(SourcePosition_LoadIndexed) {
455 const char* kScript = 449 const char* kScript =
456 "var x = 0;\n" 450 "var x = 0;\n"
457 "var z = new List(3);\n" 451 "var z = new List(3);\n"
458 "main() {\n" 452 "main() {\n"
459 " z[0];\n" 453 " z[0];\n"
460 " var y = z[0] + z[1] + z[2];\n" 454 " var y = z[0] + z[1] + z[2];\n"
461 "}\n"; 455 "}\n";
462 456
463 SourcePositionTest spt(thread, kScript); 457 SourcePositionTest spt(thread, kScript);
(...skipping 18 matching lines...) Expand all
482 476
483 spt.InstanceCallAt(5, 23, Token::kADD); 477 spt.InstanceCallAt(5, 23, Token::kADD);
484 478
485 spt.FuzzyInstructionMatchAt("Constant(#null)", 6, 1); 479 spt.FuzzyInstructionMatchAt("Constant(#null)", 6, 1);
486 spt.FuzzyInstructionMatchAt("DebugStepCheck", 6, 1); 480 spt.FuzzyInstructionMatchAt("DebugStepCheck", 6, 1);
487 spt.FuzzyInstructionMatchAt("Return", 6, 1); 481 spt.FuzzyInstructionMatchAt("Return", 6, 1);
488 482
489 spt.EnsureSourcePositions(); 483 spt.EnsureSourcePositions();
490 } 484 }
491 485
492
493 TEST_CASE(SourcePosition_StoreIndexed) { 486 TEST_CASE(SourcePosition_StoreIndexed) {
494 const char* kScript = 487 const char* kScript =
495 "var x = 0;\n" 488 "var x = 0;\n"
496 "var z = new List(4);\n" 489 "var z = new List(4);\n"
497 "main() {\n" 490 "main() {\n"
498 " z[0];\n" 491 " z[0];\n"
499 " z[3] = z[0] + z[1] + z[2];\n" 492 " z[3] = z[0] + z[1] + z[2];\n"
500 "}\n"; 493 "}\n";
501 494
502 SourcePositionTest spt(thread, kScript); 495 SourcePositionTest spt(thread, kScript);
(...skipping 23 matching lines...) Expand all
526 519
527 spt.InstanceCallAt(5, 4, Token::kASSIGN_INDEX); 520 spt.InstanceCallAt(5, 4, Token::kASSIGN_INDEX);
528 521
529 spt.FuzzyInstructionMatchAt("Constant(#null)", 6, 1); 522 spt.FuzzyInstructionMatchAt("Constant(#null)", 6, 1);
530 spt.FuzzyInstructionMatchAt("DebugStepCheck", 6, 1); 523 spt.FuzzyInstructionMatchAt("DebugStepCheck", 6, 1);
531 spt.FuzzyInstructionMatchAt("Return", 6, 1); 524 spt.FuzzyInstructionMatchAt("Return", 6, 1);
532 525
533 spt.EnsureSourcePositions(); 526 spt.EnsureSourcePositions();
534 } 527 }
535 528
536
537 TEST_CASE(SourcePosition_BitwiseOperations) { 529 TEST_CASE(SourcePosition_BitwiseOperations) {
538 const char* kScript = 530 const char* kScript =
539 "var x = 0;\n" 531 "var x = 0;\n"
540 "var y = 1;\n" 532 "var y = 1;\n"
541 "main() {\n" 533 "main() {\n"
542 " var z;\n" 534 " var z;\n"
543 " z = x & y;\n" 535 " z = x & y;\n"
544 " z = x | y;\n" 536 " z = x | y;\n"
545 " z = x ^ y;\n" 537 " z = x ^ y;\n"
546 " z = ~z;\n" 538 " z = ~z;\n"
(...skipping 29 matching lines...) Expand all
576 spt.InstanceCallAt(8, 7, Token::kBIT_NOT); 568 spt.InstanceCallAt(8, 7, Token::kBIT_NOT);
577 spt.FuzzyInstructionMatchAt("StoreLocal(z", 8, 3); 569 spt.FuzzyInstructionMatchAt("StoreLocal(z", 8, 3);
578 570
579 spt.FuzzyInstructionMatchAt("LoadLocal(z", 9, 10); 571 spt.FuzzyInstructionMatchAt("LoadLocal(z", 9, 10);
580 spt.FuzzyInstructionMatchAt("DebugStepCheck", 9, 3); 572 spt.FuzzyInstructionMatchAt("DebugStepCheck", 9, 3);
581 spt.FuzzyInstructionMatchAt("Return", 9, 3); 573 spt.FuzzyInstructionMatchAt("Return", 9, 3);
582 574
583 spt.EnsureSourcePositions(); 575 spt.EnsureSourcePositions();
584 } 576 }
585 577
586
587 TEST_CASE(SourcePosition_IfElse) { 578 TEST_CASE(SourcePosition_IfElse) {
588 const char* kScript = 579 const char* kScript =
589 "var x = 5;\n" 580 "var x = 5;\n"
590 "var y = 5;\n" 581 "var y = 5;\n"
591 "main() {\n" 582 "main() {\n"
592 " if (x != 0) {\n" 583 " if (x != 0) {\n"
593 " return x;\n" 584 " return x;\n"
594 " } else {\n" 585 " } else {\n"
595 " return y;\n" 586 " return y;\n"
596 " }\n" 587 " }\n"
597 "}\n"; 588 "}\n";
598 589
599 SourcePositionTest spt(thread, kScript); 590 SourcePositionTest spt(thread, kScript);
600 spt.BuildGraphFor("main"); 591 spt.BuildGraphFor("main");
601 spt.FuzzyInstructionMatchAt("DebugStepCheck", 3, 5); 592 spt.FuzzyInstructionMatchAt("DebugStepCheck", 3, 5);
602 spt.FuzzyInstructionMatchAt("CheckStackOverflow", 3, 5); 593 spt.FuzzyInstructionMatchAt("CheckStackOverflow", 3, 5);
603 spt.FuzzyInstructionMatchAt("LoadStaticField", 4, 7); 594 spt.FuzzyInstructionMatchAt("LoadStaticField", 4, 7);
604 spt.InstanceCallAt(4, 9, Token::kEQ); 595 spt.InstanceCallAt(4, 9, Token::kEQ);
605 spt.FuzzyInstructionMatchAt("Branch if StrictCompare", 4, 9); 596 spt.FuzzyInstructionMatchAt("Branch if StrictCompare", 4, 9);
606 spt.FuzzyInstructionMatchAt("LoadStaticField", 5, 12); 597 spt.FuzzyInstructionMatchAt("LoadStaticField", 5, 12);
607 spt.FuzzyInstructionMatchAt("DebugStepCheck", 5, 5); 598 spt.FuzzyInstructionMatchAt("DebugStepCheck", 5, 5);
608 spt.FuzzyInstructionMatchAt("Return", 5, 5); 599 spt.FuzzyInstructionMatchAt("Return", 5, 5);
609 spt.FuzzyInstructionMatchAt("LoadStaticField", 7, 12); 600 spt.FuzzyInstructionMatchAt("LoadStaticField", 7, 12);
610 spt.FuzzyInstructionMatchAt("DebugStepCheck", 7, 5); 601 spt.FuzzyInstructionMatchAt("DebugStepCheck", 7, 5);
611 spt.FuzzyInstructionMatchAt("Return", 7, 5); 602 spt.FuzzyInstructionMatchAt("Return", 7, 5);
612 603
613 spt.EnsureSourcePositions(); 604 spt.EnsureSourcePositions();
614 } 605 }
615 606
616
617 TEST_CASE(SourcePosition_Switch) { 607 TEST_CASE(SourcePosition_Switch) {
618 const char* kScript = 608 const char* kScript =
619 "var x = 5;\n" 609 "var x = 5;\n"
620 "var y = 5;\n" 610 "var y = 5;\n"
621 "main() {\n" 611 "main() {\n"
622 " switch (x) {\n" 612 " switch (x) {\n"
623 " case 1: return 3;\n" 613 " case 1: return 3;\n"
624 " case 2: return 4;\n" 614 " case 2: return 4;\n"
625 " default: return 5;\n" 615 " default: return 5;\n"
626 " }\n" 616 " }\n"
627 "}\n"; 617 "}\n";
628 618
629
630 SourcePositionTest spt(thread, kScript); 619 SourcePositionTest spt(thread, kScript);
631 spt.BuildGraphFor("main"); 620 spt.BuildGraphFor("main");
632 621
633 spt.FuzzyInstructionMatchAt("DebugStepCheck", 3, 5); 622 spt.FuzzyInstructionMatchAt("DebugStepCheck", 3, 5);
634 spt.FuzzyInstructionMatchAt("CheckStackOverflow", 3, 5); 623 spt.FuzzyInstructionMatchAt("CheckStackOverflow", 3, 5);
635 spt.FuzzyInstructionMatchAt("Constant(#Field", 4, 11); 624 spt.FuzzyInstructionMatchAt("Constant(#Field", 4, 11);
636 spt.FuzzyInstructionMatchAt("LoadStaticField", 4, 11); 625 spt.FuzzyInstructionMatchAt("LoadStaticField", 4, 11);
637 spt.FuzzyInstructionMatchAt("StoreLocal(:switch_expr", 4, 11); 626 spt.FuzzyInstructionMatchAt("StoreLocal(:switch_expr", 4, 11);
638 627
639 spt.FuzzyInstructionMatchAt("Constant(#1", 5, 10); 628 spt.FuzzyInstructionMatchAt("Constant(#1", 5, 10);
(...skipping 12 matching lines...) Expand all
652 spt.FuzzyInstructionMatchAt("DebugStepCheck", 6, 13); 641 spt.FuzzyInstructionMatchAt("DebugStepCheck", 6, 13);
653 spt.FuzzyInstructionMatchAt("Return", 6, 13); 642 spt.FuzzyInstructionMatchAt("Return", 6, 13);
654 643
655 spt.FuzzyInstructionMatchAt("Constant(#5", 7, 21); // '5' 644 spt.FuzzyInstructionMatchAt("Constant(#5", 7, 21); // '5'
656 spt.FuzzyInstructionMatchAt("DebugStepCheck", 7, 14); 645 spt.FuzzyInstructionMatchAt("DebugStepCheck", 7, 14);
657 spt.FuzzyInstructionMatchAt("Return", 7, 14); 646 spt.FuzzyInstructionMatchAt("Return", 7, 14);
658 647
659 spt.EnsureSourcePositions(); 648 spt.EnsureSourcePositions();
660 } 649 }
661 650
662
663 TEST_CASE(SourcePosition_TryCatchFinally) { 651 TEST_CASE(SourcePosition_TryCatchFinally) {
664 const char* kScript = 652 const char* kScript =
665 "var x = 5;\n" 653 "var x = 5;\n"
666 "var y = 5;\n" 654 "var y = 5;\n"
667 "main() {\n" 655 "main() {\n"
668 " try {\n" 656 " try {\n"
669 " throw 'A';\n" 657 " throw 'A';\n"
670 " } catch (e) {\n" 658 " } catch (e) {\n"
671 " print(e);\n" 659 " print(e);\n"
672 " return 77;\n" 660 " return 77;\n"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 692
705 spt.FuzzyInstructionMatchAt("LoadLocal(:saved_try_context", 9, 13); // '{' 693 spt.FuzzyInstructionMatchAt("LoadLocal(:saved_try_context", 9, 13); // '{'
706 spt.FuzzyInstructionMatchAt("StoreLocal(:current_context", 9, 13); // '{' 694 spt.FuzzyInstructionMatchAt("StoreLocal(:current_context", 9, 13); // '{'
707 695
708 spt.FuzzyInstructionMatchAt("Constant(#99", 10, 12); // '9' 696 spt.FuzzyInstructionMatchAt("Constant(#99", 10, 12); // '9'
709 spt.FuzzyInstructionMatchAt("Return", 10, 5); // 'r' 697 spt.FuzzyInstructionMatchAt("Return", 10, 5); // 'r'
710 698
711 spt.EnsureSourcePositions(); 699 spt.EnsureSourcePositions();
712 } 700 }
713 701
714
715 TEST_CASE(SourcePosition_InstanceFields) { 702 TEST_CASE(SourcePosition_InstanceFields) {
716 const char* kScript = 703 const char* kScript =
717 "class A {\n" 704 "class A {\n"
718 " var x;\n" 705 " var x;\n"
719 " var y;\n" 706 " var y;\n"
720 "}\n" 707 "}\n"
721 "main() {\n" 708 "main() {\n"
722 " var z = new A();\n" 709 " var z = new A();\n"
723 " z.x = 99;\n" 710 " z.x = 99;\n"
724 " z.y = z.x;\n" 711 " z.y = z.x;\n"
725 " return z.y;\n" 712 " return z.y;\n"
726 "}\n"; 713 "}\n";
727 714
728 SourcePositionTest spt(thread, kScript); 715 SourcePositionTest spt(thread, kScript);
729 spt.BuildGraphFor("main"); 716 spt.BuildGraphFor("main");
730 spt.FuzzyInstructionMatchAt("AllocateObject(A)", 6, 15); // 'A' 717 spt.FuzzyInstructionMatchAt("AllocateObject(A)", 6, 15); // 'A'
731 spt.FuzzyInstructionMatchAt("StaticCall", 6, 15); // 'A' 718 spt.FuzzyInstructionMatchAt("StaticCall", 6, 15); // 'A'
732 spt.FuzzyInstructionMatchAt("StoreLocal(z", 6, 9); // '=' 719 spt.FuzzyInstructionMatchAt("StoreLocal(z", 6, 9); // '='
733 spt.InstanceCallAt("set:x", 7, 5); // 'x' 720 spt.InstanceCallAt("set:x", 7, 5); // 'x'
734 spt.InstanceCallAt("get:x", 8, 11); // 'x' 721 spt.InstanceCallAt("get:x", 8, 11); // 'x'
735 spt.InstanceCallAt("set:y", 8, 5); // 'y' 722 spt.InstanceCallAt("set:y", 8, 5); // 'y'
736 723
737 spt.InstanceCallAt("get:y", 9, 12); // 'y' 724 spt.InstanceCallAt("get:y", 9, 12); // 'y'
738 spt.FuzzyInstructionMatchAt("DebugStepCheck", 9, 3); 725 spt.FuzzyInstructionMatchAt("DebugStepCheck", 9, 3);
739 spt.FuzzyInstructionMatchAt("Return", 9, 3); 726 spt.FuzzyInstructionMatchAt("Return", 9, 3);
740 727
741 spt.EnsureSourcePositions(); 728 spt.EnsureSourcePositions();
742 } 729 }
743 730
744
745 TEST_CASE(SourcePosition_Async) { 731 TEST_CASE(SourcePosition_Async) {
746 const char* kScript = 732 const char* kScript =
747 "import 'dart:async';\n" 733 "import 'dart:async';\n"
748 "var x = 5;\n" 734 "var x = 5;\n"
749 "var y = 5;\n" 735 "var y = 5;\n"
750 "foo(Future f1, Future f2) async {\n" 736 "foo(Future f1, Future f2) async {\n"
751 " await f1;\n" 737 " await f1;\n"
752 " await f2;\n" 738 " await f2;\n"
753 " return 55;\n" 739 " return 55;\n"
754 "}\n" 740 "}\n"
755 "main() {\n" 741 "main() {\n"
756 " foo(new Future.value(33));\n" 742 " foo(new Future.value(33));\n"
757 "}\n"; 743 "}\n";
758 744
759 SourcePositionTest spt(thread, kScript); 745 SourcePositionTest spt(thread, kScript);
760 spt.BuildGraphFor("foo"); 746 spt.BuildGraphFor("foo");
761 spt.EnsureSourcePositions(); 747 spt.EnsureSourcePositions();
762 spt.Dump(); 748 spt.Dump();
763 } 749 }
764 750
765 #endif // !PRODUCT 751 #endif // !PRODUCT
766 752
767 static bool SyntheticRoundTripTest(TokenPosition token_pos) { 753 static bool SyntheticRoundTripTest(TokenPosition token_pos) {
768 const TokenPosition synthetic_token_pos = token_pos.ToSynthetic(); 754 const TokenPosition synthetic_token_pos = token_pos.ToSynthetic();
769 return synthetic_token_pos.FromSynthetic() == token_pos; 755 return synthetic_token_pos.FromSynthetic() == token_pos;
770 } 756 }
771 757
772
773 VM_UNIT_TEST_CASE(SourcePosition_SyntheticTokens) { 758 VM_UNIT_TEST_CASE(SourcePosition_SyntheticTokens) {
774 EXPECT(TokenPosition::kNoSourcePos == -1); 759 EXPECT(TokenPosition::kNoSourcePos == -1);
775 EXPECT(TokenPosition::kMinSourcePos == 0); 760 EXPECT(TokenPosition::kMinSourcePos == 0);
776 EXPECT(TokenPosition::kMaxSourcePos > 0); 761 EXPECT(TokenPosition::kMaxSourcePos > 0);
777 EXPECT(TokenPosition::kMaxSourcePos > TokenPosition::kMinSourcePos); 762 EXPECT(TokenPosition::kMaxSourcePos > TokenPosition::kMinSourcePos);
778 EXPECT(TokenPosition::kMinSource.value() == TokenPosition::kMinSourcePos); 763 EXPECT(TokenPosition::kMinSource.value() == TokenPosition::kMinSourcePos);
779 EXPECT(TokenPosition::kMaxSource.value() == TokenPosition::kMaxSourcePos); 764 EXPECT(TokenPosition::kMaxSource.value() == TokenPosition::kMaxSourcePos);
780 EXPECT(!TokenPosition(0).IsSynthetic()); 765 EXPECT(!TokenPosition(0).IsSynthetic());
781 EXPECT(TokenPosition(0).ToSynthetic().IsSynthetic()); 766 EXPECT(TokenPosition(0).ToSynthetic().IsSynthetic());
782 EXPECT(TokenPosition(9).ToSynthetic().IsSynthetic()); 767 EXPECT(TokenPosition(9).ToSynthetic().IsSynthetic());
783 EXPECT(!TokenPosition(-1).FromSynthetic().IsSynthetic()); 768 EXPECT(!TokenPosition(-1).FromSynthetic().IsSynthetic());
784 EXPECT(!TokenPosition::kNoSource.IsSynthetic()); 769 EXPECT(!TokenPosition::kNoSource.IsSynthetic());
785 EXPECT(!TokenPosition::kLast.IsSynthetic()); 770 EXPECT(!TokenPosition::kLast.IsSynthetic());
786 EXPECT(SyntheticRoundTripTest(TokenPosition(0))); 771 EXPECT(SyntheticRoundTripTest(TokenPosition(0)));
787 EXPECT(SyntheticRoundTripTest(TokenPosition::kMaxSource)); 772 EXPECT(SyntheticRoundTripTest(TokenPosition::kMaxSource));
788 EXPECT(SyntheticRoundTripTest(TokenPosition::kMinSource)); 773 EXPECT(SyntheticRoundTripTest(TokenPosition::kMinSource));
789 } 774 }
790 775
791 } // namespace dart 776 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/flow_graph_builder.cc ('k') | runtime/vm/flow_graph_compiler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698