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

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

Issue 1383503002: Add Resolution and Parsing interfaces for computeType, ensureResolved and parseNode. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Add TODOs. Created 5 years, 2 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 | « tests/compiler/dart2js/patch_test.dart ('k') | tests/compiler/dart2js/type_checker_test.dart » ('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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 import 'dart:async'; 5 import 'dart:async';
6 import 'dart:collection'; 6 import 'dart:collection';
7 7
8 import 'package:async_helper/async_helper.dart'; 8 import 'package:async_helper/async_helper.dart';
9 import 'package:expect/expect.dart'; 9 import 'package:expect/expect.dart';
10 import 'package:compiler/src/constants/expressions.dart'; 10 import 'package:compiler/src/constants/expressions.dart';
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 compiler.warnings[0].message.kind); 186 compiler.warnings[0].message.kind);
187 }), 187 }),
188 188
189 MockCompiler.create((MockCompiler compiler) { 189 MockCompiler.create((MockCompiler compiler) {
190 compiler.parseScript('class Foo<T> {' 190 compiler.parseScript('class Foo<T> {'
191 ' Foo<T> t;' 191 ' Foo<T> t;'
192 ' foo(Foo<T> f) {}' 192 ' foo(Foo<T> f) {}'
193 ' bar() { g(Foo<T> f) {}; g(); }' 193 ' bar() { g(Foo<T> f) {}; g(); }'
194 '}'); 194 '}');
195 ClassElement foo = compiler.mainApp.find('Foo'); 195 ClassElement foo = compiler.mainApp.find('Foo');
196 foo.ensureResolved(compiler); 196 foo.ensureResolved(compiler.resolution);
197 foo.lookupLocalMember('t').computeType(compiler);; 197 foo.lookupLocalMember('t').computeType(compiler.resolution);
198 foo.lookupLocalMember('foo').computeType(compiler);; 198 foo.lookupLocalMember('foo').computeType(compiler.resolution);
199 compiler.resolver.resolve(foo.lookupLocalMember('bar')); 199 compiler.resolver.resolve(foo.lookupLocalMember('bar'));
200 Expect.equals(0, compiler.warnings.length); 200 Expect.equals(0, compiler.warnings.length);
201 Expect.equals(0, compiler.errors.length); 201 Expect.equals(0, compiler.errors.length);
202 }), 202 }),
203 ]); 203 ]);
204 } 204 }
205 205
206 Future testSuperCalls() { 206 Future testSuperCalls() {
207 return MockCompiler.create((MockCompiler compiler) { 207 return MockCompiler.create((MockCompiler compiler) {
208 String script = """class A { foo() {} } 208 String script = """class A { foo() {} }
209 class B extends A { foo() => super.foo(); }"""; 209 class B extends A { foo() => super.foo(); }""";
210 compiler.parseScript(script); 210 compiler.parseScript(script);
211 compiler.resolveStatement("B b;"); 211 compiler.resolveStatement("B b;");
212 212
213 ClassElement classB = compiler.mainApp.find("B"); 213 ClassElement classB = compiler.mainApp.find("B");
214 FunctionElement fooB = classB.lookupLocalMember("foo"); 214 FunctionElement fooB = classB.lookupLocalMember("foo");
215 ClassElement classA = compiler.mainApp.find("A"); 215 ClassElement classA = compiler.mainApp.find("A");
216 FunctionElement fooA = classA.lookupLocalMember("foo"); 216 FunctionElement fooA = classA.lookupLocalMember("foo");
217 217
218 ResolverVisitor visitor = 218 ResolverVisitor visitor =
219 new ResolverVisitor(compiler, fooB, 219 new ResolverVisitor(compiler, fooB,
220 new ResolutionRegistry(compiler, 220 new ResolutionRegistry(compiler,
221 new CollectingTreeElements(fooB))); 221 new CollectingTreeElements(fooB)));
222 FunctionExpression node = (fooB as FunctionElementX).parseNode(compiler); 222 FunctionExpression node =
223 (fooB as FunctionElementX).parseNode(compiler.parsing);
223 visitor.visit(node.body); 224 visitor.visit(node.body);
224 Map mapping = map(visitor); 225 Map mapping = map(visitor);
225 226
226 Send superCall = node.body.asReturn().expression; 227 Send superCall = node.body.asReturn().expression;
227 FunctionElement called = mapping[superCall]; 228 FunctionElement called = mapping[superCall];
228 Expect.isNotNull(called); 229 Expect.isNotNull(called);
229 Expect.equals(fooA, called); 230 Expect.equals(fooA, called);
230 }); 231 });
231 } 232 }
232 233
(...skipping 22 matching lines...) Expand all
255 MockCompiler.create((MockCompiler compiler) { 256 MockCompiler.create((MockCompiler compiler) {
256 compiler.parseScript("class Foo { foo() { return this; } }"); 257 compiler.parseScript("class Foo { foo() { return this; } }");
257 compiler.resolveStatement("Foo foo;"); 258 compiler.resolveStatement("Foo foo;");
258 ClassElement fooElement = compiler.mainApp.find("Foo"); 259 ClassElement fooElement = compiler.mainApp.find("Foo");
259 FunctionElement funElement = fooElement.lookupLocalMember("foo"); 260 FunctionElement funElement = fooElement.lookupLocalMember("foo");
260 ResolverVisitor visitor = 261 ResolverVisitor visitor =
261 new ResolverVisitor(compiler, funElement, 262 new ResolverVisitor(compiler, funElement,
262 new ResolutionRegistry(compiler, 263 new ResolutionRegistry(compiler,
263 new CollectingTreeElements(funElement))); 264 new CollectingTreeElements(funElement)));
264 FunctionExpression function = 265 FunctionExpression function =
265 (funElement as FunctionElementX).parseNode(compiler); 266 (funElement as FunctionElementX).parseNode(compiler.parsing);
266 visitor.visit(function.body); 267 visitor.visit(function.body);
267 Map mapping = map(visitor); 268 Map mapping = map(visitor);
268 List<Element> values = mapping.values.toList(); 269 List<Element> values = mapping.values.toList();
269 Expect.equals(0, mapping.length); 270 Expect.equals(0, mapping.length);
270 Expect.equals(0, compiler.warnings.length); 271 Expect.equals(0, compiler.warnings.length);
271 }), 272 }),
272 MockCompiler.create((MockCompiler compiler) { 273 MockCompiler.create((MockCompiler compiler) {
273 compiler.resolveStatement("main() { return this; }"); 274 compiler.resolveStatement("main() { return this; }");
274 Expect.equals(0, compiler.warnings.length); 275 Expect.equals(0, compiler.warnings.length);
275 Expect.equals(1, compiler.errors.length); 276 Expect.equals(1, compiler.errors.length);
276 Expect.equals(MessageKind.NO_INSTANCE_AVAILABLE, 277 Expect.equals(MessageKind.NO_INSTANCE_AVAILABLE,
277 compiler.errors[0].message.kind); 278 compiler.errors[0].message.kind);
278 }), 279 }),
279 MockCompiler.create((MockCompiler compiler) { 280 MockCompiler.create((MockCompiler compiler) {
280 compiler.parseScript("class Foo { static foo() { return this; } }"); 281 compiler.parseScript("class Foo { static foo() { return this; } }");
281 compiler.resolveStatement("Foo foo;"); 282 compiler.resolveStatement("Foo foo;");
282 ClassElement fooElement = compiler.mainApp.find("Foo"); 283 ClassElement fooElement = compiler.mainApp.find("Foo");
283 FunctionElement funElement = fooElement.lookupLocalMember("foo"); 284 FunctionElement funElement = fooElement.lookupLocalMember("foo");
284 ResolverVisitor visitor = new ResolverVisitor(compiler, funElement, 285 ResolverVisitor visitor = new ResolverVisitor(compiler, funElement,
285 new ResolutionRegistry(compiler, 286 new ResolutionRegistry(compiler,
286 new CollectingTreeElements(funElement))); 287 new CollectingTreeElements(funElement)));
287 FunctionExpression function = 288 FunctionExpression function =
288 (funElement as FunctionElementX).parseNode(compiler); 289 (funElement as FunctionElementX).parseNode(compiler.parsing);
289 visitor.visit(function.body); 290 visitor.visit(function.body);
290 Expect.equals(0, compiler.warnings.length); 291 Expect.equals(0, compiler.warnings.length);
291 Expect.equals(1, compiler.errors.length); 292 Expect.equals(1, compiler.errors.length);
292 Expect.equals(MessageKind.NO_INSTANCE_AVAILABLE, 293 Expect.equals(MessageKind.NO_INSTANCE_AVAILABLE,
293 compiler.errors[0].message.kind); 294 compiler.errors[0].message.kind);
294 }), 295 }),
295 ]); 296 ]);
296 } 297 }
297 298
298 Future testLocalsOne() { 299 Future testLocalsOne() {
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 compiler.clearMessages(); 524 compiler.clearMessages();
524 }), 525 }),
525 MockCompiler.create((MockCompiler compiler) { 526 MockCompiler.create((MockCompiler compiler) {
526 compiler.parseScript("class Foo extends Bar {}"); 527 compiler.parseScript("class Foo extends Bar {}");
527 compiler.parseScript("class Bar {}"); 528 compiler.parseScript("class Bar {}");
528 Map mapping = compiler.resolveStatement("Foo bar;").map; 529 Map mapping = compiler.resolveStatement("Foo bar;").map;
529 Expect.equals(1, mapping.length); 530 Expect.equals(1, mapping.length);
530 531
531 ClassElement fooElement = compiler.mainApp.find('Foo'); 532 ClassElement fooElement = compiler.mainApp.find('Foo');
532 ClassElement barElement = compiler.mainApp.find('Bar'); 533 ClassElement barElement = compiler.mainApp.find('Bar');
533 Expect.equals(barElement.computeType(compiler), 534 Expect.equals(barElement.computeType(compiler.resolution),
534 fooElement.supertype); 535 fooElement.supertype);
535 Expect.isTrue(fooElement.interfaces.isEmpty); 536 Expect.isTrue(fooElement.interfaces.isEmpty);
536 Expect.isTrue(barElement.interfaces.isEmpty); 537 Expect.isTrue(barElement.interfaces.isEmpty);
537 }), 538 }),
538 ]); 539 ]);
539 } 540 }
540 541
541 Future testVarSuperclass() { 542 Future testVarSuperclass() {
542 return MockCompiler.create((MockCompiler compiler) { 543 return MockCompiler.create((MockCompiler compiler) {
543 compiler.parseScript("class Foo extends var {}"); 544 compiler.parseScript("class Foo extends var {}");
(...skipping 29 matching lines...) Expand all
573 new ResolutionRegistry(compiler, 574 new ResolutionRegistry(compiler,
574 new CollectingTreeElements(null))); 575 new CollectingTreeElements(null)));
575 compiler.resolveStatement("Foo bar;"); 576 compiler.resolveStatement("Foo bar;");
576 577
577 ClassElement fooElement = compiler.mainApp.find('Foo'); 578 ClassElement fooElement = compiler.mainApp.find('Foo');
578 ClassElement barElement = compiler.mainApp.find('Bar'); 579 ClassElement barElement = compiler.mainApp.find('Bar');
579 580
580 Expect.equals(null, barElement.supertype); 581 Expect.equals(null, barElement.supertype);
581 Expect.isTrue(barElement.interfaces.isEmpty); 582 Expect.isTrue(barElement.interfaces.isEmpty);
582 583
583 Expect.equals(barElement.computeType(compiler), 584 Expect.equals(barElement.computeType(compiler.resolution),
584 fooElement.interfaces.head); 585 fooElement.interfaces.head);
585 Expect.equals(1, length(fooElement.interfaces)); 586 Expect.equals(1, length(fooElement.interfaces));
586 }); 587 });
587 } 588 }
588 589
589 Future testTwoInterfaces() { 590 Future testTwoInterfaces() {
590 return MockCompiler.create((MockCompiler compiler) { 591 return MockCompiler.create((MockCompiler compiler) {
591 compiler.parseScript( 592 compiler.parseScript(
592 """abstract class I1 {} 593 """abstract class I1 {}
593 abstract class I2 {} 594 abstract class I2 {}
594 class C implements I1, I2 {}"""); 595 class C implements I1, I2 {}""");
595 compiler.resolveStatement("Foo bar;"); 596 compiler.resolveStatement("Foo bar;");
596 597
597 ClassElement c = compiler.mainApp.find('C'); 598 ClassElement c = compiler.mainApp.find('C');
598 ClassElement i1 = compiler.mainApp.find('I1'); 599 ClassElement i1 = compiler.mainApp.find('I1');
599 ClassElement i2 = compiler.mainApp.find('I2'); 600 ClassElement i2 = compiler.mainApp.find('I2');
600 601
601 Expect.equals(2, length(c.interfaces)); 602 Expect.equals(2, length(c.interfaces));
602 Expect.equals(i1.computeType(compiler), at(c.interfaces, 0)); 603 Expect.equals(i1.computeType(compiler.resolution), at(c.interfaces, 0));
603 Expect.equals(i2.computeType(compiler), at(c.interfaces, 1)); 604 Expect.equals(i2.computeType(compiler.resolution), at(c.interfaces, 1));
604 }); 605 });
605 } 606 }
606 607
607 Future testFunctionExpression() { 608 Future testFunctionExpression() {
608 return MockCompiler.create((MockCompiler compiler) { 609 return MockCompiler.create((MockCompiler compiler) {
609 ResolverVisitor visitor = compiler.resolverVisitor(); 610 ResolverVisitor visitor = compiler.resolverVisitor();
610 Map mapping = compiler.resolveStatement("int f() {}").map; 611 Map mapping = compiler.resolveStatement("int f() {}").map;
611 Expect.equals(2, mapping.length); 612 Expect.equals(2, mapping.length);
612 Element element; 613 Element element;
613 Node node; 614 Node node;
(...skipping 30 matching lines...) Expand all
644 Expect.equals(ElementKind.GENERATIVE_CONSTRUCTOR, element.kind); 645 Expect.equals(ElementKind.GENERATIVE_CONSTRUCTOR, element.kind);
645 Expect.isTrue(element.isSynthesized); 646 Expect.isTrue(element.isSynthesized);
646 }); 647 });
647 } 648 }
648 649
649 Future testTopLevelFields() { 650 Future testTopLevelFields() {
650 return MockCompiler.create((MockCompiler compiler) { 651 return MockCompiler.create((MockCompiler compiler) {
651 compiler.parseScript("int a;"); 652 compiler.parseScript("int a;");
652 VariableElementX element = compiler.mainApp.find("a"); 653 VariableElementX element = compiler.mainApp.find("a");
653 Expect.equals(ElementKind.FIELD, element.kind); 654 Expect.equals(ElementKind.FIELD, element.kind);
654 VariableDefinitions node = element.variables.parseNode(element, compiler); 655 VariableDefinitions node =
656 element.variables.parseNode(element, compiler.parsing);
655 Identifier typeName = node.type.typeName; 657 Identifier typeName = node.type.typeName;
656 Expect.equals(typeName.source, 'int'); 658 Expect.equals(typeName.source, 'int');
657 659
658 compiler.parseScript("var b, c;"); 660 compiler.parseScript("var b, c;");
659 VariableElementX bElement = compiler.mainApp.find("b"); 661 VariableElementX bElement = compiler.mainApp.find("b");
660 VariableElementX cElement = compiler.mainApp.find("c"); 662 VariableElementX cElement = compiler.mainApp.find("c");
661 Expect.equals(ElementKind.FIELD, bElement.kind); 663 Expect.equals(ElementKind.FIELD, bElement.kind);
662 Expect.equals(ElementKind.FIELD, cElement.kind); 664 Expect.equals(ElementKind.FIELD, cElement.kind);
663 Expect.isTrue(bElement != cElement); 665 Expect.isTrue(bElement != cElement);
664 666
665 VariableDefinitions bNode = bElement.variables.parseNode(bElement, compiler) ; 667 VariableDefinitions bNode =
666 VariableDefinitions cNode = cElement.variables.parseNode(cElement, compiler) ; 668 bElement.variables.parseNode(bElement, compiler.parsing);
669 VariableDefinitions cNode =
670 cElement.variables.parseNode(cElement, compiler.parsing);
667 Expect.equals(bNode, cNode); 671 Expect.equals(bNode, cNode);
668 Expect.isNull(bNode.type); 672 Expect.isNull(bNode.type);
669 Expect.isTrue(bNode.modifiers.isVar); 673 Expect.isTrue(bNode.modifiers.isVar);
670 }); 674 });
671 } 675 }
672 676
673 Future resolveConstructor( 677 Future resolveConstructor(
674 String script, String statement, String className, 678 String script, String statement, String className,
675 String constructor, int expectedElementCount, 679 String constructor, int expectedElementCount,
676 {List expectedWarnings: const [], 680 {List expectedWarnings: const [],
(...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after
1406 } 1410 }
1407 main() => A.m(); 1411 main() => A.m();
1408 ''', functionName: 'm'); 1412 ''', functionName: 'm');
1409 check(''' 1413 check('''
1410 class A { 1414 class A {
1411 m() => () => await - 3; 1415 m() => () => await - 3;
1412 } 1416 }
1413 main() => new A().m(); 1417 main() => new A().m();
1414 ''', className: 'A'); 1418 ''', className: 'A');
1415 } 1419 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/patch_test.dart ('k') | tests/compiler/dart2js/type_checker_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698