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


C# IType.ToNormal方法代码示例

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


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

示例1: GetEnumGetHashCodeMethod

        public static void GetEnumGetHashCodeMethod(
            IType enumType,
            ITypeResolver typeResolver,
            out object[] code,
            out IList<object> tokenResolutions,
            out IList<IType> locals,
            out IList<IParameter> parameters)
        {
            Debug.Assert(enumType.ToNormal().IsEnum, "This is for enum only");

            var codeList = new List<object>();

            codeList.Add(Code.Ldarg_0);
            codeList.AppendInt(Code.Ldfld, 1);
            codeList.Add(Code.Conv_I4);

            // return
            codeList.Add(Code.Ret);

            // End of Code
            // tokens
            tokenResolutions = new List<object>();
            // data
            tokenResolutions.Add(enumType.GetFieldByName("Value", typeResolver));            

            // locals
            locals = new List<IType>();

            // code
            code = codeList.ToArray();

            // parameters
            parameters = new List<IParameter>();
        }
开发者ID:afrog33k,项目名称:csnative,代码行数:34,代码来源:EnumGen.cs

示例2: SynthesizedMethodStringAdapter

 /// <summary>
 /// </summary>
 /// <param name="type">
 /// </param>
 /// <param name="methodName">
 /// </param>
 public SynthesizedMethodStringAdapter(
     string methodName,
     string typeFullName,
     IType returnType,
     IParameter[] parameters = null)
 {
     this.typeFullName = typeFullName;
     this.Type = returnType.ToNormal();
     this.MethodName = methodName;
     this.parameters = parameters;
 }
开发者ID:afrog33k,项目名称:csnative,代码行数:17,代码来源:SynthesizedMethodStringAdapter.cs

示例3: SynthesizedMethodTypeBase

 /// <summary>
 /// </summary>
 /// <param name="type">
 /// </param>
 /// <param name="methodName">
 /// </param>
 public SynthesizedMethodTypeBase(IType type, string methodName)
 {
     this.Type = type.ToNormal();
     this.MethodName = methodName;
 }
开发者ID:afrog33k,项目名称:csnative,代码行数:11,代码来源:SynthesizedMethodTypeBase.cs

示例4: BuildVirtualTable

        /// <summary>
        /// </summary>
        /// <param name="virtualTable">
        /// </param>
        /// <param name="thisType">
        /// </param>
        /// <param name="llvmWriter">
        /// </param>
        public static void BuildVirtualTable(this List<LlvmWriter.Pair<IMethod, IMethod>> virtualTable, IType thisType, LlvmWriter llvmWriter)
        {
            if (thisType.BaseType != null)
            {
                virtualTable.BuildVirtualTable(thisType.BaseType, llvmWriter);
            }

            // get all virtual methods in current type and replace or append
            foreach (var virtualOrAbstractMethod in IlReader.Methods(thisType).Where(m => m.IsVirtual || m.IsAbstract || m.IsOverride))
            {
                if (virtualOrAbstractMethod.IsAbstract && virtualOrAbstractMethod.DeclaringType.Equals(thisType))
                {
                    virtualTable.Add(new LlvmWriter.Pair<IMethod, IMethod> { Key = virtualOrAbstractMethod, Value = virtualOrAbstractMethod });
                    continue;
                }

                // find method in virtual table
                var baseMethod = virtualOrAbstractMethod.IsOverride
                                     ? virtualTable.First(m => m.Key.IsMatchingOverride(virtualOrAbstractMethod))
                                     : virtualTable.FirstOrDefault(m => m.Key.IsMatchingOverride(virtualOrAbstractMethod));

                if (baseMethod == null)
                {
                    virtualTable.Add(new LlvmWriter.Pair<IMethod, IMethod> { Key = virtualOrAbstractMethod, Value = virtualOrAbstractMethod });
                    continue;
                }

                baseMethod.Value = virtualOrAbstractMethod;
            }

            // append custom methods
            // custom GetHashCode for Enums
            if (thisType.ToNormal().IsEnum)
            {
                var getHashCodeMethod = new SynthesizedGetHashCodeMethod(thisType, llvmWriter);
                var baseMethod = virtualTable.First(m => m.Key.IsMatchingOverride(getHashCodeMethod));
                baseMethod.Value = getHashCodeMethod;
            }

            // custom GetType
            // TODO: you need to append it before processing custom methods
            var getTypeMethod = new SynthesizedGetTypeMethod(thisType, llvmWriter);
            var baseGetTypeMethod = virtualTable.FirstOrDefault(m => m.Key.IsMatchingOverride(getTypeMethod));
#if !FOR_MSCORLIBTEST
            Debug.Assert(baseGetTypeMethod != null, "Could not find virtual method GetType (adjust source code and make GetType a virtual method");
#endif
            if (baseGetTypeMethod != null)
            {
                baseGetTypeMethod.Value = getTypeMethod;
            }
        }
开发者ID:SperoSophia,项目名称:il2bc,代码行数:59,代码来源:VirtualTableGen.cs

示例5: WriteLlvmLoad

        /// <summary>
        /// </summary>
        /// <param name="llvmWriter">
        /// </param>
        /// <param name="opCode">
        /// </param>
        /// <param name="typeToLoad">
        /// </param>
        /// <param name="source">
        /// </param>
        /// <param name="appendReference">
        /// </param>
        /// <param name="structAsRef">
        /// </param>
        /// <param name="indirect">
        /// </param>
        public static void WriteLlvmLoad(
            this LlvmWriter llvmWriter,
            OpCodePart opCode,
            IType typeToLoad,
            FullyDefinedReference source,
            bool appendReference = true,
            bool structAsRef = false,
            bool indirect = false)
        {
            // TODO: review the whole proc.
            var writer = llvmWriter.Output;

            var isStruct = typeToLoad.ToNormal().IsStructureType();

            Debug.Assert(
                structAsRef || !isStruct || typeToLoad.IsByRef || isStruct && !typeToLoad.IsByRef && opCode.HasResult);

            if (!isStruct || typeToLoad.IsByRef || structAsRef || !opCode.HasResult || (indirect && !isStruct))
            {
                ////Debug.Assert(source.Type.IsPointer);
                var dereferencedType = source.Type.IsPointer ? source.Type.GetElementType() : null;

                var effectiveSource = source;

                // check if you need bitcast pointer type
                if (!typeToLoad.IsPointer && dereferencedType != null && typeToLoad.TypeNotEquals(dereferencedType))
                {
                    // check if you need cast here
                    llvmWriter.WriteBitcast(opCode, source, typeToLoad);
                    writer.WriteLine(string.Empty);
                    effectiveSource = opCode.Result;
                }

                if (indirect && !source.Type.IsPointer && !source.Type.IsByRef && source.Type.IntTypeBitSize() > 0)
                {
                    // check if you need cast here
                    llvmWriter.WriteIntToPtr(opCode, source, typeToLoad);
                    writer.WriteLine(string.Empty);
                    effectiveSource = opCode.Result;
                }

                llvmWriter.WriteSetResultNumber(opCode, typeToLoad);

                // last part
                writer.Write("load ");
                typeToLoad.WriteTypePrefix(llvmWriter, structAsRef);
                if (appendReference)
                {
                    // add reference to type
                    writer.Write('*');
                }

                writer.Write(' ');
                writer.Write(effectiveSource.ToString());

                // TODO: optional do we need to calculate it propertly?
                writer.Write(", align " + LlvmWriter.PointerSize);
            }
            else
            {
                llvmWriter.WriteCopyStruct(writer, opCode, typeToLoad, source, opCode.Result);
            }
        }
开发者ID:afrog33k,项目名称:csnative,代码行数:79,代码来源:LlvmHelpersGen.cs

示例6: GetEnumToStringMethod

        public static void GetEnumToStringMethod(
                    IType enumType,
                    ITypeResolver typeResolver,
                    out object[] code,
                    out IList<object> tokenResolutions,
                    out IList<IType> locals,
                    out IList<IParameter> parameters)
        {
            Debug.Assert(enumType.ToNormal().IsEnum, "This is for enum only");

            var codeList = new List<object>();

            codeList.Add(Code.Ldarg_0);
            codeList.AppendInt(Code.Ldfld, 1);

            var sizeOfEnum = enumType.GetEnumUnderlyingType().IntTypeBitSize() / 8;

            // build cmp/jmp cases
            var stringValues = 1;
            foreach (var enumConstValue in IlReader.Fields(enumType, typeResolver).Where(f => f.IsConst))
            {
                codeList.Add(Code.Dup);
                if (sizeOfEnum == 8)
                {
                    codeList.AppendULong(
                        Code.Ldc_I8, enumConstValue.ConstantValue.ToString() == "-1" ? 0xffffffffffffffff : Convert.ToUInt64(enumConstValue.ConstantValue));
                }
                else
                {
                    codeList.AppendUInt(Code.Ldc_I4, unchecked((uint)Convert.ToInt64(enumConstValue.ConstantValue)));
                }

                codeList.Add(Code.Bne_Un_S);
                codeList.Add(6);
                codeList.AppendInt(Code.Ldstr, ++stringValues);
                codeList.Add(Code.Ret);
            }

            codeList.Add(Code.Pop);
            codeList.AppendInt(Code.Ldstr, ++stringValues);
            codeList.Add(Code.Ret);

            // End of Code
            // tokens
            tokenResolutions = new List<object>();
            // data
            tokenResolutions.Add(enumType.GetFieldByName("Value", typeResolver));
            foreach (var enumConstValue in IlReader.Fields(enumType, typeResolver).Where(f => f.IsConst))
            {
                tokenResolutions.Add(enumConstValue.Name);
            }

            // default value
            tokenResolutions.Add(string.Empty);

            // locals
            locals = new List<IType>();

            // code
            code = codeList.ToArray();

            // parameters
            parameters = new List<IParameter>();
        }
开发者ID:afrog33k,项目名称:csnative,代码行数:64,代码来源:EnumGen.cs

示例7: SynthesizedValueParameter

 /// <summary>
 /// </summary>
 /// <param name="type">
 /// </param>
 public SynthesizedValueParameter(IType type)
 {
     this.type = type.ToNormal();
 }
开发者ID:SperoSophia,项目名称:il2bc,代码行数:8,代码来源:SynthesizedValueParameter.cs

示例8: WriteInit

        /// <summary>
        /// </summary>
        /// <param name="llvmWriter">
        /// </param>
        /// <param name="opCodePart">
        /// </param>
        /// <param name="declaringTypeIn">
        /// </param>
        /// <param name="objectSource">
        /// </param>
        public static void WriteInit(this LlvmWriter llvmWriter, OpCodePart opCodePart, IType declaringTypeIn, FullyDefinedReference objectSource)
        {
            var writer = llvmWriter.Output;

            var declaringTypeNormal = declaringTypeIn.ToNormal();
            var declaringTypeClass = declaringTypeIn.IsValueType ? declaringTypeIn.ToClass() : declaringTypeIn;

            writer.WriteLine("; Init obj");

            if (declaringTypeNormal.IsValueType)
            {
                llvmWriter.WriteBitcast(opCodePart, objectSource, llvmWriter.ResolveType("System.Byte").ToPointerType());
                writer.WriteLine(string.Empty);

                llvmWriter.WriteMemSet(declaringTypeNormal, opCodePart.Result);
                writer.WriteLine(string.Empty);

                if (declaringTypeNormal.IsStructureType())
                {
                    // init now
                    opCodePart.Result = objectSource;

                    declaringTypeClass.WriteCallInitObjectMethod(llvmWriter, opCodePart);
                    writer.WriteLine(string.Empty);
                }
            }
            else
            {
                // this is type reference, initialize it with null
                llvmWriter.WriteBitcast(opCodePart, objectSource, llvmWriter.ResolveType("System.Byte").ToPointerType().ToPointerType());
                writer.WriteLine(string.Empty);

                writer.WriteLine("store i8* null, i8** {0}", opCodePart.Result);
            }

            writer.Write("; end of init obj");
        }
开发者ID:SperoSophia,项目名称:il2bc,代码行数:47,代码来源:ObjectInfrastructure.cs

示例9: WriteBoxObject

        /// <summary>
        /// </summary>
        /// <param name="llvmWriter">
        /// </param>
        /// <param name="opCode">
        /// </param>
        /// <param name="declaringType">
        /// </param>
        /// <param name="newObjectResult">
        /// </param>
        /// <param name="callInit">
        /// </param>
        public static void WriteBoxObject(
            this LlvmWriter llvmWriter, OpCodePart opCode, IType declaringType, FullyDefinedReference newObjectResult = null, bool callInit = false)
        {
            var writer = llvmWriter.Output;

            var valueLoadResult = opCode.Result;

            var isStruct = declaringType.ToNormal().IsStructureType();

            opCode.Result = null;

            writer.WriteLine("; Boxing");

            writer.WriteLine(string.Empty);
            llvmWriter.CheckIfExternalDeclarationIsRequired(declaringType);

            // call new if null
            if (newObjectResult == null)
            {
                declaringType.WriteCallNewObjectMethod(llvmWriter, opCode);
                newObjectResult = opCode.Result;
            }
            else
            {
                opCode.Result = newObjectResult;
            }

            writer.WriteLine(string.Empty);
            writer.WriteLine("; Copy data");

            if (!isStruct)
            {
                // write access to a field
                if (!llvmWriter.WriteFieldAccess(
                        writer, 
                        opCode, 
                        declaringType.ToClass(), 
                        declaringType.ToClass(), 
                        0, 
                        opCode.Result))
                {
                    writer.WriteLine("; No data");
                    return;
                }

                writer.WriteLine(string.Empty);
            }

            var fieldType = declaringType.ToNormal();

            opCode.OpCodeOperands = new[] { new OpCodePart(OpCodesEmit.Ldarg_0, 0, 0) };
            opCode.OpCodeOperands[0].Result = valueLoadResult;
            if (valueLoadResult == null)
            {
                llvmWriter.ActualWrite(writer, opCode.OpCodeOperands[0]);
            }

            llvmWriter.SaveToField(opCode, fieldType, 0);

            writer.WriteLine(string.Empty);
            writer.WriteLine("; End of Copy data");

            if (callInit)
            {
                opCode.Result = newObjectResult;
                declaringType.WriteCallInitObjectMethod(llvmWriter, opCode);
                writer.WriteLine(string.Empty);
            }

            opCode.Result = newObjectResult.ToClassType();
        }
开发者ID:SperoSophia,项目名称:il2bc,代码行数:83,代码来源:ObjectInfrastructure.cs

示例10: Methods

        /// <summary>
        /// </summary>
        /// <param name="type">
        /// </param>
        /// <param name="flags">
        /// </param>
        /// <returns>
        /// </returns>
        public static IEnumerable<IMethod> Methods(IType type, BindingFlags flags, ITypeResolver typeResolver, bool excludeSpecializations = false)
        {
            Debug.Assert(type != null);

            if (!excludeSpecializations)
            {
                foreach (var method in type.GetMethods(flags).Where(m => !m.IsGenericMethodDefinition))
                {
                    yield return method;
                }
            }
            else
            {
                foreach (var method in type.GetMethods(flags))
                {
                    yield return method;
                }
            }

            if (!excludeSpecializations)
            {
                // TODO: remove if and write code to get info from following synth methods
                // append C# native compiler infrastructure methods
                yield return new SynthesizedGetSizeMethod(type, typeResolver);

                // append internal methods
                yield return new SynthesizedGetTypeMethod(type, typeResolver);
            }

            var normal = type.ToNormal();
            if (normal.IsEnum)
            {
                yield return new SynthesizedEnumGetHashCodeMethod(type, typeResolver);
                yield return new SynthesizedEnumToStringMethod(type, typeResolver);
            }

            // append methods or MultiArray
            if (type.IsMultiArray)
            {
                yield return new SynthesizedMultiDimArrayGetMethod(type, typeResolver);
                yield return new SynthesizedMultiDimArraySetMethod(type, typeResolver);
                yield return new SynthesizedMultiDimArrayAddressMethod(type, typeResolver);
            }
            else if (type.IsArray)
            {
                yield return new SynthesizedSingleDimArrayIListGetEnumeratorMethod(type, typeResolver);
                yield return new SynthesizedSingleDimArrayIListGetCountMethod(type, typeResolver);
                yield return new SynthesizedSingleDimArrayIListGetItemMethod(type, typeResolver);
                yield return new SynthesizedSingleDimArrayIListSetItemMethod(type, typeResolver);
            }
            else if (type.IsString)
            {
                yield return new SynthesizedStrLenMethod(typeResolver);
                yield return new SynthesizedCtorSBytePtrMethod(typeResolver);
                yield return new SynthesizedCtorSBytePtrStartLengthMethod(typeResolver);
                yield return new SynthesizedCtorSBytePtrStartLengthEncodingMethod(typeResolver);
            }

            if (excludeSpecializations)
            {
                yield break;
            }

            // append specialized methods
            IEnumerable<IMethod> genMethodSpecializationForType = null;
            if (genMethodSpec == null || !genMethodSpec.TryGetValue(type, out genMethodSpecializationForType))
            {
                yield break;
            }

            // return Generic Method Specializations for a type
            foreach (var method in
                genMethodSpecializationForType)
            {
                yield return method;
            }
        }
开发者ID:afrog33k,项目名称:csnative,代码行数:85,代码来源:IlReader.cs

示例11: Fields

        /// <summary>
        /// </summary>
        /// <param name="type">
        /// </param>
        /// <param name="flags">
        /// </param>
        /// <returns>
        /// </returns>
        public static IEnumerable<IField> Fields(IType type, BindingFlags flags, ITypeResolver typeResolver)
        {
            Debug.Assert(type != null);

            foreach (var field in type.GetFields(flags))
            {
                yield return field;
            }

            // extra fields
            var normal = type.ToNormal();
            if (normal.IsEnum)
            {
                foreach (var field in EnumGen.GetFields(normal, typeResolver))
                {
                    yield return field;
                }                    
            } 
            else if (type.IsMultiArray)
            {
                // append methods or MultiArray
                foreach (var field in ArrayMultiDimensionGen.GetFields(type, typeResolver)) 
                {
                    yield return field;
                }
            }
            else if (type.IsArray)
            {
                // append methods or MultiArray
                foreach (var field in ArraySingleDimensionGen.GetFields(type, typeResolver))
                {
                    yield return field;
                }
            }
        }
开发者ID:afrog33k,项目名称:csnative,代码行数:43,代码来源:IlReader.cs


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