| 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); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 R visitNewExpression(NewExpression node) => visitExpression(node); | 58 R visitNewExpression(NewExpression node) => visitExpression(node); |
| 59 R visitNodeList(NodeList node) => visitNode(node); | 59 R visitNodeList(NodeList node) => visitNode(node); |
| 60 R visitOperator(Operator node) => visitIdentifier(node); | 60 R visitOperator(Operator node) => visitIdentifier(node); |
| 61 R visitParenthesizedExpression(ParenthesizedExpression node) { | 61 R visitParenthesizedExpression(ParenthesizedExpression node) { |
| 62 return visitExpression(node); | 62 return visitExpression(node); |
| 63 } | 63 } |
| 64 R visitPart(Part node) => visitLibraryTag(node); | 64 R visitPart(Part node) => visitLibraryTag(node); |
| 65 R visitPartOf(PartOf node) => visitNode(node); | 65 R visitPartOf(PartOf node) => visitNode(node); |
| 66 R visitPostfix(Postfix node) => visitNodeList(node); | 66 R visitPostfix(Postfix node) => visitNodeList(node); |
| 67 R visitPrefix(Prefix node) => visitNodeList(node); | 67 R visitPrefix(Prefix node) => visitNodeList(node); |
| 68 R visitRedirectingFactoryBody(RedirectingFactoryBody node) { |
| 69 return visitStatement(node); |
| 70 } |
| 68 R visitRethrow(Rethrow node) => visitStatement(node); | 71 R visitRethrow(Rethrow node) => visitStatement(node); |
| 69 R visitReturn(Return node) => visitStatement(node); | 72 R visitReturn(Return node) => visitStatement(node); |
| 70 R visitSend(Send node) => visitExpression(node); | 73 R visitSend(Send node) => visitExpression(node); |
| 71 R visitSendSet(SendSet node) => visitSend(node); | 74 R visitSendSet(SendSet node) => visitSend(node); |
| 72 R visitStatement(Statement node) => visitNode(node); | 75 R visitStatement(Statement node) => visitNode(node); |
| 73 R visitStringNode(StringNode node) => visitExpression(node); | 76 R visitStringNode(StringNode node) => visitExpression(node); |
| 74 R visitStringInterpolation(StringInterpolation node) => visitStringNode(node); | 77 R visitStringInterpolation(StringInterpolation node) => visitStringNode(node); |
| 75 R visitStringInterpolationPart(StringInterpolationPart node) { | 78 R visitStringInterpolationPart(StringInterpolationPart node) { |
| 76 return visitNode(node); | 79 return visitNode(node); |
| 77 } | 80 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 103 * A node in a syntax tree. | 106 * A node in a syntax tree. |
| 104 * | 107 * |
| 105 * The abstract part of "abstract syntax tree" is invalidated when | 108 * The abstract part of "abstract syntax tree" is invalidated when |
| 106 * supporting tools such as code formatting. These tools need concrete | 109 * supporting tools such as code formatting. These tools need concrete |
| 107 * syntax such as parentheses and no constant folding. | 110 * syntax such as parentheses and no constant folding. |
| 108 * | 111 * |
| 109 * We support these tools by storing additional references back to the | 112 * We support these tools by storing additional references back to the |
| 110 * token stream. These references are stored in fields ending with | 113 * token stream. These references are stored in fields ending with |
| 111 * "Token". | 114 * "Token". |
| 112 */ | 115 */ |
| 113 abstract class Node extends TreeElementMixin implements Spannable { | 116 abstract class Node extends NullTreeElementMixin implements Spannable { |
| 114 final int hashCode; | 117 final int hashCode; |
| 115 static int _HASH_COUNTER = 0; | 118 static int _HASH_COUNTER = 0; |
| 116 | 119 |
| 117 Node() : hashCode = ++_HASH_COUNTER; | 120 Node() : hashCode = ++_HASH_COUNTER; |
| 118 | 121 |
| 119 accept(Visitor visitor); | 122 accept(Visitor visitor); |
| 120 | 123 |
| 121 visitChildren(Visitor visitor); | 124 visitChildren(Visitor visitor); |
| 122 | 125 |
| 123 /** | 126 /** |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 MixinApplication asMixinApplication() => null; | 181 MixinApplication asMixinApplication() => null; |
| 179 Modifiers asModifiers() => null; | 182 Modifiers asModifiers() => null; |
| 180 NamedArgument asNamedArgument() => null; | 183 NamedArgument asNamedArgument() => null; |
| 181 NamedMixinApplication asNamedMixinApplication() => null; | 184 NamedMixinApplication asNamedMixinApplication() => null; |
| 182 NewExpression asNewExpression() => null; | 185 NewExpression asNewExpression() => null; |
| 183 NodeList asNodeList() => null; | 186 NodeList asNodeList() => null; |
| 184 Operator asOperator() => null; | 187 Operator asOperator() => null; |
| 185 ParenthesizedExpression asParenthesizedExpression() => null; | 188 ParenthesizedExpression asParenthesizedExpression() => null; |
| 186 Part asPart() => null; | 189 Part asPart() => null; |
| 187 PartOf asPartOf() => null; | 190 PartOf asPartOf() => null; |
| 191 RedirectingFactoryBody asRedirectingFactoryBody() => null; |
| 188 Rethrow asRethrow() => null; | 192 Rethrow asRethrow() => null; |
| 189 Return asReturn() => null; | 193 Return asReturn() => null; |
| 190 Send asSend() => null; | 194 Send asSend() => null; |
| 191 SendSet asSendSet() => null; | 195 SendSet asSendSet() => null; |
| 192 Statement asStatement() => null; | 196 Statement asStatement() => null; |
| 193 StringInterpolation asStringInterpolation() => null; | 197 StringInterpolation asStringInterpolation() => null; |
| 194 StringInterpolationPart asStringInterpolationPart() => null; | 198 StringInterpolationPart asStringInterpolationPart() => null; |
| 195 StringJuxtaposition asStringJuxtaposition() => null; | 199 StringJuxtaposition asStringJuxtaposition() => null; |
| 196 StringNode asStringNode() => null; | 200 StringNode asStringNode() => null; |
| 197 SwitchCase asSwitchCase() => null; | 201 SwitchCase asSwitchCase() => null; |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 bool get isErroneous => true; | 335 bool get isErroneous => true; |
| 332 } | 336 } |
| 333 | 337 |
| 334 /** | 338 /** |
| 335 * A message send aka method invocation. In Dart, most operations can | 339 * A message send aka method invocation. In Dart, most operations can |
| 336 * (and should) be considered as message sends. Getters and setters | 340 * (and should) be considered as message sends. Getters and setters |
| 337 * are just methods with a special syntax. Consequently, we model | 341 * are just methods with a special syntax. Consequently, we model |
| 338 * property access, assignment, operators, and method calls with this | 342 * property access, assignment, operators, and method calls with this |
| 339 * one node. | 343 * one node. |
| 340 */ | 344 */ |
| 341 class Send extends Expression { | 345 class Send extends Expression with StoredTreeElementMixin { |
| 342 final Node receiver; | 346 final Node receiver; |
| 343 final Node selector; | 347 final Node selector; |
| 344 final NodeList argumentsNode; | 348 final NodeList argumentsNode; |
| 345 Link<Node> get arguments => argumentsNode.nodes; | 349 Link<Node> get arguments => argumentsNode.nodes; |
| 346 | 350 |
| 347 Send([this.receiver, this.selector, this.argumentsNode]); | 351 Send([this.receiver, this.selector, this.argumentsNode]); |
| 348 Send.postfix(this.receiver, this.selector, [Node argument = null]) | 352 Send.postfix(this.receiver, this.selector, [Node argument = null]) |
| 349 : argumentsNode = (argument == null) | 353 : argumentsNode = (argument == null) |
| 350 ? new Postfix() | 354 ? new Postfix() |
| 351 : new Postfix.singleton(argument); | 355 : new Postfix.singleton(argument); |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 FunctionDeclaration asFunctionDeclaration() => this; | 698 FunctionDeclaration asFunctionDeclaration() => this; |
| 695 | 699 |
| 696 accept(Visitor visitor) => visitor.visitFunctionDeclaration(this); | 700 accept(Visitor visitor) => visitor.visitFunctionDeclaration(this); |
| 697 | 701 |
| 698 visitChildren(Visitor visitor) => function.accept(visitor); | 702 visitChildren(Visitor visitor) => function.accept(visitor); |
| 699 | 703 |
| 700 Token getBeginToken() => function.getBeginToken(); | 704 Token getBeginToken() => function.getBeginToken(); |
| 701 Token getEndToken() => function.getEndToken(); | 705 Token getEndToken() => function.getEndToken(); |
| 702 } | 706 } |
| 703 | 707 |
| 704 class FunctionExpression extends Expression { | 708 class FunctionExpression extends Expression with StoredTreeElementMixin { |
| 705 final Node name; | 709 final Node name; |
| 706 | 710 |
| 707 /** | 711 /** |
| 708 * List of VariableDefinitions or NodeList. | 712 * List of VariableDefinitions or NodeList. |
| 709 * | 713 * |
| 710 * A NodeList can only occur at the end and holds named parameters. | 714 * A NodeList can only occur at the end and holds named parameters. |
| 711 */ | 715 */ |
| 712 final NodeList parameters; | 716 final NodeList parameters; |
| 713 | 717 |
| 714 final Statement body; | 718 final Statement body; |
| 715 final TypeAnnotation returnType; | 719 final TypeAnnotation returnType; |
| 716 final Modifiers modifiers; | 720 final Modifiers modifiers; |
| 717 final NodeList initializers; | 721 final NodeList initializers; |
| 718 | 722 |
| 719 final Token getOrSet; | 723 final Token getOrSet; |
| 720 | 724 |
| 721 FunctionExpression(this.name, this.parameters, this.body, this.returnType, | 725 FunctionExpression(this.name, this.parameters, this.body, this.returnType, |
| 722 this.modifiers, this.initializers, this.getOrSet) { | 726 this.modifiers, this.initializers, this.getOrSet) { |
| 723 assert(modifiers != null); | 727 assert(modifiers != null); |
| 724 } | 728 } |
| 725 | 729 |
| 726 FunctionExpression asFunctionExpression() => this; | 730 FunctionExpression asFunctionExpression() => this; |
| 727 | 731 |
| 728 accept(Visitor visitor) => visitor.visitFunctionExpression(this); | 732 accept(Visitor visitor) => visitor.visitFunctionExpression(this); |
| 729 | 733 |
| 730 bool get isRedirectingFactory { | 734 bool get isRedirectingFactory { |
| 731 return body != null && body.asReturn() != null && | 735 return body != null && body.asRedirectingFactoryBody() != null; |
| 732 body.asReturn().isRedirectingFactoryBody; | |
| 733 } | 736 } |
| 734 | 737 |
| 735 visitChildren(Visitor visitor) { | 738 visitChildren(Visitor visitor) { |
| 736 if (modifiers != null) modifiers.accept(visitor); | 739 if (modifiers != null) modifiers.accept(visitor); |
| 737 if (returnType != null) returnType.accept(visitor); | 740 if (returnType != null) returnType.accept(visitor); |
| 738 if (name != null) name.accept(visitor); | 741 if (name != null) name.accept(visitor); |
| 739 if (parameters != null) parameters.accept(visitor); | 742 if (parameters != null) parameters.accept(visitor); |
| 740 if (initializers != null) initializers.accept(visitor); | 743 if (initializers != null) initializers.accept(visitor); |
| 741 if (body != null) body.accept(visitor); | 744 if (body != null) body.accept(visitor); |
| 742 } | 745 } |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 968 | 971 |
| 969 Token getEndToken() => identifiers.getEndToken(); | 972 Token getEndToken() => identifiers.getEndToken(); |
| 970 | 973 |
| 971 String get slowNameString { | 974 String get slowNameString { |
| 972 Unparser unparser = new Unparser(); | 975 Unparser unparser = new Unparser(); |
| 973 unparser.unparseNodeListOfIdentifiers(identifiers); | 976 unparser.unparseNodeListOfIdentifiers(identifiers); |
| 974 return unparser.result; | 977 return unparser.result; |
| 975 } | 978 } |
| 976 } | 979 } |
| 977 | 980 |
| 978 class Identifier extends Expression { | 981 class Identifier extends Expression with StoredTreeElementMixin { |
| 979 final Token token; | 982 final Token token; |
| 980 | 983 |
| 981 String get source => token.value; | 984 String get source => token.value; |
| 982 | 985 |
| 983 Identifier(Token this.token); | 986 Identifier(Token this.token); |
| 984 | 987 |
| 985 bool isThis() => identical(source, 'this'); | 988 bool isThis() => identical(source, 'this'); |
| 986 | 989 |
| 987 bool isSuper() => identical(source, 'super'); | 990 bool isSuper() => identical(source, 'super'); |
| 988 | 991 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1015 final Node expression; | 1018 final Node expression; |
| 1016 final Token beginToken; | 1019 final Token beginToken; |
| 1017 final Token endToken; | 1020 final Token endToken; |
| 1018 | 1021 |
| 1019 Return(this.beginToken, this.endToken, this.expression); | 1022 Return(this.beginToken, this.endToken, this.expression); |
| 1020 | 1023 |
| 1021 Return asReturn() => this; | 1024 Return asReturn() => this; |
| 1022 | 1025 |
| 1023 bool get hasExpression => expression != null; | 1026 bool get hasExpression => expression != null; |
| 1024 | 1027 |
| 1025 bool get isRedirectingFactoryBody => beginToken.stringValue == '='; | |
| 1026 | |
| 1027 accept(Visitor visitor) => visitor.visitReturn(this); | 1028 accept(Visitor visitor) => visitor.visitReturn(this); |
| 1028 | 1029 |
| 1029 visitChildren(Visitor visitor) { | 1030 visitChildren(Visitor visitor) { |
| 1030 if (expression != null) expression.accept(visitor); | 1031 if (expression != null) expression.accept(visitor); |
| 1031 } | 1032 } |
| 1032 | 1033 |
| 1033 Token getBeginToken() => beginToken; | 1034 Token getBeginToken() => beginToken; |
| 1034 | 1035 |
| 1035 Token getEndToken() { | 1036 Token getEndToken() { |
| 1036 if (endToken == null) return expression.getEndToken(); | 1037 if (endToken == null) return expression.getEndToken(); |
| 1037 return endToken; | 1038 return endToken; |
| 1038 } | 1039 } |
| 1039 } | 1040 } |
| 1040 | 1041 |
| 1042 class RedirectingFactoryBody extends Statement with StoredTreeElementMixin { |
| 1043 final Node constructorReference; |
| 1044 final Token beginToken; |
| 1045 final Token endToken; |
| 1046 |
| 1047 RedirectingFactoryBody(this.beginToken, this.endToken, |
| 1048 this.constructorReference); |
| 1049 |
| 1050 RedirectingFactoryBody asRedirectingFactoryBody() => this; |
| 1051 |
| 1052 accept(Visitor visitor) => visitor.visitRedirectingFactoryBody(this); |
| 1053 |
| 1054 visitChildren(Visitor visitor) { |
| 1055 constructorReference.accept(visitor); |
| 1056 } |
| 1057 |
| 1058 Token getBeginToken() => beginToken; |
| 1059 |
| 1060 Token getEndToken() => endToken; |
| 1061 } |
| 1062 |
| 1041 class ExpressionStatement extends Statement { | 1063 class ExpressionStatement extends Statement { |
| 1042 final Expression expression; | 1064 final Expression expression; |
| 1043 final Token endToken; | 1065 final Token endToken; |
| 1044 | 1066 |
| 1045 ExpressionStatement(this.expression, this.endToken); | 1067 ExpressionStatement(this.expression, this.endToken); |
| 1046 | 1068 |
| 1047 ExpressionStatement asExpressionStatement() => this; | 1069 ExpressionStatement asExpressionStatement() => this; |
| 1048 | 1070 |
| 1049 accept(Visitor visitor) => visitor.visitExpressionStatement(this); | 1071 accept(Visitor visitor) => visitor.visitExpressionStatement(this); |
| 1050 | 1072 |
| (...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1658 | 1680 |
| 1659 class ContinueStatement extends GotoStatement { | 1681 class ContinueStatement extends GotoStatement { |
| 1660 ContinueStatement(Identifier target, Token keywordToken, Token semicolonToken) | 1682 ContinueStatement(Identifier target, Token keywordToken, Token semicolonToken) |
| 1661 : super(target, keywordToken, semicolonToken); | 1683 : super(target, keywordToken, semicolonToken); |
| 1662 | 1684 |
| 1663 ContinueStatement asContinueStatement() => this; | 1685 ContinueStatement asContinueStatement() => this; |
| 1664 | 1686 |
| 1665 accept(Visitor visitor) => visitor.visitContinueStatement(this); | 1687 accept(Visitor visitor) => visitor.visitContinueStatement(this); |
| 1666 } | 1688 } |
| 1667 | 1689 |
| 1668 class ForIn extends Loop { | 1690 class ForIn extends Loop with StoredTreeElementMixin { |
| 1669 final Node declaredIdentifier; | 1691 final Node declaredIdentifier; |
| 1670 final Expression expression; | 1692 final Expression expression; |
| 1671 | 1693 |
| 1672 final Token forToken; | 1694 final Token forToken; |
| 1673 final Token inToken; | 1695 final Token inToken; |
| 1674 | 1696 |
| 1675 ForIn(this.declaredIdentifier, this.expression, | 1697 ForIn(this.declaredIdentifier, this.expression, |
| 1676 Statement body, this.forToken, this.inToken) : super(body); | 1698 Statement body, this.forToken, this.inToken) : super(body); |
| 1677 | 1699 |
| 1678 Expression get condition => null; | 1700 Expression get condition => null; |
| (...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2155 | 2177 |
| 2156 // VariableDefinitions. | 2178 // VariableDefinitions. |
| 2157 get metadata => null; | 2179 get metadata => null; |
| 2158 get type => null; | 2180 get type => null; |
| 2159 | 2181 |
| 2160 // Typedef. | 2182 // Typedef. |
| 2161 get typeParameters => null; | 2183 get typeParameters => null; |
| 2162 get formals => null; | 2184 get formals => null; |
| 2163 get typedefKeyword => null; | 2185 get typedefKeyword => null; |
| 2164 } | 2186 } |
| OLD | NEW |