static void Parse(FileInfo file) { if (file.Exists) { lexer = new Lexer (new FileReader (file.FullName)); p.Parse (lexer); CSharpVisitor v = new CSharpVisitor (); v.Visit (p.compilationUnit, null); v.Cu.ErrorsDuringCompile = p.Errors.count > 0; if (v.Cu.ErrorsDuringCompile) { Console.WriteLine ("errors in parsing " + file.FullName); errors ++; } else { counter ++; } foreach (ErrorInfo error in p.Errors.ErrorInformation) Console.WriteLine (error.ToString ()); } }
public ICompilationUnitBase Parse(string fileName, string fileContent) { ICSharpCode.SharpRefactory.Parser.Parser p = new ICSharpCode.SharpRefactory.Parser.Parser(); Lexer lexer = new Lexer(new StringReader(fileContent)); p.Parse(lexer); CSharpVisitor visitor = new CSharpVisitor(); visitor.Visit(p.compilationUnit, null); visitor.Cu.ErrorsDuringCompile = p.Errors.count > 0; visitor.Cu.Tag = p.compilationUnit; visitor.Cu.ErrorInformation = p.Errors.ErrorInformation; RetrieveRegions(visitor.Cu, lexer.SpecialTracker); foreach (IClass c in visitor.Cu.Classes) c.Region.FileName = fileName; return visitor.Cu; }
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 ArrayList CtrlSpace(int caretLine, int caretColumn, string fileName) { ArrayList result = new ArrayList(TypeReference.PrimitiveTypes); this.caretLine = caretLine; 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) { Console.WriteLine("!Warning: no parseinformation!"); return null; } lookupTableVisitor = new LookupTableVisitor(); lookupTableVisitor.Visit(fileCompilationUnit, null); CSharpVisitor cSharpVisitor = new CSharpVisitor(); cu = (ICompilationUnit)cSharpVisitor.Visit(fileCompilationUnit, null); if (cu != null) { callingClass = GetInnermostClass(); Console.WriteLine("CallingClass is " + (callingClass == null ? "null" : callingClass.Name)); } foreach (string name in lookupTableVisitor.variables.Keys) { ArrayList variables = (ArrayList)lookupTableVisitor.variables[name]; if (variables != null && variables.Count > 0) { foreach (LocalLookupVariable v in variables) { if (IsInside(new Point(caretColumn, caretLine), v.StartPos, v.EndPos)) { result.Add(new Parameter (name, new ReturnType (v.TypeRef.SystemType))); break; } } } } if (callingClass != null) { ListMembers(result, callingClass); } string n = ""; result.AddRange(parserContext.GetNamespaceContents (n, true)); foreach (IUsing u in cu.Usings) { if (u != null && (u.Region == null || u.Region.IsInside(caretLine, caretColumn))) { foreach (string name in u.Usings) { result.AddRange(parserContext.GetNamespaceContents (name, true)); } foreach (string alias in u.Aliases.Keys) { result.Add(alias); } } } return result; }
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; }