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