| 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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 var patchLibrary = new LibraryElementX(script, null, originLibrary); | 138 var patchLibrary = new LibraryElementX(script, null, originLibrary); |
| 139 return compiler.withCurrentElement(patchLibrary, () { | 139 return compiler.withCurrentElement(patchLibrary, () { |
| 140 handler.registerNewLibrary(patchLibrary); | 140 handler.registerNewLibrary(patchLibrary); |
| 141 var imports = new LinkBuilder<tree.LibraryTag>(); | 141 var imports = new LinkBuilder<tree.LibraryTag>(); |
| 142 compiler.withCurrentElement(patchLibrary.entryCompilationUnit, () { | 142 compiler.withCurrentElement(patchLibrary.entryCompilationUnit, () { |
| 143 // This patches the elements of the patch library into [library]. | 143 // This patches the elements of the patch library into [library]. |
| 144 // Injected elements are added directly under the compilation unit. | 144 // Injected elements are added directly under the compilation unit. |
| 145 // Patch elements are stored on the patched functions or classes. | 145 // Patch elements are stored on the patched functions or classes. |
| 146 scanLibraryElements(patchLibrary.entryCompilationUnit, imports); | 146 scanLibraryElements(patchLibrary.entryCompilationUnit, imports); |
| 147 }); | 147 }); |
| 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 // TODO(rnystrom): Remove .toList() here if #11523 is fixed. | 148 // TODO(rnystrom): Remove .toList() here if #11523 is fixed. |
| 153 return Future.forEach(imports.toLink().toList(), (tag) { | 149 return Future.forEach(imports.toLink().toList(), (tag) { |
| 154 return compiler.withCurrentElement(patchLibrary, () { | 150 return compiler.withCurrentElement(patchLibrary, () { |
| 155 return compiler.libraryLoader.registerLibraryFromTag( | 151 return compiler.libraryLoader.registerLibraryFromTag( |
| 156 handler, patchLibrary, tag); | 152 handler, patchLibrary, tag); |
| 157 }); | 153 }); |
| 158 }); | 154 }); |
| 159 }); | 155 }); |
| 160 }); | 156 }); |
| 161 } | 157 } |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 | 549 |
| 554 // TODO(johnniwinther): Add unittest when patch is (real) metadata. | 550 // TODO(johnniwinther): Add unittest when patch is (real) metadata. |
| 555 bool isPatchElement(Element element) { | 551 bool isPatchElement(Element element) { |
| 556 // TODO(lrn): More checks needed if we introduce metadata for real. | 552 // TODO(lrn): More checks needed if we introduce metadata for real. |
| 557 // In that case, it must have the identifier "native" as metadata. | 553 // In that case, it must have the identifier "native" as metadata. |
| 558 for (Link link = element.metadata; !link.isEmpty; link = link.tail) { | 554 for (Link link = element.metadata; !link.isEmpty; link = link.tail) { |
| 559 if (link.head is PatchMetadataAnnotation) return true; | 555 if (link.head is PatchMetadataAnnotation) return true; |
| 560 } | 556 } |
| 561 return false; | 557 return false; |
| 562 } | 558 } |
| OLD | NEW |