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

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

Issue 10693071: Use VM type cast and save handles. (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/benchmark_test.cc ('k') | runtime/vm/code_generator.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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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/flags.h" 7 #include "vm/flags.h"
8 #include "vm/heap.h" 8 #include "vm/heap.h"
9 #include "vm/isolate.h" 9 #include "vm/isolate.h"
10 #include "vm/longjump.h" 10 #include "vm/longjump.h"
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 // that the type parameter appeared in a static scope. Leaving the type as 489 // that the type parameter appeared in a static scope. Leaving the type as
490 // unresolved is the correct thing to do. 490 // unresolved is the correct thing to do.
491 491
492 // Lookup the type class. 492 // Lookup the type class.
493 const UnresolvedClass& unresolved_class = 493 const UnresolvedClass& unresolved_class =
494 UnresolvedClass::Handle(type.unresolved_class()); 494 UnresolvedClass::Handle(type.unresolved_class());
495 const Class& type_class = 495 const Class& type_class =
496 Class::Handle(ResolveClass(cls, unresolved_class)); 496 Class::Handle(ResolveClass(cls, unresolved_class));
497 497
498 // Replace unresolved class with resolved type class. 498 // Replace unresolved class with resolved type class.
499 ASSERT(type.IsType()); 499 const Type& parameterized_type = Type::Cast(type);
500 Type& parameterized_type = Type::Handle();
501 parameterized_type ^= type.raw();
502 if (!type_class.IsNull()) { 500 if (!type_class.IsNull()) {
503 parameterized_type.set_type_class(Object::Handle(type_class.raw())); 501 parameterized_type.set_type_class(Object::Handle(type_class.raw()));
504 } else { 502 } else {
505 // The type class could not be resolved. The type is malformed. 503 // The type class could not be resolved. The type is malformed.
506 FinalizeMalformedType(Error::Handle(), // No previous error. 504 FinalizeMalformedType(Error::Handle(), // No previous error.
507 cls, parameterized_type, finalization, 505 cls, parameterized_type, finalization,
508 "cannot resolve class name '%s' from '%s'", 506 "cannot resolve class name '%s' from '%s'",
509 String::Handle(unresolved_class.Name()).ToCString(), 507 String::Handle(unresolved_class.Name()).ToCString(),
510 String::Handle(cls.Name()).ToCString()); 508 String::Handle(cls.Name()).ToCString());
511 return; 509 return;
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 return type.raw(); 615 return type.raw();
618 } 616 }
619 ASSERT(type.IsResolved()); 617 ASSERT(type.IsResolved());
620 ASSERT((finalization == kFinalize) || (finalization == kFinalizeWellFormed)); 618 ASSERT((finalization == kFinalize) || (finalization == kFinalizeWellFormed));
621 619
622 if (FLAG_trace_type_finalization) { 620 if (FLAG_trace_type_finalization) {
623 OS::Print("Finalize type '%s'\n", String::Handle(type.Name()).ToCString()); 621 OS::Print("Finalize type '%s'\n", String::Handle(type.Name()).ToCString());
624 } 622 }
625 623
626 if (type.IsTypeParameter()) { 624 if (type.IsTypeParameter()) {
627 TypeParameter& type_parameter = TypeParameter::Handle(); 625 const TypeParameter& type_parameter = TypeParameter::Cast(type);
628 type_parameter ^= type.raw();
629 const Class& parameterized_class = 626 const Class& parameterized_class =
630 Class::Handle(type_parameter.parameterized_class()); 627 Class::Handle(type_parameter.parameterized_class());
631 ASSERT(!parameterized_class.IsNull()); 628 ASSERT(!parameterized_class.IsNull());
632 // The index must reflect the position of this type parameter in the type 629 // The index must reflect the position of this type parameter in the type
633 // arguments vector of its parameterized class. The offset to add is the 630 // arguments vector of its parameterized class. The offset to add is the
634 // number of type arguments in the super type, which is equal to the 631 // number of type arguments in the super type, which is equal to the
635 // difference in number of type arguments and type parameters of the 632 // difference in number of type arguments and type parameters of the
636 // parameterized class. 633 // parameterized class.
637 const intptr_t offset = parameterized_class.NumTypeArguments() - 634 const intptr_t offset = parameterized_class.NumTypeArguments() -
638 parameterized_class.NumTypeParameters(); 635 parameterized_class.NumTypeParameters();
639 type_parameter.set_index(type_parameter.index() + offset); 636 type_parameter.set_index(type_parameter.index() + offset);
640 type_parameter.set_is_finalized(); 637 type_parameter.set_is_finalized();
641 // We do not canonicalize type parameters. 638 // We do not canonicalize type parameters.
642 return type_parameter.raw(); 639 return type_parameter.raw();
643 } 640 }
644 641
645 // At this point, we can only have a parameterized_type. 642 // At this point, we can only have a parameterized_type.
646 Type& parameterized_type = Type::Handle(); 643 const Type& parameterized_type = Type::Cast(type);
647 parameterized_type ^= type.raw();
648 644
649 if (parameterized_type.IsBeingFinalized()) { 645 if (parameterized_type.IsBeingFinalized()) {
650 // Self reference detected. The type is malformed. 646 // Self reference detected. The type is malformed.
651 FinalizeMalformedType( 647 FinalizeMalformedType(
652 Error::Handle(), // No previous error. 648 Error::Handle(), // No previous error.
653 cls, parameterized_type, finalization, 649 cls, parameterized_type, finalization,
654 "type '%s' illegally refers to itself", 650 "type '%s' illegally refers to itself",
655 String::Handle(parameterized_type.Name()).ToCString()); 651 String::Handle(parameterized_type.Name()).ToCString());
656 return parameterized_type.raw(); 652 return parameterized_type.raw();
657 } 653 }
(...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after
1501 void ClassFinalizer::ReportError(const char* format, ...) { 1497 void ClassFinalizer::ReportError(const char* format, ...) {
1502 va_list args; 1498 va_list args;
1503 va_start(args, format); 1499 va_start(args, format);
1504 const Error& error = Error::Handle( 1500 const Error& error = Error::Handle(
1505 Parser::FormatError(Script::Handle(), -1, "Error", format, args)); 1501 Parser::FormatError(Script::Handle(), -1, "Error", format, args));
1506 va_end(args); 1502 va_end(args);
1507 ReportError(error); 1503 ReportError(error);
1508 } 1504 }
1509 1505
1510 } // namespace dart 1506 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/benchmark_test.cc ('k') | runtime/vm/code_generator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698