[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
This commit is contained in:
Kadir Cetinkaya 2020-06-25 10:56:51 +02:00
parent e4e2d8e4c2
commit b5d3abea22
No known key found for this signature in database
GPG Key ID: E39E36B8D2057ED6
1 changed files with 10 additions and 12 deletions

View File

@ -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);
}