forked from qt-creator/qt-creator
Clang: Remove old code
We maybe bring back the clang query interface but the local rename is better served by other plugins. Change-Id: I97bedcb20870632b7dd50977794a65b2b09ededb Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -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 \
|
||||
|
||||
@@ -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 ¤tDeclation : 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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user