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 1343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1354 ReportError(cls, field.token_pos(), | 1354 ReportError(cls, field.token_pos(), |
1355 "field '%s' of class '%s' conflicts with method '%s' " | 1355 "field '%s' of class '%s' conflicts with method '%s' " |
1356 "of super class '%s'", | 1356 "of super class '%s'", |
1357 name.ToCString(), | 1357 name.ToCString(), |
1358 class_name.ToCString(), | 1358 class_name.ToCString(), |
1359 name.ToCString(), | 1359 name.ToCString(), |
1360 super_class_name.ToCString()); | 1360 super_class_name.ToCString()); |
1361 } | 1361 } |
1362 } | 1362 } |
1363 if (field.is_static() && | 1363 if (field.is_static() && |
1364 (field.value() != Object::null()) && | 1364 (field.StaticValue() != Object::null()) && |
1365 (field.value() != Object::sentinel().raw())) { | 1365 (field.StaticValue() != Object::sentinel().raw())) { |
1366 // The parser does not preset the value if the type is a type parameter or | 1366 // The parser does not preset the value if the type is a type parameter or |
1367 // is parameterized unless the value is null. | 1367 // is parameterized unless the value is null. |
1368 Error& error = Error::Handle(Z); | 1368 Error& error = Error::Handle(Z); |
1369 if (type.IsMalformedOrMalbounded()) { | 1369 if (type.IsMalformedOrMalbounded()) { |
1370 error = type.error(); | 1370 error = type.error(); |
1371 } else { | 1371 } else { |
1372 ASSERT(type.IsInstantiated()); | 1372 ASSERT(type.IsInstantiated()); |
1373 } | 1373 } |
1374 const Instance& const_value = Instance::Handle(Z, field.value()); | 1374 const Instance& const_value = |
| 1375 Instance::Handle(Z, field.StaticValue()); |
1375 if (!error.IsNull() || | 1376 if (!error.IsNull() || |
1376 (!type.IsDynamicType() && | 1377 (!type.IsDynamicType() && |
1377 !const_value.IsInstanceOf(type, | 1378 !const_value.IsInstanceOf(type, |
1378 Object::null_type_arguments(), | 1379 Object::null_type_arguments(), |
1379 &error))) { | 1380 &error))) { |
1380 if (Isolate::Current()->flags().error_on_bad_type()) { | 1381 if (Isolate::Current()->flags().error_on_bad_type()) { |
1381 const AbstractType& const_value_type = AbstractType::Handle( | 1382 const AbstractType& const_value_type = AbstractType::Handle( |
1382 Z, const_value.GetType()); | 1383 Z, const_value.GetType()); |
1383 const String& const_value_type_name = String::Handle( | 1384 const String& const_value_type_name = String::Handle( |
1384 Z, const_value_type.UserVisibleName()); | 1385 Z, const_value_type.UserVisibleName()); |
(...skipping 21 matching lines...) Expand all Loading... |
1406 /* is_static = */ true, | 1407 /* is_static = */ true, |
1407 /* is_const = */ field.is_const(), | 1408 /* is_const = */ field.is_const(), |
1408 /* is_abstract = */ false, | 1409 /* is_abstract = */ false, |
1409 /* is_external = */ false, | 1410 /* is_external = */ false, |
1410 /* is_native = */ false, | 1411 /* is_native = */ false, |
1411 cls, | 1412 cls, |
1412 field.token_pos())); | 1413 field.token_pos())); |
1413 getter.set_result_type(type); | 1414 getter.set_result_type(type); |
1414 getter.set_is_debuggable(false); | 1415 getter.set_is_debuggable(false); |
1415 cls.AddFunction(getter); | 1416 cls.AddFunction(getter); |
1416 field.set_value(Object::sentinel()); | 1417 field.SetStaticValue(Object::sentinel(), true); |
1417 } | 1418 } |
1418 } | 1419 } |
1419 } | 1420 } |
1420 } | 1421 } |
1421 // Collect interfaces, super interfaces, and super classes of this class. | 1422 // Collect interfaces, super interfaces, and super classes of this class. |
1422 GrowableArray<const Class*> interfaces(Z, 4); | 1423 GrowableArray<const Class*> interfaces(Z, 4); |
1423 CollectInterfaces(cls, &interfaces); | 1424 CollectInterfaces(cls, &interfaces); |
1424 // Include superclasses in list of interfaces and super interfaces. | 1425 // Include superclasses in list of interfaces and super interfaces. |
1425 super_class = cls.SuperClass(); | 1426 super_class = cls.SuperClass(); |
1426 while (!super_class.IsNull()) { | 1427 while (!super_class.IsNull()) { |
(...skipping 997 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2424 // getter function object for each enumeration value and for the | 2425 // getter function object for each enumeration value and for the |
2425 // values field. We also don't have to generate the code for these getters | 2426 // values field. We also don't have to generate the code for these getters |
2426 // from thin air (no source code is available). | 2427 // from thin air (no source code is available). |
2427 void ClassFinalizer::AllocateEnumValues(const Class &enum_cls) { | 2428 void ClassFinalizer::AllocateEnumValues(const Class &enum_cls) { |
2428 const Field& index_field = | 2429 const Field& index_field = |
2429 Field::Handle(enum_cls.LookupInstanceField(Symbols::Index())); | 2430 Field::Handle(enum_cls.LookupInstanceField(Symbols::Index())); |
2430 ASSERT(!index_field.IsNull()); | 2431 ASSERT(!index_field.IsNull()); |
2431 const Field& values_field = | 2432 const Field& values_field = |
2432 Field::Handle(enum_cls.LookupStaticField(Symbols::Values())); | 2433 Field::Handle(enum_cls.LookupStaticField(Symbols::Values())); |
2433 ASSERT(!values_field.IsNull()); | 2434 ASSERT(!values_field.IsNull()); |
2434 ASSERT(Instance::Handle(values_field.value()).IsArray()); | 2435 ASSERT(Instance::Handle(values_field.StaticValue()).IsArray()); |
2435 Array& values_list = Array::Handle(Array::RawCast(values_field.value())); | 2436 Array& values_list = Array::Handle( |
| 2437 Array::RawCast(values_field.StaticValue())); |
2436 | 2438 |
2437 const Array& fields = Array::Handle(enum_cls.fields()); | 2439 const Array& fields = Array::Handle(enum_cls.fields()); |
2438 Field& field = Field::Handle(); | 2440 Field& field = Field::Handle(); |
2439 Instance& ordinal_value = Instance::Handle(); | 2441 Instance& ordinal_value = Instance::Handle(); |
2440 Instance& enum_value = Instance::Handle(); | 2442 Instance& enum_value = Instance::Handle(); |
2441 | 2443 |
2442 for (intptr_t i = 0; i < fields.Length(); i++) { | 2444 for (intptr_t i = 0; i < fields.Length(); i++) { |
2443 field = Field::RawCast(fields.At(i)); | 2445 field = Field::RawCast(fields.At(i)); |
2444 if (!field.is_static()) continue; | 2446 if (!field.is_static()) continue; |
2445 ordinal_value = field.value(); | 2447 ordinal_value = field.StaticValue(); |
2446 // The static fields that need to be initialized with enum instances | 2448 // The static fields that need to be initialized with enum instances |
2447 // contain the smi value of the ordinal number, which was stored in | 2449 // contain the smi value of the ordinal number, which was stored in |
2448 // the field by the parser. Other fields contain non-smi values. | 2450 // the field by the parser. Other fields contain non-smi values. |
2449 if (!ordinal_value.IsSmi()) continue; | 2451 if (!ordinal_value.IsSmi()) continue; |
2450 enum_value = Instance::New(enum_cls, Heap::kOld); | 2452 enum_value = Instance::New(enum_cls, Heap::kOld); |
2451 enum_value.SetField(index_field, ordinal_value); | 2453 enum_value.SetField(index_field, ordinal_value); |
2452 const char* error_msg = ""; | 2454 const char* error_msg = ""; |
2453 enum_value = enum_value.CheckAndCanonicalize(&error_msg); | 2455 enum_value = enum_value.CheckAndCanonicalize(&error_msg); |
2454 if (enum_value.IsNull()) { | 2456 if (enum_value.IsNull()) { |
2455 ReportError(enum_cls, enum_cls.token_pos(), "Failed finalizing values."); | 2457 ReportError(enum_cls, enum_cls.token_pos(), "Failed finalizing values."); |
2456 UNREACHABLE(); | 2458 UNREACHABLE(); |
2457 } | 2459 } |
2458 ASSERT(enum_value.IsCanonical()); | 2460 ASSERT(enum_value.IsCanonical()); |
2459 field.set_value(enum_value); | 2461 field.SetStaticValue(enum_value, true); |
2460 field.RecordStore(enum_value); | 2462 field.RecordStore(enum_value); |
2461 intptr_t ord = Smi::Cast(ordinal_value).Value(); | 2463 intptr_t ord = Smi::Cast(ordinal_value).Value(); |
2462 ASSERT(ord < values_list.Length()); | 2464 ASSERT(ord < values_list.Length()); |
2463 values_list.SetAt(ord, enum_value); | 2465 values_list.SetAt(ord, enum_value); |
2464 } | 2466 } |
2465 values_list.MakeImmutable(); | 2467 values_list.MakeImmutable(); |
2466 } | 2468 } |
2467 | 2469 |
2468 | 2470 |
2469 bool ClassFinalizer::IsSuperCycleFree(const Class& cls) { | 2471 bool ClassFinalizer::IsSuperCycleFree(const Class& cls) { |
(...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3215 ASSERT(fields_array.Length() == ByteBuffer::NumberOfFields()); | 3217 ASSERT(fields_array.Length() == ByteBuffer::NumberOfFields()); |
3216 field ^= fields_array.At(0); | 3218 field ^= fields_array.At(0); |
3217 ASSERT(field.Offset() == ByteBuffer::data_offset()); | 3219 ASSERT(field.Offset() == ByteBuffer::data_offset()); |
3218 name ^= field.name(); | 3220 name ^= field.name(); |
3219 expected_name ^= String::New("_data"); | 3221 expected_name ^= String::New("_data"); |
3220 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name)); | 3222 ASSERT(String::EqualsIgnoringPrivateKey(name, expected_name)); |
3221 #endif | 3223 #endif |
3222 } | 3224 } |
3223 | 3225 |
3224 } // namespace dart | 3226 } // namespace dart |
OLD | NEW |