From 4def43086e42f5f8a23ad0c3ba62af42e1ccd7f5 Mon Sep 17 00:00:00 2001 From: Eberhard Graether Date: Fri, 19 Apr 2019 14:08:11 +0200 Subject: [PATCH] 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 --- src/lib_cxx/data/parser/cxx/CxxAstVisitor.cpp | 4 +-- .../CxxAstVisitorComponentBraceRecorder.cpp | 8 +++--- .../cxx/CxxAstVisitorComponentIndexer.cpp | 4 +-- src/lib_cxx/data/parser/cxx/CxxParser.cpp | 28 +++++++++++-------- .../cxx/name_resolver/CxxDeclNameResolver.cpp | 8 +++--- 5 files changed, 28 insertions(+), 24 deletions(-) diff --git a/src/lib_cxx/data/parser/cxx/CxxAstVisitor.cpp b/src/lib_cxx/data/parser/cxx/CxxAstVisitor.cpp index bc44af0e..69731bb3 100644 --- a/src/lib_cxx/data/parser/cxx/CxxAstVisitor.cpp +++ b/src/lib_cxx/data/parser/cxx/CxxAstVisitor.cpp @@ -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)) diff --git a/src/lib_cxx/data/parser/cxx/CxxAstVisitorComponentBraceRecorder.cpp b/src/lib_cxx/data/parser/cxx/CxxAstVisitorComponentBraceRecorder.cpp index b2ec6403..e14cdf9f 100644 --- a/src/lib_cxx/data/parser/cxx/CxxAstVisitorComponentBraceRecorder.cpp +++ b/src/lib_cxx/data/parser/cxx/CxxAstVisitorComponentBraceRecorder.cpp @@ -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())) ); } } diff --git a/src/lib_cxx/data/parser/cxx/CxxAstVisitorComponentIndexer.cpp b/src/lib_cxx/data/parser/cxx/CxxAstVisitorComponentIndexer.cpp index c8e8d9e7..f84e2864 100644 --- a/src/lib_cxx/data/parser/cxx/CxxAstVisitorComponentIndexer.cpp +++ b/src/lib_cxx/data/parser/cxx/CxxAstVisitorComponentIndexer.cpp @@ -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())) diff --git a/src/lib_cxx/data/parser/cxx/CxxParser.cpp b/src/lib_cxx/data/parser/cxx/CxxParser.cpp index 11421bc9..3b80b6c0 100644 --- a/src/lib_cxx/data/parser/cxx/CxxParser.cpp +++ b/src/lib_cxx/data/parser/cxx/CxxParser.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -34,7 +35,7 @@ namespace // copied from clang codebase clang::driver::Driver *newDriver( clang::DiagnosticsEngine *Diagnostics, const char *BinaryName, - clang::IntrusiveRefCntPtr VFS) { + clang::IntrusiveRefCntPtr 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 Files(new clang::FileManager(clang::FileSystemOptions())); - clang::tooling::ToolInvocation Invocation(prependSyntaxOnlyToolArgs(appendFilePath(Args, FileNameRef)), ToolAction, Files.get()); + + llvm::IntrusiveRefCntPtr OverlayFileSystem(new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem())); + llvm::IntrusiveRefCntPtr InMemoryFileSystem(new llvm::vfs::InMemoryFileSystem); + OverlayFileSystem->pushOverlay(InMemoryFileSystem); + llvm::IntrusiveRefCntPtr 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 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("-", compileCommand.CommandLine.front())) + std::vector args = indexerCommand->getCompilerFlags(); + if (!args.empty() && !utility::isPrefix(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); diff --git a/src/lib_cxx/data/parser/cxx/name_resolver/CxxDeclNameResolver.cpp b/src/lib_cxx/data/parser/cxx/name_resolver/CxxDeclNameResolver.cpp index 94ec70c9..2cb2ffec 100644 --- a/src/lib_cxx/data/parser/cxx/name_resolver/CxxDeclNameResolver.cpp +++ b/src/lib_cxx/data/parser/cxx/name_resolver/CxxDeclNameResolver.cpp @@ -252,7 +252,7 @@ std::unique_ptr CxxDeclNameResolver::getDeclName(const clang::Named { const clang::SourceManager& sourceManager = declaration->getASTContext().getSourceManager(); const clang::PresumedLoc& presumedBegin = - sourceManager.getPresumedLoc(clang::dyn_cast_or_null(functionDecl)->getParent()->getLocStart()); + sourceManager.getPresumedLoc(clang::dyn_cast_or_null(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()) {