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

Side by Side Diff: frog/leg/tree_validator.dart

Issue 9873021: Move frog/leg to lib/compiler/implementation. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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 | Annotate | Revision Log
« no previous file with comments | « frog/leg/tree/visitors.dart ('k') | frog/leg/typechecker.dart » ('j') | 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) 2011, 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 class TreeValidatorTask extends CompilerTask {
6 TreeValidatorTask(Compiler compiler) : super(compiler);
7
8 void validate(Node tree) {
9 assert(check(tree));
10 }
11
12 bool check(Node tree) {
13 List<InvalidNodeError> errors = [];
14 void report(node, message) {
15 final error = new InvalidNodeError(node, message);
16 errors.add(error);
17 compiler.reportWarning(node, message);
18 };
19 final validator = new ValidatorVisitor(report);
20 tree.accept(new TraversingVisitor(validator));
21
22 return errors.isEmpty();
23 }
24 }
25
26 class ValidatorVisitor extends AbstractVisitor {
27 final Function reportInvalidNode;
28
29 ValidatorVisitor(Function this.reportInvalidNode);
30
31 expect(Node node, bool test, [message]) {
32 if (!test) reportInvalidNode(node, message);
33 }
34
35 visitNode(Node node) {}
36
37 visitSendSet(SendSet node) {
38 final selector = node.selector;
39 final name = node.assignmentOperator.source.stringValue;
40 final arguments = node.arguments;
41
42 expect(node, arguments !== null);
43 expect(node, selector is Identifier, 'selector is not assignable');
44 if (name === '++' || name === '--') {
45 expect(node, node.assignmentOperator is Operator);
46 if (node.isIndex) {
47 expect(node.arguments.tail.head, node.arguments.tail.isEmpty());
48 } else {
49 expect(node.arguments.head, node.arguments.isEmpty());
50 }
51 } else {
52 expect(node, !node.arguments.isEmpty());
53 }
54 }
55 }
56
57 class InvalidNodeError {
58 final Node node;
59 final String message;
60 InvalidNodeError(this.node, [this.message]);
61
62 toString() {
63 String nodeString = new Unparser(true).unparse(node);
64 String result = 'invalid node: $nodeString';
65 if (message !== null) result = '$result ($message)';
66 return result;
67 }
68 }
OLDNEW
« no previous file with comments | « frog/leg/tree/visitors.dart ('k') | frog/leg/typechecker.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698