Browse Source

Create a simple expression parser.

pull/191/merge
Eusebiu Marcu 14 years ago
parent
commit
16d84ed0d9
  1. 20
      Debugger/ILSpy.Debugger/Services/Debugger/DebuggerService.cs
  2. 4
      Debugger/ILSpy.Debugger/Services/Debugger/WindowsDebugger.cs
  3. 68
      Debugger/ILSpy.Debugger/Services/ParserService/ParserService.cs
  4. 4
      Debugger/ILSpy.Debugger/ToolTips/TextEditorListener.cs
  5. 2
      ICSharpCode.Decompiler/Disassembler/CodeMappings.cs
  6. 4
      ICSharpCode.Decompiler/Disassembler/MethodBodyDisassembler.cs
  7. 4
      ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs

20
Debugger/ILSpy.Debugger/Services/Debugger/DebuggerService.cs

@ -201,18 +201,24 @@ namespace ILSpy.Debugger.Services @@ -201,18 +201,24 @@ namespace ILSpy.Debugger.Services
/// </summary>
internal static void HandleToolTipRequest(ToolTipRequestEventArgs e)
{
if (!e.InDocument)
return;
var logicPos = e.LogicalPosition;
var doc = (TextDocument)e.Editor.Document;
string variable =
ParserService.SimpleParseAt(doc.Text, doc.GetOffset(new TextLocation(logicPos.Line, logicPos.Column)));
if (currentDebugger == null || !currentDebugger.IsDebugging) {
e.ContentToShow = "test";
e.ContentToShow = variable;
}
else {
e.ContentToShow = currentDebugger.GetTooltipControl(e.LogicalPosition, "test");
e.ContentToShow = currentDebugger.GetTooltipControl(e.LogicalPosition, variable);
}
// FIXME
// if (!e.InDocument)
// return;
// var logicPos = e.LogicalPosition;
// var doc = (TextDocument)e.Editor.Document;
// FIXME Do proper parsing
//
// using (var sr = new StringReader(doc.Text))
// {

4
Debugger/ILSpy.Debugger/Services/Debugger/WindowsDebugger.cs

@ -490,7 +490,7 @@ namespace ILSpy.Debugger.Services @@ -490,7 +490,7 @@ namespace ILSpy.Debugger.Services
void AddBreakpoint(BreakpointBookmark bookmark)
{
uint token;
ILCodeMapping map = CodeMappings.GetInstructionByTypeAndLine(bookmark.TypeName, bookmark.LineNumber, out token);
ILCodeMapping map = ILCodeMappings.GetInstructionByTypeAndLine(bookmark.TypeName, bookmark.LineNumber, out token);
if (map != null) {
Breakpoint breakpoint = new ILBreakpoint(debugger, bookmark.LineNumber, token, map.ILInstruction.Offset , bookmark.IsEnabled);
@ -727,7 +727,7 @@ namespace ILSpy.Debugger.Services @@ -727,7 +727,7 @@ namespace ILSpy.Debugger.Services
int ilOffset = debuggedProcess.SelectedStackFrame.IP;
int line;
string typeName;
CodeMappings.GetSourceCodeFromMetadataTokenAndOffset(token, ilOffset, out typeName, out line);
ILCodeMappings.GetSourceCodeFromMetadataTokenAndOffset(token, ilOffset, out typeName, out line);
if (typeName != null) {
DebuggerService.JumpToCurrentLine(typeName, line, 0, line, 0);
}

68
Debugger/ILSpy.Debugger/Services/ParserService/ParserService.cs

@ -17,14 +17,76 @@ @@ -17,14 +17,76 @@
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
namespace ILSpy.Debugger.Services
{
/// <summary>
/// Description of ParserService.
/// </summary>
public static class ParserService
{
static HashSet<string> mySet = new HashSet<string>();
static ParserService()
{
mySet.AddRange((new [] {
".",
"{",
"}",
"(",
")",
"[",
"]",
" ",
"=",
"+",
"-",
"/",
"%",
"*",
"&",
Environment.NewLine,
";",
",",
"~",
"!",
"?",
@"\n",
@"\t",
@"\r",
"|"
}).AsReadOnly());
}
/// <summary>
/// Returns the variable name
/// </summary>
/// <param name="fullText"></param>
/// <param name="offset"></param>
/// <returns></returns>
public static string SimpleParseAt(string fullText, int offset)
{
if (string.IsNullOrEmpty(fullText))
return string.Empty;
if (offset <= 0 || offset >= fullText.Length)
return string.Empty;
string currentValue = fullText[offset].ToString();
if (mySet.Contains(currentValue))
return string.Empty;
int left = offset, right = offset;
//search left
while((!mySet.Contains(currentValue) || currentValue == ".") && offset >= 0)
currentValue = fullText[--left].ToString();
currentValue = fullText[offset].ToString();
// searh right
while(!mySet.Contains(currentValue) && offset < fullText.Length)
currentValue = fullText[++right].ToString();
return fullText.Substring(left + 1, right - 1 - left).Trim();
}
}
}

4
Debugger/ILSpy.Debugger/ToolTips/TextEditorListener.cs

@ -82,7 +82,7 @@ namespace ILSpy.Debugger.ToolTips @@ -82,7 +82,7 @@ namespace ILSpy.Debugger.ToolTips
args.InDocument = pos.HasValue;
if (pos.HasValue) {
args.LogicalPosition = new AstLocation(pos.Value.Column, pos.Value.Line);
args.LogicalPosition = new AstLocation(pos.Value.Line, pos.Value.Column);
}
DebuggerService.HandleToolTipRequest(args);
@ -116,7 +116,7 @@ namespace ILSpy.Debugger.ToolTips @@ -116,7 +116,7 @@ namespace ILSpy.Debugger.ToolTips
if(args.ContentToShow is string) {
toolTip.Content = new TextBlock
{
Text = args.ContentToShow as string,
Text = (args.ContentToShow as string),
TextWrapping = TextWrapping.Wrap
};
}

2
ICSharpCode.Decompiler/Disassembler/CodeMappings.cs

@ -64,7 +64,7 @@ namespace ICSharpCode.Decompiler.Disassembler @@ -64,7 +64,7 @@ namespace ICSharpCode.Decompiler.Disassembler
}
}
public static class CodeMappings
public static class ILCodeMappings
{
static Dictionary<string, List<MethodMapping>> ilCodeMappings = new Dictionary<string, List<MethodMapping>>();

4
ICSharpCode.Decompiler/Disassembler/MethodBodyDisassembler.cs

@ -49,8 +49,8 @@ namespace ICSharpCode.Decompiler.Disassembler @@ -49,8 +49,8 @@ namespace ICSharpCode.Decompiler.Disassembler
{
// create mappings
MethodMapping currentMethodMapping = null;
if (CodeMappings.ILSourceCodeMappings.ContainsKey(body.Method.DeclaringType.FullName)) {
var mapping = CodeMappings.ILSourceCodeMappings[body.Method.DeclaringType.FullName];
if (ILCodeMappings.ILSourceCodeMappings.ContainsKey(body.Method.DeclaringType.FullName)) {
var mapping = ILCodeMappings.ILSourceCodeMappings[body.Method.DeclaringType.FullName];
if (mapping.Find(map => (int)map.MetadataToken == body.Method.MetadataToken.ToInt32()) == null) {
currentMethodMapping = new MethodMapping() {
MetadataToken = (uint)body.Method.MetadataToken.ToInt32(),

4
ICSharpCode.Decompiler/Disassembler/ReflectionDisassembler.cs

@ -102,8 +102,8 @@ namespace ICSharpCode.Decompiler.Disassembler @@ -102,8 +102,8 @@ namespace ICSharpCode.Decompiler.Disassembler
void DisassembleMethodInternal(MethodDefinition method)
{
// create mappings for types that were not disassebled
if (!CodeMappings.ILSourceCodeMappings.ContainsKey(method.DeclaringType.FullName)) {
CodeMappings.ILSourceCodeMappings.Add(method.DeclaringType.FullName, new List<MethodMapping>());
if (!ILCodeMappings.ILSourceCodeMappings.ContainsKey(method.DeclaringType.FullName)) {
ILCodeMappings.ILSourceCodeMappings.Add(method.DeclaringType.FullName, new List<MethodMapping>());
}
// .method public hidebysig specialname

Loading…
Cancel
Save