string Evaluate(string code) { Process process = WindowsDebugger.CurrentProcess; StackFrame frame = WindowsDebugger.CurrentStackFrame; if (process == null) { return("No process is being debugged"); } if (process.IsRunning) { return("The process is running"); } if (frame == null) { return("No current execution frame"); } try { var val = WindowsDebugger.Evaluate(code, allowSetValue: true); return(ExpressionEvaluationVisitor.FormatValue(WindowsDebugger.EvalThread, val)); } catch (GetValueException e) { return(e.Message); } }
public override void HandleToolTipRequest(ToolTipRequestEventArgs e) { if (!(IsDebugging && CurrentProcess.IsPaused)) { return; } if (CurrentStackFrame == null) { return; } if (!e.InDocument) { return; } var resolveResult = SD.ParserService.Resolve(e.Editor, e.LogicalPosition, CurrentStackFrame.AppDomain.Compilation); if (resolveResult == null) { return; } if (resolveResult is LocalResolveResult || resolveResult is MemberResolveResult) { string text = ResolveResultPrettyPrinter.Print(resolveResult); Func <Value> getValue = delegate { ExpressionEvaluationVisitor eval = new ExpressionEvaluationVisitor(CurrentStackFrame, EvalThread, CurrentStackFrame.AppDomain.Compilation); return(eval.Convert(resolveResult)); }; try { var rootNode = new ValueNode(ClassBrowserIconService.LocalVariable, text, getValue); e.SetToolTip(new DebuggerTooltipControl(rootNode)); } catch (InvalidOperationException ex) { SD.Log.Warn(ex); } } }
/// <summary> /// Evaluates the binding. /// </summary> internal object EvaluateBinding(ExpressionEvaluationVisitor visitor, string expression, string pathExpression) { // parse var node = ParseBinding(expression); var result = visitor.Visit(node); visitor.BackupCurrentPosition(result, pathExpression); return result; }
/// <summary> /// Evaluates the data context path and returns the visitor with hierarchy. /// </summary> private ExpressionEvaluationVisitor EvaluateDataContextPath(DotvvmBindableControl contextControl) { // get the hierarchy of DataContext the control is in var dataContexts = contextControl.GetAllAncestors().OfType<DotvvmBindableControl>() .Select(c => new { Binding = c.GetBinding(DotvvmBindableControl.DataContextProperty, false), Control = c }) .Where(b => b.Binding != null) .ToList(); // evaluate the DataContext path var viewRoot = contextControl.GetRoot(); var visitor = new ExpressionEvaluationVisitor(GetRootDataContext(viewRoot), viewRoot) { AllowMethods = AllowMethods }; for (var i = dataContexts.Count - 1; i >= 0; i--) { var binding = dataContexts[i].Binding; if (!(binding is ValueBindingExpression)) { throw new Exception("The DataContext property can only contain value bindings!"); // TODO: exception handling } var pathExpression = ((ValueBindingExpression)binding).GetViewModelPathExpression(dataContexts[i].Control, DotvvmBindableControl.DataContextProperty); EvaluateBinding(visitor, binding.Expression, pathExpression); } return visitor; }
void AssertEval(string expression, string expected) { NUnit.Framework.Assert.AreEqual(expected, ExpressionEvaluationVisitor.FormatValue(EvalThread, Evaluate(CurrentStackFrame, EvalThread, expression, evalContext))); }
/// <summary> /// Resolves the path in the view model and returns the target object. /// </summary> private List<object> ResolveViewModelPath(object viewModel, RedwoodControl viewRootControl, string[] path) { var visitor = new ExpressionEvaluationVisitor(viewModel, viewRootControl); var outputHierarchy = new List<object>(); outputHierarchy.Add(viewModel); foreach (var expression in path) { // evaluate path fragment var pathTree = CSharpSyntaxTree.ParseText(expression, new CSharpParseOptions(LanguageVersion.CSharp5, DocumentationMode.Parse, SourceCodeKind.Interactive)); var pathExpr = pathTree.EnsureSingleExpression(); var result = visitor.Visit(pathExpr); visitor.BackupCurrentPosition(result, expression); outputHierarchy.Add(result); } return outputHierarchy; }
/// <summary> /// Evaluates the expression the on view model with specified hierarchy. /// </summary> private object EvaluateOnViewModel(object viewModel, RedwoodControl viewRootControl, List<object> hierarchy, string expression) { var pathTree = CSharpSyntaxTree.ParseText(expression, new CSharpParseOptions(LanguageVersion.CSharp5, DocumentationMode.Parse, SourceCodeKind.Interactive)); var pathExpr = pathTree.EnsureSingleExpression(); var visitor = new ExpressionEvaluationVisitor(viewModel, viewRootControl, hierarchy); return visitor.Visit(pathExpr); }
/// <summary> /// Finds the method on view model. /// </summary> private static MethodInfo FindMethodOnViewModel(object viewModel, RedwoodControl viewRootControl, List<object> hierarchy, InvocationExpressionSyntax node, out object target) { MethodInfo method; var methodEvaluator = new ExpressionEvaluationVisitor(viewModel, viewRootControl, hierarchy) { AllowMethods = true }; method = methodEvaluator.Visit(node.Expression) as MethodInfo; if (method == null) { throw new Exception("The command path was not found!"); } target = methodEvaluator.MethodInvocationTarget; return method; }
/// <summary> /// Evaluates the command arguments. /// </summary> private static object[] EvaluateCommandArguments(object viewModel, RedwoodControl viewRootControl, List<object> hierarchy, InvocationExpressionSyntax node) { var arguments = node.ArgumentList.Arguments.Select(a => { var evaluator = new ExpressionEvaluationVisitor(viewModel, viewRootControl, hierarchy); return evaluator.Visit(a); }).ToArray(); return arguments; }