Browse Source

Fixed casting bug

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5325 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
David Srbecký 16 years ago
parent
commit
7a5ed71060
  1. 6
      src/AddIns/Debugger/Debugger.Core/NRefactory/Ast/ExpressionExtensionMethods.cs
  2. 15
      src/AddIns/Debugger/Debugger.Core/NRefactory/Visitors/ExpressionEvaluator.cs
  3. 19
      src/AddIns/Debugger/Debugger.Tests/Tests/ExpressionEvaluator_Tests.cs

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

@ -275,6 +275,8 @@ namespace ICSharpCode.NRefactory.Ast @@ -275,6 +275,8 @@ namespace ICSharpCode.NRefactory.Ast
if (expr is TypeReferenceExpression && ((TypeReferenceExpression)expr).TypeReference.GetStaticType() != null)
return ((TypeReferenceExpression)expr).TypeReference.GetStaticType();
appDomain.Process.TraceMessage("Resolving {0}", expr.PrettyPrint());
TypeReference typeRef = NormalizeTypeReference(expr);
List<TypeReference> genTypeRefs;
@ -314,14 +316,12 @@ namespace ICSharpCode.NRefactory.Ast @@ -314,14 +316,12 @@ namespace ICSharpCode.NRefactory.Ast
Array.Resize(ref outterGenArgs, genArgs.Length - typeRef.GenericTypes.Count);
DebugType outter = ResolveTypeInternal(((InnerClassTypeReference)typeRef).BaseType, outterGenArgs, appDomain);
if (outter == null)
return null;
string nestedName = typeRef.GenericTypes.Count == 0 ? typeRef.Type : typeRef.Type + "`" + typeRef.GenericTypes.Count;
type = DebugType.CreateFromName(appDomain, nestedName, outter, genArgs);
}
if (type == null)
return null;
throw new GetValueException("Can not resolve " + typeRef.PrettyPrint());
for(int i = 0; i < typeRef.PointerNestingLevel; i++) {
type = (DebugType)type.MakePointerType();

15
src/AddIns/Debugger/Debugger.Core/NRefactory/Visitors/ExpressionEvaluator.cs

@ -270,17 +270,6 @@ namespace ICSharpCode.NRefactory.Visitors @@ -270,17 +270,6 @@ namespace ICSharpCode.NRefactory.Visitors
return types.ToArray();
}
DebugType GetDebugType(INode expr)
{
if (expr is ParenthesizedExpression) {
return GetDebugType(((ParenthesizedExpression)expr).Expression);
} else if (expr is CastExpression) {
return ((CastExpression)expr).CastTo.ResolveType(context.AppDomain);
} else {
return null;
}
}
TypedValue CreateValue(object primitiveValue)
{
Value val = Eval.CreateValue(context.AppDomain, primitiveValue);
@ -465,8 +454,6 @@ namespace ICSharpCode.NRefactory.Visitors @@ -465,8 +454,6 @@ namespace ICSharpCode.NRefactory.Visitors
// Static
target = null;
targetType = memberRef.TargetObject.ResolveType(context.AppDomain);
if (targetType == null)
throw;
}
methodName = memberRef.MemberName;
} else {
@ -540,8 +527,6 @@ namespace ICSharpCode.NRefactory.Visitors @@ -540,8 +527,6 @@ namespace ICSharpCode.NRefactory.Visitors
// Static
target = null;
targetType = memberReferenceExpression.TargetObject.ResolveType(context.AppDomain);
if (targetType == null)
throw;
}
MemberInfo[] memberInfos = targetType.GetMember(memberReferenceExpression.MemberName, DebugType.BindingFlagsAllInScope);
if (memberInfos.Length == 0)

19
src/AddIns/Debugger/Debugger.Tests/Tests/ExpressionEvaluator_Tests.cs

@ -134,6 +134,7 @@ namespace Debugger.Tests @@ -134,6 +134,7 @@ namespace Debugger.Tests
List<char> list = new List<char>(array);
DerivedClass myClass = new DerivedClass();
BaseClass myClass2 = myClass;
int*[][,] complexType1 = new int*[][,] { new int*[,] { { (int*)0xDA1D } } };
A<int>.B.C<char>[][,] complexType2 = new A<int>.B.C<char>[0][,];
@ -195,6 +196,11 @@ namespace Debugger.Tests { @@ -195,6 +196,11 @@ namespace Debugger.Tests {
list.Add((char)42); list.Add((char)52); list
list = new System.Collections.Generic.List<char>(array2); list
(Debugger.Tests.ExpressionEvaluator_Tests.BaseClass)myClass
(Debugger.Tests.ExpressionEvaluator_Tests.DerivedClass)myClass2
(string)i
(string)hi
(int)hi
";
[NUnit.Framework.Test]
@ -307,9 +313,9 @@ namespace Debugger.Tests { @@ -307,9 +313,9 @@ namespace Debugger.Tests {
<ProcessStarted />
<ModuleLoaded>mscorlib.dll (No symbols)</ModuleLoaded>
<ModuleLoaded>ExpressionEvaluator_Tests.exe (Has symbols)</ModuleLoaded>
<DebuggingPaused>Break ExpressionEvaluator_Tests.cs:145,4-145,40</DebuggingPaused>
<DebuggingPaused>StepComplete ExpressionEvaluator_Tests.cs:146,4-146,19</DebuggingPaused>
<DebuggingPaused>StepComplete ExpressionEvaluator_Tests.cs:147,4-147,39</DebuggingPaused>
<DebuggingPaused>Break ExpressionEvaluator_Tests.cs:146,4-146,40</DebuggingPaused>
<DebuggingPaused>StepComplete ExpressionEvaluator_Tests.cs:147,4-147,19</DebuggingPaused>
<DebuggingPaused>StepComplete ExpressionEvaluator_Tests.cs:148,4-148,39</DebuggingPaused>
<Eval> </Eval>
<Eval> b = 1 </Eval>
<Eval> i = 4 </Eval>
@ -405,6 +411,11 @@ namespace Debugger.Tests { @@ -405,6 +411,11 @@ namespace Debugger.Tests {
<Eval> list = new System.Collections.Generic.List&lt;char&gt;(array2) = List`1 {'w', 'o', 'r', 'l', 'd'} </Eval>
<Eval> list = List`1 {'w', 'o', 'r', 'l', 'd'} </Eval>
<Eval> </Eval>
<Eval> (Debugger.Tests.ExpressionEvaluator_Tests.BaseClass)myClass = Debugger.Tests.ExpressionEvaluator_Tests+DerivedClass </Eval>
<Eval> (Debugger.Tests.ExpressionEvaluator_Tests.DerivedClass)myClass2 = Debugger.Tests.ExpressionEvaluator_Tests+DerivedClass </Eval>
<Eval> (string)i = Can not cast System.Int32 to System.String </Eval>
<Eval> (string)hi = "hi" </Eval>
<Eval> (int)hi = Can not cast System.String to System.Int32 </Eval>
<Eval> </Eval>
<Eval> Debugger.Tests.ExpressionEvaluator_Tests.DerivedClass.ConstInt = 42 </Eval>
<Eval> Debugger.Tests.ExpressionEvaluator_Tests.DerivedClass.ConstString = "const string" </Eval>
@ -440,7 +451,7 @@ namespace Debugger.Tests { @@ -440,7 +451,7 @@ namespace Debugger.Tests {
<TypesIdentitcal>True</TypesIdentitcal>
<TypesEqual>True</TypesEqual>
<WorkerThreadMoved>False</WorkerThreadMoved>
<DebuggingPaused>Break ExpressionEvaluator_Tests.cs:148,4-148,40</DebuggingPaused>
<DebuggingPaused>Break ExpressionEvaluator_Tests.cs:149,4-149,40</DebuggingPaused>
<WorkerThreadMoved>True</WorkerThreadMoved>
<ProcessExited />
</Test>

Loading…
Cancel
Save