| OLD | NEW |
| 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/object.h" | 5 #include "vm/object.h" |
| 6 | 6 |
| 7 #include "vm/assembler.h" | 7 #include "vm/assembler.h" |
| 8 #include "vm/assert.h" | 8 #include "vm/assert.h" |
| 9 #include "vm/bigint_operations.h" | 9 #include "vm/bigint_operations.h" |
| 10 #include "vm/bootstrap.h" | 10 #include "vm/bootstrap.h" |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 cls.set_script(script); | 355 cls.set_script(script); |
| 356 lib.AddClass(cls); | 356 lib.AddClass(cls); |
| 357 } | 357 } |
| 358 | 358 |
| 359 | 359 |
| 360 void Object::Init(Isolate* isolate) { | 360 void Object::Init(Isolate* isolate) { |
| 361 TIMERSCOPE(time_bootstrap); | 361 TIMERSCOPE(time_bootstrap); |
| 362 ObjectStore* object_store = isolate->object_store(); | 362 ObjectStore* object_store = isolate->object_store(); |
| 363 | 363 |
| 364 Class& cls = Class::Handle(); | 364 Class& cls = Class::Handle(); |
| 365 Type& type = Type::Handle(); | 365 ParameterizedType& type = ParameterizedType::Handle(); |
| 366 Array& array = Array::Handle(); | 366 Array& array = Array::Handle(); |
| 367 | 367 |
| 368 // All RawArray fields will be initialized to an empty array, therefore | 368 // All RawArray fields will be initialized to an empty array, therefore |
| 369 // initialize array class first. | 369 // initialize array class first. |
| 370 cls = Class::New<Array>(); | 370 cls = Class::New<Array>(); |
| 371 object_store->set_array_class(cls); | 371 object_store->set_array_class(cls); |
| 372 | 372 |
| 373 // Array and ImmutableArray are the only VM classes that are parameterized. | 373 // Array and ImmutableArray are the only VM classes that are parameterized. |
| 374 // Since they are pre-finalized, CalculateFieldOffsets() is not called, so we | 374 // Since they are pre-finalized, CalculateFieldOffsets() is not called, so we |
| 375 // need to set the offset of their type_arguments_ field, which is explicitly | 375 // need to set the offset of their type_arguments_ field, which is explicitly |
| (...skipping 973 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1349 interface_args = interface.arguments(); | 1349 interface_args = interface.arguments(); |
| 1350 if (!interface_args.IsNull() && !interface_args.IsInstantiated()) { | 1350 if (!interface_args.IsNull() && !interface_args.IsInstantiated()) { |
| 1351 // This type implements an interface that is parameterized with generic | 1351 // This type implements an interface that is parameterized with generic |
| 1352 // type(s), e.g. it implements Array<T>. | 1352 // type(s), e.g. it implements Array<T>. |
| 1353 // The uninstantiated type T must be instantiated using the type | 1353 // The uninstantiated type T must be instantiated using the type |
| 1354 // parameters of this type before performing the type test. | 1354 // parameters of this type before performing the type test. |
| 1355 if (type_arguments.IsNull()) { | 1355 if (type_arguments.IsNull()) { |
| 1356 // This type is raw, so the uninstantiated type arguments of the | 1356 // This type is raw, so the uninstantiated type arguments of the |
| 1357 // interface cannot be instantiated and we must check against a raw | 1357 // interface cannot be instantiated and we must check against a raw |
| 1358 // interface. | 1358 // interface. |
| 1359 interface_args = TypeArguments::null(); | 1359 interface_args = TypeArray::null(); |
| 1360 } else { | 1360 } else { |
| 1361 // The type arguments of this type that are referred to by the type | 1361 // The type arguments of this type that are referred to by the type |
| 1362 // parameters of the interface are at the end of the type vector, | 1362 // parameters of the interface are at the end of the type vector, |
| 1363 // after the type arguments of the super type of this type. | 1363 // after the type arguments of the super type of this type. |
| 1364 const intptr_t offset = NumTypeArguments() - NumTypeParameters(); | 1364 const intptr_t offset = NumTypeArguments() - NumTypeParameters(); |
| 1365 interface_args = interface_args.InstantiateFrom(type_arguments, | 1365 interface_args = interface_args.InstantiateFrom(type_arguments, |
| 1366 offset); | 1366 offset); |
| 1367 // TODO(regis): Check the subtyping constraints if any, i.e. if | 1367 // TODO(regis): Check the subtyping constraints if any, i.e. if |
| 1368 // interface.type_parameter_extends() is not an array of DynamicType. | 1368 // interface.type_parameter_extends() is not an array of DynamicType. |
| 1369 // Should we pass the constraints to InstantiateFrom and it would | 1369 // Should we pass the constraints to InstantiateFrom and it would |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1701 RawUnresolvedClass* Type::unresolved_class() const { | 1701 RawUnresolvedClass* Type::unresolved_class() const { |
| 1702 // Type is an abstract class. | 1702 // Type is an abstract class. |
| 1703 UNREACHABLE(); | 1703 UNREACHABLE(); |
| 1704 return UnresolvedClass::null(); | 1704 return UnresolvedClass::null(); |
| 1705 } | 1705 } |
| 1706 | 1706 |
| 1707 | 1707 |
| 1708 RawTypeArguments* Type::arguments() const { | 1708 RawTypeArguments* Type::arguments() const { |
| 1709 // Type is an abstract class. | 1709 // Type is an abstract class. |
| 1710 UNREACHABLE(); | 1710 UNREACHABLE(); |
| 1711 return TypeArguments::null(); | 1711 return NULL; |
| 1712 } | 1712 } |
| 1713 | 1713 |
| 1714 | 1714 |
| 1715 bool Type::IsInstantiated() const { | 1715 bool Type::IsInstantiated() const { |
| 1716 // Type is an abstract class. | 1716 // Type is an abstract class. |
| 1717 UNREACHABLE(); | 1717 UNREACHABLE(); |
| 1718 return false; | 1718 return false; |
| 1719 } | 1719 } |
| 1720 | 1720 |
| 1721 | 1721 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1738 UNREACHABLE(); | 1738 UNREACHABLE(); |
| 1739 return false; | 1739 return false; |
| 1740 } | 1740 } |
| 1741 | 1741 |
| 1742 | 1742 |
| 1743 RawType* Type::InstantiateFrom( | 1743 RawType* Type::InstantiateFrom( |
| 1744 const TypeArguments& instantiator_type_arguments, | 1744 const TypeArguments& instantiator_type_arguments, |
| 1745 intptr_t offset) const { | 1745 intptr_t offset) const { |
| 1746 // Type is an abstract class. | 1746 // Type is an abstract class. |
| 1747 UNREACHABLE(); | 1747 UNREACHABLE(); |
| 1748 return Type::null(); | 1748 return NULL; |
| 1749 } | 1749 } |
| 1750 | 1750 |
| 1751 | 1751 |
| 1752 RawType* Type::Canonicalize() const { | 1752 RawType* Type::Canonicalize() const { |
| 1753 // Type is an abstract class. | 1753 // Type is an abstract class. |
| 1754 UNREACHABLE(); | 1754 UNREACHABLE(); |
| 1755 return Type::null(); | 1755 return NULL; |
| 1756 } | 1756 } |
| 1757 | 1757 |
| 1758 | 1758 |
| 1759 RawString* Type::Name() const { | 1759 RawString* Type::Name() const { |
| 1760 // If the type is still being finalized, we may be reporting an error about | 1760 // If the type is still being finalized, we may be reporting an error about |
| 1761 // an illformed type, so proceed with caution. | 1761 // an illformed type, so proceed with caution. |
| 1762 const TypeArguments& args = TypeArguments::Handle(arguments()); | 1762 const TypeArguments& args = TypeArguments::Handle(arguments()); |
| 1763 const intptr_t num_args = args.IsNull() ? 0 : args.Length(); | 1763 const intptr_t num_args = args.IsNull() ? 0 : args.Length(); |
| 1764 String& class_name = String::Handle(); | 1764 String& class_name = String::Handle(); |
| 1765 intptr_t first_type_param_index; | 1765 intptr_t first_type_param_index; |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1919 TypeArguments::Handle(other.arguments())); | 1919 TypeArguments::Handle(other.arguments())); |
| 1920 } else { | 1920 } else { |
| 1921 ASSERT(test == kIsAssignableTo); | 1921 ASSERT(test == kIsAssignableTo); |
| 1922 return cls.IsAssignableTo(TypeArguments::Handle(arguments()), | 1922 return cls.IsAssignableTo(TypeArguments::Handle(arguments()), |
| 1923 Class::Handle(other.type_class()), | 1923 Class::Handle(other.type_class()), |
| 1924 TypeArguments::Handle(other.arguments())); | 1924 TypeArguments::Handle(other.arguments())); |
| 1925 } | 1925 } |
| 1926 } | 1926 } |
| 1927 | 1927 |
| 1928 | 1928 |
| 1929 RawType* Type::NullType() { | 1929 RawParameterizedType* Type::NullType() { |
| 1930 return Isolate::Current()->object_store()->null_type(); | 1930 return Isolate::Current()->object_store()->null_type(); |
| 1931 } | 1931 } |
| 1932 | 1932 |
| 1933 | 1933 |
| 1934 RawType* Type::DynamicType() { | 1934 RawParameterizedType* Type::DynamicType() { |
| 1935 return Isolate::Current()->object_store()->dynamic_type(); | 1935 return Isolate::Current()->object_store()->dynamic_type(); |
| 1936 } | 1936 } |
| 1937 | 1937 |
| 1938 | 1938 |
| 1939 RawType* Type::VoidType() { | 1939 RawParameterizedType* Type::VoidType() { |
| 1940 return Isolate::Current()->object_store()->void_type(); | 1940 return Isolate::Current()->object_store()->void_type(); |
| 1941 } | 1941 } |
| 1942 | 1942 |
| 1943 | 1943 |
| 1944 RawType* Type::ObjectType() { | 1944 RawParameterizedType* Type::ObjectType() { |
| 1945 return Isolate::Current()->object_store()->object_type(); | 1945 return Isolate::Current()->object_store()->object_type(); |
| 1946 } | 1946 } |
| 1947 | 1947 |
| 1948 | 1948 |
| 1949 RawType* Type::BoolInterface() { | 1949 RawParameterizedType* Type::BoolInterface() { |
| 1950 return Isolate::Current()->object_store()->bool_interface(); | 1950 return Isolate::Current()->object_store()->bool_interface(); |
| 1951 } | 1951 } |
| 1952 | 1952 |
| 1953 | 1953 |
| 1954 RawType* Type::IntInterface() { | 1954 RawParameterizedType* Type::IntInterface() { |
| 1955 return Isolate::Current()->object_store()->int_interface(); | 1955 return Isolate::Current()->object_store()->int_interface(); |
| 1956 } | 1956 } |
| 1957 | 1957 |
| 1958 | 1958 |
| 1959 RawType* Type::DoubleInterface() { | 1959 RawParameterizedType* Type::DoubleInterface() { |
| 1960 return Isolate::Current()->object_store()->double_interface(); | 1960 return Isolate::Current()->object_store()->double_interface(); |
| 1961 } | 1961 } |
| 1962 | 1962 |
| 1963 | 1963 |
| 1964 RawType* Type::NumberInterface() { | 1964 RawParameterizedType* Type::NumberInterface() { |
| 1965 return Isolate::Current()->object_store()->number_interface(); | 1965 return Isolate::Current()->object_store()->number_interface(); |
| 1966 } | 1966 } |
| 1967 | 1967 |
| 1968 | 1968 |
| 1969 RawType* Type::StringInterface() { | 1969 RawParameterizedType* Type::StringInterface() { |
| 1970 return Isolate::Current()->object_store()->string_interface(); | 1970 return Isolate::Current()->object_store()->string_interface(); |
| 1971 } | 1971 } |
| 1972 | 1972 |
| 1973 | 1973 |
| 1974 RawType* Type::FunctionInterface() { | 1974 RawParameterizedType* Type::FunctionInterface() { |
| 1975 return Isolate::Current()->object_store()->function_interface(); | 1975 return Isolate::Current()->object_store()->function_interface(); |
| 1976 } | 1976 } |
| 1977 | 1977 |
| 1978 | 1978 |
| 1979 RawType* Type::ListInterface() { | 1979 RawParameterizedType* Type::ListInterface() { |
| 1980 return Isolate::Current()->object_store()->list_interface(); | 1980 return Isolate::Current()->object_store()->list_interface(); |
| 1981 } | 1981 } |
| 1982 | 1982 |
| 1983 | 1983 |
| 1984 RawType* Type::NewRawType(const Class& type_class) { | 1984 RawParameterizedType* Type::NewRawType(const Class& type_class) { |
| 1985 const TypeArguments& type_arguments = | 1985 const TypeArguments& type_arguments = |
| 1986 TypeArguments::Handle(type_class.type_parameter_extends()); | 1986 TypeArguments::Handle(type_class.type_parameter_extends()); |
| 1987 return NewParameterizedType(Object::Handle(type_class.raw()), type_arguments); | 1987 return NewParameterizedType(Object::Handle(type_class.raw()), type_arguments); |
| 1988 } | 1988 } |
| 1989 | 1989 |
| 1990 | 1990 |
| 1991 RawType* Type::NewNonParameterizedType(const Class& type_class) { | 1991 RawParameterizedType* Type::NewNonParameterizedType(const Class& type_class) { |
| 1992 ASSERT(!type_class.HasTypeArguments()); | 1992 ASSERT(!type_class.HasTypeArguments()); |
| 1993 const TypeArguments& no_type_arguments = TypeArguments::Handle(); | 1993 const TypeArguments& no_type_arguments = TypeArguments::Handle(); |
| 1994 ParameterizedType& type = ParameterizedType::Handle(); | 1994 ParameterizedType& type = ParameterizedType::Handle(); |
| 1995 type ^= ParameterizedType::New( | 1995 type ^= ParameterizedType::New( |
| 1996 Object::Handle(type_class.raw()), no_type_arguments); | 1996 Object::Handle(type_class.raw()), no_type_arguments); |
| 1997 type.set_is_finalized(); | 1997 type.set_is_finalized(); |
| 1998 type ^= type.Canonicalize(); | 1998 type ^= type.Canonicalize(); |
| 1999 return type.raw(); | 1999 return type.raw(); |
| 2000 } | 2000 } |
| 2001 | 2001 |
| 2002 | 2002 |
| 2003 RawType* Type::NewParameterizedType(const Object& clazz, | 2003 RawParameterizedType* Type::NewParameterizedType(const Object& clazz, |
| 2004 const TypeArguments& arguments) { | 2004 const TypeArguments& arguments) { |
| 2005 return ParameterizedType::New(clazz, arguments); | 2005 return ParameterizedType::New(clazz, arguments); |
| 2006 } | 2006 } |
| 2007 | 2007 |
| 2008 | 2008 |
| 2009 RawType* Type::NewTypeParameter(intptr_t index, const String& name) { | 2009 RawType* Type::NewTypeParameter(intptr_t index, const String& name) { |
| 2010 return TypeParameter::New(index, name); | 2010 return TypeParameter::New(index, name); |
| 2011 } | 2011 } |
| 2012 | 2012 |
| 2013 | 2013 |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2201 | 2201 |
| 2202 void ParameterizedType::set_type_state(int8_t state) const { | 2202 void ParameterizedType::set_type_state(int8_t state) const { |
| 2203 ASSERT(state == RawParameterizedType::kAllocated || | 2203 ASSERT(state == RawParameterizedType::kAllocated || |
| 2204 state == RawParameterizedType::kBeingFinalized || | 2204 state == RawParameterizedType::kBeingFinalized || |
| 2205 state == RawParameterizedType::kFinalized); | 2205 state == RawParameterizedType::kFinalized); |
| 2206 raw_ptr()->type_state_ = state; | 2206 raw_ptr()->type_state_ = state; |
| 2207 } | 2207 } |
| 2208 | 2208 |
| 2209 | 2209 |
| 2210 const char* ParameterizedType::ToCString() const { | 2210 const char* ParameterizedType::ToCString() const { |
| 2211 return "ParameterizedType"; | 2211 if (IsResolved()) { |
| 2212 const char* format = "ParameterizedType: class '%s', args:[%s]"; |
| 2213 const char* class_name = |
| 2214 String::Handle(Class::Handle(type_class()).Name()).ToCString(); |
| 2215 const char* args_cstr = TypeArguments::Handle(arguments()).ToCString(); |
| 2216 intptr_t len = OS::SNPrint(NULL, 0, format, class_name, args_cstr) + 1; |
| 2217 char* chars = reinterpret_cast<char*>( |
| 2218 Isolate::Current()->current_zone()->Allocate(len)); |
| 2219 OS::SNPrint(chars, len, format, class_name, args_cstr); |
| 2220 return chars; |
| 2221 } else { |
| 2222 return "Unresolved ParameterizedType"; |
| 2223 } |
| 2212 } | 2224 } |
| 2213 | 2225 |
| 2214 | 2226 |
| 2215 bool TypeParameter::Equals(const Type& other) const { | 2227 bool TypeParameter::Equals(const Type& other) const { |
| 2216 if (raw() == other.raw()) { | 2228 if (raw() == other.raw()) { |
| 2217 return true; | 2229 return true; |
| 2218 } | 2230 } |
| 2219 if (!other.IsTypeParameter()) { | 2231 if (!other.IsTypeParameter()) { |
| 2220 return false; | 2232 return false; |
| 2221 } | 2233 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2259 | 2271 |
| 2260 RawTypeParameter* TypeParameter::New(intptr_t index, const String& name) { | 2272 RawTypeParameter* TypeParameter::New(intptr_t index, const String& name) { |
| 2261 const TypeParameter& result = TypeParameter::Handle(TypeParameter::New()); | 2273 const TypeParameter& result = TypeParameter::Handle(TypeParameter::New()); |
| 2262 result.set_index(index); | 2274 result.set_index(index); |
| 2263 result.set_name(name); | 2275 result.set_name(name); |
| 2264 return result.raw(); | 2276 return result.raw(); |
| 2265 } | 2277 } |
| 2266 | 2278 |
| 2267 | 2279 |
| 2268 const char* TypeParameter::ToCString() const { | 2280 const char* TypeParameter::ToCString() const { |
| 2269 return "TypeParameter"; | 2281 const char* format = "TypeParameter: name %s; index: %d"; |
| 2282 const char* name_cstr = String::Handle(Name()).ToCString(); |
| 2283 intptr_t len = OS::SNPrint(NULL, 0, format, name_cstr, Index()) + 1; |
| 2284 char* chars = reinterpret_cast<char*>( |
| 2285 Isolate::Current()->current_zone()->Allocate(len)); |
| 2286 OS::SNPrint(chars, len, format, name_cstr, Index()); |
| 2287 return chars; |
| 2270 } | 2288 } |
| 2271 | 2289 |
| 2272 | 2290 |
| 2273 RawClass* InstantiatedType::type_class() const { | 2291 RawClass* InstantiatedType::type_class() const { |
| 2274 return Type::Handle(uninstantiated_type()).type_class(); | 2292 return Type::Handle(uninstantiated_type()).type_class(); |
| 2275 } | 2293 } |
| 2276 | 2294 |
| 2277 | 2295 |
| 2278 RawTypeArguments* InstantiatedType::arguments() const { | 2296 RawTypeArguments* InstantiatedType::arguments() const { |
| 2279 return TypeArguments::NewInstantiatedTypeArguments( | 2297 return TypeArguments::NewInstantiatedTypeArguments( |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2322 intptr_t TypeArguments::Length() const { | 2340 intptr_t TypeArguments::Length() const { |
| 2323 // TypeArguments is an abstract class. | 2341 // TypeArguments is an abstract class. |
| 2324 UNREACHABLE(); | 2342 UNREACHABLE(); |
| 2325 return -1; | 2343 return -1; |
| 2326 } | 2344 } |
| 2327 | 2345 |
| 2328 | 2346 |
| 2329 RawType* TypeArguments::TypeAt(intptr_t index) const { | 2347 RawType* TypeArguments::TypeAt(intptr_t index) const { |
| 2330 // TypeArguments is an abstract class. | 2348 // TypeArguments is an abstract class. |
| 2331 UNREACHABLE(); | 2349 UNREACHABLE(); |
| 2332 return Type::null(); | 2350 return NULL; |
| 2333 } | 2351 } |
| 2334 | 2352 |
| 2335 | 2353 |
| 2336 void TypeArguments::SetTypeAt(intptr_t index, const Type& value) const { | 2354 void TypeArguments::SetTypeAt(intptr_t index, const Type& value) const { |
| 2337 // TypeArguments is an abstract class. | 2355 // TypeArguments is an abstract class. |
| 2338 UNREACHABLE(); | 2356 UNREACHABLE(); |
| 2339 } | 2357 } |
| 2340 | 2358 |
| 2341 | 2359 |
| 2342 bool TypeArguments::IsResolved() const { | 2360 bool TypeArguments::IsResolved() const { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2380 } | 2398 } |
| 2381 return arguments.Equals(other_arguments); | 2399 return arguments.Equals(other_arguments); |
| 2382 } | 2400 } |
| 2383 | 2401 |
| 2384 | 2402 |
| 2385 RawTypeArguments* TypeArguments::InstantiateFrom( | 2403 RawTypeArguments* TypeArguments::InstantiateFrom( |
| 2386 const TypeArguments& instantiator_type_arguments, | 2404 const TypeArguments& instantiator_type_arguments, |
| 2387 intptr_t offset) const { | 2405 intptr_t offset) const { |
| 2388 // TypeArguments is an abstract class. | 2406 // TypeArguments is an abstract class. |
| 2389 UNREACHABLE(); | 2407 UNREACHABLE(); |
| 2390 return TypeArguments::null(); | 2408 return NULL; |
| 2391 } | 2409 } |
| 2392 | 2410 |
| 2393 | 2411 |
| 2394 bool TypeArguments::IsDynamicTypes(intptr_t len) const { | 2412 bool TypeArguments::IsDynamicTypes(intptr_t len) const { |
| 2395 ASSERT(Length() >= len); | 2413 ASSERT(Length() >= len); |
| 2396 Type& type = Type::Handle(); | 2414 Type& type = Type::Handle(); |
| 2397 Class& type_class = Class::Handle(); | 2415 Class& type_class = Class::Handle(); |
| 2398 for (intptr_t i = 0; i < len; i++) { | 2416 for (intptr_t i = 0; i < len; i++) { |
| 2399 type = TypeAt(i); | 2417 type = TypeAt(i); |
| 2400 ASSERT(!type.IsNull()); | 2418 ASSERT(!type.IsNull()); |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2560 const Class& type_array_class = Class::Handle(Object::type_array_class()); | 2578 const Class& type_array_class = Class::Handle(Object::type_array_class()); |
| 2561 TypeArray& result = TypeArray::Handle(); | 2579 TypeArray& result = TypeArray::Handle(); |
| 2562 { | 2580 { |
| 2563 RawObject* raw = Object::Allocate(type_array_class, | 2581 RawObject* raw = Object::Allocate(type_array_class, |
| 2564 TypeArray::InstanceSize(len), | 2582 TypeArray::InstanceSize(len), |
| 2565 Heap::kOld); | 2583 Heap::kOld); |
| 2566 NoGCScope no_gc; | 2584 NoGCScope no_gc; |
| 2567 result ^= raw; | 2585 result ^= raw; |
| 2568 result.SetLength(len); | 2586 result.SetLength(len); |
| 2569 for (intptr_t i = 0; i < len; i++) { | 2587 for (intptr_t i = 0; i < len; i++) { |
| 2570 *result.TypeAddr(i) = Type::null(); | 2588 *result.TypeAddr(i) = ParameterizedType::null(); |
| 2571 } | 2589 } |
| 2572 } | 2590 } |
| 2573 return result.raw(); | 2591 return result.raw(); |
| 2574 } | 2592 } |
| 2575 | 2593 |
| 2576 | 2594 |
| 2577 RawType** TypeArray::TypeAddr(intptr_t index) const { | 2595 RawType** TypeArray::TypeAddr(intptr_t index) const { |
| 2578 // TODO(iposva): Determine if we should throw an exception here. | 2596 // TODO(iposva): Determine if we should throw an exception here. |
| 2579 ASSERT((index >= 0) && (index < Length())); | 2597 ASSERT((index >= 0) && (index < Length())); |
| 2580 return &raw_ptr()->types_[index]; | 2598 return &raw_ptr()->types_[index]; |
| 2581 } | 2599 } |
| 2582 | 2600 |
| 2583 | 2601 |
| 2584 void TypeArray::SetLength(intptr_t value) { | 2602 void TypeArray::SetLength(intptr_t value) { |
| 2585 // This is only safe because we create a new Smi, which does not cause | 2603 // This is only safe because we create a new Smi, which does not cause |
| 2586 // heap allocation. | 2604 // heap allocation. |
| 2587 raw_ptr()->length_ = Smi::New(value); | 2605 raw_ptr()->length_ = Smi::New(value); |
| 2588 } | 2606 } |
| 2589 | 2607 |
| 2590 | 2608 |
| 2591 const char* TypeArray::ToCString() const { | 2609 const char* TypeArray::ToCString() const { |
| 2592 return "TypeArray"; | 2610 if (IsNull()) { |
| 2611 return "NULL TypeArray"; |
| 2612 } |
| 2613 const char* format = "%s [%s]"; |
| 2614 const char* prev_cstr = "TypeArray:"; |
| 2615 for (int i = 0; i < Length(); i++) { |
| 2616 const char* type_cstr = Type::Handle(TypeAt(i)).ToCString(); |
| 2617 intptr_t len = OS::SNPrint(NULL, 0, format, prev_cstr, type_cstr) + 1; |
| 2618 char* chars = reinterpret_cast<char*>( |
| 2619 Isolate::Current()->current_zone()->Allocate(len)); |
| 2620 OS::SNPrint(chars, len, format, prev_cstr, type_cstr); |
| 2621 prev_cstr = chars; |
| 2622 } |
| 2623 return prev_cstr; |
| 2593 } | 2624 } |
| 2594 | 2625 |
| 2595 | 2626 |
| 2596 intptr_t InstantiatedTypeArguments::Length() const { | 2627 intptr_t InstantiatedTypeArguments::Length() const { |
| 2597 return TypeArguments::Handle(uninstantiated_type_arguments()).Length(); | 2628 return TypeArguments::Handle(uninstantiated_type_arguments()).Length(); |
| 2598 } | 2629 } |
| 2599 | 2630 |
| 2600 | 2631 |
| 2601 RawType* InstantiatedTypeArguments::TypeAt(intptr_t index) const { | 2632 RawType* InstantiatedTypeArguments::TypeAt(intptr_t index) const { |
| 2602 const Type& type = Type::Handle( | 2633 const Type& type = Type::Handle( |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2649 const TypeArguments& instantiator_type_arguments) { | 2680 const TypeArguments& instantiator_type_arguments) { |
| 2650 const InstantiatedTypeArguments& result = | 2681 const InstantiatedTypeArguments& result = |
| 2651 InstantiatedTypeArguments::Handle(InstantiatedTypeArguments::New()); | 2682 InstantiatedTypeArguments::Handle(InstantiatedTypeArguments::New()); |
| 2652 result.set_uninstantiated_type_arguments(uninstantiated_type_arguments); | 2683 result.set_uninstantiated_type_arguments(uninstantiated_type_arguments); |
| 2653 result.set_instantiator_type_arguments(instantiator_type_arguments); | 2684 result.set_instantiator_type_arguments(instantiator_type_arguments); |
| 2654 return result.raw(); | 2685 return result.raw(); |
| 2655 } | 2686 } |
| 2656 | 2687 |
| 2657 | 2688 |
| 2658 const char* InstantiatedTypeArguments::ToCString() const { | 2689 const char* InstantiatedTypeArguments::ToCString() const { |
| 2659 return "InstantiatedTypeArguments"; | 2690 if (IsNull()) { |
| 2691 return "NULL InstantiatedTypeArguments"; |
| 2692 } |
| 2693 const char* format = "InstantiatedTypeArguments: [%s] instantiator: [%s]\n"; |
| 2694 const char* arg_cstr = |
| 2695 TypeArguments::Handle(uninstantiated_type_arguments()).ToCString(); |
| 2696 const char* instantiator_cstr = |
| 2697 TypeArguments::Handle(instantiator_type_arguments()).ToCString(); |
| 2698 intptr_t len = |
| 2699 OS::SNPrint(NULL, 0, format, arg_cstr, instantiator_cstr) + 1; |
| 2700 char* chars = reinterpret_cast<char*>( |
| 2701 Isolate::Current()->current_zone()->Allocate(len)); |
| 2702 OS::SNPrint(chars, len, format, arg_cstr, instantiator_cstr); |
| 2703 return chars; |
| 2660 } | 2704 } |
| 2661 | 2705 |
| 2662 | 2706 |
| 2663 void Function::SetCode(const Code& value) const { | 2707 void Function::SetCode(const Code& value) const { |
| 2664 StorePointer(&raw_ptr()->code_, value.raw()); | 2708 StorePointer(&raw_ptr()->code_, value.raw()); |
| 2665 ASSERT(Function::Handle(value.function()).IsNull() || | 2709 ASSERT(Function::Handle(value.function()).IsNull() || |
| 2666 (value.function() == this->raw())); | 2710 (value.function() == this->raw())); |
| 2667 value.set_function(*this); | 2711 value.set_function(*this); |
| 2668 } | 2712 } |
| 2669 | 2713 |
| (...skipping 2260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4930 Array::Handle(Array::Grow(constants, new_length, Heap::kOld)); | 4974 Array::Handle(Array::Grow(constants, new_length, Heap::kOld)); |
| 4931 cls.set_constants(new_constants); | 4975 cls.set_constants(new_constants); |
| 4932 new_constants.SetAt(index, *this); | 4976 new_constants.SetAt(index, *this); |
| 4933 } else { | 4977 } else { |
| 4934 constants.SetAt(index, *this); | 4978 constants.SetAt(index, *this); |
| 4935 } | 4979 } |
| 4936 return this->raw(); | 4980 return this->raw(); |
| 4937 } | 4981 } |
| 4938 | 4982 |
| 4939 | 4983 |
| 4940 RawType* Instance::GetType() const { | 4984 RawParameterizedType* Instance::GetType() const { |
| 4941 if (IsNull()) { | 4985 if (IsNull()) { |
| 4942 return Type::NullType(); | 4986 return ParameterizedType::NullType(); |
| 4943 } | 4987 } |
| 4944 const Class& cls = Class::Handle(clazz()); | 4988 const Class& cls = Class::Handle(clazz()); |
| 4945 TypeArguments& type_arguments = TypeArguments::Handle(); | 4989 TypeArguments& type_arguments = TypeArguments::Handle(); |
| 4946 if (cls.HasTypeArguments()) { | 4990 if (cls.HasTypeArguments()) { |
| 4947 type_arguments = GetTypeArguments(); | 4991 type_arguments = GetTypeArguments(); |
| 4948 } | 4992 } |
| 4949 const ParameterizedType& type = ParameterizedType::Handle( | 4993 const ParameterizedType& type = ParameterizedType::Handle( |
| 4950 ParameterizedType::New(cls, type_arguments)); | 4994 ParameterizedType::New(cls, type_arguments)); |
| 4951 type.set_is_finalized(); | 4995 type.set_is_finalized(); |
| 4952 return type.raw(); | 4996 return type.raw(); |
| (...skipping 2260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7213 const String& str = String::Handle(pattern()); | 7257 const String& str = String::Handle(pattern()); |
| 7214 const char* format = "JSRegExp: pattern=%s flags=%s"; | 7258 const char* format = "JSRegExp: pattern=%s flags=%s"; |
| 7215 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); | 7259 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); |
| 7216 char* chars = reinterpret_cast<char*>( | 7260 char* chars = reinterpret_cast<char*>( |
| 7217 Isolate::Current()->current_zone()->Allocate(len + 1)); | 7261 Isolate::Current()->current_zone()->Allocate(len + 1)); |
| 7218 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); | 7262 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); |
| 7219 return chars; | 7263 return chars; |
| 7220 } | 7264 } |
| 7221 | 7265 |
| 7222 } // namespace dart | 7266 } // namespace dart |
| OLD | NEW |