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

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

Issue 19662003: Refactor resolution code in the vm to properly handle ambiguity errors. (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/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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 } 143 }
144 return function.raw(); 144 return function.raw();
145 } 145 }
146 146
147 147
148 RawFunction* Resolver::ResolveStatic(const Library& library, 148 RawFunction* Resolver::ResolveStatic(const Library& library,
149 const String& class_name, 149 const String& class_name,
150 const String& function_name, 150 const String& function_name,
151 intptr_t num_arguments, 151 intptr_t num_arguments,
152 const Array& argument_names, 152 const Array& argument_names,
153 StaticResolveType resolve_type) { 153 StaticResolveType resolve_type,
154 String* ambiguity_error_msg) {
154 ASSERT(!library.IsNull()); 155 ASSERT(!library.IsNull());
155 Function& function = Function::Handle(); 156 Function& function = Function::Handle();
156 if (class_name.IsNull() || (class_name.Length() == 0)) { 157 if (class_name.IsNull() || (class_name.Length() == 0)) {
157 // Check if we are referring to a top level function. 158 // Check if we are referring to a top level function.
158 const Object& object = Object::Handle(library.LookupObject(function_name)); 159 const Object& object = Object::Handle(
160 library.LookupObject(function_name, ambiguity_error_msg));
159 if (!object.IsNull() && object.IsFunction()) { 161 if (!object.IsNull() && object.IsFunction()) {
160 function ^= object.raw(); 162 function ^= object.raw();
161 if (!function.AreValidArguments(num_arguments, argument_names, NULL)) { 163 if (!function.AreValidArguments(num_arguments, argument_names, NULL)) {
162 if (FLAG_trace_resolving) { 164 if (FLAG_trace_resolving) {
163 String& error_message = String::Handle(); 165 String& error_message = String::Handle();
164 // Obtain more detailed error message. 166 // Obtain more detailed error message.
165 function.AreValidArguments(num_arguments, 167 function.AreValidArguments(num_arguments,
166 argument_names, 168 argument_names,
167 &error_message); 169 &error_message);
168 OS::Print("ResolveStatic error '%s': %s.\n", 170 OS::Print("ResolveStatic error '%s': %s.\n",
169 function_name.ToCString(), 171 function_name.ToCString(),
170 error_message.ToCString()); 172 error_message.ToCString());
171 } 173 }
172 function = Function::null(); 174 function = Function::null();
173 } 175 }
174 } else { 176 } else {
175 if (FLAG_trace_resolving) { 177 if (FLAG_trace_resolving) {
176 OS::Print("ResolveStatic error '%s': %s.\n", 178 OS::Print("ResolveStatic error '%s': %s.\n",
177 function_name.ToCString(), "top level function not found"); 179 function_name.ToCString(),
180 ambiguity_error_msg->IsNull() ? "top level function not found"
181 : ambiguity_error_msg->ToCString());
178 } 182 }
179 } 183 }
180 } else { 184 } else {
181 // Lookup class_name in the library's class dictionary to get at 185 // Lookup class_name in the library's class dictionary to get at
182 // the dart class object. If class_name is not found in the dictionary 186 // the dart class object. If class_name is not found in the dictionary
183 // ResolveStatic will return a NULL function object. 187 // ResolveStatic will return a NULL function object.
184 const Class& cls = Class::Handle(library.LookupClass(class_name)); 188 const Class& cls = Class::Handle(
185 function = ResolveStatic(cls, 189 library.LookupClass(class_name, ambiguity_error_msg));
186 function_name, 190 if (!cls.IsNull()) {
187 num_arguments, 191 function = ResolveStatic(cls,
188 argument_names, 192 function_name,
189 resolve_type); 193 num_arguments,
194 argument_names,
195 resolve_type);
196 }
197 if (FLAG_trace_resolving && function.IsNull()) {
198 OS::Print("ResolveStatic error '%s.%s': %s.\n",
199 class_name.ToCString(),
200 function_name.ToCString(),
201 ambiguity_error_msg->IsNull() ? "static function not found"
202 : ambiguity_error_msg->ToCString());
203 }
190 } 204 }
191 return function.raw(); 205 return function.raw();
192 } 206 }
193 207
194 208
195 RawFunction* Resolver::ResolveStaticByName(const Class& cls, 209 RawFunction* Resolver::ResolveStaticByName(const Class& cls,
196 const String& function_name, 210 const String& function_name,
197 StaticResolveType resolve_type) { 211 StaticResolveType resolve_type) {
198 if (cls.IsNull()) { 212 ASSERT(!cls.IsNull());
199 // Can't resolve function if cls is null.
200 return Function::null();
201 }
202 213
203 if (FLAG_trace_resolving) { 214 if (FLAG_trace_resolving) {
204 OS::Print("ResolveStatic '%s'\n", function_name.ToCString()); 215 OS::Print("ResolveStatic '%s'\n", function_name.ToCString());
205 } 216 }
206 217
207 // Now look for a static function whose name matches function_name 218 // Now look for a static function whose name matches function_name
208 // in the class. 219 // in the class.
209 Function& function = 220 Function& function =
210 Function::Handle(cls.LookupStaticFunction(function_name)); 221 Function::Handle(cls.LookupStaticFunction(function_name));
211 if (resolve_type == kNotQualified) { 222 if (resolve_type == kNotQualified) {
212 // Walk the hierarchy. 223 // Walk the hierarchy.
213 Class& super_class = Class::Handle(cls.SuperClass()); 224 Class& super_class = Class::Handle(cls.SuperClass());
214 while (function.IsNull()) { 225 while (function.IsNull()) {
215 function = super_class.LookupStaticFunction(function_name); 226 function = super_class.LookupStaticFunction(function_name);
216 super_class = super_class.SuperClass(); 227 super_class = super_class.SuperClass();
217 if (super_class.IsNull()) break; 228 if (super_class.IsNull()) break;
218 } 229 }
219 } 230 }
220 return function.raw(); 231 return function.raw();
221 } 232 }
222 233
223 234
224 235
225 RawFunction* Resolver::ResolveStatic(const Class& cls, 236 RawFunction* Resolver::ResolveStatic(const Class& cls,
226 const String& function_name, 237 const String& function_name,
227 intptr_t num_arguments, 238 intptr_t num_arguments,
228 const Array& argument_names, 239 const Array& argument_names,
229 StaticResolveType resolve_type) { 240 StaticResolveType resolve_type) {
241 ASSERT(!cls.IsNull());
230 const Function& function = Function::Handle( 242 const Function& function = Function::Handle(
231 ResolveStaticByName(cls, function_name, resolve_type)); 243 ResolveStaticByName(cls, function_name, resolve_type));
232 if (function.IsNull() || 244 if (function.IsNull() ||
233 !function.AreValidArguments(num_arguments, argument_names, NULL)) { 245 !function.AreValidArguments(num_arguments, argument_names, NULL)) {
234 // Return a null function to signal to the upper levels to throw a 246 // Return a null function to signal to the upper levels to throw a
235 // resolution error or maybe throw the error right here. 247 // resolution error or maybe throw the error right here.
236 if (FLAG_trace_resolving) { 248 if (FLAG_trace_resolving) {
237 String& error_message = String::Handle(String::New("function not found")); 249 String& error_message = String::Handle(String::New("function not found"));
238 if (!function.IsNull()) { 250 if (!function.IsNull()) {
239 // Obtain more detailed error message. 251 // Obtain more detailed error message.
240 function.AreValidArguments(num_arguments, 252 function.AreValidArguments(num_arguments,
241 argument_names, 253 argument_names,
242 &error_message); 254 &error_message);
243 } 255 }
244 OS::Print("ResolveStatic error '%s': %s.\n", 256 OS::Print("ResolveStatic error '%s': %s.\n",
245 function_name.ToCString(), 257 function_name.ToCString(),
246 error_message.ToCString()); 258 error_message.ToCString());
247 } 259 }
248 return Function::null(); 260 return Function::null();
249 } 261 }
250 return function.raw(); 262 return function.raw();
251 } 263 }
252 264
253 } // namespace dart 265 } // 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