OLD | NEW |
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/object.h" | 5 #include "vm/object.h" |
6 | 6 |
7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
8 #include "vm/assembler.h" | 8 #include "vm/assembler.h" |
9 #include "vm/bigint_operations.h" | 9 #include "vm/bigint_operations.h" |
10 #include "vm/bootstrap.h" | 10 #include "vm/bootstrap.h" |
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 // Initialize the base interfaces used by the core VM classes. | 599 // Initialize the base interfaces used by the core VM classes. |
600 const Script& script = Script::Handle(Bootstrap::LoadScript()); | 600 const Script& script = Script::Handle(Bootstrap::LoadScript()); |
601 | 601 |
602 // Allocate and initialize the Object class and type. The Object | 602 // Allocate and initialize the Object class and type. The Object |
603 // class and ByteArray subclasses are the only pre-allocated, | 603 // class and ByteArray subclasses are the only pre-allocated, |
604 // non-interface classes in the core library. | 604 // non-interface classes in the core library. |
605 cls = Class::New<Instance>(); | 605 cls = Class::New<Instance>(); |
606 object_store->set_object_class(cls); | 606 object_store->set_object_class(cls); |
607 cls.set_name(String::Handle(String::NewSymbol("Object"))); | 607 cls.set_name(String::Handle(String::NewSymbol("Object"))); |
608 cls.set_script(script); | 608 cls.set_script(script); |
609 cls.set_class_state(RawClass::kPreFinalized); | 609 cls.set_is_prefinalized(); |
610 core_lib.AddClass(cls); | 610 core_lib.AddClass(cls); |
611 pending_classes.Add(cls, Heap::kOld); | 611 pending_classes.Add(cls, Heap::kOld); |
612 type = Type::NewNonParameterizedType(cls); | 612 type = Type::NewNonParameterizedType(cls); |
613 object_store->set_object_type(type); | 613 object_store->set_object_type(type); |
614 | 614 |
615 cls = Class::New<Int8Array>(); | 615 cls = Class::New<Int8Array>(); |
616 object_store->set_int8_array_class(cls); | 616 object_store->set_int8_array_class(cls); |
617 RegisterPrivateClass(cls, "_Int8Array", script, core_lib); | 617 RegisterPrivateClass(cls, "_Int8Array", script, core_lib); |
618 | 618 |
619 cls = Class::New<Uint8Array>(); | 619 cls = Class::New<Uint8Array>(); |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
991 if (raw_ptr()->name_ != String::null()) { | 991 if (raw_ptr()->name_ != String::null()) { |
992 return raw_ptr()->name_; | 992 return raw_ptr()->name_; |
993 } | 993 } |
994 ASSERT(class_class() != Class::null()); // class_class_ should be set up. | 994 ASSERT(class_class() != Class::null()); // class_class_ should be set up. |
995 intptr_t index = GetSingletonClassIndex(raw()); | 995 intptr_t index = GetSingletonClassIndex(raw()); |
996 return String::NewSymbol(GetSingletonClassName(index)); | 996 return String::NewSymbol(GetSingletonClassName(index)); |
997 } | 997 } |
998 | 998 |
999 | 999 |
1000 RawType* Class::SignatureType() const { | 1000 RawType* Class::SignatureType() const { |
| 1001 ASSERT(IsSignatureClass()); |
| 1002 const Function& function = Function::Handle(signature_function()); |
| 1003 ASSERT(!function.IsNull()); |
| 1004 if (function.signature_class() != raw()) { |
| 1005 // This class is a function type alias. Return the canonical signature type. |
| 1006 const Class& canonical_class = Class::Handle(function.signature_class()); |
| 1007 return canonical_class.SignatureType(); |
| 1008 } |
1001 // Return the first canonical signature type if already computed. | 1009 // Return the first canonical signature type if already computed. |
1002 const Array& signature_types = Array::Handle(canonical_types()); | 1010 const Array& signature_types = Array::Handle(canonical_types()); |
1003 if (signature_types.Length() > 0) { | 1011 if (signature_types.Length() > 0) { |
1004 Type& signature_type = Type::Handle(); | 1012 Type& signature_type = Type::Handle(); |
1005 signature_type ^= signature_types.At(0); | 1013 signature_type ^= signature_types.At(0); |
1006 if (!signature_type.IsNull()) { | 1014 if (!signature_type.IsNull()) { |
1007 return signature_type.raw(); | 1015 return signature_type.raw(); |
1008 } | 1016 } |
1009 } | 1017 } |
1010 ASSERT(IsSignatureClass()); | |
1011 // A signature class extends class Instance and is parameterized in the same | 1018 // A signature class extends class Instance and is parameterized in the same |
1012 // way as the owner class of its non-static signature function. | 1019 // way as the owner class of its non-static signature function. |
1013 // It is not type parameterized if its signature function is static. | 1020 // It is not type parameterized if its signature function is static. |
1014 // See Class::NewSignatureClass() for the setup of its type parameters. | 1021 // See Class::NewSignatureClass() for the setup of its type parameters. |
1015 // During type finalization, the type arguments of the super class of the | 1022 // During type finalization, the type arguments of the super class of the |
1016 // owner class of its signature function will be prepended to the type | 1023 // owner class of its signature function will be prepended to the type |
1017 // argument vector. Therefore, we only need to set the type arguments | 1024 // argument vector. Therefore, we only need to set the type arguments |
1018 // matching the type parameters here. | 1025 // matching the type parameters here. |
1019 const TypeArguments& signature_type_arguments = | 1026 const TypeArguments& signature_type_arguments = |
1020 TypeArguments::Handle(type_parameters()); | 1027 TypeArguments::Handle(type_parameters()); |
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1456 // Implements interface "Function". | 1463 // Implements interface "Function". |
1457 const Type& function_interface = Type::Handle(Type::FunctionInterface()); | 1464 const Type& function_interface = Type::Handle(Type::FunctionInterface()); |
1458 const Array& interfaces = Array::Handle(Array::New(1, Heap::kOld)); | 1465 const Array& interfaces = Array::Handle(Array::New(1, Heap::kOld)); |
1459 interfaces.SetAt(0, function_interface); | 1466 interfaces.SetAt(0, function_interface); |
1460 result.set_interfaces(interfaces); | 1467 result.set_interfaces(interfaces); |
1461 // Unless the signature function already has a signature class, create a | 1468 // Unless the signature function already has a signature class, create a |
1462 // canonical signature class by having the signature function point back to | 1469 // canonical signature class by having the signature function point back to |
1463 // the signature class. | 1470 // the signature class. |
1464 if (signature_function.signature_class() == Object::null()) { | 1471 if (signature_function.signature_class() == Object::null()) { |
1465 signature_function.set_signature_class(result); | 1472 signature_function.set_signature_class(result); |
| 1473 result.set_is_finalized(); |
| 1474 } else { |
| 1475 // This new signature class is an alias. |
| 1476 ASSERT(!result.IsCanonicalSignatureClass()); |
| 1477 // Do not yet mark it as finalized, so that the class finalizer can check it |
| 1478 // for illegal self references. |
| 1479 result.set_is_prefinalized(); |
1466 } | 1480 } |
1467 result.set_is_finalized(); | |
1468 // Instances of a signature class can only be closures. | 1481 // Instances of a signature class can only be closures. |
1469 ASSERT(result.instance_size() == Closure::InstanceSize()); | 1482 ASSERT(result.instance_size() == Closure::InstanceSize()); |
1470 // Cache the signature type as the first canonicalized type in result. | 1483 // Cache the signature type as the first canonicalized type in result. |
1471 const Type& signature_type = Type::Handle(result.SignatureType()); | 1484 const Type& signature_type = Type::Handle(result.SignatureType()); |
1472 ASSERT(!signature_type.IsFinalized()); | 1485 ASSERT(!signature_type.IsFinalized()); |
1473 const Array& new_canonical_types = Array::Handle(Array::New(1, Heap::kOld)); | 1486 const Array& new_canonical_types = Array::Handle(Array::New(1, Heap::kOld)); |
1474 new_canonical_types.SetAt(0, signature_type); | 1487 new_canonical_types.SetAt(0, signature_type); |
1475 result.set_canonical_types(new_canonical_types); | 1488 result.set_canonical_types(new_canonical_types); |
1476 return result.raw(); | 1489 return result.raw(); |
1477 } | 1490 } |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1650 raw_ptr()->is_const_ = true; | 1663 raw_ptr()->is_const_ = true; |
1651 } | 1664 } |
1652 | 1665 |
1653 | 1666 |
1654 void Class::set_is_finalized() const { | 1667 void Class::set_is_finalized() const { |
1655 ASSERT(!is_finalized()); | 1668 ASSERT(!is_finalized()); |
1656 set_class_state(RawClass::kFinalized); | 1669 set_class_state(RawClass::kFinalized); |
1657 } | 1670 } |
1658 | 1671 |
1659 | 1672 |
| 1673 void Class::set_is_prefinalized() const { |
| 1674 ASSERT(!is_finalized()); |
| 1675 set_class_state(RawClass::kPreFinalized); |
| 1676 } |
| 1677 |
| 1678 |
1660 void Class::set_interfaces(const Array& value) const { | 1679 void Class::set_interfaces(const Array& value) const { |
1661 // Verification and resolving of interfaces occurs in finalizer. | 1680 // Verification and resolving of interfaces occurs in finalizer. |
1662 ASSERT(!value.IsNull()); | 1681 ASSERT(!value.IsNull()); |
1663 StorePointer(&raw_ptr()->interfaces_, value.raw()); | 1682 StorePointer(&raw_ptr()->interfaces_, value.raw()); |
1664 } | 1683 } |
1665 | 1684 |
1666 | 1685 |
1667 void Class::set_functions_cache(const Array& value) const { | 1686 void Class::set_functions_cache(const Array& value) const { |
1668 ASSERT(!value.IsNull()); | 1687 ASSERT(!value.IsNull()); |
1669 StorePointer(&raw_ptr()->functions_cache_, value.raw()); | 1688 StorePointer(&raw_ptr()->functions_cache_, value.raw()); |
(...skipping 8231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9901 const String& str = String::Handle(pattern()); | 9920 const String& str = String::Handle(pattern()); |
9902 const char* format = "JSRegExp: pattern=%s flags=%s"; | 9921 const char* format = "JSRegExp: pattern=%s flags=%s"; |
9903 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); | 9922 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); |
9904 char* chars = reinterpret_cast<char*>( | 9923 char* chars = reinterpret_cast<char*>( |
9905 Isolate::Current()->current_zone()->Allocate(len + 1)); | 9924 Isolate::Current()->current_zone()->Allocate(len + 1)); |
9906 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); | 9925 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); |
9907 return chars; | 9926 return chars; |
9908 } | 9927 } |
9909 | 9928 |
9910 } // namespace dart | 9929 } // namespace dart |
OLD | NEW |