Index: runtime/vm/object.cc |
diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc |
index b8da11621e888fdcac9c668face1563ce1bfda2e..ba18f72c30c140e43e766eb77933f3aa87024c00 100644 |
--- a/runtime/vm/object.cc |
+++ b/runtime/vm/object.cc |
@@ -1670,6 +1670,13 @@ RawError* Object::Init(Isolate* isolate, kernel::Program* kernel_program) { |
// Set up recognized state of all functions (core, math and typed data). |
MethodRecognizer::InitializeState(); |
+ // Adds static const fields (class ids) to the class 'ClassID'); |
+ lib = Library::LookupLibrary(thread, Symbols::DartInternal()); |
+ ASSERT(!lib.IsNull()); |
+ cls = lib.LookupClassAllowPrivate(Symbols::ClassID()); |
+ ASSERT(!cls.IsNull()); |
+ cls.InjectCIDFields(); |
+ |
isolate->object_store()->InitKnownObjects(); |
#endif // !defined(DART_PRECOMPILED_RUNTIME) |
} else { |
@@ -3157,6 +3164,32 @@ void Class::AddFields(const GrowableArray<const Field*>& new_fields) const { |
} |
+void Class::InjectCIDFields() const { |
+ Thread* thread = Thread::Current(); |
+ Zone* zone = thread->zone(); |
+ Field& field = Field::Handle(zone); |
+ Smi& value = Smi::Handle(zone); |
+ String& field_name = String::Handle(zone); |
+ |
+#define CLASS_LIST_WITH_NULL(V) \ |
+ V(Null) \ |
+ CLASS_LIST_NO_OBJECT(V) |
+ |
+#define ADD_SET_FIELD(clazz) \ |
+ field_name = Symbols::New(thread, "cid" #clazz); \ |
+ field = \ |
+ Field::New(field_name, true, false, true, false, *this, \ |
+ Type::Handle(Type::IntType()), TokenPosition::kMinSource); \ |
+ value = Smi::New(k##clazz##Cid); \ |
+ field.SetStaticValue(value, true); \ |
+ AddField(field); |
+ |
+ CLASS_LIST_WITH_NULL(ADD_SET_FIELD) |
+#undef ADD_SET_FIELD |
+#undef CLASS_LIST_WITH_NULL |
+} |
+ |
+ |
template <class FakeInstance> |
RawClass* Class::NewCommon(intptr_t index) { |
ASSERT(Object::class_class() != Class::null()); |