From 2fd1ed46072e6728baefa928c139e7ea556e65f8 Mon Sep 17 00:00:00 2001
From: Argyrios Kyrtzidis <akyrtzi@gmail.com>
Date: Sat, 16 Aug 2014 00:26:19 +0000
Subject: [PATCH] [libclang] Introduce clang_File_isEqual for comparing CXFile
 handles.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@215796 91177308-0d34-0410-b5e6-96231b3b80d8
---
 include/clang-c/Index.h         |  8 +++++++-
 tools/libclang/CIndex.cpp       | 12 ++++++++++++
 tools/libclang/libclang.exports |  1 +
 3 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h
index 8b2d3782d35..7b8d4cf934c 100644
--- a/include/clang-c/Index.h
+++ b/include/clang-c/Index.h
@@ -32,7 +32,7 @@
  * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
  */
 #define CINDEX_VERSION_MAJOR 0
-#define CINDEX_VERSION_MINOR 27
+#define CINDEX_VERSION_MINOR 28
 
 #define CINDEX_VERSION_ENCODE(major, minor) ( \
       ((major) * 10000)                       \
@@ -335,6 +335,12 @@ clang_isFileMultipleIncludeGuarded(CXTranslationUnit tu, CXFile file);
 CINDEX_LINKAGE CXFile clang_getFile(CXTranslationUnit tu,
                                     const char *file_name);
 
+/**
+ * \brief Returns non-zero if the \c file1 and \c file2 point to the same file,
+ * or they are both NULL.
+ */
+CINDEX_LINKAGE int clang_File_isEqual(CXFile file1, CXFile file2);
+
 /**
  * @}
  */
diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp
index 716f79ac33e..97a27591cf7 100644
--- a/tools/libclang/CIndex.cpp
+++ b/tools/libclang/CIndex.cpp
@@ -3283,6 +3283,18 @@ int clang_getFileUniqueID(CXFile file, CXFileUniqueID *outID) {
   return 0;
 }
 
+int clang_File_isEqual(CXFile file1, CXFile file2) {
+  if (file1 == file2)
+    return true;
+
+  if (!file1 || !file2)
+    return false;
+
+  FileEntry *FEnt1 = static_cast<FileEntry *>(file1);
+  FileEntry *FEnt2 = static_cast<FileEntry *>(file2);
+  return FEnt1->getUniqueID() == FEnt2->getUniqueID();
+}
+
 } // end: extern "C"
 
 //===----------------------------------------------------------------------===//
diff --git a/tools/libclang/libclang.exports b/tools/libclang/libclang.exports
index ad0d585c850..5a029f7e4f9 100644
--- a/tools/libclang/libclang.exports
+++ b/tools/libclang/libclang.exports
@@ -25,6 +25,7 @@ clang_Cursor_isNull
 clang_Cursor_isObjCOptional
 clang_Cursor_isVariadic
 clang_Cursor_getModule
+clang_File_isEqual
 clang_Module_getASTFile
 clang_Module_getParent
 clang_Module_getName
-- 
GitLab