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

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

Issue 1212683002: AST changes necessary for generic method support (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 6 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 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine.parser; 8 library engine.parser;
9 9
10 import 'dart:collection';
10 import "dart:math" as math; 11 import "dart:math" as math;
11 import 'dart:collection';
12 12
13 import 'ast.dart'; 13 import 'ast.dart';
14 import 'engine.dart' show AnalysisEngine, AnalysisOptionsImpl; 14 import 'engine.dart' show AnalysisEngine, AnalysisOptionsImpl;
15 import 'error.dart'; 15 import 'error.dart';
16 import 'java_core.dart'; 16 import 'java_core.dart';
17 import 'java_engine.dart'; 17 import 'java_engine.dart';
18 import 'scanner.dart'; 18 import 'scanner.dart';
19 import 'source.dart'; 19 import 'source.dart';
20 import 'utilities_collection.dart' show TokenMap; 20 import 'utilities_collection.dart' show TokenMap;
21 import 'utilities_dart.dart'; 21 import 'utilities_dart.dart';
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 'parseLibraryName_2': new MethodTrampoline( 256 'parseLibraryName_2': new MethodTrampoline(
257 2, (Parser target, arg0, arg1) => target._parseLibraryName(arg0, arg1)), 257 2, (Parser target, arg0, arg1) => target._parseLibraryName(arg0, arg1)),
258 'parseListLiteral_2': new MethodTrampoline( 258 'parseListLiteral_2': new MethodTrampoline(
259 2, (Parser target, arg0, arg1) => target._parseListLiteral(arg0, arg1)), 259 2, (Parser target, arg0, arg1) => target._parseListLiteral(arg0, arg1)),
260 'parseListOrMapLiteral_1': new MethodTrampoline( 260 'parseListOrMapLiteral_1': new MethodTrampoline(
261 1, (Parser target, arg0) => target._parseListOrMapLiteral(arg0)), 261 1, (Parser target, arg0) => target._parseListOrMapLiteral(arg0)),
262 'parseLogicalAndExpression_0': new MethodTrampoline( 262 'parseLogicalAndExpression_0': new MethodTrampoline(
263 0, (Parser target) => target._parseLogicalAndExpression()), 263 0, (Parser target) => target._parseLogicalAndExpression()),
264 'parseMapLiteral_2': new MethodTrampoline( 264 'parseMapLiteral_2': new MethodTrampoline(
265 2, (Parser target, arg0, arg1) => target._parseMapLiteral(arg0, arg1)), 265 2, (Parser target, arg0, arg1) => target._parseMapLiteral(arg0, arg1)),
266 'parseMethodDeclarationAfterParameters_6': new MethodTrampoline(6, 266 'parseMethodDeclarationAfterParameters_7': new MethodTrampoline(7,
267 (Parser target, arg0, arg1, arg2, arg3, arg4, arg5) => target 267 (Parser target, arg0, arg1, arg2, arg3, arg4, arg5, arg6) => target
268 ._parseMethodDeclarationAfterParameters( 268 ._parseMethodDeclarationAfterParameters(
269 arg0, arg1, arg2, arg3, arg4, arg5)), 269 arg0, arg1, arg2, arg3, arg4, arg5, arg6)),
270 'parseMethodDeclarationAfterReturnType_4': new MethodTrampoline(4, 270 'parseMethodDeclarationAfterReturnType_4': new MethodTrampoline(4,
271 (Parser target, arg0, arg1, arg2, arg3) => target 271 (Parser target, arg0, arg1, arg2, arg3) => target
272 ._parseMethodDeclarationAfterReturnType(arg0, arg1, arg2, arg3)), 272 ._parseMethodDeclarationAfterReturnType(arg0, arg1, arg2, arg3)),
273 'parseModifiers_0': 273 'parseModifiers_0':
274 new MethodTrampoline(0, (Parser target) => target._parseModifiers()), 274 new MethodTrampoline(0, (Parser target) => target._parseModifiers()),
275 'parseMultiplicativeExpression_0': new MethodTrampoline( 275 'parseMultiplicativeExpression_0': new MethodTrampoline(
276 0, (Parser target) => target._parseMultiplicativeExpression()), 276 0, (Parser target) => target._parseMultiplicativeExpression()),
277 'parseNativeClause_0': 277 'parseNativeClause_0':
278 new MethodTrampoline(0, (Parser target) => target._parseNativeClause()), 278 new MethodTrampoline(0, (Parser target) => target._parseNativeClause()),
279 'parseNewExpression_0': 279 'parseNewExpression_0':
(...skipping 1793 matching lines...) Expand 10 before | Expand all | Expand 10 after
2073 */ 2073 */
2074 bool _inSwitch = false; 2074 bool _inSwitch = false;
2075 2075
2076 /** 2076 /**
2077 * A flag indicating whether the parser is currently in a constructor field 2077 * A flag indicating whether the parser is currently in a constructor field
2078 * initializer, with no intervening parens, braces, or brackets. 2078 * initializer, with no intervening parens, braces, or brackets.
2079 */ 2079 */
2080 bool _inInitializer = false; 2080 bool _inInitializer = false;
2081 2081
2082 /** 2082 /**
2083 * A flag indicating whether the parser is to parse generic method syntax.
2084 */
2085 bool parseGenericMethods = false;
2086
2087 /**
2083 * Initialize a newly created parser to parse the content of the given 2088 * Initialize a newly created parser to parse the content of the given
2084 * [_source] and to report any errors that are found to the given 2089 * [_source] and to report any errors that are found to the given
2085 * [_errorListener]. 2090 * [_errorListener].
2086 */ 2091 */
2087 Parser(this._source, this._errorListener); 2092 Parser(this._source, this._errorListener);
2088 2093
2089 void set currentToken(Token currentToken) { 2094 void set currentToken(Token currentToken) {
2090 this._currentToken = currentToken; 2095 this._currentToken = currentToken;
2091 } 2096 }
2092 2097
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
2433 if (commentAndMetadata.comment != null || 2438 if (commentAndMetadata.comment != null ||
2434 !commentAndMetadata.metadata.isEmpty) { 2439 !commentAndMetadata.metadata.isEmpty) {
2435 // 2440 //
2436 // We appear to have found an incomplete declaration at the end of the 2441 // We appear to have found an incomplete declaration at the end of the
2437 // class. At this point it consists of a metadata, which we don't want 2442 // class. At this point it consists of a metadata, which we don't want
2438 // to loose, so we'll treat it as a method declaration with a missing 2443 // to loose, so we'll treat it as a method declaration with a missing
2439 // name, parameters and empty body. 2444 // name, parameters and empty body.
2440 // 2445 //
2441 return new MethodDeclaration(commentAndMetadata.comment, 2446 return new MethodDeclaration(commentAndMetadata.comment,
2442 commentAndMetadata.metadata, null, null, null, null, null, 2447 commentAndMetadata.metadata, null, null, null, null, null,
2443 _createSyntheticIdentifier(), new FormalParameterList( 2448 _createSyntheticIdentifier(), null, new FormalParameterList(
2444 null, new List<FormalParameter>(), null, null, null), 2449 null, new List<FormalParameter>(), null, null, null),
2445 new EmptyFunctionBody(_createSyntheticToken(TokenType.SEMICOLON))); 2450 new EmptyFunctionBody(_createSyntheticToken(TokenType.SEMICOLON)));
2446 } 2451 }
2447 return null; 2452 return null;
2448 } else if (_tokenMatches(_peek(), TokenType.PERIOD) && 2453 } else if (_tokenMatches(_peek(), TokenType.PERIOD) &&
2449 _tokenMatchesIdentifier(_peekAt(2)) && 2454 _tokenMatchesIdentifier(_peekAt(2)) &&
2450 _tokenMatches(_peekAt(3), TokenType.OPEN_PAREN)) { 2455 _tokenMatches(_peekAt(3), TokenType.OPEN_PAREN)) {
2451 return _parseConstructor(commentAndMetadata, modifiers.externalKeyword, 2456 return _parseConstructor(commentAndMetadata, modifiers.externalKeyword,
2452 _validateModifiersForConstructor(modifiers), modifiers.factoryKeyword, 2457 _validateModifiersForConstructor(modifiers), modifiers.factoryKeyword,
2453 parseSimpleIdentifier(), getAndAdvance(), parseSimpleIdentifier(), 2458 parseSimpleIdentifier(), getAndAdvance(), parseSimpleIdentifier(),
2454 parseFormalParameterList()); 2459 parseFormalParameterList());
2455 } else if (_tokenMatches(_peek(), TokenType.OPEN_PAREN)) { 2460 } else if (_tokenMatches(_peek(), TokenType.OPEN_PAREN)) {
2456 SimpleIdentifier methodName = parseSimpleIdentifier(); 2461 SimpleIdentifier methodName = parseSimpleIdentifier();
2457 FormalParameterList parameters = parseFormalParameterList(); 2462 FormalParameterList parameters = parseFormalParameterList();
2458 if (_matches(TokenType.COLON) || 2463 if (_matches(TokenType.COLON) ||
2459 modifiers.factoryKeyword != null || 2464 modifiers.factoryKeyword != null ||
2460 methodName.name == className) { 2465 methodName.name == className) {
2461 return _parseConstructor(commentAndMetadata, modifiers.externalKeyword, 2466 return _parseConstructor(commentAndMetadata, modifiers.externalKeyword,
2462 _validateModifiersForConstructor(modifiers), 2467 _validateModifiersForConstructor(modifiers),
2463 modifiers.factoryKeyword, methodName, null, null, parameters); 2468 modifiers.factoryKeyword, methodName, null, null, parameters);
2464 } 2469 }
2465 _validateModifiersForGetterOrSetterOrMethod(modifiers); 2470 _validateModifiersForGetterOrSetterOrMethod(modifiers);
2466 _validateFormalParameterList(parameters); 2471 _validateFormalParameterList(parameters);
2467 return _parseMethodDeclarationAfterParameters(commentAndMetadata, 2472 return _parseMethodDeclarationAfterParameters(commentAndMetadata,
2468 modifiers.externalKeyword, modifiers.staticKeyword, null, methodName, 2473 modifiers.externalKeyword, modifiers.staticKeyword, null, methodName,
2469 parameters); 2474 null, parameters);
2470 } else if (_peek() 2475 } else if (_peek()
2471 .matchesAny([TokenType.EQ, TokenType.COMMA, TokenType.SEMICOLON])) { 2476 .matchesAny([TokenType.EQ, TokenType.COMMA, TokenType.SEMICOLON])) {
2472 if (modifiers.constKeyword == null && 2477 if (modifiers.constKeyword == null &&
2473 modifiers.finalKeyword == null && 2478 modifiers.finalKeyword == null &&
2474 modifiers.varKeyword == null) { 2479 modifiers.varKeyword == null) {
2475 _reportErrorForCurrentToken( 2480 _reportErrorForCurrentToken(
2476 ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE); 2481 ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE);
2477 } 2482 }
2478 return _parseInitializedIdentifierList(commentAndMetadata, 2483 return _parseInitializedIdentifierList(commentAndMetadata,
2479 modifiers.staticKeyword, _validateModifiersForField(modifiers), null); 2484 modifiers.staticKeyword, _validateModifiersForField(modifiers), null);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
2539 if (methodName.name == className) { 2544 if (methodName.name == className) {
2540 _reportErrorForNode(ParserErrorCode.CONSTRUCTOR_WITH_RETURN_TYPE, type); 2545 _reportErrorForNode(ParserErrorCode.CONSTRUCTOR_WITH_RETURN_TYPE, type);
2541 return _parseConstructor(commentAndMetadata, modifiers.externalKeyword, 2546 return _parseConstructor(commentAndMetadata, modifiers.externalKeyword,
2542 _validateModifiersForConstructor(modifiers), 2547 _validateModifiersForConstructor(modifiers),
2543 modifiers.factoryKeyword, methodName, null, null, parameters); 2548 modifiers.factoryKeyword, methodName, null, null, parameters);
2544 } 2549 }
2545 _validateModifiersForGetterOrSetterOrMethod(modifiers); 2550 _validateModifiersForGetterOrSetterOrMethod(modifiers);
2546 _validateFormalParameterList(parameters); 2551 _validateFormalParameterList(parameters);
2547 return _parseMethodDeclarationAfterParameters(commentAndMetadata, 2552 return _parseMethodDeclarationAfterParameters(commentAndMetadata,
2548 modifiers.externalKeyword, modifiers.staticKeyword, type, methodName, 2553 modifiers.externalKeyword, modifiers.staticKeyword, type, methodName,
2549 parameters); 2554 null, parameters);
2550 } else if (_tokenMatches(_peek(), TokenType.OPEN_CURLY_BRACKET)) { 2555 } else if (_tokenMatches(_peek(), TokenType.OPEN_CURLY_BRACKET)) {
2551 // We have found "TypeName identifier {", and are guessing that this is a 2556 // We have found "TypeName identifier {", and are guessing that this is a
2552 // getter without the keyword 'get'. 2557 // getter without the keyword 'get'.
2553 _validateModifiersForGetterOrSetterOrMethod(modifiers); 2558 _validateModifiersForGetterOrSetterOrMethod(modifiers);
2554 _reportErrorForCurrentToken(ParserErrorCode.MISSING_GET); 2559 _reportErrorForCurrentToken(ParserErrorCode.MISSING_GET);
2555 _currentToken = _injectToken( 2560 _currentToken = _injectToken(
2556 new Parser_SyntheticKeywordToken(Keyword.GET, _currentToken.offset)); 2561 new Parser_SyntheticKeywordToken(Keyword.GET, _currentToken.offset));
2557 return _parseGetter(commentAndMetadata, modifiers.externalKeyword, 2562 return _parseGetter(commentAndMetadata, modifiers.externalKeyword,
2558 modifiers.staticKeyword, type); 2563 modifiers.staticKeyword, type);
2559 } 2564 }
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after
3036 * parsed. 3041 * parsed.
3037 * 3042 *
3038 * functionExpression ::= 3043 * functionExpression ::=
3039 * formalParameterList functionExpressionBody 3044 * formalParameterList functionExpressionBody
3040 */ 3045 */
3041 FunctionExpression parseFunctionExpression() { 3046 FunctionExpression parseFunctionExpression() {
3042 FormalParameterList parameters = parseFormalParameterList(); 3047 FormalParameterList parameters = parseFormalParameterList();
3043 _validateFormalParameterList(parameters); 3048 _validateFormalParameterList(parameters);
3044 FunctionBody body = 3049 FunctionBody body =
3045 _parseFunctionBody(false, ParserErrorCode.MISSING_FUNCTION_BODY, true); 3050 _parseFunctionBody(false, ParserErrorCode.MISSING_FUNCTION_BODY, true);
3046 return new FunctionExpression(parameters, body); 3051 return new FunctionExpression(null, parameters, body);
3047 } 3052 }
3048 3053
3049 /** 3054 /**
3050 * Parse an if-null expression. Return the if-null expression that was 3055 * Parse an if-null expression. Return the if-null expression that was
3051 * parsed. 3056 * parsed.
3052 * 3057 *
3053 * ifNullExpression ::= logicalOrExpression ('??' logicalOrExpression)* 3058 * ifNullExpression ::= logicalOrExpression ('??' logicalOrExpression)*
3054 */ 3059 */
3055 Expression parseIfNullExpression() { 3060 Expression parseIfNullExpression() {
3056 Expression expression = parseLogicalOrExpression(); 3061 Expression expression = parseLogicalOrExpression();
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
3166 } 3171 }
3167 SimpleIdentifier identifier = parseSimpleIdentifier(); 3172 SimpleIdentifier identifier = parseSimpleIdentifier();
3168 if (_matches(TokenType.OPEN_PAREN)) { 3173 if (_matches(TokenType.OPEN_PAREN)) {
3169 FormalParameterList parameters = parseFormalParameterList(); 3174 FormalParameterList parameters = parseFormalParameterList();
3170 if (thisKeyword == null) { 3175 if (thisKeyword == null) {
3171 if (holder.keyword != null) { 3176 if (holder.keyword != null) {
3172 _reportErrorForToken( 3177 _reportErrorForToken(
3173 ParserErrorCode.FUNCTION_TYPED_PARAMETER_VAR, holder.keyword); 3178 ParserErrorCode.FUNCTION_TYPED_PARAMETER_VAR, holder.keyword);
3174 } 3179 }
3175 return new FunctionTypedFormalParameter(commentAndMetadata.comment, 3180 return new FunctionTypedFormalParameter(commentAndMetadata.comment,
3176 commentAndMetadata.metadata, holder.type, identifier, parameters); 3181 commentAndMetadata.metadata, holder.type, identifier, null,
3182 parameters);
3177 } else { 3183 } else {
3178 return new FieldFormalParameter(commentAndMetadata.comment, 3184 return new FieldFormalParameter(commentAndMetadata.comment,
3179 commentAndMetadata.metadata, holder.keyword, holder.type, 3185 commentAndMetadata.metadata, holder.keyword, holder.type,
3180 thisKeyword, period, identifier, parameters); 3186 thisKeyword, period, identifier, null, parameters);
3181 } 3187 }
3182 } 3188 }
3183 TypeName type = holder.type; 3189 TypeName type = holder.type;
3184 if (type != null) { 3190 if (type != null) {
3185 if (_tokenMatchesKeyword(type.name.beginToken, Keyword.VOID)) { 3191 if (_tokenMatchesKeyword(type.name.beginToken, Keyword.VOID)) {
3186 _reportErrorForToken( 3192 _reportErrorForToken(
3187 ParserErrorCode.VOID_PARAMETER, type.name.beginToken); 3193 ParserErrorCode.VOID_PARAMETER, type.name.beginToken);
3188 } else if (holder.keyword != null && 3194 } else if (holder.keyword != null &&
3189 _tokenMatchesKeyword(holder.keyword, Keyword.VAR)) { 3195 _tokenMatchesKeyword(holder.keyword, Keyword.VAR)) {
3190 _reportErrorForToken(ParserErrorCode.VAR_AND_TYPE, holder.keyword); 3196 _reportErrorForToken(ParserErrorCode.VAR_AND_TYPE, holder.keyword);
3191 } 3197 }
3192 } 3198 }
3193 if (thisKeyword != null) { 3199 if (thisKeyword != null) {
3194 return new FieldFormalParameter(commentAndMetadata.comment, 3200 return new FieldFormalParameter(commentAndMetadata.comment,
3195 commentAndMetadata.metadata, holder.keyword, holder.type, thisKeyword, 3201 commentAndMetadata.metadata, holder.keyword, holder.type, thisKeyword,
3196 period, identifier, null); 3202 period, identifier, null, null);
3197 } 3203 }
3198 return new SimpleFormalParameter(commentAndMetadata.comment, 3204 return new SimpleFormalParameter(commentAndMetadata.comment,
3199 commentAndMetadata.metadata, holder.keyword, holder.type, identifier); 3205 commentAndMetadata.metadata, holder.keyword, holder.type, identifier);
3200 } 3206 }
3201 3207
3202 /** 3208 /**
3203 * Parse a prefixed identifier. Return the prefixed identifier that was 3209 * Parse a prefixed identifier. Return the prefixed identifier that was
3204 * parsed. 3210 * parsed.
3205 * 3211 *
3206 * prefixedIdentifier ::= 3212 * prefixedIdentifier ::=
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
3475 } 3481 }
3476 3482
3477 /** 3483 /**
3478 * Convert the given [method] declaration into the nearest valid top-level 3484 * Convert the given [method] declaration into the nearest valid top-level
3479 * function declaration (that is, the function declaration that most closely 3485 * function declaration (that is, the function declaration that most closely
3480 * captures the components of the given method declaration). 3486 * captures the components of the given method declaration).
3481 */ 3487 */
3482 FunctionDeclaration _convertToFunctionDeclaration(MethodDeclaration method) => 3488 FunctionDeclaration _convertToFunctionDeclaration(MethodDeclaration method) =>
3483 new FunctionDeclaration(method.documentationComment, method.metadata, 3489 new FunctionDeclaration(method.documentationComment, method.metadata,
3484 method.externalKeyword, method.returnType, method.propertyKeyword, 3490 method.externalKeyword, method.returnType, method.propertyKeyword,
3485 method.name, new FunctionExpression(method.parameters, method.body)); 3491 method.name, new FunctionExpression(
3492 method.typeParameters, method.parameters, method.body));
3486 3493
3487 /** 3494 /**
3488 * Return `true` if the current token could be the start of a compilation unit 3495 * Return `true` if the current token could be the start of a compilation unit
3489 * member. This method is used for recovery purposes to decide when to stop 3496 * member. This method is used for recovery purposes to decide when to stop
3490 * skipping tokens after finding an error while parsing a compilation unit 3497 * skipping tokens after finding an error while parsing a compilation unit
3491 * member. 3498 * member.
3492 */ 3499 */
3493 bool _couldBeStartOfCompilationUnitMember() { 3500 bool _couldBeStartOfCompilationUnitMember() {
3494 if ((_matchesKeyword(Keyword.IMPORT) || 3501 if ((_matchesKeyword(Keyword.IMPORT) ||
3495 _matchesKeyword(Keyword.EXPORT) || 3502 _matchesKeyword(Keyword.EXPORT) ||
(...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after
4174 // ambiguity by determining whether the primary consists of anything other 4181 // ambiguity by determining whether the primary consists of anything other
4175 // than an identifier and/or is followed by an assignableSelector. 4182 // than an identifier and/or is followed by an assignableSelector.
4176 // 4183 //
4177 Expression expression = _parsePrimaryExpression(); 4184 Expression expression = _parsePrimaryExpression();
4178 bool isOptional = primaryAllowed || expression is SimpleIdentifier; 4185 bool isOptional = primaryAllowed || expression is SimpleIdentifier;
4179 while (true) { 4186 while (true) {
4180 while (_matches(TokenType.OPEN_PAREN)) { 4187 while (_matches(TokenType.OPEN_PAREN)) {
4181 ArgumentList argumentList = parseArgumentList(); 4188 ArgumentList argumentList = parseArgumentList();
4182 if (expression is SimpleIdentifier) { 4189 if (expression is SimpleIdentifier) {
4183 expression = new MethodInvocation( 4190 expression = new MethodInvocation(
4184 null, null, expression as SimpleIdentifier, argumentList); 4191 null, null, expression as SimpleIdentifier, null, argumentList);
4185 } else if (expression is PrefixedIdentifier) { 4192 } else if (expression is PrefixedIdentifier) {
4186 PrefixedIdentifier identifier = expression as PrefixedIdentifier; 4193 PrefixedIdentifier identifier = expression as PrefixedIdentifier;
4187 expression = new MethodInvocation(identifier.prefix, 4194 expression = new MethodInvocation(identifier.prefix,
4188 identifier.period, identifier.identifier, argumentList); 4195 identifier.period, identifier.identifier, null, argumentList);
4189 } else if (expression is PropertyAccess) { 4196 } else if (expression is PropertyAccess) {
4190 PropertyAccess access = expression as PropertyAccess; 4197 PropertyAccess access = expression as PropertyAccess;
4191 expression = new MethodInvocation(access.target, access.operator, 4198 expression = new MethodInvocation(access.target, access.operator,
4192 access.propertyName, argumentList); 4199 access.propertyName, null, argumentList);
4193 } else { 4200 } else {
4194 expression = 4201 expression =
4195 new FunctionExpressionInvocation(expression, argumentList); 4202 new FunctionExpressionInvocation(expression, null, argumentList);
4196 } 4203 }
4197 if (!primaryAllowed) { 4204 if (!primaryAllowed) {
4198 isOptional = false; 4205 isOptional = false;
4199 } 4206 }
4200 } 4207 }
4201 Expression selectorExpression = _parseAssignableSelector( 4208 Expression selectorExpression = _parseAssignableSelector(
4202 expression, isOptional || (expression is PrefixedIdentifier)); 4209 expression, isOptional || (expression is PrefixedIdentifier));
4203 if (identical(selectorExpression, expression)) { 4210 if (identical(selectorExpression, expression)) {
4204 if (!isOptional && (expression is PrefixedIdentifier)) { 4211 if (!isOptional && (expression is PrefixedIdentifier)) {
4205 PrefixedIdentifier identifier = expression as PrefixedIdentifier; 4212 PrefixedIdentifier identifier = expression as PrefixedIdentifier;
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
4376 _reportErrorForToken(ParserErrorCode.MISSING_IDENTIFIER, _currentToken, 4383 _reportErrorForToken(ParserErrorCode.MISSING_IDENTIFIER, _currentToken,
4377 [_currentToken.lexeme]); 4384 [_currentToken.lexeme]);
4378 functionName = _createSyntheticIdentifier(); 4385 functionName = _createSyntheticIdentifier();
4379 } 4386 }
4380 assert((expression == null && functionName != null) || 4387 assert((expression == null && functionName != null) ||
4381 (expression != null && functionName == null)); 4388 (expression != null && functionName == null));
4382 if (_currentToken.type == TokenType.OPEN_PAREN) { 4389 if (_currentToken.type == TokenType.OPEN_PAREN) {
4383 while (_currentToken.type == TokenType.OPEN_PAREN) { 4390 while (_currentToken.type == TokenType.OPEN_PAREN) {
4384 if (functionName != null) { 4391 if (functionName != null) {
4385 expression = new MethodInvocation( 4392 expression = new MethodInvocation(
4386 expression, period, functionName, parseArgumentList()); 4393 expression, period, functionName, null, parseArgumentList());
4387 period = null; 4394 period = null;
4388 functionName = null; 4395 functionName = null;
4389 } else if (expression == null) { 4396 } else if (expression == null) {
4390 // It should not be possible to get here. 4397 // It should not be possible to get here.
4391 expression = new MethodInvocation(expression, period, 4398 expression = new MethodInvocation(expression, period,
4392 _createSyntheticIdentifier(), parseArgumentList()); 4399 _createSyntheticIdentifier(), null, parseArgumentList());
4393 } else { 4400 } else {
4394 expression = 4401 expression = new FunctionExpressionInvocation(
4395 new FunctionExpressionInvocation(expression, parseArgumentList()); 4402 expression, null, parseArgumentList());
4396 } 4403 }
4397 } 4404 }
4398 } else if (functionName != null) { 4405 } else if (functionName != null) {
4399 expression = new PropertyAccess(expression, period, functionName); 4406 expression = new PropertyAccess(expression, period, functionName);
4400 period = null; 4407 period = null;
4401 } 4408 }
4402 assert(expression != null); 4409 assert(expression != null);
4403 bool progress = true; 4410 bool progress = true;
4404 while (progress) { 4411 while (progress) {
4405 progress = false; 4412 progress = false;
4406 Expression selector = _parseAssignableSelector(expression, true); 4413 Expression selector = _parseAssignableSelector(expression, true);
4407 if (!identical(selector, expression)) { 4414 if (!identical(selector, expression)) {
4408 expression = selector; 4415 expression = selector;
4409 progress = true; 4416 progress = true;
4410 while (_currentToken.type == TokenType.OPEN_PAREN) { 4417 while (_currentToken.type == TokenType.OPEN_PAREN) {
4411 if (expression is PropertyAccess) { 4418 if (expression is PropertyAccess) {
4412 PropertyAccess propertyAccess = expression as PropertyAccess; 4419 PropertyAccess propertyAccess = expression as PropertyAccess;
4413 expression = new MethodInvocation(propertyAccess.target, 4420 expression = new MethodInvocation(propertyAccess.target,
4414 propertyAccess.operator, propertyAccess.propertyName, 4421 propertyAccess.operator, propertyAccess.propertyName, null,
4415 parseArgumentList()); 4422 parseArgumentList());
4416 } else { 4423 } else {
4417 expression = new FunctionExpressionInvocation( 4424 expression = new FunctionExpressionInvocation(
4418 expression, parseArgumentList()); 4425 expression, null, parseArgumentList());
4419 } 4426 }
4420 } 4427 }
4421 } 4428 }
4422 } 4429 }
4423 if (_currentToken.type.isAssignmentOperator) { 4430 if (_currentToken.type.isAssignmentOperator) {
4424 Token operator = getAndAdvance(); 4431 Token operator = getAndAdvance();
4425 _ensureAssignable(expression); 4432 _ensureAssignable(expression);
4426 expression = new AssignmentExpression( 4433 expression = new AssignmentExpression(
4427 expression, operator, parseExpressionWithoutCascade()); 4434 expression, operator, parseExpressionWithoutCascade());
4428 } 4435 }
(...skipping 1345 matching lines...) Expand 10 before | Expand all | Expand 10 after
5774 } else { 5781 } else {
5775 body = new EmptyFunctionBody(_expect(TokenType.SEMICOLON)); 5782 body = new EmptyFunctionBody(_expect(TokenType.SEMICOLON));
5776 } 5783 }
5777 // if (!isStatement && matches(TokenType.SEMICOLON)) { 5784 // if (!isStatement && matches(TokenType.SEMICOLON)) {
5778 // // TODO(brianwilkerson) Improve this error message. 5785 // // TODO(brianwilkerson) Improve this error message.
5779 // reportError(ParserErrorCode.UNEXPECTED_TOKEN, currentToken.getLexeme ()); 5786 // reportError(ParserErrorCode.UNEXPECTED_TOKEN, currentToken.getLexeme ());
5780 // advance(); 5787 // advance();
5781 // } 5788 // }
5782 return new FunctionDeclaration(commentAndMetadata.comment, 5789 return new FunctionDeclaration(commentAndMetadata.comment,
5783 commentAndMetadata.metadata, externalKeyword, returnType, keyword, name, 5790 commentAndMetadata.metadata, externalKeyword, returnType, keyword, name,
5784 new FunctionExpression(parameters, body)); 5791 new FunctionExpression(null, parameters, body));
5785 } 5792 }
5786 5793
5787 /** 5794 /**
5788 * Parse a function declaration statement. Return the function declaration 5795 * Parse a function declaration statement. Return the function declaration
5789 * statement that was parsed. 5796 * statement that was parsed.
5790 * 5797 *
5791 * functionDeclarationStatement ::= 5798 * functionDeclarationStatement ::=
5792 * functionSignature functionBody 5799 * functionSignature functionBody
5793 */ 5800 */
5794 Statement _parseFunctionDeclarationStatement() { 5801 Statement _parseFunctionDeclarationStatement() {
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
5901 _advance(); 5908 _advance();
5902 } 5909 }
5903 FunctionBody body = _parseFunctionBody( 5910 FunctionBody body = _parseFunctionBody(
5904 externalKeyword != null || staticKeyword == null, 5911 externalKeyword != null || staticKeyword == null,
5905 ParserErrorCode.STATIC_GETTER_WITHOUT_BODY, false); 5912 ParserErrorCode.STATIC_GETTER_WITHOUT_BODY, false);
5906 if (externalKeyword != null && body is! EmptyFunctionBody) { 5913 if (externalKeyword != null && body is! EmptyFunctionBody) {
5907 _reportErrorForCurrentToken(ParserErrorCode.EXTERNAL_GETTER_WITH_BODY); 5914 _reportErrorForCurrentToken(ParserErrorCode.EXTERNAL_GETTER_WITH_BODY);
5908 } 5915 }
5909 return new MethodDeclaration(commentAndMetadata.comment, 5916 return new MethodDeclaration(commentAndMetadata.comment,
5910 commentAndMetadata.metadata, externalKeyword, staticKeyword, returnType, 5917 commentAndMetadata.metadata, externalKeyword, staticKeyword, returnType,
5911 propertyKeyword, null, name, null, body); 5918 propertyKeyword, null, name, null, null, body);
5912 } 5919 }
5913 5920
5914 /** 5921 /**
5915 * Parse a list of identifiers. Return the list of identifiers that were 5922 * Parse a list of identifiers. Return the list of identifiers that were
5916 * parsed. 5923 * parsed.
5917 * 5924 *
5918 * identifierList ::= 5925 * identifierList ::=
5919 * identifier (',' identifier)* 5926 * identifier (',' identifier)*
5920 */ 5927 */
5921 List<SimpleIdentifier> _parseIdentifierList() { 5928 List<SimpleIdentifier> _parseIdentifierList() {
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
6222 * [parameters] is the parameters to the method. Return the method declaration 6229 * [parameters] is the parameters to the method. Return the method declaration
6223 * that was parsed. 6230 * that was parsed.
6224 * 6231 *
6225 * functionDeclaration ::= 6232 * functionDeclaration ::=
6226 * ('external' 'static'?)? functionSignature functionBody 6233 * ('external' 'static'?)? functionSignature functionBody
6227 * | 'external'? functionSignature ';' 6234 * | 'external'? functionSignature ';'
6228 */ 6235 */
6229 MethodDeclaration _parseMethodDeclarationAfterParameters( 6236 MethodDeclaration _parseMethodDeclarationAfterParameters(
6230 CommentAndMetadata commentAndMetadata, Token externalKeyword, 6237 CommentAndMetadata commentAndMetadata, Token externalKeyword,
6231 Token staticKeyword, TypeName returnType, SimpleIdentifier name, 6238 Token staticKeyword, TypeName returnType, SimpleIdentifier name,
6232 FormalParameterList parameters) { 6239 TypeParameterList typeParameters, FormalParameterList parameters) {
6233 FunctionBody body = _parseFunctionBody( 6240 FunctionBody body = _parseFunctionBody(
6234 externalKeyword != null || staticKeyword == null, 6241 externalKeyword != null || staticKeyword == null,
6235 ParserErrorCode.MISSING_FUNCTION_BODY, false); 6242 ParserErrorCode.MISSING_FUNCTION_BODY, false);
6236 if (externalKeyword != null) { 6243 if (externalKeyword != null) {
6237 if (body is! EmptyFunctionBody) { 6244 if (body is! EmptyFunctionBody) {
6238 _reportErrorForNode(ParserErrorCode.EXTERNAL_METHOD_WITH_BODY, body); 6245 _reportErrorForNode(ParserErrorCode.EXTERNAL_METHOD_WITH_BODY, body);
6239 } 6246 }
6240 } else if (staticKeyword != null) { 6247 } else if (staticKeyword != null) {
6241 if (body is EmptyFunctionBody && _parseFunctionBodies) { 6248 if (body is EmptyFunctionBody && _parseFunctionBodies) {
6242 _reportErrorForNode(ParserErrorCode.ABSTRACT_STATIC_METHOD, body); 6249 _reportErrorForNode(ParserErrorCode.ABSTRACT_STATIC_METHOD, body);
6243 } 6250 }
6244 } 6251 }
6245 return new MethodDeclaration(commentAndMetadata.comment, 6252 return new MethodDeclaration(commentAndMetadata.comment,
6246 commentAndMetadata.metadata, externalKeyword, staticKeyword, returnType, 6253 commentAndMetadata.metadata, externalKeyword, staticKeyword, returnType,
6247 null, null, name, parameters, body); 6254 null, null, name, typeParameters, parameters, body);
6248 } 6255 }
6249 6256
6250 /** 6257 /**
6251 * Parse a method declaration. The [commentAndMetadata] is the documentation 6258 * Parse a method declaration. The [commentAndMetadata] is the documentation
6252 * comment and metadata to be associated with the declaration. The 6259 * comment and metadata to be associated with the declaration. The
6253 * [externalKeyword] is the 'external' token. The [staticKeyword] is the 6260 * [externalKeyword] is the 'external' token. The [staticKeyword] is the
6254 * static keyword, or `null` if the getter is not static. The [returnType] is 6261 * static keyword, or `null` if the getter is not static. The [returnType] is
6255 * the return type of the method. Return the method declaration that was 6262 * the return type of the method. Return the method declaration that was
6256 * parsed. 6263 * parsed.
6257 * 6264 *
(...skipping 12 matching lines...) Expand all
6270 _reportErrorForToken( 6277 _reportErrorForToken(
6271 ParserErrorCode.MISSING_METHOD_PARAMETERS, _currentToken.previous); 6278 ParserErrorCode.MISSING_METHOD_PARAMETERS, _currentToken.previous);
6272 parameters = new FormalParameterList( 6279 parameters = new FormalParameterList(
6273 _createSyntheticToken(TokenType.OPEN_PAREN), null, null, null, 6280 _createSyntheticToken(TokenType.OPEN_PAREN), null, null, null,
6274 _createSyntheticToken(TokenType.CLOSE_PAREN)); 6281 _createSyntheticToken(TokenType.CLOSE_PAREN));
6275 } else { 6282 } else {
6276 parameters = parseFormalParameterList(); 6283 parameters = parseFormalParameterList();
6277 } 6284 }
6278 _validateFormalParameterList(parameters); 6285 _validateFormalParameterList(parameters);
6279 return _parseMethodDeclarationAfterParameters(commentAndMetadata, 6286 return _parseMethodDeclarationAfterParameters(commentAndMetadata,
6280 externalKeyword, staticKeyword, returnType, methodName, parameters); 6287 externalKeyword, staticKeyword, returnType, methodName, null,
6288 parameters);
6281 } 6289 }
6282 6290
6283 /** 6291 /**
6284 * Parse the modifiers preceding a declaration. This method allows the 6292 * Parse the modifiers preceding a declaration. This method allows the
6285 * modifiers to appear in any order but does generate errors for duplicated 6293 * modifiers to appear in any order but does generate errors for duplicated
6286 * modifiers. Checks for other problems, such as having the modifiers appear 6294 * modifiers. Checks for other problems, such as having the modifiers appear
6287 * in the wrong order or specifying both 'const' and 'final', are reported in 6295 * in the wrong order or specifying both 'const' and 'final', are reported in
6288 * one of the methods whose name is prefixed with `validateModifiersFor`. 6296 * one of the methods whose name is prefixed with `validateModifiersFor`.
6289 * Return the modifiers that were parsed. 6297 * Return the modifiers that were parsed.
6290 * 6298 *
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
6626 } 6634 }
6627 FormalParameterList parameters = parseFormalParameterList(); 6635 FormalParameterList parameters = parseFormalParameterList();
6628 _validateFormalParameterList(parameters); 6636 _validateFormalParameterList(parameters);
6629 FunctionBody body = 6637 FunctionBody body =
6630 _parseFunctionBody(true, ParserErrorCode.MISSING_FUNCTION_BODY, false); 6638 _parseFunctionBody(true, ParserErrorCode.MISSING_FUNCTION_BODY, false);
6631 if (externalKeyword != null && body is! EmptyFunctionBody) { 6639 if (externalKeyword != null && body is! EmptyFunctionBody) {
6632 _reportErrorForCurrentToken(ParserErrorCode.EXTERNAL_OPERATOR_WITH_BODY); 6640 _reportErrorForCurrentToken(ParserErrorCode.EXTERNAL_OPERATOR_WITH_BODY);
6633 } 6641 }
6634 return new MethodDeclaration(commentAndMetadata.comment, 6642 return new MethodDeclaration(commentAndMetadata.comment,
6635 commentAndMetadata.metadata, externalKeyword, null, returnType, null, 6643 commentAndMetadata.metadata, externalKeyword, null, returnType, null,
6636 operatorKeyword, name, parameters, body); 6644 operatorKeyword, name, null, parameters, body);
6637 } 6645 }
6638 6646
6639 /** 6647 /**
6640 * Parse a return type if one is given, otherwise return `null` without 6648 * Parse a return type if one is given, otherwise return `null` without
6641 * advancing. Return the return type that was parsed. 6649 * advancing. Return the return type that was parsed.
6642 */ 6650 */
6643 TypeName _parseOptionalReturnType() { 6651 TypeName _parseOptionalReturnType() {
6644 if (_matchesKeyword(Keyword.VOID)) { 6652 if (_matchesKeyword(Keyword.VOID)) {
6645 return parseReturnType(); 6653 return parseReturnType();
6646 } else if (_matchesIdentifier() && 6654 } else if (_matchesIdentifier() &&
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
6704 if (_matches(TokenType.OPEN_SQUARE_BRACKET) || 6712 if (_matches(TokenType.OPEN_SQUARE_BRACKET) ||
6705 _matches(TokenType.PERIOD) || 6713 _matches(TokenType.PERIOD) ||
6706 _matches(TokenType.QUESTION_PERIOD) || 6714 _matches(TokenType.QUESTION_PERIOD) ||
6707 _matches(TokenType.OPEN_PAREN)) { 6715 _matches(TokenType.OPEN_PAREN)) {
6708 do { 6716 do {
6709 if (_matches(TokenType.OPEN_PAREN)) { 6717 if (_matches(TokenType.OPEN_PAREN)) {
6710 ArgumentList argumentList = parseArgumentList(); 6718 ArgumentList argumentList = parseArgumentList();
6711 if (operand is PropertyAccess) { 6719 if (operand is PropertyAccess) {
6712 PropertyAccess access = operand as PropertyAccess; 6720 PropertyAccess access = operand as PropertyAccess;
6713 operand = new MethodInvocation(access.target, access.operator, 6721 operand = new MethodInvocation(access.target, access.operator,
6714 access.propertyName, argumentList); 6722 access.propertyName, null, argumentList);
6715 } else { 6723 } else {
6716 operand = new FunctionExpressionInvocation(operand, argumentList); 6724 operand =
6725 new FunctionExpressionInvocation(operand, null, argumentList);
6717 } 6726 }
6718 } else { 6727 } else {
6719 operand = _parseAssignableSelector(operand, true); 6728 operand = _parseAssignableSelector(operand, true);
6720 } 6729 }
6721 } while (_matches(TokenType.OPEN_SQUARE_BRACKET) || 6730 } while (_matches(TokenType.OPEN_SQUARE_BRACKET) ||
6722 _matches(TokenType.PERIOD) || 6731 _matches(TokenType.PERIOD) ||
6723 _matches(TokenType.QUESTION_PERIOD) || 6732 _matches(TokenType.QUESTION_PERIOD) ||
6724 _matches(TokenType.OPEN_PAREN)); 6733 _matches(TokenType.OPEN_PAREN));
6725 return operand; 6734 return operand;
6726 } 6735 }
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
6964 FormalParameterList parameters = parseFormalParameterList(); 6973 FormalParameterList parameters = parseFormalParameterList();
6965 _validateFormalParameterList(parameters); 6974 _validateFormalParameterList(parameters);
6966 FunctionBody body = _parseFunctionBody( 6975 FunctionBody body = _parseFunctionBody(
6967 externalKeyword != null || staticKeyword == null, 6976 externalKeyword != null || staticKeyword == null,
6968 ParserErrorCode.STATIC_SETTER_WITHOUT_BODY, false); 6977 ParserErrorCode.STATIC_SETTER_WITHOUT_BODY, false);
6969 if (externalKeyword != null && body is! EmptyFunctionBody) { 6978 if (externalKeyword != null && body is! EmptyFunctionBody) {
6970 _reportErrorForCurrentToken(ParserErrorCode.EXTERNAL_SETTER_WITH_BODY); 6979 _reportErrorForCurrentToken(ParserErrorCode.EXTERNAL_SETTER_WITH_BODY);
6971 } 6980 }
6972 return new MethodDeclaration(commentAndMetadata.comment, 6981 return new MethodDeclaration(commentAndMetadata.comment,
6973 commentAndMetadata.metadata, externalKeyword, staticKeyword, returnType, 6982 commentAndMetadata.metadata, externalKeyword, staticKeyword, returnType,
6974 propertyKeyword, null, name, parameters, body); 6983 propertyKeyword, null, name, null, parameters, body);
6975 } 6984 }
6976 6985
6977 /** 6986 /**
6978 * Parse a shift expression. Return the shift expression that was parsed. 6987 * Parse a shift expression. Return the shift expression that was parsed.
6979 * 6988 *
6980 * shiftExpression ::= 6989 * shiftExpression ::=
6981 * additiveExpression (shiftOperator additiveExpression)* 6990 * additiveExpression (shiftOperator additiveExpression)*
6982 * | 'super' (shiftOperator additiveExpression)+ 6991 * | 'super' (shiftOperator additiveExpression)+
6983 */ 6992 */
6984 Expression _parseShiftExpression() { 6993 Expression _parseShiftExpression() {
(...skipping 3602 matching lines...) Expand 10 before | Expand all | Expand 10 after
10587 } 10596 }
10588 10597
10589 /** 10598 /**
10590 * Copy resolution data from the [fromNode] to the [toNode]. 10599 * Copy resolution data from the [fromNode] to the [toNode].
10591 */ 10600 */
10592 static void copyResolutionData(AstNode fromNode, AstNode toNode) { 10601 static void copyResolutionData(AstNode fromNode, AstNode toNode) {
10593 ResolutionCopier copier = new ResolutionCopier(); 10602 ResolutionCopier copier = new ResolutionCopier();
10594 copier._isEqualNodes(fromNode, toNode); 10603 copier._isEqualNodes(fromNode, toNode);
10595 } 10604 }
10596 } 10605 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698