public CXChildVisitResult Visit(CXCursor cursor, CXCursor parent, IntPtr data) { if (clang.Location_isInSystemHeader(clang.getCursorLocation(cursor)) != 0) { return(CXChildVisitResult.CXChildVisit_Continue); } CXCursorKind curKind = clang.getCursorKind(cursor); var displayName2 = clang.getCursorDisplayName(cursor).ToString(); var name2 = clang.getCursorSpelling(cursor).ToString(); this.logger.WriteLine(string.Format("{0}{1} {2} {3}", this.indent, curKind.ToString(), name2, displayName2)); var old = this.indent; this.indent += " "; clang.visitChildren(cursor, this.Visit, new CXClientData(IntPtr.Zero)); this.indent = old; return(CXChildVisitResult.CXChildVisit_Continue); }
public CXChildVisitResult VisitFile(CXCursor cursor, CXCursor parent, IntPtr data) { var location = clang.getCursorLocation(cursor); if (clang.Location_isInSystemHeader(location) != 0) { return(CXChildVisitResult.CXChildVisit_Continue); } #if false if (false) { CXFile file; uint i, j, k; clang.getFileLocation(location, out file, out i, out j, out k); var fileName = clang.getFileName(file).ToString().Replace('/', System.IO.Path.PathSeparator).Replace('\\', System.IO.Path.PathSeparator); if (this.visited.Contains(fileName)) { return(CXChildVisitResult.CXChildVisit_Continue); } this.visited.Add(fileName); } #endif CXCursorKind curKind = clang.getCursorKind(cursor); if (curKind == CXCursorKind.CXCursor_Namespace) { var previous = this.namespaces; this.namespaces += "." + clang.getCursorSpelling(cursor).ToString(); clang.visitChildren(cursor, this.VisitFile, new CXClientData(IntPtr.Zero)); this.namespaces = previous; } else if (curKind == CXCursorKind.CXCursor_ClassDecl || curKind == CXCursorKind.CXCursor_StructDecl || curKind == CXCursorKind.CXCursor_UnionDecl) { var fullName = FullName(cursor); if (!this.leaves.ContainsKey(fullName)) { var filter = string.Empty; var name = fullName; var i = fullName.LastIndexOf("."); if (i != -1) { name = fullName.Substring(i + 1); filter = fullName.Substring(0, i); } var branch = this.parser.Dependencies.GetPath(filter, "."); var leaf = this.parser.Create(name, fullName, branch); this.SetSourceProvider(leaf, cursor); this.leaves[fullName] = leaf; this.current = leaf; this.links[this.current] = new HashSet <string>(); } else { var leaf = this.leaves[fullName]; this.current = leaf; this.hasChildren = false; clang.visitChildren(cursor, this.VisitChildren, new CXClientData(IntPtr.Zero)); if (this.hasChildren) { this.SetSourceProvider(leaf, cursor); } } clang.visitChildren(cursor, this.VisitClass, new CXClientData(IntPtr.Zero)); this.current = null; } else if (curKind == CXCursorKind.CXCursor_CXXMethod || curKind == CXCursorKind.CXCursor_Constructor || curKind == CXCursorKind.CXCursor_Destructor) { this.current = null; var fullName = FileVisitor.GetClass(cursor); if (fullName.Length == 0) { return(CXChildVisitResult.CXChildVisit_Continue); } if (this.namespaces.Length > 0) { fullName = this.namespaces.Substring(1) + "." + fullName; } if (this.leaves.ContainsKey(fullName)) { this.current = this.leaves[fullName]; clang.visitChildren(cursor, this.VisitClass, new CXClientData(IntPtr.Zero)); this.current = null; } else { this.logger.Write("Cannot find class "); this.logger.WriteLine(fullName); } } else if (curKind != CXCursorKind.CXCursor_UsingDirective && curKind != CXCursorKind.CXCursor_VarDecl) { this.logger.Write("Skipping "); this.logger.WriteLine(curKind.ToString()); } return(CXChildVisitResult.CXChildVisit_Continue); }