Browse Source

Evaluate instance fields.

pull/191/merge
Eusebiu Marcu 16 years ago
parent
commit
a1a8243e26
  1. 6
      Debugger/Debugger.Core/NRefactory/Ast/ExpressionExtensionMethods.cs
  2. 40
      Debugger/Debugger.Core/NRefactory/Visitors/ExpressionEvaluator.cs
  3. 21
      Debugger/ILSpy.Debugger/Models/TreeModel/ChildNodesOfObject.cs
  4. 24
      Debugger/ILSpy.Debugger/Models/TreeModel/ExpressionNode.cs

6
Debugger/Debugger.Core/NRefactory/Ast/ExpressionExtensionMethods.cs

@ -305,7 +305,11 @@ namespace ICSharpCode.NRefactory.Ast @@ -305,7 +305,11 @@ namespace ICSharpCode.NRefactory.Ast
//
public static DebugType ResolveType(this AstNode expr, Debugger.AppDomain appDomain)
{
return expr.GetStaticType();
var result = expr.GetStaticType();
if (result != null)
return result;
return DebugType.CreateFromType(appDomain, expr.Annotation<Type>());
// if (expr is AstType && expr.GetStaticType() != null)
// return expr.GetStaticType();

40
Debugger/Debugger.Core/NRefactory/Visitors/ExpressionEvaluator.cs

@ -351,6 +351,7 @@ namespace ICSharpCode.NRefactory.Visitors @@ -351,6 +351,7 @@ namespace ICSharpCode.NRefactory.Visitors
{
TypedValue val = Evaluate(castExpression.Expression);
DebugType castTo = castExpression.Type.ResolveType(context.AppDomain);
if (castTo.IsPrimitive && val.Type.IsPrimitive && castTo != val.Type) {
object oldVal = val.PrimitiveValue;
object newVal;
@ -367,7 +368,7 @@ namespace ICSharpCode.NRefactory.Visitors @@ -367,7 +368,7 @@ namespace ICSharpCode.NRefactory.Visitors
throw new GetValueException("Can not cast {0} to {1}", val.Value.Type.FullName, castTo.FullName);
return new TypedValue(val.Value, castTo);
}
public override object VisitIdentifierExpression(IdentifierExpression identifierExpression, object data)
{
string identifier = identifierExpression.Identifier;
@ -403,7 +404,7 @@ namespace ICSharpCode.NRefactory.Visitors @@ -403,7 +404,7 @@ namespace ICSharpCode.NRefactory.Visitors
// Instance class members
// Note that the method might be generated instance method that represents anonymous method
TypedValue thisValue = GetThisValue();
TypedValue thisValue = this.GetThisValue();
if (thisValue != null) {
IDebugMemberInfo instMember = (IDebugMemberInfo)thisValue.Type.GetMember<MemberInfo>(identifier, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, DebugType.IsFieldOrNonIndexedProperty);
if (instMember != null)
@ -419,7 +420,7 @@ namespace ICSharpCode.NRefactory.Visitors @@ -419,7 +420,7 @@ namespace ICSharpCode.NRefactory.Visitors
throw new GetValueException("Identifier \"" + identifier + "\" not found in this context");
}
public override object VisitIndexerExpression(IndexerExpression indexerExpression, object data)
{
TypedValue target = Evaluate(indexerExpression.Target);
@ -453,7 +454,7 @@ namespace ICSharpCode.NRefactory.Visitors @@ -453,7 +454,7 @@ namespace ICSharpCode.NRefactory.Visitors
);
}
}
public override object VisitInvocationExpression(InvocationExpression invocationExpression, object data)
{
TypedValue target;
@ -491,7 +492,7 @@ namespace ICSharpCode.NRefactory.Visitors @@ -491,7 +492,7 @@ namespace ICSharpCode.NRefactory.Visitors
return null;
return new TypedValue(retVal, (DebugType)method.ReturnType);
}
public override object VisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression, object data)
{
if (!objectCreateExpression.Initializer.IsNull)
@ -505,7 +506,7 @@ namespace ICSharpCode.NRefactory.Visitors @@ -505,7 +506,7 @@ namespace ICSharpCode.NRefactory.Visitors
Value val = (Value)ctor.Invoke(GetValues(ctorArgs));
return new TypedValue(val, type);
}
public override object VisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression, object data)
{
if (arrayCreateExpression.AdditionalArraySpecifiers.Count() != 0)
@ -532,7 +533,7 @@ namespace ICSharpCode.NRefactory.Visitors @@ -532,7 +533,7 @@ namespace ICSharpCode.NRefactory.Visitors
}
return new TypedValue(array, type);
}
public override object VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, object data)
{
TypedValue target;
@ -558,26 +559,23 @@ namespace ICSharpCode.NRefactory.Visitors @@ -558,26 +559,23 @@ namespace ICSharpCode.NRefactory.Visitors
((IDebugMemberInfo)memberInfos[0]).MemberType
);
}
public override object VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, object data)
{
return Evaluate(parenthesizedExpression.Expression);
}
public override object VisitPrimitiveExpression(PrimitiveExpression primitiveExpression, object data)
{
return CreateValue(primitiveExpression.Value);
}
TypedValue GetThisValue()
{
// This is needed so that captured 'this' is supported
DebugLocalVariableInfo thisVar = context.MethodInfo.GetLocalVariableThis();
if (thisVar != null)
return new TypedValue(thisVar.GetValue(context), (DebugType)thisVar.LocalType);
return null;
return new TypedValue(context.GetThisValue(), (DebugType)context.MethodInfo.DeclaringType);
}
public override object VisitThisReferenceExpression(ThisReferenceExpression thisReferenceExpression, object data)
{
TypedValue thisValue = GetThisValue();
@ -585,9 +583,9 @@ namespace ICSharpCode.NRefactory.Visitors @@ -585,9 +583,9 @@ namespace ICSharpCode.NRefactory.Visitors
throw new GetValueException(context.MethodInfo.FullName + " is static method and does not have \"this\"");
return thisValue;
}
#region Binary and unary expressions
public override object VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, object data)
{
TypedValue value = Evaluate(unaryOperatorExpression.Expression);
@ -664,7 +662,7 @@ namespace ICSharpCode.NRefactory.Visitors @@ -664,7 +662,7 @@ namespace ICSharpCode.NRefactory.Visitors
throw new EvaluateException(unaryOperatorExpression, "Can not use the unary operator {0} on type {1}", op.ToString(), value.Type.FullName);
}
/// <summary>
/// Perform given arithmetic operation.
/// The arguments must be already converted to the correct types.
@ -732,7 +730,7 @@ namespace ICSharpCode.NRefactory.Visitors @@ -732,7 +730,7 @@ namespace ICSharpCode.NRefactory.Visitors
return null;
}
public override object VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data)
{
BinaryOperatorType op = binaryOperatorExpression.Operator;
@ -843,7 +841,7 @@ namespace ICSharpCode.NRefactory.Visitors @@ -843,7 +841,7 @@ namespace ICSharpCode.NRefactory.Visitors
throw new EvaluateException(binaryOperatorExpression, "Can not use the binary operator {0} on types {1} and {2}", op.ToString(), left.Type.FullName, right.Type.FullName);
}
/// <summary>
/// Perform given arithmetic operation.
/// The arguments must be already converted to the correct types.
@ -1024,7 +1022,7 @@ namespace ICSharpCode.NRefactory.Visitors @@ -1024,7 +1022,7 @@ namespace ICSharpCode.NRefactory.Visitors
return null;
}
}
#endregion
}
}

21
Debugger/ILSpy.Debugger/Models/TreeModel/ChildNodesOfObject.cs

@ -100,7 +100,7 @@ namespace ILSpy.Debugger.Models.TreeModel @@ -100,7 +100,7 @@ namespace ILSpy.Debugger.Models.TreeModel
// This is needed for expanding IEnumerable<T>
var type = new SimpleType() { Identifier = typeof(IList).FullName };
type.AddAnnotation(DebugType.CreateFromType(Mscorlib, typeof(IList)));
type.AddAnnotation(typeof(IList));
targetObject = new CastExpression() { Expression = targetObject.Clone(), Type = type };
@ -151,24 +151,5 @@ namespace ILSpy.Debugger.Models.TreeModel @@ -151,24 +151,5 @@ namespace ILSpy.Debugger.Models.TreeModel
}
}
}
static Module mscorlib;
public static Module Mscorlib {
get {
if (mscorlib != null) return mscorlib;
foreach (var appDomain in WindowsDebugger.CurrentProcess.AppDomains) {
foreach(Module m in appDomain.Process.Modules) {
if (m.Name == "mscorlib.dll" &&
m.AppDomain == appDomain) {
mscorlib = m;
return mscorlib;
}
}
}
throw new DebuggerException("Mscorlib not loaded");
}
}
}
}

24
Debugger/ILSpy.Debugger/Models/TreeModel/ExpressionNode.cs

@ -149,13 +149,23 @@ namespace ILSpy.Debugger.Models.TreeModel @@ -149,13 +149,23 @@ namespace ILSpy.Debugger.Models.TreeModel
Value val;
try {
if (expression is IdentifierExpression) {
var frame = WindowsDebugger.DebuggedProcess.SelectedThread.MostRecentStackFrame;
int token = frame.MethodInfo.MetadataToken;
List<ILVariable> list;
if (ILAstBuilder.MemberLocalVariables.TryGetValue(token, out list)) {
var variable = list.Find(v => v.Name == Name);
if (variable != null) {
var frame = WindowsDebugger.DebuggedProcess.SelectedThread.MostRecentStackFrame;
int token = frame.MethodInfo.MetadataToken;
// get the target name
int index = Name.IndexOf('.');
string targetName = Name;
if (index != -1) {
targetName = Name.Substring(0, index);
}
List<ILVariable> list;
if (ILAstBuilder.MemberLocalVariables.TryGetValue(token, out list)) {
var variable = list.Find(v => v.Name == targetName);
if (variable != null) {
if (expression is MemberReferenceExpression) {
var memberExpression = (MemberReferenceExpression)expression;
memberExpression.Target.AddAnnotation(new int[] { variable.OriginalVariable.Index });
} else {
expression.AddAnnotation(new int[] { variable.OriginalVariable.Index });
}
}

Loading…
Cancel
Save