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

Side by Side Diff: pkg/front_end/lib/src/fasta/analyzer/ast_builder.dart

Issue 2712023003: Support multiple optional parameters. (Closed)
Patch Set: Created 3 years, 10 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 | « pkg/analyzer/test/generated/parser_fasta_test.dart ('k') | no next file » | 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) 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 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 480
481 void endThrowExpression(Token throwToken, Token endToken) { 481 void endThrowExpression(Token throwToken, Token endToken) {
482 debugEvent("ThrowExpression"); 482 debugEvent("ThrowExpression");
483 push(ast.throwExpression(toAnalyzerToken(throwToken), pop())); 483 push(ast.throwExpression(toAnalyzerToken(throwToken), pop()));
484 } 484 }
485 485
486 @override 486 @override
487 void endOptionalFormalParameters( 487 void endOptionalFormalParameters(
488 int count, Token beginToken, Token endToken) { 488 int count, Token beginToken, Token endToken) {
489 debugEvent("OptionalFormalParameters"); 489 debugEvent("OptionalFormalParameters");
490 push(new _OptionalFormalParameters(popList(count), beginToken, endToken));
490 } 491 }
491 492
492 void handleValuedFormalParameter(Token equals, Token token) { 493 void handleValuedFormalParameter(Token equals, Token token) {
493 debugEvent("ValuedFormalParameter"); 494 debugEvent("ValuedFormalParameter");
494 Expression value = pop(); 495 Expression value = pop();
495 push(new _ParameterDefaultValue(equals, value)); 496 push(new _ParameterDefaultValue(equals, value));
496 } 497 }
497 498
498 void handleFormalParameterWithoutValue(Token token) { 499 void handleFormalParameterWithoutValue(Token token) {
499 debugEvent("FormalParameterWithoutValue"); 500 debugEvent("FormalParameterWithoutValue");
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 node = ast.defaultFormalParameter(node, _toAnalyzerParameterKind(kind), 539 node = ast.defaultFormalParameter(node, _toAnalyzerParameterKind(kind),
539 toAnalyzerToken(defaultValue.separator), defaultValue.value); 540 toAnalyzerToken(defaultValue.separator), defaultValue.value);
540 } 541 }
541 542
542 scope[name.name] = name.staticElement = new AnalyzerParameterElement(node); 543 scope[name.name] = name.staticElement = new AnalyzerParameterElement(node);
543 push(node); 544 push(node);
544 } 545 }
545 546
546 void endFormalParameters(int count, Token beginToken, Token endToken) { 547 void endFormalParameters(int count, Token beginToken, Token endToken) {
547 debugEvent("FormalParameters"); 548 debugEvent("FormalParameters");
548 List<FormalParameter> parameters = popList(count) ?? <FormalParameter>[]; 549 List rawParameters = popList(count) ?? const <Object>[];
549 push(ast.formalParameterList(toAnalyzerToken(beginToken), parameters, null, 550 List<FormalParameter> parameters = <FormalParameter>[];
550 null, toAnalyzerToken(endToken))); 551 Token leftDelimiter;
552 Token rightDelimiter;
553 for (Object raw in rawParameters) {
554 if (raw is _OptionalFormalParameters) {
555 parameters.addAll(raw.parameters);
556 leftDelimiter = raw.leftDelimiter;
557 rightDelimiter = raw.rightDelimiter;
558 } else {
559 parameters.add(raw as FormalParameter);
560 }
561 }
562 push(ast.formalParameterList(
563 toAnalyzerToken(beginToken),
564 parameters,
565 toAnalyzerToken(leftDelimiter),
566 toAnalyzerToken(rightDelimiter),
567 toAnalyzerToken(endToken)));
551 } 568 }
552 569
553 void handleCatchBlock(Token onKeyword, Token catchKeyword) { 570 void handleCatchBlock(Token onKeyword, Token catchKeyword) {
554 debugEvent("CatchBlock"); 571 debugEvent("CatchBlock");
555 Block body = pop(); 572 Block body = pop();
556 FormalParameterList catchParameters = popIfNotNull(catchKeyword); 573 FormalParameterList catchParameters = popIfNotNull(catchKeyword);
557 if (catchKeyword != null) { 574 if (catchKeyword != null) {
558 exitLocalScope(); 575 exitLocalScope();
559 } 576 }
560 TypeName type = popIfNotNull(onKeyword); 577 TypeName type = popIfNotNull(onKeyword);
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after
1261 } 1278 }
1262 1279
1263 /// Data structure placed on the stack to represent the default parameter 1280 /// Data structure placed on the stack to represent the default parameter
1264 /// value with the separator token. 1281 /// value with the separator token.
1265 class _ParameterDefaultValue { 1282 class _ParameterDefaultValue {
1266 final Token separator; 1283 final Token separator;
1267 final Expression value; 1284 final Expression value;
1268 1285
1269 _ParameterDefaultValue(this.separator, this.value); 1286 _ParameterDefaultValue(this.separator, this.value);
1270 } 1287 }
1288
1289 /// Data structure placed on the stack as a container for optional parameters.
1290 class _OptionalFormalParameters {
1291 final List<FormalParameter> parameters;
1292 final Token leftDelimiter;
1293 final Token rightDelimiter;
1294
1295 _OptionalFormalParameters(
1296 this.parameters, this.leftDelimiter, this.rightDelimiter);
1297 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/generated/parser_fasta_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698