internal override Expression CompileLightweightExceptionCheck(Visiting.EncoderVisitor visitor, Expression expression) { // C# Semantics: // var temp = <expression> // if (temp is BlockResult) // return temp; // temp return(Expression.Block( Expression.Assign(this.TempValue, expression), Expression.IfThen( Expression.TypeIs(this.TempValue, typeof(BlockResult)), this.ReturnLocal(this.TempValue)), this.TempValue)); }
//internal override Expression CompileLightweightExceptionCheck(Visiting.EncoderVisitor visitor, Expression expression) //{ // var na = this.HomeContext; // Init needed stuff // // C# Semantics: // // var temp = <expression> // // if (temp is BlockResult) // // { // // if (((BlockResult) temp).HomeContext == _HomeContext) // // return ((BlockResult) temp).Value; // // else // // return temp; // // } // // temp // return Expression.Block( // Expression.Assign(this.TempValue, expression), // Expression.IfThen( // Expression.TypeIs(this.TempValue, typeof(BlockResult)), // Expression.IfThenElse( // // Improve ... unnecessary test if the methods doesn't declare blocks. // Expression.Equal(Expression.Field(Expression.Convert(this.TempValue, typeof(BlockResult)), BlockResult.HomeContextField), this._HomeContextVariable), // this.ReturnLocal(Expression.Field(Expression.Convert(this.TempValue, typeof(BlockResult)), BlockResult.ValueField)), // this.ReturnLocal(this.TempValue))), // this.TempValue); //} //internal override Expression GeneratePrologAndEpilogue(List<Expression> expressions) //{ // Expression result; // if ((this.Temporaries.Count == 0) && (expressions.Count == 1)) // result = expressions[0]; // else // result = Expression.Block(this.Temporaries.Select(binding => binding.Expression), expressions); // // Somebody requested explicit return // if (this._ReturnLabel != null) // result = Expression.Label(this._ReturnLabel, result); // // Somebody requested the home context used for block returns ... we must handle this correctly with try ... catch ... // if (this._HomeContext != null) // { // if (this.Compiler.CompilerOptions.LightweightExceptions) // { // result = Expression.Block(new ParameterExpression[] { this._HomeContextVariable }, result); // } // else // { // // Semantics: // // HomeContext homeContext = new HomeContext(); ... however, this is lazy init'ed // // try // // { // // return <<result>>; // // } // // .... this is how we would like to have it ... if we could. CLR limitations do not allow filters in dynamic methods .... // // catch (BlockResult blockResult) where (blockResult.HomeContext == homeContext) ... the where semantics are not part of C# // // { // // return blockResult.Result; // // } // // .... therefore the following implementation .... // // catch (BlockResult blockResult) // // { // // if (blockResult.HomeContext == homeContext) // // return blockResult.Result; // // else // // throw; // // } // ParameterExpression blockResult = Expression.Parameter(typeof(BlockResult), "blockResult"); // CatchBlock catchBlock = Expression.Catch( // blockResult, // Expression.Condition( // Expression.ReferenceEqual(Expression.Field(blockResult, BlockResult.HomeContextField), this._HomeContextVariable), // Expression.Field(blockResult, BlockResult.ValueField), // Expression.Rethrow(typeof(object)))); // result = Expression.Block(new ParameterExpression[] { this._HomeContextVariable }, Expression.TryCatch(result, catchBlock)); // } // } // if (this._TempValue != null) // result = Expression.Block(new ParameterExpression[] { this._TempValue }, result); // return result; //} internal override Expression CompileLightweightExceptionCheck(Visiting.EncoderVisitor visitor, Expression expression) { var na = this.HomeContext; // Init needed stuff // C# Semantics: // var temp = <expression> // if (temp is BlockResult) // { // if (((BlockResult) temp).HomeContext == _HomeContext) // return ((BlockResult) temp).Value; // else // return temp; // } // temp var x = this.BlockReturnLabel; return(Expression.Block( Expression.Assign(this.TempValue, expression), Expression.IfThen( Expression.TypeIs(this.TempValue, typeof(BlockResult)), Expression.Return(this.BlockReturnLabel, this.TempValue)), this.TempValue)); }
internal override Expression CompileLightweightExceptionCheck(Visiting.EncoderVisitor visitor, Expression expression) { return(this.OuterContext.CompileLightweightExceptionCheck(visitor, expression)); }