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