OLD | NEW |
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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 import 'dart_types.dart' show DartType; | 123 import 'dart_types.dart' show DartType; |
124 import 'elements/elements.dart'; | 124 import 'elements/elements.dart'; |
125 import 'elements/modelx.dart' | 125 import 'elements/modelx.dart' |
126 show | 126 show |
127 BaseFunctionElementX, | 127 BaseFunctionElementX, |
128 ClassElementX, | 128 ClassElementX, |
129 GetterElementX, | 129 GetterElementX, |
130 LibraryElementX, | 130 LibraryElementX, |
131 MetadataAnnotationX, | 131 MetadataAnnotationX, |
132 SetterElementX; | 132 SetterElementX; |
| 133 import 'id_generator.dart'; |
133 import 'js_backend/js_backend.dart' show JavaScriptBackend; | 134 import 'js_backend/js_backend.dart' show JavaScriptBackend; |
134 import 'library_loader.dart' show LibraryLoader; | 135 import 'library_loader.dart' show LibraryLoader; |
135 import 'options.dart' show ParserOptions; | 136 import 'options.dart' show ParserOptions; |
136 import 'parser/listener.dart' show Listener, ParserError; | 137 import 'parser/listener.dart' show Listener, ParserError; |
137 import 'parser/element_listener.dart' show ElementListener; | 138 import 'parser/element_listener.dart' show ElementListener; |
138 import 'parser/member_listener.dart' show MemberListener; | 139 import 'parser/member_listener.dart' show MemberListener; |
139 import 'parser/partial_elements.dart' show PartialClassElement; | 140 import 'parser/partial_elements.dart' show PartialClassElement; |
140 import 'parser/partial_parser.dart' show PartialParser; | 141 import 'parser/partial_parser.dart' show PartialParser; |
141 import 'parser/parser.dart' show Parser; | 142 import 'parser/parser.dart' show Parser; |
142 import 'scanner/scanner.dart' show Scanner; | 143 import 'scanner/scanner.dart' show Scanner; |
(...skipping 26 matching lines...) Expand all Loading... |
169 return loader.processLibraryTags(patchLibrary); | 170 return loader.processLibraryTags(patchLibrary); |
170 }); | 171 }); |
171 }); | 172 }); |
172 } | 173 } |
173 | 174 |
174 void scanLibraryElements(CompilationUnitElement compilationUnit) { | 175 void scanLibraryElements(CompilationUnitElement compilationUnit) { |
175 measure(() { | 176 measure(() { |
176 // TODO(johnniwinther): Test that parts and exports are handled correctly. | 177 // TODO(johnniwinther): Test that parts and exports are handled correctly. |
177 Script script = compilationUnit.script; | 178 Script script = compilationUnit.script; |
178 Token tokens = new Scanner(script.file).tokenize(); | 179 Token tokens = new Scanner(script.file).tokenize(); |
179 Function idGenerator = compiler.getNextFreeClassId; | |
180 Listener patchListener = | 180 Listener patchListener = |
181 new PatchElementListener(compiler, compilationUnit, idGenerator); | 181 new PatchElementListener(compiler, compilationUnit, compiler); |
182 try { | 182 try { |
183 new PartialParser(patchListener, parserOptions).parseUnit(tokens); | 183 new PartialParser(patchListener, parserOptions).parseUnit(tokens); |
184 } on ParserError catch (e) { | 184 } on ParserError catch (e) { |
185 // No need to recover from a parser error in platform libraries, user | 185 // No need to recover from a parser error in platform libraries, user |
186 // will never see this if the libraries are tested correctly. | 186 // will never see this if the libraries are tested correctly. |
187 reporter.internalError( | 187 reporter.internalError( |
188 compilationUnit, "Parser error in patch file: $e"); | 188 compilationUnit, "Parser error in patch file: $e"); |
189 } | 189 } |
190 }); | 190 }); |
191 } | 191 } |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 | 252 |
253 Token parseClassBody(Token token) => fullParseClassBody(token); | 253 Token parseClassBody(Token token) => fullParseClassBody(token); |
254 } | 254 } |
255 | 255 |
256 /** | 256 /** |
257 * Extension of [ElementListener] for parsing patch files. | 257 * Extension of [ElementListener] for parsing patch files. |
258 */ | 258 */ |
259 class PatchElementListener extends ElementListener implements Listener { | 259 class PatchElementListener extends ElementListener implements Listener { |
260 final Compiler compiler; | 260 final Compiler compiler; |
261 | 261 |
262 PatchElementListener( | 262 PatchElementListener(Compiler compiler, CompilationUnitElement patchElement, |
263 Compiler compiler, CompilationUnitElement patchElement, int idGenerator()) | 263 IdGenerator idGenerator) |
264 : this.compiler = compiler, | 264 : this.compiler = compiler, |
265 super(compiler.parsing.getScannerOptionsFor(patchElement), | 265 super(compiler.parsing.getScannerOptionsFor(patchElement), |
266 compiler.reporter, patchElement, idGenerator); | 266 compiler.reporter, patchElement, idGenerator); |
267 | 267 |
268 @override | 268 @override |
269 void pushElement(Element patch) { | 269 void pushElement(Element patch) { |
270 popMetadata(patch); | 270 popMetadata(patch); |
271 | 271 |
272 PatchVersion patchVersion = getPatchVersion(compiler, patch); | 272 PatchVersion patchVersion = getPatchVersion(compiler, patch); |
273 if (patchVersion != null) { | 273 if (patchVersion != null) { |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 | 612 |
613 class PatchVersion { | 613 class PatchVersion { |
614 final String tag; | 614 final String tag; |
615 | 615 |
616 const PatchVersion(this.tag); | 616 const PatchVersion(this.tag); |
617 | 617 |
618 bool isActive(String patchTag) => tag == null || tag == patchTag; | 618 bool isActive(String patchTag) => tag == null || tag == patchTag; |
619 | 619 |
620 String toString() => 'PatchVersion($tag)'; | 620 String toString() => 'PatchVersion($tag)'; |
621 } | 621 } |
OLD | NEW |