当前位置: 首页>>代码示例>>C#>>正文


C# IType.IsClassCastRequired方法代码示例

本文整理汇总了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);
                }
            }
        }
开发者ID:afrog33k,项目名称:csnative,代码行数:94,代码来源:CallGen.cs

示例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);
                }
            }
        }
开发者ID:SperoSophia,项目名称:il2bc,代码行数:65,代码来源:CallGen.cs


注:本文中的IType.IsClassCastRequired方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。