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

Side by Side Diff: dart/lib/compiler/implementation/js/nodes.dart

Issue 10876008: Remove most superfluous getter arguments from dart2js. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 4 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 interface NodeVisitor<T> { 5 interface NodeVisitor<T> {
6 T visitProgram(Program node); 6 T visitProgram(Program node);
7 7
8 T visitBlock(Block node); 8 T visitBlock(Block node);
9 T visitExpressionStatement(ExpressionStatement node); 9 T visitExpressionStatement(ExpressionStatement node);
10 T visitEmptyStatement(EmptyStatement node); 10 T visitEmptyStatement(EmptyStatement node);
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 } 189 }
190 190
191 class If extends Statement { 191 class If extends Statement {
192 final Expression condition; 192 final Expression condition;
193 final Node then; 193 final Node then;
194 final Node otherwise; 194 final Node otherwise;
195 195
196 If(this.condition, this.then, this.otherwise); 196 If(this.condition, this.then, this.otherwise);
197 If.then(this.condition, this.then) : this.otherwise = new EmptyStatement(); 197 If.then(this.condition, this.then) : this.otherwise = new EmptyStatement();
198 198
199 bool get hasElse() => otherwise is !EmptyStatement; 199 bool get hasElse => otherwise is !EmptyStatement;
200 200
201 accept(NodeVisitor visitor) => visitor.visitIf(this); 201 accept(NodeVisitor visitor) => visitor.visitIf(this);
202 202
203 void visitChildren(NodeVisitor visitor) { 203 void visitChildren(NodeVisitor visitor) {
204 condition.accept(visitor); 204 condition.accept(visitor);
205 then.accept(visitor); 205 then.accept(visitor);
206 otherwise.accept(visitor); 206 otherwise.accept(visitor);
207 } 207 }
208 } 208 }
209 209
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 LiteralExpression.withData(this.template, this.inputs); 437 LiteralExpression.withData(this.template, this.inputs);
438 438
439 accept(NodeVisitor visitor) => visitor.visitLiteralExpression(this); 439 accept(NodeVisitor visitor) => visitor.visitLiteralExpression(this);
440 440
441 void visitChildren(NodeVisitor visitor) { 441 void visitChildren(NodeVisitor visitor) {
442 for (Expression expr in inputs) expr.accept(visitor); 442 for (Expression expr in inputs) expr.accept(visitor);
443 } 443 }
444 444
445 // Code that uses JS must take care of operator precedences, and 445 // Code that uses JS must take care of operator precedences, and
446 // put parenthesis if needed. 446 // put parenthesis if needed.
447 int get precedenceLevel() => PRIMARY; 447 int get precedenceLevel => PRIMARY;
448 } 448 }
449 449
450 /** 450 /**
451 * [VariableDeclarationList] is a subclass of [Expression] to simplify the 451 * [VariableDeclarationList] is a subclass of [Expression] to simplify the
452 * AST. 452 * AST.
453 */ 453 */
454 class VariableDeclarationList extends Expression { 454 class VariableDeclarationList extends Expression {
455 final List<VariableInitialization> declarations; 455 final List<VariableInitialization> declarations;
456 456
457 VariableDeclarationList(this.declarations); 457 VariableDeclarationList(this.declarations);
458 458
459 accept(NodeVisitor visitor) => visitor.visitVariableDeclarationList(this); 459 accept(NodeVisitor visitor) => visitor.visitVariableDeclarationList(this);
460 460
461 void visitChildren(NodeVisitor visitor) { 461 void visitChildren(NodeVisitor visitor) {
462 for (VariableInitialization declaration in declarations) { 462 for (VariableInitialization declaration in declarations) {
463 declaration.accept(visitor); 463 declaration.accept(visitor);
464 } 464 }
465 } 465 }
466 466
467 int get precedenceLevel() => EXPRESSION; 467 int get precedenceLevel => EXPRESSION;
468 } 468 }
469 469
470 class Sequence extends Expression { 470 class Sequence extends Expression {
471 final List<Expression> expressions; 471 final List<Expression> expressions;
472 472
473 Sequence(this.expressions); 473 Sequence(this.expressions);
474 474
475 accept(NodeVisitor visitor) => visitor.visitSequence(this); 475 accept(NodeVisitor visitor) => visitor.visitSequence(this);
476 476
477 void visitChildren(NodeVisitor visitor) { 477 void visitChildren(NodeVisitor visitor) {
478 for (Expression expr in expressions) expr.accept(visitor); 478 for (Expression expr in expressions) expr.accept(visitor);
479 } 479 }
480 480
481 int get precedenceLevel() => EXPRESSION; 481 int get precedenceLevel => EXPRESSION;
482 } 482 }
483 483
484 class Assignment extends Expression { 484 class Assignment extends Expression {
485 final Expression leftHandSide; 485 final Expression leftHandSide;
486 // Null, if the assignment is not compound. 486 // Null, if the assignment is not compound.
487 final VariableReference compoundTarget; 487 final VariableReference compoundTarget;
488 final Expression value; // May be null, for [VariableInitialization]s. 488 final Expression value; // May be null, for [VariableInitialization]s.
489 489
490 Assignment(this.leftHandSide, this.value) : compoundTarget = null; 490 Assignment(this.leftHandSide, this.value) : compoundTarget = null;
491 Assignment.compound(this.leftHandSide, String op, this.value) 491 Assignment.compound(this.leftHandSide, String op, this.value)
492 : compoundTarget = new VariableUse(op); 492 : compoundTarget = new VariableUse(op);
493 493
494 int get precedenceLevel() => ASSIGNMENT; 494 int get precedenceLevel => ASSIGNMENT;
495 495
496 bool get isCompound() => compoundTarget != null; 496 bool get isCompound => compoundTarget != null;
497 String get op() => compoundTarget == null ? null : compoundTarget.name; 497 String get op => compoundTarget == null ? null : compoundTarget.name;
498 498
499 accept(NodeVisitor visitor) => visitor.visitAssignment(this); 499 accept(NodeVisitor visitor) => visitor.visitAssignment(this);
500 500
501 void visitChildren(NodeVisitor visitor) { 501 void visitChildren(NodeVisitor visitor) {
502 leftHandSide.accept(visitor); 502 leftHandSide.accept(visitor);
503 if (compoundTarget != null) compoundTarget.accept(visitor); 503 if (compoundTarget != null) compoundTarget.accept(visitor);
504 if (value != null) value.accept(visitor); 504 if (value != null) value.accept(visitor);
505 } 505 }
506 } 506 }
507 507
508 class VariableInitialization extends Assignment { 508 class VariableInitialization extends Assignment {
509 /** [value] may be null. */ 509 /** [value] may be null. */
510 VariableInitialization(VariableDeclaration declaration, Expression value) 510 VariableInitialization(VariableDeclaration declaration, Expression value)
511 : super(declaration, value); 511 : super(declaration, value);
512 512
513 VariableDeclaration get declaration() => leftHandSide; 513 VariableDeclaration get declaration => leftHandSide;
514 514
515 accept(NodeVisitor visitor) => visitor.visitVariableInitialization(this); 515 accept(NodeVisitor visitor) => visitor.visitVariableInitialization(this);
516 } 516 }
517 517
518 class Conditional extends Expression { 518 class Conditional extends Expression {
519 final Expression condition; 519 final Expression condition;
520 final Expression then; 520 final Expression then;
521 final Expression otherwise; 521 final Expression otherwise;
522 522
523 Conditional(this.condition, this.then, this.otherwise); 523 Conditional(this.condition, this.then, this.otherwise);
524 524
525 accept(NodeVisitor visitor) => visitor.visitConditional(this); 525 accept(NodeVisitor visitor) => visitor.visitConditional(this);
526 526
527 void visitChildren(NodeVisitor visitor) { 527 void visitChildren(NodeVisitor visitor) {
528 condition.accept(visitor); 528 condition.accept(visitor);
529 then.accept(visitor); 529 then.accept(visitor);
530 otherwise.accept(visitor); 530 otherwise.accept(visitor);
531 } 531 }
532 532
533 int get precedenceLevel() => ASSIGNMENT; 533 int get precedenceLevel => ASSIGNMENT;
534 } 534 }
535 535
536 class Call extends Expression { 536 class Call extends Expression {
537 Expression target; 537 Expression target;
538 List<Expression> arguments; 538 List<Expression> arguments;
539 539
540 Call(this.target, this.arguments); 540 Call(this.target, this.arguments);
541 541
542 accept(NodeVisitor visitor) => visitor.visitCall(this); 542 accept(NodeVisitor visitor) => visitor.visitCall(this);
543 543
544 void visitChildren(NodeVisitor visitor) { 544 void visitChildren(NodeVisitor visitor) {
545 target.accept(visitor); 545 target.accept(visitor);
546 for (Expression arg in arguments) arg.accept(visitor); 546 for (Expression arg in arguments) arg.accept(visitor);
547 } 547 }
548 548
549 int get precedenceLevel() => CALL; 549 int get precedenceLevel => CALL;
550 } 550 }
551 551
552 class New extends Call { 552 class New extends Call {
553 New(Expression cls, List<Expression> arguments) : super(cls, arguments); 553 New(Expression cls, List<Expression> arguments) : super(cls, arguments);
554 554
555 accept(NodeVisitor visitor) => visitor.visitNew(this); 555 accept(NodeVisitor visitor) => visitor.visitNew(this);
556 } 556 }
557 557
558 class Binary extends Call { 558 class Binary extends Call {
559 Binary(String op, Expression left, Expression right) 559 Binary(String op, Expression left, Expression right)
560 : super(new VariableUse(op), <Expression>[left, right]); 560 : super(new VariableUse(op), <Expression>[left, right]);
561 561
562 String get op() { 562 String get op {
563 VariableUse use = target; 563 VariableUse use = target;
564 return use.name; 564 return use.name;
565 } 565 }
566 566
567 Expression get left() => arguments[0]; 567 Expression get left => arguments[0];
568 Expression get right() => arguments[1]; 568 Expression get right => arguments[1];
569 569
570 accept(NodeVisitor visitor) => visitor.visitBinary(this); 570 accept(NodeVisitor visitor) => visitor.visitBinary(this);
571 571
572 int get precedenceLevel() { 572 int get precedenceLevel {
573 // TODO(floitsch): switch to constant map. 573 // TODO(floitsch): switch to constant map.
574 switch (op) { 574 switch (op) {
575 case "*": 575 case "*":
576 case "/": 576 case "/":
577 case "%": 577 case "%":
578 return MULTIPLICATIVE; 578 return MULTIPLICATIVE;
579 case "+": 579 case "+":
580 case "-": 580 case "-":
581 return ADDITIVE; 581 return ADDITIVE;
582 case "<<": 582 case "<<":
(...skipping 26 matching lines...) Expand all
609 throw new leg.CompilerCancelledException( 609 throw new leg.CompilerCancelledException(
610 "Internal Error: Unhandled binary operator: $op"); 610 "Internal Error: Unhandled binary operator: $op");
611 } 611 }
612 } 612 }
613 } 613 }
614 614
615 class Prefix extends Call { 615 class Prefix extends Call {
616 Prefix(String op, Expression arg) 616 Prefix(String op, Expression arg)
617 : super(new VariableUse(op), <Expression>[arg]); 617 : super(new VariableUse(op), <Expression>[arg]);
618 618
619 String get op() => (target as VariableUse).name; 619 String get op => (target as VariableUse).name;
620 Expression get argument() => arguments[0]; 620 Expression get argument => arguments[0];
621 621
622 accept(NodeVisitor visitor) => visitor.visitPrefix(this); 622 accept(NodeVisitor visitor) => visitor.visitPrefix(this);
623 623
624 int get precedenceLevel() => UNARY; 624 int get precedenceLevel => UNARY;
625 } 625 }
626 626
627 class Postfix extends Call { 627 class Postfix extends Call {
628 Postfix(String op, Expression arg) 628 Postfix(String op, Expression arg)
629 : super(new VariableUse(op), <Expression>[arg]); 629 : super(new VariableUse(op), <Expression>[arg]);
630 630
631 String get op() => (target as VariableUse).name; 631 String get op => (target as VariableUse).name;
632 Expression get argument() => arguments[0]; 632 Expression get argument => arguments[0];
633 633
634 accept(NodeVisitor visitor) => visitor.visitPostfix(this); 634 accept(NodeVisitor visitor) => visitor.visitPostfix(this);
635 635
636 int get precedenceLevel() => UNARY; 636 int get precedenceLevel => UNARY;
637 } 637 }
638 638
639 abstract class VariableReference extends Expression { 639 abstract class VariableReference extends Expression {
640 final String name; 640 final String name;
641 641
642 // We treat operators as if they were special functions. They can thus be 642 // We treat operators as if they were special functions. They can thus be
643 // referenced like other variables. 643 // referenced like other variables.
644 VariableReference(this.name); 644 VariableReference(this.name);
645 645
646 abstract accept(NodeVisitor visitor); 646 abstract accept(NodeVisitor visitor);
647 int get precedenceLevel() => PRIMARY; 647 int get precedenceLevel => PRIMARY;
648 void visitChildren(NodeVisitor visitor) {} 648 void visitChildren(NodeVisitor visitor) {}
649 } 649 }
650 650
651 class VariableUse extends VariableReference { 651 class VariableUse extends VariableReference {
652 VariableUse(String name) : super(name); 652 VariableUse(String name) : super(name);
653 653
654 accept(NodeVisitor visitor) => visitor.visitVariableUse(this); 654 accept(NodeVisitor visitor) => visitor.visitVariableUse(this);
655 } 655 }
656 656
657 class VariableDeclaration extends VariableReference { 657 class VariableDeclaration extends VariableReference {
(...skipping 20 matching lines...) Expand all
678 678
679 NamedFunction(this.name, this.function); 679 NamedFunction(this.name, this.function);
680 680
681 accept(NodeVisitor visitor) => visitor.visitNamedFunction(this); 681 accept(NodeVisitor visitor) => visitor.visitNamedFunction(this);
682 682
683 void visitChildren(NodeVisitor visitor) { 683 void visitChildren(NodeVisitor visitor) {
684 name.accept(visitor); 684 name.accept(visitor);
685 function.accept(visitor); 685 function.accept(visitor);
686 } 686 }
687 687
688 int get precedenceLevel() => CALL; 688 int get precedenceLevel => CALL;
689 } 689 }
690 690
691 class Fun extends Expression { 691 class Fun extends Expression {
692 final List<Parameter> params; 692 final List<Parameter> params;
693 final Block body; 693 final Block body;
694 694
695 Fun(this.params, this.body); 695 Fun(this.params, this.body);
696 696
697 accept(NodeVisitor visitor) => visitor.visitFun(this); 697 accept(NodeVisitor visitor) => visitor.visitFun(this);
698 698
699 void visitChildren(NodeVisitor visitor) { 699 void visitChildren(NodeVisitor visitor) {
700 for (Parameter param in params) param.accept(visitor); 700 for (Parameter param in params) param.accept(visitor);
701 body.accept(visitor); 701 body.accept(visitor);
702 } 702 }
703 703
704 int get precedenceLevel() => CALL; 704 int get precedenceLevel => CALL;
705 } 705 }
706 706
707 class PropertyAccess extends Expression { 707 class PropertyAccess extends Expression {
708 final Expression receiver; 708 final Expression receiver;
709 final Expression selector; 709 final Expression selector;
710 710
711 PropertyAccess(this.receiver, this.selector); 711 PropertyAccess(this.receiver, this.selector);
712 PropertyAccess.field(this.receiver, String fieldName) 712 PropertyAccess.field(this.receiver, String fieldName)
713 : selector = new LiteralString("'$fieldName'"); 713 : selector = new LiteralString("'$fieldName'");
714 714
715 accept(NodeVisitor visitor) => visitor.visitAccess(this); 715 accept(NodeVisitor visitor) => visitor.visitAccess(this);
716 716
717 void visitChildren(NodeVisitor visitor) { 717 void visitChildren(NodeVisitor visitor) {
718 receiver.accept(visitor); 718 receiver.accept(visitor);
719 selector.accept(visitor); 719 selector.accept(visitor);
720 } 720 }
721 721
722 int get precedenceLevel() => CALL; 722 int get precedenceLevel => CALL;
723 } 723 }
724 724
725 abstract class Literal extends Expression { 725 abstract class Literal extends Expression {
726 void visitChildren(NodeVisitor visitor) {} 726 void visitChildren(NodeVisitor visitor) {}
727 727
728 int get precedenceLevel() => PRIMARY; 728 int get precedenceLevel => PRIMARY;
729 } 729 }
730 730
731 class LiteralBool extends Literal { 731 class LiteralBool extends Literal {
732 final bool value; 732 final bool value;
733 733
734 LiteralBool(this.value); 734 LiteralBool(this.value);
735 735
736 accept(NodeVisitor visitor) => visitor.visitLiteralBool(this); 736 accept(NodeVisitor visitor) => visitor.visitLiteralBool(this);
737 // [visitChildren] inherited from [Literal]. 737 // [visitChildren] inherited from [Literal].
738 } 738 }
(...skipping 27 matching lines...) Expand all
766 final List<ArrayElement> elements; 766 final List<ArrayElement> elements;
767 767
768 ArrayInitializer(this.length, this.elements); 768 ArrayInitializer(this.length, this.elements);
769 769
770 accept(NodeVisitor visitor) => visitor.visitArrayInitializer(this); 770 accept(NodeVisitor visitor) => visitor.visitArrayInitializer(this);
771 771
772 void visitChildren(NodeVisitor visitor) { 772 void visitChildren(NodeVisitor visitor) {
773 for (ArrayElement element in elements) element.accept(visitor); 773 for (ArrayElement element in elements) element.accept(visitor);
774 } 774 }
775 775
776 int get precedenceLevel() => PRIMARY; 776 int get precedenceLevel => PRIMARY;
777 } 777 }
778 778
779 /** 779 /**
780 * An expression inside an [ArrayInitialization]. An [ArrayElement] knows 780 * An expression inside an [ArrayInitialization]. An [ArrayElement] knows
781 * its position in the containing [ArrayInitialization]. 781 * its position in the containing [ArrayInitialization].
782 */ 782 */
783 class ArrayElement extends Node { 783 class ArrayElement extends Node {
784 int index; 784 int index;
785 Expression value; 785 Expression value;
786 786
(...skipping 10 matching lines...) Expand all
797 List<Property> properties; 797 List<Property> properties;
798 798
799 ObjectInitializer(this.properties); 799 ObjectInitializer(this.properties);
800 800
801 accept(NodeVisitor visitor) => visitor.visitObjectInitializer(this); 801 accept(NodeVisitor visitor) => visitor.visitObjectInitializer(this);
802 802
803 void visitChildren(NodeVisitor visitor) { 803 void visitChildren(NodeVisitor visitor) {
804 for (Property init in properties) init.accept(visitor); 804 for (Property init in properties) init.accept(visitor);
805 } 805 }
806 806
807 int get precedenceLevel() => PRIMARY; 807 int get precedenceLevel => PRIMARY;
808 } 808 }
809 809
810 class Property extends Node { 810 class Property extends Node {
811 Literal name; 811 Literal name;
812 Expression value; 812 Expression value;
813 813
814 Property(this.name, this.value); 814 Property(this.name, this.value);
815 815
816 accept(NodeVisitor visitor) => visitor.visitProperty(this); 816 accept(NodeVisitor visitor) => visitor.visitProperty(this);
817 817
(...skipping 10 matching lines...) Expand all
828 */ 828 */
829 class RegExpLiteral extends Expression { 829 class RegExpLiteral extends Expression {
830 /** Contains the pattern and the flags.*/ 830 /** Contains the pattern and the flags.*/
831 String pattern; 831 String pattern;
832 832
833 RegExpLiteral(this.pattern); 833 RegExpLiteral(this.pattern);
834 834
835 accept(NodeVisitor visitor) => visitor.visitRegExpLiteral(this); 835 accept(NodeVisitor visitor) => visitor.visitRegExpLiteral(this);
836 void visitChildren(NodeVisitor visitor) {} 836 void visitChildren(NodeVisitor visitor) {}
837 837
838 int get precedenceLevel() => PRIMARY; 838 int get precedenceLevel => PRIMARY;
839 } 839 }
OLDNEW
« no previous file with comments | « dart/lib/compiler/implementation/enqueue.dart ('k') | dart/lib/compiler/implementation/js/printer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698