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

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

Issue 17759007: First pass at asynchronous input loading in dart2js. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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 | Annotate | Revision Log
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 library mock_compiler; 5 library mock_compiler;
6 6
7 import "package:expect/expect.dart"; 7 import "package:expect/expect.dart";
8 import 'dart:async';
8 import 'dart:collection'; 9 import 'dart:collection';
9 10
10 import '../../../sdk/lib/_internal/compiler/compiler.dart' as api; 11 import '../../../sdk/lib/_internal/compiler/compiler.dart' as api;
11 import '../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar t'; 12 import '../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar t';
12 import '../../../sdk/lib/_internal/compiler/implementation/resolution/resolution .dart'; 13 import '../../../sdk/lib/_internal/compiler/implementation/resolution/resolution .dart';
13 import '../../../sdk/lib/_internal/compiler/implementation/source_file.dart'; 14 import '../../../sdk/lib/_internal/compiler/implementation/source_file.dart';
14 import '../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart'; 15 import '../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart';
15 import '../../../sdk/lib/_internal/compiler/implementation/util/util.dart'; 16 import '../../../sdk/lib/_internal/compiler/implementation/util/util.dart';
16 import 'parser_helper.dart'; 17 import 'parser_helper.dart';
17 18
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 : warnings = [], errors = [], 218 : warnings = [], errors = [],
218 sourceFiles = new Map<String, SourceFile>(), 219 sourceFiles = new Map<String, SourceFile>(),
219 super(enableTypeAssertions: enableTypeAssertions, 220 super(enableTypeAssertions: enableTypeAssertions,
220 enableMinification: enableMinification, 221 enableMinification: enableMinification,
221 enableConcreteTypeInference: enableConcreteTypeInference, 222 enableConcreteTypeInference: enableConcreteTypeInference,
222 maxConcreteTypeSize: maxConcreteTypeSize, 223 maxConcreteTypeSize: maxConcreteTypeSize,
223 disableTypeInferenceFlag: disableTypeInference, 224 disableTypeInferenceFlag: disableTypeInference,
224 analyzeAllFlag: analyzeAll, 225 analyzeAllFlag: analyzeAll,
225 analyzeOnly: analyzeOnly, 226 analyzeOnly: analyzeOnly,
226 preserveComments: preserveComments) { 227 preserveComments: preserveComments) {
227 coreLibrary = createLibrary("core", coreSource); 228 coreLibrary = deprecatedFutureValue(createLibrary("core", coreSource));
229
228 // We need to set the assert method to avoid calls with a 'null' 230 // We need to set the assert method to avoid calls with a 'null'
229 // target being interpreted as a call to assert. 231 // target being interpreted as a call to assert.
230 jsHelperLibrary = createLibrary("helper", helperSource); 232 jsHelperLibrary = deprecatedFutureValue(createLibrary("helper", helperSource ));
231 foreignLibrary = createLibrary("foreign", FOREIGN_LIBRARY); 233 foreignLibrary = deprecatedFutureValue(createLibrary("foreign", FOREIGN_LIBR ARY));
232 interceptorsLibrary = createLibrary("interceptors", interceptorsSource); 234 interceptorsLibrary = deprecatedFutureValue(createLibrary("interceptors", in terceptorsSource));
233 isolateHelperLibrary = createLibrary("isolate_helper", isolateHelperSource); 235 isolateHelperLibrary = deprecatedFutureValue(createLibrary("isolate_helper", isolateHelperSource));
234 236
235 // Set up the library imports. 237 // Set up the library imports.
236 importHelperLibrary(coreLibrary); 238 importHelperLibrary(coreLibrary);
237 libraryLoader.importLibrary(jsHelperLibrary, coreLibrary, null); 239 libraryLoader.importLibrary(jsHelperLibrary, coreLibrary, null);
238 libraryLoader.importLibrary(interceptorsLibrary, coreLibrary, null); 240 libraryLoader.importLibrary(interceptorsLibrary, coreLibrary, null);
239 libraryLoader.importLibrary(isolateHelperLibrary, coreLibrary, null); 241 libraryLoader.importLibrary(isolateHelperLibrary, coreLibrary, null);
240 242
241 assertMethod = jsHelperLibrary.find(buildSourceString('assert')); 243 assertMethod = jsHelperLibrary.find(buildSourceString('assert'));
242 identicalFunction = coreLibrary.find(buildSourceString('identical')); 244 identicalFunction = coreLibrary.find(buildSourceString('identical'));
243 245
(...skipping 17 matching lines...) Expand all
261 * library. 263 * library.
262 */ 264 */
263 void registerSource(Uri uri, String source) { 265 void registerSource(Uri uri, String source) {
264 sourceFiles[uri.toString()] = new MockFile(source); 266 sourceFiles[uri.toString()] = new MockFile(source);
265 } 267 }
266 268
267 /** 269 /**
268 * Used internally to create a library from a source text. The created library 270 * Used internally to create a library from a source text. The created library
269 * is fixed to export its top-level declarations. 271 * is fixed to export its top-level declarations.
270 */ 272 */
271 LibraryElement createLibrary(String name, String source) { 273 Future<LibraryElement> createLibrary(String name, String source) {
272 Uri uri = new Uri(scheme: "dart", path: name); 274 Uri uri = new Uri(scheme: "dart", path: name);
273 var script = new Script(uri, new MockFile(source)); 275 var script = new Script(uri, new MockFile(source));
274 var library = new LibraryElementX(script); 276 var library = new LibraryElementX(script);
275 parseScript(source, library); 277 parseScript(source, library);
276 library.setExports(library.localScope.values.toList()); 278 library.setExports(library.localScope.values.toList());
277 registerSource(uri, source); 279 registerSource(uri, source);
278 libraries.putIfAbsent(uri.toString(), () => library); 280 libraries.putIfAbsent(uri.toString(), () => library);
279 return library; 281 return new Future.value(library);
280 } 282 }
281 283
282 void reportWarning(Node node, var message) { 284 void reportWarning(Node node, var message) {
283 if (message is! Message) message = message.message; 285 if (message is! Message) message = message.message;
284 warnings.add(new WarningMessage(node, message)); 286 warnings.add(new WarningMessage(node, message));
285 reportDiagnostic(spanFromNode(node), 287 reportDiagnostic(spanFromNode(node),
286 'Warning: $message', api.Diagnostic.WARNING); 288 'Warning: $message', api.Diagnostic.WARNING);
287 } 289 }
288 290
289 void reportError(Node node, var message) { 291 void reportError(Node node, var message) {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 new CollectingTreeElements(mockElement)); 354 new CollectingTreeElements(mockElement));
353 visitor.scope = new MethodScope(visitor.scope, mockElement); 355 visitor.scope = new MethodScope(visitor.scope, mockElement);
354 return visitor; 356 return visitor;
355 } 357 }
356 358
357 parseScript(String text, [LibraryElement library]) { 359 parseScript(String text, [LibraryElement library]) {
358 if (library == null) library = mainApp; 360 if (library == null) library = mainApp;
359 parseUnit(text, this, library, registerSource); 361 parseUnit(text, this, library, registerSource);
360 } 362 }
361 363
362 void scanBuiltinLibraries() { 364 Future scanBuiltinLibraries() {
363 // Do nothing. The mock core library is already handled in the constructor. 365 // Do nothing. The mock core library is already handled in the constructor.
366 return new Future.value();
364 } 367 }
365 368
366 LibraryElement scanBuiltinLibrary(String name) { 369 Future<LibraryElement> scanBuiltinLibrary(String name) {
367 // Do nothing. The mock core library is already handled in the constructor. 370 // Do nothing. The mock core library is already handled in the constructor.
371 return new Future.value();
368 } 372 }
369 373
370 void importCoreLibrary(LibraryElement library) { 374 void importCoreLibrary(LibraryElement library) {
371 scanner.importLibrary(library, coreLibrary, null); 375 scanner.importLibrary(library, coreLibrary, null);
372 } 376 }
373 377
374 Uri translateResolvedUri(LibraryElement importingLibrary, 378 Uri translateResolvedUri(LibraryElement importingLibrary,
375 Uri resolvedUri, Node node) => resolvedUri; 379 Uri resolvedUri, Node node) => resolvedUri;
376 380
377 // The mock library doesn't need any patches. 381 // The mock library doesn't need any patches.
378 Uri resolvePatchUri(String dartLibraryName) => null; 382 Uri resolvePatchUri(String dartLibraryName) => null;
379 383
380 Script readScript(Uri uri, [Node node]) { 384 Future<Script> readScript(Uri uri, [Node node]) {
381 SourceFile sourceFile = sourceFiles[uri.toString()]; 385 SourceFile sourceFile = sourceFiles[uri.toString()];
382 if (sourceFile == null) throw new ArgumentError(uri); 386 if (sourceFile == null) throw new ArgumentError(uri);
383 return new Script(uri, sourceFile); 387 return new Future.value(new Script(uri, sourceFile));
384 } 388 }
385 389
386 Element lookupElementIn(ScopeContainerElement container, name) { 390 Element lookupElementIn(ScopeContainerElement container, name) {
387 Element element = container.localLookup(name); 391 Element element = container.localLookup(name);
388 return element != null 392 return element != null
389 ? element 393 ? element
390 : new ErroneousElementX(null, null, name, container); 394 : new ErroneousElementX(null, null, name, container);
391 } 395 }
392 } 396 }
393 397
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 } 450 }
447 } 451 }
448 452
449 class MockDeferredLoadTask extends DeferredLoadTask { 453 class MockDeferredLoadTask extends DeferredLoadTask {
450 MockDeferredLoadTask(Compiler compiler) : super(compiler); 454 MockDeferredLoadTask(Compiler compiler) : super(compiler);
451 455
452 void registerMainApp(LibraryElement mainApp) { 456 void registerMainApp(LibraryElement mainApp) {
453 // Do nothing. 457 // Do nothing.
454 } 458 }
455 } 459 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698