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

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

Issue 1915123008: Implements support for ignoring method type arguments in resolution. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 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
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 library mock_compiler; 5 library mock_compiler;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'package:compiler/compiler.dart' as api; 10 import 'package:compiler/compiler.dart' as api;
11 import 'package:compiler/src/common/names.dart' show 11 import 'package:compiler/src/common/names.dart' show
12 Uris; 12 Uris;
13 import 'package:compiler/src/constants/expressions.dart'; 13 import 'package:compiler/src/constants/expressions.dart';
14 import 'package:compiler/src/dart_types.dart' show DartType;
14 import 'package:compiler/src/diagnostics/diagnostic_listener.dart'; 15 import 'package:compiler/src/diagnostics/diagnostic_listener.dart';
15 import 'package:compiler/src/diagnostics/source_span.dart'; 16 import 'package:compiler/src/diagnostics/source_span.dart';
16 import 'package:compiler/src/diagnostics/spannable.dart'; 17 import 'package:compiler/src/diagnostics/spannable.dart';
17 import 'package:compiler/src/elements/elements.dart'; 18 import 'package:compiler/src/elements/elements.dart';
18 import 'package:compiler/src/elements/visitor.dart'; 19 import 'package:compiler/src/elements/visitor.dart';
19 import 'package:compiler/src/js_backend/backend_helpers.dart' show 20 import 'package:compiler/src/js_backend/backend_helpers.dart' show
20 BackendHelpers; 21 BackendHelpers;
21 import 'package:compiler/src/js_backend/lookup_map_analysis.dart' show 22 import 'package:compiler/src/js_backend/lookup_map_analysis.dart' show
22 LookupMapAnalysis; 23 LookupMapAnalysis;
23 import 'package:compiler/src/io/source_file.dart'; 24 import 'package:compiler/src/io/source_file.dart';
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 } 218 }
218 219
219 CollectingTreeElements resolveStatement(String text) { 220 CollectingTreeElements resolveStatement(String text) {
220 parsedTree = parseStatement(text); 221 parsedTree = parseStatement(text);
221 return resolveNodeStatement(parsedTree, new MockElement(mainApp)); 222 return resolveNodeStatement(parsedTree, new MockElement(mainApp));
222 } 223 }
223 224
224 TreeElementMapping resolveNodeStatement(Node tree, 225 TreeElementMapping resolveNodeStatement(Node tree,
225 ExecutableElement element) { 226 ExecutableElement element) {
226 ResolverVisitor visitor = 227 ResolverVisitor visitor =
227 new ResolverVisitor(this, element, 228 new ResolverVisitor(
229 this,
230 element,
228 new ResolutionRegistry(this, 231 new ResolutionRegistry(this,
229 new CollectingTreeElements(element))); 232 new CollectingTreeElements(element)),
230 if (visitor.scope is LibraryScope) { 233 scope: new MockTypeVariablesScope(
Johnni Winther 2016/04/29 07:21:06 Why is this necessary?
eernst 2016/04/29 13:24:50 I managed to remove one of the two usages of this
234 element.enclosingElement.buildScope()));
235 if (visitor.scope is LibraryScope ||
236 visitor.scope is MockTypeVariablesScope) {
231 visitor.scope = new MethodScope(visitor.scope, element); 237 visitor.scope = new MethodScope(visitor.scope, element);
232 } 238 }
233 visitor.visit(tree); 239 visitor.visit(tree);
234 visitor.scope = new LibraryScope(element.library); 240 visitor.scope = new LibraryScope(element.library);
235 return visitor.registry.mapping; 241 return visitor.registry.mapping;
236 } 242 }
237 243
238 resolverVisitor() { 244 resolverVisitor() {
239 Element mockElement = new MockElement(mainApp.entryCompilationUnit); 245 Element mockElement = new MockElement(mainApp.entryCompilationUnit);
240 ResolverVisitor visitor = 246 ResolverVisitor visitor =
241 new ResolverVisitor(this, mockElement, 247 new ResolverVisitor(
242 new ResolutionRegistry(this, 248 this,
243 new CollectingTreeElements(mockElement))); 249 mockElement,
250 new ResolutionRegistry(
251 this, new CollectingTreeElements(mockElement)),
252 scope: new MockTypeVariablesScope(
253 mockElement.enclosingElement.buildScope()));
244 visitor.scope = new MethodScope(visitor.scope, mockElement); 254 visitor.scope = new MethodScope(visitor.scope, mockElement);
245 return visitor; 255 return visitor;
246 } 256 }
247 257
248 parseScript(String text, [LibraryElement library]) { 258 parseScript(String text, [LibraryElement library]) {
249 if (library == null) library = mainApp; 259 if (library == null) library = mainApp;
250 parseUnit(text, this, library, registerSource); 260 parseUnit(text, this, library, registerSource);
251 } 261 }
252 262
253 Future scanBuiltinLibraries() { 263 Future scanBuiltinLibraries() {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 map.remove(node); 324 map.remove(node);
315 } 325 }
316 326
317 List<ConstantExpression> get constants { 327 List<ConstantExpression> get constants {
318 List<ConstantExpression> list = <ConstantExpression>[]; 328 List<ConstantExpression> list = <ConstantExpression>[];
319 forEachConstantNode((_, c) => list.add(c)); 329 forEachConstantNode((_, c) => list.add(c));
320 return list; 330 return list;
321 } 331 }
322 } 332 }
323 333
334 class MockTypeVariablesScope extends TypeVariablesScope {
335 @override
336 List<DartType> get typeVariables => <DartType>[];
337 MockTypeVariablesScope(Scope parent) : super(parent);
338 String toString() => 'MockTypeVariablesScope($parent)';
339 }
340
324 // The mock compiler does not split the program in output units. 341 // The mock compiler does not split the program in output units.
325 class MockDeferredLoadTask extends DeferredLoadTask { 342 class MockDeferredLoadTask extends DeferredLoadTask {
326 MockDeferredLoadTask(Compiler compiler) : super(compiler); 343 MockDeferredLoadTask(Compiler compiler) : super(compiler);
327 344
328 OutputUnit getElementOutputUnit(dynamic dependency) { 345 OutputUnit getElementOutputUnit(dynamic dependency) {
329 return mainOutputUnit; 346 return mainOutputUnit;
330 } 347 }
331 } 348 }
332 349
333 api.DiagnosticHandler createHandler(MockCompiler compiler, String text, 350 api.DiagnosticHandler createHandler(MockCompiler compiler, String text,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 trustTypeAnnotations: trustTypeAnnotations, 403 trustTypeAnnotations: trustTypeAnnotations,
387 enableTypeAssertions: enableTypeAssertions, 404 enableTypeAssertions: enableTypeAssertions,
388 enableUserAssertions: enableUserAssertions, 405 enableUserAssertions: enableUserAssertions,
389 expectedErrors: expectedErrors, 406 expectedErrors: expectedErrors,
390 expectedWarnings: expectedWarnings, 407 expectedWarnings: expectedWarnings,
391 outputProvider: outputProvider); 408 outputProvider: outputProvider);
392 compiler.registerSource(uri, code); 409 compiler.registerSource(uri, code);
393 compiler.diagnosticHandler = createHandler(compiler, code); 410 compiler.diagnosticHandler = createHandler(compiler, code);
394 return compiler; 411 return compiler;
395 } 412 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698