Merge remote-tracking branch 'origin/4.10'

Conflicts:
	qbs/modules/qtc/qtc.qbs
	qtcreator_ide_branding.pri
	src/libs/utils/synchronousprocess.cpp
	src/plugins/baremetal/iarewtoolchain.cpp
	src/plugins/cmakeprojectmanager/cmakeproject.cpp
	tests/unit/unittest/CMakeLists.txt

Change-Id: I124ad492df403286751e175d27fe36487ddf6d07
This commit is contained in:
Tim Jenssen
2019-07-04 14:47:52 +02:00
219 changed files with 2998 additions and 3305 deletions

View File

@@ -18,8 +18,6 @@ add_qtc_library(clangrefactoringbackend_lib STATIC
collectmacrospreprocessorcallbacks.h
collectmacrossourcefilecallbacks.cpp collectmacrossourcefilecallbacks.h
collectsymbolsaction.cpp collectsymbolsaction.h
filestatus.h
filestatuscache.cpp filestatuscache.h
filestatuspreprocessorcallbacks.cpp filestatuspreprocessorcallbacks.h
findcursorusr.h
findlocationsofusrs.h

View File

@@ -26,11 +26,8 @@ HEADERS += \
!isEmpty(LIBTOOLING_LIBS) {
SOURCES += \
$$PWD/refactoringcompilationdatabase.cpp \
$$PWD/symbolfinder.cpp \
$$PWD/symbollocationfinderaction.cpp \
$$PWD/refactoringserver.cpp \
$$PWD/macropreprocessorcallbacks.cpp \
$$PWD/findusrforcursoraction.cpp \
$$PWD/clangquery.cpp \
$$PWD/clangtool.cpp \
$$PWD/sourcerangeextractor.cpp \
@@ -44,14 +41,10 @@ SOURCES += \
HEADERS += \
$$PWD/refactoringcompilationdatabase.h \
$$PWD/symbolfinder.h \
$$PWD/symbollocationfinderaction.h \
$$PWD/refactoringserver.h \
$$PWD/macropreprocessorcallbacks.h \
$$PWD/sourcelocationsutils.h \
$$PWD/findcursorusr.h \
$$PWD/findusrforcursoraction.h \
$$PWD/findlocationsofusrs.h \
$$PWD/clangquery.h \
$$PWD/clangtool.h \
$$PWD/sourcerangeextractor.h \

View File

@@ -1,191 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include "clangrefactoringbackend_global.h"
#include <clang/AST/AST.h>
#include <clang/AST/ASTContext.h>
#include <clang/AST/RecursiveASTVisitor.h>
#include <clang/Index/USRGeneration.h>
#include <llvm/ADT/SmallVector.h>
#include <vector>
namespace ClangBackEnd {
class FindNamedDeclarationASTVisitor : public clang::RecursiveASTVisitor<FindNamedDeclarationASTVisitor>
{
public:
explicit FindNamedDeclarationASTVisitor(const clang::SourceManager &sourceManager,
const clang::SourceLocation cursorSourceLocation)
: m_sourceManager(sourceManager),
m_cursorSourceLocation(cursorSourceLocation)
{
}
bool shouldVisitTemplateInstantiations() const
{
return true;
}
bool VisitNamedDecl(const clang::NamedDecl *declaration)
{
auto name = declaration->getNameAsString();
setResultIfCursorIsInBetween(declaration,
declaration->getLocation(),
declaration->getNameAsString().length());
return true;
}
bool VisitDeclRefExpr(const clang::DeclRefExpr *expression)
{
if (!iterateNestedNameSpecifierLocation(expression->getQualifierLoc()))
return false;
const auto *declaration = expression->getFoundDecl();
return setResultIfCursorIsInBetween(declaration,
expression->getLocation(),
declaration->getNameAsString().length());
}
bool VisitMemberExpr(const clang::MemberExpr *expression)
{
const auto *declaration = expression->getFoundDecl().getDecl();
return setResultIfCursorIsInBetween(declaration,
expression->getMemberLoc(),
declaration->getNameAsString().length());
}
std::vector<const clang::NamedDecl*> takeNamedDecl()
{
return std::move(m_namedDeclarations);
}
private:
bool canSetResult(const clang::NamedDecl *declaration,
clang::SourceLocation location)
{
return declaration
&& !setResultIfCursorIsInBetween(declaration,
location,
declaration->getNameAsString().length());
}
bool iterateNestedNameSpecifierLocation(clang::NestedNameSpecifierLoc nameLocation) {
while (nameLocation) {
const auto *declaration = nameLocation.getNestedNameSpecifier()->getAsNamespace();
if (canSetResult(declaration, nameLocation.getLocalBeginLoc()))
return false;
nameLocation = nameLocation.getPrefix();
}
return true;
}
bool isValidLocationWithCursorInside(clang::SourceLocation startLocation,
clang::SourceLocation endLocation)
{
return startLocation.isValid()
&& startLocation.isFileID()
&& endLocation.isValid()
&& endLocation.isFileID()
&& isCursorLocationBetween(startLocation, endLocation);
}
bool setResultIfCursorIsInBetween(const clang::NamedDecl *declaration,
clang::SourceLocation startLocation,
clang::SourceLocation endLocation)
{
bool isValid = isValidLocationWithCursorInside(startLocation, endLocation);
if (isValid)
m_namedDeclarations.push_back(declaration);
return !isValid;
}
bool setResultIfCursorIsInBetween(const clang::NamedDecl *declaration,
clang::SourceLocation location,
uint offset) {
return offset == 0
|| setResultIfCursorIsInBetween(declaration, location, location.getLocWithOffset(offset - 1));
}
bool isCursorLocationBetween(const clang::SourceLocation startLocation,
const clang::SourceLocation endLocation)
{
return m_cursorSourceLocation == startLocation
|| m_cursorSourceLocation == endLocation
|| (m_sourceManager.isBeforeInTranslationUnit(startLocation, m_cursorSourceLocation)
&& m_sourceManager.isBeforeInTranslationUnit(m_cursorSourceLocation, endLocation));
}
std::vector<const clang::NamedDecl*> m_namedDeclarations;
const clang::SourceManager &m_sourceManager;
const clang::SourceLocation m_cursorSourceLocation;
};
inline
std::vector<const clang::NamedDecl *> namedDeclarationsAt(const clang::ASTContext &Context,
const clang::SourceLocation cursorSourceLocation)
{
const auto &sourceManager = Context.getSourceManager();
const auto currentFile = sourceManager.getFilename(cursorSourceLocation);
FindNamedDeclarationASTVisitor visitor(sourceManager, cursorSourceLocation);
auto declarations = Context.getTranslationUnitDecl()->decls();
for (auto &currentDeclation : declarations) {
const auto &fileLocation = currentDeclation->getBeginLoc();
const auto &fileName = sourceManager.getFilename(fileLocation);
if (fileName == currentFile) {
visitor.TraverseDecl(currentDeclation);
const auto &namedDeclarations = visitor.takeNamedDecl();
if (!namedDeclarations.empty())
return namedDeclarations;
}
}
return std::vector<const clang::NamedDecl *>();
}
inline
USRName USROfDeclaration(const clang::Decl *declaration)
{
USRName buffer;
if (declaration == nullptr || clang::index::generateUSRForDecl(declaration, buffer))
return buffer;
return buffer;
}
} // namespace ClangBackend

View File

@@ -1,126 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include "findcursorusr.h"
#include <clang/AST/ASTContext.h>
#include <clang/AST/RecursiveASTVisitor.h>
#include <clang/Basic/SourceLocation.h>
#include <clang/Index/USRGeneration.h>
#include <llvm/ADT/SmallVector.h>
#include <vector>
namespace ClangBackEnd {
class FindLocationsOfUSRsASTVisitor : public clang::RecursiveASTVisitor<FindLocationsOfUSRsASTVisitor>
{
public:
explicit FindLocationsOfUSRsASTVisitor(const std::vector<USRName> &unifiedSymbolResolutions)
: unifiedSymbolResolutions(unifiedSymbolResolutions)
{
}
bool VisitNamedDecl(const clang::NamedDecl *declaration) {
auto declarationUSR = USROfDeclaration(declaration);
if (containsUSR(declarationUSR))
foundLocations.push_back(declaration->getLocation());
return true;
}
bool VisitDeclRefExpr(const clang::DeclRefExpr *expression) {
const auto *declaration = expression->getFoundDecl();
iterateNestedNameSpecifierLocation(expression->getQualifierLoc());
auto declarationUSR = USROfDeclaration(declaration);
if (containsUSR(declarationUSR))
foundLocations.push_back(expression->getLocation());
return true;
}
bool VisitMemberExpr(const clang::MemberExpr *expression) {
const auto *declaration = expression->getFoundDecl().getDecl();
auto declarationUSR = USROfDeclaration(declaration);
if (containsUSR(declarationUSR))
foundLocations.push_back(expression->getMemberLoc());
return true;
}
bool shouldVisitTemplateInstantiations() const
{
return true;
}
std::vector<clang::SourceLocation> takeFoundLocations() const {
return std::move(foundLocations);
}
private:
void iterateNestedNameSpecifierLocation(clang::NestedNameSpecifierLoc nameLocation) {
while (nameLocation) {
const auto *declaration = nameLocation.getNestedNameSpecifier()->getAsNamespace();
if (declaration && containsUSR(USROfDeclaration(declaration)))
foundLocations.push_back(nameLocation.getLocalBeginLoc());
nameLocation = nameLocation.getPrefix();
}
}
bool containsUSR(const USRName &unifiedSymbolResolution)
{
auto found = std::find(unifiedSymbolResolutions.cbegin(),
unifiedSymbolResolutions.cend(),
unifiedSymbolResolution);
return found != unifiedSymbolResolutions.cend();
}
private:
// All the locations of the USR were found.
const std::vector<USRName> unifiedSymbolResolutions;
std::vector<clang::SourceLocation> foundLocations;
};
inline
std::vector<clang::SourceLocation> takeLocationsOfUSRs(std::vector<USRName> &unifiedSymbolResolutions,
clang::Decl *declartation)
{
FindLocationsOfUSRsASTVisitor visitor(unifiedSymbolResolutions);
visitor.TraverseDecl(declartation);
return visitor.takeFoundLocations();
}
} // namespace ClangBackend

View File

@@ -1,128 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include "findusrforcursoraction.h"
#include "findcursorusr.h"
#include <clang/AST/AST.h>
#include <clang/AST/ASTConsumer.h>
#include <clang/AST/ASTContext.h>
#include <algorithm>
#include <vector>
namespace ClangBackEnd {
namespace {
std::vector<USRName> collectConstructorUnifiedSymbolResolutions(const clang::CXXRecordDecl *declarations)
{
std::vector<USRName> unifiedSymbolResolutions;
const auto constructorDeclarations = declarations->getDefinition()->ctors();
std::transform(constructorDeclarations.begin(),
constructorDeclarations.end(),
std::back_inserter(unifiedSymbolResolutions),
USROfDeclaration);
return unifiedSymbolResolutions;
}
void addUnifiedSymbolResolutionsForDeclaration(const std::vector<const clang::NamedDecl *> &declarations,
std::vector<USRName> &usrs)
{
std::transform(declarations.begin(),
declarations.end(),
std::back_inserter(usrs),
[&] (const clang::NamedDecl *declaration) {
return USROfDeclaration(declaration);
});
}
}
class FindDeclarationsConsumer : public clang::ASTConsumer
{
public:
FindDeclarationsConsumer(Utils::SmallString &symbolName,
std::vector<USRName> &unifiedSymbolResolutions,
uint line,
uint column)
: m_symbolName(symbolName),
m_unifiedSymbolResolutions(unifiedSymbolResolutions),
m_line(line),
m_column(column)
{
}
void HandleTranslationUnit(clang::ASTContext &astContext) override {
const auto &sourceManager = astContext.getSourceManager();
const auto cursorSourceLocation = sourceManager.translateLineCol(sourceManager.getMainFileID(),
m_line,
m_column);
if (cursorSourceLocation.isValid())
collectUnifiedSymbolResoltions(astContext, cursorSourceLocation);
}
void collectUnifiedSymbolResoltions(clang::ASTContext &astContext,
const clang::SourceLocation &cursorSourceLocation)
{
const auto foundDeclarations = namedDeclarationsAt(astContext, cursorSourceLocation);
if (!foundDeclarations.empty()) {
const auto firstFoundDeclaration = foundDeclarations.front();
if (const auto *constructorDecl = clang::dyn_cast<clang::CXXConstructorDecl>(firstFoundDeclaration)) {
const clang::CXXRecordDecl *foundDeclarationParent = constructorDecl->getParent();
m_unifiedSymbolResolutions = collectConstructorUnifiedSymbolResolutions(foundDeclarationParent);
} else if (const auto *destructorDecl = clang::dyn_cast<clang::CXXDestructorDecl>(firstFoundDeclaration)) {
const clang::CXXRecordDecl *foundDeclarationParent = destructorDecl->getParent();
m_unifiedSymbolResolutions = collectConstructorUnifiedSymbolResolutions(foundDeclarationParent);
} else if (const auto *recordDeclaration = clang::dyn_cast<clang::CXXRecordDecl>(firstFoundDeclaration)) {
m_unifiedSymbolResolutions = collectConstructorUnifiedSymbolResolutions(recordDeclaration);
}
addUnifiedSymbolResolutionsForDeclaration(foundDeclarations, m_unifiedSymbolResolutions);
m_symbolName = firstFoundDeclaration->getNameAsString();
}
}
private:
Utils::SmallString &m_symbolName;
std::vector<USRName> &m_unifiedSymbolResolutions;
uint m_line;
uint m_column;
};
std::unique_ptr<clang::ASTConsumer>
USRFindingAction::newASTConsumer() {
return std::make_unique<FindDeclarationsConsumer>(m_symbolName, m_unifiedSymbolResolutions, m_line, m_column);
}
} // namespace ClangBackEnd

View File

@@ -1,70 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include "clangrefactoringbackend_global.h"
#include <utils/smallstring.h>
#include <clang/Frontend/FrontendAction.h>
namespace clang {
class ASTConsumer;
class CompilerInstance;
class NamedDecl;
}
namespace ClangBackEnd {
class USRFindingAction
{
public:
USRFindingAction(uint line, uint column)
: m_line(line),
m_column(column)
{
}
std::unique_ptr<clang::ASTConsumer> newASTConsumer();
std::string takeSymbolName()
{
return std::string(m_symbolName);
}
std::vector<USRName> takeUnifiedSymbolResolutions()
{
return std::move(m_unifiedSymbolResolutions);
}
private:
Utils::SmallString m_symbolName;
std::vector<USRName> m_unifiedSymbolResolutions;
uint m_line;
uint m_column;
};
} // namespace ClangBackEnd

View File

@@ -25,7 +25,6 @@
#include "refactoringserver.h"
#include "symbolfinder.h"
#include "clangquery.h"
#include "symbolindexing.h"
@@ -58,21 +57,6 @@ void RefactoringServer::end()
QCoreApplication::exit();
}
void RefactoringServer::requestSourceLocationsForRenamingMessage(RequestSourceLocationsForRenamingMessage &&message)
{
SymbolFinder symbolFinder(message.line, message.column, m_filePathCache);
symbolFinder.addFile(std::move(message.filePath),
std::move(message.unsavedContent),
std::move(message.commandLine));
symbolFinder.findSymbol();
client()->sourceLocationsForRenamingMessage({symbolFinder.takeSymbolName(),
symbolFinder.takeSourceLocations(),
message.textDocumentRevision});
}
void RefactoringServer::requestSourceRangesAndDiagnosticsForQueryMessage(
RequestSourceRangesAndDiagnosticsForQueryMessage &&message)
{

View File

@@ -60,7 +60,6 @@ public:
GeneratedFiles &generatedFiles);
void end() override;
void requestSourceLocationsForRenamingMessage(RequestSourceLocationsForRenamingMessage &&message) override;
void requestSourceRangesAndDiagnosticsForQueryMessage(RequestSourceRangesAndDiagnosticsForQueryMessage &&message) override;
void requestSourceRangesForQueryMessage(RequestSourceRangesForQueryMessage &&message) override;
void updateProjectParts(UpdateProjectPartsMessage &&message) override;

View File

@@ -1,79 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include "symbolfinder.h"
#include "locationsourcefilecallbacks.h"
#include "symbollocationfinderaction.h"
namespace ClangBackEnd {
SymbolFinder::SymbolFinder(uint line, uint column, FilePathCachingInterface &filePathCache)
: m_usrFindingAction(line, column),
m_symbolLocationFinderAction(filePathCache),
m_sourceFileCallbacks(line, column, filePathCache)
{
}
void SymbolFinder::findSymbol()
{
clang::tooling::ClangTool tool = createTool();
tool.run(clang::tooling::newFrontendActionFactory(&m_usrFindingAction, &m_sourceFileCallbacks).get());
if (m_sourceFileCallbacks.hasSourceLocations()) {
m_sourceLocations_ = m_sourceFileCallbacks.takeSourceLocations();
m_symbolName = m_sourceFileCallbacks.takeSymbolName();
} else {
m_symbolLocationFinderAction.setUnifiedSymbolResolutions(m_usrFindingAction.takeUnifiedSymbolResolutions());
tool.run(clang::tooling::newFrontendActionFactory(&m_symbolLocationFinderAction).get());
m_sourceLocations_ = m_symbolLocationFinderAction.takeSourceLocations();
m_symbolName = m_usrFindingAction.takeSymbolName();
}
}
Utils::SmallString SymbolFinder::takeSymbolName()
{
return std::move(m_symbolName);
}
const std::vector<USRName> &SymbolFinder::unifiedSymbolResolutions()
{
return m_symbolLocationFinderAction.unifiedSymbolResolutions();
}
const SourceLocationsContainer &SymbolFinder::sourceLocations() const
{
return m_sourceLocations_;
}
SourceLocationsContainer SymbolFinder::takeSourceLocations()
{
return std::move(m_sourceLocations_);
}
} // namespace ClangBackEnd

View File

@@ -1,58 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include "clangtool.h"
#include "findusrforcursoraction.h"
#include "symbollocationfinderaction.h"
#include "locationsourcefilecallbacks.h"
#include <filepathcachingfwd.h>
#include <sourcelocationscontainer.h>
namespace ClangBackEnd {
class SymbolFinder : public ClangTool
{
public:
SymbolFinder(uint line, uint column, FilePathCachingInterface &filePathCache);
void findSymbol();
Utils::SmallString takeSymbolName();
const std::vector<USRName> &unifiedSymbolResolutions();
const SourceLocationsContainer &sourceLocations() const;
SourceLocationsContainer takeSourceLocations();
private:
Utils::SmallString m_symbolName;
USRFindingAction m_usrFindingAction;
SymbolLocationFinderAction m_symbolLocationFinderAction;
LocationSourceFileCallbacks m_sourceFileCallbacks;
ClangBackEnd::SourceLocationsContainer m_sourceLocations_;
};
} // namespace ClangBackEnd

View File

@@ -98,7 +98,7 @@ void SymbolIndexer::updateProjectPart(ProjectPartContainer &&projectPart)
std::vector<SymbolIndexerTask> symbolIndexerTask;
symbolIndexerTask.reserve(projectPart.sourcePathIds.size());
for (FilePathId sourcePathId : projectPart.sourcePathIds) {
SourceTimeStamps dependentTimeStamps = m_symbolStorage.fetchIncludedIndexingTimeStamps(
SourceTimeStamps dependentTimeStamps = m_buildDependencyStorage.fetchIncludedIndexingTimeStamps(
sourcePathId);
if (!m_modifiedTimeChecker.isUpToDate(dependentTimeStamps)) {
@@ -122,7 +122,8 @@ void SymbolIndexer::updateProjectPart(ProjectPartContainer &&projectPart)
auto store = [&] {
Sqlite::ImmediateTransaction transaction{m_transactionInterface};
m_symbolStorage.insertOrUpdateIndexingTimeStamps(symbolsCollector.fileStatuses());
m_buildDependencyStorage.insertOrUpdateIndexingTimeStamps(
symbolsCollector.fileStatuses());
m_symbolStorage.addSymbolsAndSourceLocations(symbolsCollector.symbols(),
symbolsCollector.sourceLocations());
transaction.commit();
@@ -144,28 +145,17 @@ void SymbolIndexer::updateProjectPart(ProjectPartContainer &&projectPart)
}
}
m_pathWatcher.updateIdPaths(
{{projectPartId, m_buildDependencyStorage.fetchPchSources(projectPartId)}});
m_pathWatcher.updateIdPaths({{{projectPartId, SourceType::Source},
m_buildDependencyStorage.fetchPchSources(projectPartId)}});
m_symbolIndexerTaskQueue.addOrUpdateTasks(std::move(symbolIndexerTask));
m_symbolIndexerTaskQueue.processEntries();
}
void SymbolIndexer::pathsWithIdsChanged(const ProjectPartIds &) {}
void SymbolIndexer::pathsWithIdsChanged(const std::vector<IdPaths> &) {}
void SymbolIndexer::pathsChanged(const FilePathIds &filePathIds)
{
m_modifiedTimeChecker.pathsChanged(filePathIds);
FilePathIds dependentSourcePathIds = m_symbolStorage.fetchDependentSourceIds(filePathIds);
std::vector<SymbolIndexerTask> symbolIndexerTask;
symbolIndexerTask.reserve(dependentSourcePathIds.size());
for (FilePathId dependentSourcePathId : dependentSourcePathIds)
updateChangedPath(dependentSourcePathId, symbolIndexerTask);
m_symbolIndexerTaskQueue.addOrUpdateTasks(std::move(symbolIndexerTask));
m_symbolIndexerTaskQueue.processEntries();
}
void SymbolIndexer::updateChangedPath(FilePathId filePathId,
@@ -182,7 +172,8 @@ void SymbolIndexer::updateChangedPath(FilePathId filePathId,
ProjectPartId projectPartId = optionalArtefact->projectPartId;
SourceTimeStamps dependentTimeStamps = m_symbolStorage.fetchIncludedIndexingTimeStamps(filePathId);
SourceTimeStamps dependentTimeStamps = m_buildDependencyStorage.fetchIncludedIndexingTimeStamps(
filePathId);
auto indexing = [optionalArtefact = std::move(optionalArtefact),
filePathId,
@@ -207,7 +198,7 @@ void SymbolIndexer::updateChangedPath(FilePathId filePathId,
auto store = [&] {
Sqlite::ImmediateTransaction transaction{m_transactionInterface};
m_symbolStorage.insertOrUpdateIndexingTimeStamps(symbolsCollector.fileStatuses());
m_buildDependencyStorage.insertOrUpdateIndexingTimeStamps(symbolsCollector.fileStatuses());
m_symbolStorage.addSymbolsAndSourceLocations(symbolsCollector.symbols(),
symbolsCollector.sourceLocations());
transaction.commit();

View File

@@ -60,7 +60,7 @@ public:
void updateProjectParts(ProjectPartContainers &&projectParts);
void updateProjectPart(ProjectPartContainer &&projectPart);
void pathsWithIdsChanged(const ProjectPartIds &ids) override;
void pathsWithIdsChanged(const std::vector<IdPaths> &idPaths) override;
void pathsChanged(const FilePathIds &filePathIds) override;
void updateChangedPath(FilePathId filePath,
std::vector<SymbolIndexerTask> &symbolIndexerTask);
@@ -75,6 +75,9 @@ public:
FilePathIds updatableFilePathIds(const ProjectPartContainer &projectPart,
const Utils::optional<ProjectPartArtefact> &optionalArtefact) const;
private:
FilePathIds filterProjectPartSources(const FilePathIds &filePathIds) const;
private:
SymbolIndexerTaskQueueInterface &m_symbolIndexerTaskQueue;
SymbolStorageInterface &m_symbolStorage;

View File

@@ -1,99 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include "symbollocationfinderaction.h"
#include "sourcelocationsutils.h"
#include "findlocationsofusrs.h"
#include <filepathcachingfwd.h>
#include <clang/AST/ASTConsumer.h>
#include <clang/AST/ASTContext.h>
#include <memory>
namespace ClangBackEnd {
class FindingSymbolsASTConsumer : public clang::ASTConsumer
{
public:
FindingSymbolsASTConsumer(std::vector<USRName> &unifiedSymbolResolutions,
FilePathCachingInterface &filePathCache)
: m_unifiedSymbolResolutions(unifiedSymbolResolutions),
m_filePathCache(filePathCache)
{
}
void HandleTranslationUnit(clang::ASTContext &context) override
{
std::vector<clang::SourceLocation> sourceLocations;
auto &&sourceLocationsOfUsr = takeLocationsOfUSRs(m_unifiedSymbolResolutions, context.getTranslationUnitDecl());
sourceLocations.insert(sourceLocations.end(),
sourceLocationsOfUsr.begin(),
sourceLocationsOfUsr.end());
std::sort(sourceLocations.begin(), sourceLocations.end());
auto newEnd = std::unique(sourceLocations.begin(), sourceLocations.end());
sourceLocations.erase(newEnd, sourceLocations.end());
updateSourceLocations(sourceLocations, context.getSourceManager());
}
void updateSourceLocations(const std::vector<clang::SourceLocation> &sourceLocations,
const clang::SourceManager &sourceManager)
{
appendSourceLocationsToSourceLocationsContainer(*m_sourceLocationsContainer,
sourceLocations,
sourceManager,
m_filePathCache);
}
void setSourceLocations(ClangBackEnd::SourceLocationsContainer *sourceLocations)
{
m_sourceLocationsContainer = sourceLocations;
}
private:
ClangBackEnd::SourceLocationsContainer *m_sourceLocationsContainer = nullptr;
std::vector<USRName> &m_unifiedSymbolResolutions;
FilePathCachingInterface &m_filePathCache;
};
std::unique_ptr<clang::ASTConsumer> SymbolLocationFinderAction::newASTConsumer()
{
auto consumer = std::make_unique<FindingSymbolsASTConsumer>(m_unifiedSymbolResolutions_,
m_filePathCache);
consumer->setSourceLocations(&m_sourceLocations);
return consumer;
}
} // namespace ClangBackEnd

View File

@@ -1,71 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include "clangrefactoringbackend_global.h"
#include <filepathcachingfwd.h>
#include <sourcelocationscontainer.h>
#include <clang/Tooling/Refactoring.h>
namespace clang {
class ASTConsumer;
}
namespace ClangBackEnd {
class SymbolLocationFinderAction
{
public:
SymbolLocationFinderAction(FilePathCachingInterface &filePathCache)
: m_filePathCache(filePathCache)
{}
std::unique_ptr<clang::ASTConsumer> newASTConsumer();
SourceLocationsContainer takeSourceLocations()
{
return std::move(m_sourceLocations);
}
void setUnifiedSymbolResolutions(std::vector<USRName> &&unifiedSymbolResolutions)
{
m_unifiedSymbolResolutions_ = std::move(unifiedSymbolResolutions);
}
const std::vector<USRName> &unifiedSymbolResolutions() const
{
return m_unifiedSymbolResolutions_;
}
private:
ClangBackEnd::SourceLocationsContainer m_sourceLocations;
std::vector<USRName> m_unifiedSymbolResolutions_;
FilePathCachingInterface &m_filePathCache;
};
} // namespace ClangBackEnd

View File

@@ -70,93 +70,6 @@ public:
deleteNewLocationsTable();
}
void insertOrUpdateIndexingTimeStamps(const FilePathIds &filePathIds, TimeStamp indexingTimeStamp) override
{
try {
Sqlite::ImmediateTransaction transaction{database};
for (FilePathId filePathId : filePathIds) {
inserOrUpdateIndexingTimesStampStatement.write(filePathId.filePathId,
indexingTimeStamp.value);
}
transaction.commit();
} catch (const Sqlite::StatementIsBusy &) {
insertOrUpdateIndexingTimeStamps(filePathIds, indexingTimeStamp);
}
}
void insertOrUpdateIndexingTimeStamps(const FileStatuses &fileStatuses) override
{
for (FileStatus fileStatus : fileStatuses) {
inserOrUpdateIndexingTimesStampStatement.write(fileStatus.filePathId.filePathId,
fileStatus.lastModified);
}
}
SourceTimeStamps fetchIndexingTimeStamps() const override
{
try {
Sqlite::DeferredTransaction transaction{database};
auto timeStamps = fetchIndexingTimeStampsStatement.template values<SourceTimeStamp, 2>(
1024);
transaction.commit();
return timeStamps;
} catch (const Sqlite::StatementIsBusy &) {
return fetchIndexingTimeStamps();
}
}
SourceTimeStamps fetchIncludedIndexingTimeStamps(FilePathId sourcePathId) const override
{
try {
Sqlite::DeferredTransaction transaction{database};
auto timeStamps = fetchIncludedIndexingTimeStampsStatement
.template values<SourceTimeStamp, 2>(1024, sourcePathId.filePathId);
transaction.commit();
return timeStamps;
} catch (const Sqlite::StatementIsBusy &) {
return fetchIncludedIndexingTimeStamps(sourcePathId);
}
}
FilePathIds fetchDependentSourceIds(const FilePathIds &sourcePathIds) const override
{
try {
FilePathIds dependentSourceIds;
Sqlite::DeferredTransaction transaction{database};
for (FilePathId sourcePathId : sourcePathIds) {
FilePathIds newDependentSourceIds;
newDependentSourceIds.reserve(dependentSourceIds.size() + 1024);
auto newIds = fetchDependentSourceIdsStatement
.template values<FilePathId>(1024, sourcePathId.filePathId);
std::set_union(dependentSourceIds.begin(),
dependentSourceIds.end(),
newIds.begin(),
newIds.end(),
std::back_inserter(newDependentSourceIds));
dependentSourceIds = std::move(newDependentSourceIds);
}
transaction.commit();
return dependentSourceIds;
} catch (const Sqlite::StatementIsBusy &) {
return fetchDependentSourceIds(sourcePathIds);
}
}
void fillTemporarySymbolsTable(const SymbolEntries &symbolEntries)
{
WriteStatement &statement = insertSymbolsToNewSymbolsStatement;
@@ -278,25 +191,6 @@ public:
database};
WriteStatement deleteNewSymbolsTableStatement{"DELETE FROM newSymbols", database};
WriteStatement deleteNewLocationsTableStatement{"DELETE FROM newLocations", database};
WriteStatement inserOrUpdateIndexingTimesStampStatement{
"INSERT INTO fileStatuses(sourceId, indexingTimeStamp) VALUES (?001, ?002) ON "
"CONFLICT(sourceId) DO UPDATE SET indexingTimeStamp = ?002",
database};
mutable ReadStatement fetchIncludedIndexingTimeStampsStatement{
"WITH RECURSIVE collectedDependencies(sourceId) AS (VALUES(?) UNION SELECT "
"dependencySourceId FROM sourceDependencies, collectedDependencies WHERE "
"sourceDependencies.sourceId == collectedDependencies.sourceId) SELECT DISTINCT sourceId, "
"indexingTimeStamp FROM collectedDependencies NATURAL JOIN fileStatuses ORDER BY sourceId",
database};
mutable ReadStatement fetchIndexingTimeStampsStatement{
"SELECT sourceId, indexingTimeStamp FROM fileStatuses", database};
mutable ReadStatement fetchDependentSourceIdsStatement{
"WITH RECURSIVE collectedDependencies(sourceId) AS (VALUES(?) UNION SELECT "
"sourceDependencies.sourceId FROM sourceDependencies, collectedDependencies WHERE "
"sourceDependencies.dependencySourceId == collectedDependencies.sourceId) SELECT sourceId "
"FROM collectedDependencies WHERE sourceId NOT IN (SELECT dependencySourceId FROM "
"sourceDependencies) ORDER BY sourceId",
database};
};
} // namespace ClangBackEnd

View File

@@ -48,11 +48,6 @@ public:
virtual void addSymbolsAndSourceLocations(const SymbolEntries &symbolEntries,
const SourceLocationEntries &sourceLocations)
= 0;
virtual void insertOrUpdateIndexingTimeStamps(const FilePathIds &filePathIds, TimeStamp indexingTimeStamp) = 0;
virtual void insertOrUpdateIndexingTimeStamps(const FileStatuses &fileStatuses) = 0;
virtual SourceTimeStamps fetchIndexingTimeStamps() const = 0;
virtual SourceTimeStamps fetchIncludedIndexingTimeStamps(FilePathId sourcePathId) const = 0;
virtual FilePathIds fetchDependentSourceIds(const FilePathIds &sourcePathIds) const = 0;
protected:
~SymbolStorageInterface() = default;