| 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 /** | 5 /** |
| 6 * This library contains the infrastructure to parse and integrate patch files. | 6 * This library contains the infrastructure to parse and integrate patch files. |
| 7 * | 7 * |
| 8 * Three types of elements can be patched: [LibraryElement], [ClassElement], | 8 * Three types of elements can be patched: [LibraryElement], [ClassElement], |
| 9 * [FunctionElement]. Patches are introduced in patch libraries which are loaded | 9 * [FunctionElement]. Patches are introduced in patch libraries which are loaded |
| 10 * together with the corresponding origin library. Which libraries that are | 10 * together with the corresponding origin library. Which libraries that are |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 Parser; | 152 Parser; |
| 153 import 'scanner/scanner.dart' show | 153 import 'scanner/scanner.dart' show |
| 154 Scanner; | 154 Scanner; |
| 155 import 'script.dart'; | 155 import 'script.dart'; |
| 156 import 'tokens/token.dart' show | 156 import 'tokens/token.dart' show |
| 157 StringToken, | 157 StringToken, |
| 158 Token; | 158 Token; |
| 159 | 159 |
| 160 class PatchParserTask extends CompilerTask { | 160 class PatchParserTask extends CompilerTask { |
| 161 final String name = "Patching Parser"; | 161 final String name = "Patching Parser"; |
| 162 final bool _enableConditionalDirectives; |
| 162 | 163 |
| 163 PatchParserTask(Compiler compiler): super(compiler); | 164 PatchParserTask(Compiler compiler, {bool enableConditionalDirectives}) |
| 165 : this._enableConditionalDirectives = enableConditionalDirectives, |
| 166 super(compiler); |
| 164 | 167 |
| 165 /** | 168 /** |
| 166 * Scans a library patch file, applies the method patches and | 169 * Scans a library patch file, applies the method patches and |
| 167 * injections to the library, and returns a list of class | 170 * injections to the library, and returns a list of class |
| 168 * patches. | 171 * patches. |
| 169 */ | 172 */ |
| 170 Future patchLibrary(LibraryLoader loader, | 173 Future patchLibrary(LibraryLoader loader, |
| 171 Uri patchUri, LibraryElement originLibrary) { | 174 Uri patchUri, LibraryElement originLibrary) { |
| 172 return compiler.readScript(originLibrary, patchUri) | 175 return compiler.readScript(originLibrary, patchUri) |
| 173 .then((Script script) { | 176 .then((Script script) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 188 void scanLibraryElements(CompilationUnitElement compilationUnit) { | 191 void scanLibraryElements(CompilationUnitElement compilationUnit) { |
| 189 measure(() { | 192 measure(() { |
| 190 // TODO(johnniwinther): Test that parts and exports are handled correctly. | 193 // TODO(johnniwinther): Test that parts and exports are handled correctly. |
| 191 Script script = compilationUnit.script; | 194 Script script = compilationUnit.script; |
| 192 Token tokens = new Scanner(script.file).tokenize(); | 195 Token tokens = new Scanner(script.file).tokenize(); |
| 193 Function idGenerator = compiler.getNextFreeClassId; | 196 Function idGenerator = compiler.getNextFreeClassId; |
| 194 Listener patchListener = new PatchElementListener(compiler, | 197 Listener patchListener = new PatchElementListener(compiler, |
| 195 compilationUnit, | 198 compilationUnit, |
| 196 idGenerator); | 199 idGenerator); |
| 197 try { | 200 try { |
| 198 new PartialParser(patchListener).parseUnit(tokens); | 201 new PartialParser(patchListener, |
| 202 enableConditionalDirectives: _enableConditionalDirectives) |
| 203 .parseUnit(tokens); |
| 199 } on ParserError catch (e) { | 204 } on ParserError catch (e) { |
| 200 // No need to recover from a parser error in platform libraries, user | 205 // No need to recover from a parser error in platform libraries, user |
| 201 // will never see this if the libraries are tested correctly. | 206 // will never see this if the libraries are tested correctly. |
| 202 reporter.internalError( | 207 reporter.internalError( |
| 203 compilationUnit, "Parser error in patch file: $e"); | 208 compilationUnit, "Parser error in patch file: $e"); |
| 204 } | 209 } |
| 205 }); | 210 }); |
| 206 } | 211 } |
| 207 | 212 |
| 208 void parsePatchClassNode(PartialClassElement cls) { | 213 void parsePatchClassNode(PartialClassElement cls) { |
| 209 // Parse [PartialClassElement] using a "patch"-aware parser instead | 214 // Parse [PartialClassElement] using a "patch"-aware parser instead |
| 210 // of calling its [parseNode] method. | 215 // of calling its [parseNode] method. |
| 211 if (cls.cachedNode != null) return; | 216 if (cls.cachedNode != null) return; |
| 212 | 217 |
| 213 measure(() => reporter.withCurrentElement(cls, () { | 218 measure(() => reporter.withCurrentElement(cls, () { |
| 214 MemberListener listener = new PatchMemberListener(compiler, cls); | 219 MemberListener listener = new PatchMemberListener(compiler, cls); |
| 215 Parser parser = new PatchClassElementParser(listener); | 220 Parser parser = new PatchClassElementParser( |
| 221 listener, enableConditionalDirectives: _enableConditionalDirectives); |
| 216 try { | 222 try { |
| 217 Token token = parser.parseTopLevelDeclaration(cls.beginToken); | 223 Token token = parser.parseTopLevelDeclaration(cls.beginToken); |
| 218 assert(identical(token, cls.endToken.next)); | 224 assert(identical(token, cls.endToken.next)); |
| 219 } on ParserError catch (e) { | 225 } on ParserError catch (e) { |
| 220 // No need to recover from a parser error in platform libraries, user | 226 // No need to recover from a parser error in platform libraries, user |
| 221 // will never see this if the libraries are tested correctly. | 227 // will never see this if the libraries are tested correctly. |
| 222 reporter.internalError( | 228 reporter.internalError( |
| 223 cls, "Parser error in patch file: $e"); | 229 cls, "Parser error in patch file: $e"); |
| 224 } | 230 } |
| 225 cls.cachedNode = listener.popNode(); | 231 cls.cachedNode = listener.popNode(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 enclosingClass.addMember(patch, reporter); | 263 enclosingClass.addMember(patch, reporter); |
| 258 } | 264 } |
| 259 } | 265 } |
| 260 } | 266 } |
| 261 | 267 |
| 262 /** | 268 /** |
| 263 * Partial parser for patch files that also handles the members of class | 269 * Partial parser for patch files that also handles the members of class |
| 264 * declarations. | 270 * declarations. |
| 265 */ | 271 */ |
| 266 class PatchClassElementParser extends PartialParser { | 272 class PatchClassElementParser extends PartialParser { |
| 267 PatchClassElementParser(Listener listener) : super(listener); | 273 PatchClassElementParser(Listener listener, {bool enableConditionalDirectives}) |
| 274 : super(listener, |
| 275 enableConditionalDirectives: enableConditionalDirectives); |
| 268 | 276 |
| 269 Token parseClassBody(Token token) => fullParseClassBody(token); | 277 Token parseClassBody(Token token) => fullParseClassBody(token); |
| 270 } | 278 } |
| 271 | 279 |
| 272 /** | 280 /** |
| 273 * Extension of [ElementListener] for parsing patch files. | 281 * Extension of [ElementListener] for parsing patch files. |
| 274 */ | 282 */ |
| 275 class PatchElementListener extends ElementListener implements Listener { | 283 class PatchElementListener extends ElementListener implements Listener { |
| 276 final Compiler compiler; | 284 final Compiler compiler; |
| 277 | 285 |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 | 696 |
| 689 class PatchVersion { | 697 class PatchVersion { |
| 690 final String tag; | 698 final String tag; |
| 691 | 699 |
| 692 const PatchVersion(this.tag); | 700 const PatchVersion(this.tag); |
| 693 | 701 |
| 694 bool isActive(String patchTag) => tag == null || tag == patchTag; | 702 bool isActive(String patchTag) => tag == null || tag == patchTag; |
| 695 | 703 |
| 696 String toString() => 'PatchVersion($tag)'; | 704 String toString() => 'PatchVersion($tag)'; |
| 697 } | 705 } |
| OLD | NEW |