| 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); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 T visitLiteralString(LiteralString node); | 53 T visitLiteralString(LiteralString node); |
| 54 T visitLiteralNumber(LiteralNumber node); | 54 T visitLiteralNumber(LiteralNumber node); |
| 55 T visitLiteralNull(LiteralNull node); | 55 T visitLiteralNull(LiteralNull node); |
| 56 | 56 |
| 57 T visitArrayInitializer(ArrayInitializer node); | 57 T visitArrayInitializer(ArrayInitializer node); |
| 58 T visitArrayHole(ArrayHole node); | 58 T visitArrayHole(ArrayHole node); |
| 59 T visitObjectInitializer(ObjectInitializer node); | 59 T visitObjectInitializer(ObjectInitializer node); |
| 60 T visitProperty(Property node); | 60 T visitProperty(Property node); |
| 61 T visitRegExpLiteral(RegExpLiteral node); | 61 T visitRegExpLiteral(RegExpLiteral node); |
| 62 | 62 |
| 63 T visitAwait(Await node); |
| 64 |
| 63 T visitComment(Comment node); | 65 T visitComment(Comment node); |
| 64 | 66 |
| 65 T visitInterpolatedExpression(InterpolatedExpression node); | 67 T visitInterpolatedExpression(InterpolatedExpression node); |
| 66 T visitInterpolatedLiteral(InterpolatedLiteral node); | 68 T visitInterpolatedLiteral(InterpolatedLiteral node); |
| 67 T visitInterpolatedParameter(InterpolatedParameter node); | 69 T visitInterpolatedParameter(InterpolatedParameter node); |
| 68 T visitInterpolatedSelector(InterpolatedSelector node); | 70 T visitInterpolatedSelector(InterpolatedSelector node); |
| 69 T visitInterpolatedStatement(InterpolatedStatement node); | 71 T visitInterpolatedStatement(InterpolatedStatement node); |
| 70 } | 72 } |
| 71 | 73 |
| 72 class BaseVisitor<T> implements NodeVisitor<T> { | 74 class BaseVisitor<T> implements NodeVisitor<T> { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 => visitInterpolatedNode(node); | 160 => visitInterpolatedNode(node); |
| 159 T visitInterpolatedParameter(InterpolatedParameter node) | 161 T visitInterpolatedParameter(InterpolatedParameter node) |
| 160 => visitInterpolatedNode(node); | 162 => visitInterpolatedNode(node); |
| 161 T visitInterpolatedSelector(InterpolatedSelector node) | 163 T visitInterpolatedSelector(InterpolatedSelector node) |
| 162 => visitInterpolatedNode(node); | 164 => visitInterpolatedNode(node); |
| 163 T visitInterpolatedStatement(InterpolatedStatement node) | 165 T visitInterpolatedStatement(InterpolatedStatement node) |
| 164 => visitInterpolatedNode(node); | 166 => visitInterpolatedNode(node); |
| 165 | 167 |
| 166 // Ignore comments by default. | 168 // Ignore comments by default. |
| 167 T visitComment(Comment node) => null; | 169 T visitComment(Comment node) => null; |
| 170 |
| 171 T visitAwait(Await node) => visitExpression(node); |
| 168 } | 172 } |
| 169 | 173 |
| 170 abstract class Node { | 174 abstract class Node { |
| 171 get sourcePosition => _sourcePosition; | 175 get sourcePosition => _sourcePosition; |
| 172 get endSourcePosition => _endSourcePosition; | 176 get endSourcePosition => _endSourcePosition; |
| 173 | 177 |
| 174 var _sourcePosition; | 178 var _sourcePosition; |
| 175 var _endSourcePosition; | 179 var _endSourcePosition; |
| 176 | 180 |
| 177 accept(NodeVisitor visitor); | 181 accept(NodeVisitor visitor); |
| (...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 840 function.accept(visitor); | 844 function.accept(visitor); |
| 841 } | 845 } |
| 842 NamedFunction _clone() => new NamedFunction(name, function); | 846 NamedFunction _clone() => new NamedFunction(name, function); |
| 843 | 847 |
| 844 int get precedenceLevel => CALL; | 848 int get precedenceLevel => CALL; |
| 845 } | 849 } |
| 846 | 850 |
| 847 class Fun extends Expression { | 851 class Fun extends Expression { |
| 848 final List<Parameter> params; | 852 final List<Parameter> params; |
| 849 final Block body; | 853 final Block body; |
| 854 final AsyncModifier asyncModifier; |
| 850 | 855 |
| 851 Fun(this.params, this.body); | 856 Fun(this.params, this.body, {this.asyncModifier: const AsyncModifier.sync()}); |
| 852 | 857 |
| 853 accept(NodeVisitor visitor) => visitor.visitFun(this); | 858 accept(NodeVisitor visitor) => visitor.visitFun(this); |
| 854 | 859 |
| 855 void visitChildren(NodeVisitor visitor) { | 860 void visitChildren(NodeVisitor visitor) { |
| 856 for (Parameter param in params) param.accept(visitor); | 861 for (Parameter param in params) param.accept(visitor); |
| 857 body.accept(visitor); | 862 body.accept(visitor); |
| 858 } | 863 } |
| 859 | 864 |
| 860 Fun _clone() => new Fun(params, body); | 865 Fun _clone() => new Fun(params, body); |
| 861 | 866 |
| 862 int get precedenceLevel => CALL; | 867 int get precedenceLevel => CALL; |
| 863 } | 868 } |
| 864 | 869 |
| 870 class AsyncModifier { |
| 871 final bool isAsync; |
| 872 final bool isYielding; |
| 873 |
| 874 const AsyncModifier.sync() : isAsync = false, isYielding = false; |
| 875 const AsyncModifier.async() : isAsync = true, isYielding = false; |
| 876 const AsyncModifier.asyncStar() : isAsync = true, isYielding = true; |
| 877 const AsyncModifier.syncStar() : isAsync = false, isYielding = true; |
| 878 } |
| 879 |
| 865 class PropertyAccess extends Expression { | 880 class PropertyAccess extends Expression { |
| 866 final Expression receiver; | 881 final Expression receiver; |
| 867 final Expression selector; | 882 final Expression selector; |
| 868 | 883 |
| 869 PropertyAccess(this.receiver, this.selector); | 884 PropertyAccess(this.receiver, this.selector); |
| 870 PropertyAccess.field(this.receiver, String fieldName) | 885 PropertyAccess.field(this.receiver, String fieldName) |
| 871 : selector = new LiteralString('"$fieldName"'); | 886 : selector = new LiteralString('"$fieldName"'); |
| 872 PropertyAccess.indexed(this.receiver, int index) | 887 PropertyAccess.indexed(this.receiver, int index) |
| 873 : selector = new LiteralNumber('$index'); | 888 : selector = new LiteralNumber('$index'); |
| 874 | 889 |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1084 RegExpLiteral(this.pattern); | 1099 RegExpLiteral(this.pattern); |
| 1085 | 1100 |
| 1086 accept(NodeVisitor visitor) => visitor.visitRegExpLiteral(this); | 1101 accept(NodeVisitor visitor) => visitor.visitRegExpLiteral(this); |
| 1087 void visitChildren(NodeVisitor visitor) {} | 1102 void visitChildren(NodeVisitor visitor) {} |
| 1088 RegExpLiteral _clone() => new RegExpLiteral(pattern); | 1103 RegExpLiteral _clone() => new RegExpLiteral(pattern); |
| 1089 | 1104 |
| 1090 int get precedenceLevel => PRIMARY; | 1105 int get precedenceLevel => PRIMARY; |
| 1091 } | 1106 } |
| 1092 | 1107 |
| 1093 /** | 1108 /** |
| 1109 * An asynchronous await. |
| 1110 * |
| 1111 * Not part of javascript. We desugar this expression before outputting. |
| 1112 * Should only occur in a [Fun] with `asyncModifier` async or asyncStar. |
| 1113 */ |
| 1114 class Await extends Expression { |
| 1115 /** The awaited expression. */ |
| 1116 final Expression expression; |
| 1117 |
| 1118 Await(this.expression); |
| 1119 |
| 1120 int get precedenceLevel => UNARY; |
| 1121 accept(NodeVisitor visitor) => visitor.visitAwait(this); |
| 1122 void visitChildren(NodeVisitor visitor) => expression.accept(visitor); |
| 1123 Await _clone() => new Await(expression); |
| 1124 |
| 1125 } |
| 1126 |
| 1127 /** |
| 1094 * A comment. | 1128 * A comment. |
| 1095 * | 1129 * |
| 1096 * Extends [Statement] so we can add comments before statements in | 1130 * Extends [Statement] so we can add comments before statements in |
| 1097 * [Block] and [Program]. | 1131 * [Block] and [Program]. |
| 1098 */ | 1132 */ |
| 1099 class Comment extends Statement { | 1133 class Comment extends Statement { |
| 1100 final String comment; | 1134 final String comment; |
| 1101 | 1135 |
| 1102 Comment(this.comment); | 1136 Comment(this.comment); |
| 1103 | 1137 |
| 1104 accept(NodeVisitor visitor) => visitor.visitComment(this); | 1138 accept(NodeVisitor visitor) => visitor.visitComment(this); |
| 1105 Comment _clone() => new Comment(comment); | 1139 Comment _clone() => new Comment(comment); |
| 1106 | 1140 |
| 1107 void visitChildren(NodeVisitor visitor) {} | 1141 void visitChildren(NodeVisitor visitor) {} |
| 1108 } | 1142 } |
| OLD | NEW |