OLD | NEW |
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 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 : warnings = [], errors = [], | 227 : warnings = [], errors = [], |
227 sourceFiles = new Map<String, SourceFile>(), | 228 sourceFiles = new Map<String, SourceFile>(), |
228 super(enableTypeAssertions: enableTypeAssertions, | 229 super(enableTypeAssertions: enableTypeAssertions, |
229 enableMinification: enableMinification, | 230 enableMinification: enableMinification, |
230 enableConcreteTypeInference: enableConcreteTypeInference, | 231 enableConcreteTypeInference: enableConcreteTypeInference, |
231 maxConcreteTypeSize: maxConcreteTypeSize, | 232 maxConcreteTypeSize: maxConcreteTypeSize, |
232 disableTypeInferenceFlag: disableTypeInference, | 233 disableTypeInferenceFlag: disableTypeInference, |
233 analyzeAllFlag: analyzeAll, | 234 analyzeAllFlag: analyzeAll, |
234 analyzeOnly: analyzeOnly, | 235 analyzeOnly: analyzeOnly, |
235 preserveComments: preserveComments) { | 236 preserveComments: preserveComments) { |
236 coreLibrary = createLibrary("core", coreSource); | 237 coreLibrary = deprecatedFutureValue(createLibrary("core", coreSource)); |
| 238 |
237 // We need to set the assert method to avoid calls with a 'null' | 239 // We need to set the assert method to avoid calls with a 'null' |
238 // target being interpreted as a call to assert. | 240 // target being interpreted as a call to assert. |
239 jsHelperLibrary = createLibrary("helper", helperSource); | 241 jsHelperLibrary = deprecatedFutureValue( |
240 foreignLibrary = createLibrary("foreign", FOREIGN_LIBRARY); | 242 createLibrary("helper", helperSource)); |
241 interceptorsLibrary = createLibrary("interceptors", interceptorsSource); | 243 foreignLibrary = deprecatedFutureValue( |
242 isolateHelperLibrary = createLibrary("isolate_helper", isolateHelperSource); | 244 createLibrary("foreign", FOREIGN_LIBRARY)); |
| 245 interceptorsLibrary = deprecatedFutureValue( |
| 246 createLibrary("interceptors", interceptorsSource)); |
| 247 isolateHelperLibrary = deprecatedFutureValue( |
| 248 createLibrary("isolate_helper", isolateHelperSource)); |
243 | 249 |
244 // Set up the library imports. | 250 // Set up the library imports. |
245 importHelperLibrary(coreLibrary); | 251 importHelperLibrary(coreLibrary); |
246 libraryLoader.importLibrary(jsHelperLibrary, coreLibrary, null); | 252 libraryLoader.importLibrary(jsHelperLibrary, coreLibrary, null); |
247 libraryLoader.importLibrary(interceptorsLibrary, coreLibrary, null); | 253 libraryLoader.importLibrary(interceptorsLibrary, coreLibrary, null); |
248 libraryLoader.importLibrary(isolateHelperLibrary, coreLibrary, null); | 254 libraryLoader.importLibrary(isolateHelperLibrary, coreLibrary, null); |
249 | 255 |
250 assertMethod = jsHelperLibrary.find(buildSourceString('assert')); | 256 assertMethod = jsHelperLibrary.find(buildSourceString('assert')); |
251 identicalFunction = coreLibrary.find(buildSourceString('identical')); | 257 identicalFunction = coreLibrary.find(buildSourceString('identical')); |
252 | 258 |
(...skipping 17 matching lines...) Expand all Loading... |
270 * library. | 276 * library. |
271 */ | 277 */ |
272 void registerSource(Uri uri, String source) { | 278 void registerSource(Uri uri, String source) { |
273 sourceFiles[uri.toString()] = new MockFile(source); | 279 sourceFiles[uri.toString()] = new MockFile(source); |
274 } | 280 } |
275 | 281 |
276 /** | 282 /** |
277 * Used internally to create a library from a source text. The created library | 283 * Used internally to create a library from a source text. The created library |
278 * is fixed to export its top-level declarations. | 284 * is fixed to export its top-level declarations. |
279 */ | 285 */ |
280 LibraryElement createLibrary(String name, String source) { | 286 Future<LibraryElement> createLibrary(String name, String source) { |
281 Uri uri = new Uri(scheme: "dart", path: name); | 287 Uri uri = new Uri(scheme: "dart", path: name); |
282 var script = new Script(uri, new MockFile(source)); | 288 var script = new Script(uri, new MockFile(source)); |
283 var library = new LibraryElementX(script); | 289 var library = new LibraryElementX(script); |
284 library.libraryTag = new LibraryName(null, null, null); | 290 library.libraryTag = new LibraryName(null, null, null); |
285 parseScript(source, library); | 291 parseScript(source, library); |
286 library.setExports(library.localScope.values.toList()); | 292 library.setExports(library.localScope.values.toList()); |
287 registerSource(uri, source); | 293 registerSource(uri, source); |
288 libraries.putIfAbsent(uri.toString(), () => library); | 294 libraries.putIfAbsent(uri.toString(), () => library); |
289 return library; | 295 return new Future.value(library); |
290 } | 296 } |
291 | 297 |
292 void reportWarning(Node node, var message) { | 298 void reportWarning(Node node, var message) { |
293 if (message is! Message) message = message.message; | 299 if (message is! Message) message = message.message; |
294 warnings.add(new WarningMessage(node, message)); | 300 warnings.add(new WarningMessage(node, message)); |
295 reportDiagnostic(spanFromNode(node), | 301 reportDiagnostic(spanFromNode(node), |
296 'Warning: $message', api.Diagnostic.WARNING); | 302 'Warning: $message', api.Diagnostic.WARNING); |
297 } | 303 } |
298 | 304 |
299 void reportError(Spannable node, | 305 void reportError(Spannable node, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 new CollectingTreeElements(mockElement)); | 371 new CollectingTreeElements(mockElement)); |
366 visitor.scope = new MethodScope(visitor.scope, mockElement); | 372 visitor.scope = new MethodScope(visitor.scope, mockElement); |
367 return visitor; | 373 return visitor; |
368 } | 374 } |
369 | 375 |
370 parseScript(String text, [LibraryElement library]) { | 376 parseScript(String text, [LibraryElement library]) { |
371 if (library == null) library = mainApp; | 377 if (library == null) library = mainApp; |
372 parseUnit(text, this, library, registerSource); | 378 parseUnit(text, this, library, registerSource); |
373 } | 379 } |
374 | 380 |
375 void scanBuiltinLibraries() { | 381 Future scanBuiltinLibraries() { |
376 // Do nothing. The mock core library is already handled in the constructor. | 382 // Do nothing. The mock core library is already handled in the constructor. |
| 383 return new Future.value(); |
377 } | 384 } |
378 | 385 |
379 LibraryElement scanBuiltinLibrary(String name) { | 386 Future<LibraryElement> scanBuiltinLibrary(String name) { |
380 // Do nothing. The mock core library is already handled in the constructor. | 387 // Do nothing. The mock core library is already handled in the constructor. |
| 388 return new Future.value(); |
381 } | 389 } |
382 | 390 |
383 void importCoreLibrary(LibraryElement library) { | 391 void importCoreLibrary(LibraryElement library) { |
384 scanner.importLibrary(library, coreLibrary, null); | 392 scanner.importLibrary(library, coreLibrary, null); |
385 } | 393 } |
386 | 394 |
387 Uri translateResolvedUri(LibraryElement importingLibrary, | 395 Uri translateResolvedUri(LibraryElement importingLibrary, |
388 Uri resolvedUri, Node node) => resolvedUri; | 396 Uri resolvedUri, Node node) => resolvedUri; |
389 | 397 |
390 // The mock library doesn't need any patches. | 398 // The mock library doesn't need any patches. |
391 Uri resolvePatchUri(String dartLibraryName) => null; | 399 Uri resolvePatchUri(String dartLibraryName) => null; |
392 | 400 |
393 Script readScript(Uri uri, [Node node]) { | 401 Future<Script> readScript(Uri uri, [Element element, Node node]) { |
394 SourceFile sourceFile = sourceFiles[uri.toString()]; | 402 SourceFile sourceFile = sourceFiles[uri.toString()]; |
395 if (sourceFile == null) throw new ArgumentError(uri); | 403 if (sourceFile == null) throw new ArgumentError(uri); |
396 return new Script(uri, sourceFile); | 404 return new Future.value(new Script(uri, sourceFile)); |
397 } | 405 } |
398 | 406 |
399 Element lookupElementIn(ScopeContainerElement container, name) { | 407 Element lookupElementIn(ScopeContainerElement container, name) { |
400 Element element = container.localLookup(name); | 408 Element element = container.localLookup(name); |
401 return element != null | 409 return element != null |
402 ? element | 410 ? element |
403 : new ErroneousElementX(null, null, name, container); | 411 : new ErroneousElementX(null, null, name, container); |
404 } | 412 } |
405 } | 413 } |
406 | 414 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 } | 467 } |
460 } | 468 } |
461 | 469 |
462 class MockDeferredLoadTask extends DeferredLoadTask { | 470 class MockDeferredLoadTask extends DeferredLoadTask { |
463 MockDeferredLoadTask(Compiler compiler) : super(compiler); | 471 MockDeferredLoadTask(Compiler compiler) : super(compiler); |
464 | 472 |
465 void registerMainApp(LibraryElement mainApp) { | 473 void registerMainApp(LibraryElement mainApp) { |
466 // Do nothing. | 474 // Do nothing. |
467 } | 475 } |
468 } | 476 } |
OLD | NEW |