Esempio n. 1
0
        private static int ComputeSum(ParameterInfo[] parameters, Type[] argTypes)
        {
            Debug.Assert(parameters.Length == argTypes.Length);
            var sum = 0;

            for (var i = 0; i <= parameters.Length - 1; i++)
            {
                sum += ImplicitConverter.GetImplicitConvertScore(argTypes[i], parameters[i].ParameterType);
            }

            return(sum);
        }
Esempio n. 2
0
        public override void Emit(FleeIlGenerator ilg, IServiceProvider services)
        {
            this.myChild.Emit(ilg, services);
            ImplicitConverter.EmitImplicitConvert(this.myChild.ResultType, this.myResultType, ilg);
            var options = (ExpressionOptions)services.GetService(typeof(ExpressionOptions));
            var flag    = !options.IsGeneric;

            if (flag)
            {
                ImplicitConverter.EmitImplicitConvert(this.myResultType, typeof(object), ilg);
            }
            ilg.Emit(OpCodes.Ret);
        }
Esempio n. 3
0
        private void EmitVirtualPropertyLoad(FleeIlGenerator ilg)
        {
            var index = ilg.GetTempLocalIndex(this.myPrevious.ResultType);

            Utility.EmitStoreLocal(ilg, index);
            EmitLoadVariables(ilg);
            ilg.Emit(OpCodes.Ldstr, this.myName);
            Utility.EmitLoadLocal(ilg, index);
            ImplicitConverter.EmitImplicitConvert(this.myPrevious.ResultType, typeof(object), ilg);
            var mi = VariableCollection.GetVirtualPropertyLoadMethod(this.ResultType);

            this.EmitMethodCall(mi, ilg);
        }
Esempio n. 4
0
        protected override Type GetResultType(Type leftType, Type rightType)
        {
            var  binaryResultType   = ImplicitConverter.GetBinaryResultType(leftType, rightType);
            var  overloadedOperator = this.GetOverloadedCompareOperator();
            var  isEqualityOp       = IsOpTypeEqualOrNotEqual(this.myOperation);
            var  flag = (leftType == typeof(string)) & (rightType == typeof(string)) & isEqualityOp;
            Type getResultType;

            if (flag)
            {
                getResultType = typeof(bool);
            }
            else
            {
                var flag2 = overloadedOperator != null;
                if (flag2)
                {
                    getResultType = overloadedOperator.ReturnType;
                }
                else
                {
                    var flag3 = binaryResultType != null;
                    if (flag3)
                    {
                        getResultType = typeof(bool);
                    }
                    else
                    {
                        var flag4 = (leftType == typeof(bool)) & (rightType == typeof(bool)) & isEqualityOp;
                        if (flag4)
                        {
                            getResultType = typeof(bool);
                        }
                        else
                        {
                            var flag5 = this.AreBothChildrenReferenceTypes() & isEqualityOp;
                            if (flag5)
                            {
                                getResultType = typeof(bool);
                            }
                            else
                            {
                                var flag6 = this.AreBothChildrenSameEnum();
                                getResultType = flag6 ? typeof(bool) : null;
                            }
                        }
                    }
                }
            }
            return(getResultType);
        }
Esempio n. 5
0
        private static bool AreValidArgumentsForParameters(Type[] argTypes, ParameterInfo[] parameters)
        {
            Debug.Assert(argTypes.Length == parameters.Length);
            // Match if every given argument is implicitly convertible to the method's corresponding parameter
            for (var i = 0; i <= argTypes.Length - 1; i++)
            {
                if (ImplicitConverter.EmitImplicitConvert(argTypes[i], parameters[i].ParameterType, null) == false)
                {
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 6
0
        private void EmitRegularFunctionInternal(ParameterInfo[] parameters, ExpressionElement[] elements, FleeIlGenerator ilg,
                                                 IServiceProvider services)
        {
            Debug.Assert(parameters.Length == elements.Length, "argument count mismatch");
            var num = parameters.Length - 1;

            for (var i = 0; i <= num; i++)
            {
                var element = elements[i];
                var pi      = parameters[i];
                element.Emit(ilg, services);
                var success = ImplicitConverter.EmitImplicitConvert(element.ResultType, pi.ParameterType, ilg);
                Debug.Assert(success, "conversion failed");
            }
        }
Esempio n. 7
0
        private void EmitArrayLoad(FleeIlGenerator ilg, IServiceProvider services)
        {
            this.myIndexerElement.Emit(ilg, services);
            ImplicitConverter.EmitImplicitConvert(this.myIndexerElement.ResultType, typeof(int), ilg);
            var elementType = this.ResultType;
            var flag        = !elementType.IsValueType;

            if (flag)
            {
                ilg.Emit(OpCodes.Ldelem_Ref);
            }
            else
            {
                this.EmitValueTypeArrayLoad(ilg, elementType);
            }
        }
Esempio n. 8
0
        public override void Emit(FleeIlGenerator ilg, IServiceProvider services)
        {
            var resultType = this.ResultType;

            this.myChild.Emit(ilg, services);
            ImplicitConverter.EmitImplicitConvert(this.myChild.ResultType, resultType, ilg);
            var mi   = Utility.GetSimpleOverloadedOperator("UnaryNegation", resultType, resultType);
            var flag = mi == null;

            if (flag)
            {
                ilg.Emit(OpCodes.Neg);
            }
            else
            {
                ilg.Emit(OpCodes.Call, mi);
            }
        }
Esempio n. 9
0
        private void SetupArrayIndexer()
        {
            this.myIndexerElement = this.myIndexerElements[0];
            var flag = this.myIndexerElements.Count > 1;

            if (flag)
            {
                this.ThrowCompileException("MultiArrayIndexNotSupported", CompileExceptionReason.TypeMismatch);
            }
            else
            {
                var flag2 = !ImplicitConverter.EmitImplicitConvert(this.myIndexerElement.ResultType, typeof(int), null);
                if (flag2)
                {
                    this.ThrowCompileException("ArrayIndexersMustBeOfType", CompileExceptionReason.TypeMismatch, typeof(int).Name);
                }
            }
        }
Esempio n. 10
0
        public override void Emit(FleeIlGenerator ilg, IServiceProvider services)
        {
            var resultType = this.ResultType;
            var flag       = resultType == typeof(bool);

            if (flag)
            {
                this.DoEmitLogical(ilg, services);
            }
            else
            {
                this.myLeftChild.Emit(ilg, services);
                ImplicitConverter.EmitImplicitConvert(this.myLeftChild.ResultType, resultType, ilg);
                this.myRightChild.Emit(ilg, services);
                ImplicitConverter.EmitImplicitConvert(this.myRightChild.ResultType, resultType, ilg);
                EmitBitwiseOperation(ilg, this.myOperation);
            }
        }
Esempio n. 11
0
        protected override Type GetResultType(Type leftType, Type rightType)
        {
            var  flag          = !ImplicitConverter.EmitImplicitNumericConvert(rightType, typeof(int), null);
            Type getResultType = null;

            if (!flag)
            {
                var flag2 = !Utility.IsIntegralType(leftType);
                if (flag2)
                {
                    getResultType = null;
                }
                else
                {
                    switch (Type.GetTypeCode(leftType))
                    {
                    case TypeCode.SByte:
                    case TypeCode.Byte:
                    case TypeCode.Int16:
                    case TypeCode.UInt16:
                    case TypeCode.Int32:
                        getResultType = typeof(int);
                        break;

                    case TypeCode.UInt32:
                        getResultType = typeof(uint);
                        break;

                    case TypeCode.Int64:
                        getResultType = typeof(long);
                        break;

                    case TypeCode.UInt64:
                        getResultType = typeof(ulong);
                        break;

                    default:
                        Debug.Assert(false, "unknown left shift operand");
                        break;
                    }
                }
            }
            return(getResultType);
        }
Esempio n. 12
0
        private void ResolveForCollectionSearch()
        {
            this.myTargetCollectionType = this.GetTargetCollectionType();
            var flag = this.myTargetCollectionType == null;

            if (flag)
            {
                this.ThrowCompileException("SearchArgIsNotKnownCollectionType", CompileExceptionReason.TypeMismatch,
                                           this.myTargetCollectionElement.ResultType.Name);
            }
            var mi    = this.GetCollectionContainsMethod();
            var p     = mi.GetParameters()[0];
            var flag2 = !ImplicitConverter.EmitImplicitConvert(this.myOperand.ResultType, p.ParameterType, null);

            if (flag2)
            {
                this.ThrowCompileException("OperandNotConvertibleToCollectionType", CompileExceptionReason.TypeMismatch,
                                           this.myOperand.ResultType.Name, p.ParameterType.Name);
            }
        }
Esempio n. 13
0
        private bool IsParamArrayMatch(Type[] argTypes, ParameterInfo[] parameters, ParameterInfo paramArrayParameter)
        {
            // Get the count of arguments before the paramArray parameter
            var fixedParameterCount = paramArrayParameter.Position;
            var fixedArgTypes       = new Type[fixedParameterCount];
            var fixedParameters     = new ParameterInfo[fixedParameterCount];

            // Get the argument types and parameters before the paramArray
            Array.Copy(argTypes, fixedArgTypes, fixedParameterCount);
            Array.Copy(parameters, fixedParameters, fixedParameterCount);

            // If the fixed arguments don't match, we are not a match
            if (AreValidArgumentsForParameters(fixedArgTypes, fixedParameters) == false)
            {
                return(false);
            }

            // Get the type of the paramArray
            this.paramArrayElementType = paramArrayParameter.ParameterType.GetElementType();

            // Get the types of the arguments passed to the paramArray
            var paramArrayArgTypes = new Type[argTypes.Length - fixedParameterCount];

            Array.Copy(argTypes, fixedParameterCount, paramArrayArgTypes, 0, paramArrayArgTypes.Length);

            // Check each argument
            foreach (var argType in paramArrayArgTypes)
            {
                if (ImplicitConverter.EmitImplicitConvert(argType, this.paramArrayElementType, null) == false)
                {
                    return(false);
                }
            }

            this.myFixedArgTypes      = fixedArgTypes;
            this.myParamArrayArgTypes = paramArrayArgTypes;

            // They all match, so we are a match
            return(true);
        }
Esempio n. 14
0
        private void EmitConditional(FleeIlGenerator ilg, IServiceProvider services, BranchManager bm)
        {
            var falseLabel = bm.FindLabel("falseLabel");
            var endLabel   = bm.FindLabel("endLabel");

            this.myCondition.Emit(ilg, services);
            var isTemp = ilg.IsTemp;

            if (isTemp)
            {
                bm.AddBranch(ilg, falseLabel);
                ilg.Emit(OpCodes.Brfalse_S, falseLabel);
            }
            else
            {
                var flag = !bm.IsLongBranch(ilg, falseLabel);
                ilg.Emit(flag ? OpCodes.Brfalse_S : OpCodes.Brfalse, falseLabel);
            }
            this.myWhenTrue.Emit(ilg, services);
            ImplicitConverter.EmitImplicitConvert(this.myWhenTrue.ResultType, this.myResultType, ilg);
            var isTemp2 = ilg.IsTemp;

            if (isTemp2)
            {
                bm.AddBranch(ilg, endLabel);
                ilg.Emit(OpCodes.Br_S, endLabel);
            }
            else
            {
                var flag2 = !bm.IsLongBranch(ilg, endLabel);
                ilg.Emit(flag2 ? OpCodes.Br_S : OpCodes.Br, endLabel);
            }
            bm.MarkLabel(ilg, falseLabel);
            ilg.MarkLabel(falseLabel);
            this.myWhenFalse.Emit(ilg, services);
            ImplicitConverter.EmitImplicitConvert(this.myWhenFalse.ResultType, this.myResultType, ilg);
            bm.MarkLabel(ilg, endLabel);
            ilg.MarkLabel(endLabel);
        }
Esempio n. 15
0
        private static void EmitElementArrayLoad(ExpressionElement[] elements, Type arrayElementType, FleeIlGenerator ilg,
                                                 IServiceProvider services)
        {
            LiteralElement.EmitLoad(elements.Length, ilg);
            ilg.Emit(OpCodes.Newarr, arrayElementType);
            var local           = ilg.DeclareLocal(arrayElementType.MakeArrayType());
            var arrayLocalIndex = local.LocalIndex;

            Utility.EmitStoreLocal(ilg, arrayLocalIndex);
            var num = elements.Length - 1;

            for (var i = 0; i <= num; i++)
            {
                Utility.EmitLoadLocal(ilg, arrayLocalIndex);
                LiteralElement.EmitLoad(i, ilg);
                var element = elements[i];
                element.Emit(ilg, services);
                ImplicitConverter.EmitImplicitConvert(element.ResultType, arrayElementType, ilg);
                Utility.EmitArrayStore(ilg, arrayElementType);
            }
            Utility.EmitLoadLocal(ilg, arrayLocalIndex);
        }
Esempio n. 16
0
 public override MethodBase SelectMethod(BindingFlags bindingAttr, MethodBase[] match, Type[] types,
                                         ParameterModifier[] modifiers)
 {
     checked
     {
         MethodBase selectMethod;
         for (var i = 0; i < match.Length; i++)
         {
             var mi         = (MethodInfo)match[i];
             var parameters = mi.GetParameters();
             var leftValid  = ImplicitConverter.EmitImplicitConvert(this.myLeftType, parameters[0].ParameterType, null);
             var rightValid = ImplicitConverter.EmitImplicitConvert(this.myRightType, parameters[1].ParameterType, null);
             var flag       = leftValid & rightValid;
             if (flag)
             {
                 selectMethod = mi;
                 return(selectMethod);
             }
         }
         selectMethod = null;
         return(selectMethod);
     }
 }
Esempio n. 17
0
        private void EmitStringConcat(FleeIlGenerator ilg, IServiceProvider services)
        {
            var        flag = this.AreBothChildrenOfType(typeof(string));
            MethodInfo concatMethodInfo;
            Type       argType;

            if (flag)
            {
                concatMethodInfo = ourStringConcatMethodInfo;
                argType          = typeof(string);
            }
            else
            {
                Debug.Assert(this.IsEitherChildOfType(typeof(string)), "one child must be a string");
                concatMethodInfo = ourObjectConcatMethodInfo;
                argType          = typeof(object);
            }
            this.myLeftChild.Emit(ilg, services);
            ImplicitConverter.EmitImplicitConvert(this.myLeftChild.ResultType, argType, ilg);
            this.myRightChild.Emit(ilg, services);
            ImplicitConverter.EmitImplicitConvert(this.myRightChild.ResultType, argType, ilg);
            ilg.Emit(OpCodes.Call, concatMethodInfo);
        }
Esempio n. 18
0
        private bool IsValidCast(Type sourceType, Type destType)
        {
            var  flag = sourceType == destType;
            bool isValidCast;

            if (flag)
            {
                isValidCast = true;
            }
            else
            {
                var flag2 = destType.IsAssignableFrom(sourceType);
                if (flag2)
                {
                    isValidCast = true;
                }
                else
                {
                    var flag3 = ImplicitConverter.EmitImplicitConvert(sourceType, destType, null);
                    if (flag3)
                    {
                        isValidCast = true;
                    }
                    else
                    {
                        var flag4 = IsCastableNumericType(sourceType) & IsCastableNumericType(destType);
                        if (flag4)
                        {
                            isValidCast = true;
                        }
                        else
                        {
                            var flag5 = sourceType.IsEnum | destType.IsEnum;
                            if (flag5)
                            {
                                isValidCast = this.IsValidExplicitEnumCast(sourceType, destType);
                            }
                            else
                            {
                                var flag6 = this.GetExplictOverloadedOperator(sourceType, destType) != null;
                                if (flag6)
                                {
                                    isValidCast = true;
                                }
                                else
                                {
                                    var isValueType = sourceType.IsValueType;
                                    if (isValueType)
                                    {
                                        isValidCast = false;
                                    }
                                    else
                                    {
                                        var isValueType2 = destType.IsValueType;
                                        if (isValueType2)
                                        {
                                            var interfaces = destType.GetInterfaces();
                                            isValidCast = IsBaseType(destType, sourceType) |
                                                          (Array.IndexOf(interfaces, sourceType) != -1);
                                        }
                                        else
                                        {
                                            isValidCast = this.IsValidExplicitReferenceCast(sourceType, destType);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(isValidCast);
        }