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 import 'dart:collection' show IterableMixin; | 5 import 'dart:collection' show IterableMixin; |
6 | 6 |
7 import '../common.dart'; | 7 import '../common.dart'; |
8 import '../tokens/precedence_constants.dart' as Precedence show FUNCTION_INFO; | 8 import '../tokens/precedence_constants.dart' as Precedence show FUNCTION_INFO; |
9 import '../tokens/token.dart' show BeginGroupToken, Token; | 9 import '../tokens/token.dart' show BeginGroupToken, Token; |
10 import '../tokens/token_constants.dart' as Tokens show IDENTIFIER_TOKEN, KEYWORD
_TOKEN, PLUS_TOKEN; | 10 import '../tokens/token_constants.dart' as Tokens |
| 11 show IDENTIFIER_TOKEN, KEYWORD_TOKEN, PLUS_TOKEN; |
11 import '../util/util.dart'; | 12 import '../util/util.dart'; |
12 import '../util/characters.dart'; | 13 import '../util/characters.dart'; |
13 import '../resolution/secret_tree_element.dart' show NullTreeElementMixin, Store
dTreeElementMixin; | 14 import '../resolution/secret_tree_element.dart' |
| 15 show NullTreeElementMixin, StoredTreeElementMixin; |
14 import '../elements/elements.dart' show MetadataAnnotation; | 16 import '../elements/elements.dart' show MetadataAnnotation; |
15 import 'dartstring.dart'; | 17 import 'dartstring.dart'; |
16 import 'prettyprint.dart'; | 18 import 'prettyprint.dart'; |
17 import 'unparser.dart'; | 19 import 'unparser.dart'; |
18 | 20 |
19 abstract class Visitor<R> { | 21 abstract class Visitor<R> { |
20 const Visitor(); | 22 const Visitor(); |
21 | 23 |
22 R visitNode(Node node); | 24 R visitNode(Node node); |
23 | 25 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 R visitStringJuxtaposition(StringJuxtaposition node) => visitStringNode(node); | 69 R visitStringJuxtaposition(StringJuxtaposition node) => visitStringNode(node); |
68 R visitSyncForIn(SyncForIn node) => visitLoop(node); | 70 R visitSyncForIn(SyncForIn node) => visitLoop(node); |
69 R visitLoop(Loop node) => visitStatement(node); | 71 R visitLoop(Loop node) => visitStatement(node); |
70 R visitMetadata(Metadata node) => visitNode(node); | 72 R visitMetadata(Metadata node) => visitNode(node); |
71 R visitMixinApplication(MixinApplication node) => visitNode(node); | 73 R visitMixinApplication(MixinApplication node) => visitNode(node); |
72 R visitModifiers(Modifiers node) => visitNode(node); | 74 R visitModifiers(Modifiers node) => visitNode(node); |
73 R visitNamedArgument(NamedArgument node) => visitExpression(node); | 75 R visitNamedArgument(NamedArgument node) => visitExpression(node); |
74 R visitNamedMixinApplication(NamedMixinApplication node) { | 76 R visitNamedMixinApplication(NamedMixinApplication node) { |
75 return visitMixinApplication(node); | 77 return visitMixinApplication(node); |
76 } | 78 } |
| 79 |
77 R visitNewExpression(NewExpression node) => visitExpression(node); | 80 R visitNewExpression(NewExpression node) => visitExpression(node); |
78 R visitNodeList(NodeList node) => visitNode(node); | 81 R visitNodeList(NodeList node) => visitNode(node); |
79 R visitOperator(Operator node) => visitIdentifier(node); | 82 R visitOperator(Operator node) => visitIdentifier(node); |
80 R visitParenthesizedExpression(ParenthesizedExpression node) { | 83 R visitParenthesizedExpression(ParenthesizedExpression node) { |
81 return visitExpression(node); | 84 return visitExpression(node); |
82 } | 85 } |
| 86 |
83 R visitPart(Part node) => visitLibraryTag(node); | 87 R visitPart(Part node) => visitLibraryTag(node); |
84 R visitPartOf(PartOf node) => visitNode(node); | 88 R visitPartOf(PartOf node) => visitNode(node); |
85 R visitPostfix(Postfix node) => visitNodeList(node); | 89 R visitPostfix(Postfix node) => visitNodeList(node); |
86 R visitPrefix(Prefix node) => visitNodeList(node); | 90 R visitPrefix(Prefix node) => visitNodeList(node); |
87 R visitRedirectingFactoryBody(RedirectingFactoryBody node) { | 91 R visitRedirectingFactoryBody(RedirectingFactoryBody node) { |
88 return visitStatement(node); | 92 return visitStatement(node); |
89 } | 93 } |
| 94 |
90 R visitRethrow(Rethrow node) => visitStatement(node); | 95 R visitRethrow(Rethrow node) => visitStatement(node); |
91 R visitReturn(Return node) => visitStatement(node); | 96 R visitReturn(Return node) => visitStatement(node); |
92 R visitSend(Send node) => visitExpression(node); | 97 R visitSend(Send node) => visitExpression(node); |
93 R visitSendSet(SendSet node) => visitSend(node); | 98 R visitSendSet(SendSet node) => visitSend(node); |
94 R visitStatement(Statement node) => visitNode(node); | 99 R visitStatement(Statement node) => visitNode(node); |
95 R visitStringNode(StringNode node) => visitExpression(node); | 100 R visitStringNode(StringNode node) => visitExpression(node); |
96 R visitStringInterpolation(StringInterpolation node) => visitStringNode(node); | 101 R visitStringInterpolation(StringInterpolation node) => visitStringNode(node); |
97 R visitStringInterpolationPart(StringInterpolationPart node) { | 102 R visitStringInterpolationPart(StringInterpolationPart node) { |
98 return visitNode(node); | 103 return visitNode(node); |
99 } | 104 } |
| 105 |
100 R visitSwitchCase(SwitchCase node) => visitNode(node); | 106 R visitSwitchCase(SwitchCase node) => visitNode(node); |
101 R visitSwitchStatement(SwitchStatement node) => visitStatement(node); | 107 R visitSwitchStatement(SwitchStatement node) => visitStatement(node); |
102 R visitLiteralSymbol(LiteralSymbol node) => visitExpression(node); | 108 R visitLiteralSymbol(LiteralSymbol node) => visitExpression(node); |
103 R visitThrow(Throw node) => visitExpression(node); | 109 R visitThrow(Throw node) => visitExpression(node); |
104 R visitTryStatement(TryStatement node) => visitStatement(node); | 110 R visitTryStatement(TryStatement node) => visitStatement(node); |
105 R visitTypeAnnotation(TypeAnnotation node) => visitNode(node); | 111 R visitTypeAnnotation(TypeAnnotation node) => visitNode(node); |
106 R visitTypedef(Typedef node) => visitNode(node); | 112 R visitTypedef(Typedef node) => visitNode(node); |
107 R visitTypeVariable(TypeVariable node) => visitNode(node); | 113 R visitTypeVariable(TypeVariable node) => visitNode(node); |
108 R visitVariableDefinitions(VariableDefinitions node) => visitStatement(node); | 114 R visitVariableDefinitions(VariableDefinitions node) => visitStatement(node); |
109 R visitWhile(While node) => visitLoop(node); | 115 R visitWhile(While node) => visitLoop(node); |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 final Identifier name; | 262 final Identifier name; |
257 final Node superclass; | 263 final Node superclass; |
258 final NodeList interfaces; | 264 final NodeList interfaces; |
259 final NodeList typeParameters; | 265 final NodeList typeParameters; |
260 final NodeList body; | 266 final NodeList body; |
261 | 267 |
262 final Token beginToken; | 268 final Token beginToken; |
263 final Token extendsKeyword; | 269 final Token extendsKeyword; |
264 final Token endToken; | 270 final Token endToken; |
265 | 271 |
266 ClassNode(this.modifiers, this.name, this.typeParameters, this.superclass, | 272 ClassNode( |
267 this.interfaces, this.beginToken, | 273 this.modifiers, |
268 this.extendsKeyword, this.body, this.endToken); | 274 this.name, |
| 275 this.typeParameters, |
| 276 this.superclass, |
| 277 this.interfaces, |
| 278 this.beginToken, |
| 279 this.extendsKeyword, |
| 280 this.body, |
| 281 this.endToken); |
269 | 282 |
270 ClassNode asClassNode() => this; | 283 ClassNode asClassNode() => this; |
271 | 284 |
272 accept(Visitor visitor) => visitor.visitClassNode(this); | 285 accept(Visitor visitor) => visitor.visitClassNode(this); |
273 | 286 |
274 visitChildren(Visitor visitor) { | 287 visitChildren(Visitor visitor) { |
275 if (name != null) name.accept(visitor); | 288 if (name != null) name.accept(visitor); |
276 if (typeParameters != null) typeParameters.accept(visitor); | 289 if (typeParameters != null) typeParameters.accept(visitor); |
277 if (superclass != null) superclass.accept(visitor); | 290 if (superclass != null) superclass.accept(visitor); |
278 if (interfaces != null) interfaces.accept(visitor); | 291 if (interfaces != null) interfaces.accept(visitor); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 final Identifier name; | 341 final Identifier name; |
329 final NodeList typeParameters; | 342 final NodeList typeParameters; |
330 | 343 |
331 final Modifiers modifiers; | 344 final Modifiers modifiers; |
332 final MixinApplication mixinApplication; | 345 final MixinApplication mixinApplication; |
333 final NodeList interfaces; | 346 final NodeList interfaces; |
334 | 347 |
335 final Token classKeyword; | 348 final Token classKeyword; |
336 final Token endToken; | 349 final Token endToken; |
337 | 350 |
338 NamedMixinApplication(this.name, this.typeParameters, | 351 NamedMixinApplication(this.name, this.typeParameters, this.modifiers, |
339 this.modifiers, this.mixinApplication, this.interfaces, | 352 this.mixinApplication, this.interfaces, this.classKeyword, this.endToken); |
340 this.classKeyword, this.endToken); | |
341 | 353 |
342 TypeAnnotation get superclass => mixinApplication.superclass; | 354 TypeAnnotation get superclass => mixinApplication.superclass; |
343 NodeList get mixins => mixinApplication.mixins; | 355 NodeList get mixins => mixinApplication.mixins; |
344 | 356 |
345 MixinApplication asMixinApplication() => this; | 357 MixinApplication asMixinApplication() => this; |
346 NamedMixinApplication asNamedMixinApplication() => this; | 358 NamedMixinApplication asNamedMixinApplication() => this; |
347 | 359 |
348 accept(Visitor visitor) => visitor.visitNamedMixinApplication(this); | 360 accept(Visitor visitor) => visitor.visitNamedMixinApplication(this); |
349 | 361 |
350 visitChildren(Visitor visitor) { | 362 visitChildren(Visitor visitor) { |
(...skipping 23 matching lines...) Expand all Loading... |
374 Statement asStatement() => this; | 386 Statement asStatement() => this; |
375 | 387 |
376 // TODO(ahe): make class abstract instead of adding an abstract method. | 388 // TODO(ahe): make class abstract instead of adding an abstract method. |
377 accept(Visitor visitor); | 389 accept(Visitor visitor); |
378 | 390 |
379 bool isValidBreakTarget() => true; | 391 bool isValidBreakTarget() => true; |
380 } | 392 } |
381 | 393 |
382 /// Erroneous expression that behaves as a literal null. | 394 /// Erroneous expression that behaves as a literal null. |
383 class ErrorExpression extends LiteralNull { | 395 class ErrorExpression extends LiteralNull { |
384 ErrorExpression(token) | 396 ErrorExpression(token) : super(token); |
385 : super(token); | |
386 | 397 |
387 ErrorExpression asErrorExpression() => this; | 398 ErrorExpression asErrorExpression() => this; |
388 | 399 |
389 bool get isErroneous => true; | 400 bool get isErroneous => true; |
390 } | 401 } |
391 | 402 |
392 /** | 403 /** |
393 * A message send aka method invocation. In Dart, most operations can | 404 * A message send aka method invocation. In Dart, most operations can |
394 * (and should) be considered as message sends. Getters and setters | 405 * (and should) be considered as message sends. Getters and setters |
395 * are just methods with a special syntax. Consequently, we model | 406 * are just methods with a special syntax. Consequently, we model |
396 * property access, assignment, operators, and method calls with this | 407 * property access, assignment, operators, and method calls with this |
397 * one node. | 408 * one node. |
398 */ | 409 */ |
399 class Send extends Expression with StoredTreeElementMixin { | 410 class Send extends Expression with StoredTreeElementMixin { |
400 final Node receiver; | 411 final Node receiver; |
401 final Node selector; | 412 final Node selector; |
402 final NodeList argumentsNode; | 413 final NodeList argumentsNode; |
403 | 414 |
404 /// Whether this is a conditinal send of the form `a?.b`. | 415 /// Whether this is a conditinal send of the form `a?.b`. |
405 final bool isConditional; | 416 final bool isConditional; |
406 | 417 |
407 Link<Node> get arguments => argumentsNode.nodes; | 418 Link<Node> get arguments => argumentsNode.nodes; |
408 | 419 |
409 Send([this.receiver, this.selector, this.argumentsNode, | 420 Send( |
| 421 [this.receiver, |
| 422 this.selector, |
| 423 this.argumentsNode, |
410 this.isConditional = false]); | 424 this.isConditional = false]); |
411 Send.postfix(this.receiver, this.selector, | 425 Send.postfix(this.receiver, this.selector, |
412 [Node argument = null, this.isConditional = false]) | 426 [Node argument = null, this.isConditional = false]) |
413 : argumentsNode = (argument == null) | 427 : argumentsNode = (argument == null) |
414 ? new Postfix() | 428 ? new Postfix() |
415 : new Postfix.singleton(argument); | 429 : new Postfix.singleton(argument); |
416 Send.prefix(this.receiver, this.selector, | 430 Send.prefix(this.receiver, this.selector, |
417 [Node argument = null, this.isConditional = false]) | 431 [Node argument = null, this.isConditional = false]) |
418 : argumentsNode = (argument == null) | 432 : argumentsNode = |
419 ? new Prefix() | 433 (argument == null) ? new Prefix() : new Prefix.singleton(argument); |
420 : new Prefix.singleton(argument); | |
421 | 434 |
422 Send asSend() => this; | 435 Send asSend() => this; |
423 | 436 |
424 accept(Visitor visitor) => visitor.visitSend(this); | 437 accept(Visitor visitor) => visitor.visitSend(this); |
425 | 438 |
426 visitChildren(Visitor visitor) { | 439 visitChildren(Visitor visitor) { |
427 if (receiver != null) receiver.accept(visitor); | 440 if (receiver != null) receiver.accept(visitor); |
428 if (selector != null) selector.accept(visitor); | 441 if (selector != null) selector.accept(visitor); |
429 if (argumentsNode != null) argumentsNode.accept(visitor); | 442 if (argumentsNode != null) argumentsNode.accept(visitor); |
430 } | 443 } |
431 | 444 |
432 int argumentCount() { | 445 int argumentCount() { |
433 return (argumentsNode == null) ? -1 : argumentsNode.slowLength(); | 446 return (argumentsNode == null) ? -1 : argumentsNode.slowLength(); |
434 } | 447 } |
435 | 448 |
436 bool get isSuperCall { | 449 bool get isSuperCall { |
437 return receiver != null && receiver.isSuper(); | 450 return receiver != null && receiver.isSuper(); |
438 } | 451 } |
| 452 |
439 bool get isOperator => selector is Operator; | 453 bool get isOperator => selector is Operator; |
440 bool get isPropertyAccess => argumentsNode == null; | 454 bool get isPropertyAccess => argumentsNode == null; |
441 bool get isFunctionObjectInvocation => selector == null; | 455 bool get isFunctionObjectInvocation => selector == null; |
442 bool get isPrefix => argumentsNode is Prefix; | 456 bool get isPrefix => argumentsNode is Prefix; |
443 bool get isPostfix => argumentsNode is Postfix; | 457 bool get isPostfix => argumentsNode is Postfix; |
444 bool get isCall => !isOperator && !isPropertyAccess; | 458 bool get isCall => !isOperator && !isPropertyAccess; |
445 bool get isIndex => | 459 bool get isIndex => |
446 isOperator && identical(selector.asOperator().source, '[]'); | 460 isOperator && identical(selector.asOperator().source, '[]'); |
447 bool get isLogicalAnd => | 461 bool get isLogicalAnd => |
448 isOperator && identical(selector.asOperator().source, '&&'); | 462 isOperator && identical(selector.asOperator().source, '&&'); |
449 bool get isLogicalOr => | 463 bool get isLogicalOr => |
450 isOperator && identical(selector.asOperator().source, '||'); | 464 isOperator && identical(selector.asOperator().source, '||'); |
451 bool get isIfNull => | 465 bool get isIfNull => |
452 isOperator && identical(selector.asOperator().source, '??'); | 466 isOperator && identical(selector.asOperator().source, '??'); |
453 | 467 |
454 bool get isTypeCast { | 468 bool get isTypeCast { |
455 return isOperator | 469 return isOperator && identical(selector.asOperator().source, 'as'); |
456 && identical(selector.asOperator().source, 'as'); | |
457 } | 470 } |
458 | 471 |
459 bool get isTypeTest { | 472 bool get isTypeTest { |
460 return isOperator | 473 return isOperator && identical(selector.asOperator().source, 'is'); |
461 && identical(selector.asOperator().source, 'is'); | |
462 } | 474 } |
463 | 475 |
464 bool get isIsNotCheck { | 476 bool get isIsNotCheck { |
465 return isTypeTest && arguments.head.asSend() != null; | 477 return isTypeTest && arguments.head.asSend() != null; |
466 } | 478 } |
467 | 479 |
468 TypeAnnotation get typeAnnotationFromIsCheckOrCast { | 480 TypeAnnotation get typeAnnotationFromIsCheckOrCast { |
469 assert(isOperator); | 481 assert(isOperator); |
470 assert(identical(selector.asOperator().source, 'is') || | 482 assert(identical(selector.asOperator().source, 'is') || |
471 identical(selector.asOperator().source, 'as')); | 483 identical(selector.asOperator().source, 'as')); |
472 return isIsNotCheck | 484 return isIsNotCheck ? arguments.head.asSend().receiver : arguments.head; |
473 ? arguments.head.asSend().receiver | |
474 : arguments.head; | |
475 } | 485 } |
476 | 486 |
477 Token getBeginToken() { | 487 Token getBeginToken() { |
478 if (isPrefix && !isIndex) return selector.getBeginToken(); | 488 if (isPrefix && !isIndex) return selector.getBeginToken(); |
479 return firstBeginToken(receiver, selector); | 489 return firstBeginToken(receiver, selector); |
480 } | 490 } |
481 | 491 |
482 Token getEndToken() { | 492 Token getEndToken() { |
483 if (isPrefix) { | 493 if (isPrefix) { |
484 if (receiver != null) return receiver.getEndToken(); | 494 if (receiver != null) return receiver.getEndToken(); |
(...skipping 21 matching lines...) Expand all Loading... |
506 | 516 |
507 class Prefix extends NodeList { | 517 class Prefix extends NodeList { |
508 Prefix() : super(null, const Link<Node>()); | 518 Prefix() : super(null, const Link<Node>()); |
509 Prefix.singleton(Node argument) : super.singleton(argument); | 519 Prefix.singleton(Node argument) : super.singleton(argument); |
510 } | 520 } |
511 | 521 |
512 class SendSet extends Send { | 522 class SendSet extends Send { |
513 final Operator assignmentOperator; | 523 final Operator assignmentOperator; |
514 SendSet(receiver, selector, this.assignmentOperator, argumentsNode, | 524 SendSet(receiver, selector, this.assignmentOperator, argumentsNode, |
515 [bool isConditional = false]) | 525 [bool isConditional = false]) |
516 : super(receiver, selector, argumentsNode, isConditional); | 526 : super(receiver, selector, argumentsNode, isConditional); |
517 SendSet.postfix(receiver, | 527 SendSet.postfix(receiver, selector, this.assignmentOperator, |
518 selector, | 528 [Node argument = null, bool isConditional = false]) |
519 this.assignmentOperator, | |
520 [Node argument = null, bool isConditional = false]) | |
521 : super.postfix(receiver, selector, argument, isConditional); | 529 : super.postfix(receiver, selector, argument, isConditional); |
522 SendSet.prefix(receiver, | 530 SendSet.prefix(receiver, selector, this.assignmentOperator, |
523 selector, | 531 [Node argument = null, bool isConditional = false]) |
524 this.assignmentOperator, | |
525 [Node argument = null, bool isConditional = false]) | |
526 : super.prefix(receiver, selector, argument, isConditional); | 532 : super.prefix(receiver, selector, argument, isConditional); |
527 | 533 |
528 SendSet asSendSet() => this; | 534 SendSet asSendSet() => this; |
529 | 535 |
530 accept(Visitor visitor) => visitor.visitSendSet(this); | 536 accept(Visitor visitor) => visitor.visitSendSet(this); |
531 | 537 |
532 /// `true` if this send is not a simple assignment. | 538 /// `true` if this send is not a simple assignment. |
533 bool get isComplex => !identical(assignmentOperator.source, '='); | 539 bool get isComplex => !identical(assignmentOperator.source, '='); |
534 | 540 |
535 /// Whether this is an if-null assignment of the form `a ??= b`. | 541 /// Whether this is an if-null assignment of the form `a ??= b`. |
536 bool get isIfNullAssignment => | 542 bool get isIfNullAssignment => identical(assignmentOperator.source, '??='); |
537 identical(assignmentOperator.source, '??='); | |
538 | 543 |
539 visitChildren(Visitor visitor) { | 544 visitChildren(Visitor visitor) { |
540 super.visitChildren(visitor); | 545 super.visitChildren(visitor); |
541 if (assignmentOperator != null) assignmentOperator.accept(visitor); | 546 if (assignmentOperator != null) assignmentOperator.accept(visitor); |
542 } | 547 } |
543 | 548 |
544 Send copyWithReceiver(Node newReceiver, bool isConditional) { | 549 Send copyWithReceiver(Node newReceiver, bool isConditional) { |
545 assert(receiver == null); | 550 assert(receiver == null); |
546 return new SendSet(newReceiver, selector, assignmentOperator, | 551 return new SendSet(newReceiver, selector, assignmentOperator, argumentsNode, |
547 argumentsNode, isConditional); | 552 isConditional); |
548 } | 553 } |
549 | 554 |
550 Token getBeginToken() { | 555 Token getBeginToken() { |
551 if (isPrefix) return assignmentOperator.getBeginToken(); | 556 if (isPrefix) return assignmentOperator.getBeginToken(); |
552 return super.getBeginToken(); | 557 return super.getBeginToken(); |
553 } | 558 } |
554 | 559 |
555 Token getEndToken() { | 560 Token getEndToken() { |
556 if (isPostfix) return assignmentOperator.getEndToken(); | 561 if (isPostfix) return assignmentOperator.getEndToken(); |
557 return super.getEndToken(); | 562 return super.getEndToken(); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
619 | 624 |
620 visitChildren(Visitor visitor) { | 625 visitChildren(Visitor visitor) { |
621 if (nodes == null) return; | 626 if (nodes == null) return; |
622 for (Link<Node> link = nodes; !link.isEmpty; link = link.tail) { | 627 for (Link<Node> link = nodes; !link.isEmpty; link = link.tail) { |
623 if (link.head != null) link.head.accept(visitor); | 628 if (link.head != null) link.head.accept(visitor); |
624 } | 629 } |
625 } | 630 } |
626 | 631 |
627 Token getBeginToken() { | 632 Token getBeginToken() { |
628 if (beginToken != null) return beginToken; | 633 if (beginToken != null) return beginToken; |
629 if (nodes != null) { | 634 if (nodes != null) { |
630 for (Link<Node> link = nodes; !link.isEmpty; link = link.tail) { | 635 for (Link<Node> link = nodes; !link.isEmpty; link = link.tail) { |
631 if (link.head.getBeginToken() != null) { | 636 if (link.head.getBeginToken() != null) { |
632 return link.head.getBeginToken(); | 637 return link.head.getBeginToken(); |
633 } | 638 } |
634 if (link.head.getEndToken() != null) { | 639 if (link.head.getEndToken() != null) { |
635 return link.head.getEndToken(); | 640 return link.head.getEndToken(); |
636 } | 641 } |
637 } | 642 } |
638 } | 643 } |
639 return endToken; | 644 return endToken; |
640 } | 645 } |
641 | 646 |
642 Token getEndToken() { | 647 Token getEndToken() { |
643 if (endToken != null) return endToken; | 648 if (endToken != null) return endToken; |
644 if (nodes != null) { | 649 if (nodes != null) { |
645 Link<Node> link = nodes; | 650 Link<Node> link = nodes; |
646 if (link.isEmpty) return beginToken; | 651 if (link.isEmpty) return beginToken; |
647 while (!link.tail.isEmpty) link = link.tail; | 652 while (!link.tail.isEmpty) link = link.tail; |
648 Node lastNode = link.head; | 653 Node lastNode = link.head; |
(...skipping 25 matching lines...) Expand all Loading... |
674 } | 679 } |
675 | 680 |
676 class If extends Statement { | 681 class If extends Statement { |
677 final ParenthesizedExpression condition; | 682 final ParenthesizedExpression condition; |
678 final Statement thenPart; | 683 final Statement thenPart; |
679 final Statement elsePart; | 684 final Statement elsePart; |
680 | 685 |
681 final Token ifToken; | 686 final Token ifToken; |
682 final Token elseToken; | 687 final Token elseToken; |
683 | 688 |
684 If(this.condition, this.thenPart, this.elsePart, | 689 If(this.condition, this.thenPart, this.elsePart, this.ifToken, |
685 this.ifToken, this.elseToken); | 690 this.elseToken); |
686 | 691 |
687 If asIf() => this; | 692 If asIf() => this; |
688 | 693 |
689 bool get hasElsePart => elsePart != null; | 694 bool get hasElsePart => elsePart != null; |
690 | 695 |
691 accept(Visitor visitor) => visitor.visitIf(this); | 696 accept(Visitor visitor) => visitor.visitIf(this); |
692 | 697 |
693 visitChildren(Visitor visitor) { | 698 visitChildren(Visitor visitor) { |
694 if (condition != null) condition.accept(visitor); | 699 if (condition != null) condition.accept(visitor); |
695 if (thenPart != null) thenPart.accept(visitor); | 700 if (thenPart != null) thenPart.accept(visitor); |
696 if (elsePart != null) elsePart.accept(visitor); | 701 if (elsePart != null) elsePart.accept(visitor); |
697 } | 702 } |
698 | 703 |
699 Token getBeginToken() => ifToken; | 704 Token getBeginToken() => ifToken; |
700 | 705 |
701 Token getEndToken() { | 706 Token getEndToken() { |
702 if (elsePart == null) return thenPart.getEndToken(); | 707 if (elsePart == null) return thenPart.getEndToken(); |
703 return elsePart.getEndToken(); | 708 return elsePart.getEndToken(); |
704 } | 709 } |
705 } | 710 } |
706 | 711 |
707 class Conditional extends Expression { | 712 class Conditional extends Expression { |
708 final Expression condition; | 713 final Expression condition; |
709 final Expression thenExpression; | 714 final Expression thenExpression; |
710 final Expression elseExpression; | 715 final Expression elseExpression; |
711 | 716 |
712 final Token questionToken; | 717 final Token questionToken; |
713 final Token colonToken; | 718 final Token colonToken; |
714 | 719 |
715 Conditional(this.condition, this.thenExpression, | 720 Conditional(this.condition, this.thenExpression, this.elseExpression, |
716 this.elseExpression, this.questionToken, this.colonToken); | 721 this.questionToken, this.colonToken); |
717 | 722 |
718 Conditional asConditional() => this; | 723 Conditional asConditional() => this; |
719 | 724 |
720 accept(Visitor visitor) => visitor.visitConditional(this); | 725 accept(Visitor visitor) => visitor.visitConditional(this); |
721 | 726 |
722 visitChildren(Visitor visitor) { | 727 visitChildren(Visitor visitor) { |
723 condition.accept(visitor); | 728 condition.accept(visitor); |
724 thenExpression.accept(visitor); | 729 thenExpression.accept(visitor); |
725 elseExpression.accept(visitor); | 730 elseExpression.accept(visitor); |
726 } | 731 } |
727 | 732 |
728 Token getBeginToken() => condition.getBeginToken(); | 733 Token getBeginToken() => condition.getBeginToken(); |
729 | 734 |
730 Token getEndToken() => elseExpression.getEndToken(); | 735 Token getEndToken() => elseExpression.getEndToken(); |
731 } | 736 } |
732 | 737 |
733 class For extends Loop { | 738 class For extends Loop { |
734 /** Either a variable declaration or an expression. */ | 739 /** Either a variable declaration or an expression. */ |
735 final Node initializer; | 740 final Node initializer; |
736 /** Either an expression statement or an empty statement. */ | 741 /** Either an expression statement or an empty statement. */ |
737 final Statement conditionStatement; | 742 final Statement conditionStatement; |
738 final NodeList update; | 743 final NodeList update; |
739 | 744 |
740 final Token forToken; | 745 final Token forToken; |
741 | 746 |
742 For(this.initializer, this.conditionStatement, this.update, body, | 747 For(this.initializer, this.conditionStatement, this.update, body, |
743 this.forToken) : super(body); | 748 this.forToken) |
| 749 : super(body); |
744 | 750 |
745 For asFor() => this; | 751 For asFor() => this; |
746 | 752 |
747 Expression get condition { | 753 Expression get condition { |
748 ExpressionStatement expressionStatement = | 754 ExpressionStatement expressionStatement = |
749 conditionStatement.asExpressionStatement(); | 755 conditionStatement.asExpressionStatement(); |
750 if (expressionStatement != null) { | 756 if (expressionStatement != null) { |
751 return expressionStatement.expression; | 757 return expressionStatement.expression; |
752 } else { | 758 } else { |
753 return null; | 759 return null; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
829 | 835 |
830 final Statement body; | 836 final Statement body; |
831 final TypeAnnotation returnType; | 837 final TypeAnnotation returnType; |
832 final Modifiers modifiers; | 838 final Modifiers modifiers; |
833 final NodeList initializers; | 839 final NodeList initializers; |
834 | 840 |
835 final Token getOrSet; | 841 final Token getOrSet; |
836 final AsyncModifier asyncModifier; | 842 final AsyncModifier asyncModifier; |
837 | 843 |
838 FunctionExpression(this.name, this.parameters, this.body, this.returnType, | 844 FunctionExpression(this.name, this.parameters, this.body, this.returnType, |
839 this.modifiers, this.initializers, this.getOrSet, | 845 this.modifiers, this.initializers, this.getOrSet, this.asyncModifier) { |
840 this.asyncModifier) { | |
841 assert(modifiers != null); | 846 assert(modifiers != null); |
842 } | 847 } |
843 | 848 |
844 FunctionExpression asFunctionExpression() => this; | 849 FunctionExpression asFunctionExpression() => this; |
845 | 850 |
846 accept(Visitor visitor) => visitor.visitFunctionExpression(this); | 851 accept(Visitor visitor) => visitor.visitFunctionExpression(this); |
847 | 852 |
848 bool get isRedirectingFactory { | 853 bool get isRedirectingFactory { |
849 return body != null && body.asRedirectingFactoryBody() != null; | 854 return body != null && body.asRedirectingFactoryBody() != null; |
850 } | 855 } |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
918 } on FormatException catch (ex) { | 923 } on FormatException catch (ex) { |
919 (this.handler)(token, ex); | 924 (this.handler)(token, ex); |
920 } | 925 } |
921 } | 926 } |
922 | 927 |
923 accept(Visitor visitor) => visitor.visitLiteralInt(this); | 928 accept(Visitor visitor) => visitor.visitLiteralInt(this); |
924 } | 929 } |
925 | 930 |
926 class LiteralDouble extends Literal<double> { | 931 class LiteralDouble extends Literal<double> { |
927 LiteralDouble(Token token, DecodeErrorHandler handler) | 932 LiteralDouble(Token token, DecodeErrorHandler handler) |
928 : super(token, handler); | 933 : super(token, handler); |
929 | 934 |
930 LiteralDouble asLiteralDouble() => this; | 935 LiteralDouble asLiteralDouble() => this; |
931 | 936 |
932 double get value { | 937 double get value { |
933 try { | 938 try { |
934 Token valueToken = token; | 939 Token valueToken = token; |
935 if (identical(valueToken.kind, Tokens.PLUS_TOKEN)) { | 940 if (identical(valueToken.kind, Tokens.PLUS_TOKEN)) { |
936 valueToken = valueToken.next; | 941 valueToken = valueToken.next; |
937 } | 942 } |
938 return double.parse(valueToken.value); | 943 return double.parse(valueToken.value); |
(...skipping 13 matching lines...) Expand all Loading... |
952 bool get value { | 957 bool get value { |
953 if (identical(token.stringValue, 'true')) return true; | 958 if (identical(token.stringValue, 'true')) return true; |
954 if (identical(token.stringValue, 'false')) return false; | 959 if (identical(token.stringValue, 'false')) return false; |
955 (this.handler)(token, "not a bool ${token.value}"); | 960 (this.handler)(token, "not a bool ${token.value}"); |
956 throw false; | 961 throw false; |
957 } | 962 } |
958 | 963 |
959 accept(Visitor visitor) => visitor.visitLiteralBool(this); | 964 accept(Visitor visitor) => visitor.visitLiteralBool(this); |
960 } | 965 } |
961 | 966 |
962 | |
963 class StringQuoting { | 967 class StringQuoting { |
964 | |
965 /// Cache of common quotings. | 968 /// Cache of common quotings. |
966 static const List<StringQuoting> _mapping = const <StringQuoting>[ | 969 static const List<StringQuoting> _mapping = const <StringQuoting>[ |
967 const StringQuoting($SQ, raw: false, leftQuoteLength: 1), | 970 const StringQuoting($SQ, raw: false, leftQuoteLength: 1), |
968 const StringQuoting($SQ, raw: true, leftQuoteLength: 1), | 971 const StringQuoting($SQ, raw: true, leftQuoteLength: 1), |
969 const StringQuoting($DQ, raw: false, leftQuoteLength: 1), | 972 const StringQuoting($DQ, raw: false, leftQuoteLength: 1), |
970 const StringQuoting($DQ, raw: true, leftQuoteLength: 1), | 973 const StringQuoting($DQ, raw: true, leftQuoteLength: 1), |
971 // No string quotes with 2 characters. | 974 // No string quotes with 2 characters. |
972 null, | 975 null, |
973 null, | 976 null, |
974 null, | 977 null, |
(...skipping 15 matching lines...) Expand all Loading... |
990 const StringQuoting($DQ, raw: true, leftQuoteLength: 5), | 993 const StringQuoting($DQ, raw: true, leftQuoteLength: 5), |
991 const StringQuoting($SQ, raw: false, leftQuoteLength: 6), | 994 const StringQuoting($SQ, raw: false, leftQuoteLength: 6), |
992 const StringQuoting($SQ, raw: true, leftQuoteLength: 6), | 995 const StringQuoting($SQ, raw: true, leftQuoteLength: 6), |
993 const StringQuoting($DQ, raw: false, leftQuoteLength: 6), | 996 const StringQuoting($DQ, raw: false, leftQuoteLength: 6), |
994 const StringQuoting($DQ, raw: true, leftQuoteLength: 6) | 997 const StringQuoting($DQ, raw: true, leftQuoteLength: 6) |
995 ]; | 998 ]; |
996 | 999 |
997 final bool raw; | 1000 final bool raw; |
998 final int leftQuoteCharCount; | 1001 final int leftQuoteCharCount; |
999 final int quote; | 1002 final int quote; |
1000 const StringQuoting(this.quote, { this.raw, int leftQuoteLength }) | 1003 const StringQuoting(this.quote, {this.raw, int leftQuoteLength}) |
1001 : this.leftQuoteCharCount = leftQuoteLength; | 1004 : this.leftQuoteCharCount = leftQuoteLength; |
1002 String get quoteChar => identical(quote, $DQ) ? '"' : "'"; | 1005 String get quoteChar => identical(quote, $DQ) ? '"' : "'"; |
1003 | 1006 |
1004 int get leftQuoteLength => (raw ? 1 : 0) + leftQuoteCharCount; | 1007 int get leftQuoteLength => (raw ? 1 : 0) + leftQuoteCharCount; |
1005 int get rightQuoteLength => (leftQuoteCharCount > 2) ? 3 : 1; | 1008 int get rightQuoteLength => (leftQuoteCharCount > 2) ? 3 : 1; |
1006 static StringQuoting getQuoting(int quote, bool raw, int leftQuoteLength) { | 1009 static StringQuoting getQuoting(int quote, bool raw, int leftQuoteLength) { |
1007 int quoteKindOffset = (quote == $DQ) ? 2 : 0; | 1010 int quoteKindOffset = (quote == $DQ) ? 2 : 0; |
1008 int rawOffset = raw ? 1 : 0; | 1011 int rawOffset = raw ? 1 : 0; |
1009 int index = (leftQuoteLength - 1) * 4 + rawOffset + quoteKindOffset; | 1012 int index = (leftQuoteLength - 1) * 4 + rawOffset + quoteKindOffset; |
1010 if (index < _mapping.length) return _mapping[index]; | 1013 if (index < _mapping.length) return _mapping[index]; |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1145 Token getEndToken() => identifiers.getEndToken(); | 1148 Token getEndToken() => identifiers.getEndToken(); |
1146 | 1149 |
1147 String get slowNameString { | 1150 String get slowNameString { |
1148 Unparser unparser = new Unparser(); | 1151 Unparser unparser = new Unparser(); |
1149 unparser.unparseNodeListOfIdentifiers(identifiers); | 1152 unparser.unparseNodeListOfIdentifiers(identifiers); |
1150 return unparser.result; | 1153 return unparser.result; |
1151 } | 1154 } |
1152 } | 1155 } |
1153 | 1156 |
1154 class Operator extends Identifier { | 1157 class Operator extends Identifier { |
1155 static const COMPLEX_OPERATORS = | 1158 static const COMPLEX_OPERATORS = const [ |
1156 const ["--", "++", '+=', "-=", "*=", "/=", "%=", "&=", "|=", "~/=", "^=", | 1159 "--", |
1157 ">>=", "<<=", "??="]; | 1160 "++", |
| 1161 '+=', |
| 1162 "-=", |
| 1163 "*=", |
| 1164 "/=", |
| 1165 "%=", |
| 1166 "&=", |
| 1167 "|=", |
| 1168 "~/=", |
| 1169 "^=", |
| 1170 ">>=", |
| 1171 "<<=", |
| 1172 "??=" |
| 1173 ]; |
1158 | 1174 |
1159 static const INCREMENT_OPERATORS = const <String>["++", "--"]; | 1175 static const INCREMENT_OPERATORS = const <String>["++", "--"]; |
1160 | 1176 |
1161 Operator(Token token) : super(token); | 1177 Operator(Token token) : super(token); |
1162 | 1178 |
1163 Operator asOperator() => this; | 1179 Operator asOperator() => this; |
1164 | 1180 |
1165 accept(Visitor visitor) => visitor.visitOperator(this); | 1181 accept(Visitor visitor) => visitor.visitOperator(this); |
1166 } | 1182 } |
1167 | 1183 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1214 Token getBeginToken() => yieldToken; | 1230 Token getBeginToken() => yieldToken; |
1215 | 1231 |
1216 Token getEndToken() => endToken; | 1232 Token getEndToken() => endToken; |
1217 } | 1233 } |
1218 | 1234 |
1219 class RedirectingFactoryBody extends Statement with StoredTreeElementMixin { | 1235 class RedirectingFactoryBody extends Statement with StoredTreeElementMixin { |
1220 final Node constructorReference; | 1236 final Node constructorReference; |
1221 final Token beginToken; | 1237 final Token beginToken; |
1222 final Token endToken; | 1238 final Token endToken; |
1223 | 1239 |
1224 RedirectingFactoryBody(this.beginToken, this.endToken, | 1240 RedirectingFactoryBody( |
1225 this.constructorReference); | 1241 this.beginToken, this.endToken, this.constructorReference); |
1226 | 1242 |
1227 RedirectingFactoryBody asRedirectingFactoryBody() => this; | 1243 RedirectingFactoryBody asRedirectingFactoryBody() => this; |
1228 | 1244 |
1229 accept(Visitor visitor) => visitor.visitRedirectingFactoryBody(this); | 1245 accept(Visitor visitor) => visitor.visitRedirectingFactoryBody(this); |
1230 | 1246 |
1231 visitChildren(Visitor visitor) { | 1247 visitChildren(Visitor visitor) { |
1232 constructorReference.accept(visitor); | 1248 constructorReference.accept(visitor); |
1233 } | 1249 } |
1234 | 1250 |
1235 Token getBeginToken() => beginToken; | 1251 Token getBeginToken() => beginToken; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1323 | 1339 |
1324 class Rethrow extends Statement { | 1340 class Rethrow extends Statement { |
1325 final Token throwToken; | 1341 final Token throwToken; |
1326 final Token endToken; | 1342 final Token endToken; |
1327 | 1343 |
1328 Rethrow(this.throwToken, this.endToken); | 1344 Rethrow(this.throwToken, this.endToken); |
1329 | 1345 |
1330 Rethrow asRethrow() => this; | 1346 Rethrow asRethrow() => this; |
1331 | 1347 |
1332 accept(Visitor visitor) => visitor.visitRethrow(this); | 1348 accept(Visitor visitor) => visitor.visitRethrow(this); |
1333 visitChildren(Visitor visitor) { } | 1349 visitChildren(Visitor visitor) {} |
1334 | 1350 |
1335 Token getBeginToken() => throwToken; | 1351 Token getBeginToken() => throwToken; |
1336 Token getEndToken() => endToken; | 1352 Token getEndToken() => endToken; |
1337 } | 1353 } |
1338 | 1354 |
1339 class TypeAnnotation extends Node { | 1355 class TypeAnnotation extends Node { |
1340 final Expression typeName; | 1356 final Expression typeName; |
1341 final NodeList typeArguments; | 1357 final NodeList typeArguments; |
1342 | 1358 |
1343 TypeAnnotation(Expression this.typeName, NodeList this.typeArguments); | 1359 TypeAnnotation(Expression this.typeName, NodeList this.typeArguments); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1381 return (bound != null) ? bound.getEndToken() : name.getEndToken(); | 1397 return (bound != null) ? bound.getEndToken() : name.getEndToken(); |
1382 } | 1398 } |
1383 } | 1399 } |
1384 | 1400 |
1385 class VariableDefinitions extends Statement { | 1401 class VariableDefinitions extends Statement { |
1386 final NodeList metadata; | 1402 final NodeList metadata; |
1387 final TypeAnnotation type; | 1403 final TypeAnnotation type; |
1388 final Modifiers modifiers; | 1404 final Modifiers modifiers; |
1389 final NodeList definitions; | 1405 final NodeList definitions; |
1390 | 1406 |
1391 VariableDefinitions(this.type, | 1407 VariableDefinitions(this.type, this.modifiers, this.definitions) |
1392 this.modifiers, | |
1393 this.definitions) | |
1394 : this.metadata = null { | 1408 : this.metadata = null { |
1395 assert(modifiers != null); | 1409 assert(modifiers != null); |
1396 } | 1410 } |
1397 | 1411 |
1398 // TODO(johnniwinther): Make this its own node type. | 1412 // TODO(johnniwinther): Make this its own node type. |
1399 VariableDefinitions.forParameter(this.metadata, | 1413 VariableDefinitions.forParameter( |
1400 this.type, | 1414 this.metadata, this.type, this.modifiers, this.definitions) { |
1401 this.modifiers, | |
1402 this.definitions) { | |
1403 assert(modifiers != null); | 1415 assert(modifiers != null); |
1404 } | 1416 } |
1405 | 1417 |
1406 VariableDefinitions asVariableDefinitions() => this; | 1418 VariableDefinitions asVariableDefinitions() => this; |
1407 | 1419 |
1408 accept(Visitor visitor) => visitor.visitVariableDefinitions(this); | 1420 accept(Visitor visitor) => visitor.visitVariableDefinitions(this); |
1409 | 1421 |
1410 visitChildren(Visitor visitor) { | 1422 visitChildren(Visitor visitor) { |
1411 if (metadata != null) metadata.accept(visitor); | 1423 if (metadata != null) metadata.accept(visitor); |
1412 if (type != null) type.accept(visitor); | 1424 if (type != null) type.accept(visitor); |
(...skipping 20 matching lines...) Expand all Loading... |
1433 bool isValidContinueTarget() => true; | 1445 bool isValidContinueTarget() => true; |
1434 } | 1446 } |
1435 | 1447 |
1436 class DoWhile extends Loop { | 1448 class DoWhile extends Loop { |
1437 final Token doKeyword; | 1449 final Token doKeyword; |
1438 final Token whileKeyword; | 1450 final Token whileKeyword; |
1439 final Token endToken; | 1451 final Token endToken; |
1440 | 1452 |
1441 final Expression condition; | 1453 final Expression condition; |
1442 | 1454 |
1443 DoWhile(Statement body, Expression this.condition, | 1455 DoWhile(Statement body, Expression this.condition, Token this.doKeyword, |
1444 Token this.doKeyword, Token this.whileKeyword, Token this.endToken) | 1456 Token this.whileKeyword, Token this.endToken) |
1445 : super(body); | 1457 : super(body); |
1446 | 1458 |
1447 DoWhile asDoWhile() => this; | 1459 DoWhile asDoWhile() => this; |
1448 | 1460 |
1449 accept(Visitor visitor) => visitor.visitDoWhile(this); | 1461 accept(Visitor visitor) => visitor.visitDoWhile(this); |
1450 | 1462 |
1451 visitChildren(Visitor visitor) { | 1463 visitChildren(Visitor visitor) { |
1452 if (condition != null) condition.accept(visitor); | 1464 if (condition != null) condition.accept(visitor); |
1453 if (body != null) body.accept(visitor); | 1465 if (body != null) body.accept(visitor); |
1454 } | 1466 } |
1455 | 1467 |
1456 Token getBeginToken() => doKeyword; | 1468 Token getBeginToken() => doKeyword; |
1457 | 1469 |
1458 Token getEndToken() => endToken; | 1470 Token getEndToken() => endToken; |
1459 } | 1471 } |
1460 | 1472 |
1461 class While extends Loop { | 1473 class While extends Loop { |
1462 final Token whileKeyword; | 1474 final Token whileKeyword; |
1463 final Expression condition; | 1475 final Expression condition; |
1464 | 1476 |
1465 While(Expression this.condition, Statement body, | 1477 While(Expression this.condition, Statement body, Token this.whileKeyword) |
1466 Token this.whileKeyword) : super(body); | 1478 : super(body); |
1467 | 1479 |
1468 While asWhile() => this; | 1480 While asWhile() => this; |
1469 | 1481 |
1470 accept(Visitor visitor) => visitor.visitWhile(this); | 1482 accept(Visitor visitor) => visitor.visitWhile(this); |
1471 | 1483 |
1472 visitChildren(Visitor visitor) { | 1484 visitChildren(Visitor visitor) { |
1473 if (condition != null) condition.accept(visitor); | 1485 if (condition != null) condition.accept(visitor); |
1474 if (body != null) body.accept(visitor); | 1486 if (body != null) body.accept(visitor); |
1475 } | 1487 } |
1476 | 1488 |
1477 Token getBeginToken() => whileKeyword; | 1489 Token getBeginToken() => whileKeyword; |
1478 | 1490 |
1479 Token getEndToken() => body.getEndToken(); | 1491 Token getEndToken() => body.getEndToken(); |
1480 } | 1492 } |
1481 | 1493 |
1482 class ParenthesizedExpression extends Expression { | 1494 class ParenthesizedExpression extends Expression { |
1483 final Expression expression; | 1495 final Expression expression; |
1484 final BeginGroupToken beginToken; | 1496 final BeginGroupToken beginToken; |
1485 | 1497 |
1486 ParenthesizedExpression(Expression this.expression, | 1498 ParenthesizedExpression( |
1487 BeginGroupToken this.beginToken); | 1499 Expression this.expression, BeginGroupToken this.beginToken); |
1488 | 1500 |
1489 ParenthesizedExpression asParenthesizedExpression() => this; | 1501 ParenthesizedExpression asParenthesizedExpression() => this; |
1490 | 1502 |
1491 accept(Visitor visitor) => visitor.visitParenthesizedExpression(this); | 1503 accept(Visitor visitor) => visitor.visitParenthesizedExpression(this); |
1492 | 1504 |
1493 visitChildren(Visitor visitor) { | 1505 visitChildren(Visitor visitor) { |
1494 if (expression != null) expression.accept(visitor); | 1506 if (expression != null) expression.accept(visitor); |
1495 } | 1507 } |
1496 | 1508 |
1497 Token getBeginToken() => beginToken; | 1509 Token getBeginToken() => beginToken; |
(...skipping 28 matching lines...) Expand all Loading... |
1526 static const int FLAG_EXTERNAL = FLAG_FACTORY << 1; | 1538 static const int FLAG_EXTERNAL = FLAG_FACTORY << 1; |
1527 | 1539 |
1528 Modifiers(NodeList nodes) : this.withFlags(nodes, computeFlags(nodes.nodes)); | 1540 Modifiers(NodeList nodes) : this.withFlags(nodes, computeFlags(nodes.nodes)); |
1529 | 1541 |
1530 Modifiers.withFlags(this.nodes, this.flags); | 1542 Modifiers.withFlags(this.nodes, this.flags); |
1531 | 1543 |
1532 static int computeFlags(Link<Node> nodes) { | 1544 static int computeFlags(Link<Node> nodes) { |
1533 int flags = 0; | 1545 int flags = 0; |
1534 for (; !nodes.isEmpty; nodes = nodes.tail) { | 1546 for (; !nodes.isEmpty; nodes = nodes.tail) { |
1535 String value = nodes.head.asIdentifier().source; | 1547 String value = nodes.head.asIdentifier().source; |
1536 if (identical(value, 'static')) flags |= FLAG_STATIC; | 1548 if (identical(value, 'static')) |
1537 else if (identical(value, 'abstract')) flags |= FLAG_ABSTRACT; | 1549 flags |= FLAG_STATIC; |
1538 else if (identical(value, 'final')) flags |= FLAG_FINAL; | 1550 else if (identical(value, 'abstract')) |
1539 else if (identical(value, 'var')) flags |= FLAG_VAR; | 1551 flags |= FLAG_ABSTRACT; |
1540 else if (identical(value, 'const')) flags |= FLAG_CONST; | 1552 else if (identical(value, 'final')) |
1541 else if (identical(value, 'factory')) flags |= FLAG_FACTORY; | 1553 flags |= FLAG_FINAL; |
1542 else if (identical(value, 'external')) flags |= FLAG_EXTERNAL; | 1554 else if (identical(value, 'var')) |
1543 else throw 'internal error: ${nodes.head}'; | 1555 flags |= FLAG_VAR; |
| 1556 else if (identical(value, 'const')) |
| 1557 flags |= FLAG_CONST; |
| 1558 else if (identical(value, 'factory')) |
| 1559 flags |= FLAG_FACTORY; |
| 1560 else if (identical(value, 'external')) |
| 1561 flags |= FLAG_EXTERNAL; |
| 1562 else |
| 1563 throw 'internal error: ${nodes.head}'; |
1544 } | 1564 } |
1545 return flags; | 1565 return flags; |
1546 } | 1566 } |
1547 | 1567 |
1548 Node findModifier(String modifier) { | 1568 Node findModifier(String modifier) { |
1549 Link<Node> nodeList = nodes.nodes; | 1569 Link<Node> nodeList = nodes.nodes; |
1550 for (; !nodeList.isEmpty; nodeList = nodeList.tail) { | 1570 for (; !nodeList.isEmpty; nodeList = nodeList.tail) { |
1551 String value = nodeList.head.asIdentifier().source; | 1571 String value = nodeList.head.asIdentifier().source; |
1552 if(identical(value, modifier)) { | 1572 if (identical(value, modifier)) { |
1553 return nodeList.head; | 1573 return nodeList.head; |
1554 } | 1574 } |
1555 } | 1575 } |
1556 return null; | 1576 return null; |
1557 } | 1577 } |
1558 | 1578 |
1559 Modifiers asModifiers() => this; | 1579 Modifiers asModifiers() => this; |
1560 Token getBeginToken() => nodes.getBeginToken(); | 1580 Token getBeginToken() => nodes.getBeginToken(); |
1561 Token getEndToken() => nodes.getEndToken(); | 1581 Token getEndToken() => nodes.getEndToken(); |
1562 accept(Visitor visitor) => visitor.visitModifiers(this); | 1582 accept(Visitor visitor) => visitor.visitModifiers(this); |
1563 visitChildren(Visitor visitor) => nodes.accept(visitor); | 1583 visitChildren(Visitor visitor) => nodes.accept(visitor); |
1564 | 1584 |
1565 bool get isStatic => (flags & FLAG_STATIC) != 0; | 1585 bool get isStatic => (flags & FLAG_STATIC) != 0; |
1566 bool get isAbstract => (flags & FLAG_ABSTRACT) != 0; | 1586 bool get isAbstract => (flags & FLAG_ABSTRACT) != 0; |
1567 bool get isFinal => (flags & FLAG_FINAL) != 0; | 1587 bool get isFinal => (flags & FLAG_FINAL) != 0; |
1568 bool get isVar => (flags & FLAG_VAR) != 0; | 1588 bool get isVar => (flags & FLAG_VAR) != 0; |
1569 bool get isConst => (flags & FLAG_CONST) != 0; | 1589 bool get isConst => (flags & FLAG_CONST) != 0; |
1570 bool get isFactory => (flags & FLAG_FACTORY) != 0; | 1590 bool get isFactory => (flags & FLAG_FACTORY) != 0; |
1571 bool get isExternal => (flags & FLAG_EXTERNAL) != 0; | 1591 bool get isExternal => (flags & FLAG_EXTERNAL) != 0; |
1572 | 1592 |
1573 Node getStatic() => findModifier('static'); | 1593 Node getStatic() => findModifier('static'); |
1574 | 1594 |
1575 /** | 1595 /** |
1576 * Use this to check if the declaration is either explicitly or implicitly | 1596 * Use this to check if the declaration is either explicitly or implicitly |
1577 * final. | 1597 * final. |
1578 */ | 1598 */ |
1579 bool get isFinalOrConst => isFinal || isConst; | 1599 bool get isFinalOrConst => isFinal || isConst; |
1580 | 1600 |
1581 String toString() { | 1601 String toString() { |
1582 return modifiersToString(isStatic: isStatic, | 1602 return modifiersToString( |
1583 isAbstract: isAbstract, | 1603 isStatic: isStatic, |
1584 isFinal: isFinal, | 1604 isAbstract: isAbstract, |
1585 isVar: isVar, | 1605 isFinal: isFinal, |
1586 isConst: isConst, | 1606 isVar: isVar, |
1587 isFactory: isFactory, | 1607 isConst: isConst, |
1588 isExternal: isExternal); | 1608 isFactory: isFactory, |
| 1609 isExternal: isExternal); |
1589 } | 1610 } |
1590 } | 1611 } |
1591 | 1612 |
1592 class StringInterpolation extends StringNode { | 1613 class StringInterpolation extends StringNode { |
1593 final LiteralString string; | 1614 final LiteralString string; |
1594 final NodeList parts; | 1615 final NodeList parts; |
1595 | 1616 |
1596 StringInterpolation(this.string, this.parts); | 1617 StringInterpolation(this.string, this.parts); |
1597 | 1618 |
1598 StringInterpolation asStringInterpolation() => this; | 1619 StringInterpolation asStringInterpolation() => this; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1652 */ | 1673 */ |
1653 DartString dartStringCache = null; | 1674 DartString dartStringCache = null; |
1654 | 1675 |
1655 StringJuxtaposition(this.first, this.second); | 1676 StringJuxtaposition(this.first, this.second); |
1656 | 1677 |
1657 StringJuxtaposition asStringJuxtaposition() => this; | 1678 StringJuxtaposition asStringJuxtaposition() => this; |
1658 | 1679 |
1659 bool get isInterpolation { | 1680 bool get isInterpolation { |
1660 if (isInterpolationCache == null) { | 1681 if (isInterpolationCache == null) { |
1661 isInterpolationCache = (first.accept(const IsInterpolationVisitor()) || | 1682 isInterpolationCache = (first.accept(const IsInterpolationVisitor()) || |
1662 second.accept(const IsInterpolationVisitor())); | 1683 second.accept(const IsInterpolationVisitor())); |
1663 } | 1684 } |
1664 return isInterpolationCache; | 1685 return isInterpolationCache; |
1665 } | 1686 } |
1666 | 1687 |
1667 /** | 1688 /** |
1668 * Retrieve a single DartString that represents this entire juxtaposition | 1689 * Retrieve a single DartString that represents this entire juxtaposition |
1669 * of string literals. | 1690 * of string literals. |
1670 * Should only be called if [isInterpolation] returns false. | 1691 * Should only be called if [isInterpolation] returns false. |
1671 */ | 1692 */ |
1672 DartString get dartString { | 1693 DartString get dartString { |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1783 | 1804 |
1784 Token getEndToken() => expression.getEndToken(); | 1805 Token getEndToken() => expression.getEndToken(); |
1785 } | 1806 } |
1786 | 1807 |
1787 class SwitchStatement extends Statement { | 1808 class SwitchStatement extends Statement { |
1788 final ParenthesizedExpression parenthesizedExpression; | 1809 final ParenthesizedExpression parenthesizedExpression; |
1789 final NodeList cases; | 1810 final NodeList cases; |
1790 | 1811 |
1791 final Token switchKeyword; | 1812 final Token switchKeyword; |
1792 | 1813 |
1793 SwitchStatement(this.parenthesizedExpression, this.cases, | 1814 SwitchStatement(this.parenthesizedExpression, this.cases, this.switchKeyword); |
1794 this.switchKeyword); | |
1795 | 1815 |
1796 SwitchStatement asSwitchStatement() => this; | 1816 SwitchStatement asSwitchStatement() => this; |
1797 | 1817 |
1798 Expression get expression => parenthesizedExpression.expression; | 1818 Expression get expression => parenthesizedExpression.expression; |
1799 | 1819 |
1800 accept(Visitor visitor) => visitor.visitSwitchStatement(this); | 1820 accept(Visitor visitor) => visitor.visitSwitchStatement(this); |
1801 | 1821 |
1802 visitChildren(Visitor visitor) { | 1822 visitChildren(Visitor visitor) { |
1803 parenthesizedExpression.accept(visitor); | 1823 parenthesizedExpression.accept(visitor); |
1804 cases.accept(visitor); | 1824 cases.accept(visitor); |
(...skipping 28 matching lines...) Expand all Loading... |
1833 | 1853 |
1834 /** List of [Label] and [CaseMatch] nodes. */ | 1854 /** List of [Label] and [CaseMatch] nodes. */ |
1835 final NodeList labelsAndCases; | 1855 final NodeList labelsAndCases; |
1836 /** A "default" keyword token, if applicable. */ | 1856 /** A "default" keyword token, if applicable. */ |
1837 final Token defaultKeyword; | 1857 final Token defaultKeyword; |
1838 /** List of statements, the body of the case. */ | 1858 /** List of statements, the body of the case. */ |
1839 final NodeList statements; | 1859 final NodeList statements; |
1840 | 1860 |
1841 final Token startToken; | 1861 final Token startToken; |
1842 | 1862 |
1843 SwitchCase(this.labelsAndCases, this.defaultKeyword, | 1863 SwitchCase(this.labelsAndCases, this.defaultKeyword, this.statements, |
1844 this.statements, this.startToken); | 1864 this.startToken); |
1845 | 1865 |
1846 SwitchCase asSwitchCase() => this; | 1866 SwitchCase asSwitchCase() => this; |
1847 | 1867 |
1848 bool get isDefaultCase => defaultKeyword != null; | 1868 bool get isDefaultCase => defaultKeyword != null; |
1849 | 1869 |
1850 bool isValidContinueTarget() => true; | 1870 bool isValidContinueTarget() => true; |
1851 | 1871 |
1852 accept(Visitor visitor) => visitor.visitSwitchCase(this); | 1872 accept(Visitor visitor) => visitor.visitSwitchCase(this); |
1853 | 1873 |
1854 visitChildren(Visitor visitor) { | 1874 visitChildren(Visitor visitor) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1889 Token getBeginToken() => keywordToken; | 1909 Token getBeginToken() => keywordToken; |
1890 | 1910 |
1891 Token getEndToken() => semicolonToken; | 1911 Token getEndToken() => semicolonToken; |
1892 | 1912 |
1893 // TODO(ahe): make class abstract instead of adding an abstract method. | 1913 // TODO(ahe): make class abstract instead of adding an abstract method. |
1894 accept(Visitor visitor); | 1914 accept(Visitor visitor); |
1895 } | 1915 } |
1896 | 1916 |
1897 class BreakStatement extends GotoStatement { | 1917 class BreakStatement extends GotoStatement { |
1898 BreakStatement(Identifier target, Token keywordToken, Token semicolonToken) | 1918 BreakStatement(Identifier target, Token keywordToken, Token semicolonToken) |
1899 : super(target, keywordToken, semicolonToken); | 1919 : super(target, keywordToken, semicolonToken); |
1900 | 1920 |
1901 BreakStatement asBreakStatement() => this; | 1921 BreakStatement asBreakStatement() => this; |
1902 | 1922 |
1903 accept(Visitor visitor) => visitor.visitBreakStatement(this); | 1923 accept(Visitor visitor) => visitor.visitBreakStatement(this); |
1904 } | 1924 } |
1905 | 1925 |
1906 class ContinueStatement extends GotoStatement { | 1926 class ContinueStatement extends GotoStatement { |
1907 ContinueStatement(Identifier target, Token keywordToken, Token semicolonToken) | 1927 ContinueStatement(Identifier target, Token keywordToken, Token semicolonToken) |
1908 : super(target, keywordToken, semicolonToken); | 1928 : super(target, keywordToken, semicolonToken); |
1909 | 1929 |
1910 ContinueStatement asContinueStatement() => this; | 1930 ContinueStatement asContinueStatement() => this; |
1911 | 1931 |
1912 accept(Visitor visitor) => visitor.visitContinueStatement(this); | 1932 accept(Visitor visitor) => visitor.visitContinueStatement(this); |
1913 } | 1933 } |
1914 | 1934 |
1915 abstract class ForIn extends Loop { | 1935 abstract class ForIn extends Loop { |
1916 final Node declaredIdentifier; | 1936 final Node declaredIdentifier; |
1917 final Expression expression; | 1937 final Expression expression; |
1918 | 1938 |
1919 final Token forToken; | 1939 final Token forToken; |
1920 final Token inToken; | 1940 final Token inToken; |
1921 | 1941 |
1922 ForIn(this.declaredIdentifier, this.expression, | 1942 ForIn(this.declaredIdentifier, this.expression, Statement body, this.forToken, |
1923 Statement body, this.forToken, this.inToken) | 1943 this.inToken) |
1924 : super(body); | 1944 : super(body); |
1925 | 1945 |
1926 Expression get condition => null; | 1946 Expression get condition => null; |
1927 | 1947 |
1928 ForIn asForIn() => this; | 1948 ForIn asForIn() => this; |
1929 | 1949 |
1930 Token getEndToken() => body.getEndToken(); | 1950 Token getEndToken() => body.getEndToken(); |
1931 } | 1951 } |
1932 | 1952 |
1933 class SyncForIn extends ForIn with StoredTreeElementMixin { | 1953 class SyncForIn extends ForIn with StoredTreeElementMixin { |
1934 SyncForIn(declaredIdentifier, expression, Statement body, forToken, inToken) | 1954 SyncForIn(declaredIdentifier, expression, Statement body, forToken, inToken) |
1935 : super(declaredIdentifier, expression, body, forToken, inToken); | 1955 : super(declaredIdentifier, expression, body, forToken, inToken); |
1936 | 1956 |
1937 SyncForIn asSyncForIn() => this; | 1957 SyncForIn asSyncForIn() => this; |
1938 | 1958 |
1939 accept(Visitor visitor) => visitor.visitSyncForIn(this); | 1959 accept(Visitor visitor) => visitor.visitSyncForIn(this); |
1940 | 1960 |
1941 visitChildren(Visitor visitor) { | 1961 visitChildren(Visitor visitor) { |
1942 declaredIdentifier.accept(visitor); | 1962 declaredIdentifier.accept(visitor); |
1943 expression.accept(visitor); | 1963 expression.accept(visitor); |
1944 body.accept(visitor); | 1964 body.accept(visitor); |
1945 } | 1965 } |
1946 | 1966 |
1947 Token getBeginToken() => forToken; | 1967 Token getBeginToken() => forToken; |
1948 } | 1968 } |
1949 | 1969 |
1950 class AsyncForIn extends ForIn with StoredTreeElementMixin { | 1970 class AsyncForIn extends ForIn with StoredTreeElementMixin { |
1951 final Token awaitToken; | 1971 final Token awaitToken; |
1952 | 1972 |
1953 AsyncForIn(declaredIdentifier, expression, | 1973 AsyncForIn(declaredIdentifier, expression, Statement body, this.awaitToken, |
1954 Statement body, this.awaitToken, forToken, inToken) | 1974 forToken, inToken) |
1955 : super(declaredIdentifier, expression, body, forToken, inToken); | 1975 : super(declaredIdentifier, expression, body, forToken, inToken); |
1956 | 1976 |
1957 AsyncForIn asAsyncForIn() => this; | 1977 AsyncForIn asAsyncForIn() => this; |
1958 | 1978 |
1959 accept(Visitor visitor) => visitor.visitAsyncForIn(this); | 1979 accept(Visitor visitor) => visitor.visitAsyncForIn(this); |
1960 | 1980 |
1961 visitChildren(Visitor visitor) { | 1981 visitChildren(Visitor visitor) { |
1962 declaredIdentifier.accept(visitor); | 1982 declaredIdentifier.accept(visitor); |
1963 expression.accept(visitor); | 1983 expression.accept(visitor); |
1964 body.accept(visitor); | 1984 body.accept(visitor); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2019 bool get isExport => false; | 2039 bool get isExport => false; |
2020 bool get isPart => false; | 2040 bool get isPart => false; |
2021 bool get isPartOf => false; | 2041 bool get isPartOf => false; |
2022 } | 2042 } |
2023 | 2043 |
2024 class LibraryName extends LibraryTag { | 2044 class LibraryName extends LibraryTag { |
2025 final Expression name; | 2045 final Expression name; |
2026 | 2046 |
2027 final Token libraryKeyword; | 2047 final Token libraryKeyword; |
2028 | 2048 |
2029 LibraryName(this.libraryKeyword, | 2049 LibraryName(this.libraryKeyword, this.name, List<MetadataAnnotation> metadata) |
2030 this.name, | 2050 : super(metadata); |
2031 List<MetadataAnnotation> metadata) | |
2032 : super(metadata); | |
2033 | 2051 |
2034 bool get isLibraryName => true; | 2052 bool get isLibraryName => true; |
2035 | 2053 |
2036 LibraryName asLibraryName() => this; | 2054 LibraryName asLibraryName() => this; |
2037 | 2055 |
2038 accept(Visitor visitor) => visitor.visitLibraryName(this); | 2056 accept(Visitor visitor) => visitor.visitLibraryName(this); |
2039 | 2057 |
2040 visitChildren(Visitor visitor) => name.accept(visitor); | 2058 visitChildren(Visitor visitor) => name.accept(visitor); |
2041 | 2059 |
2042 Token getBeginToken() => libraryKeyword; | 2060 Token getBeginToken() => libraryKeyword; |
2043 | 2061 |
2044 Token getEndToken() => name.getEndToken().next; | 2062 Token getEndToken() => name.getEndToken().next; |
2045 } | 2063 } |
2046 | 2064 |
2047 /** | 2065 /** |
2048 * This tag describes a dependency between one library and the exported | 2066 * This tag describes a dependency between one library and the exported |
2049 * identifiers of another library. The other library is specified by the [uri]. | 2067 * identifiers of another library. The other library is specified by the [uri]. |
2050 * Combinators filter away some identifiers from the other library. | 2068 * Combinators filter away some identifiers from the other library. |
2051 */ | 2069 */ |
2052 abstract class LibraryDependency extends LibraryTag { | 2070 abstract class LibraryDependency extends LibraryTag { |
2053 final StringNode uri; | 2071 final StringNode uri; |
2054 final NodeList conditionalUris; | 2072 final NodeList conditionalUris; |
2055 final NodeList combinators; | 2073 final NodeList combinators; |
2056 | 2074 |
2057 LibraryDependency(this.uri, | 2075 LibraryDependency(this.uri, this.conditionalUris, this.combinators, |
2058 this.conditionalUris, | 2076 List<MetadataAnnotation> metadata) |
2059 this.combinators, | 2077 : super(metadata); |
2060 List<MetadataAnnotation> metadata) | |
2061 : super(metadata); | |
2062 | 2078 |
2063 LibraryDependency asLibraryDependency() => this; | 2079 LibraryDependency asLibraryDependency() => this; |
2064 | 2080 |
2065 bool get hasConditionalUris => conditionalUris != null; | 2081 bool get hasConditionalUris => conditionalUris != null; |
2066 } | 2082 } |
2067 | 2083 |
2068 /** | 2084 /** |
2069 * An [:import:] library tag. | 2085 * An [:import:] library tag. |
2070 * | 2086 * |
2071 * An import tag is dependency on another library where the exported identifiers | 2087 * An import tag is dependency on another library where the exported identifiers |
2072 * are put into the import scope of the importing library. The import scope is | 2088 * are put into the import scope of the importing library. The import scope is |
2073 * only visible inside the library. | 2089 * only visible inside the library. |
2074 */ | 2090 */ |
2075 class Import extends LibraryDependency { | 2091 class Import extends LibraryDependency { |
2076 final Identifier prefix; | 2092 final Identifier prefix; |
2077 final Token importKeyword; | 2093 final Token importKeyword; |
2078 final bool isDeferred; | 2094 final bool isDeferred; |
2079 | 2095 |
2080 Import(this.importKeyword, StringNode uri, NodeList conditionalUris, | 2096 Import(this.importKeyword, StringNode uri, NodeList conditionalUris, |
2081 this.prefix, NodeList combinators, | 2097 this.prefix, NodeList combinators, List<MetadataAnnotation> metadata, |
2082 List<MetadataAnnotation> metadata, | 2098 {this.isDeferred}) |
2083 {this.isDeferred}) | |
2084 : super(uri, conditionalUris, combinators, metadata); | 2099 : super(uri, conditionalUris, combinators, metadata); |
2085 | 2100 |
2086 bool get isImport => true; | 2101 bool get isImport => true; |
2087 | 2102 |
2088 Import asImport() => this; | 2103 Import asImport() => this; |
2089 | 2104 |
2090 accept(Visitor visitor) => visitor.visitImport(this); | 2105 accept(Visitor visitor) => visitor.visitImport(this); |
2091 | 2106 |
2092 visitChildren(Visitor visitor) { | 2107 visitChildren(Visitor visitor) { |
2093 uri.accept(visitor); | 2108 uri.accept(visitor); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2168 /** | 2183 /** |
2169 * An [:export:] library tag. | 2184 * An [:export:] library tag. |
2170 * | 2185 * |
2171 * An export tag is dependency on another library where the exported identifiers | 2186 * An export tag is dependency on another library where the exported identifiers |
2172 * are put into the export scope of the exporting library. The export scope is | 2187 * are put into the export scope of the exporting library. The export scope is |
2173 * not visible inside the library. | 2188 * not visible inside the library. |
2174 */ | 2189 */ |
2175 class Export extends LibraryDependency { | 2190 class Export extends LibraryDependency { |
2176 final Token exportKeyword; | 2191 final Token exportKeyword; |
2177 | 2192 |
2178 Export(this.exportKeyword, | 2193 Export(this.exportKeyword, StringNode uri, NodeList conditionalUris, |
2179 StringNode uri, | 2194 NodeList combinators, List<MetadataAnnotation> metadata) |
2180 NodeList conditionalUris, | |
2181 NodeList combinators, | |
2182 List<MetadataAnnotation> metadata) | |
2183 : super(uri, conditionalUris, combinators, metadata); | 2195 : super(uri, conditionalUris, combinators, metadata); |
2184 | 2196 |
2185 bool get isExport => true; | 2197 bool get isExport => true; |
2186 | 2198 |
2187 Export asExport() => this; | 2199 Export asExport() => this; |
2188 | 2200 |
2189 accept(Visitor visitor) => visitor.visitExport(this); | 2201 accept(Visitor visitor) => visitor.visitExport(this); |
2190 | 2202 |
2191 visitChildren(Visitor visitor) { | 2203 visitChildren(Visitor visitor) { |
2192 uri.accept(visitor); | 2204 uri.accept(visitor); |
2193 if (combinators != null) combinators.accept(visitor); | 2205 if (combinators != null) combinators.accept(visitor); |
2194 } | 2206 } |
2195 | 2207 |
2196 Token getBeginToken() => exportKeyword; | 2208 Token getBeginToken() => exportKeyword; |
2197 | 2209 |
2198 Token getEndToken() { | 2210 Token getEndToken() { |
2199 if (combinators != null) return combinators.getEndToken().next; | 2211 if (combinators != null) return combinators.getEndToken().next; |
2200 if (conditionalUris != null) return conditionalUris.getEndToken().next; | 2212 if (conditionalUris != null) return conditionalUris.getEndToken().next; |
2201 return uri.getEndToken().next; | 2213 return uri.getEndToken().next; |
2202 } | 2214 } |
2203 } | 2215 } |
2204 | 2216 |
2205 class Part extends LibraryTag { | 2217 class Part extends LibraryTag { |
2206 final StringNode uri; | 2218 final StringNode uri; |
2207 | 2219 |
2208 final Token partKeyword; | 2220 final Token partKeyword; |
2209 | 2221 |
2210 Part(this.partKeyword, this.uri, List<MetadataAnnotation> metadata) | 2222 Part(this.partKeyword, this.uri, List<MetadataAnnotation> metadata) |
2211 : super(metadata); | 2223 : super(metadata); |
2212 | 2224 |
2213 bool get isPart => true; | 2225 bool get isPart => true; |
2214 | 2226 |
2215 Part asPart() => this; | 2227 Part asPart() => this; |
2216 | 2228 |
2217 accept(Visitor visitor) => visitor.visitPart(this); | 2229 accept(Visitor visitor) => visitor.visitPart(this); |
2218 | 2230 |
2219 visitChildren(Visitor visitor) => uri.accept(visitor); | 2231 visitChildren(Visitor visitor) => uri.accept(visitor); |
2220 | 2232 |
2221 Token getBeginToken() => partKeyword; | 2233 Token getBeginToken() => partKeyword; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2272 class Typedef extends Node { | 2284 class Typedef extends Node { |
2273 final TypeAnnotation returnType; | 2285 final TypeAnnotation returnType; |
2274 final Identifier name; | 2286 final Identifier name; |
2275 final NodeList typeParameters; | 2287 final NodeList typeParameters; |
2276 final NodeList formals; | 2288 final NodeList formals; |
2277 | 2289 |
2278 final Token typedefKeyword; | 2290 final Token typedefKeyword; |
2279 final Token endToken; | 2291 final Token endToken; |
2280 | 2292 |
2281 Typedef(this.returnType, this.name, this.typeParameters, this.formals, | 2293 Typedef(this.returnType, this.name, this.typeParameters, this.formals, |
2282 this.typedefKeyword, this.endToken); | 2294 this.typedefKeyword, this.endToken); |
2283 | 2295 |
2284 Typedef asTypedef() => this; | 2296 Typedef asTypedef() => this; |
2285 | 2297 |
2286 accept(Visitor visitor) => visitor.visitTypedef(this); | 2298 accept(Visitor visitor) => visitor.visitTypedef(this); |
2287 | 2299 |
2288 visitChildren(Visitor visitor) { | 2300 visitChildren(Visitor visitor) { |
2289 if (returnType != null) returnType.accept(visitor); | 2301 if (returnType != null) returnType.accept(visitor); |
2290 name.accept(visitor); | 2302 name.accept(visitor); |
2291 if (typeParameters != null) typeParameters.accept(visitor); | 2303 if (typeParameters != null) typeParameters.accept(visitor); |
2292 formals.accept(visitor); | 2304 formals.accept(visitor); |
2293 } | 2305 } |
2294 | 2306 |
2295 Token getBeginToken() => typedefKeyword; | 2307 Token getBeginToken() => typedefKeyword; |
2296 | 2308 |
2297 Token getEndToken() => endToken; | 2309 Token getEndToken() => endToken; |
2298 } | 2310 } |
2299 | 2311 |
2300 class TryStatement extends Statement { | 2312 class TryStatement extends Statement { |
2301 final Block tryBlock; | 2313 final Block tryBlock; |
2302 final NodeList catchBlocks; | 2314 final NodeList catchBlocks; |
2303 final Block finallyBlock; | 2315 final Block finallyBlock; |
2304 | 2316 |
2305 final Token tryKeyword; | 2317 final Token tryKeyword; |
2306 final Token finallyKeyword; | 2318 final Token finallyKeyword; |
2307 | 2319 |
2308 TryStatement(this.tryBlock, this.catchBlocks, this.finallyBlock, | 2320 TryStatement(this.tryBlock, this.catchBlocks, this.finallyBlock, |
2309 this.tryKeyword, this.finallyKeyword); | 2321 this.tryKeyword, this.finallyKeyword); |
2310 | 2322 |
2311 TryStatement asTryStatement() => this; | 2323 TryStatement asTryStatement() => this; |
2312 | 2324 |
2313 accept(Visitor visitor) => visitor.visitTryStatement(this); | 2325 accept(Visitor visitor) => visitor.visitTryStatement(this); |
2314 | 2326 |
2315 visitChildren(Visitor visitor) { | 2327 visitChildren(Visitor visitor) { |
2316 tryBlock.accept(visitor); | 2328 tryBlock.accept(visitor); |
2317 catchBlocks.accept(visitor); | 2329 catchBlocks.accept(visitor); |
2318 if (finallyBlock != null) finallyBlock.accept(visitor); | 2330 if (finallyBlock != null) finallyBlock.accept(visitor); |
2319 } | 2331 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2361 } | 2373 } |
2362 | 2374 |
2363 class CatchBlock extends Node { | 2375 class CatchBlock extends Node { |
2364 final TypeAnnotation type; | 2376 final TypeAnnotation type; |
2365 final NodeList formals; | 2377 final NodeList formals; |
2366 final Block block; | 2378 final Block block; |
2367 | 2379 |
2368 final Token onKeyword; | 2380 final Token onKeyword; |
2369 final Token catchKeyword; | 2381 final Token catchKeyword; |
2370 | 2382 |
2371 CatchBlock(this.type, this.formals, this.block, | 2383 CatchBlock( |
2372 this.onKeyword, this.catchKeyword); | 2384 this.type, this.formals, this.block, this.onKeyword, this.catchKeyword); |
2373 | 2385 |
2374 CatchBlock asCatchBlock() => this; | 2386 CatchBlock asCatchBlock() => this; |
2375 | 2387 |
2376 accept(Visitor visitor) => visitor.visitCatchBlock(this); | 2388 accept(Visitor visitor) => visitor.visitCatchBlock(this); |
2377 | 2389 |
2378 Node get exception { | 2390 Node get exception { |
2379 if (formals == null || formals.nodes.isEmpty) return null; | 2391 if (formals == null || formals.nodes.isEmpty) return null; |
2380 VariableDefinitions declarations = formals.nodes.head; | 2392 VariableDefinitions declarations = formals.nodes.head; |
2381 return declarations.definitions.nodes.head; | 2393 return declarations.definitions.nodes.head; |
2382 } | 2394 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2415 } | 2427 } |
2416 | 2428 |
2417 Token getBeginToken() => token; | 2429 Token getBeginToken() => token; |
2418 | 2430 |
2419 Token getEndToken() => expression.getEndToken(); | 2431 Token getEndToken() => expression.getEndToken(); |
2420 } | 2432 } |
2421 | 2433 |
2422 class Initializers { | 2434 class Initializers { |
2423 static bool isSuperConstructorCall(Send node) { | 2435 static bool isSuperConstructorCall(Send node) { |
2424 return (node.receiver == null && node.selector.isSuper()) || | 2436 return (node.receiver == null && node.selector.isSuper()) || |
2425 (node.receiver != null && | 2437 (node.receiver != null && |
2426 node.receiver.isSuper() && | 2438 node.receiver.isSuper() && |
2427 !node.isConditional && | 2439 !node.isConditional && |
2428 node.selector.asIdentifier() != null); | 2440 node.selector.asIdentifier() != null); |
2429 } | 2441 } |
2430 | 2442 |
2431 static bool isConstructorRedirect(Send node) { | 2443 static bool isConstructorRedirect(Send node) { |
2432 return (node.receiver == null && node.selector.isThis()) || | 2444 return (node.receiver == null && node.selector.isThis()) || |
2433 (node.receiver != null && | 2445 (node.receiver != null && |
2434 node.receiver.isThis() && | 2446 node.receiver.isThis() && |
2435 !node.isConditional && | 2447 !node.isConditional && |
2436 node.selector.asIdentifier() != null); | 2448 node.selector.asIdentifier() != null); |
2437 } | 2449 } |
2438 } | 2450 } |
2439 | 2451 |
2440 class GetDartStringVisitor extends Visitor<DartString> { | 2452 class GetDartStringVisitor extends Visitor<DartString> { |
2441 const GetDartStringVisitor(); | 2453 const GetDartStringVisitor(); |
2442 DartString visitNode(Node node) => null; | 2454 DartString visitNode(Node node) => null; |
2443 DartString visitStringJuxtaposition(StringJuxtaposition node) | 2455 DartString visitStringJuxtaposition(StringJuxtaposition node) => |
2444 => node.dartString; | 2456 node.dartString; |
2445 DartString visitLiteralString(LiteralString node) => node.dartString; | 2457 DartString visitLiteralString(LiteralString node) => node.dartString; |
2446 } | 2458 } |
2447 | 2459 |
2448 class IsInterpolationVisitor extends Visitor<bool> { | 2460 class IsInterpolationVisitor extends Visitor<bool> { |
2449 const IsInterpolationVisitor(); | 2461 const IsInterpolationVisitor(); |
2450 bool visitNode(Node node) => false; | 2462 bool visitNode(Node node) => false; |
2451 bool visitStringInterpolation(StringInterpolation node) => true; | 2463 bool visitStringInterpolation(StringInterpolation node) => true; |
2452 bool visitStringJuxtaposition(StringJuxtaposition node) | 2464 bool visitStringJuxtaposition(StringJuxtaposition node) => |
2453 => node.isInterpolation; | 2465 node.isInterpolation; |
2454 } | 2466 } |
2455 | 2467 |
2456 /// Erroneous node used to recover from parser errors. Implements various | 2468 /// Erroneous node used to recover from parser errors. Implements various |
2457 /// interfaces and provides bare minimum of implementation to avoid unnecessary | 2469 /// interfaces and provides bare minimum of implementation to avoid unnecessary |
2458 /// messages. | 2470 /// messages. |
2459 class ErrorNode | 2471 class ErrorNode extends Node |
2460 extends Node | |
2461 implements FunctionExpression, VariableDefinitions, Typedef { | 2472 implements FunctionExpression, VariableDefinitions, Typedef { |
2462 final Token token; | 2473 final Token token; |
2463 final String reason; | 2474 final String reason; |
2464 final Identifier name; | 2475 final Identifier name; |
2465 final NodeList definitions; | 2476 final NodeList definitions; |
2466 | 2477 |
2467 ErrorNode.internal(this.token, this.reason, this.name, this.definitions); | 2478 ErrorNode.internal(this.token, this.reason, this.name, this.definitions); |
2468 | 2479 |
2469 factory ErrorNode(Token token, String reason) { | 2480 factory ErrorNode(Token token, String reason) { |
2470 Identifier name = new Identifier(token); | 2481 Identifier name = new Identifier(token); |
2471 NodeList definitions = new NodeList( | 2482 NodeList definitions = |
2472 null, const Link<Node>().prepend(name), null, null); | 2483 new NodeList(null, const Link<Node>().prepend(name), null, null); |
2473 return new ErrorNode.internal(token, reason, name, definitions); | 2484 return new ErrorNode.internal(token, reason, name, definitions); |
2474 } | 2485 } |
2475 | 2486 |
2476 Token get beginToken => token; | 2487 Token get beginToken => token; |
2477 Token get endToken => token; | 2488 Token get endToken => token; |
2478 | 2489 |
2479 Token getBeginToken() => token; | 2490 Token getBeginToken() => token; |
2480 | 2491 |
2481 Token getEndToken() => token; | 2492 Token getEndToken() => token; |
2482 | 2493 |
(...skipping 17 matching lines...) Expand all Loading... |
2500 | 2511 |
2501 // VariableDefinitions. | 2512 // VariableDefinitions. |
2502 get metadata => null; | 2513 get metadata => null; |
2503 get type => null; | 2514 get type => null; |
2504 | 2515 |
2505 // Typedef. | 2516 // Typedef. |
2506 get typeParameters => null; | 2517 get typeParameters => null; |
2507 get formals => null; | 2518 get formals => null; |
2508 get typedefKeyword => null; | 2519 get typedefKeyword => null; |
2509 } | 2520 } |
OLD | NEW |