forked from qt-creator/qt-creator
Clang: Collect source files
Change-Id: If0183cafd00ed7e42bacbdb72a1d65624dc03cee Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
@@ -31,55 +31,8 @@ QtcTool {
|
||||
Group {
|
||||
prefix: "source/"
|
||||
files: [
|
||||
"clangquery.cpp",
|
||||
"clangquerygatherer.cpp",
|
||||
"clangquerygatherer.h",
|
||||
"clangquery.h",
|
||||
"clangrefactoringbackend_global.h",
|
||||
"clangtool.cpp",
|
||||
"clangtool.h",
|
||||
"collectmacrossourcefilecallbacks.cpp",
|
||||
"collectmacrossourcefilecallbacks.h",
|
||||
"collectsymbolsaction.cpp",
|
||||
"collectsymbolsaction.h",
|
||||
"collectsymbolsastvisitor.h",
|
||||
"collectsymbolsconsumer.h",
|
||||
"findcursorusr.h",
|
||||
"findlocationsofusrs.h",
|
||||
"findusrforcursoraction.cpp",
|
||||
"findusrforcursoraction.h",
|
||||
"locationsourcefilecallbacks.cpp",
|
||||
"locationsourcefilecallbacks.h",
|
||||
"macropreprocessorcallbacks.cpp",
|
||||
"macropreprocessorcallbacks.h",
|
||||
"refactoringcompilationdatabase.cpp",
|
||||
"refactoringcompilationdatabase.h",
|
||||
"refactoringserver.cpp",
|
||||
"refactoringserver.h",
|
||||
"sourcelocationentry.h",
|
||||
"sourcelocationsutils.h",
|
||||
"sourcerangeextractor.cpp",
|
||||
"sourcerangeextractor.h",
|
||||
"sourcerangefilter.cpp",
|
||||
"sourcerangefilter.h",
|
||||
"storagesqlitestatementfactory.h",
|
||||
"symbolentry.cpp",
|
||||
"symbolentry.h",
|
||||
"symbolfinder.cpp",
|
||||
"symbolfinder.h",
|
||||
"symbolindexer.cpp",
|
||||
"symbolindexer.h",
|
||||
"symbolindexing.cpp",
|
||||
"symbolindexing.h",
|
||||
"symbolindexinginterface.h",
|
||||
"symbollocationfinderaction.cpp",
|
||||
"symbollocationfinderaction.h",
|
||||
"symbolscollector.cpp",
|
||||
"symbolscollector.h",
|
||||
"symbolscollectorinterface.h",
|
||||
"symbolstorage.cpp",
|
||||
"symbolstorage.h",
|
||||
"symbolstorageinterface.h",
|
||||
"*.cpp",
|
||||
"*.h",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,8 @@ HEADERS += \
|
||||
$$PWD/symbolstorage.h \
|
||||
$$PWD/storagesqlitestatementfactory.h \
|
||||
$$PWD/symbolindexing.h \
|
||||
$$PWD/symbolindexinginterface.h
|
||||
$$PWD/symbolindexinginterface.h \
|
||||
$$PWD/collectmacrospreprocessorcallbacks.h
|
||||
|
||||
!isEmpty(LIBTOOLING_LIBS) {
|
||||
SOURCES += \
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2017 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 "sourcelocationsutils.h"
|
||||
|
||||
#include <filepath.h>
|
||||
#include <filepathid.h>
|
||||
|
||||
#include <clang/Lex/MacroInfo.h>
|
||||
#include <clang/Lex/PPCallbacks.h>
|
||||
#include <clang/Lex/Preprocessor.h>
|
||||
|
||||
namespace ClangBackEnd {
|
||||
|
||||
class CollectMacrosPreprocessorCallbacks final : public clang::PPCallbacks
|
||||
{
|
||||
public:
|
||||
CollectMacrosPreprocessorCallbacks(FilePathIds &sourceFiles,
|
||||
FilePathCachingInterface &filePathCache)
|
||||
: m_sourceFiles(sourceFiles),
|
||||
m_filePathCache(filePathCache)
|
||||
|
||||
{
|
||||
}
|
||||
|
||||
void InclusionDirective(clang::SourceLocation /*hashLocation*/,
|
||||
const clang::Token &/*includeToken*/,
|
||||
llvm::StringRef /*fileName*/,
|
||||
bool /*isAngled*/,
|
||||
clang::CharSourceRange /*fileNameRange*/,
|
||||
const clang::FileEntry *file,
|
||||
llvm::StringRef /*searchPath*/,
|
||||
llvm::StringRef /*relativePath*/,
|
||||
const clang::Module * /*imported*/) override
|
||||
{
|
||||
if (!m_skipInclude && file)
|
||||
addSourceFile(file);
|
||||
|
||||
m_skipInclude = false;
|
||||
}
|
||||
|
||||
bool FileNotFound(clang::StringRef /*fileNameRef*/, clang::SmallVectorImpl<char> &/*recoveryPath*/) override
|
||||
{
|
||||
m_skipInclude = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void addSourceFile(const clang::FileEntry *file)
|
||||
{
|
||||
auto filePathId = m_filePathCache.filePathId(
|
||||
FilePath::fromNativeFilePath(absolutePath(file->getName())));
|
||||
|
||||
auto found = std::find(m_sourceFiles.begin(), m_sourceFiles.end(), filePathId);
|
||||
|
||||
if (found == m_sourceFiles.end() || *found != filePathId)
|
||||
m_sourceFiles.insert(found, filePathId);
|
||||
}
|
||||
|
||||
private:
|
||||
FilePathIds &m_sourceFiles;
|
||||
FilePathCachingInterface &m_filePathCache;
|
||||
bool m_skipInclude = false;
|
||||
};
|
||||
|
||||
} // namespace ClangBackEnd
|
||||
@@ -24,12 +24,21 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "collectmacrossourcefilecallbacks.h"
|
||||
#include "collectmacrospreprocessorcallbacks.h"
|
||||
|
||||
#include <clang/Frontend/CompilerInstance.h>
|
||||
|
||||
|
||||
namespace ClangBackEnd {
|
||||
|
||||
CollectMacrosSourceFileCallbacks::CollectMacrosSourceFileCallbacks()
|
||||
bool CollectMacrosSourceFileCallbacks::handleBeginSource(clang::CompilerInstance &compilerInstance)
|
||||
{
|
||||
auto callbacks = std::make_unique<CollectMacrosPreprocessorCallbacks>(m_sourceFiles,
|
||||
m_filePathCache);
|
||||
|
||||
compilerInstance.getPreprocessorPtr()->addPPCallbacks(std::move(callbacks));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace ClangBackEnd
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <filepathcachinginterface.h>
|
||||
|
||||
#include <clang/Tooling/Tooling.h>
|
||||
|
||||
namespace ClangBackEnd {
|
||||
@@ -32,7 +34,31 @@ namespace ClangBackEnd {
|
||||
class CollectMacrosSourceFileCallbacks : public clang::tooling::SourceFileCallbacks
|
||||
{
|
||||
public:
|
||||
CollectMacrosSourceFileCallbacks();
|
||||
CollectMacrosSourceFileCallbacks(FilePathCachingInterface &filePathCache)
|
||||
: m_filePathCache(filePathCache)
|
||||
{
|
||||
}
|
||||
|
||||
bool handleBeginSource(clang::CompilerInstance &compilerInstance) override;
|
||||
|
||||
const FilePathIds &sourceFiles() const
|
||||
{
|
||||
return m_sourceFiles;
|
||||
}
|
||||
|
||||
void addSourceFiles(const Utils::PathStringVector &filePaths)
|
||||
{
|
||||
std::transform(filePaths.begin(),
|
||||
filePaths.end(),
|
||||
std::back_inserter(m_sourceFiles),
|
||||
[&] (const Utils::PathString &filePath) {
|
||||
return m_filePathCache.filePathId(FilePathView{filePath});
|
||||
});
|
||||
}
|
||||
|
||||
private:
|
||||
FilePathIds m_sourceFiles;
|
||||
FilePathCachingInterface &m_filePathCache;
|
||||
};
|
||||
|
||||
} // namespace ClangBackEnd
|
||||
|
||||
@@ -27,9 +27,12 @@
|
||||
|
||||
namespace ClangBackEnd {
|
||||
|
||||
SymbolIndexer::SymbolIndexer(SymbolsCollectorInterface &symbolsCollector, SymbolStorageInterface &symbolStorage)
|
||||
SymbolIndexer::SymbolIndexer(SymbolsCollectorInterface &symbolsCollector,
|
||||
SymbolStorageInterface &symbolStorage,
|
||||
ClangPathWatcherInterface &pathWatcher)
|
||||
: m_symbolsCollector(symbolsCollector),
|
||||
m_symbolStorage(symbolStorage)
|
||||
m_symbolStorage(symbolStorage),
|
||||
m_pathWatcher(pathWatcher)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
|
||||
#include "symbolscollectorinterface.h"
|
||||
#include "symbolstorageinterface.h"
|
||||
#include "clangpathwatcher.h"
|
||||
|
||||
#include <projectpartcontainerv2.h>
|
||||
#include <filecontainerv2.h>
|
||||
@@ -37,7 +38,8 @@ class SymbolIndexer
|
||||
{
|
||||
public:
|
||||
SymbolIndexer(SymbolsCollectorInterface &symbolsCollector,
|
||||
SymbolStorageInterface &symbolStorage);
|
||||
SymbolStorageInterface &symbolStorage,
|
||||
ClangPathWatcherInterface &pathWatcher);
|
||||
|
||||
void updateProjectParts(V2::ProjectPartContainers &&projectParts,
|
||||
V2::FileContainers &&generatedFiles);
|
||||
@@ -45,6 +47,7 @@ public:
|
||||
private:
|
||||
SymbolsCollectorInterface &m_symbolsCollector;
|
||||
SymbolStorageInterface &m_symbolStorage;
|
||||
ClangPathWatcherInterface &m_pathWatcher;
|
||||
};
|
||||
|
||||
} // namespace ClangBackEnd
|
||||
|
||||
@@ -39,6 +39,8 @@
|
||||
#include <sqlitereadstatement.h>
|
||||
#include <sqlitewritestatement.h>
|
||||
|
||||
#include <QFileSystemWatcher>
|
||||
|
||||
namespace ClangBackEnd {
|
||||
|
||||
class SymbolIndexing final : public SymbolIndexingInterface
|
||||
@@ -72,7 +74,8 @@ private:
|
||||
SymbolsCollector m_collector{m_filePathCache};
|
||||
StatementFactory m_statementFactory;
|
||||
Storage m_symbolStorage{m_statementFactory, m_filePathCache};
|
||||
SymbolIndexer m_indexer{m_collector, m_symbolStorage};
|
||||
ClangPathWatcher<QFileSystemWatcher, QTimer> m_sourceWatcher{m_filePathCache};
|
||||
SymbolIndexer m_indexer{m_collector, m_symbolStorage, m_sourceWatcher};
|
||||
};
|
||||
|
||||
} // namespace ClangBackEnd
|
||||
|
||||
@@ -28,13 +28,15 @@
|
||||
namespace ClangBackEnd {
|
||||
|
||||
SymbolsCollector::SymbolsCollector(FilePathCachingInterface &filePathCache)
|
||||
: m_collectSymbolsAction(filePathCache)
|
||||
: m_collectSymbolsAction(filePathCache),
|
||||
m_collectMacrosSourceFileCallbacks(filePathCache)
|
||||
{
|
||||
}
|
||||
|
||||
void SymbolsCollector::addFiles(const Utils::PathStringVector &filePaths, const Utils::SmallStringVector &arguments)
|
||||
{
|
||||
ClangTool::addFiles(filePaths, arguments);
|
||||
m_collectMacrosSourceFileCallbacks.addSourceFiles(filePaths);
|
||||
}
|
||||
|
||||
void SymbolsCollector::addUnsavedFiles(const V2::FileContainers &unsavedFiles)
|
||||
@@ -60,4 +62,9 @@ const SourceLocationEntries &SymbolsCollector::sourceLocations() const
|
||||
return m_collectSymbolsAction.sourceLocations();
|
||||
}
|
||||
|
||||
const FilePathIds &SymbolsCollector::sourceFiles() const
|
||||
{
|
||||
return m_collectMacrosSourceFileCallbacks.sourceFiles();
|
||||
}
|
||||
|
||||
} // namespace ClangBackEnd
|
||||
|
||||
@@ -49,6 +49,7 @@ public:
|
||||
|
||||
const SymbolEntries &symbols() const override;
|
||||
const SourceLocationEntries &sourceLocations() const override;
|
||||
const FilePathIds &sourceFiles() const override;
|
||||
|
||||
private:
|
||||
CollectSymbolsAction m_collectSymbolsAction;
|
||||
|
||||
@@ -49,6 +49,7 @@ public:
|
||||
|
||||
virtual const SymbolEntries &symbols() const = 0;
|
||||
virtual const SourceLocationEntries &sourceLocations() const = 0;
|
||||
virtual const FilePathIds &sourceFiles() const = 0;
|
||||
};
|
||||
|
||||
} // namespace ClangBackEnd
|
||||
|
||||
Reference in New Issue
Block a user