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

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

Issue 10695137: Provide better error message when passing wrong number of arguments. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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/parser.cc ('k') | no next file » | 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/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
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)) {
66 // Return a null function to signal to the upper levels to dispatch to 67 // Return a null function to signal to the upper levels to dispatch to
67 // "noSuchMethod" function. 68 // "noSuchMethod" function.
68 if (FLAG_trace_resolving) { 69 if (FLAG_trace_resolving) {
70 String& error_message = String::Handle(String::New("function not found"));
71 if (!function.IsNull()) {
72 // Obtain more detailed error message.
73 function.AreValidArgumentCounts(num_arguments,
74 num_named_arguments,
75 &error_message);
76 }
69 OS::Print("ResolveDynamic error '%s': %s.\n", 77 OS::Print("ResolveDynamic error '%s': %s.\n",
70 function_name.ToCString(), 78 function_name.ToCString(),
71 function.IsNull() ? 79 error_message.ToCString());
72 "function not found" : "argument count mismatch");
73 } 80 }
74 return Function::null(); 81 return Function::null();
75 } 82 }
76 return function.raw(); 83 return function.raw();
77 } 84 }
78 85
79 86
80 RawFunction* Resolver::ResolveStatic(const Library& library, 87 RawFunction* Resolver::ResolveStatic(const Library& library,
81 const String& class_name, 88 const String& class_name,
82 const String& function_name, 89 const String& function_name,
83 int num_arguments, 90 int num_arguments,
84 const Array& argument_names, 91 const Array& argument_names,
85 StaticResolveType resolve_type) { 92 StaticResolveType resolve_type) {
86 ASSERT(!library.IsNull()); 93 ASSERT(!library.IsNull());
87 Function& function = Function::Handle(); 94 Function& function = Function::Handle();
88 if (class_name.IsNull() || (class_name.Length() == 0)) { 95 if (class_name.IsNull() || (class_name.Length() == 0)) {
89 // Check if we are referring to a top level function. 96 // Check if we are referring to a top level function.
90 const Object& object = Object::Handle(library.LookupObject(function_name)); 97 const Object& object = Object::Handle(library.LookupObject(function_name));
91 if (!object.IsNull() && object.IsFunction()) { 98 if (!object.IsNull() && object.IsFunction()) {
92 function ^= object.raw(); 99 function ^= object.raw();
93 if (!function.AreValidArguments(num_arguments, argument_names)) { 100 if (!function.AreValidArguments(num_arguments, argument_names, NULL)) {
94 if (FLAG_trace_resolving) { 101 if (FLAG_trace_resolving) {
102 String& error_message = String::Handle();
103 // Obtain more detailed error message.
104 function.AreValidArguments(num_arguments,
105 argument_names,
106 &error_message);
95 OS::Print("ResolveStatic error '%s': %s.\n", 107 OS::Print("ResolveStatic error '%s': %s.\n",
96 function_name.ToCString(), "arguments mismatch"); 108 function_name.ToCString(),
109 error_message.ToCString());
97 } 110 }
98 function = Function::null(); 111 function = Function::null();
99 } 112 }
100 } else { 113 } else {
101 if (FLAG_trace_resolving) { 114 if (FLAG_trace_resolving) {
102 OS::Print("ResolveStatic error '%s': %s.\n", 115 OS::Print("ResolveStatic error '%s': %s.\n",
103 function_name.ToCString(), "top level function not found"); 116 function_name.ToCString(), "top level function not found");
104 } 117 }
105 } 118 }
106 } else { 119 } else {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 162
150 163
151 RawFunction* Resolver::ResolveStatic(const Class& cls, 164 RawFunction* Resolver::ResolveStatic(const Class& cls,
152 const String& function_name, 165 const String& function_name,
153 int num_arguments, 166 int num_arguments,
154 const Array& argument_names, 167 const Array& argument_names,
155 StaticResolveType resolve_type) { 168 StaticResolveType resolve_type) {
156 const Function& function = Function::Handle( 169 const Function& function = Function::Handle(
157 ResolveStaticByName(cls, function_name, resolve_type)); 170 ResolveStaticByName(cls, function_name, resolve_type));
158 if (function.IsNull() || 171 if (function.IsNull() ||
159 !function.AreValidArguments(num_arguments, argument_names)) { 172 !function.AreValidArguments(num_arguments, argument_names, NULL)) {
160 // Return a null function to signal to the upper levels to throw a 173 // Return a null function to signal to the upper levels to throw a
161 // resolution error or maybe throw the error right here. 174 // resolution error or maybe throw the error right here.
162 if (FLAG_trace_resolving) { 175 if (FLAG_trace_resolving) {
176 String& error_message = String::Handle(String::New("function not found"));
177 if (!function.IsNull()) {
178 // Obtain more detailed error message.
179 function.AreValidArguments(num_arguments,
180 argument_names,
181 &error_message);
182 }
163 OS::Print("ResolveStatic error '%s': %s.\n", 183 OS::Print("ResolveStatic error '%s': %s.\n",
164 function_name.ToCString(), 184 function_name.ToCString(),
165 function.IsNull() ? 185 error_message.ToCString());
166 "function not found" : "arguments mismatch");
167 } 186 }
168 return Function::null(); 187 return Function::null();
169 } 188 }
170 return function.raw(); 189 return function.raw();
171 } 190 }
172 191
173 } // namespace dart 192 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698