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

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: Updated cf. comments. 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
« no previous file with comments | « pkg/compiler/lib/src/js/js.dart ('k') | pkg/compiler/lib/src/js/printer.dart » ('j') | 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 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],
204 // keeping the existing [endPosition]
205 Node withLocation(var sourcePosition) =>
206 withPosition(sourcePosition, this.endSourcePosition);
207
208 VariableUse asVariableUse() => null; 199 VariableUse asVariableUse() => null;
209 200
210 bool get isCommaOperator => false; 201 bool get isCommaOperator => false;
211 202
212 Statement toStatement() { 203 Statement toStatement() {
213 throw new UnsupportedError('toStatement'); 204 throw new UnsupportedError('toStatement');
214 } 205 }
215 } 206 }
216 207
217 class Program extends Node { 208 class Program extends Node {
218 final List<Statement> body; 209 final List<Statement> body;
219 Program(this.body); 210 Program(this.body);
220 211
221 accept(NodeVisitor visitor) => visitor.visitProgram(this); 212 accept(NodeVisitor visitor) => visitor.visitProgram(this);
222 void visitChildren(NodeVisitor visitor) { 213 void visitChildren(NodeVisitor visitor) {
223 for (Statement statement in body) statement.accept(visitor); 214 for (Statement statement in body) statement.accept(visitor);
224 } 215 }
225 Program _clone() => new Program(body); 216 Program _clone() => new Program(body);
226 } 217 }
227 218
228 abstract class Statement extends Node { 219 abstract class Statement extends Node {
229 Statement toStatement() => this; 220 Statement toStatement() => this;
230
231 Statement withPosition(var sourcePosition, var endSourcePosition) =>
232 super.withPosition(sourcePosition, endSourcePosition);
233 } 221 }
234 222
235 class Block extends Statement { 223 class Block extends Statement {
236 final List<Statement> statements; 224 final List<Statement> statements;
237 Block(this.statements); 225 Block(this.statements);
238 Block.empty() : this.statements = <Statement>[]; 226 Block.empty() : this.statements = <Statement>[];
239 227
240 accept(NodeVisitor visitor) => visitor.visitBlock(this); 228 accept(NodeVisitor visitor) => visitor.visitBlock(this);
241 void visitChildren(NodeVisitor visitor) { 229 void visitChildren(NodeVisitor visitor) {
242 for (Statement statement in statements) statement.accept(visitor); 230 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); 517 accept(NodeVisitor visitor) => visitor.visitLiteralStatement(this);
530 void visitChildren(NodeVisitor visitor) { } 518 void visitChildren(NodeVisitor visitor) { }
531 519
532 LiteralStatement _clone() => new LiteralStatement(code); 520 LiteralStatement _clone() => new LiteralStatement(code);
533 } 521 }
534 522
535 abstract class Expression extends Node { 523 abstract class Expression extends Node {
536 int get precedenceLevel; 524 int get precedenceLevel;
537 525
538 Statement toStatement() => new ExpressionStatement(this); 526 Statement toStatement() => new ExpressionStatement(this);
539
540 Expression withPosition(var sourcePosition, var endSourcePosition) =>
541 super.withPosition(sourcePosition, endSourcePosition);
542 } 527 }
543 528
544 /// Wrap a CodeBuffer as an expression. 529 /// Wrap a CodeBuffer as an expression.
545 class Blob extends Expression { 530 class Blob extends Expression {
546 // TODO(ahe): This class is an aid to convert everything to ASTs, remove when 531 // TODO(ahe): This class is an aid to convert everything to ASTs, remove when
547 // not needed anymore. 532 // not needed anymore.
548 533
549 final CodeBuffer buffer; 534 final CodeBuffer buffer;
550 535
551 Blob(this.buffer); 536 Blob(this.buffer);
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after
1133 class Comment extends Statement { 1118 class Comment extends Statement {
1134 final String comment; 1119 final String comment;
1135 1120
1136 Comment(this.comment); 1121 Comment(this.comment);
1137 1122
1138 accept(NodeVisitor visitor) => visitor.visitComment(this); 1123 accept(NodeVisitor visitor) => visitor.visitComment(this);
1139 Comment _clone() => new Comment(comment); 1124 Comment _clone() => new Comment(comment);
1140 1125
1141 void visitChildren(NodeVisitor visitor) {} 1126 void visitChildren(NodeVisitor visitor) {}
1142 } 1127 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js/js.dart ('k') | pkg/compiler/lib/src/js/printer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698