summaryrefslogtreecommitdiffstats
path: root/clang/tools/CIndex
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-10-16 21:24:31 +0000
committerDouglas Gregor <dgregor@apple.com>2009-10-16 21:24:31 +0000
commitd3d923a0f2cc85e5e94ab13cd70d231633e3d33c (patch)
tree08bb8eb57f99c1d90e9172758823050f0169e1cb /clang/tools/CIndex
parent007ceb46039daf322651ab02c26fd8993bad2144 (diff)
downloadbcm5719-llvm-d3d923a0f2cc85e5e94ab13cd70d231633e3d33c.tar.gz
bcm5719-llvm-d3d923a0f2cc85e5e94ab13cd70d231633e3d33c.zip
Make CIndex and c-index-test a little bit more robust. The only
substantive change is that clang_getCursorSource() now returns the file in which a macro was instantiated when the cursor points into a macro instantiation, rather than crashing. llvm-svn: 84275
Diffstat (limited to 'clang/tools/CIndex')
-rw-r--r--clang/tools/CIndex/CIndex.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/clang/tools/CIndex/CIndex.cpp b/clang/tools/CIndex/CIndex.cpp
index 133a269afdf..d0638d07728 100644
--- a/clang/tools/CIndex/CIndex.cpp
+++ b/clang/tools/CIndex/CIndex.cpp
@@ -22,11 +22,12 @@
#include "clang/Basic/FileManager.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Frontend/ASTUnit.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/System/Path.h"
#include <cstdio>
#include <dlfcn.h>
#include <sys/wait.h>
#include <vector>
-#include "llvm/System/Path.h"
using namespace clang;
using namespace idx;
@@ -823,7 +824,18 @@ const char *clang_getCursorSource(CXCursor C)
SourceManager &SourceMgr = ND->getASTContext().getSourceManager();
SourceLocation SLoc = getLocationFromCursor(C, SourceMgr, ND);
- return SourceMgr.getBufferName(SLoc);
+ if (SLoc.isFileID())
+ return SourceMgr.getBufferName(SLoc);
+
+ // Retrieve the file in which the macro was instantiated, then provide that
+ // buffer name.
+ // FIXME: Do we want to give specific macro-instantiation information?
+ const llvm::MemoryBuffer *Buffer
+ = SourceMgr.getBuffer(SourceMgr.getDecomposedSpellingLoc(SLoc).first);
+ if (!Buffer)
+ return 0;
+
+ return Buffer->getBufferIdentifier();
}
void clang_getDefinitionSpellingAndExtent(CXCursor C,
OpenPOWER on IntegriCloud