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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 46 final AstFactory ast = standard.astFactory; | 46 final AstFactory ast = standard.astFactory; |
| 47 | 47 |
| 48 final KernelLibraryBuilder library; | 48 final KernelLibraryBuilder library; |
| 49 | 49 |
| 50 final Builder member; | 50 final Builder member; |
| 51 | 51 |
| 52 final ElementStore elementStore; | 52 final ElementStore elementStore; |
| 53 | 53 |
| 54 bool isFirstIdentifier = false; | 54 bool isFirstIdentifier = false; |
| 55 | 55 |
| 56 /// If `true`, the first call to [handleIdentifier] should push a | |
| 57 /// List<SimpleIdentifier> on the stack, and [handleQualified] should append | |
| 58 /// to the list. | |
| 59 var accumulateIdentifierComponents = false; | |
|
ahe
2017/02/20 09:59:40
Should we change the parser so it can tell you how
Paul Berry
2017/02/20 14:48:31
I don't know. In general I like the "handleQualif
| |
| 60 | |
| 56 AstBuilder(this.library, this.member, this.elementStore, Scope scope) | 61 AstBuilder(this.library, this.member, this.elementStore, Scope scope) |
| 57 : super(scope); | 62 : super(scope); |
| 58 | 63 |
| 59 Uri get uri => library.fileUri ?? library.uri; | 64 Uri get uri => library.fileUri ?? library.uri; |
| 60 | 65 |
| 61 createJumpTarget(JumpTargetKind kind, int charOffset) { | 66 createJumpTarget(JumpTargetKind kind, int charOffset) { |
| 62 // TODO(ahe): Implement jump targets. | 67 // TODO(ahe): Implement jump targets. |
| 63 return null; | 68 return null; |
| 64 } | 69 } |
| 65 | 70 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 } | 128 } |
| 124 | 129 |
| 125 void beginExpression(Token token) { | 130 void beginExpression(Token token) { |
| 126 isFirstIdentifier = true; | 131 isFirstIdentifier = true; |
| 127 } | 132 } |
| 128 | 133 |
| 129 void handleIdentifier(Token token) { | 134 void handleIdentifier(Token token) { |
| 130 debugEvent("handleIdentifier"); | 135 debugEvent("handleIdentifier"); |
| 131 String name = token.value; | 136 String name = token.value; |
| 132 SimpleIdentifier identifier = ast.simpleIdentifier(toAnalyzerToken(token)); | 137 SimpleIdentifier identifier = ast.simpleIdentifier(toAnalyzerToken(token)); |
| 133 if (isFirstIdentifier) { | 138 if (accumulateIdentifierComponents) { |
| 134 Builder builder = scope.lookup(name, token.charOffset, uri); | 139 if (isFirstIdentifier) { |
| 135 if (builder != null) { | 140 push([identifier]); |
| 136 Element element = elementStore[builder]; | 141 } else { |
| 137 assert(element != null); | 142 push(identifier); |
| 138 identifier.staticElement = element; | |
| 139 } | 143 } |
| 144 } else { | |
| 145 if (isFirstIdentifier) { | |
| 146 Builder builder = scope.lookup(name, token.charOffset, uri); | |
| 147 if (builder != null) { | |
| 148 Element element = elementStore[builder]; | |
| 149 assert(element != null); | |
| 150 identifier.staticElement = element; | |
| 151 } | |
| 152 } | |
| 153 push(identifier); | |
| 140 } | 154 } |
| 141 push(identifier); | |
| 142 isFirstIdentifier = false; | 155 isFirstIdentifier = false; |
| 143 } | 156 } |
| 144 | 157 |
| 145 void endSend(Token token) { | 158 void endSend(Token token) { |
| 146 debugEvent("Send"); | 159 debugEvent("Send"); |
| 147 MethodInvocation arguments = pop(); | 160 MethodInvocation arguments = pop(); |
| 148 TypeArgumentList typeArguments = pop(); | 161 TypeArgumentList typeArguments = pop(); |
| 149 if (arguments != null) { | 162 if (arguments != null) { |
| 150 if (typeArguments != null) { | 163 if (typeArguments != null) { |
| 151 arguments.typeArguments = typeArguments; | 164 arguments.typeArguments = typeArguments; |
| (...skipping 697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 849 toAnalyzerToken(classKeyword), | 862 toAnalyzerToken(classKeyword), |
| 850 name, | 863 name, |
| 851 typeParameters, | 864 typeParameters, |
| 852 equals, | 865 equals, |
| 853 abstractKeyword, | 866 abstractKeyword, |
| 854 superclass, | 867 superclass, |
| 855 withClause, | 868 withClause, |
| 856 implementsClause, | 869 implementsClause, |
| 857 toAnalyzerToken(endToken))); | 870 toAnalyzerToken(endToken))); |
| 858 } | 871 } |
| 872 | |
| 873 @override | |
| 874 void beginLibraryName(Token token) { | |
| 875 accumulateIdentifierComponents = true; | |
| 876 isFirstIdentifier = true; | |
| 877 } | |
| 878 | |
| 879 @override | |
| 880 void endLibraryName(Token libraryKeyword, Token semicolon) { | |
| 881 debugEvent("LibraryName"); | |
| 882 List<SimpleIdentifier> libraryName = pop(); | |
| 883 var name = ast.libraryIdentifier(libraryName); | |
| 884 List<Annotation> metadata = pop(); | |
| 885 Comment comment = null; // TODO(paulberry) | |
| 886 push(ast.libraryDirective(comment, metadata, | |
| 887 toAnalyzerToken(libraryKeyword), name, toAnalyzerToken(semicolon))); | |
| 888 accumulateIdentifierComponents = false; | |
| 889 } | |
| 890 | |
| 891 @override | |
| 892 void handleQualified(Token period) { | |
| 893 if (accumulateIdentifierComponents) { | |
| 894 SimpleIdentifier identifier = pop(); | |
| 895 List<SimpleIdentifier> list = pop(); | |
| 896 list.add(identifier); | |
| 897 push(list); | |
| 898 } else { | |
| 899 // TODO(paulberry): implement. | |
| 900 logEvent('Qualified'); | |
| 901 } | |
| 902 } | |
| 903 | |
| 904 @override | |
| 905 void endPart(Token partKeyword, Token semicolon) { | |
| 906 debugEvent("Part"); | |
| 907 StringLiteral uri = pop(); | |
| 908 List<Annotation> metadata = pop(); | |
| 909 Comment comment = null; // TODO(paulberry) | |
| 910 push(ast.partDirective(comment, metadata, toAnalyzerToken(partKeyword), uri, | |
| 911 toAnalyzerToken(semicolon))); | |
| 912 } | |
| 913 | |
| 914 @override | |
| 915 void beginPartOf(Token token) { | |
| 916 accumulateIdentifierComponents = true; | |
| 917 isFirstIdentifier = true; | |
| 918 } | |
| 919 | |
| 920 @override | |
| 921 void endPartOf(Token partKeyword, Token semicolon) { | |
| 922 debugEvent("PartOf"); | |
| 923 List<SimpleIdentifier> libraryName = pop(); | |
| 924 var name = ast.libraryIdentifier(libraryName); | |
| 925 StringLiteral uri = null; // TODO(paulberry) | |
| 926 // TODO(paulberry,ahe): seems hacky. It would be nice if the parser passed | |
| 927 // in a reference to the "of" keyword. | |
|
ahe
2017/02/20 09:59:40
We can do so, just file a bug.
Paul Berry
2017/02/20 14:48:32
Acknowledged.
| |
| 928 var ofKeyword = partKeyword.next; | |
| 929 List<Annotation> metadata = pop(); | |
| 930 Comment comment = null; // TODO(paulberry) | |
| 931 push(ast.partOfDirective(comment, metadata, toAnalyzerToken(partKeyword), | |
| 932 toAnalyzerToken(ofKeyword), uri, name, toAnalyzerToken(semicolon))); | |
| 933 accumulateIdentifierComponents = false; | |
| 934 } | |
| 859 } | 935 } |
| 860 | 936 |
| 861 /// Data structure placed on the stack to represent a class body. | 937 /// Data structure placed on the stack to represent a class body. |
| 862 /// | 938 /// |
| 863 /// This is needed because analyzer has no separate AST representation of a | 939 /// 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 | 940 /// class body; it simply stores all of the relevant data in the |
| 865 /// [ClassDeclaration] object. | 941 /// [ClassDeclaration] object. |
| 866 class _ClassBody { | 942 class _ClassBody { |
| 867 final Token beginToken; | 943 final Token beginToken; |
| 868 | 944 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 881 /// [ClassDeclaration] or [ClassTypeAlias] object. | 957 /// [ClassDeclaration] or [ClassTypeAlias] object. |
| 882 class _MixinApplication { | 958 class _MixinApplication { |
| 883 final TypeName supertype; | 959 final TypeName supertype; |
| 884 | 960 |
| 885 final Token withKeyword; | 961 final Token withKeyword; |
| 886 | 962 |
| 887 final List<TypeName> mixinTypes; | 963 final List<TypeName> mixinTypes; |
| 888 | 964 |
| 889 _MixinApplication(this.supertype, this.withKeyword, this.mixinTypes); | 965 _MixinApplication(this.supertype, this.withKeyword, this.mixinTypes); |
| 890 } | 966 } |
| OLD | NEW |