Used by compilers to provide additional debug information about LambdaExpression to DebugContext
Example #1
0
        /// <summary>
        /// Transforms a LambdaExpression to a debuggable LambdaExpression
        /// </summary>
        public MSAst.LambdaExpression TransformLambda(MSAst.LambdaExpression lambda, DebugLambdaInfo lambdaInfo)
        {
            ContractUtils.RequiresNotNull(lambda, "lambda");
            ContractUtils.RequiresNotNull(lambdaInfo, "lambdaInfo");

            return(new DebuggableLambdaBuilder(this, lambdaInfo).Transform(lambda));
        }
Example #2
0
        /// <summary>
        /// Transforms a LambdaExpression to a debuggable LambdaExpression
        /// </summary>
        public LambdaExpression TransformLambda(LambdaExpression lambda, DebugLambdaInfo lambdaInfo)
        {
            ContractUtils.RequiresNotNull(lambda, nameof(lambda));
            ContractUtils.RequiresNotNull(lambdaInfo, nameof(lambdaInfo));

            return(new DebuggableLambdaBuilder(this, lambdaInfo).Transform(lambda));
        }
        internal DebuggableLambdaBuilder(DebugContext debugContext, DebugLambdaInfo lambdaInfo) {
            _debugContext = debugContext;
            _lambdaInfo = lambdaInfo;

            _alias = _lambdaInfo.LambdaAlias;
            _debugContextExpression = AstUtils.Constant(debugContext);

            // Variables
            _verifiedLocals = new List<MSAst.ParameterExpression>();
            _verifiedLocalNames = new Dictionary<string, object>();
            _pendingLocals = new List<MSAst.ParameterExpression>();
            _variableInfos = new List<VariableInfo>();
            _pendingToVariableInfosMap = new Dictionary<MSAst.ParameterExpression, VariableInfo>();
            _pendingToVerifiedLocalsMap = new Dictionary<MSAst.ParameterExpression, MSAst.ParameterExpression>();

            // DebugMode expression that's used by the transformed code to see what the current debug mode is
            _globalDebugMode = Ast.Property(_debugContextExpression, "Mode");
        }
Example #4
0
        /// <summary>
        /// Transforms a LambdaExpression to a debuggable LambdaExpression
        /// </summary>
        public MSAst.LambdaExpression TransformLambda(MSAst.LambdaExpression lambda, DebugLambdaInfo lambdaInfo) {
            ContractUtils.RequiresNotNull(lambda, "lambda");
            ContractUtils.RequiresNotNull(lambdaInfo, "lambdaInfo");

            return new DebuggableLambdaBuilder(this, lambdaInfo).Transform(lambda);
        }
        public override Expression Reduce()
        {
            var temp = Expr.Variable(typeof(Delegate), "$function$");

            Expr function = _body;

            if (_context.EnableTracing)
            {
                var aliases = _scope.AllLocals().Zip(_scope.GetLocalNames(), (p, n) => new KeyValuePair<ParameterExpression, string>(p, n)).ToDictionary(x => x.Key, y => y.Value);
                var debugInfo = new DebugLambdaInfo(null, _identifier, false, _scope.AllLocals(), aliases, _scope);
                function = _context.Language.DebugContext.TransformLambda(_body).Reduce();
            }
            else
                function = _body.Reduce();

            return  Expression.Block(new[] { temp },
                        Expr.Assign(temp, function),
                        CodeContext.RegisterFunction(_context, temp, _scope),
                        temp);
        }