protected sealed override Expression VisitLoop(LoopExpression node) => VisitLoop(node, CurrentExpectedType);
 protected override Expression VisitLoop(LoopExpression node)
 {
     throw new ExpressionParseException(0, $"Invalid expression type in binding expression: {node.NodeType}.");
 }
 protected override Expression VisitLoop(LoopExpression node)
 {
     return(GiveUp(node));
 }
Esempio n. 4
0
 private Variable VisitLoop(LoopExpression node)
 {
     throw new NotSupportedException("Expression of type " + node.NodeType + " is not supported");
     //this.Out("loop { ... }");
 }
Esempio n. 5
0
 protected abstract void WriteLoop(LoopExpression expr);
Esempio n. 6
0
 /// <summary>
 /// Visits the children of the <see cref="T:System.Linq.Expressions.LoopExpression"/>.
 /// </summary>
 /// <returns>
 /// The modified expression, if it or any sub-Expression was modified; otherwise, returns the original
 ///     Expression.
 /// </returns>
 /// <param name="node">
 /// The expression to visit.
 /// </param>
 protected override Expression VisitLoop(LoopExpression node)
 {
     return(this.VisitImplementation(node) ?? base.VisitLoop(node));
 }
 protected override Expression VisitLoop(LoopExpression node) => throw ExpressionNotSupported(node);
Esempio n. 8
0
        public void ToStringTest()
        {
            LoopExpression e = Expression.Loop(Expression.Empty());

            Assert.Equal("loop { ... }", e.ToString());
        }
Esempio n. 9
0
        internal static BlockExpression Build(Type defindType, Type instanceType, Type convertType, Type arrayItemType)
        {
            /*
             *  //defind:IEnumerable<string>    new: List<string>  convert: List<string>
             *  IEnumerable<string> li = new List<string>();
             *  List<string> list = (List<string>)li;
             *
             *  //defind:ArrayList   new:ArrayList   convert: IList/ArrayList
             *   ArrayList v = new ArrayList();
             *   var df = (IList)v;
             */

            Expression[] methodListCall = new Expression[9];

            LabelTarget returnTarget = Expression.Label(defindType, "returnLable");
            Expression  ifReadNullOrArrayLeftReturnNull;

            if (!defindType.IsValueType)
            {
                /*
                 * if (reader.ReadNullOrArrayLeft())
                 *   return null;
                 */
                ifReadNullOrArrayLeftReturnNull = Expression.IfThen(Expression.Call(ExpressionMembers.Reader, JsonReader._ReadNullOrArrayLeft), Expression.Return(returnTarget, Expression.Constant(null, defindType)));
            }
            else
            {
                ifReadNullOrArrayLeftReturnNull = Expression.Call(ExpressionMembers.Reader, JsonReader._ReadArrayLeft);
            }
            methodListCall[0] = ifReadNullOrArrayLeftReturnNull;

            /*
             * List<> list =new List<>();
             */
            NewExpression       listCtor = Expression.New(instanceType);
            ParameterExpression list     = Expression.Variable(defindType, "list");

            methodListCall[1] = Expression.Assign(list, listCtor);

            /*
             * if(reader.ReadBoolArrayRight)
             *       return list;
             */
            methodListCall[2] = (Expression.IfThen(Expression.Call(ExpressionMembers.Reader, JsonReader._ReadBoolArrayRight), Expression.Return(returnTarget, list)));

            /*
             * ICollection<int> iCollec = (ICollection<int>)list;
             * iCollec.Add(ReadInt())
             */
            MethodInfo iCollecAdd = convertType.GetMethod("Add", BindingFlags.Public | BindingFlags.Instance);

            ParameterExpression iCollec = Expression.Variable(convertType, "iDic");

            methodListCall[3] = Expression.Assign(iCollec, Expression.Convert(list, convertType));

            /*
             * int moveNext=1;
             */
            methodListCall[4] = ExpressionMembers.MoveNextAssignOne;

            /*
             * while(moveNext-->0)
             * {}
             */
            LabelTarget    loopBreak      = Expression.Label("loopBreak");
            LoopExpression loopExpression = Expression.Loop(Expression.IfThenElse(ExpressionMembers.MoveNextDecrement,
                                                                                  ReturnFunc <Expression>(() =>
            {
                Expression[] methodCall = new Expression[2];

                /*
                 * list.Add(item);
                 */
                methodCall[0] = Expression.Call(iCollec, iCollecAdd, ExpressionMembers.GetMethodCall(arrayItemType));

                /*
                 * if(reader.ReadBoolComma()==true)
                 *       moveNext++;
                 */
                methodCall[1] = ExpressionMembers.IfReadBoolCommaIsTrueSoMoveNextIncrement;

                return(Expression.Block(methodCall));;
            })
                                                                                  , Expression.Break(loopBreak)));

            methodListCall[5] = Expression.Block(loopExpression, Expression.Label(loopBreak));

            /*
             * reader.ReadArrayRight()
             */
            methodListCall[6] = Expression.Call(ExpressionMembers.Reader, JsonReader._ReadArrayRight);

            /*
             * return list;
             */
            GotoExpression  returnExpression = Expression.Return(returnTarget, list);
            LabelExpression returnLabel      = Expression.Label(returnTarget, list);

            methodListCall[7] = returnExpression;
            methodListCall[8] = returnLabel;

            return(Expression.Block(new[] { iCollec, list, ExpressionMembers.MoveNext }, methodListCall));
        }
 /// <summary>
 /// Visits the children of <see cref="System.Linq.Expressions.LoopExpression"/>.
 /// </summary>
 /// <param name="node">The expression to visit.</param>
 /// <returns>The modified expression, if it or any subexpression was modified; otherwise,
 /// returns the original expression.</returns>
 protected override Expression VisitLoop(LoopExpression node)
 {
     throw new NotSupportedException($"Node type {node.GetType().Name} is not supported.");
 }
Esempio n. 11
0
 protected override Expression VisitLoop(LoopExpression node)
 {
     onReturn();
     return(node);
 }
Esempio n. 12
0
 protected override Expression VisitLoop(LoopExpression node) => throw new ApplicationException();
 private static void CalcHashCodeLoop(LoopExpression node, Context context)
 {
     CalcHashCode(node.Body, context);
     CalcHashCodeLabel(node.ContinueLabel, context);
     CalcHashCodeLabel(node.BreakLabel, context);
 }
Esempio n. 14
0
        public void UpdateSameIsSame()
        {
            LoopExpression loop = Expression.Loop(Expression.Empty(), Expression.Label(), Expression.Label());

            Assert.Same(loop, loop.Update(loop.BreakLabel, loop.ContinueLabel, loop.Body));
        }
Esempio n. 15
0
 public virtual void Visit(LoopExpression expression, TranslationContext context, bool negated = false)
 {
 }
Esempio n. 16
0
        public void UpdateDifferentContinueIsDifferent()
        {
            LoopExpression loop = Expression.Loop(Expression.Empty(), Expression.Label(), Expression.Label());

            Assert.NotSame(loop, loop.Update(loop.BreakLabel, Expression.Label(), loop.Body));
        }
Esempio n. 17
0
 protected internal override Expression VisitLoop(LoopExpression node)
 {
     Out("loop { ... }");
     return(node);
 }
Esempio n. 18
0
 protected override Expression VisitLoop(LoopExpression node)
 {
     throw new NotSupportedException();
 }
Esempio n. 19
0
        internal static BlockExpression Build(Type type)
        {
            Type arrayItemType = type.GetElementType();

            Expression[] methodListCall = new Expression[11];
            LabelTarget  returnTarget   = Expression.Label(type, "returnLable");

            /*
             * if (reader.ReadNullOrArrayLeft())
             *   return null;
             */
            Expression ifReadNullOrArrayLeftReturnNull = Expression.IfThen(Expression.Call(ExpressionMembers.Reader, JsonReader._ReadNullOrArrayLeft), Expression.Return(returnTarget, Expression.Constant(null, type)));

            methodListCall[0] = ifReadNullOrArrayLeftReturnNull;

            /*
             * int arrayLength=reader._GetArrayLength;
             * T[] array=new [arrayLength];
             */
            ParameterExpression arrayLength = Expression.Variable(typeof(int), "arrayLength");

            methodListCall[1] = Expression.Assign(arrayLength, Expression.Call(ExpressionMembers.Reader, JsonReader._GetArrayLength, ExpressionMembers.JsonDeserializeHandler));
            NewExpression       aryCtor = Expression.New(type.GetConstructors()[0], arrayLength);
            ParameterExpression array   = Expression.Variable(type, "array");

            methodListCall[2] = Expression.Assign(array, aryCtor);

            /*
             * if(arrayLength==0)
             *  goto ReadArrayRightLabel;
             */
            LabelTarget readArrayRightLabel = Expression.Label(typeof(void), "ReadArrayRightLabel");

            methodListCall[3] = Expression.IfThen(Expression.Equal(arrayLength, Expression.Constant(0)), Expression.Goto(readArrayRightLabel));

            /*
             * int moveNext=1;
             */
            methodListCall[4] = ExpressionMembers.MoveNextAssignOne;

            /*
             * int idx=0;
             */
            ParameterExpression idx = Expression.Variable(typeof(int), "idx");

            methodListCall[5] = Expression.Assign(idx, Expression.Constant(0));

            /*
             * while(moveNext-->0)
             * {}
             */
            LabelTarget    loopBreak      = Expression.Label("loopBreak");
            LoopExpression loopExpression = Expression.Loop(Expression.IfThenElse(ExpressionMembers.MoveNextDecrement,
                                                                                  ReturnFunc <Expression>(() =>
            {
                Expression[] methodCall = new Expression[3];

                /*
                 * ary[idx]=item;
                 */
                methodCall[0] = Expression.Assign(Expression.ArrayAccess(array, idx), ExpressionMembers.GetMethodCall(arrayItemType));

                /*
                 * if(reader.ReadBoolComma()==true)
                 *       moveNext++;
                 */
                methodCall[1] = ExpressionMembers.IfReadBoolCommaIsTrueSoMoveNextIncrement;

                /*
                 * idx++;
                 */
                methodCall[2] = Expression.PostIncrementAssign(idx);
                return(Expression.Block(methodCall));;
            })
                                                                                  , Expression.Break(loopBreak)));

            methodListCall[6] = Expression.Block(loopExpression, Expression.Label(loopBreak));

            /*
             * ReadArrayRightLabel:
             * reader.ReadArrayRight()
             */
            methodListCall[7] = Expression.Label(readArrayRightLabel);
            methodListCall[8] = Expression.Call(ExpressionMembers.Reader, JsonReader._ReadArrayRight);

            /*
             * return list;
             */
            GotoExpression  returnExpression = Expression.Return(returnTarget, array);
            LabelExpression returnLabel      = Expression.Label(returnTarget, array);

            methodListCall[9]  = returnExpression;
            methodListCall[10] = returnLabel;

            return(Expression.Block(new[] { arrayLength, array, idx, ExpressionMembers.MoveNext }, methodListCall));
        }
 public Expression Adapt(LoopExpression loop) => GetLoopBlock(loop);
 private bool CompareLoop(LoopExpression a, LoopExpression b)
     => Equals(a.BreakLabel, b.BreakLabel)
         && Equals(a.ContinueLabel, b.ContinueLabel)
         && Compare(a.Body, b.Body);
Esempio n. 22
0
 private static string VisitLoop(LoopExpression node)
 {
     throw new NotImplementedException();
 }
Esempio n. 23
0
        internal static BlockExpression Build(Type defindType, Type instanceType, Type convertType, Type keyType, Type valueType)
        {
            /*
             * defind:ExpandoObject    new:ExpandoObject   convert:IDictionary<string, object>
             * ExpandoObject ss = new ExpandoObject();
             * IDictionary<string, object> dic = (IDictionary<string, object>)ss;
             *
             * hashtable
             */


            Expression[] methodDictionaryCall = new Expression[9];

            LabelTarget returnTarget = Expression.Label(defindType, "returnLable");
            Expression  ifReadNullOrObjLeftReturnNull;

            if (!defindType.IsValueType)
            {
                /*
                 * if (reader.ReadNullOrObjLeft())
                 *   return null;
                 */
                ifReadNullOrObjLeftReturnNull = Expression.IfThen(Expression.Call(ExpressionMembers.Reader, JsonReader._ReadNullOrObjLeft), Expression.Return(returnTarget, Expression.Constant(null, defindType)));
            }
            else
            {
                ifReadNullOrObjLeftReturnNull = Expression.Call(ExpressionMembers.Reader, JsonReader._ReadObjLeft);
            }
            methodDictionaryCall[0] = ifReadNullOrObjLeftReturnNull;

            /*
             * Dictionary<> dictionary =new Dictionary<>();
             */
            NewExpression       dictionaryCtor = Expression.New(instanceType);
            ParameterExpression dictionary     = Expression.Variable(defindType, "dictionary");

            methodDictionaryCall[1] = Expression.Assign(dictionary, dictionaryCtor);

            /*
             * if(reader.ReadBoolObjRight)
             *     return dictionary;
             */
            methodDictionaryCall[2] = (Expression.IfThen(Expression.Call(ExpressionMembers.Reader, JsonReader._ReadBoolObjRight), Expression.Return(returnTarget, dictionary)));

            /*
             * IDictionary iDic = dictionary;
             * IDictionary<,> iDic = dictionary;
             */
            MethodInfo          iDicAdd = convertType.GetMethod("Add");
            ParameterExpression iDic    = Expression.Variable(convertType, "iDic");

            methodDictionaryCall[3] = Expression.Assign(iDic, Expression.Convert(dictionary, convertType));

            /*
             * int moveNext=2;
             */
            methodDictionaryCall[4] = ExpressionMembers.MoveNextAssignOne;

            ParameterExpression key   = Expression.Variable(keyType, "key");
            ParameterExpression value = Expression.Variable(valueType, "value");

            /*
             * while(moveNext-->0)
             *  {}
             */
            LabelTarget    loopBreak      = Expression.Label("loopBreak");
            LoopExpression loopExpression = Expression.Loop(Expression.IfThenElse(ExpressionMembers.MoveNextDecrement,
                                                                                  ReturnFunc <Expression>(() =>
            {
                Expression[] methodCall = new Expression[5];

                /*
                 *  ReadKey()
                 */
                methodCall[0] = ExpressionMembers.GenerateKeyValuePairByReadKey(keyType, key);

                /*
                 * reader.ReadColon()
                 */
                methodCall[1] = (Expression.Call(ExpressionMembers.Reader, JsonReader._ReadColon));

                /*
                 * value = ResolveProvider<ValueType>.InvokeGet(reader, handler);
                 */
                methodCall[2] = (Expression.Assign(value, ExpressionMembers.GetMethodCall(valueType)));

                /*
                 * iDic.Add(key,value);
                 */
                methodCall[3] = (Expression.Call(iDic, iDicAdd, key, value));

                /*
                 * if(reader.ReadComma()==true)
                 *       moveNext++;
                 */
                methodCall[4] = (ExpressionMembers.IfReadBoolCommaIsTrueSoMoveNextIncrement);

                return(Expression.Block(methodCall));;
            })
                                                                                  , Expression.Break(loopBreak)));

            methodDictionaryCall[5] = Expression.Block(loopExpression, Expression.Label(loopBreak));

            /*
             * reader.ReadObjRight();
             */
            methodDictionaryCall[6] = Expression.Call(ExpressionMembers.Reader, JsonReader._ReadObjRight);

            /*
             * return dictionary
             */
            GotoExpression  returnExpression = Expression.Return(returnTarget, dictionary);
            LabelExpression returnLabel      = Expression.Label(returnTarget, dictionary);

            methodDictionaryCall[7] = returnExpression;
            methodDictionaryCall[8] = returnLabel;

            return(Expression.Block(new[] { iDic, dictionary, key, value, ExpressionMembers.MoveNext }, methodDictionaryCall));
        }
Esempio n. 24
0
 protected override Expression VisitLoop(LoopExpression node)
 {
     Trace(MethodBase.GetCurrentMethod(), node);
     return(base.VisitLoop(node));
 }
        private static BlockExpression GenerateWhile(ParameterExpression newModel, Type type, CharTries charTries)
        {
            //(state):0==The initial state does not change,1==Capital letters,2==Initial lowercase

            /*
             * char c;
             * while(moveNext-->0)
             * {
             * }
             */
            ParameterExpression firstChar      = Expression.Variable(typeof(char), "firstChar");
            LabelTarget         tailOfMethod   = Expression.Label(typeof(void), "tailOfMethod");
            LabelTarget         whileBreak     = Expression.Label();
            LoopExpression      loopExpression = Expression.Loop(Expression.IfThenElse(ExpressionMembers.MoveNextDecrement,
                                                                                       ReturnFunc <Expression>(() =>
            {
                Expression[] expressions = new Expression[6];

                /*
                 * isArrive=false;
                 */
                expressions[0] = ExpressionMembers.IsArriveAssignFalse;

                /*
                 * 2019-11-10 16:55:31,Add two configuration options of IgnoreJsonKeys and IsIgnoreExtraKeysInJSON
                 */
                expressions[1] = GenerateIgnoreKeys(type, tailOfMethod);

                /*
                 * if(handler.option.GlobalKeyFormat!=null)
                 *     GenerateGlobalKeyFormat()
                 * else
                 *     ReadKey()
                 */
                expressions[2] = Expression.IfThenElse(
                    Expression.NotEqual(Expression.MakeMemberAccess(ExpressionMembers.JsonDeserializeOption, JsonDeserializeOption._GlobalKeyFormat), Expression.Constant(null, JsonDeserializeOption._GlobalKeyFormat.FieldType)),
                    GenerateGlobalKeyFormat(type, newModel, tailOfMethod),
                    GenerateKeyValueObjectReadKey(firstChar, charTries, newModel)
                    );

                /*
                 *  if(!isArrive)
                 *       throw
                 */
                expressions[3] = Expression.IfThen(Expression.Equal(ExpressionMembers.IsArrive, Expression.Constant(false, typeof(bool))), Expression.Throw(Expression.New(JsonDeserializationTypeResolutionException._JsonDeserializationTypeResolutionExceptionCtor, ExpressionMembers.Reader, type.IsInterface ? (Expression)Expression.Constant(type, typeof(Type)) : Expression.Call(newModel, type.GetMethod("GetType")))));

                /*
                 * Label -> tailOfMethod:
                 */
                expressions[4] = Expression.Label(tailOfMethod);

                /*
                 *  if(reader.ReadComma()==true)
                 *      moveNext++;
                 */
                expressions[5] = ExpressionMembers.IfReadBoolCommaIsTrueSoMoveNextIncrement;

                return(Expression.Block(expressions));
            })
                                                                                       , Expression.Break(whileBreak)));

            return(Expression.Block(new[] { firstChar }, loopExpression, Expression.Label(whileBreak)));
        }
 protected virtual Expression VisitLoop(LoopExpression node, Type expectedType)
 => node.Update(VisitLabelTarget(node.BreakLabel, expectedType), VisitLabelTarget(node.ContinueLabel, expectedType), Visit(node.Body, node.Type));
Esempio n. 27
0
 /// <summary>
 /// Visits the children of <see cref="System.Linq.Expressions.LoopExpression"/>.
 /// </summary>
 /// <param name="node">The expression to visit.</param>
 /// <returns>The modified expression, if it or any subexpression was modified; otherwise,
 /// returns the original expression.</returns>
 protected override Expression VisitLoop(LoopExpression node)
 {
     throw new NotSupportedException(string.Format(Resources.EX_PROCESS_NODE_NOT_SUPPORT, node.GetType().Name));
 }
 public LoopExpressionProxy(LoopExpression node) {
     _node = node;
 }
 protected override Expression VisitLoop(LoopExpression node)
 {
     Combine(node.NodeType);
     Combine(node.Type);
     return(base.VisitLoop(node));
 }