| 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 scan(CompilationUnitElement compilationUnit) { | 9 void scan(CompilationUnitElement compilationUnit) { |
| 10 measure(() { | 10 measure(() { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 imports.addLast(tag); | 50 imports.addLast(tag); |
| 51 } else if (tag.isLibrary()) { | 51 } else if (tag.isLibrary()) { |
| 52 tagState = checkTag(TagState.LIBRARY, tag); | 52 tagState = checkTag(TagState.LIBRARY, tag); |
| 53 if (library.libraryTag !== null) { | 53 if (library.libraryTag !== null) { |
| 54 compiler.cancel("duplicated library declaration", node: tag); | 54 compiler.cancel("duplicated library declaration", node: tag); |
| 55 } else { | 55 } else { |
| 56 library.libraryTag = tag; | 56 library.libraryTag = tag; |
| 57 } | 57 } |
| 58 } else if (tag.isSource()) { | 58 } else if (tag.isSource()) { |
| 59 tagState = checkTag(TagState.SOURCE, tag); | 59 tagState = checkTag(TagState.SOURCE, tag); |
| 60 Script script = compiler.readScript(resolved, tag); | 60 Script script = compiler.readScript(resolved, argument); |
| 61 CompilationUnitElement unit = | 61 CompilationUnitElement unit = |
| 62 new CompilationUnitElement(script, library); | 62 new CompilationUnitElement(script, library); |
| 63 compiler.withCurrentElement(unit, () => scan(unit)); | 63 compiler.withCurrentElement(unit, () => scan(unit)); |
| 64 } else if (tag.isResource()) { | 64 } else if (tag.isResource()) { |
| 65 tagState = checkTag(TagState.RESOURCE, tag); | 65 tagState = checkTag(TagState.RESOURCE, tag); |
| 66 compiler.reportWarning(tag, 'ignoring resource tag'); | 66 compiler.reportWarning(tag, 'ignoring resource tag'); |
| 67 } else { | 67 } else { |
| 68 compiler.cancel("illegal script tag: ${tag.tag}", node: tag); | 68 compiler.cancel("illegal script tag: ${tag.tag}", node: tag); |
| 69 } | 69 } |
| 70 } | 70 } |
| 71 // TODO(ahe): During Compiler.scanBuiltinLibraries, | 71 // TODO(ahe): During Compiler.scanBuiltinLibraries, |
| 72 // compiler.coreLibrary is null. Clean this up when there is a | 72 // compiler.coreLibrary is null. Clean this up when there is a |
| 73 // better way to access "dart:core". | 73 // better way to access "dart:core". |
| 74 bool implicitlyImportCoreLibrary = compiler.coreLibrary !== null; | 74 bool implicitlyImportCoreLibrary = compiler.coreLibrary !== null; |
| 75 for (ScriptTag tag in imports.toLink()) { | 75 for (ScriptTag tag in imports.toLink()) { |
| 76 // Now that we have processed all the source tags, it is safe to | 76 // Now that we have processed all the source tags, it is safe to |
| 77 // start loading other libraries. | 77 // start loading other libraries. |
| 78 StringNode argument = tag.argument; | 78 StringNode argument = tag.argument; |
| 79 Uri resolved = base.resolve(argument.dartString.slowToString()); | 79 Uri resolved = base.resolve(argument.dartString.slowToString()); |
| 80 if (resolved.toString() == "dart:core") { | 80 if (resolved.toString() == "dart:core") { |
| 81 implicitlyImportCoreLibrary = false; | 81 implicitlyImportCoreLibrary = false; |
| 82 } | 82 } |
| 83 importLibrary(library, loadLibrary(resolved, tag), tag); | 83 importLibrary(library, loadLibrary(resolved, argument), tag); |
| 84 } | 84 } |
| 85 if (implicitlyImportCoreLibrary) { | 85 if (implicitlyImportCoreLibrary) { |
| 86 importLibrary(library, compiler.coreLibrary, null); | 86 importLibrary(library, compiler.coreLibrary, null); |
| 87 } | 87 } |
| 88 } | 88 } |
| 89 | 89 |
| 90 void scanElements(CompilationUnitElement compilationUnit) { | 90 void scanElements(CompilationUnitElement compilationUnit) { |
| 91 Script script = compilationUnit.script; | 91 Script script = compilationUnit.script; |
| 92 Token tokens; | 92 Token tokens; |
| 93 try { | 93 try { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 106 } | 106 } |
| 107 compiler.dietParser.dietParse(compilationUnit, tokens); | 107 compiler.dietParser.dietParse(compilationUnit, tokens); |
| 108 } catch (CompilerCancelledException ex) { | 108 } catch (CompilerCancelledException ex) { |
| 109 throw; | 109 throw; |
| 110 } catch (var ex) { | 110 } catch (var ex) { |
| 111 compiler.unhandledExceptionOnElement(compilationUnit); | 111 compiler.unhandledExceptionOnElement(compilationUnit); |
| 112 throw; | 112 throw; |
| 113 } | 113 } |
| 114 } | 114 } |
| 115 | 115 |
| 116 LibraryElement loadLibrary(Uri uri, ScriptTag node) { | 116 LibraryElement loadLibrary(Uri uri, Node node) { |
| 117 bool newLibrary = false; | 117 bool newLibrary = false; |
| 118 LibraryElement library = | 118 LibraryElement library = |
| 119 compiler.universe.libraries.putIfAbsent(uri.toString(), () { | 119 compiler.universe.libraries.putIfAbsent(uri.toString(), () { |
| 120 newLibrary = true; | 120 newLibrary = true; |
| 121 Script script = compiler.readScript(uri, node); | 121 Script script = compiler.readScript(uri, node); |
| 122 LibraryElement element = new LibraryElement(script); | 122 LibraryElement element = new LibraryElement(script); |
| 123 native.maybeEnableNative(compiler, element, uri); | 123 native.maybeEnableNative(compiler, element, uri); |
| 124 return element; | 124 return element; |
| 125 }); | 125 }); |
| 126 if (newLibrary) { | 126 if (newLibrary) { |
| 127 compiler.withCurrentElement(library, () => scan(library)); | 127 compiler.withCurrentElement(library, () => scan(library)); |
| 128 compiler.onLibraryLoaded(library, uri); | 128 compiler.onLibraryLoaded(library, uri); |
| 129 } | 129 } |
| 130 return library; | 130 return library; |
| 131 } | 131 } |
| 132 | 132 |
| 133 void importLibrary(LibraryElement library, LibraryElement imported, | 133 void importLibrary(LibraryElement library, LibraryElement imported, |
| 134 ScriptTag tag) { | 134 ScriptTag tag) { |
| 135 if (!imported.hasLibraryName()) { | 135 if (!imported.hasLibraryName()) { |
| 136 compiler.withCurrentElement(library, () { | 136 compiler.withCurrentElement(library, () { |
| 137 compiler.reportError(tag, | 137 compiler.reportError(tag === null ? null : tag.argument, |
| 138 'no #library tag found in ${imported.script.uri}'); | 138 'no #library tag found in ${imported.script.uri}'); |
| 139 }); | 139 }); |
| 140 } | 140 } |
| 141 if (tag !== null && tag.prefix !== null) { | 141 if (tag !== null && tag.prefix !== null) { |
| 142 SourceString prefix = | 142 SourceString prefix = |
| 143 new SourceString(tag.prefix.dartString.slowToString()); | 143 new SourceString(tag.prefix.dartString.slowToString()); |
| 144 Element e = library.find(prefix); | 144 Element e = library.find(prefix); |
| 145 if (e === null) { | 145 if (e === null) { |
| 146 e = new PrefixElement(prefix, library, tag.getBeginToken()); | 146 e = new PrefixElement(prefix, library, tag.getBeginToken()); |
| 147 library.define(e, compiler); | 147 library.define(e, compiler); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 static final int RESOURCE = 4; | 205 static final int RESOURCE = 4; |
| 206 | 206 |
| 207 /** Next state. */ | 207 /** Next state. */ |
| 208 static final List<int> NEXT = | 208 static final List<int> NEXT = |
| 209 const <int>[NO_TAG_SEEN, | 209 const <int>[NO_TAG_SEEN, |
| 210 IMPORT, // Only one library tag is allowed. | 210 IMPORT, // Only one library tag is allowed. |
| 211 IMPORT, | 211 IMPORT, |
| 212 SOURCE, | 212 SOURCE, |
| 213 RESOURCE]; | 213 RESOURCE]; |
| 214 } | 214 } |
| OLD | NEW |