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

Side by Side Diff: runtime/vm/parser.cc

Issue 45833002: Disallow explicit parameter default values in redirecting factory (issue 13662). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | sdk/lib/async/zone.dart » ('j') | 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 #include "vm/parser.h" 5 #include "vm/parser.h"
6 6
7 #include "lib/invocation_mirror.h" 7 #include "lib/invocation_mirror.h"
8 #include "vm/bigint_operations.h" 8 #include "vm/bigint_operations.h"
9 #include "vm/bootstrap.h" 9 #include "vm/bootstrap.h"
10 #include "vm/class_finalizer.h" 10 #include "vm/class_finalizer.h"
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 struct ParamList { 437 struct ParamList {
438 ParamList() { 438 ParamList() {
439 Clear(); 439 Clear();
440 } 440 }
441 441
442 void Clear() { 442 void Clear() {
443 num_fixed_parameters = 0; 443 num_fixed_parameters = 0;
444 num_optional_parameters = 0; 444 num_optional_parameters = 0;
445 has_optional_positional_parameters = false; 445 has_optional_positional_parameters = false;
446 has_optional_named_parameters = false; 446 has_optional_named_parameters = false;
447 has_explicit_default_values = false;
447 has_field_initializer = false; 448 has_field_initializer = false;
448 implicitly_final = false; 449 implicitly_final = false;
449 skipped = false; 450 skipped = false;
450 this->parameters = new ZoneGrowableArray<ParamDesc>(); 451 this->parameters = new ZoneGrowableArray<ParamDesc>();
451 } 452 }
452 453
453 void AddFinalParameter(intptr_t name_pos, 454 void AddFinalParameter(intptr_t name_pos,
454 const String* name, 455 const String* name,
455 const AbstractType* type) { 456 const AbstractType* type) {
456 this->num_fixed_parameters++; 457 this->num_fixed_parameters++;
(...skipping 25 matching lines...) Expand all
482 } 483 }
483 484
484 void SetImplicitlyFinal() { 485 void SetImplicitlyFinal() {
485 implicitly_final = true; 486 implicitly_final = true;
486 } 487 }
487 488
488 int num_fixed_parameters; 489 int num_fixed_parameters;
489 int num_optional_parameters; 490 int num_optional_parameters;
490 bool has_optional_positional_parameters; 491 bool has_optional_positional_parameters;
491 bool has_optional_named_parameters; 492 bool has_optional_named_parameters;
493 bool has_explicit_default_values;
492 bool has_field_initializer; 494 bool has_field_initializer;
493 bool implicitly_final; 495 bool implicitly_final;
494 bool skipped; 496 bool skipped;
495 ZoneGrowableArray<ParamDesc>* parameters; 497 ZoneGrowableArray<ParamDesc>* parameters;
496 }; 498 };
497 499
498 500
499 struct MemberDesc { 501 struct MemberDesc {
500 MemberDesc() { 502 MemberDesc() {
501 Clear(); 503 Clear();
(...skipping 969 matching lines...) Expand 10 before | Expand all | Expand 10 after
1471 !params->has_optional_named_parameters) || 1473 !params->has_optional_named_parameters) ||
1472 !allow_explicit_default_value) { 1474 !allow_explicit_default_value) {
1473 ErrorMsg("parameter must not specify a default value"); 1475 ErrorMsg("parameter must not specify a default value");
1474 } 1476 }
1475 if (params->has_optional_positional_parameters) { 1477 if (params->has_optional_positional_parameters) {
1476 ExpectToken(Token::kASSIGN); 1478 ExpectToken(Token::kASSIGN);
1477 } else { 1479 } else {
1478 ExpectToken(Token::kCOLON); 1480 ExpectToken(Token::kCOLON);
1479 } 1481 }
1480 params->num_optional_parameters++; 1482 params->num_optional_parameters++;
1483 params->has_explicit_default_values = true; // Also if explicitly NULL.
1481 if (is_top_level_) { 1484 if (is_top_level_) {
1482 // Skip default value parsing. 1485 // Skip default value parsing.
1483 SkipExpr(); 1486 SkipExpr();
1484 } else { 1487 } else {
1485 const Object& const_value = ParseConstExpr()->literal(); 1488 const Object& const_value = ParseConstExpr()->literal();
1486 parameter.default_value = &const_value; 1489 parameter.default_value = &const_value;
1487 } 1490 }
1488 } else { 1491 } else {
1489 if (params->has_optional_positional_parameters || 1492 if (params->has_optional_positional_parameters ||
1490 params->has_optional_named_parameters) { 1493 params->has_optional_named_parameters) {
(...skipping 1525 matching lines...) Expand 10 before | Expand all | Expand 10 after
3016 ErrorMsg(method->name_pos, "illegal %s parameters", 3019 ErrorMsg(method->name_pos, "illegal %s parameters",
3017 method->IsGetter() ? "getter" : "setter"); 3020 method->IsGetter() ? "getter" : "setter");
3018 } 3021 }
3019 } 3022 }
3020 3023
3021 // Parse redirecting factory constructor. 3024 // Parse redirecting factory constructor.
3022 Type& redirection_type = Type::Handle(); 3025 Type& redirection_type = Type::Handle();
3023 String& redirection_identifier = String::Handle(); 3026 String& redirection_identifier = String::Handle();
3024 bool is_redirecting = false; 3027 bool is_redirecting = false;
3025 if (method->IsFactory() && (CurrentToken() == Token::kASSIGN)) { 3028 if (method->IsFactory() && (CurrentToken() == Token::kASSIGN)) {
3029 // Default parameter values are disallowed in redirecting factories.
3030 if (method->params.has_explicit_default_values) {
3031 ErrorMsg("redirecting factory '%s' may not specify a default value "
hausner 2013/10/25 22:26:38 Should this message use plural, like: may not spec
regis 2013/10/25 22:54:42 The spec uses singular, but I changed it to plural
3032 "for an optional parameter",
3033 method->name->ToCString());
3034 }
3026 ConsumeToken(); 3035 ConsumeToken();
3027 const intptr_t type_pos = TokenPos(); 3036 const intptr_t type_pos = TokenPos();
3028 is_redirecting = true; 3037 is_redirecting = true;
3029 const AbstractType& type = AbstractType::Handle( 3038 const AbstractType& type = AbstractType::Handle(
3030 ParseType(ClassFinalizer::kResolveTypeParameters)); 3039 ParseType(ClassFinalizer::kResolveTypeParameters));
3031 if (!type.IsMalformed() && type.IsTypeParameter()) { 3040 if (!type.IsMalformed() && type.IsTypeParameter()) {
3032 // Replace the type with a malformed type and compile a throw when called. 3041 // Replace the type with a malformed type and compile a throw when called.
3033 redirection_type = ClassFinalizer::NewFinalizedMalformedType( 3042 redirection_type = ClassFinalizer::NewFinalizedMalformedType(
3034 Error::Handle(), // No previous error. 3043 Error::Handle(), // No previous error.
3035 script_, 3044 script_,
(...skipping 7543 matching lines...) Expand 10 before | Expand all | Expand 10 after
10579 void Parser::SkipQualIdent() { 10588 void Parser::SkipQualIdent() {
10580 ASSERT(IsIdentifier()); 10589 ASSERT(IsIdentifier());
10581 ConsumeToken(); 10590 ConsumeToken();
10582 if (CurrentToken() == Token::kPERIOD) { 10591 if (CurrentToken() == Token::kPERIOD) {
10583 ConsumeToken(); // Consume the kPERIOD token. 10592 ConsumeToken(); // Consume the kPERIOD token.
10584 ExpectIdentifier("identifier expected after '.'"); 10593 ExpectIdentifier("identifier expected after '.'");
10585 } 10594 }
10586 } 10595 }
10587 10596
10588 } // namespace dart 10597 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/async/zone.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698