Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 fasta.analyzer.ast_builder; | 5 library fasta.analyzer.ast_builder; |
| 6 | 6 |
| 7 import 'package:front_end/src/fasta/scanner/token.dart' | 7 import 'package:front_end/src/fasta/scanner/token.dart' |
| 8 show BeginGroupToken, Token; | 8 show BeginGroupToken, Token; |
| 9 | 9 |
| 10 import 'package:analyzer/analyzer.dart'; | 10 import 'package:analyzer/analyzer.dart'; |
| (...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 722 List<SimpleIdentifier> shownNames = pop(); | 722 List<SimpleIdentifier> shownNames = pop(); |
| 723 push(ast.showCombinator(toAnalyzerToken(showKeyword), shownNames)); | 723 push(ast.showCombinator(toAnalyzerToken(showKeyword), shownNames)); |
| 724 } | 724 } |
| 725 | 725 |
| 726 @override | 726 @override |
| 727 void endHide(Token hideKeyword) { | 727 void endHide(Token hideKeyword) { |
| 728 debugEvent("Hide"); | 728 debugEvent("Hide"); |
| 729 List<SimpleIdentifier> hiddenNames = pop(); | 729 List<SimpleIdentifier> hiddenNames = pop(); |
| 730 push(ast.hideCombinator(toAnalyzerToken(hideKeyword), hiddenNames)); | 730 push(ast.hideCombinator(toAnalyzerToken(hideKeyword), hiddenNames)); |
| 731 } | 731 } |
| 732 | |
| 733 @override | |
| 734 void endTypeList(int count) { | |
| 735 debugEvent("TypeList"); | |
| 736 push(popList(count) ?? NullValue.TypeList); | |
| 737 } | |
| 738 | |
| 739 @override | |
| 740 void endClassBody(int memberCount, Token beginToken, Token endToken) { | |
| 741 debugEvent("ClassBody"); | |
| 742 push(new _ClassBody( | |
| 743 beginToken, popList(memberCount) ?? <ClassMember>[], endToken)); | |
| 744 } | |
| 745 | |
| 746 @override | |
| 747 void endClassDeclaration(int interfacesCount, Token beginToken, | |
| 748 Token extendsKeyword, Token implementsKeyword, Token endToken) { | |
| 749 debugEvent("ClassDeclaration"); | |
| 750 _ClassBody body = pop(); | |
| 751 ImplementsClause implementsClause; | |
| 752 if (implementsKeyword != null) { | |
| 753 List<TypeName> interfaces = popList(interfacesCount); | |
| 754 implementsClause = | |
| 755 ast.implementsClause(toAnalyzerToken(implementsKeyword), interfaces); | |
| 756 } | |
| 757 ExtendsClause extendsClause; | |
| 758 WithClause withClause; | |
| 759 var supertype = pop(); | |
| 760 if (supertype == null) { | |
| 761 // No extends clause | |
| 762 } else if (supertype is TypeName) { | |
| 763 extendsClause = | |
| 764 ast.extendsClause(toAnalyzerToken(extendsKeyword), supertype); | |
| 765 } else if (supertype is _MixinApplication) { | |
| 766 extendsClause = ast.extendsClause( | |
| 767 toAnalyzerToken(extendsKeyword), supertype.supertype); | |
| 768 withClause = ast.withClause( | |
| 769 toAnalyzerToken(supertype.withKeyword), supertype.mixinTypes); | |
| 770 } else { | |
| 771 internalError('Unexpected kind of supertype ${supertype.runtimeType}'); | |
| 772 } | |
| 773 TypeParameterList typeParameters = pop(); | |
| 774 SimpleIdentifier name = pop(); | |
| 775 Token classKeyword; | |
| 776 // TODO(paulberry,ahe): This is a hack. The parser should give us the class | |
| 777 // keyword. | |
|
ahe
2017/02/20 13:04:39
No problem. If you file bugs with lack of token in
Paul Berry
2017/02/20 14:25:10
Ok. I'm still planning to go through all my CLs c
| |
| 778 if (identical(beginToken.value, 'abstract')) { | |
|
ahe
2017/02/20 13:04:39
I suggest using optional like this:
if (optional(
Paul Berry
2017/02/20 14:25:10
Acknowledged.
| |
| 779 classKeyword = beginToken.next; | |
| 780 } else { | |
| 781 classKeyword = beginToken; | |
| 782 } | |
| 783 var modifiers = pop(); | |
| 784 assert(modifiers == null); // TODO(paulberry) | |
| 785 analyzer.Token abstractKeyword; | |
| 786 List<Annotation> metadata = pop(); | |
| 787 Comment comment = null; // TODO(paulberry) | |
| 788 push(ast.classDeclaration( | |
| 789 comment, | |
| 790 metadata, | |
| 791 abstractKeyword, | |
| 792 toAnalyzerToken(classKeyword), | |
| 793 name, | |
| 794 typeParameters, | |
| 795 extendsClause, | |
| 796 withClause, | |
| 797 implementsClause, | |
| 798 toAnalyzerToken(body.beginToken), | |
| 799 body.members, | |
| 800 toAnalyzerToken(body.endToken))); | |
| 801 } | |
| 802 | |
| 803 @override | |
| 804 void endMixinApplication() { | |
| 805 debugEvent("MixinApplication"); | |
| 806 List<TypeName> mixinTypes = pop(); | |
| 807 // TODO(paulberry,ahe): the parser doesn't give us enough information to | |
| 808 // locate the "with" keyword. | |
| 809 Token withKeyword; | |
| 810 TypeName supertype = pop(); | |
| 811 push(new _MixinApplication(supertype, withKeyword, mixinTypes)); | |
| 812 } | |
| 813 | |
| 814 @override | |
| 815 void endNamedMixinApplication( | |
| 816 Token beginToken, Token implementsKeyword, Token endToken) { | |
| 817 debugEvent("NamedMixinApplication"); | |
| 818 ImplementsClause implementsClause; | |
| 819 if (implementsKeyword != null) { | |
| 820 List<TypeName> interfaces = pop(); | |
| 821 implementsClause = | |
| 822 ast.implementsClause(toAnalyzerToken(implementsKeyword), interfaces); | |
| 823 } | |
| 824 _MixinApplication mixinApplication = pop(); | |
| 825 var superclass = mixinApplication.supertype; | |
| 826 var withClause = ast.withClause( | |
| 827 toAnalyzerToken(mixinApplication.withKeyword), | |
| 828 mixinApplication.mixinTypes); | |
| 829 // TODO(paulberry,ahe): the parser should give us the "=" token. | |
| 830 analyzer.Token equals; | |
| 831 TypeParameterList typeParameters = pop(); | |
| 832 SimpleIdentifier name = pop(); | |
| 833 Token classKeyword; | |
| 834 // TODO(paulberry,ahe): This is a hack. The parser should give us the class | |
| 835 // keyword. | |
|
ahe
2017/02/20 13:04:39
I agree with all these comments about the parser g
| |
| 836 if (identical(beginToken.value, 'abstract')) { | |
| 837 classKeyword = beginToken.next; | |
| 838 } else { | |
| 839 classKeyword = beginToken; | |
| 840 } | |
| 841 var modifiers = pop(); | |
| 842 assert(modifiers == null); // TODO(paulberry) | |
| 843 analyzer.Token abstractKeyword; | |
| 844 List<Annotation> metadata = pop(); | |
| 845 Comment comment = null; // TODO(paulberry) | |
| 846 push(ast.classTypeAlias( | |
| 847 comment, | |
| 848 metadata, | |
| 849 toAnalyzerToken(classKeyword), | |
| 850 name, | |
| 851 typeParameters, | |
| 852 equals, | |
| 853 abstractKeyword, | |
| 854 superclass, | |
| 855 withClause, | |
| 856 implementsClause, | |
| 857 toAnalyzerToken(endToken))); | |
| 858 } | |
| 732 } | 859 } |
| 860 | |
| 861 /// Data structure placed on the stack to represent a class body. | |
| 862 /// | |
| 863 /// This is needed because analyzer has no separate AST representation of a | |
| 864 /// class body; it simply stores all of the relevant data in the | |
| 865 /// [ClassDeclaration] object. | |
|
ahe
2017/02/20 13:04:39
An alternative implementation is to simply push mo
Paul Berry
2017/02/20 14:25:10
Acknowledged. I think I prefer using the temporar
| |
| 866 class _ClassBody { | |
| 867 final Token beginToken; | |
| 868 | |
| 869 final List<ClassMember> members; | |
| 870 | |
| 871 final Token endToken; | |
| 872 | |
| 873 _ClassBody(this.beginToken, this.members, this.endToken); | |
| 874 } | |
| 875 | |
| 876 /// Data structure placed on the stack to represent a mixin application (a | |
| 877 /// structure of the form "A with B, C"). | |
| 878 /// | |
| 879 /// This is needed because analyzer has no separate AST representation of a | |
| 880 /// mixin application; it simply stores all of the relevant data in the | |
| 881 /// [ClassDeclaration] or [ClassTypeAlias] object. | |
| 882 class _MixinApplication { | |
| 883 final TypeName supertype; | |
| 884 | |
| 885 final Token withKeyword; | |
| 886 | |
| 887 final List<TypeName> mixinTypes; | |
| 888 | |
| 889 _MixinApplication(this.supertype, this.withKeyword, this.mixinTypes); | |
| 890 } | |
| OLD | NEW |