]> granicus.if.org Git - clang/commitdiff
Extend libclang debugging output for clang_getCursor() to show the definition we...
authorDouglas Gregor <dgregor@apple.com>
Fri, 10 Dec 2010 01:45:00 +0000 (01:45 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 10 Dec 2010 01:45:00 +0000 (01:45 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@121451 91177308-0d34-0410-b5e6-96231b3b80d8

tools/libclang/CIndex.cpp

index d85e801d387ff9b7f71b2261dd98cdb326d3e1d9..a74a7a9895f82536b3ae23da3fc5479384863d57 100644 (file)
@@ -3130,6 +3130,24 @@ CXCursor clang_getCursor(CXTranslationUnit TU, CXSourceLocation Loc) {
     clang_disposeString(ResultFileName);
     clang_disposeString(KindSpelling);
     clang_disposeString(USR);
+    
+    CXCursor Definition = clang_getCursorDefinition(Result);
+    if (!clang_equalCursors(Definition, clang_getNullCursor())) {
+      CXSourceLocation DefinitionLoc = clang_getCursorLocation(Definition);
+      CXString DefinitionKindSpelling
+                                = clang_getCursorKindSpelling(Definition.kind);
+      CXFile DefinitionFile;
+      unsigned DefinitionLine, DefinitionColumn;
+      clang_getInstantiationLocation(DefinitionLoc, &DefinitionFile, 
+                                     &DefinitionLine, &DefinitionColumn, 0);
+      CXString DefinitionFileName = clang_getFileName(DefinitionFile);
+      fprintf(stderr, "  -> %s(%s:%d:%d)\n",
+              clang_getCString(DefinitionKindSpelling),
+              clang_getCString(DefinitionFileName),
+              DefinitionLine, DefinitionColumn);
+      clang_disposeString(DefinitionFileName);
+      clang_disposeString(DefinitionKindSpelling);
+    }
   }
 
   return Result;