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