Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Side by Side Diff: lib/compiler/implementation/tree/nodes.dart

Issue 11033016: Added TODO. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « lib/compiler/implementation/tree/dartstring.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 abstract class Visitor<R> { 5 abstract class Visitor<R> {
6 const Visitor(); 6 const Visitor();
7 7
8 abstract R visitNode(Node node); 8 abstract R visitNode(Node node);
9 9
10 R visitBlock(Block node) => visitStatement(node); 10 R visitBlock(Block node) => visitStatement(node);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 * A node in a syntax tree. 98 * A node in a syntax tree.
99 * 99 *
100 * The abstract part of "abstract syntax tree" is invalidated when 100 * The abstract part of "abstract syntax tree" is invalidated when
101 * supporting tools such as code formatting. These tools need concrete 101 * supporting tools such as code formatting. These tools need concrete
102 * syntax such as parentheses and no constant folding. 102 * syntax such as parentheses and no constant folding.
103 * 103 *
104 * We support these tools by storing additional references back to the 104 * We support these tools by storing additional references back to the
105 * token stream. These references are stored in fields ending with 105 * token stream. These references are stored in fields ending with
106 * "Token". 106 * "Token".
107 */ 107 */
108 class Node implements Spannable { 108 abstract class Node implements Spannable {
109 final int _hashCode; 109 final int _hashCode;
110 static int _HASH_COUNTER = 0; 110 static int _HASH_COUNTER = 0;
111 111
112 Node() : _hashCode = ++_HASH_COUNTER; 112 Node() : _hashCode = ++_HASH_COUNTER;
113 113
114 hashCode() => _hashCode; 114 hashCode() => _hashCode;
115 115
116 abstract accept(Visitor visitor); 116 abstract accept(Visitor visitor);
117 117
118 abstract visitChildren(Visitor visitor); 118 abstract visitChildren(Visitor visitor);
(...skipping 20 matching lines...) Expand all
139 BreakStatement asBreakStatement() => null; 139 BreakStatement asBreakStatement() => null;
140 Cascade asCascade() => null; 140 Cascade asCascade() => null;
141 CascadeReceiver asCascadeReceiver() => null; 141 CascadeReceiver asCascadeReceiver() => null;
142 CaseMatch asCaseMatch() => null; 142 CaseMatch asCaseMatch() => null;
143 CatchBlock asCatchBlock() => null; 143 CatchBlock asCatchBlock() => null;
144 ClassNode asClassNode() => null; 144 ClassNode asClassNode() => null;
145 Conditional asConditional() => null; 145 Conditional asConditional() => null;
146 ContinueStatement asContinueStatement() => null; 146 ContinueStatement asContinueStatement() => null;
147 DoWhile asDoWhile() => null; 147 DoWhile asDoWhile() => null;
148 EmptyStatement asEmptyStatement() => null; 148 EmptyStatement asEmptyStatement() => null;
149 Export AsExport() => Null; 149 Export AsExport() => null;
150 Expression asExpression() => null; 150 Expression asExpression() => null;
151 ExpressionStatement asExpressionStatement() => null; 151 ExpressionStatement asExpressionStatement() => null;
152 For asFor() => null; 152 For asFor() => null;
153 ForIn asForIn() => null; 153 ForIn asForIn() => null;
154 FunctionDeclaration asFunctionDeclaration() => null; 154 FunctionDeclaration asFunctionDeclaration() => null;
155 FunctionExpression asFunctionExpression() => null; 155 FunctionExpression asFunctionExpression() => null;
156 Identifier asIdentifier() => null; 156 Identifier asIdentifier() => null;
157 If asIf() => null; 157 If asIf() => null;
158 Import AsImport() => Null; 158 Import AsImport() => null;
159 Label asLabel() => null; 159 Label asLabel() => null;
160 LabeledStatement asLabeledStatement() => null; 160 LabeledStatement asLabeledStatement() => null;
161 LibraryName AsLibraryName() => Null; 161 LibraryName AsLibraryName() => null;
162 LiteralBool asLiteralBool() => null; 162 LiteralBool asLiteralBool() => null;
163 LiteralDouble asLiteralDouble() => null; 163 LiteralDouble asLiteralDouble() => null;
164 LiteralInt asLiteralInt() => null; 164 LiteralInt asLiteralInt() => null;
165 LiteralList asLiteralList() => null; 165 LiteralList asLiteralList() => null;
166 LiteralMap asLiteralMap() => null; 166 LiteralMap asLiteralMap() => null;
167 LiteralMapEntry asLiteralMapEntry() => null; 167 LiteralMapEntry asLiteralMapEntry() => null;
168 LiteralNull asLiteralNull() => null; 168 LiteralNull asLiteralNull() => null;
169 LiteralString asLiteralString() => null; 169 LiteralString asLiteralString() => null;
170 Modifiers asModifiers() => null; 170 Modifiers asModifiers() => null;
171 NamedArgument asNamedArgument() => null; 171 NamedArgument asNamedArgument() => null;
172 NodeList asNodeList() => null; 172 NodeList asNodeList() => null;
173 Operator asOperator() => null; 173 Operator asOperator() => null;
174 ParenthesizedExpression asParenthesizedExpression() => null; 174 ParenthesizedExpression asParenthesizedExpression() => null;
175 Part AsPart() => Null; 175 Part AsPart() => null;
176 PartOf AsPartOf() => Null; 176 PartOf AsPartOf() => null;
177 Return asReturn() => null; 177 Return asReturn() => null;
178 ScriptTag asScriptTag() => null; 178 ScriptTag asScriptTag() => null;
179 Send asSend() => null; 179 Send asSend() => null;
180 SendSet asSendSet() => null; 180 SendSet asSendSet() => null;
181 Statement asStatement() => null; 181 Statement asStatement() => null;
182 StringInterpolation asStringInterpolation() => null; 182 StringInterpolation asStringInterpolation() => null;
183 StringInterpolationPart asStringInterpolationPart() => null; 183 StringInterpolationPart asStringInterpolationPart() => null;
184 StringJuxtaposition asStringJuxtaposition() => null; 184 StringJuxtaposition asStringJuxtaposition() => null;
185 StringNode asStringNode() => null; 185 StringNode asStringNode() => null;
186 SwitchCase asSwitchCase() => null; 186 SwitchCase asSwitchCase() => null;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 229
230 bool get isInterface => beginToken.stringValue === 'interface'; 230 bool get isInterface => beginToken.stringValue === 'interface';
231 231
232 bool get isClass => !isInterface; 232 bool get isClass => !isInterface;
233 233
234 Token getBeginToken() => beginToken; 234 Token getBeginToken() => beginToken;
235 235
236 Token getEndToken() => endToken; 236 Token getEndToken() => endToken;
237 } 237 }
238 238
239 class Expression extends Node { 239 abstract class Expression extends Node {
240 Expression(); 240 Expression();
241 241
242 Expression asExpression() => this; 242 Expression asExpression() => this;
243 243
244 // TODO(ahe): make class abstract instead of adding an abstract method. 244 // TODO(ahe): make class abstract instead of adding an abstract method.
245 abstract accept(Visitor visitor); 245 abstract accept(Visitor visitor);
246 } 246 }
247 247
248 class Statement extends Node { 248 abstract class Statement extends Node {
249 Statement(); 249 Statement();
250 250
251 Statement asStatement() => this; 251 Statement asStatement() => this;
252 252
253 // TODO(ahe): make class abstract instead of adding an abstract method. 253 // TODO(ahe): make class abstract instead of adding an abstract method.
254 abstract accept(Visitor visitor); 254 abstract accept(Visitor visitor);
255 255
256 bool isValidBreakTarget() => true; 256 bool isValidBreakTarget() => true;
257 } 257 }
258 258
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 669
670 Token getEndToken() { 670 Token getEndToken() {
671 Token token = (body === null) ? null : body.getEndToken(); 671 Token token = (body === null) ? null : body.getEndToken();
672 token = (token === null) ? parameters.getEndToken() : token; 672 token = (token === null) ? parameters.getEndToken() : token;
673 return (token === null) ? name.getEndToken() : token; 673 return (token === null) ? name.getEndToken() : token;
674 } 674 }
675 } 675 }
676 676
677 typedef void DecodeErrorHandler(Token token, var error); 677 typedef void DecodeErrorHandler(Token token, var error);
678 678
679 class Literal<T> extends Expression { 679 abstract class Literal<T> extends Expression {
680 final Token token; 680 final Token token;
681 final DecodeErrorHandler handler; 681 final DecodeErrorHandler handler;
682 682
683 Literal(Token this.token, DecodeErrorHandler this.handler); 683 Literal(Token this.token, DecodeErrorHandler this.handler);
684 684
685 abstract T get value; 685 abstract T get value;
686 686
687 visitChildren(Visitor visitor) {} 687 visitChildren(Visitor visitor) {}
688 688
689 Token getBeginToken() => token; 689 Token getBeginToken() => token;
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 static StringQuoting getQuoting(int quote, bool raw, int quoteLength) { 808 static StringQuoting getQuoting(int quote, bool raw, int quoteLength) {
809 int index = quoteLength - 1; 809 int index = quoteLength - 1;
810 if (quoteLength > 2) index -= 1; 810 if (quoteLength > 2) index -= 1;
811 return mapping[(raw ? 1 : 0) + index * 2 + (quote === $SQ ? 8 : 0)]; 811 return mapping[(raw ? 1 : 0) + index * 2 + (quote === $SQ ? 8 : 0)];
812 } 812 }
813 } 813 }
814 814
815 /** 815 /**
816 * Superclass for classes representing string literals. 816 * Superclass for classes representing string literals.
817 */ 817 */
818 class StringNode extends Expression { 818 abstract class StringNode extends Expression {
819 abstract DartString get dartString; 819 abstract DartString get dartString;
820 abstract bool get isInterpolation; 820 abstract bool get isInterpolation;
821 821
822 StringNode asStringNode() => this; 822 StringNode asStringNode() => this;
823 } 823 }
824 824
825 class LiteralString extends StringNode { 825 class LiteralString extends StringNode {
826 final Token token; 826 final Token token;
827 /** Non-null on validated string literals. */ 827 /** Non-null on validated string literals. */
828 final DartString dartString; 828 final DartString dartString;
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
1039 var token = firstBeginToken(modifiers, type); 1039 var token = firstBeginToken(modifiers, type);
1040 if (token === null) { 1040 if (token === null) {
1041 token = definitions.getBeginToken(); 1041 token = definitions.getBeginToken();
1042 } 1042 }
1043 return token; 1043 return token;
1044 } 1044 }
1045 1045
1046 Token getEndToken() => endToken; 1046 Token getEndToken() => endToken;
1047 } 1047 }
1048 1048
1049 class Loop extends Statement { 1049 abstract class Loop extends Statement {
1050 abstract Expression get condition; 1050 abstract Expression get condition;
1051 final Statement body; 1051 final Statement body;
1052 1052
1053 Loop(this.body); 1053 Loop(this.body);
1054 1054
1055 bool isValidContinueTarget() => true; 1055 bool isValidContinueTarget() => true;
1056 } 1056 }
1057 1057
1058 class DoWhile extends Loop { 1058 class DoWhile extends Loop {
1059 final Token doKeyword; 1059 final Token doKeyword;
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
1481 return defaultKeyword.next; 1481 return defaultKeyword.next;
1482 } 1482 }
1483 // The colon after the last expression. 1483 // The colon after the last expression.
1484 return labelsAndCases.getEndToken(); 1484 return labelsAndCases.getEndToken();
1485 } else { 1485 } else {
1486 return statements.getEndToken(); 1486 return statements.getEndToken();
1487 } 1487 }
1488 } 1488 }
1489 } 1489 }
1490 1490
1491 class GotoStatement extends Statement { 1491 abstract class GotoStatement extends Statement {
1492 final Identifier target; 1492 final Identifier target;
1493 final Token keywordToken; 1493 final Token keywordToken;
1494 final Token semicolonToken; 1494 final Token semicolonToken;
1495 1495
1496 GotoStatement(this.target, this.keywordToken, this.semicolonToken); 1496 GotoStatement(this.target, this.keywordToken, this.semicolonToken);
1497 1497
1498 visitChildren(Visitor visitor) { 1498 visitChildren(Visitor visitor) {
1499 if (target !== null) target.accept(visitor); 1499 if (target !== null) target.accept(visitor);
1500 } 1500 }
1501 1501
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1641 } else if (isLibrary()) { 1641 } else if (isLibrary()) {
1642 return new LibraryName(tag.token, argument); 1642 return new LibraryName(tag.token, argument);
1643 } else if (isSource()) { 1643 } else if (isSource()) {
1644 return new Part(tag.token, argument); 1644 return new Part(tag.token, argument);
1645 } else { 1645 } else {
1646 throw 'Unknown script tag ${tag.token.slowToString()}'; 1646 throw 'Unknown script tag ${tag.token.slowToString()}';
1647 } 1647 }
1648 } 1648 }
1649 } 1649 }
1650 1650
1651 class LibraryTag extends Node { 1651 abstract class LibraryTag extends Node {
1652 bool get isLibraryName => false; 1652 bool get isLibraryName => false;
1653 bool get isImport => false; 1653 bool get isImport => false;
1654 bool get isExport => false; 1654 bool get isExport => false;
1655 bool get isPart => false; 1655 bool get isPart => false;
1656 bool get isPartOf => false; 1656 bool get isPartOf => false;
1657 } 1657 }
1658 1658
1659 class LibraryName extends LibraryTag { 1659 class LibraryName extends LibraryTag {
1660 final Expression name; 1660 final Expression name;
1661 1661
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1759 final Expression name; 1759 final Expression name;
1760 1760
1761 final Token partKeyword; 1761 final Token partKeyword;
1762 1762
1763 PartOf(this.partKeyword, this.name); 1763 PartOf(this.partKeyword, this.name);
1764 1764
1765 Token get ofKeyword => partKeyword.next; 1765 Token get ofKeyword => partKeyword.next;
1766 1766
1767 bool get isPartOf => true; 1767 bool get isPartOf => true;
1768 1768
1769 Part asPartOf() => this; 1769 PartOf asPartOf() => this;
1770 1770
1771 accept(Visitor visitor) => visitor.visitPartOf(this); 1771 accept(Visitor visitor) => visitor.visitPartOf(this);
1772 1772
1773 visitChildren(Visitor visitor) => name.accept(visitor); 1773 visitChildren(Visitor visitor) => name.accept(visitor);
1774 1774
1775 Token getBeginToken() => partKeyword; 1775 Token getBeginToken() => partKeyword;
1776 1776
1777 Token getEndToken() => name.getEndToken().next; 1777 Token getEndToken() => name.getEndToken().next;
1778 } 1778 }
1779 1779
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
1951 * argument). 1951 * argument).
1952 * 1952 *
1953 * TODO(ahe): This method is controversial, the team needs to discuss 1953 * TODO(ahe): This method is controversial, the team needs to discuss
1954 * if top-level methods are acceptable and what naming conventions to 1954 * if top-level methods are acceptable and what naming conventions to
1955 * use. 1955 * use.
1956 */ 1956 */
1957 initializerDo(Node node, f(Node node)) { 1957 initializerDo(Node node, f(Node node)) {
1958 SendSet send = node.asSendSet(); 1958 SendSet send = node.asSendSet();
1959 if (send !== null) return f(send.arguments.head); 1959 if (send !== null) return f(send.arguments.head);
1960 } 1960 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/tree/dartstring.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698