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


C# Compiler.GetTypeDef方法代码示例

本文整理汇总了C#中Compiler.GetTypeDef方法的典型用法代码示例。如果您正苦于以下问题:C# Compiler.GetTypeDef方法的具体用法?C# Compiler.GetTypeDef怎么用?C# Compiler.GetTypeDef使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Compiler的用法示例。


在下文中一共展示了Compiler.GetTypeDef方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GenerateMethod

        public override RloMethod GenerateMethod(Compiler compiler, MethodInstantiationPath instantiationPath)
        {
            TypeSpecDelegateTag delegateType = m_dt;
            TypeSpecClassTag delegateClassType = delegateType.DelegateType;
            MethodSpecTag methodSpec = delegateType.MethodSpec;

            TypeSpecClassTag targetType = methodSpec.DeclaringClass;

            CliClass delegateCls = compiler.GetClosedClass(delegateClassType);

            TypeNameTag delegateTypeName = delegateCls.TypeName;
            HighTypeDef delegateTypeDef = compiler.GetTypeDef(delegateTypeName);
            if (delegateTypeDef.Semantics != TypeSemantics.Delegate)
                throw new RpaCompileException("Delegate-bound class is not a delegate");

            HighTypeDef targetTypeDef = compiler.GetTypeDef(targetType.TypeName);

            CliClass targetCls = null;
            CliInterface targetIfc = null;

            bool isInterface;
            switch (targetTypeDef.Semantics)
            {
                case TypeSemantics.Class:
                case TypeSemantics.Delegate:
                case TypeSemantics.Enum:
                case TypeSemantics.Struct:
                    isInterface = false;
                    targetCls = compiler.GetClosedClass(targetType);
                    break;
                case TypeSemantics.Interface:
                    isInterface = true;
                    targetIfc = compiler.GetClosedInterface(targetType);
                    break;
                default:
                    throw new ArgumentException();
            }

            MethodSignatureTag declSignature = delegateTypeDef.DelegateSignature;

            MethodDeclTag invokeDeclTag = new MethodDeclTag("Invoke", declSignature, delegateTypeName);
            invokeDeclTag = compiler.TagRepository.InternMethodDeclTag(invokeDeclTag);

            uint vtableSlotIndex = delegateCls.DeclTagToVTableSlot[invokeDeclTag];
            CliVtableSlot vtableSlot = delegateCls.VTable[vtableSlotIndex];

            MethodSignatureTag delegateMethodSignature = vtableSlot.MethodSignature;
            MethodSignatureTag targetMethodSignature;

            switch (methodSpec.MethodSlotType)
            {
                case MethodSlotType.Instance:
                case MethodSlotType.Static:
                    {
                        if (isInterface)
                            throw new RpaCompileException("Wrong method spec type for interface");

                        HighMethod method = targetCls.Methods[targetCls.DeclTagToMethod[methodSpec.MethodDecl]];
                        targetMethodSignature = method.MethodSignature.Instantiate(compiler.TagRepository, methodSpec.DeclaringClass.ArgTypes, methodSpec.GenericParameters);
                    }
                    break;
                case MethodSlotType.Virtual:
                    {
                        if (isInterface)
                        {
                            HighClassVtableSlot vtSlot = targetIfc.Slots[targetIfc.CliSlotForSlotTag(methodSpec.MethodDecl)];
                            targetMethodSignature = vtSlot.Signature.Instantiate(compiler.TagRepository, methodSpec.DeclaringClass.ArgTypes, methodSpec.GenericParameters);
                        }
                        else
                        {
                            CliVtableSlot calledVtableSlot = targetCls.VTable[targetCls.DeclTagToVTableSlot[methodSpec.MethodDecl]];

                            if (calledVtableSlot.MethodSignature.NumGenericParameters > 0)
                                throw new RpaCompileException("Can't generate delegate thunk to virtual generic");

                            targetMethodSignature = calledVtableSlot.MethodSignature.Instantiate(compiler.TagRepository, methodSpec.DeclaringClass.ArgTypes, methodSpec.GenericParameters);
                        }
                    }
                    break;
                default:
                    throw new Exception();
            }

            List<HighInstruction> instrs = new List<HighInstruction>();

            HighLocal thisLocal = new HighLocal(m_dt, HighLocal.ETypeOfType.Value);
            HighLocal[] locals = new HighLocal[0];

            List<HighLocal> args = new List<HighLocal>();

            int numParams = delegateMethodSignature.ParamTypes.Length;
            if (numParams != targetMethodSignature.ParamTypes.Length)
                throw new RpaCompileException("Delegate parameter count mismatch");

            List<HighSsaRegister> convertedParameters = new List<HighSsaRegister>();
            for (int i = 0; i < numParams; i++)
            {
                MethodSignatureParam delegateSigParam = delegateMethodSignature.ParamTypes[i];
                MethodSignatureParam targetSigParam = targetMethodSignature.ParamTypes[i];

//.........这里部分代码省略.........
开发者ID:elasota,项目名称:clarity,代码行数:101,代码来源:GMDelegateInvoke.cs

示例2: GenerateMethod

        public override RloMethod GenerateMethod(Compiler compiler, MethodInstantiationPath instantiationPath)
        {
            TypeSpecClassTag delegateClassType = m_dt;

            CliClass delegateCls = compiler.GetClosedClass(delegateClassType);

            TypeNameTag delegateTypeName = delegateCls.TypeName;
            HighTypeDef delegateTypeDef = compiler.GetTypeDef(delegateTypeName);
            if (delegateTypeDef.Semantics != TypeSemantics.Delegate)
                throw new RpaCompileException("Delegate-bound class is not a delegate");

            MethodSignatureTag declSignature = delegateTypeDef.DelegateSignature;

            MethodDeclTag invokeDeclTag = new MethodDeclTag("Invoke", declSignature, delegateTypeName);
            invokeDeclTag = compiler.TagRepository.InternMethodDeclTag(invokeDeclTag);

            uint vtableSlotIndex = delegateCls.DeclTagToVTableSlot[invokeDeclTag];
            CliVtableSlot vtableSlot = delegateCls.VTable[vtableSlotIndex];

            MethodSignatureTag delegateMethodSignature = vtableSlot.MethodSignature;

            TypeSpecMulticastDelegateTag mdType = new TypeSpecMulticastDelegateTag(m_dt);
            mdType = (TypeSpecMulticastDelegateTag)compiler.TagRepository.InternTypeSpec(mdType);

            List<HighSsaRegister> loadedParams = new List<HighSsaRegister>();

            HighLocal thisLocal = new HighLocal(mdType, HighLocal.ETypeOfType.Value);

            List<HighLocal> args = new List<HighLocal>();
            HighSsaRegister thisReg = new HighSsaRegister(HighValueType.ReferenceValue, mdType, null);

            List<HighInstruction> entryInstrs = new List<HighInstruction>();
            entryInstrs.Add(new Rpa.Instructions.LoadLocalInstruction(null, thisReg, thisLocal));

            foreach (MethodSignatureParam param in delegateMethodSignature.ParamTypes)
            {
                switch (param.TypeOfType.Value)
                {
                    case MethodSignatureParamTypeOfType.Values.ByRef:
                        {
                            HighSsaRegister paramSsa = new HighSsaRegister(HighValueType.ManagedPtr, param.Type, null);
                            HighLocal local = new HighLocal(param.Type, HighLocal.ETypeOfType.ByRef);
                            args.Add(local);
                            entryInstrs.Add(new Rpa.Instructions.LoadLocalInstruction(null, paramSsa, local));
                            loadedParams.Add(paramSsa);
                        }
                        break;
                    case MethodSignatureParamTypeOfType.Values.Value:
                        {
                            bool isValueType = compiler.TypeIsValueType(param.Type);
                            HighSsaRegister paramSsa = new HighSsaRegister(isValueType ? HighValueType.ValueValue : HighValueType.ReferenceValue, param.Type, null);
                            HighLocal local = new HighLocal(param.Type, HighLocal.ETypeOfType.Value);
                            args.Add(local);
                            entryInstrs.Add(new Rpa.Instructions.LoadLocalInstruction(null, paramSsa, local));
                            loadedParams.Add(paramSsa);
                        }
                        break;
                    case MethodSignatureParamTypeOfType.Values.TypedByRef:
                        throw new NotImplementedException();
                    default:
                        throw new Exception();
                }
            }

            HighSsaRegister returnValue = null;
            if (!(delegateMethodSignature.RetType is TypeSpecVoidTag))
            {
                bool isValueType = compiler.TypeIsValueType(delegateMethodSignature.RetType);
                returnValue = new HighSsaRegister(isValueType ? HighValueType.ValueValue : HighValueType.ReferenceValue, delegateMethodSignature.RetType, null);
            }

            TypeSpecClassTag nativeUIntType = m_vtCache.GetSystemUIntPtrType(compiler);
            HighSsaRegister numDelegatesValue = new HighSsaRegister(HighValueType.ValueValue, nativeUIntType, null);
            HighSsaRegister zeroNativeUIntConstant = new HighSsaRegister(HighValueType.ConstantValue, nativeUIntType, (ulong)0);

            HighCfgNodeHandle entryHdl = new HighCfgNodeHandle();
            HighCfgNodeHandle loopCallHdl = new HighCfgNodeHandle();
            HighCfgNodeHandle loopIncrementHdl = new HighCfgNodeHandle();
            HighCfgNodeHandle returnHdl = new HighCfgNodeHandle();

            HighSsaRegister postIncrementReg = new HighSsaRegister(HighValueType.ValueValue, nativeUIntType, null);

            entryInstrs.Add(new Instructions.GetMulticastDelegateInvocationCountInstruction(null, numDelegatesValue, thisReg));
            entryInstrs.Add(new Rpa.Instructions.BranchInstruction(null, loopCallHdl));

            entryHdl.Value = new HighCfgNode(entryInstrs.ToArray());

            HighSsaRegister currentCountReg = new HighSsaRegister(HighValueType.ValueValue, nativeUIntType, null);

            {
                List<HighInstruction> instrs = new List<HighInstruction>();
                HighSsaRegister delegateValue = new HighSsaRegister(HighValueType.ReferenceValue, m_dt, null);

                HighInstruction callInstr = new Instructions.CallRloVirtualMethodInstruction(null, vtableSlotIndex, returnValue, thisReg, loadedParams.ToArray());
                callInstr.ContinuationEdge = new HighCfgEdge(callInstr, loopIncrementHdl);

                instrs.Add(callInstr);

                HighPhiLink[] loopLinks = new HighPhiLink[] {
                    new HighPhiLink(entryHdl, zeroNativeUIntConstant),
//.........这里部分代码省略.........
开发者ID:elasota,项目名称:clarity,代码行数:101,代码来源:GMMulticastDelegateInvoke.cs

示例3: GenerateMethod

        public override RloMethod GenerateMethod(Compiler compiler, MethodInstantiationPath instantiationPath)
        {
            VTableGenerationCache vtCache = m_vtCache;
            HighTypeDef typeDef = compiler.GetTypeDef(m_bt.ContainedType.TypeName);

            switch (typeDef.Semantics)
            {
                case TypeSemantics.Enum:
                case TypeSemantics.Struct:
                    break;
                default:
                    throw new ArgumentException("Unknown method type");
            }

            CliClass cls = compiler.GetClosedClass(m_bt.ContainedType);

            HighLocal instanceLocal = new HighLocal(m_bt, HighLocal.ETypeOfType.Value);
            HighLocal[] args = new HighLocal[] { new HighLocal(vtCache.GetSystemObjectType(compiler), HighLocal.ETypeOfType.Value) };
            HighLocal[] locals = new HighLocal[0];

            HighCfgNodeHandle returnFalseHdl = new HighCfgNodeHandle();

            HighCfgNodeHandle entryHdl = new HighCfgNodeHandle();
            HighCfgNodeHandle getOtherTypeHdl = new HighCfgNodeHandle();
            HighCfgNodeHandle checkTypeHdl = new HighCfgNodeHandle();
            HighCfgNodeHandle unboxThisHdl = new HighCfgNodeHandle();
            HighCfgNodeHandle unboxOtherHdl = new HighCfgNodeHandle();
            HighCfgNodeHandle nextFieldCheckHdl = new HighCfgNodeHandle();

            HighSsaRegister thisRef = new HighSsaRegister(HighValueType.ReferenceValue, vtCache.GetSystemObjectType(compiler), null);
            HighSsaRegister otherRef = new HighSsaRegister(HighValueType.ReferenceValue, vtCache.GetSystemObjectType(compiler), null);

            HighSsaRegister thisType = new HighSsaRegister(HighValueType.ReferenceValue, vtCache.GetSystemTypeType(compiler), null);
            HighSsaRegister otherType = new HighSsaRegister(HighValueType.ReferenceValue, vtCache.GetSystemTypeType(compiler), null);
            HighSsaRegister unboxedThisPtr = new HighSsaRegister(HighValueType.ManagedPtr, m_bt.ContainedType, null);
            HighSsaRegister unboxedOtherPtr = new HighSsaRegister(HighValueType.ManagedPtr, m_bt.ContainedType, null);

            TypeSpecClassTag boolType = vtCache.GetSystemBoolType(compiler);

            {
                List<HighInstruction> instrs = new List<HighInstruction>();
                instrs.Add(new Rpa.Instructions.LoadLocalInstruction(null, thisRef, instanceLocal));
                instrs.Add(new Rpa.Instructions.LoadLocalInstruction(null, otherRef, args[0]));
                instrs.Add(new Rpa.Instructions.BranchRefNullInstruction(null, otherRef, returnFalseHdl, getOtherTypeHdl));
                entryHdl.Value = new HighCfgNode(new HighCfgNodeHandle[0], new HighPhi[0], instrs.ToArray());
            }

            {
                List<HighInstruction> instrs = new List<HighInstruction>();
                Instructions.CallRloInstanceMethodInstruction callInstr = new Instructions.CallRloInstanceMethodInstruction(null, vtCache.GetSystemObjectGetType(compiler), otherType, otherRef, new HighSsaRegister[0]);
                callInstr.ContinuationEdge = new HighCfgEdge(callInstr, checkTypeHdl);
                instrs.Add(callInstr);
                getOtherTypeHdl.Value = new HighCfgNode(new HighCfgNodeHandle[0], new HighPhi[0], instrs.ToArray());
            }

            {
                List<HighInstruction> instrs = new List<HighInstruction>();
                instrs.Add(new Rpa.Instructions.GetTypeInfoInstruction(null, thisType, m_bt.ContainedType));
                instrs.Add(new Rpa.Instructions.BranchCompareRefsInstruction(null, thisType, otherType, unboxThisHdl, returnFalseHdl));
                checkTypeHdl.Value = new HighCfgNode(new HighCfgNodeHandle[0], new HighPhi[0], instrs.ToArray());
            }

            {
                List<HighInstruction> instrs = new List<HighInstruction>();
                Rpa.Instructions.UnboxPtrInstruction unboxInstr = new Rpa.Instructions.UnboxPtrInstruction(null, unboxedThisPtr, thisRef);
                unboxInstr.ContinuationEdge = new HighCfgEdge(unboxInstr, unboxOtherHdl);
                instrs.Add(unboxInstr);
                unboxThisHdl.Value = new HighCfgNode(new HighCfgNodeHandle[0], new HighPhi[0], instrs.ToArray());
            }

            {
                List<HighInstruction> instrs = new List<HighInstruction>();
                Rpa.Instructions.UnboxPtrInstruction unboxInstr = new Rpa.Instructions.UnboxPtrInstruction(null, unboxedOtherPtr, otherRef);
                unboxInstr.ContinuationEdge = new HighCfgEdge(unboxInstr, nextFieldCheckHdl);
                instrs.Add(unboxInstr);
                unboxOtherHdl.Value = new HighCfgNode(new HighCfgNodeHandle[0], new HighPhi[0], instrs.ToArray());
            }

            if ((vtCache.GetClassPodFlags(compiler, cls) & VTableGenerationCache.PodFlags.Equality) != VTableGenerationCache.PodFlags.None)
            {
                HighCfgNodeHandle nextHdl = new HighCfgNodeHandle();
                List<HighInstruction> instrs = new List<HighInstruction>();
                instrs.Add(new Instructions.BranchComparePodInstruction(null, unboxedThisPtr, unboxedOtherPtr, nextHdl, returnFalseHdl));
                nextFieldCheckHdl.Value = new HighCfgNode(new HighCfgNodeHandle[0], new HighPhi[0], instrs.ToArray());

                nextFieldCheckHdl = nextHdl;
            }
            else
            {
                foreach (HighField fld in cls.InstanceFields)
                {
                    HighCfgNodeHandle nextHdl = new HighCfgNodeHandle();

                    TypeSpecTag fldType = fld.Type;
                    HighSsaRegister thisFldPtr = new HighSsaRegister(HighValueType.ManagedPtr, fldType, null);
                    HighSsaRegister otherFldPtr = new HighSsaRegister(HighValueType.ManagedPtr, fldType, null);

                    {
                        List<HighInstruction> instrs = new List<HighInstruction>();
                        instrs.Add(new Rpa.Instructions.PtrFieldInstruction(null, thisFldPtr, unboxedThisPtr, fld.Name));
//.........这里部分代码省略.........
开发者ID:elasota,项目名称:clarity,代码行数:101,代码来源:GMBoxedValueTypeEquals.cs


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