| 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 tree; | 5 part of tree; |
| 6 | 6 |
| 7 abstract class Visitor<R> { | 7 abstract class Visitor<R> { |
| 8 const Visitor(); | 8 const Visitor(); |
| 9 | 9 |
| 10 R visitNode(Node node); | 10 R visitNode(Node node); |
| 11 | 11 |
| 12 R visitAsyncModifier(AsyncModifier node) => visitNode(node); |
| 13 R visitAwait(Await node) => visitExpression(node); |
| 12 R visitBlock(Block node) => visitStatement(node); | 14 R visitBlock(Block node) => visitStatement(node); |
| 13 R visitBreakStatement(BreakStatement node) => visitGotoStatement(node); | 15 R visitBreakStatement(BreakStatement node) => visitGotoStatement(node); |
| 14 R visitCascade(Cascade node) => visitExpression(node); | 16 R visitCascade(Cascade node) => visitExpression(node); |
| 15 R visitCascadeReceiver(CascadeReceiver node) => visitExpression(node); | 17 R visitCascadeReceiver(CascadeReceiver node) => visitExpression(node); |
| 16 R visitCaseMatch(CaseMatch node) => visitNode(node); | 18 R visitCaseMatch(CaseMatch node) => visitNode(node); |
| 17 R visitCatchBlock(CatchBlock node) => visitNode(node); | 19 R visitCatchBlock(CatchBlock node) => visitNode(node); |
| 18 R visitClassNode(ClassNode node) => visitNode(node); | 20 R visitClassNode(ClassNode node) => visitNode(node); |
| 19 R visitCombinator(Combinator node) => visitNode(node); | 21 R visitCombinator(Combinator node) => visitNode(node); |
| 20 R visitConditional(Conditional node) => visitExpression(node); | 22 R visitConditional(Conditional node) => visitExpression(node); |
| 21 R visitContinueStatement(ContinueStatement node) => visitGotoStatement(node); | 23 R visitContinueStatement(ContinueStatement node) => visitGotoStatement(node); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 R visitSwitchCase(SwitchCase node) => visitNode(node); | 83 R visitSwitchCase(SwitchCase node) => visitNode(node); |
| 82 R visitSwitchStatement(SwitchStatement node) => visitStatement(node); | 84 R visitSwitchStatement(SwitchStatement node) => visitStatement(node); |
| 83 R visitLiteralSymbol(LiteralSymbol node) => visitExpression(node); | 85 R visitLiteralSymbol(LiteralSymbol node) => visitExpression(node); |
| 84 R visitThrow(Throw node) => visitExpression(node); | 86 R visitThrow(Throw node) => visitExpression(node); |
| 85 R visitTryStatement(TryStatement node) => visitStatement(node); | 87 R visitTryStatement(TryStatement node) => visitStatement(node); |
| 86 R visitTypeAnnotation(TypeAnnotation node) => visitNode(node); | 88 R visitTypeAnnotation(TypeAnnotation node) => visitNode(node); |
| 87 R visitTypedef(Typedef node) => visitNode(node); | 89 R visitTypedef(Typedef node) => visitNode(node); |
| 88 R visitTypeVariable(TypeVariable node) => visitNode(node); | 90 R visitTypeVariable(TypeVariable node) => visitNode(node); |
| 89 R visitVariableDefinitions(VariableDefinitions node) => visitStatement(node); | 91 R visitVariableDefinitions(VariableDefinitions node) => visitStatement(node); |
| 90 R visitWhile(While node) => visitLoop(node); | 92 R visitWhile(While node) => visitLoop(node); |
| 93 R visitYield(Yield node) => visitStatement(node); |
| 91 } | 94 } |
| 92 | 95 |
| 93 Token firstBeginToken(Node first, Node second) { | 96 Token firstBeginToken(Node first, Node second) { |
| 94 Token token = null; | 97 Token token = null; |
| 95 if (first != null) { | 98 if (first != null) { |
| 96 token = first.getBeginToken(); | 99 token = first.getBeginToken(); |
| 97 } | 100 } |
| 98 if (token == null && second != null) { | 101 if (token == null && second != null) { |
| 99 // [token] might be null even when [first] is not, e.g. for empty Modifiers. | 102 // [token] might be null even when [first] is not, e.g. for empty Modifiers. |
| 100 token = second.getBeginToken(); | 103 token = second.getBeginToken(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 toDebugString() { | 137 toDebugString() { |
| 135 return PrettyPrinter.prettyPrint(this); | 138 return PrettyPrinter.prettyPrint(this); |
| 136 } | 139 } |
| 137 | 140 |
| 138 String getObjectDescription() => super.toString(); | 141 String getObjectDescription() => super.toString(); |
| 139 | 142 |
| 140 Token getBeginToken(); | 143 Token getBeginToken(); |
| 141 | 144 |
| 142 Token getEndToken(); | 145 Token getEndToken(); |
| 143 | 146 |
| 147 AsyncModifier asAsyncModifier() => null; |
| 148 Await asAwait() => null; |
| 144 Block asBlock() => null; | 149 Block asBlock() => null; |
| 145 BreakStatement asBreakStatement() => null; | 150 BreakStatement asBreakStatement() => null; |
| 146 Cascade asCascade() => null; | 151 Cascade asCascade() => null; |
| 147 CascadeReceiver asCascadeReceiver() => null; | 152 CascadeReceiver asCascadeReceiver() => null; |
| 148 CaseMatch asCaseMatch() => null; | 153 CaseMatch asCaseMatch() => null; |
| 149 CatchBlock asCatchBlock() => null; | 154 CatchBlock asCatchBlock() => null; |
| 150 ClassNode asClassNode() => null; | 155 ClassNode asClassNode() => null; |
| 151 Combinator asCombinator() => null; | 156 Combinator asCombinator() => null; |
| 152 Conditional asConditional() => null; | 157 Conditional asConditional() => null; |
| 153 ContinueStatement asContinueStatement() => null; | 158 ContinueStatement asContinueStatement() => null; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 StringNode asStringNode() => null; | 205 StringNode asStringNode() => null; |
| 201 SwitchCase asSwitchCase() => null; | 206 SwitchCase asSwitchCase() => null; |
| 202 SwitchStatement asSwitchStatement() => null; | 207 SwitchStatement asSwitchStatement() => null; |
| 203 Throw asThrow() => null; | 208 Throw asThrow() => null; |
| 204 TryStatement asTryStatement() => null; | 209 TryStatement asTryStatement() => null; |
| 205 TypeAnnotation asTypeAnnotation() => null; | 210 TypeAnnotation asTypeAnnotation() => null; |
| 206 TypeVariable asTypeVariable() => null; | 211 TypeVariable asTypeVariable() => null; |
| 207 Typedef asTypedef() => null; | 212 Typedef asTypedef() => null; |
| 208 VariableDefinitions asVariableDefinitions() => null; | 213 VariableDefinitions asVariableDefinitions() => null; |
| 209 While asWhile() => null; | 214 While asWhile() => null; |
| 215 Yield asYield() => null; |
| 210 | 216 |
| 211 bool isValidBreakTarget() => false; | 217 bool isValidBreakTarget() => false; |
| 212 bool isValidContinueTarget() => false; | 218 bool isValidContinueTarget() => false; |
| 213 bool isThis() => false; | 219 bool isThis() => false; |
| 214 bool isSuper() => false; | 220 bool isSuper() => false; |
| 215 | 221 |
| 216 bool get isErroneous => false; | 222 bool get isErroneous => false; |
| 217 } | 223 } |
| 218 | 224 |
| 219 class ClassNode extends Node { | 225 class ClassNode extends Node { |
| (...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 700 FunctionDeclaration asFunctionDeclaration() => this; | 706 FunctionDeclaration asFunctionDeclaration() => this; |
| 701 | 707 |
| 702 accept(Visitor visitor) => visitor.visitFunctionDeclaration(this); | 708 accept(Visitor visitor) => visitor.visitFunctionDeclaration(this); |
| 703 | 709 |
| 704 visitChildren(Visitor visitor) => function.accept(visitor); | 710 visitChildren(Visitor visitor) => function.accept(visitor); |
| 705 | 711 |
| 706 Token getBeginToken() => function.getBeginToken(); | 712 Token getBeginToken() => function.getBeginToken(); |
| 707 Token getEndToken() => function.getEndToken(); | 713 Token getEndToken() => function.getEndToken(); |
| 708 } | 714 } |
| 709 | 715 |
| 716 /// Node representing the method implementation modifiers `sync*`, `async`, and |
| 717 /// `async*` or the invalid modifier `sync`. |
| 718 class AsyncModifier extends Node { |
| 719 /// The `async` or `sync` token. |
| 720 final Token asyncToken; |
| 721 |
| 722 /// The `*` token. |
| 723 final Token starToken; |
| 724 |
| 725 AsyncModifier(this.asyncToken, this.starToken); |
| 726 |
| 727 AsyncModifier asAsyncModifier() => this; |
| 728 |
| 729 accept(Visitor visitor) => visitor.visitAsyncModifier(this); |
| 730 |
| 731 visitChildren(Visitor visitor) {} |
| 732 |
| 733 Token getBeginToken() => asyncToken; |
| 734 |
| 735 Token getEndToken() => starToken != null ? starToken : asyncToken; |
| 736 |
| 737 /// Is `true` if this modifier is either `async` or `async*`. |
| 738 bool get isAsynchronous => asyncToken.value == 'async'; |
| 739 |
| 740 /// Is `true` if this modifier is either `sync*` or `async*`. |
| 741 bool get isYielding => starToken != null; |
| 742 } |
| 743 |
| 710 class FunctionExpression extends Expression with StoredTreeElementMixin { | 744 class FunctionExpression extends Expression with StoredTreeElementMixin { |
| 711 final Node name; | 745 final Node name; |
| 712 | 746 |
| 713 /** | 747 /** |
| 714 * List of VariableDefinitions or NodeList. | 748 * List of VariableDefinitions or NodeList. |
| 715 * | 749 * |
| 716 * A NodeList can only occur at the end and holds named parameters. | 750 * A NodeList can only occur at the end and holds named parameters. |
| 717 */ | 751 */ |
| 718 final NodeList parameters; | 752 final NodeList parameters; |
| 719 | 753 |
| 720 final Statement body; | 754 final Statement body; |
| 721 final TypeAnnotation returnType; | 755 final TypeAnnotation returnType; |
| 722 final Modifiers modifiers; | 756 final Modifiers modifiers; |
| 723 final NodeList initializers; | 757 final NodeList initializers; |
| 724 | 758 |
| 725 final Token getOrSet; | 759 final Token getOrSet; |
| 760 final AsyncModifier asyncModifier; |
| 726 | 761 |
| 727 FunctionExpression(this.name, this.parameters, this.body, this.returnType, | 762 FunctionExpression(this.name, this.parameters, this.body, this.returnType, |
| 728 this.modifiers, this.initializers, this.getOrSet) { | 763 this.modifiers, this.initializers, this.getOrSet, |
| 764 this.asyncModifier) { |
| 729 assert(modifiers != null); | 765 assert(modifiers != null); |
| 730 } | 766 } |
| 731 | 767 |
| 732 FunctionExpression asFunctionExpression() => this; | 768 FunctionExpression asFunctionExpression() => this; |
| 733 | 769 |
| 734 accept(Visitor visitor) => visitor.visitFunctionExpression(this); | 770 accept(Visitor visitor) => visitor.visitFunctionExpression(this); |
| 735 | 771 |
| 736 bool get isRedirectingFactory { | 772 bool get isRedirectingFactory { |
| 737 return body != null && body.asRedirectingFactoryBody() != null; | 773 return body != null && body.asRedirectingFactoryBody() != null; |
| 738 } | 774 } |
| 739 | 775 |
| 740 visitChildren(Visitor visitor) { | 776 visitChildren(Visitor visitor) { |
| 741 if (modifiers != null) modifiers.accept(visitor); | 777 if (modifiers != null) modifiers.accept(visitor); |
| 742 if (returnType != null) returnType.accept(visitor); | 778 if (returnType != null) returnType.accept(visitor); |
| 743 if (name != null) name.accept(visitor); | 779 if (name != null) name.accept(visitor); |
| 744 if (parameters != null) parameters.accept(visitor); | 780 if (parameters != null) parameters.accept(visitor); |
| 745 if (initializers != null) initializers.accept(visitor); | 781 if (initializers != null) initializers.accept(visitor); |
| 782 if (asyncModifier != null) asyncModifier.accept(visitor); |
| 746 if (body != null) body.accept(visitor); | 783 if (body != null) body.accept(visitor); |
| 747 } | 784 } |
| 748 | 785 |
| 749 bool hasBody() => body.asEmptyStatement() == null; | 786 bool hasBody() => body.asEmptyStatement() == null; |
| 750 | 787 |
| 751 bool hasEmptyBody() { | 788 bool hasEmptyBody() { |
| 752 Block block = body.asBlock(); | 789 Block block = body.asBlock(); |
| 753 if (block == null) return false; | 790 if (block == null) return false; |
| 754 return block.statements.isEmpty; | 791 return block.statements.isEmpty; |
| 755 } | 792 } |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1034 } | 1071 } |
| 1035 | 1072 |
| 1036 Token getBeginToken() => beginToken; | 1073 Token getBeginToken() => beginToken; |
| 1037 | 1074 |
| 1038 Token getEndToken() { | 1075 Token getEndToken() { |
| 1039 if (endToken == null) return expression.getEndToken(); | 1076 if (endToken == null) return expression.getEndToken(); |
| 1040 return endToken; | 1077 return endToken; |
| 1041 } | 1078 } |
| 1042 } | 1079 } |
| 1043 | 1080 |
| 1081 class Yield extends Statement { |
| 1082 final Node expression; |
| 1083 final Token yieldToken; |
| 1084 final Token starToken; |
| 1085 final Token endToken; |
| 1086 |
| 1087 Yield(this.yieldToken, this.starToken, this.expression, this.endToken); |
| 1088 |
| 1089 Yield asYield() => this; |
| 1090 |
| 1091 bool get hasStar => starToken != null; |
| 1092 |
| 1093 accept(Visitor visitor) => visitor.visitYield(this); |
| 1094 |
| 1095 visitChildren(Visitor visitor) { |
| 1096 expression.accept(visitor); |
| 1097 } |
| 1098 |
| 1099 Token getBeginToken() => yieldToken; |
| 1100 |
| 1101 Token getEndToken() => endToken; |
| 1102 } |
| 1103 |
| 1044 class RedirectingFactoryBody extends Statement with StoredTreeElementMixin { | 1104 class RedirectingFactoryBody extends Statement with StoredTreeElementMixin { |
| 1045 final Node constructorReference; | 1105 final Node constructorReference; |
| 1046 final Token beginToken; | 1106 final Token beginToken; |
| 1047 final Token endToken; | 1107 final Token endToken; |
| 1048 | 1108 |
| 1049 RedirectingFactoryBody(this.beginToken, this.endToken, | 1109 RedirectingFactoryBody(this.beginToken, this.endToken, |
| 1050 this.constructorReference); | 1110 this.constructorReference); |
| 1051 | 1111 |
| 1052 RedirectingFactoryBody asRedirectingFactoryBody() => this; | 1112 RedirectingFactoryBody asRedirectingFactoryBody() => this; |
| 1053 | 1113 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1095 | 1155 |
| 1096 visitChildren(Visitor visitor) { | 1156 visitChildren(Visitor visitor) { |
| 1097 expression.accept(visitor); | 1157 expression.accept(visitor); |
| 1098 } | 1158 } |
| 1099 | 1159 |
| 1100 Token getBeginToken() => throwToken; | 1160 Token getBeginToken() => throwToken; |
| 1101 | 1161 |
| 1102 Token getEndToken() => endToken; | 1162 Token getEndToken() => endToken; |
| 1103 } | 1163 } |
| 1104 | 1164 |
| 1165 class Await extends Expression { |
| 1166 final Expression expression; |
| 1167 |
| 1168 final Token awaitToken; |
| 1169 |
| 1170 Await(this.awaitToken, this.expression); |
| 1171 |
| 1172 Await asAwait() => this; |
| 1173 |
| 1174 accept(Visitor visitor) => visitor.visitAwait(this); |
| 1175 |
| 1176 visitChildren(Visitor visitor) { |
| 1177 expression.accept(visitor); |
| 1178 } |
| 1179 |
| 1180 Token getBeginToken() => awaitToken; |
| 1181 |
| 1182 Token getEndToken() => expression.getEndToken(); |
| 1183 } |
| 1184 |
| 1105 class Rethrow extends Statement { | 1185 class Rethrow extends Statement { |
| 1106 final Token throwToken; | 1186 final Token throwToken; |
| 1107 final Token endToken; | 1187 final Token endToken; |
| 1108 | 1188 |
| 1109 Rethrow(this.throwToken, this.endToken); | 1189 Rethrow(this.throwToken, this.endToken); |
| 1110 | 1190 |
| 1111 Rethrow asRethrow() => this; | 1191 Rethrow asRethrow() => this; |
| 1112 | 1192 |
| 1113 accept(Visitor visitor) => visitor.visitRethrow(this); | 1193 accept(Visitor visitor) => visitor.visitRethrow(this); |
| 1114 visitChildren(Visitor visitor) { } | 1194 visitChildren(Visitor visitor) { } |
| (...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1687 | 1767 |
| 1688 ContinueStatement asContinueStatement() => this; | 1768 ContinueStatement asContinueStatement() => this; |
| 1689 | 1769 |
| 1690 accept(Visitor visitor) => visitor.visitContinueStatement(this); | 1770 accept(Visitor visitor) => visitor.visitContinueStatement(this); |
| 1691 } | 1771 } |
| 1692 | 1772 |
| 1693 class ForIn extends Loop with StoredTreeElementMixin { | 1773 class ForIn extends Loop with StoredTreeElementMixin { |
| 1694 final Node declaredIdentifier; | 1774 final Node declaredIdentifier; |
| 1695 final Expression expression; | 1775 final Expression expression; |
| 1696 | 1776 |
| 1777 final Token awaitToken; |
| 1697 final Token forToken; | 1778 final Token forToken; |
| 1698 final Token inToken; | 1779 final Token inToken; |
| 1699 | 1780 |
| 1700 ForIn(this.declaredIdentifier, this.expression, | 1781 ForIn(this.declaredIdentifier, this.expression, |
| 1701 Statement body, this.forToken, this.inToken) : super(body); | 1782 Statement body, this.awaitToken, this.forToken, this.inToken) |
| 1783 : super(body); |
| 1784 |
| 1785 bool get isAsync => awaitToken != null; |
| 1702 | 1786 |
| 1703 Expression get condition => null; | 1787 Expression get condition => null; |
| 1704 | 1788 |
| 1705 ForIn asForIn() => this; | 1789 ForIn asForIn() => this; |
| 1706 | 1790 |
| 1707 accept(Visitor visitor) => visitor.visitForIn(this); | 1791 accept(Visitor visitor) => visitor.visitForIn(this); |
| 1708 | 1792 |
| 1709 visitChildren(Visitor visitor) { | 1793 visitChildren(Visitor visitor) { |
| 1710 declaredIdentifier.accept(visitor); | 1794 declaredIdentifier.accept(visitor); |
| 1711 expression.accept(visitor); | 1795 expression.accept(visitor); |
| 1712 body.accept(visitor); | 1796 body.accept(visitor); |
| 1713 } | 1797 } |
| 1714 | 1798 |
| 1715 Token getBeginToken() => forToken; | 1799 Token getBeginToken() => awaitToken != null ? awaitToken : forToken; |
| 1716 | 1800 |
| 1717 Token getEndToken() => body.getEndToken(); | 1801 Token getEndToken() => body.getEndToken(); |
| 1718 } | 1802 } |
| 1719 | 1803 |
| 1720 class Label extends Node { | 1804 class Label extends Node { |
| 1721 final Identifier identifier; | 1805 final Identifier identifier; |
| 1722 final Token colonToken; | 1806 final Token colonToken; |
| 1723 | 1807 |
| 1724 Label(this.identifier, this.colonToken); | 1808 Label(this.identifier, this.colonToken); |
| 1725 | 1809 |
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2161 | 2245 |
| 2162 Token getEndToken() => token; | 2246 Token getEndToken() => token; |
| 2163 | 2247 |
| 2164 accept(Visitor visitor) {} | 2248 accept(Visitor visitor) {} |
| 2165 | 2249 |
| 2166 visitChildren(Visitor visitor) {} | 2250 visitChildren(Visitor visitor) {} |
| 2167 | 2251 |
| 2168 bool get isErroneous => true; | 2252 bool get isErroneous => true; |
| 2169 | 2253 |
| 2170 // FunctionExpression. | 2254 // FunctionExpression. |
| 2255 get asyncModifier => null; |
| 2171 get parameters => null; | 2256 get parameters => null; |
| 2172 get body => null; | 2257 get body => null; |
| 2173 get returnType => null; | 2258 get returnType => null; |
| 2174 get modifiers => Modifiers.EMPTY; | 2259 get modifiers => Modifiers.EMPTY; |
| 2175 get initializers => null; | 2260 get initializers => null; |
| 2176 get getOrSet => null; | 2261 get getOrSet => null; |
| 2177 get isRedirectingFactory => false; | 2262 get isRedirectingFactory => false; |
| 2178 bool hasBody() => false; | 2263 bool hasBody() => false; |
| 2179 bool hasEmptyBody() => false; | 2264 bool hasEmptyBody() => false; |
| 2180 | 2265 |
| 2181 // VariableDefinitions. | 2266 // VariableDefinitions. |
| 2182 get metadata => null; | 2267 get metadata => null; |
| 2183 get type => null; | 2268 get type => null; |
| 2184 | 2269 |
| 2185 // Typedef. | 2270 // Typedef. |
| 2186 get typeParameters => null; | 2271 get typeParameters => null; |
| 2187 get formals => null; | 2272 get formals => null; |
| 2188 get typedefKeyword => null; | 2273 get typedefKeyword => null; |
| 2189 } | 2274 } |
| OLD | NEW |