| OLD | NEW |
| 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 part of js_ast; | 5 part of js_ast; |
| 6 | 6 |
| 7 abstract class NodeVisitor<T> { | 7 abstract class NodeVisitor<T> { |
| 8 T visitProgram(Program node); | 8 T visitProgram(Program node); |
| 9 | 9 |
| 10 T visitBlock(Block node); | 10 T visitBlock(Block node); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 | 62 |
| 63 T visitAwait(Await node); | 63 T visitAwait(Await node); |
| 64 | 64 |
| 65 T visitComment(Comment node); | 65 T visitComment(Comment node); |
| 66 | 66 |
| 67 T visitInterpolatedExpression(InterpolatedExpression node); | 67 T visitInterpolatedExpression(InterpolatedExpression node); |
| 68 T visitInterpolatedLiteral(InterpolatedLiteral node); | 68 T visitInterpolatedLiteral(InterpolatedLiteral node); |
| 69 T visitInterpolatedParameter(InterpolatedParameter node); | 69 T visitInterpolatedParameter(InterpolatedParameter node); |
| 70 T visitInterpolatedSelector(InterpolatedSelector node); | 70 T visitInterpolatedSelector(InterpolatedSelector node); |
| 71 T visitInterpolatedStatement(InterpolatedStatement node); | 71 T visitInterpolatedStatement(InterpolatedStatement node); |
| 72 T visitInterpolatedDeclaration(InterpolatedDeclaration node); |
| 72 } | 73 } |
| 73 | 74 |
| 74 class BaseVisitor<T> implements NodeVisitor<T> { | 75 class BaseVisitor<T> implements NodeVisitor<T> { |
| 75 T visitNode(Node node) { | 76 T visitNode(Node node) { |
| 76 node.visitChildren(this); | 77 node.visitChildren(this); |
| 77 return null; | 78 return null; |
| 78 } | 79 } |
| 79 | 80 |
| 80 T visitProgram(Program node) => visitNode(node); | 81 T visitProgram(Program node) => visitNode(node); |
| 81 | 82 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 T visitInterpolatedExpression(InterpolatedExpression node) | 157 T visitInterpolatedExpression(InterpolatedExpression node) |
| 157 => visitInterpolatedNode(node); | 158 => visitInterpolatedNode(node); |
| 158 T visitInterpolatedLiteral(InterpolatedLiteral node) | 159 T visitInterpolatedLiteral(InterpolatedLiteral node) |
| 159 => visitInterpolatedNode(node); | 160 => visitInterpolatedNode(node); |
| 160 T visitInterpolatedParameter(InterpolatedParameter node) | 161 T visitInterpolatedParameter(InterpolatedParameter node) |
| 161 => visitInterpolatedNode(node); | 162 => visitInterpolatedNode(node); |
| 162 T visitInterpolatedSelector(InterpolatedSelector node) | 163 T visitInterpolatedSelector(InterpolatedSelector node) |
| 163 => visitInterpolatedNode(node); | 164 => visitInterpolatedNode(node); |
| 164 T visitInterpolatedStatement(InterpolatedStatement node) | 165 T visitInterpolatedStatement(InterpolatedStatement node) |
| 165 => visitInterpolatedNode(node); | 166 => visitInterpolatedNode(node); |
| 167 T visitInterpolatedDeclaration(InterpolatedDeclaration node) { |
| 168 return visitInterpolatedNode(node); |
| 169 } |
| 166 | 170 |
| 167 // Ignore comments by default. | 171 // Ignore comments by default. |
| 168 T visitComment(Comment node) => null; | 172 T visitComment(Comment node) => null; |
| 169 | 173 |
| 170 T visitAwait(Await node) => visitExpression(node); | 174 T visitAwait(Await node) => visitExpression(node); |
| 171 T visitDartYield(DartYield node) => visitStatement(node); | 175 T visitDartYield(DartYield node) => visitStatement(node); |
| 172 } | 176 } |
| 173 | 177 |
| 174 /// This tag interface has no behaviour but must be implemented by any class | 178 /// This tag interface has no behaviour but must be implemented by any class |
| 175 /// that is to be stored on a [Node] as source information. | 179 /// that is to be stored on a [Node] as source information. |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 void visitChildren(NodeVisitor visitor) { | 416 void visitChildren(NodeVisitor visitor) { |
| 413 body.accept(visitor); | 417 body.accept(visitor); |
| 414 if (catchPart != null) catchPart.accept(visitor); | 418 if (catchPart != null) catchPart.accept(visitor); |
| 415 if (finallyPart != null) finallyPart.accept(visitor); | 419 if (finallyPart != null) finallyPart.accept(visitor); |
| 416 } | 420 } |
| 417 | 421 |
| 418 Try _clone() => new Try(body, catchPart, finallyPart); | 422 Try _clone() => new Try(body, catchPart, finallyPart); |
| 419 } | 423 } |
| 420 | 424 |
| 421 class Catch extends Node { | 425 class Catch extends Node { |
| 422 final VariableDeclaration declaration; | 426 final Declaration declaration; |
| 423 final Block body; | 427 final Block body; |
| 424 | 428 |
| 425 Catch(this.declaration, this.body); | 429 Catch(this.declaration, this.body); |
| 426 | 430 |
| 427 accept(NodeVisitor visitor) => visitor.visitCatch(this); | 431 accept(NodeVisitor visitor) => visitor.visitCatch(this); |
| 428 | 432 |
| 429 void visitChildren(NodeVisitor visitor) { | 433 void visitChildren(NodeVisitor visitor) { |
| 430 declaration.accept(visitor); | 434 declaration.accept(visitor); |
| 431 body.accept(visitor); | 435 body.accept(visitor); |
| 432 } | 436 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 accept(NodeVisitor visitor) => visitor.visitDefault(this); | 481 accept(NodeVisitor visitor) => visitor.visitDefault(this); |
| 478 | 482 |
| 479 void visitChildren(NodeVisitor visitor) { | 483 void visitChildren(NodeVisitor visitor) { |
| 480 body.accept(visitor); | 484 body.accept(visitor); |
| 481 } | 485 } |
| 482 | 486 |
| 483 Default _clone() => new Default(body); | 487 Default _clone() => new Default(body); |
| 484 } | 488 } |
| 485 | 489 |
| 486 class FunctionDeclaration extends Statement { | 490 class FunctionDeclaration extends Statement { |
| 487 final VariableDeclaration name; | 491 final Declaration name; |
| 488 final Fun function; | 492 final Fun function; |
| 489 | 493 |
| 490 FunctionDeclaration(this.name, this.function); | 494 FunctionDeclaration(this.name, this.function); |
| 491 | 495 |
| 492 accept(NodeVisitor visitor) => visitor.visitFunctionDeclaration(this); | 496 accept(NodeVisitor visitor) => visitor.visitFunctionDeclaration(this); |
| 493 | 497 |
| 494 void visitChildren(NodeVisitor visitor) { | 498 void visitChildren(NodeVisitor visitor) { |
| 495 name.accept(visitor); | 499 name.accept(visitor); |
| 496 function.accept(visitor); | 500 function.accept(visitor); |
| 497 } | 501 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 | 546 |
| 543 DartYield _clone() => new DartYield(expression, hasStar); | 547 DartYield _clone() => new DartYield(expression, hasStar); |
| 544 } | 548 } |
| 545 | 549 |
| 546 abstract class Expression extends Node { | 550 abstract class Expression extends Node { |
| 547 int get precedenceLevel; | 551 int get precedenceLevel; |
| 548 | 552 |
| 549 Statement toStatement() => new ExpressionStatement(this); | 553 Statement toStatement() => new ExpressionStatement(this); |
| 550 } | 554 } |
| 551 | 555 |
| 556 abstract class Declaration implements VariableReference { |
| 557 |
| 558 } |
| 559 |
| 552 class LiteralExpression extends Expression { | 560 class LiteralExpression extends Expression { |
| 553 final String template; | 561 final String template; |
| 554 final List<Expression> inputs; | 562 final List<Expression> inputs; |
| 555 | 563 |
| 556 LiteralExpression(this.template) : inputs = const []; | 564 LiteralExpression(this.template) : inputs = const []; |
| 557 LiteralExpression.withData(this.template, this.inputs); | 565 LiteralExpression.withData(this.template, this.inputs); |
| 558 | 566 |
| 559 accept(NodeVisitor visitor) => visitor.visitLiteralExpression(this); | 567 accept(NodeVisitor visitor) => visitor.visitLiteralExpression(this); |
| 560 | 568 |
| 561 void visitChildren(NodeVisitor visitor) { | 569 void visitChildren(NodeVisitor visitor) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 leftHandSide.accept(visitor); | 621 leftHandSide.accept(visitor); |
| 614 if (value != null) value.accept(visitor); | 622 if (value != null) value.accept(visitor); |
| 615 } | 623 } |
| 616 | 624 |
| 617 Assignment _clone() => | 625 Assignment _clone() => |
| 618 new Assignment.compound(leftHandSide, op, value); | 626 new Assignment.compound(leftHandSide, op, value); |
| 619 } | 627 } |
| 620 | 628 |
| 621 class VariableInitialization extends Assignment { | 629 class VariableInitialization extends Assignment { |
| 622 /** [value] may be null. */ | 630 /** [value] may be null. */ |
| 623 VariableInitialization(VariableDeclaration declaration, Expression value) | 631 VariableInitialization(Declaration declaration, Expression value) |
| 624 : super(declaration, value); | 632 : super(declaration, value); |
| 625 | 633 |
| 626 VariableDeclaration get declaration => leftHandSide; | 634 Declaration get declaration => leftHandSide; |
| 627 | 635 |
| 628 accept(NodeVisitor visitor) => visitor.visitVariableInitialization(this); | 636 accept(NodeVisitor visitor) => visitor.visitVariableInitialization(this); |
| 629 | 637 |
| 630 VariableInitialization _clone() => | 638 VariableInitialization _clone() => |
| 631 new VariableInitialization(declaration, value); | 639 new VariableInitialization(declaration, value); |
| 632 } | 640 } |
| 633 | 641 |
| 634 class Conditional extends Expression { | 642 class Conditional extends Expression { |
| 635 final Expression condition; | 643 final Expression condition; |
| 636 final Expression then; | 644 final Expression then; |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 791 VariableUse(String name) : super(name); | 799 VariableUse(String name) : super(name); |
| 792 | 800 |
| 793 accept(NodeVisitor visitor) => visitor.visitVariableUse(this); | 801 accept(NodeVisitor visitor) => visitor.visitVariableUse(this); |
| 794 VariableUse _clone() => new VariableUse(name); | 802 VariableUse _clone() => new VariableUse(name); |
| 795 | 803 |
| 796 VariableUse asVariableUse() => this; | 804 VariableUse asVariableUse() => this; |
| 797 | 805 |
| 798 toString() => 'VariableUse($name)'; | 806 toString() => 'VariableUse($name)'; |
| 799 } | 807 } |
| 800 | 808 |
| 801 class VariableDeclaration extends VariableReference { | 809 class VariableDeclaration extends VariableReference implements Declaration { |
| 802 final bool allowRename; | 810 final bool allowRename; |
| 803 VariableDeclaration(String name, {this.allowRename: true}) : super(name); | 811 VariableDeclaration(String name, {this.allowRename: true}) : super(name); |
| 804 | 812 |
| 805 accept(NodeVisitor visitor) => visitor.visitVariableDeclaration(this); | 813 accept(NodeVisitor visitor) => visitor.visitVariableDeclaration(this); |
| 806 VariableDeclaration _clone() => new VariableDeclaration(name); | 814 VariableDeclaration _clone() => new VariableDeclaration(name); |
| 807 } | 815 } |
| 808 | 816 |
| 809 class Parameter extends VariableDeclaration { | 817 class Parameter extends VariableDeclaration { |
| 810 Parameter(String name) : super(name); | 818 Parameter(String name) : super(name); |
| 811 | 819 |
| 812 accept(NodeVisitor visitor) => visitor.visitParameter(this); | 820 accept(NodeVisitor visitor) => visitor.visitParameter(this); |
| 813 Parameter _clone() => new Parameter(name); | 821 Parameter _clone() => new Parameter(name); |
| 814 } | 822 } |
| 815 | 823 |
| 816 class This extends Parameter { | 824 class This extends Parameter { |
| 817 This() : super("this"); | 825 This() : super("this"); |
| 818 | 826 |
| 819 accept(NodeVisitor visitor) => visitor.visitThis(this); | 827 accept(NodeVisitor visitor) => visitor.visitThis(this); |
| 820 This _clone() => new This(); | 828 This _clone() => new This(); |
| 821 } | 829 } |
| 822 | 830 |
| 823 class NamedFunction extends Expression { | 831 class NamedFunction extends Expression { |
| 824 final VariableDeclaration name; | 832 final Declaration name; |
| 825 final Fun function; | 833 final Fun function; |
| 826 | 834 |
| 827 NamedFunction(this.name, this.function); | 835 NamedFunction(this.name, this.function); |
| 828 | 836 |
| 829 accept(NodeVisitor visitor) => visitor.visitNamedFunction(this); | 837 accept(NodeVisitor visitor) => visitor.visitNamedFunction(this); |
| 830 | 838 |
| 831 void visitChildren(NodeVisitor visitor) { | 839 void visitChildren(NodeVisitor visitor) { |
| 832 name.accept(visitor); | 840 name.accept(visitor); |
| 833 function.accept(visitor); | 841 function.accept(visitor); |
| 834 } | 842 } |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1086 class InterpolatedStatement extends Statement with InterpolatedNode { | 1094 class InterpolatedStatement extends Statement with InterpolatedNode { |
| 1087 final nameOrPosition; | 1095 final nameOrPosition; |
| 1088 | 1096 |
| 1089 InterpolatedStatement(this.nameOrPosition); | 1097 InterpolatedStatement(this.nameOrPosition); |
| 1090 | 1098 |
| 1091 accept(NodeVisitor visitor) => visitor.visitInterpolatedStatement(this); | 1099 accept(NodeVisitor visitor) => visitor.visitInterpolatedStatement(this); |
| 1092 void visitChildren(NodeVisitor visitor) {} | 1100 void visitChildren(NodeVisitor visitor) {} |
| 1093 InterpolatedStatement _clone() => new InterpolatedStatement(nameOrPosition); | 1101 InterpolatedStatement _clone() => new InterpolatedStatement(nameOrPosition); |
| 1094 } | 1102 } |
| 1095 | 1103 |
| 1104 class InterpolatedDeclaration extends Expression |
| 1105 with InterpolatedNode |
| 1106 implements Declaration { |
| 1107 final nameOrPosition; |
| 1108 |
| 1109 InterpolatedDeclaration(this.nameOrPosition); |
| 1110 |
| 1111 accept(NodeVisitor visitor) => visitor.visitInterpolatedDeclaration(this); |
| 1112 void visitChildren(NodeVisitor visitor) {} |
| 1113 InterpolatedDeclaration _clone() { |
| 1114 return new InterpolatedDeclaration(nameOrPosition); |
| 1115 } |
| 1116 |
| 1117 @override |
| 1118 String get name => throw "No name for the interpolated node"; |
| 1119 |
| 1120 @override |
| 1121 int get precedenceLevel => PRIMARY; |
| 1122 } |
| 1123 |
| 1096 /** | 1124 /** |
| 1097 * [RegExpLiteral]s, despite being called "Literal", do not inherit from | 1125 * [RegExpLiteral]s, despite being called "Literal", do not inherit from |
| 1098 * [Literal]. Indeed, regular expressions in JavaScript have a side-effect and | 1126 * [Literal]. Indeed, regular expressions in JavaScript have a side-effect and |
| 1099 * are thus not in the same category as numbers or strings. | 1127 * are thus not in the same category as numbers or strings. |
| 1100 */ | 1128 */ |
| 1101 class RegExpLiteral extends Expression { | 1129 class RegExpLiteral extends Expression { |
| 1102 /** Contains the pattern and the flags.*/ | 1130 /** Contains the pattern and the flags.*/ |
| 1103 final String pattern; | 1131 final String pattern; |
| 1104 | 1132 |
| 1105 RegExpLiteral(this.pattern); | 1133 RegExpLiteral(this.pattern); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1139 class Comment extends Statement { | 1167 class Comment extends Statement { |
| 1140 final String comment; | 1168 final String comment; |
| 1141 | 1169 |
| 1142 Comment(this.comment); | 1170 Comment(this.comment); |
| 1143 | 1171 |
| 1144 accept(NodeVisitor visitor) => visitor.visitComment(this); | 1172 accept(NodeVisitor visitor) => visitor.visitComment(this); |
| 1145 Comment _clone() => new Comment(comment); | 1173 Comment _clone() => new Comment(comment); |
| 1146 | 1174 |
| 1147 void visitChildren(NodeVisitor visitor) {} | 1175 void visitChildren(NodeVisitor visitor) {} |
| 1148 } | 1176 } |
| OLD | NEW |