Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(316)

Unified Diff: sdk/lib/_internal/compiler/implementation/patch_parser.dart

Issue 350693007: Load patches via callback. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sdk/lib/_internal/compiler/implementation/patch_parser.dart
diff --git a/sdk/lib/_internal/compiler/implementation/patch_parser.dart b/sdk/lib/_internal/compiler/implementation/patch_parser.dart
index 215d8a841c06bd8fc22e3d099598dd42dde9383c..56ea93ad700d4c2b95e47b2ec21ca4c8239f8634 100644
--- a/sdk/lib/_internal/compiler/implementation/patch_parser.dart
+++ b/sdk/lib/_internal/compiler/implementation/patch_parser.dart
@@ -126,6 +126,7 @@ import "elements/modelx.dart"
MetadataAnnotationX,
ClassElementX,
FunctionElementX;
+import "library_loader.dart" show LibraryLoaderCallback;
import 'util/util.dart';
class PatchParserTask extends leg.CompilerTask {
@@ -137,43 +138,33 @@ class PatchParserTask extends leg.CompilerTask {
* injections to the library, and returns a list of class
* patches.
*/
- Future patchLibrary(leg.LibraryDependencyHandler handler,
+ Future patchLibrary(LibraryLoaderCallback callback,
Uri patchUri, LibraryElement originLibrary) {
return compiler.readScript(originLibrary, patchUri)
.then((leg.Script script) {
var patchLibrary = new LibraryElementX(script, null, originLibrary);
return compiler.withCurrentElement(patchLibrary, () {
- handler.registerNewLibrary(patchLibrary);
- var imports = new LinkBuilder<tree.LibraryTag>();
+ callback.onLibraryCreated(patchLibrary);
compiler.withCurrentElement(patchLibrary.entryCompilationUnit, () {
// This patches the elements of the patch library into [library].
// Injected elements are added directly under the compilation unit.
// Patch elements are stored on the patched functions or classes.
- scanLibraryElements(patchLibrary.entryCompilationUnit, imports);
- });
- // TODO(rnystrom): Remove .toList() here if #11523 is fixed.
- return Future.forEach(imports.toLink().toList(), (tag) {
- return compiler.withCurrentElement(patchLibrary, () {
- return compiler.libraryLoader.registerLibraryFromTag(
- handler, patchLibrary, tag);
- });
+ scanLibraryElements(patchLibrary.entryCompilationUnit);
});
+ return callback.onLibraryScanned(patchLibrary);
});
});
}
- void scanLibraryElements(
- CompilationUnitElement compilationUnit,
- LinkBuilder<tree.LibraryTag> imports) {
+ void scanLibraryElements(CompilationUnitElement compilationUnit) {
measure(() {
- // TODO(lrn): Possibly recursively handle 'part' directives in patch.
+ // TODO(johnniwinther): Test that parts and exports are handled correctly.
leg.Script script = compilationUnit.script;
Token tokens = new Scanner(script.file).tokenize();
Function idGenerator = compiler.getNextFreeClassId;
Listener patchListener = new PatchElementListener(compiler,
compilationUnit,
- idGenerator,
- imports);
+ idGenerator);
new PartialParser(patchListener).parseUnit(tokens);
});
}
@@ -222,26 +213,13 @@ class PatchClassElementParser extends PartialParser {
*/
class PatchElementListener extends ElementListener implements Listener {
final leg.Compiler compiler;
- final LinkBuilder<tree.LibraryTag> imports;
PatchElementListener(leg.Compiler compiler,
CompilationUnitElement patchElement,
- int idGenerator(),
- this.imports)
+ int idGenerator())
: this.compiler = compiler,
super(compiler, patchElement, idGenerator);
- /**
- * Allow script tags (import only, the parser rejects the rest for now) in
- * patch files. The import tags will be added to the library.
- */
- bool allowLibraryTags() => true;
-
- void addLibraryTag(tree.LibraryTag tag) {
- super.addLibraryTag(tag);
- imports.addLast(tag);
- }
-
void pushElement(Element patch) {
super.pushElement(patch);
if (isPatchElement(compiler, patch)) {

Powered by Google App Engine
This is Rietveld 408576698