| 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 import 'dart:uri'; | 9 import 'dart:uri'; |
| 10 | 10 |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 DateTime(year); | 166 DateTime(year); |
| 167 DateTime.utc(year); | 167 DateTime.utc(year); |
| 168 } | 168 } |
| 169 abstract class Pattern {} | 169 abstract class Pattern {} |
| 170 bool identical(Object a, Object b) { return true; }'''; | 170 bool identical(Object a, Object b) { return true; }'''; |
| 171 | 171 |
| 172 const String DEFAULT_ISOLATE_HELPERLIB = r''' | 172 const String DEFAULT_ISOLATE_HELPERLIB = r''' |
| 173 class _WorkerBase {}'''; | 173 class _WorkerBase {}'''; |
| 174 | 174 |
| 175 class MockCompiler extends Compiler { | 175 class MockCompiler extends Compiler { |
| 176 api.DiagnosticHandler diagnosticHandler; |
| 176 List<WarningMessage> warnings; | 177 List<WarningMessage> warnings; |
| 177 List<WarningMessage> errors; | 178 List<WarningMessage> errors; |
| 178 final Map<String, SourceFile> sourceFiles; | 179 final Map<String, SourceFile> sourceFiles; |
| 179 Node parsedTree; | 180 Node parsedTree; |
| 180 | 181 |
| 181 MockCompiler({String coreSource: DEFAULT_CORELIB, | 182 MockCompiler({String coreSource: DEFAULT_CORELIB, |
| 182 String helperSource: DEFAULT_HELPERLIB, | 183 String helperSource: DEFAULT_HELPERLIB, |
| 183 String interceptorsSource: DEFAULT_INTERCEPTORSLIB, | 184 String interceptorsSource: DEFAULT_INTERCEPTORSLIB, |
| 184 String isolateHelperSource: DEFAULT_ISOLATE_HELPERLIB, | 185 String isolateHelperSource: DEFAULT_ISOLATE_HELPERLIB, |
| 185 bool enableTypeAssertions: false, | 186 bool enableTypeAssertions: false, |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 parseScript(source, library); | 250 parseScript(source, library); |
| 250 library.setExports(library.localScope.values.toList()); | 251 library.setExports(library.localScope.values.toList()); |
| 251 registerSource(uri, source); | 252 registerSource(uri, source); |
| 252 libraries.putIfAbsent(uri.toString(), () => library); | 253 libraries.putIfAbsent(uri.toString(), () => library); |
| 253 return library; | 254 return library; |
| 254 } | 255 } |
| 255 | 256 |
| 256 void reportWarning(Node node, var message) { | 257 void reportWarning(Node node, var message) { |
| 257 if (message is! Message) message = message.message; | 258 if (message is! Message) message = message.message; |
| 258 warnings.add(new WarningMessage(node, message)); | 259 warnings.add(new WarningMessage(node, message)); |
| 260 reportDiagnostic(spanFromNode(node), |
| 261 'Warning: $message', api.Diagnostic.WARNING); |
| 259 } | 262 } |
| 260 | 263 |
| 261 void reportError(Node node, var message) { | 264 void reportError(Node node, var message) { |
| 262 if (message is String && message.startsWith("no library name found in")) { | 265 if (message is String && message.startsWith("no library name found in")) { |
| 263 // TODO(ahe): Fix the MockCompiler to not have this problem. | 266 // TODO(ahe): Fix the MockCompiler to not have this problem. |
| 264 return; | 267 return; |
| 265 } | 268 } |
| 266 if (message is! Message) message = message.message; | 269 if (message is! Message) message = message.message; |
| 267 errors.add(new WarningMessage(node, message)); | 270 errors.add(new WarningMessage(node, message)); |
| 271 reportDiagnostic(spanFromNode(node), |
| 272 'Error: $message', api.Diagnostic.ERROR); |
| 268 } | 273 } |
| 269 | 274 |
| 270 void reportMessage(SourceSpan span, var message, api.Diagnostic kind) { | 275 void reportMessage(SourceSpan span, var message, api.Diagnostic kind) { |
| 271 var diagnostic = new WarningMessage(null, message.message); | 276 var diagnostic = new WarningMessage(null, message.message); |
| 272 if (kind == api.Diagnostic.ERROR) { | 277 if (kind == api.Diagnostic.ERROR) { |
| 273 errors.add(diagnostic); | 278 errors.add(diagnostic); |
| 274 } else { | 279 } else { |
| 275 warnings.add(diagnostic); | 280 warnings.add(diagnostic); |
| 276 } | 281 } |
| 282 reportDiagnostic(span, "$message", kind); |
| 277 } | 283 } |
| 278 | 284 |
| 279 void reportDiagnostic(SourceSpan span, String message, var kind) { | 285 void reportDiagnostic(SourceSpan span, String message, api.Diagnostic kind) { |
| 280 print(message); | 286 if (diagnosticHandler != null) { |
| 287 if (span != null) { |
| 288 diagnosticHandler(span.uri, span.begin, span.end, message, kind); |
| 289 } else { |
| 290 diagnosticHandler(null, null, null, message, kind); |
| 291 } |
| 292 } |
| 281 } | 293 } |
| 282 | 294 |
| 283 bool get compilationFailed => !errors.isEmpty; | 295 bool get compilationFailed => !errors.isEmpty; |
| 284 | 296 |
| 285 void clearWarnings() { | 297 void clearWarnings() { |
| 286 warnings = []; | 298 warnings = []; |
| 287 } | 299 } |
| 288 | 300 |
| 289 void clearErrors() { | 301 void clearErrors() { |
| 290 errors = []; | 302 errors = []; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 312 mainApp.entryCompilationUnit); | 324 mainApp.entryCompilationUnit); |
| 313 ResolverVisitor visitor = | 325 ResolverVisitor visitor = |
| 314 new ResolverVisitor(this, mockElement, | 326 new ResolverVisitor(this, mockElement, |
| 315 new CollectingTreeElements(mockElement)); | 327 new CollectingTreeElements(mockElement)); |
| 316 visitor.scope = new MethodScope(visitor.scope, mockElement); | 328 visitor.scope = new MethodScope(visitor.scope, mockElement); |
| 317 return visitor; | 329 return visitor; |
| 318 } | 330 } |
| 319 | 331 |
| 320 parseScript(String text, [LibraryElement library]) { | 332 parseScript(String text, [LibraryElement library]) { |
| 321 if (library == null) library = mainApp; | 333 if (library == null) library = mainApp; |
| 322 parseUnit(text, this, library); | 334 parseUnit(text, this, library, registerSource); |
| 323 } | 335 } |
| 324 | 336 |
| 325 void scanBuiltinLibraries() { | 337 void scanBuiltinLibraries() { |
| 326 // Do nothing. The mock core library is already handled in the constructor. | 338 // Do nothing. The mock core library is already handled in the constructor. |
| 327 } | 339 } |
| 328 | 340 |
| 329 LibraryElement scanBuiltinLibrary(String name) { | 341 LibraryElement scanBuiltinLibrary(String name) { |
| 330 // Do nothing. The mock core library is already handled in the constructor. | 342 // Do nothing. The mock core library is already handled in the constructor. |
| 331 } | 343 } |
| 332 | 344 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 } | 421 } |
| 410 } | 422 } |
| 411 | 423 |
| 412 class MockDeferredLoadTask extends DeferredLoadTask { | 424 class MockDeferredLoadTask extends DeferredLoadTask { |
| 413 MockDeferredLoadTask(Compiler compiler) : super(compiler); | 425 MockDeferredLoadTask(Compiler compiler) : super(compiler); |
| 414 | 426 |
| 415 void registerMainApp(LibraryElement mainApp) { | 427 void registerMainApp(LibraryElement mainApp) { |
| 416 // Do nothing. | 428 // Do nothing. |
| 417 } | 429 } |
| 418 } | 430 } |
| OLD | NEW |