| 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 * TODO(johnniwinther): The terminology and invariants described below will not | 6 * TODO(johnniwinther): The terminology and invariants described below will not |
| 7 * hold until CL 10905305 has been committed. | 7 * hold until CL 10905305 has been committed. |
| 8 * | 8 * |
| 9 * This library contains the infrastructure to parse and integrate patch files. | 9 * This library contains the infrastructure to parse and integrate patch files. |
| 10 * | 10 * |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 | 124 |
| 125 class PatchParserTask extends leg.CompilerTask { | 125 class PatchParserTask extends leg.CompilerTask { |
| 126 PatchParserTask(leg.Compiler compiler): super(compiler); | 126 PatchParserTask(leg.Compiler compiler): super(compiler); |
| 127 final String name = "Patching Parser"; | 127 final String name = "Patching Parser"; |
| 128 | 128 |
| 129 /** | 129 /** |
| 130 * Scans a library patch file, applies the method patches and | 130 * Scans a library patch file, applies the method patches and |
| 131 * injections to the library, and returns a list of class | 131 * injections to the library, and returns a list of class |
| 132 * patches. | 132 * patches. |
| 133 */ | 133 */ |
| 134 void patchLibrary(Uri patchUri, LibraryElement library) { | 134 void patchLibrary(ImportExportHandler handler, |
| 135 Uri patchUri, LibraryElement library) { |
| 135 leg.Script script = compiler.readScript(patchUri, null); | 136 leg.Script script = compiler.readScript(patchUri, null); |
| 136 CompilationUnitElement compilationUnit = | 137 CompilationUnitElement compilationUnit = |
| 137 new CompilationUnitElement(script, library); | 138 new CompilationUnitElement(script, library); |
| 138 LinkBuilder<tree.LibraryTag> imports = new LinkBuilder<tree.LibraryTag>(); | 139 LinkBuilder<tree.LibraryTag> imports = new LinkBuilder<tree.LibraryTag>(); |
| 139 compiler.withCurrentElement(compilationUnit, () { | 140 compiler.withCurrentElement(compilationUnit, () { |
| 140 // This patches the elements of the patch library into [library]. | 141 // This patches the elements of the patch library into [library]. |
| 141 // Injected elements are added directly under the compilation unit. | 142 // Injected elements are added directly under the compilation unit. |
| 142 // Patch elements are stored on the patched functions or classes. | 143 // Patch elements are stored on the patched functions or classes. |
| 143 scanLibraryElements(compilationUnit, imports); | 144 scanLibraryElements(compilationUnit, imports); |
| 144 }); | 145 }); |
| 145 // After scanning declarations, we handle the import tags in the patch. | 146 // After scanning declarations, we handle the import tags in the patch. |
| 146 // TODO(lrn): These imports end up in the original library and are in | 147 // TODO(lrn): These imports end up in the original library and are in |
| 147 // scope for the original methods too. This should be fixed. | 148 // scope for the original methods too. This should be fixed. |
| 148 for (tree.LibraryTag tag in imports.toLink()) { | 149 for (tree.LibraryTag tag in imports.toLink()) { |
| 149 compiler.scanner.importLibraryFromTag(tag, compilationUnit); | 150 compiler.scanner.loadLibraryFromTag( |
| 151 handler, library, tag, compilationUnit); |
| 150 } | 152 } |
| 151 } | 153 } |
| 152 | 154 |
| 153 void scanLibraryElements( | 155 void scanLibraryElements( |
| 154 CompilationUnitElement compilationUnit, | 156 CompilationUnitElement compilationUnit, |
| 155 LinkBuilder<tree.LibraryTag> imports) { | 157 LinkBuilder<tree.LibraryTag> imports) { |
| 156 measure(() { | 158 measure(() { |
| 157 // TODO(lrn): Possibly recursively handle #source directives in patch. | 159 // TODO(lrn): Possibly recursively handle #source directives in patch. |
| 158 leg.Script script = compilationUnit.script; | 160 leg.Script script = compilationUnit.script; |
| 159 Token tokens = new StringScanner(script.text).tokenize(); | 161 Token tokens = new StringScanner(script.text).tokenize(); |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 super.addMember(element); | 403 super.addMember(element); |
| 402 } | 404 } |
| 403 } | 405 } |
| 404 | 406 |
| 405 // TODO(ahe): Get rid of this class. | 407 // TODO(ahe): Get rid of this class. |
| 406 class PatchMetadataAnnotation extends MetadataAnnotation { | 408 class PatchMetadataAnnotation extends MetadataAnnotation { |
| 407 final leg.Constant value = null; | 409 final leg.Constant value = null; |
| 408 | 410 |
| 409 PatchMetadataAnnotation() : super(STATE_DONE); | 411 PatchMetadataAnnotation() : super(STATE_DONE); |
| 410 } | 412 } |
| OLD | NEW |