build: Updated to clang 8

* updated "runToolOnCodeWithArgs" from clang 3.7 code to clang 8 code
* fixed "clang-tool" may have occurred in compile command twice
This commit is contained in:
Eberhard Graether
2019-04-19 14:08:11 +02:00
parent 4dd032dcff
commit 4def43086e
5 changed files with 28 additions and 24 deletions
@@ -541,11 +541,11 @@ bool CxxAstVisitor::shouldVisitStmt(const clang::Stmt* s) const
{
if (s)
{
clang::SourceLocation loc = m_astContext->getSourceManager().getExpansionLoc(s->getLocStart());
clang::SourceLocation loc = m_astContext->getSourceManager().getExpansionLoc(s->getBeginLoc());
if (loc.isInvalid())
{
loc = s->getLocStart();
loc = s->getBeginLoc();
}
if (isLocatedInProjectFile(loc))
@@ -41,9 +41,9 @@ void CxxAstVisitorComponentBraceRecorder::visitNamespaceDecl(clang::NamespaceDec
if (getAstVisitor()->shouldVisitDecl(d))
{
recordBraces(
getFilePath(d->getLocStart()),
getParseLocation(getFirstLBraceLocation(d->getLocStart())),
getParseLocation(getLastRBraceLocation(d->getLocStart(), d->getLocEnd()))
getFilePath(d->getBeginLoc()),
getParseLocation(getFirstLBraceLocation(d->getBeginLoc())),
getParseLocation(getLastRBraceLocation(d->getBeginLoc(), d->getEndLoc()))
);
}
}
@@ -97,7 +97,7 @@ void CxxAstVisitorComponentBraceRecorder::visitMSAsmStmt(clang::MSAsmStmt* s)
recordBraces(
getFilePath(s->getLBraceLoc()),
getParseLocation(s->getLBraceLoc()),
getParseLocation(getLastRBraceLocation(s->getLocStart(), s->getLocEnd()))
getParseLocation(getLastRBraceLocation(s->getBeginLoc(), s->getEndLoc()))
);
}
}
@@ -684,7 +684,7 @@ void CxxAstVisitorComponentIndexer::visitLambdaExpr(clang::LambdaExpr* s)
{
Id symbolId = getOrCreateSymbolId(methodDecl);
m_client->recordSymbolKind(symbolId, SYMBOL_FUNCTION);
m_client->recordLocation(symbolId, getParseLocation(s->getLocStart()), ParseLocationType::TOKEN);
m_client->recordLocation(symbolId, getParseLocation(s->getBeginLoc()), ParseLocationType::TOKEN);
m_client->recordLocation(symbolId, getParseLocationOfFunctionBody(methodDecl), ParseLocationType::SCOPE);
m_client->recordDefinitionKind(symbolId, utility::isImplicit(methodDecl) ? DEFINITION_IMPLICIT : DEFINITION_EXPLICIT);
}
@@ -741,7 +741,7 @@ ParseLocation CxxAstVisitorComponentIndexer::getSignatureLocation(clang::Functio
if (d->getNumParams() > 0)
{
endLoc = d->getParamDecl(d->getNumParams() - 1)->getLocEnd();
endLoc = d->getParamDecl(d->getNumParams() - 1)->getEndLoc();
}
while (sm.isBeforeInTranslationUnit(endLoc, signatureRange.getEnd()))
+16 -12
View File
@@ -5,6 +5,7 @@
#include <clang/Driver/Options.h>
#include <clang/Frontend/CompilerInvocation.h>
#include <clang/Tooling/Tooling.h>
#include <llvm/Support/VirtualFileSystem.h>
#include <llvm/Option/ArgList.h>
#include <llvm/Support/TargetSelect.h>
@@ -34,7 +35,7 @@ namespace
// copied from clang codebase
clang::driver::Driver *newDriver(
clang::DiagnosticsEngine *Diagnostics, const char *BinaryName,
clang::IntrusiveRefCntPtr<clang::vfs::FileSystem> VFS) {
clang::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS) {
clang::driver::Driver *CompilerDriver =
new clang::driver::Driver(BinaryName, llvm::sys::getDefaultTargetTriple(),
*Diagnostics, std::move(VFS));
@@ -115,16 +116,19 @@ namespace
{
llvm::SmallString<16> FileNameStorage;
llvm::StringRef FileNameRef = FileName.toNullTerminatedStringRef(FileNameStorage);
llvm::IntrusiveRefCntPtr<clang::FileManager> Files(new clang::FileManager(clang::FileSystemOptions()));
clang::tooling::ToolInvocation Invocation(prependSyntaxOnlyToolArgs(appendFilePath(Args, FileNameRef)), ToolAction, Files.get());
llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFileSystem(new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem()));
llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem(new llvm::vfs::InMemoryFileSystem);
OverlayFileSystem->pushOverlay(InMemoryFileSystem);
llvm::IntrusiveRefCntPtr<clang::FileManager> Files(new clang::FileManager(clang::FileSystemOptions(), OverlayFileSystem));
clang::tooling::ToolInvocation Invocation(prependSyntaxOnlyToolArgs(appendFilePath(Args, FileNameRef)), ToolAction, Files.get());
llvm::SmallString<1024> CodeStorage;
Invocation.mapVirtualFile(FileNameRef, Code.toNullTerminatedStringRef(CodeStorage));
llvm::StringRef CodeRef = Code.toNullTerminatedStringRef(CodeStorage);
for (auto &FilenameWithContent : VirtualMappedFiles)
{
Invocation.mapVirtualFile(FilenameWithContent.first, FilenameWithContent.second);
}
InMemoryFileSystem->addFile(FileNameRef, 0,
llvm::MemoryBuffer::getMemBufferCopy(CodeRef));
Invocation.setDiagnosticConsumer(DiagConsumer);
@@ -150,12 +154,12 @@ void CxxParser::buildIndex(std::shared_ptr<IndexerCommandCxx> indexerCommand)
clang::tooling::CompileCommand compileCommand;
compileCommand.Filename = utility::encodeToUtf8(indexerCommand->getSourceFilePath().wstr());
compileCommand.Directory = utility::encodeToUtf8(indexerCommand->getWorkingDirectory().wstr());
compileCommand.CommandLine = getCommandlineArgumentsEssential(indexerCommand->getCompilerFlags());
if (!utility::isPrefix<std::string>("-", compileCommand.CommandLine.front()))
std::vector<std::wstring> args = indexerCommand->getCompilerFlags();
if (!args.empty() && !utility::isPrefix<std::wstring>(L"-", args.front()))
{
compileCommand.CommandLine.erase(compileCommand.CommandLine.begin());
args.erase(args.begin());
}
compileCommand.CommandLine = getCommandlineArgumentsEssential(args);
compileCommand.CommandLine = prependSyntaxOnlyToolArgs(compileCommand.CommandLine);
CxxCompilationDatabaseSingle compilationDatabase(compileCommand);
@@ -252,7 +252,7 @@ std::unique_ptr<CxxDeclName> CxxDeclNameResolver::getDeclName(const clang::Named
{
const clang::SourceManager& sourceManager = declaration->getASTContext().getSourceManager();
const clang::PresumedLoc& presumedBegin =
sourceManager.getPresumedLoc(clang::dyn_cast_or_null<clang::CXXMethodDecl>(functionDecl)->getParent()->getLocStart());
sourceManager.getPresumedLoc(clang::dyn_cast_or_null<clang::CXXMethodDecl>(functionDecl)->getParent()->getBeginLoc());
functionName = L"lambda at " + std::to_wstring(presumedBegin.getLine()) + L":" + std::to_wstring(presumedBegin.getColumn());
}
else if (clang::FunctionTemplateDecl* templateFunctionDeclaration = functionDecl->getDescribedFunctionTemplate())
@@ -453,20 +453,20 @@ std::wstring CxxDeclNameResolver::getTranslationUnitMainFileName(const clang::De
std::wstring CxxDeclNameResolver::getDeclarationFileName(const clang::Decl* declaration)
{
const clang::SourceManager& sourceManager = declaration->getASTContext().getSourceManager();
const clang::FileID fileId = sourceManager.getFileID(declaration->getLocStart());
const clang::FileID fileId = sourceManager.getFileID(declaration->getBeginLoc());
const clang::FileEntry* fileEntry = sourceManager.getFileEntryForID(fileId);
if (fileEntry != nullptr && fileEntry->isValid())
{
return getCanonicalFilePathCache()->getCanonicalFilePath(fileId, sourceManager).fileName();
}
return getCanonicalFilePathCache()->getCanonicalFilePath(
utility::decodeFromUtf8(sourceManager.getPresumedLoc(declaration->getLocStart()).getFilename())).fileName();
utility::decodeFromUtf8(sourceManager.getPresumedLoc(declaration->getBeginLoc()).getFilename())).fileName();
}
std::wstring CxxDeclNameResolver::getNameForAnonymousSymbol(const std::wstring& symbolKindName, const clang::Decl* declaration)
{
const clang::SourceManager& sourceManager = declaration->getASTContext().getSourceManager();
const clang::PresumedLoc& presumedBegin = sourceManager.getPresumedLoc(declaration->getLocStart());
const clang::PresumedLoc& presumedBegin = sourceManager.getPresumedLoc(declaration->getBeginLoc());
if (presumedBegin.isValid())
{