| 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:collection'; | 8 import 'dart:collection'; |
| 9 | 9 |
| 10 import '../../../sdk/lib/_internal/compiler/compiler.dart' as api; | 10 import '../../../sdk/lib/_internal/compiler/compiler.dart' as api; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart' | 23 import '../../../sdk/lib/_internal/compiler/implementation/dart2jslib.dart' |
| 24 hide TreeElementMapping; | 24 hide TreeElementMapping; |
| 25 | 25 |
| 26 import '../../../sdk/lib/_internal/compiler/implementation/dart_types.dart'; | 26 import '../../../sdk/lib/_internal/compiler/implementation/dart_types.dart'; |
| 27 | 27 |
| 28 import '../../../sdk/lib/_internal/compiler/implementation/deferred_load.dart' | 28 import '../../../sdk/lib/_internal/compiler/implementation/deferred_load.dart' |
| 29 show DeferredLoadTask; | 29 show DeferredLoadTask; |
| 30 | 30 |
| 31 | 31 |
| 32 class WarningMessage { | 32 class WarningMessage { |
| 33 Node node; | 33 Spannable node; |
| 34 Message message; | 34 Message message; |
| 35 WarningMessage(this.node, this.message); | 35 WarningMessage(this.node, this.message); |
| 36 | 36 |
| 37 toString() => message.toString(); | 37 toString() => message.toString(); |
| 38 } | 38 } |
| 39 | 39 |
| 40 const String DEFAULT_HELPERLIB = r''' | 40 const String DEFAULT_HELPERLIB = r''' |
| 41 wrapException(x) { return x; } | 41 wrapException(x) { return x; } |
| 42 iae(x) { throw x; } ioore(x) { throw x; } | 42 iae(x) { throw x; } ioore(x) { throw x; } |
| 43 guard$array(x) { return x; } | 43 guard$array(x) { return x; } |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 } | 274 } |
| 275 | 275 |
| 276 /** | 276 /** |
| 277 * Used internally to create a library from a source text. The created library | 277 * Used internally to create a library from a source text. The created library |
| 278 * is fixed to export its top-level declarations. | 278 * is fixed to export its top-level declarations. |
| 279 */ | 279 */ |
| 280 LibraryElement createLibrary(String name, String source) { | 280 LibraryElement createLibrary(String name, String source) { |
| 281 Uri uri = new Uri(scheme: "dart", path: name); | 281 Uri uri = new Uri(scheme: "dart", path: name); |
| 282 var script = new Script(uri, new MockFile(source)); | 282 var script = new Script(uri, new MockFile(source)); |
| 283 var library = new LibraryElementX(script); | 283 var library = new LibraryElementX(script); |
| 284 library.libraryTag = new LibraryName(null, null, null); |
| 284 parseScript(source, library); | 285 parseScript(source, library); |
| 285 library.setExports(library.localScope.values.toList()); | 286 library.setExports(library.localScope.values.toList()); |
| 286 registerSource(uri, source); | 287 registerSource(uri, source); |
| 287 libraries.putIfAbsent(uri.toString(), () => library); | 288 libraries.putIfAbsent(uri.toString(), () => library); |
| 288 return library; | 289 return library; |
| 289 } | 290 } |
| 290 | 291 |
| 291 void reportWarning(Node node, var message) { | 292 void reportWarning(Node node, var message) { |
| 292 if (message is! Message) message = message.message; | 293 if (message is! Message) message = message.message; |
| 293 warnings.add(new WarningMessage(node, message)); | 294 warnings.add(new WarningMessage(node, message)); |
| 294 reportDiagnostic(spanFromNode(node), | 295 reportDiagnostic(spanFromNode(node), |
| 295 'Warning: $message', api.Diagnostic.WARNING); | 296 'Warning: $message', api.Diagnostic.WARNING); |
| 296 } | 297 } |
| 297 | 298 |
| 298 void reportError(Node node, var message) { | 299 void reportError(Spannable node, |
| 299 if (message is String && message.startsWith("no library name found in")) { | 300 MessageKind errorCode, |
| 300 // TODO(ahe): Fix the MockCompiler to not have this problem. | 301 [Map arguments = const {}]) { |
| 301 return; | 302 Message message = errorCode.message(arguments); |
| 302 } | |
| 303 if (message is! Message) message = message.message; | |
| 304 errors.add(new WarningMessage(node, message)); | 303 errors.add(new WarningMessage(node, message)); |
| 305 reportDiagnostic(spanFromNode(node), | 304 reportDiagnostic(spanFromSpannable(node), '$message', api.Diagnostic.ERROR); |
| 306 'Error: $message', api.Diagnostic.ERROR); | 305 } |
| 306 |
| 307 void reportFatalError(Spannable node, |
| 308 MessageKind errorCode, |
| 309 [Map arguments = const {}]) { |
| 310 reportError(node, errorCode, arguments); |
| 307 } | 311 } |
| 308 | 312 |
| 309 void reportMessage(SourceSpan span, var message, api.Diagnostic kind) { | 313 void reportMessage(SourceSpan span, var message, api.Diagnostic kind) { |
| 310 var diagnostic = new WarningMessage(null, message.message); | 314 var diagnostic = new WarningMessage(null, message.message); |
| 311 if (kind == api.Diagnostic.ERROR) { | 315 if (kind == api.Diagnostic.ERROR) { |
| 312 errors.add(diagnostic); | 316 errors.add(diagnostic); |
| 313 } else { | 317 } else { |
| 314 warnings.add(diagnostic); | 318 warnings.add(diagnostic); |
| 315 } | 319 } |
| 316 reportDiagnostic(span, "$message", kind); | 320 reportDiagnostic(span, "$message", kind); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 } | 459 } |
| 456 } | 460 } |
| 457 | 461 |
| 458 class MockDeferredLoadTask extends DeferredLoadTask { | 462 class MockDeferredLoadTask extends DeferredLoadTask { |
| 459 MockDeferredLoadTask(Compiler compiler) : super(compiler); | 463 MockDeferredLoadTask(Compiler compiler) : super(compiler); |
| 460 | 464 |
| 461 void registerMainApp(LibraryElement mainApp) { | 465 void registerMainApp(LibraryElement mainApp) { |
| 462 // Do nothing. | 466 // Do nothing. |
| 463 } | 467 } |
| 464 } | 468 } |
| OLD | NEW |