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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 LibraryElementX, | 130 LibraryElementX, |
131 MetadataAnnotationX, | 131 MetadataAnnotationX, |
132 SetterElementX; | 132 SetterElementX; |
133 import 'id_generator.dart'; | 133 import 'id_generator.dart'; |
134 import 'js_backend/js_backend.dart' show JavaScriptBackend; | 134 import 'js_backend/js_backend.dart' show JavaScriptBackend; |
135 import 'library_loader.dart' show LibraryLoader; | 135 import 'library_loader.dart' show LibraryLoader; |
136 import 'parser/element_listener.dart' show ElementListener; | 136 import 'parser/element_listener.dart' show ElementListener; |
137 import 'package:dart_parser/dart_parser.dart' | 137 import 'package:dart_parser/dart_parser.dart' |
138 show Listener, Parser, ParserError; | 138 show Listener, Parser, ParserError; |
139 import 'parser/member_listener.dart' show MemberListener; | 139 import 'parser/member_listener.dart' show MemberListener; |
140 import 'parser/partial_elements.dart' show PartialClassElement, PartialParser; | 140 import 'parser/partial_elements.dart' |
| 141 show ClassElementParser, PartialClassElement; |
141 import 'script.dart'; | 142 import 'script.dart'; |
142 import 'package:dart_scanner/dart_scanner.dart' show StringToken, Token; | 143 import 'package:dart_scanner/dart_scanner.dart' show StringToken, Token; |
143 import 'parser/diet_parser_task.dart' show DietParser; | 144 import 'parser/diet_parser_task.dart' show PartialParser; |
144 | 145 |
145 class PatchParserTask extends CompilerTask { | 146 class PatchParserTask extends CompilerTask { |
146 final String name = "Patching Parser"; | 147 final String name = "Patching Parser"; |
147 final Compiler compiler; | 148 final Compiler compiler; |
148 DiagnosticReporter get reporter => compiler.reporter; | 149 DiagnosticReporter get reporter => compiler.reporter; |
149 | 150 |
150 PatchParserTask(Compiler compiler) | 151 PatchParserTask(Compiler compiler) |
151 : compiler = compiler, | 152 : compiler = compiler, |
152 super(compiler.measurer); | 153 super(compiler.measurer); |
153 | 154 |
(...skipping 20 matching lines...) Expand all Loading... |
174 } | 175 } |
175 | 176 |
176 void scanLibraryElements(CompilationUnitElement compilationUnit) { | 177 void scanLibraryElements(CompilationUnitElement compilationUnit) { |
177 measure(() { | 178 measure(() { |
178 // TODO(johnniwinther): Test that parts and exports are handled correctly. | 179 // TODO(johnniwinther): Test that parts and exports are handled correctly. |
179 Script script = compilationUnit.script; | 180 Script script = compilationUnit.script; |
180 Token tokens = compiler.scanner.scanFile(script.file); | 181 Token tokens = compiler.scanner.scanFile(script.file); |
181 Listener patchListener = new PatchElementListener( | 182 Listener patchListener = new PatchElementListener( |
182 compiler, compilationUnit, compiler.idGenerator); | 183 compiler, compilationUnit, compiler.idGenerator); |
183 try { | 184 try { |
184 new DietParser(patchListener).parseUnit(tokens); | 185 new PartialParser(patchListener).parseUnit(tokens); |
185 } on ParserError catch (e) { | 186 } on ParserError catch (e) { |
186 // No need to recover from a parser error in platform libraries, user | 187 // No need to recover from a parser error in platform libraries, user |
187 // will never see this if the libraries are tested correctly. | 188 // will never see this if the libraries are tested correctly. |
188 reporter.internalError( | 189 reporter.internalError( |
189 compilationUnit, "Parser error in patch file: $e"); | 190 compilationUnit, "Parser error in patch file: $e"); |
190 } | 191 } |
191 }); | 192 }); |
192 } | 193 } |
193 | 194 |
194 void parsePatchClassNode(PartialClassElement cls) { | 195 void parsePatchClassNode(PartialClassElement cls) { |
195 // Parse [PartialClassElement] using a "patch"-aware parser instead | 196 // Parse [PartialClassElement] using a "patch"-aware parser instead |
196 // of calling its [parseNode] method. | 197 // of calling its [parseNode] method. |
197 if (cls.cachedNode != null) return; | 198 if (cls.cachedNode != null) return; |
198 | 199 |
199 measure(() => reporter.withCurrentElement(cls, () { | 200 measure(() => reporter.withCurrentElement(cls, () { |
200 MemberListener listener = new PatchMemberListener(compiler, cls); | 201 MemberListener listener = new PatchMemberListener(compiler, cls); |
201 Parser parser = new PartialParser(listener); | 202 Parser parser = new ClassElementParser(listener); |
202 try { | 203 try { |
203 Token token = parser.parseTopLevelDeclaration(cls.beginToken); | 204 Token token = parser.parseTopLevelDeclaration(cls.beginToken); |
204 assert(identical(token, cls.endToken.next)); | 205 assert(identical(token, cls.endToken.next)); |
205 } on ParserError catch (e) { | 206 } on ParserError catch (e) { |
206 // No need to recover from a parser error in platform libraries, | 207 // No need to recover from a parser error in platform libraries, |
207 // user will never see this if the libraries are tested correctly. | 208 // user will never see this if the libraries are tested correctly. |
208 reporter.internalError(cls, "Parser error in patch file: $e"); | 209 reporter.internalError(cls, "Parser error in patch file: $e"); |
209 } | 210 } |
210 cls.cachedNode = listener.popNode(); | 211 cls.cachedNode = listener.popNode(); |
211 assert(listener.nodes.isEmpty); | 212 assert(listener.nodes.isEmpty); |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 | 607 |
607 class PatchVersion { | 608 class PatchVersion { |
608 final String tag; | 609 final String tag; |
609 | 610 |
610 const PatchVersion(this.tag); | 611 const PatchVersion(this.tag); |
611 | 612 |
612 bool isActive(String patchTag) => tag == null || tag == patchTag; | 613 bool isActive(String patchTag) => tag == null || tag == patchTag; |
613 | 614 |
614 String toString() => 'PatchVersion($tag)'; | 615 String toString() => 'PatchVersion($tag)'; |
615 } | 616 } |
OLD | NEW |