protected SourceLocation DoParseExpression(ScriptingContext context, LocationType type, string arg) { F.Expression expr = context.ParseExpression(arg); MethodExpression mexpr = expr.ResolveMethod(context, type); if (mexpr != null) { return(mexpr.EvaluateSource(context)); } else { return(context.FindMethod(arg)); } }
public string EvaluateExpression(ScriptingContext context, string text, DisplayFormat format) { F.Expression expression = context.ParseExpression(text); try { expression = expression.Resolve(context); } catch (ScriptingException ex) { throw new ScriptingException("Cannot resolve expression `{0}': {1}", text, ex.Message); } catch { throw new ScriptingException("Cannot resolve expression `{0}'.", text); } try { object retval = expression.Evaluate(context); return(context.FormatObject(retval, format)); } catch (ScriptingException ex) { throw new ScriptingException("Cannot evaluate expression `{0}': {1}", text, ex.Message); } catch { throw new ScriptingException("Cannot evaluate expression `{0}'.", text); } }
public string EvaluateExpression(ScriptingContext context, string text, DisplayFormat format) { F.Expression expression = context.ParseExpression (text); try { expression = expression.Resolve (context); } catch (ScriptingException ex) { throw new ScriptingException ("Cannot resolve expression `{0}': {1}", text, ex.Message); } catch { throw new ScriptingException ("Cannot resolve expression `{0}'.", text); } try { object retval = expression.Evaluate (context); return context.FormatObject (retval, format); } catch (ScriptingException ex) { throw new ScriptingException ("Cannot evaluate expression `{0}': {1}", text, ex.Message); } catch { throw new ScriptingException ("Cannot evaluate expression `{0}'.", text); } }
protected override bool DoResolve(ScriptingContext context) { if (global) { if (local) throw new ScriptingException ( "Cannot use both -local and -global."); if (Group != null) throw new ScriptingException ( "Cannot use both -group and -global."); tgroup = ThreadGroup.Global; } else if (local) { if (Group != null) throw new ScriptingException ( "Cannot use both -group and -local."); tgroup = context.Interpreter.GetThreadGroup (Group, false); } else if (Group != null) { tgroup = context.Interpreter.GetThreadGroup (Group, false); } else { tgroup = ThreadGroup.Global; } if (context.Interpreter.HasTarget) { context.CurrentProcess = context.Interpreter.GetProcess (p_index); context.CurrentThread = context.Interpreter.GetThread (t_index); } if (!gui && !lazy && context.Interpreter.HasTarget) { Thread thread = context.CurrentThread; if (!thread.IsStopped) throw new TargetException (TargetError.NotStopped); Backtrace backtrace = thread.GetBacktrace (); StackFrame frame; if (f_index == -1) frame = backtrace.CurrentFrame; else { if (f_index >= backtrace.Count) throw new ScriptingException ( "No such frame: {0}", f_index); frame = backtrace [f_index]; } context.CurrentFrame = frame; if (context.Interpreter.ExpressionParser.ParseLocation (context, Argument, out location)) return true; } uint line; int pos = Argument.IndexOf (':'); if (pos == 0) throw new ScriptingException ("Invalid breakpoint expression"); else if (pos > 0) { string tmp = Argument.Substring (pos+1); if (!UInt32.TryParse (tmp, out line)) throw new ScriptingException ("Invalid breakpoint expression"); return true; } if (UInt32.TryParse (Argument, out line)) { if (!context.Interpreter.HasTarget) throw new ScriptingException ("Cannot insert breakpoint by line: no current source file."); return true; } Expression expr = context.ParseExpression (Argument); if (expr is PointerExpression) { address = ((PointerExpression) expr).EvaluateAddress (context); return true; } if (!context.Interpreter.HasTarget) return true; MethodExpression mexpr; try { mexpr = expr.ResolveMethod (context, type); } catch { mexpr = null; } if (mexpr != null) location = mexpr.EvaluateSource (context); else { location = context.FindMethod (Argument); if (location != null) return true; address = context.CurrentProcess.LookupSymbol (Argument); if (!address.IsNull) return true; } if (lazy || gui) return true; if (location == null) throw new ScriptingException ("No such method: `{0}'.", Argument); return true; }
protected override bool DoResolve(ScriptingContext context) { if (Argument == "") throw new ScriptingException ("Argument expected"); context.ParseExpression (Argument); return true; }
protected Expression DoParseExpression(ScriptingContext context, string arg) { return context.ParseExpression (arg); }
TargetType EvaluateExpressionType(ScriptingContext context, string expression) { try { Expression expr = context.ParseExpression (expression); Expression resolved = expr.TryResolveType (context); if (resolved != null) expr = resolved; else expr = expr.Resolve (context); if (expr == null) Assert.Fail ("Cannot resolve expression `{0}'.", expression); return expr.EvaluateType (context); } catch (ScriptingException) { throw; } catch (AssertionException) { throw; } catch (Exception ex) { Assert.Fail ("Failed to evalaute type of expression `{0}': {1}", expression, ex); return null; } }
object EvaluateExpression(ScriptingContext context, string expression) { try { Expression expr = context.ParseExpression (expression); expr = expr.Resolve (context); if (expr == null) Assert.Fail ("Cannot resolve expression `{0}'.", expression); object obj = expr.Evaluate (context); if (obj == null) Assert.Fail ("Failed to evaluate expression `{0}.", expression); return obj; } catch (ScriptingException) { throw; } catch (AssertionException) { throw; } catch (Exception ex) { Assert.Fail ("Failed to evalaute expression `{0}': {1}", expression, ex); return null; } }
protected SourceLocation DoParseExpression(ScriptingContext context, LocationType type, string arg) { F.Expression expr = context.ParseExpression (arg); MethodExpression mexpr = expr.ResolveMethod (context, type); if (mexpr != null) return mexpr.EvaluateSource (context); else return context.FindMethod (arg); }