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

Side by Side Diff: runtime/vm/resolver.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
« no previous file with comments | « runtime/vm/resolver.h ('k') | runtime/vm/resolver_test.cc » ('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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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/resolver.h" 5 #include "vm/resolver.h"
6 6
7 #include "vm/dart_entry.h"
7 #include "vm/flags.h" 8 #include "vm/flags.h"
8 #include "vm/isolate.h" 9 #include "vm/isolate.h"
9 #include "vm/object.h" 10 #include "vm/object.h"
10 #include "vm/object_store.h" 11 #include "vm/object_store.h"
11 #include "vm/symbols.h" 12 #include "vm/symbols.h"
12 13
13 namespace dart { 14 namespace dart {
14 15
15 DEFINE_FLAG(bool, trace_resolving, false, "Trace resolving."); 16 DEFINE_FLAG(bool, trace_resolving, false, "Trace resolving.");
16 17
17 18
18 // The actual names of named arguments are not checked by the dynamic resolver, 19 // The actual names of named arguments are not checked by the dynamic resolver,
19 // but by the method entry code. It is important that the dynamic resolver 20 // but by the method entry code. It is important that the dynamic resolver
20 // checks that no named arguments are passed to a method that does not accept 21 // checks that no named arguments are passed to a method that does not accept
21 // them, since the entry code of such a method does not check for named 22 // them, since the entry code of such a method does not check for named
22 // arguments. The dynamic resolver actually checks that a valid number of named 23 // arguments. The dynamic resolver actually checks that a valid number of named
23 // arguments is passed in. 24 // arguments is passed in.
24 RawFunction* Resolver::ResolveDynamic(const Instance& receiver, 25 RawFunction* Resolver::ResolveDynamic(const Instance& receiver,
25 const String& function_name, 26 const String& function_name,
26 int num_arguments, 27 const ArgumentsDescriptor& args_desc) {
27 int num_named_arguments) {
28 // Figure out type of receiver first. 28 // Figure out type of receiver first.
29 Class& cls = Class::Handle(); 29 Class& cls = Class::Handle();
30 cls = receiver.clazz(); 30 cls = receiver.clazz();
31 // For lookups treat null as an instance of class Object. 31 // For lookups treat null as an instance of class Object.
32 if (cls.IsNullClass()) { 32 if (cls.IsNullClass()) {
33 cls = Isolate::Current()->object_store()->object_class(); 33 cls = Isolate::Current()->object_store()->object_class();
34 } 34 }
35 ASSERT(!cls.IsNull()); 35 ASSERT(!cls.IsNull());
36 36
37 return ResolveDynamicForReceiverClass( 37 return ResolveDynamicForReceiverClass(cls, function_name, args_desc);
38 cls, function_name, num_arguments, num_named_arguments);
39 } 38 }
40 39
41 40
42 RawFunction* Resolver::ResolveDynamicForReceiverClass( 41 RawFunction* Resolver::ResolveDynamicForReceiverClass(
43 const Class& receiver_class, 42 const Class& receiver_class,
44 const String& function_name, 43 const String& function_name,
45 int num_arguments, 44 const ArgumentsDescriptor& args_desc) {
46 int num_named_arguments) {
47 45
48 Function& function = 46 Function& function =
49 Function::Handle(ResolveDynamicAnyArgs(receiver_class, function_name)); 47 Function::Handle(ResolveDynamicAnyArgs(receiver_class, function_name));
50 48
51 if (function.IsNull() || 49 if (function.IsNull() ||
52 !function.AreValidArgumentCounts(num_arguments, 50 !function.AreValidArguments(args_desc, NULL)) {
53 num_named_arguments,
54 NULL)) {
55 // Return a null function to signal to the upper levels to dispatch to 51 // Return a null function to signal to the upper levels to dispatch to
56 // "noSuchMethod" function. 52 // "noSuchMethod" function.
57 if (FLAG_trace_resolving) { 53 if (FLAG_trace_resolving) {
58 String& error_message = String::Handle(String::New("function not found")); 54 String& error_message = String::Handle(String::New("function not found"));
59 if (!function.IsNull()) { 55 if (!function.IsNull()) {
60 // Obtain more detailed error message. 56 // Obtain more detailed error message.
61 function.AreValidArgumentCounts(num_arguments, 57 function.AreValidArguments(args_desc, &error_message);
62 num_named_arguments,
63 &error_message);
64 } 58 }
65 OS::Print("ResolveDynamic error '%s': %s.\n", 59 OS::Print("ResolveDynamic error '%s': %s.\n",
66 function_name.ToCString(), 60 function_name.ToCString(),
67 error_message.ToCString()); 61 error_message.ToCString());
68 } 62 }
69 return Function::null(); 63 return Function::null();
70 } 64 }
71 return function.raw(); 65 return function.raw();
72 } 66 }
73 67
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 141
148 cls = cls.SuperClass(); 142 cls = cls.SuperClass();
149 } 143 }
150 return function.raw(); 144 return function.raw();
151 } 145 }
152 146
153 147
154 RawFunction* Resolver::ResolveStatic(const Library& library, 148 RawFunction* Resolver::ResolveStatic(const Library& library,
155 const String& class_name, 149 const String& class_name,
156 const String& function_name, 150 const String& function_name,
157 int num_arguments, 151 intptr_t num_arguments,
158 const Array& argument_names, 152 const Array& argument_names,
159 StaticResolveType resolve_type) { 153 StaticResolveType resolve_type) {
160 ASSERT(!library.IsNull()); 154 ASSERT(!library.IsNull());
161 Function& function = Function::Handle(); 155 Function& function = Function::Handle();
162 if (class_name.IsNull() || (class_name.Length() == 0)) { 156 if (class_name.IsNull() || (class_name.Length() == 0)) {
163 // Check if we are referring to a top level function. 157 // Check if we are referring to a top level function.
164 const Object& object = Object::Handle(library.LookupObject(function_name)); 158 const Object& object = Object::Handle(library.LookupObject(function_name));
165 if (!object.IsNull() && object.IsFunction()) { 159 if (!object.IsNull() && object.IsFunction()) {
166 function ^= object.raw(); 160 function ^= object.raw();
167 if (!function.AreValidArguments(num_arguments, argument_names, NULL)) { 161 if (!function.AreValidArguments(num_arguments, argument_names, NULL)) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 if (super_class.IsNull()) break; 217 if (super_class.IsNull()) break;
224 } 218 }
225 } 219 }
226 return function.raw(); 220 return function.raw();
227 } 221 }
228 222
229 223
230 224
231 RawFunction* Resolver::ResolveStatic(const Class& cls, 225 RawFunction* Resolver::ResolveStatic(const Class& cls,
232 const String& function_name, 226 const String& function_name,
233 int num_arguments, 227 intptr_t num_arguments,
234 const Array& argument_names, 228 const Array& argument_names,
235 StaticResolveType resolve_type) { 229 StaticResolveType resolve_type) {
236 const Function& function = Function::Handle( 230 const Function& function = Function::Handle(
237 ResolveStaticByName(cls, function_name, resolve_type)); 231 ResolveStaticByName(cls, function_name, resolve_type));
238 if (function.IsNull() || 232 if (function.IsNull() ||
239 !function.AreValidArguments(num_arguments, argument_names, NULL)) { 233 !function.AreValidArguments(num_arguments, argument_names, NULL)) {
240 // Return a null function to signal to the upper levels to throw a 234 // Return a null function to signal to the upper levels to throw a
241 // resolution error or maybe throw the error right here. 235 // resolution error or maybe throw the error right here.
242 if (FLAG_trace_resolving) { 236 if (FLAG_trace_resolving) {
243 String& error_message = String::Handle(String::New("function not found")); 237 String& error_message = String::Handle(String::New("function not found"));
244 if (!function.IsNull()) { 238 if (!function.IsNull()) {
245 // Obtain more detailed error message. 239 // Obtain more detailed error message.
246 function.AreValidArguments(num_arguments, 240 function.AreValidArguments(num_arguments,
247 argument_names, 241 argument_names,
248 &error_message); 242 &error_message);
249 } 243 }
250 OS::Print("ResolveStatic error '%s': %s.\n", 244 OS::Print("ResolveStatic error '%s': %s.\n",
251 function_name.ToCString(), 245 function_name.ToCString(),
252 error_message.ToCString()); 246 error_message.ToCString());
253 } 247 }
254 return Function::null(); 248 return Function::null();
255 } 249 }
256 return function.raw(); 250 return function.raw();
257 } 251 }
258 252
259 } // namespace dart 253 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/resolver.h ('k') | runtime/vm/resolver_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698