Add support for 'CXFile' (<rdar://problem/7303360>).
- 4 new functions (clang_getCursorSourceFile, clang_getDeclSourceFile, clang_getFileName, clang_getFileTime).
- Should remove clang_getDeclSource() and clang_getCursorSource(). For now, just put 'deprecate' comment in header.
- Also changed CXX style comment to C style (to eliminate warning).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@85238 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/CIndex/CIndex.cpp b/tools/CIndex/CIndex.cpp
index f044f89..5ffa6d7 100644
--- a/tools/CIndex/CIndex.cpp
+++ b/tools/CIndex/CIndex.cpp
@@ -571,9 +571,40 @@
const char *clang_getDeclSource(CXDecl AnonDecl)
{
assert(AnonDecl && "Passed null CXDecl");
+ FileEntry *FEnt = static_cast<FileEntry *>(clang_getDeclSourceFile(AnonDecl));
+ assert (FEnt && "Cannot find FileEntry for Decl");
+ return clang_getFileName(FEnt);
+}
+
+static const FileEntry *getFileEntryFromSourceLocation(SourceManager &SMgr,
+ SourceLocation SLoc)
+{
+ FileID FID;
+ if (SLoc.isFileID())
+ FID = SMgr.getFileID(SLoc);
+ else
+ FID = SMgr.getDecomposedSpellingLoc(SLoc).first;
+ return SMgr.getFileEntryForID(FID);
+}
+
+CXFile clang_getDeclSourceFile(CXDecl AnonDecl)
+{
+ assert(AnonDecl && "Passed null CXDecl");
NamedDecl *ND = static_cast<NamedDecl *>(AnonDecl);
SourceManager &SourceMgr = ND->getASTContext().getSourceManager();
- return SourceMgr.getBufferName(ND->getLocation());
+ return (void *)getFileEntryFromSourceLocation(SourceMgr, ND->getLocation());
+}
+
+const char *clang_getFileName(CXFile SFile) {
+ assert(SFile && "Passed null CXFile");
+ FileEntry *FEnt = static_cast<FileEntry *>(SFile);
+ return FEnt->getName();
+}
+
+time_t clang_getFileTime(CXFile SFile) {
+ assert(SFile && "Passed null CXFile");
+ FileEntry *FEnt = static_cast<FileEntry *>(SFile);
+ return FEnt->getModificationTime();
}
const char *clang_getCursorSpelling(CXCursor C)
@@ -930,6 +961,16 @@
return Buffer->getBufferIdentifier();
}
+CXFile clang_getCursorSourceFile(CXCursor C)
+{
+ assert(C.decl && "CXCursor has null decl");
+ NamedDecl *ND = static_cast<NamedDecl *>(C.decl);
+ SourceManager &SourceMgr = ND->getASTContext().getSourceManager();
+
+ return (void *)getFileEntryFromSourceLocation(SourceMgr,
+ getLocationFromCursor(C,SourceMgr, ND));
+}
+
void clang_getDefinitionSpellingAndExtent(CXCursor C,
const char **startBuf,
const char **endBuf,