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

Side by Side Diff: pkg/compiler/lib/src/js_backend/codegen/codegen.dart

Issue 1088493002: Assignment expressions in tree IR. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 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
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 code_generator; 5 library code_generator;
6 6
7 import 'glue.dart'; 7 import 'glue.dart';
8 8
9 import '../../tree_ir/tree_ir_nodes.dart' as tree_ir; 9 import '../../tree_ir/tree_ir_nodes.dart' as tree_ir;
10 import '../../js/js.dart' as js; 10 import '../../js/js.dart' as js;
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 @override 388 @override
389 js.Expression visitVariableUse(tree_ir.VariableUse node) { 389 js.Expression visitVariableUse(tree_ir.VariableUse node) {
390 return buildVariableAccess(node.variable); 390 return buildVariableAccess(node.variable);
391 } 391 }
392 392
393 js.Expression buildVariableAccess(tree_ir.Variable variable) { 393 js.Expression buildVariableAccess(tree_ir.Variable variable) {
394 return new js.VariableUse(getVariableName(variable)); 394 return new js.VariableUse(getVariableName(variable));
395 } 395 }
396 396
397 @override 397 @override
398 js.Expression visitAssign(tree_ir.Assign node) {
399 return new js.Assignment(
400 buildVariableAccess(node.variable),
401 visitExpression(node.value));
402 }
403
404 @override
398 void visitContinue(tree_ir.Continue node) { 405 void visitContinue(tree_ir.Continue node) {
399 tree_ir.Statement fallthrough = this.fallthrough; 406 tree_ir.Statement fallthrough = this.fallthrough;
400 if (node.target.binding == fallthrough) { 407 if (node.target.binding == fallthrough) {
401 // Fall through to continue target 408 // Fall through to continue target
402 } else if (fallthrough is tree_ir.Continue && 409 } else if (fallthrough is tree_ir.Continue &&
403 fallthrough.target == node.target) { 410 fallthrough.target == node.target) {
404 // Fall through to equivalent continue 411 // Fall through to equivalent continue
405 } else { 412 } else {
406 usedLabels.add(node.target); 413 usedLabels.add(node.target);
407 accumulator.add(new js.Continue(node.target.name)); 414 accumulator.add(new js.Continue(node.target.name));
(...skipping 29 matching lines...) Expand all
437 fallthrough = fallthroughStatement; 444 fallthrough = fallthroughStatement;
438 js.Statement result = buildBody(); 445 js.Statement result = buildBody();
439 if (usedLabels.remove(label)) { 446 if (usedLabels.remove(label)) {
440 result = new js.LabeledStatement(label.name, result); 447 result = new js.LabeledStatement(label.name, result);
441 } 448 }
442 fallthrough = savedFallthrough; 449 fallthrough = savedFallthrough;
443 return result; 450 return result;
444 } 451 }
445 452
446 @override 453 @override
447 void visitAssign(tree_ir.Assign node) {
448 tree_ir.Expression value = node.value;
449 js.Expression definition = visitExpression(value);
450
451 accumulator.add(new js.ExpressionStatement(new js.Assignment(
452 buildVariableAccess(node.variable),
453 definition)));
454 visitStatement(node.next);
455 }
456
457 @override
458 void visitBreak(tree_ir.Break node) { 454 void visitBreak(tree_ir.Break node) {
459 tree_ir.Statement fallthrough = this.fallthrough; 455 tree_ir.Statement fallthrough = this.fallthrough;
460 if (node.target.binding.next == fallthrough) { 456 if (node.target.binding.next == fallthrough) {
461 // Fall through to break target 457 // Fall through to break target
462 } else if (fallthrough is tree_ir.Break && 458 } else if (fallthrough is tree_ir.Break &&
463 fallthrough.target == node.target) { 459 fallthrough.target == node.target) {
464 // Fall through to equivalent break 460 // Fall through to equivalent break
465 } else { 461 } else {
466 usedLabels.add(node.target); 462 usedLabels.add(node.target);
467 accumulator.add(new js.Break(node.target.name)); 463 accumulator.add(new js.Break(node.target.name));
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 } 549 }
554 550
555 @override 551 @override
556 js.Expression visitGetField(tree_ir.GetField node) { 552 js.Expression visitGetField(tree_ir.GetField node) {
557 return new js.PropertyAccess.field( 553 return new js.PropertyAccess.field(
558 visitExpression(node.object), 554 visitExpression(node.object),
559 glue.instanceFieldPropertyName(node.field)); 555 glue.instanceFieldPropertyName(node.field));
560 } 556 }
561 557
562 @override 558 @override
563 void visitSetField(tree_ir.SetField node) { 559 js.Assignment visitSetField(tree_ir.SetField node) {
564 js.PropertyAccess field = 560 js.PropertyAccess field =
565 new js.PropertyAccess.field( 561 new js.PropertyAccess.field(
566 visitExpression(node.object), 562 visitExpression(node.object),
567 glue.instanceFieldPropertyName(node.field)); 563 glue.instanceFieldPropertyName(node.field));
568 js.Assignment asn = new js.Assignment(field, visitExpression(node.value)); 564 return new js.Assignment(field, visitExpression(node.value));
569 accumulator.add(new js.ExpressionStatement(asn));
570 visitStatement(node.next);
571 } 565 }
572 566
573 js.Expression buildStaticHelperInvocation(FunctionElement helper, 567 js.Expression buildStaticHelperInvocation(FunctionElement helper,
574 List<js.Expression> arguments) { 568 List<js.Expression> arguments) {
575 registry.registerStaticUse(helper); 569 registry.registerStaticUse(helper);
576 return buildStaticInvoke(new Selector.fromElement(helper), helper, 570 return buildStaticInvoke(new Selector.fromElement(helper), helper,
577 arguments); 571 arguments);
578 } 572 }
579 573
580 @override 574 @override
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 @override 613 @override
620 visitFunctionExpression(tree_ir.FunctionExpression node) { 614 visitFunctionExpression(tree_ir.FunctionExpression node) {
621 return errorUnsupportedNode(node); 615 return errorUnsupportedNode(node);
622 } 616 }
623 617
624 @override 618 @override
625 visitFunctionDeclaration(tree_ir.FunctionDeclaration node) { 619 visitFunctionDeclaration(tree_ir.FunctionDeclaration node) {
626 return errorUnsupportedNode(node); 620 return errorUnsupportedNode(node);
627 } 621 }
628 622
623 @override
624 visitVariableDeclaration(tree_ir.VariableDeclaration node) {
625 return errorUnsupportedNode(node);
626 }
627
629 errorUnsupportedNode(tree_ir.DartSpecificNode node) { 628 errorUnsupportedNode(tree_ir.DartSpecificNode node) {
630 throw "Unsupported node in JS backend: $node"; 629 throw "Unsupported node in JS backend: $node";
631 } 630 }
632 } 631 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698