| 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 compiler.scanner.sourceTagInLibrary(tag, resolved, library); | 61 importSourceFromTag(tag, resolved, library); |
| 62 } else if (tag.isResource()) { | 62 } else if (tag.isResource()) { |
| 63 tagState = checkTag(TagState.RESOURCE, tag); | 63 tagState = checkTag(TagState.RESOURCE, tag); |
| 64 compiler.reportWarning(tag, 'ignoring resource tag'); | 64 compiler.reportWarning(tag, 'ignoring resource tag'); |
| 65 } else { | 65 } else { |
| 66 compiler.cancel("illegal script tag: ${tag.tag}", node: tag); | 66 compiler.cancel("illegal script tag: ${tag.tag}", node: tag); |
| 67 } | 67 } |
| 68 } | 68 } |
| 69 | 69 |
| 70 // Apply patch, if any. | 70 // Apply patch, if any. |
| 71 if (library.uri.scheme == 'dart') { | 71 if (library.uri.scheme == 'dart') { |
| 72 compiler.patchDartLibrary(library, library.uri.path); | 72 compiler.patchDartLibrary(library, library.uri.path); |
| 73 } | 73 } |
| 74 | 74 |
| 75 // 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 |
| 76 // start loading other libraries. | 76 // start loading other libraries. |
| 77 | 77 |
| 78 if (library.uri.scheme != 'dart' || library.uri.path != 'core') { | 78 if (library.uri.scheme != 'dart' || library.uri.path != 'core') { |
| 79 compiler.importCoreLibrary(library); | 79 compiler.importCoreLibrary(library); |
| 80 } | 80 } |
| 81 | 81 |
| 82 for (ScriptTag tag in imports.toLink()) { | 82 for (ScriptTag tag in imports.toLink()) { |
| 83 importLibraryFromTag(tag, library.entryCompilationUnit); | 83 importLibraryFromTag(tag, library.entryCompilationUnit); |
| 84 } | 84 } |
| 85 } | 85 } |
| 86 | 86 |
| 87 /** | 87 /** |
| 88 * Source a tag in the scope of [library]. The [path] given is used as is, | 88 * Handle a source tag in the scope of [library]. The [path] given is used as |
| 89 * any resolve should be done beforehand. | 89 * is, any resolution should be done beforehand. |
| 90 */ | 90 */ |
| 91 void sourceTagInLibrary(ScriptTag tag, Uri path, LibraryElement library) { | 91 void importSourceFromTag(ScriptTag tag, Uri path, LibraryElement library) { |
| 92 Script script = compiler.readScript(path, tag); | 92 Script sourceScript = compiler.readScript(path, tag); |
| 93 CompilationUnitElement unit = new CompilationUnitElement(script, library); | 93 CompilationUnitElement unit = |
| 94 new CompilationUnitElement(sourceScript, library); |
| 94 compiler.withCurrentElement(unit, () => compiler.scanner.scan(unit)); | 95 compiler.withCurrentElement(unit, () => compiler.scanner.scan(unit)); |
| 95 } | 96 } |
| 96 | 97 |
| 97 /** | 98 /** |
| 98 * Handle an import script tag by importing the referenced library into the | 99 * Handle an import script tag by importing the referenced library into the |
| 99 * current library. | 100 * current library. |
| 100 * Returns the resolved library [Uri]. | 101 * Returns the resolved library [Uri]. |
| 101 */ | 102 */ |
| 102 Uri importLibraryFromTag(ScriptTag tag, | 103 Uri importLibraryFromTag(ScriptTag tag, |
| 103 CompilationUnitElement compilationUnit) { | 104 CompilationUnitElement compilationUnit) { |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 static final int RESOURCE = 4; | 229 static final int RESOURCE = 4; |
| 229 | 230 |
| 230 /** Next state. */ | 231 /** Next state. */ |
| 231 static final List<int> NEXT = | 232 static final List<int> NEXT = |
| 232 const <int>[NO_TAG_SEEN, | 233 const <int>[NO_TAG_SEEN, |
| 233 IMPORT, // Only one library tag is allowed. | 234 IMPORT, // Only one library tag is allowed. |
| 234 IMPORT, | 235 IMPORT, |
| 235 SOURCE, | 236 SOURCE, |
| 236 RESOURCE]; | 237 RESOURCE]; |
| 237 } | 238 } |
| OLD | NEW |