| 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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 'parser/listener.dart' show | 140 import 'parser/listener.dart' show |
| 141 Listener, | 141 Listener, |
| 142 ParserError; | 142 ParserError; |
| 143 import 'parser/element_listener.dart' show | 143 import 'parser/element_listener.dart' show |
| 144 ElementListener; | 144 ElementListener, |
| 145 ParserOptions; |
| 145 import 'parser/member_listener.dart' show | 146 import 'parser/member_listener.dart' show |
| 146 MemberListener; | 147 MemberListener; |
| 147 import 'parser/partial_elements.dart' show | 148 import 'parser/partial_elements.dart' show |
| 148 PartialClassElement; | 149 PartialClassElement; |
| 149 import 'parser/partial_parser.dart' show | 150 import 'parser/partial_parser.dart' show |
| 150 PartialParser; | 151 PartialParser; |
| 151 import 'parser/parser.dart' show | 152 import 'parser/parser.dart' show |
| 152 Parser; | 153 Parser; |
| 153 import 'scanner/scanner.dart' show | 154 import 'scanner/scanner.dart' show |
| 154 Scanner; | 155 Scanner; |
| 155 import 'script.dart'; | 156 import 'script.dart'; |
| 156 import 'tokens/token.dart' show | 157 import 'tokens/token.dart' show |
| 157 StringToken, | 158 StringToken, |
| 158 Token; | 159 Token; |
| 159 | 160 |
| 160 class PatchParserTask extends CompilerTask { | 161 class PatchParserTask extends CompilerTask { |
| 161 final String name = "Patching Parser"; | 162 final String name = "Patching Parser"; |
| 162 final bool _enableConditionalDirectives; | 163 final bool _enableConditionalDirectives; |
| 164 final bool _enableGenericMethods; |
| 163 | 165 |
| 164 PatchParserTask(Compiler compiler, {bool enableConditionalDirectives}) | 166 PatchParserTask(Compiler compiler, ParserOptions parserOptions) |
| 165 : this._enableConditionalDirectives = enableConditionalDirectives, | 167 : this._enableConditionalDirectives = |
| 168 parserOptions.enableConditionalDirectives, |
| 169 this._enableGenericMethods = parserOptions.enableGenericMethods, |
| 166 super(compiler); | 170 super(compiler); |
| 167 | 171 |
| 168 /** | 172 /** |
| 169 * Scans a library patch file, applies the method patches and | 173 * Scans a library patch file, applies the method patches and |
| 170 * injections to the library, and returns a list of class | 174 * injections to the library, and returns a list of class |
| 171 * patches. | 175 * patches. |
| 172 */ | 176 */ |
| 173 Future patchLibrary(LibraryLoader loader, | 177 Future patchLibrary(LibraryLoader loader, |
| 174 Uri patchUri, LibraryElement originLibrary) { | 178 Uri patchUri, LibraryElement originLibrary) { |
| 175 return compiler.readScript(originLibrary, patchUri) | 179 return compiler.readScript(originLibrary, patchUri) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 192 measure(() { | 196 measure(() { |
| 193 // TODO(johnniwinther): Test that parts and exports are handled correctly. | 197 // TODO(johnniwinther): Test that parts and exports are handled correctly. |
| 194 Script script = compilationUnit.script; | 198 Script script = compilationUnit.script; |
| 195 Token tokens = new Scanner(script.file).tokenize(); | 199 Token tokens = new Scanner(script.file).tokenize(); |
| 196 Function idGenerator = compiler.getNextFreeClassId; | 200 Function idGenerator = compiler.getNextFreeClassId; |
| 197 Listener patchListener = new PatchElementListener(compiler, | 201 Listener patchListener = new PatchElementListener(compiler, |
| 198 compilationUnit, | 202 compilationUnit, |
| 199 idGenerator); | 203 idGenerator); |
| 200 try { | 204 try { |
| 201 new PartialParser(patchListener, | 205 new PartialParser(patchListener, |
| 202 enableConditionalDirectives: _enableConditionalDirectives) | 206 enableConditionalDirectives: _enableConditionalDirectives, |
| 207 enableGenericMethods: _enableGenericMethods) |
| 203 .parseUnit(tokens); | 208 .parseUnit(tokens); |
| 204 } on ParserError catch (e) { | 209 } on ParserError catch (e) { |
| 205 // No need to recover from a parser error in platform libraries, user | 210 // No need to recover from a parser error in platform libraries, user |
| 206 // will never see this if the libraries are tested correctly. | 211 // will never see this if the libraries are tested correctly. |
| 207 reporter.internalError( | 212 reporter.internalError( |
| 208 compilationUnit, "Parser error in patch file: $e"); | 213 compilationUnit, "Parser error in patch file: $e"); |
| 209 } | 214 } |
| 210 }); | 215 }); |
| 211 } | 216 } |
| 212 | 217 |
| 213 void parsePatchClassNode(PartialClassElement cls) { | 218 void parsePatchClassNode(PartialClassElement cls) { |
| 214 // Parse [PartialClassElement] using a "patch"-aware parser instead | 219 // Parse [PartialClassElement] using a "patch"-aware parser instead |
| 215 // of calling its [parseNode] method. | 220 // of calling its [parseNode] method. |
| 216 if (cls.cachedNode != null) return; | 221 if (cls.cachedNode != null) return; |
| 217 | 222 |
| 218 measure(() => reporter.withCurrentElement(cls, () { | 223 measure(() => reporter.withCurrentElement(cls, () { |
| 219 MemberListener listener = new PatchMemberListener(compiler, cls); | 224 MemberListener listener = new PatchMemberListener(compiler, cls); |
| 220 Parser parser = new PatchClassElementParser( | 225 Parser parser = new PatchClassElementParser( |
| 221 listener, enableConditionalDirectives: _enableConditionalDirectives); | 226 listener, |
| 227 enableConditionalDirectives: _enableConditionalDirectives, |
| 228 enableGenericMethods: _enableGenericMethods); |
| 222 try { | 229 try { |
| 223 Token token = parser.parseTopLevelDeclaration(cls.beginToken); | 230 Token token = parser.parseTopLevelDeclaration(cls.beginToken); |
| 224 assert(identical(token, cls.endToken.next)); | 231 assert(identical(token, cls.endToken.next)); |
| 225 } on ParserError catch (e) { | 232 } on ParserError catch (e) { |
| 226 // No need to recover from a parser error in platform libraries, user | 233 // No need to recover from a parser error in platform libraries, user |
| 227 // will never see this if the libraries are tested correctly. | 234 // will never see this if the libraries are tested correctly. |
| 228 reporter.internalError( | 235 reporter.internalError( |
| 229 cls, "Parser error in patch file: $e"); | 236 cls, "Parser error in patch file: $e"); |
| 230 } | 237 } |
| 231 cls.cachedNode = listener.popNode(); | 238 cls.cachedNode = listener.popNode(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 enclosingClass.addMember(patch, reporter); | 270 enclosingClass.addMember(patch, reporter); |
| 264 } | 271 } |
| 265 } | 272 } |
| 266 } | 273 } |
| 267 | 274 |
| 268 /** | 275 /** |
| 269 * Partial parser for patch files that also handles the members of class | 276 * Partial parser for patch files that also handles the members of class |
| 270 * declarations. | 277 * declarations. |
| 271 */ | 278 */ |
| 272 class PatchClassElementParser extends PartialParser { | 279 class PatchClassElementParser extends PartialParser { |
| 273 PatchClassElementParser(Listener listener, {bool enableConditionalDirectives}) | 280 PatchClassElementParser(Listener listener, |
| 281 {bool enableConditionalDirectives: false, |
| 282 bool enableGenericMethods: false}) |
| 274 : super(listener, | 283 : super(listener, |
| 275 enableConditionalDirectives: enableConditionalDirectives); | 284 enableConditionalDirectives: enableConditionalDirectives, |
| 285 enableGenericMethods: enableGenericMethods); |
| 276 | 286 |
| 277 Token parseClassBody(Token token) => fullParseClassBody(token); | 287 Token parseClassBody(Token token) => fullParseClassBody(token); |
| 278 } | 288 } |
| 279 | 289 |
| 280 /** | 290 /** |
| 281 * Extension of [ElementListener] for parsing patch files. | 291 * Extension of [ElementListener] for parsing patch files. |
| 282 */ | 292 */ |
| 283 class PatchElementListener extends ElementListener implements Listener { | 293 class PatchElementListener extends ElementListener implements Listener { |
| 284 final Compiler compiler; | 294 final Compiler compiler; |
| 285 | 295 |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 696 | 706 |
| 697 class PatchVersion { | 707 class PatchVersion { |
| 698 final String tag; | 708 final String tag; |
| 699 | 709 |
| 700 const PatchVersion(this.tag); | 710 const PatchVersion(this.tag); |
| 701 | 711 |
| 702 bool isActive(String patchTag) => tag == null || tag == patchTag; | 712 bool isActive(String patchTag) => tag == null || tag == patchTag; |
| 703 | 713 |
| 704 String toString() => 'PatchVersion($tag)'; | 714 String toString() => 'PatchVersion($tag)'; |
| 705 } | 715 } |
| OLD | NEW |