Chromium Code Reviews| 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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 TypeAnnotation asTypeAnnotation() => null; | 201 TypeAnnotation asTypeAnnotation() => null; |
| 202 TypeVariable asTypeVariable() => null; | 202 TypeVariable asTypeVariable() => null; |
| 203 Typedef asTypedef() => null; | 203 Typedef asTypedef() => null; |
| 204 VariableDefinitions asVariableDefinitions() => null; | 204 VariableDefinitions asVariableDefinitions() => null; |
| 205 While asWhile() => null; | 205 While asWhile() => null; |
| 206 | 206 |
| 207 bool isValidBreakTarget() => false; | 207 bool isValidBreakTarget() => false; |
| 208 bool isValidContinueTarget() => false; | 208 bool isValidContinueTarget() => false; |
| 209 bool isThis() => false; | 209 bool isThis() => false; |
| 210 bool isSuper() => false; | 210 bool isSuper() => false; |
| 211 | |
| 212 bool get isErroneous => false; | |
| 211 } | 213 } |
| 212 | 214 |
| 213 class ClassNode extends Node { | 215 class ClassNode extends Node { |
| 214 final Modifiers modifiers; | 216 final Modifiers modifiers; |
| 215 final Identifier name; | 217 final Identifier name; |
| 216 final Node superclass; | 218 final Node superclass; |
| 217 final NodeList interfaces; | 219 final NodeList interfaces; |
| 218 final NodeList typeParameters; | 220 final NodeList typeParameters; |
| 219 final NodeList body; | 221 final NodeList body; |
| 220 | 222 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 312 Statement(); | 314 Statement(); |
| 313 | 315 |
| 314 Statement asStatement() => this; | 316 Statement asStatement() => this; |
| 315 | 317 |
| 316 // TODO(ahe): make class abstract instead of adding an abstract method. | 318 // TODO(ahe): make class abstract instead of adding an abstract method. |
| 317 accept(Visitor visitor); | 319 accept(Visitor visitor); |
| 318 | 320 |
| 319 bool isValidBreakTarget() => true; | 321 bool isValidBreakTarget() => true; |
| 320 } | 322 } |
| 321 | 323 |
| 322 /// Errorneous expression that behaves as a literal null. | 324 /// Errorneous expression that behaves as a literal null. |
|
ahe
2014/06/18 06:52:52
Also fixed here :-)
| |
| 323 class ErrorExpression extends LiteralNull { | 325 class ErrorExpression extends LiteralNull { |
| 324 ErrorExpression(token) | 326 ErrorExpression(token) |
| 325 : super(token); | 327 : super(token); |
| 326 | 328 |
| 327 ErrorExpression asErrorExpression() => this; | 329 ErrorExpression asErrorExpression() => this; |
| 330 | |
| 331 bool get isErroneous => true; | |
| 328 } | 332 } |
| 329 | 333 |
| 330 /** | 334 /** |
| 331 * A message send aka method invocation. In Dart, most operations can | 335 * A message send aka method invocation. In Dart, most operations can |
| 332 * (and should) be considered as message sends. Getters and setters | 336 * (and should) be considered as message sends. Getters and setters |
| 333 * are just methods with a special syntax. Consequently, we model | 337 * are just methods with a special syntax. Consequently, we model |
| 334 * property access, assignment, operators, and method calls with this | 338 * property access, assignment, operators, and method calls with this |
| 335 * one node. | 339 * one node. |
| 336 */ | 340 */ |
| 337 class Send extends Expression { | 341 class Send extends Expression { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 408 return firstBeginToken(receiver, selector); | 412 return firstBeginToken(receiver, selector); |
| 409 } | 413 } |
| 410 | 414 |
| 411 Token getEndToken() { | 415 Token getEndToken() { |
| 412 if (isPrefix) { | 416 if (isPrefix) { |
| 413 if (receiver != null) return receiver.getEndToken(); | 417 if (receiver != null) return receiver.getEndToken(); |
| 414 if (selector != null) return selector.getEndToken(); | 418 if (selector != null) return selector.getEndToken(); |
| 415 return null; | 419 return null; |
| 416 } | 420 } |
| 417 if (!isPostfix && argumentsNode != null) { | 421 if (!isPostfix && argumentsNode != null) { |
| 418 return argumentsNode.getEndToken(); | 422 Token token = argumentsNode.getEndToken(); |
| 423 if (token != null) return token; | |
| 419 } | 424 } |
| 420 if (selector != null) return selector.getEndToken(); | 425 if (selector != null) return selector.getEndToken(); |
| 421 return receiver.getBeginToken(); | 426 return getBeginToken(); |
| 422 } | 427 } |
| 423 | 428 |
| 424 Send copyWithReceiver(Node newReceiver) { | 429 Send copyWithReceiver(Node newReceiver) { |
| 425 assert(receiver == null); | 430 assert(receiver == null); |
| 426 return new Send(newReceiver, selector, argumentsNode); | 431 return new Send(newReceiver, selector, argumentsNode); |
| 427 } | 432 } |
| 428 } | 433 } |
| 429 | 434 |
| 430 class Postfix extends NodeList { | 435 class Postfix extends NodeList { |
| 431 Postfix() : super(null, const Link<Node>()); | 436 Postfix() : super(null, const Link<Node>()); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 551 } | 556 } |
| 552 return endToken; | 557 return endToken; |
| 553 } | 558 } |
| 554 | 559 |
| 555 Token getEndToken() { | 560 Token getEndToken() { |
| 556 if (endToken != null) return endToken; | 561 if (endToken != null) return endToken; |
| 557 if (nodes != null) { | 562 if (nodes != null) { |
| 558 Link<Node> link = nodes; | 563 Link<Node> link = nodes; |
| 559 if (link.isEmpty) return beginToken; | 564 if (link.isEmpty) return beginToken; |
| 560 while (!link.tail.isEmpty) link = link.tail; | 565 while (!link.tail.isEmpty) link = link.tail; |
| 561 if (link.head.getEndToken() != null) return link.head.getEndToken(); | 566 if (link.head != null) { |
|
Johnni Winther
2014/06/17 06:13:18
Add a variable for `link.head`.
ahe
2014/06/18 06:52:53
Done.
| |
| 562 if (link.head.getBeginToken() != null) return link.head.getBeginToken(); | 567 if (link.head.getEndToken() != null) return link.head.getEndToken(); |
| 568 if (link.head.getBeginToken() != null) return link.head.getBeginToken(); | |
| 569 } | |
| 563 } | 570 } |
| 564 return beginToken; | 571 return beginToken; |
| 565 } | 572 } |
| 566 } | 573 } |
| 567 | 574 |
| 568 class Block extends Statement { | 575 class Block extends Statement { |
| 569 final NodeList statements; | 576 final NodeList statements; |
| 570 | 577 |
| 571 Block(this.statements); | 578 Block(this.statements); |
| 572 | 579 |
| (...skipping 1534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2107 } | 2114 } |
| 2108 | 2115 |
| 2109 class IsInterpolationVisitor extends Visitor<bool> { | 2116 class IsInterpolationVisitor extends Visitor<bool> { |
| 2110 const IsInterpolationVisitor(); | 2117 const IsInterpolationVisitor(); |
| 2111 bool visitNode(Node node) => false; | 2118 bool visitNode(Node node) => false; |
| 2112 bool visitStringInterpolation(StringInterpolation node) => true; | 2119 bool visitStringInterpolation(StringInterpolation node) => true; |
| 2113 bool visitStringJuxtaposition(StringJuxtaposition node) | 2120 bool visitStringJuxtaposition(StringJuxtaposition node) |
| 2114 => node.isInterpolation; | 2121 => node.isInterpolation; |
| 2115 } | 2122 } |
| 2116 | 2123 |
| 2124 /// Errorneous node used to recover from parser errors. Implements various | |
|
Johnni Winther
2014/06/17 06:13:18
'Errorneous' -> 'Erroneous'
ahe
2014/06/18 06:52:52
Done.
| |
| 2125 /// interfaces and provides bare minimum of implementation to avoid unnecessary | |
| 2126 /// messages. | |
| 2127 class ErrorNode | |
| 2128 extends Node | |
| 2129 implements FunctionExpression, VariableDefinitions, Typedef { | |
| 2130 final Token token; | |
| 2131 final String reason; | |
| 2132 final Identifier name; | |
| 2133 final NodeList definitions; | |
| 2134 | |
| 2135 ErrorNode.internal(this.token, this.reason, this.name, this.definitions); | |
| 2136 | |
| 2137 factory ErrorNode(Token token, String reason) { | |
| 2138 Identifier name = new Identifier(token); | |
| 2139 NodeList definitions = new NodeList( | |
| 2140 null, const Link<Node>().prepend(name), null, null); | |
| 2141 return new ErrorNode.internal(token, reason, name, definitions); | |
| 2142 } | |
| 2143 | |
| 2144 Token get beginToken => token; | |
| 2145 Token get endToken => token; | |
| 2146 | |
| 2147 Token getBeginToken() => token; | |
| 2148 | |
| 2149 Token getEndToken() => token; | |
| 2150 | |
| 2151 accept(Visitor visitor) {} | |
| 2152 | |
| 2153 visitChildren(Visitor visitor) {} | |
| 2154 | |
| 2155 bool get isErroneous => true; | |
| 2156 | |
| 2157 // FunctionExpression. | |
| 2158 get parameters => null; | |
| 2159 get body => null; | |
| 2160 get returnType => null; | |
| 2161 get modifiers => Modifiers.EMPTY; | |
| 2162 get initializers => null; | |
| 2163 get getOrSet => null; | |
| 2164 get isRedirectingFactory => false; | |
| 2165 bool hasBody() => false; | |
| 2166 bool hasEmptyBody() => false; | |
| 2167 | |
| 2168 // VariableDefinitions. | |
| 2169 get metadata => null; | |
| 2170 get type => null; | |
| 2171 | |
| 2172 // Typedef. | |
| 2173 get typeParameters => null; | |
| 2174 get formals => null; | |
| 2175 get typedefKeyword => null; | |
| 2176 } | |
| OLD | NEW |