public static DeferredSectionExpression DeferredSection( PathExpression path, BlockExpression body, BlockExpression inversion) { return new DeferredSectionExpression(path, body, inversion); }
internal static MSAst.Expression RemoveDebugInfo(int prevStart, MSAst.Expression res) { MSAst.BlockExpression block = res as MSAst.BlockExpression; if (block != null && block.Expressions.Count > 0) { MSAst.DebugInfoExpression dbgInfo = block.Expressions[0] as MSAst.DebugInfoExpression; // body on the same line as an if, don't generate a 2nd sequence point if (dbgInfo != null && dbgInfo.StartLine == prevStart) { // we remove the debug info based upon how it's generated in DebugStatement.AddDebugInfo which is // the helper method which adds the debug info. if (block.Type == typeof(void)) { Debug.Assert(block.Expressions.Count == 3); Debug.Assert(block.Expressions[2] is MSAst.DebugInfoExpression && ((MSAst.DebugInfoExpression)block.Expressions[2]).IsClear); res = block.Expressions[1]; } else { Debug.Assert(block.Expressions.Count == 4); Debug.Assert(block.Expressions[3] is MSAst.DebugInfoExpression && ((MSAst.DebugInfoExpression)block.Expressions[2]).IsClear); Debug.Assert(block.Expressions[1] is MSAst.BinaryExpression && ((MSAst.BinaryExpression)block.Expressions[2]).NodeType == MSAst.ExpressionType.Assign); res = ((MSAst.BinaryExpression)block.Expressions[1]).Right; } } } return(res); }
private static bool CanOptimize(BlockExpression block) { // TODO: some more optimizations are possible even if the types don't match, // e.g. flattening all but the last child block into the parent block. return block.Variables.Count == 0 && block.Result.Type == block.Type; }
protected override Expression VisitBlock(BlockExpression node) { return Expression.Block( node.Type, node.Variables, node.Expressions.Select(expr => Visit(expr))); }
internal static ReadOnlyCollection<Expression> ReturnReadOnlyExpressions(BlockExpression provider, ref object collection) { Expression comparand = collection as Expression; if (comparand != null) { Interlocked.CompareExchange(ref collection, new ReadOnlyCollection<Expression>(new BlockExpressionList(provider, comparand)), comparand); } return (ReadOnlyCollection<Expression>) collection; }
public DeferredSectionExpression( PathExpression path, BlockExpression body, BlockExpression inversion) { Path = path; Body = body; Inversion = inversion; }
/// <summary> /// /// </summary> /// <param name="t"></param> /// <param name="count">要退栈的元素数</param> /// <returns></returns> internal BlockExpression Block(BlockExpression t, int count) { Contract.Assert(count>=0); if(count == 0) { return t; } return Expression.Block(t, Expression.Call(typeof(Instructor).GetMethod("StackPop"),count.GetConstantExpression())); }
protected override MSAst.Expression VisitBlock(MSAst.BlockExpression node) { // Record all variables declared within the block foreach (MSAst.ParameterExpression local in node.Variables) { _locals.Add(local); } return(base.VisitBlock(node)); }
public override void HandleElement(Expression item) { if (IsInversionBlock(item)) { _accumulatedBody = Expression.Block(_body); _body = new List<Expression>(); } else { _body.Add(item); } }
protected override Expression VisitBlock(BlockExpression node) { if (CanOptimize(node)) { return FlattenBlocks(node); } var variables = VisitAndConvert(node.Variables, nameof(VisitBlock)); var expressions = VisitSequence(node.Expressions); return node.Update(variables, expressions); }
internal override lambda.Expression Compile(lambda.Expression[] param, lambda.LabelTarget fault) { lambda.ParameterExpression param1 = lambda.Expression.Parameter(typeof(object)); lambda.ParameterExpression param2 = lambda.Expression.Parameter(typeof(object)); lambda.ParameterExpression evaluated = lambda.Expression.Variable(typeof(bool)); lambda.ParameterExpression ret = lambda.Expression.Variable(typeof(object)); List <lambda.Expression> expressions = new List <lambda.Expression>(); expressions.Add(lambda.Expression.Assign(evaluated, lambda.Expression.Constant(false))); expressions.Add(lambda.Expression.Assign(param1, param[0])); expressions.Add(lambda.Expression.Assign(param2, param[1])); if ((_acceptedType & AcceptedType.Numeric) == AcceptedType.Numeric) { lambda.ParameterExpression paramNumeric1 = lambda.Expression.Parameter(typeof(double)); lambda.ParameterExpression paramNumeric2 = lambda.Expression.Parameter(typeof(double)); lambda.BlockExpression numericBlock = lambda.Expression.Block( new[] { paramNumeric1, paramNumeric2 }, lambda.Expression.Assign(paramNumeric1, lambda.Expression.Convert(lambda.Expression.Call(_miChangeType, param1, lambda.Expression.Constant(typeof(double))), typeof(double))), lambda.Expression.Assign(paramNumeric2, lambda.Expression.Convert(lambda.Expression.Call(_miChangeType, param2, lambda.Expression.Constant(typeof(double))), typeof(double))), lambda.Expression.Assign(evaluated, lambda.Expression.Constant(true)), lambda.Expression.Assign(ret, lambda.Expression.Convert(CompileNumericBlock(paramNumeric1, paramNumeric2), typeof(object))) ); expressions.Add(lambda.Expression.TryCatch(numericBlock, lambda.Expression.Catch(typeof(Exception), lambda.Expression.Assign(ret, lambda.Expression.Convert(lambda.Expression.Constant(null), typeof(object))) ))); } if ((_acceptedType & AcceptedType.String) == AcceptedType.String) { lambda.ParameterExpression paramString1 = lambda.Expression.Parameter(typeof(string)); lambda.ParameterExpression paramString2 = lambda.Expression.Parameter(typeof(string)); lambda.BlockExpression stringBlock = lambda.Expression.Block( new[] { paramString1, paramString2 }, lambda.Expression.Assign(paramString1, lambda.Expression.Convert(lambda.Expression.Call(_miChangeType, param1, lambda.Expression.Constant(typeof(string))), typeof(string))), lambda.Expression.Assign(paramString2, lambda.Expression.Convert(lambda.Expression.Call(_miChangeType, param2, lambda.Expression.Constant(typeof(string))), typeof(string))), lambda.Expression.Assign(evaluated, lambda.Expression.Constant(true)), lambda.Expression.Assign(ret, lambda.Expression.Convert(CompileStringBlock(paramString1, paramString2), typeof(object))) ); expressions.Add(lambda.Expression.IfThen(lambda.Expression.Equal(evaluated, lambda.Expression.Constant(false)), lambda.Expression.TryCatch(stringBlock, lambda.Expression.Catch(typeof(Exception), lambda.Expression.Assign(ret, lambda.Expression.Convert(lambda.Expression.Constant(null), typeof(object))) )))); } expressions.Add(lambda.Expression.IfThenElse(evaluated, ret, lambda.Expression.Goto(fault))); expressions.Add(ret); lambda.BlockExpression block = lambda.Expression.Block( new[] { param1, param2, evaluated, ret }, expressions.ToArray() ); return(block); }
protected override Expression VisitBlock(BlockExpression blockExpression) { if (blockExpression.Variables.Count == 0) { var list = new List<Expression>(); this.VisitBlockInternal(list, blockExpression); return base.VisitBlock(Expression.Block(list)); } else { return base.VisitBlock(blockExpression); } }
private void VisitBlockInternal(List<Expression> expressions, BlockExpression blockExpression) { foreach (var expression in blockExpression.Expressions) { if (expression.NodeType == ExpressionType.Block) { this.VisitBlockInternal(expressions, (BlockExpression)expression); } else { expressions.Add(expression); } } }
protected override Expression VisitBlock(BlockExpression node) { var modifiedExpressionList = new List<Expression>(); foreach (var expression in node.Expressions) { if (expression.NodeType == ExpressionType.Default && expression.Type == typeof(void)) { continue; } modifiedExpressionList.Add(expression); } return base.VisitBlock(Expression.Block(node.Variables, modifiedExpressionList)); }
protected override Expression VisitBlock(BlockExpression node) { var map = default(IDictionary<LabelTarget, LabelInfo>); foreach (var e in node.Expressions) { if (e.NodeType == ExpressionType.Label) { var l = (LabelExpression)e; if (l.Type != typeof(void)) { if (map == null) { map = new Dictionary<LabelTarget, LabelInfo>(); } var name = l.Target.Name; var newLabel = Expression.Label(typeof(void), name); var labelValue = Expression.Parameter(l.Type, name); var info = new LabelInfo { Target = newLabel, Value = labelValue, }; map.Add(l.Target, info); } } } if (map != null) { _labels.Push(map); } var res = (BlockExpression)base.VisitBlock(node); if (map != null) { _labels.Pop(); var newVariables = map.Values.Map(i => i.Value); res = res.Update(res.Variables.Concat(newVariables), res.Expressions); } return res; }
protected override Expression VisitBlock(BlockExpression node) { if (node.Variables.Count == 0 && node.Expressions.Count == 1) { // ローカル変数が無く、式がひとつなら、その式として実行すればよい。 return Visit(node.Expressions[0]); } // ブロックの場合、そのブロックの最後のみを走査する。 Expression nextLastExpr = null; var lastExpr = node.Expressions[node.Expressions.Count - 1]; nextLastExpr = Visit(lastExpr); if (nextLastExpr == lastExpr) return node; var exprs = new Expression[node.Expressions.Count]; for (int i = 0; i < exprs.Length - 1; i++) exprs[i] = node.Expressions[i]; exprs[exprs.Length - 1] = nextLastExpr; return Expression.Block(node.Variables, exprs); }
// ----- ----- ----- ----- ----- methods ----- ----- ----- ----- ----- protected override Expression VisitBlock(BlockExpression node) { var block = base.VisitBlock(node) as BlockExpression; List<ParameterExpression> lst = new List<ParameterExpression>(); foreach (var param in node.Variables) { SuffixFuncInfo info; if (_dic.TryGetValue(param, out info)) { lst.Add(info.FuncExpr); } } if (lst.Count == 0) { return block; } else { lst.AddRange(node.Variables); return Expression.Block(lst, block.Expressions); } }
public void Compile() { lambda.ParameterExpression value = lambda.Expression.Parameter(typeof(object[]), "value"); lambda.ParameterExpression result = lambda.Expression.Variable(typeof(object), "result"); lambda.LabelTarget fault = lambda.Expression.Label("fault"); lambda.LabelTarget ret = lambda.Expression.Label("return"); lambda.BlockExpression block = lambda.Expression.Block( new[] { result }, lambda.Expression.Assign(result, es.Compile(value, fault)), result, lambda.Expression.Goto(ret), lambda.Expression.Label(fault), lambda.Expression.Assign(result, lambda.Expression.Constant(null)), lambda.Expression.Label(ret), result ); _lambdaExpression = lambda.Expression.Lambda <Func <object[], object> >(block, value).Compile(); }
public void SetUp() { good = Expression.Constant("I am good"); genericEx = new NotImplementedException(); throwGeneral = Expression.Block(Expression.Throw(Expression.Constant(genericEx)), Expression.Constant("bar")); smEx = new StructureMapException("you stink!"); throwSM = Expression.Block(Expression.Throw(Expression.Constant(smEx)), Expression.Constant("bar")); var gateway = new StubbedGateway(); Expression<Action> goodExpr = () => gateway.DoSomething(); goodVoid = Expression.Block(goodExpr.Body); badVoid = Expression.Block(Expression.Throw(Expression.Constant(genericEx))); badSmVoid = Expression.Block(Expression.Throw(Expression.Constant(smEx))); }
protected override Linq.Expression VisitBlock(Linq.BlockExpression node) { var block = new Block(this.Current); if (!Extensions.AreEquivalent(node.Type, node.Expressions.Last().Type)) { block.Type = this.VisitType(node.Type); } foreach (var variable in node.Variables) { block.Variables.Add(new Parameter(this.VisitCache(variable))); } foreach (var blockExpression in node.Expressions) { block.Expressions.Add(this.VisitCacheParse(blockExpression)); } return(node); }
public override Expression GetAccumulatedBlock() { if (_accumulatedBody == null) { _accumulatedBody = Expression.Block(_body); _accumulatedInversion = Expression.Block(Expression.Empty()); } else if (_accumulatedInversion == null && _body.Any()) { _accumulatedInversion = Expression.Block(_body); } else { _accumulatedInversion = Expression.Block(Expression.Empty()); } return HandlebarsExpression.DeferredSection( _startingNode, _accumulatedBody, _accumulatedInversion); }
protected override Expression VisitBlock(BlockExpression node) { var res = (BlockExpression)base.VisitBlock(node); if (CanOptimize(res)) { var expressions = default(List<Expression>); for (var i = 0; i < res.Expressions.Count; i++) { var expression = res.Expressions[i]; var nested = expression as BlockExpression; if (nested != null && CanOptimize(nested)) { if (expressions == null) { expressions = new List<Expression>(); for (var j = 0; j < i; j++) { expressions.Add(res.Expressions[j]); } } expressions.AddRange(nested.Expressions); } else if (expressions != null) { expressions.Add(expression); } } if (expressions != null) { return res.Update(res.Variables, expressions); } } return res; }
internal override lambda.Expression CompileArrayBlock(lambda.ParameterExpression paramArray1, lambda.LabelTarget fault) { lambda.ParameterExpression counter = lambda.Expression.Variable(typeof(int), "counter"); lambda.ParameterExpression exc = lambda.Expression.Variable(typeof(bool), "exc"); lambda.ParameterExpression row = lambda.Expression.Variable(typeof(object[]), "row"); lambda.ParameterExpression ret = lambda.Expression.Variable(typeof(object[]), "ret"); lambda.LabelTarget label = lambda.Expression.Label(typeof(object)); lambda.LabelTarget loclalfault = lambda.Expression.Label(); lambda.LabelTarget loclalsucces = lambda.Expression.Label(); lambda.BlockExpression foorEachBlock = lambda.Expression.Block( new[] { counter, ret, exc }, lambda.Expression.Assign(exc, lambda.Expression.Constant(false)), lambda.Expression.Assign(counter, lambda.Expression.Constant(0)), lambda.Expression.Assign(ret, lambda.Expression.Convert(lambda.Expression.ArrayIndex(paramArray1, lambda.Expression.Subtract(lambda.Expression.ArrayLength(paramArray1), lambda.Expression.Constant(1))), typeof(object[]))), // lambda.Expression.NewArrayBounds(typeof(object), lambda.Expression.ArrayLength(paramArray1))), lambda.Expression.Loop(lambda.Expression.IfThenElse( lambda.Expression.LessThan(counter, lambda.Expression.Subtract(lambda.Expression.ArrayLength(paramArray1), lambda.Expression.Constant(1))), lambda.Expression.Block( new[] { row }, lambda.Expression.TryCatch( lambda.Expression.Block( lambda.Expression.Assign(row, lambda.Expression.Convert(lambda.Expression.ArrayIndex(paramArray1, counter), typeof(object[]))), lambda.Expression.Assign(lambda.Expression.ArrayAccess(ret, counter), lambda.Expression.Convert(base.Compile(row, loclalfault), typeof(object))), lambda.Expression.Goto(loclalsucces), lambda.Expression.Label(loclalfault), lambda.Expression.Assign(lambda.Expression.ArrayAccess(ret, counter), lambda.Expression.Constant(null)), lambda.Expression.Label(loclalsucces), ret) , lambda.Expression.Catch(typeof(Exception), lambda.Expression.Block( lambda.Expression.Assign(counter, lambda.Expression.Subtract(lambda.Expression.ArrayLength(paramArray1), lambda.Expression.Constant(1))), lambda.Expression.Assign(exc, lambda.Expression.Constant(true)), ret))) , lambda.Expression.PostIncrementAssign(counter) ), lambda.Expression.IfThenElse(exc, lambda.Expression.Goto(fault), lambda.Expression.Break(label, lambda.Expression.Convert(ret, typeof(object)))) ), label) ); return(foorEachBlock); }
protected override Expression VisitBlock(BlockExpression node) { using (this.AcquireIndentationContext(BraceLanguageStyleIndentationOptions.IncludeBraces)) { if (node.Variables != null) { foreach (var expression in node.Variables) { this.WriteVariableDeclaration(expression); } } if (node.Variables != null && node.Variables.Count > 0) { this.WriteLine(); } this.VisitExpressionList(node.Expressions); } return node; }
// We remove all nested variables declared inside the block. protected override Expression VisitBlock(MSAst.BlockExpression node) { if (_transformToGenerator) { _currentLocals.Push(node); } try { BlockExpression modifiedBlock = Ast.Block(node.Type, node.Expressions); return(base.VisitBlock(modifiedBlock)); } finally { if (_transformToGenerator) { #if DEBUG BlockExpression poppedBlock = #endif _currentLocals.Pop(); #if DEBUG Debug.Assert(Type.ReferenceEquals(node, poppedBlock)); #endif } } }
protected override Expression VisitBlock(BlockExpression node) { var modifiedExpressionList = new List<Expression>(); foreach (var expression in node.Expressions) { if (expression.NodeType == ExpressionType.Call) { var methodCall = (MethodCallExpression)expression; if (methodCall.Object != null && methodCall.Object.Type == TransientLifetimeManagerType && object.Equals(methodCall.Method, SetValueMethodInfo)) { continue; } modifiedExpressionList.Add(expression); } else { modifiedExpressionList.Add(expression); } } return base.VisitBlock(Expression.Block(node.Variables, modifiedExpressionList)); }
internal override lambda.Expression CompileArrayBlock(lambda.ParameterExpression paramArray1, lambda.LabelTarget fault) { lambda.ParameterExpression counter = lambda.Expression.Variable(typeof(int), "counter"); lambda.ParameterExpression countitem = lambda.Expression.Variable(typeof(int), "countitem"); lambda.LabelTarget label = lambda.Expression.Label(typeof(object)); lambda.BlockExpression block = lambda.Expression.Block( new[] { counter, countitem }, lambda.Expression.Assign(counter, lambda.Expression.Constant(0)), lambda.Expression.Assign(countitem, lambda.Expression.Constant(0)), lambda.Expression.Loop( lambda.Expression.IfThenElse( lambda.Expression.LessThan(counter, lambda.Expression.ArrayLength(paramArray1)), lambda.Expression.Block( lambda.Expression.TryCatch(lambda.Expression.Block( lambda.Expression.IfThen(lambda.Expression.IsTrue(lambda.Expression.Convert(lambda.Expression.ArrayIndex(paramArray1, counter), typeof(bool))), lambda.Expression.PostIncrementAssign(countitem)), countitem), lambda.Expression.Catch(typeof(Exception), countitem)), lambda.Expression.PostIncrementAssign(counter)), lambda.Expression.Break(label, lambda.Expression.Convert(countitem, typeof(object))) ), label)); return(block); }
public static Expression[] VisitBlockExpressions(ExpressionVisitor visitor, BlockExpression block) { Expression[] newNodes = null; for (int i = 0, n = block.ExpressionCount; i < n; i++) { Expression curNode = block.GetExpression(i); Expression node = visitor.Visit(curNode); if (newNodes != null) { newNodes[i] = node; } else if (!object.ReferenceEquals(node, curNode)) { newNodes = new Expression[n]; for (int j = 0; j < i; j++) { newNodes[j] = block.GetExpression(j); } newNodes[i] = node; } } return newNodes; }
public static BlockExpression Visit(this BlockExpression block, Action <IExpressionVisitor> visitor) => Expression.Block(visitor.CreateVisitor().Visit(block));
private static string VisitBlock(BlockExpression node) { throw new NotImplementedException(); }
internal override ReadOnlyCollection <Expression> GetOrMakeExpressions() { return(BlockExpression.ReturnReadOnlyExpressions(this, ref this._arg0)); }
protected override MSAst.Expression VisitDebugInfo(MSAst.DebugInfoExpression node) { if (!node.IsClear) { MSAst.Expression transformedExpression; // Verify that DebugInfoExpression has valid SymbolDocumentInfo if (node.Document == null) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, ErrorStrings.DebugInfoWithoutSymbolDocumentInfo, _locationCookie)); } DebugSourceFile sourceFile = _debugContext.GetDebugSourceFile( String.IsNullOrEmpty(node.Document.FileName) ? "<compile>" : node.Document.FileName); // Update the location cookie int locationCookie = _locationCookie++; if (!_transformToGenerator) { MSAst.Expression tracebackCall = null; if (locationCookie == 0) { tracebackCall = Ast.Empty(); } else { tracebackCall = Ast.Call( typeof(RuntimeOps).GetMethod("OnTraceEvent"), _thread, AstUtils.Constant(locationCookie), Ast.Convert(Ast.Constant(null), typeof(Exception)) ); } transformedExpression = Ast.Block( Ast.Assign( _debugMarker, AstUtils.Constant(locationCookie) ), Ast.IfThen( Ast.GreaterThan( Ast.Property(_sourceFilesToVariablesMap[sourceFile], "Mode"), Ast.Constant((int)DebugMode.ExceptionsOnly) ), Ast.IfThen( Ast.OrElse( Ast.Equal( Ast.Property(_sourceFilesToVariablesMap[sourceFile], "Mode"), Ast.Constant((int)DebugMode.FullyEnabled) ), Ast.ArrayIndex( _traceLocations, AstUtils.Constant(locationCookie) ) ), Ast.Block( _pushFrame ?? Ast.Empty(), tracebackCall ) ) ) ); } else { Debug.Assert(_generatorLabelTarget != null); transformedExpression = Ast.Block( AstUtils.YieldReturn( _generatorLabelTarget, _debugYieldValue, locationCookie ) ); // Update the variable scope map if (_currentLocals.Count > 0) { IList <VariableInfo> scopedVaribles; MSAst.BlockExpression curentBlock = _currentLocals.Peek(); if (!_variableScopeMapCache.TryGetValue(curentBlock, out scopedVaribles)) { scopedVaribles = new List <VariableInfo>(); MSAst.BlockExpression[] blocks = _currentLocals.ToArray(); for (int i = blocks.Length - 1; i >= 0; i--) { foreach (var variable in blocks[i].Variables) { scopedVaribles.Add(_localsToVarInfos[variable]); } } _variableScopeMapCache.Add(curentBlock, scopedVaribles); } _variableScopeMap.Add(locationCookie, scopedVaribles); } DebugSourceSpan span = new DebugSourceSpan( sourceFile, node.StartLine, node.StartColumn, node.EndLine, node.EndColumn); // Update the location-span map _markerLocationMap.Add(locationCookie, span); } return(transformedExpression); } else { return(Ast.Empty()); } }
//protected override Expression VisitLambda<T>(Expression<T> node) //{ // // delve into the lambda // return base.VisitLambda(node); //} //protected override Expression VisitParameter(ParameterExpression node) //{ // // called on member invoke // return base.VisitParameter(node); //} protected override Expression VisitBlock(BlockExpression node) { throw new NotSupportedException(); }
public BlockExpressionProxy(BlockExpression node) { ContractUtils.RequiresNotNull(node, nameof(node)); _node = node; }
private static Expression GetSerializationExpression(Expression value, Type valueType, BlockExpression serializeClass, BlockExpression serializePolymorphicClass) { if (valueType.IsSealed) return serializeClass; if (IsPurePolymorphic(valueType)) return serializePolymorphicClass; return Expression.IfThenElse( Expression.Equal(GetActualValueType(value), Expression.Constant(valueType)), serializeClass, serializePolymorphicClass ); }
protected override Expression VisitBlock(BlockExpression expression) { BlockExpression current; if (!TryGetCurrent(expression, out current)) { return expression; } if (!(this.result &= current.NodeType == expression.NodeType)) { return expression; } if (!(this.result &= current.Type == expression.Type)) { return expression; } this.currentObject = current.Result; this.Visit(expression.Result); if (!this.result) { return expression; } this.currentObject = current.Expressions; this.VisitExpressionList(expression.Expressions); if (!this.result) { return expression; } this.currentObject = current.Variables; this.VisitExpressionList(expression.Variables); if (!this.result) { return expression; } this.currentObject = current; return expression; }
private LocalDefinition[] CompileBlockStart(BlockExpression node) { LocalDefinition[] emptyLocals; int count = this._instructions.Count; ReadOnlyCollection<ParameterExpression> variables = node.Variables; if (variables.Count != 0) { emptyLocals = new LocalDefinition[variables.Count]; int num2 = 0; foreach (ParameterExpression expression in variables) { LocalDefinition definition = this._locals.DefineLocal(expression, count); emptyLocals[num2++] = definition; this._instructions.EmitInitializeLocal(definition.Index, expression.Type); } } else { emptyLocals = EmptyLocals; } for (int i = 0; i < (node.Expressions.Count - 1); i++) { this.CompileAsVoid(node.Expressions[i]); } return emptyLocals; }
public BlockExpressionProxy(BlockExpression node) { _node = node; }
public virtual bool IsEvaluatableBlock (BlockExpression node) { ArgumentUtility.CheckNotNull ("node", node); return true; }
internal BlockExpressionList(BlockExpression provider, Expression arg0) { _block = provider; _arg0 = arg0; }
/// <summary> /// 定义一个匿名函数 /// </summary> /// <param name="info"> /// TupleStruct<Int32,bool> /// @First 函数参数个数 /// @Second 是否是不定参数 /// </param> /// <param name="body">函数体</param> /// <param name="label">结束标记</param> /// <param name="upValues">闭包变量集合</param> /// <returns></returns> internal Expression MethodDef(TupleStruct<Int32,bool> info, BlockExpression body, LabelTarget label, List<KeyValuePair<string, Int32>> upValues) { //函数体 Expression funcBody = Expression.Block(body, Expression.Call(typeof(Instructor).GetMethod("SetReturnVoid")),Expression.Label(label)); Action func = Expression.Lambda<Action>(funcBody).Compile(); //编译方法体 Expression o = ScriptObject.CreateFunction(func, info.First, info.Second).GetConstantExpression(); if (upValues == null || upValues.Count == 0) return o; List<Expression> steps = new List<Expression>(); Expression e = Expression.Call(typeof(Instructor).GetMethod("SetUpvaluesLength"), o, upValues.Count.GetConstantExpression()); steps.Add(e); for (int i = 0; i < upValues.Count; i++) { KeyValuePair<string, Int32> upvalue = upValues[i]; e = Expression.Call(typeof(Instructor).GetMethod("SetUpvalue"), o, i.GetConstantExpression(), upvalue.Value.GetConstantExpression()); steps.Add(e); } steps.Add(o); return Expression.Block(steps); }
}//end static method internal XElement BlockExpressionToXElement(BlockExpression e) { object value; string xName = "BlockExpression"; object[] XElementValues = new object[6]; value = ((BlockExpression)e).Expressions; XElementValues[0] = GenerateXmlFromProperty(typeof(System.Collections.ObjectModel.ReadOnlyCollection<System.Linq.Expressions.Expression>), "Expressions", value ?? string.Empty); value = ((BlockExpression)e).Variables; XElementValues[1] = GenerateXmlFromProperty(typeof(System.Collections.ObjectModel.ReadOnlyCollection<System.Linq.Expressions.ParameterExpression>), "Variables", value ?? string.Empty); value = ((BlockExpression)e).Result; XElementValues[2] = GenerateXmlFromProperty(typeof(System.Linq.Expressions.Expression), "Result", value ?? string.Empty); value = ((BlockExpression)e).NodeType; XElementValues[3] = GenerateXmlFromProperty(typeof(System.Linq.Expressions.ExpressionType), "NodeType", value ?? string.Empty); value = ((BlockExpression)e).Type; XElementValues[4] = GenerateXmlFromProperty(typeof(System.Type), "Type", value ?? string.Empty); value = ((BlockExpression)e).CanReduce; XElementValues[5] = GenerateXmlFromProperty(typeof(System.Boolean), "CanReduce", value ?? string.Empty); return new XElement(xName, XElementValues); }//end static method