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

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

Issue 1388523002: dart2js: add support for configuration-specific imports. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Address comments and add flag. Created 5 years, 2 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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 Parser; 150 Parser;
151 import 'scanner/scanner.dart' show 151 import 'scanner/scanner.dart' show
152 Scanner; 152 Scanner;
153 import 'script.dart'; 153 import 'script.dart';
154 import 'tokens/token.dart' show 154 import 'tokens/token.dart' show
155 StringToken, 155 StringToken,
156 Token; 156 Token;
157 157
158 class PatchParserTask extends CompilerTask { 158 class PatchParserTask extends CompilerTask {
159 final String name = "Patching Parser"; 159 final String name = "Patching Parser";
160 final bool _enableConditionalDirectives;
160 161
161 PatchParserTask(Compiler compiler): super(compiler); 162 PatchParserTask(Compiler compiler, {bool enableConditionalDirectives})
163 : this._enableConditionalDirectives = enableConditionalDirectives,
164 super(compiler);
162 165
163 /** 166 /**
164 * Scans a library patch file, applies the method patches and 167 * Scans a library patch file, applies the method patches and
165 * injections to the library, and returns a list of class 168 * injections to the library, and returns a list of class
166 * patches. 169 * patches.
167 */ 170 */
168 Future patchLibrary(LibraryLoader loader, 171 Future patchLibrary(LibraryLoader loader,
169 Uri patchUri, LibraryElement originLibrary) { 172 Uri patchUri, LibraryElement originLibrary) {
170 return compiler.readScript(originLibrary, patchUri) 173 return compiler.readScript(originLibrary, patchUri)
171 .then((Script script) { 174 .then((Script script) {
(...skipping 14 matching lines...) Expand all
186 void scanLibraryElements(CompilationUnitElement compilationUnit) { 189 void scanLibraryElements(CompilationUnitElement compilationUnit) {
187 measure(() { 190 measure(() {
188 // TODO(johnniwinther): Test that parts and exports are handled correctly. 191 // TODO(johnniwinther): Test that parts and exports are handled correctly.
189 Script script = compilationUnit.script; 192 Script script = compilationUnit.script;
190 Token tokens = new Scanner(script.file).tokenize(); 193 Token tokens = new Scanner(script.file).tokenize();
191 Function idGenerator = compiler.getNextFreeClassId; 194 Function idGenerator = compiler.getNextFreeClassId;
192 Listener patchListener = new PatchElementListener(compiler, 195 Listener patchListener = new PatchElementListener(compiler,
193 compilationUnit, 196 compilationUnit,
194 idGenerator); 197 idGenerator);
195 try { 198 try {
196 new PartialParser(patchListener).parseUnit(tokens); 199 new PartialParser(patchListener,
200 enableConditionalDirectives: _enableConditionalDirectives)
201 .parseUnit(tokens);
197 } on ParserError catch (e) { 202 } on ParserError catch (e) {
198 // 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
199 // will never see this if the libraries are tested correctly. 204 // will never see this if the libraries are tested correctly.
200 compiler.internalError( 205 compiler.internalError(
201 compilationUnit, "Parser error in patch file: $e"); 206 compilationUnit, "Parser error in patch file: $e");
202 } 207 }
203 }); 208 });
204 } 209 }
205 210
206 void parsePatchClassNode(PartialClassElement cls) { 211 void parsePatchClassNode(PartialClassElement cls) {
207 // Parse [PartialClassElement] using a "patch"-aware parser instead 212 // Parse [PartialClassElement] using a "patch"-aware parser instead
208 // of calling its [parseNode] method. 213 // of calling its [parseNode] method.
209 if (cls.cachedNode != null) return; 214 if (cls.cachedNode != null) return;
210 215
211 measure(() => compiler.withCurrentElement(cls, () { 216 measure(() => compiler.withCurrentElement(cls, () {
212 MemberListener listener = new PatchMemberListener(compiler, cls); 217 MemberListener listener = new PatchMemberListener(compiler, cls);
213 Parser parser = new PatchClassElementParser(listener); 218 Parser parser = new PatchClassElementParser(
219 listener, enableConditionalDirectives: _enableConditionalDirectives);
214 try { 220 try {
215 Token token = parser.parseTopLevelDeclaration(cls.beginToken); 221 Token token = parser.parseTopLevelDeclaration(cls.beginToken);
216 assert(identical(token, cls.endToken.next)); 222 assert(identical(token, cls.endToken.next));
217 } on ParserError catch (e) { 223 } on ParserError catch (e) {
218 // No need to recover from a parser error in platform libraries, user 224 // No need to recover from a parser error in platform libraries, user
219 // will never see this if the libraries are tested correctly. 225 // will never see this if the libraries are tested correctly.
220 compiler.internalError( 226 compiler.internalError(
221 cls, "Parser error in patch file: $e"); 227 cls, "Parser error in patch file: $e");
222 } 228 }
223 cls.cachedNode = listener.popNode(); 229 cls.cachedNode = listener.popNode();
(...skipping 26 matching lines...) Expand all
250 enclosingClass.addMember(patch, listener); 256 enclosingClass.addMember(patch, listener);
251 } 257 }
252 } 258 }
253 } 259 }
254 260
255 /** 261 /**
256 * Partial parser for patch files that also handles the members of class 262 * Partial parser for patch files that also handles the members of class
257 * declarations. 263 * declarations.
258 */ 264 */
259 class PatchClassElementParser extends PartialParser { 265 class PatchClassElementParser extends PartialParser {
260 PatchClassElementParser(Listener listener) : super(listener); 266 PatchClassElementParser(Listener listener, {bool enableConditionalDirectives})
267 : super(listener,
268 enableConditionalDirectives: enableConditionalDirectives);
261 269
262 Token parseClassBody(Token token) => fullParseClassBody(token); 270 Token parseClassBody(Token token) => fullParseClassBody(token);
263 } 271 }
264 272
265 /** 273 /**
266 * Extension of [ElementListener] for parsing patch files. 274 * Extension of [ElementListener] for parsing patch files.
267 */ 275 */
268 class PatchElementListener extends ElementListener implements Listener { 276 class PatchElementListener extends ElementListener implements Listener {
269 final Compiler compiler; 277 final Compiler compiler;
270 278
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 639
632 class PatchVersion { 640 class PatchVersion {
633 final String tag; 641 final String tag;
634 642
635 const PatchVersion(this.tag); 643 const PatchVersion(this.tag);
636 644
637 bool isActive(String patchTag) => tag == null || tag == patchTag; 645 bool isActive(String patchTag) => tag == null || tag == patchTag;
638 646
639 String toString() => 'PatchVersion($tag)'; 647 String toString() => 'PatchVersion($tag)';
640 } 648 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698