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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 // in the class. | 55 // in the class. |
56 Function& function = | 56 Function& function = |
57 Function::Handle(cls.LookupDynamicFunction(function_name)); | 57 Function::Handle(cls.LookupDynamicFunction(function_name)); |
58 while (function.IsNull()) { | 58 while (function.IsNull()) { |
59 cls = cls.SuperClass(); | 59 cls = cls.SuperClass(); |
60 if (cls.IsNull()) break; | 60 if (cls.IsNull()) break; |
61 function = cls.LookupDynamicFunction(function_name); | 61 function = cls.LookupDynamicFunction(function_name); |
62 } | 62 } |
63 if (function.IsNull() || | 63 if (function.IsNull() || |
64 !function.AreValidArgumentCounts(num_arguments, | 64 !function.AreValidArgumentCounts(num_arguments, |
65 num_named_arguments)) { | 65 num_named_arguments, |
| 66 NULL, |
| 67 0)) { |
66 // Return a null function to signal to the upper levels to dispatch to | 68 // Return a null function to signal to the upper levels to dispatch to |
67 // "noSuchMethod" function. | 69 // "noSuchMethod" function. |
68 if (FLAG_trace_resolving) { | 70 if (FLAG_trace_resolving) { |
| 71 const intptr_t kMessageBufferSize = 256; |
| 72 char message_buffer[kMessageBufferSize] = "function not found"; |
| 73 if (!function.IsNull()) { |
| 74 // Obtain more detailed error message. |
| 75 function.AreValidArgumentCounts(num_arguments, |
| 76 num_named_arguments, |
| 77 message_buffer, |
| 78 kMessageBufferSize); |
| 79 } |
69 OS::Print("ResolveDynamic error '%s': %s.\n", | 80 OS::Print("ResolveDynamic error '%s': %s.\n", |
70 function_name.ToCString(), | 81 function_name.ToCString(), |
71 function.IsNull() ? | 82 message_buffer); |
72 "function not found" : "argument count mismatch"); | |
73 } | 83 } |
74 return Function::null(); | 84 return Function::null(); |
75 } | 85 } |
76 return function.raw(); | 86 return function.raw(); |
77 } | 87 } |
78 | 88 |
79 | 89 |
80 RawFunction* Resolver::ResolveStatic(const Library& library, | 90 RawFunction* Resolver::ResolveStatic(const Library& library, |
81 const String& class_name, | 91 const String& class_name, |
82 const String& function_name, | 92 const String& function_name, |
83 int num_arguments, | 93 int num_arguments, |
84 const Array& argument_names, | 94 const Array& argument_names, |
85 StaticResolveType resolve_type) { | 95 StaticResolveType resolve_type) { |
86 ASSERT(!library.IsNull()); | 96 ASSERT(!library.IsNull()); |
87 Function& function = Function::Handle(); | 97 Function& function = Function::Handle(); |
88 if (class_name.IsNull() || (class_name.Length() == 0)) { | 98 if (class_name.IsNull() || (class_name.Length() == 0)) { |
89 // Check if we are referring to a top level function. | 99 // Check if we are referring to a top level function. |
90 const Object& object = Object::Handle(library.LookupObject(function_name)); | 100 const Object& object = Object::Handle(library.LookupObject(function_name)); |
91 if (!object.IsNull() && object.IsFunction()) { | 101 if (!object.IsNull() && object.IsFunction()) { |
92 function ^= object.raw(); | 102 function ^= object.raw(); |
93 if (!function.AreValidArguments(num_arguments, argument_names)) { | 103 if (!function.AreValidArguments(num_arguments, argument_names, NULL, 0)) { |
94 if (FLAG_trace_resolving) { | 104 if (FLAG_trace_resolving) { |
| 105 const intptr_t kMessageBufferSize = 256; |
| 106 char message_buffer[kMessageBufferSize]; |
| 107 // Obtain more detailed error message. |
| 108 function.AreValidArguments(num_arguments, |
| 109 argument_names, |
| 110 message_buffer, |
| 111 kMessageBufferSize); |
95 OS::Print("ResolveStatic error '%s': %s.\n", | 112 OS::Print("ResolveStatic error '%s': %s.\n", |
96 function_name.ToCString(), "arguments mismatch"); | 113 function_name.ToCString(), |
| 114 message_buffer); |
97 } | 115 } |
98 function = Function::null(); | 116 function = Function::null(); |
99 } | 117 } |
100 } else { | 118 } else { |
101 if (FLAG_trace_resolving) { | 119 if (FLAG_trace_resolving) { |
102 OS::Print("ResolveStatic error '%s': %s.\n", | 120 OS::Print("ResolveStatic error '%s': %s.\n", |
103 function_name.ToCString(), "top level function not found"); | 121 function_name.ToCString(), "top level function not found"); |
104 } | 122 } |
105 } | 123 } |
106 } else { | 124 } else { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 | 167 |
150 | 168 |
151 RawFunction* Resolver::ResolveStatic(const Class& cls, | 169 RawFunction* Resolver::ResolveStatic(const Class& cls, |
152 const String& function_name, | 170 const String& function_name, |
153 int num_arguments, | 171 int num_arguments, |
154 const Array& argument_names, | 172 const Array& argument_names, |
155 StaticResolveType resolve_type) { | 173 StaticResolveType resolve_type) { |
156 const Function& function = Function::Handle( | 174 const Function& function = Function::Handle( |
157 ResolveStaticByName(cls, function_name, resolve_type)); | 175 ResolveStaticByName(cls, function_name, resolve_type)); |
158 if (function.IsNull() || | 176 if (function.IsNull() || |
159 !function.AreValidArguments(num_arguments, argument_names)) { | 177 !function.AreValidArguments(num_arguments, argument_names, NULL, 0)) { |
160 // Return a null function to signal to the upper levels to throw a | 178 // Return a null function to signal to the upper levels to throw a |
161 // resolution error or maybe throw the error right here. | 179 // resolution error or maybe throw the error right here. |
162 if (FLAG_trace_resolving) { | 180 if (FLAG_trace_resolving) { |
| 181 const intptr_t kMessageBufferSize = 256; |
| 182 char message_buffer[kMessageBufferSize] = "function not found"; |
| 183 if (!function.IsNull()) { |
| 184 // Obtain more detailed error message. |
| 185 function.AreValidArguments(num_arguments, |
| 186 argument_names, |
| 187 message_buffer, |
| 188 kMessageBufferSize); |
| 189 } |
163 OS::Print("ResolveStatic error '%s': %s.\n", | 190 OS::Print("ResolveStatic error '%s': %s.\n", |
164 function_name.ToCString(), | 191 function_name.ToCString(), |
165 function.IsNull() ? | 192 message_buffer); |
166 "function not found" : "arguments mismatch"); | |
167 } | 193 } |
168 return Function::null(); | 194 return Function::null(); |
169 } | 195 } |
170 return function.raw(); | 196 return function.raw(); |
171 } | 197 } |
172 | 198 |
173 } // namespace dart | 199 } // namespace dart |
OLD | NEW |