public ArrayList IsAsResolve(string expression, int caretLine, int caretColumn, string fileName, string fileContent) { ArrayList result = new ArrayList (); this.caretLine = caretLine; this.caretColumn = caretColumn; IParseInformation parseInfo = parserContext.GetParseInformation (fileName); ICSharpCode.SharpRefactory.Parser.AST.CompilationUnit fcu = parseInfo.MostRecentCompilationUnit.Tag as ICSharpCode.SharpRefactory.Parser.AST.CompilationUnit; if (fcu == null) return null; ICSharpCode.SharpRefactory.Parser.Parser p = new ICSharpCode.SharpRefactory.Parser.Parser (); Lexer l = new Lexer (new StringReader (expression)); Expression expr = p.ParseExpression(l); if (expr == null) return null; lookupTableVisitor = new LookupTableVisitor (); lookupTableVisitor.Visit (fcu, null); TypeVisitor typeVisitor = new TypeVisitor (this); CSharpVisitor csharpVisitor = new CSharpVisitor (); cu = (ICompilationUnit)csharpVisitor.Visit (fcu, null); if (cu != null) { callingClass = GetInnermostClass (); } IReturnType type = expr.AcceptVisitor (typeVisitor, null) as IReturnType; if (type == null || type.PointerNestingLevel != 0) { fcu = parserContext.ParseFile (fileName, fileContent).MostRecentCompilationUnit.Tag as ICSharpCode.SharpRefactory.Parser.AST.CompilationUnit; lookupTableVisitor.Visit (fcu, null); cu = (ICompilationUnit)csharpVisitor.Visit (fcu, null); if (cu != null) { callingClass = GetInnermostClass (); } type = expr.AcceptVisitor (typeVisitor, null) as IReturnType; if (type == null) return null; } if (type.ArrayDimensions != null && type.ArrayDimensions.Length > 0) type = new ReturnType ("System.Array"); IClass returnClass = SearchType (type.FullyQualifiedName, cu); // IClass returnClass = parserContext.SearchType (type.FullyQualifiedName, null, cu); if (returnClass == null) return null; foreach (IClass iclass in parserContext.GetClassInheritanceTree (returnClass)) { if (!result.Contains (iclass)) result.Add (iclass); } return result; }
public string EvaluateDebuggerDisplay(ITargetObject obj, string display) { StringBuilder sb = new StringBuilder (""); DebuggingService dbgr = (DebuggingService)Runtime.DebuggingService; EvaluationContext ctx = new EvaluationContext (obj); ctx.CurrentProcess = new ProcessHandle (dbgr.MainThread); /* break up the string into runs of {...} and * normal text. treat the {...} as C# * expressions, and evaluate them */ int start_idx = 0; while (true) { int left_idx; int right_idx; left_idx = display.IndexOf ('{', start_idx); if (left_idx == -1) { /* we're done. */ sb.Append (display.Substring (start_idx)); break; } if (left_idx != start_idx) { sb.Append (display.Substring (start_idx, left_idx - start_idx)); } right_idx = display.IndexOf ('}', left_idx + 1); if (right_idx == -1) { // '{...\0'. ignore the '{', append the rest, and break out */ sb.Append (display.Substring (left_idx + 1)); break; } if (right_idx - left_idx > 1) { /* there's enough space for an * expression. parse it and see * what we get. */ RefParse.Parser parser; AST.Expression ast_expr; Expression dbgr_expr; DebuggerASTVisitor visitor; string snippet; object retval; /* parse the snippet to build up MD's AST */ parser = new RefParse.Parser(); snippet = display.Substring (left_idx + 1, right_idx - left_idx - 1); ast_expr = parser.ParseExpression (new RefParse.Lexer (new RefParse.StringReader (snippet))); /* use our visitor to convert from MD's AST to types that * facilitate evaluation by the debugger */ visitor = new DebuggerASTVisitor (); dbgr_expr = (Expression)ast_expr.AcceptVisitor (visitor, null); /* finally, resolve and evaluate the expression */ dbgr_expr = dbgr_expr.Resolve (ctx); retval = dbgr_expr.Evaluate (ctx); #region "c&p'ed from debugger/frontend/Style.cs" if (retval is long) { sb.Append (String.Format ("0x{0:x}", (long) retval)); } else if (retval is string) { sb.Append ('"' + (string) retval + '"'); } else if (retval is ITargetObject) { ITargetObject tobj = (ITargetObject) retval; sb.Append (tobj.Print ()); } else { sb.Append (retval.ToString ()); } #endregion } start_idx = right_idx + 1; } return sb.ToString (); }
public IReturnType internalResolve(string expression, int caretLineNumber, int caretColumn, string fileName, string fileContent) { //Console.WriteLine("Start Resolving"); if (expression == null) { return null; } expression = expression.TrimStart(null); if (expression == "") { return null; } this.caretLine = caretLineNumber; this.caretColumn = caretColumn; IParseInformation parseInfo = parserContext.GetParseInformation(fileName); ICSharpCode.SharpRefactory.Parser.AST.CompilationUnit fileCompilationUnit = parseInfo.MostRecentCompilationUnit.Tag as ICSharpCode.SharpRefactory.Parser.AST.CompilationUnit; if (fileCompilationUnit == null) { // ICSharpCode.SharpRefactory.Parser.Parser fileParser = new ICSharpCode.SharpRefactory.Parser.Parser(); // fileParser.Parse(new Lexer(new StringReader(fileContent))); Console.WriteLine("Warning: no parse information!"); return null; } /* //// try to find last expression in original string, it could be like " if (act!=null) act" //// in this case only "act" should be parsed as expression !!is so!! don't change things that work Expression expr=null; // tentative expression Lexer l=null; ICSharpCode.SharpRefactory.Parser.Parser p = new ICSharpCode.SharpRefactory.Parser.Parser(); while (expression.Length > 0) { l = new Lexer(new StringReader(expression)); expr = p.ParseExpression(l); if (l.LookAhead.val != "" && expression.LastIndexOf(l.LookAhead.val) >= 0) { if (expression.Substring(expression.LastIndexOf(l.LookAhead.val) + l.LookAhead.val.Length).Length > 0) expression=expression.Substring(expression.LastIndexOf(l.LookAhead.val) + l.LookAhead.val.Length).Trim(); else { expression=l.LookAhead.val.Trim(); l=new Lexer(new StringReader(expression)); expr=p.ParseExpression(l); break; } } else { if (l.Token.val!="" || expr!=null) break; } } //// here last subexpression should be fixed in expr if it should be changed in expressionfinder don't fix it here */ ICSharpCode.SharpRefactory.Parser.Parser p = new ICSharpCode.SharpRefactory.Parser.Parser(); Lexer l = new Lexer(new StringReader(expression)); Expression expr = p.ParseExpression(l); if (expr == null) { return null; } lookupTableVisitor = new LookupTableVisitor(); lookupTableVisitor.Visit(fileCompilationUnit, null); TypeVisitor typeVisitor = new TypeVisitor(this); CSharpVisitor cSharpVisitor = new CSharpVisitor(); cu = (ICompilationUnit)cSharpVisitor.Visit(fileCompilationUnit, null); if (cu != null) { callingClass = GetInnermostClass(); // Console.WriteLine("CallingClass is " + callingClass == null ? "null" : callingClass.Name); } //Console.WriteLine("expression = " + expr.ToString()); IReturnType type = expr.AcceptVisitor(typeVisitor, null) as IReturnType; //Console.WriteLine("type visited"); if (type == null || type.PointerNestingLevel != 0) { // Console.WriteLine("Type == null || type.PointerNestingLevel != 0"); if (type != null) { //Console.WriteLine("PointerNestingLevel is " + type.PointerNestingLevel); } else { //Console.WriteLine("Type == null"); } //// when type is null might be file needs to be reparsed - some vars were lost fileCompilationUnit = parserContext.ParseFile (fileName, fileContent).MostRecentCompilationUnit.Tag as ICSharpCode.SharpRefactory.Parser.AST.CompilationUnit; lookupTableVisitor.Visit(fileCompilationUnit,null); cu = (ICompilationUnit)cSharpVisitor.Visit(fileCompilationUnit, null); if (cu != null) { callingClass = GetInnermostClass(); } type=expr.AcceptVisitor(typeVisitor,null) as IReturnType; if (type==null) return null; } if (type.ArrayDimensions != null && type.ArrayDimensions.Length > 0) { type = new ReturnType("System.Array"); } Console.WriteLine("Here: Type is " + type.FullyQualifiedName); return type; }