[include-fixer] Rename XrefsDB to SymbolIndex.
It's not really containing xrefs so the name didn't fit. No functional change. llvm-svn: 269403
This commit is contained in:
parent
1d48e50159
commit
a3d823336a
|
@ -18,7 +18,7 @@ generated with existing tools.
|
|||
|
||||
- Compilation database. Contains the compiler commands for any given file in a
|
||||
project and can be generated by CMake, see `How To Setup Tooling For LLVM`_.
|
||||
- Xrefs database. Contains all symbol information in a project to match a given
|
||||
- Symbol index. Contains all symbol information in a project to match a given
|
||||
identifier to a header file.
|
||||
|
||||
Ideally both databases (``compile_commands.json`` and
|
||||
|
@ -30,7 +30,7 @@ so only implementation files can be handled by tools.
|
|||
|
||||
.. _How To Setup Tooling For LLVM: http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html
|
||||
|
||||
Creating an Xrefs Database From a Compilation Database
|
||||
Creating a Symbol Index From a Compilation Database
|
||||
------------------------------------------------------
|
||||
|
||||
The include fixer contains :program:`find-all-symbols`, a tool to create a
|
||||
|
|
|
@ -4,9 +4,9 @@ set(LLVM_LINK_COMPONENTS
|
|||
|
||||
add_clang_library(clangIncludeFixer
|
||||
IncludeFixer.cpp
|
||||
InMemoryXrefsDB.cpp
|
||||
XrefsDBManager.cpp
|
||||
YamlXrefsDB.cpp
|
||||
InMemorySymbolIndex.cpp
|
||||
SymbolIndexManager.cpp
|
||||
YamlSymbolIndex.cpp
|
||||
|
||||
LINK_LIBS
|
||||
clangAST
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
//===-- InMemoryXrefsDB.cpp -----------------------------------------------===//
|
||||
//===-- InMemorySymbolIndex.cpp--------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
|
@ -7,14 +7,14 @@
|
|||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "InMemoryXrefsDB.h"
|
||||
#include "InMemorySymbolIndex.h"
|
||||
|
||||
using clang::find_all_symbols::SymbolInfo;
|
||||
|
||||
namespace clang {
|
||||
namespace include_fixer {
|
||||
|
||||
InMemoryXrefsDB::InMemoryXrefsDB(
|
||||
InMemorySymbolIndex::InMemorySymbolIndex(
|
||||
const std::map<std::string, std::vector<std::string>> &LookupTable) {
|
||||
for (const auto &Entry : LookupTable) {
|
||||
llvm::StringRef Identifier(Entry.first);
|
||||
|
@ -35,7 +35,8 @@ InMemoryXrefsDB::InMemoryXrefsDB(
|
|||
}
|
||||
}
|
||||
|
||||
std::vector<SymbolInfo> InMemoryXrefsDB::search(llvm::StringRef Identifier) {
|
||||
std::vector<SymbolInfo>
|
||||
InMemorySymbolIndex::search(llvm::StringRef Identifier) {
|
||||
auto I = LookupTable.find(Identifier);
|
||||
if (I != LookupTable.end())
|
||||
return I->second;
|
|
@ -1,4 +1,4 @@
|
|||
//===-- InMemoryXrefsDB.h ---------------------------------------*- C++ -*-===//
|
||||
//===-- InMemorySymbolIndex.h -----------------------------------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
|
@ -7,10 +7,10 @@
|
|||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
#ifndef LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_INMEMORYXREFSDB_H
|
||||
#define LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_INMEMORYXREFSDB_H
|
||||
#ifndef LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_INMEMORYSYMBOLINDEX_H
|
||||
#define LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_INMEMORYSYMBOLINDEX_H
|
||||
|
||||
#include "XrefsDB.h"
|
||||
#include "SymbolIndex.h"
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
@ -19,9 +19,9 @@ namespace clang {
|
|||
namespace include_fixer {
|
||||
|
||||
/// Xref database with fixed content.
|
||||
class InMemoryXrefsDB : public XrefsDB {
|
||||
class InMemorySymbolIndex : public SymbolIndex {
|
||||
public:
|
||||
InMemoryXrefsDB(
|
||||
InMemorySymbolIndex(
|
||||
const std::map<std::string, std::vector<std::string>> &LookupTable);
|
||||
|
||||
std::vector<clang::find_all_symbols::SymbolInfo>
|
||||
|
@ -35,4 +35,4 @@ private:
|
|||
} // namespace include_fixer
|
||||
} // namespace clang
|
||||
|
||||
#endif // LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_INMEMORYXREFSDB_H
|
||||
#endif // LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_INMEMORYSYMBOLINDEX_H
|
|
@ -58,8 +58,9 @@ private:
|
|||
class Action : public clang::ASTFrontendAction,
|
||||
public clang::ExternalSemaSource {
|
||||
public:
|
||||
explicit Action(XrefsDBManager &XrefsDBMgr, bool MinimizeIncludePaths)
|
||||
: XrefsDBMgr(XrefsDBMgr), MinimizeIncludePaths(MinimizeIncludePaths) {}
|
||||
explicit Action(SymbolIndexManager &SymbolIndexMgr, bool MinimizeIncludePaths)
|
||||
: SymbolIndexMgr(SymbolIndexMgr),
|
||||
MinimizeIncludePaths(MinimizeIncludePaths) {}
|
||||
|
||||
std::unique_ptr<clang::ASTConsumer>
|
||||
CreateASTConsumer(clang::CompilerInstance &Compiler,
|
||||
|
@ -246,7 +247,7 @@ private:
|
|||
DEBUG(llvm::dbgs() << " ...");
|
||||
|
||||
std::string error_text;
|
||||
auto SearchReply = XrefsDBMgr.search(Query);
|
||||
auto SearchReply = SymbolIndexMgr.search(Query);
|
||||
DEBUG(llvm::dbgs() << SearchReply.size() << " replies\n");
|
||||
if (SearchReply.empty())
|
||||
return clang::TypoCorrection();
|
||||
|
@ -262,7 +263,7 @@ private:
|
|||
}
|
||||
|
||||
/// The client to use to find cross-references.
|
||||
XrefsDBManager &XrefsDBMgr;
|
||||
SymbolIndexManager &SymbolIndexMgr;
|
||||
|
||||
// Remeber things we looked up to avoid querying things twice.
|
||||
llvm::StringSet<> SeenQueries;
|
||||
|
@ -328,10 +329,10 @@ void PreprocessorHooks::InclusionDirective(
|
|||
} // namespace
|
||||
|
||||
IncludeFixerActionFactory::IncludeFixerActionFactory(
|
||||
XrefsDBManager &XrefsDBMgr,
|
||||
SymbolIndexManager &SymbolIndexMgr,
|
||||
std::vector<clang::tooling::Replacement> &Replacements,
|
||||
bool MinimizeIncludePaths)
|
||||
: XrefsDBMgr(XrefsDBMgr), Replacements(Replacements),
|
||||
: SymbolIndexMgr(SymbolIndexMgr), Replacements(Replacements),
|
||||
MinimizeIncludePaths(MinimizeIncludePaths) {}
|
||||
|
||||
IncludeFixerActionFactory::~IncludeFixerActionFactory() = default;
|
||||
|
@ -355,7 +356,7 @@ bool IncludeFixerActionFactory::runInvocation(
|
|||
|
||||
// Run the parser, gather missing includes.
|
||||
auto ScopedToolAction =
|
||||
llvm::make_unique<Action>(XrefsDBMgr, MinimizeIncludePaths);
|
||||
llvm::make_unique<Action>(SymbolIndexMgr, MinimizeIncludePaths);
|
||||
Compiler.ExecuteAction(*ScopedToolAction);
|
||||
|
||||
// Generate replacements.
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#ifndef LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_INCLUDEFIXER_H
|
||||
#define LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_INCLUDEFIXER_H
|
||||
|
||||
#include "XrefsDBManager.h"
|
||||
#include "SymbolIndexManager.h"
|
||||
#include "clang/Tooling/Core/Replacement.h"
|
||||
#include "clang/Tooling/Tooling.h"
|
||||
#include <memory>
|
||||
|
@ -27,11 +27,11 @@ namespace include_fixer {
|
|||
|
||||
class IncludeFixerActionFactory : public clang::tooling::ToolAction {
|
||||
public:
|
||||
/// \param XrefsDBMgr A source for matching symbols to header files.
|
||||
/// \param SymbolIndexMgr A source for matching symbols to header files.
|
||||
/// \param Replacements Storage for the output of the fixer.
|
||||
/// \param MinimizeIncludePaths whether inserted include paths are optimized.
|
||||
IncludeFixerActionFactory(
|
||||
XrefsDBManager &XrefsDBMgr,
|
||||
SymbolIndexManager &SymbolIndexMgr,
|
||||
std::vector<clang::tooling::Replacement> &Replacements,
|
||||
bool MinimizeIncludePaths = true);
|
||||
~IncludeFixerActionFactory() override;
|
||||
|
@ -44,7 +44,7 @@ public:
|
|||
|
||||
private:
|
||||
/// The client to use to find cross-references.
|
||||
XrefsDBManager &XrefsDBMgr;
|
||||
SymbolIndexManager &SymbolIndexMgr;
|
||||
|
||||
/// Replacements are written here.
|
||||
std::vector<clang::tooling::Replacement> &Replacements;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
//===-- XrefsDB.h - Interface for symbol-header matching --------*- C++ -*-===//
|
||||
//===-- SymbolIndex.h - Interface for symbol-header matching ----*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
|
@ -7,8 +7,8 @@
|
|||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_XREFSDB_H
|
||||
#define LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_XREFSDB_H
|
||||
#ifndef LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_SYMBOLINDEX_H
|
||||
#define LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_SYMBOLINDEX_H
|
||||
|
||||
#include "find-all-symbols/SymbolInfo.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
|
@ -19,9 +19,9 @@ namespace include_fixer {
|
|||
|
||||
/// This class provides an interface for finding all `SymbolInfo`s corresponding
|
||||
/// to a symbol name from a symbol database.
|
||||
class XrefsDB {
|
||||
class SymbolIndex {
|
||||
public:
|
||||
virtual ~XrefsDB() = default;
|
||||
virtual ~SymbolIndex() = default;
|
||||
|
||||
/// Search for all `SymbolInfo`s corresponding to an identifier.
|
||||
/// \param Identifier The unqualified identifier being searched for.
|
||||
|
@ -35,4 +35,4 @@ public:
|
|||
} // namespace include_fixer
|
||||
} // namespace clang
|
||||
|
||||
#endif // LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_XREFSDB_H
|
||||
#endif // LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_SYMBOLINDEX_H
|
|
@ -1,4 +1,4 @@
|
|||
//===-- XrefsDBManager.cpp - Managing multiple XrefsDBs ---------*- C++ -*-===//
|
||||
//===-- SymbolIndexManager.cpp - Managing multiple SymbolIndices-*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
|
@ -7,7 +7,7 @@
|
|||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "XrefsDBManager.h"
|
||||
#include "SymbolIndexManager.h"
|
||||
#include "find-all-symbols/SymbolInfo.h"
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
#include "llvm/Support/Debug.h"
|
||||
|
@ -18,14 +18,14 @@ namespace clang {
|
|||
namespace include_fixer {
|
||||
|
||||
std::vector<std::string>
|
||||
XrefsDBManager::search(llvm::StringRef Identifier) const {
|
||||
SymbolIndexManager::search(llvm::StringRef Identifier) const {
|
||||
// The identifier may be fully qualified, so split it and get all the context
|
||||
// names.
|
||||
llvm::SmallVector<llvm::StringRef, 8> Names;
|
||||
Identifier.split(Names, "::");
|
||||
|
||||
std::vector<clang::find_all_symbols::SymbolInfo> Symbols;
|
||||
for (const auto &DB : XrefsDBs) {
|
||||
for (const auto &DB : SymbolIndices) {
|
||||
auto Res = DB->search(Names.back().str());
|
||||
Symbols.insert(Symbols.end(), Res.begin(), Res.end());
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
//===-- XrefsDBManager.h - Managing multiple XrefsDBs -----------*- C++ -*-===//
|
||||
//===-- SymbolIndexManager.h - Managing multiple SymbolIndices --*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
|
@ -7,10 +7,10 @@
|
|||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_XREFSDBMANAGER_H
|
||||
#define LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_XREFSDBMANAGER_H
|
||||
#ifndef LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_SYMBOLINDEXMANAGER_H
|
||||
#define LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_SYMBOLINDEXMANAGER_H
|
||||
|
||||
#include "XrefsDB.h"
|
||||
#include "SymbolIndex.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
|
||||
namespace clang {
|
||||
|
@ -18,10 +18,10 @@ namespace include_fixer {
|
|||
|
||||
/// This class provides an interface for finding the header files corresponding
|
||||
/// to an indentifier in the source code from multiple symbol databases.
|
||||
class XrefsDBManager {
|
||||
class SymbolIndexManager {
|
||||
public:
|
||||
void addXrefsDB(std::unique_ptr<XrefsDB> DB) {
|
||||
XrefsDBs.push_back(std::move(DB));
|
||||
void addSymbolIndex(std::unique_ptr<SymbolIndex> DB) {
|
||||
SymbolIndices.push_back(std::move(DB));
|
||||
}
|
||||
|
||||
/// Search for header files to be included for an identifier.
|
||||
|
@ -32,11 +32,11 @@ public:
|
|||
// FIXME: Expose the type name so we can also insert using declarations (or
|
||||
// fix the usage)
|
||||
// FIXME: Move mapping from SymbolInfo to headers out of
|
||||
// XrefsDBManager::search and return SymbolInfos instead of header paths.
|
||||
// SymbolIndexManager::search and return SymbolInfos instead of header paths.
|
||||
std::vector<std::string> search(llvm::StringRef Identifier) const;
|
||||
|
||||
private:
|
||||
std::vector<std::unique_ptr<XrefsDB>> XrefsDBs;
|
||||
std::vector<std::unique_ptr<SymbolIndex>> SymbolIndices;
|
||||
};
|
||||
|
||||
} // namespace include_fixer
|
|
@ -1,4 +1,4 @@
|
|||
//===-- YamlXrefsDB.cpp ---------------------------------------------------===//
|
||||
//===-- YamlSymbolIndex.cpp -----------------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
|
@ -7,7 +7,7 @@
|
|||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "YamlXrefsDB.h"
|
||||
#include "YamlSymbolIndex.h"
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
#include "llvm/Support/Errc.h"
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
|
@ -21,20 +21,20 @@ using clang::find_all_symbols::SymbolInfo;
|
|||
namespace clang {
|
||||
namespace include_fixer {
|
||||
|
||||
llvm::ErrorOr<std::unique_ptr<YamlXrefsDB>>
|
||||
YamlXrefsDB::createFromFile(llvm::StringRef FilePath) {
|
||||
llvm::ErrorOr<std::unique_ptr<YamlSymbolIndex>>
|
||||
YamlSymbolIndex::createFromFile(llvm::StringRef FilePath) {
|
||||
auto Buffer = llvm::MemoryBuffer::getFile(FilePath);
|
||||
if (!Buffer)
|
||||
return Buffer.getError();
|
||||
|
||||
return std::unique_ptr<YamlXrefsDB>(
|
||||
new YamlXrefsDB(clang::find_all_symbols::ReadSymbolInfosFromYAML(
|
||||
return std::unique_ptr<YamlSymbolIndex>(
|
||||
new YamlSymbolIndex(clang::find_all_symbols::ReadSymbolInfosFromYAML(
|
||||
Buffer.get()->getBuffer())));
|
||||
}
|
||||
|
||||
llvm::ErrorOr<std::unique_ptr<YamlXrefsDB>>
|
||||
YamlXrefsDB::createFromDirectory(llvm::StringRef Directory,
|
||||
llvm::StringRef Name) {
|
||||
llvm::ErrorOr<std::unique_ptr<YamlSymbolIndex>>
|
||||
YamlSymbolIndex::createFromDirectory(llvm::StringRef Directory,
|
||||
llvm::StringRef Name) {
|
||||
// Walk upwards from Directory, looking for files.
|
||||
for (llvm::SmallString<128> PathStorage = Directory; !Directory.empty();
|
||||
Directory = llvm::sys::path::parent_path(Directory)) {
|
||||
|
@ -47,7 +47,7 @@ YamlXrefsDB::createFromDirectory(llvm::StringRef Directory,
|
|||
return llvm::make_error_code(llvm::errc::no_such_file_or_directory);
|
||||
}
|
||||
|
||||
std::vector<SymbolInfo> YamlXrefsDB::search(llvm::StringRef Identifier) {
|
||||
std::vector<SymbolInfo> YamlSymbolIndex::search(llvm::StringRef Identifier) {
|
||||
std::vector<SymbolInfo> Results;
|
||||
for (const auto &Symbol : Symbols) {
|
||||
if (Symbol.getName() == Identifier)
|
|
@ -1,4 +1,4 @@
|
|||
//===-- YamlXrefsDB.h -------------------------------------------*- C++ -*-===//
|
||||
//===-- YamlSymbolIndex.h ---------------------------------------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
|
@ -7,10 +7,10 @@
|
|||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_YAMLXREFSDB_H
|
||||
#define LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_YAMLXREFSDB_H
|
||||
#ifndef LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_YAMLSYMBOLINDEX_H
|
||||
#define LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_YAMLSYMBOLINDEX_H
|
||||
|
||||
#include "XrefsDB.h"
|
||||
#include "SymbolIndex.h"
|
||||
#include "find-all-symbols/SymbolInfo.h"
|
||||
#include "llvm/Support/ErrorOr.h"
|
||||
#include <map>
|
||||
|
@ -20,20 +20,21 @@ namespace clang {
|
|||
namespace include_fixer {
|
||||
|
||||
/// Yaml format database.
|
||||
class YamlXrefsDB : public XrefsDB {
|
||||
class YamlSymbolIndex : public SymbolIndex {
|
||||
public:
|
||||
/// Create a new Yaml db from a file.
|
||||
static llvm::ErrorOr<std::unique_ptr<YamlXrefsDB>>
|
||||
static llvm::ErrorOr<std::unique_ptr<YamlSymbolIndex>>
|
||||
createFromFile(llvm::StringRef FilePath);
|
||||
/// Look for a file called \c Name in \c Directory and all parent directories.
|
||||
static llvm::ErrorOr<std::unique_ptr<YamlXrefsDB>>
|
||||
static llvm::ErrorOr<std::unique_ptr<YamlSymbolIndex>>
|
||||
createFromDirectory(llvm::StringRef Directory, llvm::StringRef Name);
|
||||
|
||||
std::vector<clang::find_all_symbols::SymbolInfo>
|
||||
search(llvm::StringRef Identifier) override;
|
||||
|
||||
private:
|
||||
explicit YamlXrefsDB(std::vector<clang::find_all_symbols::SymbolInfo> Symbols)
|
||||
explicit YamlSymbolIndex(
|
||||
std::vector<clang::find_all_symbols::SymbolInfo> Symbols)
|
||||
: Symbols(std::move(Symbols)) {}
|
||||
|
||||
std::vector<clang::find_all_symbols::SymbolInfo> Symbols;
|
||||
|
@ -42,4 +43,4 @@ private:
|
|||
} // namespace include_fixer
|
||||
} // namespace clang
|
||||
|
||||
#endif // LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_YAMLXREFSDB_H
|
||||
#endif // LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_YAMLSYMBOLINDEX_H
|
|
@ -7,8 +7,8 @@
|
|||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_FIND_ALL_SYMBOLS_SYMBOL_INFO_H
|
||||
#define LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_FIND_ALL_SYMBOLS_SYMBOL_INFO_H
|
||||
#ifndef LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_FIND_ALL_SYMBOLS_SYMBOLINFO_H
|
||||
#define LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_FIND_ALL_SYMBOLS_SYMBOLINFO_H
|
||||
|
||||
#include "llvm/ADT/Optional.h"
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
|
@ -110,4 +110,4 @@ std::vector<SymbolInfo> ReadSymbolInfosFromYAML(llvm::StringRef Yaml);
|
|||
} // namespace find_all_symbols
|
||||
} // namespace clang
|
||||
|
||||
#endif // LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_FIND_ALL_SYMBOLS_SYMBOL_INFO_H
|
||||
#endif // LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_FIND_ALL_SYMBOLS_SYMBOLINFO_H
|
||||
|
|
|
@ -7,10 +7,10 @@
|
|||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "InMemoryXrefsDB.h"
|
||||
#include "InMemorySymbolIndex.h"
|
||||
#include "IncludeFixer.h"
|
||||
#include "XrefsDBManager.h"
|
||||
#include "YamlXrefsDB.h"
|
||||
#include "SymbolIndexManager.h"
|
||||
#include "YamlSymbolIndex.h"
|
||||
#include "clang/Frontend/TextDiagnosticPrinter.h"
|
||||
#include "clang/Rewrite/Core/Rewriter.h"
|
||||
#include "clang/Tooling/CommonOptionsParser.h"
|
||||
|
@ -53,13 +53,13 @@ int includeFixerMain(int argc, const char **argv) {
|
|||
options.getSourcePathList());
|
||||
|
||||
// Set up data source.
|
||||
auto XrefsDBMgr = llvm::make_unique<include_fixer::XrefsDBManager>();
|
||||
auto SymbolIndexMgr = llvm::make_unique<include_fixer::SymbolIndexManager>();
|
||||
switch (DatabaseFormat) {
|
||||
case fixed: {
|
||||
// Parse input and fill the database with it.
|
||||
// <symbol>=<header><, header...>
|
||||
// Multiple symbols can be given, separated by semicolons.
|
||||
std::map<std::string, std::vector<std::string>> XrefsMap;
|
||||
std::map<std::string, std::vector<std::string>> SymbolsMap;
|
||||
SmallVector<StringRef, 4> SemicolonSplits;
|
||||
StringRef(Input).split(SemicolonSplits, ";");
|
||||
for (StringRef Pair : SemicolonSplits) {
|
||||
|
@ -69,23 +69,24 @@ int includeFixerMain(int argc, const char **argv) {
|
|||
Split.second.split(CommaSplits, ",");
|
||||
for (StringRef Header : CommaSplits)
|
||||
Headers.push_back(Header.trim());
|
||||
XrefsMap[Split.first.trim()] = std::move(Headers);
|
||||
SymbolsMap[Split.first.trim()] = std::move(Headers);
|
||||
}
|
||||
XrefsDBMgr->addXrefsDB(
|
||||
llvm::make_unique<include_fixer::InMemoryXrefsDB>(std::move(XrefsMap)));
|
||||
SymbolIndexMgr->addSymbolIndex(
|
||||
llvm::make_unique<include_fixer::InMemorySymbolIndex>(
|
||||
std::move(SymbolsMap)));
|
||||
break;
|
||||
}
|
||||
case yaml: {
|
||||
llvm::ErrorOr<std::unique_ptr<include_fixer::YamlXrefsDB>> DB(nullptr);
|
||||
llvm::ErrorOr<std::unique_ptr<include_fixer::YamlSymbolIndex>> DB(nullptr);
|
||||
if (!Input.empty()) {
|
||||
DB = include_fixer::YamlXrefsDB::createFromFile(Input);
|
||||
DB = include_fixer::YamlSymbolIndex::createFromFile(Input);
|
||||
} else {
|
||||
// If we don't have any input file, look in the directory of the first
|
||||
// file and its parents.
|
||||
SmallString<128> AbsolutePath(
|
||||
tooling::getAbsolutePath(options.getSourcePathList().front()));
|
||||
StringRef Directory = llvm::sys::path::parent_path(AbsolutePath);
|
||||
DB = include_fixer::YamlXrefsDB::createFromDirectory(
|
||||
DB = include_fixer::YamlSymbolIndex::createFromDirectory(
|
||||
Directory, "find_all_symbols_db.yaml");
|
||||
}
|
||||
|
||||
|
@ -95,15 +96,15 @@ int includeFixerMain(int argc, const char **argv) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
XrefsDBMgr->addXrefsDB(std::move(*DB));
|
||||
SymbolIndexMgr->addSymbolIndex(std::move(*DB));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Now run our tool.
|
||||
std::vector<tooling::Replacement> Replacements;
|
||||
include_fixer::IncludeFixerActionFactory Factory(*XrefsDBMgr, Replacements,
|
||||
MinimizeIncludePaths);
|
||||
include_fixer::IncludeFixerActionFactory Factory(
|
||||
*SymbolIndexMgr, Replacements, MinimizeIncludePaths);
|
||||
|
||||
tool.run(&Factory); // Always succeeds.
|
||||
|
||||
|
|
|
@ -7,9 +7,9 @@
|
|||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "InMemoryXrefsDB.h"
|
||||
#include "InMemorySymbolIndex.h"
|
||||
#include "IncludeFixer.h"
|
||||
#include "XrefsDBManager.h"
|
||||
#include "SymbolIndexManager.h"
|
||||
#include "unittests/Tooling/RewriterTestContext.h"
|
||||
#include "clang/Tooling/Tooling.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
@ -47,18 +47,19 @@ static bool runOnCode(tooling::ToolAction *ToolAction, StringRef Code,
|
|||
static std::string runIncludeFixer(
|
||||
StringRef Code,
|
||||
const std::vector<std::string> &ExtraArgs = std::vector<std::string>()) {
|
||||
std::map<std::string, std::vector<std::string>> XrefsMap = {
|
||||
std::map<std::string, std::vector<std::string>> SymbolsMap = {
|
||||
{"std::string", {"<string>"}},
|
||||
{"std::sting", {"\"sting\""}},
|
||||
{"std::string::size_type", {"<string>"}},
|
||||
{"a::b::foo", {"dir/otherdir/qux.h"}},
|
||||
};
|
||||
auto XrefsDBMgr = llvm::make_unique<include_fixer::XrefsDBManager>();
|
||||
XrefsDBMgr->addXrefsDB(
|
||||
llvm::make_unique<include_fixer::InMemoryXrefsDB>(std::move(XrefsMap)));
|
||||
auto SymbolIndexMgr = llvm::make_unique<include_fixer::SymbolIndexManager>();
|
||||
SymbolIndexMgr->addSymbolIndex(
|
||||
llvm::make_unique<include_fixer::InMemorySymbolIndex>(
|
||||
std::move(SymbolsMap)));
|
||||
|
||||
std::vector<clang::tooling::Replacement> Replacements;
|
||||
IncludeFixerActionFactory Factory(*XrefsDBMgr, Replacements);
|
||||
IncludeFixerActionFactory Factory(*SymbolIndexMgr, Replacements);
|
||||
runOnCode(&Factory, Code, "input.cc", ExtraArgs);
|
||||
clang::RewriterTestContext Context;
|
||||
clang::FileID ID = Context.createInMemoryFile("input.cc", Code);
|
||||
|
@ -84,7 +85,8 @@ TEST(IncludeFixer, Typo) {
|
|||
runIncludeFixer("#include \"foo.h\"\nstd::string::size_type foo;\n"));
|
||||
|
||||
// string without "std::" can also be fixed since fixed db results go through
|
||||
// XrefsDBManager, and XrefsDBManager matches unqualified identifiers too.
|
||||
// SymbolIndexManager, and SymbolIndexManager matches unqualified identifiers
|
||||
// too.
|
||||
EXPECT_EQ("#include <string>\nstring foo;\n",
|
||||
runIncludeFixer("string foo;\n"));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue