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


C# XModel.XTypeReference类代码示例

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


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

示例1: XTypeSpecification

 /// <summary>
 /// Default ctor
 /// </summary>
 protected XTypeSpecification(XTypeReference elementType)
     : base(elementType.Module, false, elementType.GenericParameters.Select(x => x.Name))
 {
     if (elementType == null)
         throw new ArgumentNullException("elementType");
     this.elementType = elementType;
 }
开发者ID:Xtremrules,项目名称:dot42,代码行数:10,代码来源:XTypeSpecification.cs

示例2: UnboxIfGeneric

        private static void UnboxIfGeneric(XTypeReference type, AstExpression node, XTypeSystem typeSystem)
        {
            if (type.IsGenericParameter || type.IsGenericParameterArray())
            {
                var resultType = node.GetResultType();
                if (resultType.IsByReference && !type.IsByReference)
                {
                    var elementType = resultType.ElementType;

                    var clone = new AstExpression(node);
                    node.SetCode(AstCode.SimpleCastclass).SetArguments(clone).Operand = elementType;
                }
                else
                {
                    if (TreatAsStruct(type, resultType))
                    {
                        ConvertUnboxStruct(node, resultType, typeSystem);
                    }
                    else
                    {
                        var clone = new AstExpression(node);
                        node.SetCode(AstCode.UnboxFromGeneric).SetArguments(clone).Operand = type;
                    }
                }
            }
        }
开发者ID:jakesays,项目名称:dot42,代码行数:26,代码来源:GenericsConverter.cs

示例3: XGenericInstanceType

 /// <summary>
 /// Default ctor
 /// </summary>
 public XGenericInstanceType(XTypeReference elementType, IEnumerable<XTypeReference> genericArguments)
     : base(elementType)
 {
     this.genericArguments = genericArguments.ToList().AsReadOnly();
     if (this.genericArguments.Count != GenericParameters.Count)
         throw new ArgumentException("Mismatch in generic parameter/argument count");
 }
开发者ID:Xtremrules,项目名称:dot42,代码行数:10,代码来源:XGenericInstanceType.cs

示例4: 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

示例5: AddGenericDefinitionAnnotationIfGeneric

        /// <summary>
        /// Create a IGnericDefinition annotation and attaches it to the given provider.
        /// TODO: this might better belong somewhere else.
        /// </summary>
        public static void AddGenericDefinitionAnnotationIfGeneric(this IAnnotationProvider provider, XTypeReference xtype, AssemblyCompiler compiler, DexTargetPackage targetPackage, bool forceTypeDefinition=false)
        {
            if (!xtype.IsGenericInstance && !xtype.IsGenericParameter)
                return;

            Annotation annotation = GetGenericDefinitionAnnotationForType(xtype, forceTypeDefinition, compiler, targetPackage);
            if(annotation != null)
                provider.Annotations.Add(annotation);
        }
开发者ID:jakesays,项目名称:dot42,代码行数:13,代码来源:DexAnnotations.cs

示例6: Convert

        /// <summary>
        /// Convert the result of the given node to uint8/uint16 if needed.
        /// </summary>
        private static void Convert(AstExpression node, AstCode convertCode, XTypeReference expectedType)
        {
            // Copy load expression
            var clone = new AstExpression(node);

            // Convert node
            node.Code = convertCode;
            node.SetArguments(clone);
            node.Operand = null;
            node.SetType(expectedType);
        }
开发者ID:rfcclub,项目名称:dot42,代码行数:14,代码来源:ConvertBeforeStoreConversionConverter.cs

示例7: CreateAnnotation

        public static Annotation CreateAnnotation(XTypeReference xtype, bool forceTypeDefinition,
            AssemblyCompiler compiler, DexTargetPackage targetPackage)
        {
            var genericsDefAnnotationClass = compiler.GetDot42InternalType(InternalConstants.GenericDefinitionAnnotation)
                .GetClassReference(targetPackage);

            var annotation = new Annotation
            {
                Type = genericsDefAnnotationClass,
                Visibility = AnnotationVisibility.Runtime
            };

            string s = GetDefinition(xtype, forceTypeDefinition, compiler, targetPackage);
            if (string.IsNullOrEmpty(s)) return null;

            annotation.Arguments.Add(new AnnotationArgument("Definition", s));

            return annotation;
        }
开发者ID:Xtremrules,项目名称:dot42,代码行数:19,代码来源:GenericDefinitionAnnotationFactory.cs

示例8: ConvertIfNeeded

 /// <summary>
 /// Convert the given argument if it does not match the target type.
 /// </summary>
 private static void ConvertIfNeeded(AstExpression arg, XTypeReference targetType)
 {
     var argType = arg.GetResultType();
     if (!targetType.IsSame(argType))
     {
         if (targetType.IsChar())
         {
             if (argType.IsUInt16() || argType.IsByte()) Convert(arg, AstCode.Conv_U2, targetType);
         }
         else if (targetType.IsUInt16())
         {
             if (argType.IsChar() || argType.IsByte()) Convert(arg, AstCode.Int_to_ushort, targetType);
         }
         else if (targetType.IsInt16())
         {
             if (argType.IsChar() || argType.IsByte()) Convert(arg, AstCode.Conv_I2, targetType);
         }
     }
 }
开发者ID:rfcclub,项目名称:dot42,代码行数:22,代码来源:ConvertBeforeStoreConversionConverter.cs

示例9: ConvertIfNeeded

        /// <summary>
        /// Convert the result of the given node to uint8/uint16 if needed.
        /// </summary>
        private static void ConvertIfNeeded(AstExpression node, XTypeReference valueType, AstExpression parent)
        {
            AstCode convCode;
            if (valueType.IsByte())
            {
                // Convert from int to uint8
                convCode = AstCode.Int_to_ubyte;
            }
            else if (valueType.IsUInt16())
            {
                // Convert from int to uint16
                convCode = AstCode.Int_to_ushort;
            }
            else if (valueType.IsChar())
            {
                // Convert from int to uint16
                convCode = AstCode.Conv_U2;
            }
            else
            {
                // Do not convert
                return;
            }

            // Avoid recursion
            if ((parent != null) && (parent.Code == convCode))
                return;

            // Copy load expression
            var clone = new AstExpression(node);

            // Convert node
            node.Code = convCode;
            node.Arguments.Clear();
            node.Arguments.Add(clone);
            node.Operand = null;
            node.InferredType = valueType;
            
            // keep the expected type!
            node.ExpectedType = clone.ExpectedType;
            clone.ExpectedType = valueType;
            
        }
开发者ID:Xtremrules,项目名称:dot42,代码行数:46,代码来源:ConvertAfterLoadConversionConverter.cs

示例10: GetAsEnumerableTMethodName

 /// <summary>
 /// Returns the method name when converting an array to an IEnumerableT in compiler helper.
 /// 
 /// (not sure if this is the best place for this method...)
 /// </summary>
 public static string GetAsEnumerableTMethodName(XTypeReference sourceArrayElementType)
 {
     var convertMethodName = "AsObjectEnumerable";
     if (sourceArrayElementType.IsPrimitive)
     {
         if (sourceArrayElementType.IsBoolean()) convertMethodName = "AsBoolEnumerable";
         else if (sourceArrayElementType.IsByte()) convertMethodName = "AsByteEnumerable";
         else if (sourceArrayElementType.IsSByte()) convertMethodName = "AsSByteEnumerable";
         else if (sourceArrayElementType.IsChar()) convertMethodName = "AsCharEnumerable";
         else if (sourceArrayElementType.IsInt16()) convertMethodName = "AsInt16Enumerable";
         else if (sourceArrayElementType.IsUInt16()) convertMethodName = "AsUInt16Enumerable";
         else if (sourceArrayElementType.IsInt32()) convertMethodName = "AsInt32Enumerable";
         else if (sourceArrayElementType.IsUInt32()) convertMethodName = "AsUInt32Enumerable";
         else if (sourceArrayElementType.IsInt64()) convertMethodName = "AsInt64Enumerable";
         else if (sourceArrayElementType.IsFloat()) convertMethodName = "AsFloatEnumerable";
         else if (sourceArrayElementType.IsDouble()) convertMethodName = "AsDoubleEnumerable";
         else throw new ArgumentOutOfRangeException("Unknown primitive array element type " + sourceArrayElementType);
     }
     return convertMethodName;
 }
开发者ID:Xtremrules,项目名称:dot42,代码行数:25,代码来源:FrameworkReferences.cs

示例11: GetPrimitiveType

 /// <summary>
 /// Gets a primitive type or null if the given type is not primitive.
 /// </summary>
 private static PrimitiveType GetPrimitiveType(XTypeReference type)
 {
     // Handle primitive types
     switch (type.Kind)
     {
         case XTypeReferenceKind.Bool:
             return PrimitiveType.Boolean;
         case XTypeReferenceKind.Char:
             return PrimitiveType.Char;
         case XTypeReferenceKind.Float:
             return PrimitiveType.Float;
         case XTypeReferenceKind.Double:
             return PrimitiveType.Double;
         case XTypeReferenceKind.SByte:
         case XTypeReferenceKind.Byte:
             return PrimitiveType.Byte;
         case XTypeReferenceKind.Short:
         case XTypeReferenceKind.UShort:
             return PrimitiveType.Short;
         case XTypeReferenceKind.Int:
         case XTypeReferenceKind.UInt:
             return PrimitiveType.Int;
         case XTypeReferenceKind.Long:
         case XTypeReferenceKind.ULong:
             return PrimitiveType.Long;
         case XTypeReferenceKind.Void:
             return PrimitiveType.Void;
         case XTypeReferenceKind.IntPtr:
         case XTypeReferenceKind.UIntPtr:
             return PrimitiveType.Int; // Is this correct?
     }
     return null;
 }
开发者ID:rfcclub,项目名称:dot42,代码行数:36,代码来源:XModel.cs

示例12: GetConvertedName

 /// <summary>
 /// Gets the converted name of the given type.
 /// </summary>
 public static string GetConvertedName(XTypeReference type)
 {
     return ConvertTypeName(type.Name);
 }
开发者ID:Xtremrules,项目名称:dot42,代码行数:7,代码来源:NameConverter.cs

示例13: CreateLoadValueSequence

        /// <summary>
        /// Create code to load a value from an annotation interface.
        /// </summary>
        /// <returns>The register(s) holding the value</returns>
        private static Register[] CreateLoadValueSequence(
            ISourceLocation seqp,
            MethodBody body,
            XTypeReference valueType,
            Register annotationReg,
            MethodDefinition getter,
            AssemblyCompiler compiler,
            DexTargetPackage targetPackage,
            out Instruction branchIfNotSet)
        {
            // NOTE: It would be better if we wouldn't get the values as object arrays
            //       but as arrays of the actual type. 
            //       Apparently though the DexWriter will not write our attributes
            //       if they contain arrays not of type object[]. Therefore the 
            //       conversion code below.
            //       All in all it would be much cleaner if we could emit Ast code here
            //       instead of RL code.
            List<Register> result = new List<Register>();

            // get the array.
            Register regObject = body.AllocateRegister(RCategory.Temp, RType.Object);
            Register regIntVal = body.AllocateRegister(RCategory.Temp, RType.Value);
            
            body.Instructions.Add(seqp, RCode.Invoke_interface, getter, annotationReg);
            body.Instructions.Add(seqp, RCode.Move_result_object, regObject);

            // allocate result, initialize to default value.
            if (valueType.IsWide())
            {
                Tuple<Register, Register> regs = body.AllocateWideRegister(RCategory.Temp);
                body.Instructions.Add(seqp, RCode.Const_wide, 0, regs.Item1);
                result.Add(regs.Item1);
                result.Add(regs.Item2);
            }
            else if (valueType.IsPrimitive)
            {
                Register reg = body.AllocateRegister(RCategory.Temp, RType.Value);
                body.Instructions.Add(seqp, RCode.Const, 0, reg);
                result.Add(reg);
            }
            else // object 
            {
                Register reg = body.AllocateRegister(RCategory.Temp, RType.Object);
                body.Instructions.Add(seqp, RCode.Const, 0, reg);
                result.Add(reg);
            }

            // check if value is unset (array length 0) or null (array length 2)
            body.Instructions.Add(seqp, RCode.Array_length, regIntVal, regObject);
            branchIfNotSet = body.Instructions.Add(seqp, RCode.If_eqz, regIntVal);
            body.Instructions.Add(seqp, RCode.Rsub_int, 1, regIntVal, regIntVal);
            var branchOnNull = body.Instructions.Add(seqp, RCode.If_nez, regIntVal);

            // get the (boxed) value
            body.Instructions.Add(seqp, RCode.Const, 0, regIntVal);

            // convert to target type.
            if (valueType.IsArray)
            {
                Register regTmp = body.AllocateRegister(RCategory.Temp, RType.Object);
                Register regType = body.AllocateRegister(RCategory.Temp, RType.Object);
                
                var helper = compiler.GetDot42InternalType(InternalConstants.CompilerHelperName);
                var convertArray = helper.Resolve().Methods.First(p => p.Name == "ConvertArray" && p.Parameters.Count == 2)
                                         .GetReference(targetPackage);
                var underlying = valueType.ElementType.GetReference(targetPackage);

                body.Instructions.Add(seqp, RCode.Aget_object, regTmp, regObject, regIntVal);
                body.Instructions.Add(seqp, RCode.Const_class, underlying, regType);
                body.Instructions.Add(seqp, RCode.Invoke_static, convertArray, regTmp, regType);
                body.Instructions.Add(seqp, RCode.Move_result_object, result[0]);
                body.Instructions.Add(seqp, RCode.Check_cast, valueType.GetReference(targetPackage), result[0]);
            }
            else if (valueType.IsEnum())
            {
                Register regTmp = body.AllocateRegister(RCategory.Temp, RType.Object);
                Register regType = body.AllocateRegister(RCategory.Temp, RType.Object);
                
                var getFromObject = compiler.GetDot42InternalType("Enum").Resolve()
                                            .Methods.Single(p=>p.Name == "GetFromObject")
                                            .GetReference(targetPackage);

                body.Instructions.Add(seqp, RCode.Aget_object, regTmp, regObject, regIntVal);
                body.Instructions.Add(seqp, RCode.Const_class, valueType.GetReference(targetPackage), regType);
                body.Instructions.Add(seqp, RCode.Invoke_static, getFromObject, regType, regTmp);
                body.Instructions.Add(seqp, valueType.MoveResult(), result[0]);
                body.Instructions.Add(seqp, RCode.Check_cast, valueType.GetReference(targetPackage), result[0]);
            }
            else if(!valueType.IsPrimitive)
            {
                body.Instructions.Add(seqp, RCode.Aget_object, result[0], regObject, regIntVal);
                body.Instructions.Add(seqp, RCode.Check_cast, valueType.GetReference(targetPackage), result[0]);
            }
            else
            {
                Register regTmp = body.AllocateRegister(RCategory.Temp, RType.Object);
//.........这里部分代码省略.........
开发者ID:jakesays,项目名称:dot42,代码行数:101,代码来源:AttributeAnnotationInterfaceBuilder.cs

示例14: GetUnboxValueMethod

 /// <summary>
 /// Gets a unbox method for the given primitive type.
 /// </summary>
 internal static MethodReference GetUnboxValueMethod(XTypeReference type, AssemblyCompiler compiler, DexTargetPackage targetPackage, out RCode convertAfterCode)
 {
     var info = Get(type);
     convertAfterCode = info.convertAfterCode;
     var boxingClass = compiler.GetDot42InternalType("Boxing").GetClassReference(targetPackage);
     return new MethodReference(boxingClass, info.unboxMethodName, new Prototype(info.primitiveType, new Parameter(FrameworkReferences.Object, "value")));
 }
开发者ID:Xtremrules,项目名称:dot42,代码行数:10,代码来源:BoxInfo.cs

示例15: UnboxGenericArrayResult

 /// <summary>
 /// Create code to unbox the given source array of boxed type elements resulting from a call into an array of primitive elements.
 /// </summary>
 public static RLRange UnboxGenericArrayResult(this IRLBuilder builder, ISourceLocation sequencePoint, RegisterSpec boxedArray,
                                        XTypeReference type, DexTargetPackage targetPackage, IRegisterAllocator frame, AssemblyCompiler compiler)
 {
     var internalBoxingType = compiler.GetDot42InternalType("Boxing").Resolve();
     var primitiveArray = frame.AllocateTemp(type.GetReference(targetPackage));
     var ilUnboxMethod = internalBoxingType.Methods.First(x => x.Name.StartsWith("Unbox") && (x.Parameters.Count == 1) && (x.ReturnType.IsSame(type, true)));
     var unboxMethod = ilUnboxMethod.GetReference(targetPackage);
     var call = builder.Add(sequencePoint, RCode.Invoke_static, unboxMethod, boxedArray);
     var saveArray = builder.Add(sequencePoint, RCode.Move_result_object, primitiveArray);
     return new RLRange(call, saveArray, primitiveArray);
 }
开发者ID:rfcclub,项目名称:dot42,代码行数:14,代码来源:RLBuilder.cs


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