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 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 Loading... |
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 Import import = tag; | 176 tagState = checkTag(TagState.IMPORT_OR_EXPORT, tag); |
177 tagState = checkTag(TagState.IMPORT_OR_EXPORT, import); | 177 if (tag.uri.dartString.slowToString() == 'dart:core') { |
178 if (import.uri.dartString.slowToString() == 'dart:core') { | |
179 importsDartCore = true; | 178 importsDartCore = true; |
180 } | 179 } |
181 libraryDependencies.addLast(import); | 180 libraryDependencies.addLast(tag); |
182 } else if (tag.isExport) { | 181 } else if (tag.isExport) { |
183 tagState = checkTag(TagState.IMPORT_OR_EXPORT, tag); | 182 tagState = checkTag(TagState.IMPORT_OR_EXPORT, tag); |
184 libraryDependencies.addLast(tag); | 183 libraryDependencies.addLast(tag); |
185 } else if (tag.isLibraryName) { | 184 } else if (tag.isLibraryName) { |
186 tagState = checkTag(TagState.LIBRARY, tag); | 185 tagState = checkTag(TagState.LIBRARY, tag); |
187 if (library.libraryTag != null) { | 186 if (library.libraryTag != null) { |
188 compiler.cancel("duplicated library declaration", node: tag); | 187 compiler.cancel("duplicated library declaration", node: tag); |
189 } else { | 188 } else { |
190 library.libraryTag = tag; | 189 library.libraryTag = tag; |
191 } | 190 } |
192 checkDuplicatedLibraryName(library); | 191 checkDuplicatedLibraryName(library); |
193 } else if (tag.isPart) { | 192 } else if (tag.isPart) { |
194 Part part = tag; | 193 StringNode uri = tag.uri; |
195 StringNode uri = part.uri; | |
196 Uri resolved = base.resolve(uri.dartString.slowToString()); | 194 Uri resolved = base.resolve(uri.dartString.slowToString()); |
197 tagState = checkTag(TagState.SOURCE, part); | 195 tagState = checkTag(TagState.SOURCE, tag); |
198 scanPart(part, resolved, library); | 196 scanPart(tag, resolved, library); |
199 } else { | 197 } else { |
200 compiler.internalError("Unhandled library tag.", node: tag); | 198 compiler.internalError("Unhandled library tag.", node: tag); |
201 } | 199 } |
202 } | 200 } |
203 | 201 |
204 // Apply patch, if any. | 202 // Apply patch, if any. |
205 if (library.uri.scheme == 'dart') { | 203 if (library.uri.scheme == 'dart') { |
206 patchDartLibrary(handler, library, library.uri.path); | 204 patchDartLibrary(handler, library, library.uri.path); |
207 } | 205 } |
208 | 206 |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 } | 539 } |
542 | 540 |
543 /** | 541 /** |
544 * Adds [element] to the export scope for this node. If the [element] name | 542 * Adds [element] to the export scope for this node. If the [element] name |
545 * is a duplicate, an error element is inserted into the export scope. | 543 * is a duplicate, an error element is inserted into the export scope. |
546 */ | 544 */ |
547 Element addElementToExportScope(Compiler compiler, Element element) { | 545 Element addElementToExportScope(Compiler compiler, Element element) { |
548 SourceString name = element.name; | 546 SourceString name = element.name; |
549 Element existingElement = exportScope[name]; | 547 Element existingElement = exportScope[name]; |
550 if (existingElement != null) { | 548 if (existingElement != null) { |
551 if (existingElement.isErroneous()) { | 549 if (existingElement.getLibrary() != library) { |
552 compiler.reportMessage(compiler.spanFromElement(element), | |
553 MessageKind.DUPLICATE_EXPORT.error([name]), api.Diagnostic.ERROR); | |
554 element = existingElement; | |
555 } else if (existingElement.getLibrary() != library) { | |
556 // Declared elements hide exported elements. | 550 // 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); | |
561 element = exportScope[name] = new ErroneousElement( | 551 element = exportScope[name] = new ErroneousElement( |
562 MessageKind.DUPLICATE_EXPORT, [name], name, library); | 552 MessageKind.DUPLICATE_EXPORT, [name], name, library); |
563 } | 553 } |
564 } else { | 554 } else { |
565 exportScope[name] = element; | 555 exportScope[name] = element; |
566 } | 556 } |
567 return element; | 557 return element; |
568 } | 558 } |
569 | 559 |
570 /** | 560 /** |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
700 } | 690 } |
701 | 691 |
702 /** | 692 /** |
703 * Registers all top-level entities of [library] as starting point for the | 693 * Registers all top-level entities of [library] as starting point for the |
704 * fixed-point computation of the import/export scopes. | 694 * fixed-point computation of the import/export scopes. |
705 */ | 695 */ |
706 void registerLibraryExports(LibraryElement library) { | 696 void registerLibraryExports(LibraryElement library) { |
707 nodeMap[library].registerInitialExports(); | 697 nodeMap[library].registerInitialExports(); |
708 } | 698 } |
709 } | 699 } |
OLD | NEW |