本文整理汇总了C#中IType.IsClassCastRequired方法的典型用法代码示例。如果您正苦于以下问题:C# IType.IsClassCastRequired方法的具体用法?C# IType.IsClassCastRequired怎么用?C# IType.IsClassCastRequired使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IType
的用法示例。
在下文中一共展示了IType.IsClassCastRequired方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteFunctionCallPrepareThisExpression
/// <summary>
/// </summary>
/// <param name="opCodeMethodInfo">
/// </param>
/// <param name="thisType">
/// </param>
/// <param name="opCodeFirstOperand">
/// </param>
/// <param name="resultOfFirstOperand">
/// </param>
/// <param name="llvmWriter">
/// </param>
public static void WriteFunctionCallPrepareThisExpression(
this OpCodePart opCodeMethodInfo,
IType thisType,
OpCodePart opCodeFirstOperand,
BaseWriter.ReturnResult resultOfFirstOperand,
LlvmWriter llvmWriter)
{
var writer = llvmWriter.Output;
// check if you need to cast this parameter
var isPrimitive = resultOfFirstOperand.Type.IsPrimitiveTypeOrEnum();
var isPrimitivePointer = resultOfFirstOperand.Type.IsPointer &&
resultOfFirstOperand.Type.GetElementType().IsPrimitiveTypeOrEnum();
var dynamicCastRequired = false;
if (!isPrimitive && !isPrimitivePointer &&
thisType.IsClassCastRequired(opCodeFirstOperand, out dynamicCastRequired))
{
writer.WriteLine("; Cast of 'This' parameter");
llvmWriter.WriteCast(opCodeFirstOperand, opCodeFirstOperand.Result, thisType);
writer.WriteLine(string.Empty);
}
if (dynamicCastRequired)
{
writer.WriteLine("; Dynamic Cast of 'This' parameter");
llvmWriter.WriteDynamicCast(writer, opCodeFirstOperand, opCodeFirstOperand.Result, thisType);
writer.WriteLine(string.Empty);
}
if (isPrimitive || isPrimitivePointer)
{
var primitiveType = resultOfFirstOperand.Type;
if (isPrimitivePointer)
{
writer.WriteLine("; Box Primitive pointer type for 'This' parameter");
primitiveType = resultOfFirstOperand.Type.GetElementType();
var firstOperandResult = opCodeFirstOperand.Result;
opCodeFirstOperand.Result = null;
llvmWriter.WriteLlvmLoad(
opCodeFirstOperand,
firstOperandResult.Type.ToDereferencedType(),
firstOperandResult);
}
else
{
writer.WriteLine("; Box Primitive type(void*) for 'This' parameter");
var intType = llvmWriter.GetIntTypeByByteSize(LlvmWriter.PointerSize);
var uintType = llvmWriter.GetUIntTypeByByteSize(LlvmWriter.PointerSize);
if (intType.TypeEquals(primitiveType) || uintType.TypeEquals(primitiveType))
{
var declType = (opCodeMethodInfo as OpCodeMethodInfoPart).Operand.DeclaringType;
Debug.Assert(declType.IsStructureType(), "only Struct type can be used");
primitiveType = declType.ToClass();
llvmWriter.AdjustIntConvertableTypes(
writer,
opCodeMethodInfo.OpCodeOperands[0],
declType.ToPointerType());
}
else
{
Debug.Assert(false, "only Int type allowed");
}
}
// convert value to object
opCodeMethodInfo.Result = null;
var opCodeNone = OpCodePart.CreateNop;
opCodeNone.OpCodeOperands = new[] { opCodeMethodInfo.OpCodeOperands[0] };
primitiveType.ToClass().WriteCallBoxObjectMethod(llvmWriter, opCodeNone);
opCodeFirstOperand.Result = opCodeNone.Result;
writer.WriteLine(string.Empty);
if (thisType.IsClassCastRequired(opCodeFirstOperand, out dynamicCastRequired))
{
writer.WriteLine("; Cast of 'Boxed' 'This' parameter");
llvmWriter.WriteCast(opCodeFirstOperand, opCodeFirstOperand.Result, thisType);
writer.WriteLine(string.Empty);
}
}
}
示例2: WriteFunctionCallPrepareThisExpression
/// <summary>
/// </summary>
/// <param name="opCodeMethodInfo">
/// </param>
/// <param name="thisType">
/// </param>
/// <param name="opCodeFirstOperand">
/// </param>
/// <param name="resultOfFirstOperand">
/// </param>
/// <param name="llvmWriter">
/// </param>
public static void WriteFunctionCallPrepareThisExpression(
this OpCodePart opCodeMethodInfo, IType thisType, OpCodePart opCodeFirstOperand, BaseWriter.ReturnResult resultOfFirstOperand, LlvmWriter llvmWriter)
{
var writer = llvmWriter.Output;
// check if you need to cast this parameter
var isPrimitive = resultOfFirstOperand.Type.IsPrimitiveTypeOrEnum();
var isPrimitivePointer = resultOfFirstOperand.Type.IsPointer && resultOfFirstOperand.Type.GetElementType().IsPrimitiveTypeOrEnum();
var dynamicCastRequired = false;
if (!isPrimitive && !isPrimitivePointer && thisType.IsClassCastRequired(opCodeFirstOperand, out dynamicCastRequired))
{
writer.WriteLine("; Cast of 'This' parameter");
llvmWriter.WriteCast(opCodeFirstOperand, opCodeFirstOperand.Result, thisType);
writer.WriteLine(string.Empty);
}
if (dynamicCastRequired)
{
writer.WriteLine("; Dynamic Cast of 'This' parameter");
llvmWriter.WriteDynamicCast(writer, opCodeFirstOperand, opCodeFirstOperand.Result, thisType);
writer.WriteLine(string.Empty);
}
if (isPrimitive || isPrimitivePointer)
{
writer.WriteLine("; Box Primitive type for 'This' parameter");
var primitiveType = !isPrimitivePointer ? resultOfFirstOperand.Type : resultOfFirstOperand.Type.GetElementType();
if (isPrimitivePointer)
{
var firstOperandResult = opCodeFirstOperand.Result;
opCodeFirstOperand.Result = null;
llvmWriter.WriteLlvmLoad(opCodeFirstOperand, firstOperandResult.Type.ToDereferencedType(), firstOperandResult);
}
// convert value to object
opCodeMethodInfo.Result = null;
var opCodeNone = OpCodePart.CreateNop;
opCodeNone.OpCodeOperands = new[] { opCodeMethodInfo.OpCodeOperands[0] };
primitiveType.ToClass().WriteCallBoxObjectMethod(llvmWriter, opCodeNone);
opCodeFirstOperand.Result = opCodeNone.Result;
writer.WriteLine(string.Empty);
if (thisType.IsClassCastRequired(opCodeFirstOperand, out dynamicCastRequired))
{
writer.WriteLine("; Cast of 'Boxed' 'This' parameter");
llvmWriter.WriteCast(opCodeFirstOperand, opCodeFirstOperand.Result, thisType);
writer.WriteLine(string.Empty);
}
}
}