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

Side by Side Diff: runtime/lib/object.cc

Issue 2799373002: Pass a second type argument vector to all type instantiation calls in the VM. (Closed)
Patch Set: addressed comments Created 3 years, 8 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
« no previous file with comments | « runtime/lib/mirrors.cc ('k') | runtime/lib/object_patch.dart » ('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/bootstrap_natives.h" 5 #include "vm/bootstrap_natives.h"
6 6
7 #include "lib/invocation_mirror.h" 7 #include "lib/invocation_mirror.h"
8 #include "vm/code_patcher.h" 8 #include "vm/code_patcher.h"
9 #include "vm/exceptions.h" 9 #include "vm/exceptions.h"
10 #include "vm/heap.h" 10 #include "vm/heap.h"
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 } 162 }
163 163
164 const TypeArguments& left_type_arguments = 164 const TypeArguments& left_type_arguments =
165 TypeArguments::Handle(left.GetTypeArguments()); 165 TypeArguments::Handle(left.GetTypeArguments());
166 const TypeArguments& right_type_arguments = 166 const TypeArguments& right_type_arguments =
167 TypeArguments::Handle(right.GetTypeArguments()); 167 TypeArguments::Handle(right.GetTypeArguments());
168 return Bool::Get(left_type_arguments.Equals(right_type_arguments)).raw(); 168 return Bool::Get(left_type_arguments.Equals(right_type_arguments)).raw();
169 } 169 }
170 170
171 171
172 DEFINE_NATIVE_ENTRY(Object_instanceOf, 3) { 172 DEFINE_NATIVE_ENTRY(Object_instanceOf, 4) {
173 const Instance& instance = 173 const Instance& instance =
174 Instance::CheckedHandle(zone, arguments->NativeArgAt(0)); 174 Instance::CheckedHandle(zone, arguments->NativeArgAt(0));
175 const TypeArguments& instantiator_type_arguments = 175 const TypeArguments& instantiator_type_arguments =
176 TypeArguments::CheckedHandle(zone, arguments->NativeArgAt(1)); 176 TypeArguments::CheckedHandle(zone, arguments->NativeArgAt(1));
177 const TypeArguments& function_type_arguments =
178 TypeArguments::CheckedHandle(zone, arguments->NativeArgAt(2));
177 const AbstractType& type = 179 const AbstractType& type =
178 AbstractType::CheckedHandle(zone, arguments->NativeArgAt(2)); 180 AbstractType::CheckedHandle(zone, arguments->NativeArgAt(3));
179 ASSERT(type.IsFinalized()); 181 ASSERT(type.IsFinalized());
180 ASSERT(!type.IsMalformed()); 182 ASSERT(!type.IsMalformed());
181 ASSERT(!type.IsMalbounded()); 183 ASSERT(!type.IsMalbounded());
182 Error& bound_error = Error::Handle(zone, Error::null()); 184 Error& bound_error = Error::Handle(zone, Error::null());
183 const bool is_instance_of = 185 const bool is_instance_of = instance.IsInstanceOf(
184 instance.IsInstanceOf(type, instantiator_type_arguments, &bound_error); 186 type, instantiator_type_arguments, function_type_arguments, &bound_error);
185 if (FLAG_trace_type_checks) { 187 if (FLAG_trace_type_checks) {
186 const char* result_str = is_instance_of ? "true" : "false"; 188 const char* result_str = is_instance_of ? "true" : "false";
187 OS::Print("Native Object.instanceOf: result %s\n", result_str); 189 OS::Print("Native Object.instanceOf: result %s\n", result_str);
188 const AbstractType& instance_type = 190 const AbstractType& instance_type =
189 AbstractType::Handle(zone, instance.GetType(Heap::kNew)); 191 AbstractType::Handle(zone, instance.GetType(Heap::kNew));
190 OS::Print(" instance type: %s\n", 192 OS::Print(" instance type: %s\n",
191 String::Handle(zone, instance_type.Name()).ToCString()); 193 String::Handle(zone, instance_type.Name()).ToCString());
192 OS::Print(" test type: %s\n", 194 OS::Print(" test type: %s\n",
193 String::Handle(zone, type.Name()).ToCString()); 195 String::Handle(zone, type.Name()).ToCString());
194 if (!bound_error.IsNull()) { 196 if (!bound_error.IsNull()) {
(...skipping 16 matching lines...) Expand all
211 return Bool::Get(is_instance_of).raw(); 213 return Bool::Get(is_instance_of).raw();
212 } 214 }
213 215
214 DEFINE_NATIVE_ENTRY(Object_simpleInstanceOf, 2) { 216 DEFINE_NATIVE_ENTRY(Object_simpleInstanceOf, 2) {
215 // This native is only called when the right hand side passes 217 // This native is only called when the right hand side passes
216 // SimpleInstanceOfType and it is a non-negative test. 218 // SimpleInstanceOfType and it is a non-negative test.
217 const Instance& instance = 219 const Instance& instance =
218 Instance::CheckedHandle(zone, arguments->NativeArgAt(0)); 220 Instance::CheckedHandle(zone, arguments->NativeArgAt(0));
219 const AbstractType& type = 221 const AbstractType& type =
220 AbstractType::CheckedHandle(zone, arguments->NativeArgAt(1)); 222 AbstractType::CheckedHandle(zone, arguments->NativeArgAt(1));
221 const TypeArguments& instantiator_type_arguments =
222 TypeArguments::Handle(TypeArguments::null());
223 ASSERT(type.IsFinalized()); 223 ASSERT(type.IsFinalized());
224 ASSERT(!type.IsMalformed()); 224 ASSERT(!type.IsMalformed());
225 ASSERT(!type.IsMalbounded()); 225 ASSERT(!type.IsMalbounded());
226 ASSERT(type.IsInstantiated());
226 Error& bound_error = Error::Handle(zone, Error::null()); 227 Error& bound_error = Error::Handle(zone, Error::null());
227 const bool is_instance_of = 228 const bool is_instance_of =
228 instance.IsInstanceOf(type, instantiator_type_arguments, &bound_error); 229 instance.IsInstanceOf(type, Object::null_type_arguments(),
230 Object::null_type_arguments(), &bound_error);
229 if (!is_instance_of && !bound_error.IsNull()) { 231 if (!is_instance_of && !bound_error.IsNull()) {
230 // Throw a dynamic type error only if the instanceof test fails. 232 // Throw a dynamic type error only if the instanceof test fails.
231 DartFrameIterator iterator; 233 DartFrameIterator iterator;
232 StackFrame* caller_frame = iterator.NextFrame(); 234 StackFrame* caller_frame = iterator.NextFrame();
233 ASSERT(caller_frame != NULL); 235 ASSERT(caller_frame != NULL);
234 const TokenPosition location = caller_frame->GetTokenPos(); 236 const TokenPosition location = caller_frame->GetTokenPos();
235 String& bound_error_message = 237 String& bound_error_message =
236 String::Handle(zone, String::New(bound_error.ToErrorCString())); 238 String::Handle(zone, String::New(bound_error.ToErrorCString()));
237 Exceptions::CreateAndThrowTypeError(location, AbstractType::Handle(zone), 239 Exceptions::CreateAndThrowTypeError(location, AbstractType::Handle(zone),
238 AbstractType::Handle(zone), 240 AbstractType::Handle(zone),
239 Symbols::Empty(), bound_error_message); 241 Symbols::Empty(), bound_error_message);
240 UNREACHABLE(); 242 UNREACHABLE();
241 } 243 }
242 return Bool::Get(is_instance_of).raw(); 244 return Bool::Get(is_instance_of).raw();
243 } 245 }
244 246
245 247
246 DEFINE_NATIVE_ENTRY(Object_as, 3) { 248 DEFINE_NATIVE_ENTRY(Object_as, 4) {
247 const Instance& instance = 249 const Instance& instance =
248 Instance::CheckedHandle(zone, arguments->NativeArgAt(0)); 250 Instance::CheckedHandle(zone, arguments->NativeArgAt(0));
249 const TypeArguments& instantiator_type_arguments = 251 const TypeArguments& instantiator_type_arguments =
250 TypeArguments::CheckedHandle(zone, arguments->NativeArgAt(1)); 252 TypeArguments::CheckedHandle(zone, arguments->NativeArgAt(1));
253 const TypeArguments& function_type_arguments =
254 TypeArguments::CheckedHandle(zone, arguments->NativeArgAt(2));
251 AbstractType& type = 255 AbstractType& type =
252 AbstractType::CheckedHandle(zone, arguments->NativeArgAt(2)); 256 AbstractType::CheckedHandle(zone, arguments->NativeArgAt(3));
253 ASSERT(type.IsFinalized()); 257 ASSERT(type.IsFinalized());
254 ASSERT(!type.IsMalformed()); 258 ASSERT(!type.IsMalformed());
255 ASSERT(!type.IsMalbounded()); 259 ASSERT(!type.IsMalbounded());
256 Error& bound_error = Error::Handle(zone); 260 Error& bound_error = Error::Handle(zone);
257 const bool is_instance_of = 261 const bool is_instance_of =
258 instance.IsNull() || 262 instance.IsNull() ||
259 instance.IsInstanceOf(type, instantiator_type_arguments, &bound_error); 263 instance.IsInstanceOf(type, instantiator_type_arguments,
264 function_type_arguments, &bound_error);
260 if (FLAG_trace_type_checks) { 265 if (FLAG_trace_type_checks) {
261 const char* result_str = is_instance_of ? "true" : "false"; 266 const char* result_str = is_instance_of ? "true" : "false";
262 OS::Print("Object.as: result %s\n", result_str); 267 OS::Print("Object.as: result %s\n", result_str);
263 const AbstractType& instance_type = 268 const AbstractType& instance_type =
264 AbstractType::Handle(zone, instance.GetType(Heap::kNew)); 269 AbstractType::Handle(zone, instance.GetType(Heap::kNew));
265 OS::Print(" instance type: %s\n", 270 OS::Print(" instance type: %s\n",
266 String::Handle(zone, instance_type.Name()).ToCString()); 271 String::Handle(zone, instance_type.Name()).ToCString());
267 OS::Print(" cast type: %s\n", 272 OS::Print(" cast type: %s\n",
268 String::Handle(zone, type.Name()).ToCString()); 273 String::Handle(zone, type.Name()).ToCString());
269 if (!bound_error.IsNull()) { 274 if (!bound_error.IsNull()) {
270 OS::Print(" bound error: %s\n", bound_error.ToErrorCString()); 275 OS::Print(" bound error: %s\n", bound_error.ToErrorCString());
271 } 276 }
272 } 277 }
273 if (!is_instance_of) { 278 if (!is_instance_of) {
274 DartFrameIterator iterator; 279 DartFrameIterator iterator;
275 StackFrame* caller_frame = iterator.NextFrame(); 280 StackFrame* caller_frame = iterator.NextFrame();
276 ASSERT(caller_frame != NULL); 281 ASSERT(caller_frame != NULL);
277 const TokenPosition location = caller_frame->GetTokenPos(); 282 const TokenPosition location = caller_frame->GetTokenPos();
278 const AbstractType& instance_type = 283 const AbstractType& instance_type =
279 AbstractType::Handle(zone, instance.GetType(Heap::kNew)); 284 AbstractType::Handle(zone, instance.GetType(Heap::kNew));
280 if (!type.IsInstantiated()) { 285 if (!type.IsInstantiated()) {
281 // Instantiate type before reporting the error. 286 // Instantiate type before reporting the error.
282 type = type.InstantiateFrom(instantiator_type_arguments, NULL, NULL, NULL, 287 type = type.InstantiateFrom(instantiator_type_arguments,
288 function_type_arguments, NULL, NULL, NULL,
283 Heap::kNew); 289 Heap::kNew);
284 // Note that the instantiated type may be malformed. 290 // Note that the instantiated type may be malformed.
285 } 291 }
286 if (bound_error.IsNull()) { 292 if (bound_error.IsNull()) {
287 Exceptions::CreateAndThrowTypeError(location, instance_type, type, 293 Exceptions::CreateAndThrowTypeError(location, instance_type, type,
288 Symbols::InTypeCast(), 294 Symbols::InTypeCast(),
289 Object::null_string()); 295 Object::null_string());
290 } else { 296 } else {
291 ASSERT(isolate->type_checks()); 297 ASSERT(isolate->type_checks());
292 const String& bound_error_message = 298 const String& bound_error_message =
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 351
346 DEFINE_NATIVE_ENTRY(Internal_inquireIs64Bit, 0) { 352 DEFINE_NATIVE_ENTRY(Internal_inquireIs64Bit, 0) {
347 #if defined(ARCH_IS_64_BIT) 353 #if defined(ARCH_IS_64_BIT)
348 return Bool::True().raw(); 354 return Bool::True().raw();
349 #else 355 #else
350 return Bool::False().raw(); 356 return Bool::False().raw();
351 #endif // defined(ARCH_IS_64_BIT) 357 #endif // defined(ARCH_IS_64_BIT)
352 } 358 }
353 359
354 } // namespace dart 360 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/lib/mirrors.cc ('k') | runtime/lib/object_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698