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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/patch_parser.dart

Issue 17759007: First pass at asynchronous input loading in dart2js. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove withCurrentElementAsync Created 7 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 * TODO(johnniwinther): Simplify this invariant to use only declarations in 107 * TODO(johnniwinther): Simplify this invariant to use only declarations in
108 * [tree.TreeElements]. 108 * [tree.TreeElements].
109 * - Builders shift between declaration and implementation depending on usages. 109 * - Builders shift between declaration and implementation depending on usages.
110 * - Compile-time constants use constructor implementation exclusively. 110 * - Compile-time constants use constructor implementation exclusively.
111 * - Work on function parameters is performed on the declaration of the function 111 * - Work on function parameters is performed on the declaration of the function
112 * element. 112 * element.
113 */ 113 */
114 114
115 library patchparser; 115 library patchparser;
116 116
117 import 'dart:async';
118
117 import "tree/tree.dart" as tree; 119 import "tree/tree.dart" as tree;
118 import "dart2jslib.dart" as leg; // CompilerTask, Compiler. 120 import "dart2jslib.dart" as leg; // CompilerTask, Compiler.
119 import "../compiler.dart" as api; 121 import "../compiler.dart" as api;
120 import "scanner/scannerlib.dart"; // Scanner, Parsers, Listeners 122 import "scanner/scannerlib.dart"; // Scanner, Parsers, Listeners
121 import "elements/elements.dart"; 123 import "elements/elements.dart";
122 import "elements/modelx.dart" show LibraryElementX, MetadataAnnotationX; 124 import "elements/modelx.dart" show LibraryElementX, MetadataAnnotationX;
123 import 'util/util.dart'; 125 import 'util/util.dart';
124 126
125 class PatchParserTask extends leg.CompilerTask { 127 class PatchParserTask extends leg.CompilerTask {
126 PatchParserTask(leg.Compiler compiler): super(compiler); 128 PatchParserTask(leg.Compiler compiler): super(compiler);
127 final String name = "Patching Parser"; 129 final String name = "Patching Parser";
128 130
129 /** 131 /**
130 * Scans a library patch file, applies the method patches and 132 * Scans a library patch file, applies the method patches and
131 * injections to the library, and returns a list of class 133 * injections to the library, and returns a list of class
132 * patches. 134 * patches.
133 */ 135 */
134 void patchLibrary(leg.LibraryDependencyHandler handler, 136 Future patchLibrary(leg.LibraryDependencyHandler handler,
135 Uri patchUri, LibraryElement originLibrary) { 137 Uri patchUri, LibraryElement originLibrary) {
136 138 return compiler.readScript(patchUri, null).then((leg.Script script) {
137 leg.Script script = compiler.readScript(patchUri, null); 139 var patchLibrary = new LibraryElementX(script, null, originLibrary);
138 var patchLibrary = new LibraryElementX(script, null, originLibrary);
139 compiler.withCurrentElement(patchLibrary, () {
140 handler.registerNewLibrary(patchLibrary); 140 handler.registerNewLibrary(patchLibrary);
ahe 2013/08/06 16:29:17 Shouldn't lines 140-141 be inside withCurrentEleme
Johnni Winther 2013/08/27 11:05:00 Done.
141 LinkBuilder<tree.LibraryTag> 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. 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 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. 150 // scope for the original methods too. This should be fixed.
151 compiler.importHelperLibrary(originLibrary); 151 compiler.importHelperLibrary(originLibrary);
152 for (tree.LibraryTag tag in imports.toLink()) { 152 // TODO(rnystrom): Remove .toList() here if #11523 is fixed.
153 compiler.libraryLoader.registerLibraryFromTag( 153 return Future.forEach(imports.toLink().toList(), (tag) {
ahe 2013/08/06 16:29:17 Shouldn't there be a withCurrentElement here?
Johnni Winther 2013/08/27 11:05:00 Done.
154 handler, patchLibrary, tag); 154 return compiler.libraryLoader.registerLibraryFromTag(
155 } 155 handler, patchLibrary, tag);
156 });
156 }); 157 });
157 } 158 }
158 159
159 void scanLibraryElements( 160 void scanLibraryElements(
160 CompilationUnitElement compilationUnit, 161 CompilationUnitElement compilationUnit,
161 LinkBuilder<tree.LibraryTag> imports) { 162 LinkBuilder<tree.LibraryTag> imports) {
162 measure(() { 163 measure(() {
163 // TODO(lrn): Possibly recursively handle #source directives in patch. 164 // TODO(lrn): Possibly recursively handle #source directives in patch.
164 leg.Script script = compilationUnit.script; 165 leg.Script script = compilationUnit.script;
165 Token tokens = new StringScanner(script.text).tokenize(); 166 Token tokens = new StringScanner(script.text).tokenize();
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 548
548 // TODO(johnniwinther): Add unittest when patch is (real) metadata. 549 // TODO(johnniwinther): Add unittest when patch is (real) metadata.
549 bool isPatchElement(Element element) { 550 bool isPatchElement(Element element) {
550 // TODO(lrn): More checks needed if we introduce metadata for real. 551 // TODO(lrn): More checks needed if we introduce metadata for real.
551 // In that case, it must have the identifier "native" as metadata. 552 // In that case, it must have the identifier "native" as metadata.
552 for (Link link = element.metadata; !link.isEmpty; link = link.tail) { 553 for (Link link = element.metadata; !link.isEmpty; link = link.tail) {
553 if (link.head is PatchMetadataAnnotation) return true; 554 if (link.head is PatchMetadataAnnotation) return true;
554 } 555 }
555 return false; 556 return false;
556 } 557 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698