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

Side by Side Diff: pkg/compiler/lib/src/js/nodes.dart

Issue 893963005: Refactor handling of source map information. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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
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 part of js; 5 part of js;
6 6
7 abstract class NodeVisitor<T> { 7 abstract class NodeVisitor<T> {
8 T visitProgram(Program node); 8 T visitProgram(Program node);
9 9
10 T visitBlock(Block node); 10 T visitBlock(Block node);
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 T visitInterpolatedStatement(InterpolatedStatement node) 165 T visitInterpolatedStatement(InterpolatedStatement node)
166 => visitInterpolatedNode(node); 166 => visitInterpolatedNode(node);
167 167
168 // Ignore comments by default. 168 // Ignore comments by default.
169 T visitComment(Comment node) => null; 169 T visitComment(Comment node) => null;
170 170
171 T visitAwait(Await node) => visitExpression(node); 171 T visitAwait(Await node) => visitExpression(node);
172 } 172 }
173 173
174 abstract class Node { 174 abstract class Node {
175 get sourcePosition => _sourcePosition; 175 SourceInformation get sourceInformation => _sourceInformation;
176 get endSourcePosition => _endSourcePosition;
177 176
178 var _sourcePosition; 177 SourceInformation _sourceInformation;
179 var _endSourcePosition;
180 178
181 accept(NodeVisitor visitor); 179 accept(NodeVisitor visitor);
182 void visitChildren(NodeVisitor visitor); 180 void visitChildren(NodeVisitor visitor);
183 181
184 // Shallow clone of node. Does not clone positions since the only use of this 182 // Shallow clone of node. Does not clone positions since the only use of this
185 // private method is create a copy with a new position. 183 // private method is create a copy with a new position.
186 Node _clone(); 184 Node _clone();
187 185
188 // Returns a node equivalent to [this], but with new source position and end 186 // Returns a node equivalent to [this], but with new source position and end
189 // source position. 187 // source position.
190 Node withPosition(var sourcePosition, var endSourcePosition) { 188 Node withSourceInformation(SourceInformation sourceInformation) {
191 if (sourcePosition == _sourcePosition && 189 if (sourceInformation == _sourceInformation) {
192 endSourcePosition == _endSourcePosition) {
193 return this; 190 return this;
194 } 191 }
195 Node clone = _clone(); 192 Node clone = _clone();
196 // TODO(sra): Should existing data be 'sticky' if we try to overwrite with 193 // TODO(sra): Should existing data be 'sticky' if we try to overwrite with
197 // `null`? 194 // `null`?
198 clone._sourcePosition = sourcePosition; 195 clone._sourceInformation = sourceInformation;
199 clone._endSourcePosition = endSourcePosition;
200 return clone; 196 return clone;
201 } 197 }
202 198
203 // Returns a node equivalent to [this], but with new [this.sourcePositions], 199 // Returns a node equivalent to [this], but with new [this.sourcePositions],
204 // keeping the existing [endPosition] 200 // keeping the existing [endPosition]
205 Node withLocation(var sourcePosition) => 201 //Node withLocation(var sourcePosition) =>
floitsch 2015/02/09 13:16:22 Remove?
Johnni Winther 2015/02/09 14:58:36 Done.
206 withPosition(sourcePosition, this.endSourcePosition); 202 // withPosition(sourcePosition, this.endSourcePosition);
207 203
208 VariableUse asVariableUse() => null; 204 VariableUse asVariableUse() => null;
209 205
210 bool get isCommaOperator => false; 206 bool get isCommaOperator => false;
211 207
212 Statement toStatement() { 208 Statement toStatement() {
213 throw new UnsupportedError('toStatement'); 209 throw new UnsupportedError('toStatement');
214 } 210 }
215 } 211 }
216 212
217 class Program extends Node { 213 class Program extends Node {
218 final List<Statement> body; 214 final List<Statement> body;
219 Program(this.body); 215 Program(this.body);
220 216
221 accept(NodeVisitor visitor) => visitor.visitProgram(this); 217 accept(NodeVisitor visitor) => visitor.visitProgram(this);
222 void visitChildren(NodeVisitor visitor) { 218 void visitChildren(NodeVisitor visitor) {
223 for (Statement statement in body) statement.accept(visitor); 219 for (Statement statement in body) statement.accept(visitor);
224 } 220 }
225 Program _clone() => new Program(body); 221 Program _clone() => new Program(body);
226 } 222 }
227 223
228 abstract class Statement extends Node { 224 abstract class Statement extends Node {
229 Statement toStatement() => this; 225 Statement toStatement() => this;
230
231 Statement withPosition(var sourcePosition, var endSourcePosition) =>
232 super.withPosition(sourcePosition, endSourcePosition);
233 } 226 }
234 227
235 class Block extends Statement { 228 class Block extends Statement {
236 final List<Statement> statements; 229 final List<Statement> statements;
237 Block(this.statements); 230 Block(this.statements);
238 Block.empty() : this.statements = <Statement>[]; 231 Block.empty() : this.statements = <Statement>[];
239 232
240 accept(NodeVisitor visitor) => visitor.visitBlock(this); 233 accept(NodeVisitor visitor) => visitor.visitBlock(this);
241 void visitChildren(NodeVisitor visitor) { 234 void visitChildren(NodeVisitor visitor) {
242 for (Statement statement in statements) statement.accept(visitor); 235 for (Statement statement in statements) statement.accept(visitor);
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 accept(NodeVisitor visitor) => visitor.visitLiteralStatement(this); 522 accept(NodeVisitor visitor) => visitor.visitLiteralStatement(this);
530 void visitChildren(NodeVisitor visitor) { } 523 void visitChildren(NodeVisitor visitor) { }
531 524
532 LiteralStatement _clone() => new LiteralStatement(code); 525 LiteralStatement _clone() => new LiteralStatement(code);
533 } 526 }
534 527
535 abstract class Expression extends Node { 528 abstract class Expression extends Node {
536 int get precedenceLevel; 529 int get precedenceLevel;
537 530
538 Statement toStatement() => new ExpressionStatement(this); 531 Statement toStatement() => new ExpressionStatement(this);
539
540 Expression withPosition(var sourcePosition, var endSourcePosition) =>
541 super.withPosition(sourcePosition, endSourcePosition);
542 } 532 }
543 533
544 /// Wrap a CodeBuffer as an expression. 534 /// Wrap a CodeBuffer as an expression.
545 class Blob extends Expression { 535 class Blob extends Expression {
546 // TODO(ahe): This class is an aid to convert everything to ASTs, remove when 536 // TODO(ahe): This class is an aid to convert everything to ASTs, remove when
547 // not needed anymore. 537 // not needed anymore.
548 538
549 final CodeBuffer buffer; 539 final CodeBuffer buffer;
550 540
551 Blob(this.buffer); 541 Blob(this.buffer);
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after
1133 class Comment extends Statement { 1123 class Comment extends Statement {
1134 final String comment; 1124 final String comment;
1135 1125
1136 Comment(this.comment); 1126 Comment(this.comment);
1137 1127
1138 accept(NodeVisitor visitor) => visitor.visitComment(this); 1128 accept(NodeVisitor visitor) => visitor.visitComment(this);
1139 Comment _clone() => new Comment(comment); 1129 Comment _clone() => new Comment(comment);
1140 1130
1141 void visitChildren(NodeVisitor visitor) {} 1131 void visitChildren(NodeVisitor visitor) {}
1142 } 1132 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698