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

Side by Side Diff: lib/compiler/implementation/tree/unparser.dart

Issue 10913067: Simplify Unparser.unparseClassWithBody. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 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
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 // Returns null if no need to rename a node. 5 // Returns null if no need to rename a node.
6 typedef String Renamer(Node node); 6 typedef String Renamer(Node node);
7 7
8 String unparse(Node node) { 8 String unparse(Node node) {
9 Unparser unparser = new Unparser(); 9 Unparser unparser = new Unparser();
10 unparser.unparse(node); 10 unparser.unparse(node);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 } 54 }
55 55
56 visitCascade(Cascade node) { 56 visitCascade(Cascade node) {
57 visit(node.expression); 57 visit(node.expression);
58 } 58 }
59 59
60 visitCascadeReceiver(CascadeReceiver node) { 60 visitCascadeReceiver(CascadeReceiver node) {
61 visit(node.expression); 61 visit(node.expression);
62 } 62 }
63 63
64 unparseClassWithBody(ClassNode node, void classBodyEmitter()) { 64 unparseClassWithBody(ClassNode node, Iterable<Node> members) {
Roman 2012/09/04 17:12:15 thank you for specifying type :)
Anton Muhin 2012/09/04 18:00:40 My pleasure
65 addToken(node.beginToken); 65 addToken(node.beginToken);
66 if (node.beginToken.stringValue == 'abstract') { 66 if (node.beginToken.stringValue == 'abstract') {
67 addToken(node.beginToken.next); 67 addToken(node.beginToken.next);
68 } 68 }
69 visit(node.name); 69 visit(node.name);
70 if (node.typeParameters !== null) { 70 if (node.typeParameters !== null) {
71 visit(node.typeParameters); 71 visit(node.typeParameters);
72 } 72 }
73 if (node.extendsKeyword !== null) { 73 if (node.extendsKeyword !== null) {
74 sb.add(' '); 74 sb.add(' ');
75 addToken(node.extendsKeyword); 75 addToken(node.extendsKeyword);
76 visit(node.superclass); 76 visit(node.superclass);
77 } 77 }
78 if (!node.interfaces.isEmpty()) { 78 if (!node.interfaces.isEmpty()) {
79 sb.add(' '); 79 sb.add(' ');
80 visit(node.interfaces); 80 visit(node.interfaces);
81 } 81 }
82 if (node.defaultClause !== null) { 82 if (node.defaultClause !== null) {
83 sb.add(' default '); 83 sb.add(' default ');
84 visit(node.defaultClause); 84 visit(node.defaultClause);
85 } 85 }
86 sb.add('{'); 86 sb.add('{');
87 classBodyEmitter(); 87 for (final member in members) {
88 visit(member);
89 }
88 sb.add('}'); 90 sb.add('}');
89 } 91 }
90 92
91 visitClassNode(ClassNode node) { 93 visitClassNode(ClassNode node) {
92 unparseClassWithBody(node, () { 94 unparseClassWithBody(node, node.body.nodes);
Roman 2012/09/04 17:12:15 original code performed null check on body. Are yo
Anton Muhin 2012/09/04 18:00:40 Not quite, but so far tests revealed no such cases
93 NodeList body = node.body;
94 if (body !== null) {
95 sb.add('\n');
96 Link nodes = body.nodes;
97 if (!nodes.isEmpty()) {
98 sb.add(' ');
99 nodes.printOn(sb, '\n ');
100 sb.add('\n');
101 }
102 }
103 });
104 sb.add('\n');
105 } 95 }
106 96
107 visitConditional(Conditional node) { 97 visitConditional(Conditional node) {
108 visit(node.condition); 98 visit(node.condition);
109 add(node.questionToken.value); 99 add(node.questionToken.value);
110 visit(node.thenExpression); 100 visit(node.thenExpression);
111 add(node.colonToken.value); 101 add(node.colonToken.value);
112 visit(node.elseExpression); 102 visit(node.elseExpression);
113 } 103 }
114 104
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 sb.add(' '); 507 sb.add(' ');
518 } 508 }
519 visit(node.name); 509 visit(node.name);
520 if (node.typeParameters !== null) { 510 if (node.typeParameters !== null) {
521 visit(node.typeParameters); 511 visit(node.typeParameters);
522 } 512 }
523 visit(node.formals); 513 visit(node.formals);
524 add(node.endToken.value); 514 add(node.endToken.value);
525 } 515 }
526 } 516 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/dart_backend/emitter.dart ('k') | tests/compiler/dart2js/unparser2_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698