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

Side by Side Diff: tests/compiler/dart2js/semantic_visitor_test.dart

Issue 1043723002: Handle NewExpression in SemanticSendVisitor. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebased+fix modely.dart Created 5 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « pkg/compiler/lib/src/resolved_visitor.dart ('k') | no next file » | 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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 library dart2js.semantics_visitor_test; 5 library dart2js.semantics_visitor_test;
6 6
7 import 'dart:async';
7 import 'package:async_helper/async_helper.dart'; 8 import 'package:async_helper/async_helper.dart';
8 import 'package:expect/expect.dart'; 9 import 'package:expect/expect.dart';
9 import 'package:compiler/src/constants/expressions.dart'; 10 import 'package:compiler/src/constants/expressions.dart';
10 import 'package:compiler/src/dart_types.dart'; 11 import 'package:compiler/src/dart_types.dart';
11 import 'package:compiler/src/dart2jslib.dart'; 12 import 'package:compiler/src/dart2jslib.dart';
12 import 'package:compiler/src/elements/elements.dart'; 13 import 'package:compiler/src/elements/elements.dart';
13 import 'package:compiler/src/resolution/resolution.dart'; 14 import 'package:compiler/src/resolution/resolution.dart';
14 import 'package:compiler/src/resolution/semantic_visitor.dart'; 15 import 'package:compiler/src/resolution/semantic_visitor.dart';
15 import 'package:compiler/src/resolution/operators.dart'; 16 import 'package:compiler/src/resolution/operators.dart';
16 import 'package:compiler/src/tree/tree.dart'; 17 import 'package:compiler/src/tree/tree.dart';
(...skipping 10 matching lines...) Expand all
27 final expression; 28 final expression;
28 final left; 29 final left;
29 final right; 30 final right;
30 final type; 31 final type;
31 final operator; 32 final operator;
32 final index; 33 final index;
33 final getter; 34 final getter;
34 final setter; 35 final setter;
35 final constant; 36 final constant;
36 final selector; 37 final selector;
38 final parameters;
39 final body;
40 final target;
41 final targetType;
42 final initializers;
37 43
38 const Visit(this.method, 44 const Visit(this.method,
39 {this.element, 45 {this.element,
40 this.rhs, 46 this.rhs,
41 this.arguments, 47 this.arguments,
42 this.receiver, 48 this.receiver,
43 this.name, 49 this.name,
44 this.expression, 50 this.expression,
45 this.left, 51 this.left,
46 this.right, 52 this.right,
47 this.type, 53 this.type,
48 this.operator, 54 this.operator,
49 this.index, 55 this.index,
50 this.getter, 56 this.getter,
51 this.setter, 57 this.setter,
52 this.constant, 58 this.constant,
53 this.selector}); 59 this.selector,
60 this.parameters,
61 this.body,
62 this.target,
63 this.targetType,
64 this.initializers});
54 65
55 int get hashCode => toString().hashCode; 66 int get hashCode => toString().hashCode;
56 67
57 bool operator ==(other) => '$this' == '$other'; 68 bool operator ==(other) => '$this' == '$other';
58 69
59 String toString() { 70 String toString() {
60 StringBuffer sb = new StringBuffer(); 71 StringBuffer sb = new StringBuffer();
61 sb.write('method=$method'); 72 sb.write('method=$method');
62 if (element != null) { 73 if (element != null) {
63 sb.write(',element=$element'); 74 sb.write(',element=$element');
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 } 108 }
98 if (setter != null) { 109 if (setter != null) {
99 sb.write(',setter=$setter'); 110 sb.write(',setter=$setter');
100 } 111 }
101 if (constant != null) { 112 if (constant != null) {
102 sb.write(',constant=$constant'); 113 sb.write(',constant=$constant');
103 } 114 }
104 if (selector != null) { 115 if (selector != null) {
105 sb.write(',selector=$selector'); 116 sb.write(',selector=$selector');
106 } 117 }
118 if (parameters != null) {
119 sb.write(',parameters=$parameters');
120 }
121 if (body != null) {
122 sb.write(',body=$body');
123 }
124 if (target != null) {
125 sb.write(',target=$target');
126 }
127 if (targetType != null) {
128 sb.write(',targetType=$targetType');
129 }
130 if (initializers != null) {
131 sb.write(',initializers=$initializers');
132 }
107 return sb.toString(); 133 return sb.toString();
108 } 134 }
109 } 135 }
110 136
111 class Test { 137 class Test {
112 final String codeByPrefix; 138 final String codeByPrefix;
113 final String code; 139 final String code;
114 final /*Visit | List<Visit>*/ expectedVisits; 140 final /*Visit | List<Visit>*/ expectedVisits;
115 final String cls; 141 final String cls;
142 final String method;
116 143
117 const Test(this.code, this.expectedVisits) 144 const Test(this.code, this.expectedVisits)
118 : cls = null, codeByPrefix = null; 145 : cls = null, method = 'm', codeByPrefix = null;
119 const Test.clazz(this.code, this.expectedVisits) 146 const Test.clazz(this.code, this.expectedVisits,
120 : cls = 'C', codeByPrefix = null; 147 {this.cls: 'C', this.method: 'm'})
148 : codeByPrefix = null;
121 const Test.prefix(this.codeByPrefix, this.code, this.expectedVisits) 149 const Test.prefix(this.codeByPrefix, this.code, this.expectedVisits)
122 : cls = null; 150 : cls = null, method = 'm';
123
124 String get method => 'm';
125 151
126 String toString() { 152 String toString() {
127 StringBuffer sb = new StringBuffer(); 153 StringBuffer sb = new StringBuffer();
128 sb.writeln(); 154 sb.writeln();
129 sb.writeln(code); 155 sb.writeln(code);
130 if (codeByPrefix != null) { 156 if (codeByPrefix != null) {
131 sb.writeln('imported by prefix:'); 157 sb.writeln('imported by prefix:');
132 sb.writeln(codeByPrefix); 158 sb.writeln(codeByPrefix);
133 } 159 }
134 return sb.toString(); 160 return sb.toString();
135 } 161 }
136 } 162 }
137 163
138 const List<Test> TESTS = const [ 164 const Map<String, List<Test>> SEND_TESTS = const {
165 'Parameters': const [
139 // Parameters 166 // Parameters
140 const Test('m(o) => o;', 167 const Test('m(o) => o;',
141 const Visit(VisitKind.VISIT_PARAMETER_GET, 168 const Visit(VisitKind.VISIT_PARAMETER_GET,
142 element: 'parameter(m#o)')), 169 element: 'parameter(m#o)')),
143 const Test('m(o) { o = 42; }', 170 const Test('m(o) { o = 42; }',
144 const Visit(VisitKind.VISIT_PARAMETER_SET, 171 const Visit(VisitKind.VISIT_PARAMETER_SET,
145 element: 'parameter(m#o)', 172 element: 'parameter(m#o)',
146 rhs:'42')), 173 rhs:'42')),
147 const Test('m(o) { o(null, 42); }', 174 const Test('m(o) { o(null, 42); }',
148 const Visit(VisitKind.VISIT_PARAMETER_INVOKE, 175 const Visit(VisitKind.VISIT_PARAMETER_INVOKE,
149 element: 'parameter(m#o)', 176 element: 'parameter(m#o)',
150 arguments: '(null,42)', 177 arguments: '(null,42)',
151 selector: 'Selector(call, call, arity=2)')), 178 selector: 'Selector(call, call, arity=2)')),
152 179 ],
180 'Local variables': const [
153 // Local variables 181 // Local variables
154 const Test('m() { var o; return o; }', 182 const Test('m() { var o; return o; }',
155 const Visit(VisitKind.VISIT_LOCAL_VARIABLE_GET, 183 const Visit(VisitKind.VISIT_LOCAL_VARIABLE_GET,
156 element: 'variable(m#o)')), 184 element: 'variable(m#o)')),
157 const Test('m() { var o; o = 42; }', 185 const Test('m() { var o; o = 42; }',
158 const Visit(VisitKind.VISIT_LOCAL_VARIABLE_SET, 186 const Visit(VisitKind.VISIT_LOCAL_VARIABLE_SET,
159 element: 'variable(m#o)', 187 element: 'variable(m#o)',
160 rhs:'42')), 188 rhs:'42')),
161 const Test('m() { var o; o(null, 42); }', 189 const Test('m() { var o; o(null, 42); }',
162 const Visit(VisitKind.VISIT_LOCAL_VARIABLE_INVOKE, 190 const Visit(VisitKind.VISIT_LOCAL_VARIABLE_INVOKE,
163 element: 'variable(m#o)', 191 element: 'variable(m#o)',
164 arguments: '(null,42)', 192 arguments: '(null,42)',
165 selector: 'Selector(call, call, arity=2)')), 193 selector: 'Selector(call, call, arity=2)')),
166 194 ],
195 'Local functions': const [
167 // Local functions 196 // Local functions
168 const Test('m() { o(a, b) {}; return o; }', 197 const Test('m() { o(a, b) {}; return o; }',
169 const Visit(VisitKind.VISIT_LOCAL_FUNCTION_GET, 198 const Visit(VisitKind.VISIT_LOCAL_FUNCTION_GET,
170 element: 'function(m#o)')), 199 element: 'function(m#o)')),
171 const Test('m() { o(a, b) {}; o(null, 42); }', 200 const Test('m() { o(a, b) {}; o(null, 42); }',
172 const Visit(VisitKind.VISIT_LOCAL_FUNCTION_INVOKE, 201 const Visit(VisitKind.VISIT_LOCAL_FUNCTION_INVOKE,
173 element: 'function(m#o)', 202 element: 'function(m#o)',
174 arguments: '(null,42)', 203 arguments: '(null,42)',
175 selector: 'Selector(call, call, arity=2)')), 204 selector: 'Selector(call, call, arity=2)')),
176 205 ],
206 'Static fields': const [
177 // Static fields 207 // Static fields
178 const Test( 208 const Test(
179 ''' 209 '''
180 class C { static var o; } 210 class C { static var o; }
181 m() => C.o; 211 m() => C.o;
182 ''', 212 ''',
183 const Visit(VisitKind.VISIT_STATIC_FIELD_GET, 213 const Visit(VisitKind.VISIT_STATIC_FIELD_GET,
184 element: 'field(C#o)')), 214 element: 'field(C#o)')),
185 const Test.clazz( 215 const Test.clazz(
186 ''' 216 '''
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 const Test.prefix( 308 const Test.prefix(
279 ''' 309 '''
280 class C { 310 class C {
281 static var o; 311 static var o;
282 } 312 }
283 ''', 313 ''',
284 'm() { p.C.o(null, 42); }', 314 'm() { p.C.o(null, 42); }',
285 const Visit(VisitKind.VISIT_STATIC_FIELD_INVOKE, 315 const Visit(VisitKind.VISIT_STATIC_FIELD_INVOKE,
286 element: 'field(C#o)', 316 element: 'field(C#o)',
287 arguments: '(null,42)')), 317 arguments: '(null,42)')),
288 318 ],
319 'Static properties': const [
289 // Static properties 320 // Static properties
290 const Test( 321 const Test(
291 ''' 322 '''
292 class C { 323 class C {
293 static get o => null; 324 static get o => null;
294 } 325 }
295 m() => C.o; 326 m() => C.o;
296 ''', 327 ''',
297 const Visit(VisitKind.VISIT_STATIC_GETTER_GET, 328 const Visit(VisitKind.VISIT_STATIC_GETTER_GET,
298 element: 'getter(C#o)')), 329 element: 'getter(C#o)')),
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 const Test.prefix( 423 const Test.prefix(
393 ''' 424 '''
394 class C { 425 class C {
395 static get o => null; 426 static get o => null;
396 } 427 }
397 ''', 428 ''',
398 'm() { p.C.o(null, 42); }', 429 'm() { p.C.o(null, 42); }',
399 const Visit(VisitKind.VISIT_STATIC_GETTER_INVOKE, 430 const Visit(VisitKind.VISIT_STATIC_GETTER_INVOKE,
400 element: 'getter(C#o)', 431 element: 'getter(C#o)',
401 arguments: '(null,42)')), 432 arguments: '(null,42)')),
402 433 ],
434 'Static functions': const [
403 // Static functions 435 // Static functions
404 const Test( 436 const Test(
405 ''' 437 '''
406 class C { static o(a, b) {} } 438 class C { static o(a, b) {} }
407 m() => C.o; 439 m() => C.o;
408 ''', 440 ''',
409 const Visit(VisitKind.VISIT_STATIC_FUNCTION_GET, 441 const Visit(VisitKind.VISIT_STATIC_FUNCTION_GET,
410 element: 'function(C#o)')), 442 element: 'function(C#o)')),
411 const Test.clazz( 443 const Test.clazz(
412 ''' 444 '''
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 const Test.prefix( 498 const Test.prefix(
467 ''' 499 '''
468 class C { 500 class C {
469 static o(a, b) {} 501 static o(a, b) {}
470 } 502 }
471 ''', 503 ''',
472 'm() { p.C.o(null, 42); }', 504 'm() { p.C.o(null, 42); }',
473 const Visit(VisitKind.VISIT_STATIC_FUNCTION_INVOKE, 505 const Visit(VisitKind.VISIT_STATIC_FUNCTION_INVOKE,
474 element: 'function(C#o)', 506 element: 'function(C#o)',
475 arguments: '(null,42)')), 507 arguments: '(null,42)')),
476 508 ],
509 'Top level fields': const [
477 // Top level fields 510 // Top level fields
478 const Test( 511 const Test(
479 ''' 512 '''
480 var o; 513 var o;
481 m() => o; 514 m() => o;
482 ''', 515 ''',
483 const Visit(VisitKind.VISIT_TOP_LEVEL_FIELD_GET, 516 const Visit(VisitKind.VISIT_TOP_LEVEL_FIELD_GET,
484 element: 'field(o)')), 517 element: 'field(o)')),
485 const Test.prefix( 518 const Test.prefix(
486 ''' 519 '''
(...skipping 27 matching lines...) Expand all
514 element: 'field(o)', 547 element: 'field(o)',
515 arguments: '(null,42)')), 548 arguments: '(null,42)')),
516 const Test.prefix( 549 const Test.prefix(
517 ''' 550 '''
518 var o; 551 var o;
519 ''', 552 ''',
520 'm() { p.o(null, 42); }', 553 'm() { p.o(null, 42); }',
521 const Visit(VisitKind.VISIT_TOP_LEVEL_FIELD_INVOKE, 554 const Visit(VisitKind.VISIT_TOP_LEVEL_FIELD_INVOKE,
522 element: 'field(o)', 555 element: 'field(o)',
523 arguments: '(null,42)')), 556 arguments: '(null,42)')),
524 557 ],
558 'Top level properties': const [
525 // Top level properties 559 // Top level properties
526 const Test( 560 const Test(
527 ''' 561 '''
528 get o => null; 562 get o => null;
529 m() => o; 563 m() => o;
530 ''', 564 ''',
531 const Visit(VisitKind.VISIT_TOP_LEVEL_GETTER_GET, 565 const Visit(VisitKind.VISIT_TOP_LEVEL_GETTER_GET,
532 element: 'getter(o)')), 566 element: 'getter(o)')),
533 const Test.prefix( 567 const Test.prefix(
534 ''' 568 '''
(...skipping 29 matching lines...) Expand all
564 element: 'getter(o)', 598 element: 'getter(o)',
565 arguments: '(null,42)')), 599 arguments: '(null,42)')),
566 const Test.prefix( 600 const Test.prefix(
567 ''' 601 '''
568 get o => null; 602 get o => null;
569 ''', 603 ''',
570 'm() { p.o(null, 42); }', 604 'm() { p.o(null, 42); }',
571 const Visit(VisitKind.VISIT_TOP_LEVEL_GETTER_INVOKE, 605 const Visit(VisitKind.VISIT_TOP_LEVEL_GETTER_INVOKE,
572 element: 'getter(o)', 606 element: 'getter(o)',
573 arguments: '(null,42)')), 607 arguments: '(null,42)')),
574 608 ],
609 'Top level functions': const [
575 // Top level functions 610 // Top level functions
576 const Test( 611 const Test(
577 ''' 612 '''
578 o(a, b) {} 613 o(a, b) {}
579 m() => o; 614 m() => o;
580 ''', 615 ''',
581 const Visit(VisitKind.VISIT_TOP_LEVEL_FUNCTION_GET, 616 const Visit(VisitKind.VISIT_TOP_LEVEL_FUNCTION_GET,
582 element: 'function(o)')), 617 element: 'function(o)')),
583 const Test( 618 const Test(
584 ''' 619 '''
585 o(a, b) {} 620 o(a, b) {}
586 m() => o(null, 42); 621 m() => o(null, 42);
587 ''', 622 ''',
588 const Visit(VisitKind.VISIT_TOP_LEVEL_FUNCTION_INVOKE, 623 const Visit(VisitKind.VISIT_TOP_LEVEL_FUNCTION_INVOKE,
589 element: 'function(o)', 624 element: 'function(o)',
590 arguments: '(null,42)')), 625 arguments: '(null,42)')),
591 const Test.prefix( 626 const Test.prefix(
592 ''' 627 '''
593 o(a, b) {} 628 o(a, b) {}
594 ''', 629 ''',
595 'm() { p.o(null, 42); }', 630 'm() { p.o(null, 42); }',
596 const Visit(VisitKind.VISIT_TOP_LEVEL_FUNCTION_INVOKE, 631 const Visit(VisitKind.VISIT_TOP_LEVEL_FUNCTION_INVOKE,
597 element: 'function(o)', 632 element: 'function(o)',
598 arguments: '(null,42)')), 633 arguments: '(null,42)')),
599 634 ],
635 'Dynamic properties': const [
600 // Dynamic properties 636 // Dynamic properties
601 const Test('m(o) => o.foo;', 637 const Test('m(o) => o.foo;',
602 const Visit(VisitKind.VISIT_DYNAMIC_PROPERTY_GET, 638 const [
603 receiver: 'o', 639 const Visit(VisitKind.VISIT_DYNAMIC_PROPERTY_GET,
604 name: 'foo')), 640 receiver: 'o',
641 name: 'foo'),
642 const Visit(VisitKind.VISIT_PARAMETER_GET,
643 element: 'parameter(m#o)'),
644 ]),
605 const Test('m(o) { o.foo = 42; }', 645 const Test('m(o) { o.foo = 42; }',
606 const Visit(VisitKind.VISIT_DYNAMIC_PROPERTY_SET, 646 const [
607 receiver: 'o', 647 const Visit(VisitKind.VISIT_DYNAMIC_PROPERTY_SET,
608 name: 'foo', 648 receiver: 'o',
609 rhs: '42')), 649 name: 'foo',
650 rhs: '42'),
651 const Visit(VisitKind.VISIT_PARAMETER_GET,
652 element: 'parameter(m#o)'),
653 ]),
610 const Test('m(o) { o.foo(null, 42); }', 654 const Test('m(o) { o.foo(null, 42); }',
611 const Visit(VisitKind.VISIT_DYNAMIC_PROPERTY_INVOKE, 655 const [
612 receiver: 'o', 656 const Visit(VisitKind.VISIT_DYNAMIC_PROPERTY_INVOKE,
613 name: 'foo', 657 receiver: 'o',
614 arguments: '(null,42)')), 658 name: 'foo',
615 659 arguments: '(null,42)'),
660 const Visit(VisitKind.VISIT_PARAMETER_GET,
661 element: 'parameter(m#o)'),
662 ]),
663 ],
664 'This access': const [
616 // This access 665 // This access
617 const Test.clazz( 666 const Test.clazz(
618 ''' 667 '''
619 class C { 668 class C {
620 m() => this; 669 m() => this;
621 } 670 }
622 ''', 671 ''',
623 const Visit(VisitKind.VISIT_THIS_GET)), 672 const Visit(VisitKind.VISIT_THIS_GET)),
624 const Test.clazz( 673 const Test.clazz(
625 ''' 674 '''
626 class C { 675 class C {
627 call(a, b) {} 676 call(a, b) {}
628 m() { this(null, 42); } 677 m() { this(null, 42); }
629 } 678 }
630 ''', 679 ''',
631 const Visit(VisitKind.VISIT_THIS_INVOKE, 680 const Visit(VisitKind.VISIT_THIS_INVOKE,
632 arguments: '(null,42)')), 681 arguments: '(null,42)')),
633 682 ],
683 'This properties': const [
634 // This properties 684 // This properties
635 const Test.clazz( 685 const Test.clazz(
636 ''' 686 '''
637 class C { 687 class C {
638 var foo; 688 var foo;
639 m() => foo; 689 m() => foo;
640 } 690 }
641 ''', 691 ''',
642 const Visit(VisitKind.VISIT_THIS_PROPERTY_GET, 692 const Visit(VisitKind.VISIT_THIS_PROPERTY_GET,
643 name: 'foo')), 693 name: 'foo')),
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 const Test.clazz( 771 const Test.clazz(
722 ''' 772 '''
723 class C { 773 class C {
724 var foo; 774 var foo;
725 m() { this.foo(null, 42); } 775 m() { this.foo(null, 42); }
726 } 776 }
727 ''', 777 ''',
728 const Visit(VisitKind.VISIT_THIS_PROPERTY_INVOKE, 778 const Visit(VisitKind.VISIT_THIS_PROPERTY_INVOKE,
729 name: 'foo', 779 name: 'foo',
730 arguments: '(null,42)')), 780 arguments: '(null,42)')),
731 781 ],
782 'Super fields': const [
732 // Super fields 783 // Super fields
733 const Test.clazz( 784 const Test.clazz(
734 ''' 785 '''
735 class B { 786 class B {
736 var o; 787 var o;
737 } 788 }
738 class C extends B { 789 class C extends B {
739 m() => super.o; 790 m() => super.o;
740 } 791 }
741 ''', 792 ''',
(...skipping 16 matching lines...) Expand all
758 class B { 809 class B {
759 var o; 810 var o;
760 } 811 }
761 class C extends B { 812 class C extends B {
762 m() { super.o(null, 42); } 813 m() { super.o(null, 42); }
763 } 814 }
764 ''', 815 ''',
765 const Visit(VisitKind.VISIT_SUPER_FIELD_INVOKE, 816 const Visit(VisitKind.VISIT_SUPER_FIELD_INVOKE,
766 element: 'field(B#o)', 817 element: 'field(B#o)',
767 arguments: '(null,42)')), 818 arguments: '(null,42)')),
768 819 ],
820 'Super properties': const [
769 // Super properties 821 // Super properties
770 const Test.clazz( 822 const Test.clazz(
771 ''' 823 '''
772 class B { 824 class B {
773 get o => null; 825 get o => null;
774 } 826 }
775 class C extends B { 827 class C extends B {
776 m() => super.o; 828 m() => super.o;
777 } 829 }
778 ''', 830 ''',
(...skipping 16 matching lines...) Expand all
795 class B { 847 class B {
796 get o => null; 848 get o => null;
797 } 849 }
798 class C extends B { 850 class C extends B {
799 m() { super.o(null, 42); } 851 m() { super.o(null, 42); }
800 } 852 }
801 ''', 853 ''',
802 const Visit(VisitKind.VISIT_SUPER_GETTER_INVOKE, 854 const Visit(VisitKind.VISIT_SUPER_GETTER_INVOKE,
803 element: 'getter(B#o)', 855 element: 'getter(B#o)',
804 arguments: '(null,42)')), 856 arguments: '(null,42)')),
805 857 ],
858 'Super methods': const [
806 // Super methods 859 // Super methods
807 const Test.clazz( 860 const Test.clazz(
808 ''' 861 '''
809 class B { 862 class B {
810 o(a, b) {} 863 o(a, b) {}
811 } 864 }
812 class C extends B { 865 class C extends B {
813 m() => super.o; 866 m() => super.o;
814 } 867 }
815 ''', 868 ''',
816 const Visit(VisitKind.VISIT_SUPER_METHOD_GET, 869 const Visit(VisitKind.VISIT_SUPER_METHOD_GET,
817 element: 'function(B#o)')), 870 element: 'function(B#o)')),
818 const Test.clazz( 871 const Test.clazz(
819 ''' 872 '''
820 class B { 873 class B {
821 o(a, b) {} 874 o(a, b) {}
822 } 875 }
823 class C extends B { 876 class C extends B {
824 m() { super.o(null, 42); } 877 m() { super.o(null, 42); }
825 } 878 }
826 ''', 879 ''',
827 const Visit(VisitKind.VISIT_SUPER_METHOD_INVOKE, 880 const Visit(VisitKind.VISIT_SUPER_METHOD_INVOKE,
828 element: 'function(B#o)', 881 element: 'function(B#o)',
829 arguments: '(null,42)')), 882 arguments: '(null,42)')),
830 883 ],
884 'Expression invoke': const [
831 // Expression invoke 885 // Expression invoke
832 const Test('m() => (a, b){}(null, 42);', 886 const Test('m() => (a, b){}(null, 42);',
833 const Visit(VisitKind.VISIT_EXPRESSION_INVOKE, 887 const Visit(VisitKind.VISIT_EXPRESSION_INVOKE,
834 receiver: '(a,b){}', 888 receiver: '(a,b){}',
835 arguments: '(null,42)')), 889 arguments: '(null,42)')),
836 890 ],
891 'Class type literals': const [
837 // Class type literals 892 // Class type literals
838 const Test( 893 const Test(
839 ''' 894 '''
840 class C {} 895 class C {}
841 m() => C; 896 m() => C;
842 ''', 897 ''',
843 const Visit(VisitKind.VISIT_CLASS_TYPE_LITERAL_GET, 898 const Visit(VisitKind.VISIT_CLASS_TYPE_LITERAL_GET,
844 constant: 'C')), 899 constant: 'C')),
845 const Test( 900 const Test(
846 ''' 901 '''
847 class C {} 902 class C {}
848 m() => C(null, 42); 903 m() => C(null, 42);
849 ''', 904 ''',
850 const Visit(VisitKind.VISIT_CLASS_TYPE_LITERAL_INVOKE, 905 const Visit(VisitKind.VISIT_CLASS_TYPE_LITERAL_INVOKE,
851 constant: 'C', 906 constant: 'C',
852 arguments: '(null,42)')), 907 arguments: '(null,42)')),
853 908 ],
909 'Typedef type literals': const [
854 // Typedef type literals 910 // Typedef type literals
855 const Test( 911 const Test(
856 ''' 912 '''
857 typedef F(); 913 typedef F();
858 m() => F; 914 m() => F;
859 ''', 915 ''',
860 const Visit(VisitKind.VISIT_TYPEDEF_TYPE_LITERAL_GET, 916 const Visit(VisitKind.VISIT_TYPEDEF_TYPE_LITERAL_GET,
861 constant: 'F')), 917 constant: 'F')),
862 const Test( 918 const Test(
863 ''' 919 '''
864 typedef F(); 920 typedef F();
865 m() => F(null, 42); 921 m() => F(null, 42);
866 ''', 922 ''',
867 const Visit(VisitKind.VISIT_TYPEDEF_TYPE_LITERAL_INVOKE, 923 const Visit(VisitKind.VISIT_TYPEDEF_TYPE_LITERAL_INVOKE,
868 constant: 'F', 924 constant: 'F',
869 arguments: '(null,42)')), 925 arguments: '(null,42)')),
870 926 ],
927 'Type variable type literals': const [
871 // Type variable type literals 928 // Type variable type literals
872 const Test.clazz( 929 const Test.clazz(
873 ''' 930 '''
874 class C<T> { 931 class C<T> {
875 m() => T; 932 m() => T;
876 } 933 }
877 ''', 934 ''',
878 const Visit(VisitKind.VISIT_TYPE_VARIABLE_TYPE_LITERAL_GET, 935 const Visit(VisitKind.VISIT_TYPE_VARIABLE_TYPE_LITERAL_GET,
879 element: 'type_variable(C#T)')), 936 element: 'type_variable(C#T)')),
880 const Test.clazz( 937 const Test.clazz(
881 ''' 938 '''
882 class C<T> { 939 class C<T> {
883 m() => T(null, 42); 940 m() => T(null, 42);
884 } 941 }
885 ''', 942 ''',
886 const Visit(VisitKind.VISIT_TYPE_VARIABLE_TYPE_LITERAL_INVOKE, 943 const Visit(VisitKind.VISIT_TYPE_VARIABLE_TYPE_LITERAL_INVOKE,
887 element: 'type_variable(C#T)', 944 element: 'type_variable(C#T)',
888 arguments: '(null,42)')), 945 arguments: '(null,42)')),
889 946
947 ],
948 'Dynamic type literals': const [
890 // Dynamic type literals 949 // Dynamic type literals
891 const Test( 950 const Test(
892 ''' 951 '''
893 m() => dynamic; 952 m() => dynamic;
894 ''', 953 ''',
895 const Visit(VisitKind.VISIT_DYNAMIC_TYPE_LITERAL_GET, 954 const Visit(VisitKind.VISIT_DYNAMIC_TYPE_LITERAL_GET,
896 constant: 'dynamic')), 955 constant: 'dynamic')),
897 // TODO(johnniwinther): Enable this when we pass the right constant. 956 // TODO(johnniwinther): Enable this when we pass the right constant.
898 // Currently we generated the constant for `Type` instead of `dynamic`. 957 // Currently we generated the constant for `Type` instead of `dynamic`.
899 /*const Test( 958 /*const Test(
900 ''' 959 '''
901 m() { dynamic(null, 42); } 960 m() { dynamic(null, 42); }
902 ''', 961 ''',
903 const Visit(VisitKind.VISIT_DYNAMIC_TYPE_LITERAL_INVOKE, 962 const Visit(VisitKind.VISIT_DYNAMIC_TYPE_LITERAL_INVOKE,
904 constant: 'dynamic', 963 constant: 'dynamic',
905 arguments: '(null,42)')),*/ 964 arguments: '(null,42)')),*/
906 965 ],
966 'Assert': const [
907 // Assert 967 // Assert
908 const Test( 968 const Test(
909 ''' 969 '''
910 m() { assert(false); } 970 m() { assert(false); }
911 ''', 971 ''',
912 const Visit(VisitKind.VISIT_ASSERT, expression: 'false')), 972 const Visit(VisitKind.VISIT_ASSERT, expression: 'false')),
913 973 ],
974 'Logical and': const [
914 // Logical and 975 // Logical and
915 const Test( 976 const Test(
916 ''' 977 '''
917 m() => true && false; 978 m() => true && false;
918 ''', 979 ''',
919 const Visit(VisitKind.VISIT_LOGICAL_AND, left: 'true', right: 'false')), 980 const Visit(VisitKind.VISIT_LOGICAL_AND, left: 'true', right: 'false')),
920 981 ],
982 'Logical or': const [
921 // Logical or 983 // Logical or
922 const Test( 984 const Test(
923 ''' 985 '''
924 m() => true || false; 986 m() => true || false;
925 ''', 987 ''',
926 const Visit(VisitKind.VISIT_LOGICAL_OR, left: 'true', right: 'false')), 988 const Visit(VisitKind.VISIT_LOGICAL_OR, left: 'true', right: 'false')),
927 989 ],
990 'Is test': const [
928 // Is test 991 // Is test
929 const Test( 992 const Test(
930 ''' 993 '''
931 class C {} 994 class C {}
932 m() => 0 is C; 995 m() => 0 is C;
933 ''', 996 ''',
934 const Visit(VisitKind.VISIT_IS, expression: '0', type: 'C')), 997 const Visit(VisitKind.VISIT_IS, expression: '0', type: 'C')),
935 998 ],
999 'Is not test': const [
936 // Is not test 1000 // Is not test
937 const Test( 1001 const Test(
938 ''' 1002 '''
939 class C {} 1003 class C {}
940 m() => 0 is! C; 1004 m() => 0 is! C;
941 ''', 1005 ''',
942 const Visit(VisitKind.VISIT_IS_NOT, expression: '0', type: 'C')), 1006 const Visit(VisitKind.VISIT_IS_NOT, expression: '0', type: 'C')),
943 1007 ],
944 // Is test 1008 'As test': const [
1009 // As test
945 const Test( 1010 const Test(
946 ''' 1011 '''
947 class C {} 1012 class C {}
948 m() => 0 as C; 1013 m() => 0 as C;
949 ''', 1014 ''',
950 const Visit(VisitKind.VISIT_AS, expression: '0', type: 'C')), 1015 const Visit(VisitKind.VISIT_AS, expression: '0', type: 'C')),
951 1016 ],
1017 'Binary operators': const [
952 // Binary operators 1018 // Binary operators
953 const Test( 1019 const Test(
954 ''' 1020 '''
955 m() => 2 + 3; 1021 m() => 2 + 3;
956 ''', 1022 ''',
957 const Visit(VisitKind.VISIT_BINARY, 1023 const Visit(VisitKind.VISIT_BINARY,
958 left: '2', operator: '+', right: '3')), 1024 left: '2', operator: '+', right: '3')),
959 const Test( 1025 const Test(
960 ''' 1026 '''
961 m() => 2 - 3; 1027 m() => 2 - 3;
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1046 operator +(_) => null; 1112 operator +(_) => null;
1047 } 1113 }
1048 class C extends B { 1114 class C extends B {
1049 m() => super + 42; 1115 m() => super + 42;
1050 } 1116 }
1051 ''', 1117 ''',
1052 const Visit(VisitKind.VISIT_SUPER_BINARY, 1118 const Visit(VisitKind.VISIT_SUPER_BINARY,
1053 element: 'function(B#+)', 1119 element: 'function(B#+)',
1054 operator: '+', 1120 operator: '+',
1055 right: '42')), 1121 right: '42')),
1122 ],
1123 'Index': const [
1056 // Index 1124 // Index
1057 const Test( 1125 const Test(
1058 ''' 1126 '''
1059 m() => 2[3]; 1127 m() => 2[3];
1060 ''', 1128 ''',
1061 const Visit(VisitKind.VISIT_INDEX, 1129 const Visit(VisitKind.VISIT_INDEX,
1062 receiver: '2', index: '3')), 1130 receiver: '2', index: '3')),
1063 const Test( 1131 const Test(
1064 ''' 1132 '''
1065 m() => --2[3]; 1133 m() => --2[3];
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1107 } 1175 }
1108 class C extends B { 1176 class C extends B {
1109 m() => super[42]--; 1177 m() => super[42]--;
1110 } 1178 }
1111 ''', 1179 ''',
1112 const Visit(VisitKind.VISIT_SUPER_INDEX_POSTFIX, 1180 const Visit(VisitKind.VISIT_SUPER_INDEX_POSTFIX,
1113 getter: 'function(B#[])', 1181 getter: 'function(B#[])',
1114 setter: 'function(B#[]=)', 1182 setter: 'function(B#[]=)',
1115 index: '42', 1183 index: '42',
1116 operator: '--')), 1184 operator: '--')),
1117 1185 ],
1186 'Equals': const [
1118 // Equals 1187 // Equals
1119 const Test( 1188 const Test(
1120 ''' 1189 '''
1121 m() => 2 == 3; 1190 m() => 2 == 3;
1122 ''', 1191 ''',
1123 const Visit(VisitKind.VISIT_EQUALS, 1192 const Visit(VisitKind.VISIT_EQUALS,
1124 left: '2', right: '3')), 1193 left: '2', right: '3')),
1125 const Test.clazz( 1194 const Test.clazz(
1126 ''' 1195 '''
1127 class B { 1196 class B {
1128 operator ==(_) => null; 1197 operator ==(_) => null;
1129 } 1198 }
1130 class C extends B { 1199 class C extends B {
1131 m() => super == 42; 1200 m() => super == 42;
1132 } 1201 }
1133 ''', 1202 ''',
1134 const Visit(VisitKind.VISIT_SUPER_EQUALS, 1203 const Visit(VisitKind.VISIT_SUPER_EQUALS,
1135 element: 'function(B#==)', 1204 element: 'function(B#==)',
1136 right: '42')), 1205 right: '42')),
1137 1206 ],
1207 'Not equals': const [
1138 // Not equals 1208 // Not equals
1139 const Test( 1209 const Test(
1140 ''' 1210 '''
1141 m() => 2 != 3; 1211 m() => 2 != 3;
1142 ''', 1212 ''',
1143 const Visit(VisitKind.VISIT_NOT_EQUALS, 1213 const Visit(VisitKind.VISIT_NOT_EQUALS,
1144 left: '2', right: '3')), 1214 left: '2', right: '3')),
1145 // TODO(johnniwinther): Enable this. Resolution does not store the element. 1215 // TODO(johnniwinther): Enable this. Resolution does not store the element.
1146 /*const Test.clazz( 1216 /*const Test.clazz(
1147 ''' 1217 '''
1148 class B { 1218 class B {
1149 operator ==(_) => null; 1219 operator ==(_) => null;
1150 } 1220 }
1151 class C extends B { 1221 class C extends B {
1152 m() => super != 42; 1222 m() => super != 42;
1153 } 1223 }
1154 ''', 1224 ''',
1155 const Visit(VisitKind.VISIT_SUPER_NOT_EQUALS, 1225 const Visit(VisitKind.VISIT_SUPER_NOT_EQUALS,
1156 element: 'function(B#==)', 1226 element: 'function(B#==)',
1157 right: '42')),*/ 1227 right: '42')),*/
1158 1228 ],
1229 'Unary expression': const [
1159 // Unary expression 1230 // Unary expression
1160 const Test( 1231 const Test(
1161 ''' 1232 '''
1162 m() => -false; 1233 m() => -false;
1163 ''', 1234 ''',
1164 const Visit(VisitKind.VISIT_UNARY, 1235 const Visit(VisitKind.VISIT_UNARY,
1165 expression: 'false', operator: '-')), 1236 expression: 'false', operator: '-')),
1166 const Test( 1237 const Test(
1167 ''' 1238 '''
1168 m() => ~false; 1239 m() => ~false;
(...skipping 20 matching lines...) Expand all
1189 m() => ~super; 1260 m() => ~super;
1190 } 1261 }
1191 ''', 1262 ''',
1192 const Visit(VisitKind.VISIT_SUPER_UNARY, 1263 const Visit(VisitKind.VISIT_SUPER_UNARY,
1193 element: 'function(B#~)', operator: '~')), 1264 element: 'function(B#~)', operator: '~')),
1194 const Test( 1265 const Test(
1195 ''' 1266 '''
1196 m() => !0; 1267 m() => !0;
1197 ''', 1268 ''',
1198 const Visit(VisitKind.VISIT_NOT, expression: '0')), 1269 const Visit(VisitKind.VISIT_NOT, expression: '0')),
1199 1270 ],
1271 'Index set': const [
1200 // Index set 1272 // Index set
1201 const Test( 1273 const Test(
1202 ''' 1274 '''
1203 m() => 0[1] = 2; 1275 m() => 0[1] = 2;
1204 ''', 1276 ''',
1205 const Visit(VisitKind.VISIT_INDEX_SET, 1277 const Visit(VisitKind.VISIT_INDEX_SET,
1206 receiver: '0', index: '1', rhs: '2')), 1278 receiver: '0', index: '1', rhs: '2')),
1207 const Test.clazz( 1279 const Test.clazz(
1208 ''' 1280 '''
1209 class B { 1281 class B {
1210 operator []=(a, b) {} 1282 operator []=(a, b) {}
1211 } 1283 }
1212 class C extends B { 1284 class C extends B {
1213 m() => super[1] = 2; 1285 m() => super[1] = 2;
1214 } 1286 }
1215 ''', 1287 ''',
1216 const Visit(VisitKind.VISIT_SUPER_INDEX_SET, 1288 const Visit(VisitKind.VISIT_SUPER_INDEX_SET,
1217 element: 'function(B#[]=)', index: '1', rhs: '2')), 1289 element: 'function(B#[]=)', index: '1', rhs: '2')),
1218 1290 ],
1291 'Compound assignment': const [
1219 // Compound assignment 1292 // Compound assignment
1220 const Test( 1293 const Test(
1221 ''' 1294 '''
1222 m(a) => a.b += 42; 1295 m(a) => a.b += 42;
1223 ''', 1296 ''',
1224 const [ 1297 const [
1225 const Visit(VisitKind.VISIT_DYNAMIC_PROPERTY_COMPOUND, 1298 const Visit(VisitKind.VISIT_DYNAMIC_PROPERTY_COMPOUND,
1226 receiver: 'a', operator: '+=', rhs: '42', 1299 receiver: 'a', operator: '+=', rhs: '42',
1227 getter: 'Selector(getter, b, arity=0)', 1300 getter: 'Selector(getter, b, arity=0)',
1228 setter: 'Selector(setter, b, arity=1)'), 1301 setter: 'Selector(setter, b, arity=1)'),
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
1526 final a; 1599 final a;
1527 } 1600 }
1528 1601
1529 class C extends B { 1602 class C extends B {
1530 m() => super.a += 42; 1603 m() => super.a += 42;
1531 } 1604 }
1532 ''', 1605 ''',
1533 const Visit(VisitKind.VISIT_SUPER_FIELD_FIELD_COMPOUND, 1606 const Visit(VisitKind.VISIT_SUPER_FIELD_FIELD_COMPOUND,
1534 getter: 'field(B#a)', setter: 'field(A#a)', 1607 getter: 'field(B#a)', setter: 'field(A#a)',
1535 operator: '+=', rhs: '42')),*/ 1608 operator: '+=', rhs: '42')),*/
1536 1609 ],
1610 'Compound index assignment': const [
1537 // Compound index assignment 1611 // Compound index assignment
1538 const Test( 1612 const Test(
1539 ''' 1613 '''
1540 m() => 0[1] += 42; 1614 m() => 0[1] += 42;
1541 ''', 1615 ''',
1542 const Visit(VisitKind.VISIT_COMPOUND_INDEX_SET, 1616 const Visit(VisitKind.VISIT_COMPOUND_INDEX_SET,
1543 receiver: '0', index: '1', operator: '+=', rhs: '42')), 1617 receiver: '0', index: '1', operator: '+=', rhs: '42')),
1544 // TODO(johnniwinther): Enable this when the getter element is stored. 1618 // TODO(johnniwinther): Enable this when the getter element is stored.
1545 /*const Test.clazz( 1619 /*const Test.clazz(
1546 ''' 1620 '''
1547 class B { 1621 class B {
1548 operator [](_) {} 1622 operator [](_) {}
1549 operator []=(a, b) {} 1623 operator []=(a, b) {}
1550 } 1624 }
1551 class C extends B { 1625 class C extends B {
1552 m() => super[1] += 42; 1626 m() => super[1] += 42;
1553 } 1627 }
1554 ''', 1628 ''',
1555 const Visit(VisitKind.VISIT_SUPER_COMPOUND_INDEX_SET, 1629 const Visit(VisitKind.VISIT_SUPER_COMPOUND_INDEX_SET,
1556 getter: 'function(B#[])', setter: 'function(B#[]=)', 1630 getter: 'function(B#[])', setter: 'function(B#[]=)',
1557 index: '1', operator: '+=', rhs: '42')),*/ 1631 index: '1', operator: '+=', rhs: '42')),*/
1558 1632 ],
1633 'Prefix expression': const [
1559 // Prefix expression 1634 // Prefix expression
1560 const Test( 1635 const Test(
1561 ''' 1636 '''
1562 m(a) => --a.b; 1637 m(a) => --a.b;
1563 ''', 1638 ''',
1564 const [ 1639 const [
1565 const Visit(VisitKind.VISIT_DYNAMIC_PROPERTY_PREFIX, 1640 const Visit(VisitKind.VISIT_DYNAMIC_PROPERTY_PREFIX,
1566 receiver: 'a', operator: '--', 1641 receiver: 'a', operator: '--',
1567 getter: 'Selector(getter, b, arity=0)', 1642 getter: 'Selector(getter, b, arity=0)',
1568 setter: 'Selector(setter, b, arity=1)'), 1643 setter: 'Selector(setter, b, arity=1)'),
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
1770 set a(_) {} 1845 set a(_) {}
1771 } 1846 }
1772 1847
1773 class C extends B { 1848 class C extends B {
1774 m() => ++super.a; 1849 m() => ++super.a;
1775 } 1850 }
1776 ''', 1851 ''',
1777 const Visit(VisitKind.VISIT_SUPER_FIELD_SETTER_PREFIX, 1852 const Visit(VisitKind.VISIT_SUPER_FIELD_SETTER_PREFIX,
1778 getter: 'field(A#a)', setter: 'setter(B#a)', 1853 getter: 'field(A#a)', setter: 'setter(B#a)',
1779 operator: '++')), 1854 operator: '++')),
1780 1855 ],
1781 // Prefix expression 1856 'Postfix expression': const [
1857 // Postfix expression
1782 const Test( 1858 const Test(
1783 ''' 1859 '''
1784 m(a) => a.b--; 1860 m(a) => a.b--;
1785 ''', 1861 ''',
1786 const [ 1862 const [
1787 const Visit(VisitKind.VISIT_DYNAMIC_PROPERTY_POSTFIX, 1863 const Visit(VisitKind.VISIT_DYNAMIC_PROPERTY_POSTFIX,
1788 receiver: 'a', operator: '--', 1864 receiver: 'a', operator: '--',
1789 getter: 'Selector(getter, b, arity=0)', 1865 getter: 'Selector(getter, b, arity=0)',
1790 setter: 'Selector(setter, b, arity=1)'), 1866 setter: 'Selector(setter, b, arity=1)'),
1791 const Visit(VisitKind.VISIT_PARAMETER_GET, 1867 const Visit(VisitKind.VISIT_PARAMETER_GET,
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
1992 set a(_) {} 2068 set a(_) {}
1993 } 2069 }
1994 2070
1995 class C extends B { 2071 class C extends B {
1996 m() => super.a++; 2072 m() => super.a++;
1997 } 2073 }
1998 ''', 2074 ''',
1999 const Visit(VisitKind.VISIT_SUPER_FIELD_SETTER_POSTFIX, 2075 const Visit(VisitKind.VISIT_SUPER_FIELD_SETTER_POSTFIX,
2000 getter: 'field(A#a)', setter: 'setter(B#a)', 2076 getter: 'field(A#a)', setter: 'setter(B#a)',
2001 operator: '++')), 2077 operator: '++')),
2002 2078 ],
2003 ]; 2079 'Constructor invocations': const [
2004 2080 const Test(
2005 main() { 2081 '''
2082 class Class {
2083 const Class(a, b);
2084 }
2085 m() => const Class(true, 42);
2086 ''',
2087 const Visit(VisitKind.VISIT_CONST_CONSTRUCTOR_INVOKE,
2088 constant: 'const Class(true, 42)')),
2089 const Test(
2090 '''
2091 class Class {}
2092 m() => new Class();
2093 ''',
2094 const Visit(VisitKind.VISIT_GENERATIVE_CONSTRUCTOR_INVOKE,
2095 element: 'generative_constructor(Class#)',
2096 arguments: '()',
2097 type: 'Class',
2098 selector: 'Selector(call, , arity=0)')),
2099 const Test(
2100 '''
2101 class Class {
2102 Class(a, b);
2103 }
2104 m() => new Class(true, 42);
2105 ''',
2106 const Visit(VisitKind.VISIT_GENERATIVE_CONSTRUCTOR_INVOKE,
2107 element: 'generative_constructor(Class#)',
2108 arguments: '(true,42)',
2109 type: 'Class',
2110 selector: 'Selector(call, , arity=2)')),
2111 const Test(
2112 '''
2113 class Class {
2114 Class.named(a, b);
2115 }
2116 m() => new Class.named(true, 42);
2117 ''',
2118 const Visit(VisitKind.VISIT_GENERATIVE_CONSTRUCTOR_INVOKE,
2119 element: 'generative_constructor(Class#named)',
2120 arguments: '(true,42)',
2121 type: 'Class',
2122 selector: 'Selector(call, named, arity=2)')),
2123 const Test(
2124 '''
2125 class Class {
2126 Class(a, b) : this._(a, b);
2127 Class._(a, b);
2128 }
2129 m() => new Class(true, 42);
2130 ''',
2131 const Visit(VisitKind.VISIT_REDIRECTING_GENERATIVE_CONSTRUCTOR_INVOKE,
2132 element: 'generative_constructor(Class#)',
2133 arguments: '(true,42)',
2134 type: 'Class',
2135 selector: 'Selector(call, , arity=2)')),
2136 const Test(
2137 '''
2138 class Class {
2139 factory Class(a, b) => new Class._(a, b);
2140 Class._(a, b);
2141 }
2142 m() => new Class(true, 42);
2143 ''',
2144 const Visit(VisitKind.VISIT_FACTORY_CONSTRUCTOR_INVOKE,
2145 element: 'function(Class#)',
2146 arguments: '(true,42)',
2147 type: 'Class',
2148 selector: 'Selector(call, , arity=2)')),
2149 const Test(
2150 '''
2151 class Class<T> {
2152 factory Class(a, b) = Class<int>.a;
2153 factory Class.a(a, b) = Class<Class<T>>.b;
2154 Class.b(a, b);
2155 }
2156 m() => new Class<double>(true, 42);
2157 ''',
2158 const Visit(VisitKind.VISIT_REDIRECTING_FACTORY_CONSTRUCTOR_INVOKE,
2159 element: 'function(Class#)',
2160 arguments: '(true,42)',
2161 type: 'Class<double>',
2162 target: 'generative_constructor(Class#b)',
2163 targetType: 'Class<Class<int>>',
2164 selector: 'Selector(call, , arity=2)')),
2165 const Test(
2166 '''
2167 class Class {
2168 Class(a, b);
2169 }
2170 m() => new Class.unresolved(true, 42);
2171 ''',
2172 const Visit(
2173 VisitKind.ERROR_UNRESOLVED_CONSTRUCTOR_INVOKE,
2174 arguments: '(true,42)')),
2175 const Test(
2176 '''
2177 m() => new Unresolved(true, 42);
2178 ''',
2179 const Visit(
2180 // TODO(johnniwinther): Update this to
2181 // `VisitKind.ERROR_UNRESOLVED_CLASS_CONSTRUCTOR_INVOKE`.
2182 VisitKind.ERROR_UNRESOLVED_CONSTRUCTOR_INVOKE,
2183 arguments: '(true,42)')),
2184 const Test(
2185 '''
2186 abstract class AbstractClass {}
2187 m() => new AbstractClass();
2188 ''',
2189 const Visit(
2190 VisitKind.ERROR_ABSTRACT_CLASS_CONSTRUCTOR_INVOKE,
2191 element: 'generative_constructor(AbstractClass#)',
2192 type: 'AbstractClass',
2193 arguments: '()',
2194 selector: 'Selector(call, , arity=0)')),
2195 const Test(
2196 '''
2197 class Class {
2198 factory Class(a, b) = Unresolved;
2199 }
2200 m() => new Class(true, 42);
2201 ''',
2202 const Visit(
2203 VisitKind.ERROR_UNRESOLVED_REDIRECTING_FACTORY_CONSTRUCTOR_INVOKE,
2204 element: 'function(Class#)',
2205 arguments: '(true,42)',
2206 type: 'Class',
2207 selector: 'Selector(call, , arity=2)')),
2208 const Test(
2209 '''
2210 class Class {
2211 factory Class(a, b) = Class.named;
2212 }
2213 m() => new Class(true, 42);
2214 ''',
2215 const Visit(
2216 VisitKind.ERROR_UNRESOLVED_REDIRECTING_FACTORY_CONSTRUCTOR_INVOKE,
2217 element: 'function(Class#)',
2218 arguments: '(true,42)',
2219 type: 'Class',
2220 selector: 'Selector(call, , arity=2)')),
2221 const Test(
2222 '''
2223 class Class {
2224 factory Class(a, b) = Class.named;
2225 factory Class.named(a, b) = Class.unresolved;
2226 }
2227 m() => new Class(true, 42);
2228 ''',
2229 const Visit(
2230 VisitKind.ERROR_UNRESOLVED_REDIRECTING_FACTORY_CONSTRUCTOR_INVOKE,
2231 element: 'function(Class#)',
2232 arguments: '(true,42)',
2233 type: 'Class',
2234 selector: 'Selector(call, , arity=2)')),
2235 const Test(
2236 '''
2237 abstract class AbstractClass {
2238 AbstractClass(a, b);
2239 }
2240 class Class {
2241 factory Class(a, b) = AbstractClass;
2242 }
2243 m() => new Class(true, 42);
2244 ''',
2245 const Visit(
2246 VisitKind.ERROR_UNRESOLVED_REDIRECTING_FACTORY_CONSTRUCTOR_INVOKE,
2247 element: 'function(Class#)',
2248 arguments: '(true,42)',
2249 type: 'Class',
2250 selector: 'Selector(call, , arity=2)')),
2251 ],
2252 };
2253
2254 main(List<String> arguments) {
2255 asyncTest(() => Future.forEach([
2256 () {
2257 return test(
2258 arguments,
2259 SEND_TESTS,
2260 (elements) => new SemanticSendTestVisitor(elements));
2261 },
2262 ], (f) => f()));
2263 }
2264
2265 Future test(List<String> arguments,
2266 Map<String, List<Test>> TESTS,
2267 SemanticTestVisitor createVisitor(TreeElements elements)) {
2006 Map<String, String> sourceFiles = {}; 2268 Map<String, String> sourceFiles = {};
2007 Map<String, Test> testMap = {}; 2269 Map<String, Test> testMap = {};
2008 StringBuffer mainSource = new StringBuffer(); 2270 StringBuffer mainSource = new StringBuffer();
2009 int index = 0; 2271 int index = 0;
2010 TESTS.forEach((Test test) { 2272 TESTS.forEach((String group, List<Test> tests) {
2011 StringBuffer testSource = new StringBuffer(); 2273 if (arguments.isNotEmpty && !arguments.contains(group)) return;
2012 if (test.codeByPrefix != null) { 2274
2013 String prefixFilename = 'pre$index.dart'; 2275 tests.forEach((Test test) {
2014 sourceFiles[prefixFilename] = test.codeByPrefix; 2276 StringBuffer testSource = new StringBuffer();
2015 testSource.writeln("import '$prefixFilename' as p;"); 2277 if (test.codeByPrefix != null) {
2016 } 2278 String prefixFilename = 'pre$index.dart';
2017 2279 sourceFiles[prefixFilename] = test.codeByPrefix;
2018 String filename = 'lib$index.dart'; 2280 testSource.writeln("import '$prefixFilename' as p;");
2019 testSource.writeln(test.code); 2281 }
2020 sourceFiles[filename] = testSource.toString(); 2282
2021 mainSource.writeln("import '$filename';"); 2283 String filename = 'lib$index.dart';
2022 testMap[filename] = test; 2284 testSource.writeln(test.code);
2023 index++; 2285 sourceFiles[filename] = testSource.toString();
2286 mainSource.writeln("import '$filename';");
2287 testMap[filename] = test;
2288 index++;
2289 });
2024 }); 2290 });
2025 mainSource.writeln("main() {}"); 2291 mainSource.writeln("main() {}");
2026 sourceFiles['main.dart'] = mainSource.toString(); 2292 sourceFiles['main.dart'] = mainSource.toString();
2027 2293
2028 asyncTest(() { 2294 Compiler compiler = compilerFor(sourceFiles,
2029 Compiler compiler = compilerFor(sourceFiles, 2295 options: ['--analyze-all', '--analyze-only']);
2030 options: ['--analyze-all', '--analyze-only']); 2296 return compiler.run(Uri.parse('memory:main.dart')).then((_) {
2031 return compiler.run(Uri.parse('memory:main.dart')).then((_) { 2297 testMap.forEach((String filename, Test test) {
2032 testMap.forEach((String filename, Test test) { 2298 LibraryElement library = compiler.libraryLoader.lookupLibrary(
2033 LibraryElement library = compiler.libraryLoader.lookupLibrary( 2299 Uri.parse('memory:$filename'));
2034 Uri.parse('memory:$filename')); 2300 var expectedVisits = test.expectedVisits;
2035 var expectedVisits = test.expectedVisits; 2301 if (expectedVisits is! List) {
2036 if (expectedVisits is! List) { 2302 expectedVisits = [expectedVisits];
2037 expectedVisits = [expectedVisits]; 2303 }
2038 } 2304 AstElement element;
2039 AstElement element; 2305 String cls = test.cls;
2040 String cls = test.cls; 2306 String method = test.method;
2041 String method = test.method; 2307 if (cls == null) {
2042 if (cls == null) { 2308 element = library.find(method);
2043 element = library.find(method); 2309 } else {
2044 } else { 2310 ClassElement classElement = library.find(cls);
2045 ClassElement classElement = library.find(cls); 2311 Expect.isNotNull(classElement,
2046 Expect.isNotNull(classElement, 2312 "Class '$cls' not found in:\n"
2047 "Class '$cls' not found in:\n" 2313 "${library.compilationUnit.script.text}");
2048 "${library.compilationUnit.script.text}"); 2314 element = classElement.localLookup(method);
2049 element = classElement.localLookup(method); 2315 }
2050 } 2316 Expect.isNotNull(element, "Element '$method' not found in:\n"
2051 Expect.isNotNull(element, "Element '$method' not found in:\n" 2317 "${library.compilationUnit.script.text}");
2052 "${library.compilationUnit.script.text}"); 2318 ResolvedAst resolvedAst = element.resolvedAst;
2053 ResolvedAst resolvedAst = element.resolvedAst; 2319 SemanticTestVisitor visitor = createVisitor(resolvedAst.elements);
2054 SemanticTestVisitor visitor = 2320 try {
2055 new SemanticTestVisitor(resolvedAst.elements); 2321 compiler.withCurrentElement(resolvedAst.element, () {
2056 try { 2322 //print(resolvedAst.node.toDebugString());
2057 compiler.withCurrentElement(resolvedAst.element, () { 2323 resolvedAst.node.accept(visitor);
2058 //print(resolvedAst.node.toDebugString()); 2324 });
2059 resolvedAst.node.accept(visitor); 2325 } catch (e, s) {
2060 }); 2326 Expect.fail("$e:\n$s\nIn test:\n"
2061 } catch (e, s) { 2327 "${library.compilationUnit.script.text}");
2062 Expect.fail("$e:\n$s\nIn test:\n" 2328 }
2063 "${library.compilationUnit.script.text}"); 2329 Expect.listEquals(expectedVisits, visitor.visits,
2064 } 2330 "In test:\n"
2065 Expect.listEquals(expectedVisits, visitor.visits, 2331 "${library.compilationUnit.script.text}");
2066 "In test:\n"
2067 "${library.compilationUnit.script.text}");
2068 });
2069 }); 2332 });
2070 }); 2333 });
2071 } 2334 }
2072 2335
2073 2336
2074 class SemanticTestVisitor extends SemanticVisitor with SemanticSendVisitor { 2337 abstract class SemanticTestVisitor extends TraversalVisitor {
2075 List<Visit> visits = <Visit>[]; 2338 List<Visit> visits = <Visit>[];
2076 2339
2077 SemanticTestVisitor(TreeElements elements) : super(elements); 2340 SemanticTestVisitor(TreeElements elements) : super(elements);
2078 2341
2079 apply(Node node, arg) => node.accept(this); 2342 apply(Node node, arg) => node.accept(this);
2080 2343
2081 internalError(Spannable spannable, String message) { 2344 internalError(Spannable spannable, String message) {
2082 throw new SpannableAssertionFailure(spannable, message); 2345 throw new SpannableAssertionFailure(spannable, message);
2083 } 2346 }
2347 }
2084 2348
2085 SemanticSendVisitor get sendVisitor => this; 2349 class SemanticSendTestVisitor extends SemanticTestVisitor {
2086 2350
2087 @override 2351 SemanticSendTestVisitor(TreeElements elements) : super(elements);
2088 visitNode(Node node) {
2089 node.visitChildren(this);
2090 }
2091 2352
2092 @override 2353 @override
2093 visitAs( 2354 visitAs(
2094 Send node, 2355 Send node,
2095 Node expression, 2356 Node expression,
2096 DartType type, 2357 DartType type,
2097 arg) { 2358 arg) {
2098 visits.add(new Visit(VisitKind.VISIT_AS, 2359 visits.add(new Visit(VisitKind.VISIT_AS,
2099 expression: expression, type: type)); 2360 expression: expression, type: type));
2100 apply(expression, arg); 2361 apply(expression, arg);
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
2215 } 2476 }
2216 2477
2217 @override 2478 @override
2218 visitDynamicPropertyGet( 2479 visitDynamicPropertyGet(
2219 Send node, 2480 Send node,
2220 Node receiver, 2481 Node receiver,
2221 Selector selector, 2482 Selector selector,
2222 arg) { 2483 arg) {
2223 visits.add(new Visit(VisitKind.VISIT_DYNAMIC_PROPERTY_GET, 2484 visits.add(new Visit(VisitKind.VISIT_DYNAMIC_PROPERTY_GET,
2224 receiver: receiver, name: selector.name)); 2485 receiver: receiver, name: selector.name));
2486 apply(receiver, arg);
2225 } 2487 }
2226 2488
2227 @override 2489 @override
2228 visitDynamicPropertyInvoke( 2490 visitDynamicPropertyInvoke(
2229 Send node, 2491 Send node,
2230 Node receiver, 2492 Node receiver,
2231 NodeList arguments, 2493 NodeList arguments,
2232 Selector selector, 2494 Selector selector,
2233 arg) { 2495 arg) {
2234 visits.add(new Visit(VisitKind.VISIT_DYNAMIC_PROPERTY_INVOKE, 2496 visits.add(new Visit(VisitKind.VISIT_DYNAMIC_PROPERTY_INVOKE,
2235 receiver: receiver, name: selector.name, arguments: arguments)); 2497 receiver: receiver, name: selector.name, arguments: arguments));
2498 apply(receiver, arg);
2236 apply(arguments, arg); 2499 apply(arguments, arg);
2237 } 2500 }
2238 2501
2239 @override 2502 @override
2240 visitDynamicPropertySet( 2503 visitDynamicPropertySet(
2241 SendSet node, 2504 SendSet node,
2242 Node receiver, 2505 Node receiver,
2243 Selector selector, 2506 Selector selector,
2244 Node rhs, 2507 Node rhs,
2245 arg) { 2508 arg) {
2246 visits.add(new Visit(VisitKind.VISIT_DYNAMIC_PROPERTY_SET, 2509 visits.add(new Visit(VisitKind.VISIT_DYNAMIC_PROPERTY_SET,
2247 receiver: receiver, name: selector.name, rhs: rhs)); 2510 receiver: receiver, name: selector.name, rhs: rhs));
2511 apply(receiver, arg);
2248 } 2512 }
2249 2513
2250 @override 2514 @override
2251 visitDynamicTypeLiteralGet( 2515 visitDynamicTypeLiteralGet(
2252 Send node, 2516 Send node,
2253 ConstantExpression constant, 2517 ConstantExpression constant,
2254 arg) { 2518 arg) {
2255 visits.add(new Visit(VisitKind.VISIT_DYNAMIC_TYPE_LITERAL_GET, 2519 visits.add(new Visit(VisitKind.VISIT_DYNAMIC_TYPE_LITERAL_GET,
2256 constant: constant.getText())); 2520 constant: constant.getText()));
2257 } 2521 }
(...skipping 1750 matching lines...) Expand 10 before | Expand all | Expand 10 after
4008 FunctionElement indexFunction, 4272 FunctionElement indexFunction,
4009 FunctionElement indexSetFunction, 4273 FunctionElement indexSetFunction,
4010 Node index, 4274 Node index,
4011 IncDecOperator operator, 4275 IncDecOperator operator,
4012 arg) { 4276 arg) {
4013 visits.add(new Visit(VisitKind.VISIT_SUPER_INDEX_PREFIX, 4277 visits.add(new Visit(VisitKind.VISIT_SUPER_INDEX_PREFIX,
4014 getter: indexFunction, setter: indexSetFunction, 4278 getter: indexFunction, setter: indexSetFunction,
4015 index: index, operator: operator)); 4279 index: index, operator: operator));
4016 apply(index, arg); 4280 apply(index, arg);
4017 } 4281 }
4282
4283 @override
4284 errorUnresolvedClassConstructorInvoke(
4285 NewExpression node,
4286 Element constructor,
4287 MalformedType type,
4288 NodeList arguments,
4289 Selector selector,
4290 arg) {
4291 // TODO(johnniwinther): Test [type] and [selector].
4292 visits.add(new Visit(
4293 VisitKind.ERROR_UNRESOLVED_CLASS_CONSTRUCTOR_INVOKE,
4294 arguments: arguments));
4295 apply(arguments, arg);
4296 }
4297
4298 @override
4299 errorUnresolvedConstructorInvoke(
4300 NewExpression node,
4301 Element constructor,
4302 DartType type,
4303 NodeList arguments,
4304 Selector selector,
4305 arg) {
4306 // TODO(johnniwinther): Test [type] and [selector].
4307 visits.add(new Visit(
4308 VisitKind.ERROR_UNRESOLVED_CONSTRUCTOR_INVOKE,
4309 arguments: arguments));
4310 apply(arguments, arg);
4311 }
4312
4313 @override
4314 visitConstConstructorInvoke(
4315 NewExpression node,
4316 ConstructedConstantExpression constant,
4317 arg) {
4318 visits.add(new Visit(VisitKind.VISIT_CONST_CONSTRUCTOR_INVOKE,
4319 constant: constant.getText()));
4320 }
4321
4322 @override
4323 visitFactoryConstructorInvoke(
4324 NewExpression node,
4325 ConstructorElement constructor,
4326 InterfaceType type,
4327 NodeList arguments,
4328 Selector selector,
4329 arg) {
4330 visits.add(new Visit(
4331 VisitKind.VISIT_FACTORY_CONSTRUCTOR_INVOKE,
4332 element: constructor,
4333 type: type,
4334 arguments: arguments,
4335 selector: selector));
4336 apply(arguments, arg);
4337 }
4338
4339 @override
4340 visitGenerativeConstructorInvoke(
4341 NewExpression node,
4342 ConstructorElement constructor,
4343 InterfaceType type,
4344 NodeList arguments,
4345 Selector selector,
4346 arg) {
4347 visits.add(new Visit(
4348 VisitKind.VISIT_GENERATIVE_CONSTRUCTOR_INVOKE,
4349 element: constructor,
4350 type: type,
4351 arguments: arguments,
4352 selector: selector));
4353 apply(arguments, arg);
4354 }
4355
4356 @override
4357 visitRedirectingFactoryConstructorInvoke(
4358 NewExpression node,
4359 ConstructorElement constructor,
4360 InterfaceType type,
4361 ConstructorElement effectiveTarget,
4362 InterfaceType effectiveTargetType,
4363 NodeList arguments,
4364 Selector selector,
4365 arg) {
4366 visits.add(new Visit(
4367 VisitKind.VISIT_REDIRECTING_FACTORY_CONSTRUCTOR_INVOKE,
4368 element: constructor,
4369 type: type,
4370 target: effectiveTarget,
4371 targetType: effectiveTargetType,
4372 arguments: arguments,
4373 selector: selector));
4374 apply(arguments, arg);
4375 }
4376
4377 @override
4378 visitRedirectingGenerativeConstructorInvoke(
4379 NewExpression node,
4380 ConstructorElement constructor,
4381 InterfaceType type,
4382 NodeList arguments,
4383 Selector selector,
4384 arg) {
4385 visits.add(new Visit(
4386 VisitKind.VISIT_REDIRECTING_GENERATIVE_CONSTRUCTOR_INVOKE,
4387 element: constructor,
4388 type: type,
4389 arguments: arguments,
4390 selector: selector));
4391 apply(arguments, arg);
4392 }
4393
4394 @override
4395 errorAbstractClassConstructorInvoke(
4396 NewExpression node,
4397 ConstructorElement constructor,
4398 InterfaceType type,
4399 NodeList arguments,
4400 Selector selector,
4401 arg) {
4402 visits.add(new Visit(
4403 VisitKind.ERROR_ABSTRACT_CLASS_CONSTRUCTOR_INVOKE,
4404 element: constructor,
4405 type: type,
4406 arguments: arguments,
4407 selector: selector));
4408 apply(arguments, arg);
4409 }
4410
4411 @override
4412 errorUnresolvedRedirectingFactoryConstructorInvoke(
4413 NewExpression node,
4414 ConstructorElement constructor,
4415 InterfaceType type,
4416 NodeList arguments,
4417 Selector selector,
4418 arg) {
4419 visits.add(new Visit(
4420 VisitKind.ERROR_UNRESOLVED_REDIRECTING_FACTORY_CONSTRUCTOR_INVOKE,
4421 element: constructor,
4422 type: type,
4423 arguments: arguments,
4424 selector: selector));
4425 apply(arguments, arg);
4426 }
4018 } 4427 }
4019 4428
4020 enum VisitKind { 4429 enum VisitKind {
4021 VISIT_PARAMETER_GET, 4430 VISIT_PARAMETER_GET,
4022 VISIT_PARAMETER_SET, 4431 VISIT_PARAMETER_SET,
4023 VISIT_PARAMETER_INVOKE, 4432 VISIT_PARAMETER_INVOKE,
4024 VISIT_PARAMETER_COMPOUND, 4433 VISIT_PARAMETER_COMPOUND,
4025 VISIT_PARAMETER_PREFIX, 4434 VISIT_PARAMETER_PREFIX,
4026 VISIT_PARAMETER_POSTFIX, 4435 VISIT_PARAMETER_POSTFIX,
4027 4436
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
4167 VISIT_SUPER_INDEX_SET, 4576 VISIT_SUPER_INDEX_SET,
4168 VISIT_SUPER_COMPOUND_INDEX_SET, 4577 VISIT_SUPER_COMPOUND_INDEX_SET,
4169 4578
4170 VISIT_ASSERT, 4579 VISIT_ASSERT,
4171 VISIT_LOGICAL_AND, 4580 VISIT_LOGICAL_AND,
4172 VISIT_LOGICAL_OR, 4581 VISIT_LOGICAL_OR,
4173 VISIT_IS, 4582 VISIT_IS,
4174 VISIT_IS_NOT, 4583 VISIT_IS_NOT,
4175 VISIT_AS, 4584 VISIT_AS,
4176 4585
4586 VISIT_CONST_CONSTRUCTOR_INVOKE,
4587 VISIT_GENERATIVE_CONSTRUCTOR_INVOKE,
4588 VISIT_REDIRECTING_GENERATIVE_CONSTRUCTOR_INVOKE,
4589 VISIT_FACTORY_CONSTRUCTOR_INVOKE,
4590 VISIT_REDIRECTING_FACTORY_CONSTRUCTOR_INVOKE,
4591
4592 ERROR_UNRESOLVED_CLASS_CONSTRUCTOR_INVOKE,
4593 ERROR_UNRESOLVED_CONSTRUCTOR_INVOKE,
4594 ERROR_ABSTRACT_CLASS_CONSTRUCTOR_INVOKE,
4595 ERROR_UNRESOLVED_REDIRECTING_FACTORY_CONSTRUCTOR_INVOKE,
4596
4177 // TODO(johnniwinther): Add tests for error cases. 4597 // TODO(johnniwinther): Add tests for error cases.
4178 } 4598 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/resolved_visitor.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698