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

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

Issue 1674043002: Fix confusion between parameters vs arguments in parser. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 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 | « no previous file | pkg/analyzer/test/generated/parser_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 4153 matching lines...) Expand 10 before | Expand all | Expand 10 after
4164 if (type == TokenType.CLOSE_CURLY_BRACKET || 4164 if (type == TokenType.CLOSE_CURLY_BRACKET ||
4165 type == TokenType.KEYWORD || 4165 type == TokenType.KEYWORD ||
4166 type == TokenType.IDENTIFIER || 4166 type == TokenType.IDENTIFIER ||
4167 type == TokenType.OPEN_CURLY_BRACKET) { 4167 type == TokenType.OPEN_CURLY_BRACKET) {
4168 return true; 4168 return true;
4169 } 4169 }
4170 } 4170 }
4171 return false; 4171 return false;
4172 } 4172 }
4173 4173
4174 bool _isLikelyParameterList() { 4174 bool _isLikelyArgumentList() {
4175 if (_matches(TokenType.OPEN_PAREN)) { 4175 if (_matches(TokenType.OPEN_PAREN)) {
4176 return true; 4176 return true;
4177 } 4177 }
4178 if (!parseGenericMethods) { 4178 if (!parseGenericMethods) {
4179 return false; 4179 return false;
4180 } 4180 }
4181 Token token = _skipTypeArgumentList(_currentToken); 4181 Token token = _skipTypeArgumentList(_currentToken);
4182 return token != null && _tokenMatches(token, TokenType.OPEN_PAREN); 4182 return token != null && _tokenMatches(token, TokenType.OPEN_PAREN);
4183 } 4183 }
4184 4184
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
4232 token = token.next; 4232 token = token.next;
4233 } 4233 }
4234 // Formal parameter list is expect now. 4234 // Formal parameter list is expect now.
4235 return _tokenMatches(token, TokenType.OPEN_PAREN); 4235 return _tokenMatches(token, TokenType.OPEN_PAREN);
4236 } 4236 }
4237 4237
4238 bool _isPeekGenericTypeParametersAndOpenParen() { 4238 bool _isPeekGenericTypeParametersAndOpenParen() {
4239 if (!parseGenericMethods) { 4239 if (!parseGenericMethods) {
4240 return false; 4240 return false;
4241 } 4241 }
4242 Token token = _skipTypeArgumentList(_peek()); 4242 Token token = _skipTypeParameterList(_peek());
4243 return token != null && _tokenMatches(token, TokenType.OPEN_PAREN); 4243 return token != null && _tokenMatches(token, TokenType.OPEN_PAREN);
4244 } 4244 }
4245 4245
4246 /** 4246 /**
4247 * Return `true` if the current token appears to be the beginning of a switch 4247 * Return `true` if the current token appears to be the beginning of a switch
4248 * member. 4248 * member.
4249 */ 4249 */
4250 bool _isSwitchMember() { 4250 bool _isSwitchMember() {
4251 Token token = _currentToken; 4251 Token token = _currentToken;
4252 while (_tokenMatches(token, TokenType.IDENTIFIER) && 4252 while (_tokenMatches(token, TokenType.IDENTIFIER) &&
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
4452 allowConditional: false); 4452 allowConditional: false);
4453 } 4453 }
4454 // 4454 //
4455 // A primary expression can start with an identifier. We resolve the 4455 // A primary expression can start with an identifier. We resolve the
4456 // ambiguity by determining whether the primary consists of anything other 4456 // ambiguity by determining whether the primary consists of anything other
4457 // than an identifier and/or is followed by an assignableSelector. 4457 // than an identifier and/or is followed by an assignableSelector.
4458 // 4458 //
4459 Expression expression = _parsePrimaryExpression(); 4459 Expression expression = _parsePrimaryExpression();
4460 bool isOptional = primaryAllowed || expression is SimpleIdentifier; 4460 bool isOptional = primaryAllowed || expression is SimpleIdentifier;
4461 while (true) { 4461 while (true) {
4462 while (_isLikelyParameterList()) { 4462 while (_isLikelyArgumentList()) {
4463 TypeArgumentList typeArguments = _parseOptionalTypeArguments(); 4463 TypeArgumentList typeArguments = _parseOptionalTypeArguments();
4464 ArgumentList argumentList = parseArgumentList(); 4464 ArgumentList argumentList = parseArgumentList();
4465 if (expression is SimpleIdentifier) { 4465 if (expression is SimpleIdentifier) {
4466 expression = new MethodInvocation(null, null, 4466 expression = new MethodInvocation(null, null,
4467 expression as SimpleIdentifier, typeArguments, argumentList); 4467 expression as SimpleIdentifier, typeArguments, argumentList);
4468 } else if (expression is PrefixedIdentifier) { 4468 } else if (expression is PrefixedIdentifier) {
4469 PrefixedIdentifier identifier = expression as PrefixedIdentifier; 4469 PrefixedIdentifier identifier = expression as PrefixedIdentifier;
4470 expression = new MethodInvocation( 4470 expression = new MethodInvocation(
4471 identifier.prefix, 4471 identifier.prefix,
4472 identifier.period, 4472 identifier.period,
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
4660 } finally { 4660 } finally {
4661 _inInitializer = wasInInitializer; 4661 _inInitializer = wasInInitializer;
4662 } 4662 }
4663 } else { 4663 } else {
4664 _reportErrorForToken(ParserErrorCode.MISSING_IDENTIFIER, _currentToken, 4664 _reportErrorForToken(ParserErrorCode.MISSING_IDENTIFIER, _currentToken,
4665 [_currentToken.lexeme]); 4665 [_currentToken.lexeme]);
4666 functionName = _createSyntheticIdentifier(); 4666 functionName = _createSyntheticIdentifier();
4667 } 4667 }
4668 assert((expression == null && functionName != null) || 4668 assert((expression == null && functionName != null) ||
4669 (expression != null && functionName == null)); 4669 (expression != null && functionName == null));
4670 if (_isLikelyParameterList()) { 4670 if (_isLikelyArgumentList()) {
4671 while (_isLikelyParameterList()) { 4671 while (_isLikelyArgumentList()) {
4672 TypeArgumentList typeArguments = _parseOptionalTypeArguments(); 4672 TypeArgumentList typeArguments = _parseOptionalTypeArguments();
4673 if (functionName != null) { 4673 if (functionName != null) {
4674 expression = new MethodInvocation(expression, period, functionName, 4674 expression = new MethodInvocation(expression, period, functionName,
4675 typeArguments, parseArgumentList()); 4675 typeArguments, parseArgumentList());
4676 period = null; 4676 period = null;
4677 functionName = null; 4677 functionName = null;
4678 } else if (expression == null) { 4678 } else if (expression == null) {
4679 // It should not be possible to get here. 4679 // It should not be possible to get here.
4680 expression = new MethodInvocation(expression, period, 4680 expression = new MethodInvocation(expression, period,
4681 _createSyntheticIdentifier(), typeArguments, parseArgumentList()); 4681 _createSyntheticIdentifier(), typeArguments, parseArgumentList());
4682 } else { 4682 } else {
4683 expression = new FunctionExpressionInvocation( 4683 expression = new FunctionExpressionInvocation(
4684 expression, typeArguments, parseArgumentList()); 4684 expression, typeArguments, parseArgumentList());
4685 } 4685 }
4686 } 4686 }
4687 } else if (functionName != null) { 4687 } else if (functionName != null) {
4688 expression = new PropertyAccess(expression, period, functionName); 4688 expression = new PropertyAccess(expression, period, functionName);
4689 period = null; 4689 period = null;
4690 } 4690 }
4691 assert(expression != null); 4691 assert(expression != null);
4692 bool progress = true; 4692 bool progress = true;
4693 while (progress) { 4693 while (progress) {
4694 progress = false; 4694 progress = false;
4695 Expression selector = _parseAssignableSelector(expression, true); 4695 Expression selector = _parseAssignableSelector(expression, true);
4696 if (!identical(selector, expression)) { 4696 if (!identical(selector, expression)) {
4697 expression = selector; 4697 expression = selector;
4698 progress = true; 4698 progress = true;
4699 while (_isLikelyParameterList()) { 4699 while (_isLikelyArgumentList()) {
4700 TypeArgumentList typeArguments = _parseOptionalTypeArguments(); 4700 TypeArgumentList typeArguments = _parseOptionalTypeArguments();
4701 if (expression is PropertyAccess) { 4701 if (expression is PropertyAccess) {
4702 PropertyAccess propertyAccess = expression as PropertyAccess; 4702 PropertyAccess propertyAccess = expression as PropertyAccess;
4703 expression = new MethodInvocation( 4703 expression = new MethodInvocation(
4704 propertyAccess.target, 4704 propertyAccess.target,
4705 propertyAccess.operator, 4705 propertyAccess.operator,
4706 propertyAccess.propertyName, 4706 propertyAccess.propertyName,
4707 typeArguments, 4707 typeArguments,
4708 parseArgumentList()); 4708 parseArgumentList());
4709 } else { 4709 } else {
(...skipping 2587 matching lines...) Expand 10 before | Expand all | Expand 10 after
7297 * | argumentList 7297 * | argumentList
7298 */ 7298 */
7299 Expression _parsePostfixExpression() { 7299 Expression _parsePostfixExpression() {
7300 Expression operand = _parseAssignableExpression(true); 7300 Expression operand = _parseAssignableExpression(true);
7301 if (_matches(TokenType.OPEN_SQUARE_BRACKET) || 7301 if (_matches(TokenType.OPEN_SQUARE_BRACKET) ||
7302 _matches(TokenType.PERIOD) || 7302 _matches(TokenType.PERIOD) ||
7303 _matches(TokenType.QUESTION_PERIOD) || 7303 _matches(TokenType.QUESTION_PERIOD) ||
7304 _matches(TokenType.OPEN_PAREN) || 7304 _matches(TokenType.OPEN_PAREN) ||
7305 (parseGenericMethods && _matches(TokenType.LT))) { 7305 (parseGenericMethods && _matches(TokenType.LT))) {
7306 do { 7306 do {
7307 if (_isLikelyParameterList()) { 7307 if (_isLikelyArgumentList()) {
7308 TypeArgumentList typeArguments = _parseOptionalTypeArguments(); 7308 TypeArgumentList typeArguments = _parseOptionalTypeArguments();
7309 ArgumentList argumentList = parseArgumentList(); 7309 ArgumentList argumentList = parseArgumentList();
7310 if (operand is PropertyAccess) { 7310 if (operand is PropertyAccess) {
7311 PropertyAccess access = operand as PropertyAccess; 7311 PropertyAccess access = operand as PropertyAccess;
7312 operand = new MethodInvocation(access.target, access.operator, 7312 operand = new MethodInvocation(access.target, access.operator,
7313 access.propertyName, typeArguments, argumentList); 7313 access.propertyName, typeArguments, argumentList);
7314 } else { 7314 } else {
7315 operand = new FunctionExpressionInvocation( 7315 operand = new FunctionExpressionInvocation(
7316 operand, typeArguments, argumentList); 7316 operand, typeArguments, argumentList);
7317 } 7317 }
(...skipping 2092 matching lines...) Expand 10 before | Expand all | Expand 10 after
9410 9410
9411 static const ParserErrorCode CONST_CLASS = const ParserErrorCode( 9411 static const ParserErrorCode CONST_CLASS = const ParserErrorCode(
9412 'CONST_CLASS', "Classes cannot be declared to be 'const'"); 9412 'CONST_CLASS', "Classes cannot be declared to be 'const'");
9413 9413
9414 static const ParserErrorCode CONST_CONSTRUCTOR_WITH_BODY = 9414 static const ParserErrorCode CONST_CONSTRUCTOR_WITH_BODY =
9415 shared_messages.CONST_CONSTRUCTOR_WITH_BODY; 9415 shared_messages.CONST_CONSTRUCTOR_WITH_BODY;
9416 9416
9417 static const ParserErrorCode CONST_ENUM = const ParserErrorCode( 9417 static const ParserErrorCode CONST_ENUM = const ParserErrorCode(
9418 'CONST_ENUM', "Enums cannot be declared to be 'const'"); 9418 'CONST_ENUM', "Enums cannot be declared to be 'const'");
9419 9419
9420 static const ParserErrorCode CONST_FACTORY = 9420 static const ParserErrorCode CONST_FACTORY = shared_messages.CONST_FACTORY;
9421 shared_messages.CONST_FACTORY;
9422 9421
9423 static const ParserErrorCode CONST_METHOD = const ParserErrorCode( 9422 static const ParserErrorCode CONST_METHOD = const ParserErrorCode(
9424 'CONST_METHOD', 9423 'CONST_METHOD',
9425 "Getters, setters and methods cannot be declared to be 'const'"); 9424 "Getters, setters and methods cannot be declared to be 'const'");
9426 9425
9427 static const ParserErrorCode CONST_TYPEDEF = const ParserErrorCode( 9426 static const ParserErrorCode CONST_TYPEDEF = const ParserErrorCode(
9428 'CONST_TYPEDEF', "Type aliases cannot be declared to be 'const'"); 9427 'CONST_TYPEDEF', "Type aliases cannot be declared to be 'const'");
9429 9428
9430 static const ParserErrorCode CONSTRUCTOR_WITH_RETURN_TYPE = 9429 static const ParserErrorCode CONSTRUCTOR_WITH_RETURN_TYPE =
9431 const ParserErrorCode('CONSTRUCTOR_WITH_RETURN_TYPE', 9430 const ParserErrorCode('CONSTRUCTOR_WITH_RETURN_TYPE',
(...skipping 1927 matching lines...) Expand 10 before | Expand all | Expand 10 after
11359 } 11358 }
11360 11359
11361 /** 11360 /**
11362 * Copy resolution data from the [fromNode] to the [toNode]. 11361 * Copy resolution data from the [fromNode] to the [toNode].
11363 */ 11362 */
11364 static void copyResolutionData(AstNode fromNode, AstNode toNode) { 11363 static void copyResolutionData(AstNode fromNode, AstNode toNode) {
11365 ResolutionCopier copier = new ResolutionCopier(); 11364 ResolutionCopier copier = new ResolutionCopier();
11366 copier._isEqualNodes(fromNode, toNode); 11365 copier._isEqualNodes(fromNode, toNode);
11367 } 11366 }
11368 } 11367 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/parser_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698