Browse Source

Initial implementation of expression evaluator

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2789 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
David Srbecký 18 years ago
parent
commit
bf2a0e0547
  1. 7
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/StackFrame.cs
  2. 43
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Expressions/EvaluateAstVisitor.cs
  3. 11
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Expressions/Expression.Evaluate.cs

7
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/StackFrame.cs

@ -494,11 +494,16 @@ namespace Debugger
IEnumerable<Value> LocalVariablesEnum { IEnumerable<Value> LocalVariablesEnum {
get { get {
foreach(ISymUnmanagedVariable symVar in this.MethodInfo.LocalVariables) { foreach(ISymUnmanagedVariable symVar in this.MethodInfo.LocalVariables) {
yield return new Value(process, symVar.Name, GetCorValueOfLocalVariable(symVar)); yield return GetLocalVariableValue(symVar);
} }
} }
} }
public Value GetLocalVariableValue(ISymUnmanagedVariable symVar)
{
return new Value(this.Process, symVar.Name, GetCorValueOfLocalVariable(symVar));
}
ICorDebugValue GetCorValueOfLocalVariable(ISymUnmanagedVariable symVar) ICorDebugValue GetCorValueOfLocalVariable(ISymUnmanagedVariable symVar)
{ {
if (this.HasExpired) throw new CannotGetValueException("StackFrame has expired"); if (this.HasExpired) throw new CannotGetValueException("StackFrame has expired");

43
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Expressions/EvaluateAstVisitor.cs

@ -11,6 +11,7 @@ using System.Collections.Generic;
using ICSharpCode.NRefactory; using ICSharpCode.NRefactory;
using ICSharpCode.NRefactory.PrettyPrinter; using ICSharpCode.NRefactory.PrettyPrinter;
using ICSharpCode.NRefactory.Ast; using ICSharpCode.NRefactory.Ast;
using Ast = ICSharpCode.NRefactory.Ast;
using Debugger.Wrappers.CorSym; using Debugger.Wrappers.CorSym;
namespace Debugger namespace Debugger
@ -28,19 +29,55 @@ namespace Debugger
this.stackFrame = stackFrame; this.stackFrame = stackFrame;
} }
public override object VisitThisReferenceExpression(ThisReferenceExpression thisReferenceExpression, object data)
{
return this.StackFrame.ThisValue;
}
public override object VisitIdentifierExpression(IdentifierExpression identifierExpression, object data) public override object VisitIdentifierExpression(IdentifierExpression identifierExpression, object data)
{ {
throw new NotImplementedException(); if (identifierExpression is LocalVariableIdentifierExpression) {
LocalVariableIdentifierExpression localVariableIdentifierExpression = (LocalVariableIdentifierExpression)identifierExpression;
return this.StackFrame.GetLocalVariableValue(localVariableIdentifierExpression.SymVar);
} else if (identifierExpression is ParameterIdentifierExpression) {
ParameterIdentifierExpression parameterIdentifierExpression = (ParameterIdentifierExpression)identifierExpression;
return this.StackFrame.GetArgument(parameterIdentifierExpression.ParameterIndex);
} else {
return this.StackFrame.GetValue(identifierExpression.Identifier);
}
} }
public override object VisitIndexerExpression(IndexerExpression indexerExpression, object data) public override object VisitIndexerExpression(IndexerExpression indexerExpression, object data)
{ {
throw new NotImplementedException(); Value target = (Value)indexerExpression.TargetObject.AcceptVisitor(this, data);
List<int> indexes = new List<int>();
foreach(Ast.Expression indexExpr in indexerExpression.Indexes) {
if (indexExpr is PrimitiveExpression) {
PrimitiveExpression primitiveExpression = (PrimitiveExpression)indexExpr;
indexes.Add(int.Parse(primitiveExpression.StringValue));
} else {
Value indexValue = (Value)indexExpr.AcceptVisitor(this, data);
if (!indexValue.IsInteger) {
throw new DebuggerException("Integer expected");
}
indexes.Add((int)indexValue.PrimitiveValue);
}
}
return target.GetArrayElement(indexes.ToArray());
} }
public override object VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, object data) public override object VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, object data)
{ {
throw new NotImplementedException(); Value target = (Value)memberReferenceExpression.TargetObject.AcceptVisitor(this, data);
if (memberReferenceExpression is FieldReferenceExpression) {
FieldReferenceExpression fieldReferenceExpression = (FieldReferenceExpression)memberReferenceExpression;
return target.GetFieldValue(fieldReferenceExpression.FieldInfo);
} else if (memberReferenceExpression is PropertyReferenceExpression) {
PropertyReferenceExpression propertyReferenceExpression = (PropertyReferenceExpression)memberReferenceExpression;
return target.GetPropertyValue(propertyReferenceExpression.PropertyInfo);
} else {
return target.GetMember(memberReferenceExpression.FieldName);
}
} }
} }
} }

11
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Expressions/Expression.Evaluate.cs

@ -17,9 +17,16 @@ namespace Debugger
{ {
public partial class Expression: DebuggerObject public partial class Expression: DebuggerObject
{ {
public Value Evaluate() public Value Evaluate(Process process)
{ {
return Evaluate(null); if (process != null &&
process.SelectedThread != null &&
process.SelectedThread.SelectedStackFrame != null)
{
return Evaluate(process.SelectedThread.SelectedStackFrame);
} else {
return null;
}
} }
public Value Evaluate(StackFrame stackFrame) public Value Evaluate(StackFrame stackFrame)

Loading…
Cancel
Save