Exemplo n.º 1
0
/*
 * Add an abstract virtual method constructor to a class.
 */
static ILMethod *AddAbstractMethod(ILClass *classInfo, const char *name,
							       ILType *returnType, ILType *argType)
{
	ILMethod *method;
	ILType *signature;
	method = ILMethodCreate(classInfo, 0, name,
					  	    IL_META_METHODDEF_PUBLIC |
					  	    IL_META_METHODDEF_HIDE_BY_SIG |
							IL_META_METHODDEF_ABSTRACT |
							IL_META_METHODDEF_VIRTUAL |
							IL_META_METHODDEF_NEW_SLOT);
	if(!method)
	{
		return 0;
	}
	signature = ILTypeCreateMethod(ILClassToContext(classInfo), returnType);
	if(!signature)
	{
		return 0;
	}
	ILTypeSetCallConv(signature, IL_META_CALLCONV_HASTHIS);
	if(argType != ILType_Void)
	{
		if(!ILTypeAddParam(ILClassToContext(classInfo), signature, argType))
		{
			return 0;
		}
	}
	ILMemberSetSignature((ILMember *)method, signature);
	return method;
}
Exemplo n.º 2
0
/*
 * Add the constructor to the "DecimalConstantAttribute" class.
 *
 * public DecimalConstantAttribute(byte scale, byte sign,
 *                                 uint hi, uint mid, uint low);
 */
static int AddDecimalConstructor(ILClass *classInfo)
{
	ILMethod *method;
	ILContext *context;
	ILType *signature;
	method = ILMethodCreate(classInfo, 0, ".ctor",
					  	    IL_META_METHODDEF_PUBLIC |
					  	    IL_META_METHODDEF_HIDE_BY_SIG |
							IL_META_METHODDEF_SPECIAL_NAME |
							IL_META_METHODDEF_RT_SPECIAL_NAME);
	if(!method)
	{
		return 0;
	}
	context = ILClassToContext(classInfo);
	signature = ILTypeCreateMethod(context, ILType_Void);
	if(!signature)
	{
		return 0;
	}
	ILTypeSetCallConv(signature, IL_META_CALLCONV_HASTHIS);
	if(!ILTypeAddParam(context, signature, ILType_UInt8))
	{
		return 0;
	}
	if(!ILTypeAddParam(context, signature, ILType_UInt8))
	{
		return 0;
	}
	if(!ILTypeAddParam(context, signature, ILType_UInt32))
	{
		return 0;
	}
	if(!ILTypeAddParam(context, signature, ILType_UInt32))
	{
		return 0;
	}
	if(!ILTypeAddParam(context, signature, ILType_UInt32))
	{
		return 0;
	}
	ILMemberSetSignature((ILMember *)method, signature);
	return 1;
}
Exemplo n.º 3
0
/*
 * Add an ordinary method to a class.
 */
static ILMethod *AddMethod(ILClass *classInfo, const char *name,
					       ILType *returnType, ILType *argType1,
						   ILType *argType2, ILUInt32 attrs)
{
	ILMethod *method;
	ILType *signature;
	method = ILMethodCreate(classInfo, 0, name,
					  	    IL_META_METHODDEF_PUBLIC |
					  	    IL_META_METHODDEF_HIDE_BY_SIG | attrs);
	if(!method)
	{
		return 0;
	}
	signature = ILTypeCreateMethod(ILClassToContext(classInfo), returnType);
	if(!signature)
	{
		return 0;
	}
	if((attrs & IL_META_METHODDEF_STATIC) == 0)
	{
		ILTypeSetCallConv(signature, IL_META_CALLCONV_HASTHIS);
	}
	if(argType1 != ILType_Void)
	{
		if(!ILTypeAddParam(ILClassToContext(classInfo), signature, argType1))
		{
			return 0;
		}
	}
	if(argType2 != ILType_Void)
	{
		if(!ILTypeAddParam(ILClassToContext(classInfo), signature, argType2))
		{
			return 0;
		}
	}
	ILMemberSetSignature((ILMember *)method, signature);
	return method;
}
Exemplo n.º 4
0
/*
 * Add a parameterized constructor to a class.
 */
static int AddParamConstructor(ILClass *classInfo, ILType *argType1,
							   ILType *argType2)
{
	ILMethod *method;
	ILType *signature;
	method = ILMethodCreate(classInfo, 0, ".ctor",
					  	    IL_META_METHODDEF_PUBLIC |
					  	    IL_META_METHODDEF_HIDE_BY_SIG |
							IL_META_METHODDEF_SPECIAL_NAME |
							IL_META_METHODDEF_RT_SPECIAL_NAME);
	if(!method)
	{
		return 0;
	}
	signature = ILTypeCreateMethod(ILClassToContext(classInfo), ILType_Void);
	if(!signature)
	{
		return 0;
	}
	if(argType1 != ILType_Void)
	{
		if(!ILTypeAddParam(ILClassToContext(classInfo), signature, argType1))
		{
			return 0;
		}
	}
	if(argType2 != ILType_Void)
	{
		if(!ILTypeAddParam(ILClassToContext(classInfo), signature, argType2))
		{
			return 0;
		}
	}
	ILTypeSetCallConv(signature, IL_META_CALLCONV_HASTHIS);
	ILMemberSetSignature((ILMember *)method, signature);
	return 1;
}
Exemplo n.º 5
0
/*
 * Expand the instantiations in a class.  Returns zero if out of memory.
 */
static int ExpandInstantiations(ILImage *image, ILClass *classInfo,
								ILType *classType, ILType *classParams)
{
	ILClass *origClass;
	ILMember *member;
	ILMethod *newMethod;
	ILField *newField;
	ILEvent *newEvent;
	ILType *signature;
	ILImplements *impl;
	ILClass *tempInfo;

	/* Bail out if not a "with" type, since the instantiation would
	   have already been taken care of by "ILClassFromType" */
	if(!ILType_IsWith(classType))
	{
		return 1;
	}

	/* Find the original class underlying the type */
	origClass = ILClassFromType(image, 0, ILTypeGetWithMain(classType), 0);
	if(!origClass)
	{
		return 0;
	}
	origClass = ILClassResolve(origClass);

	/* Copy across the class attributes */
	ILClassSetAttrs(classInfo, ~((ILUInt32)0), ILClass_Attrs(origClass));
	
	/* Mark this class as being expanded, to deal with circularities */
	classInfo->attributes |= IL_META_TYPEDEF_CLASS_EXPANDED;

	/* Expand the parent class and interfaces */
	if(origClass->parent)
	{
		ILClass *parentClass;

		parentClass = ILClassExpand
			(image, ILClass_ParentClass(origClass), classParams, 0);
		if(!parentClass)
		{
			classInfo->parent = 0;
			return 0;
		}
		classInfo->parent = ILToProgramItem(parentClass);
	}
	impl = _ILClass_Implements(origClass);
	while(impl)
	{
		tempInfo = ILImplements_InterfaceClass(impl);
		tempInfo = ILClassExpand(image, tempInfo, classParams, 0);
		if(!tempInfo)
		{
			return 0;
		}
		if(!ILClassAddImplements(classInfo, ILToProgramItem(tempInfo), 0))
		{
			return 0;
		}
		impl = _ILImplements_NextImplements(impl);
	}

	/* Expand the methods and fields */
	member = 0;
	while((member = ILClassNextMember(origClass, member)) != 0)
	{
		switch(ILMemberGetKind(member))
		{
			case IL_META_MEMBERKIND_METHOD:
			{
				newMethod = ILMethodCreateInstance(image, (ILMethod *)member,
												   classInfo, classParams, 0);

				if(!newMethod)
				{
					return 0;
				}
			}
			break;

			case IL_META_MEMBERKIND_FIELD:
			{
				/* Create a new field */
				newField = (ILField *)ILMemberCreateInstance(member, classInfo);

				if(!newField)
				{
					return 0;
				}

				/* Copy the original field's properties */
				signature = ILTypeInstantiate(image->context,
											  ILMember_Signature(member),
											  classParams, 0);
				if(!signature)
				{
					return 0;
				}
				else
				{
					ILMemberSetSignature((ILMember *)newField, signature);
				}
			}
			break;
			
			case IL_META_MEMBERKIND_EVENT:
			{
				/* Create a new event */
				newEvent = (ILEvent *)ILMemberCreateInstance(member, classInfo);

				if(!newEvent)
				{
					return 0;
				}

				/* Copy the original field's properties */
				signature = ILTypeInstantiate(image->context,
											  ILMember_Signature(member),
											  classParams, 0);
				if(!signature)
				{
					return 0;
				}
				else
				{
					ILMemberSetSignature((ILMember *)newEvent, signature);
				}
			}
			break;

			case IL_META_MEMBERKIND_PROPERTY:
			{
				/* TODO */
			}
			break;

			case IL_META_MEMBERKIND_OVERRIDE:
			{
				/* TODO */
			}
			break;

			case IL_META_MEMBERKIND_PINVOKE:
			{
				/* TODO */
			}
			break;
		}		
	}

	/* Done */
	return 1;
}