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

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

Issue 160753004: Do not resolve type arguments when only a resolved type class is needed to (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 10 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/class_finalizer.h ('k') | runtime/vm/object.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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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/class_finalizer.h" 5 #include "vm/class_finalizer.h"
6 6
7 #include "vm/code_generator.h" 7 #include "vm/code_generator.h"
8 #include "vm/flags.h" 8 #include "vm/flags.h"
9 #include "vm/heap.h" 9 #include "vm/heap.h"
10 #include "vm/isolate.h" 10 #include "vm/isolate.h"
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 "cannot resolve redirecting factory"); 414 "cannot resolve redirecting factory");
415 target_target = Function::null(); 415 target_target = Function::null();
416 } 416 }
417 } 417 }
418 } 418 }
419 factory.SetRedirectionType(target_type); 419 factory.SetRedirectionType(target_type);
420 factory.SetRedirectionTarget(target_target); 420 factory.SetRedirectionTarget(target_target);
421 } 421 }
422 422
423 423
424 void ClassFinalizer::ResolveTypeClass(const Class& cls,
425 const AbstractType& type) {
426 if (type.IsFinalized() || type.HasResolvedTypeClass()) {
427 return;
428 }
429 if (FLAG_trace_type_finalization) {
430 OS::Print("Resolve type class of '%s'\n",
431 String::Handle(type.Name()).ToCString());
432 }
433
434 // Type parameters are always resolved in the parser in the correct
435 // non-static scope or factory scope. That resolution scope is unknown here.
436 // Being able to resolve a type parameter from class cls here would indicate
437 // that the type parameter appeared in a static scope. Leaving the type as
438 // unresolved is the correct thing to do.
439
440 // Lookup the type class.
441 const UnresolvedClass& unresolved_class =
442 UnresolvedClass::Handle(type.unresolved_class());
443 const Class& type_class =
444 Class::Handle(ResolveClass(cls, unresolved_class));
445
446 // Replace unresolved class with resolved type class.
447 const Type& parameterized_type = Type::Cast(type);
448 if (type_class.IsNull()) {
449 // The type class could not be resolved. The type is malformed.
450 FinalizeMalformedType(
451 Error::Handle(), // No previous error.
452 Script::Handle(cls.script()),
453 parameterized_type,
454 "cannot resolve class '%s' from '%s'",
455 String::Handle(unresolved_class.Name()).ToCString(),
456 String::Handle(cls.Name()).ToCString());
457 return;
458 }
459 parameterized_type.set_type_class(type_class);
460 }
461
462
424 void ClassFinalizer::ResolveType(const Class& cls, const AbstractType& type) { 463 void ClassFinalizer::ResolveType(const Class& cls, const AbstractType& type) {
425 if (type.IsResolved() || type.IsFinalized()) { 464 // TODO(regis): Add a kResolved bit in type_state_ for efficiency.
465 if (type.IsFinalized() || type.IsResolved()) {
426 return; 466 return;
427 } 467 }
428 if (FLAG_trace_type_finalization) { 468 if (FLAG_trace_type_finalization) {
429 OS::Print("Resolve type '%s'\n", String::Handle(type.Name()).ToCString()); 469 OS::Print("Resolve type '%s'\n", String::Handle(type.Name()).ToCString());
430 } 470 }
431 471
432 // Resolve the type class. 472 ResolveTypeClass(cls, type);
433 if (!type.HasResolvedTypeClass()) {
434 // Type parameters are always resolved in the parser in the correct
435 // non-static scope or factory scope. That resolution scope is unknown here.
436 // Being able to resolve a type parameter from class cls here would indicate
437 // that the type parameter appeared in a static scope. Leaving the type as
438 // unresolved is the correct thing to do.
439
440 // Lookup the type class.
441 const UnresolvedClass& unresolved_class =
442 UnresolvedClass::Handle(type.unresolved_class());
443 const Class& type_class =
444 Class::Handle(ResolveClass(cls, unresolved_class));
445
446 // Replace unresolved class with resolved type class.
447 const Type& parameterized_type = Type::Cast(type);
448 if (type_class.IsNull()) {
449 // The type class could not be resolved. The type is malformed.
450 FinalizeMalformedType(
451 Error::Handle(), // No previous error.
452 Script::Handle(cls.script()),
453 parameterized_type,
454 "cannot resolve class '%s' from '%s'",
455 String::Handle(unresolved_class.Name()).ToCString(),
456 String::Handle(cls.Name()).ToCString());
457 return;
458 }
459 parameterized_type.set_type_class(type_class);
460 }
461 473
462 // Resolve type arguments, if any. 474 // Resolve type arguments, if any.
463 const TypeArguments& arguments = TypeArguments::Handle(type.arguments()); 475 const TypeArguments& arguments = TypeArguments::Handle(type.arguments());
464 if (!arguments.IsNull()) { 476 if (!arguments.IsNull()) {
465 const intptr_t num_arguments = arguments.Length(); 477 const intptr_t num_arguments = arguments.Length();
466 AbstractType& type_argument = AbstractType::Handle(); 478 AbstractType& type_argument = AbstractType::Handle();
467 for (intptr_t i = 0; i < num_arguments; i++) { 479 for (intptr_t i = 0; i < num_arguments; i++) {
468 type_argument = arguments.TypeAt(i); 480 type_argument = arguments.TypeAt(i);
469 ResolveType(cls, type_argument); 481 ResolveType(cls, type_argument);
470 } 482 }
(...skipping 2419 matching lines...) Expand 10 before | Expand all | Expand 10 after
2890 expected_name ^= String::New("_offset"); 2902 expected_name ^= String::New("_offset");
2891 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name)); 2903 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name));
2892 field ^= fields_array.At(2); 2904 field ^= fields_array.At(2);
2893 ASSERT(field.Offset() == TypedDataView::length_offset()); 2905 ASSERT(field.Offset() == TypedDataView::length_offset());
2894 name ^= field.name(); 2906 name ^= field.name();
2895 ASSERT(name.Equals("length")); 2907 ASSERT(name.Equals("length"));
2896 #endif 2908 #endif
2897 } 2909 }
2898 2910
2899 } // namespace dart 2911 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/class_finalizer.h ('k') | runtime/vm/object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698