| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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/class_finalizer.h" | 5 #include "vm/class_finalizer.h" |
| 6 | 6 |
| 7 #include "vm/code_generator.h" | 7 #include "vm/code_generator.h" |
| 8 #include "vm/flags.h" | 8 #include "vm/flags.h" |
| 9 #include "vm/heap.h" | 9 #include "vm/heap.h" |
| 10 #include "vm/isolate.h" | 10 #include "vm/isolate.h" |
| (...skipping 2460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2471 ASSERT(!index_field.IsNull()); | 2471 ASSERT(!index_field.IsNull()); |
| 2472 const Field& name_field = Field::Handle( | 2472 const Field& name_field = Field::Handle( |
| 2473 zone, enum_cls.LookupInstanceFieldAllowPrivate(Symbols::_name())); | 2473 zone, enum_cls.LookupInstanceFieldAllowPrivate(Symbols::_name())); |
| 2474 ASSERT(!name_field.IsNull()); | 2474 ASSERT(!name_field.IsNull()); |
| 2475 const Field& values_field = | 2475 const Field& values_field = |
| 2476 Field::Handle(zone, enum_cls.LookupStaticField(Symbols::Values())); | 2476 Field::Handle(zone, enum_cls.LookupStaticField(Symbols::Values())); |
| 2477 ASSERT(!values_field.IsNull()); | 2477 ASSERT(!values_field.IsNull()); |
| 2478 ASSERT(Instance::Handle(zone, values_field.StaticValue()).IsArray()); | 2478 ASSERT(Instance::Handle(zone, values_field.StaticValue()).IsArray()); |
| 2479 Array& values_list = | 2479 Array& values_list = |
| 2480 Array::Handle(zone, Array::RawCast(values_field.StaticValue())); | 2480 Array::Handle(zone, Array::RawCast(values_field.StaticValue())); |
| 2481 const String& enum_name = String::Handle(enum_cls.ScrubbedName()); |
| 2482 const String& name_prefix = |
| 2483 String::Handle(String::Concat(enum_name, Symbols::Dot())); |
| 2481 | 2484 |
| 2482 const Array& fields = Array::Handle(zone, enum_cls.fields()); | |
| 2483 Field& field = Field::Handle(zone); | 2485 Field& field = Field::Handle(zone); |
| 2484 Instance& ordinal_value = Instance::Handle(zone); | 2486 Instance& ordinal_value = Instance::Handle(zone); |
| 2485 Instance& enum_value = Instance::Handle(zone); | 2487 Instance& enum_value = Instance::Handle(zone); |
| 2486 | 2488 |
| 2487 const String& enum_name = String::Handle(enum_cls.ScrubbedName()); | 2489 String& enum_ident = String::Handle(); |
| 2488 const String& name_prefix = | |
| 2489 String::Handle(String::Concat(enum_name, Symbols::Dot())); | |
| 2490 | 2490 |
| 2491 String& enum_ident = String::Handle(); | 2491 enum_ident = |
| 2492 Symbols::FromConcat(thread, Symbols::_DeletedEnumPrefix(), enum_name); |
| 2493 enum_value = Instance::New(enum_cls, Heap::kOld); |
| 2494 enum_value.SetField(index_field, Smi::Handle(zone, Smi::New(-1))); |
| 2495 enum_value.SetField(name_field, enum_ident); |
| 2496 const char* error_msg = NULL; |
| 2497 enum_value = enum_value.CheckAndCanonicalize(thread, &error_msg); |
| 2498 ASSERT(!enum_value.IsNull()); |
| 2499 ASSERT(enum_value.IsCanonical()); |
| 2500 field = enum_cls.LookupStaticField(Symbols::_DeletedEnumSentinel()); |
| 2501 ASSERT(!field.IsNull()); |
| 2502 field.SetStaticValue(enum_value, true); |
| 2503 field.RecordStore(enum_value); |
| 2504 |
| 2505 const Array& fields = Array::Handle(zone, enum_cls.fields()); |
| 2492 for (intptr_t i = 0; i < fields.Length(); i++) { | 2506 for (intptr_t i = 0; i < fields.Length(); i++) { |
| 2493 field = Field::RawCast(fields.At(i)); | 2507 field = Field::RawCast(fields.At(i)); |
| 2494 if (!field.is_static()) continue; | 2508 if (!field.is_static()) continue; |
| 2495 ordinal_value = field.StaticValue(); | 2509 ordinal_value = field.StaticValue(); |
| 2496 // The static fields that need to be initialized with enum instances | 2510 // The static fields that need to be initialized with enum instances |
| 2497 // contain the smi value of the ordinal number, which was stored in | 2511 // contain the smi value of the ordinal number, which was stored in |
| 2498 // the field by the parser. Other fields contain non-smi values. | 2512 // the field by the parser. Other fields contain non-smi values. |
| 2499 if (!ordinal_value.IsSmi()) continue; | 2513 if (!ordinal_value.IsSmi()) continue; |
| 2500 enum_ident = field.name(); | 2514 enum_ident = field.name(); |
| 2501 // Construct the string returned by toString. | 2515 // Construct the string returned by toString. |
| 2502 ASSERT(!enum_ident.IsNull()); | 2516 ASSERT(!enum_ident.IsNull()); |
| 2503 // For the user-visible name of the enumeration value, we need to | 2517 // For the user-visible name of the enumeration value, we need to |
| 2504 // unmangle private names. | 2518 // unmangle private names. |
| 2505 if (enum_ident.CharAt(0) == '_') { | 2519 if (enum_ident.CharAt(0) == '_') { |
| 2506 enum_ident = String::ScrubName(enum_ident); | 2520 enum_ident = String::ScrubName(enum_ident); |
| 2507 } | 2521 } |
| 2508 enum_ident = Symbols::FromConcat(thread, name_prefix, enum_ident); | 2522 enum_ident = Symbols::FromConcat(thread, name_prefix, enum_ident); |
| 2509 enum_value = Instance::New(enum_cls, Heap::kOld); | 2523 enum_value = Instance::New(enum_cls, Heap::kOld); |
| 2510 enum_value.SetField(index_field, ordinal_value); | 2524 enum_value.SetField(index_field, ordinal_value); |
| 2511 enum_value.SetField(name_field, enum_ident); | 2525 enum_value.SetField(name_field, enum_ident); |
| 2512 const char* error_msg = ""; | |
| 2513 enum_value = enum_value.CheckAndCanonicalize(thread, &error_msg); | 2526 enum_value = enum_value.CheckAndCanonicalize(thread, &error_msg); |
| 2514 ASSERT(!enum_value.IsNull()); | 2527 ASSERT(!enum_value.IsNull()); |
| 2515 ASSERT(enum_value.IsCanonical()); | 2528 ASSERT(enum_value.IsCanonical()); |
| 2516 field.SetStaticValue(enum_value, true); | 2529 field.SetStaticValue(enum_value, true); |
| 2517 field.RecordStore(enum_value); | 2530 field.RecordStore(enum_value); |
| 2518 intptr_t ord = Smi::Cast(ordinal_value).Value(); | 2531 intptr_t ord = Smi::Cast(ordinal_value).Value(); |
| 2519 ASSERT(ord < values_list.Length()); | 2532 ASSERT(ord < values_list.Length()); |
| 2520 values_list.SetAt(ord, enum_value); | 2533 values_list.SetAt(ord, enum_value); |
| 2521 } | 2534 } |
| 2522 values_list.MakeImmutable(); | 2535 values_list.MakeImmutable(); |
| 2523 const char* error_msg = NULL; | |
| 2524 values_list ^= values_list.CheckAndCanonicalize(thread, &error_msg); | 2536 values_list ^= values_list.CheckAndCanonicalize(thread, &error_msg); |
| 2525 ASSERT(!values_list.IsNull()); | 2537 ASSERT(!values_list.IsNull()); |
| 2526 } | 2538 } |
| 2527 | 2539 |
| 2528 | 2540 |
| 2529 bool ClassFinalizer::IsSuperCycleFree(const Class& cls) { | 2541 bool ClassFinalizer::IsSuperCycleFree(const Class& cls) { |
| 2530 Class& test1 = Class::Handle(cls.raw()); | 2542 Class& test1 = Class::Handle(cls.raw()); |
| 2531 Class& test2 = Class::Handle(cls.SuperClass()); | 2543 Class& test2 = Class::Handle(cls.SuperClass()); |
| 2532 // A finalized class has been checked for cycles. | 2544 // A finalized class has been checked for cycles. |
| 2533 // Using the hare and tortoise algorithm for locating cycles. | 2545 // Using the hare and tortoise algorithm for locating cycles. |
| (...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3267 ASSERT(fields_array.Length() == ByteBuffer::NumberOfFields()); | 3279 ASSERT(fields_array.Length() == ByteBuffer::NumberOfFields()); |
| 3268 field ^= fields_array.At(0); | 3280 field ^= fields_array.At(0); |
| 3269 ASSERT(field.Offset() == ByteBuffer::data_offset()); | 3281 ASSERT(field.Offset() == ByteBuffer::data_offset()); |
| 3270 name ^= field.name(); | 3282 name ^= field.name(); |
| 3271 expected_name ^= String::New("_data"); | 3283 expected_name ^= String::New("_data"); |
| 3272 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name)); | 3284 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name)); |
| 3273 #endif | 3285 #endif |
| 3274 } | 3286 } |
| 3275 | 3287 |
| 3276 } // namespace dart | 3288 } // namespace dart |
| OLD | NEW |