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

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

Issue 1851753002: Enable conditional directives by default. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 Parser; 152 Parser;
153 import 'scanner/scanner.dart' show 153 import 'scanner/scanner.dart' show
154 Scanner; 154 Scanner;
155 import 'script.dart'; 155 import 'script.dart';
156 import 'tokens/token.dart' show 156 import 'tokens/token.dart' show
157 StringToken, 157 StringToken,
158 Token; 158 Token;
159 159
160 class PatchParserTask extends CompilerTask { 160 class PatchParserTask extends CompilerTask {
161 final String name = "Patching Parser"; 161 final String name = "Patching Parser";
162 final bool _enableConditionalDirectives;
163 162
164 PatchParserTask(Compiler compiler, {bool enableConditionalDirectives}) 163 PatchParserTask(Compiler compiler) : super(compiler);
165 : this._enableConditionalDirectives = enableConditionalDirectives,
166 super(compiler);
167 164
168 /** 165 /**
169 * Scans a library patch file, applies the method patches and 166 * Scans a library patch file, applies the method patches and
170 * injections to the library, and returns a list of class 167 * injections to the library, and returns a list of class
171 * patches. 168 * patches.
172 */ 169 */
173 Future patchLibrary(LibraryLoader loader, 170 Future patchLibrary(LibraryLoader loader,
174 Uri patchUri, LibraryElement originLibrary) { 171 Uri patchUri, LibraryElement originLibrary) {
175 return compiler.readScript(patchUri, originLibrary) 172 return compiler.readScript(patchUri, originLibrary)
176 .then((Script script) { 173 .then((Script script) {
(...skipping 14 matching lines...) Expand all
191 void scanLibraryElements(CompilationUnitElement compilationUnit) { 188 void scanLibraryElements(CompilationUnitElement compilationUnit) {
192 measure(() { 189 measure(() {
193 // TODO(johnniwinther): Test that parts and exports are handled correctly. 190 // TODO(johnniwinther): Test that parts and exports are handled correctly.
194 Script script = compilationUnit.script; 191 Script script = compilationUnit.script;
195 Token tokens = new Scanner(script.file).tokenize(); 192 Token tokens = new Scanner(script.file).tokenize();
196 Function idGenerator = compiler.getNextFreeClassId; 193 Function idGenerator = compiler.getNextFreeClassId;
197 Listener patchListener = new PatchElementListener(compiler, 194 Listener patchListener = new PatchElementListener(compiler,
198 compilationUnit, 195 compilationUnit,
199 idGenerator); 196 idGenerator);
200 try { 197 try {
201 new PartialParser(patchListener, 198 new PartialParser(patchListener).parseUnit(tokens);
202 enableConditionalDirectives: _enableConditionalDirectives)
203 .parseUnit(tokens);
204 } on ParserError catch (e) { 199 } on ParserError catch (e) {
205 // No need to recover from a parser error in platform libraries, user 200 // No need to recover from a parser error in platform libraries, user
206 // will never see this if the libraries are tested correctly. 201 // will never see this if the libraries are tested correctly.
207 reporter.internalError( 202 reporter.internalError(
208 compilationUnit, "Parser error in patch file: $e"); 203 compilationUnit, "Parser error in patch file: $e");
209 } 204 }
210 }); 205 });
211 } 206 }
212 207
213 void parsePatchClassNode(PartialClassElement cls) { 208 void parsePatchClassNode(PartialClassElement cls) {
214 // Parse [PartialClassElement] using a "patch"-aware parser instead 209 // Parse [PartialClassElement] using a "patch"-aware parser instead
215 // of calling its [parseNode] method. 210 // of calling its [parseNode] method.
216 if (cls.cachedNode != null) return; 211 if (cls.cachedNode != null) return;
217 212
218 measure(() => reporter.withCurrentElement(cls, () { 213 measure(() => reporter.withCurrentElement(cls, () {
219 MemberListener listener = new PatchMemberListener(compiler, cls); 214 MemberListener listener = new PatchMemberListener(compiler, cls);
220 Parser parser = new PatchClassElementParser( 215 Parser parser = new PatchClassElementParser(listener);
221 listener, enableConditionalDirectives: _enableConditionalDirectives);
222 try { 216 try {
223 Token token = parser.parseTopLevelDeclaration(cls.beginToken); 217 Token token = parser.parseTopLevelDeclaration(cls.beginToken);
224 assert(identical(token, cls.endToken.next)); 218 assert(identical(token, cls.endToken.next));
225 } on ParserError catch (e) { 219 } on ParserError catch (e) {
226 // No need to recover from a parser error in platform libraries, user 220 // No need to recover from a parser error in platform libraries, user
227 // will never see this if the libraries are tested correctly. 221 // will never see this if the libraries are tested correctly.
228 reporter.internalError( 222 reporter.internalError(
229 cls, "Parser error in patch file: $e"); 223 cls, "Parser error in patch file: $e");
230 } 224 }
231 cls.cachedNode = listener.popNode(); 225 cls.cachedNode = listener.popNode();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 enclosingClass.addMember(patch, reporter); 257 enclosingClass.addMember(patch, reporter);
264 } 258 }
265 } 259 }
266 } 260 }
267 261
268 /** 262 /**
269 * Partial parser for patch files that also handles the members of class 263 * Partial parser for patch files that also handles the members of class
270 * declarations. 264 * declarations.
271 */ 265 */
272 class PatchClassElementParser extends PartialParser { 266 class PatchClassElementParser extends PartialParser {
273 PatchClassElementParser(Listener listener, {bool enableConditionalDirectives}) 267 PatchClassElementParser(Listener listener) : super(listener);
274 : super(listener,
275 enableConditionalDirectives: enableConditionalDirectives);
276 268
277 Token parseClassBody(Token token) => fullParseClassBody(token); 269 Token parseClassBody(Token token) => fullParseClassBody(token);
278 } 270 }
279 271
280 /** 272 /**
281 * Extension of [ElementListener] for parsing patch files. 273 * Extension of [ElementListener] for parsing patch files.
282 */ 274 */
283 class PatchElementListener extends ElementListener implements Listener { 275 class PatchElementListener extends ElementListener implements Listener {
284 final Compiler compiler; 276 final Compiler compiler;
285 277
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 688
697 class PatchVersion { 689 class PatchVersion {
698 final String tag; 690 final String tag;
699 691
700 const PatchVersion(this.tag); 692 const PatchVersion(this.tag);
701 693
702 bool isActive(String patchTag) => tag == null || tag == patchTag; 694 bool isActive(String patchTag) => tag == null || tag == patchTag;
703 695
704 String toString() => 'PatchVersion($tag)'; 696 String toString() => 'PatchVersion($tag)';
705 } 697 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698