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

Kadir Cetinkaya via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 25 02:08:40 PDT 2020


kadircet created this revision.
kadircet added reviewers: sammccall, bkramer.
Herald added subscribers: cfe-commits, arphaman.
Herald added a project: clang.

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 <https://reviews.llvm.org/D82498>.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D82532

Files:
  clang/tools/libclang/CIndexInclusionStack.cpp


Index: clang/tools/libclang/CIndexInclusionStack.cpp
===================================================================
--- clang/tools/libclang/CIndexInclusionStack.cpp
+++ 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 @@
 
   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 @@
     // 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 @@
   // 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);
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D82532.273262.patch
Type: text/x-patch
Size: 2412 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200625/cd0eb3f6/attachment-0001.bin>


More information about the cfe-commits mailing list