| 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 "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
| 9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
| 10 #include "vm/bigint_operations.h" | 10 #include "vm/bigint_operations.h" |
| (...skipping 1430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1441 // This class is a function type alias. Return the canonical signature type. | 1441 // This class is a function type alias. Return the canonical signature type. |
| 1442 const Class& canonical_class = Class::Handle(function.signature_class()); | 1442 const Class& canonical_class = Class::Handle(function.signature_class()); |
| 1443 return canonical_class.SignatureType(); | 1443 return canonical_class.SignatureType(); |
| 1444 } | 1444 } |
| 1445 // Return the first canonical signature type if already computed. | 1445 // Return the first canonical signature type if already computed. |
| 1446 const Array& signature_types = Array::Handle(canonical_types()); | 1446 const Array& signature_types = Array::Handle(canonical_types()); |
| 1447 // The canonical_types array is initialized to the empty array. | 1447 // The canonical_types array is initialized to the empty array. |
| 1448 ASSERT(!signature_types.IsNull()); | 1448 ASSERT(!signature_types.IsNull()); |
| 1449 if (signature_types.Length() > 0) { | 1449 if (signature_types.Length() > 0) { |
| 1450 // At most one signature type per signature class. | 1450 // At most one signature type per signature class. |
| 1451 ASSERT(signature_types.Length() == 1); | 1451 ASSERT((signature_types.Length() == 1) || |
| 1452 ((signature_types.Length() == 2) && |
| 1453 (signature_types.At(1) == Type::null()))); |
| 1452 Type& signature_type = Type::Handle(); | 1454 Type& signature_type = Type::Handle(); |
| 1453 signature_type ^= signature_types.At(0); | 1455 signature_type ^= signature_types.At(0); |
| 1454 ASSERT(!signature_type.IsNull()); | 1456 ASSERT(!signature_type.IsNull()); |
| 1455 return signature_type.raw(); | 1457 return signature_type.raw(); |
| 1456 } | 1458 } |
| 1457 // A signature class extends class Instance and is parameterized in the same | 1459 // A signature class extends class Instance and is parameterized in the same |
| 1458 // way as the owner class of its non-static signature function. | 1460 // way as the owner class of its non-static signature function. |
| 1459 // It is not type parameterized if its signature function is static. | 1461 // It is not type parameterized if its signature function is static. |
| 1460 // See Class::NewSignatureClass() for the setup of its type parameters. | 1462 // See Class::NewSignatureClass() for the setup of its type parameters. |
| 1461 // During type finalization, the type arguments of the super class of the | 1463 // During type finalization, the type arguments of the super class of the |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1913 RawClass* Class::New(const String& name, | 1915 RawClass* Class::New(const String& name, |
| 1914 const Script& script, | 1916 const Script& script, |
| 1915 intptr_t token_pos) { | 1917 intptr_t token_pos) { |
| 1916 Class& result = Class::Handle(New<Instance>(name, script, token_pos)); | 1918 Class& result = Class::Handle(New<Instance>(name, script, token_pos)); |
| 1917 return result.raw(); | 1919 return result.raw(); |
| 1918 } | 1920 } |
| 1919 | 1921 |
| 1920 | 1922 |
| 1921 RawClass* Class::NewSignatureClass(const String& name, | 1923 RawClass* Class::NewSignatureClass(const String& name, |
| 1922 const Function& signature_function, | 1924 const Function& signature_function, |
| 1923 const Script& script) { | 1925 const Script& script, |
| 1926 intptr_t token_pos) { |
| 1927 const Class& result = Class::Handle(New<Instance>(name, script, token_pos)); |
| 1928 const Type& super_type = Type::Handle(Type::ObjectType()); |
| 1929 ASSERT(!super_type.IsNull()); |
| 1930 // Instances of a signature class can only be closures. |
| 1931 result.set_instance_size(Closure::InstanceSize()); |
| 1932 result.set_next_field_offset(Closure::InstanceSize()); |
| 1933 result.set_super_type(super_type); |
| 1934 result.set_type_arguments_field_offset(Closure::type_arguments_offset()); |
| 1935 // Implements interface "Function". |
| 1936 const Type& function_type = Type::Handle(Type::Function()); |
| 1937 const Array& interfaces = Array::Handle(Array::New(1, Heap::kOld)); |
| 1938 interfaces.SetAt(0, function_type); |
| 1939 result.set_interfaces(interfaces); |
| 1940 if (!signature_function.IsNull()) { |
| 1941 result.PatchSignatureFunction(signature_function); |
| 1942 } |
| 1943 return result.raw(); |
| 1944 } |
| 1945 |
| 1946 |
| 1947 void Class::PatchSignatureFunction(const Function& signature_function) const { |
| 1924 ASSERT(!signature_function.IsNull()); | 1948 ASSERT(!signature_function.IsNull()); |
| 1925 const Class& owner_class = Class::Handle(signature_function.Owner()); | 1949 const Class& owner_class = Class::Handle(signature_function.Owner()); |
| 1926 ASSERT(!owner_class.IsNull()); | 1950 ASSERT(!owner_class.IsNull()); |
| 1927 TypeArguments& type_parameters = TypeArguments::Handle(); | 1951 TypeArguments& type_parameters = TypeArguments::Handle(); |
| 1928 // A signature class extends class Instance and is parameterized in the same | 1952 // A signature class extends class Instance and is parameterized in the same |
| 1929 // way as the owner class of its non-static signature function. | 1953 // way as the owner class of its non-static signature function. |
| 1930 // It is not type parameterized if its signature function is static. | 1954 // It is not type parameterized if its signature function is static. |
| 1955 // In case of a function type alias, the function owner is the alias class |
| 1956 // instead of the enclosing class. |
| 1931 if (!signature_function.is_static() && | 1957 if (!signature_function.is_static() && |
| 1932 (owner_class.NumTypeParameters() > 0) && | 1958 (owner_class.NumTypeParameters() > 0) && |
| 1933 !signature_function.HasInstantiatedSignature()) { | 1959 !signature_function.HasInstantiatedSignature()) { |
| 1934 type_parameters = owner_class.type_parameters(); | 1960 type_parameters = owner_class.type_parameters(); |
| 1935 } | 1961 } |
| 1936 const intptr_t token_pos = signature_function.token_pos(); | 1962 set_signature_function(signature_function); |
| 1937 Class& result = Class::Handle(New<Instance>(name, script, token_pos)); | 1963 set_type_parameters(type_parameters); |
| 1938 const Type& super_type = Type::Handle(Type::ObjectType()); | 1964 if (owner_class.raw() == raw()) { |
| 1939 ASSERT(!super_type.IsNull()); | 1965 // This signature class is an alias, which cannot be the canonical |
| 1940 result.set_instance_size(Closure::InstanceSize()); | 1966 // signature class for this signature function. |
| 1941 result.set_next_field_offset(Closure::InstanceSize()); | 1967 ASSERT(!IsCanonicalSignatureClass()); |
| 1942 result.set_super_type(super_type); | 1968 } else if (signature_function.signature_class() == Object::null()) { |
| 1943 result.set_signature_function(signature_function); | 1969 // Make this signature class the canonical signature class. |
| 1944 result.set_type_parameters(type_parameters); | 1970 signature_function.set_signature_class(*this); |
| 1945 result.SetFields(Object::empty_array()); | 1971 ASSERT(IsCanonicalSignatureClass()); |
| 1946 result.SetFunctions(Object::empty_array()); | |
| 1947 result.set_type_arguments_field_offset( | |
| 1948 Closure::type_arguments_offset()); | |
| 1949 // Implements interface "Function". | |
| 1950 const Type& function_type = Type::Handle(Type::Function()); | |
| 1951 const Array& interfaces = Array::Handle(Array::New(1, Heap::kOld)); | |
| 1952 interfaces.SetAt(0, function_type); | |
| 1953 result.set_interfaces(interfaces); | |
| 1954 // Unless the signature function already has a signature class, create a | |
| 1955 // canonical signature class by having the signature function point back to | |
| 1956 // the signature class. | |
| 1957 if (signature_function.signature_class() == Object::null()) { | |
| 1958 signature_function.set_signature_class(result); | |
| 1959 result.set_is_finalized(); | |
| 1960 } else { | |
| 1961 // This new signature class is an alias. | |
| 1962 ASSERT(!result.IsCanonicalSignatureClass()); | |
| 1963 // Do not yet mark it as finalized, so that the class finalizer can check it | |
| 1964 // for illegal self references. | |
| 1965 result.set_is_prefinalized(); | |
| 1966 } | 1972 } |
| 1967 // Instances of a signature class can only be closures. | 1973 set_is_prefinalized(); |
| 1968 ASSERT(result.instance_size() == Closure::InstanceSize()); | |
| 1969 // Cache the signature type as the first canonicalized type in result. | |
| 1970 const Type& signature_type = Type::Handle(result.SignatureType()); | |
| 1971 ASSERT(!signature_type.IsFinalized()); | |
| 1972 const Array& new_canonical_types = Array::Handle(Array::New(1, Heap::kOld)); | |
| 1973 new_canonical_types.SetAt(0, signature_type); | |
| 1974 result.set_canonical_types(new_canonical_types); | |
| 1975 return result.raw(); | |
| 1976 } | 1974 } |
| 1977 | 1975 |
| 1978 | 1976 |
| 1979 RawClass* Class::NewNativeWrapper(const Library& library, | 1977 RawClass* Class::NewNativeWrapper(const Library& library, |
| 1980 const String& name, | 1978 const String& name, |
| 1981 int field_count) { | 1979 int field_count) { |
| 1982 Class& cls = Class::Handle(library.LookupClass(name)); | 1980 Class& cls = Class::Handle(library.LookupClass(name)); |
| 1983 if (cls.IsNull()) { | 1981 if (cls.IsNull()) { |
| 1984 cls = New<Instance>(name, Script::Handle(), Scanner::kDummyTokenIndex); | 1982 cls = New<Instance>(name, Script::Handle(), Scanner::kDummyTokenIndex); |
| 1985 cls.SetFields(Object::empty_array()); | 1983 cls.SetFields(Object::empty_array()); |
| (...skipping 2225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4211 ASSERT(!owner_class.IsNull() && (Owner() == closure_function.Owner())); | 4209 ASSERT(!owner_class.IsNull() && (Owner() == closure_function.Owner())); |
| 4212 const Library& library = Library::Handle(owner_class.library()); | 4210 const Library& library = Library::Handle(owner_class.library()); |
| 4213 ASSERT(!library.IsNull()); | 4211 ASSERT(!library.IsNull()); |
| 4214 const String& signature = String::Handle(closure_function.Signature()); | 4212 const String& signature = String::Handle(closure_function.Signature()); |
| 4215 Class& signature_class = Class::ZoneHandle( | 4213 Class& signature_class = Class::ZoneHandle( |
| 4216 library.LookupLocalClass(signature)); | 4214 library.LookupLocalClass(signature)); |
| 4217 if (signature_class.IsNull()) { | 4215 if (signature_class.IsNull()) { |
| 4218 const Script& script = Script::Handle(this->script()); | 4216 const Script& script = Script::Handle(this->script()); |
| 4219 signature_class = Class::NewSignatureClass(signature, | 4217 signature_class = Class::NewSignatureClass(signature, |
| 4220 closure_function, | 4218 closure_function, |
| 4221 script); | 4219 script, |
| 4220 closure_function.token_pos()); |
| 4222 library.AddClass(signature_class); | 4221 library.AddClass(signature_class); |
| 4223 } else { | 4222 } else { |
| 4224 closure_function.set_signature_class(signature_class); | 4223 closure_function.set_signature_class(signature_class); |
| 4225 } | 4224 } |
| 4226 const Type& signature_type = Type::Handle(signature_class.SignatureType()); | 4225 const Type& signature_type = Type::Handle(signature_class.SignatureType()); |
| 4227 if (!signature_type.IsFinalized()) { | 4226 if (!signature_type.IsFinalized()) { |
| 4228 ClassFinalizer::FinalizeType( | 4227 ClassFinalizer::FinalizeType( |
| 4229 signature_class, signature_type, ClassFinalizer::kCanonicalize); | 4228 signature_class, signature_type, ClassFinalizer::kCanonicalize); |
| 4230 } | 4229 } |
| 4231 ASSERT(closure_function.signature_class() == signature_class.raw()); | 4230 ASSERT(closure_function.signature_class() == signature_class.raw()); |
| 4232 set_implicit_closure_function(closure_function); | 4231 set_implicit_closure_function(closure_function); |
| 4233 ASSERT(closure_function.IsImplicitClosureFunction()); | 4232 ASSERT(closure_function.IsImplicitClosureFunction()); |
| 4234 return closure_function.raw(); | 4233 return closure_function.raw(); |
| 4235 } | 4234 } |
| 4236 | 4235 |
| 4237 | 4236 |
| 4238 RawString* Function::BuildSignature( | 4237 RawString* Function::BuildSignature( |
| 4239 bool instantiate, | 4238 bool instantiate, |
| 4240 NameVisibility name_visibility, | 4239 NameVisibility name_visibility, |
| 4241 const AbstractTypeArguments& instantiator) const { | 4240 const AbstractTypeArguments& instantiator) const { |
| 4242 const GrowableObjectArray& pieces = | 4241 const GrowableObjectArray& pieces = |
| 4243 GrowableObjectArray::Handle(GrowableObjectArray::New()); | 4242 GrowableObjectArray::Handle(GrowableObjectArray::New()); |
| 4244 String& name = String::Handle(); | 4243 String& name = String::Handle(); |
| 4245 if (!instantiate && !is_static() && (name_visibility == kInternalName)) { | 4244 if (!instantiate && !is_static() && (name_visibility == kInternalName)) { |
| 4246 // Prefix the signature with its class and type parameters, if any (e.g. | 4245 // Prefix the signature with its signature class and type parameters, if any |
| 4247 // "Map<K, V>(K) => bool"). | 4246 // (e.g. "Map<K, V>(K) => bool"). In case of a function type alias, the |
| 4247 // signature class name is the alias name. |
| 4248 // The signature of static functions cannot be type parameterized. | 4248 // The signature of static functions cannot be type parameterized. |
| 4249 const Class& function_class = Class::Handle(Owner()); | 4249 const Class& function_class = Class::Handle(Owner()); |
| 4250 ASSERT(!function_class.IsNull()); | 4250 ASSERT(!function_class.IsNull()); |
| 4251 const TypeArguments& type_parameters = TypeArguments::Handle( | 4251 const TypeArguments& type_parameters = TypeArguments::Handle( |
| 4252 function_class.type_parameters()); | 4252 function_class.type_parameters()); |
| 4253 if (!type_parameters.IsNull()) { | 4253 if (!type_parameters.IsNull()) { |
| 4254 const String& function_class_name = String::Handle(function_class.Name()); | 4254 const String& function_class_name = String::Handle(function_class.Name()); |
| 4255 pieces.Add(function_class_name); | 4255 pieces.Add(function_class_name); |
| 4256 intptr_t num_type_parameters = type_parameters.Length(); | 4256 intptr_t num_type_parameters = type_parameters.Length(); |
| 4257 pieces.Add(Symbols::LAngleBracket()); | 4257 pieces.Add(Symbols::LAngleBracket()); |
| (...skipping 8530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12788 } | 12788 } |
| 12789 return result.raw(); | 12789 return result.raw(); |
| 12790 } | 12790 } |
| 12791 | 12791 |
| 12792 | 12792 |
| 12793 const char* WeakProperty::ToCString() const { | 12793 const char* WeakProperty::ToCString() const { |
| 12794 return "_WeakProperty"; | 12794 return "_WeakProperty"; |
| 12795 } | 12795 } |
| 12796 | 12796 |
| 12797 } // namespace dart | 12797 } // namespace dart |
| OLD | NEW |