| 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 { |
| 94 tokens = new StringScanner(script.text).tokenize(); | 94 try { |
| 95 } catch (MalformedInputException ex) { | 95 tokens = new StringScanner(script.text).tokenize(); |
| 96 Token token; | 96 } catch (MalformedInputException ex) { |
| 97 var message; | 97 Token token; |
| 98 if (ex.position is num) { | 98 var message; |
| 99 // TODO(ahe): Always use tokens in MalformedInputException. | 99 if (ex.position is num) { |
| 100 token = new Token(EOF_INFO, ex.position); | 100 // TODO(ahe): Always use tokens in MalformedInputException. |
| 101 } else { | 101 token = new Token(EOF_INFO, ex.position); |
| 102 token = ex.position; | 102 } else { |
| 103 token = ex.position; |
| 104 } |
| 105 compiler.cancel(ex.message, token: token); |
| 103 } | 106 } |
| 104 compiler.cancel(ex.message, token: token); | 107 compiler.dietParser.dietParse(compilationUnit, tokens); |
| 108 } catch (CompilerCancelledException ex) { |
| 109 throw; |
| 110 } catch (var ex) { |
| 111 compiler.unhandledExceptionOnElement(compilationUnit); |
| 112 throw; |
| 105 } | 113 } |
| 106 compiler.dietParser.dietParse(compilationUnit, tokens); | |
| 107 } | 114 } |
| 108 | 115 |
| 109 LibraryElement loadLibrary(Uri uri, Node node) { | 116 LibraryElement loadLibrary(Uri uri, Node node) { |
| 110 bool newLibrary = false; | 117 bool newLibrary = false; |
| 111 LibraryElement library = | 118 LibraryElement library = |
| 112 compiler.libraries.putIfAbsent(uri.toString(), () { | 119 compiler.libraries.putIfAbsent(uri.toString(), () { |
| 113 newLibrary = true; | 120 newLibrary = true; |
| 114 Script script = compiler.readScript(uri, node); | 121 Script script = compiler.readScript(uri, node); |
| 115 LibraryElement element = new LibraryElement(script); | 122 LibraryElement element = new LibraryElement(script); |
| 116 native.maybeEnableNative(compiler, element, uri); | 123 native.maybeEnableNative(compiler, element, uri); |
| 117 return element; | 124 return element; |
| 118 }); | 125 }); |
| 119 if (newLibrary) { | 126 if (newLibrary) { |
| 120 compiler.withCurrentElement(library, () { | 127 compiler.withCurrentElement(library, () => scan(library)); |
| 121 scan(library); | 128 compiler.onLibraryLoaded(library, uri); |
| 122 compiler.onLibraryLoaded(library, uri); | |
| 123 }); | |
| 124 } | 129 } |
| 125 return library; | 130 return library; |
| 126 } | 131 } |
| 127 | 132 |
| 128 void importLibrary(LibraryElement library, LibraryElement imported, | 133 void importLibrary(LibraryElement library, LibraryElement imported, |
| 129 ScriptTag tag) { | 134 ScriptTag tag) { |
| 130 if (!imported.hasLibraryName()) { | 135 if (!imported.hasLibraryName()) { |
| 131 compiler.withCurrentElement(library, () { | 136 compiler.withCurrentElement(library, () { |
| 132 compiler.reportError(tag === null ? null : tag.argument, | 137 compiler.reportError(tag === null ? null : tag.argument, |
| 133 'no #library tag found in ${imported.script.uri}'); | 138 'no #library tag found in ${imported.script.uri}'); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 static final int RESOURCE = 4; | 205 static final int RESOURCE = 4; |
| 201 | 206 |
| 202 /** Next state. */ | 207 /** Next state. */ |
| 203 static final List<int> NEXT = | 208 static final List<int> NEXT = |
| 204 const <int>[NO_TAG_SEEN, | 209 const <int>[NO_TAG_SEEN, |
| 205 IMPORT, // Only one library tag is allowed. | 210 IMPORT, // Only one library tag is allowed. |
| 206 IMPORT, | 211 IMPORT, |
| 207 SOURCE, | 212 SOURCE, |
| 208 RESOURCE]; | 213 RESOURCE]; |
| 209 } | 214 } |
| OLD | NEW |