Ejemplo n.º 1
0
static tMD_MethodDef* FindMethodInType(tMD_TypeDef *pTypeDef, STRING name, tMetaData *pSigMetaData, BLOB_ sigBlob, tMD_TypeDef **ppClassTypeArgs, tMD_TypeDef **ppMethodTypeArgs) {
	U32 i;
	tMD_TypeDef *pLookInType = pTypeDef;

	do {
		for (i=0; i<pLookInType->numMethods; i++) {
			if (MetaData_CompareNameAndSig(name, sigBlob, pSigMetaData, ppClassTypeArgs, ppMethodTypeArgs, pLookInType->ppMethods[i], pLookInType->ppClassTypeArgs, NULL)) {
				return pLookInType->ppMethods[i];
			}
		}
		pLookInType = pLookInType->pParent;
	} while (pLookInType != NULL);

	{
		// Error reporting!!
		U32 entry, numParams, i;
		SIG sig;
		char *pMsg;
		tMD_TypeDef *pParamTypeDef;

		pMsg = (char*)malloc(2048);
		*pMsg = 0;
		sig = MetaData_GetBlob(sigBlob, &i);
		entry = MetaData_DecodeSigEntry(&sig);
		if ((entry & SIG_METHODDEF_HASTHIS) == 0) {
			sprintf(strchr(pMsg, 0), "static ");
		}
		if (entry & SIG_METHODDEF_GENERIC) {
			// read number of generic type args - don't care what it is
			MetaData_DecodeSigEntry(&sig);
		}
		numParams = MetaData_DecodeSigEntry(&sig);
		pParamTypeDef = Type_GetTypeFromSig(pSigMetaData, &sig, ppClassTypeArgs, ppMethodTypeArgs); // return type
		if (pParamTypeDef != NULL) {
			sprintf(strchr(pMsg, 0), "%s ", pParamTypeDef->name);
		}
		sprintf(strchr(pMsg, 0), "%s.%s.%s(", pTypeDef->nameSpace, pTypeDef->name, name);
		for (i=0; i<numParams; i++) {
			pParamTypeDef = Type_GetTypeFromSig(pSigMetaData, &sig, ppClassTypeArgs, ppMethodTypeArgs);
			if (i > 0) {
				sprintf(strchr(pMsg, 0), ",");
			}
			if (pParamTypeDef != NULL) {
				sprintf(strchr(pMsg, 0), pParamTypeDef->name);
			} else {
				sprintf(strchr(pMsg, 0), "???");
			}
		}
		Crash("FindMethodInType(): Cannot find method %s)", pMsg);
	}
	FAKE_RETURN;
}
Ejemplo n.º 2
0
// Find the method that has been overridden by pMethodDef.
// This is to get the correct vTable offset for the method.
// This must search the MethodImpl table to see if the default inheritence rules are being overridden.
// Return NULL if this method does not override anything.
static tMD_MethodDef* FindVirtualOverriddenMethod(tMD_TypeDef *pTypeDef, tMD_MethodDef *pMethodDef)
{
	U32 i;

	do 
	{
		// Search MethodImpl table
		for (i=pTypeDef->pMetaData->tables.numRows[MD_TABLE_METHODIMPL]; i>0; i--) 
		{
			tMD_MethodImpl *pMethodImpl;

			pMethodImpl = (tMD_MethodImpl*)MetaData_GetTableRow(pTypeDef->pMetaData, MAKE_TABLE_INDEX(MD_TABLE_METHODIMPL, i));
			if (pMethodImpl->class_ == pTypeDef->tableIndex)
			{
				tMD_MethodDef *pMethodDeclDef;

				pMethodDeclDef = MetaData_GetMethodDefFromDefRefOrSpec(pTypeDef->pMetaData, pMethodImpl->methodDeclaration, pTypeDef->ppClassTypeArgs, pMethodDef->ppMethodTypeArgs);
				if (pMethodDeclDef->tableIndex == pMethodDef->tableIndex)
				{
					IDX_TABLE methodToken;
					tMD_MethodDef *pMethod;

					methodToken = pMethodImpl->methodBody;
					pMethod = (tMD_MethodDef*)MetaData_GetTableRow(pTypeDef->pMetaData, methodToken);
					return pMethod;
				}
			}
		}

		// Use normal inheritence rules
		// It must be a virtual method that's being overridden.
		for (i=pTypeDef->numVirtualMethods - 1; i != 0xffffffff; i--)
		{
			if (MetaData_CompareNameAndSig(pMethodDef->name, pMethodDef->signature, pMethodDef->pMetaData, pMethodDef->pParentType->ppClassTypeArgs, pMethodDef->ppMethodTypeArgs, pTypeDef->pVTable[i], pTypeDef->ppClassTypeArgs, NULL)) 
			{
				return pTypeDef->pVTable[i];
			}
		}
		pTypeDef = pTypeDef->pParent;
	} while (pTypeDef != NULL);

	return NULL;
}