| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library analyzer.src.generated.parser; | 5 library analyzer.src.generated.parser; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 import "dart:math" as math; | 8 import "dart:math" as math; |
| 9 | 9 |
| 10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
| 11 import 'package:analyzer/dart/ast/token.dart'; | 11 import 'package:analyzer/dart/ast/token.dart'; |
| 12 import 'package:analyzer/dart/ast/visitor.dart'; | |
| 13 import 'package:analyzer/src/dart/ast/ast.dart'; | 12 import 'package:analyzer/src/dart/ast/ast.dart'; |
| 14 import 'package:analyzer/src/dart/ast/token.dart'; | 13 import 'package:analyzer/src/dart/ast/token.dart'; |
| 15 import 'package:analyzer/src/dart/ast/utilities.dart'; | |
| 16 import 'package:analyzer/src/dart/scanner/reader.dart'; | 14 import 'package:analyzer/src/dart/scanner/reader.dart'; |
| 17 import 'package:analyzer/src/dart/scanner/scanner.dart'; | 15 import 'package:analyzer/src/dart/scanner/scanner.dart'; |
| 18 import 'package:analyzer/src/generated/engine.dart' show AnalysisEngine; | 16 import 'package:analyzer/src/generated/engine.dart' show AnalysisEngine; |
| 19 import 'package:analyzer/src/generated/error.dart'; | 17 import 'package:analyzer/src/generated/error.dart'; |
| 20 import 'package:analyzer/src/generated/generated/shared_messages.dart' | 18 import 'package:analyzer/src/generated/generated/shared_messages.dart' |
| 21 as shared_messages; | 19 as shared_messages; |
| 22 import 'package:analyzer/src/generated/java_core.dart'; | 20 import 'package:analyzer/src/generated/java_core.dart'; |
| 23 import 'package:analyzer/src/generated/java_engine.dart'; | 21 import 'package:analyzer/src/generated/java_engine.dart'; |
| 24 import 'package:analyzer/src/generated/source.dart'; | 22 import 'package:analyzer/src/generated/source.dart'; |
| 25 import 'package:analyzer/src/generated/utilities_collection.dart' show TokenMap; | |
| 26 import 'package:analyzer/src/generated/utilities_dart.dart'; | 23 import 'package:analyzer/src/generated/utilities_dart.dart'; |
| 27 | 24 |
| 28 export 'package:analyzer/src/dart/ast/utilities.dart' show ResolutionCopier; | 25 export 'package:analyzer/src/dart/ast/utilities.dart' show ResolutionCopier; |
| 29 | 26 |
| 30 Map<String, MethodTrampoline> methodTable_Parser = <String, MethodTrampoline>{ | 27 Map<String, MethodTrampoline> methodTable_Parser = <String, MethodTrampoline>{ |
| 31 'parseCompilationUnit_1': new MethodTrampoline( | 28 'parseCompilationUnit_1': new MethodTrampoline( |
| 32 1, (Parser target, arg0) => target.parseCompilationUnit(arg0)), | 29 1, (Parser target, arg0) => target.parseCompilationUnit(arg0)), |
| 33 'parseDirectives_1': new MethodTrampoline( | 30 'parseDirectives_1': new MethodTrampoline( |
| 34 1, (Parser target, arg0) => target.parseDirectives(arg0)), | 31 1, (Parser target, arg0) => target.parseDirectives(arg0)), |
| 35 'parseExpression_1': new MethodTrampoline( | 32 'parseExpression_1': new MethodTrampoline( |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 */ | 524 */ |
| 528 final TypeName type; | 525 final TypeName type; |
| 529 | 526 |
| 530 /** | 527 /** |
| 531 * Initialize a newly created holder with the given [keyword] and [type]. | 528 * Initialize a newly created holder with the given [keyword] and [type]. |
| 532 */ | 529 */ |
| 533 FinalConstVarOrType(this.keyword, this.type); | 530 FinalConstVarOrType(this.keyword, this.type); |
| 534 } | 531 } |
| 535 | 532 |
| 536 /** | 533 /** |
| 537 * A dispatcher that will invoke the right parse method when re-parsing a | |
| 538 * specified child of the visited node. All of the methods in this class assume | |
| 539 * that the parser is positioned to parse the replacement for the node. All of | |
| 540 * the methods will throw an [IncrementalParseException] if the node could not | |
| 541 * be parsed for some reason. | |
| 542 */ | |
| 543 @deprecated | |
| 544 class IncrementalParseDispatcher implements AstVisitor<AstNode> { | |
| 545 /** | |
| 546 * The parser used to parse the replacement for the node. | |
| 547 */ | |
| 548 final Parser _parser; | |
| 549 | |
| 550 /** | |
| 551 * The node that is to be replaced. | |
| 552 */ | |
| 553 final AstNode _oldNode; | |
| 554 | |
| 555 /** | |
| 556 * Initialize a newly created dispatcher to parse a single node that will | |
| 557 * use the [_parser] to replace the [_oldNode]. | |
| 558 */ | |
| 559 IncrementalParseDispatcher(this._parser, this._oldNode); | |
| 560 | |
| 561 @override | |
| 562 AstNode visitAdjacentStrings(AdjacentStrings node) { | |
| 563 if (node.strings.contains(_oldNode)) { | |
| 564 return _parser.parseStringLiteral(); | |
| 565 } | |
| 566 return _notAChild(node); | |
| 567 } | |
| 568 | |
| 569 @override | |
| 570 AstNode visitAnnotation(Annotation node) { | |
| 571 if (identical(_oldNode, node.name)) { | |
| 572 throw new InsufficientContextException(); | |
| 573 } else if (identical(_oldNode, node.constructorName)) { | |
| 574 throw new InsufficientContextException(); | |
| 575 } else if (identical(_oldNode, node.arguments)) { | |
| 576 return _parser.parseArgumentList(); | |
| 577 } | |
| 578 return _notAChild(node); | |
| 579 } | |
| 580 | |
| 581 @override | |
| 582 AstNode visitArgumentList(ArgumentList node) { | |
| 583 if (node.arguments.contains(_oldNode)) { | |
| 584 return _parser.parseArgument(); | |
| 585 } | |
| 586 return _notAChild(node); | |
| 587 } | |
| 588 | |
| 589 @override | |
| 590 AstNode visitAsExpression(AsExpression node) { | |
| 591 if (identical(_oldNode, node.expression)) { | |
| 592 return _parser.parseBitwiseOrExpression(); | |
| 593 } else if (identical(_oldNode, node.type)) { | |
| 594 return _parser.parseTypeName(); | |
| 595 } | |
| 596 return _notAChild(node); | |
| 597 } | |
| 598 | |
| 599 @override | |
| 600 AstNode visitAssertStatement(AssertStatement node) { | |
| 601 if (identical(_oldNode, node.condition)) { | |
| 602 return _parser.parseExpression2(); | |
| 603 } | |
| 604 if (identical(_oldNode, node.message)) { | |
| 605 return _parser.parseExpression2(); | |
| 606 } | |
| 607 return _notAChild(node); | |
| 608 } | |
| 609 | |
| 610 @override | |
| 611 AstNode visitAssignmentExpression(AssignmentExpression node) { | |
| 612 if (identical(_oldNode, node.leftHandSide)) { | |
| 613 // TODO(brianwilkerson) If the assignment is part of a cascade section, | |
| 614 // then we don't have a single parse method that will work. | |
| 615 // Otherwise, we can parse a conditional expression, but need to ensure | |
| 616 // that the resulting expression is assignable. | |
| 617 // return parser.parseConditionalExpression(); | |
| 618 throw new InsufficientContextException(); | |
| 619 } else if (identical(_oldNode, node.rightHandSide)) { | |
| 620 if (_isCascadeAllowedInAssignment(node)) { | |
| 621 return _parser.parseExpression2(); | |
| 622 } | |
| 623 return _parser.parseExpressionWithoutCascade(); | |
| 624 } | |
| 625 return _notAChild(node); | |
| 626 } | |
| 627 | |
| 628 @override | |
| 629 AstNode visitAwaitExpression(AwaitExpression node) { | |
| 630 if (identical(_oldNode, node.expression)) { | |
| 631 // TODO(brianwilkerson) Depending on precedence, | |
| 632 // this might not be sufficient. | |
| 633 return _parser.parseExpression2(); | |
| 634 } | |
| 635 return _notAChild(node); | |
| 636 } | |
| 637 | |
| 638 @override | |
| 639 AstNode visitBinaryExpression(BinaryExpression node) { | |
| 640 if (identical(_oldNode, node.leftOperand)) { | |
| 641 throw new InsufficientContextException(); | |
| 642 } else if (identical(_oldNode, node.rightOperand)) { | |
| 643 throw new InsufficientContextException(); | |
| 644 } | |
| 645 return _notAChild(node); | |
| 646 } | |
| 647 | |
| 648 @override | |
| 649 AstNode visitBlock(Block node) { | |
| 650 if (node.statements.contains(_oldNode)) { | |
| 651 return _parser.parseStatement2(); | |
| 652 } | |
| 653 return _notAChild(node); | |
| 654 } | |
| 655 | |
| 656 @override | |
| 657 AstNode visitBlockFunctionBody(BlockFunctionBody node) { | |
| 658 if (identical(_oldNode, node.block)) { | |
| 659 return _parser.parseBlock(); | |
| 660 } | |
| 661 return _notAChild(node); | |
| 662 } | |
| 663 | |
| 664 @override | |
| 665 AstNode visitBooleanLiteral(BooleanLiteral node) => _notAChild(node); | |
| 666 | |
| 667 @override | |
| 668 AstNode visitBreakStatement(BreakStatement node) { | |
| 669 if (identical(_oldNode, node.label)) { | |
| 670 return _parser.parseSimpleIdentifier(); | |
| 671 } | |
| 672 return _notAChild(node); | |
| 673 } | |
| 674 | |
| 675 @override | |
| 676 AstNode visitCascadeExpression(CascadeExpression node) { | |
| 677 if (identical(_oldNode, node.target)) { | |
| 678 return _parser.parseConditionalExpression(); | |
| 679 } else if (node.cascadeSections.contains(_oldNode)) { | |
| 680 throw new InsufficientContextException(); | |
| 681 } | |
| 682 return _notAChild(node); | |
| 683 } | |
| 684 | |
| 685 @override | |
| 686 AstNode visitCatchClause(CatchClause node) { | |
| 687 if (identical(_oldNode, node.exceptionType)) { | |
| 688 return _parser.parseTypeName(); | |
| 689 } else if (identical(_oldNode, node.exceptionParameter)) { | |
| 690 return _parser.parseSimpleIdentifier(isDeclaration: true); | |
| 691 } else if (identical(_oldNode, node.stackTraceParameter)) { | |
| 692 return _parser.parseSimpleIdentifier(isDeclaration: true); | |
| 693 } else if (identical(_oldNode, node.body)) { | |
| 694 return _parser.parseBlock(); | |
| 695 } | |
| 696 return _notAChild(node); | |
| 697 } | |
| 698 | |
| 699 @override | |
| 700 AstNode visitClassDeclaration(ClassDeclaration node) { | |
| 701 if (identical(_oldNode, node.documentationComment)) { | |
| 702 throw new InsufficientContextException(); | |
| 703 } else if (node.metadata.contains(_oldNode)) { | |
| 704 return _parser.parseAnnotation(); | |
| 705 } else if (identical(_oldNode, node.name)) { | |
| 706 // Changing the class name changes whether a member is interpreted as a | |
| 707 // constructor or not, so we'll just have to re-parse the entire class. | |
| 708 throw new InsufficientContextException(); | |
| 709 } else if (identical(_oldNode, node.typeParameters)) { | |
| 710 return _parser.parseTypeParameterList(); | |
| 711 } else if (identical(_oldNode, node.extendsClause)) { | |
| 712 return _parser.parseExtendsClause(); | |
| 713 } else if (identical(_oldNode, node.withClause)) { | |
| 714 return _parser.parseWithClause(); | |
| 715 } else if (identical(_oldNode, node.implementsClause)) { | |
| 716 return _parser.parseImplementsClause(); | |
| 717 } else if (node.members.contains(_oldNode)) { | |
| 718 ClassMember member = _parser.parseClassMember(node.name.name); | |
| 719 if (member == null) { | |
| 720 throw new InsufficientContextException(); | |
| 721 } | |
| 722 return member; | |
| 723 } | |
| 724 return _notAChild(node); | |
| 725 } | |
| 726 | |
| 727 @override | |
| 728 AstNode visitClassTypeAlias(ClassTypeAlias node) { | |
| 729 if (identical(_oldNode, node.documentationComment)) { | |
| 730 throw new InsufficientContextException(); | |
| 731 } else if (node.metadata.contains(_oldNode)) { | |
| 732 return _parser.parseAnnotation(); | |
| 733 } else if (identical(_oldNode, node.name)) { | |
| 734 return _parser.parseSimpleIdentifier(isDeclaration: true); | |
| 735 } else if (identical(_oldNode, node.typeParameters)) { | |
| 736 return _parser.parseTypeParameterList(); | |
| 737 } else if (identical(_oldNode, node.superclass)) { | |
| 738 return _parser.parseTypeName(); | |
| 739 } else if (identical(_oldNode, node.withClause)) { | |
| 740 return _parser.parseWithClause(); | |
| 741 } else if (identical(_oldNode, node.implementsClause)) { | |
| 742 return _parser.parseImplementsClause(); | |
| 743 } | |
| 744 return _notAChild(node); | |
| 745 } | |
| 746 | |
| 747 @override | |
| 748 AstNode visitComment(Comment node) { | |
| 749 throw new InsufficientContextException(); | |
| 750 } | |
| 751 | |
| 752 @override | |
| 753 AstNode visitCommentReference(CommentReference node) { | |
| 754 if (identical(_oldNode, node.identifier)) { | |
| 755 return _parser.parsePrefixedIdentifier(); | |
| 756 } | |
| 757 return _notAChild(node); | |
| 758 } | |
| 759 | |
| 760 @override | |
| 761 AstNode visitCompilationUnit(CompilationUnit node) { | |
| 762 throw new InsufficientContextException(); | |
| 763 } | |
| 764 | |
| 765 @override | |
| 766 AstNode visitConditionalExpression(ConditionalExpression node) { | |
| 767 if (identical(_oldNode, node.condition)) { | |
| 768 return _parser.parseIfNullExpression(); | |
| 769 } else if (identical(_oldNode, node.thenExpression)) { | |
| 770 return _parser.parseExpressionWithoutCascade(); | |
| 771 } else if (identical(_oldNode, node.elseExpression)) { | |
| 772 return _parser.parseExpressionWithoutCascade(); | |
| 773 } | |
| 774 return _notAChild(node); | |
| 775 } | |
| 776 | |
| 777 @override | |
| 778 AstNode visitConfiguration(Configuration node) { | |
| 779 if (identical(_oldNode, node.name)) { | |
| 780 throw new InsufficientContextException(); | |
| 781 } else if (identical(_oldNode, node.value)) { | |
| 782 return _parser.parseStringLiteral(); | |
| 783 } else if (identical(_oldNode, node.libraryUri)) { | |
| 784 return _parser.parseStringLiteral(); | |
| 785 } | |
| 786 return _notAChild(node); | |
| 787 } | |
| 788 | |
| 789 @override | |
| 790 AstNode visitConstructorDeclaration(ConstructorDeclaration node) { | |
| 791 if (identical(_oldNode, node.documentationComment)) { | |
| 792 throw new InsufficientContextException(); | |
| 793 } else if (node.metadata.contains(_oldNode)) { | |
| 794 return _parser.parseAnnotation(); | |
| 795 } else if (identical(_oldNode, node.returnType)) { | |
| 796 throw new InsufficientContextException(); | |
| 797 } else if (identical(_oldNode, node.name)) { | |
| 798 throw new InsufficientContextException(); | |
| 799 } else if (identical(_oldNode, node.parameters)) { | |
| 800 return _parser.parseFormalParameterList(); | |
| 801 } else if (identical(_oldNode, node.redirectedConstructor)) { | |
| 802 throw new InsufficientContextException(); | |
| 803 } else if (node.initializers.contains(_oldNode)) { | |
| 804 throw new InsufficientContextException(); | |
| 805 } else if (identical(_oldNode, node.body)) { | |
| 806 throw new InsufficientContextException(); | |
| 807 } | |
| 808 return _notAChild(node); | |
| 809 } | |
| 810 | |
| 811 @override | |
| 812 AstNode visitConstructorFieldInitializer(ConstructorFieldInitializer node) { | |
| 813 if (identical(_oldNode, node.fieldName)) { | |
| 814 return _parser.parseSimpleIdentifier(); | |
| 815 } else if (identical(_oldNode, node.expression)) { | |
| 816 throw new InsufficientContextException(); | |
| 817 } | |
| 818 return _notAChild(node); | |
| 819 } | |
| 820 | |
| 821 @override | |
| 822 AstNode visitConstructorName(ConstructorName node) { | |
| 823 if (identical(_oldNode, node.type)) { | |
| 824 return _parser.parseTypeName(); | |
| 825 } else if (identical(_oldNode, node.name)) { | |
| 826 return _parser.parseSimpleIdentifier(); | |
| 827 } | |
| 828 return _notAChild(node); | |
| 829 } | |
| 830 | |
| 831 @override | |
| 832 AstNode visitContinueStatement(ContinueStatement node) { | |
| 833 if (identical(_oldNode, node.label)) { | |
| 834 return _parser.parseSimpleIdentifier(); | |
| 835 } | |
| 836 return _notAChild(node); | |
| 837 } | |
| 838 | |
| 839 @override | |
| 840 AstNode visitDeclaredIdentifier(DeclaredIdentifier node) { | |
| 841 if (identical(_oldNode, node.documentationComment)) { | |
| 842 throw new InsufficientContextException(); | |
| 843 } else if (node.metadata.contains(_oldNode)) { | |
| 844 return _parser.parseAnnotation(); | |
| 845 } else if (identical(_oldNode, node.type)) { | |
| 846 throw new InsufficientContextException(); | |
| 847 } else if (identical(_oldNode, node.identifier)) { | |
| 848 return _parser.parseSimpleIdentifier(); | |
| 849 } | |
| 850 return _notAChild(node); | |
| 851 } | |
| 852 | |
| 853 @override | |
| 854 AstNode visitDefaultFormalParameter(DefaultFormalParameter node) { | |
| 855 if (identical(_oldNode, node.parameter)) { | |
| 856 return _parser.parseNormalFormalParameter(); | |
| 857 } else if (identical(_oldNode, node.defaultValue)) { | |
| 858 return _parser.parseExpression2(); | |
| 859 } | |
| 860 return _notAChild(node); | |
| 861 } | |
| 862 | |
| 863 @override | |
| 864 AstNode visitDoStatement(DoStatement node) { | |
| 865 if (identical(_oldNode, node.body)) { | |
| 866 return _parser.parseStatement2(); | |
| 867 } else if (identical(_oldNode, node.condition)) { | |
| 868 return _parser.parseExpression2(); | |
| 869 } | |
| 870 return _notAChild(node); | |
| 871 } | |
| 872 | |
| 873 @override | |
| 874 AstNode visitDottedName(DottedName node) { | |
| 875 if (node.components.contains(_oldNode)) { | |
| 876 throw new InsufficientContextException(); | |
| 877 } | |
| 878 return _notAChild(node); | |
| 879 } | |
| 880 | |
| 881 @override | |
| 882 AstNode visitDoubleLiteral(DoubleLiteral node) => _notAChild(node); | |
| 883 | |
| 884 @override | |
| 885 AstNode visitEmptyFunctionBody(EmptyFunctionBody node) => _notAChild(node); | |
| 886 | |
| 887 @override | |
| 888 AstNode visitEmptyStatement(EmptyStatement node) => _notAChild(node); | |
| 889 | |
| 890 @override | |
| 891 AstNode visitEnumConstantDeclaration(EnumConstantDeclaration node) { | |
| 892 if (identical(_oldNode, node.documentationComment)) { | |
| 893 throw new InsufficientContextException(); | |
| 894 } else if (node.metadata.contains(_oldNode)) { | |
| 895 return _parser.parseAnnotation(); | |
| 896 } else if (identical(_oldNode, node.name)) { | |
| 897 return _parser.parseSimpleIdentifier(isDeclaration: true); | |
| 898 } | |
| 899 return _notAChild(node); | |
| 900 } | |
| 901 | |
| 902 @override | |
| 903 AstNode visitEnumDeclaration(EnumDeclaration node) { | |
| 904 if (identical(_oldNode, node.documentationComment)) { | |
| 905 throw new InsufficientContextException(); | |
| 906 } else if (node.metadata.contains(_oldNode)) { | |
| 907 return _parser.parseAnnotation(); | |
| 908 } else if (identical(_oldNode, node.name)) { | |
| 909 return _parser.parseSimpleIdentifier(isDeclaration: true); | |
| 910 } else if (node.constants.contains(_oldNode)) { | |
| 911 throw new InsufficientContextException(); | |
| 912 } | |
| 913 return _notAChild(node); | |
| 914 } | |
| 915 | |
| 916 @override | |
| 917 AstNode visitExportDirective(ExportDirective node) { | |
| 918 if (identical(_oldNode, node.documentationComment)) { | |
| 919 throw new InsufficientContextException(); | |
| 920 } else if (node.metadata.contains(_oldNode)) { | |
| 921 return _parser.parseAnnotation(); | |
| 922 } else if (identical(_oldNode, node.uri)) { | |
| 923 return _parser.parseStringLiteral(); | |
| 924 } else if (node.combinators.contains(_oldNode)) { | |
| 925 throw new IncrementalParseException(); | |
| 926 //return parser.parseCombinator(); | |
| 927 } | |
| 928 return _notAChild(node); | |
| 929 } | |
| 930 | |
| 931 @override | |
| 932 AstNode visitExpressionFunctionBody(ExpressionFunctionBody node) { | |
| 933 if (identical(_oldNode, node.expression)) { | |
| 934 return _parser.parseExpression2(); | |
| 935 } | |
| 936 return _notAChild(node); | |
| 937 } | |
| 938 | |
| 939 @override | |
| 940 AstNode visitExpressionStatement(ExpressionStatement node) { | |
| 941 if (identical(_oldNode, node.expression)) { | |
| 942 return _parser.parseExpression2(); | |
| 943 } | |
| 944 return _notAChild(node); | |
| 945 } | |
| 946 | |
| 947 @override | |
| 948 AstNode visitExtendsClause(ExtendsClause node) { | |
| 949 if (identical(_oldNode, node.superclass)) { | |
| 950 return _parser.parseTypeName(); | |
| 951 } | |
| 952 return _notAChild(node); | |
| 953 } | |
| 954 | |
| 955 @override | |
| 956 AstNode visitFieldDeclaration(FieldDeclaration node) { | |
| 957 if (identical(_oldNode, node.documentationComment)) { | |
| 958 throw new InsufficientContextException(); | |
| 959 } else if (node.metadata.contains(_oldNode)) { | |
| 960 return _parser.parseAnnotation(); | |
| 961 } else if (identical(_oldNode, node.fields)) { | |
| 962 throw new InsufficientContextException(); | |
| 963 } | |
| 964 return _notAChild(node); | |
| 965 } | |
| 966 | |
| 967 @override | |
| 968 AstNode visitFieldFormalParameter(FieldFormalParameter node) { | |
| 969 if (identical(_oldNode, node.documentationComment)) { | |
| 970 throw new InsufficientContextException(); | |
| 971 } else if (node.metadata.contains(_oldNode)) { | |
| 972 return _parser.parseAnnotation(); | |
| 973 } else if (identical(_oldNode, node.type)) { | |
| 974 return _parser.parseTypeName(); | |
| 975 } else if (identical(_oldNode, node.identifier)) { | |
| 976 return _parser.parseSimpleIdentifier(); | |
| 977 } else if (identical(_oldNode, node.parameters)) { | |
| 978 return _parser.parseFormalParameterList(); | |
| 979 } | |
| 980 return _notAChild(node); | |
| 981 } | |
| 982 | |
| 983 @override | |
| 984 AstNode visitForEachStatement(ForEachStatement node) { | |
| 985 if (identical(_oldNode, node.loopVariable)) { | |
| 986 throw new InsufficientContextException(); | |
| 987 //return parser.parseDeclaredIdentifier(); | |
| 988 } else if (identical(_oldNode, node.identifier)) { | |
| 989 return _parser.parseSimpleIdentifier(isDeclaration: true); | |
| 990 } else if (identical(_oldNode, node.body)) { | |
| 991 return _parser.parseStatement2(); | |
| 992 } | |
| 993 return _notAChild(node); | |
| 994 } | |
| 995 | |
| 996 @override | |
| 997 AstNode visitFormalParameterList(FormalParameterList node) { | |
| 998 // We don't know which kind of parameter to parse. | |
| 999 throw new InsufficientContextException(); | |
| 1000 } | |
| 1001 | |
| 1002 @override | |
| 1003 AstNode visitForStatement(ForStatement node) { | |
| 1004 if (identical(_oldNode, node.variables)) { | |
| 1005 throw new InsufficientContextException(); | |
| 1006 } else if (identical(_oldNode, node.initialization)) { | |
| 1007 throw new InsufficientContextException(); | |
| 1008 } else if (identical(_oldNode, node.condition)) { | |
| 1009 return _parser.parseExpression2(); | |
| 1010 } else if (node.updaters.contains(_oldNode)) { | |
| 1011 return _parser.parseExpression2(); | |
| 1012 } else if (identical(_oldNode, node.body)) { | |
| 1013 return _parser.parseStatement2(); | |
| 1014 } | |
| 1015 return _notAChild(node); | |
| 1016 } | |
| 1017 | |
| 1018 @override | |
| 1019 AstNode visitFunctionDeclaration(FunctionDeclaration node) { | |
| 1020 if (identical(_oldNode, node.documentationComment)) { | |
| 1021 throw new InsufficientContextException(); | |
| 1022 } else if (node.metadata.contains(_oldNode)) { | |
| 1023 return _parser.parseAnnotation(); | |
| 1024 } else if (identical(_oldNode, node.returnType)) { | |
| 1025 return _parser.parseReturnType(); | |
| 1026 } else if (identical(_oldNode, node.name)) { | |
| 1027 return _parser.parseSimpleIdentifier(isDeclaration: true); | |
| 1028 } else if (identical(_oldNode, node.functionExpression)) { | |
| 1029 throw new InsufficientContextException(); | |
| 1030 } | |
| 1031 return _notAChild(node); | |
| 1032 } | |
| 1033 | |
| 1034 @override | |
| 1035 AstNode visitFunctionDeclarationStatement(FunctionDeclarationStatement node) { | |
| 1036 if (identical(_oldNode, node.functionDeclaration)) { | |
| 1037 throw new InsufficientContextException(); | |
| 1038 } | |
| 1039 return _notAChild(node); | |
| 1040 } | |
| 1041 | |
| 1042 @override | |
| 1043 AstNode visitFunctionExpression(FunctionExpression node) { | |
| 1044 if (identical(_oldNode, node.parameters)) { | |
| 1045 return _parser.parseFormalParameterList(); | |
| 1046 } else if (identical(_oldNode, node.body)) { | |
| 1047 throw new InsufficientContextException(); | |
| 1048 } | |
| 1049 return _notAChild(node); | |
| 1050 } | |
| 1051 | |
| 1052 @override | |
| 1053 AstNode visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { | |
| 1054 if (identical(_oldNode, node.function)) { | |
| 1055 throw new InsufficientContextException(); | |
| 1056 } else if (identical(_oldNode, node.argumentList)) { | |
| 1057 return _parser.parseArgumentList(); | |
| 1058 } | |
| 1059 return _notAChild(node); | |
| 1060 } | |
| 1061 | |
| 1062 @override | |
| 1063 AstNode visitFunctionTypeAlias(FunctionTypeAlias node) { | |
| 1064 if (identical(_oldNode, node.documentationComment)) { | |
| 1065 throw new InsufficientContextException(); | |
| 1066 } else if (node.metadata.contains(_oldNode)) { | |
| 1067 return _parser.parseAnnotation(); | |
| 1068 } else if (identical(_oldNode, node.returnType)) { | |
| 1069 return _parser.parseReturnType(); | |
| 1070 } else if (identical(_oldNode, node.name)) { | |
| 1071 return _parser.parseSimpleIdentifier(isDeclaration: true); | |
| 1072 } else if (identical(_oldNode, node.typeParameters)) { | |
| 1073 return _parser.parseTypeParameterList(); | |
| 1074 } else if (identical(_oldNode, node.parameters)) { | |
| 1075 return _parser.parseFormalParameterList(); | |
| 1076 } | |
| 1077 return _notAChild(node); | |
| 1078 } | |
| 1079 | |
| 1080 @override | |
| 1081 AstNode visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { | |
| 1082 if (identical(_oldNode, node.documentationComment)) { | |
| 1083 throw new InsufficientContextException(); | |
| 1084 } else if (node.metadata.contains(_oldNode)) { | |
| 1085 return _parser.parseAnnotation(); | |
| 1086 } else if (identical(_oldNode, node.returnType)) { | |
| 1087 return _parser.parseReturnType(); | |
| 1088 } else if (identical(_oldNode, node.identifier)) { | |
| 1089 return _parser.parseSimpleIdentifier(isDeclaration: true); | |
| 1090 } else if (identical(_oldNode, node.parameters)) { | |
| 1091 return _parser.parseFormalParameterList(); | |
| 1092 } | |
| 1093 return _notAChild(node); | |
| 1094 } | |
| 1095 | |
| 1096 @override | |
| 1097 AstNode visitHideCombinator(HideCombinator node) { | |
| 1098 if (node.hiddenNames.contains(_oldNode)) { | |
| 1099 return _parser.parseSimpleIdentifier(); | |
| 1100 } | |
| 1101 return _notAChild(node); | |
| 1102 } | |
| 1103 | |
| 1104 @override | |
| 1105 AstNode visitIfStatement(IfStatement node) { | |
| 1106 if (identical(_oldNode, node.condition)) { | |
| 1107 return _parser.parseExpression2(); | |
| 1108 } else if (identical(_oldNode, node.thenStatement)) { | |
| 1109 return _parser.parseStatement2(); | |
| 1110 } else if (identical(_oldNode, node.elseStatement)) { | |
| 1111 return _parser.parseStatement2(); | |
| 1112 } | |
| 1113 return _notAChild(node); | |
| 1114 } | |
| 1115 | |
| 1116 @override | |
| 1117 AstNode visitImplementsClause(ImplementsClause node) { | |
| 1118 if (node.interfaces.contains(node)) { | |
| 1119 return _parser.parseTypeName(); | |
| 1120 } | |
| 1121 return _notAChild(node); | |
| 1122 } | |
| 1123 | |
| 1124 @override | |
| 1125 AstNode visitImportDirective(ImportDirective node) { | |
| 1126 if (identical(_oldNode, node.documentationComment)) { | |
| 1127 throw new InsufficientContextException(); | |
| 1128 } else if (node.metadata.contains(_oldNode)) { | |
| 1129 return _parser.parseAnnotation(); | |
| 1130 } else if (identical(_oldNode, node.uri)) { | |
| 1131 return _parser.parseStringLiteral(); | |
| 1132 } else if (identical(_oldNode, node.prefix)) { | |
| 1133 return _parser.parseSimpleIdentifier(isDeclaration: true); | |
| 1134 } else if (node.combinators.contains(_oldNode)) { | |
| 1135 return _parser.parseCombinator(); | |
| 1136 } | |
| 1137 return _notAChild(node); | |
| 1138 } | |
| 1139 | |
| 1140 @override | |
| 1141 AstNode visitIndexExpression(IndexExpression node) { | |
| 1142 if (identical(_oldNode, node.target)) { | |
| 1143 throw new InsufficientContextException(); | |
| 1144 } else if (identical(_oldNode, node.index)) { | |
| 1145 return _parser.parseExpression2(); | |
| 1146 } | |
| 1147 return _notAChild(node); | |
| 1148 } | |
| 1149 | |
| 1150 @override | |
| 1151 AstNode visitInstanceCreationExpression(InstanceCreationExpression node) { | |
| 1152 if (identical(_oldNode, node.constructorName)) { | |
| 1153 return _parser.parseConstructorName(); | |
| 1154 } else if (identical(_oldNode, node.argumentList)) { | |
| 1155 return _parser.parseArgumentList(); | |
| 1156 } | |
| 1157 return _notAChild(node); | |
| 1158 } | |
| 1159 | |
| 1160 @override | |
| 1161 AstNode visitIntegerLiteral(IntegerLiteral node) => _notAChild(node); | |
| 1162 | |
| 1163 @override | |
| 1164 AstNode visitInterpolationExpression(InterpolationExpression node) { | |
| 1165 if (identical(_oldNode, node.expression)) { | |
| 1166 if (node.leftBracket == null) { | |
| 1167 throw new InsufficientContextException(); | |
| 1168 //return parser.parseThisOrSimpleIdentifier(); | |
| 1169 } | |
| 1170 return _parser.parseExpression2(); | |
| 1171 } | |
| 1172 return _notAChild(node); | |
| 1173 } | |
| 1174 | |
| 1175 @override | |
| 1176 AstNode visitInterpolationString(InterpolationString node) { | |
| 1177 throw new InsufficientContextException(); | |
| 1178 } | |
| 1179 | |
| 1180 @override | |
| 1181 AstNode visitIsExpression(IsExpression node) { | |
| 1182 if (identical(_oldNode, node.expression)) { | |
| 1183 return _parser.parseBitwiseOrExpression(); | |
| 1184 } else if (identical(_oldNode, node.type)) { | |
| 1185 return _parser.parseTypeName(); | |
| 1186 } | |
| 1187 return _notAChild(node); | |
| 1188 } | |
| 1189 | |
| 1190 @override | |
| 1191 AstNode visitLabel(Label node) { | |
| 1192 if (identical(_oldNode, node.label)) { | |
| 1193 return _parser.parseSimpleIdentifier( | |
| 1194 isDeclaration: node.parent is LabeledStatement); | |
| 1195 } | |
| 1196 return _notAChild(node); | |
| 1197 } | |
| 1198 | |
| 1199 @override | |
| 1200 AstNode visitLabeledStatement(LabeledStatement node) { | |
| 1201 if (node.labels.contains(_oldNode)) { | |
| 1202 return _parser.parseLabel(isDeclaration: true); | |
| 1203 } else if (identical(_oldNode, node.statement)) { | |
| 1204 return _parser.parseStatement2(); | |
| 1205 } | |
| 1206 return _notAChild(node); | |
| 1207 } | |
| 1208 | |
| 1209 @override | |
| 1210 AstNode visitLibraryDirective(LibraryDirective node) { | |
| 1211 if (identical(_oldNode, node.documentationComment)) { | |
| 1212 throw new InsufficientContextException(); | |
| 1213 } else if (node.metadata.contains(_oldNode)) { | |
| 1214 return _parser.parseAnnotation(); | |
| 1215 } else if (identical(_oldNode, node.name)) { | |
| 1216 return _parser.parseLibraryIdentifier(); | |
| 1217 } | |
| 1218 return _notAChild(node); | |
| 1219 } | |
| 1220 | |
| 1221 @override | |
| 1222 AstNode visitLibraryIdentifier(LibraryIdentifier node) { | |
| 1223 if (node.components.contains(_oldNode)) { | |
| 1224 return _parser.parseSimpleIdentifier(); | |
| 1225 } | |
| 1226 return _notAChild(node); | |
| 1227 } | |
| 1228 | |
| 1229 @override | |
| 1230 AstNode visitListLiteral(ListLiteral node) { | |
| 1231 if (identical(_oldNode, node.typeArguments)) { | |
| 1232 return _parser.parseTypeArgumentList(); | |
| 1233 } else if (node.elements.contains(_oldNode)) { | |
| 1234 return _parser.parseExpression2(); | |
| 1235 } | |
| 1236 return _notAChild(node); | |
| 1237 } | |
| 1238 | |
| 1239 @override | |
| 1240 AstNode visitMapLiteral(MapLiteral node) { | |
| 1241 if (identical(_oldNode, node.typeArguments)) { | |
| 1242 return _parser.parseTypeArgumentList(); | |
| 1243 } else if (node.entries.contains(_oldNode)) { | |
| 1244 return _parser.parseMapLiteralEntry(); | |
| 1245 } | |
| 1246 return _notAChild(node); | |
| 1247 } | |
| 1248 | |
| 1249 @override | |
| 1250 AstNode visitMapLiteralEntry(MapLiteralEntry node) { | |
| 1251 if (identical(_oldNode, node.key)) { | |
| 1252 return _parser.parseExpression2(); | |
| 1253 } else if (identical(_oldNode, node.value)) { | |
| 1254 return _parser.parseExpression2(); | |
| 1255 } | |
| 1256 return _notAChild(node); | |
| 1257 } | |
| 1258 | |
| 1259 @override | |
| 1260 AstNode visitMethodDeclaration(MethodDeclaration node) { | |
| 1261 if (identical(_oldNode, node.documentationComment)) { | |
| 1262 throw new InsufficientContextException(); | |
| 1263 } else if (node.metadata.contains(_oldNode)) { | |
| 1264 return _parser.parseAnnotation(); | |
| 1265 } else if (identical(_oldNode, node.returnType)) { | |
| 1266 throw new InsufficientContextException(); | |
| 1267 //return parser.parseTypeName(); | |
| 1268 //return parser.parseReturnType(); | |
| 1269 } else if (identical(_oldNode, node.name)) { | |
| 1270 if (node.operatorKeyword != null) { | |
| 1271 throw new InsufficientContextException(); | |
| 1272 } | |
| 1273 return _parser.parseSimpleIdentifier(isDeclaration: true); | |
| 1274 } else if (identical(_oldNode, node.body)) { | |
| 1275 //return parser.parseFunctionBody(); | |
| 1276 throw new InsufficientContextException(); | |
| 1277 } else if (identical(_oldNode, node.parameters)) { | |
| 1278 // TODO(paulberry): if we want errors to be correct, we'll need to also | |
| 1279 // call _validateFormalParameterList, and sometimes | |
| 1280 // _validateModifiersForGetterOrSetterOrMethod. | |
| 1281 return _parser.parseFormalParameterList(); | |
| 1282 } | |
| 1283 return _notAChild(node); | |
| 1284 } | |
| 1285 | |
| 1286 @override | |
| 1287 AstNode visitMethodInvocation(MethodInvocation node) { | |
| 1288 if (identical(_oldNode, node.target)) { | |
| 1289 throw new IncrementalParseException(); | |
| 1290 } else if (identical(_oldNode, node.methodName)) { | |
| 1291 return _parser.parseSimpleIdentifier(); | |
| 1292 } else if (identical(_oldNode, node.argumentList)) { | |
| 1293 return _parser.parseArgumentList(); | |
| 1294 } | |
| 1295 return _notAChild(node); | |
| 1296 } | |
| 1297 | |
| 1298 @override | |
| 1299 AstNode visitNamedExpression(NamedExpression node) { | |
| 1300 if (identical(_oldNode, node.name)) { | |
| 1301 return _parser.parseLabel(); | |
| 1302 } else if (identical(_oldNode, node.expression)) { | |
| 1303 return _parser.parseExpression2(); | |
| 1304 } | |
| 1305 return _notAChild(node); | |
| 1306 } | |
| 1307 | |
| 1308 @override | |
| 1309 AstNode visitNativeClause(NativeClause node) { | |
| 1310 if (identical(_oldNode, node.name)) { | |
| 1311 return _parser.parseStringLiteral(); | |
| 1312 } | |
| 1313 return _notAChild(node); | |
| 1314 } | |
| 1315 | |
| 1316 @override | |
| 1317 AstNode visitNativeFunctionBody(NativeFunctionBody node) { | |
| 1318 if (identical(_oldNode, node.stringLiteral)) { | |
| 1319 return _parser.parseStringLiteral(); | |
| 1320 } | |
| 1321 return _notAChild(node); | |
| 1322 } | |
| 1323 | |
| 1324 @override | |
| 1325 AstNode visitNullLiteral(NullLiteral node) => _notAChild(node); | |
| 1326 | |
| 1327 @override | |
| 1328 AstNode visitParenthesizedExpression(ParenthesizedExpression node) { | |
| 1329 if (identical(_oldNode, node.expression)) { | |
| 1330 return _parser.parseExpression2(); | |
| 1331 } | |
| 1332 return _notAChild(node); | |
| 1333 } | |
| 1334 | |
| 1335 @override | |
| 1336 AstNode visitPartDirective(PartDirective node) { | |
| 1337 if (identical(_oldNode, node.documentationComment)) { | |
| 1338 throw new InsufficientContextException(); | |
| 1339 } else if (node.metadata.contains(_oldNode)) { | |
| 1340 return _parser.parseAnnotation(); | |
| 1341 } else if (identical(_oldNode, node.uri)) { | |
| 1342 return _parser.parseStringLiteral(); | |
| 1343 } | |
| 1344 return _notAChild(node); | |
| 1345 } | |
| 1346 | |
| 1347 @override | |
| 1348 AstNode visitPartOfDirective(PartOfDirective node) { | |
| 1349 if (identical(_oldNode, node.documentationComment)) { | |
| 1350 throw new InsufficientContextException(); | |
| 1351 } else if (node.metadata.contains(_oldNode)) { | |
| 1352 return _parser.parseAnnotation(); | |
| 1353 } else if (identical(_oldNode, node.libraryName)) { | |
| 1354 return _parser.parseLibraryIdentifier(); | |
| 1355 } | |
| 1356 return _notAChild(node); | |
| 1357 } | |
| 1358 | |
| 1359 @override | |
| 1360 AstNode visitPostfixExpression(PostfixExpression node) { | |
| 1361 if (identical(_oldNode, node.operand)) { | |
| 1362 throw new InsufficientContextException(); | |
| 1363 } | |
| 1364 return _notAChild(node); | |
| 1365 } | |
| 1366 | |
| 1367 @override | |
| 1368 AstNode visitPrefixedIdentifier(PrefixedIdentifier node) { | |
| 1369 if (identical(_oldNode, node.prefix)) { | |
| 1370 return _parser.parseSimpleIdentifier(); | |
| 1371 } else if (identical(_oldNode, node.identifier)) { | |
| 1372 return _parser.parseSimpleIdentifier(); | |
| 1373 } | |
| 1374 return _notAChild(node); | |
| 1375 } | |
| 1376 | |
| 1377 @override | |
| 1378 AstNode visitPrefixExpression(PrefixExpression node) { | |
| 1379 if (identical(_oldNode, node.operand)) { | |
| 1380 throw new InsufficientContextException(); | |
| 1381 } | |
| 1382 return _notAChild(node); | |
| 1383 } | |
| 1384 | |
| 1385 @override | |
| 1386 AstNode visitPropertyAccess(PropertyAccess node) { | |
| 1387 if (identical(_oldNode, node.target)) { | |
| 1388 throw new InsufficientContextException(); | |
| 1389 } else if (identical(_oldNode, node.propertyName)) { | |
| 1390 return _parser.parseSimpleIdentifier(); | |
| 1391 } | |
| 1392 return _notAChild(node); | |
| 1393 } | |
| 1394 | |
| 1395 @override | |
| 1396 AstNode visitRedirectingConstructorInvocation( | |
| 1397 RedirectingConstructorInvocation node) { | |
| 1398 if (identical(_oldNode, node.constructorName)) { | |
| 1399 return _parser.parseSimpleIdentifier(); | |
| 1400 } else if (identical(_oldNode, node.argumentList)) { | |
| 1401 return _parser.parseArgumentList(); | |
| 1402 } | |
| 1403 return _notAChild(node); | |
| 1404 } | |
| 1405 | |
| 1406 @override | |
| 1407 AstNode visitRethrowExpression(RethrowExpression node) => _notAChild(node); | |
| 1408 | |
| 1409 @override | |
| 1410 AstNode visitReturnStatement(ReturnStatement node) { | |
| 1411 if (identical(_oldNode, node.expression)) { | |
| 1412 return _parser.parseExpression2(); | |
| 1413 } | |
| 1414 return _notAChild(node); | |
| 1415 } | |
| 1416 | |
| 1417 @override | |
| 1418 AstNode visitScriptTag(ScriptTag node) => _notAChild(node); | |
| 1419 | |
| 1420 @override | |
| 1421 AstNode visitShowCombinator(ShowCombinator node) { | |
| 1422 if (node.shownNames.contains(_oldNode)) { | |
| 1423 return _parser.parseSimpleIdentifier(); | |
| 1424 } | |
| 1425 return _notAChild(node); | |
| 1426 } | |
| 1427 | |
| 1428 @override | |
| 1429 AstNode visitSimpleFormalParameter(SimpleFormalParameter node) { | |
| 1430 if (identical(_oldNode, node.documentationComment)) { | |
| 1431 throw new InsufficientContextException(); | |
| 1432 } else if (node.metadata.contains(_oldNode)) { | |
| 1433 return _parser.parseAnnotation(); | |
| 1434 } else if (identical(_oldNode, node.type)) { | |
| 1435 throw new InsufficientContextException(); | |
| 1436 } else if (identical(_oldNode, node.identifier)) { | |
| 1437 throw new InsufficientContextException(); | |
| 1438 } | |
| 1439 return _notAChild(node); | |
| 1440 } | |
| 1441 | |
| 1442 @override | |
| 1443 AstNode visitSimpleIdentifier(SimpleIdentifier node) => _notAChild(node); | |
| 1444 | |
| 1445 @override | |
| 1446 AstNode visitSimpleStringLiteral(SimpleStringLiteral node) => | |
| 1447 _notAChild(node); | |
| 1448 | |
| 1449 @override | |
| 1450 AstNode visitStringInterpolation(StringInterpolation node) { | |
| 1451 if (node.elements.contains(_oldNode)) { | |
| 1452 throw new InsufficientContextException(); | |
| 1453 } | |
| 1454 return _notAChild(node); | |
| 1455 } | |
| 1456 | |
| 1457 @override | |
| 1458 AstNode visitSuperConstructorInvocation(SuperConstructorInvocation node) { | |
| 1459 if (identical(_oldNode, node.constructorName)) { | |
| 1460 return _parser.parseSimpleIdentifier(); | |
| 1461 } else if (identical(_oldNode, node.argumentList)) { | |
| 1462 return _parser.parseArgumentList(); | |
| 1463 } | |
| 1464 return _notAChild(node); | |
| 1465 } | |
| 1466 | |
| 1467 @override | |
| 1468 AstNode visitSuperExpression(SuperExpression node) => _notAChild(node); | |
| 1469 | |
| 1470 @override | |
| 1471 AstNode visitSwitchCase(SwitchCase node) { | |
| 1472 if (node.labels.contains(_oldNode)) { | |
| 1473 return _parser.parseLabel(); | |
| 1474 } else if (identical(_oldNode, node.expression)) { | |
| 1475 return _parser.parseExpression2(); | |
| 1476 } else if (node.statements.contains(_oldNode)) { | |
| 1477 return _parser.parseStatement2(); | |
| 1478 } | |
| 1479 return _notAChild(node); | |
| 1480 } | |
| 1481 | |
| 1482 @override | |
| 1483 AstNode visitSwitchDefault(SwitchDefault node) { | |
| 1484 if (node.labels.contains(_oldNode)) { | |
| 1485 return _parser.parseLabel(); | |
| 1486 } else if (node.statements.contains(_oldNode)) { | |
| 1487 return _parser.parseStatement2(); | |
| 1488 } | |
| 1489 return _notAChild(node); | |
| 1490 } | |
| 1491 | |
| 1492 @override | |
| 1493 AstNode visitSwitchStatement(SwitchStatement node) { | |
| 1494 if (identical(_oldNode, node.expression)) { | |
| 1495 return _parser.parseExpression2(); | |
| 1496 } else if (node.members.contains(_oldNode)) { | |
| 1497 throw new InsufficientContextException(); | |
| 1498 } | |
| 1499 return _notAChild(node); | |
| 1500 } | |
| 1501 | |
| 1502 @override | |
| 1503 AstNode visitSymbolLiteral(SymbolLiteral node) => _notAChild(node); | |
| 1504 | |
| 1505 @override | |
| 1506 AstNode visitThisExpression(ThisExpression node) => _notAChild(node); | |
| 1507 | |
| 1508 @override | |
| 1509 AstNode visitThrowExpression(ThrowExpression node) { | |
| 1510 if (identical(_oldNode, node.expression)) { | |
| 1511 if (_isCascadeAllowedInThrow(node)) { | |
| 1512 return _parser.parseExpression2(); | |
| 1513 } | |
| 1514 return _parser.parseExpressionWithoutCascade(); | |
| 1515 } | |
| 1516 return _notAChild(node); | |
| 1517 } | |
| 1518 | |
| 1519 @override | |
| 1520 AstNode visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { | |
| 1521 if (identical(_oldNode, node.documentationComment)) { | |
| 1522 throw new InsufficientContextException(); | |
| 1523 } else if (node.metadata.contains(_oldNode)) { | |
| 1524 return _parser.parseAnnotation(); | |
| 1525 } else if (identical(_oldNode, node.variables)) { | |
| 1526 throw new InsufficientContextException(); | |
| 1527 } | |
| 1528 return _notAChild(node); | |
| 1529 } | |
| 1530 | |
| 1531 @override | |
| 1532 AstNode visitTryStatement(TryStatement node) { | |
| 1533 if (identical(_oldNode, node.body)) { | |
| 1534 return _parser.parseBlock(); | |
| 1535 } else if (node.catchClauses.contains(_oldNode)) { | |
| 1536 throw new InsufficientContextException(); | |
| 1537 } else if (identical(_oldNode, node.finallyBlock)) { | |
| 1538 throw new InsufficientContextException(); | |
| 1539 } | |
| 1540 return _notAChild(node); | |
| 1541 } | |
| 1542 | |
| 1543 @override | |
| 1544 AstNode visitTypeArgumentList(TypeArgumentList node) { | |
| 1545 if (node.arguments.contains(_oldNode)) { | |
| 1546 return _parser.parseTypeName(); | |
| 1547 } | |
| 1548 return _notAChild(node); | |
| 1549 } | |
| 1550 | |
| 1551 @override | |
| 1552 AstNode visitTypeName(TypeName node) { | |
| 1553 if (identical(_oldNode, node.name)) { | |
| 1554 return _parser.parsePrefixedIdentifier(); | |
| 1555 } else if (identical(_oldNode, node.typeArguments)) { | |
| 1556 return _parser.parseTypeArgumentList(); | |
| 1557 } | |
| 1558 return _notAChild(node); | |
| 1559 } | |
| 1560 | |
| 1561 @override | |
| 1562 AstNode visitTypeParameter(TypeParameter node) { | |
| 1563 if (identical(_oldNode, node.documentationComment)) { | |
| 1564 throw new InsufficientContextException(); | |
| 1565 } else if (node.metadata.contains(_oldNode)) { | |
| 1566 return _parser.parseAnnotation(); | |
| 1567 } else if (identical(_oldNode, node.name)) { | |
| 1568 return _parser.parseSimpleIdentifier(isDeclaration: true); | |
| 1569 } else if (identical(_oldNode, node.bound)) { | |
| 1570 return _parser.parseTypeName(); | |
| 1571 } | |
| 1572 return _notAChild(node); | |
| 1573 } | |
| 1574 | |
| 1575 @override | |
| 1576 AstNode visitTypeParameterList(TypeParameterList node) { | |
| 1577 if (node.typeParameters.contains(node)) { | |
| 1578 return _parser.parseTypeParameter(); | |
| 1579 } | |
| 1580 return _notAChild(node); | |
| 1581 } | |
| 1582 | |
| 1583 @override | |
| 1584 AstNode visitVariableDeclaration(VariableDeclaration node) { | |
| 1585 if (identical(_oldNode, node.documentationComment)) { | |
| 1586 throw new InsufficientContextException(); | |
| 1587 } else if (node.metadata.contains(_oldNode)) { | |
| 1588 return _parser.parseAnnotation(); | |
| 1589 } else if (identical(_oldNode, node.name)) { | |
| 1590 throw new InsufficientContextException(); | |
| 1591 } else if (identical(_oldNode, node.initializer)) { | |
| 1592 throw new InsufficientContextException(); | |
| 1593 } | |
| 1594 return _notAChild(node); | |
| 1595 } | |
| 1596 | |
| 1597 @override | |
| 1598 AstNode visitVariableDeclarationList(VariableDeclarationList node) { | |
| 1599 if (identical(_oldNode, node.documentationComment)) { | |
| 1600 throw new InsufficientContextException(); | |
| 1601 } else if (node.metadata.contains(_oldNode)) { | |
| 1602 return _parser.parseAnnotation(); | |
| 1603 } else if (identical(_oldNode, node.type)) { | |
| 1604 // There is not enough context to know whether we should reparse the type | |
| 1605 // using parseReturnType() (which allows 'void') or parseTypeName() | |
| 1606 // (which doesn't). Note that even though the language disallows | |
| 1607 // variables of type 'void', the parser sometimes accepts them in the | |
| 1608 // course of error recovery (e.g. "class C { void v; }" | |
| 1609 throw new InsufficientContextException(); | |
| 1610 } else if (node.variables.contains(_oldNode)) { | |
| 1611 throw new InsufficientContextException(); | |
| 1612 } | |
| 1613 return _notAChild(node); | |
| 1614 } | |
| 1615 | |
| 1616 @override | |
| 1617 AstNode visitVariableDeclarationStatement(VariableDeclarationStatement node) { | |
| 1618 if (identical(_oldNode, node.variables)) { | |
| 1619 throw new InsufficientContextException(); | |
| 1620 } | |
| 1621 return _notAChild(node); | |
| 1622 } | |
| 1623 | |
| 1624 @override | |
| 1625 AstNode visitWhileStatement(WhileStatement node) { | |
| 1626 if (identical(_oldNode, node.condition)) { | |
| 1627 return _parser.parseExpression2(); | |
| 1628 } else if (identical(_oldNode, node.body)) { | |
| 1629 return _parser.parseStatement2(); | |
| 1630 } | |
| 1631 return _notAChild(node); | |
| 1632 } | |
| 1633 | |
| 1634 @override | |
| 1635 AstNode visitWithClause(WithClause node) { | |
| 1636 if (node.mixinTypes.contains(node)) { | |
| 1637 return _parser.parseTypeName(); | |
| 1638 } | |
| 1639 return _notAChild(node); | |
| 1640 } | |
| 1641 | |
| 1642 @override | |
| 1643 AstNode visitYieldStatement(YieldStatement node) { | |
| 1644 if (identical(_oldNode, node.expression)) { | |
| 1645 return _parser.parseExpression2(); | |
| 1646 } | |
| 1647 return _notAChild(node); | |
| 1648 } | |
| 1649 | |
| 1650 /** | |
| 1651 * Return `true` if the given assignment [expression] can have a cascade | |
| 1652 * expression on the right-hand side. | |
| 1653 */ | |
| 1654 bool _isCascadeAllowedInAssignment(AssignmentExpression expression) { | |
| 1655 // TODO(brianwilkerson) Implement this method. | |
| 1656 throw new InsufficientContextException(); | |
| 1657 } | |
| 1658 | |
| 1659 /** | |
| 1660 * Return `true` if the given throw [expression] can have a cascade | |
| 1661 * expression. | |
| 1662 */ | |
| 1663 bool _isCascadeAllowedInThrow(ThrowExpression expression) { | |
| 1664 // TODO(brianwilkerson) Implement this method. | |
| 1665 throw new InsufficientContextException(); | |
| 1666 } | |
| 1667 | |
| 1668 /** | |
| 1669 * Throw an exception indicating that the visited [node] was not the parent of | |
| 1670 * the node to be replaced. | |
| 1671 */ | |
| 1672 AstNode _notAChild(AstNode node) { | |
| 1673 throw new IncrementalParseException( | |
| 1674 "Internal error: the visited node (a ${node.runtimeType}) was not the pa
rent of the node to be replaced (a ${_oldNode.runtimeType})"); | |
| 1675 } | |
| 1676 } | |
| 1677 | |
| 1678 /** | |
| 1679 * An exception that occurred while attempting to parse a replacement for a | |
| 1680 * specified node in an existing AST structure. | |
| 1681 */ | |
| 1682 @deprecated | |
| 1683 class IncrementalParseException { | |
| 1684 final String message; | |
| 1685 IncrementalParseException([this.message = '']); | |
| 1686 String toString() => '$runtimeType: $message'; | |
| 1687 } | |
| 1688 | |
| 1689 /** | |
| 1690 * An object used to re-parse a single AST structure within a larger AST | |
| 1691 * structure. | |
| 1692 */ | |
| 1693 @deprecated | |
| 1694 class IncrementalParser { | |
| 1695 /** | |
| 1696 * The source being parsed. | |
| 1697 */ | |
| 1698 final Source _source; | |
| 1699 | |
| 1700 /** | |
| 1701 * A map from old tokens to new tokens used during the cloning process. | |
| 1702 */ | |
| 1703 final TokenMap _tokenMap; | |
| 1704 | |
| 1705 /** | |
| 1706 * The error listener that will be informed of any errors that are found | |
| 1707 * during the parse. | |
| 1708 */ | |
| 1709 final AnalysisErrorListener _errorListener; | |
| 1710 | |
| 1711 /** | |
| 1712 * The node in the AST structure that contains the revised content. | |
| 1713 */ | |
| 1714 AstNode _updatedNode; | |
| 1715 | |
| 1716 /** | |
| 1717 * Initialize a newly created incremental parser to parse a portion of the | |
| 1718 * content of the given [_source]. The [_tokenMap] is a map from old tokens to | |
| 1719 * new tokens that is used during the cloning process. The [_errorListener] | |
| 1720 * will be informed of any errors that are found during the parse. | |
| 1721 */ | |
| 1722 IncrementalParser(this._source, this._tokenMap, this._errorListener); | |
| 1723 | |
| 1724 /** | |
| 1725 * Return the node in the AST structure that contains the revised content. | |
| 1726 */ | |
| 1727 AstNode get updatedNode => _updatedNode; | |
| 1728 | |
| 1729 /** | |
| 1730 * Given a range of tokens that were re-scanned, re-parse the minimum number | |
| 1731 * of tokens to produce a consistent AST structure. The range is represented | |
| 1732 * by the first and last tokens in the range. | |
| 1733 * | |
| 1734 * More specifically, the [leftToken] is the token in the new token stream | |
| 1735 * immediately to the left of the range of tokens that were inserted and the | |
| 1736 * [rightToken] is the token in the new token stream immediately to the right | |
| 1737 * of the range of tokens that were inserted. The [originalStart] and | |
| 1738 * [originalEnd] are the offsets in the original source of the first and last | |
| 1739 * characters that were modified. | |
| 1740 * | |
| 1741 * The tokens are assumed to be contained in the same token stream. | |
| 1742 */ | |
| 1743 AstNode reparse(AstNode originalStructure, Token leftToken, Token rightToken, | |
| 1744 int originalStart, int originalEnd) { | |
| 1745 AstNode oldNode = null; | |
| 1746 AstNode newNode = null; | |
| 1747 // | |
| 1748 // Find the first token that needs to be re-parsed. | |
| 1749 // | |
| 1750 Token firstToken = leftToken.next; | |
| 1751 if (identical(firstToken, rightToken)) { | |
| 1752 // If there are no new tokens, then we need to include at least one copied | |
| 1753 // node in the range. | |
| 1754 firstToken = leftToken; | |
| 1755 } | |
| 1756 // | |
| 1757 // Find the smallest AST node that encompasses the range of re-scanned | |
| 1758 // tokens. | |
| 1759 // | |
| 1760 if (originalEnd < originalStart) { | |
| 1761 oldNode = new NodeLocator(originalStart).searchWithin(originalStructure); | |
| 1762 } else { | |
| 1763 oldNode = new NodeLocator(originalStart, originalEnd) | |
| 1764 .searchWithin(originalStructure); | |
| 1765 } | |
| 1766 // | |
| 1767 // Find the token at which parsing is to begin. | |
| 1768 // | |
| 1769 int originalOffset = oldNode.offset; | |
| 1770 Token parseToken = _findTokenAt(firstToken, originalOffset); | |
| 1771 if (parseToken == null) { | |
| 1772 return null; | |
| 1773 } | |
| 1774 // | |
| 1775 // Parse the appropriate AST structure starting at the appropriate place. | |
| 1776 // | |
| 1777 Parser parser = new Parser(_source, _errorListener); | |
| 1778 parser.currentToken = parseToken; | |
| 1779 while (newNode == null) { | |
| 1780 AstNode parent = oldNode.parent; | |
| 1781 if (parent == null) { | |
| 1782 parseToken = _findFirstToken(parseToken); | |
| 1783 parser.currentToken = parseToken; | |
| 1784 return parser.parseCompilationUnit2(); | |
| 1785 } | |
| 1786 bool advanceToParent = false; | |
| 1787 try { | |
| 1788 IncrementalParseDispatcher dispatcher = | |
| 1789 new IncrementalParseDispatcher(parser, oldNode); | |
| 1790 IncrementalParseStateBuilder contextBuilder = | |
| 1791 new IncrementalParseStateBuilder(parser); | |
| 1792 contextBuilder.buildState(oldNode); | |
| 1793 newNode = parent.accept(dispatcher); | |
| 1794 // | |
| 1795 // Validate that the new node can replace the old node. | |
| 1796 // | |
| 1797 Token mappedToken = _tokenMap.get(oldNode.endToken.next); | |
| 1798 if (mappedToken == null || | |
| 1799 newNode == null || | |
| 1800 mappedToken.offset != newNode.endToken.next.offset || | |
| 1801 newNode.offset != oldNode.offset) { | |
| 1802 advanceToParent = true; | |
| 1803 } | |
| 1804 } on InsufficientContextException { | |
| 1805 advanceToParent = true; | |
| 1806 } catch (exception) { | |
| 1807 return null; | |
| 1808 } | |
| 1809 if (advanceToParent) { | |
| 1810 newNode = null; | |
| 1811 oldNode = parent; | |
| 1812 originalOffset = oldNode.offset; | |
| 1813 parseToken = _findTokenAt(parseToken, originalOffset); | |
| 1814 parser.currentToken = parseToken; | |
| 1815 } | |
| 1816 } | |
| 1817 _updatedNode = newNode; | |
| 1818 // | |
| 1819 // Replace the old node with the new node in a copy of the original AST | |
| 1820 // structure. | |
| 1821 // | |
| 1822 if (identical(oldNode, originalStructure)) { | |
| 1823 // We ended up re-parsing the whole structure, so there's no need for a | |
| 1824 // copy. | |
| 1825 ResolutionCopier.copyResolutionData(oldNode, newNode); | |
| 1826 return newNode; | |
| 1827 } | |
| 1828 ResolutionCopier.copyResolutionData(oldNode, newNode); | |
| 1829 IncrementalAstCloner cloner = | |
| 1830 new IncrementalAstCloner(oldNode, newNode, _tokenMap); | |
| 1831 return originalStructure.accept(cloner); | |
| 1832 } | |
| 1833 | |
| 1834 /** | |
| 1835 * Return the first (non-EOF) token in the token stream containing the | |
| 1836 * [firstToken]. | |
| 1837 */ | |
| 1838 Token _findFirstToken(Token firstToken) { | |
| 1839 while (firstToken.type != TokenType.EOF) { | |
| 1840 firstToken = firstToken.previous; | |
| 1841 } | |
| 1842 return firstToken.next; | |
| 1843 } | |
| 1844 | |
| 1845 /** | |
| 1846 * Find the token at or before the [firstToken] with the given [offset], or | |
| 1847 * `null` if there is no such token. | |
| 1848 */ | |
| 1849 Token _findTokenAt(Token firstToken, int offset) { | |
| 1850 while (firstToken.offset > offset && firstToken.type != TokenType.EOF) { | |
| 1851 firstToken = firstToken.previous; | |
| 1852 } | |
| 1853 return firstToken; | |
| 1854 } | |
| 1855 } | |
| 1856 | |
| 1857 /** | |
| 1858 * A visitor capable of inferring the correct parser state for incremental | |
| 1859 * parsing. This visitor visits each parent/child relationship in the chain of | |
| 1860 * ancestors of the node to be replaced (starting with the root of the parse | |
| 1861 * tree), updating the parser to the correct state for parsing the child of the | |
| 1862 * given parent. Once it has visited all of these relationships, the parser | |
| 1863 * will be in the correct state for reparsing the node to be replaced. | |
| 1864 */ | |
| 1865 @deprecated | |
| 1866 class IncrementalParseStateBuilder extends SimpleAstVisitor { | |
| 1867 // TODO(paulberry): add support for other pieces of parser state (_inAsync, | |
| 1868 // _inGenerator, _inLoop, and _inSwitch). Note that _inLoop and _inSwitch | |
| 1869 // only affect error message generation. | |
| 1870 | |
| 1871 /** | |
| 1872 * The parser whose state should be built. | |
| 1873 */ | |
| 1874 final Parser _parser; | |
| 1875 | |
| 1876 /** | |
| 1877 * The child node in the parent/child relationship currently being visited. | |
| 1878 * (The corresponding parent is the node passed to the visit...() function.) | |
| 1879 */ | |
| 1880 AstNode _childNode; | |
| 1881 | |
| 1882 /** | |
| 1883 * Create an IncrementalParseStateBuilder which will build the correct state | |
| 1884 * for [_parser]. | |
| 1885 */ | |
| 1886 IncrementalParseStateBuilder(this._parser); | |
| 1887 | |
| 1888 /** | |
| 1889 * Build the correct parser state for parsing a replacement for [node]. | |
| 1890 */ | |
| 1891 void buildState(AstNode node) { | |
| 1892 List<AstNode> ancestors = <AstNode>[]; | |
| 1893 while (node != null) { | |
| 1894 ancestors.add(node); | |
| 1895 node = node.parent; | |
| 1896 } | |
| 1897 _parser._inInitializer = false; | |
| 1898 for (int i = ancestors.length - 2; i >= 0; i--) { | |
| 1899 _childNode = ancestors[i]; | |
| 1900 ancestors[i + 1].accept(this); | |
| 1901 } | |
| 1902 } | |
| 1903 | |
| 1904 @override | |
| 1905 void visitArgumentList(ArgumentList node) { | |
| 1906 _parser._inInitializer = false; | |
| 1907 } | |
| 1908 | |
| 1909 @override | |
| 1910 void visitConstructorFieldInitializer(ConstructorFieldInitializer node) { | |
| 1911 if (identical(_childNode, node.expression)) { | |
| 1912 _parser._inInitializer = true; | |
| 1913 } | |
| 1914 } | |
| 1915 | |
| 1916 @override | |
| 1917 void visitIndexExpression(IndexExpression node) { | |
| 1918 if (identical(_childNode, node.index)) { | |
| 1919 _parser._inInitializer = false; | |
| 1920 } | |
| 1921 } | |
| 1922 | |
| 1923 @override | |
| 1924 void visitInterpolationExpression(InterpolationExpression node) { | |
| 1925 if (identical(_childNode, node.expression)) { | |
| 1926 _parser._inInitializer = false; | |
| 1927 } | |
| 1928 } | |
| 1929 | |
| 1930 @override | |
| 1931 void visitListLiteral(ListLiteral node) { | |
| 1932 if (node.elements.contains(_childNode)) { | |
| 1933 _parser._inInitializer = false; | |
| 1934 } | |
| 1935 } | |
| 1936 | |
| 1937 @override | |
| 1938 void visitMapLiteral(MapLiteral node) { | |
| 1939 if (node.entries.contains(_childNode)) { | |
| 1940 _parser._inInitializer = false; | |
| 1941 } | |
| 1942 } | |
| 1943 | |
| 1944 @override | |
| 1945 void visitParenthesizedExpression(ParenthesizedExpression node) { | |
| 1946 if (identical(_childNode, node.expression)) { | |
| 1947 _parser._inInitializer = false; | |
| 1948 } | |
| 1949 } | |
| 1950 } | |
| 1951 | |
| 1952 /** | |
| 1953 * An exception indicating that an AST node cannot be re-parsed because there is | |
| 1954 * not enough context to know how to re-parse the node. Clients can attempt to | |
| 1955 * re-parse the parent of the node. | |
| 1956 */ | |
| 1957 @deprecated | |
| 1958 class InsufficientContextException extends IncrementalParseException { | |
| 1959 InsufficientContextException([String message = '']) : super(message); | |
| 1960 } | |
| 1961 | |
| 1962 /** | |
| 1963 * Wrapper around [Function] which should be called with "target" and | 534 * Wrapper around [Function] which should be called with "target" and |
| 1964 * "arguments". | 535 * "arguments". |
| 1965 */ | 536 */ |
| 1966 class MethodTrampoline { | 537 class MethodTrampoline { |
| 1967 int parameterCount; | 538 int parameterCount; |
| 1968 Function trampoline; | 539 Function trampoline; |
| 1969 MethodTrampoline(this.parameterCount, this.trampoline); | 540 MethodTrampoline(this.parameterCount, this.trampoline); |
| 1970 Object invoke(target, List arguments) { | 541 Object invoke(target, List arguments) { |
| 1971 if (arguments.length != parameterCount) { | 542 if (arguments.length != parameterCount) { |
| 1972 throw new ArgumentError("${arguments.length} != $parameterCount"); | 543 throw new ArgumentError("${arguments.length} != $parameterCount"); |
| (...skipping 8538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10511 */ | 9082 */ |
| 10512 const ParserErrorCode(String name, String message, [String correction]) | 9083 const ParserErrorCode(String name, String message, [String correction]) |
| 10513 : super(name, message, correction); | 9084 : super(name, message, correction); |
| 10514 | 9085 |
| 10515 @override | 9086 @override |
| 10516 ErrorSeverity get errorSeverity => ErrorSeverity.ERROR; | 9087 ErrorSeverity get errorSeverity => ErrorSeverity.ERROR; |
| 10517 | 9088 |
| 10518 @override | 9089 @override |
| 10519 ErrorType get type => ErrorType.SYNTACTIC_ERROR; | 9090 ErrorType get type => ErrorType.SYNTACTIC_ERROR; |
| 10520 } | 9091 } |
| OLD | NEW |