OLD | NEW |
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 4145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4156 } | 4156 } |
4157 FinalConstVarOrType holder = parseFinalConstVarOrType(!inFunctionType, | 4157 FinalConstVarOrType holder = parseFinalConstVarOrType(!inFunctionType, |
4158 inFunctionType: inFunctionType); | 4158 inFunctionType: inFunctionType); |
4159 Token thisKeyword = null; | 4159 Token thisKeyword = null; |
4160 Token period = null; | 4160 Token period = null; |
4161 if (_matchesKeyword(Keyword.THIS)) { | 4161 if (_matchesKeyword(Keyword.THIS)) { |
4162 thisKeyword = getAndAdvance(); | 4162 thisKeyword = getAndAdvance(); |
4163 period = _expect(TokenType.PERIOD); | 4163 period = _expect(TokenType.PERIOD); |
4164 } | 4164 } |
4165 if (!_matchesIdentifier() && inFunctionType) { | 4165 if (!_matchesIdentifier() && inFunctionType) { |
4166 SimpleFormalParameterImpl parameter = astFactory.simpleFormalParameter( | 4166 return astFactory.simpleFormalParameter2( |
4167 commentAndMetadata.comment, | 4167 comment: commentAndMetadata.comment, |
4168 commentAndMetadata.metadata, | 4168 metadata: commentAndMetadata.metadata, |
4169 holder.keyword, | 4169 covariantKeyword: covariantKeyword, |
4170 holder.type, | 4170 keyword: holder.keyword, |
4171 null); | 4171 type: holder.type, |
4172 parameter.covariantKeyword = covariantKeyword; | 4172 identifier: null); |
4173 return parameter; | |
4174 } | 4173 } |
4175 SimpleIdentifier identifier = parseSimpleIdentifier(); | 4174 SimpleIdentifier identifier = parseSimpleIdentifier(); |
4176 TypeParameterList typeParameters = _parseGenericMethodTypeParameters(); | 4175 TypeParameterList typeParameters = _parseGenericMethodTypeParameters(); |
4177 if (_matches(TokenType.OPEN_PAREN)) { | 4176 if (_matches(TokenType.OPEN_PAREN)) { |
4178 FormalParameterList parameters = _parseFormalParameterListUnchecked(); | 4177 FormalParameterList parameters = _parseFormalParameterListUnchecked(); |
4179 if (thisKeyword == null) { | 4178 if (thisKeyword == null) { |
4180 if (holder.keyword != null) { | 4179 if (holder.keyword != null) { |
4181 _reportErrorForToken( | 4180 _reportErrorForToken( |
4182 ParserErrorCode.FUNCTION_TYPED_PARAMETER_VAR, holder.keyword); | 4181 ParserErrorCode.FUNCTION_TYPED_PARAMETER_VAR, holder.keyword); |
4183 } | 4182 } |
4184 Token question = null; | 4183 Token question = null; |
4185 if (enableNnbd && _matches(TokenType.QUESTION)) { | 4184 if (enableNnbd && _matches(TokenType.QUESTION)) { |
4186 question = getAndAdvance(); | 4185 question = getAndAdvance(); |
4187 } | 4186 } |
4188 FunctionTypedFormalParameterImpl parameter = | 4187 return astFactory.functionTypedFormalParameter2( |
4189 astFactory.functionTypedFormalParameter( | 4188 comment: commentAndMetadata.comment, |
4190 commentAndMetadata.comment, | 4189 metadata: commentAndMetadata.metadata, |
4191 commentAndMetadata.metadata, | 4190 covariantKeyword: covariantKeyword, |
4192 holder.type, | 4191 returnType: holder.type, |
4193 astFactory.simpleIdentifier(identifier.token, | 4192 identifier: astFactory.simpleIdentifier(identifier.token, |
4194 isDeclaration: true), | 4193 isDeclaration: true), |
4195 typeParameters, | 4194 typeParameters: typeParameters, |
4196 parameters, | 4195 parameters: parameters, |
4197 question: question); | 4196 question: question); |
4198 parameter.covariantKeyword = covariantKeyword; | |
4199 return parameter; | |
4200 } else { | 4197 } else { |
4201 FieldFormalParameterImpl parameter = astFactory.fieldFormalParameter( | 4198 return astFactory.fieldFormalParameter2( |
4202 commentAndMetadata.comment, | 4199 comment: commentAndMetadata.comment, |
4203 commentAndMetadata.metadata, | 4200 metadata: commentAndMetadata.metadata, |
4204 holder.keyword, | 4201 covariantKeyword: covariantKeyword, |
4205 holder.type, | 4202 keyword: holder.keyword, |
4206 thisKeyword, | 4203 type: holder.type, |
4207 period, | 4204 thisKeyword: thisKeyword, |
4208 identifier, | 4205 period: period, |
4209 typeParameters, | 4206 identifier: identifier, |
4210 parameters); | 4207 typeParameters: typeParameters, |
4211 parameter.covariantKeyword = covariantKeyword; | 4208 parameters: parameters); |
4212 return parameter; | |
4213 } | 4209 } |
4214 } else if (typeParameters != null) { | 4210 } else if (typeParameters != null) { |
4215 // TODO(brianwilkerson) Report an error. It looks like a function-typed | 4211 // TODO(brianwilkerson) Report an error. It looks like a function-typed |
4216 // parameter with no parameter list. | 4212 // parameter with no parameter list. |
4217 //_reportErrorForToken(ParserErrorCode.MISSING_PARAMETERS, typeParameters.
endToken); | 4213 //_reportErrorForToken(ParserErrorCode.MISSING_PARAMETERS, typeParameters.
endToken); |
4218 } | 4214 } |
4219 TypeAnnotation type = holder.type; | 4215 TypeAnnotation type = holder.type; |
4220 if (type != null) { | 4216 if (type != null) { |
4221 if (type is TypeName && | 4217 if (type is TypeName && |
4222 _tokenMatchesKeyword(type.name.beginToken, Keyword.VOID)) { | 4218 _tokenMatchesKeyword(type.name.beginToken, Keyword.VOID)) { |
4223 _reportErrorForToken( | 4219 _reportErrorForToken( |
4224 ParserErrorCode.VOID_PARAMETER, type.name.beginToken); | 4220 ParserErrorCode.VOID_PARAMETER, type.name.beginToken); |
4225 } else if (holder.keyword != null && | 4221 } else if (holder.keyword != null && |
4226 _tokenMatchesKeyword(holder.keyword, Keyword.VAR)) { | 4222 _tokenMatchesKeyword(holder.keyword, Keyword.VAR)) { |
4227 _reportErrorForToken(ParserErrorCode.VAR_AND_TYPE, holder.keyword); | 4223 _reportErrorForToken(ParserErrorCode.VAR_AND_TYPE, holder.keyword); |
4228 } | 4224 } |
4229 } | 4225 } |
4230 if (thisKeyword != null) { | 4226 if (thisKeyword != null) { |
4231 // TODO(brianwilkerson) If there are type parameters but no parameters, | 4227 // TODO(brianwilkerson) If there are type parameters but no parameters, |
4232 // should we create a synthetic empty parameter list here so we can | 4228 // should we create a synthetic empty parameter list here so we can |
4233 // capture the type parameters? | 4229 // capture the type parameters? |
4234 FieldFormalParameterImpl parameter = astFactory.fieldFormalParameter( | 4230 return astFactory.fieldFormalParameter2( |
4235 commentAndMetadata.comment, | 4231 comment: commentAndMetadata.comment, |
4236 commentAndMetadata.metadata, | 4232 metadata: commentAndMetadata.metadata, |
4237 holder.keyword, | 4233 covariantKeyword: covariantKeyword, |
4238 type, | 4234 keyword: holder.keyword, |
4239 thisKeyword, | 4235 type: type, |
4240 period, | 4236 thisKeyword: thisKeyword, |
4241 identifier, | 4237 period: period, |
4242 null, | 4238 identifier: identifier); |
4243 null); | |
4244 parameter.covariantKeyword = covariantKeyword; | |
4245 return parameter; | |
4246 } | 4239 } |
4247 SimpleFormalParameterImpl parameter = astFactory.simpleFormalParameter( | 4240 return astFactory.simpleFormalParameter2( |
4248 commentAndMetadata.comment, | 4241 comment: commentAndMetadata.comment, |
4249 commentAndMetadata.metadata, | 4242 metadata: commentAndMetadata.metadata, |
4250 holder.keyword, | 4243 covariantKeyword: covariantKeyword, |
4251 type, | 4244 keyword: holder.keyword, |
4252 astFactory.simpleIdentifier(identifier.token, isDeclaration: true)); | 4245 type: type, |
4253 parameter.covariantKeyword = covariantKeyword; | 4246 identifier: |
4254 return parameter; | 4247 astFactory.simpleIdentifier(identifier.token, isDeclaration: true)); |
4255 } | 4248 } |
4256 | 4249 |
4257 /** | 4250 /** |
4258 * Parse an operator declaration. The [commentAndMetadata] is the | 4251 * Parse an operator declaration. The [commentAndMetadata] is the |
4259 * documentation comment and metadata to be associated with the declaration. | 4252 * documentation comment and metadata to be associated with the declaration. |
4260 * The [externalKeyword] is the 'external' token. The [returnType] is the | 4253 * The [externalKeyword] is the 'external' token. The [returnType] is the |
4261 * return type that has already been parsed, or `null` if there was no return | 4254 * return type that has already been parsed, or `null` if there was no return |
4262 * type. Return the operator declaration that was parsed. | 4255 * type. Return the operator declaration that was parsed. |
4263 * | 4256 * |
4264 * operatorDeclaration ::= | 4257 * operatorDeclaration ::= |
(...skipping 4244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8509 */ | 8502 */ |
8510 Parser_SyntheticKeywordToken(Keyword keyword, int offset) | 8503 Parser_SyntheticKeywordToken(Keyword keyword, int offset) |
8511 : super(keyword, offset); | 8504 : super(keyword, offset); |
8512 | 8505 |
8513 @override | 8506 @override |
8514 int get length => 0; | 8507 int get length => 0; |
8515 | 8508 |
8516 @override | 8509 @override |
8517 Token copy() => new Parser_SyntheticKeywordToken(keyword, offset); | 8510 Token copy() => new Parser_SyntheticKeywordToken(keyword, offset); |
8518 } | 8511 } |
OLD | NEW |