Chromium Code Reviews| 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:async'; |
| 9 import 'dart:collection'; | 9 import 'dart:collection'; |
| 10 | 10 |
| 11 import '../../../sdk/lib/_internal/compiler/compiler.dart' as api; | 11 import '../../../sdk/lib/_internal/compiler/compiler.dart' as api; |
| 12 import '../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar t'; | 12 import '../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar t'; |
| 13 import '../../../sdk/lib/_internal/compiler/implementation/resolution/resolution .dart'; | 13 import '../../../sdk/lib/_internal/compiler/implementation/resolution/resolution .dart'; |
| 14 import '../../../sdk/lib/_internal/compiler/implementation/source_file.dart'; | 14 import '../../../sdk/lib/_internal/compiler/implementation/source_file.dart'; |
| 15 import '../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart'; | 15 import '../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart'; |
| 16 import '../../../sdk/lib/_internal/compiler/implementation/util/util.dart'; | 16 import '../../../sdk/lib/_internal/compiler/implementation/util/util.dart'; |
| 17 import 'parser_helper.dart'; | 17 import 'parser_helper.dart'; |
| 18 | 18 |
| 19 import '../../../sdk/lib/_internal/compiler/implementation/elements/modelx.dart' | 19 import '../../../sdk/lib/_internal/compiler/implementation/elements/modelx.dart' |
| 20 show ElementX, | 20 show ElementX, |
| 21 LibraryElementX, | 21 LibraryElementX, |
| 22 ErroneousElementX; | 22 ErroneousElementX; |
| 23 | 23 |
| 24 import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart' | 24 import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart' |
| 25 hide TreeElementMapping; | 25 hide TreeElementMapping; |
| 26 | 26 |
| 27 import '../../../sdk/lib/_internal/compiler/implementation/dart_types.dart'; | |
|
Johnni Winther
2013/09/04 12:13:41
Unused import.
| |
| 28 | |
| 29 import '../../../sdk/lib/_internal/compiler/implementation/deferred_load.dart' | 27 import '../../../sdk/lib/_internal/compiler/implementation/deferred_load.dart' |
| 30 show DeferredLoadTask; | 28 show DeferredLoadTask; |
| 31 | 29 |
| 32 | 30 |
| 33 class WarningMessage { | 31 class WarningMessage { |
| 34 Spannable node; | 32 Spannable node; |
| 35 Message message; | 33 Message message; |
| 36 WarningMessage(this.node, this.message); | 34 WarningMessage(this.node, this.message); |
| 37 | 35 |
| 38 toString() => message.toString(); | 36 toString() => message.toString(); |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 232 sourceFiles = new Map<String, SourceFile>(), | 230 sourceFiles = new Map<String, SourceFile>(), |
| 233 super(enableTypeAssertions: enableTypeAssertions, | 231 super(enableTypeAssertions: enableTypeAssertions, |
| 234 enableMinification: enableMinification, | 232 enableMinification: enableMinification, |
| 235 enableConcreteTypeInference: enableConcreteTypeInference, | 233 enableConcreteTypeInference: enableConcreteTypeInference, |
| 236 maxConcreteTypeSize: maxConcreteTypeSize, | 234 maxConcreteTypeSize: maxConcreteTypeSize, |
| 237 disableTypeInferenceFlag: disableTypeInference, | 235 disableTypeInferenceFlag: disableTypeInference, |
| 238 analyzeAllFlag: analyzeAll, | 236 analyzeAllFlag: analyzeAll, |
| 239 analyzeOnly: analyzeOnly, | 237 analyzeOnly: analyzeOnly, |
| 240 emitJavaScript: emitJavaScript, | 238 emitJavaScript: emitJavaScript, |
| 241 preserveComments: preserveComments) { | 239 preserveComments: preserveComments) { |
| 242 coreLibrary = deprecatedFutureValue(createLibrary("core", coreSource)); | 240 coreLibrary = createLibrary("core", coreSource); |
| 243 | 241 |
| 244 // We need to set the assert method to avoid calls with a 'null' | 242 // We need to set the assert method to avoid calls with a 'null' |
| 245 // target being interpreted as a call to assert. | 243 // target being interpreted as a call to assert. |
| 246 jsHelperLibrary = deprecatedFutureValue( | 244 jsHelperLibrary = createLibrary("helper", helperSource); |
| 247 createLibrary("helper", helperSource)); | 245 foreignLibrary = createLibrary("foreign", FOREIGN_LIBRARY); |
| 248 foreignLibrary = deprecatedFutureValue( | 246 interceptorsLibrary = createLibrary("interceptors", interceptorsSource); |
| 249 createLibrary("foreign", FOREIGN_LIBRARY)); | 247 isolateHelperLibrary = createLibrary("isolate_helper", isolateHelperSource); |
| 250 interceptorsLibrary = deprecatedFutureValue( | |
| 251 createLibrary("interceptors", interceptorsSource)); | |
| 252 isolateHelperLibrary = deprecatedFutureValue( | |
| 253 createLibrary("isolate_helper", isolateHelperSource)); | |
| 254 | 248 |
| 255 // Set up the library imports. | 249 // Set up the library imports. |
| 256 importHelperLibrary(coreLibrary); | 250 importHelperLibrary(coreLibrary); |
| 257 libraryLoader.importLibrary(jsHelperLibrary, coreLibrary, null); | 251 libraryLoader.importLibrary(jsHelperLibrary, coreLibrary, null); |
| 258 libraryLoader.importLibrary(interceptorsLibrary, coreLibrary, null); | 252 libraryLoader.importLibrary(interceptorsLibrary, coreLibrary, null); |
| 259 libraryLoader.importLibrary(isolateHelperLibrary, coreLibrary, null); | 253 libraryLoader.importLibrary(isolateHelperLibrary, coreLibrary, null); |
| 260 | 254 |
| 261 assertMethod = jsHelperLibrary.find(buildSourceString('assert')); | 255 assertMethod = jsHelperLibrary.find(buildSourceString('assert')); |
| 262 identicalFunction = coreLibrary.find(buildSourceString('identical')); | 256 identicalFunction = coreLibrary.find(buildSourceString('identical')); |
| 263 | 257 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 281 * library. | 275 * library. |
| 282 */ | 276 */ |
| 283 void registerSource(Uri uri, String source) { | 277 void registerSource(Uri uri, String source) { |
| 284 sourceFiles[uri.toString()] = new MockFile(source); | 278 sourceFiles[uri.toString()] = new MockFile(source); |
| 285 } | 279 } |
| 286 | 280 |
| 287 /** | 281 /** |
| 288 * Used internally to create a library from a source text. The created library | 282 * Used internally to create a library from a source text. The created library |
| 289 * is fixed to export its top-level declarations. | 283 * is fixed to export its top-level declarations. |
| 290 */ | 284 */ |
| 291 Future<LibraryElement> createLibrary(String name, String source) { | 285 LibraryElement createLibrary(String name, String source) { |
| 292 Uri uri = new Uri(scheme: "dart", path: name); | 286 Uri uri = new Uri(scheme: "dart", path: name); |
| 293 var script = new Script(uri, new MockFile(source)); | 287 var script = new Script(uri, new MockFile(source)); |
| 294 var library = new LibraryElementX(script); | 288 var library = new LibraryElementX(script); |
| 295 library.libraryTag = new LibraryName(null, null, null); | 289 library.libraryTag = new LibraryName(null, null, null); |
| 296 parseScript(source, library); | 290 parseScript(source, library); |
| 297 library.setExports(library.localScope.values.toList()); | 291 library.setExports(library.localScope.values.toList()); |
| 298 registerSource(uri, source); | 292 registerSource(uri, source); |
| 299 libraries.putIfAbsent(uri.toString(), () => library); | 293 libraries.putIfAbsent(uri.toString(), () => library); |
| 300 return new Future.value(library); | 294 return library; |
| 301 } | 295 } |
| 302 | 296 |
| 303 void reportWarning(Node node, var message) { | 297 void reportWarning(Node node, var message) { |
| 304 if (message is! Message) message = message.message; | 298 if (message is! Message) message = message.message; |
| 305 warnings.add(new WarningMessage(node, message)); | 299 warnings.add(new WarningMessage(node, message)); |
| 306 reportDiagnostic(spanFromNode(node), | 300 reportDiagnostic(spanFromNode(node), |
| 307 'Warning: $message', api.Diagnostic.WARNING); | 301 'Warning: $message', api.Diagnostic.WARNING); |
| 308 } | 302 } |
| 309 | 303 |
| 310 void reportError(Spannable node, | 304 void reportError(Spannable node, |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 468 } | 462 } |
| 469 } | 463 } |
| 470 | 464 |
| 471 class MockDeferredLoadTask extends DeferredLoadTask { | 465 class MockDeferredLoadTask extends DeferredLoadTask { |
| 472 MockDeferredLoadTask(Compiler compiler) : super(compiler); | 466 MockDeferredLoadTask(Compiler compiler) : super(compiler); |
| 473 | 467 |
| 474 void registerMainApp(LibraryElement mainApp) { | 468 void registerMainApp(LibraryElement mainApp) { |
| 475 // Do nothing. | 469 // Do nothing. |
| 476 } | 470 } |
| 477 } | 471 } |
| OLD | NEW |