From: Kadir Cetinkaya Date: Thu, 25 Jun 2020 08:56:51 +0000 (+0200) Subject: [libclang] Get rid of relience on SourceManager member signature X-Git-Tag: llvmorg-12-init~1976 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b5d3abea228bf17a009a007061c82d14461766c7;p=platform%2Fupstream%2Fllvm.git [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 --- diff --git a/clang/tools/libclang/CIndexInclusionStack.cpp b/clang/tools/libclang/CIndexInclusionStack.cpp index f1c5b53..7572512 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( - const_cast(FI.getContentCache()->OrigEntry)), + const_cast(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); }