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

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

Issue 2488043002: Enable generic method support by default (Closed)
Patch Set: clean up Created 4 years, 1 month 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 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 231
232 /** 232 /**
233 * A flag indicating whether the parser is currently in a constructor field 233 * A flag indicating whether the parser is currently in a constructor field
234 * initializer, with no intervening parentheses, braces, or brackets. 234 * initializer, with no intervening parentheses, braces, or brackets.
235 */ 235 */
236 bool _inInitializer = false; 236 bool _inInitializer = false;
237 237
238 /** 238 /**
239 * A flag indicating whether the parser is to parse generic method syntax. 239 * A flag indicating whether the parser is to parse generic method syntax.
240 */ 240 */
241 @deprecated
241 bool parseGenericMethods = false; 242 bool parseGenericMethods = false;
242 243
243 /** 244 /**
244 * A flag indicating whether to parse generic method comments, of the form 245 * A flag indicating whether to parse generic method comments, of the form
245 * `/*=T*/` and `/*<T>*/`. 246 * `/*=T*/` and `/*<T>*/`.
246 */ 247 */
247 bool parseGenericMethodComments = false; 248 bool parseGenericMethodComments = false;
248 249
249 /** 250 /**
250 * Initialize a newly created parser to parse tokens in the given [_source] 251 * Initialize a newly created parser to parse tokens in the given [_source]
(...skipping 1142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1393 ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE); 1394 ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE);
1394 } 1395 }
1395 return parseInitializedIdentifierList(commentAndMetadata, 1396 return parseInitializedIdentifierList(commentAndMetadata,
1396 modifiers.staticKeyword, _validateModifiersForField(modifiers), null); 1397 modifiers.staticKeyword, _validateModifiersForField(modifiers), null);
1397 } else if (keyword == Keyword.TYPEDEF) { 1398 } else if (keyword == Keyword.TYPEDEF) {
1398 _reportErrorForCurrentToken(ParserErrorCode.TYPEDEF_IN_CLASS); 1399 _reportErrorForCurrentToken(ParserErrorCode.TYPEDEF_IN_CLASS);
1399 // TODO(brianwilkerson) We don't currently have any way to capture the 1400 // TODO(brianwilkerson) We don't currently have any way to capture the
1400 // function type alias that was parsed. 1401 // function type alias that was parsed.
1401 _parseFunctionTypeAlias(commentAndMetadata, getAndAdvance()); 1402 _parseFunctionTypeAlias(commentAndMetadata, getAndAdvance());
1402 return null; 1403 return null;
1403 } else if (parseGenericMethods) { 1404 } else {
1404 Token token = _skipTypeParameterList(_peek()); 1405 Token token = _skipTypeParameterList(_peek());
1405 if (token != null && _tokenMatches(token, TokenType.OPEN_PAREN)) { 1406 if (token != null && _tokenMatches(token, TokenType.OPEN_PAREN)) {
1406 return _parseMethodDeclarationAfterReturnType(commentAndMetadata, 1407 return _parseMethodDeclarationAfterReturnType(commentAndMetadata,
1407 modifiers.externalKeyword, modifiers.staticKeyword, null); 1408 modifiers.externalKeyword, modifiers.staticKeyword, null);
1408 } 1409 }
1409 } 1410 }
1410 TypeName type = _parseTypeNameAfterIdentifier(); 1411 TypeName type = _parseTypeNameAfterIdentifier();
1411 keyword = _currentToken.keyword; 1412 keyword = _currentToken.keyword;
1412 next = _peek(); 1413 next = _peek();
1413 isFollowedByIdentifier = _tokenMatchesIdentifier(next); 1414 isFollowedByIdentifier = _tokenMatchesIdentifier(next);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1482 _validateModifiersForGetterOrSetterOrMethod(modifiers); 1483 _validateModifiersForGetterOrSetterOrMethod(modifiers);
1483 _validateFormalParameterList(parameters); 1484 _validateFormalParameterList(parameters);
1484 return _parseMethodDeclarationAfterParameters( 1485 return _parseMethodDeclarationAfterParameters(
1485 commentAndMetadata, 1486 commentAndMetadata,
1486 modifiers.externalKeyword, 1487 modifiers.externalKeyword,
1487 modifiers.staticKeyword, 1488 modifiers.staticKeyword,
1488 type, 1489 type,
1489 methodName, 1490 methodName,
1490 typeParameters, 1491 typeParameters,
1491 parameters); 1492 parameters);
1492 } else if (parseGenericMethods && _tokenMatches(next, TokenType.LT)) { 1493 } else if (_tokenMatches(next, TokenType.LT)) {
1493 return _parseMethodDeclarationAfterReturnType(commentAndMetadata, 1494 return _parseMethodDeclarationAfterReturnType(commentAndMetadata,
1494 modifiers.externalKeyword, modifiers.staticKeyword, type); 1495 modifiers.externalKeyword, modifiers.staticKeyword, type);
1495 } else if (_tokenMatches(next, TokenType.OPEN_CURLY_BRACKET)) { 1496 } else if (_tokenMatches(next, TokenType.OPEN_CURLY_BRACKET)) {
1496 // We have found "TypeName identifier {", and are guessing that this is a 1497 // We have found "TypeName identifier {", and are guessing that this is a
1497 // getter without the keyword 'get'. 1498 // getter without the keyword 'get'.
1498 _validateModifiersForGetterOrSetterOrMethod(modifiers); 1499 _validateModifiersForGetterOrSetterOrMethod(modifiers);
1499 _reportErrorForCurrentToken(ParserErrorCode.MISSING_GET); 1500 _reportErrorForCurrentToken(ParserErrorCode.MISSING_GET);
1500 _currentToken = _injectToken( 1501 _currentToken = _injectToken(
1501 new Parser_SyntheticKeywordToken(Keyword.GET, _currentToken.offset)); 1502 new Parser_SyntheticKeywordToken(Keyword.GET, _currentToken.offset));
1502 return parseGetter(commentAndMetadata, modifiers.externalKeyword, 1503 return parseGetter(commentAndMetadata, modifiers.externalKeyword,
(...skipping 2608 matching lines...) Expand 10 before | Expand all | Expand 10 after
4111 * assignableSelector 4112 * assignableSelector
4112 * | argumentList 4113 * | argumentList
4113 */ 4114 */
4114 Expression parsePostfixExpression() { 4115 Expression parsePostfixExpression() {
4115 Expression operand = parseAssignableExpression(true); 4116 Expression operand = parseAssignableExpression(true);
4116 TokenType type = _currentToken.type; 4117 TokenType type = _currentToken.type;
4117 if (type == TokenType.OPEN_SQUARE_BRACKET || 4118 if (type == TokenType.OPEN_SQUARE_BRACKET ||
4118 type == TokenType.PERIOD || 4119 type == TokenType.PERIOD ||
4119 type == TokenType.QUESTION_PERIOD || 4120 type == TokenType.QUESTION_PERIOD ||
4120 type == TokenType.OPEN_PAREN || 4121 type == TokenType.OPEN_PAREN ||
4121 (parseGenericMethods && type == TokenType.LT) || 4122 type == TokenType.LT ||
4122 type == TokenType.INDEX) { 4123 type == TokenType.INDEX) {
4123 do { 4124 do {
4124 if (_isLikelyArgumentList()) { 4125 if (_isLikelyArgumentList()) {
4125 TypeArgumentList typeArguments = _parseOptionalTypeArguments(); 4126 TypeArgumentList typeArguments = _parseOptionalTypeArguments();
4126 ArgumentList argumentList = parseArgumentList(); 4127 ArgumentList argumentList = parseArgumentList();
4127 Expression currentOperand = operand; 4128 Expression currentOperand = operand;
4128 if (currentOperand is PropertyAccess) { 4129 if (currentOperand is PropertyAccess) {
4129 operand = new MethodInvocation( 4130 operand = new MethodInvocation(
4130 currentOperand.target, 4131 currentOperand.target,
4131 currentOperand.operator, 4132 currentOperand.operator,
(...skipping 1624 matching lines...) Expand 10 before | Expand all | Expand 10 after
5756 (0x30 <= character && character <= 0x39) || 5757 (0x30 <= character && character <= 0x39) ||
5757 (0x41 <= character && character <= 0x46) || 5758 (0x41 <= character && character <= 0x46) ||
5758 (0x61 <= character && character <= 0x66); 5759 (0x61 <= character && character <= 0x66);
5759 5760
5760 bool _isLikelyArgumentList() { 5761 bool _isLikelyArgumentList() {
5761 // Try to reduce the amount of lookahead required here before enabling 5762 // Try to reduce the amount of lookahead required here before enabling
5762 // generic methods. 5763 // generic methods.
5763 if (_matches(TokenType.OPEN_PAREN)) { 5764 if (_matches(TokenType.OPEN_PAREN)) {
5764 return true; 5765 return true;
5765 } 5766 }
5766 if (!parseGenericMethods) {
5767 return false;
5768 }
5769 Token token = skipTypeArgumentList(_currentToken); 5767 Token token = skipTypeArgumentList(_currentToken);
5770 return token != null && _tokenMatches(token, TokenType.OPEN_PAREN); 5768 return token != null && _tokenMatches(token, TokenType.OPEN_PAREN);
5771 } 5769 }
5772 5770
5773 /** 5771 /**
5774 * Given that we have just found bracketed text within the given [comment], 5772 * Given that we have just found bracketed text within the given [comment],
5775 * look to see whether that text is (a) followed by a parenthesized link 5773 * look to see whether that text is (a) followed by a parenthesized link
5776 * address, (b) followed by a colon, or (c) followed by optional whitespace 5774 * address, (b) followed by a colon, or (c) followed by optional whitespace
5777 * and another square bracket. The [rightIndex] is the index of the right 5775 * and another square bracket. The [rightIndex] is the index of the right
5778 * bracket. Return `true` if the bracketed text is followed by a link address. 5776 * bracket. Return `true` if the bracketed text is followed by a link address.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
5817 // Consume all operator tokens. 5815 // Consume all operator tokens.
5818 Token token = startToken.next; 5816 Token token = startToken.next;
5819 while (token.isOperator) { 5817 while (token.isOperator) {
5820 token = token.next; 5818 token = token.next;
5821 } 5819 }
5822 // Formal parameter list is expect now. 5820 // Formal parameter list is expect now.
5823 return _tokenMatches(token, TokenType.OPEN_PAREN); 5821 return _tokenMatches(token, TokenType.OPEN_PAREN);
5824 } 5822 }
5825 5823
5826 bool _isPeekGenericTypeParametersAndOpenParen() { 5824 bool _isPeekGenericTypeParametersAndOpenParen() {
5827 if (!parseGenericMethods) {
5828 return false;
5829 }
5830 Token token = _skipTypeParameterList(_peek()); 5825 Token token = _skipTypeParameterList(_peek());
5831 return token != null && _tokenMatches(token, TokenType.OPEN_PAREN); 5826 return token != null && _tokenMatches(token, TokenType.OPEN_PAREN);
5832 } 5827 }
5833 5828
5834 /** 5829 /**
5835 * Return `true` if the [startToken] appears to be the first token of a type 5830 * Return `true` if the [startToken] appears to be the first token of a type
5836 * name that is followed by a variable or field formal parameter. 5831 * name that is followed by a variable or field formal parameter.
5837 */ 5832 */
5838 bool _isTypedIdentifier(Token startToken) { 5833 bool _isTypedIdentifier(Token startToken) {
5839 Token token = skipReturnType(startToken); 5834 Token token = skipReturnType(startToken);
(...skipping 771 matching lines...) Expand 10 before | Expand all | Expand 10 after
6611 return null; 6606 return null;
6612 } 6607 }
6613 6608
6614 /** 6609 /**
6615 * Parse the generic method or function's type parameters. 6610 * Parse the generic method or function's type parameters.
6616 * 6611 *
6617 * For backwards compatibility this can optionally use comments. 6612 * For backwards compatibility this can optionally use comments.
6618 * See [parseGenericMethodComments]. 6613 * See [parseGenericMethodComments].
6619 */ 6614 */
6620 TypeParameterList _parseGenericMethodTypeParameters() { 6615 TypeParameterList _parseGenericMethodTypeParameters() {
6621 if (parseGenericMethods && _matches(TokenType.LT) || 6616 if (_matches(TokenType.LT) || _injectGenericCommentTypeList()) {
6622 _injectGenericCommentTypeList()) {
6623 return parseTypeParameterList(); 6617 return parseTypeParameterList();
6624 } 6618 }
6625 return null; 6619 return null;
6626 } 6620 }
6627 6621
6628 /** 6622 /**
6629 * Parse a library name. The [missingNameError] is the error code to be used 6623 * Parse a library name. The [missingNameError] is the error code to be used
6630 * if the library name is missing. The [missingNameToken] is the token 6624 * if the library name is missing. The [missingNameToken] is the token
6631 * associated with the error produced if the library name is missing. Return 6625 * associated with the error produced if the library name is missing. Return
6632 * the library name that was parsed. 6626 * the library name that was parsed.
(...skipping 1489 matching lines...) Expand 10 before | Expand all | Expand 10 after
8122 */ 8116 */
8123 Parser_SyntheticKeywordToken(Keyword keyword, int offset) 8117 Parser_SyntheticKeywordToken(Keyword keyword, int offset)
8124 : super(keyword, offset); 8118 : super(keyword, offset);
8125 8119
8126 @override 8120 @override
8127 int get length => 0; 8121 int get length => 0;
8128 8122
8129 @override 8123 @override
8130 Token copy() => new Parser_SyntheticKeywordToken(keyword, offset); 8124 Token copy() => new Parser_SyntheticKeywordToken(keyword, offset);
8131 } 8125 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/incremental_resolver.dart ('k') | pkg/analyzer/lib/src/task/dart.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698