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