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

Side by Side Diff: lib/compiler/implementation/unparse_validator.dart

Issue 10332196: Start working on unparse validation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Next iteration Created 8 years, 7 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 | « lib/compiler/implementation/leg.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 /**
6 * Checks result's of [Node] unparse.
7 */
8 class UnparseValidator extends CompilerTask {
9 final bool validateUnparse;
10
11 UnparseValidator(Compiler compiler, this.validateUnparse) : super(compiler);
12
13 void check(Element element) {
14 if (!validateUnparse) {
ahe 2012/05/22 08:49:04 Just one line: if (!validateUnparse) return;
Anton Muhin 2012/05/22 15:34:32 Done.
15 return;
16 }
17
18 if (element is! PartialFunctionElement) {
ahe 2012/05/22 08:49:04 Ditto.
Anton Muhin 2012/05/22 15:34:32 Done.
19 // TODO(antonm): consider supporting other kinds of elements.
20 return;
21 }
22
23 PartialFunctionElement originalFunction = element;
24 FunctionExpression originalNode = originalFunction.parseNode(compiler);
25 String unparsed = originalNode.unparse(false);
26
27 Token newTokens = new StringScanner(unparsed).tokenize();
28
29 // Find the getOrSet token.
30 // TODO(ahe): This is to frigging complicated. Simplify it.
ahe 2012/05/22 08:49:04 It's great that you copied this verbatim :-)
Anton Muhin 2012/05/22 15:34:32 :)
31 Parser parser = new Parser(new Listener());
32 Token getOrSet =
33 parser.findGetOrSet(parser.parseModifiers(newTokens));
34
35 // TODO(ahe): This is also too frigging complicated.
36 Script originalScript = element.getCompilationUnit().script;
37 SourceFile synthesizedSourceFile =
38 new SourceFile(originalScript.name, unparsed);
39 Script synthesizedScript =
40 new Script(originalScript.uri, synthesizedSourceFile);
41 LibraryElement lib = new LibraryElement(synthesizedScript);
42 NodeListener listener = new NodeListener(compiler, lib);
43 parser = new Parser(listener);
44 final oldHandler = compiler.handler;
Anton Muhin 2012/05/21 19:14:39 this trick is sketchy, but allows nice diagnostics
ahe 2012/05/22 08:49:04 I don't understand why you have to do this. How is
Anton Muhin 2012/05/22 08:56:32 The old handler will lookup SourceFile via uri and
ahe 2012/05/22 09:04:45 The source file should be found in the "currentEle
Anton Muhin 2012/05/22 15:34:32 As far as I understand it goes like this: we get
ahe 2012/05/22 15:50:56 Shoot. I forgot about the compiler API. It would b
Anton Muhin 2012/05/22 19:16:57 I am sorry, I've already submitted w/o it. Sendin
45 compiler.handler = (uri, begin, end, message, fatal) {
46 final errorMessage =
47 synthesizedSourceFile.getLocationMessage(message, begin, end, true);
48 print('$errorMessage');
49 };
50 try {
51 compiler.withCurrentElement(lib, () {
52 parser.parseFunction(newTokens, getOrSet);
53 });
54 } finally {
55 compiler.handler = oldHandler;
56 }
57 FunctionExpression newNode = listener.popNode();
58 // TODO(antonm): add Node comparison.
59 }
60 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/leg.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698