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

Side by Side Diff: pkg/compiler/lib/src/patch_parser.dart

Issue 1864433004: Repeats and fixes the changes landed & reverted as CL 1789553003. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updates to external dependents Created 4 years, 8 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
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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 BaseFunctionElementX, 130 BaseFunctionElementX,
131 ClassElementX, 131 ClassElementX,
132 GetterElementX, 132 GetterElementX,
133 LibraryElementX, 133 LibraryElementX,
134 MetadataAnnotationX, 134 MetadataAnnotationX,
135 SetterElementX; 135 SetterElementX;
136 import 'js_backend/js_backend.dart' show 136 import 'js_backend/js_backend.dart' show
137 JavaScriptBackend; 137 JavaScriptBackend;
138 import 'library_loader.dart' show 138 import 'library_loader.dart' show
139 LibraryLoader; 139 LibraryLoader;
140 import 'options.dart' show
141 ParserOptions;
140 import 'parser/listener.dart' show 142 import 'parser/listener.dart' show
141 Listener, 143 Listener,
142 ParserError; 144 ParserError;
143 import 'parser/element_listener.dart' show 145 import 'parser/element_listener.dart' show
144 ElementListener; 146 ElementListener;
145 import 'parser/member_listener.dart' show 147 import 'parser/member_listener.dart' show
146 MemberListener; 148 MemberListener;
147 import 'parser/partial_elements.dart' show 149 import 'parser/partial_elements.dart' show
148 PartialClassElement; 150 PartialClassElement;
149 import 'parser/partial_parser.dart' show 151 import 'parser/partial_parser.dart' show
150 PartialParser; 152 PartialParser;
151 import 'parser/parser.dart' show 153 import 'parser/parser.dart' show
152 Parser; 154 Parser;
153 import 'scanner/scanner.dart' show 155 import 'scanner/scanner.dart' show
154 Scanner; 156 Scanner;
155 import 'script.dart'; 157 import 'script.dart';
156 import 'tokens/token.dart' show 158 import 'tokens/token.dart' show
157 StringToken, 159 StringToken,
158 Token; 160 Token;
159 161
160 class PatchParserTask extends CompilerTask { 162 class PatchParserTask extends CompilerTask {
161 final String name = "Patching Parser"; 163 final String name = "Patching Parser";
162 final bool _enableConditionalDirectives; 164 final ParserOptions parserOptions;
163 165
164 PatchParserTask(Compiler compiler, {bool enableConditionalDirectives}) 166 PatchParserTask(Compiler compiler, this.parserOptions) : super(compiler);
165 : this._enableConditionalDirectives = enableConditionalDirectives,
166 super(compiler);
167 167
168 /** 168 /**
169 * Scans a library patch file, applies the method patches and 169 * Scans a library patch file, applies the method patches and
170 * injections to the library, and returns a list of class 170 * injections to the library, and returns a list of class
171 * patches. 171 * patches.
172 */ 172 */
173 Future patchLibrary(LibraryLoader loader, 173 Future patchLibrary(LibraryLoader loader,
174 Uri patchUri, LibraryElement originLibrary) { 174 Uri patchUri, LibraryElement originLibrary) {
175 return compiler.readScript(patchUri, originLibrary) 175 return compiler.readScript(patchUri, originLibrary)
176 .then((Script script) { 176 .then((Script script) {
(...skipping 14 matching lines...) Expand all
191 void scanLibraryElements(CompilationUnitElement compilationUnit) { 191 void scanLibraryElements(CompilationUnitElement compilationUnit) {
192 measure(() { 192 measure(() {
193 // TODO(johnniwinther): Test that parts and exports are handled correctly. 193 // TODO(johnniwinther): Test that parts and exports are handled correctly.
194 Script script = compilationUnit.script; 194 Script script = compilationUnit.script;
195 Token tokens = new Scanner(script.file).tokenize(); 195 Token tokens = new Scanner(script.file).tokenize();
196 Function idGenerator = compiler.getNextFreeClassId; 196 Function idGenerator = compiler.getNextFreeClassId;
197 Listener patchListener = new PatchElementListener(compiler, 197 Listener patchListener = new PatchElementListener(compiler,
198 compilationUnit, 198 compilationUnit,
199 idGenerator); 199 idGenerator);
200 try { 200 try {
201 new PartialParser(patchListener, 201 new PartialParser(patchListener, parserOptions).parseUnit(tokens);
202 enableConditionalDirectives: _enableConditionalDirectives)
203 .parseUnit(tokens);
204 } on ParserError catch (e) { 202 } on ParserError catch (e) {
205 // No need to recover from a parser error in platform libraries, user 203 // No need to recover from a parser error in platform libraries, user
206 // will never see this if the libraries are tested correctly. 204 // will never see this if the libraries are tested correctly.
207 reporter.internalError( 205 reporter.internalError(
208 compilationUnit, "Parser error in patch file: $e"); 206 compilationUnit, "Parser error in patch file: $e");
209 } 207 }
210 }); 208 });
211 } 209 }
212 210
213 void parsePatchClassNode(PartialClassElement cls) { 211 void parsePatchClassNode(PartialClassElement cls) {
214 // Parse [PartialClassElement] using a "patch"-aware parser instead 212 // Parse [PartialClassElement] using a "patch"-aware parser instead
215 // of calling its [parseNode] method. 213 // of calling its [parseNode] method.
216 if (cls.cachedNode != null) return; 214 if (cls.cachedNode != null) return;
217 215
218 measure(() => reporter.withCurrentElement(cls, () { 216 measure(() => reporter.withCurrentElement(cls, () {
219 MemberListener listener = new PatchMemberListener(compiler, cls); 217 MemberListener listener = new PatchMemberListener(compiler, cls);
220 Parser parser = new PatchClassElementParser( 218 Parser parser = new PatchClassElementParser(listener, parserOptions);
221 listener, enableConditionalDirectives: _enableConditionalDirectives);
222 try { 219 try {
223 Token token = parser.parseTopLevelDeclaration(cls.beginToken); 220 Token token = parser.parseTopLevelDeclaration(cls.beginToken);
224 assert(identical(token, cls.endToken.next)); 221 assert(identical(token, cls.endToken.next));
225 } on ParserError catch (e) { 222 } on ParserError catch (e) {
226 // No need to recover from a parser error in platform libraries, user 223 // No need to recover from a parser error in platform libraries, user
227 // will never see this if the libraries are tested correctly. 224 // will never see this if the libraries are tested correctly.
228 reporter.internalError( 225 reporter.internalError(
229 cls, "Parser error in patch file: $e"); 226 cls, "Parser error in patch file: $e");
230 } 227 }
231 cls.cachedNode = listener.popNode(); 228 cls.cachedNode = listener.popNode();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 enclosingClass.addMember(patch, reporter); 260 enclosingClass.addMember(patch, reporter);
264 } 261 }
265 } 262 }
266 } 263 }
267 264
268 /** 265 /**
269 * Partial parser for patch files that also handles the members of class 266 * Partial parser for patch files that also handles the members of class
270 * declarations. 267 * declarations.
271 */ 268 */
272 class PatchClassElementParser extends PartialParser { 269 class PatchClassElementParser extends PartialParser {
273 PatchClassElementParser(Listener listener, {bool enableConditionalDirectives}) 270 PatchClassElementParser(Listener listener, ParserOptions options)
274 : super(listener, 271 : super(listener, options);
275 enableConditionalDirectives: enableConditionalDirectives);
276 272
277 Token parseClassBody(Token token) => fullParseClassBody(token); 273 Token parseClassBody(Token token) => fullParseClassBody(token);
278 } 274 }
279 275
280 /** 276 /**
281 * Extension of [ElementListener] for parsing patch files. 277 * Extension of [ElementListener] for parsing patch files.
282 */ 278 */
283 class PatchElementListener extends ElementListener implements Listener { 279 class PatchElementListener extends ElementListener implements Listener {
284 final Compiler compiler; 280 final Compiler compiler;
285 281
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 692
697 class PatchVersion { 693 class PatchVersion {
698 final String tag; 694 final String tag;
699 695
700 const PatchVersion(this.tag); 696 const PatchVersion(this.tag);
701 697
702 bool isActive(String patchTag) => tag == null || tag == patchTag; 698 bool isActive(String patchTag) => tag == null || tag == patchTag;
703 699
704 String toString() => 'PatchVersion($tag)'; 700 String toString() => 'PatchVersion($tag)';
705 } 701 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/parser/partial_parser.dart ('k') | pkg/dart2js_incremental/lib/dart2js_incremental.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698