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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 function = ResolveStatic(cls, | 111 function = ResolveStatic(cls, |
112 function_name, | 112 function_name, |
113 num_arguments, | 113 num_arguments, |
114 argument_names, | 114 argument_names, |
115 resolve_type); | 115 resolve_type); |
116 } | 116 } |
117 return function.raw(); | 117 return function.raw(); |
118 } | 118 } |
119 | 119 |
120 | 120 |
121 RawFunction* Resolver::ResolveStatic(const Class& cls, | 121 RawFunction* Resolver::ResolveStaticByName(const Class& cls, |
122 const String& function_name, | 122 const String& function_name, |
123 int num_arguments, | 123 StaticResolveType resolve_type) { |
124 const Array& argument_names, | |
125 StaticResolveType resolve_type) { | |
126 if (cls.IsNull()) { | 124 if (cls.IsNull()) { |
127 // Can't resolve function if cls is null. | 125 // Can't resolve function if cls is null. |
128 return Function::null(); | 126 return Function::null(); |
129 } | 127 } |
130 | 128 |
131 if (FLAG_trace_resolving) { | 129 if (FLAG_trace_resolving) { |
132 OS::Print("ResolveStatic '%s'\n", function_name.ToCString()); | 130 OS::Print("ResolveStatic '%s'\n", function_name.ToCString()); |
133 } | 131 } |
134 | 132 |
135 // Now look for a static function whose name matches function_name | 133 // Now look for a static function whose name matches function_name |
136 // in the class. | 134 // in the class. |
137 Function& function = | 135 Function& function = |
138 Function::Handle(cls.LookupStaticFunction(function_name)); | 136 Function::Handle(cls.LookupStaticFunction(function_name)); |
139 if (resolve_type == kNotQualified) { | 137 if (resolve_type == kNotQualified) { |
140 // Walk the hierarchy. | 138 // Walk the hierarchy. |
141 Class& super_class = Class::Handle(cls.SuperClass()); | 139 Class& super_class = Class::Handle(cls.SuperClass()); |
142 while (function.IsNull()) { | 140 while (function.IsNull()) { |
143 function = super_class.LookupStaticFunction(function_name); | 141 function = super_class.LookupStaticFunction(function_name); |
144 super_class = super_class.SuperClass(); | 142 super_class = super_class.SuperClass(); |
145 if (super_class.IsNull()) break; | 143 if (super_class.IsNull()) break; |
146 } | 144 } |
147 } | 145 } |
| 146 return function.raw(); |
| 147 } |
| 148 |
| 149 |
| 150 |
| 151 RawFunction* Resolver::ResolveStatic(const Class& cls, |
| 152 const String& function_name, |
| 153 int num_arguments, |
| 154 const Array& argument_names, |
| 155 StaticResolveType resolve_type) { |
| 156 const Function& function = Function::Handle( |
| 157 ResolveStaticByName(cls, function_name, resolve_type)); |
148 if (function.IsNull() || | 158 if (function.IsNull() || |
149 !function.AreValidArguments(num_arguments, argument_names)) { | 159 !function.AreValidArguments(num_arguments, argument_names)) { |
150 // Return a null function to signal to the upper levels to throw a | 160 // Return a null function to signal to the upper levels to throw a |
151 // resolution error or maybe throw the error right here. | 161 // resolution error or maybe throw the error right here. |
152 if (FLAG_trace_resolving) { | 162 if (FLAG_trace_resolving) { |
153 OS::Print("ResolveStatic error '%s': %s.\n", | 163 OS::Print("ResolveStatic error '%s': %s.\n", |
154 function_name.ToCString(), | 164 function_name.ToCString(), |
155 function.IsNull() ? | 165 function.IsNull() ? |
156 "function not found" : "arguments mismatch"); | 166 "function not found" : "arguments mismatch"); |
157 } | 167 } |
158 return Function::null(); | 168 return Function::null(); |
159 } | 169 } |
160 return function.raw(); | 170 return function.raw(); |
161 } | 171 } |
162 | 172 |
163 } // namespace dart | 173 } // namespace dart |
OLD | NEW |