Esempio n. 1
0
Class RegisterClass(old_class* cls, bool hasExt)
{
	LOG << "Processing old ObjC class " << cls->name << std::endl;
	
	const old_class* meta = cls->isa.cls;
	Class conv, super;
	auto & g_classPointers = getClassPointers();
	/*
	old_class* psuper = cls->super_class.cls;
	auto itSuper = g_classPointers.find(psuper); // TODO: may not be needed, should always be a string

	if (itSuper != g_classPointers.end())
		super = itSuper->second;
	else
		super = reinterpret_cast<Class>(psuper);
	*/

	super = (Class) objc_getClass(cls->super_class.name);
	LOG << "...with superclass @" << super << std::endl;
	conv = objc_allocateClassPair(super, cls->name, 0);
	
	if (cls->methodList)
		ConvertMethodListGen(conv, cls->methodList);
	if (meta->methodList)
		ConvertMethodListGen(object_getClass(id(conv)), meta->methodList);
	if (cls->ivars)
		ConvertIvarList(conv, cls->ivars);
	if (cls->protocols)
		AddClassProtocols(conv, cls->protocols);
	
	if (hasExt && cls->ext && cls->ext->propertyLists)
	{
		LOG << "Class has EXT and a property list/lists\n";
		//if (cls->info & CLS_NO_PROPERTY_ARRAY)
		if (true)
		{
			ConvertProperties(cls->ext->propertyList, [conv](const char* name, const objc_property_attribute_t* attr, unsigned int count) { class_addProperty(conv, name, attr, count); bug_gnustepFixPropertyCount(conv); });
		}
		else
		{
			for (size_t i = 0; cls->ext->propertyLists[i] != nullptr; i++)
			{
				const old_property_list* l = cls->ext->propertyLists[i];
				ConvertProperties(l, [conv](const char* name, const objc_property_attribute_t* attr, unsigned int count) { class_addProperty(conv, name, attr, count); bug_gnustepFixPropertyCount(conv); });
			}
		}
	}
	
	objc_registerClassPair(conv);
	g_classPointers[cls] = conv;
	g_classPointers[cls->name] = conv;

	LOG << "ObjC class " << cls->name << " @" << conv << std::endl;
	
	return conv;
}
Esempio n. 2
0
Class RegisterClass(const class_t* cls, intptr_t slide)
{
	LOG << "Processing ObjC class " << cls->data()->className << std::endl;
	
	const class_t* meta = cls->isa;
	Class conv, super;
	auto itSuper = g_classPointers.find(cls->superclass);

	if (itSuper != g_classPointers.end())
		super = itSuper->second;
	else
		super = reinterpret_cast<Class>(cls->superclass);
	
	LOG << "...superclass is @" << super << std::endl;
	assert(objc_getClass(cls->data()->className) == nullptr);
	conv = objc_allocateClassPair(super, cls->data()->className, 0);
	
	const class_ro_t* ro = cls->data();
	const class_ro_t* roMeta = meta->data();
	
	if (ro->baseMethods)
		ConvertMethodListGen(conv, ro->baseMethods);
	if (roMeta->baseMethods)
		ConvertMethodListGen(object_getClass(id(conv)), roMeta->baseMethods);
	if (ro->ivars)
		ConvertIvarList(conv, ro->ivars);
	if (ro->baseProtocols)
		AddClassProtocols(conv, ro->baseProtocols, slide);
	if (ro->baseProperties)
	{
		ConvertProperties(ro->baseProperties, [conv](const char* name, const objc_property_attribute_t* attr, unsigned int count) { class_addProperty(conv, name, attr, count); bug_gnustepFixPropertyCount(conv); });
	}
	
	// conv->instance_size = ro->instSize;
	// conv->isa->instance_size = roMeta->instSize;
	
	objc_registerClassPair(conv);
	
	LOG << "ObjC class " << cls->data()->className << " now @" << conv << std::endl;
	g_classPointers[cls] = conv;
	g_classPointers[cls->isa] = object_getClass(id(conv));
	
	return conv;
}
Esempio n. 3
0
Class RegisterClass(const class_t* cls, intptr_t slide, uint32_t image_index)
{
	if (nullptr == cls)
	{
		return nullptr;
	}

	auto & g_classPointers = getClassPointers();
	auto itClass = g_classPointers.find(cls);
	if (itClass != g_classPointers.end())
	{
		LOG << "Found existing class @" << itClass->second << std::endl;
		return itClass->second;
	}

	Class super = RegisterClass(cls->superclass, slide, image_index);

	LOG << "...superclass is @" << super << std::endl;
	if (nullptr != super)
	{
		LOG << "...superclass name " << (((uintptr_t)super != (uintptr_t)cls->superclass) ? cls->superclass->data()->className : class_getName(super)) << std::endl;
		LOG << "...super name " << class_getName(super) << std::endl;
	}

	if (nullptr == cls->data())
	{
		// TODO: Is this a bad pointer filled in, or are we supposed to do something different with this?
		// This is from when we call RegisterClass recursively sometimes...
		std::cerr << "Error - Null class data at class @" << cls << std::endl;
		return nullptr;
	}

	if (nullptr == cls->data()->className)
	{
		// TODO: Is this a bad pointer filled in, or are we supposed to do something different with this?
		// This is from when we call RegisterClass recursively sometimes...
		std::cerr << "Error - Null class name at class @" << cls << std::endl;
		return nullptr;
	}

	LOG << "Processing ObjC class " << cls->data()->className << std::endl;

	Class sameClass = (Class)objc_getClass(cls->data()->className);
	if (nullptr != sameClass)
	{
		LOG << "Found a class with the same name @" << sameClass << std::endl;
		return sameClass;
	}

	LOG << "obj_allocateClassPair(" << super << ", " << cls->data()->className << ")" << std::endl;

	Class conv = objc_allocateClassPair(super, cls->data()->className, 0);

	if (nullptr == conv)
	{
		std::cerr << "Failed to allocate class " << cls->data()->className << std::endl;
		return nullptr;
	}

	Class meta = object_getClass(id(conv));

	const class_ro_t* ro = cls->data();

	if (ro->baseMethods)
		ConvertMethodListGen(conv, ro->baseMethods, image_index);
	if (g_classPointers.find(cls->isa) == g_classPointers.end())
	{
		const class_ro_t* roMeta = cls->isa->data();
		if (roMeta->baseMethods)
			ConvertMethodListGen(meta, roMeta->baseMethods, image_index);
	}
	if (ro->ivars)
		ConvertIvarList(conv, ro->ivars);
	if (ro->baseProtocols)
		AddClassProtocols(conv, ro->baseProtocols, slide);
	if (ro->baseProperties)
	{
		ConvertProperties(ro->baseProperties, [conv](const char* name, const objc_property_attribute_t* attr, unsigned int count) { class_addProperty(conv, name, attr, count); bug_gnustepFixPropertyCount(conv); });
	}

	// conv->instance_size = ro->instSize;

	objc_registerClassPair(conv);
	
	LOG << "ObjC class " << cls->data()->className << " now @" << conv << std::endl;
	g_classPointers[cls] = conv;
	g_classPointers[conv] = conv;
	g_classPointers[meta] = meta;

	return conv;
}