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

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

Issue 2639883005: Add parser support for covariant parameters (Closed)
Patch Set: Created 3 years, 11 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
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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 */ 82 */
83 Token abstractKeyword; 83 Token abstractKeyword;
84 84
85 /** 85 /**
86 * The token representing the keyword 'const', or `null` if the keyword was 86 * The token representing the keyword 'const', or `null` if the keyword was
87 * not found. 87 * not found.
88 */ 88 */
89 Token constKeyword; 89 Token constKeyword;
90 90
91 /** 91 /**
92 * The token representing the keyword 'covariant', or `null` if the keyword
93 * was not found.
94 */
95 Token covariantKeyword;
96
97 /**
92 * The token representing the keyword 'external', or `null` if the keyword was 98 * The token representing the keyword 'external', or `null` if the keyword was
93 * not found. 99 * not found.
94 */ 100 */
95 Token externalKeyword; 101 Token externalKeyword;
96 102
97 /** 103 /**
98 * The token representing the keyword 'factory', or `null` if the keyword was 104 * The token representing the keyword 'factory', or `null` if the keyword was
99 * not found. 105 * not found.
100 */ 106 */
101 Token factoryKeyword; 107 Token factoryKeyword;
(...skipping 1153 matching lines...) Expand 10 before | Expand all | Expand 10 after
1255 TokenType.COMMA, 1261 TokenType.COMMA,
1256 TokenType.SEMICOLON 1262 TokenType.SEMICOLON
1257 ])) { 1263 ])) {
1258 // 1264 //
1259 // We appear to have a variable declaration with a type of "void". 1265 // We appear to have a variable declaration with a type of "void".
1260 // 1266 //
1261 _reportErrorForNode(ParserErrorCode.VOID_VARIABLE, returnType); 1267 _reportErrorForNode(ParserErrorCode.VOID_VARIABLE, returnType);
1262 return parseInitializedIdentifierList( 1268 return parseInitializedIdentifierList(
1263 commentAndMetadata, 1269 commentAndMetadata,
1264 modifiers.staticKeyword, 1270 modifiers.staticKeyword,
1271 modifiers.covariantKeyword,
1265 _validateModifiersForField(modifiers), 1272 _validateModifiersForField(modifiers),
1266 returnType); 1273 returnType);
1267 } 1274 }
1268 } 1275 }
1269 if (_isOperator(_currentToken)) { 1276 if (_isOperator(_currentToken)) {
1270 // 1277 //
1271 // We appear to have found an operator declaration without the 1278 // We appear to have found an operator declaration without the
1272 // 'operator' keyword. 1279 // 'operator' keyword.
1273 // 1280 //
1274 _validateModifiersForOperator(modifiers); 1281 _validateModifiersForOperator(modifiers);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1319 return null; 1326 return null;
1320 } else if (_isOperator(_currentToken)) { 1327 } else if (_isOperator(_currentToken)) {
1321 // 1328 //
1322 // We appear to have found an operator declaration without the 1329 // We appear to have found an operator declaration without the
1323 // 'operator' keyword. 1330 // 'operator' keyword.
1324 // 1331 //
1325 _validateModifiersForOperator(modifiers); 1332 _validateModifiersForOperator(modifiers);
1326 return parseOperator( 1333 return parseOperator(
1327 commentAndMetadata, modifiers.externalKeyword, null); 1334 commentAndMetadata, modifiers.externalKeyword, null);
1328 } 1335 }
1329 Token keyword = modifiers.varKeyword; 1336 Token keyword = modifiers.varKeyword ??
1330 if (keyword == null) { 1337 modifiers.finalKeyword ??
1331 keyword = modifiers.finalKeyword; 1338 modifiers.constKeyword;
1332 }
1333 if (keyword == null) {
1334 keyword = modifiers.constKeyword;
1335 }
1336 if (keyword != null) { 1339 if (keyword != null) {
1337 // 1340 //
1338 // We appear to have found an incomplete field declaration. 1341 // We appear to have found an incomplete field declaration.
1339 // 1342 //
1340 _reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER); 1343 _reportErrorForCurrentToken(ParserErrorCode.MISSING_IDENTIFIER);
1341 VariableDeclaration variable = astFactory.variableDeclaration( 1344 VariableDeclaration variable = astFactory.variableDeclaration(
1342 createSyntheticIdentifier(), null, null); 1345 createSyntheticIdentifier(), null, null);
1343 List<VariableDeclaration> variables = <VariableDeclaration>[variable]; 1346 List<VariableDeclaration> variables = <VariableDeclaration>[variable];
1344 return astFactory.fieldDeclaration( 1347 FieldDeclarationImpl field = astFactory.fieldDeclaration(
1345 commentAndMetadata.comment, 1348 commentAndMetadata.comment,
1346 commentAndMetadata.metadata, 1349 commentAndMetadata.metadata,
1347 null, 1350 null,
1348 astFactory.variableDeclarationList( 1351 astFactory.variableDeclarationList(
1349 null, null, keyword, null, variables), 1352 null, null, keyword, null, variables),
1350 _expect(TokenType.SEMICOLON)); 1353 _expect(TokenType.SEMICOLON));
1354 field.covariantKeyword = modifiers.covariantKeyword;
1355 return field;
1351 } 1356 }
1352 _reportErrorForToken( 1357 _reportErrorForToken(
1353 ParserErrorCode.EXPECTED_CLASS_MEMBER, _currentToken); 1358 ParserErrorCode.EXPECTED_CLASS_MEMBER, _currentToken);
1354 if (commentAndMetadata.comment != null || 1359 if (commentAndMetadata.comment != null ||
1355 commentAndMetadata.hasMetadata) { 1360 commentAndMetadata.hasMetadata) {
1356 // 1361 //
1357 // We appear to have found an incomplete declaration at the end of the 1362 // We appear to have found an incomplete declaration at the end of the
1358 // class. At this point it consists of a metadata, which we don't want 1363 // class. At this point it consists of a metadata, which we don't want
1359 // to loose, so we'll treat it as a method declaration with a missing 1364 // to loose, so we'll treat it as a method declaration with a missing
1360 // name, parameters and empty body. 1365 // name, parameters and empty body.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1419 TokenType.EQ, 1424 TokenType.EQ,
1420 TokenType.COMMA, 1425 TokenType.COMMA,
1421 TokenType.SEMICOLON 1426 TokenType.SEMICOLON
1422 ])) { 1427 ])) {
1423 if (modifiers.constKeyword == null && 1428 if (modifiers.constKeyword == null &&
1424 modifiers.finalKeyword == null && 1429 modifiers.finalKeyword == null &&
1425 modifiers.varKeyword == null) { 1430 modifiers.varKeyword == null) {
1426 _reportErrorForCurrentToken( 1431 _reportErrorForCurrentToken(
1427 ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE); 1432 ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE);
1428 } 1433 }
1429 return parseInitializedIdentifierList(commentAndMetadata, 1434 return parseInitializedIdentifierList(
1430 modifiers.staticKeyword, _validateModifiersForField(modifiers), null); 1435 commentAndMetadata,
1436 modifiers.staticKeyword,
1437 modifiers.covariantKeyword,
1438 _validateModifiersForField(modifiers),
1439 null);
1431 } else if (keyword == Keyword.TYPEDEF) { 1440 } else if (keyword == Keyword.TYPEDEF) {
1432 _reportErrorForCurrentToken(ParserErrorCode.TYPEDEF_IN_CLASS); 1441 _reportErrorForCurrentToken(ParserErrorCode.TYPEDEF_IN_CLASS);
1433 // TODO(brianwilkerson) We don't currently have any way to capture the 1442 // TODO(brianwilkerson) We don't currently have any way to capture the
1434 // function type alias that was parsed. 1443 // function type alias that was parsed.
1435 _parseFunctionTypeAlias(commentAndMetadata, getAndAdvance()); 1444 _parseFunctionTypeAlias(commentAndMetadata, getAndAdvance());
1436 return null; 1445 return null;
1437 } else { 1446 } else {
1438 Token token = _skipTypeParameterList(_peek()); 1447 Token token = _skipTypeParameterList(_peek());
1439 if (token != null && _tokenMatches(token, TokenType.OPEN_PAREN)) { 1448 if (token != null && _tokenMatches(token, TokenType.OPEN_PAREN)) {
1440 return _parseMethodDeclarationAfterReturnType(commentAndMetadata, 1449 return _parseMethodDeclarationAfterReturnType(commentAndMetadata,
(...skipping 19 matching lines...) Expand all
1460 } else if (!_matchesIdentifier()) { 1469 } else if (!_matchesIdentifier()) {
1461 if (_matches(TokenType.CLOSE_CURLY_BRACKET)) { 1470 if (_matches(TokenType.CLOSE_CURLY_BRACKET)) {
1462 // 1471 //
1463 // We appear to have found an incomplete declaration at the end of the 1472 // We appear to have found an incomplete declaration at the end of the
1464 // class. At this point it consists of a type name, so we'll treat it as 1473 // class. At this point it consists of a type name, so we'll treat it as
1465 // a field declaration with a missing field name and semicolon. 1474 // a field declaration with a missing field name and semicolon.
1466 // 1475 //
1467 return parseInitializedIdentifierList( 1476 return parseInitializedIdentifierList(
1468 commentAndMetadata, 1477 commentAndMetadata,
1469 modifiers.staticKeyword, 1478 modifiers.staticKeyword,
1479 modifiers.covariantKeyword,
1470 _validateModifiersForField(modifiers), 1480 _validateModifiersForField(modifiers),
1471 type); 1481 type);
1472 } 1482 }
1473 if (_isOperator(_currentToken)) { 1483 if (_isOperator(_currentToken)) {
1474 // 1484 //
1475 // We appear to have found an operator declaration without the 1485 // We appear to have found an operator declaration without the
1476 // 'operator' keyword. 1486 // 'operator' keyword.
1477 // 1487 //
1478 _validateModifiersForOperator(modifiers); 1488 _validateModifiersForOperator(modifiers);
1479 return parseOperator( 1489 return parseOperator(
1480 commentAndMetadata, modifiers.externalKeyword, type); 1490 commentAndMetadata, modifiers.externalKeyword, type);
1481 } 1491 }
1482 // 1492 //
1483 // We appear to have found an incomplete declaration before another 1493 // We appear to have found an incomplete declaration before another
1484 // declaration. At this point it consists of a type name, so we'll treat 1494 // declaration. At this point it consists of a type name, so we'll treat
1485 // it as a field declaration with a missing field name and semicolon. 1495 // it as a field declaration with a missing field name and semicolon.
1486 // 1496 //
1487 _reportErrorForToken( 1497 _reportErrorForToken(
1488 ParserErrorCode.EXPECTED_CLASS_MEMBER, _currentToken); 1498 ParserErrorCode.EXPECTED_CLASS_MEMBER, _currentToken);
1489 try { 1499 try {
1490 _lockErrorListener(); 1500 _lockErrorListener();
1491 return parseInitializedIdentifierList( 1501 return parseInitializedIdentifierList(
1492 commentAndMetadata, 1502 commentAndMetadata,
1493 modifiers.staticKeyword, 1503 modifiers.staticKeyword,
1504 modifiers.covariantKeyword,
1494 _validateModifiersForField(modifiers), 1505 _validateModifiersForField(modifiers),
1495 type); 1506 type);
1496 } finally { 1507 } finally {
1497 _unlockErrorListener(); 1508 _unlockErrorListener();
1498 } 1509 }
1499 } else if (_tokenMatches(next, TokenType.OPEN_PAREN)) { 1510 } else if (_tokenMatches(next, TokenType.OPEN_PAREN)) {
1500 SimpleIdentifier methodName = 1511 SimpleIdentifier methodName =
1501 _parseSimpleIdentifierUnchecked(isDeclaration: true); 1512 _parseSimpleIdentifierUnchecked(isDeclaration: true);
1502 TypeParameterList typeParameters = _parseGenericCommentTypeParameters(); 1513 TypeParameterList typeParameters = _parseGenericCommentTypeParameters();
1503 FormalParameterList parameters = parseFormalParameterList(); 1514 FormalParameterList parameters = parseFormalParameterList();
(...skipping 25 matching lines...) Expand all
1529 } else if (_tokenMatches(next, TokenType.OPEN_CURLY_BRACKET)) { 1540 } else if (_tokenMatches(next, TokenType.OPEN_CURLY_BRACKET)) {
1530 // We have found "TypeName identifier {", and are guessing that this is a 1541 // We have found "TypeName identifier {", and are guessing that this is a
1531 // getter without the keyword 'get'. 1542 // getter without the keyword 'get'.
1532 _validateModifiersForGetterOrSetterOrMethod(modifiers); 1543 _validateModifiersForGetterOrSetterOrMethod(modifiers);
1533 _reportErrorForCurrentToken(ParserErrorCode.MISSING_GET); 1544 _reportErrorForCurrentToken(ParserErrorCode.MISSING_GET);
1534 _currentToken = _injectToken( 1545 _currentToken = _injectToken(
1535 new Parser_SyntheticKeywordToken(Keyword.GET, _currentToken.offset)); 1546 new Parser_SyntheticKeywordToken(Keyword.GET, _currentToken.offset));
1536 return parseGetter(commentAndMetadata, modifiers.externalKeyword, 1547 return parseGetter(commentAndMetadata, modifiers.externalKeyword,
1537 modifiers.staticKeyword, type); 1548 modifiers.staticKeyword, type);
1538 } 1549 }
1539 return parseInitializedIdentifierList(commentAndMetadata, 1550 return parseInitializedIdentifierList(
1540 modifiers.staticKeyword, _validateModifiersForField(modifiers), type); 1551 commentAndMetadata,
1552 modifiers.staticKeyword,
1553 modifiers.covariantKeyword,
1554 _validateModifiersForField(modifiers),
1555 type);
1541 } 1556 }
1542 1557
1543 /** 1558 /**
1544 * Parse a single combinator. Return the combinator that was parsed, or `null` 1559 * Parse a single combinator. Return the combinator that was parsed, or `null`
1545 * if no combinator is found. 1560 * if no combinator is found.
1546 * 1561 *
1547 * combinator ::= 1562 * combinator ::=
1548 * 'show' identifier (',' identifier)* 1563 * 'show' identifier (',' identifier)*
1549 * | 'hide' identifier (',' identifier)* 1564 * | 'hide' identifier (',' identifier)*
1550 */ 1565 */
(...skipping 1988 matching lines...) Expand 10 before | Expand all | Expand 10 after
3539 3554
3540 /** 3555 /**
3541 * Parse a list of initialized identifiers. The [commentAndMetadata] is the 3556 * Parse a list of initialized identifiers. The [commentAndMetadata] is the
3542 * documentation comment and metadata to be associated with the declaration. 3557 * documentation comment and metadata to be associated with the declaration.
3543 * The [staticKeyword] is the static keyword, or `null` if the getter is not 3558 * The [staticKeyword] is the static keyword, or `null` if the getter is not
3544 * static. The [keyword] is the token representing the 'final', 'const' or 3559 * static. The [keyword] is the token representing the 'final', 'const' or
3545 * 'var' keyword, or `null` if there is no keyword. The [type] is the type 3560 * 'var' keyword, or `null` if there is no keyword. The [type] is the type
3546 * that has already been parsed, or `null` if 'var' was provided. Return the 3561 * that has already been parsed, or `null` if 'var' was provided. Return the
3547 * getter that was parsed. 3562 * getter that was parsed.
3548 * 3563 *
3549 * ?? ::= 3564 * declaration ::=
3550 * 'static'? ('var' | type) initializedIdentifierList ';' 3565 * ('static' | 'covariant')? ('var' | type) initializedIdentifierList ';'
3551 * | 'final' type? initializedIdentifierList ';' 3566 * | 'final' type? initializedIdentifierList ';'
3552 * 3567 *
3553 * initializedIdentifierList ::= 3568 * initializedIdentifierList ::=
3554 * initializedIdentifier (',' initializedIdentifier)* 3569 * initializedIdentifier (',' initializedIdentifier)*
3555 * 3570 *
3556 * initializedIdentifier ::= 3571 * initializedIdentifier ::=
3557 * identifier ('=' expression)? 3572 * identifier ('=' expression)?
3558 */ 3573 */
3559 FieldDeclaration parseInitializedIdentifierList( 3574 FieldDeclaration parseInitializedIdentifierList(
3560 CommentAndMetadata commentAndMetadata, 3575 CommentAndMetadata commentAndMetadata,
3561 Token staticKeyword, 3576 Token staticKeyword,
3577 Token covariantKeyword,
3562 Token keyword, 3578 Token keyword,
3563 TypeAnnotation type) { 3579 TypeAnnotation type) {
3564 VariableDeclarationList fieldList = 3580 VariableDeclarationList fieldList =
3565 parseVariableDeclarationListAfterType(null, keyword, type); 3581 parseVariableDeclarationListAfterType(null, keyword, type);
3566 return astFactory.fieldDeclaration( 3582 FieldDeclarationImpl field = astFactory.fieldDeclaration(
3567 commentAndMetadata.comment, 3583 commentAndMetadata.comment,
3568 commentAndMetadata.metadata, 3584 commentAndMetadata.metadata,
3569 staticKeyword, 3585 staticKeyword,
3570 fieldList, 3586 fieldList,
3571 _expect(TokenType.SEMICOLON)); 3587 _expect(TokenType.SEMICOLON));
3588 field.covariantKeyword = covariantKeyword;
3589 return field;
3572 } 3590 }
3573 3591
3574 /** 3592 /**
3575 * Parse an instance creation expression. The [keyword] is the 'new' or 3593 * Parse an instance creation expression. The [keyword] is the 'new' or
3576 * 'const' keyword that introduces the expression. Return the instance 3594 * 'const' keyword that introduces the expression. Return the instance
3577 * creation expression that was parsed. 3595 * creation expression that was parsed.
3578 * 3596 *
3579 * instanceCreationExpression ::= 3597 * instanceCreationExpression ::=
3580 * ('new' | 'const') type ('.' identifier)? argumentList 3598 * ('new' | 'const') type ('.' identifier)? argumentList
3581 */ 3599 */
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
3818 modifiers.abstractKeyword = getAndAdvance(); 3836 modifiers.abstractKeyword = getAndAdvance();
3819 } 3837 }
3820 } else if (keyword == Keyword.CONST) { 3838 } else if (keyword == Keyword.CONST) {
3821 if (modifiers.constKeyword != null) { 3839 if (modifiers.constKeyword != null) {
3822 _reportErrorForCurrentToken( 3840 _reportErrorForCurrentToken(
3823 ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexeme]); 3841 ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexeme]);
3824 _advance(); 3842 _advance();
3825 } else { 3843 } else {
3826 modifiers.constKeyword = getAndAdvance(); 3844 modifiers.constKeyword = getAndAdvance();
3827 } 3845 }
3846 } else if (keyword == Keyword.COVARIANT) {
3847 if (modifiers.constKeyword != null) {
3848 _reportErrorForCurrentToken(
3849 ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexeme]);
3850 _advance();
3851 } else {
3852 modifiers.covariantKeyword = getAndAdvance();
3853 }
3828 } else if (keyword == Keyword.EXTERNAL) { 3854 } else if (keyword == Keyword.EXTERNAL) {
3829 if (modifiers.externalKeyword != null) { 3855 if (modifiers.externalKeyword != null) {
3830 _reportErrorForCurrentToken( 3856 _reportErrorForCurrentToken(
3831 ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexeme]); 3857 ParserErrorCode.DUPLICATED_MODIFIER, [_currentToken.lexeme]);
3832 _advance(); 3858 _advance();
3833 } else { 3859 } else {
3834 modifiers.externalKeyword = getAndAdvance(); 3860 modifiers.externalKeyword = getAndAdvance();
3835 } 3861 }
3836 } else if (keyword == Keyword.FACTORY) { 3862 } else if (keyword == Keyword.FACTORY) {
3837 if (modifiers.factoryKeyword != null) { 3863 if (modifiers.factoryKeyword != null) {
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
4103 * 4129 *
4104 * fieldFormalParameter ::= 4130 * fieldFormalParameter ::=
4105 * metadata finalConstVarOrType? 'this' '.' identifier 4131 * metadata finalConstVarOrType? 'this' '.' identifier
4106 * 4132 *
4107 * simpleFormalParameter ::= 4133 * simpleFormalParameter ::=
4108 * declaredIdentifier 4134 * declaredIdentifier
4109 * | metadata identifier 4135 * | metadata identifier
4110 */ 4136 */
4111 NormalFormalParameter parseNormalFormalParameter( 4137 NormalFormalParameter parseNormalFormalParameter(
4112 {bool inFunctionType: false}) { 4138 {bool inFunctionType: false}) {
4139 Token covariantKeyword;
4113 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata(); 4140 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata();
4141 if (_matchesKeyword(Keyword.COVARIANT)) {
4142 covariantKeyword = getAndAdvance();
4143 }
4114 FinalConstVarOrType holder = parseFinalConstVarOrType(!inFunctionType, 4144 FinalConstVarOrType holder = parseFinalConstVarOrType(!inFunctionType,
4115 inFunctionType: inFunctionType); 4145 inFunctionType: inFunctionType);
4116 Token thisKeyword = null; 4146 Token thisKeyword = null;
4117 Token period = null; 4147 Token period = null;
4118 if (_matchesKeyword(Keyword.THIS)) { 4148 if (_matchesKeyword(Keyword.THIS)) {
4119 thisKeyword = getAndAdvance(); 4149 thisKeyword = getAndAdvance();
4120 period = _expect(TokenType.PERIOD); 4150 period = _expect(TokenType.PERIOD);
4121 } 4151 }
4122 if (!_matchesIdentifier() && inFunctionType) { 4152 if (!_matchesIdentifier() && inFunctionType) {
4123 return astFactory.simpleFormalParameter(commentAndMetadata.comment, 4153 SimpleFormalParameterImpl parameter = astFactory.simpleFormalParameter(
4124 commentAndMetadata.metadata, holder.keyword, holder.type, null); 4154 commentAndMetadata.comment,
4155 commentAndMetadata.metadata,
4156 holder.keyword,
4157 holder.type,
4158 null);
4159 parameter.covariantKeyword = covariantKeyword;
4160 return parameter;
4125 } 4161 }
4126 SimpleIdentifier identifier = parseSimpleIdentifier(); 4162 SimpleIdentifier identifier = parseSimpleIdentifier();
4127 TypeParameterList typeParameters = _parseGenericMethodTypeParameters(); 4163 TypeParameterList typeParameters = _parseGenericMethodTypeParameters();
4128 if (_matches(TokenType.OPEN_PAREN)) { 4164 if (_matches(TokenType.OPEN_PAREN)) {
4129 FormalParameterList parameters = _parseFormalParameterListUnchecked(); 4165 FormalParameterList parameters = _parseFormalParameterListUnchecked();
4130 if (thisKeyword == null) { 4166 if (thisKeyword == null) {
4131 if (holder.keyword != null) { 4167 if (holder.keyword != null) {
4132 _reportErrorForToken( 4168 _reportErrorForToken(
4133 ParserErrorCode.FUNCTION_TYPED_PARAMETER_VAR, holder.keyword); 4169 ParserErrorCode.FUNCTION_TYPED_PARAMETER_VAR, holder.keyword);
4134 } 4170 }
4135 Token question = null; 4171 Token question = null;
4136 if (enableNnbd && _matches(TokenType.QUESTION)) { 4172 if (enableNnbd && _matches(TokenType.QUESTION)) {
4137 question = getAndAdvance(); 4173 question = getAndAdvance();
4138 } 4174 }
4139 return astFactory.functionTypedFormalParameter( 4175 FunctionTypedFormalParameterImpl parameter =
4140 commentAndMetadata.comment, 4176 astFactory.functionTypedFormalParameter(
4141 commentAndMetadata.metadata, 4177 commentAndMetadata.comment,
4142 holder.type, 4178 commentAndMetadata.metadata,
4143 astFactory.simpleIdentifier(identifier.token, isDeclaration: true), 4179 holder.type,
4144 typeParameters, 4180 astFactory.simpleIdentifier(identifier.token,
4145 parameters, 4181 isDeclaration: true),
4146 question: question); 4182 typeParameters,
4183 parameters,
4184 question: question);
4185 parameter.covariantKeyword = covariantKeyword;
4186 return parameter;
4147 } else { 4187 } else {
4148 return astFactory.fieldFormalParameter( 4188 FieldFormalParameterImpl parameter = astFactory.fieldFormalParameter(
4149 commentAndMetadata.comment, 4189 commentAndMetadata.comment,
4150 commentAndMetadata.metadata, 4190 commentAndMetadata.metadata,
4151 holder.keyword, 4191 holder.keyword,
4152 holder.type, 4192 holder.type,
4153 thisKeyword, 4193 thisKeyword,
4154 period, 4194 period,
4155 identifier, 4195 identifier,
4156 typeParameters, 4196 typeParameters,
4157 parameters); 4197 parameters);
4198 parameter.covariantKeyword = covariantKeyword;
4199 return parameter;
4158 } 4200 }
4159 } else if (typeParameters != null) { 4201 } else if (typeParameters != null) {
4160 // TODO(brianwilkerson) Report an error. It looks like a function-typed 4202 // TODO(brianwilkerson) Report an error. It looks like a function-typed
4161 // parameter with no parameter list. 4203 // parameter with no parameter list.
4162 //_reportErrorForToken(ParserErrorCode.MISSING_PARAMETERS, typeParameters. endToken); 4204 //_reportErrorForToken(ParserErrorCode.MISSING_PARAMETERS, typeParameters. endToken);
4163 } 4205 }
4164 TypeAnnotation type = holder.type; 4206 TypeAnnotation type = holder.type;
4165 if (type != null) { 4207 if (type != null) {
4166 if (type is TypeName && 4208 if (type is TypeName &&
4167 _tokenMatchesKeyword(type.name.beginToken, Keyword.VOID)) { 4209 _tokenMatchesKeyword(type.name.beginToken, Keyword.VOID)) {
4168 _reportErrorForToken( 4210 _reportErrorForToken(
4169 ParserErrorCode.VOID_PARAMETER, type.name.beginToken); 4211 ParserErrorCode.VOID_PARAMETER, type.name.beginToken);
4170 } else if (holder.keyword != null && 4212 } else if (holder.keyword != null &&
4171 _tokenMatchesKeyword(holder.keyword, Keyword.VAR)) { 4213 _tokenMatchesKeyword(holder.keyword, Keyword.VAR)) {
4172 _reportErrorForToken(ParserErrorCode.VAR_AND_TYPE, holder.keyword); 4214 _reportErrorForToken(ParserErrorCode.VAR_AND_TYPE, holder.keyword);
4173 } 4215 }
4174 } 4216 }
4175 if (thisKeyword != null) { 4217 if (thisKeyword != null) {
4176 // TODO(brianwilkerson) If there are type parameters but no parameters, 4218 // TODO(brianwilkerson) If there are type parameters but no parameters,
4177 // should we create a synthetic empty parameter list here so we can 4219 // should we create a synthetic empty parameter list here so we can
4178 // capture the type parameters? 4220 // capture the type parameters?
4179 return astFactory.fieldFormalParameter( 4221 FieldFormalParameterImpl parameter = astFactory.fieldFormalParameter(
4180 commentAndMetadata.comment, 4222 commentAndMetadata.comment,
4181 commentAndMetadata.metadata, 4223 commentAndMetadata.metadata,
4182 holder.keyword, 4224 holder.keyword,
4183 type, 4225 type,
4184 thisKeyword, 4226 thisKeyword,
4185 period, 4227 period,
4186 identifier, 4228 identifier,
4187 null, 4229 null,
4188 null); 4230 null);
4231 parameter.covariantKeyword = covariantKeyword;
4232 return parameter;
4189 } 4233 }
4190 return astFactory.simpleFormalParameter( 4234 SimpleFormalParameterImpl parameter = astFactory.simpleFormalParameter(
4191 commentAndMetadata.comment, 4235 commentAndMetadata.comment,
4192 commentAndMetadata.metadata, 4236 commentAndMetadata.metadata,
4193 holder.keyword, 4237 holder.keyword,
4194 type, 4238 type,
4195 astFactory.simpleIdentifier(identifier.token, isDeclaration: true)); 4239 astFactory.simpleIdentifier(identifier.token, isDeclaration: true));
4240 parameter.covariantKeyword = covariantKeyword;
4241 return parameter;
4196 } 4242 }
4197 4243
4198 /** 4244 /**
4199 * Parse an operator declaration. The [commentAndMetadata] is the 4245 * Parse an operator declaration. The [commentAndMetadata] is the
4200 * documentation comment and metadata to be associated with the declaration. 4246 * documentation comment and metadata to be associated with the declaration.
4201 * The [externalKeyword] is the 'external' token. The [returnType] is the 4247 * The [externalKeyword] is the 'external' token. The [returnType] is the
4202 * return type that has already been parsed, or `null` if there was no return 4248 * return type that has already been parsed, or `null` if there was no return
4203 * type. Return the operator declaration that was parsed. 4249 * type. Return the operator declaration that was parsed.
4204 * 4250 *
4205 * operatorDeclaration ::= 4251 * operatorDeclaration ::=
(...skipping 3919 matching lines...) Expand 10 before | Expand all | Expand 10 after
8125 8171
8126 /** 8172 /**
8127 * Validate that the given set of [modifiers] is appropriate for a constructor 8173 * Validate that the given set of [modifiers] is appropriate for a constructor
8128 * and return the 'const' keyword if there is one. 8174 * and return the 'const' keyword if there is one.
8129 */ 8175 */
8130 Token _validateModifiersForConstructor(Modifiers modifiers) { 8176 Token _validateModifiersForConstructor(Modifiers modifiers) {
8131 if (modifiers.abstractKeyword != null) { 8177 if (modifiers.abstractKeyword != null) {
8132 _reportErrorForToken( 8178 _reportErrorForToken(
8133 ParserErrorCode.ABSTRACT_CLASS_MEMBER, modifiers.abstractKeyword); 8179 ParserErrorCode.ABSTRACT_CLASS_MEMBER, modifiers.abstractKeyword);
8134 } 8180 }
8181 if (modifiers.covariantKeyword != null) {
8182 _reportErrorForToken(
8183 ParserErrorCode.COVARIANT_CONSTRUCTOR, modifiers.covariantKeyword);
8184 }
8135 if (modifiers.finalKeyword != null) { 8185 if (modifiers.finalKeyword != null) {
8136 _reportErrorForToken( 8186 _reportErrorForToken(
8137 ParserErrorCode.FINAL_CONSTRUCTOR, modifiers.finalKeyword); 8187 ParserErrorCode.FINAL_CONSTRUCTOR, modifiers.finalKeyword);
8138 } 8188 }
8139 if (modifiers.staticKeyword != null) { 8189 if (modifiers.staticKeyword != null) {
8140 _reportErrorForToken( 8190 _reportErrorForToken(
8141 ParserErrorCode.STATIC_CONSTRUCTOR, modifiers.staticKeyword); 8191 ParserErrorCode.STATIC_CONSTRUCTOR, modifiers.staticKeyword);
8142 } 8192 }
8143 if (modifiers.varKeyword != null) { 8193 if (modifiers.varKeyword != null) {
8144 _reportErrorForToken( 8194 _reportErrorForToken(
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
8197 } 8247 }
8198 if (modifiers.externalKeyword != null) { 8248 if (modifiers.externalKeyword != null) {
8199 _reportErrorForToken( 8249 _reportErrorForToken(
8200 ParserErrorCode.EXTERNAL_FIELD, modifiers.externalKeyword); 8250 ParserErrorCode.EXTERNAL_FIELD, modifiers.externalKeyword);
8201 } 8251 }
8202 if (modifiers.factoryKeyword != null) { 8252 if (modifiers.factoryKeyword != null) {
8203 _reportErrorForToken( 8253 _reportErrorForToken(
8204 ParserErrorCode.NON_CONSTRUCTOR_FACTORY, modifiers.factoryKeyword); 8254 ParserErrorCode.NON_CONSTRUCTOR_FACTORY, modifiers.factoryKeyword);
8205 } 8255 }
8206 Token staticKeyword = modifiers.staticKeyword; 8256 Token staticKeyword = modifiers.staticKeyword;
8257 Token covariantKeyword = modifiers.covariantKeyword;
8207 Token constKeyword = modifiers.constKeyword; 8258 Token constKeyword = modifiers.constKeyword;
8208 Token finalKeyword = modifiers.finalKeyword; 8259 Token finalKeyword = modifiers.finalKeyword;
8209 Token varKeyword = modifiers.varKeyword; 8260 Token varKeyword = modifiers.varKeyword;
8210 if (constKeyword != null) { 8261 if (constKeyword != null) {
8262 if (covariantKeyword != null) {
8263 _reportErrorForToken(
8264 ParserErrorCode.CONST_AND_COVARIANT, covariantKeyword);
8265 }
8211 if (finalKeyword != null) { 8266 if (finalKeyword != null) {
8212 _reportErrorForToken(ParserErrorCode.CONST_AND_FINAL, finalKeyword); 8267 _reportErrorForToken(ParserErrorCode.CONST_AND_FINAL, finalKeyword);
8213 } 8268 }
8214 if (varKeyword != null) { 8269 if (varKeyword != null) {
8215 _reportErrorForToken(ParserErrorCode.CONST_AND_VAR, varKeyword); 8270 _reportErrorForToken(ParserErrorCode.CONST_AND_VAR, varKeyword);
8216 } 8271 }
8217 if (staticKeyword != null && constKeyword.offset < staticKeyword.offset) { 8272 if (staticKeyword != null && constKeyword.offset < staticKeyword.offset) {
8218 _reportErrorForToken(ParserErrorCode.STATIC_AFTER_CONST, staticKeyword); 8273 _reportErrorForToken(ParserErrorCode.STATIC_AFTER_CONST, staticKeyword);
8219 } 8274 }
8220 } else if (finalKeyword != null) { 8275 } else if (finalKeyword != null) {
8276 if (covariantKeyword != null) {
8277 _reportErrorForToken(
8278 ParserErrorCode.FINAL_AND_COVARIANT, covariantKeyword);
8279 }
8221 if (varKeyword != null) { 8280 if (varKeyword != null) {
8222 _reportErrorForToken(ParserErrorCode.FINAL_AND_VAR, varKeyword); 8281 _reportErrorForToken(ParserErrorCode.FINAL_AND_VAR, varKeyword);
8223 } 8282 }
8224 if (staticKeyword != null && finalKeyword.offset < staticKeyword.offset) { 8283 if (staticKeyword != null && finalKeyword.offset < staticKeyword.offset) {
8225 _reportErrorForToken(ParserErrorCode.STATIC_AFTER_FINAL, staticKeyword); 8284 _reportErrorForToken(ParserErrorCode.STATIC_AFTER_FINAL, staticKeyword);
8226 } 8285 }
8227 } else if (varKeyword != null && 8286 } else if (varKeyword != null) {
8228 staticKeyword != null && 8287 if (staticKeyword != null && varKeyword.offset < staticKeyword.offset) {
8229 varKeyword.offset < staticKeyword.offset) { 8288 _reportErrorForToken(ParserErrorCode.STATIC_AFTER_VAR, staticKeyword);
8230 _reportErrorForToken(ParserErrorCode.STATIC_AFTER_VAR, staticKeyword); 8289 }
8290 if (covariantKeyword != null &&
8291 varKeyword.offset < covariantKeyword.offset) {
8292 _reportErrorForToken(
8293 ParserErrorCode.COVARIANT_AFTER_VAR, covariantKeyword);
8294 }
8295 }
8296 if (covariantKeyword != null && staticKeyword != null) {
8297 _reportErrorForToken(ParserErrorCode.COVARIANT_AND_STATIC, staticKeyword);
8231 } 8298 }
8232 return Token.lexicallyFirst([constKeyword, finalKeyword, varKeyword]); 8299 return Token.lexicallyFirst([constKeyword, finalKeyword, varKeyword]);
8233 } 8300 }
8234 8301
8235 /** 8302 /**
8236 * Validate that the given set of [modifiers] is appropriate for a local 8303 * Validate that the given set of [modifiers] is appropriate for a local
8237 * function. 8304 * function.
8238 */ 8305 */
8239 void _validateModifiersForFunctionDeclarationStatement(Modifiers modifiers) { 8306 void _validateModifiersForFunctionDeclarationStatement(Modifiers modifiers) {
8240 if (modifiers.abstractKeyword != null || 8307 if (modifiers.abstractKeyword != null ||
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
8311 _reportErrorForToken( 8378 _reportErrorForToken(
8312 ParserErrorCode.VAR_RETURN_TYPE, modifiers.varKeyword); 8379 ParserErrorCode.VAR_RETURN_TYPE, modifiers.varKeyword);
8313 } 8380 }
8314 } 8381 }
8315 8382
8316 /** 8383 /**
8317 * Validate that the given set of [modifiers] is appropriate for a top-level 8384 * Validate that the given set of [modifiers] is appropriate for a top-level
8318 * declaration. 8385 * declaration.
8319 */ 8386 */
8320 void _validateModifiersForTopLevelDeclaration(Modifiers modifiers) { 8387 void _validateModifiersForTopLevelDeclaration(Modifiers modifiers) {
8388 if (modifiers.covariantKeyword != null) {
8389 _reportErrorForToken(ParserErrorCode.COVARIANT_TOP_LEVEL_DECLARATION,
8390 modifiers.covariantKeyword);
8391 }
8321 if (modifiers.factoryKeyword != null) { 8392 if (modifiers.factoryKeyword != null) {
8322 _reportErrorForToken(ParserErrorCode.FACTORY_TOP_LEVEL_DECLARATION, 8393 _reportErrorForToken(ParserErrorCode.FACTORY_TOP_LEVEL_DECLARATION,
8323 modifiers.factoryKeyword); 8394 modifiers.factoryKeyword);
8324 } 8395 }
8325 if (modifiers.staticKeyword != null) { 8396 if (modifiers.staticKeyword != null) {
8326 _reportErrorForToken(ParserErrorCode.STATIC_TOP_LEVEL_DECLARATION, 8397 _reportErrorForToken(ParserErrorCode.STATIC_TOP_LEVEL_DECLARATION,
8327 modifiers.staticKeyword); 8398 modifiers.staticKeyword);
8328 } 8399 }
8329 } 8400 }
8330 8401
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
8418 */ 8489 */
8419 Parser_SyntheticKeywordToken(Keyword keyword, int offset) 8490 Parser_SyntheticKeywordToken(Keyword keyword, int offset)
8420 : super(keyword, offset); 8491 : super(keyword, offset);
8421 8492
8422 @override 8493 @override
8423 int get length => 0; 8494 int get length => 0;
8424 8495
8425 @override 8496 @override
8426 Token copy() => new Parser_SyntheticKeywordToken(keyword, offset); 8497 Token copy() => new Parser_SyntheticKeywordToken(keyword, offset);
8427 } 8498 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/error_verifier.dart ('k') | pkg/analyzer/test/generated/parser_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698