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

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

Issue 2123073003: remove dependency on compiler from resolution (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: respond to comments Created 4 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 | « tests/compiler/dart2js/mock_compiler.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) 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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 class B extends A { foo() => super.foo(); }"""; 216 class B extends A { foo() => super.foo(); }""";
217 compiler.parseScript(script); 217 compiler.parseScript(script);
218 compiler.resolveStatement("B b;"); 218 compiler.resolveStatement("B b;");
219 219
220 ClassElement classB = compiler.mainApp.find("B"); 220 ClassElement classB = compiler.mainApp.find("B");
221 FunctionElement fooB = classB.lookupLocalMember("foo"); 221 FunctionElement fooB = classB.lookupLocalMember("foo");
222 ClassElement classA = compiler.mainApp.find("A"); 222 ClassElement classA = compiler.mainApp.find("A");
223 FunctionElement fooA = classA.lookupLocalMember("foo"); 223 FunctionElement fooA = classA.lookupLocalMember("foo");
224 224
225 ResolverVisitor visitor = new ResolverVisitor( 225 ResolverVisitor visitor = new ResolverVisitor(
226 compiler, 226 compiler.resolution,
227 fooB, 227 fooB,
228 new ResolutionRegistry(compiler, new CollectingTreeElements(fooB)), 228 new ResolutionRegistry(
229 compiler.backend,
230 new CollectingTreeElements(fooB)),
229 scope: new MockTypeVariablesScope(classB.buildScope())); 231 scope: new MockTypeVariablesScope(classB.buildScope()));
230 FunctionExpression node = 232 FunctionExpression node =
231 (fooB as FunctionElementX).parseNode(compiler.parsingContext); 233 (fooB as FunctionElementX).parseNode(compiler.parsingContext);
232 visitor.visit(node.body); 234 visitor.visit(node.body);
233 Map mapping = map(visitor); 235 Map mapping = map(visitor);
234 236
235 Send superCall = node.body.asReturn().expression; 237 Send superCall = node.body.asReturn().expression;
236 FunctionElement called = mapping[superCall]; 238 FunctionElement called = mapping[superCall];
237 Expect.isNotNull(called); 239 Expect.isNotNull(called);
238 Expect.equals(fooA, called); 240 Expect.equals(fooA, called);
(...skipping 22 matching lines...) Expand all
261 } 263 }
262 264
263 Future testThis() { 265 Future testThis() {
264 return Future.wait([ 266 return Future.wait([
265 MockCompiler.create((MockCompiler compiler) { 267 MockCompiler.create((MockCompiler compiler) {
266 compiler.parseScript("class Foo { foo() { return this; } }"); 268 compiler.parseScript("class Foo { foo() { return this; } }");
267 compiler.resolveStatement("Foo foo;"); 269 compiler.resolveStatement("Foo foo;");
268 ClassElement fooElement = compiler.mainApp.find("Foo"); 270 ClassElement fooElement = compiler.mainApp.find("Foo");
269 FunctionElement funElement = fooElement.lookupLocalMember("foo"); 271 FunctionElement funElement = fooElement.lookupLocalMember("foo");
270 ResolverVisitor visitor = new ResolverVisitor( 272 ResolverVisitor visitor = new ResolverVisitor(
271 compiler, 273 compiler.resolution,
272 funElement, 274 funElement,
273 new ResolutionRegistry( 275 new ResolutionRegistry(
274 compiler, new CollectingTreeElements(funElement)), 276 compiler.backend, new CollectingTreeElements(funElement)),
275 scope: new MockTypeVariablesScope(fooElement.buildScope())); 277 scope: new MockTypeVariablesScope(fooElement.buildScope()));
276 FunctionExpression function = 278 FunctionExpression function =
277 (funElement as FunctionElementX).parseNode(compiler.parsingContext); 279 (funElement as FunctionElementX).parseNode(compiler.parsingContext);
278 visitor.visit(function.body); 280 visitor.visit(function.body);
279 Map mapping = map(visitor); 281 Map mapping = map(visitor);
280 List<Element> values = mapping.values.toList(); 282 List<Element> values = mapping.values.toList();
281 DiagnosticCollector collector = compiler.diagnosticCollector; 283 DiagnosticCollector collector = compiler.diagnosticCollector;
282 Expect.equals(0, mapping.length); 284 Expect.equals(0, mapping.length);
283 Expect.equals(0, collector.warnings.length); 285 Expect.equals(0, collector.warnings.length);
284 }), 286 }),
285 MockCompiler.create((MockCompiler compiler) { 287 MockCompiler.create((MockCompiler compiler) {
286 compiler.resolveStatement("main() { return this; }"); 288 compiler.resolveStatement("main() { return this; }");
287 DiagnosticCollector collector = compiler.diagnosticCollector; 289 DiagnosticCollector collector = compiler.diagnosticCollector;
288 Expect.equals(0, collector.warnings.length); 290 Expect.equals(0, collector.warnings.length);
289 Expect.equals(1, collector.errors.length); 291 Expect.equals(1, collector.errors.length);
290 Expect.equals(MessageKind.NO_INSTANCE_AVAILABLE, 292 Expect.equals(MessageKind.NO_INSTANCE_AVAILABLE,
291 collector.errors.first.message.kind); 293 collector.errors.first.message.kind);
292 }), 294 }),
293 MockCompiler.create((MockCompiler compiler) { 295 MockCompiler.create((MockCompiler compiler) {
294 compiler.parseScript("class Foo { static foo() { return this; } }"); 296 compiler.parseScript("class Foo { static foo() { return this; } }");
295 compiler.resolveStatement("Foo foo;"); 297 compiler.resolveStatement("Foo foo;");
296 ClassElement fooElement = compiler.mainApp.find("Foo"); 298 ClassElement fooElement = compiler.mainApp.find("Foo");
297 FunctionElement funElement = fooElement.lookupLocalMember("foo"); 299 FunctionElement funElement = fooElement.lookupLocalMember("foo");
298 ResolverVisitor visitor = new ResolverVisitor( 300 ResolverVisitor visitor = new ResolverVisitor(
299 compiler, 301 compiler.resolution,
300 funElement, 302 funElement,
301 new ResolutionRegistry( 303 new ResolutionRegistry(
302 compiler, new CollectingTreeElements(funElement)), 304 compiler.backend, new CollectingTreeElements(funElement)),
303 scope: new MockTypeVariablesScope(fooElement.buildScope())); 305 scope: new MockTypeVariablesScope(fooElement.buildScope()));
304 FunctionExpression function = 306 FunctionExpression function =
305 (funElement as FunctionElementX).parseNode(compiler.parsingContext); 307 (funElement as FunctionElementX).parseNode(compiler.parsingContext);
306 visitor.visit(function.body); 308 visitor.visit(function.body);
307 DiagnosticCollector collector = compiler.diagnosticCollector; 309 DiagnosticCollector collector = compiler.diagnosticCollector;
308 Expect.equals(0, collector.warnings.length); 310 Expect.equals(0, collector.warnings.length);
309 Expect.equals(1, collector.errors.length); 311 Expect.equals(1, collector.errors.length);
310 Expect.equals(MessageKind.NO_INSTANCE_AVAILABLE, 312 Expect.equals(MessageKind.NO_INSTANCE_AVAILABLE,
311 collector.errors.first.message.kind); 313 collector.errors.first.message.kind);
312 }), 314 }),
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 MessageTemplate.TEMPLATES[MessageKind.CANNOT_RESOLVE_TYPE], 583 MessageTemplate.TEMPLATES[MessageKind.CANNOT_RESOLVE_TYPE],
582 {'typeName': 'bar'}, false), 584 {'typeName': 'bar'}, false),
583 collector.errors.first.message); 585 collector.errors.first.message);
584 collector.clear(); 586 collector.clear();
585 587
586 // Add the abstract class to the world and make sure everything is setup 588 // Add the abstract class to the world and make sure everything is setup
587 // correctly. 589 // correctly.
588 compiler.parseScript("abstract class Bar {}"); 590 compiler.parseScript("abstract class Bar {}");
589 591
590 ResolverVisitor visitor = new ResolverVisitor( 592 ResolverVisitor visitor = new ResolverVisitor(
591 compiler, 593 compiler.resolution,
592 null, 594 null,
593 new ResolutionRegistry(compiler, new CollectingTreeElements(null))); 595 new ResolutionRegistry(
596 compiler.backend,
597 new CollectingTreeElements(null)));
594 compiler.resolveStatement("Foo bar;"); 598 compiler.resolveStatement("Foo bar;");
595 599
596 ClassElement fooElement = compiler.mainApp.find('Foo'); 600 ClassElement fooElement = compiler.mainApp.find('Foo');
597 ClassElement barElement = compiler.mainApp.find('Bar'); 601 ClassElement barElement = compiler.mainApp.find('Bar');
598 602
599 Expect.equals(null, barElement.supertype); 603 Expect.equals(null, barElement.supertype);
600 Expect.isTrue(barElement.interfaces.isEmpty); 604 Expect.isTrue(barElement.interfaces.isEmpty);
601 605
602 Expect.equals(barElement.computeType(compiler.resolution), 606 Expect.equals(barElement.computeType(compiler.resolution),
603 fooElement.interfaces.head); 607 fooElement.interfaces.head);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 Map<String, String> corelib}) { 704 Map<String, String> corelib}) {
701 MockCompiler compiler = new MockCompiler.internal(coreSource: corelib); 705 MockCompiler compiler = new MockCompiler.internal(coreSource: corelib);
702 return compiler.init().then((_) { 706 return compiler.init().then((_) {
703 compiler.parseScript(script); 707 compiler.parseScript(script);
704 compiler.resolveStatement(statement); 708 compiler.resolveStatement(statement);
705 ClassElement classElement = compiler.mainApp.find(className); 709 ClassElement classElement = compiler.mainApp.find(className);
706 Element element; 710 Element element;
707 element = classElement.lookupConstructor(constructor); 711 element = classElement.lookupConstructor(constructor);
708 FunctionExpression tree = (element as FunctionElement).node; 712 FunctionExpression tree = (element as FunctionElement).node;
709 ResolverVisitor visitor = new ResolverVisitor( 713 ResolverVisitor visitor = new ResolverVisitor(
710 compiler, 714 compiler.resolution,
711 element, 715 element,
712 new ResolutionRegistry(compiler, new CollectingTreeElements(element)), 716 new ResolutionRegistry(
717 compiler.backend,
718 new CollectingTreeElements(element)),
713 scope: classElement.buildScope()); 719 scope: classElement.buildScope());
714 new InitializerResolver(visitor, element, tree).resolveInitializers(); 720 new InitializerResolver(visitor, element, tree).resolveInitializers();
715 visitor.visit(tree.body); 721 visitor.visit(tree.body);
716 Expect.equals(expectedElementCount, map(visitor).length, 722 Expect.equals(expectedElementCount, map(visitor).length,
717 "${map(visitor).values} for '$statement' in context of `$script`"); 723 "${map(visitor).values} for '$statement' in context of `$script`");
718 724
719 DiagnosticCollector collector = compiler.diagnosticCollector; 725 DiagnosticCollector collector = compiler.diagnosticCollector;
720 compareWarningKinds(script, expectedWarnings, collector.warnings); 726 compareWarningKinds(script, expectedWarnings, collector.warnings);
721 compareWarningKinds(script, expectedErrors, collector.errors); 727 compareWarningKinds(script, expectedErrors, collector.errors);
722 compareWarningKinds(script, expectedInfos, collector.infos); 728 compareWarningKinds(script, expectedInfos, collector.infos);
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after
1447 } 1453 }
1448 main() => A.m(); 1454 main() => A.m();
1449 ''', functionName: 'm'); 1455 ''', functionName: 'm');
1450 check(''' 1456 check('''
1451 class A { 1457 class A {
1452 m() => () => await - 3; 1458 m() => () => await - 3;
1453 } 1459 }
1454 main() => new A().m(); 1460 main() => new A().m();
1455 ''', className: 'A'); 1461 ''', className: 'A');
1456 } 1462 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/mock_compiler.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698