protected override ITargetObject DoEvaluateVariable(EvaluationContext context) { FrameHandle frame = context.CurrentFrame; TargetLocation location = EvaluateAddress (context); return frame.Language.CreatePointer (frame.Frame, location.Address); }
public override TargetLocation EvaluateAddress(EvaluationContext context) { ITargetObject obj = expr.EvaluateVariable (context); if (!obj.Location.HasAddress) throw new EvaluationException ( "Cannot take address of expression `{0}'", expr.Name); return obj.Location; }
protected override ITargetType DoEvaluateType(EvaluationContext context) { FrameHandle frame = context.CurrentFrame; ITargetPointerType ptype = expr.EvaluateType (context) as ITargetPointerType; if (ptype != null) return ptype; return frame.Language.PointerType; }
protected override ITargetObject DoEvaluateVariable(EvaluationContext context) { bool cond = false; try { cond = (bool) this.test.Evaluate (context); } catch (Exception e) { throw new EvaluationException ( "Cannot convert {0} to a boolean for conditional: {1}", this.test, e); } return cond ? true_expr.EvaluateVariable (context) : false_expr.EvaluateVariable (context); }
public static ITargetMethodInfo OverloadResolve(EvaluationContext context, ILanguage language, ITargetStructType stype, Expression[] types, ArrayList candidates) { // We do a very simple overload resolution here ITargetType[] argtypes = new ITargetType [types.Length]; for (int i = 0; i < types.Length; i++) argtypes [i] = types [i].EvaluateType (context); // Ok, no we need to find an exact match. ITargetMethodInfo match = null; foreach (ITargetMethodInfo method in candidates) { bool ok = true; for (int i = 0; i < types.Length; i++) { if (method.Type.ParameterTypes [i].TypeHandle != argtypes [i].TypeHandle) { ok = false; break; } } if (!ok) continue; // We need to find exactly one match if (match != null) return null; match = method; } return match; }
protected override Expression DoResolve(EvaluationContext context) { return ResolveMemberAccess (context, false); }
public Expression ResolveMemberAccess(EvaluationContext context, bool allow_instance) { StackFrame frame = context.CurrentFrame.Frame; Expression expr; Expression ltype = left.TryResolveType (context); if (ltype != null) { ITargetStructType stype = ltype.EvaluateType (context) as ITargetStructType; if (stype == null) throw new EvaluationException ( "`{0}' is not a struct or class", ltype.Name); expr = StructAccessExpression.FindMember ( stype, frame, null, allow_instance, name); if (expr == null) throw new EvaluationException ( "Type `{0}' has no member `{1}'", stype.Name, name); return expr; } Expression lexpr = left.TryResolve (context); if (lexpr == null) throw new EvaluationException ( "No such variable or type: `{0}'", left.Name); ITargetStructObject sobj = lexpr.EvaluateVariable (context) as ITargetStructObject; if (sobj == null) throw new EvaluationException ( "`{0}' is not a struct or class", left.Name); expr = StructAccessExpression.FindMember ( sobj.Type, frame, sobj, true, name); if (expr == null) throw new EvaluationException ( "Type `{0}' has no member `{1}'", sobj.Type.Name, name); return expr; }
protected override ITargetObject DoEvaluateVariable(EvaluationContext context) { return Invoke (context, false); }
protected virtual Expression DoResolveType(EvaluationContext context) { return null; }
public ITargetObject EvaluateVariable(EvaluationContext context) { if (!resolved) throw new InvalidOperationException ( String.Format ( "Some clown tried to evaluate the " + "unresolved expression `{0}' ({1})", Name, GetType ())); try { ITargetObject retval = DoEvaluateVariable (context); if (retval == null) throw new EvaluationException ( "Expression `{0}' is not a variable", Name); return retval; } catch (LocationInvalidException ex) { throw new EvaluationException ( "Location of variable `{0}' is invalid: {1}", Name, ex.Message); } }
public ITargetType EvaluateType(EvaluationContext context) { if (!resolved) throw new InvalidOperationException ( String.Format ( "Some clown tried to evaluate the " + "unresolved expression `{0}'", Name)); try { ITargetType type = DoEvaluateType (context); if (type == null) throw new EvaluationException ( "Cannot get type of expression `{0}'", Name); return type; } catch (LocationInvalidException ex) { throw new EvaluationException ( "Location of variable `{0}' is invalid: {1}", Name, ex.Message); } }
public SourceLocation EvaluateLocation(EvaluationContext context, LocationType type, Expression [] types) { if (!resolved) throw new InvalidOperationException ( String.Format ( "Some clown tried to evaluate the " + "unresolved expression `{0}'", Name)); try { SourceLocation location = DoEvaluateLocation (context, type, types); if (location == null) throw new EvaluationException ( "Expression `{0}' is not a method", Name); return location; } catch (LocationInvalidException ex) { throw new EvaluationException ( "Location of variable `{0}' is invalid: {1}", Name, ex.Message); } }
public object Evaluate(EvaluationContext context) { if (!resolved) throw new InvalidOperationException ( String.Format ( "Some clown tried to evaluate the " + "unresolved expression `{0}'", Name)); object result = DoEvaluate (context); if (result == null) throw new EvaluationException ( "Cannot evaluate expression `{0}'", Name); return result; }
public void Assign(EvaluationContext context, ITargetObject obj) { if (!resolved) throw new InvalidOperationException ( String.Format ( "Some clown tried to evaluate the " + "unresolved expression `{0}'", Name)); bool ok = DoAssign (context, obj); if (!ok) throw new EvaluationException ( "Expression `{0}' is not an lvalue", Name); }
protected override Expression DoResolve(EvaluationContext context) { test = test.Resolve (context); true_expr = true_expr.Resolve (context); false_expr = false_expr.Resolve (context); resolved = true; return this; }
protected virtual ITargetObject DoEvaluateVariable(EvaluationContext context) { return null; }
protected abstract Expression DoResolve(EvaluationContext context);
public Expression ResolveType(EvaluationContext context) { Expression expr = DoResolveType (context); if (expr == null) throw new EvaluationException ( "Expression `{0}' is not a type.", Name); return expr; }
public ITargetObject Invoke(EvaluationContext context, bool debug) { Expression[] args = new Expression [arguments.Length]; for (int i = 0; i < arguments.Length; i++) { args [i] = arguments [i].Resolve (context); if (args [i] == null) return null; } ITargetFunctionObject func = mg.EvaluateMethod ( context, context.CurrentFrame.Frame, args); ITargetObject[] objs = new ITargetObject [args.Length]; for (int i = 0; i < args.Length; i++) objs [i] = args [i].EvaluateVariable (context); try { ITargetObject retval = func.Invoke (objs, debug); if (!debug && !func.Type.HasReturnValue) throw new EvaluationException ("Method `{0}' doesn't return a value.", Name); return retval; } catch (Mono.Debugger.TargetInvocationException ex) { throw new EvaluationException ("Invocation of `{0}' raised an exception: {1}", Name, ex.Message); } }
public Expression TryResolveType(EvaluationContext context) { try { return DoResolveType (context); } catch (EvaluationException) { return null; } catch (Mono.Debugger.TargetException) { return null; } }
protected override SourceLocation DoEvaluateLocation(EvaluationContext context, LocationType type, Expression[] types) { Expression[] argtypes = new Expression [arguments.Length]; for (int i = 0; i < arguments.Length; i++) { argtypes [i] = arguments [i].ResolveType (context); if (argtypes [i] == null) return null; } return method_expr.EvaluateLocation (context, type, argtypes); }
protected virtual bool DoAssign(EvaluationContext context, ITargetObject obj) { return false; }
protected override Expression DoResolve(EvaluationContext context) { method_expr = method_expr.Resolve (context); if (method_expr == null) return null; mg = method_expr as MethodGroupExpression; if (mg == null) throw new EvaluationException ( "Expression `{0}' is not a method.", method_expr.Name); resolved = true; return this; }
protected virtual object DoEvaluate(EvaluationContext context) { return DoEvaluateVariable (context); }
protected override Expression DoResolve(EvaluationContext context) { expr = expr.Resolve (context); if (expr == null) return null; resolved = true; return this; }
protected virtual SourceLocation DoEvaluateLocation(EvaluationContext context, LocationType type, Expression[] types) { return null; }
protected override Expression DoResolveType(EvaluationContext context) { StackFrame frame = context.CurrentFrame.Frame; ITargetType the_type; Expression ltype = left.TryResolveType (context); if (ltype == null) the_type = frame.Language.LookupType (frame, Name); else { string nested = ltype.Name + "+" + name; the_type = frame.Language.LookupType (frame, nested); } if (the_type == null) return null; return new TypeExpression (the_type); }
protected virtual ITargetType DoEvaluateType(EvaluationContext context) { return EvaluateVariable (context).TypeInfo.Type; }
public string EvaluateDebuggerDisplay(ITargetObject obj, string display) { StringBuilder sb = new StringBuilder (""); DebuggingService dbgr = (DebuggingService)Runtime.DebuggingService; EvaluationContext ctx = new EvaluationContext (obj); ctx.CurrentProcess = new ProcessHandle (dbgr.MainThread); /* break up the string into runs of {...} and * normal text. treat the {...} as C# * expressions, and evaluate them */ int start_idx = 0; while (true) { int left_idx; int right_idx; left_idx = display.IndexOf ('{', start_idx); if (left_idx == -1) { /* we're done. */ sb.Append (display.Substring (start_idx)); break; } if (left_idx != start_idx) { sb.Append (display.Substring (start_idx, left_idx - start_idx)); } right_idx = display.IndexOf ('}', left_idx + 1); if (right_idx == -1) { // '{...\0'. ignore the '{', append the rest, and break out */ sb.Append (display.Substring (left_idx + 1)); break; } if (right_idx - left_idx > 1) { /* there's enough space for an * expression. parse it and see * what we get. */ RefParse.Parser parser; AST.Expression ast_expr; Expression dbgr_expr; DebuggerASTVisitor visitor; string snippet; object retval; /* parse the snippet to build up MD's AST */ parser = new RefParse.Parser(); snippet = display.Substring (left_idx + 1, right_idx - left_idx - 1); ast_expr = parser.ParseExpression (new RefParse.Lexer (new RefParse.StringReader (snippet))); /* use our visitor to convert from MD's AST to types that * facilitate evaluation by the debugger */ visitor = new DebuggerASTVisitor (); dbgr_expr = (Expression)ast_expr.AcceptVisitor (visitor, null); /* finally, resolve and evaluate the expression */ dbgr_expr = dbgr_expr.Resolve (ctx); retval = dbgr_expr.Evaluate (ctx); #region "c&p'ed from debugger/frontend/Style.cs" if (retval is long) { sb.Append (String.Format ("0x{0:x}", (long) retval)); } else if (retval is string) { sb.Append ('"' + (string) retval + '"'); } else if (retval is ITargetObject) { ITargetObject tobj = (ITargetObject) retval; sb.Append (tobj.Print ()); } else { sb.Append (retval.ToString ()); } #endregion } start_idx = right_idx + 1; } return sb.ToString (); }
static ITargetClassObject TryParentCast(EvaluationContext context, ITargetClassObject source, ITargetClassType source_type, ITargetClassType target_type) { if (source_type == target_type) return source; if (!source_type.HasParent) return null; source = TryParentCast ( context, source, source_type.ParentType, target_type); if (source == null) return null; return source.Parent; }