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

Side by Side Diff: pkg/front_end/lib/src/fasta/source/outline_builder.dart

Issue 2926953004: Various semantic checks on formal parameters. (Closed)
Patch Set: Added missing FASTA_IGNORED and rebased on aa8ca9244a3cc5fa7c3816a9340558e7d2f37ae1. Created 3 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) 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.outline_builder; 5 library fasta.outline_builder;
6 6
7 import 'package:kernel/ast.dart' show ProcedureKind; 7 import 'package:kernel/ast.dart' show ProcedureKind;
8 8
9 import '../fasta_codes.dart' show FastaMessage, codeExpectedBlockToSkip; 9 import '../fasta_codes.dart' show FastaMessage, codeExpectedBlockToSkip;
10 10
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 for (FormalParameterBuilder parameter in parameters) { 514 for (FormalParameterBuilder parameter in parameters) {
515 parameter.kind = kind; 515 parameter.kind = kind;
516 } 516 }
517 push(parameters); 517 push(parameters);
518 } 518 }
519 519
520 @override 520 @override
521 void endFormalParameters( 521 void endFormalParameters(
522 int count, Token beginToken, Token endToken, MemberKind kind) { 522 int count, Token beginToken, Token endToken, MemberKind kind) {
523 debugEvent("FormalParameters"); 523 debugEvent("FormalParameters");
524 List formals = popList(count); 524 List<FormalParameterBuilder> formals;
525 if (formals != null && formals.isNotEmpty) { 525 if (count == 1) {
danrubel 2017/06/09 17:08:52 It feels like these if / else if blocks should be
ahe 2017/06/09 18:53:31 I think this code needs some TLC :-)
526 var last = formals.last; 526 var last = pop();
527 if (last is List) { 527 if (last is List) {
528 // TODO(sigmund): change `List newList` back to `var` (this is a 528 formals = new List<FormalParameterBuilder>.from(last);
danrubel 2017/06/09 17:08:52 Will `last` ever have zero entries, or more than c
ahe 2017/06/09 18:53:31 This is a problem with how the parser generates ev
529 // workaround for issue #28651). Eventually, make optional 529 } else {
530 // formals a separate stack entry (#28673). 530 formals = <FormalParameterBuilder>[last];
531 List newList =
532 new List<FormalParameterBuilder>(formals.length - 1 + last.length);
533 newList.setRange(0, formals.length - 1, formals);
534 newList.setRange(formals.length - 1, newList.length, last);
535 for (int i = 0; i < last.length; i++) {
536 newList[i + formals.length - 1] = last[i];
537 }
538 formals = newList;
539 } 531 }
532 } else if (count > 1) {
533 var last = pop();
534 count--;
535 if (last is List) {
536 formals = new List<FormalParameterBuilder>.filled(
537 count + last.length, null,
538 growable: true);
539 // ignore: ARGUMENT_TYPE_NOT_ASSIGNABLE
540 formals.setRange(count, formals.length, last);
541 } else {
542 formals = new List<FormalParameterBuilder>.filled(count + 1, null,
543 growable: true);
544 formals[count] = last;
545 }
546 popList(count, formals);
540 } 547 }
541 if (formals != null) { 548 if (formals != null) {
542 for (var formal in formals) { 549 if (formals.length == 2) {
543 if (formal is! FormalParameterBuilder) { 550 // The name may be null for generalized function types.
544 internalError(formals); 551 if (formals[0].name != null && formals[0].name == formals[1].name) {
552 library.addCompileTimeError(formals[1].charOffset,
553 "Duplicated parameter name '${formals[1].name}'.");
554 library.addCompileTimeError(formals[0].charOffset,
555 "Other parameter named '${formals[1].name}'.");
556 }
557 } else if (formals.length > 2) {
558 Map<String, FormalParameterBuilder> seenNames =
559 <String, FormalParameterBuilder>{};
560 for (FormalParameterBuilder formal in formals) {
561 if (formal.name == null) continue;
562 if (seenNames.containsKey(formal.name)) {
563 library.addCompileTimeError(formal.charOffset,
564 "Duplicated parameter name '${formal.name}'.");
565 library.addCompileTimeError(seenNames[formal.name].charOffset,
566 "Other parameter named '${formal.name}'.");
567 } else {
568 seenNames[formal.name] = formal;
569 }
545 } 570 }
546 } 571 }
547 formals = new List<FormalParameterBuilder>.from(formals);
548 } 572 }
549 push(beginToken.charOffset); 573 push(beginToken.charOffset);
550 push(formals ?? NullValue.FormalParameters); 574 push(formals ?? NullValue.FormalParameters);
551 } 575 }
552 576
553 @override 577 @override
554 void handleNoFormalParameters(Token token, MemberKind kind) { 578 void handleNoFormalParameters(Token token, MemberKind kind) {
555 push(token.charOffset); 579 push(token.charOffset);
556 super.handleNoFormalParameters(token, kind); 580 super.handleNoFormalParameters(token, kind);
557 } 581 }
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 Link<Token> handleMemberName(Link<Token> identifiers) { 834 Link<Token> handleMemberName(Link<Token> identifiers) {
811 if (!enableNative || identifiers.isEmpty) return identifiers; 835 if (!enableNative || identifiers.isEmpty) return identifiers;
812 return removeNativeClause(identifiers); 836 return removeNativeClause(identifiers);
813 } 837 }
814 838
815 @override 839 @override
816 void debugEvent(String name) { 840 void debugEvent(String name) {
817 // printEvent(name); 841 // printEvent(name);
818 } 842 }
819 } 843 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698