Chromium Code Reviews| 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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 | 129 |
| 130 /** | 130 /** |
| 131 * Scans a library patch file, applies the method patches and | 131 * Scans a library patch file, applies the method patches and |
| 132 * injections to the library, and returns a list of class | 132 * injections to the library, and returns a list of class |
| 133 * patches. | 133 * patches. |
| 134 */ | 134 */ |
| 135 void patchLibrary(leg.LibraryDependencyHandler handler, | 135 void patchLibrary(leg.LibraryDependencyHandler handler, |
| 136 Uri patchUri, LibraryElement originLibrary) { | 136 Uri patchUri, LibraryElement originLibrary) { |
| 137 | 137 |
| 138 leg.Script script = compiler.readScript(patchUri, null); | 138 leg.Script script = compiler.readScript(patchUri, null); |
| 139 var patchLibrary = new LibraryElementX(script, patchUri, originLibrary); | 139 var patchLibrary = |
| 140 handler.registerNewLibrary(patchLibrary); | 140 new LibraryElementX(script, originLibrary.uri, originLibrary); |
| 141 LinkBuilder<tree.LibraryTag> imports = new LinkBuilder<tree.LibraryTag>(); | 141 compiler.withCurrentElement(patchLibrary, () { |
| 142 compiler.withCurrentElement(patchLibrary.entryCompilationUnit, () { | 142 handler.registerNewLibrary(patchLibrary); |
| 143 // This patches the elements of the patch library into [library]. | 143 LinkBuilder<tree.LibraryTag> imports = new LinkBuilder<tree.LibraryTag>(); |
| 144 // Injected elements are added directly under the compilation unit. | 144 compiler.withCurrentElement(patchLibrary.entryCompilationUnit, () { |
| 145 // Patch elements are stored on the patched functions or classes. | 145 // This patches the elements of the patch library into [library]. |
| 146 scanLibraryElements(patchLibrary.entryCompilationUnit, imports); | 146 // Injected elements are added directly under the compilation unit. |
| 147 // Patch elements are stored on the patched functions or classes. | |
| 148 scanLibraryElements(patchLibrary.entryCompilationUnit, imports); | |
| 149 }); | |
| 150 // After scanning declarations, we handle the import tags in the patch. | |
| 151 // TODO(lrn): These imports end up in the original library and are in | |
| 152 // scope for the original methods too. This should be fixed. | |
| 153 compiler.importHelperLibrary(originLibrary); | |
| 154 for (tree.LibraryTag tag in imports.toLink()) { | |
| 155 compiler.libraryLoader.registerLibraryFromTag(handler, patchLibrary, tag ); | |
|
ngeoffray
2013/01/16 15:40:57
line too long
Johnni Winther
2013/01/21 09:27:54
Done.
| |
| 156 } | |
| 147 }); | 157 }); |
| 148 // After scanning declarations, we handle the import tags in the patch. | |
| 149 // TODO(lrn): These imports end up in the original library and are in | |
| 150 // scope for the original methods too. This should be fixed. | |
| 151 compiler.importHelperLibrary(originLibrary); | |
| 152 for (tree.LibraryTag tag in imports.toLink()) { | |
| 153 compiler.libraryLoader.registerLibraryFromTag(handler, patchLibrary, tag); | |
| 154 } | |
| 155 } | 158 } |
| 156 | 159 |
| 157 void scanLibraryElements( | 160 void scanLibraryElements( |
| 158 CompilationUnitElement compilationUnit, | 161 CompilationUnitElement compilationUnit, |
| 159 LinkBuilder<tree.LibraryTag> imports) { | 162 LinkBuilder<tree.LibraryTag> imports) { |
| 160 measure(() { | 163 measure(() { |
| 161 // TODO(lrn): Possibly recursively handle #source directives in patch. | 164 // TODO(lrn): Possibly recursively handle #source directives in patch. |
| 162 leg.Script script = compilationUnit.script; | 165 leg.Script script = compilationUnit.script; |
| 163 Token tokens = new StringScanner(script.text).tokenize(); | 166 Token tokens = new StringScanner(script.text).tokenize(); |
| 164 Function idGenerator = compiler.getNextFreeClassId; | 167 Function idGenerator = compiler.getNextFreeClassId; |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 499 } | 502 } |
| 500 | 503 |
| 501 // TODO(ahe): Get rid of this class. | 504 // TODO(ahe): Get rid of this class. |
| 502 class PatchMetadataAnnotation extends MetadataAnnotationX { | 505 class PatchMetadataAnnotation extends MetadataAnnotationX { |
| 503 final leg.Constant value = null; | 506 final leg.Constant value = null; |
| 504 | 507 |
| 505 PatchMetadataAnnotation() : super(STATE_DONE); | 508 PatchMetadataAnnotation() : super(STATE_DONE); |
| 506 | 509 |
| 507 Token get beginToken => null; | 510 Token get beginToken => null; |
| 508 } | 511 } |
| OLD | NEW |