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 | 6 |
7 #include "vm/bigint_operations.h" | 7 #include "vm/bigint_operations.h" |
8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
10 #include "vm/compiler_stats.h" | 10 #include "vm/compiler_stats.h" |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 String::Handle(Symbols::SavedArgDescVarPrefix()))) { | 136 String::Handle(Symbols::SavedArgDescVarPrefix()))) { |
137 return saved_args_desc_var; | 137 return saved_args_desc_var; |
138 } | 138 } |
139 } | 139 } |
140 return NULL; | 140 return NULL; |
141 } | 141 } |
142 | 142 |
143 | 143 |
144 void ParsedFunction::AllocateVariables() { | 144 void ParsedFunction::AllocateVariables() { |
145 LocalScope* scope = node_sequence()->scope(); | 145 LocalScope* scope = node_sequence()->scope(); |
146 const int fixed_parameter_count = function().num_fixed_parameters(); | 146 const intptr_t num_fixed_params = function().num_fixed_parameters(); |
147 const int optional_parameter_count = function().num_optional_parameters(); | 147 const intptr_t num_opt_pos_params = |
148 int parameter_count = fixed_parameter_count + optional_parameter_count; | 148 function().num_optional_positional_parameters(); |
| 149 const intptr_t num_opt_named_params = |
| 150 function().num_optional_named_parameters(); |
| 151 const intptr_t num_opt_params = num_opt_pos_params + num_opt_named_params; |
| 152 intptr_t num_params = num_fixed_params + num_opt_params; |
149 const bool is_native_instance_closure = | 153 const bool is_native_instance_closure = |
150 function().is_native() && function().IsImplicitInstanceClosureFunction(); | 154 function().is_native() && function().IsImplicitInstanceClosureFunction(); |
151 // Compute start indices to parameters and locals, and the number of | 155 // Compute start indices to parameters and locals, and the number of |
152 // parameters to copy. | 156 // parameters to copy. |
153 if ((optional_parameter_count == 0) && !is_native_instance_closure) { | 157 if ((num_opt_params == 0) && !is_native_instance_closure) { |
154 // Parameter i will be at fp[1 + parameter_count - i] and local variable | 158 // Parameter i will be at fp[1 + num_params - i] and local variable |
155 // j will be at fp[kFirstLocalSlotIndex - j]. | 159 // j will be at fp[kFirstLocalSlotIndex - j]. |
156 ASSERT(GetSavedArgumentsDescriptorVar() == NULL); | 160 ASSERT(GetSavedArgumentsDescriptorVar() == NULL); |
157 first_parameter_index_ = 1 + parameter_count; | 161 first_parameter_index_ = 1 + num_params; |
158 first_stack_local_index_ = kFirstLocalSlotIndex; | 162 first_stack_local_index_ = kFirstLocalSlotIndex; |
159 copied_parameter_count_ = 0; | 163 num_copied_params_ = 0; |
160 } else { | 164 } else { |
161 // Parameter i will be at fp[kFirstLocalSlotIndex - i] and local variable | 165 // Parameter i will be at fp[kFirstLocalSlotIndex - i] and local variable |
162 // j will be at fp[kFirstLocalSlotIndex - parameter_count - j]. | 166 // j will be at fp[kFirstLocalSlotIndex - num_params - j]. |
163 // The saved argument descriptor variable must be allocated similarly to | 167 // The saved argument descriptor variable must be allocated similarly to |
164 // a parameter, so that it gets both a frame slot and a context slot when | 168 // a parameter, so that it gets both a frame slot and a context slot when |
165 // captured. | 169 // captured. |
166 if (GetSavedArgumentsDescriptorVar() != NULL) { | 170 if (GetSavedArgumentsDescriptorVar() != NULL) { |
167 parameter_count += 1; | 171 num_params += 1; |
168 } | 172 } |
169 first_parameter_index_ = kFirstLocalSlotIndex; | 173 first_parameter_index_ = kFirstLocalSlotIndex; |
170 first_stack_local_index_ = first_parameter_index_ - parameter_count; | 174 first_stack_local_index_ = first_parameter_index_ - num_params; |
171 copied_parameter_count_ = parameter_count; | 175 num_copied_params_ = num_params; |
172 if (is_native_instance_closure) { | 176 if (is_native_instance_closure) { |
173 copied_parameter_count_ += 1; | 177 num_copied_params_ += 1; |
174 first_parameter_index_ -= 1; | 178 first_parameter_index_ -= 1; |
175 first_stack_local_index_ -= 1; | 179 first_stack_local_index_ -= 1; |
176 } | 180 } |
177 } | 181 } |
178 | 182 |
179 // Allocate parameters and local variables, either in the local frame or | 183 // Allocate parameters and local variables, either in the local frame or |
180 // in the context(s). | 184 // in the context(s). |
181 LocalScope* context_owner = NULL; // No context needed yet. | 185 LocalScope* context_owner = NULL; // No context needed yet. |
182 int next_free_frame_index = | 186 int next_free_frame_index = |
183 scope->AllocateVariables(first_parameter_index_, | 187 scope->AllocateVariables(first_parameter_index_, |
184 parameter_count, | 188 num_params, |
185 first_stack_local_index_, | 189 first_stack_local_index_, |
186 scope, | 190 scope, |
187 &context_owner); | 191 &context_owner); |
188 | 192 |
189 // If this function is not a closure function and if it contains captured | 193 // If this function is not a closure function and if it contains captured |
190 // variables, the context needs to be saved on entry and restored on exit. | 194 // variables, the context needs to be saved on entry and restored on exit. |
191 // Add and allocate a local variable to this purpose. | 195 // Add and allocate a local variable to this purpose. |
192 if ((context_owner != NULL) && !function().IsClosureFunction()) { | 196 if ((context_owner != NULL) && !function().IsClosureFunction()) { |
193 const String& context_var_name = | 197 const String& context_var_name = |
194 String::ZoneHandle(Symbols::SavedEntryContextVar()); | 198 String::ZoneHandle(Symbols::SavedEntryContextVar()); |
195 LocalVariable* context_var = | 199 LocalVariable* context_var = |
196 new LocalVariable(function().token_pos(), | 200 new LocalVariable(function().token_pos(), |
197 context_var_name, | 201 context_var_name, |
198 Type::ZoneHandle(Type::DynamicType())); | 202 Type::ZoneHandle(Type::DynamicType())); |
199 context_var->set_index(next_free_frame_index--); | 203 context_var->set_index(next_free_frame_index--); |
200 scope->AddVariable(context_var); | 204 scope->AddVariable(context_var); |
201 set_saved_context_var(context_var); | 205 set_saved_context_var(context_var); |
202 } | 206 } |
203 | 207 |
204 // Frame indices are relative to the frame pointer and are decreasing. | 208 // Frame indices are relative to the frame pointer and are decreasing. |
205 ASSERT(next_free_frame_index <= first_stack_local_index_); | 209 ASSERT(next_free_frame_index <= first_stack_local_index_); |
206 stack_local_count_ = first_stack_local_index_ - next_free_frame_index; | 210 num_stack_locals_ = first_stack_local_index_ - next_free_frame_index; |
207 } | 211 } |
208 | 212 |
209 | 213 |
210 struct Parser::Block : public ZoneAllocated { | 214 struct Parser::Block : public ZoneAllocated { |
211 Block(Block* outer_block, LocalScope* local_scope, SequenceNode* seq) | 215 Block(Block* outer_block, LocalScope* local_scope, SequenceNode* seq) |
212 : parent(outer_block), scope(local_scope), statements(seq) { | 216 : parent(outer_block), scope(local_scope), statements(seq) { |
213 ASSERT(scope != NULL); | 217 ASSERT(scope != NULL); |
214 ASSERT(statements != NULL); | 218 ASSERT(statements != NULL); |
215 } | 219 } |
216 Block* parent; // Enclosing block, or NULL if outermost. | 220 Block* parent; // Enclosing block, or NULL if outermost. |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 | 424 |
421 | 425 |
422 struct ParamList { | 426 struct ParamList { |
423 ParamList() { | 427 ParamList() { |
424 Clear(); | 428 Clear(); |
425 } | 429 } |
426 | 430 |
427 void Clear() { | 431 void Clear() { |
428 num_fixed_parameters = 0; | 432 num_fixed_parameters = 0; |
429 num_optional_parameters = 0; | 433 num_optional_parameters = 0; |
430 has_named_optional_parameters = false; | 434 has_optional_positional_parameters = false; |
| 435 has_optional_named_parameters = false; |
431 has_field_initializer = false; | 436 has_field_initializer = false; |
432 implicitly_final = false; | 437 implicitly_final = false; |
433 this->parameters = new ZoneGrowableArray<ParamDesc>(); | 438 this->parameters = new ZoneGrowableArray<ParamDesc>(); |
434 } | 439 } |
435 | 440 |
436 void AddFinalParameter(intptr_t name_pos, | 441 void AddFinalParameter(intptr_t name_pos, |
437 String* name, | 442 String* name, |
438 const AbstractType* type) { | 443 const AbstractType* type) { |
439 this->num_fixed_parameters++; | 444 this->num_fixed_parameters++; |
440 ParamDesc param; | 445 ParamDesc param; |
(...skipping 10 matching lines...) Expand all Loading... |
451 &String::ZoneHandle(Symbols::This()), | 456 &String::ZoneHandle(Symbols::This()), |
452 receiver_type); | 457 receiver_type); |
453 } | 458 } |
454 | 459 |
455 void SetImplicitlyFinal() { | 460 void SetImplicitlyFinal() { |
456 implicitly_final = true; | 461 implicitly_final = true; |
457 } | 462 } |
458 | 463 |
459 int num_fixed_parameters; | 464 int num_fixed_parameters; |
460 int num_optional_parameters; | 465 int num_optional_parameters; |
461 bool has_named_optional_parameters; // Indicates use of the new syntax. | 466 bool has_optional_positional_parameters; |
| 467 bool has_optional_named_parameters; |
462 bool has_field_initializer; | 468 bool has_field_initializer; |
463 bool implicitly_final; | 469 bool implicitly_final; |
464 ZoneGrowableArray<ParamDesc>* parameters; | 470 ZoneGrowableArray<ParamDesc>* parameters; |
465 }; | 471 }; |
466 | 472 |
467 | 473 |
468 struct MemberDesc { | 474 struct MemberDesc { |
469 MemberDesc() { | 475 MemberDesc() { |
470 Clear(); | 476 Clear(); |
471 } | 477 } |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
766 | 772 |
767 // TODO(regis): Implement support for non-const final static fields (currently | 773 // TODO(regis): Implement support for non-const final static fields (currently |
768 // supported "final" fields are actually const fields). | 774 // supported "final" fields are actually const fields). |
769 // TODO(regis): Since a const variable is implicitly final, | 775 // TODO(regis): Since a const variable is implicitly final, |
770 // rename ParseStaticConstGetter to ParseStaticFinalGetter and | 776 // rename ParseStaticConstGetter to ParseStaticFinalGetter and |
771 // rename kConstImplicitGetter to kImplicitFinalGetter. | 777 // rename kConstImplicitGetter to kImplicitFinalGetter. |
772 SequenceNode* Parser::ParseStaticConstGetter(const Function& func) { | 778 SequenceNode* Parser::ParseStaticConstGetter(const Function& func) { |
773 TRACE_PARSER("ParseStaticConstGetter"); | 779 TRACE_PARSER("ParseStaticConstGetter"); |
774 ParamList params; | 780 ParamList params; |
775 ASSERT(func.num_fixed_parameters() == 0); // static. | 781 ASSERT(func.num_fixed_parameters() == 0); // static. |
776 ASSERT(func.num_optional_parameters() == 0); | 782 ASSERT(!func.HasOptionalParameters()); |
777 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); | 783 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); |
778 | 784 |
779 // Build local scope for function and populate with the formal parameters. | 785 // Build local scope for function and populate with the formal parameters. |
780 OpenFunctionBlock(func); | 786 OpenFunctionBlock(func); |
781 AddFormalParamsToScope(¶ms, current_block_->scope); | 787 AddFormalParamsToScope(¶ms, current_block_->scope); |
782 | 788 |
783 const String& field_name = *ExpectIdentifier("field name expected"); | 789 const String& field_name = *ExpectIdentifier("field name expected"); |
784 const Class& field_class = Class::Handle(func.Owner()); | 790 const Class& field_class = Class::Handle(func.Owner()); |
785 const Field& field = | 791 const Field& field = |
786 Field::ZoneHandle(field_class.LookupStaticField(field_name)); | 792 Field::ZoneHandle(field_class.LookupStaticField(field_name)); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
882 // Create AstNodes for an implicit instance getter method: | 888 // Create AstNodes for an implicit instance getter method: |
883 // LoadLocalNode 0 ('this'); | 889 // LoadLocalNode 0 ('this'); |
884 // LoadInstanceFieldNode (field_name); | 890 // LoadInstanceFieldNode (field_name); |
885 // ReturnNode (field's value); | 891 // ReturnNode (field's value); |
886 SequenceNode* Parser::ParseInstanceGetter(const Function& func) { | 892 SequenceNode* Parser::ParseInstanceGetter(const Function& func) { |
887 TRACE_PARSER("ParseInstanceGetter"); | 893 TRACE_PARSER("ParseInstanceGetter"); |
888 ParamList params; | 894 ParamList params; |
889 ASSERT(current_class().raw() == func.Owner()); | 895 ASSERT(current_class().raw() == func.Owner()); |
890 params.AddReceiver(ReceiverType(TokenPos())); | 896 params.AddReceiver(ReceiverType(TokenPos())); |
891 ASSERT(func.num_fixed_parameters() == 1); // receiver. | 897 ASSERT(func.num_fixed_parameters() == 1); // receiver. |
892 ASSERT(func.num_optional_parameters() == 0); | 898 ASSERT(!func.HasOptionalParameters()); |
893 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); | 899 ASSERT(AbstractType::Handle(func.result_type()).IsResolved()); |
894 | 900 |
895 // Build local scope for function and populate with the formal parameters. | 901 // Build local scope for function and populate with the formal parameters. |
896 OpenFunctionBlock(func); | 902 OpenFunctionBlock(func); |
897 AddFormalParamsToScope(¶ms, current_block_->scope); | 903 AddFormalParamsToScope(¶ms, current_block_->scope); |
898 | 904 |
899 // Receiver is local 0. | 905 // Receiver is local 0. |
900 LocalVariable* receiver = current_block_->scope->VariableAt(0); | 906 LocalVariable* receiver = current_block_->scope->VariableAt(0); |
901 LoadLocalNode* load_receiver = new LoadLocalNode(TokenPos(), receiver); | 907 LoadLocalNode* load_receiver = new LoadLocalNode(TokenPos(), receiver); |
902 // TokenPos() returns the function's token position which points to the | 908 // TokenPos() returns the function's token position which points to the |
(...skipping 28 matching lines...) Expand all Loading... |
931 Field::ZoneHandle(field_class.LookupInstanceField(field_name)); | 937 Field::ZoneHandle(field_class.LookupInstanceField(field_name)); |
932 const AbstractType& field_type = AbstractType::ZoneHandle(field.type()); | 938 const AbstractType& field_type = AbstractType::ZoneHandle(field.type()); |
933 | 939 |
934 ParamList params; | 940 ParamList params; |
935 ASSERT(current_class().raw() == func.Owner()); | 941 ASSERT(current_class().raw() == func.Owner()); |
936 params.AddReceiver(ReceiverType(TokenPos())); | 942 params.AddReceiver(ReceiverType(TokenPos())); |
937 params.AddFinalParameter(TokenPos(), | 943 params.AddFinalParameter(TokenPos(), |
938 &String::ZoneHandle(Symbols::Value()), | 944 &String::ZoneHandle(Symbols::Value()), |
939 &field_type); | 945 &field_type); |
940 ASSERT(func.num_fixed_parameters() == 2); // receiver, value. | 946 ASSERT(func.num_fixed_parameters() == 2); // receiver, value. |
941 ASSERT(func.num_optional_parameters() == 0); | 947 ASSERT(!func.HasOptionalParameters()); |
942 ASSERT(AbstractType::Handle(func.result_type()).IsVoidType()); | 948 ASSERT(AbstractType::Handle(func.result_type()).IsVoidType()); |
943 | 949 |
944 // Build local scope for function and populate with the formal parameters. | 950 // Build local scope for function and populate with the formal parameters. |
945 OpenFunctionBlock(func); | 951 OpenFunctionBlock(func); |
946 AddFormalParamsToScope(¶ms, current_block_->scope); | 952 AddFormalParamsToScope(¶ms, current_block_->scope); |
947 | 953 |
948 LoadLocalNode* receiver = | 954 LoadLocalNode* receiver = |
949 new LoadLocalNode(TokenPos(), current_block_->scope->VariableAt(0)); | 955 new LoadLocalNode(TokenPos(), current_block_->scope->VariableAt(0)); |
950 LoadLocalNode* value = | 956 LoadLocalNode* value = |
951 new LoadLocalNode(TokenPos(), current_block_->scope->VariableAt(1)); | 957 new LoadLocalNode(TokenPos(), current_block_->scope->VariableAt(1)); |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1132 Type& signature_type = Type::ZoneHandle(signature_class.SignatureType()); | 1138 Type& signature_type = Type::ZoneHandle(signature_class.SignatureType()); |
1133 if (!is_top_level_ && !signature_type.IsFinalized()) { | 1139 if (!is_top_level_ && !signature_type.IsFinalized()) { |
1134 signature_type ^= ClassFinalizer::FinalizeType( | 1140 signature_type ^= ClassFinalizer::FinalizeType( |
1135 signature_class, signature_type, ClassFinalizer::kCanonicalize); | 1141 signature_class, signature_type, ClassFinalizer::kCanonicalize); |
1136 } | 1142 } |
1137 // The type of the parameter is now the signature type. | 1143 // The type of the parameter is now the signature type. |
1138 parameter.type = &signature_type; | 1144 parameter.type = &signature_type; |
1139 } | 1145 } |
1140 } | 1146 } |
1141 | 1147 |
1142 if (CurrentToken() == Token::kASSIGN) { | 1148 if ((CurrentToken() == Token::kASSIGN) || (CurrentToken() == Token::kCOLON)) { |
1143 if (!params->has_named_optional_parameters || | 1149 if ((!params->has_optional_positional_parameters && |
| 1150 !params->has_optional_named_parameters) || |
1144 !allow_explicit_default_value) { | 1151 !allow_explicit_default_value) { |
1145 ErrorMsg("parameter must not specify a default value"); | 1152 ErrorMsg("parameter must not specify a default value"); |
1146 } | 1153 } |
1147 ConsumeToken(); | 1154 if (params->has_optional_positional_parameters) { |
| 1155 ExpectToken(Token::kASSIGN); |
| 1156 } else { |
| 1157 ExpectToken(Token::kCOLON); |
| 1158 } |
1148 params->num_optional_parameters++; | 1159 params->num_optional_parameters++; |
1149 if (is_top_level_) { | 1160 if (is_top_level_) { |
1150 // Skip default value parsing. | 1161 // Skip default value parsing. |
1151 SkipExpr(); | 1162 SkipExpr(); |
1152 } else { | 1163 } else { |
1153 const Object& const_value = ParseConstExpr()->literal(); | 1164 const Object& const_value = ParseConstExpr()->literal(); |
1154 parameter.default_value = &const_value; | 1165 parameter.default_value = &const_value; |
1155 } | 1166 } |
1156 } else { | 1167 } else { |
1157 if (params->has_named_optional_parameters) { | 1168 if (params->has_optional_positional_parameters || |
| 1169 params->has_optional_named_parameters) { |
1158 // Implicit default value is null. | 1170 // Implicit default value is null. |
1159 params->num_optional_parameters++; | 1171 params->num_optional_parameters++; |
1160 parameter.default_value = &Object::ZoneHandle(); | 1172 parameter.default_value = &Object::ZoneHandle(); |
1161 } else { | 1173 } else { |
1162 params->num_fixed_parameters++; | 1174 params->num_fixed_parameters++; |
1163 ASSERT(params->num_optional_parameters == 0); | 1175 ASSERT(params->num_optional_parameters == 0); |
1164 } | 1176 } |
1165 } | 1177 } |
1166 if (parameter.type->IsVoidType()) { | 1178 if (parameter.type->IsVoidType()) { |
1167 ErrorMsg("parameter '%s' may not be 'void'", parameter.name->ToCString()); | 1179 ErrorMsg("parameter '%s' may not be 'void'", parameter.name->ToCString()); |
1168 } | 1180 } |
1169 params->parameters->Add(parameter); | 1181 params->parameters->Add(parameter); |
1170 } | 1182 } |
1171 | 1183 |
1172 | 1184 |
1173 void Parser::ParseFormalParameterList(bool allow_explicit_default_values, | 1185 void Parser::ParseFormalParameterList(bool allow_explicit_default_values, |
1174 ParamList* params) { | 1186 ParamList* params) { |
1175 TRACE_PARSER("ParseFormalParameterList"); | 1187 TRACE_PARSER("ParseFormalParameterList"); |
1176 ASSERT(CurrentToken() == Token::kLPAREN); | 1188 ASSERT(CurrentToken() == Token::kLPAREN); |
1177 | 1189 |
1178 if (LookaheadToken(1) != Token::kRPAREN) { | 1190 if (LookaheadToken(1) != Token::kRPAREN) { |
1179 // Parse positional parameters. | 1191 // Parse fixed parameters. |
1180 ParseFormalParameters(allow_explicit_default_values, params); | 1192 ParseFormalParameters(allow_explicit_default_values, params); |
1181 if (params->has_named_optional_parameters) { | 1193 if (params->has_optional_positional_parameters || |
1182 // Parse named optional parameters. | 1194 params->has_optional_named_parameters) { |
| 1195 // Parse optional parameters. |
1183 ParseFormalParameters(allow_explicit_default_values, params); | 1196 ParseFormalParameters(allow_explicit_default_values, params); |
1184 if (CurrentToken() != Token::kRBRACK) { | 1197 if (params->has_optional_positional_parameters) { |
1185 ErrorMsg("',' or ']' expected"); | 1198 if (CurrentToken() != Token::kRBRACK) { |
| 1199 ErrorMsg("',' or ']' expected"); |
| 1200 } |
| 1201 } else { |
| 1202 if (CurrentToken() != Token::kRBRACE) { |
| 1203 ErrorMsg("',' or '}' expected"); |
| 1204 } |
1186 } | 1205 } |
1187 ExpectToken(Token::kRBRACK); | 1206 ConsumeToken(); // ']' or '}'. |
1188 } | 1207 } |
1189 if ((CurrentToken() != Token::kRPAREN) && | 1208 if ((CurrentToken() != Token::kRPAREN) && |
1190 !params->has_named_optional_parameters) { | 1209 !params->has_optional_positional_parameters && |
| 1210 !params->has_optional_named_parameters) { |
1191 ErrorMsg("',' or ')' expected"); | 1211 ErrorMsg("',' or ')' expected"); |
1192 } | 1212 } |
1193 } else { | 1213 } else { |
1194 ConsumeToken(); | 1214 ConsumeToken(); |
1195 } | 1215 } |
1196 ExpectToken(Token::kRPAREN); | 1216 ExpectToken(Token::kRPAREN); |
1197 } | 1217 } |
1198 | 1218 |
1199 | 1219 |
1200 // Parses a sequence of normal or named formal parameters. | 1220 // Parses a sequence of normal or optional formal parameters. |
1201 void Parser::ParseFormalParameters(bool allow_explicit_default_values, | 1221 void Parser::ParseFormalParameters(bool allow_explicit_default_values, |
1202 ParamList* params) { | 1222 ParamList* params) { |
1203 TRACE_PARSER("ParseFormalParameters"); | 1223 TRACE_PARSER("ParseFormalParameters"); |
1204 do { | 1224 do { |
1205 ConsumeToken(); | 1225 ConsumeToken(); |
1206 if (!params->has_named_optional_parameters && | 1226 if (!params->has_optional_positional_parameters && |
| 1227 !params->has_optional_named_parameters && |
1207 (CurrentToken() == Token::kLBRACK)) { | 1228 (CurrentToken() == Token::kLBRACK)) { |
1208 // End of normal parameters, start of named parameters. | 1229 // End of normal parameters, start of optional positional parameters. |
1209 params->has_named_optional_parameters = true; | 1230 params->has_optional_positional_parameters = true; |
| 1231 return; |
| 1232 } |
| 1233 if (!params->has_optional_positional_parameters && |
| 1234 !params->has_optional_named_parameters && |
| 1235 (CurrentToken() == Token::kLBRACE)) { |
| 1236 // End of normal parameters, start of optional named parameters. |
| 1237 params->has_optional_named_parameters = true; |
1210 return; | 1238 return; |
1211 } | 1239 } |
1212 ParseFormalParameter(allow_explicit_default_values, params); | 1240 ParseFormalParameter(allow_explicit_default_values, params); |
1213 } while (CurrentToken() == Token::kCOMMA); | 1241 } while (CurrentToken() == Token::kCOMMA); |
1214 } | 1242 } |
1215 | 1243 |
1216 | 1244 |
1217 String& Parser::ParseNativeDeclaration() { | 1245 String& Parser::ParseNativeDeclaration() { |
1218 TRACE_PARSER("ParseNativeDeclaration"); | 1246 TRACE_PARSER("ParseNativeDeclaration"); |
1219 ASSERT(IsLiteral("native")); | 1247 ASSERT(IsLiteral("native")); |
(...skipping 1521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2741 expected_num_parameters = 2; | 2769 expected_num_parameters = 2; |
2742 } | 2770 } |
2743 } else if ((operator_token == Token::kNEGATE) || | 2771 } else if ((operator_token == Token::kNEGATE) || |
2744 (operator_token == Token::kBIT_NOT)) { | 2772 (operator_token == Token::kBIT_NOT)) { |
2745 // TODO(hausner): Remove support for keyword 'negate'. | 2773 // TODO(hausner): Remove support for keyword 'negate'. |
2746 expected_num_parameters = 1; | 2774 expected_num_parameters = 1; |
2747 } else { | 2775 } else { |
2748 expected_num_parameters = 2; | 2776 expected_num_parameters = 2; |
2749 } | 2777 } |
2750 if ((member.params.num_optional_parameters > 0) || | 2778 if ((member.params.num_optional_parameters > 0) || |
2751 (member.params.has_named_optional_parameters) || | 2779 member.params.has_optional_positional_parameters || |
| 2780 member.params.has_optional_named_parameters || |
2752 (member.params.num_fixed_parameters != expected_num_parameters)) { | 2781 (member.params.num_fixed_parameters != expected_num_parameters)) { |
2753 // Subtract receiver when reporting number of expected arguments. | 2782 // Subtract receiver when reporting number of expected arguments. |
2754 ErrorMsg(member.name_pos, "operator %s expects %"Pd" argument(s)", | 2783 ErrorMsg(member.name_pos, "operator %s expects %"Pd" argument(s)", |
2755 member.name->ToCString(), (expected_num_parameters - 1)); | 2784 member.name->ToCString(), (expected_num_parameters - 1)); |
2756 } | 2785 } |
2757 } | 2786 } |
2758 | 2787 |
2759 | 2788 |
2760 void Parser::ParseClassMemberDefinition(ClassDesc* members) { | 2789 void Parser::ParseClassMemberDefinition(ClassDesc* members) { |
2761 TRACE_PARSER("ParseClassMemberDefinition"); | 2790 TRACE_PARSER("ParseClassMemberDefinition"); |
(...skipping 1510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4272 } | 4301 } |
4273 } | 4302 } |
4274 } | 4303 } |
4275 | 4304 |
4276 | 4305 |
4277 // Populate the parameter type array and parameter name array of the function | 4306 // Populate the parameter type array and parameter name array of the function |
4278 // with the formal parameter types and names. | 4307 // with the formal parameter types and names. |
4279 void Parser::AddFormalParamsToFunction(const ParamList* params, | 4308 void Parser::AddFormalParamsToFunction(const ParamList* params, |
4280 const Function& func) { | 4309 const Function& func) { |
4281 ASSERT((params != NULL) && (params->parameters != NULL)); | 4310 ASSERT((params != NULL) && (params->parameters != NULL)); |
4282 func.set_num_fixed_parameters(params->num_fixed_parameters); | 4311 ASSERT((params->num_optional_parameters > 0) == |
4283 func.set_num_optional_parameters(params->num_optional_parameters); | 4312 (params->has_optional_positional_parameters || |
| 4313 params->has_optional_named_parameters)); |
| 4314 func.SetNumberOfParameters(params->num_fixed_parameters, |
| 4315 params->num_optional_parameters, |
| 4316 params->has_optional_positional_parameters); |
4284 const int num_parameters = params->parameters->length(); | 4317 const int num_parameters = params->parameters->length(); |
4285 ASSERT(num_parameters == func.NumberOfParameters()); | 4318 ASSERT(num_parameters == func.NumberOfParameters()); |
4286 func.set_parameter_types(Array::Handle(Array::New(num_parameters, | 4319 func.set_parameter_types(Array::Handle(Array::New(num_parameters, |
4287 Heap::kOld))); | 4320 Heap::kOld))); |
4288 func.set_parameter_names(Array::Handle(Array::New(num_parameters, | 4321 func.set_parameter_names(Array::Handle(Array::New(num_parameters, |
4289 Heap::kOld))); | 4322 Heap::kOld))); |
4290 for (int i = 0; i < num_parameters; i++) { | 4323 for (int i = 0; i < num_parameters; i++) { |
4291 ParamDesc& param_desc = (*params->parameters)[i]; | 4324 ParamDesc& param_desc = (*params->parameters)[i]; |
4292 ASSERT(is_top_level_ || param_desc.type->IsResolved()); | 4325 ASSERT(is_top_level_ || param_desc.type->IsResolved()); |
4293 func.SetParameterTypeAt(i, *param_desc.type); | 4326 func.SetParameterTypeAt(i, *param_desc.type); |
(...skipping 5110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9404 void Parser::SkipQualIdent() { | 9437 void Parser::SkipQualIdent() { |
9405 ASSERT(IsIdentifier()); | 9438 ASSERT(IsIdentifier()); |
9406 ConsumeToken(); | 9439 ConsumeToken(); |
9407 if (CurrentToken() == Token::kPERIOD) { | 9440 if (CurrentToken() == Token::kPERIOD) { |
9408 ConsumeToken(); // Consume the kPERIOD token. | 9441 ConsumeToken(); // Consume the kPERIOD token. |
9409 ExpectIdentifier("identifier expected after '.'"); | 9442 ExpectIdentifier("identifier expected after '.'"); |
9410 } | 9443 } |
9411 } | 9444 } |
9412 | 9445 |
9413 } // namespace dart | 9446 } // namespace dart |
OLD | NEW |