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 class ScannerTask extends CompilerTask { | 5 class ScannerTask extends CompilerTask { |
6 ScannerTask(Compiler compiler) : super(compiler); | 6 ScannerTask(Compiler compiler) : super(compiler); |
7 String get name => 'Scanner'; | 7 String get name => 'Scanner'; |
8 | 8 |
| 9 final Map<String, LibraryElement> libraryNames = |
| 10 new Map<String, LibraryElement>(); |
| 11 |
9 void scanLibrary(LibraryElement library) { | 12 void scanLibrary(LibraryElement library) { |
10 var compilationUnit = library.entryCompilationUnit; | 13 var compilationUnit = library.entryCompilationUnit; |
11 compiler.log("scanning library ${compilationUnit.script.name}"); | 14 compiler.log("scanning library ${compilationUnit.script.name}"); |
12 scan(compilationUnit); | 15 scan(compilationUnit); |
13 processLibraryTags(library); | 16 processLibraryTags(library); |
14 } | 17 } |
15 | 18 |
16 void scan(CompilationUnitElement compilationUnit) { | 19 void scan(CompilationUnitElement compilationUnit) { |
17 measure(() { | 20 measure(() { |
18 scanElements(compilationUnit); | 21 scanElements(compilationUnit); |
(...skipping 29 matching lines...) Expand all Loading... |
48 // before it fully declares all the members that are sourced | 51 // before it fully declares all the members that are sourced |
49 // in. | 52 // in. |
50 imports.addLast(tag); | 53 imports.addLast(tag); |
51 } else if (tag.isLibraryName) { | 54 } else if (tag.isLibraryName) { |
52 tagState = checkTag(TagState.LIBRARY, tag); | 55 tagState = checkTag(TagState.LIBRARY, tag); |
53 if (library.libraryTag !== null) { | 56 if (library.libraryTag !== null) { |
54 compiler.cancel("duplicated library declaration", node: tag); | 57 compiler.cancel("duplicated library declaration", node: tag); |
55 } else { | 58 } else { |
56 library.libraryTag = tag; | 59 library.libraryTag = tag; |
57 } | 60 } |
| 61 checkDuplicatedLibraryName(library); |
58 } else if (tag.isPart) { | 62 } else if (tag.isPart) { |
59 StringNode uri = tag.uri; | 63 StringNode uri = tag.uri; |
60 Uri resolved = base.resolve(uri.dartString.slowToString()); | 64 Uri resolved = base.resolve(uri.dartString.slowToString()); |
61 tagState = checkTag(TagState.SOURCE, tag); | 65 tagState = checkTag(TagState.SOURCE, tag); |
62 loadPart(tag, resolved, library); | 66 loadPart(tag, resolved, library); |
63 } else { | 67 } else { |
64 compiler.internalError("Unhandled library tag.", node: tag); | 68 compiler.internalError("Unhandled library tag.", node: tag); |
65 } | 69 } |
66 } | 70 } |
67 | 71 |
68 // Apply patch, if any. | 72 // Apply patch, if any. |
69 if (library.uri.scheme == 'dart') { | 73 if (library.uri.scheme == 'dart') { |
70 compiler.patchDartLibrary(library, library.uri.path); | 74 compiler.patchDartLibrary(library, library.uri.path); |
71 } | 75 } |
72 | 76 |
73 // Now that we have processed all the source tags, it is safe to | 77 // Now that we have processed all the source tags, it is safe to |
74 // start loading other libraries. | 78 // start loading other libraries. |
75 | 79 |
76 if (library.uri.scheme != 'dart' || library.uri.path != 'core') { | 80 if (library.uri.scheme != 'dart' || library.uri.path != 'core') { |
77 compiler.importCoreLibrary(library); | 81 compiler.importCoreLibrary(library); |
78 } | 82 } |
79 | 83 |
80 for (Import tag in imports.toLink()) { | 84 for (Import tag in imports.toLink()) { |
81 importLibraryFromTag(tag, library.entryCompilationUnit); | 85 importLibraryFromTag(tag, library.entryCompilationUnit); |
82 } | 86 } |
83 } | 87 } |
84 | 88 |
| 89 void checkDuplicatedLibraryName(LibraryElement library) { |
| 90 LibraryTag tag = library.libraryTag; |
| 91 if (tag != null) { |
| 92 String name = library.getLibraryOrScriptName(); |
| 93 LibraryElement existing = |
| 94 libraryNames.putIfAbsent(name, () => library); |
| 95 if (existing !== library) { |
| 96 Uri uri = library.entryCompilationUnit.script.uri; |
| 97 compiler.reportMessage( |
| 98 compiler.spanFromNode(tag.name, uri), |
| 99 MessageKind.DUPLICATED_LIBRARY_NAME.error([name]), |
| 100 api_s.Diagnostic.WARNING); |
| 101 Uri existingUri = existing.entryCompilationUnit.script.uri; |
| 102 compiler.reportMessage( |
| 103 compiler.spanFromNode(existing.libraryTag.name, existingUri), |
| 104 MessageKind.DUPLICATED_LIBRARY_NAME.error([name]), |
| 105 api_s.Diagnostic.WARNING); |
| 106 } |
| 107 } |
| 108 } |
| 109 |
85 /** | 110 /** |
86 * Handle a part tag in the scope of [library]. The [path] given is used as | 111 * Handle a part tag in the scope of [library]. The [path] given is used as |
87 * is, any resolution should be done beforehand. | 112 * is, any resolution should be done beforehand. |
88 */ | 113 */ |
89 void loadPart(Part part, Uri path, LibraryElement library) { | 114 void loadPart(Part part, Uri path, LibraryElement library) { |
90 Script sourceScript = compiler.readScript(path, part.uri); | 115 Script sourceScript = compiler.readScript(path, part.uri); |
91 CompilationUnitElement unit = | 116 CompilationUnitElement unit = |
92 new CompilationUnitElement(sourceScript, library); | 117 new CompilationUnitElement(sourceScript, library); |
93 compiler.withCurrentElement(unit, () => compiler.scanner.scan(unit)); | 118 compiler.withCurrentElement(unit, () => compiler.scanner.scan(unit)); |
94 } | 119 } |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 static const int RESOURCE = 4; | 243 static const int RESOURCE = 4; |
219 | 244 |
220 /** Next state. */ | 245 /** Next state. */ |
221 static const List<int> NEXT = | 246 static const List<int> NEXT = |
222 const <int>[NO_TAG_SEEN, | 247 const <int>[NO_TAG_SEEN, |
223 IMPORT, // Only one library tag is allowed. | 248 IMPORT, // Only one library tag is allowed. |
224 IMPORT, | 249 IMPORT, |
225 SOURCE, | 250 SOURCE, |
226 RESOURCE]; | 251 RESOURCE]; |
227 } | 252 } |
OLD | NEW |