| 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 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 } | 372 } |
| 373 push(variable); | 373 push(variable); |
| 374 scope[variable.name.name] = variable.name.staticElement = | 374 scope[variable.name.name] = variable.name.staticElement = |
| 375 new AnalyzerLocalVariableElemment(variable); | 375 new AnalyzerLocalVariableElemment(variable); |
| 376 } | 376 } |
| 377 | 377 |
| 378 void endVariablesDeclaration(int count, Token endToken) { | 378 void endVariablesDeclaration(int count, Token endToken) { |
| 379 debugEvent("VariablesDeclaration"); | 379 debugEvent("VariablesDeclaration"); |
| 380 List<VariableDeclaration> variables = popList(count); | 380 List<VariableDeclaration> variables = popList(count); |
| 381 TypeName type = pop(); | 381 TypeName type = pop(); |
| 382 pop(); // Modifiers. | 382 pop(); // TODO(paulberry): Modifiers. |
| 383 push(ast.variableDeclarationStatement( | 383 push(ast.variableDeclarationStatement( |
| 384 ast.variableDeclarationList(null, null, null, type, variables), | 384 ast.variableDeclarationList(null, null, null, type, variables), |
| 385 toAnalyzerToken(endToken))); | 385 toAnalyzerToken(endToken))); |
| 386 } | 386 } |
| 387 | 387 |
| 388 void handleAssignmentExpression(Token token) { | 388 void handleAssignmentExpression(Token token) { |
| 389 debugEvent("AssignmentExpression"); | 389 debugEvent("AssignmentExpression"); |
| 390 Expression rhs = pop(); | 390 Expression rhs = pop(); |
| 391 Expression lhs = pop(); | 391 Expression lhs = pop(); |
| 392 push(ast.assignmentExpression(lhs, toAnalyzerToken(token), rhs)); | 392 push(ast.assignmentExpression(lhs, toAnalyzerToken(token), rhs)); |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 AstNode nameOrFunctionTypedParameter = pop(); | 563 AstNode nameOrFunctionTypedParameter = pop(); |
| 564 | 564 |
| 565 FormalParameter node; | 565 FormalParameter node; |
| 566 SimpleIdentifier name; | 566 SimpleIdentifier name; |
| 567 if (nameOrFunctionTypedParameter is FormalParameter) { | 567 if (nameOrFunctionTypedParameter is FormalParameter) { |
| 568 node = nameOrFunctionTypedParameter; | 568 node = nameOrFunctionTypedParameter; |
| 569 name = nameOrFunctionTypedParameter.identifier; | 569 name = nameOrFunctionTypedParameter.identifier; |
| 570 } else { | 570 } else { |
| 571 name = nameOrFunctionTypedParameter; | 571 name = nameOrFunctionTypedParameter; |
| 572 TypeName type = pop(); | 572 TypeName type = pop(); |
| 573 Token keyword = _popOptionalSingleModifier(); | 573 _Modifiers modifiers = pop(); |
| 574 Token keyword = modifiers?.finalConstOrVarKeyword; |
| 574 pop(); // TODO(paulberry): Metadata. | 575 pop(); // TODO(paulberry): Metadata. |
| 575 if (thisKeyword == null) { | 576 if (thisKeyword == null) { |
| 576 node = ast.simpleFormalParameter2( | 577 node = ast.simpleFormalParameter2( |
| 577 covariantKeyword: toAnalyzerToken(covariantKeyword), | 578 covariantKeyword: toAnalyzerToken(covariantKeyword), |
| 578 keyword: toAnalyzerToken(keyword), | 579 keyword: toAnalyzerToken(keyword), |
| 579 type: type, | 580 type: type, |
| 580 identifier: name); | 581 identifier: name); |
| 581 } else { | 582 } else { |
| 582 // TODO(scheglov): Ideally the period token should be passed in. | 583 // TODO(scheglov): Ideally the period token should be passed in. |
| 583 Token period = identical('.', thisKeyword.next?.stringValue) | 584 Token period = identical('.', thisKeyword.next?.stringValue) |
| (...skipping 22 matching lines...) Expand all Loading... |
| 606 void endFunctionTypedFormalParameter( | 607 void endFunctionTypedFormalParameter( |
| 607 Token covariantKeyword, Token thisKeyword, FormalParameterType kind) { | 608 Token covariantKeyword, Token thisKeyword, FormalParameterType kind) { |
| 608 debugEvent("FunctionTypedFormalParameter"); | 609 debugEvent("FunctionTypedFormalParameter"); |
| 609 | 610 |
| 610 FormalParameterList formalParameters = pop(); | 611 FormalParameterList formalParameters = pop(); |
| 611 TypeParameterList typeParameters = pop(); | 612 TypeParameterList typeParameters = pop(); |
| 612 SimpleIdentifier name = pop(); | 613 SimpleIdentifier name = pop(); |
| 613 TypeName returnType = pop(); | 614 TypeName returnType = pop(); |
| 614 | 615 |
| 615 { | 616 { |
| 616 List<Token> modifiers = pop(); | 617 _Modifiers modifiers = pop(); |
| 617 if (modifiers.isNotEmpty) { | 618 if (modifiers != null) { |
| 618 // TODO(scheglov): Report error. | 619 // TODO(scheglov): Report error. |
| 619 internalError('Unexpected modifier. Report an error.'); | 620 internalError('Unexpected modifier. Report an error.'); |
| 620 } | 621 } |
| 621 } | 622 } |
| 622 | 623 |
| 623 pop(); // TODO(paulberry): Metadata. | 624 pop(); // TODO(paulberry): Metadata. |
| 624 | 625 |
| 625 FormalParameter node; | 626 FormalParameter node; |
| 626 if (thisKeyword == null) { | 627 if (thisKeyword == null) { |
| 627 node = ast.functionTypedFormalParameter2( | 628 node = ast.functionTypedFormalParameter2( |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 push(ast.postfixExpression(pop(), toAnalyzerToken(token))); | 757 push(ast.postfixExpression(pop(), toAnalyzerToken(token))); |
| 757 } | 758 } |
| 758 | 759 |
| 759 void handleModifier(Token token) { | 760 void handleModifier(Token token) { |
| 760 debugEvent("Modifier"); | 761 debugEvent("Modifier"); |
| 761 push(token); | 762 push(token); |
| 762 } | 763 } |
| 763 | 764 |
| 764 void handleModifiers(int count) { | 765 void handleModifiers(int count) { |
| 765 debugEvent("Modifiers"); | 766 debugEvent("Modifiers"); |
| 766 push(popList(count) ?? const <Token>[]); | 767 if (count == 0) { |
| 768 push(NullValue.Modifiers); |
| 769 } else { |
| 770 push(new _Modifiers(popList(count))); |
| 771 } |
| 767 } | 772 } |
| 768 | 773 |
| 769 FunctionBody _endFunctionBody() { | 774 FunctionBody _endFunctionBody() { |
| 770 AstNode body = pop(); | 775 AstNode body = pop(); |
| 771 // TODO(paulberry): asyncMarker should have a type that allows constructing | 776 // TODO(paulberry): asyncMarker should have a type that allows constructing |
| 772 // the necessary analyzer AST data structures. | 777 // the necessary analyzer AST data structures. |
| 773 AsyncMarker asyncMarker = pop(); | 778 AsyncMarker asyncMarker = pop(); |
| 774 assert(asyncMarker == AsyncMarker.Sync); | 779 assert(asyncMarker == AsyncMarker.Sync); |
| 775 analyzer.Token asyncKeyword = null; | 780 analyzer.Token asyncKeyword = null; |
| 776 analyzer.Token star = null; | 781 analyzer.Token star = null; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 789 void endTopLevelMethod(Token beginToken, Token getOrSet, Token endToken) { | 794 void endTopLevelMethod(Token beginToken, Token getOrSet, Token endToken) { |
| 790 // TODO(paulberry): set up scopes properly to resolve parameters and type | 795 // TODO(paulberry): set up scopes properly to resolve parameters and type |
| 791 // variables. | 796 // variables. |
| 792 debugEvent("TopLevelMethod"); | 797 debugEvent("TopLevelMethod"); |
| 793 FunctionBody body = _endFunctionBody(); | 798 FunctionBody body = _endFunctionBody(); |
| 794 FormalParameterList parameters = pop(); | 799 FormalParameterList parameters = pop(); |
| 795 TypeParameterList typeParameters = pop(); | 800 TypeParameterList typeParameters = pop(); |
| 796 SimpleIdentifier name = pop(); | 801 SimpleIdentifier name = pop(); |
| 797 analyzer.Token propertyKeyword = toAnalyzerToken(getOrSet); | 802 analyzer.Token propertyKeyword = toAnalyzerToken(getOrSet); |
| 798 TypeAnnotation returnType = pop(); | 803 TypeAnnotation returnType = pop(); |
| 799 Token externalKeyword = _popOptionalSingleModifier(); | 804 _Modifiers modifiers = pop(); |
| 805 Token externalKeyword = modifiers?.externalKeyword; |
| 800 List<Annotation> metadata = pop(); | 806 List<Annotation> metadata = pop(); |
| 801 // TODO(paulberry): capture doc comments. See dartbug.com/28851. | 807 // TODO(paulberry): capture doc comments. See dartbug.com/28851. |
| 802 Comment comment = null; | 808 Comment comment = null; |
| 803 push(ast.functionDeclaration( | 809 push(ast.functionDeclaration( |
| 804 comment, | 810 comment, |
| 805 metadata, | 811 metadata, |
| 806 toAnalyzerToken(externalKeyword), | 812 toAnalyzerToken(externalKeyword), |
| 807 returnType, | 813 returnType, |
| 808 propertyKeyword, | 814 propertyKeyword, |
| 809 name, | 815 name, |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 976 toAnalyzerToken(extendsKeyword), supertype.supertype); | 982 toAnalyzerToken(extendsKeyword), supertype.supertype); |
| 977 withClause = ast.withClause( | 983 withClause = ast.withClause( |
| 978 toAnalyzerToken(supertype.withKeyword), supertype.mixinTypes); | 984 toAnalyzerToken(supertype.withKeyword), supertype.mixinTypes); |
| 979 } else { | 985 } else { |
| 980 internalError('Unexpected kind of supertype ${supertype.runtimeType}'); | 986 internalError('Unexpected kind of supertype ${supertype.runtimeType}'); |
| 981 } | 987 } |
| 982 TypeParameterList typeParameters = pop(); | 988 TypeParameterList typeParameters = pop(); |
| 983 SimpleIdentifier name = pop(); | 989 SimpleIdentifier name = pop(); |
| 984 assert(className == name.name); | 990 assert(className == name.name); |
| 985 className = null; | 991 className = null; |
| 986 Token abstractKeyword = _popOptionalSingleModifier(); | 992 _Modifiers modifiers = pop(); |
| 993 Token abstractKeyword = modifiers?.abstractKeyword; |
| 987 List<Annotation> metadata = pop(); | 994 List<Annotation> metadata = pop(); |
| 988 // TODO(paulberry): capture doc comments. See dartbug.com/28851. | 995 // TODO(paulberry): capture doc comments. See dartbug.com/28851. |
| 989 Comment comment = null; | 996 Comment comment = null; |
| 990 push(ast.classDeclaration( | 997 push(ast.classDeclaration( |
| 991 comment, | 998 comment, |
| 992 metadata, | 999 metadata, |
| 993 toAnalyzerToken(abstractKeyword), | 1000 toAnalyzerToken(abstractKeyword), |
| 994 toAnalyzerToken(classKeyword), | 1001 toAnalyzerToken(classKeyword), |
| 995 name, | 1002 name, |
| 996 typeParameters, | 1003 typeParameters, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1024 ast.implementsClause(toAnalyzerToken(implementsKeyword), interfaces); | 1031 ast.implementsClause(toAnalyzerToken(implementsKeyword), interfaces); |
| 1025 } | 1032 } |
| 1026 _MixinApplication mixinApplication = pop(); | 1033 _MixinApplication mixinApplication = pop(); |
| 1027 var superclass = mixinApplication.supertype; | 1034 var superclass = mixinApplication.supertype; |
| 1028 var withClause = ast.withClause( | 1035 var withClause = ast.withClause( |
| 1029 toAnalyzerToken(mixinApplication.withKeyword), | 1036 toAnalyzerToken(mixinApplication.withKeyword), |
| 1030 mixinApplication.mixinTypes); | 1037 mixinApplication.mixinTypes); |
| 1031 analyzer.Token equals = toAnalyzerToken(equalsToken); | 1038 analyzer.Token equals = toAnalyzerToken(equalsToken); |
| 1032 TypeParameterList typeParameters = pop(); | 1039 TypeParameterList typeParameters = pop(); |
| 1033 SimpleIdentifier name = pop(); | 1040 SimpleIdentifier name = pop(); |
| 1034 Token abstractKeyword = _popOptionalSingleModifier(); | 1041 _Modifiers modifiers = pop(); |
| 1042 Token abstractKeyword = modifiers?.abstractKeyword; |
| 1035 List<Annotation> metadata = pop(); | 1043 List<Annotation> metadata = pop(); |
| 1036 // TODO(paulberry): capture doc comments. See dartbug.com/28851. | 1044 // TODO(paulberry): capture doc comments. See dartbug.com/28851. |
| 1037 Comment comment = null; | 1045 Comment comment = null; |
| 1038 push(ast.classTypeAlias( | 1046 push(ast.classTypeAlias( |
| 1039 comment, | 1047 comment, |
| 1040 metadata, | 1048 metadata, |
| 1041 toAnalyzerToken(classKeyword), | 1049 toAnalyzerToken(classKeyword), |
| 1042 name, | 1050 name, |
| 1043 typeParameters, | 1051 typeParameters, |
| 1044 equals, | 1052 equals, |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1130 Expression initializer = pop(); | 1138 Expression initializer = pop(); |
| 1131 SimpleIdentifier name = pop(); | 1139 SimpleIdentifier name = pop(); |
| 1132 push(ast.variableDeclaration( | 1140 push(ast.variableDeclaration( |
| 1133 name, toAnalyzerToken(assignment), initializer)); | 1141 name, toAnalyzerToken(assignment), initializer)); |
| 1134 } | 1142 } |
| 1135 | 1143 |
| 1136 void endTopLevelFields(int count, Token beginToken, Token endToken) { | 1144 void endTopLevelFields(int count, Token beginToken, Token endToken) { |
| 1137 debugEvent("TopLevelFields"); | 1145 debugEvent("TopLevelFields"); |
| 1138 List<VariableDeclaration> variables = popList(count); | 1146 List<VariableDeclaration> variables = popList(count); |
| 1139 TypeAnnotation type = pop(); | 1147 TypeAnnotation type = pop(); |
| 1140 Token keyword = _popOptionalSingleModifier(); | 1148 _Modifiers modifiers = pop(); |
| 1149 Token keyword = modifiers?.finalConstOrVarKeyword; |
| 1141 var variableList = ast.variableDeclarationList( | 1150 var variableList = ast.variableDeclarationList( |
| 1142 null, null, toAnalyzerToken(keyword), type, variables); | 1151 null, null, toAnalyzerToken(keyword), type, variables); |
| 1143 List<Annotation> metadata = pop(); | 1152 List<Annotation> metadata = pop(); |
| 1144 // TODO(paulberry): capture doc comments. See dartbug.com/28851. | 1153 // TODO(paulberry): capture doc comments. See dartbug.com/28851. |
| 1145 Comment comment = null; | 1154 Comment comment = null; |
| 1146 push(ast.topLevelVariableDeclaration( | 1155 push(ast.topLevelVariableDeclaration( |
| 1147 comment, metadata, variableList, toAnalyzerToken(endToken))); | 1156 comment, metadata, variableList, toAnalyzerToken(endToken))); |
| 1148 } | 1157 } |
| 1149 | 1158 |
| 1150 @override | 1159 @override |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1175 void endMethod(Token getOrSet, Token beginToken, Token endToken) { | 1184 void endMethod(Token getOrSet, Token beginToken, Token endToken) { |
| 1176 debugEvent("Method"); | 1185 debugEvent("Method"); |
| 1177 FunctionBody body = _endFunctionBody(); | 1186 FunctionBody body = _endFunctionBody(); |
| 1178 ConstructorName redirectedConstructor = null; // TODO(paulberry) | 1187 ConstructorName redirectedConstructor = null; // TODO(paulberry) |
| 1179 List<ConstructorInitializer> initializers = null; // TODO(paulberry) | 1188 List<ConstructorInitializer> initializers = null; // TODO(paulberry) |
| 1180 Token separator = null; // TODO(paulberry) | 1189 Token separator = null; // TODO(paulberry) |
| 1181 FormalParameterList parameters = pop(); | 1190 FormalParameterList parameters = pop(); |
| 1182 TypeParameterList typeParameters = pop(); // TODO(paulberry) | 1191 TypeParameterList typeParameters = pop(); // TODO(paulberry) |
| 1183 var name = pop(); | 1192 var name = pop(); |
| 1184 TypeAnnotation returnType = pop(); // TODO(paulberry) | 1193 TypeAnnotation returnType = pop(); // TODO(paulberry) |
| 1185 Token modifierKeyword = null; // TODO(paulberry) | 1194 _Modifiers modifiers = pop(); |
| 1186 Token externalKeyword = null; | |
| 1187 Token constKeyword = null; | |
| 1188 Token factoryKeyword = null; | |
| 1189 List<Token> modifiers = pop(); | |
| 1190 for (Token modifier in modifiers) { | |
| 1191 String value = modifier.stringValue; | |
| 1192 if (identical('external', value)) { | |
| 1193 // TODO(scheglov): Check the order and uniqueness. | |
| 1194 externalKeyword = modifier; | |
| 1195 } else if (identical('const', value)) { | |
| 1196 // TODO(scheglov): Check the order and uniqueness. | |
| 1197 constKeyword = modifier; | |
| 1198 } else if (identical('factory', value)) { | |
| 1199 // TODO(scheglov): Check the order and uniqueness. | |
| 1200 factoryKeyword = modifier; | |
| 1201 } else { | |
| 1202 // TODO(scheglov): Report error. | |
| 1203 internalError("Invalid modifier ($value). Report an error."); | |
| 1204 } | |
| 1205 } | |
| 1206 | |
| 1207 List<Annotation> metadata = pop(); | 1195 List<Annotation> metadata = pop(); |
| 1208 // TODO(paulberry): capture doc comments. See dartbug.com/28851. | 1196 // TODO(paulberry): capture doc comments. See dartbug.com/28851. |
| 1209 Comment comment = null; | 1197 Comment comment = null; |
| 1210 Token period; | 1198 Token period; |
| 1211 void unnamedConstructor( | 1199 void unnamedConstructor( |
| 1212 SimpleIdentifier returnType, SimpleIdentifier name) { | 1200 SimpleIdentifier returnType, SimpleIdentifier name) { |
| 1213 push(ast.constructorDeclaration( | 1201 push(ast.constructorDeclaration( |
| 1214 comment, | 1202 comment, |
| 1215 metadata, | 1203 metadata, |
| 1216 toAnalyzerToken(externalKeyword), | 1204 toAnalyzerToken(modifiers?.externalKeyword), |
| 1217 toAnalyzerToken(constKeyword), | 1205 toAnalyzerToken(modifiers?.finalConstOrVarKeyword), |
| 1218 toAnalyzerToken(factoryKeyword), | 1206 null, // TODO(paulberry): factoryKeyword |
| 1219 returnType, | 1207 returnType, |
| 1220 toAnalyzerToken(period), | 1208 toAnalyzerToken(period), |
| 1221 name, | 1209 name, |
| 1222 parameters, | 1210 parameters, |
| 1223 toAnalyzerToken(separator), | 1211 toAnalyzerToken(separator), |
| 1224 initializers, | 1212 initializers, |
| 1225 redirectedConstructor, | 1213 redirectedConstructor, |
| 1226 body)); | 1214 body)); |
| 1227 } | 1215 } |
| 1228 | 1216 |
| 1229 void method(Token operatorKeyword, SimpleIdentifier name) { | 1217 void method(Token operatorKeyword, SimpleIdentifier name) { |
| 1230 push(ast.methodDeclaration( | 1218 push(ast.methodDeclaration( |
| 1231 comment, | 1219 comment, |
| 1232 metadata, | 1220 metadata, |
| 1233 toAnalyzerToken(externalKeyword), | 1221 toAnalyzerToken(modifiers?.externalKeyword), |
| 1234 toAnalyzerToken(modifierKeyword), | 1222 toAnalyzerToken( |
| 1223 modifiers?.abstractKeyword ?? modifiers?.staticKeyword), |
| 1235 returnType, | 1224 returnType, |
| 1236 toAnalyzerToken(getOrSet), | 1225 toAnalyzerToken(getOrSet), |
| 1237 toAnalyzerToken(operatorKeyword), | 1226 toAnalyzerToken(operatorKeyword), |
| 1238 name, | 1227 name, |
| 1239 typeParameters, | 1228 typeParameters, |
| 1240 parameters, | 1229 parameters, |
| 1241 body)); | 1230 body)); |
| 1242 } | 1231 } |
| 1243 | 1232 |
| 1244 if (name is SimpleIdentifier) { | 1233 if (name is SimpleIdentifier) { |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1344 push(ast.typeArgumentList( | 1333 push(ast.typeArgumentList( |
| 1345 toAnalyzerToken(beginToken), arguments, toAnalyzerToken(endToken))); | 1334 toAnalyzerToken(beginToken), arguments, toAnalyzerToken(endToken))); |
| 1346 } | 1335 } |
| 1347 | 1336 |
| 1348 @override | 1337 @override |
| 1349 void endFields( | 1338 void endFields( |
| 1350 int count, Token covariantKeyword, Token beginToken, Token endToken) { | 1339 int count, Token covariantKeyword, Token beginToken, Token endToken) { |
| 1351 debugEvent("Fields"); | 1340 debugEvent("Fields"); |
| 1352 List<VariableDeclaration> variables = popList(count); | 1341 List<VariableDeclaration> variables = popList(count); |
| 1353 TypeAnnotation type = pop(); | 1342 TypeAnnotation type = pop(); |
| 1354 List<Token> modifiers = pop(); | 1343 _Modifiers modifiers = pop(); |
| 1355 Token staticKeyword; | 1344 var variableList = ast.variableDeclarationList(null, null, |
| 1356 Token keyword; | 1345 toAnalyzerToken(modifiers?.finalConstOrVarKeyword), type, variables); |
| 1357 for (Token modifier in modifiers) { | |
| 1358 String value = modifier.stringValue; | |
| 1359 if (identical('static', value)) { | |
| 1360 // TODO(paulberry): Check the order and uniqueness. | |
| 1361 staticKeyword = modifier; | |
| 1362 } else if (identical('var', value)) { | |
| 1363 // TODO(paulberry): Check the order and uniqueness. | |
| 1364 keyword = modifier; | |
| 1365 } else { | |
| 1366 // TODO(paulberry): Report error. | |
| 1367 internalError("Invalid modifier ($value). Report an error."); | |
| 1368 } | |
| 1369 } | |
| 1370 var variableList = ast.variableDeclarationList( | |
| 1371 null, null, toAnalyzerToken(keyword), type, variables); | |
| 1372 List<Annotation> metadata = pop(); | 1346 List<Annotation> metadata = pop(); |
| 1373 // TODO(paulberry): capture doc comments. See dartbug.com/28851. | 1347 // TODO(paulberry): capture doc comments. See dartbug.com/28851. |
| 1374 Comment comment = null; | 1348 Comment comment = null; |
| 1375 push(ast.fieldDeclaration2( | 1349 push(ast.fieldDeclaration2( |
| 1376 comment: comment, | 1350 comment: comment, |
| 1377 metadata: metadata, | 1351 metadata: metadata, |
| 1378 covariantKeyword: toAnalyzerToken(covariantKeyword), | 1352 covariantKeyword: toAnalyzerToken(covariantKeyword), |
| 1379 staticKeyword: toAnalyzerToken(staticKeyword), | 1353 staticKeyword: toAnalyzerToken(modifiers?.staticKeyword), |
| 1380 fieldList: variableList, | 1354 fieldList: variableList, |
| 1381 semicolon: toAnalyzerToken(endToken))); | 1355 semicolon: toAnalyzerToken(endToken))); |
| 1382 } | 1356 } |
| 1383 | 1357 |
| 1384 @override | 1358 @override |
| 1385 void handleOperatorName(Token operatorKeyword, Token token) { | 1359 void handleOperatorName(Token operatorKeyword, Token token) { |
| 1386 debugEvent("OperatorName"); | 1360 debugEvent("OperatorName"); |
| 1387 push(new _OperatorName(operatorKeyword, | 1361 push(new _OperatorName(operatorKeyword, |
| 1388 ast.simpleIdentifier(toAnalyzerToken(token), isDeclaration: true))); | 1362 ast.simpleIdentifier(toAnalyzerToken(token), isDeclaration: true))); |
| 1389 } | 1363 } |
| 1390 | 1364 |
| 1391 /** | |
| 1392 * Pop the modifiers list, if the list is empty return `null`, if the list | |
| 1393 * has one item return it; otherwise return `null`. | |
| 1394 */ | |
| 1395 Token _popOptionalSingleModifier() { | |
| 1396 List<Token> modifiers = pop(); | |
| 1397 if (modifiers.length == 0) { | |
| 1398 return null; | |
| 1399 } else if (modifiers.length == 1) { | |
| 1400 // TODO(scheglov): Verify that the modifier is valid. | |
| 1401 return modifiers[0]; | |
| 1402 } else { | |
| 1403 // TODO(scheglov): Report error. | |
| 1404 internalError("Invalid modifier. Report an error."); | |
| 1405 return null; | |
| 1406 } | |
| 1407 } | |
| 1408 | |
| 1409 ParameterKind _toAnalyzerParameterKind(FormalParameterType type) { | 1365 ParameterKind _toAnalyzerParameterKind(FormalParameterType type) { |
| 1410 if (type == FormalParameterType.POSITIONAL) { | 1366 if (type == FormalParameterType.POSITIONAL) { |
| 1411 return ParameterKind.POSITIONAL; | 1367 return ParameterKind.POSITIONAL; |
| 1412 } else if (type == FormalParameterType.NAMED) { | 1368 } else if (type == FormalParameterType.NAMED) { |
| 1413 return ParameterKind.NAMED; | 1369 return ParameterKind.NAMED; |
| 1414 } else { | 1370 } else { |
| 1415 return ParameterKind.REQUIRED; | 1371 return ParameterKind.REQUIRED; |
| 1416 } | 1372 } |
| 1417 } | 1373 } |
| 1418 } | 1374 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1468 } | 1424 } |
| 1469 | 1425 |
| 1470 /// Data structure placed on the stack to represent the keyword "operator" | 1426 /// Data structure placed on the stack to represent the keyword "operator" |
| 1471 /// followed by a token. | 1427 /// followed by a token. |
| 1472 class _OperatorName { | 1428 class _OperatorName { |
| 1473 final Token operatorKeyword; | 1429 final Token operatorKeyword; |
| 1474 final SimpleIdentifier name; | 1430 final SimpleIdentifier name; |
| 1475 | 1431 |
| 1476 _OperatorName(this.operatorKeyword, this.name); | 1432 _OperatorName(this.operatorKeyword, this.name); |
| 1477 } | 1433 } |
| 1434 |
| 1435 /// Data structure placed on the stack to represent a non-empty sequence |
| 1436 /// of modifiers. |
| 1437 class _Modifiers { |
| 1438 Token abstractKeyword; |
| 1439 Token externalKeyword; |
| 1440 Token finalConstOrVarKeyword; |
| 1441 Token staticKeyword; |
| 1442 |
| 1443 _Modifiers(List<Token> modifierTokens) { |
| 1444 // No need to check the order and uniqueness of the modifiers, or that |
| 1445 // disallowed modifiers are not used; the parser should do that. |
| 1446 // TODO(paulberry,ahe): implement the necessary logic in the parser. |
| 1447 for (var token in modifierTokens) { |
| 1448 var s = token.value; |
| 1449 if (identical('abstract', s)) { |
| 1450 abstractKeyword = token; |
| 1451 } else if (identical('const', s)) { |
| 1452 finalConstOrVarKeyword = token; |
| 1453 } else if (identical('external', s)) { |
| 1454 externalKeyword = token; |
| 1455 } else if (identical('final', s)) { |
| 1456 finalConstOrVarKeyword = token; |
| 1457 } else if (identical('static', s)) { |
| 1458 staticKeyword = token; |
| 1459 } else if (identical('var', s)) { |
| 1460 finalConstOrVarKeyword = token; |
| 1461 } else { |
| 1462 internalError('Unhandled modifier: $s'); |
| 1463 } |
| 1464 } |
| 1465 } |
| 1466 } |
| OLD | NEW |