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 1107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1118 } | 1118 } |
1119 | 1119 |
1120 @override | 1120 @override |
1121 void endMethod(Token getOrSet, Token beginToken, Token endToken) { | 1121 void endMethod(Token getOrSet, Token beginToken, Token endToken) { |
1122 debugEvent("Method"); | 1122 debugEvent("Method"); |
1123 FunctionBody body = _endFunctionBody(); | 1123 FunctionBody body = _endFunctionBody(); |
1124 ConstructorName redirectedConstructor = null; // TODO(paulberry) | 1124 ConstructorName redirectedConstructor = null; // TODO(paulberry) |
1125 List<ConstructorInitializer> initializers = null; // TODO(paulberry) | 1125 List<ConstructorInitializer> initializers = null; // TODO(paulberry) |
1126 Token separator = null; // TODO(paulberry) | 1126 Token separator = null; // TODO(paulberry) |
1127 FormalParameterList parameters = pop(); | 1127 FormalParameterList parameters = pop(); |
1128 /* TypeParameterList typeParameters = */ pop(); // TODO(paulberry) | 1128 TypeParameterList typeParameters = pop(); // TODO(paulberry) |
1129 var name = pop(); | 1129 var name = pop(); |
1130 // TODO(paulberry) | 1130 Token operatorKeyword = null; // TODO(paulberry) |
1131 // analyzer.Token propertyKeyword = toAnalyzerToken(getOrSet); | 1131 TypeAnnotation returnType = pop(); // TODO(paulberry) |
1132 /* TypeAnnotation returnType = */ pop(); // TODO(paulberry) | 1132 Token modifierKeyword = null; // TODO(paulberry) |
1133 | |
1134 Token externalKeyword = null; | 1133 Token externalKeyword = null; |
1135 Token constKeyword = null; | 1134 Token constKeyword = null; |
1136 Token factoryKeyword = null; | 1135 Token factoryKeyword = null; |
1137 List<Token> modifiers = pop(); | 1136 List<Token> modifiers = pop(); |
1138 for (Token modifier in modifiers) { | 1137 for (Token modifier in modifiers) { |
1139 String value = modifier.stringValue; | 1138 String value = modifier.stringValue; |
1140 if (identical('external', value)) { | 1139 if (identical('external', value)) { |
1141 // TODO(scheglov): Check the order and uniqueness. | 1140 // TODO(scheglov): Check the order and uniqueness. |
1142 externalKeyword = modifier; | 1141 externalKeyword = modifier; |
1143 } else if (identical('const', value)) { | 1142 } else if (identical('const', value)) { |
1144 // TODO(scheglov): Check the order and uniqueness. | 1143 // TODO(scheglov): Check the order and uniqueness. |
1145 constKeyword = modifier; | 1144 constKeyword = modifier; |
1146 } else if (identical('factory', value)) { | 1145 } else if (identical('factory', value)) { |
1147 // TODO(scheglov): Check the order and uniqueness. | 1146 // TODO(scheglov): Check the order and uniqueness. |
1148 factoryKeyword = modifier; | 1147 factoryKeyword = modifier; |
1149 } else { | 1148 } else { |
1150 // TODO(scheglov): Report error. | 1149 // TODO(scheglov): Report error. |
1151 internalError("Invalid modifier ($value). Report an error."); | 1150 internalError("Invalid modifier ($value). Report an error."); |
1152 } | 1151 } |
1153 } | 1152 } |
1154 | 1153 |
1155 List<Annotation> metadata = pop(); | 1154 List<Annotation> metadata = pop(); |
1156 // TODO(paulberry): capture doc comments. See dartbug.com/28851. | 1155 // TODO(paulberry): capture doc comments. See dartbug.com/28851. |
1157 Comment comment = null; | 1156 Comment comment = null; |
1158 SimpleIdentifier returnType2; | 1157 SimpleIdentifier returnType2; |
1159 Token period; | 1158 Token period; |
1160 SimpleIdentifier name2; | 1159 SimpleIdentifier name2; |
| 1160 void unnamedConstructor() { |
| 1161 push(ast.constructorDeclaration( |
| 1162 comment, |
| 1163 metadata, |
| 1164 toAnalyzerToken(externalKeyword), |
| 1165 toAnalyzerToken(constKeyword), |
| 1166 toAnalyzerToken(factoryKeyword), |
| 1167 returnType2, |
| 1168 toAnalyzerToken(period), |
| 1169 name2, |
| 1170 parameters, |
| 1171 toAnalyzerToken(separator), |
| 1172 initializers, |
| 1173 redirectedConstructor, |
| 1174 body)); |
| 1175 } |
| 1176 |
| 1177 void method() { |
| 1178 push(ast.methodDeclaration( |
| 1179 comment, |
| 1180 metadata, |
| 1181 toAnalyzerToken(externalKeyword), |
| 1182 toAnalyzerToken(modifierKeyword), |
| 1183 returnType, |
| 1184 toAnalyzerToken(getOrSet), |
| 1185 toAnalyzerToken(operatorKeyword), |
| 1186 name, |
| 1187 typeParameters, |
| 1188 parameters, |
| 1189 body)); |
| 1190 } |
| 1191 |
1161 if (name is SimpleIdentifier) { | 1192 if (name is SimpleIdentifier) { |
1162 returnType2 = name; | 1193 returnType2 = name; |
| 1194 if (name.name == className) { |
| 1195 unnamedConstructor(); |
| 1196 } else { |
| 1197 method(); |
| 1198 } |
| 1199 } else { |
| 1200 throw new UnimplementedError(); |
1163 } | 1201 } |
1164 push(ast.constructorDeclaration( | |
1165 comment, | |
1166 metadata, | |
1167 toAnalyzerToken(externalKeyword), | |
1168 toAnalyzerToken(constKeyword), | |
1169 toAnalyzerToken(factoryKeyword), | |
1170 returnType2, | |
1171 toAnalyzerToken(period), | |
1172 name2, | |
1173 parameters, | |
1174 toAnalyzerToken(separator), | |
1175 initializers, | |
1176 redirectedConstructor, | |
1177 body)); | |
1178 } | 1202 } |
1179 | 1203 |
1180 @override | 1204 @override |
1181 void endMember() { | 1205 void endMember() { |
1182 debugEvent("Member"); | 1206 debugEvent("Member"); |
1183 } | 1207 } |
1184 | 1208 |
1185 @override | 1209 @override |
1186 void handleVoidKeyword(Token token) { | 1210 void handleVoidKeyword(Token token) { |
1187 debugEvent("VoidKeyword"); | 1211 debugEvent("VoidKeyword"); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1339 | 1363 |
1340 /// Data structure placed on the stack as a container for optional parameters. | 1364 /// Data structure placed on the stack as a container for optional parameters. |
1341 class _OptionalFormalParameters { | 1365 class _OptionalFormalParameters { |
1342 final List<FormalParameter> parameters; | 1366 final List<FormalParameter> parameters; |
1343 final Token leftDelimiter; | 1367 final Token leftDelimiter; |
1344 final Token rightDelimiter; | 1368 final Token rightDelimiter; |
1345 | 1369 |
1346 _OptionalFormalParameters( | 1370 _OptionalFormalParameters( |
1347 this.parameters, this.leftDelimiter, this.rightDelimiter); | 1371 this.parameters, this.leftDelimiter, this.rightDelimiter); |
1348 } | 1372 } |
OLD | NEW |