Chromium Code Reviews| 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())); | |
| 2484 | |
| 2485 const String& deleted_enum_senintel_name = String::Handle( | |
| 2486 zone, | |
| 2487 Symbols::FromConcat(thread, Symbols::_DeletedEnumPrefix(), enum_name)); | |
| 2488 Instance& deleted_enum_sentinel_value = | |
| 2489 Instance::Handle(zone, Instance::New(enum_cls, Heap::kOld)); | |
| 2490 deleted_enum_sentinel_value.SetField(index_field, | |
| 2491 Smi::Handle(zone, Smi::New(-1))); | |
| 2492 deleted_enum_sentinel_value.SetField(name_field, deleted_enum_senintel_name); | |
| 2493 const char* error_msg = NULL; | |
| 2494 deleted_enum_sentinel_value = | |
| 2495 deleted_enum_sentinel_value.CheckAndCanonicalize(thread, &error_msg); | |
| 2496 ASSERT(!deleted_enum_sentinel_value.IsNull()); | |
| 2497 ASSERT(deleted_enum_sentinel_value.IsCanonical()); | |
| 2498 const Field& deleted_enum_field = Field::Handle( | |
| 2499 zone, enum_cls.LookupStaticField(Symbols::_DeletedEnumSentinel())); | |
| 2500 ASSERT(!deleted_enum_field.IsNull()); | |
| 2501 deleted_enum_field.SetStaticValue(deleted_enum_sentinel_value, true); | |
| 2502 deleted_enum_field.RecordStore(deleted_enum_sentinel_value); | |
| 2481 | 2503 |
| 2482 const Array& fields = Array::Handle(zone, enum_cls.fields()); | 2504 const Array& fields = Array::Handle(zone, enum_cls.fields()); |
| 2483 Field& field = Field::Handle(zone); | 2505 Field& field = Field::Handle(zone); |
| 2484 Instance& ordinal_value = Instance::Handle(zone); | 2506 Instance& ordinal_value = Instance::Handle(zone); |
| 2485 Instance& enum_value = Instance::Handle(zone); | 2507 Instance& enum_value = Instance::Handle(zone); |
| 2486 | 2508 |
| 2487 const String& enum_name = String::Handle(enum_cls.ScrubbedName()); | |
| 2488 const String& name_prefix = | |
| 2489 String::Handle(String::Concat(enum_name, Symbols::Dot())); | |
| 2490 | |
| 2491 String& enum_ident = String::Handle(); | 2509 String& enum_ident = String::Handle(); |
|
siva
2016/11/14 22:18:23
A samll nit, the same handles created here field,
Cutch
2016/11/15 22:13:55
Done.
| |
| 2492 for (intptr_t i = 0; i < fields.Length(); i++) { | 2510 for (intptr_t i = 0; i < fields.Length(); i++) { |
| 2493 field = Field::RawCast(fields.At(i)); | 2511 field = Field::RawCast(fields.At(i)); |
| 2494 if (!field.is_static()) continue; | 2512 if (!field.is_static()) continue; |
| 2495 ordinal_value = field.StaticValue(); | 2513 ordinal_value = field.StaticValue(); |
| 2496 // The static fields that need to be initialized with enum instances | 2514 // The static fields that need to be initialized with enum instances |
| 2497 // contain the smi value of the ordinal number, which was stored in | 2515 // contain the smi value of the ordinal number, which was stored in |
| 2498 // the field by the parser. Other fields contain non-smi values. | 2516 // the field by the parser. Other fields contain non-smi values. |
| 2499 if (!ordinal_value.IsSmi()) continue; | 2517 if (!ordinal_value.IsSmi()) continue; |
| 2500 enum_ident = field.name(); | 2518 enum_ident = field.name(); |
| 2501 // Construct the string returned by toString. | 2519 // Construct the string returned by toString. |
| 2502 ASSERT(!enum_ident.IsNull()); | 2520 ASSERT(!enum_ident.IsNull()); |
| 2503 // For the user-visible name of the enumeration value, we need to | 2521 // For the user-visible name of the enumeration value, we need to |
| 2504 // unmangle private names. | 2522 // unmangle private names. |
| 2505 if (enum_ident.CharAt(0) == '_') { | 2523 if (enum_ident.CharAt(0) == '_') { |
| 2506 enum_ident = String::ScrubName(enum_ident); | 2524 enum_ident = String::ScrubName(enum_ident); |
| 2507 } | 2525 } |
| 2508 enum_ident = Symbols::FromConcat(thread, name_prefix, enum_ident); | 2526 enum_ident = Symbols::FromConcat(thread, name_prefix, enum_ident); |
| 2509 enum_value = Instance::New(enum_cls, Heap::kOld); | 2527 enum_value = Instance::New(enum_cls, Heap::kOld); |
| 2510 enum_value.SetField(index_field, ordinal_value); | 2528 enum_value.SetField(index_field, ordinal_value); |
| 2511 enum_value.SetField(name_field, enum_ident); | 2529 enum_value.SetField(name_field, enum_ident); |
| 2512 const char* error_msg = ""; | |
| 2513 enum_value = enum_value.CheckAndCanonicalize(thread, &error_msg); | 2530 enum_value = enum_value.CheckAndCanonicalize(thread, &error_msg); |
| 2514 ASSERT(!enum_value.IsNull()); | 2531 ASSERT(!enum_value.IsNull()); |
| 2515 ASSERT(enum_value.IsCanonical()); | 2532 ASSERT(enum_value.IsCanonical()); |
| 2516 field.SetStaticValue(enum_value, true); | 2533 field.SetStaticValue(enum_value, true); |
| 2517 field.RecordStore(enum_value); | 2534 field.RecordStore(enum_value); |
| 2518 intptr_t ord = Smi::Cast(ordinal_value).Value(); | 2535 intptr_t ord = Smi::Cast(ordinal_value).Value(); |
| 2519 ASSERT(ord < values_list.Length()); | 2536 ASSERT(ord < values_list.Length()); |
| 2520 values_list.SetAt(ord, enum_value); | 2537 values_list.SetAt(ord, enum_value); |
| 2521 } | 2538 } |
| 2522 values_list.MakeImmutable(); | 2539 values_list.MakeImmutable(); |
| 2523 const char* error_msg = NULL; | |
| 2524 values_list ^= values_list.CheckAndCanonicalize(thread, &error_msg); | 2540 values_list ^= values_list.CheckAndCanonicalize(thread, &error_msg); |
| 2525 ASSERT(!values_list.IsNull()); | 2541 ASSERT(!values_list.IsNull()); |
| 2526 } | 2542 } |
| 2527 | 2543 |
| 2528 | 2544 |
| 2529 bool ClassFinalizer::IsSuperCycleFree(const Class& cls) { | 2545 bool ClassFinalizer::IsSuperCycleFree(const Class& cls) { |
| 2530 Class& test1 = Class::Handle(cls.raw()); | 2546 Class& test1 = Class::Handle(cls.raw()); |
| 2531 Class& test2 = Class::Handle(cls.SuperClass()); | 2547 Class& test2 = Class::Handle(cls.SuperClass()); |
| 2532 // A finalized class has been checked for cycles. | 2548 // A finalized class has been checked for cycles. |
| 2533 // Using the hare and tortoise algorithm for locating cycles. | 2549 // 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()); | 3283 ASSERT(fields_array.Length() == ByteBuffer::NumberOfFields()); |
| 3268 field ^= fields_array.At(0); | 3284 field ^= fields_array.At(0); |
| 3269 ASSERT(field.Offset() == ByteBuffer::data_offset()); | 3285 ASSERT(field.Offset() == ByteBuffer::data_offset()); |
| 3270 name ^= field.name(); | 3286 name ^= field.name(); |
| 3271 expected_name ^= String::New("_data"); | 3287 expected_name ^= String::New("_data"); |
| 3272 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name)); | 3288 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name)); |
| 3273 #endif | 3289 #endif |
| 3274 } | 3290 } |
| 3275 | 3291 |
| 3276 } // namespace dart | 3292 } // namespace dart |
| OLD | NEW |