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


C# XTypeReference.TryResolve方法代码示例

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


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

示例1: Box

        /// <summary>
        /// Create code to box the given source value into the given type.
        /// </summary>
        public static RLRange Box(this IRLBuilder builder, ISourceLocation sequencePoint, RegisterSpec source, XTypeReference type, DexTargetPackage targetPackage, IRegisterAllocator frame)
        {
            if (type.IsPrimitive)
            {
                if (type.IsByte()) builder.Add(sequencePoint, RCode.Int_to_byte, source.Register, source.Register);
                else if (type.IsUInt16()) builder.Add(sequencePoint, RCode.Int_to_short, source.Register, source.Register);
                // Call appropriate valueOf method
                var boxedType = type.Module.TypeSystem.Object;
                var r = frame.AllocateTemp(boxedType.GetReference(targetPackage));
                var call = builder.Add(sequencePoint, RCode.Invoke_static, type.GetBoxValueOfMethod(), source.Registers);
                var last = builder.Add(sequencePoint, RCode.Move_result_object, r);
                return new RLRange(call, last, r);
            }
            if (type.IsGenericParameter)
            {
                var nop = builder.Add(sequencePoint, RCode.Nop);
                return new RLRange(nop, source);
            }
            XTypeDefinition typeDef ;
            if (type.TryResolve(out typeDef) && (typeDef.IsEnum))
            {
                // Call appropriate valueOf method
                /*var boxedType = type.Module.TypeSystem.Object;
                var r = frame.AllocateTemp(boxedType.GetReference(target, nsConverter));
                var call = builder.Add(sequencePoint, RCode.Invoke_static, typeDef.GetEnumUnderlyingType().GetBoxValueOfMethod(), source.Registers);
                var last = builder.Add(sequencePoint, RCode.Move_result_object, r);
                return new RLRange(call, last, r);*/
            }

            // Just cast
            var checkCast = builder.Add(sequencePoint, RCode.Check_cast, type.GetReference(targetPackage), source);
            return new RLRange(checkCast, source);
        }
开发者ID:rfcclub,项目名称:dot42,代码行数:36,代码来源:RLBuilder.cs

示例2: OpcodeForType

        /// <summary>
        /// Generate an Add opcode.
        /// </summary>
        private static RCode OpcodeForType(XTypeReference type, RCode[] opcodes)
        {
            if (type.IsInt32() || type.IsUInt32() || type.IsInt16() || type.IsUInt16() || type.IsChar() || type.IsByte() || type.IsSByte() || type.IsBoolean()) return opcodes[0];
            if (type.IsInt64() || type.IsUInt64()) return opcodes[1];
            if (type.IsFloat()) return opcodes[2];
            if (type.IsDouble()) return opcodes[3];

            XTypeDefinition typeDef;
            if (type.TryResolve(out typeDef))
            {
                if (typeDef.IsEnum)
                {
                    return OpcodeForType(typeDef.GetEnumUnderlyingType(), opcodes);
                }
            }

            throw new ArgumentException("Unsupported type " + type);
        }
开发者ID:Xtremrules,项目名称:dot42,代码行数:21,代码来源:RCode.cs

示例3: OperandFitsInType

 static bool OperandFitsInType(XTypeReference type, int num)
 {
     XTypeDefinition typeDef;
     if (type.TryResolve(out typeDef) && typeDef.IsEnum)
     {
         type = typeDef.Fields.Single(f => f.IsRuntimeSpecialName && !f.IsStatic).FieldType;
     }
     switch (type.Kind)
     {
         case XTypeReferenceKind.SByte:
             return sbyte.MinValue <= num && num <= sbyte.MaxValue;
         case XTypeReferenceKind.Short:
             return short.MinValue <= num && num <= short.MaxValue;
         case XTypeReferenceKind.Byte:
             return byte.MinValue <= num && num <= byte.MaxValue;
         case XTypeReferenceKind.Char:
             return char.MinValue <= num && num <= char.MaxValue;
         case XTypeReferenceKind.UShort:
             return ushort.MinValue <= num && num <= ushort.MaxValue;
         default:
             return true;
     }
 }
开发者ID:rfcclub,项目名称:dot42,代码行数:23,代码来源:TypeAnalysis.cs

示例4: IsSigned

 static bool? IsSigned(XTypeReference type)
 {
     if (type == null || IsArrayPointerOrReference(type))
         return null;
     // unfortunately we cannot rely on type.IsValueType here - it's not set when the instruction operand is a typeref (as opposed to a typespec)
     XTypeDefinition typeDef;
     if (type.TryResolve(out typeDef) && typeDef.IsEnum)
     {
         var underlyingType = typeDef.Fields.Single(f => f.IsRuntimeSpecialName && !f.IsStatic).FieldType;
         return IsSigned(underlyingType);
     }
     switch (type.Kind)
     {
         case XTypeReferenceKind.SByte:
         case XTypeReferenceKind.Short:
         case XTypeReferenceKind.Int:
         case XTypeReferenceKind.Long:
         case XTypeReferenceKind.IntPtr:
             return true;
         case XTypeReferenceKind.Byte:
         case XTypeReferenceKind.Char:
         case XTypeReferenceKind.UShort:
         case XTypeReferenceKind.UInt:
         case XTypeReferenceKind.ULong:
         case XTypeReferenceKind.UIntPtr:
             return false;
         default:
             return null;
     }
 }
开发者ID:rfcclub,项目名称:dot42,代码行数:30,代码来源:TypeAnalysis.cs

示例5: IsEnum

 public static bool IsEnum(XTypeReference type)
 {
     // Arrays/Pointers/ByReference resolve to their element type, but we don't want to consider those to be enums
     // However, GenericInstanceTypes, ModOpts etc. should be considered enums.
     if (type == null || IsArrayPointerOrReference(type))
         return false;
     // unfortunately we cannot rely on type.IsValueType here - it's not set when the instruction operand is a typeref (as opposed to a typespec)
     XTypeDefinition typeDef;
     return type.TryResolve(out typeDef) && typeDef.IsEnum;
 }
开发者ID:rfcclub,项目名称:dot42,代码行数:10,代码来源:TypeAnalysis.cs

示例6: GetInformationAmount

        private const int NativeInt = 33; // treat native int as between int32 and int64

        private static int GetInformationAmount(XTypeReference type)
        {
            if (type == null)
                return 0;
            if (type.IsValueType && !IsArrayPointerOrReference(type))
            {
                // value type might be an enum
                XTypeDefinition typeDef;
                if (type.TryResolve(out typeDef) && typeDef.IsEnum)
                {
                    var underlyingType = typeDef.Fields.Single(f => f.IsRuntimeSpecialName && !f.IsStatic).FieldType;
                    return GetInformationAmount(underlyingType);
                }
            }
            switch (type.Kind)
            {
                case XTypeReferenceKind.Void:
                    return 0;
                case XTypeReferenceKind.Bool:
                    return 1;
                case XTypeReferenceKind.SByte:
                case XTypeReferenceKind.Byte:
                    return 8;
                case XTypeReferenceKind.Char:
                case XTypeReferenceKind.Short:
                case XTypeReferenceKind.UShort:
                    return 16;
                case XTypeReferenceKind.Int:
                case XTypeReferenceKind.UInt:
                case XTypeReferenceKind.Float:
                    return 32;
                case XTypeReferenceKind.Long:
                case XTypeReferenceKind.ULong:
                case XTypeReferenceKind.Double:
                    return 64;
                case XTypeReferenceKind.IntPtr:
                case XTypeReferenceKind.UIntPtr:
                    return NativeInt;
                default:
                    return 100; // we consider structs/objects to have more information than any primitives
            }
        }
开发者ID:rfcclub,项目名称:dot42,代码行数:44,代码来源:TypeAnalysis.cs


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