| 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 30 matching lines...) Expand all Loading... |
| 41 R visitLiteralBool(LiteralBool node) => visitLiteral(node); | 41 R visitLiteralBool(LiteralBool node) => visitLiteral(node); |
| 42 R visitLiteralDouble(LiteralDouble node) => visitLiteral(node); | 42 R visitLiteralDouble(LiteralDouble node) => visitLiteral(node); |
| 43 R visitLiteralInt(LiteralInt node) => visitLiteral(node); | 43 R visitLiteralInt(LiteralInt node) => visitLiteral(node); |
| 44 R visitLiteralList(LiteralList node) => visitExpression(node); | 44 R visitLiteralList(LiteralList node) => visitExpression(node); |
| 45 R visitLiteralMap(LiteralMap node) => visitExpression(node); | 45 R visitLiteralMap(LiteralMap node) => visitExpression(node); |
| 46 R visitLiteralMapEntry(LiteralMapEntry node) => visitNode(node); | 46 R visitLiteralMapEntry(LiteralMapEntry node) => visitNode(node); |
| 47 R visitLiteralNull(LiteralNull node) => visitLiteral(node); | 47 R visitLiteralNull(LiteralNull node) => visitLiteral(node); |
| 48 R visitLiteralString(LiteralString node) => visitStringNode(node); | 48 R visitLiteralString(LiteralString node) => visitStringNode(node); |
| 49 R visitStringJuxtaposition(StringJuxtaposition node) => visitStringNode(node); | 49 R visitStringJuxtaposition(StringJuxtaposition node) => visitStringNode(node); |
| 50 R visitLoop(Loop node) => visitStatement(node); | 50 R visitLoop(Loop node) => visitStatement(node); |
| 51 R visitMetadata(Metadata node) => visitNode(node); |
| 51 R visitMixinApplication(MixinApplication node) => visitNode(node); | 52 R visitMixinApplication(MixinApplication node) => visitNode(node); |
| 52 R visitModifiers(Modifiers node) => visitNode(node); | 53 R visitModifiers(Modifiers node) => visitNode(node); |
| 53 R visitNamedArgument(NamedArgument node) => visitExpression(node); | 54 R visitNamedArgument(NamedArgument node) => visitExpression(node); |
| 54 R visitNamedMixinApplication(NamedMixinApplication node) { | 55 R visitNamedMixinApplication(NamedMixinApplication node) { |
| 55 return visitMixinApplication(node); | 56 return visitMixinApplication(node); |
| 56 } | 57 } |
| 57 R visitNewExpression(NewExpression node) => visitExpression(node); | 58 R visitNewExpression(NewExpression node) => visitExpression(node); |
| 58 R visitNodeList(NodeList node) => visitNode(node); | 59 R visitNodeList(NodeList node) => visitNode(node); |
| 59 R visitOperator(Operator node) => visitIdentifier(node); | 60 R visitOperator(Operator node) => visitIdentifier(node); |
| 60 R visitParenthesizedExpression(ParenthesizedExpression node) { | 61 R visitParenthesizedExpression(ParenthesizedExpression node) { |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 LibraryDependency asLibraryDependency() => null; | 167 LibraryDependency asLibraryDependency() => null; |
| 167 LiteralBool asLiteralBool() => null; | 168 LiteralBool asLiteralBool() => null; |
| 168 LiteralDouble asLiteralDouble() => null; | 169 LiteralDouble asLiteralDouble() => null; |
| 169 LiteralInt asLiteralInt() => null; | 170 LiteralInt asLiteralInt() => null; |
| 170 LiteralList asLiteralList() => null; | 171 LiteralList asLiteralList() => null; |
| 171 LiteralMap asLiteralMap() => null; | 172 LiteralMap asLiteralMap() => null; |
| 172 LiteralMapEntry asLiteralMapEntry() => null; | 173 LiteralMapEntry asLiteralMapEntry() => null; |
| 173 LiteralNull asLiteralNull() => null; | 174 LiteralNull asLiteralNull() => null; |
| 174 LiteralString asLiteralString() => null; | 175 LiteralString asLiteralString() => null; |
| 175 LiteralSymbol asLiteralSymbol() => null; | 176 LiteralSymbol asLiteralSymbol() => null; |
| 177 Metadata asMetadata() => null; |
| 176 MixinApplication asMixinApplication() => null; | 178 MixinApplication asMixinApplication() => null; |
| 177 Modifiers asModifiers() => null; | 179 Modifiers asModifiers() => null; |
| 178 NamedArgument asNamedArgument() => null; | 180 NamedArgument asNamedArgument() => null; |
| 179 NamedMixinApplication asNamedMixinApplication() => null; | 181 NamedMixinApplication asNamedMixinApplication() => null; |
| 180 NewExpression asNewExpression() => null; | 182 NewExpression asNewExpression() => null; |
| 181 NodeList asNodeList() => null; | 183 NodeList asNodeList() => null; |
| 182 Operator asOperator() => null; | 184 Operator asOperator() => null; |
| 183 ParenthesizedExpression asParenthesizedExpression() => null; | 185 ParenthesizedExpression asParenthesizedExpression() => null; |
| 184 Part asPart() => null; | 186 Part asPart() => null; |
| 185 PartOf asPartOf() => null; | 187 PartOf asPartOf() => null; |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 return super.getBeginToken(); | 474 return super.getBeginToken(); |
| 473 } | 475 } |
| 474 | 476 |
| 475 Token getEndToken() { | 477 Token getEndToken() { |
| 476 if (isPostfix) return assignmentOperator.getEndToken(); | 478 if (isPostfix) return assignmentOperator.getEndToken(); |
| 477 return super.getEndToken(); | 479 return super.getEndToken(); |
| 478 } | 480 } |
| 479 } | 481 } |
| 480 | 482 |
| 481 class NewExpression extends Expression { | 483 class NewExpression extends Expression { |
| 482 /** The token NEW or CONST */ | 484 /** The token NEW or CONST or `null` for metadata */ |
| 483 final Token newToken; | 485 final Token newToken; |
| 484 | 486 |
| 485 // Note: we expect that send.receiver is null. | 487 // Note: we expect that send.receiver is null. |
| 486 final Send send; | 488 final Send send; |
| 487 | 489 |
| 488 NewExpression([this.newToken, this.send]); | 490 NewExpression([this.newToken, this.send]); |
| 489 | 491 |
| 490 NewExpression asNewExpression() => this; | 492 NewExpression asNewExpression() => this; |
| 491 | 493 |
| 492 accept(Visitor visitor) => visitor.visitNewExpression(this); | 494 accept(Visitor visitor) => visitor.visitNewExpression(this); |
| 493 | 495 |
| 494 visitChildren(Visitor visitor) { | 496 visitChildren(Visitor visitor) { |
| 495 if (send != null) send.accept(visitor); | 497 if (send != null) send.accept(visitor); |
| 496 } | 498 } |
| 497 | 499 |
| 498 bool isConst() { | 500 bool isConst() { |
| 499 return identical(newToken.stringValue, 'const') | 501 return newToken == null || identical(newToken.stringValue, 'const'); |
| 500 || identical(newToken.stringValue, '@'); | |
| 501 } | 502 } |
| 502 | 503 |
| 503 Token getBeginToken() => newToken; | 504 Token getBeginToken() => newToken != null ? newToken : send.getBeginToken(); |
| 504 | 505 |
| 505 Token getEndToken() => send.getEndToken(); | 506 Token getEndToken() => send.getEndToken(); |
| 506 } | 507 } |
| 507 | 508 |
| 508 class NodeList extends Node { | 509 class NodeList extends Node { |
| 509 final Link<Node> nodes; | 510 final Link<Node> nodes; |
| 510 final Token beginToken; | 511 final Token beginToken; |
| 511 final Token endToken; | 512 final Token endToken; |
| 512 final String delimiter; | 513 final String delimiter; |
| 513 bool get isEmpty => nodes.isEmpty; | 514 bool get isEmpty => nodes.isEmpty; |
| (...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1129 TypeVariable asTypeVariable() => this; | 1130 TypeVariable asTypeVariable() => this; |
| 1130 | 1131 |
| 1131 Token getBeginToken() => name.getBeginToken(); | 1132 Token getBeginToken() => name.getBeginToken(); |
| 1132 | 1133 |
| 1133 Token getEndToken() { | 1134 Token getEndToken() { |
| 1134 return (bound != null) ? bound.getEndToken() : name.getEndToken(); | 1135 return (bound != null) ? bound.getEndToken() : name.getEndToken(); |
| 1135 } | 1136 } |
| 1136 } | 1137 } |
| 1137 | 1138 |
| 1138 class VariableDefinitions extends Statement { | 1139 class VariableDefinitions extends Statement { |
| 1140 final NodeList metadata; |
| 1139 final TypeAnnotation type; | 1141 final TypeAnnotation type; |
| 1140 final Modifiers modifiers; | 1142 final Modifiers modifiers; |
| 1141 final NodeList definitions; | 1143 final NodeList definitions; |
| 1142 VariableDefinitions(this.type, this.modifiers, this.definitions) { | 1144 |
| 1145 VariableDefinitions(this.type, |
| 1146 this.modifiers, |
| 1147 this.definitions) |
| 1148 : this.metadata = null { |
| 1143 assert(modifiers != null); | 1149 assert(modifiers != null); |
| 1144 } | 1150 } |
| 1145 | 1151 |
| 1152 // TODO(johnniwinther): Make this its own node type. |
| 1153 VariableDefinitions.forParameter(this.metadata, |
| 1154 this.type, |
| 1155 this.modifiers, |
| 1156 this.definitions) { |
| 1157 assert(modifiers != null); |
| 1158 } |
| 1159 |
| 1146 VariableDefinitions asVariableDefinitions() => this; | 1160 VariableDefinitions asVariableDefinitions() => this; |
| 1147 | 1161 |
| 1148 accept(Visitor visitor) => visitor.visitVariableDefinitions(this); | 1162 accept(Visitor visitor) => visitor.visitVariableDefinitions(this); |
| 1149 | 1163 |
| 1150 visitChildren(Visitor visitor) { | 1164 visitChildren(Visitor visitor) { |
| 1151 if (type != null) type.accept(visitor); | 1165 if (type != null) type.accept(visitor); |
| 1152 if (definitions != null) definitions.accept(visitor); | 1166 if (definitions != null) definitions.accept(visitor); |
| 1153 } | 1167 } |
| 1154 | 1168 |
| 1155 Token getBeginToken() { | 1169 Token getBeginToken() { |
| (...skipping 885 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2041 if (type != null) type.accept(visitor); | 2055 if (type != null) type.accept(visitor); |
| 2042 if (formals != null) formals.accept(visitor); | 2056 if (formals != null) formals.accept(visitor); |
| 2043 block.accept(visitor); | 2057 block.accept(visitor); |
| 2044 } | 2058 } |
| 2045 | 2059 |
| 2046 Token getBeginToken() => onKeyword != null ? onKeyword : catchKeyword; | 2060 Token getBeginToken() => onKeyword != null ? onKeyword : catchKeyword; |
| 2047 | 2061 |
| 2048 Token getEndToken() => block.getEndToken(); | 2062 Token getEndToken() => block.getEndToken(); |
| 2049 } | 2063 } |
| 2050 | 2064 |
| 2065 class Metadata extends Node { |
| 2066 final Token token; |
| 2067 final Expression expression; |
| 2068 |
| 2069 Metadata(this.token, this.expression); |
| 2070 |
| 2071 Metadata asMetadata() => this; |
| 2072 |
| 2073 accept(Visitor visitor) => visitor.visitMetadata(this); |
| 2074 |
| 2075 visitChildren(Visitor visitor) { |
| 2076 expression.accept(visitor); |
| 2077 } |
| 2078 |
| 2079 Token getBeginToken() => token; |
| 2080 |
| 2081 Token getEndToken() => expression.getEndToken(); |
| 2082 } |
| 2083 |
| 2051 class Initializers { | 2084 class Initializers { |
| 2052 static bool isSuperConstructorCall(Send node) { | 2085 static bool isSuperConstructorCall(Send node) { |
| 2053 return (node.receiver == null && node.selector.isSuper()) || | 2086 return (node.receiver == null && node.selector.isSuper()) || |
| 2054 (node.receiver != null && | 2087 (node.receiver != null && |
| 2055 node.receiver.isSuper() && | 2088 node.receiver.isSuper() && |
| 2056 node.selector.asIdentifier() != null); | 2089 node.selector.asIdentifier() != null); |
| 2057 } | 2090 } |
| 2058 | 2091 |
| 2059 static bool isConstructorRedirect(Send node) { | 2092 static bool isConstructorRedirect(Send node) { |
| 2060 return (node.receiver == null && node.selector.isThis()) || | 2093 return (node.receiver == null && node.selector.isThis()) || |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2085 * argument). | 2118 * argument). |
| 2086 * | 2119 * |
| 2087 * TODO(ahe): This method is controversial, the team needs to discuss | 2120 * TODO(ahe): This method is controversial, the team needs to discuss |
| 2088 * if top-level methods are acceptable and what naming conventions to | 2121 * if top-level methods are acceptable and what naming conventions to |
| 2089 * use. | 2122 * use. |
| 2090 */ | 2123 */ |
| 2091 initializerDo(Node node, f(Node node)) { | 2124 initializerDo(Node node, f(Node node)) { |
| 2092 SendSet send = node.asSendSet(); | 2125 SendSet send = node.asSendSet(); |
| 2093 if (send != null) return f(send.arguments.head); | 2126 if (send != null) return f(send.arguments.head); |
| 2094 } | 2127 } |
| OLD | NEW |