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 visitYield(Yield 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 visitYield(Yield 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 class Yield extends Statement { | |
floitsch
2015/02/02 22:00:06
Add comment.
There exists a JS yield, and this one
sigurdm
2015/02/03 16:59:27
I was not aware of js yield, I renamed this to Dar
| |
538 final Expression expression; | |
539 | |
540 final bool hasStar; | |
541 | |
542 Yield(this.expression, this.hasStar); | |
543 | |
544 accept(NodeVisitor visitor) => visitor.visitYield(this); | |
545 | |
546 void visitChildren(NodeVisitor visitor) { | |
547 expression.accept(visitor); | |
548 } | |
549 | |
550 Yield _clone() => new Yield(expression, hasStar); | |
551 } | |
552 | |
535 abstract class Expression extends Node { | 553 abstract class Expression extends Node { |
536 int get precedenceLevel; | 554 int get precedenceLevel; |
537 | 555 |
538 Statement toStatement() => new ExpressionStatement(this); | 556 Statement toStatement() => new ExpressionStatement(this); |
539 | 557 |
540 Expression withPosition(var sourcePosition, var endSourcePosition) => | 558 Expression withPosition(var sourcePosition, var endSourcePosition) => |
541 super.withPosition(sourcePosition, endSourcePosition); | 559 super.withPosition(sourcePosition, endSourcePosition); |
542 } | 560 } |
543 | 561 |
544 /// Wrap a CodeBuffer as an expression. | 562 /// Wrap a CodeBuffer as an expression. |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
855 | 873 |
856 Fun(this.params, this.body, {this.asyncModifier: const AsyncModifier.sync()}); | 874 Fun(this.params, this.body, {this.asyncModifier: const AsyncModifier.sync()}); |
857 | 875 |
858 accept(NodeVisitor visitor) => visitor.visitFun(this); | 876 accept(NodeVisitor visitor) => visitor.visitFun(this); |
859 | 877 |
860 void visitChildren(NodeVisitor visitor) { | 878 void visitChildren(NodeVisitor visitor) { |
861 for (Parameter param in params) param.accept(visitor); | 879 for (Parameter param in params) param.accept(visitor); |
862 body.accept(visitor); | 880 body.accept(visitor); |
863 } | 881 } |
864 | 882 |
865 Fun _clone() => new Fun(params, body); | 883 Fun _clone() => new Fun(params, body, asyncModifier: asyncModifier); |
866 | 884 |
867 int get precedenceLevel => CALL; | 885 int get precedenceLevel => CALL; |
868 } | 886 } |
869 | 887 |
870 class AsyncModifier { | 888 class AsyncModifier { |
871 final bool isAsync; | 889 final bool isAsync; |
872 final bool isYielding; | 890 final bool isYielding; |
891 final String description; | |
873 | 892 |
874 const AsyncModifier.sync() : isAsync = false, isYielding = false; | 893 const AsyncModifier.sync() |
875 const AsyncModifier.async() : isAsync = true, isYielding = false; | 894 : isAsync = false, |
876 const AsyncModifier.asyncStar() : isAsync = true, isYielding = true; | 895 isYielding = false, |
877 const AsyncModifier.syncStar() : isAsync = false, isYielding = true; | 896 description = "sync"; |
897 const AsyncModifier.async() | |
898 : isAsync = true, | |
899 isYielding = false, | |
900 description = "async"; | |
901 const AsyncModifier.asyncStar() | |
902 : isAsync = true, | |
903 isYielding = true, | |
904 description = "async*"; | |
905 const AsyncModifier.syncStar() | |
906 : isAsync = false, | |
907 isYielding = true, | |
908 description = "sync*"; | |
909 toString() => description; | |
878 } | 910 } |
879 | 911 |
880 class PropertyAccess extends Expression { | 912 class PropertyAccess extends Expression { |
881 final Expression receiver; | 913 final Expression receiver; |
882 final Expression selector; | 914 final Expression selector; |
883 | 915 |
884 PropertyAccess(this.receiver, this.selector); | 916 PropertyAccess(this.receiver, this.selector); |
885 PropertyAccess.field(this.receiver, String fieldName) | 917 PropertyAccess.field(this.receiver, String fieldName) |
886 : selector = new LiteralString('"$fieldName"'); | 918 : selector = new LiteralString('"$fieldName"'); |
887 PropertyAccess.indexed(this.receiver, int index) | 919 PropertyAccess.indexed(this.receiver, int index) |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1133 class Comment extends Statement { | 1165 class Comment extends Statement { |
1134 final String comment; | 1166 final String comment; |
1135 | 1167 |
1136 Comment(this.comment); | 1168 Comment(this.comment); |
1137 | 1169 |
1138 accept(NodeVisitor visitor) => visitor.visitComment(this); | 1170 accept(NodeVisitor visitor) => visitor.visitComment(this); |
1139 Comment _clone() => new Comment(comment); | 1171 Comment _clone() => new Comment(comment); |
1140 | 1172 |
1141 void visitChildren(NodeVisitor visitor) {} | 1173 void visitChildren(NodeVisitor visitor) {} |
1142 } | 1174 } |
OLD | NEW |