Example #1
0
        public ExpressionElement[] ToArray()
        {
            var arr = new ExpressionElement[this.myElements.Count - 1 + 1];

            this.myElements.CopyTo(arr, 0);
            return(arr);
        }
Example #2
0
        public ArgumentList(ICollection elements)
        {
            var arr = new ExpressionElement[elements.Count - 1 + 1];

            elements.CopyTo(arr, 0);
            this.myElements = arr;
        }
Example #3
0
 private void Configure(ExpressionElement leftChild, ExpressionElement rightChild, object op)
 {
     this.myLeftChild  = leftChild;
     this.myRightChild = rightChild;
     this.GetOperation(RuntimeHelpers.GetObjectValue(op));
     this.ValidateInternal(RuntimeHelpers.GetObjectValue(op));
 }
Example #4
0
        public ConditionalElement(ExpressionElement condition, ExpressionElement whenTrue, ExpressionElement whenFalse)
        {
            this.myCondition = condition;
            this.myWhenTrue  = whenTrue;
            this.myWhenFalse = whenFalse;
            var flag = this.myCondition.ResultType != typeof(bool);

            if (flag)
            {
                this.ThrowCompileException("FirstArgNotBoolean", CompileExceptionReason.TypeMismatch);
            }
            var flag2 = ImplicitConverter.EmitImplicitConvert(this.myWhenFalse.ResultType, this.myWhenTrue.ResultType, null);

            if (flag2)
            {
                this.myResultType = this.myWhenTrue.ResultType;
            }
            else
            {
                var flag3 = ImplicitConverter.EmitImplicitConvert(this.myWhenTrue.ResultType, this.myWhenFalse.ResultType, null);
                if (flag3)
                {
                    this.myResultType = this.myWhenFalse.ResultType;
                }
                else
                {
                    this.ThrowCompileException("NeitherArgIsConvertibleToTheOther", CompileExceptionReason.TypeMismatch,
                                               this.myWhenTrue.ResultType.Name, this.myWhenFalse.ResultType.Name);
                }
            }
        }
Example #5
0
        protected static void EmitChildWithConvert(ExpressionElement child, Type resultType, FleeIlGenerator ilg,
                                                   IServiceProvider services)
        {
            child.Emit(ilg, services);
            var converted = ImplicitConverter.EmitImplicitConvert(child.ResultType, resultType, ilg);

            Debug.Assert(converted, "convert failed");
        }
Example #6
0
        public InElement(ExpressionElement operand, IList listElements)
        {
            this.myOperand = operand;
            var arr = new ExpressionElement[listElements.Count - 1 + 1];

            listElements.CopyTo(arr, 0);
            this.myArguments = new List <ExpressionElement>(arr);
            this.ResolveForListSearch();
        }
Example #7
0
        public void SetChild(ExpressionElement child)
        {
            this.myChild      = child;
            this.myResultType = this.GetResultType(child.ResultType);
            var flag = this.myResultType == null;

            if (flag)
            {
                this.ThrowCompileException("OperationNotDefinedForType", CompileExceptionReason.TypeMismatch,
                                           this.myChild.ResultType.Name);
            }
        }
Example #8
0
        private static void EmitOperand(ExpressionElement operand, ShortCircuitInfo info, FleeIlGenerator ilg,
                                        IServiceProvider services)
        {
            var flag = info.Branches.HasLabel(operand);

            if (flag)
            {
                var leftLabel = info.Branches.FindLabel(operand);
                ilg.MarkLabel(leftLabel);
                MarkBranchTarget(info, leftLabel, ilg);
            }
            operand.Emit(ilg, services);
        }
Example #9
0
        private void EmitParamArrayArguments(ParameterInfo[] parameters, ExpressionElement[] elements, FleeIlGenerator ilg,
                                             IServiceProvider services)
        {
            var fixedParameters = new ParameterInfo[this.myTargetMethodInfo.myFixedArgTypes.Length - 1 + 1];

            Array.Copy(parameters, fixedParameters, fixedParameters.Length);
            var fixedElements = new ExpressionElement[this.myTargetMethodInfo.myFixedArgTypes.Length - 1 + 1];

            Array.Copy(elements, fixedElements, fixedElements.Length);
            this.EmitRegularFunctionInternal(fixedParameters, fixedElements, ilg, services);
            var paramArrayElements = new ExpressionElement[elements.Length - fixedElements.Length - 1 + 1];

            Array.Copy(elements, fixedElements.Length, paramArrayElements, 0, paramArrayElements.Length);
            EmitElementArrayLoad(paramArrayElements, this.myTargetMethodInfo.paramArrayElementType, ilg, services);
        }
Example #10
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);
                }
            }
        }
Example #11
0
        private static void EmitToAssembly(ExpressionElement rootElement, IServiceContainer services)
        {
            var assemblyName = new AssemblyName(EmitAssemblyName);

            var assemblyFileName = $"{EmitAssemblyName}.dll";

            var assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Save);
            var moduleBuilder   = assemblyBuilder.DefineDynamicModule(assemblyFileName, assemblyFileName);

            var mb = moduleBuilder.DefineGlobalMethod("Evaluate", MethodAttributes.Public | MethodAttributes.Static, typeof(T), new[]
            {
                typeof(object),
                typeof(ExpressionContext),
                typeof(VariableCollection)
            });
            var ilg = new FleeIlGenerator(mb.GetILGenerator());

            rootElement.Emit(ilg, services);

            moduleBuilder.CreateGlobalFunctions();
            assemblyBuilder.Save(assemblyFileName);
        }
Example #12
0
        public CastElement(ExpressionElement castExpression, string[] destTypeParts, bool isArray, IServiceProvider services)
        {
            this.myCastExpression = castExpression;
            this.myDestType       = GetDestType(destTypeParts, services);
            var flag = this.myDestType == null;

            if (flag)
            {
                this.ThrowCompileException("CouldNotResolveType", CompileExceptionReason.UndefinedName,
                                           GetDestTypeString(destTypeParts, isArray));
            }
            if (isArray)
            {
                this.myDestType = this.myDestType.MakeArrayType();
            }
            var flag2 = !this.IsValidCast(this.myCastExpression.ResultType, this.myDestType);

            if (flag2)
            {
                this.ThrowInvalidCastException();
            }
        }
Example #13
0
        private bool FindIndexer(Type targetType)
        {
            var members = targetType.GetDefaultMembers();
            var methods = new List <MethodInfo>();
            var array   = members;

            checked
            {
                for (var i = 0; i < array.Length; i++)
                {
                    var mi   = array[i];
                    var pi   = mi as PropertyInfo;
                    var flag = pi != null;
                    if (flag)
                    {
                        methods.Add(pi.GetGetMethod(true));
                    }
                }
                var func = new FunctionCallElement("Indexer", methods.ToArray(), this.myIndexerElements);
                func.Resolve(this.myServices);
                this.myIndexerElement = func;
                return(true);
            }
        }
Example #14
0
 public ExpressionMemberElement(ExpressionElement element)
 {
     this.myElement = element;
 }
Example #15
0
 public LocalBasedElement(ExpressionElement target, int index)
 {
     this.MyTarget = target;
     this.MyIndex  = index;
 }
Example #16
0
 protected static bool IsChildOfType(ExpressionElement child, Type t)
 {
     return(child.ResultType == t);
 }
Example #17
0
 public void Initialize(ExpressionElement leftChild, ExpressionElement rightChild, LogicalCompareOperation op)
 {
     this.myLeftChild  = leftChild;
     this.myRightChild = rightChild;
     this.myOperation  = op;
 }
Example #18
0
 public RootExpressionElement(ExpressionElement child, Type resultType)
 {
     this.myChild      = child;
     this.myResultType = resultType;
     this.Validate();
 }
Example #19
0
 public InElement(ExpressionElement operand, ExpressionElement targetCollection)
 {
     this.myOperand = operand;
     this.myTargetCollectionElement = targetCollection;
     this.ResolveForCollectionSearch();
 }