protected override Expression VisitLabel(LabelExpression node) => node;
/// <summary> /// This API supports the Entity Framework Core infrastructure and is not intended to be used /// directly from your code. This API may change or be removed in future releases. /// </summary> protected override Expression VisitLabel(LabelExpression labelExpression) { _stringBuilder.Append(labelExpression.Target.ToString()); return(labelExpression); }
protected override Expression VisitLabel(LabelExpression node) { return(EvalFunc(VisitLabelFunc, node, base.VisitLabel)); }
/// <inheritdoc /> protected abstract override T VisitLabel(LabelExpression node);
private static void ParseParams(string s, Module m, LSystem l) { //substr to , if exists //if it does //parse the substr //else check for ops //if(ops) //perform op on thing before and thing after //add value to m.params //else add value to m.params //String.Split!!! split on , and we have the array for every element in this array parse it! We don't need recursion this way right?!?!? //Just do it for every string in the split s = s.Replace(" ", ""); string[] sParams = s.Split(','); float val = 0.0f; List <Expression> exps = new List <Expression>(); //Our input f ParameterExpression f = Expression.Parameter(typeof(float[]), "f"); ParameterExpression newFs = Expression.Variable(typeof(float[]), "s"); //Create a new param array based on the number of params we now have //ParameterExpression newFs = Expression.Variable(typeof(float[]), "s"); NewArrayExpression nArray = Expression.NewArrayBounds(typeof(float), Expression.Constant(sParams.Length)); BinaryExpression assignS = Expression.Assign(newFs, nArray); //exps.Add(f); exps.Add(newFs); exps.Add(nArray); exps.Add(assignS); int nArrayIndex = 0; foreach (string p in sParams) { //need to handle not (!) and negative numbers (-1)! int opIndex = p.IndexOfAny(new char[] { '*', '/', '+', '-', '&', '^', '|' }); if (opIndex >= 1) { //setup initial expressions (float[] input, float[] s creation, return s) Might also need a block expression //if temp1 is a char, then MethodCall GetVar(<char>) from lSys //else if temp1 is $<int> then create param from the float[]? //else constant //if temp2 ... //if(either temp1 or 2 isn't const) //create op expression //compile the Expression<Transition>? //set m.Transition to this float temp1 = 0.0f; string str_t1 = p.Substring(0, opIndex); bool isT1 = float.TryParse(str_t1, out temp1); float temp2 = 0.0f; string str_t2 = p.Substring(opIndex + 1); bool isT2 = float.TryParse(str_t2, out temp2); //assuming no other ops and stuff char op = p[opIndex]; if (isT1 && isT2) { if (op == '*') { val = temp1 * temp2; } if (op == '/') { val = temp1 / temp2; } if (op == '+') { val = temp1 + temp2; } if (op == '-') { val = temp1 - temp2; } //if (op == '&') val = temp1 & temp2; //if (op == '^') val = temp1 ^ temp2; //if (op == '|') val = temp1 | temp2; //if (op == '!') val = temp1 ! temp2; Expression e = Expression.Assign(Expression.ArrayAccess(newFs, Expression.Constant(nArrayIndex)), Expression.Constant(val)); exps.Add(e); m.parameters.Add(val); } else { //the param is a transition, add 0.0f to params and build expression tree storing compiled version to trans //Should this maybe go into a method? //going to be using this stuff multiple times //what gets passed? p? or just the substring till or after the op? //returns a list of exprs to add to the list... Expression exp1 = null; Expression exp2 = null; if (!isT1 && !isT2) { //then both are an issue //create exprs for t1 and t2 if (str_t1[0] == '$') { exp1 = Expression.ArrayAccess(f, Expression.Constant(int.Parse(str_t1.Substring(1)))); } else { exp1 = Expression.Call(Expression.Constant(l), typeof(LSystem).GetMethod("GetVar"), Expression.Constant(str_t1)); //Debug.Log(exp1); } if (str_t2[0] == '$') { exp2 = Expression.ArrayAccess(f, Expression.Constant(int.Parse(str_t2.Substring(1)))); } else { exp2 = Expression.Call(Expression.Constant(l), typeof(LSystem).GetMethod("GetVar"), Expression.Constant(str_t2)); } } else if (isT1) { exp1 = Expression.Constant(temp1); if (str_t2[0] == '$') { exp2 = Expression.ArrayAccess(f, Expression.Constant(int.Parse(str_t2.Substring(1)))); } else { exp2 = Expression.Call(Expression.Constant(l), typeof(LSystem).GetMethod("GetVar"), Expression.Constant(str_t2)); } } //then t2 is the issue else { exp2 = Expression.Constant(temp2); if (str_t1[0] == '$') { exp1 = Expression.ArrayAccess(f, Expression.Constant(int.Parse(str_t1.Substring(1)))); } else { exp1 = Expression.Call(Expression.Constant(l), typeof(LSystem).GetMethod("GetVar"), Expression.Constant(str_t1)); //Debug.Log(exp1); } } //t1 is the issue Expression opExp = null; if (op == '*') { opExp = Expression.Multiply(exp1, exp2); } if (op == '/') { opExp = Expression.Divide(exp1, exp2); } if (op == '+') { opExp = Expression.Add(exp1, exp2); } if (op == '-') { opExp = Expression.Subtract(exp1, exp2); } Expression setS = Expression.Assign(Expression.ArrayAccess(newFs, Expression.Constant(nArrayIndex)), opExp); exps.Add(exp1); exps.Add(exp2); exps.Add(opExp); exps.Add(setS); //Keep the params array the correct length with default value, it will get overwritten m.parameters.Add(0.0f); } } else { val = 0.0f; bool isVal = float.TryParse(p, out val); Expression e; if (isVal) { e = Expression.Assign(Expression.ArrayAccess(newFs, Expression.Constant(nArrayIndex)), Expression.Constant(val)); exps.Add(e); m.parameters.Add(val); } else { if (p[0] == '$') { int index = int.Parse(p.Substring(1)); e = Expression.Assign(Expression.ArrayAccess(newFs, Expression.Constant(nArrayIndex)), Expression.ArrayAccess(f, Expression.Constant(index))); exps.Add(e); m.parameters.Add(0.0f); } else { //Need the lSys instance for this... hmmm e = Expression.Assign(Expression.ArrayAccess(newFs, Expression.Constant(nArrayIndex)), Expression.Call(Expression.Constant(l), typeof(LSystem).GetMethod("GetVar"), Expression.Constant(p))); //Debug.Log(e); exps.Add(e); m.parameters.Add(l.GetVar(p)); } } //Expression<Module.Transition> trans = Expression.Lambda<Module.Transition>(); //trans.Compile(); //need to test for vars / params here //if const then add, if var then methodcall, if param then array access } ++nArrayIndex; } LabelTarget returnTarget = Expression.Label(typeof(float[])); GotoExpression returnExp = Expression.Return(returnTarget, newFs); Expression defaultValue = Expression.Constant(new float[sParams.Length]); LabelExpression returnLabel = Expression.Label(returnTarget, defaultValue); exps.Add(returnExp); exps.Add(returnLabel); BlockExpression block = Expression.Block(new[] { newFs }, exps); Expression <Module.Transition> trans = Expression.Lambda <Module.Transition>(block, f); m.trans = trans.Compile(); }
public static InternalComparableValueMap MakeComparatorValueMap(TQItemSelector selector) { Type KeyType = typeof(ValueMap <string, object>); Type PropType = typeof(List <object>); ParameterExpression one = Expression.Parameter(KeyType); ParameterExpression other = Expression.Parameter(KeyType); List <Expression> body = new List <Expression>(); MethodInfo internalCMP = typeof(IComparable).GetMethod("CompareTo"); PropertyInfo indexer = PropType.GetProperty("Item");// List<object>[key] // PropertyInfo countchk = PropType.GetProperty("Count"); LabelTarget returnTarget = Expression.Label(typeof(int)); ParameterExpression varCmp = Expression.Variable(typeof(int), "cmpInt"); int counter = -1; Expression oneval2 = Expression.PropertyOrField(one, "val2"); Expression otherval2 = Expression.PropertyOrField(other, "val2"); // Expression greater1 = Expression.GreaterThan(Expression.Constant(selector.parameters.Count), Expression.Property(oneval2, countchk)); // Expression greater2 = Expression.GreaterThan(Expression.Constant(selector.parameters.Count), Expression.Property(otherval2, countchk)); // Expression condGreater1 = Expression.IfThen(greater1, Expression.Return(returnTarget, Expression.Constant(1))); // Expression condGreater2 = Expression.IfThen(greater2, Expression.Return(returnTarget, Expression.Constant(1))); // // MethodInfo writeline = typeof(Console).GetMethod("WriteLine", new[]{typeof(string), typeof(string), typeof(string), typeof(string)}); // body.Add(Expression.Call( // null, writeline, // Expression.Constant("count params {0}, onevalcount {1}, othercountval {2}"), // Expression.Convert(Expression.Constant(selector.parameters.Count),typeof(object)), // Expression.Convert(Expression.Property(oneval2, countchk),typeof(object)), // Expression.Convert(Expression.Property(otherval2, countchk),typeof(object))) // ); // body.Add(condGreater1); // body.Add(condGreater2); foreach (KeyValuePair <string, TQItemSelectorParam> rule in selector.parameters) { counter++; if (rule.Value.ValueSet == TQItemSelectorSet.Equals || rule.Value.ValueSet == TQItemSelectorSet.NotEquals) { continue; } Expression callOut = Expression.Property(oneval2, indexer, Expression.Constant(counter)); Expression callOut2 = Expression.Property(otherval2, indexer, Expression.Constant(counter)); Expression internalComparator; if (rule.Value.ValueSet == TQItemSelectorSet.Ascending) { Expression castedA = Expression.Convert(callOut, typeof(IComparable)); Expression castedB = Expression.Convert(callOut2, typeof(object)); internalComparator = Expression.Call(castedA, internalCMP, castedB); } else { Expression castedA = Expression.Convert(callOut2, typeof(IComparable)); Expression castedB = Expression.Convert(callOut, typeof(object)); internalComparator = Expression.Call(castedA, internalCMP, castedB); } Expression setexp = Expression.Assign(varCmp, internalComparator); body.Add(setexp); Expression isNEq = Expression.NotEqual(varCmp, Expression.Constant(0)); Expression cond3 = Expression.IfThen(isNEq, Expression.Return(returnTarget, varCmp)); body.Add(cond3); } LabelExpression returnDef = Expression.Label(returnTarget, Expression.Constant(0)); body.Add(returnDef); Expression expression_body = Expression.Block(new[] { varCmp }, body); return((InternalComparableValueMap)Expression.Lambda(typeof(InternalComparableValueMap), expression_body, one, other).Compile()); }
protected override Expression VisitLabel(LabelExpression node) { Console.WriteLine($"call {MethodBase.GetCurrentMethod().Name} : {node}"); return(base.VisitLabel(node)); }
/// <summary> /// Visits the children of the <see cref="LabelExpression"/>. /// </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 VisitLabel(LabelExpression node) { return(node.Update(VisitLabelTarget(node.Target), Visit(node.DefaultValue))); }
bool IEvaluatableExpressionFilter.IsEvaluatableLabel(LabelExpression node) => true;
/// <summary> /// Transforms a <see cref="LabelExpression"/> of type <see cref="ExpressionType.Label"/> into an object of type <see cref="T"/>. /// </summary> protected virtual T VisitLabel(LabelExpression node) => DefaultVisit(node);
public SerializableExpression Convert(Expression expression) { if (expression == null) { return(null); } else if (serialized.ContainsKey(expression)) { /* Caching is required to maintain object references during serialization. * See the comments on SerializableExpression.ConvertWithCache for more info. */ return(serialized[expression]); } else if ((methodCall = expression as MethodCallExpression) != null) { return(serialized[expression] = new SerializableMethodCallExpression(methodCall, this)); } else if ((lambda = expression as LambdaExpression) != null) { return(serialized[expression] = new SerializableLambdaExpression(lambda, this)); } else if ((constant = expression as ConstantExpression) != null) { return(serialized[expression] = new SerializableConstantExpression(constant)); } else if ((member = expression as MemberExpression) != null) { return(serialized[expression] = new SerializableMemberExpression(member, this)); } else if ((binary = expression as BinaryExpression) != null) { return(serialized[expression] = new SerializableBinaryExpression(binary, this)); } else if ((block = expression as BlockExpression) != null) { return(serialized[expression] = new SerializableBlockExpression(block, this)); } else if ((conditional = expression as ConditionalExpression) != null) { return(serialized[expression] = new SerializableConditionalExpression(conditional, this)); } else if ((@default = expression as DefaultExpression) != null) { return(serialized[expression] = new SerializableDefaultExpression(@default)); } else if ((@goto = expression as GotoExpression) != null) { return(serialized[expression] = new SerializableGotoExpression(@goto, this)); } else if ((index = expression as IndexExpression) != null) { return(serialized[expression] = new SerializableIndexExpression(index, this)); } else if ((invocation = expression as InvocationExpression) != null) { return(serialized[expression] = new SerializableInvocationExpression(invocation, this)); } else if ((label = expression as LabelExpression) != null) { return(serialized[expression] = new SerializableLabelExpression(label, this)); } else if ((listInit = expression as ListInitExpression) != null) { return(serialized[expression] = new SerializableListInitExpression(listInit, this)); } else if ((loop = expression as LoopExpression) != null) { return(serialized[expression] = new SerializableLoopExpression(loop, this)); } else if ((memberInit = expression as MemberInitExpression) != null) { return(serialized[expression] = new SerializableMemberInitExpression(memberInit, this)); } else if ((newArray = expression as NewArrayExpression) != null) { return(serialized[expression] = new SerializableNewArrayExpression(newArray, this)); } else if ((@new = expression as NewExpression) != null) { return(serialized[expression] = new SerializableNewExpression(@new, this)); } else if ((parameter = expression as ParameterExpression) != null) { return(serialized[expression] = new SerializableParameterExpression(parameter)); } else if ((runtimeVariables = expression as RuntimeVariablesExpression) != null) { return(serialized[expression] = new SerializableRuntimeVariablesExpression(runtimeVariables, this)); } else if ((@switch = expression as SwitchExpression) != null) { return(serialized[expression] = new SerializableSwitchExpression(@switch, this)); } else if ((@try = expression as TryExpression) != null) { return(serialized[expression] = new SerializableTryExpression(@try, this)); } else if ((typeBinary = expression as TypeBinaryExpression) != null) { return(serialized[expression] = new SerializableTypeBinaryExpression(typeBinary, this)); } else if ((unary = expression as UnaryExpression) != null) { return(serialized[expression] = new SerializableUnaryExpression(unary, this)); } else { throw new ArgumentOutOfRangeException("expression"); } }
public LabelExpression Visit(LabelExpression label) { codeWriter.Write(@label.Target?.Name + ":", currentIndent); codeWriter.NewLine(); return(null); }
protected override Expression VisitLabel(LabelExpression node) { throw new NotSupportedException("Statements are not supported"); }
protected abstract void WriteLabel(LabelExpression expr);
protected override Expression VisitLabel(LabelExpression node) { this.expressions.Add(node); return(base.VisitLabel(node)); }
protected override Expression VisitLabel(LabelExpression node) { return(GiveUp(node)); }
/// <inheritdoc/> protected override Expression VisitLabel(LabelExpression node) { Hash(node.Target); return(base.VisitLabel(node)); }
private Expression ReplaceIn(LabelExpression label) => ReplaceIn(label, l => l.Update(l.Target, Replace(l.DefaultValue)));
public virtual bool IsEvaluatableLabel(LabelExpression node) { ArgumentUtility.CheckNotNull("node", node); return(true); }
// // 摘要: // 访问 System.Linq.Expressions.LabelExpression 的子级。 // // 参数: // node: // 要访问的表达式。 // // 返回结果: // 如果修改了该表达式或任何子表达式,则为修改后的表达式;否则返回原始表达式。 protected override Expression VisitLabel(LabelExpression node) { return(base.VisitLabel(node)); }
public object Visit(LabelExpression label) { return(null); }
protected override Expression VisitLabel(LabelExpression node) { evaluator.EnsureKnownType(node.Target); return(base.VisitLabel(node)); }
/// <summary> /// Visits the children of <see cref="System.Linq.Expressions.LabelExpression"/>. /// </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 VisitLabel(LabelExpression node) { throw new NotSupportedException(string.Format(Resources.EX_PROCESS_NODE_NOT_SUPPORT, node.GetType().Name)); }
protected override Expression VisitLabel(LabelExpression node) { throw new NotSupportedException(); }
protected override Expression VisitLabel(LabelExpression node) => node.Type == typeof(void) ? context.Rewrite(node, Converter.Identity <LabelExpression>()) : throw new NotSupportedException(ExceptionMessages.VoidLabelExpected);
private bool CompareLabel(LabelExpression a, LabelExpression b) => Equals(a.Target, b.Target) && Compare(a.DefaultValue, b.DefaultValue);
/// <summary> /// Visits the children of the <see cref="LabelExpression" />. /// </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 internal virtual Expression VisitLabel(LabelExpression node) { return(node.Update(VisitLabelTarget(node.Target), Visit(node.DefaultValue))); }
protected override Expression VisitLabel(LabelExpression node) { _stringBuilder.Append(node.Target.ToString()); return(node); }
protected override Expression VisitLabel(LabelExpression node) => base.VisitLabel(node);
public LabelExpressionProxy(LabelExpression node) { _node = node; }
protected sealed override Expression VisitLabel(LabelExpression node) => VisitLabel(node, CurrentExpectedType);