| 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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 BaseFunctionElementX, | 130 BaseFunctionElementX, |
| 131 ClassElementX, | 131 ClassElementX, |
| 132 GetterElementX, | 132 GetterElementX, |
| 133 LibraryElementX, | 133 LibraryElementX, |
| 134 MetadataAnnotationX, | 134 MetadataAnnotationX, |
| 135 SetterElementX; | 135 SetterElementX; |
| 136 import 'js_backend/js_backend.dart' show | 136 import 'js_backend/js_backend.dart' show |
| 137 JavaScriptBackend; | 137 JavaScriptBackend; |
| 138 import 'library_loader.dart' show | 138 import 'library_loader.dart' show |
| 139 LibraryLoader; | 139 LibraryLoader; |
| 140 import 'options.dart' show | |
| 141 ParserOptions; | |
| 142 import 'parser/listener.dart' show | 140 import 'parser/listener.dart' show |
| 143 Listener, | 141 Listener, |
| 144 ParserError; | 142 ParserError; |
| 145 import 'parser/element_listener.dart' show | 143 import 'parser/element_listener.dart' show |
| 146 ElementListener; | 144 ElementListener; |
| 147 import 'parser/member_listener.dart' show | 145 import 'parser/member_listener.dart' show |
| 148 MemberListener; | 146 MemberListener; |
| 149 import 'parser/partial_elements.dart' show | 147 import 'parser/partial_elements.dart' show |
| 150 PartialClassElement; | 148 PartialClassElement; |
| 151 import 'parser/partial_parser.dart' show | 149 import 'parser/partial_parser.dart' show |
| 152 PartialParser; | 150 PartialParser; |
| 153 import 'parser/parser.dart' show | 151 import 'parser/parser.dart' show |
| 154 Parser; | 152 Parser; |
| 155 import 'scanner/scanner.dart' show | 153 import 'scanner/scanner.dart' show |
| 156 Scanner; | 154 Scanner; |
| 157 import 'script.dart'; | 155 import 'script.dart'; |
| 158 import 'tokens/token.dart' show | 156 import 'tokens/token.dart' show |
| 159 StringToken, | 157 StringToken, |
| 160 Token; | 158 Token; |
| 161 | 159 |
| 162 class PatchParserTask extends CompilerTask { | 160 class PatchParserTask extends CompilerTask { |
| 163 final String name = "Patching Parser"; | 161 final String name = "Patching Parser"; |
| 164 final ParserOptions parserOptions; | 162 final bool _enableConditionalDirectives; |
| 165 | 163 |
| 166 PatchParserTask(Compiler compiler, this.parserOptions) : super(compiler); | 164 PatchParserTask(Compiler compiler, {bool enableConditionalDirectives}) |
| 165 : this._enableConditionalDirectives = enableConditionalDirectives, |
| 166 super(compiler); |
| 167 | 167 |
| 168 /** | 168 /** |
| 169 * Scans a library patch file, applies the method patches and | 169 * Scans a library patch file, applies the method patches and |
| 170 * injections to the library, and returns a list of class | 170 * injections to the library, and returns a list of class |
| 171 * patches. | 171 * patches. |
| 172 */ | 172 */ |
| 173 Future patchLibrary(LibraryLoader loader, | 173 Future patchLibrary(LibraryLoader loader, |
| 174 Uri patchUri, LibraryElement originLibrary) { | 174 Uri patchUri, LibraryElement originLibrary) { |
| 175 return compiler.readScript(patchUri, originLibrary) | 175 return compiler.readScript(patchUri, originLibrary) |
| 176 .then((Script script) { | 176 .then((Script script) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 191 void scanLibraryElements(CompilationUnitElement compilationUnit) { | 191 void scanLibraryElements(CompilationUnitElement compilationUnit) { |
| 192 measure(() { | 192 measure(() { |
| 193 // TODO(johnniwinther): Test that parts and exports are handled correctly. | 193 // TODO(johnniwinther): Test that parts and exports are handled correctly. |
| 194 Script script = compilationUnit.script; | 194 Script script = compilationUnit.script; |
| 195 Token tokens = new Scanner(script.file).tokenize(); | 195 Token tokens = new Scanner(script.file).tokenize(); |
| 196 Function idGenerator = compiler.getNextFreeClassId; | 196 Function idGenerator = compiler.getNextFreeClassId; |
| 197 Listener patchListener = new PatchElementListener(compiler, | 197 Listener patchListener = new PatchElementListener(compiler, |
| 198 compilationUnit, | 198 compilationUnit, |
| 199 idGenerator); | 199 idGenerator); |
| 200 try { | 200 try { |
| 201 new PartialParser(patchListener, parserOptions).parseUnit(tokens); | 201 new PartialParser(patchListener, |
| 202 enableConditionalDirectives: _enableConditionalDirectives) |
| 203 .parseUnit(tokens); |
| 202 } on ParserError catch (e) { | 204 } on ParserError catch (e) { |
| 203 // 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 |
| 204 // will never see this if the libraries are tested correctly. | 206 // will never see this if the libraries are tested correctly. |
| 205 reporter.internalError( | 207 reporter.internalError( |
| 206 compilationUnit, "Parser error in patch file: $e"); | 208 compilationUnit, "Parser error in patch file: $e"); |
| 207 } | 209 } |
| 208 }); | 210 }); |
| 209 } | 211 } |
| 210 | 212 |
| 211 void parsePatchClassNode(PartialClassElement cls) { | 213 void parsePatchClassNode(PartialClassElement cls) { |
| 212 // Parse [PartialClassElement] using a "patch"-aware parser instead | 214 // Parse [PartialClassElement] using a "patch"-aware parser instead |
| 213 // of calling its [parseNode] method. | 215 // of calling its [parseNode] method. |
| 214 if (cls.cachedNode != null) return; | 216 if (cls.cachedNode != null) return; |
| 215 | 217 |
| 216 measure(() => reporter.withCurrentElement(cls, () { | 218 measure(() => reporter.withCurrentElement(cls, () { |
| 217 MemberListener listener = new PatchMemberListener(compiler, cls); | 219 MemberListener listener = new PatchMemberListener(compiler, cls); |
| 218 Parser parser = new PatchClassElementParser(listener, parserOptions); | 220 Parser parser = new PatchClassElementParser( |
| 221 listener, enableConditionalDirectives: _enableConditionalDirectives); |
| 219 try { | 222 try { |
| 220 Token token = parser.parseTopLevelDeclaration(cls.beginToken); | 223 Token token = parser.parseTopLevelDeclaration(cls.beginToken); |
| 221 assert(identical(token, cls.endToken.next)); | 224 assert(identical(token, cls.endToken.next)); |
| 222 } on ParserError catch (e) { | 225 } on ParserError catch (e) { |
| 223 // 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 |
| 224 // will never see this if the libraries are tested correctly. | 227 // will never see this if the libraries are tested correctly. |
| 225 reporter.internalError( | 228 reporter.internalError( |
| 226 cls, "Parser error in patch file: $e"); | 229 cls, "Parser error in patch file: $e"); |
| 227 } | 230 } |
| 228 cls.cachedNode = listener.popNode(); | 231 cls.cachedNode = listener.popNode(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 enclosingClass.addMember(patch, reporter); | 263 enclosingClass.addMember(patch, reporter); |
| 261 } | 264 } |
| 262 } | 265 } |
| 263 } | 266 } |
| 264 | 267 |
| 265 /** | 268 /** |
| 266 * 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 |
| 267 * declarations. | 270 * declarations. |
| 268 */ | 271 */ |
| 269 class PatchClassElementParser extends PartialParser { | 272 class PatchClassElementParser extends PartialParser { |
| 270 PatchClassElementParser(Listener listener, ParserOptions options) | 273 PatchClassElementParser(Listener listener, {bool enableConditionalDirectives}) |
| 271 : super(listener, options); | 274 : super(listener, |
| 275 enableConditionalDirectives: enableConditionalDirectives); |
| 272 | 276 |
| 273 Token parseClassBody(Token token) => fullParseClassBody(token); | 277 Token parseClassBody(Token token) => fullParseClassBody(token); |
| 274 } | 278 } |
| 275 | 279 |
| 276 /** | 280 /** |
| 277 * Extension of [ElementListener] for parsing patch files. | 281 * Extension of [ElementListener] for parsing patch files. |
| 278 */ | 282 */ |
| 279 class PatchElementListener extends ElementListener implements Listener { | 283 class PatchElementListener extends ElementListener implements Listener { |
| 280 final Compiler compiler; | 284 final Compiler compiler; |
| 281 | 285 |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 | 696 |
| 693 class PatchVersion { | 697 class PatchVersion { |
| 694 final String tag; | 698 final String tag; |
| 695 | 699 |
| 696 const PatchVersion(this.tag); | 700 const PatchVersion(this.tag); |
| 697 | 701 |
| 698 bool isActive(String patchTag) => tag == null || tag == patchTag; | 702 bool isActive(String patchTag) => tag == null || tag == patchTag; |
| 699 | 703 |
| 700 String toString() => 'PatchVersion($tag)'; | 704 String toString() => 'PatchVersion($tag)'; |
| 701 } | 705 } |
| OLD | NEW |