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 js_ast; | 5 part of js_ast; |
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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 return visitInterpolatedNode(node); | 187 return visitInterpolatedNode(node); |
188 } | 188 } |
189 | 189 |
190 // Ignore comments by default. | 190 // Ignore comments by default. |
191 T visitComment(Comment node) => null; | 191 T visitComment(Comment node) => null; |
192 | 192 |
193 T visitAwait(Await node) => visitExpression(node); | 193 T visitAwait(Await node) => visitExpression(node); |
194 T visitDartYield(DartYield node) => visitStatement(node); | 194 T visitDartYield(DartYield node) => visitStatement(node); |
195 } | 195 } |
196 | 196 |
| 197 abstract class NodeVisitor1<R, A> { |
| 198 R visitProgram(Program node, A arg); |
| 199 |
| 200 R visitBlock(Block node, A arg); |
| 201 R visitExpressionStatement(ExpressionStatement node, A arg); |
| 202 R visitEmptyStatement(EmptyStatement node, A arg); |
| 203 R visitIf(If node, A arg); |
| 204 R visitFor(For node, A arg); |
| 205 R visitForIn(ForIn node, A arg); |
| 206 R visitWhile(While node, A arg); |
| 207 R visitDo(Do node, A arg); |
| 208 R visitContinue(Continue node, A arg); |
| 209 R visitBreak(Break node, A arg); |
| 210 R visitReturn(Return node, A arg); |
| 211 R visitThrow(Throw node, A arg); |
| 212 R visitTry(Try node, A arg); |
| 213 R visitCatch(Catch node, A arg); |
| 214 R visitSwitch(Switch node, A arg); |
| 215 R visitCase(Case node, A arg); |
| 216 R visitDefault(Default node, A arg); |
| 217 R visitFunctionDeclaration(FunctionDeclaration node, A arg); |
| 218 R visitLabeledStatement(LabeledStatement node, A arg); |
| 219 R visitLiteralStatement(LiteralStatement node, A arg); |
| 220 R visitDartYield(DartYield node, A arg); |
| 221 |
| 222 R visitLiteralExpression(LiteralExpression node, A arg); |
| 223 R visitVariableDeclarationList(VariableDeclarationList node, A arg); |
| 224 R visitAssignment(Assignment node, A arg); |
| 225 R visitVariableInitialization(VariableInitialization node, A arg); |
| 226 R visitConditional(Conditional cond, A arg); |
| 227 R visitNew(New node, A arg); |
| 228 R visitCall(Call node, A arg); |
| 229 R visitBinary(Binary node, A arg); |
| 230 R visitPrefix(Prefix node, A arg); |
| 231 R visitPostfix(Postfix node, A arg); |
| 232 |
| 233 R visitVariableUse(VariableUse node, A arg); |
| 234 R visitThis(This node, A arg); |
| 235 R visitVariableDeclaration(VariableDeclaration node, A arg); |
| 236 R visitParameter(Parameter node, A arg); |
| 237 R visitAccess(PropertyAccess node, A arg); |
| 238 |
| 239 R visitNamedFunction(NamedFunction node, A arg); |
| 240 R visitFun(Fun node, A arg); |
| 241 |
| 242 R visitDeferredExpression(DeferredExpression node, A arg); |
| 243 R visitDeferredNumber(DeferredNumber node, A arg); |
| 244 R visitDeferredString(DeferredString node, A arg); |
| 245 |
| 246 R visitLiteralBool(LiteralBool node, A arg); |
| 247 R visitLiteralString(LiteralString node, A arg); |
| 248 R visitLiteralNumber(LiteralNumber node, A arg); |
| 249 R visitLiteralNull(LiteralNull node, A arg); |
| 250 |
| 251 R visitStringConcatenation(StringConcatenation node, A arg); |
| 252 |
| 253 R visitName(Name node, A arg); |
| 254 |
| 255 R visitArrayInitializer(ArrayInitializer node, A arg); |
| 256 R visitArrayHole(ArrayHole node, A arg); |
| 257 R visitObjectInitializer(ObjectInitializer node, A arg); |
| 258 R visitProperty(Property node, A arg); |
| 259 R visitRegExpLiteral(RegExpLiteral node, A arg); |
| 260 |
| 261 R visitAwait(Await node, A arg); |
| 262 |
| 263 R visitComment(Comment node, A arg); |
| 264 |
| 265 R visitInterpolatedExpression(InterpolatedExpression node, A arg); |
| 266 R visitInterpolatedLiteral(InterpolatedLiteral node, A arg); |
| 267 R visitInterpolatedParameter(InterpolatedParameter node, A arg); |
| 268 R visitInterpolatedSelector(InterpolatedSelector node, A arg); |
| 269 R visitInterpolatedStatement(InterpolatedStatement node, A arg); |
| 270 R visitInterpolatedDeclaration(InterpolatedDeclaration node, A arg); |
| 271 } |
| 272 |
| 273 class BaseVisitor1<R, A> implements NodeVisitor1<R, A> { |
| 274 const BaseVisitor1(); |
| 275 |
| 276 R visitNode(Node node, A arg) { |
| 277 node.visitChildren1(this, arg); |
| 278 return null; |
| 279 } |
| 280 |
| 281 R visitProgram(Program node, A arg) => visitNode(node, arg); |
| 282 |
| 283 R visitStatement(Statement node, A arg) => visitNode(node, arg); |
| 284 R visitLoop(Loop node, A arg) => visitStatement(node, arg); |
| 285 R visitJump(Statement node, A arg) => visitStatement(node, arg); |
| 286 |
| 287 R visitBlock(Block node, A arg) => visitStatement(node, arg); |
| 288 R visitExpressionStatement(ExpressionStatement node, A arg) => |
| 289 visitStatement(node, arg); |
| 290 R visitEmptyStatement(EmptyStatement node, A arg) => |
| 291 visitStatement(node, arg); |
| 292 R visitIf(If node, A arg) => visitStatement(node, arg); |
| 293 R visitFor(For node, A arg) => visitLoop(node, arg); |
| 294 R visitForIn(ForIn node, A arg) => visitLoop(node, arg); |
| 295 R visitWhile(While node, A arg) => visitLoop(node, arg); |
| 296 R visitDo(Do node, A arg) => visitLoop(node, arg); |
| 297 R visitContinue(Continue node, A arg) => visitJump(node, arg); |
| 298 R visitBreak(Break node, A arg) => visitJump(node, arg); |
| 299 R visitReturn(Return node, A arg) => visitJump(node, arg); |
| 300 R visitThrow(Throw node, A arg) => visitJump(node, arg); |
| 301 R visitTry(Try node, A arg) => visitStatement(node, arg); |
| 302 R visitSwitch(Switch node, A arg) => visitStatement(node, arg); |
| 303 R visitFunctionDeclaration(FunctionDeclaration node, A arg) => |
| 304 visitStatement(node, arg); |
| 305 R visitLabeledStatement(LabeledStatement node, A arg) => |
| 306 visitStatement(node, arg); |
| 307 R visitLiteralStatement(LiteralStatement node, A arg) => |
| 308 visitStatement(node, arg); |
| 309 |
| 310 R visitCatch(Catch node, A arg) => visitNode(node, arg); |
| 311 R visitCase(Case node, A arg) => visitNode(node, arg); |
| 312 R visitDefault(Default node, A arg) => visitNode(node, arg); |
| 313 |
| 314 R visitExpression(Expression node, A arg) => visitNode(node, arg); |
| 315 R visitVariableReference(VariableReference node, A arg) => |
| 316 visitExpression(node, arg); |
| 317 |
| 318 R visitLiteralExpression(LiteralExpression node, A arg) => |
| 319 visitExpression(node, arg); |
| 320 R visitVariableDeclarationList(VariableDeclarationList node, A arg) => |
| 321 visitExpression(node, arg); |
| 322 R visitAssignment(Assignment node, A arg) => visitExpression(node, arg); |
| 323 R visitVariableInitialization(VariableInitialization node, A arg) { |
| 324 if (node.value != null) { |
| 325 return visitAssignment(node, arg); |
| 326 } else { |
| 327 return visitExpression(node, arg); |
| 328 } |
| 329 } |
| 330 |
| 331 R visitConditional(Conditional node, A arg) => visitExpression(node, arg); |
| 332 R visitNew(New node, A arg) => visitExpression(node, arg); |
| 333 R visitCall(Call node, A arg) => visitExpression(node, arg); |
| 334 R visitBinary(Binary node, A arg) => visitExpression(node, arg); |
| 335 R visitPrefix(Prefix node, A arg) => visitExpression(node, arg); |
| 336 R visitPostfix(Postfix node, A arg) => visitExpression(node, arg); |
| 337 R visitAccess(PropertyAccess node, A arg) => visitExpression(node, arg); |
| 338 |
| 339 R visitVariableUse(VariableUse node, A arg) => |
| 340 visitVariableReference(node, arg); |
| 341 R visitVariableDeclaration(VariableDeclaration node, A arg) => |
| 342 visitVariableReference(node, arg); |
| 343 R visitParameter(Parameter node, A arg) => |
| 344 visitVariableDeclaration(node, arg); |
| 345 R visitThis(This node, A arg) => visitParameter(node, arg); |
| 346 |
| 347 R visitNamedFunction(NamedFunction node, A arg) => visitExpression(node, arg); |
| 348 R visitFun(Fun node, A arg) => visitExpression(node, arg); |
| 349 |
| 350 R visitToken(DeferredToken node, A arg) => visitExpression(node, arg); |
| 351 |
| 352 R visitDeferredExpression(DeferredExpression node, A arg) => |
| 353 visitExpression(node, arg); |
| 354 R visitDeferredNumber(DeferredNumber node, A arg) => visitToken(node, arg); |
| 355 R visitDeferredString(DeferredString node, A arg) => visitToken(node, arg); |
| 356 |
| 357 R visitLiteral(Literal node, A arg) => visitExpression(node, arg); |
| 358 |
| 359 R visitLiteralBool(LiteralBool node, A arg) => visitLiteral(node, arg); |
| 360 R visitLiteralString(LiteralString node, A arg) => visitLiteral(node, arg); |
| 361 R visitLiteralNumber(LiteralNumber node, A arg) => visitLiteral(node, arg); |
| 362 R visitLiteralNull(LiteralNull node, A arg) => visitLiteral(node, arg); |
| 363 |
| 364 R visitStringConcatenation(StringConcatenation node, A arg) => |
| 365 visitLiteral(node, arg); |
| 366 |
| 367 R visitName(Name node, A arg) => visitNode(node, arg); |
| 368 |
| 369 R visitArrayInitializer(ArrayInitializer node, A arg) => |
| 370 visitExpression(node, arg); |
| 371 R visitArrayHole(ArrayHole node, A arg) => visitExpression(node, arg); |
| 372 R visitObjectInitializer(ObjectInitializer node, A arg) => |
| 373 visitExpression(node, arg); |
| 374 R visitProperty(Property node, A arg) => visitNode(node, arg); |
| 375 R visitRegExpLiteral(RegExpLiteral node, A arg) => visitExpression(node, arg); |
| 376 |
| 377 R visitInterpolatedNode(InterpolatedNode node, A arg) => visitNode(node, arg); |
| 378 |
| 379 R visitInterpolatedExpression(InterpolatedExpression node, A arg) => |
| 380 visitInterpolatedNode(node, arg); |
| 381 R visitInterpolatedLiteral(InterpolatedLiteral node, A arg) => |
| 382 visitInterpolatedNode(node, arg); |
| 383 R visitInterpolatedParameter(InterpolatedParameter node, A arg) => |
| 384 visitInterpolatedNode(node, arg); |
| 385 R visitInterpolatedSelector(InterpolatedSelector node, A arg) => |
| 386 visitInterpolatedNode(node, arg); |
| 387 R visitInterpolatedStatement(InterpolatedStatement node, A arg) => |
| 388 visitInterpolatedNode(node, arg); |
| 389 R visitInterpolatedDeclaration(InterpolatedDeclaration node, A arg) { |
| 390 return visitInterpolatedNode(node, arg); |
| 391 } |
| 392 |
| 393 // Ignore comments by default. |
| 394 R visitComment(Comment node, A arg) => null; |
| 395 |
| 396 R visitAwait(Await node, A arg) => visitExpression(node, arg); |
| 397 R visitDartYield(DartYield node, A arg) => visitStatement(node, arg); |
| 398 } |
| 399 |
197 /// This tag interface has no behaviour but must be implemented by any class | 400 /// This tag interface has no behaviour but must be implemented by any class |
198 /// that is to be stored on a [Node] as source information. | 401 /// that is to be stored on a [Node] as source information. |
199 abstract class JavaScriptNodeSourceInformation { | 402 abstract class JavaScriptNodeSourceInformation { |
200 const JavaScriptNodeSourceInformation(); | 403 const JavaScriptNodeSourceInformation(); |
201 } | 404 } |
202 | 405 |
203 abstract class Node { | 406 abstract class Node { |
204 JavaScriptNodeSourceInformation get sourceInformation => _sourceInformation; | 407 JavaScriptNodeSourceInformation get sourceInformation => _sourceInformation; |
205 | 408 |
206 JavaScriptNodeSourceInformation _sourceInformation; | 409 JavaScriptNodeSourceInformation _sourceInformation; |
207 | 410 |
208 accept(NodeVisitor visitor); | 411 T accept<T>(NodeVisitor<T> visitor); |
209 void visitChildren(NodeVisitor visitor); | 412 void visitChildren<T>(NodeVisitor<T> visitor); |
| 413 |
| 414 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg); |
| 415 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg); |
210 | 416 |
211 // Shallow clone of node. Does not clone positions since the only use of this | 417 // Shallow clone of node. Does not clone positions since the only use of this |
212 // private method is create a copy with a new position. | 418 // private method is create a copy with a new position. |
213 Node _clone(); | 419 Node _clone(); |
214 | 420 |
215 // Returns a node equivalent to [this], but with new source position and end | 421 // Returns a node equivalent to [this], but with new source position and end |
216 // source position. | 422 // source position. |
217 Node withSourceInformation( | 423 Node withSourceInformation( |
218 JavaScriptNodeSourceInformation sourceInformation) { | 424 JavaScriptNodeSourceInformation sourceInformation) { |
219 if (sourceInformation == _sourceInformation) { | 425 if (sourceInformation == _sourceInformation) { |
(...skipping 14 matching lines...) Expand all Loading... |
234 throw new UnsupportedError('toStatement'); | 440 throw new UnsupportedError('toStatement'); |
235 } | 441 } |
236 | 442 |
237 String debugPrint() => DebugPrint(this); | 443 String debugPrint() => DebugPrint(this); |
238 } | 444 } |
239 | 445 |
240 class Program extends Node { | 446 class Program extends Node { |
241 final List<Statement> body; | 447 final List<Statement> body; |
242 Program(this.body); | 448 Program(this.body); |
243 | 449 |
244 accept(NodeVisitor visitor) => visitor.visitProgram(this); | 450 T accept<T>(NodeVisitor<T> visitor) => visitor.visitProgram(this); |
245 void visitChildren(NodeVisitor visitor) { | 451 |
| 452 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 453 visitor.visitProgram(this, arg); |
| 454 |
| 455 void visitChildren<T>(NodeVisitor<T> visitor) { |
246 for (Statement statement in body) statement.accept(visitor); | 456 for (Statement statement in body) statement.accept(visitor); |
247 } | 457 } |
248 | 458 |
| 459 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) { |
| 460 for (Statement statement in body) statement.accept1(visitor, arg); |
| 461 } |
| 462 |
249 Program _clone() => new Program(body); | 463 Program _clone() => new Program(body); |
250 } | 464 } |
251 | 465 |
252 abstract class Statement extends Node { | 466 abstract class Statement extends Node { |
253 Statement toStatement() => this; | 467 Statement toStatement() => this; |
254 } | 468 } |
255 | 469 |
256 class Block extends Statement { | 470 class Block extends Statement { |
257 final List<Statement> statements; | 471 final List<Statement> statements; |
| 472 |
258 Block(this.statements); | 473 Block(this.statements); |
| 474 |
259 Block.empty() : this.statements = <Statement>[]; | 475 Block.empty() : this.statements = <Statement>[]; |
260 | 476 |
261 accept(NodeVisitor visitor) => visitor.visitBlock(this); | 477 T accept<T>(NodeVisitor<T> visitor) => visitor.visitBlock(this); |
262 void visitChildren(NodeVisitor visitor) { | 478 |
| 479 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 480 visitor.visitBlock(this, arg); |
| 481 |
| 482 void visitChildren<T>(NodeVisitor<T> visitor) { |
263 for (Statement statement in statements) statement.accept(visitor); | 483 for (Statement statement in statements) statement.accept(visitor); |
264 } | 484 } |
265 | 485 |
| 486 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) { |
| 487 for (Statement statement in statements) statement.accept1(visitor, arg); |
| 488 } |
| 489 |
266 Block _clone() => new Block(statements); | 490 Block _clone() => new Block(statements); |
267 } | 491 } |
268 | 492 |
269 class ExpressionStatement extends Statement { | 493 class ExpressionStatement extends Statement { |
270 final Expression expression; | 494 final Expression expression; |
| 495 |
271 ExpressionStatement(this.expression) { | 496 ExpressionStatement(this.expression) { |
272 assert(this.expression != null); | 497 assert(this.expression != null); |
273 } | 498 } |
274 | 499 |
275 accept(NodeVisitor visitor) => visitor.visitExpressionStatement(this); | 500 T accept<T>(NodeVisitor<T> visitor) => visitor.visitExpressionStatement(this); |
276 void visitChildren(NodeVisitor visitor) { | 501 |
| 502 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 503 visitor.visitExpressionStatement(this, arg); |
| 504 |
| 505 void visitChildren<T>(NodeVisitor<T> visitor) { |
277 expression.accept(visitor); | 506 expression.accept(visitor); |
278 } | 507 } |
279 | 508 |
| 509 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) { |
| 510 expression.accept1(visitor, arg); |
| 511 } |
| 512 |
280 ExpressionStatement _clone() => new ExpressionStatement(expression); | 513 ExpressionStatement _clone() => new ExpressionStatement(expression); |
281 } | 514 } |
282 | 515 |
283 class EmptyStatement extends Statement { | 516 class EmptyStatement extends Statement { |
284 EmptyStatement(); | 517 EmptyStatement(); |
285 | 518 |
286 accept(NodeVisitor visitor) => visitor.visitEmptyStatement(this); | 519 T accept<T>(NodeVisitor<T> visitor) => visitor.visitEmptyStatement(this); |
287 void visitChildren(NodeVisitor visitor) {} | 520 |
| 521 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 522 visitor.visitEmptyStatement(this, arg); |
| 523 |
| 524 void visitChildren<T>(NodeVisitor<T> visitor) {} |
| 525 |
| 526 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) {} |
| 527 |
288 EmptyStatement _clone() => new EmptyStatement(); | 528 EmptyStatement _clone() => new EmptyStatement(); |
289 } | 529 } |
290 | 530 |
291 class If extends Statement { | 531 class If extends Statement { |
292 final Expression condition; | 532 final Expression condition; |
293 final Statement then; | 533 final Statement then; |
294 final Statement otherwise; | 534 final Statement otherwise; |
295 | 535 |
296 If(this.condition, this.then, this.otherwise); | 536 If(this.condition, this.then, this.otherwise); |
| 537 |
297 If.noElse(this.condition, this.then) : this.otherwise = new EmptyStatement(); | 538 If.noElse(this.condition, this.then) : this.otherwise = new EmptyStatement(); |
298 | 539 |
299 bool get hasElse => otherwise is! EmptyStatement; | 540 bool get hasElse => otherwise is! EmptyStatement; |
300 | 541 |
301 accept(NodeVisitor visitor) => visitor.visitIf(this); | 542 T accept<T>(NodeVisitor<T> visitor) => visitor.visitIf(this); |
302 | 543 |
303 void visitChildren(NodeVisitor visitor) { | 544 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 545 visitor.visitIf(this, arg); |
| 546 |
| 547 void visitChildren<T>(NodeVisitor<T> visitor) { |
304 condition.accept(visitor); | 548 condition.accept(visitor); |
305 then.accept(visitor); | 549 then.accept(visitor); |
306 otherwise.accept(visitor); | 550 otherwise.accept(visitor); |
307 } | 551 } |
308 | 552 |
| 553 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) { |
| 554 condition.accept1(visitor, arg); |
| 555 then.accept1(visitor, arg); |
| 556 otherwise.accept1(visitor, arg); |
| 557 } |
| 558 |
309 If _clone() => new If(condition, then, otherwise); | 559 If _clone() => new If(condition, then, otherwise); |
310 } | 560 } |
311 | 561 |
312 abstract class Loop extends Statement { | 562 abstract class Loop extends Statement { |
313 final Statement body; | 563 final Statement body; |
| 564 |
314 Loop(this.body); | 565 Loop(this.body); |
315 } | 566 } |
316 | 567 |
317 class For extends Loop { | 568 class For extends Loop { |
318 final Expression init; | 569 final Expression init; |
319 final Expression condition; | 570 final Expression condition; |
320 final Expression update; | 571 final Expression update; |
321 | 572 |
322 For(this.init, this.condition, this.update, Statement body) : super(body); | 573 For(this.init, this.condition, this.update, Statement body) : super(body); |
323 | 574 |
324 accept(NodeVisitor visitor) => visitor.visitFor(this); | 575 T accept<T>(NodeVisitor<T> visitor) => visitor.visitFor(this); |
325 | 576 |
326 void visitChildren(NodeVisitor visitor) { | 577 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 578 visitor.visitFor(this, arg); |
| 579 |
| 580 void visitChildren<T>(NodeVisitor<T> visitor) { |
327 if (init != null) init.accept(visitor); | 581 if (init != null) init.accept(visitor); |
328 if (condition != null) condition.accept(visitor); | 582 if (condition != null) condition.accept(visitor); |
329 if (update != null) update.accept(visitor); | 583 if (update != null) update.accept(visitor); |
330 body.accept(visitor); | 584 body.accept(visitor); |
331 } | 585 } |
332 | 586 |
| 587 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) { |
| 588 if (init != null) init.accept1(visitor, arg); |
| 589 if (condition != null) condition.accept1(visitor, arg); |
| 590 if (update != null) update.accept1(visitor, arg); |
| 591 body.accept1(visitor, arg); |
| 592 } |
| 593 |
333 For _clone() => new For(init, condition, update, body); | 594 For _clone() => new For(init, condition, update, body); |
334 } | 595 } |
335 | 596 |
336 class ForIn extends Loop { | 597 class ForIn extends Loop { |
337 // Note that [VariableDeclarationList] is a subclass of [Expression]. | 598 // Note that [VariableDeclarationList] is a subclass of [Expression]. |
338 // Therefore we can type the leftHandSide as [Expression]. | 599 // Therefore we can type the leftHandSide as [Expression]. |
339 final Expression leftHandSide; | 600 final Expression leftHandSide; |
340 final Expression object; | 601 final Expression object; |
341 | 602 |
342 ForIn(this.leftHandSide, this.object, Statement body) : super(body); | 603 ForIn(this.leftHandSide, this.object, Statement body) : super(body); |
343 | 604 |
344 accept(NodeVisitor visitor) => visitor.visitForIn(this); | 605 T accept<T>(NodeVisitor<T> visitor) => visitor.visitForIn(this); |
345 | 606 |
346 void visitChildren(NodeVisitor visitor) { | 607 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 608 visitor.visitForIn(this, arg); |
| 609 |
| 610 void visitChildren<T>(NodeVisitor<T> visitor) { |
347 leftHandSide.accept(visitor); | 611 leftHandSide.accept(visitor); |
348 object.accept(visitor); | 612 object.accept(visitor); |
349 body.accept(visitor); | 613 body.accept(visitor); |
350 } | 614 } |
351 | 615 |
| 616 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) { |
| 617 leftHandSide.accept1(visitor, arg); |
| 618 object.accept1(visitor, arg); |
| 619 body.accept1(visitor, arg); |
| 620 } |
| 621 |
352 ForIn _clone() => new ForIn(leftHandSide, object, body); | 622 ForIn _clone() => new ForIn(leftHandSide, object, body); |
353 } | 623 } |
354 | 624 |
355 class While extends Loop { | 625 class While extends Loop { |
356 final Node condition; | 626 final Node condition; |
357 | 627 |
358 While(this.condition, Statement body) : super(body); | 628 While(this.condition, Statement body) : super(body); |
359 | 629 |
360 accept(NodeVisitor visitor) => visitor.visitWhile(this); | 630 T accept<T>(NodeVisitor<T> visitor) => visitor.visitWhile(this); |
361 | 631 |
362 void visitChildren(NodeVisitor visitor) { | 632 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 633 visitor.visitWhile(this, arg); |
| 634 |
| 635 void visitChildren<T>(NodeVisitor<T> visitor) { |
363 condition.accept(visitor); | 636 condition.accept(visitor); |
364 body.accept(visitor); | 637 body.accept(visitor); |
365 } | 638 } |
366 | 639 |
| 640 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) { |
| 641 condition.accept1(visitor, arg); |
| 642 body.accept1(visitor, arg); |
| 643 } |
| 644 |
367 While _clone() => new While(condition, body); | 645 While _clone() => new While(condition, body); |
368 } | 646 } |
369 | 647 |
370 class Do extends Loop { | 648 class Do extends Loop { |
371 final Expression condition; | 649 final Expression condition; |
372 | 650 |
373 Do(Statement body, this.condition) : super(body); | 651 Do(Statement body, this.condition) : super(body); |
374 | 652 |
375 accept(NodeVisitor visitor) => visitor.visitDo(this); | 653 T accept<T>(NodeVisitor<T> visitor) => visitor.visitDo(this); |
376 | 654 |
377 void visitChildren(NodeVisitor visitor) { | 655 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 656 visitor.visitDo(this, arg); |
| 657 |
| 658 void visitChildren<T>(NodeVisitor<T> visitor) { |
378 body.accept(visitor); | 659 body.accept(visitor); |
379 condition.accept(visitor); | 660 condition.accept(visitor); |
380 } | 661 } |
381 | 662 |
| 663 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) { |
| 664 body.accept1(visitor, arg); |
| 665 condition.accept1(visitor, arg); |
| 666 } |
| 667 |
382 Do _clone() => new Do(body, condition); | 668 Do _clone() => new Do(body, condition); |
383 } | 669 } |
384 | 670 |
385 class Continue extends Statement { | 671 class Continue extends Statement { |
386 final String targetLabel; // Can be null. | 672 final String targetLabel; // Can be null. |
387 | 673 |
388 Continue(this.targetLabel); | 674 Continue(this.targetLabel); |
389 | 675 |
390 accept(NodeVisitor visitor) => visitor.visitContinue(this); | 676 T accept<T>(NodeVisitor<T> visitor) => visitor.visitContinue(this); |
391 void visitChildren(NodeVisitor visitor) {} | 677 |
| 678 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 679 visitor.visitContinue(this, arg); |
| 680 |
| 681 void visitChildren<T>(NodeVisitor<T> visitor) {} |
| 682 |
| 683 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) {} |
392 | 684 |
393 Continue _clone() => new Continue(targetLabel); | 685 Continue _clone() => new Continue(targetLabel); |
394 } | 686 } |
395 | 687 |
396 class Break extends Statement { | 688 class Break extends Statement { |
397 final String targetLabel; // Can be null. | 689 final String targetLabel; // Can be null. |
398 | 690 |
399 Break(this.targetLabel); | 691 Break(this.targetLabel); |
400 | 692 |
401 accept(NodeVisitor visitor) => visitor.visitBreak(this); | 693 T accept<T>(NodeVisitor<T> visitor) => visitor.visitBreak(this); |
402 void visitChildren(NodeVisitor visitor) {} | 694 |
| 695 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 696 visitor.visitBreak(this, arg); |
| 697 |
| 698 void visitChildren<T>(NodeVisitor<T> visitor) {} |
| 699 |
| 700 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) {} |
403 | 701 |
404 Break _clone() => new Break(targetLabel); | 702 Break _clone() => new Break(targetLabel); |
405 } | 703 } |
406 | 704 |
407 class Return extends Statement { | 705 class Return extends Statement { |
408 final Expression value; // Can be null. | 706 final Expression value; // Can be null. |
409 | 707 |
410 Return([this.value = null]); | 708 Return([this.value = null]); |
411 | 709 |
412 accept(NodeVisitor visitor) => visitor.visitReturn(this); | 710 T accept<T>(NodeVisitor<T> visitor) => visitor.visitReturn(this); |
413 | 711 |
414 void visitChildren(NodeVisitor visitor) { | 712 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 713 visitor.visitReturn(this, arg); |
| 714 |
| 715 void visitChildren<T>(NodeVisitor<T> visitor) { |
415 if (value != null) value.accept(visitor); | 716 if (value != null) value.accept(visitor); |
416 } | 717 } |
417 | 718 |
| 719 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) { |
| 720 if (value != null) value.accept1(visitor, arg); |
| 721 } |
| 722 |
418 Return _clone() => new Return(value); | 723 Return _clone() => new Return(value); |
419 } | 724 } |
420 | 725 |
421 class Throw extends Statement { | 726 class Throw extends Statement { |
422 final Expression expression; | 727 final Expression expression; |
423 | 728 |
424 Throw(this.expression); | 729 Throw(this.expression); |
425 | 730 |
426 accept(NodeVisitor visitor) => visitor.visitThrow(this); | 731 T accept<T>(NodeVisitor<T> visitor) => visitor.visitThrow(this); |
427 | 732 |
428 void visitChildren(NodeVisitor visitor) { | 733 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 734 visitor.visitThrow(this, arg); |
| 735 |
| 736 void visitChildren<T>(NodeVisitor<T> visitor) { |
429 expression.accept(visitor); | 737 expression.accept(visitor); |
430 } | 738 } |
431 | 739 |
| 740 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) { |
| 741 expression.accept1(visitor, arg); |
| 742 } |
| 743 |
432 Throw _clone() => new Throw(expression); | 744 Throw _clone() => new Throw(expression); |
433 } | 745 } |
434 | 746 |
435 class Try extends Statement { | 747 class Try extends Statement { |
436 final Block body; | 748 final Block body; |
437 final Catch catchPart; // Can be null if [finallyPart] is non-null. | 749 final Catch catchPart; // Can be null if [finallyPart] is non-null. |
438 final Block finallyPart; // Can be null if [catchPart] is non-null. | 750 final Block finallyPart; // Can be null if [catchPart] is non-null. |
439 | 751 |
440 Try(this.body, this.catchPart, this.finallyPart) { | 752 Try(this.body, this.catchPart, this.finallyPart) { |
441 assert(catchPart != null || finallyPart != null); | 753 assert(catchPart != null || finallyPart != null); |
442 } | 754 } |
443 | 755 |
444 accept(NodeVisitor visitor) => visitor.visitTry(this); | 756 T accept<T>(NodeVisitor<T> visitor) => visitor.visitTry(this); |
445 | 757 |
446 void visitChildren(NodeVisitor visitor) { | 758 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 759 visitor.visitTry(this, arg); |
| 760 |
| 761 void visitChildren<T>(NodeVisitor<T> visitor) { |
447 body.accept(visitor); | 762 body.accept(visitor); |
448 if (catchPart != null) catchPart.accept(visitor); | 763 if (catchPart != null) catchPart.accept(visitor); |
449 if (finallyPart != null) finallyPart.accept(visitor); | 764 if (finallyPart != null) finallyPart.accept(visitor); |
450 } | 765 } |
451 | 766 |
| 767 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) { |
| 768 body.accept1(visitor, arg); |
| 769 if (catchPart != null) catchPart.accept1(visitor, arg); |
| 770 if (finallyPart != null) finallyPart.accept1(visitor, arg); |
| 771 } |
| 772 |
452 Try _clone() => new Try(body, catchPart, finallyPart); | 773 Try _clone() => new Try(body, catchPart, finallyPart); |
453 } | 774 } |
454 | 775 |
455 class Catch extends Node { | 776 class Catch extends Node { |
456 final Declaration declaration; | 777 final Declaration declaration; |
457 final Block body; | 778 final Block body; |
458 | 779 |
459 Catch(this.declaration, this.body); | 780 Catch(this.declaration, this.body); |
460 | 781 |
461 accept(NodeVisitor visitor) => visitor.visitCatch(this); | 782 T accept<T>(NodeVisitor<T> visitor) => visitor.visitCatch(this); |
462 | 783 |
463 void visitChildren(NodeVisitor visitor) { | 784 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 785 visitor.visitCatch(this, arg); |
| 786 |
| 787 void visitChildren<T>(NodeVisitor<T> visitor) { |
464 declaration.accept(visitor); | 788 declaration.accept(visitor); |
465 body.accept(visitor); | 789 body.accept(visitor); |
466 } | 790 } |
467 | 791 |
| 792 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) { |
| 793 declaration.accept1(visitor, arg); |
| 794 body.accept1(visitor, arg); |
| 795 } |
| 796 |
468 Catch _clone() => new Catch(declaration, body); | 797 Catch _clone() => new Catch(declaration, body); |
469 } | 798 } |
470 | 799 |
471 class Switch extends Statement { | 800 class Switch extends Statement { |
472 final Expression key; | 801 final Expression key; |
473 final List<SwitchClause> cases; | 802 final List<SwitchClause> cases; |
474 | 803 |
475 Switch(this.key, this.cases); | 804 Switch(this.key, this.cases); |
476 | 805 |
477 accept(NodeVisitor visitor) => visitor.visitSwitch(this); | 806 T accept<T>(NodeVisitor<T> visitor) => visitor.visitSwitch(this); |
478 | 807 |
479 void visitChildren(NodeVisitor visitor) { | 808 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 809 visitor.visitSwitch(this, arg); |
| 810 |
| 811 void visitChildren<T>(NodeVisitor<T> visitor) { |
480 key.accept(visitor); | 812 key.accept(visitor); |
481 for (SwitchClause clause in cases) clause.accept(visitor); | 813 for (SwitchClause clause in cases) clause.accept(visitor); |
482 } | 814 } |
483 | 815 |
| 816 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) { |
| 817 key.accept1(visitor, arg); |
| 818 for (SwitchClause clause in cases) clause.accept1(visitor, arg); |
| 819 } |
| 820 |
484 Switch _clone() => new Switch(key, cases); | 821 Switch _clone() => new Switch(key, cases); |
485 } | 822 } |
486 | 823 |
487 abstract class SwitchClause extends Node { | 824 abstract class SwitchClause extends Node { |
488 final Block body; | 825 final Block body; |
489 | 826 |
490 SwitchClause(this.body); | 827 SwitchClause(this.body); |
491 } | 828 } |
492 | 829 |
493 class Case extends SwitchClause { | 830 class Case extends SwitchClause { |
494 final Expression expression; | 831 final Expression expression; |
495 | 832 |
496 Case(this.expression, Block body) : super(body); | 833 Case(this.expression, Block body) : super(body); |
497 | 834 |
498 accept(NodeVisitor visitor) => visitor.visitCase(this); | 835 T accept<T>(NodeVisitor<T> visitor) => visitor.visitCase(this); |
499 | 836 |
500 void visitChildren(NodeVisitor visitor) { | 837 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 838 visitor.visitCase(this, arg); |
| 839 |
| 840 void visitChildren<T>(NodeVisitor<T> visitor) { |
501 expression.accept(visitor); | 841 expression.accept(visitor); |
502 body.accept(visitor); | 842 body.accept(visitor); |
503 } | 843 } |
504 | 844 |
| 845 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) { |
| 846 expression.accept1(visitor, arg); |
| 847 body.accept1(visitor, arg); |
| 848 } |
| 849 |
505 Case _clone() => new Case(expression, body); | 850 Case _clone() => new Case(expression, body); |
506 } | 851 } |
507 | 852 |
508 class Default extends SwitchClause { | 853 class Default extends SwitchClause { |
509 Default(Block body) : super(body); | 854 Default(Block body) : super(body); |
510 | 855 |
511 accept(NodeVisitor visitor) => visitor.visitDefault(this); | 856 T accept<T>(NodeVisitor<T> visitor) => visitor.visitDefault(this); |
512 | 857 |
513 void visitChildren(NodeVisitor visitor) { | 858 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 859 visitor.visitDefault(this, arg); |
| 860 |
| 861 void visitChildren<T>(NodeVisitor<T> visitor) { |
514 body.accept(visitor); | 862 body.accept(visitor); |
515 } | 863 } |
516 | 864 |
| 865 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) { |
| 866 body.accept1(visitor, arg); |
| 867 } |
| 868 |
517 Default _clone() => new Default(body); | 869 Default _clone() => new Default(body); |
518 } | 870 } |
519 | 871 |
520 class FunctionDeclaration extends Statement { | 872 class FunctionDeclaration extends Statement { |
521 final Declaration name; | 873 final Declaration name; |
522 final Fun function; | 874 final Fun function; |
523 | 875 |
524 FunctionDeclaration(this.name, this.function); | 876 FunctionDeclaration(this.name, this.function); |
525 | 877 |
526 accept(NodeVisitor visitor) => visitor.visitFunctionDeclaration(this); | 878 T accept<T>(NodeVisitor<T> visitor) => visitor.visitFunctionDeclaration(this); |
527 | 879 |
528 void visitChildren(NodeVisitor visitor) { | 880 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 881 visitor.visitFunctionDeclaration(this, arg); |
| 882 |
| 883 void visitChildren<T>(NodeVisitor<T> visitor) { |
529 name.accept(visitor); | 884 name.accept(visitor); |
530 function.accept(visitor); | 885 function.accept(visitor); |
531 } | 886 } |
532 | 887 |
| 888 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) { |
| 889 name.accept1(visitor, arg); |
| 890 function.accept1(visitor, arg); |
| 891 } |
| 892 |
533 FunctionDeclaration _clone() => new FunctionDeclaration(name, function); | 893 FunctionDeclaration _clone() => new FunctionDeclaration(name, function); |
534 } | 894 } |
535 | 895 |
536 class LabeledStatement extends Statement { | 896 class LabeledStatement extends Statement { |
537 final String label; | 897 final String label; |
538 final Statement body; | 898 final Statement body; |
539 | 899 |
540 LabeledStatement(this.label, this.body); | 900 LabeledStatement(this.label, this.body); |
541 | 901 |
542 accept(NodeVisitor visitor) => visitor.visitLabeledStatement(this); | 902 T accept<T>(NodeVisitor<T> visitor) => visitor.visitLabeledStatement(this); |
543 | 903 |
544 void visitChildren(NodeVisitor visitor) { | 904 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 905 visitor.visitLabeledStatement(this, arg); |
| 906 |
| 907 void visitChildren<T>(NodeVisitor<T> visitor) { |
545 body.accept(visitor); | 908 body.accept(visitor); |
546 } | 909 } |
547 | 910 |
| 911 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) { |
| 912 body.accept1(visitor, arg); |
| 913 } |
| 914 |
548 LabeledStatement _clone() => new LabeledStatement(label, body); | 915 LabeledStatement _clone() => new LabeledStatement(label, body); |
549 } | 916 } |
550 | 917 |
551 class LiteralStatement extends Statement { | 918 class LiteralStatement extends Statement { |
552 final String code; | 919 final String code; |
553 | 920 |
554 LiteralStatement(this.code); | 921 LiteralStatement(this.code); |
555 | 922 |
556 accept(NodeVisitor visitor) => visitor.visitLiteralStatement(this); | 923 T accept<T>(NodeVisitor<T> visitor) => visitor.visitLiteralStatement(this); |
557 void visitChildren(NodeVisitor visitor) {} | 924 |
| 925 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 926 visitor.visitLiteralStatement(this, arg); |
| 927 |
| 928 void visitChildren<T>(NodeVisitor<T> visitor) {} |
| 929 |
| 930 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) {} |
558 | 931 |
559 LiteralStatement _clone() => new LiteralStatement(code); | 932 LiteralStatement _clone() => new LiteralStatement(code); |
560 } | 933 } |
561 | 934 |
562 // Not a real JavaScript node, but represents the yield statement from a dart | 935 // Not a real JavaScript node, but represents the yield statement from a dart |
563 // program translated to JavaScript. | 936 // program translated to JavaScript. |
564 class DartYield extends Statement { | 937 class DartYield extends Statement { |
565 final Expression expression; | 938 final Expression expression; |
566 | 939 |
567 final bool hasStar; | 940 final bool hasStar; |
568 | 941 |
569 DartYield(this.expression, this.hasStar); | 942 DartYield(this.expression, this.hasStar); |
570 | 943 |
571 accept(NodeVisitor visitor) => visitor.visitDartYield(this); | 944 T accept<T>(NodeVisitor<T> visitor) => visitor.visitDartYield(this); |
572 | 945 |
573 void visitChildren(NodeVisitor visitor) { | 946 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 947 visitor.visitDartYield(this, arg); |
| 948 |
| 949 void visitChildren<T>(NodeVisitor<T> visitor) { |
574 expression.accept(visitor); | 950 expression.accept(visitor); |
575 } | 951 } |
576 | 952 |
| 953 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) { |
| 954 expression.accept1(visitor, arg); |
| 955 } |
| 956 |
577 DartYield _clone() => new DartYield(expression, hasStar); | 957 DartYield _clone() => new DartYield(expression, hasStar); |
578 } | 958 } |
579 | 959 |
580 abstract class Expression extends Node { | 960 abstract class Expression extends Node { |
581 int get precedenceLevel; | 961 int get precedenceLevel; |
582 | 962 |
583 Statement toStatement() => new ExpressionStatement(this); | 963 Statement toStatement() => new ExpressionStatement(this); |
584 } | 964 } |
585 | 965 |
586 abstract class Declaration implements VariableReference {} | 966 abstract class Declaration implements VariableReference {} |
587 | 967 |
588 /// An implementation of [Name] represents a potentially late bound name in | 968 /// An implementation of [Name] represents a potentially late bound name in |
589 /// the generated ast. | 969 /// the generated ast. |
590 /// | 970 /// |
591 /// While [Name] implements comparable, there is no requirement on the actual | 971 /// While [Name] implements comparable, there is no requirement on the actual |
592 /// implementation of [compareTo] other than that it needs to be stable. | 972 /// implementation of [compareTo] other than that it needs to be stable. |
593 /// In particular, there is no guarantee that implementations of [compareTo] | 973 /// In particular, there is no guarantee that implementations of [compareTo] |
594 /// will implement some form of lexicographic ordering like [String.compareTo]. | 974 /// will implement some form of lexicographic ordering like [String.compareTo]. |
595 abstract class Name extends Literal | 975 abstract class Name extends Literal |
596 implements Declaration, Parameter, Comparable { | 976 implements Declaration, Parameter, Comparable { |
597 accept(NodeVisitor visitor) => visitor.visitName(this); | 977 T accept<T>(NodeVisitor<T> visitor) => visitor.visitName(this); |
| 978 |
| 979 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 980 visitor.visitName(this, arg); |
598 | 981 |
599 /// Returns a unique [key] for this name. | 982 /// Returns a unique [key] for this name. |
600 /// | 983 /// |
601 /// The key is unrelated to the actual name and is not intended for human | 984 /// The key is unrelated to the actual name and is not intended for human |
602 /// consumption. As such, it might be long or cryptic. | 985 /// consumption. As such, it might be long or cryptic. |
603 String get key; | 986 String get key; |
604 | 987 |
605 bool get allowRename => false; | 988 bool get allowRename => false; |
606 } | 989 } |
607 | 990 |
608 class LiteralStringFromName extends LiteralString { | 991 class LiteralStringFromName extends LiteralString { |
609 Name name; | 992 Name name; |
610 | 993 |
611 LiteralStringFromName(this.name) : super(null); | 994 LiteralStringFromName(this.name) : super(null); |
612 | 995 |
613 String get value => '"${name.name}"'; | 996 String get value => '"${name.name}"'; |
614 | 997 |
615 void visitChildren(NodeVisitor visitor) { | 998 void visitChildren<T>(NodeVisitor<T> visitor) { |
616 name.accept(visitor); | 999 name.accept(visitor); |
617 } | 1000 } |
| 1001 |
| 1002 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) { |
| 1003 name.accept1(visitor, arg); |
| 1004 } |
618 } | 1005 } |
619 | 1006 |
620 class LiteralExpression extends Expression { | 1007 class LiteralExpression extends Expression { |
621 final String template; | 1008 final String template; |
622 final List<Expression> inputs; | 1009 final List<Expression> inputs; |
623 | 1010 |
624 LiteralExpression(this.template) : inputs = const []; | 1011 LiteralExpression(this.template) : inputs = const []; |
| 1012 |
625 LiteralExpression.withData(this.template, this.inputs); | 1013 LiteralExpression.withData(this.template, this.inputs); |
626 | 1014 |
627 accept(NodeVisitor visitor) => visitor.visitLiteralExpression(this); | 1015 T accept<T>(NodeVisitor<T> visitor) => visitor.visitLiteralExpression(this); |
628 | 1016 |
629 void visitChildren(NodeVisitor visitor) { | 1017 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 1018 visitor.visitLiteralExpression(this, arg); |
| 1019 |
| 1020 void visitChildren<T>(NodeVisitor<T> visitor) { |
630 if (inputs != null) { | 1021 if (inputs != null) { |
631 for (Expression expr in inputs) expr.accept(visitor); | 1022 for (Expression expr in inputs) expr.accept(visitor); |
632 } | 1023 } |
633 } | 1024 } |
634 | 1025 |
| 1026 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) { |
| 1027 if (inputs != null) { |
| 1028 for (Expression expr in inputs) expr.accept1(visitor, arg); |
| 1029 } |
| 1030 } |
| 1031 |
635 LiteralExpression _clone() => | 1032 LiteralExpression _clone() => |
636 new LiteralExpression.withData(template, inputs); | 1033 new LiteralExpression.withData(template, inputs); |
637 | 1034 |
638 // Code that uses JS must take care of operator precedences, and | 1035 // Code that uses JS must take care of operator precedences, and |
639 // put parenthesis if needed. | 1036 // put parenthesis if needed. |
640 int get precedenceLevel => PRIMARY; | 1037 int get precedenceLevel => PRIMARY; |
641 } | 1038 } |
642 | 1039 |
643 /** | 1040 /** |
644 * [VariableDeclarationList] is a subclass of [Expression] to simplify the | 1041 * [VariableDeclarationList] is a subclass of [Expression] to simplify the |
645 * AST. | 1042 * AST. |
646 */ | 1043 */ |
647 class VariableDeclarationList extends Expression { | 1044 class VariableDeclarationList extends Expression { |
648 final List<VariableInitialization> declarations; | 1045 final List<VariableInitialization> declarations; |
649 | 1046 |
650 VariableDeclarationList(this.declarations); | 1047 VariableDeclarationList(this.declarations); |
651 | 1048 |
652 accept(NodeVisitor visitor) => visitor.visitVariableDeclarationList(this); | 1049 T accept<T>(NodeVisitor<T> visitor) => |
| 1050 visitor.visitVariableDeclarationList(this); |
653 | 1051 |
654 void visitChildren(NodeVisitor visitor) { | 1052 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 1053 visitor.visitVariableDeclarationList(this, arg); |
| 1054 |
| 1055 void visitChildren<T>(NodeVisitor<T> visitor) { |
655 for (VariableInitialization declaration in declarations) { | 1056 for (VariableInitialization declaration in declarations) { |
656 declaration.accept(visitor); | 1057 declaration.accept(visitor); |
657 } | 1058 } |
658 } | 1059 } |
659 | 1060 |
| 1061 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) { |
| 1062 for (VariableInitialization declaration in declarations) { |
| 1063 declaration.accept1(visitor, arg); |
| 1064 } |
| 1065 } |
| 1066 |
660 VariableDeclarationList _clone() => new VariableDeclarationList(declarations); | 1067 VariableDeclarationList _clone() => new VariableDeclarationList(declarations); |
661 | 1068 |
662 int get precedenceLevel => EXPRESSION; | 1069 int get precedenceLevel => EXPRESSION; |
663 } | 1070 } |
664 | 1071 |
665 class Assignment extends Expression { | 1072 class Assignment extends Expression { |
666 final Expression leftHandSide; | 1073 final Expression leftHandSide; |
667 final String op; // Null, if the assignment is not compound. | 1074 final String op; // Null, if the assignment is not compound. |
668 final Expression value; // May be null, for [VariableInitialization]s. | 1075 final Expression value; // May be null, for [VariableInitialization]s. |
669 | 1076 |
670 Assignment(leftHandSide, value) : this.compound(leftHandSide, null, value); | 1077 Assignment(leftHandSide, value) : this.compound(leftHandSide, null, value); |
| 1078 |
671 // If `this.op == null` this will be a non-compound assignment. | 1079 // If `this.op == null` this will be a non-compound assignment. |
672 Assignment.compound(this.leftHandSide, this.op, this.value); | 1080 Assignment.compound(this.leftHandSide, this.op, this.value); |
673 | 1081 |
674 int get precedenceLevel => ASSIGNMENT; | 1082 int get precedenceLevel => ASSIGNMENT; |
675 | 1083 |
676 bool get isCompound => op != null; | 1084 bool get isCompound => op != null; |
677 | 1085 |
678 accept(NodeVisitor visitor) => visitor.visitAssignment(this); | 1086 T accept<T>(NodeVisitor<T> visitor) => visitor.visitAssignment(this); |
679 | 1087 |
680 void visitChildren(NodeVisitor visitor) { | 1088 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 1089 visitor.visitAssignment(this, arg); |
| 1090 |
| 1091 void visitChildren<T>(NodeVisitor<T> visitor) { |
681 leftHandSide.accept(visitor); | 1092 leftHandSide.accept(visitor); |
682 if (value != null) value.accept(visitor); | 1093 if (value != null) value.accept(visitor); |
683 } | 1094 } |
684 | 1095 |
| 1096 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) { |
| 1097 leftHandSide.accept1(visitor, arg); |
| 1098 if (value != null) value.accept1(visitor, arg); |
| 1099 } |
| 1100 |
685 Assignment _clone() => new Assignment.compound(leftHandSide, op, value); | 1101 Assignment _clone() => new Assignment.compound(leftHandSide, op, value); |
686 } | 1102 } |
687 | 1103 |
688 class VariableInitialization extends Assignment { | 1104 class VariableInitialization extends Assignment { |
689 /** [value] may be null. */ | 1105 /** [value] may be null. */ |
690 VariableInitialization(Declaration declaration, Expression value) | 1106 VariableInitialization(Declaration declaration, Expression value) |
691 : super(declaration, value); | 1107 : super(declaration, value); |
692 | 1108 |
693 Declaration get declaration => leftHandSide; | 1109 Declaration get declaration => leftHandSide; |
694 | 1110 |
695 accept(NodeVisitor visitor) => visitor.visitVariableInitialization(this); | 1111 T accept<T>(NodeVisitor<T> visitor) => |
| 1112 visitor.visitVariableInitialization(this); |
| 1113 |
| 1114 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 1115 visitor.visitVariableInitialization(this, arg); |
696 | 1116 |
697 VariableInitialization _clone() => | 1117 VariableInitialization _clone() => |
698 new VariableInitialization(declaration, value); | 1118 new VariableInitialization(declaration, value); |
699 } | 1119 } |
700 | 1120 |
701 class Conditional extends Expression { | 1121 class Conditional extends Expression { |
702 final Expression condition; | 1122 final Expression condition; |
703 final Expression then; | 1123 final Expression then; |
704 final Expression otherwise; | 1124 final Expression otherwise; |
705 | 1125 |
706 Conditional(this.condition, this.then, this.otherwise); | 1126 Conditional(this.condition, this.then, this.otherwise); |
707 | 1127 |
708 accept(NodeVisitor visitor) => visitor.visitConditional(this); | 1128 T accept<T>(NodeVisitor<T> visitor) => visitor.visitConditional(this); |
709 | 1129 |
710 void visitChildren(NodeVisitor visitor) { | 1130 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 1131 visitor.visitConditional(this, arg); |
| 1132 |
| 1133 void visitChildren<T>(NodeVisitor<T> visitor) { |
711 condition.accept(visitor); | 1134 condition.accept(visitor); |
712 then.accept(visitor); | 1135 then.accept(visitor); |
713 otherwise.accept(visitor); | 1136 otherwise.accept(visitor); |
714 } | 1137 } |
715 | 1138 |
| 1139 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) { |
| 1140 condition.accept1(visitor, arg); |
| 1141 then.accept1(visitor, arg); |
| 1142 otherwise.accept1(visitor, arg); |
| 1143 } |
| 1144 |
716 Conditional _clone() => new Conditional(condition, then, otherwise); | 1145 Conditional _clone() => new Conditional(condition, then, otherwise); |
717 | 1146 |
718 int get precedenceLevel => ASSIGNMENT; | 1147 int get precedenceLevel => ASSIGNMENT; |
719 } | 1148 } |
720 | 1149 |
721 class Call extends Expression { | 1150 class Call extends Expression { |
722 Expression target; | 1151 Expression target; |
723 List<Expression> arguments; | 1152 List<Expression> arguments; |
724 | 1153 |
725 Call(this.target, this.arguments, | 1154 Call(this.target, this.arguments, |
726 {JavaScriptNodeSourceInformation sourceInformation}) { | 1155 {JavaScriptNodeSourceInformation sourceInformation}) { |
727 this._sourceInformation = sourceInformation; | 1156 this._sourceInformation = sourceInformation; |
728 } | 1157 } |
729 | 1158 |
730 accept(NodeVisitor visitor) => visitor.visitCall(this); | 1159 T accept<T>(NodeVisitor<T> visitor) => visitor.visitCall(this); |
731 | 1160 |
732 void visitChildren(NodeVisitor visitor) { | 1161 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 1162 visitor.visitCall(this, arg); |
| 1163 |
| 1164 void visitChildren<T>(NodeVisitor<T> visitor) { |
733 target.accept(visitor); | 1165 target.accept(visitor); |
734 for (Expression arg in arguments) { | 1166 for (Expression arg in arguments) { |
735 arg.accept(visitor); | 1167 arg.accept(visitor); |
736 } | 1168 } |
737 } | 1169 } |
738 | 1170 |
| 1171 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) { |
| 1172 target.accept1(visitor, arg); |
| 1173 for (Expression arg in arguments) { |
| 1174 arg.accept1(visitor, arg); |
| 1175 } |
| 1176 } |
| 1177 |
739 Call _clone() => new Call(target, arguments); | 1178 Call _clone() => new Call(target, arguments); |
740 | 1179 |
741 int get precedenceLevel => CALL; | 1180 int get precedenceLevel => CALL; |
742 } | 1181 } |
743 | 1182 |
744 class New extends Call { | 1183 class New extends Call { |
745 New(Expression cls, List<Expression> arguments) : super(cls, arguments); | 1184 New(Expression cls, List<Expression> arguments) : super(cls, arguments); |
746 | 1185 |
747 accept(NodeVisitor visitor) => visitor.visitNew(this); | 1186 T accept<T>(NodeVisitor<T> visitor) => visitor.visitNew(this); |
| 1187 |
| 1188 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 1189 visitor.visitNew(this, arg); |
748 | 1190 |
749 New _clone() => new New(target, arguments); | 1191 New _clone() => new New(target, arguments); |
750 } | 1192 } |
751 | 1193 |
752 class Binary extends Expression { | 1194 class Binary extends Expression { |
753 final String op; | 1195 final String op; |
754 final Expression left; | 1196 final Expression left; |
755 final Expression right; | 1197 final Expression right; |
756 | 1198 |
757 Binary(this.op, this.left, this.right); | 1199 Binary(this.op, this.left, this.right); |
758 | 1200 |
759 accept(NodeVisitor visitor) => visitor.visitBinary(this); | 1201 T accept<T>(NodeVisitor<T> visitor) => visitor.visitBinary(this); |
| 1202 |
| 1203 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 1204 visitor.visitBinary(this, arg); |
760 | 1205 |
761 Binary _clone() => new Binary(op, left, right); | 1206 Binary _clone() => new Binary(op, left, right); |
762 | 1207 |
763 void visitChildren(NodeVisitor visitor) { | 1208 void visitChildren<T>(NodeVisitor<T> visitor) { |
764 left.accept(visitor); | 1209 left.accept(visitor); |
765 right.accept(visitor); | 1210 right.accept(visitor); |
766 } | 1211 } |
767 | 1212 |
| 1213 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) { |
| 1214 left.accept1(visitor, arg); |
| 1215 right.accept1(visitor, arg); |
| 1216 } |
| 1217 |
768 bool get isCommaOperator => op == ','; | 1218 bool get isCommaOperator => op == ','; |
769 | 1219 |
770 int get precedenceLevel { | 1220 int get precedenceLevel { |
771 // TODO(floitsch): switch to constant map. | 1221 // TODO(floitsch): switch to constant map. |
772 switch (op) { | 1222 switch (op) { |
773 case "*": | 1223 case "*": |
774 case "/": | 1224 case "/": |
775 case "%": | 1225 case "%": |
776 return MULTIPLICATIVE; | 1226 return MULTIPLICATIVE; |
777 case "+": | 1227 case "+": |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
810 } | 1260 } |
811 } | 1261 } |
812 } | 1262 } |
813 | 1263 |
814 class Prefix extends Expression { | 1264 class Prefix extends Expression { |
815 final String op; | 1265 final String op; |
816 final Expression argument; | 1266 final Expression argument; |
817 | 1267 |
818 Prefix(this.op, this.argument); | 1268 Prefix(this.op, this.argument); |
819 | 1269 |
820 accept(NodeVisitor visitor) => visitor.visitPrefix(this); | 1270 T accept<T>(NodeVisitor<T> visitor) => visitor.visitPrefix(this); |
| 1271 |
| 1272 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 1273 visitor.visitPrefix(this, arg); |
821 | 1274 |
822 Prefix _clone() => new Prefix(op, argument); | 1275 Prefix _clone() => new Prefix(op, argument); |
823 | 1276 |
824 void visitChildren(NodeVisitor visitor) { | 1277 void visitChildren<T>(NodeVisitor<T> visitor) { |
825 argument.accept(visitor); | 1278 argument.accept(visitor); |
826 } | 1279 } |
827 | 1280 |
| 1281 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) { |
| 1282 argument.accept1(visitor, arg); |
| 1283 } |
| 1284 |
828 int get precedenceLevel => UNARY; | 1285 int get precedenceLevel => UNARY; |
829 } | 1286 } |
830 | 1287 |
831 class Postfix extends Expression { | 1288 class Postfix extends Expression { |
832 final String op; | 1289 final String op; |
833 final Expression argument; | 1290 final Expression argument; |
834 | 1291 |
835 Postfix(this.op, this.argument); | 1292 Postfix(this.op, this.argument); |
836 | 1293 |
837 accept(NodeVisitor visitor) => visitor.visitPostfix(this); | 1294 T accept<T>(NodeVisitor<T> visitor) => visitor.visitPostfix(this); |
| 1295 |
| 1296 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 1297 visitor.visitPostfix(this, arg); |
838 | 1298 |
839 Postfix _clone() => new Postfix(op, argument); | 1299 Postfix _clone() => new Postfix(op, argument); |
840 | 1300 |
841 void visitChildren(NodeVisitor visitor) { | 1301 void visitChildren<T>(NodeVisitor<T> visitor) { |
842 argument.accept(visitor); | 1302 argument.accept(visitor); |
843 } | 1303 } |
844 | 1304 |
| 1305 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) { |
| 1306 argument.accept1(visitor, arg); |
| 1307 } |
| 1308 |
845 int get precedenceLevel => UNARY; | 1309 int get precedenceLevel => UNARY; |
846 } | 1310 } |
847 | 1311 |
848 abstract class VariableReference extends Expression { | 1312 abstract class VariableReference extends Expression { |
849 final String name; | 1313 final String name; |
850 | 1314 |
851 VariableReference(this.name) { | 1315 VariableReference(this.name) { |
852 assert(_identifierRE.hasMatch(name)); | 1316 assert(_identifierRE.hasMatch(name)); |
853 } | 1317 } |
| 1318 |
854 static RegExp _identifierRE = new RegExp(r'^[A-Za-z_$][A-Za-z_$0-9]*$'); | 1319 static RegExp _identifierRE = new RegExp(r'^[A-Za-z_$][A-Za-z_$0-9]*$'); |
855 | 1320 |
856 accept(NodeVisitor visitor); | 1321 accept(NodeVisitor visitor); |
| 1322 |
857 int get precedenceLevel => PRIMARY; | 1323 int get precedenceLevel => PRIMARY; |
858 void visitChildren(NodeVisitor visitor) {} | 1324 |
| 1325 void visitChildren<T>(NodeVisitor<T> visitor) {} |
| 1326 |
| 1327 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) {} |
859 } | 1328 } |
860 | 1329 |
861 class VariableUse extends VariableReference { | 1330 class VariableUse extends VariableReference { |
862 VariableUse(String name) : super(name); | 1331 VariableUse(String name) : super(name); |
863 | 1332 |
864 accept(NodeVisitor visitor) => visitor.visitVariableUse(this); | 1333 T accept<T>(NodeVisitor<T> visitor) => visitor.visitVariableUse(this); |
| 1334 |
| 1335 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 1336 visitor.visitVariableUse(this, arg); |
| 1337 |
865 VariableUse _clone() => new VariableUse(name); | 1338 VariableUse _clone() => new VariableUse(name); |
866 | 1339 |
867 VariableUse asVariableUse() => this; | 1340 VariableUse asVariableUse() => this; |
868 | 1341 |
869 toString() => 'VariableUse($name)'; | 1342 String toString() => 'VariableUse($name)'; |
870 } | 1343 } |
871 | 1344 |
872 class VariableDeclaration extends VariableReference implements Declaration { | 1345 class VariableDeclaration extends VariableReference implements Declaration { |
873 final bool allowRename; | 1346 final bool allowRename; |
| 1347 |
874 VariableDeclaration(String name, {this.allowRename: true}) : super(name); | 1348 VariableDeclaration(String name, {this.allowRename: true}) : super(name); |
875 | 1349 |
876 accept(NodeVisitor visitor) => visitor.visitVariableDeclaration(this); | 1350 T accept<T>(NodeVisitor<T> visitor) => visitor.visitVariableDeclaration(this); |
| 1351 |
| 1352 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 1353 visitor.visitVariableDeclaration(this, arg); |
| 1354 |
877 VariableDeclaration _clone() => new VariableDeclaration(name); | 1355 VariableDeclaration _clone() => new VariableDeclaration(name); |
878 } | 1356 } |
879 | 1357 |
880 class Parameter extends VariableDeclaration { | 1358 class Parameter extends VariableDeclaration { |
881 Parameter(String name) : super(name); | 1359 Parameter(String name) : super(name); |
882 | 1360 |
883 accept(NodeVisitor visitor) => visitor.visitParameter(this); | 1361 T accept<T>(NodeVisitor<T> visitor) => visitor.visitParameter(this); |
| 1362 |
| 1363 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 1364 visitor.visitParameter(this, arg); |
| 1365 |
884 Parameter _clone() => new Parameter(name); | 1366 Parameter _clone() => new Parameter(name); |
885 } | 1367 } |
886 | 1368 |
887 class This extends Parameter { | 1369 class This extends Parameter { |
888 This() : super("this"); | 1370 This() : super("this"); |
889 | 1371 |
890 accept(NodeVisitor visitor) => visitor.visitThis(this); | 1372 T accept<T>(NodeVisitor<T> visitor) => visitor.visitThis(this); |
| 1373 |
| 1374 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 1375 visitor.visitThis(this, arg); |
| 1376 |
891 This _clone() => new This(); | 1377 This _clone() => new This(); |
892 } | 1378 } |
893 | 1379 |
894 class NamedFunction extends Expression { | 1380 class NamedFunction extends Expression { |
895 final Declaration name; | 1381 final Declaration name; |
896 final Fun function; | 1382 final Fun function; |
897 | 1383 |
898 NamedFunction(this.name, this.function); | 1384 NamedFunction(this.name, this.function); |
899 | 1385 |
900 accept(NodeVisitor visitor) => visitor.visitNamedFunction(this); | 1386 T accept<T>(NodeVisitor<T> visitor) => visitor.visitNamedFunction(this); |
901 | 1387 |
902 void visitChildren(NodeVisitor visitor) { | 1388 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 1389 visitor.visitNamedFunction(this, arg); |
| 1390 |
| 1391 void visitChildren<T>(NodeVisitor<T> visitor) { |
903 name.accept(visitor); | 1392 name.accept(visitor); |
904 function.accept(visitor); | 1393 function.accept(visitor); |
905 } | 1394 } |
906 | 1395 |
| 1396 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) { |
| 1397 name.accept1(visitor, arg); |
| 1398 function.accept1(visitor, arg); |
| 1399 } |
| 1400 |
907 NamedFunction _clone() => new NamedFunction(name, function); | 1401 NamedFunction _clone() => new NamedFunction(name, function); |
908 | 1402 |
909 int get precedenceLevel => LEFT_HAND_SIDE; | 1403 int get precedenceLevel => LEFT_HAND_SIDE; |
910 } | 1404 } |
911 | 1405 |
912 class Fun extends Expression { | 1406 class Fun extends Expression { |
913 final List<Parameter> params; | 1407 final List<Parameter> params; |
914 final Block body; | 1408 final Block body; |
915 final AsyncModifier asyncModifier; | 1409 final AsyncModifier asyncModifier; |
916 | 1410 |
917 Fun(this.params, this.body, {this.asyncModifier: const AsyncModifier.sync()}); | 1411 Fun(this.params, this.body, {this.asyncModifier: const AsyncModifier.sync()}); |
918 | 1412 |
919 accept(NodeVisitor visitor) => visitor.visitFun(this); | 1413 T accept<T>(NodeVisitor<T> visitor) => visitor.visitFun(this); |
920 | 1414 |
921 void visitChildren(NodeVisitor visitor) { | 1415 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 1416 visitor.visitFun(this, arg); |
| 1417 |
| 1418 void visitChildren<T>(NodeVisitor<T> visitor) { |
922 for (Parameter param in params) param.accept(visitor); | 1419 for (Parameter param in params) param.accept(visitor); |
923 body.accept(visitor); | 1420 body.accept(visitor); |
924 } | 1421 } |
925 | 1422 |
| 1423 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) { |
| 1424 for (Parameter param in params) param.accept1(visitor, arg); |
| 1425 body.accept1(visitor, arg); |
| 1426 } |
| 1427 |
926 Fun _clone() => new Fun(params, body, asyncModifier: asyncModifier); | 1428 Fun _clone() => new Fun(params, body, asyncModifier: asyncModifier); |
927 | 1429 |
928 int get precedenceLevel => LEFT_HAND_SIDE; | 1430 int get precedenceLevel => LEFT_HAND_SIDE; |
929 } | 1431 } |
930 | 1432 |
931 class AsyncModifier { | 1433 class AsyncModifier { |
932 final bool isAsync; | 1434 final bool isAsync; |
933 final bool isYielding; | 1435 final bool isYielding; |
934 final String description; | 1436 final String description; |
935 | 1437 |
(...skipping 14 matching lines...) Expand all Loading... |
950 isYielding = true, | 1452 isYielding = true, |
951 description = "sync*"; | 1453 description = "sync*"; |
952 toString() => description; | 1454 toString() => description; |
953 } | 1455 } |
954 | 1456 |
955 class PropertyAccess extends Expression { | 1457 class PropertyAccess extends Expression { |
956 final Expression receiver; | 1458 final Expression receiver; |
957 final Expression selector; | 1459 final Expression selector; |
958 | 1460 |
959 PropertyAccess(this.receiver, this.selector); | 1461 PropertyAccess(this.receiver, this.selector); |
| 1462 |
960 PropertyAccess.field(this.receiver, String fieldName) | 1463 PropertyAccess.field(this.receiver, String fieldName) |
961 : selector = new LiteralString('"$fieldName"'); | 1464 : selector = new LiteralString('"$fieldName"'); |
| 1465 |
962 PropertyAccess.indexed(this.receiver, int index) | 1466 PropertyAccess.indexed(this.receiver, int index) |
963 : selector = new LiteralNumber('$index'); | 1467 : selector = new LiteralNumber('$index'); |
964 | 1468 |
965 accept(NodeVisitor visitor) => visitor.visitAccess(this); | 1469 T accept<T>(NodeVisitor<T> visitor) => visitor.visitAccess(this); |
966 | 1470 |
967 void visitChildren(NodeVisitor visitor) { | 1471 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 1472 visitor.visitAccess(this, arg); |
| 1473 |
| 1474 void visitChildren<T>(NodeVisitor<T> visitor) { |
968 receiver.accept(visitor); | 1475 receiver.accept(visitor); |
969 selector.accept(visitor); | 1476 selector.accept(visitor); |
970 } | 1477 } |
971 | 1478 |
| 1479 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) { |
| 1480 receiver.accept1(visitor, arg); |
| 1481 selector.accept1(visitor, arg); |
| 1482 } |
| 1483 |
972 PropertyAccess _clone() => new PropertyAccess(receiver, selector); | 1484 PropertyAccess _clone() => new PropertyAccess(receiver, selector); |
973 | 1485 |
974 int get precedenceLevel => LEFT_HAND_SIDE; | 1486 int get precedenceLevel => LEFT_HAND_SIDE; |
975 } | 1487 } |
976 | 1488 |
977 /// A [DeferredToken] is a placeholder for some [Expression] that is not known | 1489 /// A [DeferredToken] is a placeholder for some [Expression] that is not known |
978 /// at construction time of an ast. Unlike [InterpolatedExpression], | 1490 /// at construction time of an ast. Unlike [InterpolatedExpression], |
979 /// [DeferredToken] is not limited to templates but may also occur in | 1491 /// [DeferredToken] is not limited to templates but may also occur in |
980 /// fully instantiated asts. | 1492 /// fully instantiated asts. |
981 abstract class DeferredToken extends Expression { | 1493 abstract class DeferredToken extends Expression { |
982 void visitChildren(NodeVisitor visitor) {} | 1494 void visitChildren<T>(NodeVisitor<T> visitor) {} |
| 1495 |
| 1496 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) {} |
983 | 1497 |
984 DeferredToken _clone() => this; | 1498 DeferredToken _clone() => this; |
985 } | 1499 } |
986 | 1500 |
987 /// Interface for a deferred integer value. An implementation has to provide | 1501 /// Interface for a deferred integer value. An implementation has to provide |
988 /// a value via the [value] getter the latest when the ast is printed. | 1502 /// a value via the [value] getter the latest when the ast is printed. |
989 abstract class DeferredNumber extends DeferredToken implements Literal { | 1503 abstract class DeferredNumber extends DeferredToken implements Literal { |
990 accept(NodeVisitor visitor) => visitor.visitDeferredNumber(this); | 1504 T accept<T>(NodeVisitor<T> visitor) => visitor.visitDeferredNumber(this); |
| 1505 |
| 1506 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 1507 visitor.visitDeferredNumber(this, arg); |
991 | 1508 |
992 int get value; | 1509 int get value; |
993 | 1510 |
994 int get precedenceLevel => value.isNegative ? UNARY : PRIMARY; | 1511 int get precedenceLevel => value.isNegative ? UNARY : PRIMARY; |
995 } | 1512 } |
996 | 1513 |
997 /// Interface for a deferred string value. An implementation has to provide | 1514 /// Interface for a deferred string value. An implementation has to provide |
998 /// a value via the [value] getter the latest when the ast is printed. | 1515 /// a value via the [value] getter the latest when the ast is printed. |
999 abstract class DeferredString extends DeferredToken implements Literal { | 1516 abstract class DeferredString extends DeferredToken implements Literal { |
1000 accept(NodeVisitor visitor) => visitor.visitDeferredString(this); | 1517 T accept<T>(NodeVisitor<T> visitor) => visitor.visitDeferredString(this); |
| 1518 |
| 1519 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 1520 visitor.visitDeferredString(this, arg); |
1001 | 1521 |
1002 String get value; | 1522 String get value; |
1003 | 1523 |
1004 int get precedenceLevel => PRIMARY; | 1524 int get precedenceLevel => PRIMARY; |
1005 } | 1525 } |
1006 | 1526 |
1007 /// Interface for a deferred [Expression] value. An implementation has to provid
e | 1527 /// Interface for a deferred [Expression] value. An implementation has to provid
e |
1008 /// a value via the [value] getter the latest when the ast is printed. | 1528 /// a value via the [value] getter the latest when the ast is printed. |
1009 /// Also, [precedenceLevel] has to return the same value that | 1529 /// Also, [precedenceLevel] has to return the same value that |
1010 /// [value.precedenceLevel] returns once [value] is bound to an [Expression]. | 1530 /// [value.precedenceLevel] returns once [value] is bound to an [Expression]. |
1011 abstract class DeferredExpression extends DeferredToken { | 1531 abstract class DeferredExpression extends DeferredToken { |
1012 accept(NodeVisitor visitor) => visitor.visitDeferredExpression(this); | 1532 T accept<T>(NodeVisitor<T> visitor) => visitor.visitDeferredExpression(this); |
| 1533 |
| 1534 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 1535 visitor.visitDeferredExpression(this, arg); |
1013 | 1536 |
1014 Expression get value; | 1537 Expression get value; |
1015 } | 1538 } |
1016 | 1539 |
1017 abstract class Literal extends Expression { | 1540 abstract class Literal extends Expression { |
1018 void visitChildren(NodeVisitor visitor) {} | 1541 void visitChildren<T>(NodeVisitor<T> visitor) {} |
| 1542 |
| 1543 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) {} |
1019 | 1544 |
1020 int get precedenceLevel => PRIMARY; | 1545 int get precedenceLevel => PRIMARY; |
1021 } | 1546 } |
1022 | 1547 |
1023 class LiteralBool extends Literal { | 1548 class LiteralBool extends Literal { |
1024 final bool value; | 1549 final bool value; |
1025 | 1550 |
1026 LiteralBool(this.value); | 1551 LiteralBool(this.value); |
1027 | 1552 |
1028 accept(NodeVisitor visitor) => visitor.visitLiteralBool(this); | 1553 T accept<T>(NodeVisitor<T> visitor) => visitor.visitLiteralBool(this); |
| 1554 |
| 1555 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 1556 visitor.visitLiteralBool(this, arg); |
| 1557 |
1029 // [visitChildren] inherited from [Literal]. | 1558 // [visitChildren] inherited from [Literal]. |
| 1559 |
1030 LiteralBool _clone() => new LiteralBool(value); | 1560 LiteralBool _clone() => new LiteralBool(value); |
1031 } | 1561 } |
1032 | 1562 |
1033 class LiteralNull extends Literal { | 1563 class LiteralNull extends Literal { |
1034 LiteralNull(); | 1564 LiteralNull(); |
1035 | 1565 |
1036 accept(NodeVisitor visitor) => visitor.visitLiteralNull(this); | 1566 T accept<T>(NodeVisitor<T> visitor) => visitor.visitLiteralNull(this); |
| 1567 |
| 1568 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 1569 visitor.visitLiteralNull(this, arg); |
| 1570 |
1037 LiteralNull _clone() => new LiteralNull(); | 1571 LiteralNull _clone() => new LiteralNull(); |
1038 } | 1572 } |
1039 | 1573 |
1040 class LiteralString extends Literal { | 1574 class LiteralString extends Literal { |
1041 final String value; | 1575 final String value; |
1042 | 1576 |
1043 /** | 1577 /** |
1044 * Constructs a LiteralString from a string value. | 1578 * Constructs a LiteralString from a string value. |
1045 * | 1579 * |
1046 * The constructor does not add the required quotes. If [value] is not | 1580 * The constructor does not add the required quotes. If [value] is not |
1047 * surrounded by quotes and properly escaped, the resulting object is invalid | 1581 * surrounded by quotes and properly escaped, the resulting object is invalid |
1048 * as a JS value. | 1582 * as a JS value. |
1049 * | 1583 * |
1050 * TODO(sra): Introduce variants for known valid strings that don't allocate a | 1584 * TODO(sra): Introduce variants for known valid strings that don't allocate a |
1051 * new string just to add quotes. | 1585 * new string just to add quotes. |
1052 */ | 1586 */ |
1053 LiteralString(this.value); | 1587 LiteralString(this.value); |
1054 | 1588 |
1055 accept(NodeVisitor visitor) => visitor.visitLiteralString(this); | 1589 T accept<T>(NodeVisitor<T> visitor) => visitor.visitLiteralString(this); |
| 1590 |
| 1591 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 1592 visitor.visitLiteralString(this, arg); |
| 1593 |
1056 LiteralString _clone() => new LiteralString(value); | 1594 LiteralString _clone() => new LiteralString(value); |
1057 } | 1595 } |
1058 | 1596 |
1059 class StringConcatenation extends Literal { | 1597 class StringConcatenation extends Literal { |
1060 final List<Literal> parts; | 1598 final List<Literal> parts; |
1061 | 1599 |
1062 /** | 1600 /** |
1063 * Constructs a StringConcatenation from a list of Literal elements. | 1601 * Constructs a StringConcatenation from a list of Literal elements. |
1064 * The constructor does not add surrounding quotes to the resulting | 1602 * The constructor does not add surrounding quotes to the resulting |
1065 * concatenated string. | 1603 * concatenated string. |
1066 */ | 1604 */ |
1067 StringConcatenation(this.parts); | 1605 StringConcatenation(this.parts); |
1068 | 1606 |
1069 accept(NodeVisitor visitor) => visitor.visitStringConcatenation(this); | 1607 T accept<T>(NodeVisitor<T> visitor) => visitor.visitStringConcatenation(this); |
1070 | 1608 |
1071 void visitChildren(NodeVisitor visitor) { | 1609 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 1610 visitor.visitStringConcatenation(this, arg); |
| 1611 |
| 1612 void visitChildren<T>(NodeVisitor<T> visitor) { |
1072 for (Literal part in parts) part.accept(visitor); | 1613 for (Literal part in parts) part.accept(visitor); |
1073 } | 1614 } |
1074 | 1615 |
| 1616 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) { |
| 1617 for (Literal part in parts) part.accept1(visitor, arg); |
| 1618 } |
| 1619 |
1075 StringConcatenation _clone() => new StringConcatenation(this.parts); | 1620 StringConcatenation _clone() => new StringConcatenation(this.parts); |
1076 } | 1621 } |
1077 | 1622 |
1078 class LiteralNumber extends Literal { | 1623 class LiteralNumber extends Literal { |
1079 final String value; // Must be a valid JavaScript number literal. | 1624 final String value; // Must be a valid JavaScript number literal. |
1080 | 1625 |
1081 LiteralNumber(this.value); | 1626 LiteralNumber(this.value); |
1082 | 1627 |
1083 int get precedenceLevel => value.startsWith('-') ? UNARY : PRIMARY; | 1628 int get precedenceLevel => value.startsWith('-') ? UNARY : PRIMARY; |
1084 | 1629 |
1085 accept(NodeVisitor visitor) => visitor.visitLiteralNumber(this); | 1630 T accept<T>(NodeVisitor<T> visitor) => visitor.visitLiteralNumber(this); |
| 1631 |
| 1632 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 1633 visitor.visitLiteralNumber(this, arg); |
| 1634 |
1086 LiteralNumber _clone() => new LiteralNumber(value); | 1635 LiteralNumber _clone() => new LiteralNumber(value); |
1087 } | 1636 } |
1088 | 1637 |
1089 class ArrayInitializer extends Expression { | 1638 class ArrayInitializer extends Expression { |
1090 final List<Expression> elements; | 1639 final List<Expression> elements; |
1091 | 1640 |
1092 ArrayInitializer(this.elements); | 1641 ArrayInitializer(this.elements); |
1093 | 1642 |
1094 accept(NodeVisitor visitor) => visitor.visitArrayInitializer(this); | 1643 T accept<T>(NodeVisitor<T> visitor) => visitor.visitArrayInitializer(this); |
1095 | 1644 |
1096 void visitChildren(NodeVisitor visitor) { | 1645 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 1646 visitor.visitArrayInitializer(this, arg); |
| 1647 |
| 1648 void visitChildren<T>(NodeVisitor<T> visitor) { |
1097 for (Expression element in elements) element.accept(visitor); | 1649 for (Expression element in elements) element.accept(visitor); |
1098 } | 1650 } |
1099 | 1651 |
| 1652 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) { |
| 1653 for (Expression element in elements) element.accept1(visitor, arg); |
| 1654 } |
| 1655 |
1100 ArrayInitializer _clone() => new ArrayInitializer(elements); | 1656 ArrayInitializer _clone() => new ArrayInitializer(elements); |
1101 | 1657 |
1102 int get precedenceLevel => PRIMARY; | 1658 int get precedenceLevel => PRIMARY; |
1103 } | 1659 } |
1104 | 1660 |
1105 /** | 1661 /** |
1106 * An empty place in an [ArrayInitializer]. | 1662 * An empty place in an [ArrayInitializer]. |
1107 * For example the list [1, , , 2] would contain two holes. | 1663 * For example the list [1, , , 2] would contain two holes. |
1108 */ | 1664 */ |
1109 class ArrayHole extends Expression { | 1665 class ArrayHole extends Expression { |
1110 accept(NodeVisitor visitor) => visitor.visitArrayHole(this); | 1666 T accept<T>(NodeVisitor<T> visitor) => visitor.visitArrayHole(this); |
1111 | 1667 |
1112 void visitChildren(NodeVisitor visitor) {} | 1668 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 1669 visitor.visitArrayHole(this, arg); |
| 1670 |
| 1671 void visitChildren<T>(NodeVisitor<T> visitor) {} |
| 1672 |
| 1673 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) {} |
1113 | 1674 |
1114 ArrayHole _clone() => new ArrayHole(); | 1675 ArrayHole _clone() => new ArrayHole(); |
1115 | 1676 |
1116 int get precedenceLevel => PRIMARY; | 1677 int get precedenceLevel => PRIMARY; |
1117 } | 1678 } |
1118 | 1679 |
1119 class ObjectInitializer extends Expression { | 1680 class ObjectInitializer extends Expression { |
1120 final List<Property> properties; | 1681 final List<Property> properties; |
1121 final bool isOneLiner; | 1682 final bool isOneLiner; |
1122 | 1683 |
1123 /** | 1684 /** |
1124 * Constructs a new object-initializer containing the given [properties]. | 1685 * Constructs a new object-initializer containing the given [properties]. |
1125 * | 1686 * |
1126 * [isOneLiner] describes the behaviour when pretty-printing (non-minified). | 1687 * [isOneLiner] describes the behaviour when pretty-printing (non-minified). |
1127 * If true print all properties on the same line. | 1688 * If true print all properties on the same line. |
1128 * If false print each property on a seperate line. | 1689 * If false print each property on a seperate line. |
1129 */ | 1690 */ |
1130 ObjectInitializer(this.properties, {this.isOneLiner: true}); | 1691 ObjectInitializer(this.properties, {this.isOneLiner: true}); |
1131 | 1692 |
1132 accept(NodeVisitor visitor) => visitor.visitObjectInitializer(this); | 1693 T accept<T>(NodeVisitor<T> visitor) => visitor.visitObjectInitializer(this); |
1133 | 1694 |
1134 void visitChildren(NodeVisitor visitor) { | 1695 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 1696 visitor.visitObjectInitializer(this, arg); |
| 1697 |
| 1698 void visitChildren<T>(NodeVisitor<T> visitor) { |
1135 for (Property init in properties) init.accept(visitor); | 1699 for (Property init in properties) init.accept(visitor); |
1136 } | 1700 } |
1137 | 1701 |
| 1702 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) { |
| 1703 for (Property init in properties) init.accept1(visitor, arg); |
| 1704 } |
| 1705 |
1138 ObjectInitializer _clone() => | 1706 ObjectInitializer _clone() => |
1139 new ObjectInitializer(properties, isOneLiner: isOneLiner); | 1707 new ObjectInitializer(properties, isOneLiner: isOneLiner); |
1140 | 1708 |
1141 int get precedenceLevel => PRIMARY; | 1709 int get precedenceLevel => PRIMARY; |
1142 } | 1710 } |
1143 | 1711 |
1144 class Property extends Node { | 1712 class Property extends Node { |
1145 final Literal name; | 1713 final Literal name; |
1146 final Expression value; | 1714 final Expression value; |
1147 | 1715 |
1148 Property(this.name, this.value); | 1716 Property(this.name, this.value); |
1149 | 1717 |
1150 accept(NodeVisitor visitor) => visitor.visitProperty(this); | 1718 T accept<T>(NodeVisitor<T> visitor) => visitor.visitProperty(this); |
1151 | 1719 |
1152 void visitChildren(NodeVisitor visitor) { | 1720 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 1721 visitor.visitProperty(this, arg); |
| 1722 |
| 1723 void visitChildren<T>(NodeVisitor<T> visitor) { |
1153 name.accept(visitor); | 1724 name.accept(visitor); |
1154 value.accept(visitor); | 1725 value.accept(visitor); |
1155 } | 1726 } |
1156 | 1727 |
| 1728 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) { |
| 1729 name.accept1(visitor, arg); |
| 1730 value.accept1(visitor, arg); |
| 1731 } |
| 1732 |
1157 Property _clone() => new Property(name, value); | 1733 Property _clone() => new Property(name, value); |
1158 } | 1734 } |
1159 | 1735 |
1160 /// Tag class for all interpolated positions. | 1736 /// Tag class for all interpolated positions. |
1161 abstract class InterpolatedNode implements Node { | 1737 abstract class InterpolatedNode implements Node { |
1162 get nameOrPosition; | 1738 get nameOrPosition; |
1163 | 1739 |
1164 bool get isNamed => nameOrPosition is String; | 1740 bool get isNamed => nameOrPosition is String; |
| 1741 |
1165 bool get isPositional => nameOrPosition is int; | 1742 bool get isPositional => nameOrPosition is int; |
1166 } | 1743 } |
1167 | 1744 |
1168 class InterpolatedExpression extends Expression with InterpolatedNode { | 1745 class InterpolatedExpression extends Expression with InterpolatedNode { |
1169 final nameOrPosition; | 1746 final nameOrPosition; |
1170 | 1747 |
1171 InterpolatedExpression(this.nameOrPosition); | 1748 InterpolatedExpression(this.nameOrPosition); |
1172 | 1749 |
1173 accept(NodeVisitor visitor) => visitor.visitInterpolatedExpression(this); | 1750 T accept<T>(NodeVisitor<T> visitor) => |
1174 void visitChildren(NodeVisitor visitor) {} | 1751 visitor.visitInterpolatedExpression(this); |
| 1752 |
| 1753 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 1754 visitor.visitInterpolatedExpression(this, arg); |
| 1755 |
| 1756 void visitChildren<T>(NodeVisitor<T> visitor) {} |
| 1757 |
| 1758 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) {} |
| 1759 |
1175 InterpolatedExpression _clone() => new InterpolatedExpression(nameOrPosition); | 1760 InterpolatedExpression _clone() => new InterpolatedExpression(nameOrPosition); |
1176 | 1761 |
1177 int get precedenceLevel => PRIMARY; | 1762 int get precedenceLevel => PRIMARY; |
1178 } | 1763 } |
1179 | 1764 |
1180 class InterpolatedLiteral extends Literal with InterpolatedNode { | 1765 class InterpolatedLiteral extends Literal with InterpolatedNode { |
1181 final nameOrPosition; | 1766 final nameOrPosition; |
1182 | 1767 |
1183 InterpolatedLiteral(this.nameOrPosition); | 1768 InterpolatedLiteral(this.nameOrPosition); |
1184 | 1769 |
1185 accept(NodeVisitor visitor) => visitor.visitInterpolatedLiteral(this); | 1770 T accept<T>(NodeVisitor<T> visitor) => visitor.visitInterpolatedLiteral(this); |
1186 void visitChildren(NodeVisitor visitor) {} | 1771 |
| 1772 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 1773 visitor.visitInterpolatedLiteral(this, arg); |
| 1774 |
| 1775 void visitChildren<T>(NodeVisitor<T> visitor) {} |
| 1776 |
| 1777 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) {} |
| 1778 |
1187 InterpolatedLiteral _clone() => new InterpolatedLiteral(nameOrPosition); | 1779 InterpolatedLiteral _clone() => new InterpolatedLiteral(nameOrPosition); |
1188 } | 1780 } |
1189 | 1781 |
1190 class InterpolatedParameter extends Expression | 1782 class InterpolatedParameter extends Expression |
1191 with InterpolatedNode | 1783 with InterpolatedNode |
1192 implements Parameter { | 1784 implements Parameter { |
1193 final nameOrPosition; | 1785 final nameOrPosition; |
1194 | 1786 |
| 1787 InterpolatedParameter(this.nameOrPosition); |
| 1788 |
1195 String get name { | 1789 String get name { |
1196 throw "InterpolatedParameter.name must not be invoked"; | 1790 throw "InterpolatedParameter.name must not be invoked"; |
1197 } | 1791 } |
1198 | 1792 |
1199 bool get allowRename => false; | 1793 bool get allowRename => false; |
1200 | 1794 |
1201 InterpolatedParameter(this.nameOrPosition); | 1795 T accept<T>(NodeVisitor<T> visitor) => |
| 1796 visitor.visitInterpolatedParameter(this); |
1202 | 1797 |
1203 accept(NodeVisitor visitor) => visitor.visitInterpolatedParameter(this); | 1798 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
1204 void visitChildren(NodeVisitor visitor) {} | 1799 visitor.visitInterpolatedParameter(this, arg); |
| 1800 |
| 1801 void visitChildren<T>(NodeVisitor<T> visitor) {} |
| 1802 |
| 1803 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) {} |
| 1804 |
1205 InterpolatedParameter _clone() => new InterpolatedParameter(nameOrPosition); | 1805 InterpolatedParameter _clone() => new InterpolatedParameter(nameOrPosition); |
1206 | 1806 |
1207 int get precedenceLevel => PRIMARY; | 1807 int get precedenceLevel => PRIMARY; |
1208 } | 1808 } |
1209 | 1809 |
1210 class InterpolatedSelector extends Expression with InterpolatedNode { | 1810 class InterpolatedSelector extends Expression with InterpolatedNode { |
1211 final nameOrPosition; | 1811 final nameOrPosition; |
1212 | 1812 |
1213 InterpolatedSelector(this.nameOrPosition); | 1813 InterpolatedSelector(this.nameOrPosition); |
1214 | 1814 |
1215 accept(NodeVisitor visitor) => visitor.visitInterpolatedSelector(this); | 1815 T accept<T>(NodeVisitor<T> visitor) => |
1216 void visitChildren(NodeVisitor visitor) {} | 1816 visitor.visitInterpolatedSelector(this); |
| 1817 |
| 1818 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 1819 visitor.visitInterpolatedSelector(this, arg); |
| 1820 |
| 1821 void visitChildren<T>(NodeVisitor<T> visitor) {} |
| 1822 |
| 1823 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) {} |
| 1824 |
1217 InterpolatedSelector _clone() => new InterpolatedSelector(nameOrPosition); | 1825 InterpolatedSelector _clone() => new InterpolatedSelector(nameOrPosition); |
1218 | 1826 |
1219 int get precedenceLevel => PRIMARY; | 1827 int get precedenceLevel => PRIMARY; |
1220 } | 1828 } |
1221 | 1829 |
1222 class InterpolatedStatement extends Statement with InterpolatedNode { | 1830 class InterpolatedStatement extends Statement with InterpolatedNode { |
1223 final nameOrPosition; | 1831 final nameOrPosition; |
1224 | 1832 |
1225 InterpolatedStatement(this.nameOrPosition); | 1833 InterpolatedStatement(this.nameOrPosition); |
1226 | 1834 |
1227 accept(NodeVisitor visitor) => visitor.visitInterpolatedStatement(this); | 1835 T accept<T>(NodeVisitor<T> visitor) => |
1228 void visitChildren(NodeVisitor visitor) {} | 1836 visitor.visitInterpolatedStatement(this); |
| 1837 |
| 1838 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 1839 visitor.visitInterpolatedStatement(this, arg); |
| 1840 |
| 1841 void visitChildren<T>(NodeVisitor<T> visitor) {} |
| 1842 |
| 1843 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) {} |
| 1844 |
1229 InterpolatedStatement _clone() => new InterpolatedStatement(nameOrPosition); | 1845 InterpolatedStatement _clone() => new InterpolatedStatement(nameOrPosition); |
1230 } | 1846 } |
1231 | 1847 |
1232 class InterpolatedDeclaration extends Expression | 1848 class InterpolatedDeclaration extends Expression |
1233 with InterpolatedNode | 1849 with InterpolatedNode |
1234 implements Declaration { | 1850 implements Declaration { |
1235 final nameOrPosition; | 1851 final nameOrPosition; |
1236 | 1852 |
1237 InterpolatedDeclaration(this.nameOrPosition); | 1853 InterpolatedDeclaration(this.nameOrPosition); |
1238 | 1854 |
1239 accept(NodeVisitor visitor) => visitor.visitInterpolatedDeclaration(this); | 1855 T accept<T>(NodeVisitor<T> visitor) => |
1240 void visitChildren(NodeVisitor visitor) {} | 1856 visitor.visitInterpolatedDeclaration(this); |
| 1857 |
| 1858 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 1859 visitor.visitInterpolatedDeclaration(this, arg); |
| 1860 |
| 1861 void visitChildren<T>(NodeVisitor<T> visitor) {} |
| 1862 |
| 1863 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) {} |
| 1864 |
1241 InterpolatedDeclaration _clone() { | 1865 InterpolatedDeclaration _clone() { |
1242 return new InterpolatedDeclaration(nameOrPosition); | 1866 return new InterpolatedDeclaration(nameOrPosition); |
1243 } | 1867 } |
1244 | 1868 |
1245 @override | 1869 @override |
1246 String get name => throw "No name for the interpolated node"; | 1870 String get name => throw "No name for the interpolated node"; |
1247 | 1871 |
1248 @override | 1872 @override |
1249 int get precedenceLevel => PRIMARY; | 1873 int get precedenceLevel => PRIMARY; |
1250 } | 1874 } |
1251 | 1875 |
1252 /** | 1876 /** |
1253 * [RegExpLiteral]s, despite being called "Literal", do not inherit from | 1877 * [RegExpLiteral]s, despite being called "Literal", do not inherit from |
1254 * [Literal]. Indeed, regular expressions in JavaScript have a side-effect and | 1878 * [Literal]. Indeed, regular expressions in JavaScript have a side-effect and |
1255 * are thus not in the same category as numbers or strings. | 1879 * are thus not in the same category as numbers or strings. |
1256 */ | 1880 */ |
1257 class RegExpLiteral extends Expression { | 1881 class RegExpLiteral extends Expression { |
1258 /** Contains the pattern and the flags.*/ | 1882 /** Contains the pattern and the flags.*/ |
1259 final String pattern; | 1883 final String pattern; |
1260 | 1884 |
1261 RegExpLiteral(this.pattern); | 1885 RegExpLiteral(this.pattern); |
1262 | 1886 |
1263 accept(NodeVisitor visitor) => visitor.visitRegExpLiteral(this); | 1887 T accept<T>(NodeVisitor<T> visitor) => visitor.visitRegExpLiteral(this); |
1264 void visitChildren(NodeVisitor visitor) {} | 1888 |
| 1889 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 1890 visitor.visitRegExpLiteral(this, arg); |
| 1891 |
| 1892 void visitChildren<T>(NodeVisitor<T> visitor) {} |
| 1893 |
| 1894 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) {} |
| 1895 |
1265 RegExpLiteral _clone() => new RegExpLiteral(pattern); | 1896 RegExpLiteral _clone() => new RegExpLiteral(pattern); |
1266 | 1897 |
1267 int get precedenceLevel => PRIMARY; | 1898 int get precedenceLevel => PRIMARY; |
1268 } | 1899 } |
1269 | 1900 |
1270 /** | 1901 /** |
1271 * An asynchronous await. | 1902 * An asynchronous await. |
1272 * | 1903 * |
1273 * Not part of JavaScript. We desugar this expression before outputting. | 1904 * Not part of JavaScript. We desugar this expression before outputting. |
1274 * Should only occur in a [Fun] with `asyncModifier` async or asyncStar. | 1905 * Should only occur in a [Fun] with `asyncModifier` async or asyncStar. |
1275 */ | 1906 */ |
1276 class Await extends Expression { | 1907 class Await extends Expression { |
1277 /** The awaited expression. */ | 1908 /** The awaited expression. */ |
1278 final Expression expression; | 1909 final Expression expression; |
1279 | 1910 |
1280 Await(this.expression); | 1911 Await(this.expression); |
1281 | 1912 |
1282 int get precedenceLevel => UNARY; | 1913 int get precedenceLevel => UNARY; |
1283 accept(NodeVisitor visitor) => visitor.visitAwait(this); | 1914 |
1284 void visitChildren(NodeVisitor visitor) => expression.accept(visitor); | 1915 T accept<T>(NodeVisitor<T> visitor) => visitor.visitAwait(this); |
| 1916 |
| 1917 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 1918 visitor.visitAwait(this, arg); |
| 1919 |
| 1920 void visitChildren<T>(NodeVisitor<T> visitor) => expression.accept(visitor); |
| 1921 |
| 1922 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 1923 expression.accept1(visitor, arg); |
| 1924 |
1285 Await _clone() => new Await(expression); | 1925 Await _clone() => new Await(expression); |
1286 } | 1926 } |
1287 | 1927 |
1288 /** | 1928 /** |
1289 * A comment. | 1929 * A comment. |
1290 * | 1930 * |
1291 * Extends [Statement] so we can add comments before statements in | 1931 * Extends [Statement] so we can add comments before statements in |
1292 * [Block] and [Program]. | 1932 * [Block] and [Program]. |
1293 */ | 1933 */ |
1294 class Comment extends Statement { | 1934 class Comment extends Statement { |
1295 final String comment; | 1935 final String comment; |
1296 | 1936 |
1297 Comment(this.comment); | 1937 Comment(this.comment); |
1298 | 1938 |
1299 accept(NodeVisitor visitor) => visitor.visitComment(this); | 1939 T accept<T>(NodeVisitor<T> visitor) => visitor.visitComment(this); |
| 1940 |
| 1941 R accept1<R, A>(NodeVisitor1<R, A> visitor, A arg) => |
| 1942 visitor.visitComment(this, arg); |
| 1943 |
1300 Comment _clone() => new Comment(comment); | 1944 Comment _clone() => new Comment(comment); |
1301 | 1945 |
1302 void visitChildren(NodeVisitor visitor) {} | 1946 void visitChildren<T>(NodeVisitor<T> visitor) {} |
| 1947 |
| 1948 void visitChildren1<R, A>(NodeVisitor1<R, A> visitor, A arg) {} |
1303 } | 1949 } |
OLD | NEW |