Browse Source

Support for array lower bounds

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2787 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
David Srbecký 18 years ago
parent
commit
7f5467d178
  1. 2
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Debugger.Core.csproj
  2. 8
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Expressions/Expression.Create.cs
  3. 57
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Values/ArrayDimension.cs
  4. 101
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Values/ArrayDimensions.cs
  5. 79
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Values/Value.Array.cs
  6. 17
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/CorDebug/ICorDebugArrayValue.cs
  7. 2
      src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/ArrayValue.xml
  8. 12
      src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/FunctionArgumentVariables.xml
  9. 2
      src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/FunctionLocalVariables.xml

2
src/AddIns/Misc/Debugger/Debugger.Core/Project/Debugger.Core.csproj

@ -235,6 +235,8 @@ @@ -235,6 +235,8 @@
<Compile Include="Src\Variables\Types\MemberInfo.cs" />
<Compile Include="Src\Variables\Types\MethodInfo.cs" />
<Compile Include="Src\Variables\Types\PropertyInfo.cs" />
<Compile Include="Src\Variables\Values\ArrayDimension.cs" />
<Compile Include="Src\Variables\Values\ArrayDimensions.cs" />
<Compile Include="Src\Variables\Values\Value.Array.cs" />
<Compile Include="Src\Variables\Values\Value.Helpers.cs" />
<Compile Include="Src\Variables\Values\Value.Object.cs" />

8
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Expressions/Expression.Create.cs

@ -17,11 +17,11 @@ namespace Debugger @@ -17,11 +17,11 @@ namespace Debugger
{
public partial class Expression: DebuggerObject
{
public Expression AppendIndexer(params uint[] indices)
public Expression AppendIndexer(params int[] indices)
{
List<Ast.Expression> indicesAst = new List<Ast.Expression>();
foreach(uint indice in indices) {
indicesAst.Add(new Ast.PrimitiveExpression((int)indice, ((int)indice).ToString()));
foreach(int indice in indices) {
indicesAst.Add(new Ast.PrimitiveExpression(indice, indice.ToString()));
}
return new Ast.IndexerExpression(
this.AbstractSynatxTree,
@ -96,7 +96,7 @@ namespace Debugger @@ -96,7 +96,7 @@ namespace Debugger
public ExpressionCollection EvaluateAndGetArrayElements()
{
ExpressionCollection elements = new ExpressionCollection();
foreach(uint[] indices in this.Evaluate().ArrayIndices) {
foreach(int[] indices in this.Evaluate().ArrayDimensions.Indices) {
elements.Add(this.AppendIndexer(indices));
}
return elements;

57
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Values/ArrayDimension.cs

@ -0,0 +1,57 @@ @@ -0,0 +1,57 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="David Srbecký" email="dsrbecky@gmail.com"/>
// <version>$Revision: 2786 $</version>
// </file>
using System;
namespace Debugger
{
/// <summary>
/// Specifies the range of valid indicies for an array dimension
/// </summary>
public class ArrayDimension
{
int lowerBound;
int upperBound;
/// <summary> The smallest valid index in this dimension </summary>
public int LowerBound {
get { return lowerBound; }
}
/// <summary> The largest valid index in this dimension.
/// Returns LowerBound - 1 if the array is empty. </summary>
public int UpperBound {
get { return upperBound; }
}
/// <summary> The number of valid indicies of this dimension </summary>
public int Count {
get { return upperBound - lowerBound + 1; }
}
/// <summary> Determines whether the given index is a valid index for this dimension </summary>
public bool IsIndexValid(int index)
{
return (this.LowerBound <= index && index <= this.UpperBound);
}
public ArrayDimension(int lowerBound, int upperBound)
{
this.lowerBound = lowerBound;
this.upperBound = upperBound;
}
public override string ToString()
{
if (this.LowerBound == 0) {
return this.Count.ToString();
} else {
return this.LowerBound + ".." + this.UpperBound;
}
}
}
}

101
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Values/ArrayDimensions.cs

@ -0,0 +1,101 @@ @@ -0,0 +1,101 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="David Srbecký" email="dsrbecky@gmail.com"/>
// <version>$Revision: 2786 $</version>
// </file>
using System;
using System.Collections;
using System.Collections.Generic;
namespace Debugger
{
/// <summary>
/// Specifies the range of valid indicies for all array dimensions
/// </summary>
public class ArrayDimensions: IEnumerable<ArrayDimension>
{
List<ArrayDimension> dimensions = new List<ArrayDimension>();
public IEnumerator<ArrayDimension> GetEnumerator()
{
return dimensions.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return ((IEnumerable)dimensions).GetEnumerator();
}
/// <summary> Gets a given dimension </summary>
public ArrayDimension this[int index] {
get {
return dimensions[index];
}
}
/// <summary> Get the number of dimensions of the array </summary>
public int Count {
get {
return dimensions.Count;
}
}
/// <summary> Enumerate all vaild indicies in the array </summary>
public IEnumerable<int[]> Indices {
get {
foreach(ArrayDimension dim in this) {
if (dim.Count == 0) yield break;
}
int rank = this.Count;
int[] indices = new int[rank];
for(int i = 0; i < rank; i++) {
indices[i] = this[i].LowerBound;
}
while(true) { // Go thought all combinations
for (int i = rank - 1; i >= 1; i--) {
if (indices[i] > this[i].UpperBound) {
indices[i] = this[i].LowerBound;
indices[i - 1]++;
}
}
if (indices[0] > this[0].UpperBound) yield break; // We are done
yield return (int[])indices.Clone();
indices[rank - 1]++;
}
}
}
/// <summary> Determines whether the given index is a valid index for the array </summary>
public bool IsIndexValid(int[] indices)
{
for (int i = 0; i < this.Count; i++) {
if (!this[i].IsIndexValid(indices[i])) return false;
}
return true;
}
public ArrayDimensions(List<ArrayDimension> dimensions)
{
this.dimensions = dimensions;
}
public override string ToString()
{
string result = "[";
bool isFirst = true;
foreach(ArrayDimension dim in this) {
if (!isFirst) result += ", ";
result += dim.ToString();
isFirst = false;
}
result += "]";
return result;
}
}
}

79
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/Values/Value.Array.cs

@ -9,7 +9,8 @@ using System; @@ -9,7 +9,8 @@ using System;
using System.Collections.Generic;
using Debugger.Wrappers.CorDebug;
//TODO: Support for lower bound
// TODO: Test non-zero LowerBound
// TODO: Test very large arrays (Length > Int32.MaxValue)
namespace Debugger
{
@ -37,9 +38,9 @@ namespace Debugger @@ -37,9 +38,9 @@ namespace Debugger
/// Gets the number of elements in the array.
/// eg new object[4,5] returns 20
/// </summary>
public uint ArrayLenght {
public int ArrayLenght {
get {
return CorArrayValue.Count;
return (int)CorArrayValue.Count;
}
}
@ -47,37 +48,49 @@ namespace Debugger @@ -47,37 +48,49 @@ namespace Debugger
/// Gets the number of dimensions of the array.
/// eg new object[4,5] returns 2
/// </summary>
public uint ArrayRank {
public int ArrayRank {
get {
return CorArrayValue.Rank;
return (int)CorArrayValue.Rank;
}
}
/// <summary>
/// Gets the lengths of individual dimensions.
/// eg new object[4,5] returns {4,5};
/// </summary>
public uint[] ArrayDimensions {
/// <summary> Gets the dimensions of the array </summary>
[Debugger.Tests.ToStringOnly]
public ArrayDimensions ArrayDimensions {
get {
return CorArrayValue.Dimensions;
int rank = this.ArrayRank;
uint[] baseIndicies;
if (CorArrayValue.HasBaseIndicies() == 1) {
baseIndicies = CorArrayValue.BaseIndicies;
} else {
baseIndicies = new uint[this.ArrayRank];
}
uint[] dimensionCounts = CorArrayValue.Dimensions;
List<ArrayDimension> dimensions = new List<ArrayDimension>();
for(int i = 0; i < rank; i++) {
dimensions.Add(new ArrayDimension((int)baseIndicies[i], (int)baseIndicies[i] + (int)dimensionCounts[i] - 1));
}
return new ArrayDimensions(dimensions);
}
}
/// <summary> Returns an element of a single-dimensional array </summary>
public Value GetArrayElement(uint index)
public Value GetArrayElement(int index)
{
return GetArrayElement(new uint[] {index});
return GetArrayElement(new int[] {index});
}
/// <summary> Returns an element of an array </summary>
public Value GetArrayElement(uint[] elementIndices)
public Value GetArrayElement(int[] elementIndices)
{
uint[] indices = (uint[])elementIndices.Clone();
int[] indices = (int[])elementIndices.Clone();
return new Value(Process, GetNameFromIndices(indices), GetCorValueOfArrayElement(indices));
}
static string GetNameFromIndices(uint[] indices)
static string GetNameFromIndices(int[] indices)
{
string elementName = "[";
for (int i = 0; i < indices.Length; i++) {
@ -88,7 +101,7 @@ namespace Debugger @@ -88,7 +101,7 @@ namespace Debugger
}
// May be called later
ICorDebugValue GetCorValueOfArrayElement(uint[] indices)
ICorDebugValue GetCorValueOfArrayElement(int[] indices)
{
if (!IsArray) {
throw new CannotGetValueException("The value is not an array");
@ -96,10 +109,8 @@ namespace Debugger @@ -96,10 +109,8 @@ namespace Debugger
if (indices.Length != ArrayRank) {
throw new CannotGetValueException("Given indicies do not have the same dimension as array.");
}
for (int i = 0; i < indices.Length; i++) {
if (indices[i] > ArrayDimensions[i]) {
throw new CannotGetValueException("Given indices are out of range of the array");
}
if (!this.ArrayDimensions.IsIndexValid(indices)) {
throw new CannotGetValueException("Given indices are out of range of the array");
}
return CorArrayValue.GetElement(indices);
@ -115,34 +126,10 @@ namespace Debugger @@ -115,34 +126,10 @@ namespace Debugger
[Debugger.Tests.Ignore]
public IEnumerable<Value> ArrayElements {
get {
foreach(uint[] indices in ArrayIndices) {
foreach(int[] indices in this.ArrayDimensions.Indices) {
yield return GetArrayElement(indices);
}
}
}
/// <summary> Enumerate over all array indices </summary>
[Debugger.Tests.Ignore]
public IEnumerable<uint[]> ArrayIndices {
get {
uint[] indices = new uint[ArrayRank];
uint rank = ArrayRank;
uint[] dimensions = ArrayDimensions;
while(true) { // Go thought all combinations
for (uint i = rank - 1; i >= 1; i--) {
if (indices[i] >= dimensions[i]) {
indices[i] = 0;
indices[i-1]++;
}
}
if (indices[0] >= dimensions[0]) break; // We are done
yield return (uint[])indices.Clone();
indices[rank - 1]++;
}
}
}
}
}

17
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Wrappers/CorDebug/ICorDebugArrayValue.cs

@ -23,12 +23,29 @@ namespace Debugger.Wrappers.CorDebug @@ -23,12 +23,29 @@ namespace Debugger.Wrappers.CorDebug
}
}
public unsafe uint[] BaseIndicies {
get {
uint[] baseIndicies = new uint[this.Rank];
fixed (void* pBaseIndicies = baseIndicies) {
this.GetBaseIndicies((uint)baseIndicies.Length, new IntPtr(pBaseIndicies));
}
return baseIndicies;
}
}
public unsafe ICorDebugValue GetElement(uint[] indices)
{
fixed (void* pIndices = indices) {
return this.GetElement((uint)indices.Length, new IntPtr(pIndices));
}
}
public unsafe ICorDebugValue GetElement(int[] indices)
{
fixed (void* pIndices = indices) {
return this.GetElement((uint)indices.Length, new IntPtr(pIndices));
}
}
}
}

2
src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/ArrayValue.xml

@ -10,7 +10,7 @@ @@ -10,7 +10,7 @@
<IsArray>True</IsArray>
<ArrayLenght>5</ArrayLenght>
<ArrayRank>1</ArrayRank>
<ArrayDimensions>System.UInt32[]</ArrayDimensions>
<ArrayDimensions>[5]</ArrayDimensions>
<IsObject>False</IsObject>
<IsPrimitive>False</IsPrimitive>
<IsInteger>False</IsInteger>

12
src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/FunctionArgumentVariables.xml

@ -69,7 +69,7 @@ @@ -69,7 +69,7 @@
<IsArray>True</IsArray>
<ArrayLenght>0</ArrayLenght>
<ArrayRank>1</ArrayRank>
<ArrayDimensions>System.UInt32[]</ArrayDimensions>
<ArrayDimensions>[0]</ArrayDimensions>
<IsObject>False</IsObject>
<IsPrimitive>False</IsPrimitive>
<IsInteger>False</IsInteger>
@ -155,7 +155,7 @@ @@ -155,7 +155,7 @@
<IsArray>True</IsArray>
<ArrayLenght>1</ArrayLenght>
<ArrayRank>1</ArrayRank>
<ArrayDimensions>System.UInt32[]</ArrayDimensions>
<ArrayDimensions>[1]</ArrayDimensions>
<IsObject>False</IsObject>
<IsPrimitive>False</IsPrimitive>
<IsInteger>False</IsInteger>
@ -241,7 +241,7 @@ @@ -241,7 +241,7 @@
<IsArray>True</IsArray>
<ArrayLenght>2</ArrayLenght>
<ArrayRank>1</ArrayRank>
<ArrayDimensions>System.UInt32[]</ArrayDimensions>
<ArrayDimensions>[2]</ArrayDimensions>
<IsObject>False</IsObject>
<IsPrimitive>False</IsPrimitive>
<IsInteger>False</IsInteger>
@ -343,7 +343,7 @@ @@ -343,7 +343,7 @@
<IsArray>True</IsArray>
<ArrayLenght>0</ArrayLenght>
<ArrayRank>1</ArrayRank>
<ArrayDimensions>System.UInt32[]</ArrayDimensions>
<ArrayDimensions>[0]</ArrayDimensions>
<IsObject>False</IsObject>
<IsPrimitive>False</IsPrimitive>
<IsInteger>False</IsInteger>
@ -445,7 +445,7 @@ @@ -445,7 +445,7 @@
<IsArray>True</IsArray>
<ArrayLenght>1</ArrayLenght>
<ArrayRank>1</ArrayRank>
<ArrayDimensions>System.UInt32[]</ArrayDimensions>
<ArrayDimensions>[1]</ArrayDimensions>
<IsObject>False</IsObject>
<IsPrimitive>False</IsPrimitive>
<IsInteger>False</IsInteger>
@ -547,7 +547,7 @@ @@ -547,7 +547,7 @@
<IsArray>True</IsArray>
<ArrayLenght>2</ArrayLenght>
<ArrayRank>1</ArrayRank>
<ArrayDimensions>System.UInt32[]</ArrayDimensions>
<ArrayDimensions>[2]</ArrayDimensions>
<IsObject>False</IsObject>
<IsPrimitive>False</IsPrimitive>
<IsInteger>False</IsInteger>

2
src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/FunctionLocalVariables.xml

@ -74,7 +74,7 @@ @@ -74,7 +74,7 @@
<IsArray>True</IsArray>
<ArrayLenght>1</ArrayLenght>
<ArrayRank>1</ArrayRank>
<ArrayDimensions>System.UInt32[]</ArrayDimensions>
<ArrayDimensions>[1]</ArrayDimensions>
<IsObject>False</IsObject>
<IsPrimitive>False</IsPrimitive>
<IsInteger>False</IsInteger>

Loading…
Cancel
Save