Browse Source

Bugfixes in type resolution. Written unit tests for it.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5155 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
David Srbecký 16 years ago
parent
commit
4482b90ae4
  1. 60
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/NRefactory/Ast/ExpressionExtensionMethods.cs
  2. 56
      src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/Tests/DebugType_Tests.cs
  3. 49
      src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/Tests/ExpressionEvaluator_Tests.cs

60
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/NRefactory/Ast/ExpressionExtensionMethods.cs

@ -127,12 +127,6 @@ namespace ICSharpCode.NRefactory.Ast
public static TypeReference GetTypeReference(this Type type) public static TypeReference GetTypeReference(this Type type)
{ {
int pointerNest = 0;
while(type.IsPointer) {
pointerNest++;
type = type.GetElementType();
}
List<int> arrayRanks = new List<int>(); List<int> arrayRanks = new List<int>();
while(type.IsArray) { while(type.IsArray) {
// C# uses reverse array order // C# uses reverse array order
@ -140,7 +134,13 @@ namespace ICSharpCode.NRefactory.Ast
type = type.GetElementType(); type = type.GetElementType();
} }
if (type.IsPointer) int pointerNest = 0;
while(type.IsPointer) {
pointerNest++;
type = type.GetElementType();
}
if (type.IsArray)
throw new DebuggerException("C# does not support pointers to arrays"); throw new DebuggerException("C# does not support pointers to arrays");
string name = type.Name; string name = type.Name;
@ -149,19 +149,23 @@ namespace ICSharpCode.NRefactory.Ast
if (!string.IsNullOrEmpty(type.Namespace)) if (!string.IsNullOrEmpty(type.Namespace))
name = type.Namespace + "." + name; name = type.Namespace + "." + name;
List<TypeReference> genArgs = new List<TypeReference>(); List<Type> genArgs = new List<Type>();
// TODO: Does it inlucde parent gen arguments genArgs.AddRange(type.GetGenericArguments());
foreach(Type genArg in type.GetGenericArguments()) if (type.DeclaringType != null)
genArgs.Add(genArg.GetTypeReference()); genArgs.RemoveRange(0, type.DeclaringType.GetGenericArguments().Length);
List<TypeReference> genTypeRefs = new List<TypeReference>();
foreach(Type genArg in genArgs) {
genTypeRefs.Add(genArg.GetTypeReference());
}
if (type.DeclaringType != null) { if (type.DeclaringType != null) {
TypeReference outterRef = type.DeclaringType.GetTypeReference(); TypeReference outterRef = type.DeclaringType.GetTypeReference();
InnerClassTypeReference innerRef = new InnerClassTypeReference(outterRef, name, genArgs); InnerClassTypeReference innerRef = new InnerClassTypeReference(outterRef, name, genTypeRefs);
innerRef.PointerNestingLevel = pointerNest; innerRef.PointerNestingLevel = pointerNest;
innerRef.RankSpecifier = arrayRanks.ToArray(); innerRef.RankSpecifier = arrayRanks.ToArray();
return innerRef; return innerRef;
} else { } else {
return new TypeReference(name, pointerNest, arrayRanks.ToArray(), genArgs); return new TypeReference(name, pointerNest, arrayRanks.ToArray(), genTypeRefs);
} }
} }
@ -185,6 +189,17 @@ namespace ICSharpCode.NRefactory.Ast
); );
} else if (expr is TypeReferenceExpression) { } else if (expr is TypeReferenceExpression) {
return NormalizeTypeReference(((TypeReferenceExpression)expr).TypeReference); return NormalizeTypeReference(((TypeReferenceExpression)expr).TypeReference);
} else if (expr is InnerClassTypeReference) { // Frist - it is also TypeReference
InnerClassTypeReference typeRef = (InnerClassTypeReference)expr;
string[] names = typeRef.Type.Split('.');
TypeReference newRef = NormalizeTypeReference(typeRef.BaseType);
foreach(string name in names) {
newRef = new InnerClassTypeReference(newRef, name, new List<TypeReference>());
}
newRef.GenericTypes.AddRange(typeRef.GenericTypes);
newRef.PointerNestingLevel = typeRef.PointerNestingLevel;
newRef.RankSpecifier = typeRef.RankSpecifier;
return newRef;
} else if (expr is TypeReference) { } else if (expr is TypeReference) {
TypeReference typeRef = (TypeReference)expr; TypeReference typeRef = (TypeReference)expr;
string[] names = typeRef.Type.Split('.'); string[] names = typeRef.Type.Split('.');
@ -202,17 +217,6 @@ namespace ICSharpCode.NRefactory.Ast
newRef.PointerNestingLevel = typeRef.PointerNestingLevel; newRef.PointerNestingLevel = typeRef.PointerNestingLevel;
newRef.RankSpecifier = typeRef.RankSpecifier; newRef.RankSpecifier = typeRef.RankSpecifier;
return newRef; return newRef;
} else if (expr is InnerClassTypeReference) {
InnerClassTypeReference typeRef = (InnerClassTypeReference)expr;
string[] names = typeRef.Type.Split('.');
TypeReference newRef = NormalizeTypeReference(typeRef.BaseType);
foreach(string name in names) {
newRef = new InnerClassTypeReference(newRef, name, new List<TypeReference>());
}
newRef.GenericTypes.AddRange(typeRef.GenericTypes);
newRef.PointerNestingLevel = typeRef.PointerNestingLevel;
newRef.RankSpecifier = typeRef.RankSpecifier;
return newRef;
} else { } else {
throw new EvaluateException(expr, "Type expected. {0} seen.", expr.GetType()); throw new EvaluateException(expr, "Type expected. {0} seen.", expr.GetType());
} }
@ -222,7 +226,7 @@ namespace ICSharpCode.NRefactory.Ast
{ {
string name = typeRef.Type; string name = typeRef.Type;
if (typeRef.GenericTypes.Count > 0) if (typeRef.GenericTypes.Count > 0)
name += '`' + typeRef.GenericTypes.Count; name += "`" + typeRef.GenericTypes.Count.ToString();
if (typeRef is InnerClassTypeReference) { if (typeRef is InnerClassTypeReference) {
return GetNameWithArgCounts(((InnerClassTypeReference)typeRef).BaseType) + "." + name; return GetNameWithArgCounts(((InnerClassTypeReference)typeRef).BaseType) + "." + name;
} else { } else {
@ -256,8 +260,8 @@ namespace ICSharpCode.NRefactory.Ast
} }
// Try to construct nested type // Try to construct nested type
if (type != null && typeRef is InnerClassTypeReference) { if (type == null && typeRef is InnerClassTypeReference) {
DebugType outter = ResolveType((InnerClassTypeReference)typeRef, appDomain); DebugType outter = ResolveType(((InnerClassTypeReference)typeRef).BaseType, appDomain);
if (outter == null) if (outter == null)
return null; return null;
string nestedName = typeRef.GenericTypes.Count == 0 ? typeRef.Type : typeRef.Type + "`" + typeRef.GenericTypes.Count; string nestedName = typeRef.GenericTypes.Count == 0 ? typeRef.Type : typeRef.Type + "`" + typeRef.GenericTypes.Count;
@ -270,9 +274,11 @@ namespace ICSharpCode.NRefactory.Ast
for(int i = 0; i < typeRef.PointerNestingLevel; i++) { for(int i = 0; i < typeRef.PointerNestingLevel; i++) {
type = (DebugType)type.MakePointerType(); type = (DebugType)type.MakePointerType();
} }
if (typeRef.RankSpecifier != null) {
for(int i = typeRef.RankSpecifier.Length - 1; i >= 0; i--) { for(int i = typeRef.RankSpecifier.Length - 1; i >= 0; i--) {
type = (DebugType)type.MakeArrayType(typeRef.RankSpecifier[i] + 1); type = (DebugType)type.MakeArrayType(typeRef.RankSpecifier[i] + 1);
} }
}
return type; return type;
} }
} }

56
src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/Tests/DebugType_Tests.cs

@ -105,6 +105,7 @@ namespace Debugger.Tests
// Arrays // Arrays
char[] szArray = "Test".ToCharArray(); char[] szArray = "Test".ToCharArray();
char[,] mdArray = new char[2,3]; char[,] mdArray = new char[2,3];
char[][,] jagArray = new char[][,] { mdArray };
// Generics - nullables // Generics - nullables
int? nullable_value = 5; int? nullable_value = 5;
@ -223,7 +224,7 @@ namespace Debugger.Tests {
<ProcessStarted /> <ProcessStarted />
<ModuleLoaded>mscorlib.dll (No symbols)</ModuleLoaded> <ModuleLoaded>mscorlib.dll (No symbols)</ModuleLoaded>
<ModuleLoaded>DebugType_Tests.exe (Has symbols)</ModuleLoaded> <ModuleLoaded>DebugType_Tests.exe (Has symbols)</ModuleLoaded>
<DebuggingPaused>Break DebugType_Tests.cs:137,4-137,40</DebuggingPaused> <DebuggingPaused>Break DebugType_Tests.cs:138,4-138,40</DebuggingPaused>
<DefinedTypes <DefinedTypes
Capacity="16" Capacity="16"
Count="12"> Count="12">
@ -1065,6 +1066,59 @@ namespace Debugger.Tests {
</Type> </Type>
</LocalVariable> </LocalVariable>
</Item> </Item>
<Item>
<LocalVariable
Name="jagArray"
Type="System.Char[,][]"
Value="{System.Char[,][]}">
<Type>
<DebugType
Attributes="NotPublic"
BaseType="System.Array"
FullName="System.Char[,][]"
GetArrayRank="1"
GetElementType="System.Char[,]"
GetMembers="{System.Object System.Array.GetValue(Int32[] indices), System.Object System.Array.GetValue(Int32 index), System.Object System.Array.GetValue(Int32 index1, Int32 index2), System.Object System.Array.GetValue(Int32 index1, Int32 index2, Int32 index3), System.Object System.Array.GetValue(Int64 index), System.Object System.Array.GetValue(Int64 index1, Int64 index2), System.Object System.Array.GetValue(Int64 index1, Int64 index2, Int64 index3), System.Object System.Array.GetValue(Int64[] indices), void System.Array.SetValue(Object value, Int32 index), void System.Array.SetValue(Object value, Int32 index1, Int32 index2), void System.Array.SetValue(Object value, Int32 index1, Int32 index2, Int32 index3), void System.Array.SetValue(Object value, Int32[] indices), void System.Array.SetValue(Object value, Int64 index), void System.Array.SetValue(Object value, Int64 index1, Int64 index2), void System.Array.SetValue(Object value, Int64 index1, Int64 index2, Int64 index3), void System.Array.SetValue(Object value, Int64[] indices), System.Int32 System.Array.get_Length(), System.Int64 System.Array.get_LongLength(), System.Int32 System.Array.GetLength(Int32 dimension), System.Int64 System.Array.GetLongLength(Int32 dimension), System.Int32 System.Array.get_Rank(), System.Int32 System.Array.GetUpperBound(Int32 dimension), System.Int32 System.Array.GetLowerBound(Int32 dimension), System.Object System.Array.get_SyncRoot(), System.Boolean System.Array.get_IsReadOnly(), System.Boolean System.Array.get_IsFixedSize(), System.Boolean System.Array.get_IsSynchronized(), System.Object System.Array.Clone(), System.Int32 System.Array.CompareTo(Object other, IComparer comparer), System.Boolean System.Array.Equals(Object other, IEqualityComparer comparer), System.Int32 System.Array.GetHashCode(IEqualityComparer comparer), void System.Array.CopyTo(Array array, Int32 index), void System.Array.CopyTo(Array array, Int64 index), System.Collections.IEnumerator System.Array.GetEnumerator(), void System.Array.Initialize(), System.Int32 Length, System.Int64 LongLength, System.Int32 Rank, System.Object SyncRoot, System.Boolean IsReadOnly, System.Boolean IsFixedSize, System.Boolean IsSynchronized, void System.Object..ctor(), System.String System.Object.ToString(), System.Boolean System.Object.Equals(Object obj), System.Int32 System.Object.GetHashCode(), System.Type System.Object.GetType()}"
GetMethods="{System.Object System.Array.GetValue(Int32[] indices), System.Object System.Array.GetValue(Int32 index), System.Object System.Array.GetValue(Int32 index1, Int32 index2), System.Object System.Array.GetValue(Int32 index1, Int32 index2, Int32 index3), System.Object System.Array.GetValue(Int64 index), System.Object System.Array.GetValue(Int64 index1, Int64 index2), System.Object System.Array.GetValue(Int64 index1, Int64 index2, Int64 index3), System.Object System.Array.GetValue(Int64[] indices), void System.Array.SetValue(Object value, Int32 index), void System.Array.SetValue(Object value, Int32 index1, Int32 index2), void System.Array.SetValue(Object value, Int32 index1, Int32 index2, Int32 index3), void System.Array.SetValue(Object value, Int32[] indices), void System.Array.SetValue(Object value, Int64 index), void System.Array.SetValue(Object value, Int64 index1, Int64 index2), void System.Array.SetValue(Object value, Int64 index1, Int64 index2, Int64 index3), void System.Array.SetValue(Object value, Int64[] indices), System.Int32 System.Array.get_Length(), System.Int64 System.Array.get_LongLength(), System.Int32 System.Array.GetLength(Int32 dimension), System.Int64 System.Array.GetLongLength(Int32 dimension), System.Int32 System.Array.get_Rank(), System.Int32 System.Array.GetUpperBound(Int32 dimension), System.Int32 System.Array.GetLowerBound(Int32 dimension), System.Object System.Array.get_SyncRoot(), System.Boolean System.Array.get_IsReadOnly(), System.Boolean System.Array.get_IsFixedSize(), System.Boolean System.Array.get_IsSynchronized(), System.Object System.Array.Clone(), System.Int32 System.Array.CompareTo(Object other, IComparer comparer), System.Boolean System.Array.Equals(Object other, IEqualityComparer comparer), System.Int32 System.Array.GetHashCode(IEqualityComparer comparer), void System.Array.CopyTo(Array array, Int32 index), void System.Array.CopyTo(Array array, Int64 index), System.Collections.IEnumerator System.Array.GetEnumerator(), void System.Array.Initialize(), void System.Object..ctor(), System.String System.Object.ToString(), System.Boolean System.Object.Equals(Object obj), System.Int32 System.Object.GetHashCode(), System.Type System.Object.GetType()}"
GetProperties="{System.Int32 Length, System.Int64 LongLength, System.Int32 Rank, System.Object SyncRoot, System.Boolean IsReadOnly, System.Boolean IsFixedSize, System.Boolean IsSynchronized}"
HasElementType="True"
IsArray="True"
IsClass="True"
IsCompilerGenerated="True">
<GetElementType>
<DebugType
Attributes="NotPublic"
BaseType="System.Array"
FullName="System.Char[,]"
GetArrayRank="2"
GetElementType="System.Char"
GetMembers="{System.Object System.Array.GetValue(Int32[] indices), System.Object System.Array.GetValue(Int32 index), System.Object System.Array.GetValue(Int32 index1, Int32 index2), System.Object System.Array.GetValue(Int32 index1, Int32 index2, Int32 index3), System.Object System.Array.GetValue(Int64 index), System.Object System.Array.GetValue(Int64 index1, Int64 index2), System.Object System.Array.GetValue(Int64 index1, Int64 index2, Int64 index3), System.Object System.Array.GetValue(Int64[] indices), void System.Array.SetValue(Object value, Int32 index), void System.Array.SetValue(Object value, Int32 index1, Int32 index2), void System.Array.SetValue(Object value, Int32 index1, Int32 index2, Int32 index3), void System.Array.SetValue(Object value, Int32[] indices), void System.Array.SetValue(Object value, Int64 index), void System.Array.SetValue(Object value, Int64 index1, Int64 index2), void System.Array.SetValue(Object value, Int64 index1, Int64 index2, Int64 index3), void System.Array.SetValue(Object value, Int64[] indices), System.Int32 System.Array.get_Length(), System.Int64 System.Array.get_LongLength(), System.Int32 System.Array.GetLength(Int32 dimension), System.Int64 System.Array.GetLongLength(Int32 dimension), System.Int32 System.Array.get_Rank(), System.Int32 System.Array.GetUpperBound(Int32 dimension), System.Int32 System.Array.GetLowerBound(Int32 dimension), System.Object System.Array.get_SyncRoot(), System.Boolean System.Array.get_IsReadOnly(), System.Boolean System.Array.get_IsFixedSize(), System.Boolean System.Array.get_IsSynchronized(), System.Object System.Array.Clone(), System.Int32 System.Array.CompareTo(Object other, IComparer comparer), System.Boolean System.Array.Equals(Object other, IEqualityComparer comparer), System.Int32 System.Array.GetHashCode(IEqualityComparer comparer), void System.Array.CopyTo(Array array, Int32 index), void System.Array.CopyTo(Array array, Int64 index), System.Collections.IEnumerator System.Array.GetEnumerator(), void System.Array.Initialize(), System.Int32 Length, System.Int64 LongLength, System.Int32 Rank, System.Object SyncRoot, System.Boolean IsReadOnly, System.Boolean IsFixedSize, System.Boolean IsSynchronized, void System.Object..ctor(), System.String System.Object.ToString(), System.Boolean System.Object.Equals(Object obj), System.Int32 System.Object.GetHashCode(), System.Type System.Object.GetType()}"
GetMethods="{System.Object System.Array.GetValue(Int32[] indices), System.Object System.Array.GetValue(Int32 index), System.Object System.Array.GetValue(Int32 index1, Int32 index2), System.Object System.Array.GetValue(Int32 index1, Int32 index2, Int32 index3), System.Object System.Array.GetValue(Int64 index), System.Object System.Array.GetValue(Int64 index1, Int64 index2), System.Object System.Array.GetValue(Int64 index1, Int64 index2, Int64 index3), System.Object System.Array.GetValue(Int64[] indices), void System.Array.SetValue(Object value, Int32 index), void System.Array.SetValue(Object value, Int32 index1, Int32 index2), void System.Array.SetValue(Object value, Int32 index1, Int32 index2, Int32 index3), void System.Array.SetValue(Object value, Int32[] indices), void System.Array.SetValue(Object value, Int64 index), void System.Array.SetValue(Object value, Int64 index1, Int64 index2), void System.Array.SetValue(Object value, Int64 index1, Int64 index2, Int64 index3), void System.Array.SetValue(Object value, Int64[] indices), System.Int32 System.Array.get_Length(), System.Int64 System.Array.get_LongLength(), System.Int32 System.Array.GetLength(Int32 dimension), System.Int64 System.Array.GetLongLength(Int32 dimension), System.Int32 System.Array.get_Rank(), System.Int32 System.Array.GetUpperBound(Int32 dimension), System.Int32 System.Array.GetLowerBound(Int32 dimension), System.Object System.Array.get_SyncRoot(), System.Boolean System.Array.get_IsReadOnly(), System.Boolean System.Array.get_IsFixedSize(), System.Boolean System.Array.get_IsSynchronized(), System.Object System.Array.Clone(), System.Int32 System.Array.CompareTo(Object other, IComparer comparer), System.Boolean System.Array.Equals(Object other, IEqualityComparer comparer), System.Int32 System.Array.GetHashCode(IEqualityComparer comparer), void System.Array.CopyTo(Array array, Int32 index), void System.Array.CopyTo(Array array, Int64 index), System.Collections.IEnumerator System.Array.GetEnumerator(), void System.Array.Initialize(), void System.Object..ctor(), System.String System.Object.ToString(), System.Boolean System.Object.Equals(Object obj), System.Int32 System.Object.GetHashCode(), System.Type System.Object.GetType()}"
GetProperties="{System.Int32 Length, System.Int64 LongLength, System.Int32 Rank, System.Object SyncRoot, System.Boolean IsReadOnly, System.Boolean IsFixedSize, System.Boolean IsSynchronized}"
HasElementType="True"
IsArray="True"
IsClass="True"
IsCompilerGenerated="True">
<GetElementType>
<DebugType
Attributes="AutoLayout, AnsiClass, Class, Public, SequentialLayout, Sealed, Serializable, BeforeFieldInit"
BaseType="System.ValueType"
FullName="System.Char"
GetFields="{System.Char MaxValue, System.Char MinValue}"
GetInterfaces="{System.IComparable, System.IConvertible, System.IComparable`1[System.Char], System.IEquatable`1[System.Char]}"
GetMembers="{System.Char MaxValue, System.Char MinValue, System.Int32 System.Char.GetHashCode(), System.Boolean System.Char.Equals(Object obj), System.Boolean System.Char.Equals(Char obj), System.Int32 System.Char.CompareTo(Object value), System.Int32 System.Char.CompareTo(Char value), System.String System.Char.ToString(), System.String System.Char.ToString(IFormatProvider provider), static System.String System.Char.ToString(Char c), static System.Char System.Char.Parse(String s), static System.Boolean System.Char.TryParse(String s, Char result), static System.Boolean System.Char.IsDigit(Char c), static System.Boolean System.Char.IsDigit(String s, Int32 index), static System.Boolean System.Char.IsLetter(Char c), static System.Boolean System.Char.IsLetter(String s, Int32 index), static System.Boolean System.Char.IsWhiteSpace(Char c), static System.Boolean System.Char.IsWhiteSpace(String s, Int32 index), static System.Boolean System.Char.IsUpper(Char c), static System.Boolean System.Char.IsUpper(String s, Int32 index), static System.Boolean System.Char.IsLower(Char c), static System.Boolean System.Char.IsLower(String s, Int32 index), static System.Boolean System.Char.IsPunctuation(Char c), static System.Boolean System.Char.IsPunctuation(String s, Int32 index), static System.Boolean System.Char.IsLetterOrDigit(Char c), static System.Boolean System.Char.IsLetterOrDigit(String s, Int32 index), static System.Char System.Char.ToUpper(Char c, CultureInfo culture), static System.Char System.Char.ToUpper(Char c), static System.Char System.Char.ToUpperInvariant(Char c), static System.Char System.Char.ToLower(Char c, CultureInfo culture), static System.Char System.Char.ToLower(Char c), static System.Char System.Char.ToLowerInvariant(Char c), System.TypeCode System.Char.GetTypeCode(), static System.Boolean System.Char.IsControl(Char c), static System.Boolean System.Char.IsControl(String s, Int32 index), static System.Boolean System.Char.IsNumber(Char c), static System.Boolean System.Char.IsNumber(String s, Int32 index), static System.Boolean System.Char.IsSeparator(Char c), static System.Boolean System.Char.IsSeparator(String s, Int32 index), static System.Boolean System.Char.IsSurrogate(Char c), static System.Boolean System.Char.IsSurrogate(String s, Int32 index), static System.Boolean System.Char.IsSymbol(Char c), static System.Boolean System.Char.IsSymbol(String s, Int32 index), static System.Globalization.UnicodeCategory System.Char.GetUnicodeCategory(Char c), static System.Globalization.UnicodeCategory System.Char.GetUnicodeCategory(String s, Int32 index), static System.Double System.Char.GetNumericValue(Char c), static System.Double System.Char.GetNumericValue(String s, Int32 index), static System.Boolean System.Char.IsHighSurrogate(Char c), static System.Boolean System.Char.IsHighSurrogate(String s, Int32 index), static System.Boolean System.Char.IsLowSurrogate(Char c), static System.Boolean System.Char.IsLowSurrogate(String s, Int32 index), static System.Boolean System.Char.IsSurrogatePair(String s, Int32 index), static System.Boolean System.Char.IsSurrogatePair(Char highSurrogate, Char lowSurrogate), static System.String System.Char.ConvertFromUtf32(Int32 utf32), static System.Int32 System.Char.ConvertToUtf32(Char highSurrogate, Char lowSurrogate), static System.Int32 System.Char.ConvertToUtf32(String s, Int32 index), System.Boolean System.ValueType.Equals(Object obj), System.Int32 System.ValueType.GetHashCode(), System.String System.ValueType.ToString(), void System.Object..ctor(), System.String System.Object.ToString(), System.Boolean System.Object.Equals(Object obj), System.Int32 System.Object.GetHashCode(), System.Type System.Object.GetType()}"
GetMethods="{System.Int32 System.Char.GetHashCode(), System.Boolean System.Char.Equals(Object obj), System.Boolean System.Char.Equals(Char obj), System.Int32 System.Char.CompareTo(Object value), System.Int32 System.Char.CompareTo(Char value), System.String System.Char.ToString(), System.String System.Char.ToString(IFormatProvider provider), static System.String System.Char.ToString(Char c), static System.Char System.Char.Parse(String s), static System.Boolean System.Char.TryParse(String s, Char result), static System.Boolean System.Char.IsDigit(Char c), static System.Boolean System.Char.IsDigit(String s, Int32 index), static System.Boolean System.Char.IsLetter(Char c), static System.Boolean System.Char.IsLetter(String s, Int32 index), static System.Boolean System.Char.IsWhiteSpace(Char c), static System.Boolean System.Char.IsWhiteSpace(String s, Int32 index), static System.Boolean System.Char.IsUpper(Char c), static System.Boolean System.Char.IsUpper(String s, Int32 index), static System.Boolean System.Char.IsLower(Char c), static System.Boolean System.Char.IsLower(String s, Int32 index), static System.Boolean System.Char.IsPunctuation(Char c), static System.Boolean System.Char.IsPunctuation(String s, Int32 index), static System.Boolean System.Char.IsLetterOrDigit(Char c), static System.Boolean System.Char.IsLetterOrDigit(String s, Int32 index), static System.Char System.Char.ToUpper(Char c, CultureInfo culture), static System.Char System.Char.ToUpper(Char c), static System.Char System.Char.ToUpperInvariant(Char c), static System.Char System.Char.ToLower(Char c, CultureInfo culture), static System.Char System.Char.ToLower(Char c), static System.Char System.Char.ToLowerInvariant(Char c), System.TypeCode System.Char.GetTypeCode(), static System.Boolean System.Char.IsControl(Char c), static System.Boolean System.Char.IsControl(String s, Int32 index), static System.Boolean System.Char.IsNumber(Char c), static System.Boolean System.Char.IsNumber(String s, Int32 index), static System.Boolean System.Char.IsSeparator(Char c), static System.Boolean System.Char.IsSeparator(String s, Int32 index), static System.Boolean System.Char.IsSurrogate(Char c), static System.Boolean System.Char.IsSurrogate(String s, Int32 index), static System.Boolean System.Char.IsSymbol(Char c), static System.Boolean System.Char.IsSymbol(String s, Int32 index), static System.Globalization.UnicodeCategory System.Char.GetUnicodeCategory(Char c), static System.Globalization.UnicodeCategory System.Char.GetUnicodeCategory(String s, Int32 index), static System.Double System.Char.GetNumericValue(Char c), static System.Double System.Char.GetNumericValue(String s, Int32 index), static System.Boolean System.Char.IsHighSurrogate(Char c), static System.Boolean System.Char.IsHighSurrogate(String s, Int32 index), static System.Boolean System.Char.IsLowSurrogate(Char c), static System.Boolean System.Char.IsLowSurrogate(String s, Int32 index), static System.Boolean System.Char.IsSurrogatePair(String s, Int32 index), static System.Boolean System.Char.IsSurrogatePair(Char highSurrogate, Char lowSurrogate), static System.String System.Char.ConvertFromUtf32(Int32 utf32), static System.Int32 System.Char.ConvertToUtf32(Char highSurrogate, Char lowSurrogate), static System.Int32 System.Char.ConvertToUtf32(String s, Int32 index), System.Boolean System.ValueType.Equals(Object obj), System.Int32 System.ValueType.GetHashCode(), System.String System.ValueType.ToString(), void System.Object..ctor(), System.String System.Object.ToString(), System.Boolean System.Object.Equals(Object obj), System.Int32 System.Object.GetHashCode(), System.Type System.Object.GetType()}"
IsPrimitive="True"
IsValueType="True">
<GetElementType>null</GetElementType>
</DebugType>
</GetElementType>
</DebugType>
</GetElementType>
</DebugType>
</Type>
</LocalVariable>
</Item>
<Item> <Item>
<LocalVariable <LocalVariable
Name="nullable_value" Name="nullable_value"

49
src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/Tests/ExpressionEvaluator_Tests.cs

@ -104,12 +104,20 @@ namespace Debugger.Tests
string instanceField = "instance field value"; string instanceField = "instance field value";
static string staticField = "static field value"; static string staticField = "static field value";
public class A<T> {
public class B {
public class C<U> {
}
}
}
public static void Main() public static void Main()
{ {
new ExpressionEvaluator_Tests().Fun("function argument"); new ExpressionEvaluator_Tests().Fun("function argument");
} }
public void Fun(string arg) public unsafe void Fun(string arg)
{ {
bool flag = true; bool flag = true;
byte b = 1; byte b = 1;
@ -124,6 +132,9 @@ namespace Debugger.Tests
DerivedClass myClass = new DerivedClass(); DerivedClass myClass = new DerivedClass();
int*[][,] complexType1 = new int*[][,] { new int*[,] { { (int*)0xDA1D } } };
A<int>.B.C<char>[][,] complexType2 = new A<int>.B.C<char>[0][,];
System.Diagnostics.Debugger.Break(); System.Diagnostics.Debugger.Break();
} }
} }
@ -136,15 +147,11 @@ namespace Debugger.Tests {
using ICSharpCode.NRefactory; using ICSharpCode.NRefactory;
using ICSharpCode.NRefactory.Ast; using ICSharpCode.NRefactory.Ast;
using ICSharpCode.NRefactory.Visitors; using ICSharpCode.NRefactory.Visitors;
using NUnit.Framework;
public partial class DebuggerTests public partial class DebuggerTests
{ {
[NUnit.Framework.Test] string expressionsInput = @"
public void ExpressionEvaluator_Tests()
{
StartTest();
string input = @"
b b
i i
pi pi
@ -196,15 +203,20 @@ namespace Debugger.Tests {
!flag !flag
"; ";
input = input.Replace("'", "\""); [NUnit.Framework.Test]
public void ExpressionEvaluator_Tests()
{
StartTest();
expressionsInput = expressionsInput.Replace("'", "\"");
foreach(string line in input.Split('\n')) { foreach(string line in expressionsInput.Split('\n')) {
Eval(line.Trim()); Eval(line.Trim());
} }
// Test member hiding / overloading // Test member hiding / overloading
Value myClass = process.SelectedStackFrame.GetLocalVariableValue("myClass"); Value myClass = process.SelectedStackFrame.GetLocalVariableValue("myClass").GetPermanentReference();
List<Expression> expressions = new List<Expression>(); List<Expression> expressions = new List<Expression>();
foreach(MemberInfo memberInfo in myClass.Type.GetFieldsAndNonIndexedProperties(DebugType.BindingFlagsAll)) { foreach(MemberInfo memberInfo in myClass.Type.GetFieldsAndNonIndexedProperties(DebugType.BindingFlagsAll)) {
@ -237,6 +249,19 @@ namespace Debugger.Tests {
Eval(line.Trim()); Eval(line.Trim());
} }
// Test type round tripping
foreach(DebugLocalVariableInfo locVar in process.SelectedStackFrame.MethodInfo.GetLocalVariables()) {
if (locVar.Name.StartsWith("complexType")) {
TypeReference complexTypeRef = locVar.LocalType.GetTypeReference();
string code = "typeof(" + complexTypeRef.PrettyPrint() + ")";
TypeOfExpression complexTypeRefRT = (TypeOfExpression)ExpressionEvaluator.Parse(code, SupportedLanguage.CSharp);
DebugType type = complexTypeRefRT.TypeReference.ResolveType(process.SelectedStackFrame.AppDomain);
string status = locVar.LocalType.FullName == type.FullName ? "ok" : "fail";
ObjectDumpToString("TypeResulution", string.Format(" {0} = {1} ({2})", code, type.FullName, status));
}
}
EndTest(); EndTest();
} }
@ -271,7 +296,7 @@ namespace Debugger.Tests {
<ProcessStarted /> <ProcessStarted />
<ModuleLoaded>mscorlib.dll (No symbols)</ModuleLoaded> <ModuleLoaded>mscorlib.dll (No symbols)</ModuleLoaded>
<ModuleLoaded>ExpressionEvaluator_Tests.exe (Has symbols)</ModuleLoaded> <ModuleLoaded>ExpressionEvaluator_Tests.exe (Has symbols)</ModuleLoaded>
<DebuggingPaused>Break ExpressionEvaluator_Tests.cs:127,4-127,40</DebuggingPaused> <DebuggingPaused>Break ExpressionEvaluator_Tests.cs:138,4-138,40</DebuggingPaused>
<Eval> </Eval> <Eval> </Eval>
<Eval> b = 1 </Eval> <Eval> b = 1 </Eval>
<Eval> i = 4 </Eval> <Eval> i = 4 </Eval>
@ -352,6 +377,8 @@ namespace Debugger.Tests {
<Eval> myClass.Convert(1, 2) = Incorrect parameter type for 's'. Excpeted System.String, seen System.Int32 </Eval> <Eval> myClass.Convert(1, 2) = Incorrect parameter type for 's'. Excpeted System.String, seen System.Int32 </Eval>
<Eval> myClass.Convert("abc", 2) = "converted to abc and 2" </Eval> <Eval> myClass.Convert("abc", 2) = "converted to abc and 2" </Eval>
<Eval> </Eval> <Eval> </Eval>
<TypeResulution> typeof(System.Int32*[][,]) = System.Int32*[,][] (ok)</TypeResulution>
<TypeResulution> typeof(Debugger.Tests.ExpressionEvaluator_Tests.A&lt;System.Int32&gt;.B.C&lt;System.Char&gt;[][,]) = Debugger.Tests.ExpressionEvaluator_Tests+A`1+B+C`1[System.Int32,System.Char][,][] (ok)</TypeResulution>
<ProcessExited /> <ProcessExited />
</Test> </Test>
</DebuggerTests> </DebuggerTests>

Loading…
Cancel
Save