Chromium Code Reviews| 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 980 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 991 } | 991 } |
| 992 | 992 |
| 993 | 993 |
| 994 void Class::set_signature_function(const Function& value) const { | 994 void Class::set_signature_function(const Function& value) const { |
| 995 ASSERT(value.IsClosureFunction() || value.IsSignatureFunction()); | 995 ASSERT(value.IsClosureFunction() || value.IsSignatureFunction()); |
| 996 StorePointer(&raw_ptr()->signature_function_, value.raw()); | 996 StorePointer(&raw_ptr()->signature_function_, value.raw()); |
| 997 } | 997 } |
| 998 | 998 |
| 999 | 999 |
| 1000 void Class::set_class_state(int8_t state) const { | 1000 void Class::set_class_state(int8_t state) const { |
| 1001 ASSERT(state == RawClass::kAllocated || | 1001 ASSERT((state == RawClass::kAllocated) || |
| 1002 state == RawClass::kPreFinalized || | 1002 (state == RawClass::kPreFinalized) || |
| 1003 state == RawClass::kFinalized); | 1003 (state == RawClass::kFinalized)); |
| 1004 raw_ptr()->class_state_ = state; | 1004 raw_ptr()->class_state_ = state; |
| 1005 } | 1005 } |
| 1006 | 1006 |
| 1007 | 1007 |
| 1008 void Class::set_library(const Library& value) const { | 1008 void Class::set_library(const Library& value) const { |
| 1009 StorePointer(&raw_ptr()->library_, value.raw()); | 1009 StorePointer(&raw_ptr()->library_, value.raw()); |
| 1010 } | 1010 } |
| 1011 | 1011 |
| 1012 | 1012 |
| 1013 void Class::set_type_parameters(const TypeArguments& value) const { | 1013 void Class::set_type_parameters(const TypeArguments& value) const { |
| (...skipping 1252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2266 | 2266 |
| 2267 | 2267 |
| 2268 RawType* Type::NewNonParameterizedType( | 2268 RawType* Type::NewNonParameterizedType( |
| 2269 const Class& type_class) { | 2269 const Class& type_class) { |
| 2270 ASSERT(!type_class.HasTypeArguments()); | 2270 ASSERT(!type_class.HasTypeArguments()); |
| 2271 const TypeArguments& no_type_arguments = TypeArguments::Handle(); | 2271 const TypeArguments& no_type_arguments = TypeArguments::Handle(); |
| 2272 Type& type = Type::Handle(); | 2272 Type& type = Type::Handle(); |
| 2273 type ^= Type::New(Object::Handle(type_class.raw()), | 2273 type ^= Type::New(Object::Handle(type_class.raw()), |
| 2274 no_type_arguments, | 2274 no_type_arguments, |
| 2275 Scanner::kDummyTokenIndex); | 2275 Scanner::kDummyTokenIndex); |
| 2276 type.set_is_finalized(); | 2276 type.set_is_finalized_instantiated(); |
| 2277 type ^= type.Canonicalize(); | 2277 type ^= type.Canonicalize(); |
| 2278 return type.raw(); | 2278 return type.raw(); |
| 2279 } | 2279 } |
| 2280 | 2280 |
| 2281 | 2281 |
| 2282 void Type::set_is_finalized() const { | 2282 void Type::set_is_finalized_instantiated() const { |
| 2283 ASSERT(!IsFinalized()); | 2283 ASSERT(!IsFinalized()); |
| 2284 set_type_state(RawType::kFinalized); | 2284 set_type_state(RawType::kFinalizedInstantiated); |
| 2285 } | |
| 2286 | |
| 2287 | |
| 2288 void Type::set_is_finalized_uninstantiated() const { | |
| 2289 ASSERT(!IsFinalized()); | |
| 2290 set_type_state(RawType::kFinalizedUninstantiated); | |
| 2285 } | 2291 } |
| 2286 | 2292 |
| 2287 | 2293 |
| 2288 void Type::set_is_being_finalized() const { | 2294 void Type::set_is_being_finalized() const { |
| 2289 ASSERT(!IsFinalized() && !IsBeingFinalized()); | 2295 ASSERT(!IsFinalized() && !IsBeingFinalized()); |
| 2290 set_type_state(RawType::kBeingFinalized); | 2296 set_type_state(RawType::kBeingFinalized); |
| 2291 } | 2297 } |
| 2292 | 2298 |
| 2293 | 2299 |
| 2294 bool Type::IsMalformed() const { | 2300 bool Type::IsMalformed() const { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2353 } | 2359 } |
| 2354 } | 2360 } |
| 2355 | 2361 |
| 2356 | 2362 |
| 2357 RawAbstractTypeArguments* Type::arguments() const { | 2363 RawAbstractTypeArguments* Type::arguments() const { |
| 2358 return raw_ptr()->arguments_; | 2364 return raw_ptr()->arguments_; |
| 2359 } | 2365 } |
| 2360 | 2366 |
| 2361 | 2367 |
| 2362 bool Type::IsInstantiated() const { | 2368 bool Type::IsInstantiated() const { |
| 2369 if (raw_ptr()->type_state_ == RawType::kFinalizedInstantiated) { | |
| 2370 return true; | |
| 2371 } | |
| 2372 if (raw_ptr()->type_state_ == RawType::kFinalizedUninstantiated) { | |
| 2373 return false; | |
| 2374 } | |
| 2363 const AbstractTypeArguments& args = | 2375 const AbstractTypeArguments& args = |
|
srdjan
2012/04/24 00:56:28
Can IsInstantiated be true if the type is not fina
regis
2012/04/24 16:06:58
Yes. We call IsInstantiated() on a type before mar
| |
| 2364 AbstractTypeArguments::Handle(arguments()); | 2376 AbstractTypeArguments::Handle(arguments()); |
| 2365 return args.IsNull() || args.IsInstantiated(); | 2377 return args.IsNull() || args.IsInstantiated(); |
| 2366 } | 2378 } |
| 2367 | 2379 |
| 2368 | 2380 |
| 2369 RawAbstractType* Type::InstantiateFrom( | 2381 RawAbstractType* Type::InstantiateFrom( |
| 2370 const AbstractTypeArguments& instantiator_type_arguments) const { | 2382 const AbstractTypeArguments& instantiator_type_arguments) const { |
| 2371 ASSERT(IsFinalized()); | 2383 ASSERT(IsFinalized()); |
| 2372 ASSERT(!IsInstantiated()); | 2384 ASSERT(!IsInstantiated()); |
| 2373 AbstractTypeArguments& type_arguments = | 2385 AbstractTypeArguments& type_arguments = |
| 2374 AbstractTypeArguments::Handle(arguments()); | 2386 AbstractTypeArguments::Handle(arguments()); |
| 2375 type_arguments = type_arguments.InstantiateFrom(instantiator_type_arguments); | 2387 type_arguments = type_arguments.InstantiateFrom(instantiator_type_arguments); |
| 2376 const Class& cls = Class::Handle(type_class()); | 2388 const Class& cls = Class::Handle(type_class()); |
| 2377 ASSERT(cls.is_finalized()); | 2389 ASSERT(cls.is_finalized()); |
| 2378 Type& instantiated_type = Type::Handle( | 2390 Type& instantiated_type = Type::Handle( |
| 2379 Type::New(cls, type_arguments, token_index())); | 2391 Type::New(cls, type_arguments, token_index())); |
| 2380 ASSERT(type_arguments.IsNull() || | 2392 ASSERT(type_arguments.IsNull() || |
| 2381 (type_arguments.Length() == cls.NumTypeArguments())); | 2393 (type_arguments.Length() == cls.NumTypeArguments())); |
| 2382 instantiated_type.set_is_finalized(); | 2394 instantiated_type.set_is_finalized_instantiated(); |
| 2383 return instantiated_type.raw(); | 2395 return instantiated_type.raw(); |
| 2384 } | 2396 } |
| 2385 | 2397 |
| 2386 | 2398 |
| 2387 bool Type::Equals(const AbstractType& other) const { | 2399 bool Type::Equals(const AbstractType& other) const { |
| 2388 ASSERT(IsFinalized() && other.IsFinalized()); | 2400 ASSERT(IsFinalized() && other.IsFinalized()); |
| 2389 if (raw() == other.raw()) { | 2401 if (raw() == other.raw()) { |
| 2390 return true; | 2402 return true; |
| 2391 } | 2403 } |
| 2392 if (IsMalformed() || !other.IsType() || other.IsMalformed()) { | 2404 if (IsMalformed() || !other.IsType() || other.IsMalformed()) { |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2504 } | 2516 } |
| 2505 | 2517 |
| 2506 | 2518 |
| 2507 void Type::set_token_index(intptr_t token_index) const { | 2519 void Type::set_token_index(intptr_t token_index) const { |
| 2508 ASSERT(token_index >= 0); | 2520 ASSERT(token_index >= 0); |
| 2509 raw_ptr()->token_index_ = token_index; | 2521 raw_ptr()->token_index_ = token_index; |
| 2510 } | 2522 } |
| 2511 | 2523 |
| 2512 | 2524 |
| 2513 void Type::set_type_state(int8_t state) const { | 2525 void Type::set_type_state(int8_t state) const { |
| 2514 ASSERT(state == RawType::kAllocated || | 2526 ASSERT((state == RawType::kAllocated) || |
| 2515 state == RawType::kBeingFinalized || | 2527 (state == RawType::kBeingFinalized) || |
| 2516 state == RawType::kFinalized); | 2528 (state == RawType::kFinalizedInstantiated) || |
| 2529 (state == RawType::kFinalizedUninstantiated)); | |
| 2517 raw_ptr()->type_state_ = state; | 2530 raw_ptr()->type_state_ = state; |
| 2518 } | 2531 } |
| 2519 | 2532 |
| 2520 | 2533 |
| 2521 const char* Type::ToCString() const { | 2534 const char* Type::ToCString() const { |
| 2522 if (IsResolved()) { | 2535 if (IsResolved()) { |
| 2523 const AbstractTypeArguments& type_arguments = | 2536 const AbstractTypeArguments& type_arguments = |
| 2524 AbstractTypeArguments::Handle(arguments()); | 2537 AbstractTypeArguments::Handle(arguments()); |
| 2525 if (type_arguments.IsNull()) { | 2538 if (type_arguments.IsNull()) { |
| 2526 const char* format = "Type: class '%s'"; | 2539 const char* format = "Type: class '%s'"; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 2544 return chars; | 2557 return chars; |
| 2545 } | 2558 } |
| 2546 } else { | 2559 } else { |
| 2547 return "Unresolved Type"; | 2560 return "Unresolved Type"; |
| 2548 } | 2561 } |
| 2549 } | 2562 } |
| 2550 | 2563 |
| 2551 | 2564 |
| 2552 void TypeParameter::set_is_finalized() const { | 2565 void TypeParameter::set_is_finalized() const { |
| 2553 ASSERT(!IsFinalized()); | 2566 ASSERT(!IsFinalized()); |
| 2554 set_type_state(RawTypeParameter::kFinalized); | 2567 set_type_state(RawTypeParameter::kFinalizedUninstantiated); |
| 2555 // Field parameterized_class_ is not needed after finalization anymore. | 2568 // Field parameterized_class_ is not needed after finalization anymore. |
| 2556 set_parameterized_class(Class::Handle()); | 2569 set_parameterized_class(Class::Handle()); |
| 2557 } | 2570 } |
| 2558 | 2571 |
| 2559 | 2572 |
| 2560 bool TypeParameter::Equals(const AbstractType& other) const { | 2573 bool TypeParameter::Equals(const AbstractType& other) const { |
| 2561 if (raw() == other.raw()) { | 2574 if (raw() == other.raw()) { |
| 2562 return true; | 2575 return true; |
| 2563 } | 2576 } |
| 2564 if (!other.IsTypeParameter()) { | 2577 if (!other.IsTypeParameter()) { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2650 } | 2663 } |
| 2651 | 2664 |
| 2652 | 2665 |
| 2653 void TypeParameter::set_token_index(intptr_t token_index) const { | 2666 void TypeParameter::set_token_index(intptr_t token_index) const { |
| 2654 ASSERT(token_index >= 0); | 2667 ASSERT(token_index >= 0); |
| 2655 raw_ptr()->token_index_ = token_index; | 2668 raw_ptr()->token_index_ = token_index; |
| 2656 } | 2669 } |
| 2657 | 2670 |
| 2658 | 2671 |
| 2659 void TypeParameter::set_type_state(int8_t state) const { | 2672 void TypeParameter::set_type_state(int8_t state) const { |
| 2660 ASSERT(state == RawTypeParameter::kAllocated || | 2673 ASSERT((state == RawTypeParameter::kAllocated) || |
| 2661 state == RawTypeParameter::kBeingFinalized || | 2674 (state == RawTypeParameter::kBeingFinalized) || |
| 2662 state == RawTypeParameter::kFinalized); | 2675 (state == RawTypeParameter::kFinalizedUninstantiated)); |
| 2663 raw_ptr()->type_state_ = state; | 2676 raw_ptr()->type_state_ = state; |
| 2664 } | 2677 } |
| 2665 | 2678 |
| 2666 | 2679 |
| 2667 const char* TypeParameter::ToCString() const { | 2680 const char* TypeParameter::ToCString() const { |
| 2668 const char* format = "TypeParameter: name %s; index: %d"; | 2681 const char* format = "TypeParameter: name %s; index: %d"; |
| 2669 const char* name_cstr = String::Handle(Name()).ToCString(); | 2682 const char* name_cstr = String::Handle(Name()).ToCString(); |
| 2670 intptr_t len = OS::SNPrint(NULL, 0, format, name_cstr, Index()) + 1; | 2683 intptr_t len = OS::SNPrint(NULL, 0, format, name_cstr, Index()) + 1; |
| 2671 char* chars = reinterpret_cast<char*>( | 2684 char* chars = reinterpret_cast<char*>( |
| 2672 Isolate::Current()->current_zone()->Allocate(len)); | 2685 Isolate::Current()->current_zone()->Allocate(len)); |
| (...skipping 3873 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6546 if (IsNull()) { | 6559 if (IsNull()) { |
| 6547 return Type::NullType(); | 6560 return Type::NullType(); |
| 6548 } | 6561 } |
| 6549 const Class& cls = Class::Handle(clazz()); | 6562 const Class& cls = Class::Handle(clazz()); |
| 6550 AbstractTypeArguments& type_arguments = AbstractTypeArguments::Handle(); | 6563 AbstractTypeArguments& type_arguments = AbstractTypeArguments::Handle(); |
| 6551 if (cls.HasTypeArguments()) { | 6564 if (cls.HasTypeArguments()) { |
| 6552 type_arguments = GetTypeArguments(); | 6565 type_arguments = GetTypeArguments(); |
| 6553 } | 6566 } |
| 6554 const Type& type = Type::Handle( | 6567 const Type& type = Type::Handle( |
| 6555 Type::New(cls, type_arguments, Scanner::kDummyTokenIndex)); | 6568 Type::New(cls, type_arguments, Scanner::kDummyTokenIndex)); |
| 6556 type.set_is_finalized(); | 6569 type.set_is_finalized_instantiated(); |
| 6557 return type.raw(); | 6570 return type.raw(); |
| 6558 } | 6571 } |
| 6559 | 6572 |
| 6560 | 6573 |
| 6561 RawAbstractTypeArguments* Instance::GetTypeArguments() const { | 6574 RawAbstractTypeArguments* Instance::GetTypeArguments() const { |
| 6562 const Class& cls = Class::Handle(clazz()); | 6575 const Class& cls = Class::Handle(clazz()); |
| 6563 intptr_t field_offset = cls.type_arguments_instance_field_offset(); | 6576 intptr_t field_offset = cls.type_arguments_instance_field_offset(); |
| 6564 ASSERT(field_offset != Class::kNoTypeArguments); | 6577 ASSERT(field_offset != Class::kNoTypeArguments); |
| 6565 AbstractTypeArguments& type_arguments = AbstractTypeArguments::Handle(); | 6578 AbstractTypeArguments& type_arguments = AbstractTypeArguments::Handle(); |
| 6566 type_arguments ^= *FieldAddrAtOffset(field_offset); | 6579 type_arguments ^= *FieldAddrAtOffset(field_offset); |
| (...skipping 2653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9220 const String& str = String::Handle(pattern()); | 9233 const String& str = String::Handle(pattern()); |
| 9221 const char* format = "JSRegExp: pattern=%s flags=%s"; | 9234 const char* format = "JSRegExp: pattern=%s flags=%s"; |
| 9222 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); | 9235 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); |
| 9223 char* chars = reinterpret_cast<char*>( | 9236 char* chars = reinterpret_cast<char*>( |
| 9224 Isolate::Current()->current_zone()->Allocate(len + 1)); | 9237 Isolate::Current()->current_zone()->Allocate(len + 1)); |
| 9225 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); | 9238 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); |
| 9226 return chars; | 9239 return chars; |
| 9227 } | 9240 } |
| 9228 | 9241 |
| 9229 } // namespace dart | 9242 } // namespace dart |
| OLD | NEW |