]> granicus.if.org Git - clang/commitdiff
[libclang] Introduce clang_getFileUniqueID which returns a struct
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Sat, 26 Jan 2013 04:52:52 +0000 (04:52 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Sat, 26 Jan 2013 04:52:52 +0000 (04:52 +0000)
for a CXFile containing device/inode/modification time.

Intended to be useful as a key associated with a unique file across
an indexing session.

rdar://13091837

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173559 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang-c/Index.h
tools/libclang/CIndex.cpp
tools/libclang/libclang.exports

index 6fa8296bdfb250c422358a7f07c077aab019056e..2a66e7a798e017de615ddec41b2a82c85d78ea54 100644 (file)
@@ -32,7 +32,7 @@
  * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
  */
 #define CINDEX_VERSION_MAJOR 0
-#define CINDEX_VERSION_MINOR 10
+#define CINDEX_VERSION_MINOR 11
 
 #define CINDEX_VERSION_ENCODE(major, minor) ( \
       ((major) * 10000)                       \
@@ -296,6 +296,24 @@ CINDEX_LINKAGE CXString clang_getFileName(CXFile SFile);
  */
 CINDEX_LINKAGE time_t clang_getFileTime(CXFile SFile);
 
+/**
+ * \brief Uniquely identifies a CXFile, that refers to the same underlying file,
+ * across an indexing session.
+ */
+typedef struct {
+  unsigned long long data[3];
+} CXFileUniqueID;
+
+/**
+ * \brief Retrieve the unique ID for the given \c file.
+ *
+ * \param file the file to get the ID for.
+ * \param outID stores the returned CXFileUniqueID.
+ * \returns If there was a failure getting the unique ID, returns non-zero,
+ * otherwise returns 0.
+*/
+CINDEX_LINKAGE int clang_getFileUniqueID(CXFile file, CXFileUniqueID *outID);
+
 /**
  * \brief Determine whether the given header is guarded against
  * multiple inclusions, either with the conventional
index 5d492417bae6c3931c4a66e411c51ed1f9a94393..a8517091acb2e10ddea305391d6571386051f989 100644 (file)
@@ -2960,6 +2960,21 @@ unsigned clang_isFileMultipleIncludeGuarded(CXTranslationUnit tu, CXFile file) {
                                           .isFileMultipleIncludeGuarded(FEnt);
 }
 
+int clang_getFileUniqueID(CXFile file, CXFileUniqueID *outID) {
+  if (!file || !outID)
+    return 1;
+
+#ifdef LLVM_ON_WIN32
+  return 1; // inodes not supported on windows.
+#else
+  FileEntry *FEnt = static_cast<FileEntry *>(file);
+  outID->data[0] = FEnt->getDevice();
+  outID->data[1] = FEnt->getInode();
+  outID->data[2] = FEnt->getModificationTime();
+  return 0;
+#endif
+}
+
 } // end: extern "C"
 
 //===----------------------------------------------------------------------===//
index 8f3c86318c76f8ad31d759591bfda26766a947c1..616be4c635eb2074855819f20d39eb88595997ee 100644 (file)
@@ -166,6 +166,7 @@ clang_getFile
 clang_getFileLocation
 clang_getFileName
 clang_getFileTime
+clang_getFileUniqueID
 clang_getFunctionTypeCallingConv
 clang_getIBOutletCollectionType
 clang_getIncludedFile