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

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

Issue 19200002: Change resolving of instance methods to check early for name mismatch. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 5 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 | Annotate | Revision Log
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/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 4075 matching lines...) Expand 10 before | Expand all | Expand 10 after
4086 // marked as non-static, but they do not have a receiver. 4086 // marked as non-static, but they do not have a receiver.
4087 // Closures are handled above. 4087 // Closures are handled above.
4088 ASSERT((kind() != RawFunction::kClosureFunction) && 4088 ASSERT((kind() != RawFunction::kClosureFunction) &&
4089 (kind() != RawFunction::kSignatureFunction)); 4089 (kind() != RawFunction::kSignatureFunction));
4090 return 1; // Receiver. 4090 return 1; // Receiver.
4091 } 4091 }
4092 return 0; // No implicit parameters. 4092 return 0; // No implicit parameters.
4093 } 4093 }
4094 4094
4095 4095
4096 bool Function::AreValidArgumentCounts(int num_arguments, 4096 bool Function::AreValidArgumentCounts(intptr_t num_arguments,
4097 int num_named_arguments, 4097 intptr_t num_named_arguments,
4098 String* error_message) const { 4098 String* error_message) const {
4099 if (num_named_arguments > NumOptionalNamedParameters()) { 4099 if (num_named_arguments > NumOptionalNamedParameters()) {
4100 if (error_message != NULL) { 4100 if (error_message != NULL) {
4101 const intptr_t kMessageBufferSize = 64; 4101 const intptr_t kMessageBufferSize = 64;
4102 char message_buffer[kMessageBufferSize]; 4102 char message_buffer[kMessageBufferSize];
4103 OS::SNPrint(message_buffer, 4103 OS::SNPrint(message_buffer,
4104 kMessageBufferSize, 4104 kMessageBufferSize,
4105 "%d named passed, at most %"Pd" expected", 4105 "%"Pd" named passed, at most %"Pd" expected",
4106 num_named_arguments, 4106 num_named_arguments,
4107 NumOptionalNamedParameters()); 4107 NumOptionalNamedParameters());
4108 *error_message = String::New(message_buffer); 4108 *error_message = String::New(message_buffer);
4109 } 4109 }
4110 return false; // Too many named arguments. 4110 return false; // Too many named arguments.
4111 } 4111 }
4112 const int num_pos_args = num_arguments - num_named_arguments; 4112 const int num_pos_args = num_arguments - num_named_arguments;
4113 const int num_opt_pos_params = NumOptionalPositionalParameters(); 4113 const int num_opt_pos_params = NumOptionalPositionalParameters();
4114 const int num_pos_params = num_fixed_parameters() + num_opt_pos_params; 4114 const int num_pos_params = num_fixed_parameters() + num_opt_pos_params;
4115 if (num_pos_args > num_pos_params) { 4115 if (num_pos_args > num_pos_params) {
(...skipping 27 matching lines...) Expand all
4143 num_opt_pos_params > 0 ? "at least " : "", 4143 num_opt_pos_params > 0 ? "at least " : "",
4144 num_fixed_parameters() - num_hidden_params); 4144 num_fixed_parameters() - num_hidden_params);
4145 *error_message = String::New(message_buffer); 4145 *error_message = String::New(message_buffer);
4146 } 4146 }
4147 return false; // Too few fixed and/or positional arguments. 4147 return false; // Too few fixed and/or positional arguments.
4148 } 4148 }
4149 return true; 4149 return true;
4150 } 4150 }
4151 4151
4152 4152
4153 bool Function::AreValidArguments(int num_arguments, 4153 bool Function::AreValidArguments(intptr_t num_arguments,
4154 const Array& argument_names, 4154 const Array& argument_names,
4155 String* error_message) const { 4155 String* error_message) const {
4156 const int num_named_arguments = 4156 const intptr_t num_named_arguments =
4157 argument_names.IsNull() ? 0 : argument_names.Length(); 4157 argument_names.IsNull() ? 0 : argument_names.Length();
4158 if (!AreValidArgumentCounts(num_arguments, 4158 if (!AreValidArgumentCounts(num_arguments,
4159 num_named_arguments, 4159 num_named_arguments,
4160 error_message)) { 4160 error_message)) {
4161 return false; 4161 return false;
4162 } 4162 }
4163 // Verify that all argument names are valid parameter names. 4163 // Verify that all argument names are valid parameter names.
4164 Isolate* isolate = Isolate::Current(); 4164 Isolate* isolate = Isolate::Current();
4165 String& argument_name = String::Handle(isolate); 4165 String& argument_name = String::Handle(isolate);
4166 String& parameter_name = String::Handle(isolate); 4166 String& parameter_name = String::Handle(isolate);
4167 for (int i = 0; i < num_named_arguments; i++) { 4167 for (intptr_t i = 0; i < num_named_arguments; i++) {
4168 argument_name ^= argument_names.At(i); 4168 argument_name ^= argument_names.At(i);
4169 ASSERT(argument_name.IsSymbol()); 4169 ASSERT(argument_name.IsSymbol());
4170 bool found = false; 4170 bool found = false;
4171 const int num_positional_args = num_arguments - num_named_arguments; 4171 const intptr_t num_positional_args = num_arguments - num_named_arguments;
4172 const int num_parameters = NumParameters(); 4172 const intptr_t num_parameters = NumParameters();
4173 for (int j = num_positional_args; !found && (j < num_parameters); j++) { 4173 for (intptr_t j = num_positional_args;
4174 !found && (j < num_parameters);
4175 j++) {
4174 parameter_name = ParameterNameAt(j); 4176 parameter_name = ParameterNameAt(j);
4175 ASSERT(argument_name.IsSymbol()); 4177 ASSERT(argument_name.IsSymbol());
4176 if (argument_name.Equals(parameter_name)) { 4178 if (argument_name.Equals(parameter_name)) {
4179 found = true;
4180 }
4181 }
4182 if (!found) {
4183 if (error_message != NULL) {
4184 const intptr_t kMessageBufferSize = 64;
4185 char message_buffer[kMessageBufferSize];
4186 OS::SNPrint(message_buffer,
4187 kMessageBufferSize,
4188 "no optional formal parameter named '%s'",
4189 argument_name.ToCString());
4190 *error_message = String::New(message_buffer);
4191 }
4192 return false;
4193 }
4194 }
4195 return true;
4196 }
4197
4198
4199 bool Function::AreValidArguments(const ArgumentsDescriptor& args_desc,
4200 String* error_message) const {
4201 const intptr_t num_arguments = args_desc.Count();
4202 const intptr_t num_named_arguments = args_desc.NamedCount();
4203
4204 if (!AreValidArgumentCounts(num_arguments,
4205 num_named_arguments,
4206 error_message)) {
4207 return false;
4208 }
4209 // Verify that all argument names are valid parameter names.
4210 Isolate* isolate = Isolate::Current();
4211 String& argument_name = String::Handle(isolate);
4212 String& parameter_name = String::Handle(isolate);
4213 for (intptr_t i = 0; i < num_named_arguments; i++) {
4214 argument_name ^= args_desc.NameAt(i);
4215 ASSERT(argument_name.IsSymbol());
4216 bool found = false;
4217 const intptr_t num_positional_args = num_arguments - num_named_arguments;
4218 const int num_parameters = NumParameters();
4219 for (intptr_t j = num_positional_args;
4220 !found && (j < num_parameters);
4221 j++) {
4222 parameter_name = ParameterNameAt(j);
4223 ASSERT(argument_name.IsSymbol());
4224 if (argument_name.Equals(parameter_name)) {
4177 found = true; 4225 found = true;
4178 } 4226 }
4179 } 4227 }
4180 if (!found) { 4228 if (!found) {
4181 if (error_message != NULL) { 4229 if (error_message != NULL) {
4182 const intptr_t kMessageBufferSize = 64; 4230 const intptr_t kMessageBufferSize = 64;
4183 char message_buffer[kMessageBufferSize]; 4231 char message_buffer[kMessageBufferSize];
4184 OS::SNPrint(message_buffer, 4232 OS::SNPrint(message_buffer,
4185 kMessageBufferSize, 4233 kMessageBufferSize,
4186 "no optional formal parameter named '%s'", 4234 "no optional formal parameter named '%s'",
(...skipping 9972 matching lines...) Expand 10 before | Expand all | Expand 10 after
14159 } 14207 }
14160 14208
14161 14209
14162 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { 14210 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const {
14163 stream->OpenObject(); 14211 stream->OpenObject();
14164 stream->CloseObject(); 14212 stream->CloseObject();
14165 } 14213 }
14166 14214
14167 14215
14168 } // namespace dart 14216 } // namespace dart
OLDNEW
« runtime/vm/dart_api_impl.cc ('K') | « runtime/vm/object.h ('k') | runtime/vm/resolver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698