OLD | NEW |
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/flags.h" | 7 #include "vm/flags.h" |
8 #include "vm/isolate.h" | 8 #include "vm/isolate.h" |
9 #include "vm/object.h" | 9 #include "vm/object.h" |
10 #include "vm/object_store.h" | 10 #include "vm/object_store.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 return ResolveDynamicForReceiverClass( | 38 return ResolveDynamicForReceiverClass( |
39 cls, function_name, num_arguments, num_named_arguments); | 39 cls, function_name, num_arguments, num_named_arguments); |
40 } | 40 } |
41 | 41 |
42 | 42 |
43 RawFunction* Resolver::ResolveDynamicForReceiverClass( | 43 RawFunction* Resolver::ResolveDynamicForReceiverClass( |
44 const Class& receiver_class, | 44 const Class& receiver_class, |
45 const String& function_name, | 45 const String& function_name, |
46 int num_arguments, | 46 int num_arguments, |
47 int num_named_arguments) { | 47 int num_named_arguments) { |
48 Class& cls = Class::Handle(receiver_class.raw()); | |
49 if (FLAG_trace_resolving) { | |
50 OS::Print("ResolveDynamic '%s' for class %s\n", | |
51 function_name.ToCString(), String::Handle(cls.Name()).ToCString()); | |
52 } | |
53 | 48 |
54 // Now look for an instance function whose name matches function_name | |
55 // in the class. | |
56 Function& function = | 49 Function& function = |
57 Function::Handle(cls.LookupDynamicFunction(function_name)); | 50 Function::Handle(ResolveDynamicAnyArgs(receiver_class, function_name)); |
58 while (function.IsNull()) { | 51 |
59 cls = cls.SuperClass(); | |
60 if (cls.IsNull()) break; | |
61 function = cls.LookupDynamicFunction(function_name); | |
62 } | |
63 if (function.IsNull() || | 52 if (function.IsNull() || |
64 !function.AreValidArgumentCounts(num_arguments, | 53 !function.AreValidArgumentCounts(num_arguments, |
65 num_named_arguments, | 54 num_named_arguments, |
66 NULL)) { | 55 NULL)) { |
67 // Return a null function to signal to the upper levels to dispatch to | 56 // Return a null function to signal to the upper levels to dispatch to |
68 // "noSuchMethod" function. | 57 // "noSuchMethod" function. |
69 if (FLAG_trace_resolving) { | 58 if (FLAG_trace_resolving) { |
70 String& error_message = String::Handle(String::New("function not found")); | 59 String& error_message = String::Handle(String::New("function not found")); |
71 if (!function.IsNull()) { | 60 if (!function.IsNull()) { |
72 // Obtain more detailed error message. | 61 // Obtain more detailed error message. |
73 function.AreValidArgumentCounts(num_arguments, | 62 function.AreValidArgumentCounts(num_arguments, |
74 num_named_arguments, | 63 num_named_arguments, |
75 &error_message); | 64 &error_message); |
76 } | 65 } |
77 OS::Print("ResolveDynamic error '%s': %s.\n", | 66 OS::Print("ResolveDynamic error '%s': %s.\n", |
78 function_name.ToCString(), | 67 function_name.ToCString(), |
79 error_message.ToCString()); | 68 error_message.ToCString()); |
80 } | 69 } |
81 return Function::null(); | 70 return Function::null(); |
82 } | 71 } |
83 return function.raw(); | 72 return function.raw(); |
84 } | 73 } |
85 | 74 |
86 | 75 |
| 76 RawFunction* Resolver::ResolveDynamicAnyArgs( |
| 77 const Class& receiver_class, |
| 78 const String& function_name) { |
| 79 Class& cls = Class::Handle(receiver_class.raw()); |
| 80 if (FLAG_trace_resolving) { |
| 81 OS::Print("ResolveDynamic '%s' for class %s\n", |
| 82 function_name.ToCString(), |
| 83 String::Handle(cls.Name()).ToCString()); |
| 84 } |
| 85 // Now look for an instance function whose name matches function_name |
| 86 // in the class. |
| 87 Function& function = |
| 88 Function::Handle(cls.LookupDynamicFunction(function_name)); |
| 89 while (function.IsNull()) { |
| 90 cls = cls.SuperClass(); |
| 91 if (cls.IsNull()) break; |
| 92 function = cls.LookupDynamicFunction(function_name); |
| 93 } |
| 94 return function.raw(); |
| 95 } |
| 96 |
| 97 |
87 RawFunction* Resolver::ResolveStatic(const Library& library, | 98 RawFunction* Resolver::ResolveStatic(const Library& library, |
88 const String& class_name, | 99 const String& class_name, |
89 const String& function_name, | 100 const String& function_name, |
90 int num_arguments, | 101 int num_arguments, |
91 const Array& argument_names, | 102 const Array& argument_names, |
92 StaticResolveType resolve_type) { | 103 StaticResolveType resolve_type) { |
93 ASSERT(!library.IsNull()); | 104 ASSERT(!library.IsNull()); |
94 Function& function = Function::Handle(); | 105 Function& function = Function::Handle(); |
95 if (class_name.IsNull() || (class_name.Length() == 0)) { | 106 if (class_name.IsNull() || (class_name.Length() == 0)) { |
96 // Check if we are referring to a top level function. | 107 // Check if we are referring to a top level function. |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 OS::Print("ResolveStatic error '%s': %s.\n", | 194 OS::Print("ResolveStatic error '%s': %s.\n", |
184 function_name.ToCString(), | 195 function_name.ToCString(), |
185 error_message.ToCString()); | 196 error_message.ToCString()); |
186 } | 197 } |
187 return Function::null(); | 198 return Function::null(); |
188 } | 199 } |
189 return function.raw(); | 200 return function.raw(); |
190 } | 201 } |
191 | 202 |
192 } // namespace dart | 203 } // namespace dart |
OLD | NEW |