Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: pkg/analyzer/lib/src/generated/parser.dart

Issue 1833573006: Distinguish SimpleIdentifier uses and declarations at parse time. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Brace body. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/analyzer/lib/src/dart/ast/utilities.dart ('k') | pkg/analyzer/test/dart/ast/ast_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 analyzer.src.generated.parser; 5 library analyzer.src.generated.parser;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import "dart:math" as math; 8 import "dart:math" as math;
9 9
10 import 'package:analyzer/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
(...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 throw new InsufficientContextException(); 671 throw new InsufficientContextException();
672 } 672 }
673 return _notAChild(node); 673 return _notAChild(node);
674 } 674 }
675 675
676 @override 676 @override
677 AstNode visitCatchClause(CatchClause node) { 677 AstNode visitCatchClause(CatchClause node) {
678 if (identical(_oldNode, node.exceptionType)) { 678 if (identical(_oldNode, node.exceptionType)) {
679 return _parser.parseTypeName(); 679 return _parser.parseTypeName();
680 } else if (identical(_oldNode, node.exceptionParameter)) { 680 } else if (identical(_oldNode, node.exceptionParameter)) {
681 return _parser.parseSimpleIdentifier(); 681 return _parser.parseSimpleIdentifier(isDeclaration: true);
682 } else if (identical(_oldNode, node.stackTraceParameter)) { 682 } else if (identical(_oldNode, node.stackTraceParameter)) {
683 return _parser.parseSimpleIdentifier(); 683 return _parser.parseSimpleIdentifier(isDeclaration: true);
684 } else if (identical(_oldNode, node.body)) { 684 } else if (identical(_oldNode, node.body)) {
685 return _parser.parseBlock(); 685 return _parser.parseBlock();
686 } 686 }
687 return _notAChild(node); 687 return _notAChild(node);
688 } 688 }
689 689
690 @override 690 @override
691 AstNode visitClassDeclaration(ClassDeclaration node) { 691 AstNode visitClassDeclaration(ClassDeclaration node) {
692 if (identical(_oldNode, node.documentationComment)) { 692 if (identical(_oldNode, node.documentationComment)) {
693 throw new InsufficientContextException(); 693 throw new InsufficientContextException();
(...skipping 21 matching lines...) Expand all
715 return _notAChild(node); 715 return _notAChild(node);
716 } 716 }
717 717
718 @override 718 @override
719 AstNode visitClassTypeAlias(ClassTypeAlias node) { 719 AstNode visitClassTypeAlias(ClassTypeAlias node) {
720 if (identical(_oldNode, node.documentationComment)) { 720 if (identical(_oldNode, node.documentationComment)) {
721 throw new InsufficientContextException(); 721 throw new InsufficientContextException();
722 } else if (node.metadata.contains(_oldNode)) { 722 } else if (node.metadata.contains(_oldNode)) {
723 return _parser.parseAnnotation(); 723 return _parser.parseAnnotation();
724 } else if (identical(_oldNode, node.name)) { 724 } else if (identical(_oldNode, node.name)) {
725 return _parser.parseSimpleIdentifier(); 725 return _parser.parseSimpleIdentifier(isDeclaration: true);
726 } else if (identical(_oldNode, node.typeParameters)) { 726 } else if (identical(_oldNode, node.typeParameters)) {
727 return _parser.parseTypeParameterList(); 727 return _parser.parseTypeParameterList();
728 } else if (identical(_oldNode, node.superclass)) { 728 } else if (identical(_oldNode, node.superclass)) {
729 return _parser.parseTypeName(); 729 return _parser.parseTypeName();
730 } else if (identical(_oldNode, node.withClause)) { 730 } else if (identical(_oldNode, node.withClause)) {
731 return _parser.parseWithClause(); 731 return _parser.parseWithClause();
732 } else if (identical(_oldNode, node.implementsClause)) { 732 } else if (identical(_oldNode, node.implementsClause)) {
733 return _parser.parseImplementsClause(); 733 return _parser.parseImplementsClause();
734 } 734 }
735 return _notAChild(node); 735 return _notAChild(node);
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 @override 878 @override
879 AstNode visitEmptyStatement(EmptyStatement node) => _notAChild(node); 879 AstNode visitEmptyStatement(EmptyStatement node) => _notAChild(node);
880 880
881 @override 881 @override
882 AstNode visitEnumConstantDeclaration(EnumConstantDeclaration node) { 882 AstNode visitEnumConstantDeclaration(EnumConstantDeclaration node) {
883 if (identical(_oldNode, node.documentationComment)) { 883 if (identical(_oldNode, node.documentationComment)) {
884 throw new InsufficientContextException(); 884 throw new InsufficientContextException();
885 } else if (node.metadata.contains(_oldNode)) { 885 } else if (node.metadata.contains(_oldNode)) {
886 return _parser.parseAnnotation(); 886 return _parser.parseAnnotation();
887 } else if (identical(_oldNode, node.name)) { 887 } else if (identical(_oldNode, node.name)) {
888 return _parser.parseSimpleIdentifier(); 888 return _parser.parseSimpleIdentifier(isDeclaration: true);
889 } 889 }
890 return _notAChild(node); 890 return _notAChild(node);
891 } 891 }
892 892
893 @override 893 @override
894 AstNode visitEnumDeclaration(EnumDeclaration node) { 894 AstNode visitEnumDeclaration(EnumDeclaration node) {
895 if (identical(_oldNode, node.documentationComment)) { 895 if (identical(_oldNode, node.documentationComment)) {
896 throw new InsufficientContextException(); 896 throw new InsufficientContextException();
897 } else if (node.metadata.contains(_oldNode)) { 897 } else if (node.metadata.contains(_oldNode)) {
898 return _parser.parseAnnotation(); 898 return _parser.parseAnnotation();
899 } else if (identical(_oldNode, node.name)) { 899 } else if (identical(_oldNode, node.name)) {
900 return _parser.parseSimpleIdentifier(); 900 return _parser.parseSimpleIdentifier(isDeclaration: true);
901 } else if (node.constants.contains(_oldNode)) { 901 } else if (node.constants.contains(_oldNode)) {
902 throw new InsufficientContextException(); 902 throw new InsufficientContextException();
903 } 903 }
904 return _notAChild(node); 904 return _notAChild(node);
905 } 905 }
906 906
907 @override 907 @override
908 AstNode visitExportDirective(ExportDirective node) { 908 AstNode visitExportDirective(ExportDirective node) {
909 if (identical(_oldNode, node.documentationComment)) { 909 if (identical(_oldNode, node.documentationComment)) {
910 throw new InsufficientContextException(); 910 throw new InsufficientContextException();
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
970 } 970 }
971 return _notAChild(node); 971 return _notAChild(node);
972 } 972 }
973 973
974 @override 974 @override
975 AstNode visitForEachStatement(ForEachStatement node) { 975 AstNode visitForEachStatement(ForEachStatement node) {
976 if (identical(_oldNode, node.loopVariable)) { 976 if (identical(_oldNode, node.loopVariable)) {
977 throw new InsufficientContextException(); 977 throw new InsufficientContextException();
978 //return parser.parseDeclaredIdentifier(); 978 //return parser.parseDeclaredIdentifier();
979 } else if (identical(_oldNode, node.identifier)) { 979 } else if (identical(_oldNode, node.identifier)) {
980 return _parser.parseSimpleIdentifier(); 980 return _parser.parseSimpleIdentifier(isDeclaration: true);
981 } else if (identical(_oldNode, node.body)) { 981 } else if (identical(_oldNode, node.body)) {
982 return _parser.parseStatement2(); 982 return _parser.parseStatement2();
983 } 983 }
984 return _notAChild(node); 984 return _notAChild(node);
985 } 985 }
986 986
987 @override 987 @override
988 AstNode visitFormalParameterList(FormalParameterList node) { 988 AstNode visitFormalParameterList(FormalParameterList node) {
989 // We don't know which kind of parameter to parse. 989 // We don't know which kind of parameter to parse.
990 throw new InsufficientContextException(); 990 throw new InsufficientContextException();
(...skipping 17 matching lines...) Expand all
1008 1008
1009 @override 1009 @override
1010 AstNode visitFunctionDeclaration(FunctionDeclaration node) { 1010 AstNode visitFunctionDeclaration(FunctionDeclaration node) {
1011 if (identical(_oldNode, node.documentationComment)) { 1011 if (identical(_oldNode, node.documentationComment)) {
1012 throw new InsufficientContextException(); 1012 throw new InsufficientContextException();
1013 } else if (node.metadata.contains(_oldNode)) { 1013 } else if (node.metadata.contains(_oldNode)) {
1014 return _parser.parseAnnotation(); 1014 return _parser.parseAnnotation();
1015 } else if (identical(_oldNode, node.returnType)) { 1015 } else if (identical(_oldNode, node.returnType)) {
1016 return _parser.parseReturnType(); 1016 return _parser.parseReturnType();
1017 } else if (identical(_oldNode, node.name)) { 1017 } else if (identical(_oldNode, node.name)) {
1018 return _parser.parseSimpleIdentifier(); 1018 return _parser.parseSimpleIdentifier(isDeclaration: true);
1019 } else if (identical(_oldNode, node.functionExpression)) { 1019 } else if (identical(_oldNode, node.functionExpression)) {
1020 throw new InsufficientContextException(); 1020 throw new InsufficientContextException();
1021 } 1021 }
1022 return _notAChild(node); 1022 return _notAChild(node);
1023 } 1023 }
1024 1024
1025 @override 1025 @override
1026 AstNode visitFunctionDeclarationStatement(FunctionDeclarationStatement node) { 1026 AstNode visitFunctionDeclarationStatement(FunctionDeclarationStatement node) {
1027 if (identical(_oldNode, node.functionDeclaration)) { 1027 if (identical(_oldNode, node.functionDeclaration)) {
1028 throw new InsufficientContextException(); 1028 throw new InsufficientContextException();
(...skipping 23 matching lines...) Expand all
1052 1052
1053 @override 1053 @override
1054 AstNode visitFunctionTypeAlias(FunctionTypeAlias node) { 1054 AstNode visitFunctionTypeAlias(FunctionTypeAlias node) {
1055 if (identical(_oldNode, node.documentationComment)) { 1055 if (identical(_oldNode, node.documentationComment)) {
1056 throw new InsufficientContextException(); 1056 throw new InsufficientContextException();
1057 } else if (node.metadata.contains(_oldNode)) { 1057 } else if (node.metadata.contains(_oldNode)) {
1058 return _parser.parseAnnotation(); 1058 return _parser.parseAnnotation();
1059 } else if (identical(_oldNode, node.returnType)) { 1059 } else if (identical(_oldNode, node.returnType)) {
1060 return _parser.parseReturnType(); 1060 return _parser.parseReturnType();
1061 } else if (identical(_oldNode, node.name)) { 1061 } else if (identical(_oldNode, node.name)) {
1062 return _parser.parseSimpleIdentifier(); 1062 return _parser.parseSimpleIdentifier(isDeclaration: true);
1063 } else if (identical(_oldNode, node.typeParameters)) { 1063 } else if (identical(_oldNode, node.typeParameters)) {
1064 return _parser.parseTypeParameterList(); 1064 return _parser.parseTypeParameterList();
1065 } else if (identical(_oldNode, node.parameters)) { 1065 } else if (identical(_oldNode, node.parameters)) {
1066 return _parser.parseFormalParameterList(); 1066 return _parser.parseFormalParameterList();
1067 } 1067 }
1068 return _notAChild(node); 1068 return _notAChild(node);
1069 } 1069 }
1070 1070
1071 @override 1071 @override
1072 AstNode visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { 1072 AstNode visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
1073 if (identical(_oldNode, node.documentationComment)) { 1073 if (identical(_oldNode, node.documentationComment)) {
1074 throw new InsufficientContextException(); 1074 throw new InsufficientContextException();
1075 } else if (node.metadata.contains(_oldNode)) { 1075 } else if (node.metadata.contains(_oldNode)) {
1076 return _parser.parseAnnotation(); 1076 return _parser.parseAnnotation();
1077 } else if (identical(_oldNode, node.returnType)) { 1077 } else if (identical(_oldNode, node.returnType)) {
1078 return _parser.parseReturnType(); 1078 return _parser.parseReturnType();
1079 } else if (identical(_oldNode, node.identifier)) { 1079 } else if (identical(_oldNode, node.identifier)) {
1080 return _parser.parseSimpleIdentifier(); 1080 return _parser.parseSimpleIdentifier(isDeclaration: true);
1081 } else if (identical(_oldNode, node.parameters)) { 1081 } else if (identical(_oldNode, node.parameters)) {
1082 return _parser.parseFormalParameterList(); 1082 return _parser.parseFormalParameterList();
1083 } 1083 }
1084 return _notAChild(node); 1084 return _notAChild(node);
1085 } 1085 }
1086 1086
1087 @override 1087 @override
1088 AstNode visitHideCombinator(HideCombinator node) { 1088 AstNode visitHideCombinator(HideCombinator node) {
1089 if (node.hiddenNames.contains(_oldNode)) { 1089 if (node.hiddenNames.contains(_oldNode)) {
1090 return _parser.parseSimpleIdentifier(); 1090 return _parser.parseSimpleIdentifier();
(...skipping 23 matching lines...) Expand all
1114 1114
1115 @override 1115 @override
1116 AstNode visitImportDirective(ImportDirective node) { 1116 AstNode visitImportDirective(ImportDirective node) {
1117 if (identical(_oldNode, node.documentationComment)) { 1117 if (identical(_oldNode, node.documentationComment)) {
1118 throw new InsufficientContextException(); 1118 throw new InsufficientContextException();
1119 } else if (node.metadata.contains(_oldNode)) { 1119 } else if (node.metadata.contains(_oldNode)) {
1120 return _parser.parseAnnotation(); 1120 return _parser.parseAnnotation();
1121 } else if (identical(_oldNode, node.uri)) { 1121 } else if (identical(_oldNode, node.uri)) {
1122 return _parser.parseStringLiteral(); 1122 return _parser.parseStringLiteral();
1123 } else if (identical(_oldNode, node.prefix)) { 1123 } else if (identical(_oldNode, node.prefix)) {
1124 return _parser.parseSimpleIdentifier(); 1124 return _parser.parseSimpleIdentifier(isDeclaration: true);
1125 } else if (node.combinators.contains(_oldNode)) { 1125 } else if (node.combinators.contains(_oldNode)) {
1126 return _parser.parseCombinator(); 1126 return _parser.parseCombinator();
1127 } 1127 }
1128 return _notAChild(node); 1128 return _notAChild(node);
1129 } 1129 }
1130 1130
1131 @override 1131 @override
1132 AstNode visitIndexExpression(IndexExpression node) { 1132 AstNode visitIndexExpression(IndexExpression node) {
1133 if (identical(_oldNode, node.target)) { 1133 if (identical(_oldNode, node.target)) {
1134 throw new InsufficientContextException(); 1134 throw new InsufficientContextException();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1174 return _parser.parseBitwiseOrExpression(); 1174 return _parser.parseBitwiseOrExpression();
1175 } else if (identical(_oldNode, node.type)) { 1175 } else if (identical(_oldNode, node.type)) {
1176 return _parser.parseTypeName(); 1176 return _parser.parseTypeName();
1177 } 1177 }
1178 return _notAChild(node); 1178 return _notAChild(node);
1179 } 1179 }
1180 1180
1181 @override 1181 @override
1182 AstNode visitLabel(Label node) { 1182 AstNode visitLabel(Label node) {
1183 if (identical(_oldNode, node.label)) { 1183 if (identical(_oldNode, node.label)) {
1184 return _parser.parseSimpleIdentifier(); 1184 return _parser.parseSimpleIdentifier(
1185 isDeclaration: node.parent is LabeledStatement);
1185 } 1186 }
1186 return _notAChild(node); 1187 return _notAChild(node);
1187 } 1188 }
1188 1189
1189 @override 1190 @override
1190 AstNode visitLabeledStatement(LabeledStatement node) { 1191 AstNode visitLabeledStatement(LabeledStatement node) {
1191 if (node.labels.contains(_oldNode)) { 1192 if (node.labels.contains(_oldNode)) {
1192 return _parser.parseLabel(); 1193 return _parser.parseLabel(isDeclaration: true);
1193 } else if (identical(_oldNode, node.statement)) { 1194 } else if (identical(_oldNode, node.statement)) {
1194 return _parser.parseStatement2(); 1195 return _parser.parseStatement2();
1195 } 1196 }
1196 return _notAChild(node); 1197 return _notAChild(node);
1197 } 1198 }
1198 1199
1199 @override 1200 @override
1200 AstNode visitLibraryDirective(LibraryDirective node) { 1201 AstNode visitLibraryDirective(LibraryDirective node) {
1201 if (identical(_oldNode, node.documentationComment)) { 1202 if (identical(_oldNode, node.documentationComment)) {
1202 throw new InsufficientContextException(); 1203 throw new InsufficientContextException();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1253 } else if (node.metadata.contains(_oldNode)) { 1254 } else if (node.metadata.contains(_oldNode)) {
1254 return _parser.parseAnnotation(); 1255 return _parser.parseAnnotation();
1255 } else if (identical(_oldNode, node.returnType)) { 1256 } else if (identical(_oldNode, node.returnType)) {
1256 throw new InsufficientContextException(); 1257 throw new InsufficientContextException();
1257 //return parser.parseTypeName(); 1258 //return parser.parseTypeName();
1258 //return parser.parseReturnType(); 1259 //return parser.parseReturnType();
1259 } else if (identical(_oldNode, node.name)) { 1260 } else if (identical(_oldNode, node.name)) {
1260 if (node.operatorKeyword != null) { 1261 if (node.operatorKeyword != null) {
1261 throw new InsufficientContextException(); 1262 throw new InsufficientContextException();
1262 } 1263 }
1263 return _parser.parseSimpleIdentifier(); 1264 return _parser.parseSimpleIdentifier(isDeclaration: true);
1264 } else if (identical(_oldNode, node.body)) { 1265 } else if (identical(_oldNode, node.body)) {
1265 //return parser.parseFunctionBody(); 1266 //return parser.parseFunctionBody();
1266 throw new InsufficientContextException(); 1267 throw new InsufficientContextException();
1267 } else if (identical(_oldNode, node.parameters)) { 1268 } else if (identical(_oldNode, node.parameters)) {
1268 // TODO(paulberry): if we want errors to be correct, we'll need to also 1269 // TODO(paulberry): if we want errors to be correct, we'll need to also
1269 // call _validateFormalParameterList, and sometimes 1270 // call _validateFormalParameterList, and sometimes
1270 // _validateModifiersForGetterOrSetterOrMethod. 1271 // _validateModifiersForGetterOrSetterOrMethod.
1271 return _parser.parseFormalParameterList(); 1272 return _parser.parseFormalParameterList();
1272 } 1273 }
1273 return _notAChild(node); 1274 return _notAChild(node);
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
1548 return _notAChild(node); 1549 return _notAChild(node);
1549 } 1550 }
1550 1551
1551 @override 1552 @override
1552 AstNode visitTypeParameter(TypeParameter node) { 1553 AstNode visitTypeParameter(TypeParameter node) {
1553 if (identical(_oldNode, node.documentationComment)) { 1554 if (identical(_oldNode, node.documentationComment)) {
1554 throw new InsufficientContextException(); 1555 throw new InsufficientContextException();
1555 } else if (node.metadata.contains(_oldNode)) { 1556 } else if (node.metadata.contains(_oldNode)) {
1556 return _parser.parseAnnotation(); 1557 return _parser.parseAnnotation();
1557 } else if (identical(_oldNode, node.name)) { 1558 } else if (identical(_oldNode, node.name)) {
1558 return _parser.parseSimpleIdentifier(); 1559 return _parser.parseSimpleIdentifier(isDeclaration: true);
1559 } else if (identical(_oldNode, node.bound)) { 1560 } else if (identical(_oldNode, node.bound)) {
1560 return _parser.parseTypeName(); 1561 return _parser.parseTypeName();
1561 } 1562 }
1562 return _notAChild(node); 1563 return _notAChild(node);
1563 } 1564 }
1564 1565
1565 @override 1566 @override
1566 AstNode visitTypeParameterList(TypeParameterList node) { 1567 AstNode visitTypeParameterList(TypeParameterList node) {
1567 if (node.typeParameters.contains(node)) { 1568 if (node.typeParameters.contains(node)) {
1568 return _parser.parseTypeParameter(); 1569 return _parser.parseTypeParameter();
(...skipping 963 matching lines...) Expand 10 before | Expand all | Expand 10 after
2532 // name, parameters and empty body. 2533 // name, parameters and empty body.
2533 // 2534 //
2534 return new MethodDeclaration( 2535 return new MethodDeclaration(
2535 commentAndMetadata.comment, 2536 commentAndMetadata.comment,
2536 commentAndMetadata.metadata, 2537 commentAndMetadata.metadata,
2537 null, 2538 null,
2538 null, 2539 null,
2539 null, 2540 null,
2540 null, 2541 null,
2541 null, 2542 null,
2542 _createSyntheticIdentifier(), 2543 _createSyntheticIdentifier(isDeclaration: true),
2543 null, 2544 null,
2544 new FormalParameterList( 2545 new FormalParameterList(
2545 null, new List<FormalParameter>(), null, null, null), 2546 null, <FormalParameter>[], null, null, null),
2546 new EmptyFunctionBody(_createSyntheticToken(TokenType.SEMICOLON))); 2547 new EmptyFunctionBody(_createSyntheticToken(TokenType.SEMICOLON)));
2547 } 2548 }
2548 return null; 2549 return null;
2549 } else if (_tokenMatches(_peek(), TokenType.PERIOD) && 2550 } else if (_tokenMatches(_peek(), TokenType.PERIOD) &&
2550 _tokenMatchesIdentifier(_peekAt(2)) && 2551 _tokenMatchesIdentifier(_peekAt(2)) &&
2551 _tokenMatches(_peekAt(3), TokenType.OPEN_PAREN)) { 2552 _tokenMatches(_peekAt(3), TokenType.OPEN_PAREN)) {
2552 return _parseConstructor( 2553 return _parseConstructor(
2553 commentAndMetadata, 2554 commentAndMetadata,
2554 modifiers.externalKeyword, 2555 modifiers.externalKeyword,
2555 _validateModifiersForConstructor(modifiers), 2556 _validateModifiersForConstructor(modifiers),
2556 modifiers.factoryKeyword, 2557 modifiers.factoryKeyword,
2557 parseSimpleIdentifier(), 2558 parseSimpleIdentifier(),
2558 getAndAdvance(), 2559 getAndAdvance(),
2559 parseSimpleIdentifier(), 2560 parseSimpleIdentifier(isDeclaration: true),
2560 parseFormalParameterList()); 2561 parseFormalParameterList());
2561 } else if (_tokenMatches(_peek(), TokenType.OPEN_PAREN)) { 2562 } else if (_tokenMatches(_peek(), TokenType.OPEN_PAREN)) {
2562 TypeName returnType = _parseOptionalTypeNameComment(); 2563 TypeName returnType = _parseOptionalTypeNameComment();
2563 SimpleIdentifier methodName = parseSimpleIdentifier(); 2564 SimpleIdentifier methodName = parseSimpleIdentifier(isDeclaration: true);
2564 TypeParameterList typeParameters = _parseGenericCommentTypeParameters(); 2565 TypeParameterList typeParameters = _parseGenericCommentTypeParameters();
2565 FormalParameterList parameters = parseFormalParameterList(); 2566 FormalParameterList parameters = parseFormalParameterList();
2566 if (_matches(TokenType.COLON) || 2567 if (_matches(TokenType.COLON) ||
2567 modifiers.factoryKeyword != null || 2568 modifiers.factoryKeyword != null ||
2568 methodName.name == className) { 2569 methodName.name == className) {
2569 return _parseConstructor( 2570 return _parseConstructor(
2570 commentAndMetadata, 2571 commentAndMetadata,
2571 modifiers.externalKeyword, 2572 modifiers.externalKeyword,
2572 _validateModifiersForConstructor(modifiers), 2573 _validateModifiersForConstructor(modifiers),
2573 modifiers.factoryKeyword, 2574 modifiers.factoryKeyword,
2574 methodName, 2575 new SimpleIdentifier(methodName.token, isDeclaration: false),
2575 null, 2576 null,
2576 null, 2577 null,
2577 parameters); 2578 parameters);
2578 } 2579 }
2579 _validateModifiersForGetterOrSetterOrMethod(modifiers); 2580 _validateModifiersForGetterOrSetterOrMethod(modifiers);
2580 _validateFormalParameterList(parameters); 2581 _validateFormalParameterList(parameters);
2581 return _parseMethodDeclarationAfterParameters( 2582 return _parseMethodDeclarationAfterParameters(
2582 commentAndMetadata, 2583 commentAndMetadata,
2583 modifiers.externalKeyword, 2584 modifiers.externalKeyword,
2584 modifiers.staticKeyword, 2585 modifiers.staticKeyword,
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
2656 _lockErrorListener(); 2657 _lockErrorListener();
2657 return _parseInitializedIdentifierList( 2658 return _parseInitializedIdentifierList(
2658 commentAndMetadata, 2659 commentAndMetadata,
2659 modifiers.staticKeyword, 2660 modifiers.staticKeyword,
2660 _validateModifiersForField(modifiers), 2661 _validateModifiersForField(modifiers),
2661 type); 2662 type);
2662 } finally { 2663 } finally {
2663 _unlockErrorListener(); 2664 _unlockErrorListener();
2664 } 2665 }
2665 } else if (_tokenMatches(_peek(), TokenType.OPEN_PAREN)) { 2666 } else if (_tokenMatches(_peek(), TokenType.OPEN_PAREN)) {
2666 SimpleIdentifier methodName = parseSimpleIdentifier(); 2667 SimpleIdentifier methodName = parseSimpleIdentifier(isDeclaration: true);
2667 TypeParameterList typeParameters = _parseGenericCommentTypeParameters(); 2668 TypeParameterList typeParameters = _parseGenericCommentTypeParameters();
2668 FormalParameterList parameters = parseFormalParameterList(); 2669 FormalParameterList parameters = parseFormalParameterList();
2669 if (methodName.name == className) { 2670 if (methodName.name == className) {
2670 _reportErrorForNode(ParserErrorCode.CONSTRUCTOR_WITH_RETURN_TYPE, type); 2671 _reportErrorForNode(ParserErrorCode.CONSTRUCTOR_WITH_RETURN_TYPE, type);
2671 return _parseConstructor( 2672 return _parseConstructor(
2672 commentAndMetadata, 2673 commentAndMetadata,
2673 modifiers.externalKeyword, 2674 modifiers.externalKeyword,
2674 _validateModifiersForConstructor(modifiers), 2675 _validateModifiersForConstructor(modifiers),
2675 modifiers.factoryKeyword, 2676 modifiers.factoryKeyword,
2676 methodName, 2677 new SimpleIdentifier(methodName.token, isDeclaration: true),
2677 null, 2678 null,
2678 null, 2679 null,
2679 parameters); 2680 parameters);
2680 } 2681 }
2681 _validateModifiersForGetterOrSetterOrMethod(modifiers); 2682 _validateModifiersForGetterOrSetterOrMethod(modifiers);
2682 _validateFormalParameterList(parameters); 2683 _validateFormalParameterList(parameters);
2683 return _parseMethodDeclarationAfterParameters( 2684 return _parseMethodDeclarationAfterParameters(
2684 commentAndMetadata, 2685 commentAndMetadata,
2685 modifiers.externalKeyword, 2686 modifiers.externalKeyword,
2686 modifiers.staticKeyword, 2687 modifiers.staticKeyword,
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
3222 } 3223 }
3223 return new ImplementsClause(keyword, interfaces); 3224 return new ImplementsClause(keyword, interfaces);
3224 } 3225 }
3225 3226
3226 /** 3227 /**
3227 * Parse a label. Return the label that was parsed. 3228 * Parse a label. Return the label that was parsed.
3228 * 3229 *
3229 * label ::= 3230 * label ::=
3230 * identifier ':' 3231 * identifier ':'
3231 */ 3232 */
3232 Label parseLabel() { 3233 Label parseLabel({bool isDeclaration: false}) {
3233 SimpleIdentifier label = parseSimpleIdentifier(); 3234 SimpleIdentifier label =
3235 parseSimpleIdentifier(isDeclaration: isDeclaration);
3234 Token colon = _expect(TokenType.COLON); 3236 Token colon = _expect(TokenType.COLON);
3235 return new Label(label, colon); 3237 return new Label(label, colon);
3236 } 3238 }
3237 3239
3238 /** 3240 /**
3239 * Parse a library identifier. Return the library identifier that was parsed. 3241 * Parse a library identifier. Return the library identifier that was parsed.
3240 * 3242 *
3241 * libraryIdentifier ::= 3243 * libraryIdentifier ::=
3242 * identifier ('.' identifier)* 3244 * identifier ('.' identifier)*
3243 */ 3245 */
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
3315 FormalParameterList parameters = parseFormalParameterList(); 3317 FormalParameterList parameters = parseFormalParameterList();
3316 if (thisKeyword == null) { 3318 if (thisKeyword == null) {
3317 if (holder.keyword != null) { 3319 if (holder.keyword != null) {
3318 _reportErrorForToken( 3320 _reportErrorForToken(
3319 ParserErrorCode.FUNCTION_TYPED_PARAMETER_VAR, holder.keyword); 3321 ParserErrorCode.FUNCTION_TYPED_PARAMETER_VAR, holder.keyword);
3320 } 3322 }
3321 return new FunctionTypedFormalParameter( 3323 return new FunctionTypedFormalParameter(
3322 commentAndMetadata.comment, 3324 commentAndMetadata.comment,
3323 commentAndMetadata.metadata, 3325 commentAndMetadata.metadata,
3324 holder.type, 3326 holder.type,
3325 identifier, 3327 new SimpleIdentifier(identifier.token, isDeclaration: true),
3326 typeParameters, 3328 typeParameters,
3327 parameters); 3329 parameters);
3328 } else { 3330 } else {
3329 return new FieldFormalParameter( 3331 return new FieldFormalParameter(
3330 commentAndMetadata.comment, 3332 commentAndMetadata.comment,
3331 commentAndMetadata.metadata, 3333 commentAndMetadata.metadata,
3332 holder.keyword, 3334 holder.keyword,
3333 holder.type, 3335 holder.type,
3334 thisKeyword, 3336 thisKeyword,
3335 period, 3337 period,
(...skipping 24 matching lines...) Expand all
3360 commentAndMetadata.comment, 3362 commentAndMetadata.comment,
3361 commentAndMetadata.metadata, 3363 commentAndMetadata.metadata,
3362 holder.keyword, 3364 holder.keyword,
3363 holder.type, 3365 holder.type,
3364 thisKeyword, 3366 thisKeyword,
3365 period, 3367 period,
3366 identifier, 3368 identifier,
3367 null, 3369 null,
3368 null); 3370 null);
3369 } 3371 }
3370 return new SimpleFormalParameter(commentAndMetadata.comment, 3372 return new SimpleFormalParameter(
3371 commentAndMetadata.metadata, holder.keyword, holder.type, identifier); 3373 commentAndMetadata.comment,
3374 commentAndMetadata.metadata,
3375 holder.keyword,
3376 holder.type,
3377 new SimpleIdentifier(identifier.token, isDeclaration: true));
3372 } 3378 }
3373 3379
3374 /** 3380 /**
3375 * Parse a prefixed identifier. Return the prefixed identifier that was 3381 * Parse a prefixed identifier. Return the prefixed identifier that was
3376 * parsed. 3382 * parsed.
3377 * 3383 *
3378 * prefixedIdentifier ::= 3384 * prefixedIdentifier ::=
3379 * identifier ('.' identifier)? 3385 * identifier ('.' identifier)?
3380 */ 3386 */
3381 Identifier parsePrefixedIdentifier() { 3387 Identifier parsePrefixedIdentifier() {
(...skipping 20 matching lines...) Expand all
3402 return parseTypeName(); 3408 return parseTypeName();
3403 } 3409 }
3404 } 3410 }
3405 3411
3406 /** 3412 /**
3407 * Parse a simple identifier. Return the simple identifier that was parsed. 3413 * Parse a simple identifier. Return the simple identifier that was parsed.
3408 * 3414 *
3409 * identifier ::= 3415 * identifier ::=
3410 * IDENTIFIER 3416 * IDENTIFIER
3411 */ 3417 */
3412 SimpleIdentifier parseSimpleIdentifier() { 3418 SimpleIdentifier parseSimpleIdentifier({bool isDeclaration: false}) {
3413 if (_matchesIdentifier()) { 3419 if (_matchesIdentifier()) {
3414 String lexeme = _currentToken.lexeme; 3420 String lexeme = _currentToken.lexeme;
3415 if ((_inAsync || _inGenerator) && 3421 if ((_inAsync || _inGenerator) &&
3416 (lexeme == 'async' || lexeme == 'await' || lexeme == 'yield')) { 3422 (lexeme == 'async' || lexeme == 'await' || lexeme == 'yield')) {
3417 _reportErrorForCurrentToken( 3423 _reportErrorForCurrentToken(
3418 ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER); 3424 ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER);
3419 } 3425 }
3420 return new SimpleIdentifier(getAndAdvance()); 3426 return new SimpleIdentifier(getAndAdvance(),
3427 isDeclaration: isDeclaration);
3421 } 3428 }
3422 _reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER); 3429 _reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER);
3423 return _createSyntheticIdentifier(); 3430 return _createSyntheticIdentifier(isDeclaration: isDeclaration);
3424 } 3431 }
3425 3432
3426 /** 3433 /**
3427 * Parse a statement, starting with the given [token]. Return the statement 3434 * Parse a statement, starting with the given [token]. Return the statement
3428 * that was parsed, or `null` if the tokens do not represent a recognizable 3435 * that was parsed, or `null` if the tokens do not represent a recognizable
3429 * statement. 3436 * statement.
3430 */ 3437 */
3431 Statement parseStatement(Token token) { 3438 Statement parseStatement(Token token) {
3432 _currentToken = token; 3439 _currentToken = token;
3433 return parseStatement2(); 3440 return parseStatement2();
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
3528 } 3535 }
3529 3536
3530 /** 3537 /**
3531 * Parse a type parameter. Return the type parameter that was parsed. 3538 * Parse a type parameter. Return the type parameter that was parsed.
3532 * 3539 *
3533 * typeParameter ::= 3540 * typeParameter ::=
3534 * metadata name ('extends' bound)? 3541 * metadata name ('extends' bound)?
3535 */ 3542 */
3536 TypeParameter parseTypeParameter() { 3543 TypeParameter parseTypeParameter() {
3537 CommentAndMetadata commentAndMetadata = _parseCommentAndMetadata(); 3544 CommentAndMetadata commentAndMetadata = _parseCommentAndMetadata();
3538 SimpleIdentifier name = parseSimpleIdentifier(); 3545 SimpleIdentifier name = parseSimpleIdentifier(isDeclaration: true);
3539 if (_matchesKeyword(Keyword.EXTENDS)) { 3546 if (_matchesKeyword(Keyword.EXTENDS)) {
3540 Token keyword = getAndAdvance(); 3547 Token keyword = getAndAdvance();
3541 TypeName bound = parseTypeName(); 3548 TypeName bound = parseTypeName();
3542 return new TypeParameter(commentAndMetadata.comment, 3549 return new TypeParameter(commentAndMetadata.comment,
3543 commentAndMetadata.metadata, name, keyword, bound); 3550 commentAndMetadata.metadata, name, keyword, bound);
3544 } 3551 }
3545 return new TypeParameter(commentAndMetadata.comment, 3552 return new TypeParameter(commentAndMetadata.comment,
3546 commentAndMetadata.metadata, name, null, null); 3553 commentAndMetadata.metadata, name, null, null);
3547 } 3554 }
3548 3555
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
3698 _matchesIdentifier()) { 3705 _matchesIdentifier()) {
3699 return true; 3706 return true;
3700 } 3707 }
3701 } 3708 }
3702 return false; 3709 return false;
3703 } 3710 }
3704 3711
3705 /** 3712 /**
3706 * Return a synthetic identifier. 3713 * Return a synthetic identifier.
3707 */ 3714 */
3708 SimpleIdentifier _createSyntheticIdentifier() { 3715 SimpleIdentifier _createSyntheticIdentifier({bool isDeclaration: false}) {
3709 Token syntheticToken; 3716 Token syntheticToken;
3710 if (_currentToken.type == TokenType.KEYWORD) { 3717 if (_currentToken.type == TokenType.KEYWORD) {
3711 // Consider current keyword token as an identifier. 3718 // Consider current keyword token as an identifier.
3712 // It is not always true, e.g. "^is T" where "^" is place the place for 3719 // It is not always true, e.g. "^is T" where "^" is place the place for
3713 // synthetic identifier. By creating SyntheticStringToken we can 3720 // synthetic identifier. By creating SyntheticStringToken we can
3714 // distinguish a real identifier from synthetic. In the code completion 3721 // distinguish a real identifier from synthetic. In the code completion
3715 // behavior will depend on a cursor position - before or on "is". 3722 // behavior will depend on a cursor position - before or on "is".
3716 syntheticToken = _injectToken(new SyntheticStringToken( 3723 syntheticToken = _injectToken(new SyntheticStringToken(
3717 TokenType.IDENTIFIER, _currentToken.lexeme, _currentToken.offset)); 3724 TokenType.IDENTIFIER, _currentToken.lexeme, _currentToken.offset));
3718 } else { 3725 } else {
3719 syntheticToken = _createSyntheticToken(TokenType.IDENTIFIER); 3726 syntheticToken = _createSyntheticToken(TokenType.IDENTIFIER);
3720 } 3727 }
3721 return new SimpleIdentifier(syntheticToken); 3728 return new SimpleIdentifier(syntheticToken, isDeclaration: isDeclaration);
3722 } 3729 }
3723 3730
3724 /** 3731 /**
3725 * Return a synthetic token representing the given [keyword]. 3732 * Return a synthetic token representing the given [keyword].
3726 */ 3733 */
3727 Token _createSyntheticKeyword(Keyword keyword) => _injectToken( 3734 Token _createSyntheticKeyword(Keyword keyword) => _injectToken(
3728 new Parser_SyntheticKeywordToken(keyword, _currentToken.offset)); 3735 new Parser_SyntheticKeywordToken(keyword, _currentToken.offset));
3729 3736
3730 /** 3737 /**
3731 * Return a synthetic string literal. 3738 * Return a synthetic string literal.
(...skipping 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after
4739 next = _skipTypeParameterList(next); 4746 next = _skipTypeParameterList(next);
4740 if (next != null && _tokenMatches(next, TokenType.EQ)) { 4747 if (next != null && _tokenMatches(next, TokenType.EQ)) {
4741 return _parseClassTypeAlias( 4748 return _parseClassTypeAlias(
4742 commentAndMetadata, abstractKeyword, keyword); 4749 commentAndMetadata, abstractKeyword, keyword);
4743 } 4750 }
4744 } else if (_tokenMatches(next, TokenType.EQ)) { 4751 } else if (_tokenMatches(next, TokenType.EQ)) {
4745 return _parseClassTypeAlias( 4752 return _parseClassTypeAlias(
4746 commentAndMetadata, abstractKeyword, keyword); 4753 commentAndMetadata, abstractKeyword, keyword);
4747 } 4754 }
4748 } 4755 }
4749 SimpleIdentifier name = parseSimpleIdentifier(); 4756 SimpleIdentifier name = parseSimpleIdentifier(isDeclaration: true);
4750 String className = name.name; 4757 String className = name.name;
4751 TypeParameterList typeParameters = null; 4758 TypeParameterList typeParameters = null;
4752 if (_matches(TokenType.LT)) { 4759 if (_matches(TokenType.LT)) {
4753 typeParameters = parseTypeParameterList(); 4760 typeParameters = parseTypeParameterList();
4754 } 4761 }
4755 // 4762 //
4756 // Parse the clauses. The parser accepts clauses in any order, but will 4763 // Parse the clauses. The parser accepts clauses in any order, but will
4757 // generate errors if they are not in the order required by the 4764 // generate errors if they are not in the order required by the
4758 // specification. 4765 // specification.
4759 // 4766 //
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
4892 * 'class' keyword. Return the class type alias that was parsed. 4899 * 'class' keyword. Return the class type alias that was parsed.
4893 * 4900 *
4894 * classTypeAlias ::= 4901 * classTypeAlias ::=
4895 * identifier typeParameters? '=' 'abstract'? mixinApplication 4902 * identifier typeParameters? '=' 'abstract'? mixinApplication
4896 * 4903 *
4897 * mixinApplication ::= 4904 * mixinApplication ::=
4898 * type withClause implementsClause? ';' 4905 * type withClause implementsClause? ';'
4899 */ 4906 */
4900 ClassTypeAlias _parseClassTypeAlias(CommentAndMetadata commentAndMetadata, 4907 ClassTypeAlias _parseClassTypeAlias(CommentAndMetadata commentAndMetadata,
4901 Token abstractKeyword, Token classKeyword) { 4908 Token abstractKeyword, Token classKeyword) {
4902 SimpleIdentifier className = parseSimpleIdentifier(); 4909 SimpleIdentifier className = parseSimpleIdentifier(isDeclaration: true);
4903 TypeParameterList typeParameters = null; 4910 TypeParameterList typeParameters = null;
4904 if (_matches(TokenType.LT)) { 4911 if (_matches(TokenType.LT)) {
4905 typeParameters = parseTypeParameterList(); 4912 typeParameters = parseTypeParameterList();
4906 } 4913 }
4907 Token equals = _expect(TokenType.EQ); 4914 Token equals = _expect(TokenType.EQ);
4908 TypeName superclass = parseTypeName(); 4915 TypeName superclass = parseTypeName();
4909 WithClause withClause = null; 4916 WithClause withClause = null;
4910 if (_matchesKeyword(Keyword.WITH)) { 4917 if (_matchesKeyword(Keyword.WITH)) {
4911 withClause = parseWithClause(); 4918 withClause = parseWithClause();
4912 } else { 4919 } else {
(...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after
5701 * 5708 *
5702 * emptyStatement ::= 5709 * emptyStatement ::=
5703 * ';' 5710 * ';'
5704 */ 5711 */
5705 Statement _parseEmptyStatement() => new EmptyStatement(getAndAdvance()); 5712 Statement _parseEmptyStatement() => new EmptyStatement(getAndAdvance());
5706 5713
5707 EnumConstantDeclaration _parseEnumConstantDeclaration() { 5714 EnumConstantDeclaration _parseEnumConstantDeclaration() {
5708 CommentAndMetadata commentAndMetadata = _parseCommentAndMetadata(); 5715 CommentAndMetadata commentAndMetadata = _parseCommentAndMetadata();
5709 SimpleIdentifier name; 5716 SimpleIdentifier name;
5710 if (_matchesIdentifier()) { 5717 if (_matchesIdentifier()) {
5711 name = parseSimpleIdentifier(); 5718 name = parseSimpleIdentifier(isDeclaration: true);
5712 } else { 5719 } else {
5713 name = _createSyntheticIdentifier(); 5720 name = _createSyntheticIdentifier();
5714 } 5721 }
5715 if (commentAndMetadata.metadata.isNotEmpty) { 5722 if (commentAndMetadata.metadata.isNotEmpty) {
5716 _reportErrorForNode(ParserErrorCode.ANNOTATION_ON_ENUM_CONSTANT, 5723 _reportErrorForNode(ParserErrorCode.ANNOTATION_ON_ENUM_CONSTANT,
5717 commentAndMetadata.metadata[0]); 5724 commentAndMetadata.metadata[0]);
5718 } 5725 }
5719 return new EnumConstantDeclaration( 5726 return new EnumConstantDeclaration(
5720 commentAndMetadata.comment, commentAndMetadata.metadata, name); 5727 commentAndMetadata.comment, commentAndMetadata.metadata, name);
5721 } 5728 }
5722 5729
5723 /** 5730 /**
5724 * Parse an enum declaration. The [commentAndMetadata] is the metadata to be 5731 * Parse an enum declaration. The [commentAndMetadata] is the metadata to be
5725 * associated with the member. Return the enum declaration that was parsed. 5732 * associated with the member. Return the enum declaration that was parsed.
5726 * 5733 *
5727 * enumType ::= 5734 * enumType ::=
5728 * metadata 'enum' id '{' id (',' id)* (',')? '}' 5735 * metadata 'enum' id '{' id (',' id)* (',')? '}'
5729 */ 5736 */
5730 EnumDeclaration _parseEnumDeclaration(CommentAndMetadata commentAndMetadata) { 5737 EnumDeclaration _parseEnumDeclaration(CommentAndMetadata commentAndMetadata) {
5731 Token keyword = _expectKeyword(Keyword.ENUM); 5738 Token keyword = _expectKeyword(Keyword.ENUM);
5732 SimpleIdentifier name = parseSimpleIdentifier(); 5739 SimpleIdentifier name = parseSimpleIdentifier(isDeclaration: true);
5733 Token leftBracket = null; 5740 Token leftBracket = null;
5734 List<EnumConstantDeclaration> constants = 5741 List<EnumConstantDeclaration> constants =
5735 new List<EnumConstantDeclaration>(); 5742 new List<EnumConstantDeclaration>();
5736 Token rightBracket = null; 5743 Token rightBracket = null;
5737 if (_matches(TokenType.OPEN_CURLY_BRACKET)) { 5744 if (_matches(TokenType.OPEN_CURLY_BRACKET)) {
5738 leftBracket = _expect(TokenType.OPEN_CURLY_BRACKET); 5745 leftBracket = _expect(TokenType.OPEN_CURLY_BRACKET);
5739 if (_matchesIdentifier() || _matches(TokenType.AT)) { 5746 if (_matchesIdentifier() || _matches(TokenType.AT)) {
5740 constants.add(_parseEnumConstantDeclaration()); 5747 constants.add(_parseEnumConstantDeclaration());
5741 } else if (_matches(TokenType.COMMA) && 5748 } else if (_matches(TokenType.COMMA) &&
5742 _tokenMatchesIdentifier(_peek())) { 5749 _tokenMatchesIdentifier(_peek())) {
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
5985 [variables.length.toString()]); 5992 [variables.length.toString()]);
5986 } 5993 }
5987 VariableDeclaration variable = variables[0]; 5994 VariableDeclaration variable = variables[0];
5988 if (variable.initializer != null) { 5995 if (variable.initializer != null) {
5989 _reportErrorForCurrentToken( 5996 _reportErrorForCurrentToken(
5990 ParserErrorCode.INITIALIZED_VARIABLE_IN_FOR_EACH); 5997 ParserErrorCode.INITIALIZED_VARIABLE_IN_FOR_EACH);
5991 } 5998 }
5992 Token keyword = variableList.keyword; 5999 Token keyword = variableList.keyword;
5993 TypeName type = variableList.type; 6000 TypeName type = variableList.type;
5994 if (keyword != null || type != null) { 6001 if (keyword != null || type != null) {
5995 loopVariable = new DeclaredIdentifier(commentAndMetadata.comment, 6002 loopVariable = new DeclaredIdentifier(
5996 commentAndMetadata.metadata, keyword, type, variable.name); 6003 commentAndMetadata.comment,
6004 commentAndMetadata.metadata,
6005 keyword,
6006 type,
6007 new SimpleIdentifier(variable.name.token,
6008 isDeclaration: true));
5997 } else { 6009 } else {
5998 if (!commentAndMetadata.metadata.isEmpty) { 6010 if (!commentAndMetadata.metadata.isEmpty) {
5999 // TODO(jwren) metadata isn't allowed before the identifier in 6011 // TODO(jwren) metadata isn't allowed before the identifier in
6000 // "identifier in expression", add warning if commentAndMetadata 6012 // "identifier in expression", add warning if commentAndMetadata
6001 // has content 6013 // has content
6002 } 6014 }
6003 identifier = variable.name; 6015 identifier = variable.name;
6004 } 6016 }
6005 } 6017 }
6006 Token inKeyword = getAndAdvance(); 6018 Token inKeyword = getAndAdvance();
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
6197 Token keyword = null; 6209 Token keyword = null;
6198 bool isGetter = false; 6210 bool isGetter = false;
6199 if (_matchesKeyword(Keyword.GET) && 6211 if (_matchesKeyword(Keyword.GET) &&
6200 !_tokenMatches(_peek(), TokenType.OPEN_PAREN)) { 6212 !_tokenMatches(_peek(), TokenType.OPEN_PAREN)) {
6201 keyword = getAndAdvance(); 6213 keyword = getAndAdvance();
6202 isGetter = true; 6214 isGetter = true;
6203 } else if (_matchesKeyword(Keyword.SET) && 6215 } else if (_matchesKeyword(Keyword.SET) &&
6204 !_tokenMatches(_peek(), TokenType.OPEN_PAREN)) { 6216 !_tokenMatches(_peek(), TokenType.OPEN_PAREN)) {
6205 keyword = getAndAdvance(); 6217 keyword = getAndAdvance();
6206 } 6218 }
6207 SimpleIdentifier name = parseSimpleIdentifier(); 6219 SimpleIdentifier name = parseSimpleIdentifier(isDeclaration: true);
6208 TypeParameterList typeParameters = _parseGenericMethodTypeParameters(); 6220 TypeParameterList typeParameters = _parseGenericMethodTypeParameters();
6209 FormalParameterList parameters = null; 6221 FormalParameterList parameters = null;
6210 if (!isGetter) { 6222 if (!isGetter) {
6211 if (_matches(TokenType.OPEN_PAREN)) { 6223 if (_matches(TokenType.OPEN_PAREN)) {
6212 parameters = parseFormalParameterList(); 6224 parameters = parseFormalParameterList();
6213 _validateFormalParameterList(parameters); 6225 _validateFormalParameterList(parameters);
6214 } else { 6226 } else {
6215 _reportErrorForCurrentToken( 6227 _reportErrorForCurrentToken(
6216 ParserErrorCode.MISSING_FUNCTION_PARAMETERS); 6228 ParserErrorCode.MISSING_FUNCTION_PARAMETERS);
6217 parameters = new FormalParameterList( 6229 parameters = new FormalParameterList(
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
6297 * 6309 *
6298 * functionPrefix ::= 6310 * functionPrefix ::=
6299 * returnType? name 6311 * returnType? name
6300 */ 6312 */
6301 FunctionTypeAlias _parseFunctionTypeAlias( 6313 FunctionTypeAlias _parseFunctionTypeAlias(
6302 CommentAndMetadata commentAndMetadata, Token keyword) { 6314 CommentAndMetadata commentAndMetadata, Token keyword) {
6303 TypeName returnType = null; 6315 TypeName returnType = null;
6304 if (hasReturnTypeInTypeAlias) { 6316 if (hasReturnTypeInTypeAlias) {
6305 returnType = parseReturnType(); 6317 returnType = parseReturnType();
6306 } 6318 }
6307 SimpleIdentifier name = parseSimpleIdentifier(); 6319 SimpleIdentifier name = parseSimpleIdentifier(isDeclaration: true);
6308 TypeParameterList typeParameters = null; 6320 TypeParameterList typeParameters = null;
6309 if (_matches(TokenType.LT)) { 6321 if (_matches(TokenType.LT)) {
6310 typeParameters = parseTypeParameterList(); 6322 typeParameters = parseTypeParameterList();
6311 } 6323 }
6312 if (_matches(TokenType.SEMICOLON) || _matches(TokenType.EOF)) { 6324 if (_matches(TokenType.SEMICOLON) || _matches(TokenType.EOF)) {
6313 _reportErrorForCurrentToken(ParserErrorCode.MISSING_TYPEDEF_PARAMETERS); 6325 _reportErrorForCurrentToken(ParserErrorCode.MISSING_TYPEDEF_PARAMETERS);
6314 FormalParameterList parameters = new FormalParameterList( 6326 FormalParameterList parameters = new FormalParameterList(
6315 _createSyntheticToken(TokenType.OPEN_PAREN), 6327 _createSyntheticToken(TokenType.OPEN_PAREN),
6316 null, 6328 null,
6317 null, 6329 null,
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
6399 * 6411 *
6400 * getter ::= 6412 * getter ::=
6401 * getterSignature functionBody? 6413 * getterSignature functionBody?
6402 * 6414 *
6403 * getterSignature ::= 6415 * getterSignature ::=
6404 * 'external'? 'static'? returnType? 'get' identifier 6416 * 'external'? 'static'? returnType? 'get' identifier
6405 */ 6417 */
6406 MethodDeclaration _parseGetter(CommentAndMetadata commentAndMetadata, 6418 MethodDeclaration _parseGetter(CommentAndMetadata commentAndMetadata,
6407 Token externalKeyword, Token staticKeyword, TypeName returnType) { 6419 Token externalKeyword, Token staticKeyword, TypeName returnType) {
6408 Token propertyKeyword = _expectKeyword(Keyword.GET); 6420 Token propertyKeyword = _expectKeyword(Keyword.GET);
6409 SimpleIdentifier name = parseSimpleIdentifier(); 6421 SimpleIdentifier name = parseSimpleIdentifier(isDeclaration: true);
6410 if (_matches(TokenType.OPEN_PAREN) && 6422 if (_matches(TokenType.OPEN_PAREN) &&
6411 _tokenMatches(_peek(), TokenType.CLOSE_PAREN)) { 6423 _tokenMatches(_peek(), TokenType.CLOSE_PAREN)) {
6412 _reportErrorForCurrentToken(ParserErrorCode.GETTER_WITH_PARAMETERS); 6424 _reportErrorForCurrentToken(ParserErrorCode.GETTER_WITH_PARAMETERS);
6413 _advance(); 6425 _advance();
6414 _advance(); 6426 _advance();
6415 } 6427 }
6416 FunctionBody body = _parseFunctionBody( 6428 FunctionBody body = _parseFunctionBody(
6417 externalKeyword != null || staticKeyword == null, 6429 externalKeyword != null || staticKeyword == null,
6418 ParserErrorCode.STATIC_GETTER_WITHOUT_BODY, 6430 ParserErrorCode.STATIC_GETTER_WITHOUT_BODY,
6419 false); 6431 false);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
6485 StringLiteral libraryUri = _parseUri(); 6497 StringLiteral libraryUri = _parseUri();
6486 List<Configuration> configurations = _parseConfigurations(); 6498 List<Configuration> configurations = _parseConfigurations();
6487 Token deferredToken = null; 6499 Token deferredToken = null;
6488 Token asToken = null; 6500 Token asToken = null;
6489 SimpleIdentifier prefix = null; 6501 SimpleIdentifier prefix = null;
6490 if (_matchesKeyword(Keyword.DEFERRED)) { 6502 if (_matchesKeyword(Keyword.DEFERRED)) {
6491 deferredToken = getAndAdvance(); 6503 deferredToken = getAndAdvance();
6492 } 6504 }
6493 if (_matchesKeyword(Keyword.AS)) { 6505 if (_matchesKeyword(Keyword.AS)) {
6494 asToken = getAndAdvance(); 6506 asToken = getAndAdvance();
6495 prefix = parseSimpleIdentifier(); 6507 prefix = parseSimpleIdentifier(isDeclaration: true);
6496 } else if (deferredToken != null) { 6508 } else if (deferredToken != null) {
6497 _reportErrorForCurrentToken( 6509 _reportErrorForCurrentToken(
6498 ParserErrorCode.MISSING_PREFIX_IN_DEFERRED_IMPORT); 6510 ParserErrorCode.MISSING_PREFIX_IN_DEFERRED_IMPORT);
6499 } else if (!_matches(TokenType.SEMICOLON) && 6511 } else if (!_matches(TokenType.SEMICOLON) &&
6500 !_matchesString(_SHOW) && 6512 !_matchesString(_SHOW) &&
6501 !_matchesString(_HIDE)) { 6513 !_matchesString(_HIDE)) {
6502 Token nextToken = _peek(); 6514 Token nextToken = _peek();
6503 if (_tokenMatchesKeyword(nextToken, Keyword.AS) || 6515 if (_tokenMatchesKeyword(nextToken, Keyword.AS) ||
6504 _tokenMatchesString(nextToken, _SHOW) || 6516 _tokenMatchesString(nextToken, _SHOW) ||
6505 _tokenMatchesString(nextToken, _HIDE)) { 6517 _tokenMatchesString(nextToken, _HIDE)) {
6506 _reportErrorForCurrentToken( 6518 _reportErrorForCurrentToken(
6507 ParserErrorCode.UNEXPECTED_TOKEN, [_currentToken]); 6519 ParserErrorCode.UNEXPECTED_TOKEN, [_currentToken]);
6508 _advance(); 6520 _advance();
6509 if (_matchesKeyword(Keyword.AS)) { 6521 if (_matchesKeyword(Keyword.AS)) {
6510 asToken = getAndAdvance(); 6522 asToken = getAndAdvance();
6511 prefix = parseSimpleIdentifier(); 6523 prefix = parseSimpleIdentifier(isDeclaration: true);
6512 } 6524 }
6513 } 6525 }
6514 } 6526 }
6515 List<Combinator> combinators = _parseCombinators(); 6527 List<Combinator> combinators = _parseCombinators();
6516 Token semicolon = _expect(TokenType.SEMICOLON); 6528 Token semicolon = _expect(TokenType.SEMICOLON);
6517 return new ImportDirective( 6529 return new ImportDirective(
6518 commentAndMetadata.comment, 6530 commentAndMetadata.comment,
6519 commentAndMetadata.metadata, 6531 commentAndMetadata.metadata,
6520 importKeyword, 6532 importKeyword,
6521 libraryUri, 6533 libraryUri,
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
6809 * 6821 *
6810 * functionDeclaration ::= 6822 * functionDeclaration ::=
6811 * 'external'? 'static'? functionSignature functionBody 6823 * 'external'? 'static'? functionSignature functionBody
6812 * | 'external'? functionSignature ';' 6824 * | 'external'? functionSignature ';'
6813 */ 6825 */
6814 MethodDeclaration _parseMethodDeclarationAfterReturnType( 6826 MethodDeclaration _parseMethodDeclarationAfterReturnType(
6815 CommentAndMetadata commentAndMetadata, 6827 CommentAndMetadata commentAndMetadata,
6816 Token externalKeyword, 6828 Token externalKeyword,
6817 Token staticKeyword, 6829 Token staticKeyword,
6818 TypeName returnType) { 6830 TypeName returnType) {
6819 SimpleIdentifier methodName = parseSimpleIdentifier(); 6831 SimpleIdentifier methodName = parseSimpleIdentifier(isDeclaration: true);
6820 TypeParameterList typeParameters = _parseGenericMethodTypeParameters(); 6832 TypeParameterList typeParameters = _parseGenericMethodTypeParameters();
6821 FormalParameterList parameters; 6833 FormalParameterList parameters;
6822 if (!_matches(TokenType.OPEN_PAREN) && 6834 if (!_matches(TokenType.OPEN_PAREN) &&
6823 (_matches(TokenType.OPEN_CURLY_BRACKET) || 6835 (_matches(TokenType.OPEN_CURLY_BRACKET) ||
6824 _matches(TokenType.FUNCTION))) { 6836 _matches(TokenType.FUNCTION))) {
6825 _reportErrorForToken( 6837 _reportErrorForToken(
6826 ParserErrorCode.MISSING_METHOD_PARAMETERS, _currentToken.previous); 6838 ParserErrorCode.MISSING_METHOD_PARAMETERS, _currentToken.previous);
6827 parameters = new FormalParameterList( 6839 parameters = new FormalParameterList(
6828 _createSyntheticToken(TokenType.OPEN_PAREN), 6840 _createSyntheticToken(TokenType.OPEN_PAREN),
6829 null, 6841 null,
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
7172 operatorKeyword = getAndAdvance(); 7184 operatorKeyword = getAndAdvance();
7173 } else { 7185 } else {
7174 _reportErrorForToken( 7186 _reportErrorForToken(
7175 ParserErrorCode.MISSING_KEYWORD_OPERATOR, _currentToken); 7187 ParserErrorCode.MISSING_KEYWORD_OPERATOR, _currentToken);
7176 operatorKeyword = _createSyntheticKeyword(Keyword.OPERATOR); 7188 operatorKeyword = _createSyntheticKeyword(Keyword.OPERATOR);
7177 } 7189 }
7178 if (!_currentToken.isUserDefinableOperator) { 7190 if (!_currentToken.isUserDefinableOperator) {
7179 _reportErrorForCurrentToken( 7191 _reportErrorForCurrentToken(
7180 ParserErrorCode.NON_USER_DEFINABLE_OPERATOR, [_currentToken.lexeme]); 7192 ParserErrorCode.NON_USER_DEFINABLE_OPERATOR, [_currentToken.lexeme]);
7181 } 7193 }
7182 SimpleIdentifier name = new SimpleIdentifier(getAndAdvance()); 7194 SimpleIdentifier name =
7195 new SimpleIdentifier(getAndAdvance(), isDeclaration: true);
7183 if (_matches(TokenType.EQ)) { 7196 if (_matches(TokenType.EQ)) {
7184 Token previous = _currentToken.previous; 7197 Token previous = _currentToken.previous;
7185 if ((_tokenMatches(previous, TokenType.EQ_EQ) || 7198 if ((_tokenMatches(previous, TokenType.EQ_EQ) ||
7186 _tokenMatches(previous, TokenType.BANG_EQ)) && 7199 _tokenMatches(previous, TokenType.BANG_EQ)) &&
7187 _currentToken.offset == previous.offset + 2) { 7200 _currentToken.offset == previous.offset + 2) {
7188 _reportErrorForCurrentToken(ParserErrorCode.INVALID_OPERATOR, 7201 _reportErrorForCurrentToken(ParserErrorCode.INVALID_OPERATOR,
7189 ["${previous.lexeme}${_currentToken.lexeme}"]); 7202 ["${previous.lexeme}${_currentToken.lexeme}"]);
7190 _advance(); 7203 _advance();
7191 } 7204 }
7192 } 7205 }
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
7557 * 7570 *
7558 * setter ::= 7571 * setter ::=
7559 * setterSignature functionBody? 7572 * setterSignature functionBody?
7560 * 7573 *
7561 * setterSignature ::= 7574 * setterSignature ::=
7562 * 'external'? 'static'? returnType? 'set' identifier formalParameterL ist 7575 * 'external'? 'static'? returnType? 'set' identifier formalParameterL ist
7563 */ 7576 */
7564 MethodDeclaration _parseSetter(CommentAndMetadata commentAndMetadata, 7577 MethodDeclaration _parseSetter(CommentAndMetadata commentAndMetadata,
7565 Token externalKeyword, Token staticKeyword, TypeName returnType) { 7578 Token externalKeyword, Token staticKeyword, TypeName returnType) {
7566 Token propertyKeyword = _expectKeyword(Keyword.SET); 7579 Token propertyKeyword = _expectKeyword(Keyword.SET);
7567 SimpleIdentifier name = parseSimpleIdentifier(); 7580 SimpleIdentifier name = parseSimpleIdentifier(isDeclaration: true);
7568 FormalParameterList parameters = parseFormalParameterList(); 7581 FormalParameterList parameters = parseFormalParameterList();
7569 _validateFormalParameterList(parameters); 7582 _validateFormalParameterList(parameters);
7570 FunctionBody body = _parseFunctionBody( 7583 FunctionBody body = _parseFunctionBody(
7571 externalKeyword != null || staticKeyword == null, 7584 externalKeyword != null || staticKeyword == null,
7572 ParserErrorCode.STATIC_SETTER_WITHOUT_BODY, 7585 ParserErrorCode.STATIC_SETTER_WITHOUT_BODY,
7573 false); 7586 false);
7574 if (externalKeyword != null && body is! EmptyFunctionBody) { 7587 if (externalKeyword != null && body is! EmptyFunctionBody) {
7575 _reportErrorForCurrentToken(ParserErrorCode.EXTERNAL_SETTER_WITH_BODY); 7588 _reportErrorForCurrentToken(ParserErrorCode.EXTERNAL_SETTER_WITH_BODY);
7576 } 7589 }
7577 return new MethodDeclaration( 7590 return new MethodDeclaration(
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
7879 } 7892 }
7880 Token catchKeyword = null; 7893 Token catchKeyword = null;
7881 Token leftParenthesis = null; 7894 Token leftParenthesis = null;
7882 SimpleIdentifier exceptionParameter = null; 7895 SimpleIdentifier exceptionParameter = null;
7883 Token comma = null; 7896 Token comma = null;
7884 SimpleIdentifier stackTraceParameter = null; 7897 SimpleIdentifier stackTraceParameter = null;
7885 Token rightParenthesis = null; 7898 Token rightParenthesis = null;
7886 if (_matchesKeyword(Keyword.CATCH)) { 7899 if (_matchesKeyword(Keyword.CATCH)) {
7887 catchKeyword = getAndAdvance(); 7900 catchKeyword = getAndAdvance();
7888 leftParenthesis = _expect(TokenType.OPEN_PAREN); 7901 leftParenthesis = _expect(TokenType.OPEN_PAREN);
7889 exceptionParameter = parseSimpleIdentifier(); 7902 exceptionParameter = parseSimpleIdentifier(isDeclaration: true);
7890 if (_matches(TokenType.COMMA)) { 7903 if (_matches(TokenType.COMMA)) {
7891 comma = getAndAdvance(); 7904 comma = getAndAdvance();
7892 stackTraceParameter = parseSimpleIdentifier(); 7905 stackTraceParameter = parseSimpleIdentifier(isDeclaration: true);
7893 } 7906 }
7894 rightParenthesis = _expect(TokenType.CLOSE_PAREN); 7907 rightParenthesis = _expect(TokenType.CLOSE_PAREN);
7895 } 7908 }
7896 Block catchBody = parseBlock(); 7909 Block catchBody = parseBlock();
7897 catchClauses.add(new CatchClause( 7910 catchClauses.add(new CatchClause(
7898 onKeyword, 7911 onKeyword,
7899 exceptionType, 7912 exceptionType,
7900 catchKeyword, 7913 catchKeyword,
7901 leftParenthesis, 7914 leftParenthesis,
7902 exceptionParameter, 7915 exceptionParameter,
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
8115 VariableDeclaration _parseVariableDeclaration() { 8128 VariableDeclaration _parseVariableDeclaration() {
8116 // TODO(paulberry): prior to the fix for bug 23204, we permitted 8129 // TODO(paulberry): prior to the fix for bug 23204, we permitted
8117 // annotations before variable declarations (e.g. "String @deprecated s;"). 8130 // annotations before variable declarations (e.g. "String @deprecated s;").
8118 // Although such constructions are prohibited by the spec, we may want to 8131 // Although such constructions are prohibited by the spec, we may want to
8119 // consider handling them anyway to allow for better parser recovery in the 8132 // consider handling them anyway to allow for better parser recovery in the
8120 // event that the user erroneously tries to use them. However, as a 8133 // event that the user erroneously tries to use them. However, as a
8121 // counterargument, this would likely degrade parser recovery in the event 8134 // counterargument, this would likely degrade parser recovery in the event
8122 // of a construct like "class C { int @deprecated foo() {} }" (i.e. the 8135 // of a construct like "class C { int @deprecated foo() {} }" (i.e. the
8123 // user is in the middle of inserting "int bar;" prior to 8136 // user is in the middle of inserting "int bar;" prior to
8124 // "@deprecated foo() {}"). 8137 // "@deprecated foo() {}").
8125 SimpleIdentifier name = parseSimpleIdentifier(); 8138 SimpleIdentifier name = parseSimpleIdentifier(isDeclaration: true);
8126 Token equals = null; 8139 Token equals = null;
8127 Expression initializer = null; 8140 Expression initializer = null;
8128 if (_matches(TokenType.EQ)) { 8141 if (_matches(TokenType.EQ)) {
8129 equals = getAndAdvance(); 8142 equals = getAndAdvance();
8130 initializer = parseExpression2(); 8143 initializer = parseExpression2();
8131 } 8144 }
8132 return new VariableDeclaration(name, equals, initializer); 8145 return new VariableDeclaration(name, equals, initializer);
8133 } 8146 }
8134 8147
8135 /** 8148 /**
(...skipping 1807 matching lines...) Expand 10 before | Expand all | Expand 10 after
9943 */ 9956 */
9944 const ParserErrorCode(String name, String message, [String correction]) 9957 const ParserErrorCode(String name, String message, [String correction])
9945 : super(name, message, correction); 9958 : super(name, message, correction);
9946 9959
9947 @override 9960 @override
9948 ErrorSeverity get errorSeverity => ErrorSeverity.ERROR; 9961 ErrorSeverity get errorSeverity => ErrorSeverity.ERROR;
9949 9962
9950 @override 9963 @override
9951 ErrorType get type => ErrorType.SYNTACTIC_ERROR; 9964 ErrorType get type => ErrorType.SYNTACTIC_ERROR;
9952 } 9965 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/dart/ast/utilities.dart ('k') | pkg/analyzer/test/dart/ast/ast_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698