[clang] b5d3abe - [libclang] Get rid of relience on SourceManager member signature

Kadir Cetinkaya via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 25 03:08:32 PDT 2020


Author: Kadir Cetinkaya
Date: 2020-06-25T12:04:12+02:00
New Revision: b5d3abea228bf17a009a007061c82d14461766c7

URL: https://github.com/llvm/llvm-project/commit/b5d3abea228bf17a009a007061c82d14461766c7
DIFF: https://github.com/llvm/llvm-project/commit/b5d3abea228bf17a009a007061c82d14461766c7.diff

LOG: [libclang] Get rid of relience on SourceManager member signature

Summary:
Libclang was enforcing a singature on SourceManager::getLocalSLocEntry
which isn't possible to satisfy as pointed out in
https://reviews.llvm.org/D80681#inline-751438.

This patch updates the libclang, hopefully without breaking API stability, to
not rely on member signature. To enable changing the signature in D82498.

Reviewers: sammccall, bkramer

Subscribers: arphaman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D82532

Added: 
    

Modified: 
    clang/tools/libclang/CIndexInclusionStack.cpp

Removed: 
    


################################################################################
diff  --git a/clang/tools/libclang/CIndexInclusionStack.cpp b/clang/tools/libclang/CIndexInclusionStack.cpp
index f1c5b53c5ef6..7572512ae576 100644
--- a/clang/tools/libclang/CIndexInclusionStack.cpp
+++ b/clang/tools/libclang/CIndexInclusionStack.cpp
@@ -18,10 +18,9 @@
 #include "clang/Frontend/ASTUnit.h"
 using namespace clang;
 
-static void getInclusions(const SrcMgr::SLocEntry &(SourceManager::*Getter)(unsigned, bool*) const, unsigned n,
-                          CXTranslationUnit TU, CXInclusionVisitor CB,
-                          CXClientData clientData)
-{
+namespace {
+void getInclusions(bool IsLocal, unsigned n, CXTranslationUnit TU,
+                   CXInclusionVisitor CB, CXClientData clientData) {
   ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
   SourceManager &SM = CXXUnit->getSourceManager();
   ASTContext &Ctx = CXXUnit->getASTContext();
@@ -30,8 +29,8 @@ static void getInclusions(const SrcMgr::SLocEntry &(SourceManager::*Getter)(unsi
 
   for (unsigned i = 0 ; i < n ; ++i) {
     bool Invalid = false;
-    const SrcMgr::SLocEntry &SL = (SM.*Getter)(i, &Invalid);
-
+    const SrcMgr::SLocEntry &SL =
+        IsLocal ? SM.getLocalSLocEntry(i) : SM.getLoadedSLocEntry(i, &Invalid);
     if (!SL.isFile() || Invalid)
       continue;
 
@@ -61,11 +60,11 @@ static void getInclusions(const SrcMgr::SLocEntry &(SourceManager::*Getter)(unsi
     // Callback to the client.
     // FIXME: We should have a function to construct CXFiles.
     CB(static_cast<CXFile>(
-         const_cast<FileEntry *>(FI.getContentCache()->OrigEntry)),
+           const_cast<FileEntry *>(FI.getContentCache()->OrigEntry)),
        InclusionStack.data(), InclusionStack.size(), clientData);
   }
 }
-
+} // namespace
 
 void clang_getInclusions(CXTranslationUnit TU, CXInclusionVisitor CB,
                          CXClientData clientData) {
@@ -83,14 +82,13 @@ void clang_getInclusions(CXTranslationUnit TU, CXInclusionVisitor CB,
   // a AST/PCH file, but this file has a pre-compiled preamble, we also need
   // to look in that file.
   if (n == 1 || SM.getPreambleFileID().isValid()) {
-    getInclusions(&SourceManager::getLoadedSLocEntry,
-                  SM.loaded_sloc_entry_size(), TU, CB, clientData);
+    getInclusions(/*IsLocal=*/false, SM.loaded_sloc_entry_size(), TU, CB,
+                  clientData);
   }
 
   // Not a PCH/AST file. Note, if there is a preamble, it could still be that
   // there are #includes in this file (e.g. for any include after the first
   // declaration).
   if (n != 1)
-    getInclusions(&SourceManager::getLocalSLocEntry, n, TU, CB, clientData);
-
+    getInclusions(/*IsLocal=*/true, n, TU, CB, clientData);
 }


        


More information about the cfe-commits mailing list