| 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; | 5 part of js; |
| 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); |
| 11 T visitExpressionStatement(ExpressionStatement node); | 11 T visitExpressionStatement(ExpressionStatement node); |
| 12 T visitEmptyStatement(EmptyStatement node); | 12 T visitEmptyStatement(EmptyStatement node); |
| 13 T visitIf(If node); | 13 T visitIf(If node); |
| 14 T visitFor(For node); | 14 T visitFor(For node); |
| 15 T visitForIn(ForIn node); | 15 T visitForIn(ForIn node); |
| 16 T visitWhile(While node); | 16 T visitWhile(While node); |
| 17 T visitDo(Do node); | 17 T visitDo(Do node); |
| 18 T visitContinue(Continue node); | 18 T visitContinue(Continue node); |
| 19 T visitBreak(Break node); | 19 T visitBreak(Break node); |
| 20 T visitReturn(Return node); | 20 T visitReturn(Return node); |
| 21 T visitThrow(Throw node); | 21 T visitThrow(Throw node); |
| 22 T visitTry(Try node); | 22 T visitTry(Try node); |
| 23 T visitCatch(Catch node); | 23 T visitCatch(Catch node); |
| 24 T visitSwitch(Switch node); | 24 T visitSwitch(Switch node); |
| 25 T visitCase(Case node); | 25 T visitCase(Case node); |
| 26 T visitDefault(Default node); | 26 T visitDefault(Default node); |
| 27 T visitFunctionDeclaration(FunctionDeclaration node); | 27 T visitFunctionDeclaration(FunctionDeclaration node); |
| 28 T visitLabeledStatement(LabeledStatement node); | 28 T visitLabeledStatement(LabeledStatement node); |
| 29 T visitLiteralStatement(LiteralStatement node); | 29 T visitLiteralStatement(LiteralStatement node); |
| 30 T visitDartYield(DartYield node); |
| 30 | 31 |
| 31 T visitBlob(Blob node); | 32 T visitBlob(Blob node); |
| 32 T visitLiteralExpression(LiteralExpression node); | 33 T visitLiteralExpression(LiteralExpression node); |
| 33 T visitVariableDeclarationList(VariableDeclarationList node); | 34 T visitVariableDeclarationList(VariableDeclarationList node); |
| 34 T visitAssignment(Assignment node); | 35 T visitAssignment(Assignment node); |
| 35 T visitVariableInitialization(VariableInitialization node); | 36 T visitVariableInitialization(VariableInitialization node); |
| 36 T visitConditional(Conditional cond); | 37 T visitConditional(Conditional cond); |
| 37 T visitNew(New node); | 38 T visitNew(New node); |
| 38 T visitCall(Call node); | 39 T visitCall(Call node); |
| 39 T visitBinary(Binary node); | 40 T visitBinary(Binary node); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 => visitInterpolatedNode(node); | 163 => visitInterpolatedNode(node); |
| 163 T visitInterpolatedSelector(InterpolatedSelector node) | 164 T visitInterpolatedSelector(InterpolatedSelector node) |
| 164 => visitInterpolatedNode(node); | 165 => visitInterpolatedNode(node); |
| 165 T visitInterpolatedStatement(InterpolatedStatement node) | 166 T visitInterpolatedStatement(InterpolatedStatement node) |
| 166 => visitInterpolatedNode(node); | 167 => visitInterpolatedNode(node); |
| 167 | 168 |
| 168 // Ignore comments by default. | 169 // Ignore comments by default. |
| 169 T visitComment(Comment node) => null; | 170 T visitComment(Comment node) => null; |
| 170 | 171 |
| 171 T visitAwait(Await node) => visitExpression(node); | 172 T visitAwait(Await node) => visitExpression(node); |
| 173 T visitDartYield(DartYield node) => visitStatement(node); |
| 172 } | 174 } |
| 173 | 175 |
| 174 abstract class Node { | 176 abstract class Node { |
| 175 get sourcePosition => _sourcePosition; | 177 get sourcePosition => _sourcePosition; |
| 176 get endSourcePosition => _endSourcePosition; | 178 get endSourcePosition => _endSourcePosition; |
| 177 | 179 |
| 178 var _sourcePosition; | 180 var _sourcePosition; |
| 179 var _endSourcePosition; | 181 var _endSourcePosition; |
| 180 | 182 |
| 181 accept(NodeVisitor visitor); | 183 accept(NodeVisitor visitor); |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 final String code; | 527 final String code; |
| 526 | 528 |
| 527 LiteralStatement(this.code); | 529 LiteralStatement(this.code); |
| 528 | 530 |
| 529 accept(NodeVisitor visitor) => visitor.visitLiteralStatement(this); | 531 accept(NodeVisitor visitor) => visitor.visitLiteralStatement(this); |
| 530 void visitChildren(NodeVisitor visitor) { } | 532 void visitChildren(NodeVisitor visitor) { } |
| 531 | 533 |
| 532 LiteralStatement _clone() => new LiteralStatement(code); | 534 LiteralStatement _clone() => new LiteralStatement(code); |
| 533 } | 535 } |
| 534 | 536 |
| 537 // Not a real javascript node, but represents the yield statement from a dart |
| 538 // program translated to javascript. |
| 539 class DartYield extends Statement { |
| 540 final Expression expression; |
| 541 |
| 542 final bool hasStar; |
| 543 |
| 544 DartYield(this.expression, this.hasStar); |
| 545 |
| 546 accept(NodeVisitor visitor) => visitor.visitDartYield(this); |
| 547 |
| 548 void visitChildren(NodeVisitor visitor) { |
| 549 expression.accept(visitor); |
| 550 } |
| 551 |
| 552 DartYield _clone() => new DartYield(expression, hasStar); |
| 553 } |
| 554 |
| 535 abstract class Expression extends Node { | 555 abstract class Expression extends Node { |
| 536 int get precedenceLevel; | 556 int get precedenceLevel; |
| 537 | 557 |
| 538 Statement toStatement() => new ExpressionStatement(this); | 558 Statement toStatement() => new ExpressionStatement(this); |
| 539 | 559 |
| 540 Expression withPosition(var sourcePosition, var endSourcePosition) => | 560 Expression withPosition(var sourcePosition, var endSourcePosition) => |
| 541 super.withPosition(sourcePosition, endSourcePosition); | 561 super.withPosition(sourcePosition, endSourcePosition); |
| 542 } | 562 } |
| 543 | 563 |
| 544 /// Wrap a CodeBuffer as an expression. | 564 /// Wrap a CodeBuffer as an expression. |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 855 | 875 |
| 856 Fun(this.params, this.body, {this.asyncModifier: const AsyncModifier.sync()}); | 876 Fun(this.params, this.body, {this.asyncModifier: const AsyncModifier.sync()}); |
| 857 | 877 |
| 858 accept(NodeVisitor visitor) => visitor.visitFun(this); | 878 accept(NodeVisitor visitor) => visitor.visitFun(this); |
| 859 | 879 |
| 860 void visitChildren(NodeVisitor visitor) { | 880 void visitChildren(NodeVisitor visitor) { |
| 861 for (Parameter param in params) param.accept(visitor); | 881 for (Parameter param in params) param.accept(visitor); |
| 862 body.accept(visitor); | 882 body.accept(visitor); |
| 863 } | 883 } |
| 864 | 884 |
| 865 Fun _clone() => new Fun(params, body); | 885 Fun _clone() => new Fun(params, body, asyncModifier: asyncModifier); |
| 866 | 886 |
| 867 int get precedenceLevel => CALL; | 887 int get precedenceLevel => CALL; |
| 868 } | 888 } |
| 869 | 889 |
| 870 class AsyncModifier { | 890 class AsyncModifier { |
| 871 final bool isAsync; | 891 final bool isAsync; |
| 872 final bool isYielding; | 892 final bool isYielding; |
| 893 final String description; |
| 873 | 894 |
| 874 const AsyncModifier.sync() : isAsync = false, isYielding = false; | 895 const AsyncModifier.sync() |
| 875 const AsyncModifier.async() : isAsync = true, isYielding = false; | 896 : isAsync = false, |
| 876 const AsyncModifier.asyncStar() : isAsync = true, isYielding = true; | 897 isYielding = false, |
| 877 const AsyncModifier.syncStar() : isAsync = false, isYielding = true; | 898 description = "sync"; |
| 899 const AsyncModifier.async() |
| 900 : isAsync = true, |
| 901 isYielding = false, |
| 902 description = "async"; |
| 903 const AsyncModifier.asyncStar() |
| 904 : isAsync = true, |
| 905 isYielding = true, |
| 906 description = "async*"; |
| 907 const AsyncModifier.syncStar() |
| 908 : isAsync = false, |
| 909 isYielding = true, |
| 910 description = "sync*"; |
| 911 toString() => description; |
| 878 } | 912 } |
| 879 | 913 |
| 880 class PropertyAccess extends Expression { | 914 class PropertyAccess extends Expression { |
| 881 final Expression receiver; | 915 final Expression receiver; |
| 882 final Expression selector; | 916 final Expression selector; |
| 883 | 917 |
| 884 PropertyAccess(this.receiver, this.selector); | 918 PropertyAccess(this.receiver, this.selector); |
| 885 PropertyAccess.field(this.receiver, String fieldName) | 919 PropertyAccess.field(this.receiver, String fieldName) |
| 886 : selector = new LiteralString('"$fieldName"'); | 920 : selector = new LiteralString('"$fieldName"'); |
| 887 PropertyAccess.indexed(this.receiver, int index) | 921 PropertyAccess.indexed(this.receiver, int index) |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1133 class Comment extends Statement { | 1167 class Comment extends Statement { |
| 1134 final String comment; | 1168 final String comment; |
| 1135 | 1169 |
| 1136 Comment(this.comment); | 1170 Comment(this.comment); |
| 1137 | 1171 |
| 1138 accept(NodeVisitor visitor) => visitor.visitComment(this); | 1172 accept(NodeVisitor visitor) => visitor.visitComment(this); |
| 1139 Comment _clone() => new Comment(comment); | 1173 Comment _clone() => new Comment(comment); |
| 1140 | 1174 |
| 1141 void visitChildren(NodeVisitor visitor) {} | 1175 void visitChildren(NodeVisitor visitor) {} |
| 1142 } | 1176 } |
| OLD | NEW |