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

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

Issue 808953004: Recover from fatal parser errors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Merged with r42860. Created 5 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | dart/pkg/compiler/lib/src/resolution/members.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 163
164 void scanLibraryElements(CompilationUnitElement compilationUnit) { 164 void scanLibraryElements(CompilationUnitElement compilationUnit) {
165 measure(() { 165 measure(() {
166 // TODO(johnniwinther): Test that parts and exports are handled correctly. 166 // TODO(johnniwinther): Test that parts and exports are handled correctly.
167 Script script = compilationUnit.script; 167 Script script = compilationUnit.script;
168 Token tokens = new Scanner(script.file).tokenize(); 168 Token tokens = new Scanner(script.file).tokenize();
169 Function idGenerator = compiler.getNextFreeClassId; 169 Function idGenerator = compiler.getNextFreeClassId;
170 Listener patchListener = new PatchElementListener(compiler, 170 Listener patchListener = new PatchElementListener(compiler,
171 compilationUnit, 171 compilationUnit,
172 idGenerator); 172 idGenerator);
173 new PartialParser(patchListener).parseUnit(tokens); 173 try {
174 new PartialParser(patchListener).parseUnit(tokens);
175 } on ParserError catch (e) {
176 // No need to recover from a parser error in platform libraries, user
177 // will never see this if the libraries are tested correctly.
178 compiler.internalError(
179 compilationUnit, "Parser error in patch file: $e");
180 }
174 }); 181 });
175 } 182 }
176 183
177 void parsePatchClassNode(PartialClassElement element) { 184 void parsePatchClassNode(PartialClassElement element) {
178 // Parse [PartialClassElement] using a "patch"-aware parser instead 185 // Parse [PartialClassElement] using a "patch"-aware parser instead
179 // of calling its [parseNode] method. 186 // of calling its [parseNode] method.
180 if (element.cachedNode != null) return; 187 if (element.cachedNode != null) return;
181 188
182 measure(() => compiler.withCurrentElement(element, () { 189 measure(() => compiler.withCurrentElement(element, () {
183 MemberListener listener = new MemberListener(compiler, element); 190 MemberListener listener = new MemberListener(compiler, element);
184 Parser parser = new PatchClassElementParser(listener); 191 Parser parser = new PatchClassElementParser(listener);
185 Token token = parser.parseTopLevelDeclaration(element.beginToken); 192 try {
186 assert(identical(token, element.endToken.next)); 193 Token token = parser.parseTopLevelDeclaration(element.beginToken);
194 assert(identical(token, element.endToken.next));
195 } on ParserError catch (e) {
196 // No need to recover from a parser error in platform libraries, user
197 // will never see this if the libraries are tested correctly.
198 compiler.internalError(
199 element, "Parser error in patch file: $e");
200 }
187 element.cachedNode = listener.popNode(); 201 element.cachedNode = listener.popNode();
188 assert(listener.nodes.isEmpty); 202 assert(listener.nodes.isEmpty);
189 203
190 Link<Element> patches = element.localMembers; 204 Link<Element> patches = element.localMembers;
191 applyContainerPatch(element.origin, patches); 205 applyContainerPatch(element.origin, patches);
192 })); 206 }));
193 } 207 }
194 208
195 void applyContainerPatch(ClassElement originClass, 209 void applyContainerPatch(ClassElement originClass,
196 Link<Element> patches) { 210 Link<Element> patches) {
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 "Trying to patch a function more than once."); 518 "Trying to patch a function more than once.");
505 } 519 }
506 origin.applyPatch(patch); 520 origin.applyPatch(patch);
507 } 521 }
508 522
509 // TODO(johnniwinther): Add unittest when patch is (real) metadata. 523 // TODO(johnniwinther): Add unittest when patch is (real) metadata.
510 bool isPatchElement(Compiler compiler, Element element) { 524 bool isPatchElement(Compiler compiler, Element element) {
511 return EagerAnnotationHandler.checkAnnotation(compiler, element, 525 return EagerAnnotationHandler.checkAnnotation(compiler, element,
512 const PatchAnnotationHandler()); 526 const PatchAnnotationHandler());
513 } 527 }
OLDNEW
« no previous file with comments | « no previous file | dart/pkg/compiler/lib/src/resolution/members.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698