| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 interface Visitor<R> { | 5 interface Visitor<R> { |
| 6 R visitBlock(Block node); | 6 R visitBlock(Block node); |
| 7 R visitBreakStatement(BreakStatement node); | 7 R visitBreakStatement(BreakStatement node); |
| 8 R visitCatchBlock(CatchBlock node); | 8 R visitCatchBlock(CatchBlock node); |
| 9 R visitClassNode(ClassNode node); | 9 R visitClassNode(ClassNode node); |
| 10 R visitConditional(Conditional node); | 10 R visitConditional(Conditional node); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 StringInterpolation asStringInterpolation() => null; | 139 StringInterpolation asStringInterpolation() => null; |
| 140 StringInterpolationPart asStringInterpolationPart() => null; | 140 StringInterpolationPart asStringInterpolationPart() => null; |
| 141 SwitchCase asSwitchCase() => null; | 141 SwitchCase asSwitchCase() => null; |
| 142 SwitchStatement asSwitchStatement() => null; | 142 SwitchStatement asSwitchStatement() => null; |
| 143 Throw asThrow() => null; | 143 Throw asThrow() => null; |
| 144 TryStatement asTryStatement() => null; | 144 TryStatement asTryStatement() => null; |
| 145 TypeAnnotation asTypeAnnotation() => null; | 145 TypeAnnotation asTypeAnnotation() => null; |
| 146 Typedef asTypedef() => null; | 146 Typedef asTypedef() => null; |
| 147 VariableDefinitions asVariableDefinitions() => null; | 147 VariableDefinitions asVariableDefinitions() => null; |
| 148 While asWhile() => null; | 148 While asWhile() => null; |
| 149 |
| 150 bool isValidBreakTarget() => false; |
| 151 bool isValidContinueTarget() => false; |
| 149 } | 152 } |
| 150 | 153 |
| 151 class ClassNode extends Node { | 154 class ClassNode extends Node { |
| 152 final Identifier name; | 155 final Identifier name; |
| 153 final TypeAnnotation superclass; | 156 final TypeAnnotation superclass; |
| 154 final NodeList interfaces; | 157 final NodeList interfaces; |
| 155 | 158 |
| 156 // Using a NodeList to record the keyword "default". | 159 // Using a NodeList to record the keyword "default". |
| 157 // TODO(ahe): Consider if there is a better way to represent this. | 160 // TODO(ahe): Consider if there is a better way to represent this. |
| 158 final NodeList defaultClause; | 161 final NodeList defaultClause; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 } | 196 } |
| 194 | 197 |
| 195 class Statement extends Node { | 198 class Statement extends Node { |
| 196 Statement(); | 199 Statement(); |
| 197 | 200 |
| 198 Statement asStatement() => this; | 201 Statement asStatement() => this; |
| 199 | 202 |
| 200 // TODO(ahe): make class abstract instead of adding an abstract method. | 203 // TODO(ahe): make class abstract instead of adding an abstract method. |
| 201 abstract accept(Visitor visitor); | 204 abstract accept(Visitor visitor); |
| 202 | 205 |
| 203 bool isValidContinueTarget() => false; | 206 bool isValidBreakTarget() => true; |
| 204 } | 207 } |
| 205 | 208 |
| 206 /** | 209 /** |
| 207 * A message send aka method invocation. In Dart, most operations can | 210 * A message send aka method invocation. In Dart, most operations can |
| 208 * (and should) be considered as message sends. Getters and setters | 211 * (and should) be considered as message sends. Getters and setters |
| 209 * are just methods with a special syntax. Consequently, we model | 212 * are just methods with a special syntax. Consequently, we model |
| 210 * property access, assignment, operators, and method calls with this | 213 * property access, assignment, operators, and method calls with this |
| 211 * one node. | 214 * one node. |
| 212 */ | 215 */ |
| 213 class Send extends Expression { | 216 class Send extends Expression { |
| (...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 741 if (other is !DartString) return false; | 744 if (other is !DartString) return false; |
| 742 DartString otherString = other; | 745 DartString otherString = other; |
| 743 if (length != otherString.length) return false; | 746 if (length != otherString.length) return false; |
| 744 Iterator it1 = iterator(); | 747 Iterator it1 = iterator(); |
| 745 Iterator it2 = otherString.iterator(); | 748 Iterator it2 = otherString.iterator(); |
| 746 while (it1.hasNext()) { | 749 while (it1.hasNext()) { |
| 747 if (it1.next() != it2.next()) return false; | 750 if (it1.next() != it2.next()) return false; |
| 748 } | 751 } |
| 749 return true; | 752 return true; |
| 750 } | 753 } |
| 751 String toString() => "DartString#${length()}:${slowToString()}"; | 754 String toString() => "DartString#${length}:${slowToString()}"; |
| 752 abstract SourceString get source(); | 755 abstract SourceString get source(); |
| 753 } | 756 } |
| 754 | 757 |
| 755 class LiteralDartString extends DartString { | 758 class LiteralDartString extends DartString { |
| 756 final String string; | 759 final String string; |
| 757 const LiteralDartString(this.string); | 760 const LiteralDartString(this.string); |
| 758 int get length() => string.length; | 761 int get length() => string.length; |
| 759 Iterator<int> iterator() => new StringCodeIterator(string); | 762 Iterator<int> iterator() => new StringCodeIterator(string); |
| 760 String slowToString() => string; | 763 String slowToString() => string; |
| 761 SourceString get source() => new StringWrapper(string); | 764 SourceString get source() => new StringWrapper(string); |
| (...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1400 cases.accept(visitor); | 1403 cases.accept(visitor); |
| 1401 } | 1404 } |
| 1402 | 1405 |
| 1403 Token getBeginToken() => switchKeyword; | 1406 Token getBeginToken() => switchKeyword; |
| 1404 | 1407 |
| 1405 Token getEndToken() => cases.getEndToken(); | 1408 Token getEndToken() => cases.getEndToken(); |
| 1406 } | 1409 } |
| 1407 | 1410 |
| 1408 class SwitchCase extends Node { | 1411 class SwitchCase extends Node { |
| 1409 final Identifier label; | 1412 final Identifier label; |
| 1410 final Expression expression; | 1413 final NodeList expressions; |
| 1414 final Token defaultKeyword; |
| 1411 final NodeList statements; | 1415 final NodeList statements; |
| 1412 | 1416 |
| 1413 final Token caseKeyword; | 1417 final Token startToken; |
| 1414 | 1418 |
| 1415 SwitchCase(this.label, this.expression, this.statements, this.caseKeyword); | 1419 SwitchCase(this.label, this.expressions, this.defaultKeyword, |
| 1420 this.statements, this.startToken); |
| 1416 | 1421 |
| 1417 SwitchCase asSwitchCase() => this; | 1422 SwitchCase asSwitchCase() => this; |
| 1418 | 1423 |
| 1424 bool get isDefaultCase() => defaultKeyword !== null; |
| 1425 |
| 1419 accept(Visitor visitor) => visitor.visitSwitchCase(this); | 1426 accept(Visitor visitor) => visitor.visitSwitchCase(this); |
| 1420 | 1427 |
| 1421 visitChildren(Visitor visitor) { | 1428 visitChildren(Visitor visitor) { |
| 1422 if (label !== null) label.accept(visitor); | 1429 if (label !== null) label.accept(visitor); |
| 1423 expression.accept(visitor); | 1430 expressions.accept(visitor); |
| 1424 statements.accept(visitor); | 1431 statements.accept(visitor); |
| 1425 } | 1432 } |
| 1426 | 1433 |
| 1427 Token getBeginToken() { | 1434 Token getBeginToken() { |
| 1428 if (label !== null) return label.getBeginToken(); | 1435 return startToken; |
| 1429 return caseKeyword; | |
| 1430 } | 1436 } |
| 1431 | 1437 |
| 1432 Token getEndToken() { | 1438 Token getEndToken() { |
| 1433 if (statements.nodes.isEmpty()) { | 1439 if (statements.nodes.isEmpty()) { |
| 1434 // The colon after the expression. | 1440 // The colon after the expression. |
| 1435 return expression.getEndToken().next; | 1441 return expressions.getEndToken().next; |
| 1436 } else { | 1442 } else { |
| 1437 return statements.getEndToken(); | 1443 return statements.getEndToken(); |
| 1438 } | 1444 } |
| 1439 } | |
| 1440 } | |
| 1441 | |
| 1442 class DefaultCase extends Node { | |
| 1443 final Identifier label; | |
| 1444 final NodeList statements; | |
| 1445 | |
| 1446 final Token defaultKeyword; | |
| 1447 | |
| 1448 DefaultCase(this.label, this.statements, this.defaultKeyword); | |
| 1449 | |
| 1450 DefaultCase asDefaultCase() => this; | |
| 1451 | |
| 1452 accept(Visitor visitor) => visitor.visitDefaultCase(this); | |
| 1453 | |
| 1454 visitChildren(Visitor visitor) { | |
| 1455 if (label !== null) label.accept(visitor); | |
| 1456 statements.accept(visitor); | |
| 1457 } | |
| 1458 | |
| 1459 Token getBeginToken() { | |
| 1460 if (label !== null) return label.getBeginToken(); | |
| 1461 return defaultKeyword; | |
| 1462 } | |
| 1463 | |
| 1464 Token getEndToken() { | |
| 1465 if (statements.nodes.isEmpty()) { | |
| 1466 // The colon after default. | |
| 1467 return defaultKeyword.next; | |
| 1468 } else { | |
| 1469 return statements.getEndToken(); | |
| 1470 } | |
| 1471 } | 1445 } |
| 1472 } | 1446 } |
| 1473 | 1447 |
| 1474 class GotoStatement extends Statement { | 1448 class GotoStatement extends Statement { |
| 1475 final Identifier target; | 1449 final Identifier target; |
| 1476 final Token keywordToken; | 1450 final Token keywordToken; |
| 1477 final Token semicolonToken; | 1451 final Token semicolonToken; |
| 1478 | 1452 |
| 1479 GotoStatement(this.target, this.keywordToken, this.semicolonToken); | 1453 GotoStatement(this.target, this.keywordToken, this.semicolonToken); |
| 1480 | 1454 |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1702 static bool isConstructorRedirect(Send node) { | 1676 static bool isConstructorRedirect(Send node) { |
| 1703 return (node.receiver === null && | 1677 return (node.receiver === null && |
| 1704 node.selector.asIdentifier() !== null && | 1678 node.selector.asIdentifier() !== null && |
| 1705 node.selector.asIdentifier().isThis()) || | 1679 node.selector.asIdentifier().isThis()) || |
| 1706 (node.receiver !== null && | 1680 (node.receiver !== null && |
| 1707 node.receiver.asIdentifier() !== null && | 1681 node.receiver.asIdentifier() !== null && |
| 1708 node.receiver.asIdentifier().isThis() && | 1682 node.receiver.asIdentifier().isThis() && |
| 1709 node.selector.asIdentifier() !== null); | 1683 node.selector.asIdentifier() !== null); |
| 1710 } | 1684 } |
| 1711 } | 1685 } |
| OLD | NEW |