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

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

Issue 11293148: Report errors on duplicate export. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Status updated Created 8 years, 1 month 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
« no previous file with comments | « no previous file | tests/co19/co19-dart2dart.status » ('j') | no next file with comments »
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 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 abstract class LibraryLoader extends CompilerTask { 10 abstract class LibraryLoader extends CompilerTask {
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 return tagState; 166 return tagState;
167 } 167 }
168 return TagState.NEXT[value]; 168 return TagState.NEXT[value];
169 } 169 }
170 170
171 bool importsDartCore = false; 171 bool importsDartCore = false;
172 var libraryDependencies = new LinkBuilder<LibraryDependency>(); 172 var libraryDependencies = new LinkBuilder<LibraryDependency>();
173 Uri base = library.entryCompilationUnit.script.uri; 173 Uri base = library.entryCompilationUnit.script.uri;
174 for (LibraryTag tag in library.tags.reverse()) { 174 for (LibraryTag tag in library.tags.reverse()) {
175 if (tag.isImport) { 175 if (tag.isImport) {
176 tagState = checkTag(TagState.IMPORT_OR_EXPORT, tag); 176 Import import = tag;
177 if (tag.uri.dartString.slowToString() == 'dart:core') { 177 tagState = checkTag(TagState.IMPORT_OR_EXPORT, import);
178 if (import.uri.dartString.slowToString() == 'dart:core') {
178 importsDartCore = true; 179 importsDartCore = true;
179 } 180 }
180 libraryDependencies.addLast(tag); 181 libraryDependencies.addLast(import);
181 } else if (tag.isExport) { 182 } else if (tag.isExport) {
182 tagState = checkTag(TagState.IMPORT_OR_EXPORT, tag); 183 tagState = checkTag(TagState.IMPORT_OR_EXPORT, tag);
183 libraryDependencies.addLast(tag); 184 libraryDependencies.addLast(tag);
184 } else if (tag.isLibraryName) { 185 } else if (tag.isLibraryName) {
185 tagState = checkTag(TagState.LIBRARY, tag); 186 tagState = checkTag(TagState.LIBRARY, tag);
186 if (library.libraryTag != null) { 187 if (library.libraryTag != null) {
187 compiler.cancel("duplicated library declaration", node: tag); 188 compiler.cancel("duplicated library declaration", node: tag);
188 } else { 189 } else {
189 library.libraryTag = tag; 190 library.libraryTag = tag;
190 } 191 }
191 checkDuplicatedLibraryName(library); 192 checkDuplicatedLibraryName(library);
192 } else if (tag.isPart) { 193 } else if (tag.isPart) {
193 StringNode uri = tag.uri; 194 Part part = tag;
195 StringNode uri = part.uri;
194 Uri resolved = base.resolve(uri.dartString.slowToString()); 196 Uri resolved = base.resolve(uri.dartString.slowToString());
195 tagState = checkTag(TagState.SOURCE, tag); 197 tagState = checkTag(TagState.SOURCE, part);
196 scanPart(tag, resolved, library); 198 scanPart(part, resolved, library);
197 } else { 199 } else {
198 compiler.internalError("Unhandled library tag.", node: tag); 200 compiler.internalError("Unhandled library tag.", node: tag);
199 } 201 }
200 } 202 }
201 203
202 // Apply patch, if any. 204 // Apply patch, if any.
203 if (library.uri.scheme == 'dart') { 205 if (library.uri.scheme == 'dart') {
204 patchDartLibrary(handler, library, library.uri.path); 206 patchDartLibrary(handler, library, library.uri.path);
205 } 207 }
206 208
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 } 541 }
540 542
541 /** 543 /**
542 * Adds [element] to the export scope for this node. If the [element] name 544 * Adds [element] to the export scope for this node. If the [element] name
543 * is a duplicate, an error element is inserted into the export scope. 545 * is a duplicate, an error element is inserted into the export scope.
544 */ 546 */
545 Element addElementToExportScope(Compiler compiler, Element element) { 547 Element addElementToExportScope(Compiler compiler, Element element) {
546 SourceString name = element.name; 548 SourceString name = element.name;
547 Element existingElement = exportScope[name]; 549 Element existingElement = exportScope[name];
548 if (existingElement != null) { 550 if (existingElement != null) {
549 if (existingElement.getLibrary() != library) { 551 if (existingElement.isErroneous()) {
552 compiler.reportMessage(compiler.spanFromElement(element),
553 MessageKind.DUPLICATE_EXPORT.error([name]), api.Diagnostic.ERROR);
554 element = existingElement;
555 } else if (existingElement.getLibrary() != library) {
550 // Declared elements hide exported elements. 556 // Declared elements hide exported elements.
557 compiler.reportMessage(compiler.spanFromElement(existingElement),
558 MessageKind.DUPLICATE_EXPORT.error([name]), api.Diagnostic.ERROR);
559 compiler.reportMessage(compiler.spanFromElement(element),
560 MessageKind.DUPLICATE_EXPORT.error([name]), api.Diagnostic.ERROR);
551 element = exportScope[name] = new ErroneousElement( 561 element = exportScope[name] = new ErroneousElement(
552 MessageKind.DUPLICATE_EXPORT, [name], name, library); 562 MessageKind.DUPLICATE_EXPORT, [name], name, library);
553 } 563 }
554 } else { 564 } else {
555 exportScope[name] = element; 565 exportScope[name] = element;
556 } 566 }
557 return element; 567 return element;
558 } 568 }
559 569
560 /** 570 /**
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 } 700 }
691 701
692 /** 702 /**
693 * Registers all top-level entities of [library] as starting point for the 703 * Registers all top-level entities of [library] as starting point for the
694 * fixed-point computation of the import/export scopes. 704 * fixed-point computation of the import/export scopes.
695 */ 705 */
696 void registerLibraryExports(LibraryElement library) { 706 void registerLibraryExports(LibraryElement library) {
697 nodeMap[library].registerInitialExports(); 707 nodeMap[library].registerInitialExports();
698 } 708 }
699 } 709 }
OLDNEW
« no previous file with comments | « no previous file | tests/co19/co19-dart2dart.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698