Browse Source

Reverted expression caching

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4758 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
David Srbecký 16 years ago
parent
commit
3cfb2f81a5
  1. 196
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Expressions/ExpressionEvaluator.cs
  2. 1
      src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/AstEval.cs
  3. 1
      src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/Breakpoint.cs
  4. 2
      src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/MemoryReadWrite.cs
  5. 2
      src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/StackOverflow.cs

196
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Expressions/ExpressionEvaluator.cs

@ -121,12 +121,16 @@ namespace Debugger @@ -121,12 +121,16 @@ namespace Debugger
return false;
}
Value EvalAndPermRef(INode expression)
Value EvalAndCache(INode expression, bool permRef)
{
Stopwatch watch = new Stopwatch();
watch.Start();
Value val = (Value)expression.AcceptVisitor(this, null);
if (val != null)
if (val != null && permRef)
val = val.GetPermanentReference();
AddToCache(expression, val);
watch.Stop();
context.Process.TraceMessage("Evaluated: {0} in {1} ms total", expression.PrettyPrint(), watch.ElapsedMilliseconds);
return val;
}
@ -141,61 +145,8 @@ namespace Debugger @@ -141,61 +145,8 @@ namespace Debugger
this.context = context;
}
IDisposable LogEval(INode expression)
{
Stopwatch watch = new Stopwatch();
watch.Start();
return new CallbackOnDispose(delegate {
if (!context.Process.CachedExpressions.ContainsKey(expression))
throw new DebuggerException("Result not added to cache");
watch.Stop();
context.Process.TraceMessage("Evaluated: {0} in {1} ms total", expression.PrettyPrint(), watch.ElapsedMilliseconds);
});
}
public override object VisitEmptyStatement(EmptyStatement emptyStatement, object data)
{
using(LogEval(emptyStatement)) {
return null;
}
}
public override object VisitExpressionStatement(ExpressionStatement expressionStatement, object data)
{
using(LogEval(expressionStatement)) {
EvalAndPermRef(expressionStatement.Expression);
return null;
}
}
public override object VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, object data)
{
Value cached;
if (TryGetCached(parenthesizedExpression, out cached)) return cached;
using(LogEval(parenthesizedExpression)) {
Value res = EvalAndPermRef(parenthesizedExpression.Expression);
AddToCache(parenthesizedExpression, res);
return res;
}
}
public override object VisitBlockStatement(BlockStatement blockStatement, object data)
{
using(LogEval(blockStatement)) {
foreach(INode statement in blockStatement.Children) {
EvalAndPermRef(statement);
}
return null;
}
}
/// <remarks> We have to put that in cache as well otherwise expaning (a = b).Prop will reevalute </remarks>
public override object VisitAssignmentExpression(AssignmentExpression assignmentExpression, object data)
{
Value cached;
if (TryGetCached(assignmentExpression, out cached)) return cached;
using(LogEval(assignmentExpression)) {
BinaryOperatorType op;
switch (assignmentExpression.Op) {
case AssignmentOperatorType.Assign: op = BinaryOperatorType.None; break;
@ -217,7 +168,7 @@ namespace Debugger @@ -217,7 +168,7 @@ namespace Debugger
Value right;
if (op == BinaryOperatorType.None) {
right = EvalAndPermRef(assignmentExpression.Right);
right = (Value)assignmentExpression.Right.AcceptVisitor(this, null);
} else {
BinaryOperatorExpression binOpExpr = new BinaryOperatorExpression();
binOpExpr.Left = assignmentExpression.Left;
@ -227,71 +178,74 @@ namespace Debugger @@ -227,71 +178,74 @@ namespace Debugger
}
right = right.GetPermanentReference();
Value left = EvalAndPermRef(assignmentExpression.Left);
Value left = ((Value)assignmentExpression.Left.AcceptVisitor(this, null));
if (!left.IsReference && left.Type.FullName != right.Type.FullName) {
throw new GetValueException(string.Format("Type {0} expected, {1} seen", left.Type.FullName, right.Type.FullName));
}
left.SetValue(right);
AddToCache(assignmentExpression, right);
return right;
}
public override object VisitBlockStatement(BlockStatement blockStatement, object data)
{
foreach(INode statement in blockStatement.Children) {
statement.AcceptVisitor(this, null);
}
return null;
}
public override object VisitEmptyStatement(EmptyStatement emptyStatement, object data)
{
return null;
}
public override object VisitExpressionStatement(ExpressionStatement expressionStatement, object data)
{
expressionStatement.Expression.AcceptVisitor(this, null);
return null;
}
public override object VisitIdentifierExpression(IdentifierExpression identifierExpression, object data)
{
Value cached;
if (TryGetCached(identifierExpression, out cached)) return cached;
using(LogEval(identifierExpression)) {
string identifier = identifierExpression.Identifier;
Value result = null;
if (identifier == "__exception") {
if (context.Thread.CurrentException != null) {
result = context.Thread.CurrentException.Value;
return context.Thread.CurrentException.Value;
} else {
throw new GetValueException("No current exception");
}
}
result = result ?? context.GetArgumentValue(identifier);
Value arg = context.GetArgumentValue(identifier);
if (arg != null) return arg;
result = result ?? context.GetLocalVariableValue(identifier);
Value local = context.GetLocalVariableValue(identifier);
if (local != null) return local;
if (result == null) {
if (!context.MethodInfo.IsStatic) {
// Can be null
result = context.GetThisValue().GetMemberValue(identifier);
Value member = context.GetThisValue().GetMemberValue(identifier);
if (member != null) return member;
} else {
MemberInfo memberInfo = context.MethodInfo.DeclaringType.GetMember(identifier);
if (memberInfo != null && memberInfo.IsStatic) {
result = Value.GetMemberValue(null, memberInfo, null);
}
return Value.GetMemberValue(null, memberInfo, null);
}
}
if (result == null)
throw new GetValueException("Identifier \"" + identifier + "\" not found in this context");
AddToCache(identifierExpression, result);
return result;
}
}
public override object VisitIndexerExpression(IndexerExpression indexerExpression, object data)
{
Value cached;
if (TryGetCached(indexerExpression, out cached)) return cached;
using(LogEval(indexerExpression)) {
List<Value> indexes = new List<Value>();
foreach(Expression indexExpr in indexerExpression.Indexes) {
Value indexValue = EvalAndPermRef(indexExpr);
Value indexValue = ((Value)indexExpr.AcceptVisitor(this, null)).GetPermanentReference();
indexes.Add(indexValue);
}
Value target = EvalAndPermRef(indexerExpression.TargetObject);
Value target = (Value)indexerExpression.TargetObject.AcceptVisitor(this, null);
if (target.Type.IsArray) {
List<int> intIndexes = new List<int>();
@ -313,23 +267,16 @@ namespace Debugger @@ -313,23 +267,16 @@ namespace Debugger
PropertyInfo pi = target.Type.GetProperty("Item");
if (pi == null) throw new GetValueException("The object does not have an indexer property");
Value result = target.GetPropertyValue(pi, indexes.ToArray());
AddToCache(indexerExpression, result);
return result;
}
return target.GetPropertyValue(pi, indexes.ToArray());
}
public override object VisitInvocationExpression(InvocationExpression invocationExpression, object data)
{
Value cached;
if (TryGetCached(invocationExpression, out cached)) return cached;
using(LogEval(invocationExpression)) {
Value target;
string methodName;
MemberReferenceExpression memberRef = invocationExpression.TargetObject as MemberReferenceExpression;
if (memberRef != null) {
target = EvalAndPermRef(memberRef.TargetObject);
target = ((Value)memberRef.TargetObject.AcceptVisitor(this, null)).GetPermanentReference();
methodName = memberRef.MemberName;
} else {
IdentifierExpression ident = invocationExpression.TargetObject as IdentifierExpression;
@ -342,64 +289,44 @@ namespace Debugger @@ -342,64 +289,44 @@ namespace Debugger
}
List<Value> args = new List<Value>();
foreach(Expression expr in invocationExpression.Arguments) {
args.Add(EvalAndPermRef(expr));
args.Add(((Value)expr.AcceptVisitor(this, null)).GetPermanentReference());
}
MethodInfo method = target.Type.GetMember(methodName, BindingFlags.Method | BindingFlags.IncludeSuperType) as MethodInfo;
if (method == null) {
throw new GetValueException("Method " + methodName + " not found");
}
Value result = target.InvokeMethod(method, args.ToArray());
AddToCache(invocationExpression, result);
return result;
}
return target.InvokeMethod(method, args.ToArray());
}
public override object VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, object data)
{
Value cached;
if (TryGetCached(memberReferenceExpression, out cached)) return cached;
using(LogEval(memberReferenceExpression)) {
Value target = EvalAndPermRef(memberReferenceExpression.TargetObject);
Value target = (Value)memberReferenceExpression.TargetObject.AcceptVisitor(this, null);
Value member = target.GetMemberValue(memberReferenceExpression.MemberName);
if (member == null)
throw new GetValueException("Member \"" + memberReferenceExpression.MemberName + "\" not found");
AddToCache(memberReferenceExpression, member);
if (member != null) {
return member;
} else {
throw new GetValueException("Member \"" + memberReferenceExpression.MemberName + "\" not found");
}
}
public override object VisitPrimitiveExpression(PrimitiveExpression primitiveExpression, object data)
public override object VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, object data)
{
Value cached;
if (TryGetCached(primitiveExpression, out cached)) return cached;
using(LogEval(primitiveExpression)){
Value result = Eval.CreateValue(context.AppDomain, primitiveExpression.Value);
AddToCache(primitiveExpression, result);
return result;
return parenthesizedExpression.Expression.AcceptVisitor(this, null);
}
public override object VisitPrimitiveExpression(PrimitiveExpression primitiveExpression, object data)
{
return Eval.CreateValue(context.AppDomain, primitiveExpression.Value);
}
public override object VisitThisReferenceExpression(ThisReferenceExpression thisReferenceExpression, object data)
{
Value cached;
if (TryGetCached(thisReferenceExpression, out cached)) return cached;
using(LogEval(thisReferenceExpression)) {
Value result = context.GetThisValue();
AddToCache(thisReferenceExpression, result);
return result;
}
return context.GetThisValue();
}
public override object VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, object data)
{
Value cached;
if (TryGetCached(unaryOperatorExpression, out cached)) return cached;
using(LogEval(unaryOperatorExpression)) {
Value value = EvalAndPermRef(unaryOperatorExpression.Expression);
Value value = ((Value)unaryOperatorExpression.Expression.AcceptVisitor(this, null));
UnaryOperatorType op = unaryOperatorExpression.Op;
if (op == UnaryOperatorType.Dereference) {
@ -456,29 +383,18 @@ namespace Debugger @@ -456,29 +383,18 @@ namespace Debugger
if (result == null) throw new GetValueException("Unsuppored unary expression " + op);
Value res = Eval.CreateValue(context.AppDomain, result);
AddToCache(unaryOperatorExpression, res);
return res;
}
return Eval.CreateValue(context.AppDomain, result);
}
public override object VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data)
{
Value cached;
if (TryGetCached(binaryOperatorExpression, out cached)) return cached;
using(LogEval(binaryOperatorExpression)) {
Value left = EvalAndPermRef(binaryOperatorExpression.Left);
Value right = EvalAndPermRef(binaryOperatorExpression.Right);
Value left = ((Value)binaryOperatorExpression.Left.AcceptVisitor(this, null)).GetPermanentReference();
Value right = ((Value)binaryOperatorExpression.Right.AcceptVisitor(this, null)).GetPermanentReference();
object result = VisitBinaryOperatorExpressionInternal(left, right, binaryOperatorExpression.Op);
// Conver long to int if possible
if (result is long && int.MinValue <= (long)result && (long)result <= int.MaxValue) result = (int)(long)result;
Value res = Eval.CreateValue(context.AppDomain, result);
AddToCache(binaryOperatorExpression, res);
return res;
}
return Eval.CreateValue(context.AppDomain, result);
}
public object VisitBinaryOperatorExpressionInternal(Value leftValue, Value rightValue, BinaryOperatorType op)

1
src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/AstEval.cs

@ -38,7 +38,6 @@ namespace Debugger.Tests { @@ -38,7 +38,6 @@ namespace Debugger.Tests {
public partial class DebuggerTests
{
[NUnit.Framework.Test]
[NUnit.Framework.Ignore]
public void AstEval()
{
StartTest("AstEval.cs");

1
src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/Breakpoint.cs

@ -30,7 +30,6 @@ namespace Debugger.Tests { @@ -30,7 +30,6 @@ namespace Debugger.Tests {
public partial class DebuggerTests
{
[NUnit.Framework.Test]
[NUnit.Framework.Ignore]
public void Breakpoint()
{
Breakpoint breakpoint1 = debugger.Breakpoints.Add(@"Breakpoint.cs", 18);

2
src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/MemoryReadWrite.cs

@ -26,7 +26,7 @@ namespace Debugger.Tests { @@ -26,7 +26,7 @@ namespace Debugger.Tests {
public partial class DebuggerTests
{
[NUnit.Framework.Test]
[NUnit.Framework.Ignore]
[NUnit.Framework.Ignore("Different tokens in .NET 4")]
public void MemoryReadWrite()
{
StartTest("MemoryReadWrite.cs");

2
src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/StackOverflow.cs

@ -29,7 +29,7 @@ namespace Debugger.Tests { @@ -29,7 +29,7 @@ namespace Debugger.Tests {
public partial class DebuggerTests
{
[NUnit.Framework.Test]
[NUnit.Framework.Ignore]
[NUnit.Framework.Ignore("Different behaviour in .NET 4")]
public void StackOverflow()
{
StartTest("StackOverflow.cs");

Loading…
Cancel
Save