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/object.h" | 5 #include "vm/object.h" |
6 | 6 |
7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
10 #include "vm/cpu.h" | 10 #include "vm/cpu.h" |
(...skipping 4079 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4090 // marked as non-static, but they do not have a receiver. | 4090 // marked as non-static, but they do not have a receiver. |
4091 // Closures are handled above. | 4091 // Closures are handled above. |
4092 ASSERT((kind() != RawFunction::kClosureFunction) && | 4092 ASSERT((kind() != RawFunction::kClosureFunction) && |
4093 (kind() != RawFunction::kSignatureFunction)); | 4093 (kind() != RawFunction::kSignatureFunction)); |
4094 return 1; // Receiver. | 4094 return 1; // Receiver. |
4095 } | 4095 } |
4096 return 0; // No implicit parameters. | 4096 return 0; // No implicit parameters. |
4097 } | 4097 } |
4098 | 4098 |
4099 | 4099 |
4100 bool Function::AreValidArgumentCounts(int num_arguments, | 4100 bool Function::AreValidArgumentCounts(intptr_t num_arguments, |
4101 int num_named_arguments, | 4101 intptr_t num_named_arguments, |
4102 String* error_message) const { | 4102 String* error_message) const { |
4103 if (num_named_arguments > NumOptionalNamedParameters()) { | 4103 if (num_named_arguments > NumOptionalNamedParameters()) { |
4104 if (error_message != NULL) { | 4104 if (error_message != NULL) { |
4105 const intptr_t kMessageBufferSize = 64; | 4105 const intptr_t kMessageBufferSize = 64; |
4106 char message_buffer[kMessageBufferSize]; | 4106 char message_buffer[kMessageBufferSize]; |
4107 OS::SNPrint(message_buffer, | 4107 OS::SNPrint(message_buffer, |
4108 kMessageBufferSize, | 4108 kMessageBufferSize, |
4109 "%d named passed, at most %"Pd" expected", | 4109 "%"Pd" named passed, at most %"Pd" expected", |
4110 num_named_arguments, | 4110 num_named_arguments, |
4111 NumOptionalNamedParameters()); | 4111 NumOptionalNamedParameters()); |
4112 *error_message = String::New(message_buffer); | 4112 *error_message = String::New(message_buffer); |
4113 } | 4113 } |
4114 return false; // Too many named arguments. | 4114 return false; // Too many named arguments. |
4115 } | 4115 } |
4116 const int num_pos_args = num_arguments - num_named_arguments; | 4116 const int num_pos_args = num_arguments - num_named_arguments; |
4117 const int num_opt_pos_params = NumOptionalPositionalParameters(); | 4117 const int num_opt_pos_params = NumOptionalPositionalParameters(); |
4118 const int num_pos_params = num_fixed_parameters() + num_opt_pos_params; | 4118 const int num_pos_params = num_fixed_parameters() + num_opt_pos_params; |
4119 if (num_pos_args > num_pos_params) { | 4119 if (num_pos_args > num_pos_params) { |
(...skipping 27 matching lines...) Expand all Loading... |
4147 num_opt_pos_params > 0 ? "at least " : "", | 4147 num_opt_pos_params > 0 ? "at least " : "", |
4148 num_fixed_parameters() - num_hidden_params); | 4148 num_fixed_parameters() - num_hidden_params); |
4149 *error_message = String::New(message_buffer); | 4149 *error_message = String::New(message_buffer); |
4150 } | 4150 } |
4151 return false; // Too few fixed and/or positional arguments. | 4151 return false; // Too few fixed and/or positional arguments. |
4152 } | 4152 } |
4153 return true; | 4153 return true; |
4154 } | 4154 } |
4155 | 4155 |
4156 | 4156 |
4157 bool Function::AreValidArguments(int num_arguments, | 4157 bool Function::AreValidArguments(intptr_t num_arguments, |
4158 const Array& argument_names, | 4158 const Array& argument_names, |
4159 String* error_message) const { | 4159 String* error_message) const { |
4160 const int num_named_arguments = | 4160 const intptr_t num_named_arguments = |
4161 argument_names.IsNull() ? 0 : argument_names.Length(); | 4161 argument_names.IsNull() ? 0 : argument_names.Length(); |
4162 if (!AreValidArgumentCounts(num_arguments, | 4162 if (!AreValidArgumentCounts(num_arguments, |
4163 num_named_arguments, | 4163 num_named_arguments, |
4164 error_message)) { | 4164 error_message)) { |
4165 return false; | 4165 return false; |
4166 } | 4166 } |
4167 // Verify that all argument names are valid parameter names. | 4167 // Verify that all argument names are valid parameter names. |
4168 Isolate* isolate = Isolate::Current(); | 4168 Isolate* isolate = Isolate::Current(); |
4169 String& argument_name = String::Handle(isolate); | 4169 String& argument_name = String::Handle(isolate); |
4170 String& parameter_name = String::Handle(isolate); | 4170 String& parameter_name = String::Handle(isolate); |
4171 for (int i = 0; i < num_named_arguments; i++) { | 4171 for (intptr_t i = 0; i < num_named_arguments; i++) { |
4172 argument_name ^= argument_names.At(i); | 4172 argument_name ^= argument_names.At(i); |
4173 ASSERT(argument_name.IsSymbol()); | 4173 ASSERT(argument_name.IsSymbol()); |
4174 bool found = false; | 4174 bool found = false; |
4175 const int num_positional_args = num_arguments - num_named_arguments; | 4175 const intptr_t num_positional_args = num_arguments - num_named_arguments; |
4176 const int num_parameters = NumParameters(); | 4176 const intptr_t num_parameters = NumParameters(); |
4177 for (int j = num_positional_args; !found && (j < num_parameters); j++) { | 4177 for (intptr_t j = num_positional_args; |
| 4178 !found && (j < num_parameters); |
| 4179 j++) { |
4178 parameter_name = ParameterNameAt(j); | 4180 parameter_name = ParameterNameAt(j); |
4179 ASSERT(argument_name.IsSymbol()); | 4181 ASSERT(argument_name.IsSymbol()); |
4180 if (argument_name.Equals(parameter_name)) { | 4182 if (argument_name.Equals(parameter_name)) { |
| 4183 found = true; |
| 4184 } |
| 4185 } |
| 4186 if (!found) { |
| 4187 if (error_message != NULL) { |
| 4188 const intptr_t kMessageBufferSize = 64; |
| 4189 char message_buffer[kMessageBufferSize]; |
| 4190 OS::SNPrint(message_buffer, |
| 4191 kMessageBufferSize, |
| 4192 "no optional formal parameter named '%s'", |
| 4193 argument_name.ToCString()); |
| 4194 *error_message = String::New(message_buffer); |
| 4195 } |
| 4196 return false; |
| 4197 } |
| 4198 } |
| 4199 return true; |
| 4200 } |
| 4201 |
| 4202 |
| 4203 bool Function::AreValidArguments(const ArgumentsDescriptor& args_desc, |
| 4204 String* error_message) const { |
| 4205 const intptr_t num_arguments = args_desc.Count(); |
| 4206 const intptr_t num_named_arguments = args_desc.NamedCount(); |
| 4207 |
| 4208 if (!AreValidArgumentCounts(num_arguments, |
| 4209 num_named_arguments, |
| 4210 error_message)) { |
| 4211 return false; |
| 4212 } |
| 4213 // Verify that all argument names are valid parameter names. |
| 4214 Isolate* isolate = Isolate::Current(); |
| 4215 String& argument_name = String::Handle(isolate); |
| 4216 String& parameter_name = String::Handle(isolate); |
| 4217 for (intptr_t i = 0; i < num_named_arguments; i++) { |
| 4218 argument_name ^= args_desc.NameAt(i); |
| 4219 ASSERT(argument_name.IsSymbol()); |
| 4220 bool found = false; |
| 4221 const intptr_t num_positional_args = num_arguments - num_named_arguments; |
| 4222 const int num_parameters = NumParameters(); |
| 4223 for (intptr_t j = num_positional_args; |
| 4224 !found && (j < num_parameters); |
| 4225 j++) { |
| 4226 parameter_name = ParameterNameAt(j); |
| 4227 ASSERT(argument_name.IsSymbol()); |
| 4228 if (argument_name.Equals(parameter_name)) { |
4181 found = true; | 4229 found = true; |
4182 } | 4230 } |
4183 } | 4231 } |
4184 if (!found) { | 4232 if (!found) { |
4185 if (error_message != NULL) { | 4233 if (error_message != NULL) { |
4186 const intptr_t kMessageBufferSize = 64; | 4234 const intptr_t kMessageBufferSize = 64; |
4187 char message_buffer[kMessageBufferSize]; | 4235 char message_buffer[kMessageBufferSize]; |
4188 OS::SNPrint(message_buffer, | 4236 OS::SNPrint(message_buffer, |
4189 kMessageBufferSize, | 4237 kMessageBufferSize, |
4190 "no optional formal parameter named '%s'", | 4238 "no optional formal parameter named '%s'", |
(...skipping 9972 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14163 } | 14211 } |
14164 | 14212 |
14165 | 14213 |
14166 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { | 14214 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { |
14167 stream->OpenObject(); | 14215 stream->OpenObject(); |
14168 stream->CloseObject(); | 14216 stream->CloseObject(); |
14169 } | 14217 } |
14170 | 14218 |
14171 | 14219 |
14172 } // namespace dart | 14220 } // namespace dart |
OLD | NEW |