| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 fasta.analyzer.ast_builder; | 5 library fasta.analyzer.ast_builder; |
| 6 | 6 |
| 7 import 'package:analyzer/analyzer.dart'; | 7 import 'package:analyzer/analyzer.dart'; |
| 8 import 'package:analyzer/dart/ast/ast_factory.dart' show AstFactory; | 8 import 'package:analyzer/dart/ast/ast_factory.dart' show AstFactory; |
| 9 import 'package:analyzer/dart/ast/standard_ast_factory.dart' as standard; | 9 import 'package:analyzer/dart/ast/standard_ast_factory.dart' as standard; |
| 10 import 'package:analyzer/dart/ast/token.dart' as analyzer show Token; | 10 import 'package:analyzer/dart/ast/token.dart' as analyzer show Token; |
| (...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 | 498 |
| 499 void handleFormalParameterWithoutValue(Token token) { | 499 void handleFormalParameterWithoutValue(Token token) { |
| 500 debugEvent("FormalParameterWithoutValue"); | 500 debugEvent("FormalParameterWithoutValue"); |
| 501 push(NullValue.ParameterDefaultValue); | 501 push(NullValue.ParameterDefaultValue); |
| 502 } | 502 } |
| 503 | 503 |
| 504 void endFormalParameter( | 504 void endFormalParameter( |
| 505 Token covariantKeyword, Token thisKeyword, FormalParameterType kind) { | 505 Token covariantKeyword, Token thisKeyword, FormalParameterType kind) { |
| 506 debugEvent("FormalParameter"); | 506 debugEvent("FormalParameter"); |
| 507 _ParameterDefaultValue defaultValue = pop(); | 507 _ParameterDefaultValue defaultValue = pop(); |
| 508 SimpleIdentifier name = pop(); | 508 |
| 509 TypeName type = pop(); | 509 AstNode nameOrFunctionTypedParameter = pop(); |
| 510 Token keyword = _popOptionalSingleModifier(); | |
| 511 pop(); // TODO(paulberry): Metadata. | |
| 512 | 510 |
| 513 FormalParameter node; | 511 FormalParameter node; |
| 514 if (thisKeyword == null) { | 512 SimpleIdentifier name; |
| 515 node = ast.simpleFormalParameter2( | 513 if (nameOrFunctionTypedParameter is FunctionTypedFormalParameter) { |
| 516 covariantKeyword: toAnalyzerToken(covariantKeyword), | 514 node = nameOrFunctionTypedParameter; |
| 517 keyword: toAnalyzerToken(keyword), | 515 name = nameOrFunctionTypedParameter.identifier; |
| 518 type: type, | |
| 519 identifier: name); | |
| 520 } else { | 516 } else { |
| 521 // TODO(scheglov): Ideally the period token should be passed in. | 517 name = nameOrFunctionTypedParameter; |
| 522 Token period = identical('.', thisKeyword.next?.stringValue) | 518 TypeName type = pop(); |
| 523 ? thisKeyword.next | 519 Token keyword = _popOptionalSingleModifier(); |
| 524 : null; | 520 pop(); // TODO(paulberry): Metadata. |
| 525 TypeParameterList typeParameters; // TODO(scheglov) | 521 if (thisKeyword == null) { |
| 526 FormalParameterList formalParameters; // TODO(scheglov) | 522 node = ast.simpleFormalParameter2( |
| 527 node = ast.fieldFormalParameter2( | 523 covariantKeyword: toAnalyzerToken(covariantKeyword), |
| 528 covariantKeyword: toAnalyzerToken(covariantKeyword), | 524 keyword: toAnalyzerToken(keyword), |
| 529 keyword: toAnalyzerToken(keyword), | 525 type: type, |
| 530 type: type, | 526 identifier: name); |
| 531 thisKeyword: toAnalyzerToken(thisKeyword), | 527 } else { |
| 532 period: toAnalyzerToken(period), | 528 // TODO(scheglov): Ideally the period token should be passed in. |
| 533 identifier: name, | 529 Token period = identical('.', thisKeyword.next?.stringValue) |
| 534 typeParameters: typeParameters, | 530 ? thisKeyword.next |
| 535 parameters: formalParameters); | 531 : null; |
| 532 TypeParameterList typeParameters; // TODO(scheglov) |
| 533 FormalParameterList formalParameters; // TODO(scheglov) |
| 534 node = ast.fieldFormalParameter2( |
| 535 covariantKeyword: toAnalyzerToken(covariantKeyword), |
| 536 keyword: toAnalyzerToken(keyword), |
| 537 type: type, |
| 538 thisKeyword: toAnalyzerToken(thisKeyword), |
| 539 period: toAnalyzerToken(period), |
| 540 identifier: name, |
| 541 typeParameters: typeParameters, |
| 542 parameters: formalParameters); |
| 543 } |
| 536 } | 544 } |
| 537 | 545 |
| 538 if (defaultValue != null) { | 546 if (defaultValue != null) { |
| 539 node = ast.defaultFormalParameter(node, _toAnalyzerParameterKind(kind), | 547 node = ast.defaultFormalParameter(node, _toAnalyzerParameterKind(kind), |
| 540 toAnalyzerToken(defaultValue.separator), defaultValue.value); | 548 toAnalyzerToken(defaultValue.separator), defaultValue.value); |
| 541 } | 549 } |
| 542 | 550 |
| 543 scope[name.name] = name.staticElement = new AnalyzerParameterElement(node); | 551 scope[name.name] = name.staticElement = new AnalyzerParameterElement(node); |
| 544 push(node); | 552 push(node); |
| 545 } | 553 } |
| 546 | 554 |
| 555 @override |
| 556 void endFunctionTypedFormalParameter(Token token) { |
| 557 debugEvent("FunctionTypedFormalParameter"); |
| 558 |
| 559 FormalParameterList formalParameters = pop(); |
| 560 TypeParameterList typeParameters = pop(); |
| 561 SimpleIdentifier name = pop(); |
| 562 TypeName returnType = pop(); |
| 563 |
| 564 { |
| 565 List<Token> modifiers = pop(); |
| 566 if (modifiers.isNotEmpty) { |
| 567 // TODO(scheglov): Report error. |
| 568 internalError('Unexpected modifier. Report an error.'); |
| 569 } |
| 570 } |
| 571 |
| 572 pop(); // TODO(paulberry): Metadata. |
| 573 |
| 574 FormalParameter node; |
| 575 node = ast.functionTypedFormalParameter2( |
| 576 returnType: returnType, |
| 577 identifier: name, |
| 578 typeParameters: typeParameters, |
| 579 parameters: formalParameters); |
| 580 |
| 581 scope[name.name] = name.staticElement = new AnalyzerParameterElement(node); |
| 582 push(node); |
| 583 } |
| 584 |
| 547 void endFormalParameters(int count, Token beginToken, Token endToken) { | 585 void endFormalParameters(int count, Token beginToken, Token endToken) { |
| 548 debugEvent("FormalParameters"); | 586 debugEvent("FormalParameters"); |
| 549 List rawParameters = popList(count) ?? const <Object>[]; | 587 List rawParameters = popList(count) ?? const <Object>[]; |
| 550 List<FormalParameter> parameters = <FormalParameter>[]; | 588 List<FormalParameter> parameters = <FormalParameter>[]; |
| 551 Token leftDelimiter; | 589 Token leftDelimiter; |
| 552 Token rightDelimiter; | 590 Token rightDelimiter; |
| 553 for (Object raw in rawParameters) { | 591 for (Object raw in rawParameters) { |
| 554 if (raw is _OptionalFormalParameters) { | 592 if (raw is _OptionalFormalParameters) { |
| 555 parameters.addAll(raw.parameters); | 593 parameters.addAll(raw.parameters); |
| 556 leftDelimiter = raw.leftDelimiter; | 594 leftDelimiter = raw.leftDelimiter; |
| (...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1288 | 1326 |
| 1289 /// Data structure placed on the stack as a container for optional parameters. | 1327 /// Data structure placed on the stack as a container for optional parameters. |
| 1290 class _OptionalFormalParameters { | 1328 class _OptionalFormalParameters { |
| 1291 final List<FormalParameter> parameters; | 1329 final List<FormalParameter> parameters; |
| 1292 final Token leftDelimiter; | 1330 final Token leftDelimiter; |
| 1293 final Token rightDelimiter; | 1331 final Token rightDelimiter; |
| 1294 | 1332 |
| 1295 _OptionalFormalParameters( | 1333 _OptionalFormalParameters( |
| 1296 this.parameters, this.leftDelimiter, this.rightDelimiter); | 1334 this.parameters, this.leftDelimiter, this.rightDelimiter); |
| 1297 } | 1335 } |
| OLD | NEW |