Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #include "vm/flags.h" | 6 #include "vm/flags.h" |
| 7 | 7 |
| 8 #ifndef DART_PRECOMPILED_RUNTIME | 8 #ifndef DART_PRECOMPILED_RUNTIME |
| 9 | 9 |
| 10 #include "lib/invocation_mirror.h" | 10 #include "lib/invocation_mirror.h" |
| (...skipping 2013 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2024 params->has_optional_positional_parameters = true; | 2024 params->has_optional_positional_parameters = true; |
| 2025 return; | 2025 return; |
| 2026 } | 2026 } |
| 2027 if (!params->has_optional_positional_parameters && | 2027 if (!params->has_optional_positional_parameters && |
| 2028 !params->has_optional_named_parameters && | 2028 !params->has_optional_named_parameters && |
| 2029 (CurrentToken() == Token::kLBRACE)) { | 2029 (CurrentToken() == Token::kLBRACE)) { |
| 2030 // End of normal parameters, start of optional named parameters. | 2030 // End of normal parameters, start of optional named parameters. |
| 2031 params->has_optional_named_parameters = true; | 2031 params->has_optional_named_parameters = true; |
| 2032 return; | 2032 return; |
| 2033 } | 2033 } |
| 2034 Token::Kind terminator = | |
| 2035 params->has_optional_positional_parameters ? Token::kRBRACK : | |
| 2036 params->has_optional_named_parameters ? Token::kRBRACE : | |
| 2037 Token :: kRPAREN; | |
| 2038 if (CurrentToken() == terminator) { | |
|
hausner
2016/06/22 17:50:25
You are allowing an empty list of optional positio
Lasse Reichstein Nielsen
2016/06/24 11:43:04
Good point.
Curiously, it's only an empty named b
| |
| 2039 // Allow a trailing comma. | |
| 2040 break; | |
| 2041 } | |
| 2034 ParseFormalParameter(allow_explicit_default_values, | 2042 ParseFormalParameter(allow_explicit_default_values, |
| 2035 evaluate_metadata, | 2043 evaluate_metadata, |
| 2036 params); | 2044 params); |
| 2037 } while (CurrentToken() == Token::kCOMMA); | 2045 } while (CurrentToken() == Token::kCOMMA); |
| 2038 } | 2046 } |
| 2039 | 2047 |
| 2040 | 2048 |
| 2041 void Parser::ParseFormalParameterList(bool allow_explicit_default_values, | 2049 void Parser::ParseFormalParameterList(bool allow_explicit_default_values, |
| 2042 bool evaluate_metadata, | 2050 bool evaluate_metadata, |
| 2043 ParamList* params) { | 2051 ParamList* params) { |
| (...skipping 9068 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 11112 const bool saved_mode = SetAllowFunctionLiterals(true); | 11120 const bool saved_mode = SetAllowFunctionLiterals(true); |
| 11113 ArgumentListNode* arguments; | 11121 ArgumentListNode* arguments; |
| 11114 if (implicit_arguments == NULL) { | 11122 if (implicit_arguments == NULL) { |
| 11115 arguments = new(Z) ArgumentListNode(TokenPos()); | 11123 arguments = new(Z) ArgumentListNode(TokenPos()); |
| 11116 } else { | 11124 } else { |
| 11117 arguments = implicit_arguments; | 11125 arguments = implicit_arguments; |
| 11118 } | 11126 } |
| 11119 const GrowableObjectArray& names = | 11127 const GrowableObjectArray& names = |
| 11120 GrowableObjectArray::Handle(Z, GrowableObjectArray::New(Heap::kOld)); | 11128 GrowableObjectArray::Handle(Z, GrowableObjectArray::New(Heap::kOld)); |
| 11121 bool named_argument_seen = false; | 11129 bool named_argument_seen = false; |
| 11122 if (LookaheadToken(1) != Token::kRPAREN) { | 11130 if (LookaheadToken(1) != Token::kRPAREN) { |
|
hausner
2016/06/22 17:50:25
This special case for the empty argument list is n
Lasse Reichstein Nielsen
2016/06/24 11:43:04
True. It won't when I add code to prevent the empt
| |
| 11123 String& arg_name = String::Handle(Z); | 11131 String& arg_name = String::Handle(Z); |
| 11124 do { | 11132 do { |
| 11125 ASSERT((CurrentToken() == Token::kLPAREN) || | 11133 ASSERT((CurrentToken() == Token::kLPAREN) || |
| 11126 (CurrentToken() == Token::kCOMMA)); | 11134 (CurrentToken() == Token::kCOMMA)); |
| 11127 ConsumeToken(); | 11135 ConsumeToken(); |
| 11136 if (CurrentToken() == Token::kRPAREN) { | |
| 11137 // Allow trailing comma. | |
| 11138 break; | |
| 11139 } | |
| 11128 if (IsIdentifier() && (LookaheadToken(1) == Token::kCOLON)) { | 11140 if (IsIdentifier() && (LookaheadToken(1) == Token::kCOLON)) { |
| 11129 named_argument_seen = true; | 11141 named_argument_seen = true; |
| 11130 // The canonicalization of the arguments descriptor array built in | 11142 // The canonicalization of the arguments descriptor array built in |
| 11131 // the code generator requires that the names are symbols, i.e. | 11143 // the code generator requires that the names are symbols, i.e. |
| 11132 // canonicalized strings. | 11144 // canonicalized strings. |
| 11133 ASSERT(CurrentLiteral()->IsSymbol()); | 11145 ASSERT(CurrentLiteral()->IsSymbol()); |
| 11134 for (int i = 0; i < names.Length(); i++) { | 11146 for (int i = 0; i < names.Length(); i++) { |
| 11135 arg_name ^= names.At(i); | 11147 arg_name ^= names.At(i); |
| 11136 if (CurrentLiteral()->Equals(arg_name)) { | 11148 if (CurrentLiteral()->Equals(arg_name)) { |
| 11137 ReportError("duplicate named argument"); | 11149 ReportError("duplicate named argument"); |
| (...skipping 3362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 14500 const ArgumentListNode& function_args, | 14512 const ArgumentListNode& function_args, |
| 14501 const LocalVariable* temp_for_last_arg, | 14513 const LocalVariable* temp_for_last_arg, |
| 14502 bool is_super_invocation) { | 14514 bool is_super_invocation) { |
| 14503 UNREACHABLE(); | 14515 UNREACHABLE(); |
| 14504 return NULL; | 14516 return NULL; |
| 14505 } | 14517 } |
| 14506 | 14518 |
| 14507 } // namespace dart | 14519 } // namespace dart |
| 14508 | 14520 |
| 14509 #endif // DART_PRECOMPILED_RUNTIME | 14521 #endif // DART_PRECOMPILED_RUNTIME |
| OLD | NEW |