| 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 1348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1359 // parameters of this type before performing the type test. | 1359 // parameters of this type before performing the type test. |
| 1360 if (type_arguments.IsNull()) { | 1360 if (type_arguments.IsNull()) { |
| 1361 // This type is raw, so the uninstantiated type arguments of the | 1361 // This type is raw, so the uninstantiated type arguments of the |
| 1362 // interface cannot be instantiated and we must check against a raw | 1362 // interface cannot be instantiated and we must check against a raw |
| 1363 // interface. | 1363 // interface. |
| 1364 interface_args = TypeArguments::null(); | 1364 interface_args = TypeArguments::null(); |
| 1365 } else { | 1365 } else { |
| 1366 // The type arguments of this type that are referred to by the type | 1366 // The type arguments of this type that are referred to by the type |
| 1367 // parameters of the interface are at the end of the type vector, | 1367 // parameters of the interface are at the end of the type vector, |
| 1368 // after the type arguments of the super type of this type. | 1368 // after the type arguments of the super type of this type. |
| 1369 const intptr_t offset = NumTypeArguments() - NumTypeParameters(); | 1369 // The index of the type parameters is adjusted upon finalization. |
| 1370 interface_args = interface_args.InstantiateFrom(type_arguments, | 1370 ASSERT(interface.IsFinalized()); |
| 1371 offset); | 1371 interface_args = interface_args.InstantiateFrom(type_arguments); |
| 1372 // TODO(regis): Check the subtyping constraints if any, i.e. if | 1372 // TODO(regis): Check the subtyping constraints if any, i.e. if |
| 1373 // interface.type_parameter_extends() is not an array of DynamicType. | 1373 // interface.type_parameter_extends() is not an array of DynamicType. |
| 1374 // Should we pass the constraints to InstantiateFrom and it would | 1374 // Should we pass the constraints to InstantiateFrom and it would |
| 1375 // return null on failure? | 1375 // return null on failure? |
| 1376 } | 1376 } |
| 1377 } | 1377 } |
| 1378 if (interface_class.IsMoreSpecificThan(interface_args, | 1378 if (interface_class.IsMoreSpecificThan(interface_args, |
| 1379 other, | 1379 other, |
| 1380 other_type_arguments)) { | 1380 other_type_arguments)) { |
| 1381 return true; | 1381 return true; |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1739 | 1739 |
| 1740 | 1740 |
| 1741 bool AbstractType::Equals(const AbstractType& other) const { | 1741 bool AbstractType::Equals(const AbstractType& other) const { |
| 1742 // AbstractType is an abstract class. | 1742 // AbstractType is an abstract class. |
| 1743 UNREACHABLE(); | 1743 UNREACHABLE(); |
| 1744 return false; | 1744 return false; |
| 1745 } | 1745 } |
| 1746 | 1746 |
| 1747 | 1747 |
| 1748 RawAbstractType* AbstractType::InstantiateFrom( | 1748 RawAbstractType* AbstractType::InstantiateFrom( |
| 1749 const AbstractTypeArguments& instantiator_type_arguments, | 1749 const AbstractTypeArguments& instantiator_type_arguments) const { |
| 1750 intptr_t offset) const { | |
| 1751 // AbstractType is an abstract class. | 1750 // AbstractType is an abstract class. |
| 1752 UNREACHABLE(); | 1751 UNREACHABLE(); |
| 1753 return NULL; | 1752 return NULL; |
| 1754 } | 1753 } |
| 1755 | 1754 |
| 1756 | 1755 |
| 1757 RawAbstractType* AbstractType::Canonicalize() const { | 1756 RawAbstractType* AbstractType::Canonicalize() const { |
| 1758 // AbstractType is an abstract class. | 1757 // AbstractType is an abstract class. |
| 1759 UNREACHABLE(); | 1758 UNREACHABLE(); |
| 1760 return NULL; | 1759 return NULL; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1787 first_type_param_index = num_args - num_type_params; | 1786 first_type_param_index = num_args - num_type_params; |
| 1788 } | 1787 } |
| 1789 if (cls.IsSignatureClass()) { | 1788 if (cls.IsSignatureClass()) { |
| 1790 // We may be reporting an error about an illformed function type. In that | 1789 // We may be reporting an error about an illformed function type. In that |
| 1791 // case, avoid instantiating the signature, since it may lead to cycles. | 1790 // case, avoid instantiating the signature, since it may lead to cycles. |
| 1792 if (!IsFinalized() || IsBeingFinalized()) { | 1791 if (!IsFinalized() || IsBeingFinalized()) { |
| 1793 return class_name.raw(); | 1792 return class_name.raw(); |
| 1794 } | 1793 } |
| 1795 const Function& signature_function = Function::Handle( | 1794 const Function& signature_function = Function::Handle( |
| 1796 cls.signature_function()); | 1795 cls.signature_function()); |
| 1797 return signature_function.InstantiatedSignatureFrom( | 1796 // Signature classes have no super type. |
| 1798 args, first_type_param_index); | 1797 ASSERT(first_type_param_index == 0); |
| 1798 return signature_function.InstantiatedSignatureFrom(args); |
| 1799 } | 1799 } |
| 1800 } else { | 1800 } else { |
| 1801 const UnresolvedClass& cls = UnresolvedClass::Handle(unresolved_class()); | 1801 const UnresolvedClass& cls = UnresolvedClass::Handle(unresolved_class()); |
| 1802 class_name = cls.Name(); | 1802 class_name = cls.Name(); |
| 1803 num_type_params = num_args; | 1803 num_type_params = num_args; |
| 1804 first_type_param_index = 0; | 1804 first_type_param_index = 0; |
| 1805 } | 1805 } |
| 1806 String& type_name = String::Handle(); | 1806 String& type_name = String::Handle(); |
| 1807 if (num_type_params == 0) { | 1807 if (num_type_params == 0) { |
| 1808 type_name = class_name.raw(); | 1808 type_name = class_name.raw(); |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2088 | 2088 |
| 2089 | 2089 |
| 2090 bool Type::IsInstantiated() const { | 2090 bool Type::IsInstantiated() const { |
| 2091 const AbstractTypeArguments& args = | 2091 const AbstractTypeArguments& args = |
| 2092 AbstractTypeArguments::Handle(arguments()); | 2092 AbstractTypeArguments::Handle(arguments()); |
| 2093 return args.IsNull() || args.IsInstantiated(); | 2093 return args.IsNull() || args.IsInstantiated(); |
| 2094 } | 2094 } |
| 2095 | 2095 |
| 2096 | 2096 |
| 2097 RawAbstractType* Type::InstantiateFrom( | 2097 RawAbstractType* Type::InstantiateFrom( |
| 2098 const AbstractTypeArguments& instantiator_type_arguments, | 2098 const AbstractTypeArguments& instantiator_type_arguments) const { |
| 2099 intptr_t offset) const { | |
| 2100 ASSERT(IsFinalized()); | 2099 ASSERT(IsFinalized()); |
| 2101 ASSERT(!IsInstantiated()); | 2100 ASSERT(!IsInstantiated()); |
| 2102 AbstractTypeArguments& type_arguments = | 2101 AbstractTypeArguments& type_arguments = |
| 2103 AbstractTypeArguments::Handle(arguments()); | 2102 AbstractTypeArguments::Handle(arguments()); |
| 2104 type_arguments = type_arguments.InstantiateFrom(instantiator_type_arguments, | 2103 type_arguments = type_arguments.InstantiateFrom(instantiator_type_arguments); |
| 2105 offset); | |
| 2106 const Class& cls = Class::Handle(type_class()); | 2104 const Class& cls = Class::Handle(type_class()); |
| 2107 ASSERT(cls.is_finalized()); | 2105 ASSERT(cls.is_finalized()); |
| 2108 Type& instantiated_type = Type::Handle(Type::New(cls, type_arguments)); | 2106 Type& instantiated_type = Type::Handle(Type::New(cls, type_arguments)); |
| 2109 ASSERT(type_arguments.IsNull() || | 2107 ASSERT(type_arguments.IsNull() || |
| 2110 (type_arguments.Length() == cls.NumTypeArguments())); | 2108 (type_arguments.Length() == cls.NumTypeArguments())); |
| 2111 instantiated_type.set_is_finalized(); | 2109 instantiated_type.set_is_finalized(); |
| 2112 return instantiated_type.raw(); | 2110 return instantiated_type.raw(); |
| 2113 } | 2111 } |
| 2114 | 2112 |
| 2115 | 2113 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2240 Isolate::Current()->current_zone()->Allocate(len)); | 2238 Isolate::Current()->current_zone()->Allocate(len)); |
| 2241 OS::SNPrint(chars, len, format, class_name, args_cstr); | 2239 OS::SNPrint(chars, len, format, class_name, args_cstr); |
| 2242 return chars; | 2240 return chars; |
| 2243 } | 2241 } |
| 2244 } else { | 2242 } else { |
| 2245 return "Unresolved Type"; | 2243 return "Unresolved Type"; |
| 2246 } | 2244 } |
| 2247 } | 2245 } |
| 2248 | 2246 |
| 2249 | 2247 |
| 2248 void TypeParameter::set_is_finalized() const { |
| 2249 ASSERT(!IsFinalized()); |
| 2250 set_type_state(RawTypeParameter::kFinalized); |
| 2251 } |
| 2252 |
| 2253 |
| 2250 bool TypeParameter::Equals(const AbstractType& other) const { | 2254 bool TypeParameter::Equals(const AbstractType& other) const { |
| 2251 if (raw() == other.raw()) { | 2255 if (raw() == other.raw()) { |
| 2252 return true; | 2256 return true; |
| 2253 } | 2257 } |
| 2254 if (!other.IsTypeParameter()) { | 2258 if (!other.IsTypeParameter()) { |
| 2255 return false; | 2259 return false; |
| 2256 } | 2260 } |
| 2257 TypeParameter& other_type_parameter = TypeParameter::Handle(); | 2261 TypeParameter& other_type_parameter = TypeParameter::Handle(); |
| 2258 other_type_parameter ^= other.raw(); | 2262 other_type_parameter ^= other.raw(); |
| 2259 return Index() == other_type_parameter.Index(); | 2263 return Index() == other_type_parameter.Index(); |
| 2260 } | 2264 } |
| 2261 | 2265 |
| 2262 | 2266 |
| 2263 void TypeParameter::set_index(intptr_t value) const { | 2267 void TypeParameter::set_index(intptr_t value) const { |
| 2264 ASSERT(value >= 0); | 2268 ASSERT(value >= 0); |
| 2265 raw_ptr()->index_ = value; | 2269 raw_ptr()->index_ = value; |
| 2266 } | 2270 } |
| 2267 | 2271 |
| 2268 | 2272 |
| 2269 void TypeParameter::set_name(const String& value) const { | 2273 void TypeParameter::set_name(const String& value) const { |
| 2270 ASSERT(value.IsSymbol()); | 2274 ASSERT(value.IsSymbol()); |
| 2271 StorePointer(&raw_ptr()->name_, value.raw()); | 2275 StorePointer(&raw_ptr()->name_, value.raw()); |
| 2272 } | 2276 } |
| 2273 | 2277 |
| 2274 | 2278 |
| 2275 RawAbstractType* TypeParameter::InstantiateFrom( | 2279 RawAbstractType* TypeParameter::InstantiateFrom( |
| 2276 const AbstractTypeArguments& instantiator_type_arguments, | 2280 const AbstractTypeArguments& instantiator_type_arguments) const { |
| 2277 intptr_t offset) const { | 2281 ASSERT(IsFinalized()); |
| 2278 if (instantiator_type_arguments.IsNull()) { | 2282 if (instantiator_type_arguments.IsNull()) { |
| 2279 return Type::DynamicType(); | 2283 return Type::DynamicType(); |
| 2280 } | 2284 } |
| 2281 return instantiator_type_arguments.TypeAt(Index() + offset); | 2285 return instantiator_type_arguments.TypeAt(Index()); |
| 2282 } | 2286 } |
| 2283 | 2287 |
| 2284 | 2288 |
| 2285 RawTypeParameter* TypeParameter::New() { | 2289 RawTypeParameter* TypeParameter::New() { |
| 2286 const Class& type_parameter_class = | 2290 const Class& type_parameter_class = |
| 2287 Class::Handle(Object::type_parameter_class()); | 2291 Class::Handle(Object::type_parameter_class()); |
| 2288 RawObject* raw = Object::Allocate(type_parameter_class, | 2292 RawObject* raw = Object::Allocate(type_parameter_class, |
| 2289 TypeParameter::InstanceSize(), | 2293 TypeParameter::InstanceSize(), |
| 2290 Heap::kOld); | 2294 Heap::kOld); |
| 2291 return reinterpret_cast<RawTypeParameter*>(raw); | 2295 return reinterpret_cast<RawTypeParameter*>(raw); |
| 2292 } | 2296 } |
| 2293 | 2297 |
| 2294 | 2298 |
| 2295 RawTypeParameter* TypeParameter::New(intptr_t index, const String& name) { | 2299 RawTypeParameter* TypeParameter::New(intptr_t index, const String& name) { |
| 2296 const TypeParameter& result = TypeParameter::Handle(TypeParameter::New()); | 2300 const TypeParameter& result = TypeParameter::Handle(TypeParameter::New()); |
| 2297 result.set_index(index); | 2301 result.set_index(index); |
| 2298 result.set_name(name); | 2302 result.set_name(name); |
| 2303 result.raw_ptr()->type_state_ = RawTypeParameter::kAllocated; |
| 2299 return result.raw(); | 2304 return result.raw(); |
| 2300 } | 2305 } |
| 2301 | 2306 |
| 2302 | 2307 |
| 2308 void TypeParameter::set_type_state(int8_t state) const { |
| 2309 ASSERT(state == RawTypeParameter::kAllocated || |
| 2310 state == RawTypeParameter::kBeingFinalized || |
| 2311 state == RawTypeParameter::kFinalized); |
| 2312 raw_ptr()->type_state_ = state; |
| 2313 } |
| 2314 |
| 2315 |
| 2303 const char* TypeParameter::ToCString() const { | 2316 const char* TypeParameter::ToCString() const { |
| 2304 const char* format = "TypeParameter: name %s; index: %d"; | 2317 const char* format = "TypeParameter: name %s; index: %d"; |
| 2305 const char* name_cstr = String::Handle(Name()).ToCString(); | 2318 const char* name_cstr = String::Handle(Name()).ToCString(); |
| 2306 intptr_t len = OS::SNPrint(NULL, 0, format, name_cstr, Index()) + 1; | 2319 intptr_t len = OS::SNPrint(NULL, 0, format, name_cstr, Index()) + 1; |
| 2307 char* chars = reinterpret_cast<char*>( | 2320 char* chars = reinterpret_cast<char*>( |
| 2308 Isolate::Current()->current_zone()->Allocate(len)); | 2321 Isolate::Current()->current_zone()->Allocate(len)); |
| 2309 OS::SNPrint(chars, len, format, name_cstr, Index()); | 2322 OS::SNPrint(chars, len, format, name_cstr, Index()); |
| 2310 return chars; | 2323 return chars; |
| 2311 } | 2324 } |
| 2312 | 2325 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2435 return other_arguments.IsDynamicTypes(other_arguments.Length()); | 2448 return other_arguments.IsDynamicTypes(other_arguments.Length()); |
| 2436 } | 2449 } |
| 2437 if (other_arguments.IsNull()) { | 2450 if (other_arguments.IsNull()) { |
| 2438 return arguments.IsDynamicTypes(arguments.Length()); | 2451 return arguments.IsDynamicTypes(arguments.Length()); |
| 2439 } | 2452 } |
| 2440 return arguments.Equals(other_arguments); | 2453 return arguments.Equals(other_arguments); |
| 2441 } | 2454 } |
| 2442 | 2455 |
| 2443 | 2456 |
| 2444 RawAbstractTypeArguments* AbstractTypeArguments::InstantiateFrom( | 2457 RawAbstractTypeArguments* AbstractTypeArguments::InstantiateFrom( |
| 2445 const AbstractTypeArguments& instantiator_type_arguments, | 2458 const AbstractTypeArguments& instantiator_type_arguments) const { |
| 2446 intptr_t offset) const { | |
| 2447 // AbstractTypeArguments is an abstract class. | 2459 // AbstractTypeArguments is an abstract class. |
| 2448 UNREACHABLE(); | 2460 UNREACHABLE(); |
| 2449 return NULL; | 2461 return NULL; |
| 2450 } | 2462 } |
| 2451 | 2463 |
| 2452 | 2464 |
| 2453 bool AbstractTypeArguments::IsDynamicTypes(intptr_t len) const { | 2465 bool AbstractTypeArguments::IsDynamicTypes(intptr_t len) const { |
| 2454 ASSERT(Length() >= len); | 2466 ASSERT(Length() >= len); |
| 2455 AbstractType& type = AbstractType::Handle(); | 2467 AbstractType& type = AbstractType::Handle(); |
| 2456 Class& type_class = Class::Handle(); | 2468 Class& type_class = Class::Handle(); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2551 type = TypeAt(i); | 2563 type = TypeAt(i); |
| 2552 if (!type.IsTypeParameter() || (type.Index() != i)) { | 2564 if (!type.IsTypeParameter() || (type.Index() != i)) { |
| 2553 return false; | 2565 return false; |
| 2554 } | 2566 } |
| 2555 } | 2567 } |
| 2556 return true; | 2568 return true; |
| 2557 } | 2569 } |
| 2558 | 2570 |
| 2559 | 2571 |
| 2560 RawAbstractTypeArguments* TypeArguments::InstantiateFrom( | 2572 RawAbstractTypeArguments* TypeArguments::InstantiateFrom( |
| 2561 const AbstractTypeArguments& instantiator_type_arguments, | 2573 const AbstractTypeArguments& instantiator_type_arguments) const { |
| 2562 intptr_t offset) const { | |
| 2563 ASSERT(!IsInstantiated()); | 2574 ASSERT(!IsInstantiated()); |
| 2564 if ((offset == 0) && | 2575 if (!instantiator_type_arguments.IsNull() && |
| 2565 !instantiator_type_arguments.IsNull() && | |
| 2566 IsUninstantiatedIdentity() && | 2576 IsUninstantiatedIdentity() && |
| 2567 (instantiator_type_arguments.Length() == Length())) { | 2577 (instantiator_type_arguments.Length() == Length())) { |
| 2568 return instantiator_type_arguments.raw(); | 2578 return instantiator_type_arguments.raw(); |
| 2569 } | 2579 } |
| 2570 const intptr_t num_types = Length(); | 2580 const intptr_t num_types = Length(); |
| 2571 TypeArguments& instantiated_array = | 2581 TypeArguments& instantiated_array = |
| 2572 TypeArguments::Handle(TypeArguments::New(num_types)); | 2582 TypeArguments::Handle(TypeArguments::New(num_types)); |
| 2573 AbstractType& type = AbstractType::Handle(); | 2583 AbstractType& type = AbstractType::Handle(); |
| 2574 for (intptr_t i = 0; i < num_types; i++) { | 2584 for (intptr_t i = 0; i < num_types; i++) { |
| 2575 type = TypeAt(i); | 2585 type = TypeAt(i); |
| 2576 if (!type.IsInstantiated()) { | 2586 if (!type.IsInstantiated()) { |
| 2577 type = type.InstantiateFrom(instantiator_type_arguments, offset); | 2587 type = type.InstantiateFrom(instantiator_type_arguments); |
| 2578 } | 2588 } |
| 2579 instantiated_array.SetTypeAt(i, type); | 2589 instantiated_array.SetTypeAt(i, type); |
| 2580 } | 2590 } |
| 2581 return instantiated_array.raw(); | 2591 return instantiated_array.raw(); |
| 2582 } | 2592 } |
| 2583 | 2593 |
| 2584 | 2594 |
| 2585 RawTypeArguments* TypeArguments::New(intptr_t len) { | 2595 RawTypeArguments* TypeArguments::New(intptr_t len) { |
| 2586 if ((len < 0) || (len > kMaxTypes)) { | 2596 if ((len < 0) || (len > kMaxTypes)) { |
| 2587 // TODO(iposva): Should we throw an illegal parameter exception? | 2597 // TODO(iposva): Should we throw an illegal parameter exception? |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3046 | 3056 |
| 3047 | 3057 |
| 3048 bool Function::TestParameterType( | 3058 bool Function::TestParameterType( |
| 3049 intptr_t parameter_position, | 3059 intptr_t parameter_position, |
| 3050 const AbstractTypeArguments& type_arguments, | 3060 const AbstractTypeArguments& type_arguments, |
| 3051 const Function& other, | 3061 const Function& other, |
| 3052 const AbstractTypeArguments& other_type_arguments) const { | 3062 const AbstractTypeArguments& other_type_arguments) const { |
| 3053 AbstractType& param_type = | 3063 AbstractType& param_type = |
| 3054 AbstractType::Handle(ParameterTypeAt(parameter_position)); | 3064 AbstractType::Handle(ParameterTypeAt(parameter_position)); |
| 3055 if (!param_type.IsInstantiated()) { | 3065 if (!param_type.IsInstantiated()) { |
| 3056 param_type = param_type.InstantiateFrom(type_arguments, 0); | 3066 param_type = param_type.InstantiateFrom(type_arguments); |
| 3057 } | 3067 } |
| 3058 if (param_type.IsDynamicType()) { | 3068 if (param_type.IsDynamicType()) { |
| 3059 return true; | 3069 return true; |
| 3060 } | 3070 } |
| 3061 AbstractType& other_param_type = | 3071 AbstractType& other_param_type = |
| 3062 AbstractType::Handle(other.ParameterTypeAt(parameter_position)); | 3072 AbstractType::Handle(other.ParameterTypeAt(parameter_position)); |
| 3063 if (!other_param_type.IsInstantiated()) { | 3073 if (!other_param_type.IsInstantiated()) { |
| 3064 other_param_type = | 3074 other_param_type = other_param_type.InstantiateFrom(other_type_arguments); |
| 3065 other_param_type.InstantiateFrom(other_type_arguments, 0); | |
| 3066 } | 3075 } |
| 3067 if (other_param_type.IsDynamicType()) { | 3076 if (other_param_type.IsDynamicType()) { |
| 3068 return true; | 3077 return true; |
| 3069 } | 3078 } |
| 3070 if (!param_type.IsSubtypeOf(other_param_type) && | 3079 if (!param_type.IsSubtypeOf(other_param_type) && |
| 3071 !other_param_type.IsSubtypeOf(param_type)) { | 3080 !other_param_type.IsSubtypeOf(param_type)) { |
| 3072 return false; | 3081 return false; |
| 3073 } | 3082 } |
| 3074 return true; | 3083 return true; |
| 3075 } | 3084 } |
| 3076 | 3085 |
| 3077 | 3086 |
| 3078 bool Function::TestType( | 3087 bool Function::TestType( |
| 3079 TypeTestKind test, | 3088 TypeTestKind test, |
| 3080 const AbstractTypeArguments& type_arguments, | 3089 const AbstractTypeArguments& type_arguments, |
| 3081 const Function& other, | 3090 const Function& other, |
| 3082 const AbstractTypeArguments& other_type_arguments) const { | 3091 const AbstractTypeArguments& other_type_arguments) const { |
| 3083 const intptr_t num_fixed_params = num_fixed_parameters(); | 3092 const intptr_t num_fixed_params = num_fixed_parameters(); |
| 3084 const intptr_t num_opt_params = num_optional_parameters(); | 3093 const intptr_t num_opt_params = num_optional_parameters(); |
| 3085 const intptr_t other_num_fixed_params = other.num_fixed_parameters(); | 3094 const intptr_t other_num_fixed_params = other.num_fixed_parameters(); |
| 3086 const intptr_t other_num_opt_params = other.num_optional_parameters(); | 3095 const intptr_t other_num_opt_params = other.num_optional_parameters(); |
| 3087 if ((num_fixed_params != other_num_fixed_params) || | 3096 if ((num_fixed_params != other_num_fixed_params) || |
| 3088 ((test == AbstractType::kIsSubtypeOf) && | 3097 ((test == AbstractType::kIsSubtypeOf) && |
| 3089 (num_opt_params < other_num_opt_params))) { | 3098 (num_opt_params < other_num_opt_params))) { |
| 3090 return false; | 3099 return false; |
| 3091 } | 3100 } |
| 3092 // Check the result type. | 3101 // Check the result type. |
| 3093 AbstractType& other_res_type = AbstractType::Handle(other.result_type()); | 3102 AbstractType& other_res_type = AbstractType::Handle(other.result_type()); |
| 3094 if (!other_res_type.IsInstantiated()) { | 3103 if (!other_res_type.IsInstantiated()) { |
| 3095 other_res_type = other_res_type.InstantiateFrom(other_type_arguments, 0); | 3104 other_res_type = other_res_type.InstantiateFrom(other_type_arguments); |
| 3096 } | 3105 } |
| 3097 if (!other_res_type.IsDynamicType() && !other_res_type.IsVoidType()) { | 3106 if (!other_res_type.IsDynamicType() && !other_res_type.IsVoidType()) { |
| 3098 AbstractType& res_type = AbstractType::Handle(result_type()); | 3107 AbstractType& res_type = AbstractType::Handle(result_type()); |
| 3099 if (!res_type.IsInstantiated()) { | 3108 if (!res_type.IsInstantiated()) { |
| 3100 res_type = res_type.InstantiateFrom(type_arguments, 0); | 3109 res_type = res_type.InstantiateFrom(type_arguments); |
| 3101 } | 3110 } |
| 3102 if (!res_type.IsDynamicType() && | 3111 if (!res_type.IsDynamicType() && |
| 3103 (res_type.IsVoidType() || | 3112 (res_type.IsVoidType() || |
| 3104 !(res_type.IsSubtypeOf(other_res_type) || | 3113 !(res_type.IsSubtypeOf(other_res_type) || |
| 3105 other_res_type.IsSubtypeOf(res_type)))) { | 3114 other_res_type.IsSubtypeOf(res_type)))) { |
| 3106 return false; | 3115 return false; |
| 3107 } | 3116 } |
| 3108 } | 3117 } |
| 3109 // Check the types of fixed parameters. | 3118 // Check the types of fixed parameters. |
| 3110 for (intptr_t i = 0; i < num_fixed_params; i++) { | 3119 for (intptr_t i = 0; i < num_fixed_params; i++) { |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3270 signature_class = Class::NewSignatureClass(signature, | 3279 signature_class = Class::NewSignatureClass(signature, |
| 3271 closure_function, | 3280 closure_function, |
| 3272 script); | 3281 script); |
| 3273 library.AddClass(signature_class); | 3282 library.AddClass(signature_class); |
| 3274 } else { | 3283 } else { |
| 3275 closure_function.set_signature_class(signature_class); | 3284 closure_function.set_signature_class(signature_class); |
| 3276 } | 3285 } |
| 3277 const Type& signature_type = Type::Handle(signature_class.SignatureType()); | 3286 const Type& signature_type = Type::Handle(signature_class.SignatureType()); |
| 3278 if (!signature_type.IsFinalized()) { | 3287 if (!signature_type.IsFinalized()) { |
| 3279 String& errmsg = String::Handle(); | 3288 String& errmsg = String::Handle(); |
| 3280 ClassFinalizer::FinalizeAndCanonicalizeType(signature_type, &errmsg); | 3289 ClassFinalizer::FinalizeAndCanonicalizeType(signature_class, |
| 3290 signature_type, |
| 3291 &errmsg); |
| 3281 ASSERT(errmsg.IsNull()); | 3292 ASSERT(errmsg.IsNull()); |
| 3282 } | 3293 } |
| 3283 ASSERT(closure_function.signature_class() == signature_class.raw()); | 3294 ASSERT(closure_function.signature_class() == signature_class.raw()); |
| 3284 set_implicit_closure_function(closure_function); | 3295 set_implicit_closure_function(closure_function); |
| 3285 ASSERT(closure_function.IsImplicitClosureFunction()); | 3296 ASSERT(closure_function.IsImplicitClosureFunction()); |
| 3286 return closure_function.raw(); | 3297 return closure_function.raw(); |
| 3287 } | 3298 } |
| 3288 | 3299 |
| 3289 | 3300 |
| 3290 template<typename T> | 3301 template<typename T> |
| 3291 static RawArray* NewArray(const GrowableArray<T*>& objs) { | 3302 static RawArray* NewArray(const GrowableArray<T*>& objs) { |
| 3292 Array& a = Array::Handle(Array::New(objs.length(), Heap::kOld)); | 3303 Array& a = Array::Handle(Array::New(objs.length(), Heap::kOld)); |
| 3293 for (int i = 0; i < objs.length(); i++) { | 3304 for (int i = 0; i < objs.length(); i++) { |
| 3294 a.SetAt(i, *objs[i]); | 3305 a.SetAt(i, *objs[i]); |
| 3295 } | 3306 } |
| 3296 return a.raw(); | 3307 return a.raw(); |
| 3297 } | 3308 } |
| 3298 | 3309 |
| 3299 | 3310 |
| 3300 RawString* Function::BuildSignature(bool instantiate, | 3311 RawString* Function::BuildSignature( |
| 3301 const AbstractTypeArguments& instantiator, | 3312 bool instantiate, |
| 3302 intptr_t offset) const { | 3313 const AbstractTypeArguments& instantiator) const { |
| 3303 GrowableArray<const String*> pieces; | 3314 GrowableArray<const String*> pieces; |
| 3304 const String& kCommaSpace = String::Handle(String::NewSymbol(", ")); | 3315 const String& kCommaSpace = String::Handle(String::NewSymbol(", ")); |
| 3305 const String& kColonSpace = String::Handle(String::NewSymbol(": ")); | 3316 const String& kColonSpace = String::Handle(String::NewSymbol(": ")); |
| 3306 const String& kLParen = String::Handle(String::NewSymbol("(")); | 3317 const String& kLParen = String::Handle(String::NewSymbol("(")); |
| 3307 const String& kRParen = String::Handle(String::NewSymbol(") => ")); | 3318 const String& kRParen = String::Handle(String::NewSymbol(") => ")); |
| 3308 const String& kLBracket = String::Handle(String::NewSymbol("[")); | 3319 const String& kLBracket = String::Handle(String::NewSymbol("[")); |
| 3309 const String& kRBracket = String::Handle(String::NewSymbol("]")); | 3320 const String& kRBracket = String::Handle(String::NewSymbol("]")); |
| 3310 if (!instantiate && !is_static()) { | 3321 if (!instantiate && !is_static()) { |
| 3311 const String& kSpaceExtendsSpace = | 3322 const String& kSpaceExtendsSpace = |
| 3312 String::Handle(String::NewSymbol(" extends ")); | 3323 String::Handle(String::NewSymbol(" extends ")); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 3341 AbstractType& param_type = AbstractType::Handle(); | 3352 AbstractType& param_type = AbstractType::Handle(); |
| 3342 const intptr_t num_params = NumberOfParameters(); | 3353 const intptr_t num_params = NumberOfParameters(); |
| 3343 const intptr_t num_fixed_params = num_fixed_parameters(); | 3354 const intptr_t num_fixed_params = num_fixed_parameters(); |
| 3344 const intptr_t num_opt_params = num_optional_parameters(); | 3355 const intptr_t num_opt_params = num_optional_parameters(); |
| 3345 ASSERT((num_fixed_params + num_opt_params) == num_params); | 3356 ASSERT((num_fixed_params + num_opt_params) == num_params); |
| 3346 pieces.Add(&kLParen); | 3357 pieces.Add(&kLParen); |
| 3347 for (intptr_t i = 0; i < num_fixed_params; i++) { | 3358 for (intptr_t i = 0; i < num_fixed_params; i++) { |
| 3348 param_type = ParameterTypeAt(i); | 3359 param_type = ParameterTypeAt(i); |
| 3349 ASSERT(!param_type.IsNull()); | 3360 ASSERT(!param_type.IsNull()); |
| 3350 if (instantiate && !param_type.IsInstantiated()) { | 3361 if (instantiate && !param_type.IsInstantiated()) { |
| 3351 param_type = param_type.InstantiateFrom(instantiator, offset); | 3362 param_type = param_type.InstantiateFrom(instantiator); |
| 3352 } | 3363 } |
| 3353 pieces.Add(&String::ZoneHandle(param_type.Name())); | 3364 pieces.Add(&String::ZoneHandle(param_type.Name())); |
| 3354 if (i != (num_params - 1)) { | 3365 if (i != (num_params - 1)) { |
| 3355 pieces.Add(&kCommaSpace); | 3366 pieces.Add(&kCommaSpace); |
| 3356 } | 3367 } |
| 3357 } | 3368 } |
| 3358 if (num_opt_params > 0) { | 3369 if (num_opt_params > 0) { |
| 3359 pieces.Add(&kLBracket); | 3370 pieces.Add(&kLBracket); |
| 3360 for (intptr_t i = num_fixed_params; i < num_params; i++) { | 3371 for (intptr_t i = num_fixed_params; i < num_params; i++) { |
| 3361 pieces.Add(&String::ZoneHandle(ParameterNameAt(i))); | 3372 pieces.Add(&String::ZoneHandle(ParameterNameAt(i))); |
| 3362 pieces.Add(&kColonSpace); | 3373 pieces.Add(&kColonSpace); |
| 3363 param_type = ParameterTypeAt(i); | 3374 param_type = ParameterTypeAt(i); |
| 3364 if (instantiate && !param_type.IsInstantiated()) { | 3375 if (instantiate && !param_type.IsInstantiated()) { |
| 3365 param_type = param_type.InstantiateFrom(instantiator, offset); | 3376 param_type = param_type.InstantiateFrom(instantiator); |
| 3366 } | 3377 } |
| 3367 ASSERT(!param_type.IsNull()); | 3378 ASSERT(!param_type.IsNull()); |
| 3368 pieces.Add(&String::ZoneHandle(param_type.Name())); | 3379 pieces.Add(&String::ZoneHandle(param_type.Name())); |
| 3369 if (i != (num_params - 1)) { | 3380 if (i != (num_params - 1)) { |
| 3370 pieces.Add(&kCommaSpace); | 3381 pieces.Add(&kCommaSpace); |
| 3371 } | 3382 } |
| 3372 } | 3383 } |
| 3373 pieces.Add(&kRBracket); | 3384 pieces.Add(&kRBracket); |
| 3374 } | 3385 } |
| 3375 pieces.Add(&kRParen); | 3386 pieces.Add(&kRParen); |
| 3376 AbstractType& res_type = AbstractType::Handle(result_type()); | 3387 AbstractType& res_type = AbstractType::Handle(result_type()); |
| 3377 if (instantiate && !res_type.IsInstantiated()) { | 3388 if (instantiate && !res_type.IsInstantiated()) { |
| 3378 res_type = res_type.InstantiateFrom(instantiator, offset); | 3389 res_type = res_type.InstantiateFrom(instantiator); |
| 3379 } | 3390 } |
| 3380 pieces.Add(&String::Handle(res_type.Name())); | 3391 pieces.Add(&String::Handle(res_type.Name())); |
| 3381 const Array& strings = Array::Handle(NewArray<const String>(pieces)); | 3392 const Array& strings = Array::Handle(NewArray<const String>(pieces)); |
| 3382 return String::NewSymbol(String::Handle(String::ConcatAll(strings))); | 3393 return String::NewSymbol(String::Handle(String::ConcatAll(strings))); |
| 3383 } | 3394 } |
| 3384 | 3395 |
| 3385 | 3396 |
| 3386 bool Function::HasInstantiatedSignature() const { | 3397 bool Function::HasInstantiatedSignature() const { |
| 3387 AbstractType& type = AbstractType::Handle(result_type()); | 3398 AbstractType& type = AbstractType::Handle(result_type()); |
| 3388 if (!type.IsInstantiated()) { | 3399 if (!type.IsInstantiated()) { |
| (...skipping 1728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5117 // defining the closure. Truncating the vector to the correct length on | 5128 // defining the closure. Truncating the vector to the correct length on |
| 5118 // instantiation is unnecessary. The vector may therefore be longer. | 5129 // instantiation is unnecessary. The vector may therefore be longer. |
| 5119 ASSERT(type_arguments.IsNull() || | 5130 ASSERT(type_arguments.IsNull() || |
| 5120 (type_arguments.Length() == num_type_arguments) || | 5131 (type_arguments.Length() == num_type_arguments) || |
| 5121 (cls.IsSignatureClass() && | 5132 (cls.IsSignatureClass() && |
| 5122 (type_arguments.Length() > num_type_arguments))); | 5133 (type_arguments.Length() > num_type_arguments))); |
| 5123 } | 5134 } |
| 5124 Class& other_class = Class::Handle(); | 5135 Class& other_class = Class::Handle(); |
| 5125 AbstractTypeArguments& other_type_arguments = AbstractTypeArguments::Handle(); | 5136 AbstractTypeArguments& other_type_arguments = AbstractTypeArguments::Handle(); |
| 5126 // In case 'other' is not instantiated, we could simply call | 5137 // In case 'other' is not instantiated, we could simply call |
| 5127 // other.InstantiateFrom(other_instantiator, 0), however, we can save the | 5138 // other.InstantiateFrom(other_instantiator), however, we can save the |
| 5128 // allocation of a new AbstractType by inlining the code. | 5139 // allocation of a new AbstractType by inlining the code. |
| 5129 if (other.IsTypeParameter()) { | 5140 if (other.IsTypeParameter()) { |
| 5130 AbstractType& instantiated_other = AbstractType::Handle(); | 5141 AbstractType& instantiated_other = AbstractType::Handle(); |
| 5131 if (!other_instantiator.IsNull()) { | 5142 if (!other_instantiator.IsNull()) { |
| 5132 instantiated_other = other_instantiator.TypeAt(other.Index()); | 5143 instantiated_other = other_instantiator.TypeAt(other.Index()); |
| 5133 ASSERT(instantiated_other.IsInstantiated()); | 5144 ASSERT(instantiated_other.IsInstantiated()); |
| 5134 } else { | 5145 } else { |
| 5135 instantiated_other = Type::DynamicType(); | 5146 instantiated_other = Type::DynamicType(); |
| 5136 } | 5147 } |
| 5137 other_class = instantiated_other.type_class(); | 5148 other_class = instantiated_other.type_class(); |
| 5138 other_type_arguments = instantiated_other.arguments(); | 5149 other_type_arguments = instantiated_other.arguments(); |
| 5139 } else { | 5150 } else { |
| 5140 other_class = other.type_class(); | 5151 other_class = other.type_class(); |
| 5141 other_type_arguments = other.arguments(); | 5152 other_type_arguments = other.arguments(); |
| 5142 if (!other_type_arguments.IsNull() && | 5153 if (!other_type_arguments.IsNull() && |
| 5143 !other_type_arguments.IsInstantiated()) { | 5154 !other_type_arguments.IsInstantiated()) { |
| 5144 other_type_arguments = | 5155 other_type_arguments = |
| 5145 other_type_arguments.InstantiateFrom(other_instantiator, 0); | 5156 other_type_arguments.InstantiateFrom(other_instantiator); |
| 5146 } | 5157 } |
| 5147 } | 5158 } |
| 5148 return cls.TestType(test, type_arguments, other_class, other_type_arguments); | 5159 return cls.TestType(test, type_arguments, other_class, other_type_arguments); |
| 5149 } | 5160 } |
| 5150 | 5161 |
| 5151 | 5162 |
| 5152 bool Instance::IsValidNativeIndex(int index) const { | 5163 bool Instance::IsValidNativeIndex(int index) const { |
| 5153 const Class& cls = Class::Handle(clazz()); | 5164 const Class& cls = Class::Handle(clazz()); |
| 5154 return (index >= 0 && index < cls.num_native_fields()); | 5165 return (index >= 0 && index < cls.num_native_fields()); |
| 5155 } | 5166 } |
| (...skipping 2165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7321 const String& str = String::Handle(pattern()); | 7332 const String& str = String::Handle(pattern()); |
| 7322 const char* format = "JSRegExp: pattern=%s flags=%s"; | 7333 const char* format = "JSRegExp: pattern=%s flags=%s"; |
| 7323 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); | 7334 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); |
| 7324 char* chars = reinterpret_cast<char*>( | 7335 char* chars = reinterpret_cast<char*>( |
| 7325 Isolate::Current()->current_zone()->Allocate(len + 1)); | 7336 Isolate::Current()->current_zone()->Allocate(len + 1)); |
| 7326 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); | 7337 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); |
| 7327 return chars; | 7338 return chars; |
| 7328 } | 7339 } |
| 7329 | 7340 |
| 7330 } // namespace dart | 7341 } // namespace dart |
| OLD | NEW |