Chromium Code Reviews| 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 void scanLibrary(LibraryElement library) { | 9 void scanLibrary(LibraryElement library) { |
| 10 var compilationUnit = library.entryCompilationUnit; | 10 var compilationUnit = library.entryCompilationUnit; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 imports.addLast(tag); | 51 imports.addLast(tag); |
| 52 } else if (tag.isLibrary()) { | 52 } else if (tag.isLibrary()) { |
| 53 tagState = checkTag(TagState.LIBRARY, tag); | 53 tagState = checkTag(TagState.LIBRARY, tag); |
| 54 if (library.libraryTag !== null) { | 54 if (library.libraryTag !== null) { |
| 55 compiler.cancel("duplicated library declaration", node: tag); | 55 compiler.cancel("duplicated library declaration", node: tag); |
| 56 } else { | 56 } else { |
| 57 library.libraryTag = tag; | 57 library.libraryTag = tag; |
| 58 } | 58 } |
| 59 } else if (tag.isSource()) { | 59 } else if (tag.isSource()) { |
| 60 tagState = checkTag(TagState.SOURCE, tag); | 60 tagState = checkTag(TagState.SOURCE, tag); |
| 61 Script script = compiler.readScript(resolved, tag); | 61 compiler.scanner.sourceTagInLibrary(tag, resolved, library); |
| 62 CompilationUnitElement unit = | |
| 63 new CompilationUnitElement(script, library); | |
| 64 compiler.withCurrentElement(unit, () => scan(unit)); | |
| 65 } else if (tag.isResource()) { | 62 } else if (tag.isResource()) { |
| 66 tagState = checkTag(TagState.RESOURCE, tag); | 63 tagState = checkTag(TagState.RESOURCE, tag); |
| 67 compiler.reportWarning(tag, 'ignoring resource tag'); | 64 compiler.reportWarning(tag, 'ignoring resource tag'); |
| 68 } else { | 65 } else { |
| 69 compiler.cancel("illegal script tag: ${tag.tag}", node: tag); | 66 compiler.cancel("illegal script tag: ${tag.tag}", node: tag); |
| 70 } | 67 } |
| 71 } | 68 } |
| 72 | 69 |
| 73 // Apply patch, if any. | 70 // Apply patch, if any. |
| 74 if (library.uri.scheme == 'dart') { | 71 if (library.uri.scheme == 'dart') { |
| 75 compiler.patchDartLibrary(library, library.uri.path); | 72 compiler.patchDartLibrary(library, library.uri.path); |
| 76 } | 73 } |
| 77 | 74 |
| 78 // Now that we have processed all the source tags, it is safe to | 75 // Now that we have processed all the source tags, it is safe to |
| 79 // start loading other libraries. | 76 // start loading other libraries. |
| 80 | 77 |
| 81 if (library.uri.scheme != 'dart' || library.uri.path != 'core') { | 78 if (library.uri.scheme != 'dart' || library.uri.path != 'core') { |
| 82 compiler.importCoreLibrary(library); | 79 compiler.importCoreLibrary(library); |
| 83 } | 80 } |
| 84 | 81 |
| 85 for (ScriptTag tag in imports.toLink()) { | 82 for (ScriptTag tag in imports.toLink()) { |
| 86 importLibraryFromTag(tag, library.entryCompilationUnit); | 83 importLibraryFromTag(tag, library.entryCompilationUnit); |
| 87 } | 84 } |
| 88 } | 85 } |
| 89 | 86 |
| 90 /** | 87 /** |
| 88 * Source a tag in the scope of [library]. The [path] given is used as is, | |
|
Mads Ager (google)
2012/08/22 07:40:03
Handle a source tag in the scope of [library]?
At
Anders Johnsen
2012/08/22 13:02:27
Done.
| |
| 89 * any resolve should be done beforehand. | |
|
Mads Ager (google)
2012/08/22 07:40:03
any resolution
Anders Johnsen
2012/08/22 13:02:27
Done.
| |
| 90 */ | |
| 91 void sourceTagInLibrary(ScriptTag tag, Uri path, LibraryElement library) { | |
|
Mads Ager (google)
2012/08/22 07:40:03
Rename. sourceScript? importSourceFromTag (to matc
Anders Johnsen
2012/08/22 13:02:27
Done.
| |
| 92 Script script = compiler.readScript(path, tag); | |
| 93 CompilationUnitElement unit = new CompilationUnitElement(script, library); | |
| 94 compiler.withCurrentElement(unit, () => compiler.scanner.scan(unit)); | |
| 95 } | |
| 96 | |
| 97 /** | |
| 91 * Handle an import script tag by importing the referenced library into the | 98 * Handle an import script tag by importing the referenced library into the |
| 92 * current library. | 99 * current library. |
| 93 * Returns the resolved library [Uri]. | 100 * Returns the resolved library [Uri]. |
| 94 */ | 101 */ |
| 95 Uri importLibraryFromTag(ScriptTag tag, | 102 Uri importLibraryFromTag(ScriptTag tag, |
| 96 CompilationUnitElement compilationUnit) { | 103 CompilationUnitElement compilationUnit) { |
| 97 Uri base = compilationUnit.script.uri; | 104 Uri base = compilationUnit.script.uri; |
| 98 StringNode argument = tag.argument; | 105 StringNode argument = tag.argument; |
| 99 Uri resolved = base.resolve(argument.dartString.slowToString()); | 106 Uri resolved = base.resolve(argument.dartString.slowToString()); |
| 100 LibraryElement importedLibrary = loadLibrary(resolved, argument, resolved); | 107 LibraryElement importedLibrary = loadLibrary(resolved, argument, resolved); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 221 static final int RESOURCE = 4; | 228 static final int RESOURCE = 4; |
| 222 | 229 |
| 223 /** Next state. */ | 230 /** Next state. */ |
| 224 static final List<int> NEXT = | 231 static final List<int> NEXT = |
| 225 const <int>[NO_TAG_SEEN, | 232 const <int>[NO_TAG_SEEN, |
| 226 IMPORT, // Only one library tag is allowed. | 233 IMPORT, // Only one library tag is allowed. |
| 227 IMPORT, | 234 IMPORT, |
| 228 SOURCE, | 235 SOURCE, |
| 229 RESOURCE]; | 236 RESOURCE]; |
| 230 } | 237 } |
| OLD | NEW |