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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/dart_backend/tree_tracer.dart

Issue 284213002: dart2dart: Logical operators and related rewrite rules in dart_tree. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: SVN rebase Created 6 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
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 library dart_backend.tracer; 5 library dart_backend.tracer;
6 6
7 import 'dart:async' show EventSink; 7 import 'dart:async' show EventSink;
8 import '../tracer.dart'; 8 import '../tracer.dart';
9 import 'dart_tree.dart'; 9 import 'dart_tree.dart';
10 10
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 visitStatement(function.body); 45 visitStatement(function.body);
46 } 46 }
47 47
48 visitVariable(Variable node) {} 48 visitVariable(Variable node) {}
49 visitInvokeStatic(InvokeStatic node) {} 49 visitInvokeStatic(InvokeStatic node) {}
50 visitInvokeMethod(InvokeMethod node) {} 50 visitInvokeMethod(InvokeMethod node) {}
51 visitInvokeConstructor(InvokeConstructor node) {} 51 visitInvokeConstructor(InvokeConstructor node) {}
52 visitConcatenateStrings(ConcatenateStrings node) {} 52 visitConcatenateStrings(ConcatenateStrings node) {}
53 visitConstant(Constant node) {} 53 visitConstant(Constant node) {}
54 visitConditional(Conditional node) {} 54 visitConditional(Conditional node) {}
55 visitLogicalOperator(LogicalOperator node) {}
56 visitNot(Not node) {}
55 57
56 visitLabeledStatement(LabeledStatement node) { 58 visitLabeledStatement(LabeledStatement node) {
57 Block target = new Block(); 59 Block target = new Block();
58 breakTargets[node.label] = target; 60 breakTargets[node.label] = target;
59 visitStatement(node.body); 61 visitStatement(node.body);
60 _addBlock(target); 62 _addBlock(target);
61 visitStatement(node.next); 63 visitStatement(node.next);
62 } 64 }
63 65
64 visitAssign(Assign node) { 66 visitAssign(Assign node) {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 } 181 }
180 182
181 visitConcatenateStrings(ConcatenateStrings node) { 183 visitConcatenateStrings(ConcatenateStrings node) {
182 printStatement(null, expr(node)); 184 printStatement(null, expr(node));
183 } 185 }
184 186
185 visitConditional(Conditional node) { 187 visitConditional(Conditional node) {
186 printStatement(null, expr(node)); 188 printStatement(null, expr(node));
187 } 189 }
188 190
191 visitLogicalOperator(LogicalOperator node) {
192 printStatement(null, expr(node));
193 }
194
195 visitNot(Not node) {
196 printStatement(null, expr(node));
197 }
198
189 visitReturn(Return node) { 199 visitReturn(Return node) {
190 printStatement(null, "return ${expr(node.value)}"); 200 printStatement(null, "return ${expr(node.value)}");
191 } 201 }
192 202
193 visitBreak(Break node) { 203 visitBreak(Break node) {
194 printStatement(null, "break ${collector.breakTargets[node.target].name}"); 204 printStatement(null, "break ${collector.breakTargets[node.target].name}");
195 } 205 }
196 206
197 visitIf(If node) { 207 visitIf(If node) {
198 String condition = expr(node.condition); 208 String condition = expr(node.condition);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 269
260 String visitConcatenateStrings(ConcatenateStrings node) { 270 String visitConcatenateStrings(ConcatenateStrings node) {
261 String args = node.arguments.map(visitExpression).join(', '); 271 String args = node.arguments.map(visitExpression).join(', ');
262 return "concat [$args]"; 272 return "concat [$args]";
263 } 273 }
264 274
265 String visitConstant(Constant node) { 275 String visitConstant(Constant node) {
266 return "${node.value}"; 276 return "${node.value}";
267 } 277 }
268 278
279 bool usesInfixNotation(Expression node) {
280 return node is Conditional || node is LogicalOperator;
281 }
282
269 String visitConditional(Conditional node) { 283 String visitConditional(Conditional node) {
270 return visitExpression(node.condition) + ' ? ' + 284 String condition = visitExpression(node.condition);
271 visitExpression(node.thenExpression) + ' : ' + 285 String thenExpr = visitExpression(node.thenExpression);
272 visitExpression(node.elseExpression); 286 String elseExpr = visitExpression(node.elseExpression);
287 return "$condition ? $thenExpr : $elseExpr";
288 }
289
290 String visitLogicalOperator(LogicalOperator node) {
291 String left = visitExpression(node.left);
292 String right = visitExpression(node.right);
293 if (usesInfixNotation(node.left)) {
294 left = "($left)";
295 }
296 if (usesInfixNotation(node.right)) {
297 right = "($right)";
298 }
299 return "$left ${node.operator} $right";
300 }
301
302 String visitNot(Not node) {
303 String operand = visitExpression(node.operand);
304 if (usesInfixNotation(node.operand)) {
305 operand = '($operand)';
306 }
307 return '!$operand';
273 } 308 }
274 309
275 // Note: There should not be statements in the context of expressions. 310 // Note: There should not be statements in the context of expressions.
276 String visitStatement(Statement node) { 311 String visitStatement(Statement node) {
277 return "$node statement in expression context"; 312 return "$node statement in expression context";
278 } 313 }
279 314
280 String visitLabeledStatement(LabeledStatement node) => visitStatement(node); 315 String visitLabeledStatement(LabeledStatement node) => visitStatement(node);
281 String visitAssign(Assign node) => visitStatement(node); 316 String visitAssign(Assign node) => visitStatement(node);
282 String visitReturn(Return node) => visitStatement(node); 317 String visitReturn(Return node) => visitStatement(node);
(...skipping 25 matching lines...) Expand all
308 } 343 }
309 while (name == null || _usedNames.contains(name)) { 344 while (name == null || _usedNames.contains(name)) {
310 name = "v${_counter++}"; 345 name = "v${_counter++}";
311 } 346 }
312 _names[v] = name; 347 _names[v] = name;
313 _usedNames.add(name); 348 _usedNames.add(name);
314 } 349 }
315 return name; 350 return name;
316 } 351 }
317 } 352 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/dart_backend/dart_tree.dart ('k') | tests/language/if_flatten1_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698