Skip to content

Commit b5d3abe

Browse files
committed
[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
1 parent e4e2d8e commit b5d3abe

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

clang/tools/libclang/CIndexInclusionStack.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@
1818
#include "clang/Frontend/ASTUnit.h"
1919
using namespace clang;
2020

21-
static void getInclusions(const SrcMgr::SLocEntry &(SourceManager::*Getter)(unsigned, bool*) const, unsigned n,
22-
CXTranslationUnit TU, CXInclusionVisitor CB,
23-
CXClientData clientData)
24-
{
21+
namespace {
22+
void getInclusions(bool IsLocal, unsigned n, CXTranslationUnit TU,
23+
CXInclusionVisitor CB, CXClientData clientData) {
2524
ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
2625
SourceManager &SM = CXXUnit->getSourceManager();
2726
ASTContext &Ctx = CXXUnit->getASTContext();
@@ -30,8 +29,8 @@ static void getInclusions(const SrcMgr::SLocEntry &(SourceManager::*Getter)(unsi
3029

3130
for (unsigned i = 0 ; i < n ; ++i) {
3231
bool Invalid = false;
33-
const SrcMgr::SLocEntry &SL = (SM.*Getter)(i, &Invalid);
34-
32+
const SrcMgr::SLocEntry &SL =
33+
IsLocal ? SM.getLocalSLocEntry(i) : SM.getLoadedSLocEntry(i, &Invalid);
3534
if (!SL.isFile() || Invalid)
3635
continue;
3736

@@ -61,11 +60,11 @@ static void getInclusions(const SrcMgr::SLocEntry &(SourceManager::*Getter)(unsi
6160
// Callback to the client.
6261
// FIXME: We should have a function to construct CXFiles.
6362
CB(static_cast<CXFile>(
64-
const_cast<FileEntry *>(FI.getContentCache()->OrigEntry)),
63+
const_cast<FileEntry *>(FI.getContentCache()->OrigEntry)),
6564
InclusionStack.data(), InclusionStack.size(), clientData);
6665
}
6766
}
68-
67+
} // namespace
6968

7069
void clang_getInclusions(CXTranslationUnit TU, CXInclusionVisitor CB,
7170
CXClientData clientData) {
@@ -83,14 +82,13 @@ void clang_getInclusions(CXTranslationUnit TU, CXInclusionVisitor CB,
8382
// a AST/PCH file, but this file has a pre-compiled preamble, we also need
8483
// to look in that file.
8584
if (n == 1 || SM.getPreambleFileID().isValid()) {
86-
getInclusions(&SourceManager::getLoadedSLocEntry,
87-
SM.loaded_sloc_entry_size(), TU, CB, clientData);
85+
getInclusions(/*IsLocal=*/false, SM.loaded_sloc_entry_size(), TU, CB,
86+
clientData);
8887
}
8988

9089
// Not a PCH/AST file. Note, if there is a preamble, it could still be that
9190
// there are #includes in this file (e.g. for any include after the first
9291
// declaration).
9392
if (n != 1)
94-
getInclusions(&SourceManager::getLocalSLocEntry, n, TU, CB, clientData);
95-
93+
getInclusions(/*IsLocal=*/true, n, TU, CB, clientData);
9694
}

0 commit comments

Comments
 (0)