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:analyzer/analyzer.dart'; | 7 import 'package:analyzer/analyzer.dart'; |
8 import 'package:analyzer/dart/ast/ast_factory.dart' show AstFactory; | 8 import 'package:analyzer/dart/ast/ast_factory.dart' show AstFactory; |
9 import 'package:analyzer/dart/ast/standard_ast_factory.dart' as standard; | 9 import 'package:analyzer/dart/ast/standard_ast_factory.dart' as standard; |
10 import 'package:analyzer/dart/ast/token.dart' as analyzer show Token; | 10 import 'package:analyzer/dart/ast/token.dart' as analyzer show Token; |
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
432 void endLiteralSymbol(Token hashToken, int identifierCount) { | 432 void endLiteralSymbol(Token hashToken, int identifierCount) { |
433 debugEvent("LiteralSymbol"); | 433 debugEvent("LiteralSymbol"); |
434 List<analyzer.Token> components = new List<analyzer.Token>(identifierCount); | 434 List<analyzer.Token> components = new List<analyzer.Token>(identifierCount); |
435 for (int i = identifierCount - 1; i >= 0; i--) { | 435 for (int i = identifierCount - 1; i >= 0; i--) { |
436 SimpleIdentifier identifier = pop(); | 436 SimpleIdentifier identifier = pop(); |
437 components[i] = identifier.token; | 437 components[i] = identifier.token; |
438 } | 438 } |
439 push(ast.symbolLiteral(toAnalyzerToken(hashToken), components)); | 439 push(ast.symbolLiteral(toAnalyzerToken(hashToken), components)); |
440 } | 440 } |
441 | 441 |
442 void endType(Token beginToken, Token endToken) { | 442 void handleType(Token beginToken, Token endToken) { |
443 debugEvent("Type"); | 443 debugEvent("Type"); |
444 TypeArgumentList arguments = pop(); | 444 TypeArgumentList arguments = pop(); |
445 Identifier name = pop(); | 445 Identifier name = pop(); |
446 // TODO(paulberry,ahe): what if the type doesn't resolve to a class | 446 // TODO(paulberry,ahe): what if the type doesn't resolve to a class |
447 // element? | 447 // element? |
448 KernelClassElement cls = name.staticElement; | 448 KernelClassElement cls = name.staticElement; |
449 if (cls == null) { | 449 if (cls == null) { |
450 // TODO(paulberry): This is a kludge. Ideally we should already have | 450 // TODO(paulberry): This is a kludge. Ideally we should already have |
451 // set the static element at the time that handleIdentifier was called. | 451 // set the static element at the time that handleIdentifier was called. |
452 Builder builder = scope.lookup(name.name, beginToken.charOffset, uri); | 452 Builder builder = scope.lookup(name.name, beginToken.charOffset, uri); |
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1090 debugEvent("Member"); | 1090 debugEvent("Member"); |
1091 } | 1091 } |
1092 | 1092 |
1093 @override | 1093 @override |
1094 void handleVoidKeyword(Token token) { | 1094 void handleVoidKeyword(Token token) { |
1095 debugEvent("VoidKeyword"); | 1095 debugEvent("VoidKeyword"); |
1096 // TODO(paulberry): is this sufficient, or do we need to hook the "void" | 1096 // TODO(paulberry): is this sufficient, or do we need to hook the "void" |
1097 // keyword up to an element? | 1097 // keyword up to an element? |
1098 handleIdentifier(token); | 1098 handleIdentifier(token); |
1099 handleNoTypeArguments(token); | 1099 handleNoTypeArguments(token); |
1100 endType(token, token); | 1100 handleType(token, token); |
1101 } | 1101 } |
1102 | 1102 |
1103 @override | 1103 @override |
1104 void endFunctionTypeAlias(Token typedefKeyword, Token endToken) { | 1104 void endFunctionTypeAlias( |
1105 Token typedefKeyword, Token equals, Token endToken) { | |
1105 debugEvent("FunctionTypeAlias"); | 1106 debugEvent("FunctionTypeAlias"); |
1106 FormalParameterList parameters = pop(); | 1107 if (equals == null) { |
1107 TypeParameterList typeParameters = pop(); | 1108 FormalParameterList parameters = pop(); |
1108 SimpleIdentifier name = pop(); | 1109 TypeParameterList typeParameters = pop(); |
1109 TypeAnnotation returnType = pop(); | 1110 SimpleIdentifier name = pop(); |
1110 List<Annotation> metadata = pop(); | 1111 TypeAnnotation returnType = pop(); |
1111 // TODO(paulberry): capture doc comments. See dartbug.com/28851. | 1112 List<Annotation> metadata = pop(); |
1112 Comment comment = null; | 1113 // TODO(paulberry): capture doc comments. See dartbug.com/28851. |
1113 push(ast.functionTypeAlias( | 1114 Comment comment = null; |
1114 comment, | 1115 push(ast.functionTypeAlias( |
1115 metadata, | 1116 comment, |
1116 toAnalyzerToken(typedefKeyword), | 1117 metadata, |
1117 returnType, | 1118 toAnalyzerToken(typedefKeyword), |
1118 name, | 1119 returnType, |
1119 typeParameters, | 1120 name, |
1120 parameters, | 1121 typeParameters, |
1121 toAnalyzerToken(endToken))); | 1122 parameters, |
1123 toAnalyzerToken(endToken))); | |
1124 } else { | |
1125 TypeAnnotation type = pop(); | |
1126 TypeParameterList templateParameters = pop(); | |
1127 SimpleIdentifier name = pop(); | |
1128 List<Annotation> metadata = pop(); | |
1129 // TODO(paulberry): capture doc comments. See dartbug.com/28851. | |
1130 Comment comment = null; | |
1131 if (type is! GenericFunctionType) { | |
1132 // TODO(brianwilkerson) Generate an error and recover (better than | |
Paul Berry
2017/02/22 19:28:36
Feel free to assign this TODO to me.
floitsch
2017/02/23 12:15:19
Done.
| |
1133 // this). | |
1134 type = null; | |
1135 } | |
1136 push(ast.genericTypeAlias( | |
1137 comment, | |
1138 metadata, | |
1139 toAnalyzerToken(typedefKeyword), | |
1140 name, | |
1141 templateParameters, | |
1142 toAnalyzerToken(equals), | |
1143 type, | |
1144 toAnalyzerToken(endToken))); | |
1145 } | |
1122 } | 1146 } |
1123 | 1147 |
1124 /** | 1148 /** |
1125 * Pop the modifiers list, if the list is empty return `null`, if the list | 1149 * Pop the modifiers list, if the list is empty return `null`, if the list |
1126 * has one item return it; otherwise return `null`. | 1150 * has one item return it; otherwise return `null`. |
1127 */ | 1151 */ |
1128 Token _popOptionalSingleModifier() { | 1152 Token _popOptionalSingleModifier() { |
1129 List<Token> modifiers = pop(); | 1153 List<Token> modifiers = pop(); |
1130 if (modifiers.length == 0) { | 1154 if (modifiers.length == 0) { |
1131 return null; | 1155 return null; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1163 /// [ClassDeclaration] or [ClassTypeAlias] object. | 1187 /// [ClassDeclaration] or [ClassTypeAlias] object. |
1164 class _MixinApplication { | 1188 class _MixinApplication { |
1165 final TypeName supertype; | 1189 final TypeName supertype; |
1166 | 1190 |
1167 final Token withKeyword; | 1191 final Token withKeyword; |
1168 | 1192 |
1169 final List<TypeName> mixinTypes; | 1193 final List<TypeName> mixinTypes; |
1170 | 1194 |
1171 _MixinApplication(this.supertype, this.withKeyword, this.mixinTypes); | 1195 _MixinApplication(this.supertype, this.withKeyword, this.mixinTypes); |
1172 } | 1196 } |
OLD | NEW |