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


C# AstExpression.GetResultType方法代码示例

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


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

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

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

示例3: OpcodeForType

 /// <summary>
 /// Generate an Add opcode.
 /// </summary>
 private static RCode OpcodeForType(AstExpression expr, RCode[] opcodes)
 {
     return OpcodeForType(expr.GetResultType(), opcodes);
 }
开发者ID:Xtremrules,项目名称:dot42,代码行数:7,代码来源:RCode.cs

示例4: BoxIfGeneric

        private static void BoxIfGeneric(XTypeReference type, AstExpression node)
        {
            // TODO: CLR allows return-by-reference, though C# does not. Do we need to handle this here?

            if (type.IsGenericParameter)
            {
                var resultType = node.GetResultType();
                if (resultType.IsPrimitive)
                {
                    var clone = new AstExpression(node);
                    node.SetCode(AstCode.BoxToGeneric)
                                .SetArguments(clone)
                                .Operand = type;
                }
            }
            else if (type.IsGenericParameterArray())
            {
                var resultType = node.GetResultType().ElementType;
                if (resultType.IsPrimitive)
                {
                    var clone = new AstExpression(node);
                    node.SetCode(AstCode.BoxToGeneric).SetArguments(clone).Operand = type;
                }
            }
        }
开发者ID:Xtremrules,项目名称:dot42,代码行数:25,代码来源:GenericsConverter.cs

示例5: ConvertToByRefArray

        /// <summary>
        /// Convert the given node to a array creation operation with given element type and argument.
        /// </summary>
        private static void ConvertToByRefArray(AstExpression node, XTypeReference elementType, AstExpression argument, AstExpression storeArgument, bool isOut, bool argIsGenParam, XModule assembly)
        {
            var arrayElementType = argIsGenParam ? assembly.TypeSystem.Object : elementType;

            if (argIsGenParam && ((!isOut) || (elementType == null) || !elementType.IsSame(argument.GetResultType())))
            {
                argument = new AstExpression(node.SourceLocation, AstCode.Box, elementType, argument);
            }

            node.Code = isOut ? AstCode.ByRefOutArray : AstCode.ByRefArray;
            node.Operand = arrayElementType;
            node.InferredType = new XByReferenceType(arrayElementType);
            node.ExpectedType = new XByReferenceType(arrayElementType);
            node.Arguments.Clear();
            node.Arguments.Add(argument);
            node.StoreByRefExpression = storeArgument;
        }
开发者ID:rfcclub,项目名称:dot42,代码行数:20,代码来源:PrimitiveAddressOfConverter.cs

示例6: VisitExpression

        /// <summary>
        /// Generate code for the given expression.
        /// </summary>
        private RLRange VisitExpression(AstExpression node, List<RLRange> args, AstNode parent)
        {

            switch (node.Code)
            {
                case AstCode.Nop:
                case AstCode.Endfinally:
                case AstCode.Endfilter:
                    return new RLRange(this.Add(node.SourceLocation, RCode.Nop), null);
                case AstCode.Ldexception:
                    throw new InvalidOperationException("ldexception should not occur");
                case AstCode.Dup:
                    return new RLRange(this.Add(node.SourceLocation, RCode.Nop), args[0].Result);

                    #region Constants

                case AstCode.Ldc_I4:
                case AstCode.Ldc_R4:
                    {
                        var type = node.GetResultType();
                        var converter = type.ConstValueConverter(true);
                        var value = converter(node.Operand);
                        var r = frame.AllocateTemp(type.IsFloat() ? PrimitiveType.Float : PrimitiveType.Int);
                        var first = this.Add(node.SourceLocation, RCode.Const, value, r);
                        return new RLRange(first, r);
                    }
                case AstCode.Ldc_I8:
                case AstCode.Ldc_R8:
                    {
                        var type = node.GetResultType();
                        var converter = type.ConstValueConverter(false);
                        var value = converter(node.Operand);
                        var r = frame.AllocateTemp(type.IsDouble() ? PrimitiveType.Double : PrimitiveType.Long);
                        return new RLRange(args, this.Add(node.SourceLocation, RCode.Const_wide, value, r), r);
                    }
                case AstCode.Ldnull:
                    {
                        //Debugger.Launch();
                        var r = frame.AllocateTemp(node.GetResultType().GetReference(targetPackage));
                        return new RLRange(args, this.Add(node.SourceLocation, RCode.Const, 0, r), r);
                    }
                case AstCode.Ldstr:
                    {
                        var str = (string) node.Operand;
                        var r = frame.AllocateTemp(node.GetResultType().GetReference(targetPackage));
                        return new RLRange(args, this.Add(node.SourceLocation, RCode.Const_string, str, r), r);
                    }
                case AstCode.DefaultValue:
                    {
                        var type = (XTypeReference) node.Operand;
                        if (type.IsPrimitive)
                        {
                            var r = frame.AllocateTemp(type.GetReference(targetPackage));
                            return new RLRange(args, this.Add(node.SourceLocation, node.Arguments[0].Const(), 0, r), r);
                        }
                        if (type.IsEnum())
                        {
                            var r = frame.AllocateTemp(type.GetReference(targetPackage));
                            var denumType = type.GetClassReference(targetPackage);
                            var defaultField = new FieldReference(denumType, NameConstants.Enum.DefaultFieldName, denumType);
                            return new RLRange(this.Add(node.SourceLocation, RCode.Sget_object, defaultField, r), r);
                        }
                        else
                        {
                            var r = frame.AllocateTemp(type.GetReference(targetPackage));
                            return new RLRange(args, this.Add(node.SourceLocation, RCode.Const, 0, r), r);
                        }
                    }
                case AstCode.TypeOf:
                    {
                        var type = (XTypeReference) node.Operand;
                        var dtype = type.IsVoid() ? PrimitiveType.Void : type.GetReference(targetPackage);
                        var typeReg = frame.AllocateTemp(FrameworkReferences.Class);
                        var first = this.Add(node.SourceLocation, RCode.Const_class, dtype, typeReg);
                        return new RLRange(first, typeReg);
                    }
                case AstCode.BoxedTypeOf:
                    {
                        var type = (XTypeReference) node.Operand;
                        var typeReg = frame.AllocateTemp(FrameworkReferences.Class);
                        var first = this.Add(node.SourceLocation, RCode.Const_class, type.GetBoxedType(), typeReg);
                        return new RLRange(first, typeReg);
                    }

                    #endregion

                    #region Arithmetic

                case AstCode.Neg:
                    {
                        var tmp = this.EnsureTemp(node.SourceLocation, args[0].Result, frame);
                        return new RLRange(args, this.Add(node.SourceLocation, node.Neg(), tmp.Result, tmp.Result),
                                           tmp.Result);
                    }
                case AstCode.Not:
                    {
                        var tmp = this.EnsureTemp(node.SourceLocation, args[0].Result, frame);
//.........这里部分代码省略.........
开发者ID:rfcclub,项目名称:dot42,代码行数:101,代码来源:AstCompilerVisitor.Expression.cs

示例7: TryVisitArrayTypeMethodCallExpression

        /// <summary>
        /// Generate code for a call to a method of an array type.
        /// </summary>
        private bool TryVisitArrayTypeMethodCallExpression(AstExpression node, XMethodReference ilMethodRef, List<RLRange> args, AstNode parent, out RLRange result)
        {
            var methodName = ilMethodRef.Name;
            var dimensions = (methodName == "Set") ? args.Count - 2 : args.Count - 1;

            // Get all but last dimensions
            var arr = frame.AllocateTemp(FrameworkReferences.Object);
            var first = this.Add(node.SourceLocation, RCode.Move_object, arr, args[0].Result);
            for (var d = 0; d < dimensions - 1; d++)
            {
                this.Add(node.SourceLocation, RCode.Aget_object, arr, arr, args[d + 1].Result);
            }

            // Get/Set value
            switch (methodName)
            {
                case "Get":
                    {
                        var valueType = node.GetResultType();
                        var lastIndexArg = args[args.Count - 1];
                        var agetCode = new XArrayType(valueType).AGet();
                        var resultReg = frame.AllocateTemp(valueType.GetReference(targetPackage));
                        var last = this.Add(node.SourceLocation, agetCode, resultReg, arr, lastIndexArg.Result);
                        result = new RLRange(first, last, resultReg);
                        return true;
                    }
                case "Set":
                    {
                        var valueType = node.Arguments[node.Arguments.Count - 1].GetResultType();
                        var lastIndexArg = args[args.Count - 2];
                        var aputCode = new XArrayType(valueType).APut();

                        // Perform type conversion if needed
                        bool isConverted;
                        var valueR = args[args.Count - 1].Result;
                        var converted = this.ConvertTypeBeforeStore(node.SourceLocation, valueType, valueType, valueR, targetPackage, frame, compiler, out isConverted);
                        if (isConverted) valueR = converted.Result;
                        
                        var last = this.Add(node.SourceLocation, aputCode, valueR, arr, lastIndexArg.Result);
                        result = new RLRange(first, last, arr);
                        return true;
                    }
                default:
                    result = null;
                    return false;
            }
        }
开发者ID:rfcclub,项目名称:dot42,代码行数:50,代码来源:AstCompilerVisitor.Expression.cs


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