| 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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 | 123 |
| 124 class PatchParserTask extends leg.CompilerTask { | 124 class PatchParserTask extends leg.CompilerTask { |
| 125 PatchParserTask(leg.Compiler compiler): super(compiler); | 125 PatchParserTask(leg.Compiler compiler): super(compiler); |
| 126 final String name = "Patching Parser"; | 126 final String name = "Patching Parser"; |
| 127 | 127 |
| 128 /** | 128 /** |
| 129 * Scans a library patch file, applies the method patches and | 129 * Scans a library patch file, applies the method patches and |
| 130 * injections to the library, and returns a list of class | 130 * injections to the library, and returns a list of class |
| 131 * patches. | 131 * patches. |
| 132 */ | 132 */ |
| 133 void patchLibrary(Uri patchUri, LibraryElement originLibrary) { | 133 void patchLibrary(leg.LibraryDependencyHandler handler, |
| 134 Uri patchUri, LibraryElement originLibrary) { |
| 135 |
| 134 leg.Script script = compiler.readScript(patchUri, null); | 136 leg.Script script = compiler.readScript(patchUri, null); |
| 135 var patchLibrary = new LibraryElement(script, patchUri, originLibrary); | 137 var patchLibrary = new LibraryElement(script, patchUri, originLibrary); |
| 138 handler.registerNewLibrary(patchLibrary); |
| 136 LinkBuilder<tree.LibraryTag> imports = new LinkBuilder<tree.LibraryTag>(); | 139 LinkBuilder<tree.LibraryTag> imports = new LinkBuilder<tree.LibraryTag>(); |
| 137 compiler.withCurrentElement(patchLibrary.entryCompilationUnit, () { | 140 compiler.withCurrentElement(patchLibrary.entryCompilationUnit, () { |
| 138 // This patches the elements of the patch library into [library]. | 141 // This patches the elements of the patch library into [library]. |
| 139 // Injected elements are added directly under the compilation unit. | 142 // Injected elements are added directly under the compilation unit. |
| 140 // Patch elements are stored on the patched functions or classes. | 143 // Patch elements are stored on the patched functions or classes. |
| 141 scanLibraryElements(patchLibrary.entryCompilationUnit, imports); | 144 scanLibraryElements(patchLibrary.entryCompilationUnit, imports); |
| 142 }); | 145 }); |
| 143 // After scanning declarations, we handle the import tags in the patch. | 146 // After scanning declarations, we handle the import tags in the patch. |
| 144 // 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 |
| 145 // scope for the original methods too. This should be fixed. | 148 // scope for the original methods too. This should be fixed. |
| 146 compiler.importHelperLibrary(originLibrary); | 149 compiler.importHelperLibrary(originLibrary); |
| 147 for (tree.LibraryTag tag in imports.toLink()) { | 150 for (tree.LibraryTag tag in imports.toLink()) { |
| 148 compiler.scanner.importLibraryFromTag(tag, | 151 compiler.libraryLoader.loadLibraryFromTag(handler, patchLibrary, tag); |
| 149 patchLibrary.entryCompilationUnit); | |
| 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 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 super.addMember(element); | 492 super.addMember(element); |
| 491 } | 493 } |
| 492 } | 494 } |
| 493 | 495 |
| 494 // TODO(ahe): Get rid of this class. | 496 // TODO(ahe): Get rid of this class. |
| 495 class PatchMetadataAnnotation extends MetadataAnnotation { | 497 class PatchMetadataAnnotation extends MetadataAnnotation { |
| 496 final leg.Constant value = null; | 498 final leg.Constant value = null; |
| 497 | 499 |
| 498 PatchMetadataAnnotation() : super(STATE_DONE); | 500 PatchMetadataAnnotation() : super(STATE_DONE); |
| 499 } | 501 } |
| OLD | NEW |