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/dart_entry.h" | 7 #include "vm/dart_entry.h" |
8 #include "vm/flags.h" | 8 #include "vm/flags.h" |
9 #include "vm/isolate.h" | 9 #include "vm/isolate.h" |
10 #include "vm/object.h" | 10 #include "vm/object.h" |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 } | 136 } |
137 return function.raw(); | 137 return function.raw(); |
138 } | 138 } |
139 | 139 |
140 | 140 |
141 RawFunction* Resolver::ResolveStatic(const Library& library, | 141 RawFunction* Resolver::ResolveStatic(const Library& library, |
142 const String& class_name, | 142 const String& class_name, |
143 const String& function_name, | 143 const String& function_name, |
144 intptr_t num_arguments, | 144 intptr_t num_arguments, |
145 const Array& argument_names, | 145 const Array& argument_names, |
146 StaticResolveType resolve_type, | 146 StaticResolveType resolve_type) { |
147 String* ambiguity_error_msg) { | |
148 ASSERT(!library.IsNull()); | 147 ASSERT(!library.IsNull()); |
149 Function& function = Function::Handle(); | 148 Function& function = Function::Handle(); |
150 if (class_name.IsNull() || (class_name.Length() == 0)) { | 149 if (class_name.IsNull() || (class_name.Length() == 0)) { |
151 // Check if we are referring to a top level function. | 150 // Check if we are referring to a top level function. |
152 const Object& object = Object::Handle( | 151 const Object& object = Object::Handle(library.LookupObject(function_name)); |
153 library.LookupObject(function_name, ambiguity_error_msg)); | |
154 if (!object.IsNull() && object.IsFunction()) { | 152 if (!object.IsNull() && object.IsFunction()) { |
155 function ^= object.raw(); | 153 function ^= object.raw(); |
156 if (!function.AreValidArguments(num_arguments, argument_names, NULL)) { | 154 if (!function.AreValidArguments(num_arguments, argument_names, NULL)) { |
157 if (FLAG_trace_resolving) { | 155 if (FLAG_trace_resolving) { |
158 String& error_message = String::Handle(); | 156 String& error_message = String::Handle(); |
159 // Obtain more detailed error message. | 157 // Obtain more detailed error message. |
160 function.AreValidArguments(num_arguments, | 158 function.AreValidArguments(num_arguments, |
161 argument_names, | 159 argument_names, |
162 &error_message); | 160 &error_message); |
163 OS::Print("ResolveStatic error '%s': %s.\n", | 161 OS::Print("ResolveStatic error '%s': %s.\n", |
164 function_name.ToCString(), | 162 function_name.ToCString(), |
165 error_message.ToCString()); | 163 error_message.ToCString()); |
166 } | 164 } |
167 function = Function::null(); | 165 function = Function::null(); |
168 } | 166 } |
169 } else { | 167 } else { |
170 if (FLAG_trace_resolving) { | 168 if (FLAG_trace_resolving) { |
171 OS::Print("ResolveStatic error '%s': %s.\n", | 169 OS::Print("ResolveStatic error: function '%s' not found.\n", |
172 function_name.ToCString(), | 170 function_name.ToCString()); |
173 ambiguity_error_msg->IsNull() ? "top level function not found" | |
174 : ambiguity_error_msg->ToCString()); | |
175 } | 171 } |
176 } | 172 } |
177 } else { | 173 } else { |
178 // Lookup class_name in the library's class dictionary to get at | 174 // Lookup class_name in the library's class dictionary to get at |
179 // the dart class object. If class_name is not found in the dictionary | 175 // the dart class object. If class_name is not found in the dictionary |
180 // ResolveStatic will return a NULL function object. | 176 // ResolveStatic will return a NULL function object. |
181 const Class& cls = Class::Handle( | 177 const Class& cls = Class::Handle(library.LookupClass(class_name)); |
182 library.LookupClass(class_name, ambiguity_error_msg)); | |
183 if (!cls.IsNull()) { | 178 if (!cls.IsNull()) { |
184 function = ResolveStatic(cls, | 179 function = ResolveStatic(cls, |
185 function_name, | 180 function_name, |
186 num_arguments, | 181 num_arguments, |
187 argument_names, | 182 argument_names, |
188 resolve_type); | 183 resolve_type); |
189 } | 184 } |
190 if (FLAG_trace_resolving && function.IsNull()) { | 185 if (FLAG_trace_resolving && function.IsNull()) { |
191 OS::Print("ResolveStatic error '%s.%s': %s.\n", | 186 OS::Print("ResolveStatic error: function '%s.%s' not found.\n", |
192 class_name.ToCString(), | 187 class_name.ToCString(), |
193 function_name.ToCString(), | 188 function_name.ToCString()); |
194 ambiguity_error_msg->IsNull() ? "static function not found" | |
195 : ambiguity_error_msg->ToCString()); | |
196 } | 189 } |
197 } | 190 } |
198 return function.raw(); | 191 return function.raw(); |
199 } | 192 } |
200 | 193 |
201 | 194 |
202 RawFunction* Resolver::ResolveStaticByName(const Class& cls, | 195 RawFunction* Resolver::ResolveStaticByName(const Class& cls, |
203 const String& function_name, | 196 const String& function_name, |
204 StaticResolveType resolve_type) { | 197 StaticResolveType resolve_type) { |
205 ASSERT(!cls.IsNull()); | 198 ASSERT(!cls.IsNull()); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 OS::Print("ResolveStatic error '%s': %s.\n", | 242 OS::Print("ResolveStatic error '%s': %s.\n", |
250 function_name.ToCString(), | 243 function_name.ToCString(), |
251 error_message.ToCString()); | 244 error_message.ToCString()); |
252 } | 245 } |
253 return Function::null(); | 246 return Function::null(); |
254 } | 247 } |
255 return function.raw(); | 248 return function.raw(); |
256 } | 249 } |
257 | 250 |
258 } // namespace dart | 251 } // namespace dart |
OLD | NEW |