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

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

Issue 1942763002: Rebased and retested version of CL 1915123008. (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
« no previous file with comments | « pkg/compiler/lib/src/tree/nodes.dart ('k') | tests/compiler/dart2js/resolver_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) 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(
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: mockElement.enclosingElement.buildScope());
244 visitor.scope = new MethodScope(visitor.scope, mockElement); 253 visitor.scope = new MethodScope(visitor.scope, mockElement);
245 return visitor; 254 return visitor;
246 } 255 }
247 256
248 parseScript(String text, [LibraryElement library]) { 257 parseScript(String text, [LibraryElement library]) {
249 if (library == null) library = mainApp; 258 if (library == null) library = mainApp;
250 parseUnit(text, this, library, registerSource); 259 parseUnit(text, this, library, registerSource);
251 } 260 }
252 261
253 Future scanBuiltinLibraries() { 262 Future scanBuiltinLibraries() {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 map.remove(node); 323 map.remove(node);
315 } 324 }
316 325
317 List<ConstantExpression> get constants { 326 List<ConstantExpression> get constants {
318 List<ConstantExpression> list = <ConstantExpression>[]; 327 List<ConstantExpression> list = <ConstantExpression>[];
319 forEachConstantNode((_, c) => list.add(c)); 328 forEachConstantNode((_, c) => list.add(c));
320 return list; 329 return list;
321 } 330 }
322 } 331 }
323 332
333 class MockTypeVariablesScope extends TypeVariablesScope {
334 @override
335 List<DartType> get typeVariables => <DartType>[];
336 MockTypeVariablesScope(Scope parent) : super(parent);
337 String toString() => 'MockTypeVariablesScope($parent)';
338 }
339
324 // The mock compiler does not split the program in output units. 340 // The mock compiler does not split the program in output units.
325 class MockDeferredLoadTask extends DeferredLoadTask { 341 class MockDeferredLoadTask extends DeferredLoadTask {
326 MockDeferredLoadTask(Compiler compiler) : super(compiler); 342 MockDeferredLoadTask(Compiler compiler) : super(compiler);
327 343
328 OutputUnit getElementOutputUnit(dynamic dependency) { 344 OutputUnit getElementOutputUnit(dynamic dependency) {
329 return mainOutputUnit; 345 return mainOutputUnit;
330 } 346 }
331 } 347 }
332 348
333 api.DiagnosticHandler createHandler(MockCompiler compiler, String text, 349 api.DiagnosticHandler createHandler(MockCompiler compiler, String text,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 trustTypeAnnotations: trustTypeAnnotations, 402 trustTypeAnnotations: trustTypeAnnotations,
387 enableTypeAssertions: enableTypeAssertions, 403 enableTypeAssertions: enableTypeAssertions,
388 enableUserAssertions: enableUserAssertions, 404 enableUserAssertions: enableUserAssertions,
389 expectedErrors: expectedErrors, 405 expectedErrors: expectedErrors,
390 expectedWarnings: expectedWarnings, 406 expectedWarnings: expectedWarnings,
391 outputProvider: outputProvider); 407 outputProvider: outputProvider);
392 compiler.registerSource(uri, code); 408 compiler.registerSource(uri, code);
393 compiler.diagnosticHandler = createHandler(compiler, code); 409 compiler.diagnosticHandler = createHandler(compiler, code);
394 return compiler; 410 return compiler;
395 } 411 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/tree/nodes.dart ('k') | tests/compiler/dart2js/resolver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698