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

Side by Side Diff: dart/sdk/lib/_internal/compiler/implementation/library_loader.dart

Issue 20742002: Clean up error handling. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Added documentation guide lines. Created 7 years, 4 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 | Annotate | Revision Log
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 part of dart2js; 5 part of dart2js;
6 6
7 /** 7 /**
8 * [CompilerTask] for loading libraries and setting up the import/export scopes. 8 * [CompilerTask] for loading libraries and setting up the import/export scopes.
9 * 9 *
10 * The library loader uses four different kinds of URIs in different parts of 10 * The library loader uses four different kinds of URIs in different parts of
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 LibraryElement library) { 248 LibraryElement library) {
249 int tagState = TagState.NO_TAG_SEEN; 249 int tagState = TagState.NO_TAG_SEEN;
250 250
251 /** 251 /**
252 * If [value] is less than [tagState] complain and return 252 * If [value] is less than [tagState] complain and return
253 * [tagState]. Otherwise return the new value for [tagState] 253 * [tagState]. Otherwise return the new value for [tagState]
254 * (transition function for state machine). 254 * (transition function for state machine).
255 */ 255 */
256 int checkTag(int value, LibraryTag tag) { 256 int checkTag(int value, LibraryTag tag) {
257 if (tagState > value) { 257 if (tagState > value) {
258 compiler.reportError(tag, 'out of order'); 258 compiler.reportFatalError(
259 tag,
260 MessageKind.GENERIC, {'text': 'Error: Out of order.'});
259 return tagState; 261 return tagState;
260 } 262 }
261 return TagState.NEXT[value]; 263 return TagState.NEXT[value];
262 } 264 }
263 265
264 bool importsDartCore = false; 266 bool importsDartCore = false;
265 var libraryDependencies = new LinkBuilder<LibraryDependency>(); 267 var libraryDependencies = new LinkBuilder<LibraryDependency>();
266 Uri base = library.entryCompilationUnit.script.uri; 268 Uri base = library.entryCompilationUnit.script.uri;
267 for (LibraryTag tag in library.tags.reverse()) { 269 for (LibraryTag tag in library.tags.reverse()) {
268 if (tag.isImport) { 270 if (tag.isImport) {
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 LibraryElement library, 392 LibraryElement library,
391 LibraryDependency tag) { 393 LibraryDependency tag) {
392 Uri base = library.entryCompilationUnit.script.uri; 394 Uri base = library.entryCompilationUnit.script.uri;
393 Uri resolvedUri = base.resolve(tag.uri.dartString.slowToString()); 395 Uri resolvedUri = base.resolve(tag.uri.dartString.slowToString());
394 LibraryElement loadedLibrary = 396 LibraryElement loadedLibrary =
395 createLibrary(handler, library, resolvedUri, tag.uri, resolvedUri); 397 createLibrary(handler, library, resolvedUri, tag.uri, resolvedUri);
396 handler.registerDependency(library, tag, loadedLibrary); 398 handler.registerDependency(library, tag, loadedLibrary);
397 399
398 if (!loadedLibrary.hasLibraryName()) { 400 if (!loadedLibrary.hasLibraryName()) {
399 compiler.withCurrentElement(library, () { 401 compiler.withCurrentElement(library, () {
400 compiler.reportError(tag == null ? null : tag.uri, 402 compiler.reportFatalError(
401 'no library name found in ${loadedLibrary.canonicalUri}'); 403 tag == null ? null : tag.uri,
404 MessageKind.GENERIC,
405 {'text':
406 'Error: No library name found in ${loadedLibrary.canonicalUri}.'});
402 }); 407 });
403 } 408 }
404 } 409 }
405 410
406 /** 411 /**
407 * Create (or reuse) a library element for the library specified by the 412 * Create (or reuse) a library element for the library specified by the
408 * [resolvedUri]. 413 * [resolvedUri].
409 * 414 *
410 * If a new library is created, the [handler] is notified. 415 * If a new library is created, the [handler] is notified.
411 */ 416 */
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 if (e == null) { 503 if (e == null) {
499 e = new PrefixElementX(prefix, importingLibrary.entryCompilationUnit, 504 e = new PrefixElementX(prefix, importingLibrary.entryCompilationUnit,
500 import.getBeginToken()); 505 import.getBeginToken());
501 importingLibrary.addToScope(e, compiler); 506 importingLibrary.addToScope(e, compiler);
502 } 507 }
503 if (!identical(e.kind, ElementKind.PREFIX)) { 508 if (!identical(e.kind, ElementKind.PREFIX)) {
504 compiler.withCurrentElement(e, () { 509 compiler.withCurrentElement(e, () {
505 compiler.reportWarning(new Identifier(e.position()), 510 compiler.reportWarning(new Identifier(e.position()),
506 'duplicated definition'); 511 'duplicated definition');
507 }); 512 });
508 compiler.reportError(import.prefix, 'duplicate definition'); 513 compiler.reportFatalError(
514 import.prefix,
515 MessageKind.GENERIC, {'text': 'Error: Duplicate definition.'});
509 } 516 }
510 PrefixElement prefixElement = e; 517 PrefixElement prefixElement = e;
511 importedLibrary.forEachExport((Element element) { 518 importedLibrary.forEachExport((Element element) {
512 if (combinatorFilter.exclude(element)) return; 519 if (combinatorFilter.exclude(element)) return;
513 // TODO(johnniwinther): Clean-up like [checkDuplicateLibraryName]. 520 // TODO(johnniwinther): Clean-up like [checkDuplicateLibraryName].
514 Element existing = 521 Element existing =
515 prefixElement.imported.putIfAbsent(element.name, () => element); 522 prefixElement.imported.putIfAbsent(element.name, () => element);
516 if (!identical(existing, element)) { 523 if (!identical(existing, element)) {
517 compiler.withCurrentElement(existing, () { 524 compiler.withCurrentElement(existing, () {
518 compiler.reportWarning(new Identifier(existing.position()), 525 compiler.reportWarning(new Identifier(existing.position()),
519 'duplicated import'); 526 'duplicated import');
520 }); 527 });
521 compiler.withCurrentElement(element, () { 528 compiler.withCurrentElement(element, () {
522 compiler.reportError(new Identifier(element.position()), 529 compiler.reportFatalError(
523 'duplicated import'); 530 element,
531 MessageKind.GENERIC, {'text': 'Error: Duplicated import.'});
524 }); 532 });
525 } 533 }
526 }); 534 });
527 } else { 535 } else {
528 importedLibrary.forEachExport((Element element) { 536 importedLibrary.forEachExport((Element element) {
529 compiler.withCurrentElement(element, () { 537 compiler.withCurrentElement(element, () {
530 if (combinatorFilter.exclude(element)) return; 538 if (combinatorFilter.exclude(element)) return;
531 importingLibrary.addImport(element, import, compiler); 539 importingLibrary.addImport(element, import, compiler);
532 }); 540 });
533 }); 541 });
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 676
669 /** 677 /**
670 * Adds [element] to the export scope for this node. If the [element] name 678 * Adds [element] to the export scope for this node. If the [element] name
671 * is a duplicate, an error element is inserted into the export scope. 679 * is a duplicate, an error element is inserted into the export scope.
672 */ 680 */
673 Element addElementToExportScope(Compiler compiler, Element element) { 681 Element addElementToExportScope(Compiler compiler, Element element) {
674 SourceString name = element.name; 682 SourceString name = element.name;
675 Element existingElement = exportScope[name]; 683 Element existingElement = exportScope[name];
676 if (existingElement != null) { 684 if (existingElement != null) {
677 if (existingElement.isErroneous()) { 685 if (existingElement.isErroneous()) {
678 compiler.reportErrorCode(element, MessageKind.DUPLICATE_EXPORT, 686 compiler.reportError(element, MessageKind.DUPLICATE_EXPORT,
679 {'name': name}); 687 {'name': name});
680 element = existingElement; 688 element = existingElement;
681 } else if (existingElement.getLibrary() != library) { 689 } else if (existingElement.getLibrary() != library) {
682 // Declared elements hide exported elements. 690 // Declared elements hide exported elements.
683 compiler.reportErrorCode(existingElement, MessageKind.DUPLICATE_EXPORT, 691 compiler.reportError(existingElement, MessageKind.DUPLICATE_EXPORT,
684 {'name': name}); 692 {'name': name});
685 compiler.reportErrorCode(element, MessageKind.DUPLICATE_EXPORT, 693 compiler.reportError(element, MessageKind.DUPLICATE_EXPORT,
686 {'name': name}); 694 {'name': name});
687 element = exportScope[name] = new ErroneousElementX( 695 element = exportScope[name] = new ErroneousElementX(
688 MessageKind.DUPLICATE_EXPORT, {'name': name}, name, library); 696 MessageKind.DUPLICATE_EXPORT, {'name': name}, name, library);
689 } 697 }
690 } else { 698 } else {
691 exportScope[name] = element; 699 exportScope[name] = element;
692 } 700 }
693 return element; 701 return element;
694 } 702 }
695 703
696 /** 704 /**
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 } 839 }
832 840
833 /** 841 /**
834 * Registers all top-level entities of [library] as starting point for the 842 * Registers all top-level entities of [library] as starting point for the
835 * fixed-point computation of the import/export scopes. 843 * fixed-point computation of the import/export scopes.
836 */ 844 */
837 void registerLibraryExports(LibraryElement library) { 845 void registerLibraryExports(LibraryElement library) {
838 nodeMap[library].registerInitialExports(); 846 nodeMap[library].registerInitialExports();
839 } 847 }
840 } 848 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698