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

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

Issue 2640963003: Disable generic function types (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
« 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 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 */ 236 */
237 bool _inSwitch = false; 237 bool _inSwitch = false;
238 238
239 /** 239 /**
240 * A flag indicating whether the parser is currently in a constructor field 240 * A flag indicating whether the parser is currently in a constructor field
241 * initializer, with no intervening parentheses, braces, or brackets. 241 * initializer, with no intervening parentheses, braces, or brackets.
242 */ 242 */
243 bool _inInitializer = false; 243 bool _inInitializer = false;
244 244
245 /** 245 /**
246 * A flag indicating whether the parser is to parse generic function type
247 * syntax.
248 */
249 bool parseGenericFunctionTypes = false;
250
251 /**
246 * A flag indicating whether the parser is to parse generic method syntax. 252 * A flag indicating whether the parser is to parse generic method syntax.
247 */ 253 */
248 @deprecated 254 @deprecated
249 bool parseGenericMethods = false; 255 bool parseGenericMethods = false;
250 256
251 /** 257 /**
252 * A flag indicating whether to parse generic method comments, of the form 258 * A flag indicating whether to parse generic method comments, of the form
253 * `/*=T*/` and `/*<T>*/`. 259 * `/*=T*/` and `/*<T>*/`.
254 */ 260 */
255 bool parseGenericMethodComments = false; 261 bool parseGenericMethodComments = false;
(...skipping 4730 matching lines...) Expand 10 before | Expand all | Expand 10 after
4986 } 4992 }
4987 4993
4988 /** 4994 /**
4989 * Parse a type. 4995 * Parse a type.
4990 * 4996 *
4991 * type ::= 4997 * type ::=
4992 * typeWithoutFunction 4998 * typeWithoutFunction
4993 * | functionType 4999 * | functionType
4994 */ 5000 */
4995 TypeAnnotation parseTypeAnnotation(bool inExpression) { 5001 TypeAnnotation parseTypeAnnotation(bool inExpression) {
4996 TypeAnnotation type = null; 5002 if (parseGenericFunctionTypes) {
4997 if (_atGenericFunctionTypeAfterReturnType(_currentToken)) { 5003 TypeAnnotation type = null;
4998 // Generic function type with no return type. 5004 if (_atGenericFunctionTypeAfterReturnType(_currentToken)) {
4999 type = parseGenericFunctionTypeAfterReturnType(null); 5005 // Generic function type with no return type.
5000 } else if (_currentToken.keyword == Keyword.VOID && 5006 type = parseGenericFunctionTypeAfterReturnType(null);
5001 _atGenericFunctionTypeAfterReturnType(_currentToken.next)) { 5007 } else if (_currentToken.keyword == Keyword.VOID &&
5002 type = astFactory.typeName( 5008 _atGenericFunctionTypeAfterReturnType(_currentToken.next)) {
5003 astFactory.simpleIdentifier(getAndAdvance()), null); 5009 type = astFactory.typeName(
5004 } else { 5010 astFactory.simpleIdentifier(getAndAdvance()), null);
5005 type = parseTypeName(inExpression); 5011 } else {
5012 type = parseTypeName(inExpression);
5013 }
5014 while (_atGenericFunctionTypeAfterReturnType(_currentToken)) {
5015 type = parseGenericFunctionTypeAfterReturnType(type);
5016 }
5017 return type;
5006 } 5018 }
5007 while (_atGenericFunctionTypeAfterReturnType(_currentToken)) { 5019 return parseTypeName(inExpression);
5008 type = parseGenericFunctionTypeAfterReturnType(type);
5009 }
5010 return type;
5011 } 5020 }
5012 5021
5013 /** 5022 /**
5014 * Parse a list of type arguments. Return the type argument list that was 5023 * Parse a list of type arguments. Return the type argument list that was
5015 * parsed. 5024 * parsed.
5016 * 5025 *
5017 * This method assumes that the current token matches `TokenType.LT`. 5026 * This method assumes that the current token matches `TokenType.LT`.
5018 * 5027 *
5019 * typeArguments ::= 5028 * typeArguments ::=
5020 * '<' typeList '>' 5029 * '<' typeList '>'
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
5461 5470
5462 /** 5471 /**
5463 * Parse a type annotation, starting at the [startToken], without actually 5472 * Parse a type annotation, starting at the [startToken], without actually
5464 * creating a type annotation or changing the current token. Return the token 5473 * creating a type annotation or changing the current token. Return the token
5465 * following the type annotation that was parsed, or `null` if the given token 5474 * following the type annotation that was parsed, or `null` if the given token
5466 * is not the first token in a valid type annotation. 5475 * is not the first token in a valid type annotation.
5467 * 5476 *
5468 * This method must be kept in sync with [parseTypeAnnotation]. 5477 * This method must be kept in sync with [parseTypeAnnotation].
5469 */ 5478 */
5470 Token skipTypeAnnotation(Token startToken) { 5479 Token skipTypeAnnotation(Token startToken) {
5471 Token next = null; 5480 if (parseGenericFunctionTypes) {
5472 if (_atGenericFunctionTypeAfterReturnType(startToken)) { 5481 Token next = null;
5473 next = skipGenericFunctionTypeAfterReturnType(startToken); 5482 if (_atGenericFunctionTypeAfterReturnType(startToken)) {
5474 } else if (_currentToken.keyword == Keyword.VOID && 5483 next = skipGenericFunctionTypeAfterReturnType(startToken);
5475 _atGenericFunctionTypeAfterReturnType(_currentToken.next)) { 5484 } else if (_currentToken.keyword == Keyword.VOID &&
5476 next = next.next; 5485 _atGenericFunctionTypeAfterReturnType(_currentToken.next)) {
5477 } else { 5486 next = next.next;
5478 next = skipTypeName(startToken); 5487 } else {
5488 next = skipTypeName(startToken);
5489 }
5490 while (next != null && _tokenMatchesString(next, 'Function')) {
5491 next = skipGenericFunctionTypeAfterReturnType(next);
5492 }
5493 return next;
5479 } 5494 }
5480 while (next != null && _tokenMatchesString(next, 'Function')) { 5495 return skipTypeName(startToken);
5481 next = skipGenericFunctionTypeAfterReturnType(next);
5482 }
5483 return next;
5484 } 5496 }
5485 5497
5486 /** 5498 /**
5487 * Parse a list of type arguments, starting at the [startToken], without 5499 * Parse a list of type arguments, starting at the [startToken], without
5488 * actually creating a type argument list or changing the current token. 5500 * actually creating a type argument list or changing the current token.
5489 * Return the token following the type argument list that was parsed, or 5501 * Return the token following the type argument list that was parsed, or
5490 * `null` if the given token is not the first token in a valid type argument 5502 * `null` if the given token is not the first token in a valid type argument
5491 * list. 5503 * list.
5492 * 5504 *
5493 * This method must be kept in sync with [parseTypeArgumentList]. 5505 * This method must be kept in sync with [parseTypeArgumentList].
(...skipping 2912 matching lines...) Expand 10 before | Expand all | Expand 10 after
8406 */ 8418 */
8407 Parser_SyntheticKeywordToken(Keyword keyword, int offset) 8419 Parser_SyntheticKeywordToken(Keyword keyword, int offset)
8408 : super(keyword, offset); 8420 : super(keyword, offset);
8409 8421
8410 @override 8422 @override
8411 int get length => 0; 8423 int get length => 0;
8412 8424
8413 @override 8425 @override
8414 Token copy() => new Parser_SyntheticKeywordToken(keyword, offset); 8426 Token copy() => new Parser_SyntheticKeywordToken(keyword, offset);
8415 } 8427 }
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