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 1129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1140 @override | 1140 @override |
1141 void endMethod(Token getOrSet, Token beginToken, Token endToken) { | 1141 void endMethod(Token getOrSet, Token beginToken, Token endToken) { |
1142 debugEvent("Method"); | 1142 debugEvent("Method"); |
1143 FunctionBody body = _endFunctionBody(); | 1143 FunctionBody body = _endFunctionBody(); |
1144 ConstructorName redirectedConstructor = null; // TODO(paulberry) | 1144 ConstructorName redirectedConstructor = null; // TODO(paulberry) |
1145 List<ConstructorInitializer> initializers = null; // TODO(paulberry) | 1145 List<ConstructorInitializer> initializers = null; // TODO(paulberry) |
1146 Token separator = null; // TODO(paulberry) | 1146 Token separator = null; // TODO(paulberry) |
1147 FormalParameterList parameters = pop(); | 1147 FormalParameterList parameters = pop(); |
1148 TypeParameterList typeParameters = pop(); // TODO(paulberry) | 1148 TypeParameterList typeParameters = pop(); // TODO(paulberry) |
1149 var name = pop(); | 1149 var name = pop(); |
1150 Token operatorKeyword = null; // TODO(paulberry) | |
1151 TypeAnnotation returnType = pop(); // TODO(paulberry) | 1150 TypeAnnotation returnType = pop(); // TODO(paulberry) |
1152 Token modifierKeyword = null; // TODO(paulberry) | 1151 Token modifierKeyword = null; // TODO(paulberry) |
1153 Token externalKeyword = null; | 1152 Token externalKeyword = null; |
1154 Token constKeyword = null; | 1153 Token constKeyword = null; |
1155 Token factoryKeyword = null; | 1154 Token factoryKeyword = null; |
1156 List<Token> modifiers = pop(); | 1155 List<Token> modifiers = pop(); |
1157 for (Token modifier in modifiers) { | 1156 for (Token modifier in modifiers) { |
1158 String value = modifier.stringValue; | 1157 String value = modifier.stringValue; |
1159 if (identical('external', value)) { | 1158 if (identical('external', value)) { |
1160 // TODO(scheglov): Check the order and uniqueness. | 1159 // TODO(scheglov): Check the order and uniqueness. |
1161 externalKeyword = modifier; | 1160 externalKeyword = modifier; |
1162 } else if (identical('const', value)) { | 1161 } else if (identical('const', value)) { |
1163 // TODO(scheglov): Check the order and uniqueness. | 1162 // TODO(scheglov): Check the order and uniqueness. |
1164 constKeyword = modifier; | 1163 constKeyword = modifier; |
1165 } else if (identical('factory', value)) { | 1164 } else if (identical('factory', value)) { |
1166 // TODO(scheglov): Check the order and uniqueness. | 1165 // TODO(scheglov): Check the order and uniqueness. |
1167 factoryKeyword = modifier; | 1166 factoryKeyword = modifier; |
1168 } else { | 1167 } else { |
1169 // TODO(scheglov): Report error. | 1168 // TODO(scheglov): Report error. |
1170 internalError("Invalid modifier ($value). Report an error."); | 1169 internalError("Invalid modifier ($value). Report an error."); |
1171 } | 1170 } |
1172 } | 1171 } |
1173 | 1172 |
1174 List<Annotation> metadata = pop(); | 1173 List<Annotation> metadata = pop(); |
1175 // TODO(paulberry): capture doc comments. See dartbug.com/28851. | 1174 // TODO(paulberry): capture doc comments. See dartbug.com/28851. |
1176 Comment comment = null; | 1175 Comment comment = null; |
1177 SimpleIdentifier returnType2; | |
1178 Token period; | 1176 Token period; |
1179 SimpleIdentifier name2; | 1177 void unnamedConstructor(SimpleIdentifier returnType, SimpleIdentifier name)
{ |
1180 void unnamedConstructor() { | |
1181 push(ast.constructorDeclaration( | 1178 push(ast.constructorDeclaration( |
1182 comment, | 1179 comment, |
1183 metadata, | 1180 metadata, |
1184 toAnalyzerToken(externalKeyword), | 1181 toAnalyzerToken(externalKeyword), |
1185 toAnalyzerToken(constKeyword), | 1182 toAnalyzerToken(constKeyword), |
1186 toAnalyzerToken(factoryKeyword), | 1183 toAnalyzerToken(factoryKeyword), |
1187 returnType2, | 1184 returnType, |
1188 toAnalyzerToken(period), | 1185 toAnalyzerToken(period), |
1189 name2, | 1186 name, |
1190 parameters, | 1187 parameters, |
1191 toAnalyzerToken(separator), | 1188 toAnalyzerToken(separator), |
1192 initializers, | 1189 initializers, |
1193 redirectedConstructor, | 1190 redirectedConstructor, |
1194 body)); | 1191 body)); |
1195 } | 1192 } |
1196 | 1193 |
1197 void method() { | 1194 void method(Token operatorKeyword, SimpleIdentifier name) { |
1198 push(ast.methodDeclaration( | 1195 push(ast.methodDeclaration( |
1199 comment, | 1196 comment, |
1200 metadata, | 1197 metadata, |
1201 toAnalyzerToken(externalKeyword), | 1198 toAnalyzerToken(externalKeyword), |
1202 toAnalyzerToken(modifierKeyword), | 1199 toAnalyzerToken(modifierKeyword), |
1203 returnType, | 1200 returnType, |
1204 toAnalyzerToken(getOrSet), | 1201 toAnalyzerToken(getOrSet), |
1205 toAnalyzerToken(operatorKeyword), | 1202 toAnalyzerToken(operatorKeyword), |
1206 name, | 1203 name, |
1207 typeParameters, | 1204 typeParameters, |
1208 parameters, | 1205 parameters, |
1209 body)); | 1206 body)); |
1210 } | 1207 } |
1211 | 1208 |
1212 if (name is SimpleIdentifier) { | 1209 if (name is SimpleIdentifier) { |
1213 returnType2 = name; | |
1214 if (name.name == className) { | 1210 if (name.name == className) { |
1215 unnamedConstructor(); | 1211 unnamedConstructor(name, null); |
1216 } else { | 1212 } else { |
1217 method(); | 1213 method(null, name); |
1218 } | 1214 } |
| 1215 } else if (name is _OperatorName) { |
| 1216 method(name.operatorKeyword, name.name); |
1219 } else { | 1217 } else { |
1220 throw new UnimplementedError(); | 1218 throw new UnimplementedError(); |
1221 } | 1219 } |
1222 } | 1220 } |
1223 | 1221 |
1224 @override | 1222 @override |
1225 void endMember() { | 1223 void endMember() { |
1226 debugEvent("Member"); | 1224 debugEvent("Member"); |
1227 } | 1225 } |
1228 | 1226 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1305 } | 1303 } |
1306 | 1304 |
1307 @override | 1305 @override |
1308 void endTypeArguments(int count, Token beginToken, Token endToken) { | 1306 void endTypeArguments(int count, Token beginToken, Token endToken) { |
1309 debugEvent("TypeArguments"); | 1307 debugEvent("TypeArguments"); |
1310 List<TypeAnnotation> arguments = popList(count); | 1308 List<TypeAnnotation> arguments = popList(count); |
1311 push(ast.typeArgumentList( | 1309 push(ast.typeArgumentList( |
1312 toAnalyzerToken(beginToken), arguments, toAnalyzerToken(endToken))); | 1310 toAnalyzerToken(beginToken), arguments, toAnalyzerToken(endToken))); |
1313 } | 1311 } |
1314 | 1312 |
| 1313 @override |
| 1314 void handleOperatorName(Token operatorKeyword, Token token) { |
| 1315 debugEvent("OperatorName"); |
| 1316 push(new _OperatorName(operatorKeyword, |
| 1317 ast.simpleIdentifier(toAnalyzerToken(token), isDeclaration: true))); |
| 1318 } |
| 1319 |
1315 /** | 1320 /** |
1316 * Pop the modifiers list, if the list is empty return `null`, if the list | 1321 * Pop the modifiers list, if the list is empty return `null`, if the list |
1317 * has one item return it; otherwise return `null`. | 1322 * has one item return it; otherwise return `null`. |
1318 */ | 1323 */ |
1319 Token _popOptionalSingleModifier() { | 1324 Token _popOptionalSingleModifier() { |
1320 List<Token> modifiers = pop(); | 1325 List<Token> modifiers = pop(); |
1321 if (modifiers.length == 0) { | 1326 if (modifiers.length == 0) { |
1322 return null; | 1327 return null; |
1323 } else if (modifiers.length == 1) { | 1328 } else if (modifiers.length == 1) { |
1324 // TODO(scheglov): Verify that the modifier is valid. | 1329 // TODO(scheglov): Verify that the modifier is valid. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1383 | 1388 |
1384 /// Data structure placed on the stack as a container for optional parameters. | 1389 /// Data structure placed on the stack as a container for optional parameters. |
1385 class _OptionalFormalParameters { | 1390 class _OptionalFormalParameters { |
1386 final List<FormalParameter> parameters; | 1391 final List<FormalParameter> parameters; |
1387 final Token leftDelimiter; | 1392 final Token leftDelimiter; |
1388 final Token rightDelimiter; | 1393 final Token rightDelimiter; |
1389 | 1394 |
1390 _OptionalFormalParameters( | 1395 _OptionalFormalParameters( |
1391 this.parameters, this.leftDelimiter, this.rightDelimiter); | 1396 this.parameters, this.leftDelimiter, this.rightDelimiter); |
1392 } | 1397 } |
| 1398 |
| 1399 /// Data structure placed on the stack to represent the keyword "operator" |
| 1400 /// followed by a token. |
| 1401 class _OperatorName { |
| 1402 final Token operatorKeyword; |
| 1403 final SimpleIdentifier name; |
| 1404 |
| 1405 _OperatorName(this.operatorKeyword, this.name); |
| 1406 } |
OLD | NEW |