Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Side by Side Diff: pkg/compiler/lib/src/apiimpl.dart

Issue 1383483006: Extract DiagnosticReporter implementation from Compiler. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | pkg/compiler/lib/src/closure.dart » ('j') | pkg/compiler/lib/src/compiler.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 leg_apiimpl; 5 library leg_apiimpl;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 9
10 import 'package:package_config/packages.dart'; 10 import 'package:package_config/packages.dart';
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 } 228 }
229 return resolvedUri; 229 return resolvedUri;
230 } 230 }
231 231
232 /** 232 /**
233 * Reads the script designated by [readableUri]. 233 * Reads the script designated by [readableUri].
234 */ 234 */
235 Future<Script> readScript(Spannable node, Uri readableUri) { 235 Future<Script> readScript(Spannable node, Uri readableUri) {
236 if (!readableUri.isAbsolute) { 236 if (!readableUri.isAbsolute) {
237 if (node == null) node = NO_LOCATION_SPANNABLE; 237 if (node == null) node = NO_LOCATION_SPANNABLE;
238 internalError(node, 238 reporter.internalError(node,
239 'Relative uri $readableUri provided to readScript(Uri).'); 239 'Relative uri $readableUri provided to readScript(Uri).');
240 } 240 }
241 241
242 // We need to store the current element since we are reporting read errors 242 // We need to store the current element since we are reporting read errors
243 // asynchronously and therefore need to restore the current element for 243 // asynchronously and therefore need to restore the current element for
244 // [node] to be valid. 244 // [node] to be valid.
245 elements.Element element = currentElement; 245 elements.Element element = currentElement;
246 void reportReadError(exception) { 246 void reportReadError(exception) {
247 if (element == null || node == null) { 247 if (element == null || node == null) {
248 reportErrorMessage( 248 reporter.reportErrorMessage(
249 new SourceSpan(readableUri, 0, 0), 249 new SourceSpan(readableUri, 0, 0),
250 MessageKind.READ_SELF_ERROR, 250 MessageKind.READ_SELF_ERROR,
251 {'uri': readableUri, 'exception': exception}); 251 {'uri': readableUri, 'exception': exception});
252 } else { 252 } else {
253 withCurrentElement(element, () { 253 reporter.withCurrentElement(element, () {
254 reportErrorMessage( 254 reporter.reportErrorMessage(
255 node, 255 node,
256 MessageKind.READ_SCRIPT_ERROR, 256 MessageKind.READ_SCRIPT_ERROR,
257 {'uri': readableUri, 'exception': exception}); 257 {'uri': readableUri, 'exception': exception});
258 }); 258 });
259 } 259 }
260 } 260 }
261 261
262 Uri resourceUri = translateUri(node, readableUri); 262 Uri resourceUri = translateUri(node, readableUri);
263 if (resourceUri == null) return synthesizeScript(node, readableUri); 263 if (resourceUri == null) return synthesizeScript(node, readableUri);
264 if (resourceUri.scheme == 'dart-ext') { 264 if (resourceUri.scheme == 'dart-ext') {
265 if (!allowNativeExtensions) { 265 if (!allowNativeExtensions) {
266 withCurrentElement(element, () { 266 reporter.withCurrentElement(element, () {
267 reportErrorMessage( 267 reporter.reportErrorMessage(
268 node, MessageKind.DART_EXT_NOT_SUPPORTED); 268 node, MessageKind.DART_EXT_NOT_SUPPORTED);
269 }); 269 });
270 } 270 }
271 return synthesizeScript(node, readableUri); 271 return synthesizeScript(node, readableUri);
272 } 272 }
273 273
274 // TODO(johnniwinther): Wrap the result from [provider] in a specialized 274 // TODO(johnniwinther): Wrap the result from [provider] in a specialized
275 // [Future] to ensure that we never execute an asynchronous action without 275 // [Future] to ensure that we never execute an asynchronous action without
276 // setting up the current element of the compiler. 276 // setting up the current element of the compiler.
277 return new Future.sync(() => callUserProvider(resourceUri)).then((data) { 277 return new Future.sync(() => callUserProvider(resourceUri)).then((data) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 if (importingLibrary != null) { 328 if (importingLibrary != null) {
329 if (importingLibrary.isPlatformLibrary || importingLibrary.isPatch) { 329 if (importingLibrary.isPlatformLibrary || importingLibrary.isPatch) {
330 allowInternalLibraryAccess = true; 330 allowInternalLibraryAccess = true;
331 } else if (importingLibrary.canonicalUri.path.contains( 331 } else if (importingLibrary.canonicalUri.path.contains(
332 'sdk/tests/compiler/dart2js_native')) { 332 'sdk/tests/compiler/dart2js_native')) {
333 allowInternalLibraryAccess = true; 333 allowInternalLibraryAccess = true;
334 } 334 }
335 } 335 }
336 if (!allowInternalLibraryAccess) { 336 if (!allowInternalLibraryAccess) {
337 if (importingLibrary != null) { 337 if (importingLibrary != null) {
338 reportErrorMessage( 338 reporter.reportErrorMessage(
339 spannable, 339 spannable,
340 MessageKind.INTERNAL_LIBRARY_FROM, 340 MessageKind.INTERNAL_LIBRARY_FROM,
341 {'resolvedUri': resolvedUri, 341 {'resolvedUri': resolvedUri,
342 'importingUri': importingLibrary.canonicalUri}); 342 'importingUri': importingLibrary.canonicalUri});
343 } else { 343 } else {
344 reportErrorMessage( 344 reporter.reportErrorMessage(
345 spannable, 345 spannable,
346 MessageKind.INTERNAL_LIBRARY, 346 MessageKind.INTERNAL_LIBRARY,
347 {'resolvedUri': resolvedUri}); 347 {'resolvedUri': resolvedUri});
348 } 348 }
349 } 349 }
350 } 350 }
351 if (path == null) { 351 if (path == null) {
352 if (libraryInfo == null) { 352 if (libraryInfo == null) {
353 reportErrorMessage( 353 reporter.reportErrorMessage(
354 spannable, 354 spannable,
355 MessageKind.LIBRARY_NOT_FOUND, 355 MessageKind.LIBRARY_NOT_FOUND,
356 {'resolvedUri': resolvedUri}); 356 {'resolvedUri': resolvedUri});
357 } else { 357 } else {
358 reportErrorMessage( 358 reporter.reportErrorMessage(
359 spannable, 359 spannable,
360 MessageKind.LIBRARY_NOT_SUPPORTED, 360 MessageKind.LIBRARY_NOT_SUPPORTED,
361 {'resolvedUri': resolvedUri}); 361 {'resolvedUri': resolvedUri});
362 } 362 }
363 // TODO(johnniwinther): Support signaling the error through the returned 363 // TODO(johnniwinther): Support signaling the error through the returned
364 // value. 364 // value.
365 return null; 365 return null;
366 } 366 }
367 if (resolvedUri.path == 'html' || 367 if (resolvedUri.path == 'html' ||
368 resolvedUri.path == 'io') { 368 resolvedUri.path == 'io') {
369 // TODO(ahe): Get rid of mockableLibraryUsed when test.dart 369 // TODO(ahe): Get rid of mockableLibraryUsed when test.dart
370 // supports this use case better. 370 // supports this use case better.
371 mockableLibraryUsed = true; 371 mockableLibraryUsed = true;
372 } 372 }
373 return libraryRoot.resolve(path); 373 return libraryRoot.resolve(path);
374 } 374 }
375 375
376 Uri resolvePatchUri(String dartLibraryPath) { 376 Uri resolvePatchUri(String dartLibraryPath) {
377 String patchPath = lookupPatchPath(dartLibraryPath); 377 String patchPath = lookupPatchPath(dartLibraryPath);
378 if (patchPath == null) return null; 378 if (patchPath == null) return null;
379 return libraryRoot.resolve(patchPath); 379 return libraryRoot.resolve(patchPath);
380 } 380 }
381 381
382 Uri translatePackageUri(Spannable node, Uri uri) { 382 Uri translatePackageUri(Spannable node, Uri uri) {
383 try { 383 try {
384 checkValidPackageUri(uri); 384 checkValidPackageUri(uri);
385 } on ArgumentError catch (e) { 385 } on ArgumentError catch (e) {
386 reportErrorMessage( 386 reporter.reportErrorMessage(
387 node, 387 node,
388 MessageKind.INVALID_PACKAGE_URI, 388 MessageKind.INVALID_PACKAGE_URI,
389 {'uri': uri, 'exception': e.message}); 389 {'uri': uri, 'exception': e.message});
390 return null; 390 return null;
391 } 391 }
392 return packages.resolve(uri, 392 return packages.resolve(uri,
393 notFound: (Uri notFound) { 393 notFound: (Uri notFound) {
394 reportErrorMessage( 394 reporter.reportErrorMessage(
395 node, 395 node,
396 MessageKind.LIBRARY_NOT_FOUND, 396 MessageKind.LIBRARY_NOT_FOUND,
397 {'resolvedUri': uri}); 397 {'resolvedUri': uri});
398 return null; 398 return null;
399 }); 399 });
400 } 400 }
401 401
402 Future<elements.LibraryElement> analyzeUri( 402 Future<elements.LibraryElement> analyzeUri(
403 Uri uri, 403 Uri uri,
404 {bool skipLibraryWithPartOfTag: true}) { 404 {bool skipLibraryWithPartOfTag: true}) {
(...skipping 17 matching lines...) Expand all
422 // The input provider may put a trailing 0 byte when it reads a source 422 // The input provider may put a trailing 0 byte when it reads a source
423 // file, which confuses the package config parser. 423 // file, which confuses the package config parser.
424 if (packageConfigContents.length > 0 && 424 if (packageConfigContents.length > 0 &&
425 packageConfigContents.last == 0) { 425 packageConfigContents.last == 0) {
426 packageConfigContents = packageConfigContents.sublist( 426 packageConfigContents = packageConfigContents.sublist(
427 0, packageConfigContents.length - 1); 427 0, packageConfigContents.length - 1);
428 } 428 }
429 packages = 429 packages =
430 new MapPackages(pkgs.parse(packageConfigContents, packageConfig)); 430 new MapPackages(pkgs.parse(packageConfigContents, packageConfig));
431 }).catchError((error) { 431 }).catchError((error) {
432 reportErrorMessage( 432 reporter.reportErrorMessage(
433 NO_LOCATION_SPANNABLE, 433 NO_LOCATION_SPANNABLE,
434 MessageKind.INVALID_PACKAGE_CONFIG, 434 MessageKind.INVALID_PACKAGE_CONFIG,
435 {'uri': packageConfig, 'exception': error}); 435 {'uri': packageConfig, 'exception': error});
436 packages = Packages.noPackages; 436 packages = Packages.noPackages;
437 }); 437 });
438 } else { 438 } else {
439 if (packagesDiscoveryProvider == null) { 439 if (packagesDiscoveryProvider == null) {
440 packages = Packages.noPackages; 440 packages = Packages.noPackages;
441 } else { 441 } else {
442 return callUserPackagesDiscovery(uri).then((p) { 442 return callUserPackagesDiscovery(uri).then((p) {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 Future<Packages> callUserPackagesDiscovery(Uri uri) { 532 Future<Packages> callUserPackagesDiscovery(Uri uri) {
533 try { 533 try {
534 return userPackagesDiscoveryTask.measure( 534 return userPackagesDiscoveryTask.measure(
535 () => packagesDiscoveryProvider(uri)); 535 () => packagesDiscoveryProvider(uri));
536 } catch (ex, s) { 536 } catch (ex, s) {
537 diagnoseCrashInUserCode('Uncaught exception in package discovery', ex, s); 537 diagnoseCrashInUserCode('Uncaught exception in package discovery', ex, s);
538 rethrow; 538 rethrow;
539 } 539 }
540 } 540 }
541 541
542 void diagnoseCrashInUserCode(String message, exception, stackTrace) {
543 hasCrashed = true;
544 print('$message: ${tryToString(exception)}');
545 print(tryToString(stackTrace));
546 }
547 542
548 fromEnvironment(String name) => environment[name]; 543 fromEnvironment(String name) => environment[name];
549 544
550 LibraryInfo lookupLibraryInfo(String libraryName) { 545 LibraryInfo lookupLibraryInfo(String libraryName) {
551 return library_info.LIBRARIES[libraryName]; 546 return library_info.LIBRARIES[libraryName];
552 } 547 }
553 } 548 }
OLDNEW
« no previous file with comments | « no previous file | pkg/compiler/lib/src/closure.dart » ('j') | pkg/compiler/lib/src/compiler.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698