10 #include "../IncludeFixer.h" 11 #include "../YamlSymbolIndex.h" 12 #include "clang/Frontend/CompilerInstance.h" 13 #include "clang/Frontend/FrontendPluginRegistry.h" 14 #include "clang/Parse/ParseAST.h" 15 #include "clang/Sema/Sema.h" 16 #include "llvm/Support/Path.h" 19 namespace include_fixer {
27 struct ASTConsumerManagerWrapper :
public ASTConsumer {
28 ASTConsumerManagerWrapper(std::shared_ptr<SymbolIndexManager> SIM)
29 : SymbolIndexMgr(std::move(SIM)) {}
30 std::shared_ptr<SymbolIndexManager> SymbolIndexMgr;
40 std::unique_ptr<clang::ASTConsumer>
42 CI.setExternalSemaSource(SemaSource);
43 SemaSource->setFilePath(InFile);
44 SemaSource->setCompilerInstance(&CI);
45 return llvm::make_unique<ASTConsumerManagerWrapper>(SymbolIndexMgr);
51 const std::vector<std::string> &Args)
override {
52 StringRef DB =
"yaml";
57 for (StringRef Arg : Args) {
58 if (Arg.startswith(
"-db="))
59 DB = Arg.substr(strlen(
"-db="));
60 else if (Arg.startswith(
"-input="))
61 Input = Arg.substr(strlen(
"-input="));
64 std::string InputFile = CI.getFrontendOpts().Inputs[0].getFile();
65 auto CreateYamlIdx = [=]() -> std::unique_ptr<include_fixer::SymbolIndex> {
66 llvm::ErrorOr<std::unique_ptr<include_fixer::YamlSymbolIndex>> SymbolIdx(
74 SmallString<128> AbsolutePath(tooling::getAbsolutePath(InputFile));
75 StringRef
Directory = llvm::sys::path::parent_path(AbsolutePath);
77 Directory,
"find_all_symbols_db.yaml");
80 return std::move(*SymbolIdx);
83 SymbolIndexMgr->addSymbolIndex(std::move(CreateYamlIdx));
88 std::shared_ptr<SymbolIndexManager> SymbolIndexMgr;
89 IntrusiveRefCntPtr<IncludeFixerSemaSource> SemaSource;
98 static clang::FrontendPluginRegistry::Add<
100 X(
"clang-include-fixer",
"clang-include-fixer");
void ExecuteAction() override
Handles callbacks from sema, does the include lookup and turns it into an IncludeFixerContext.
ClangIncludeFixerPluginAction()
static cl::opt< std::string > Directory(cl::Positional, cl::Required, cl::desc("<Search Root Directory>"))
static llvm::ErrorOr< std::unique_ptr< YamlSymbolIndex > > createFromDirectory(llvm::StringRef Directory, llvm::StringRef Name)
Look for a file called Name in Directory and all parent directories.
The core include fixer plugin action.
This class provides an interface for finding the header files corresponding to an identifier in the s...
std::unique_ptr< clang::ASTConsumer > CreateASTConsumer(clang::CompilerInstance &CI, StringRef InFile) override
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
static llvm::ErrorOr< std::unique_ptr< YamlSymbolIndex > > createFromFile(llvm::StringRef FilePath)
Create a new Yaml db from a file.
static clang::FrontendPluginRegistry::Add< clang::include_fixer::ClangIncludeFixerPluginAction > X("clang-include-fixer", "clang-include-fixer")
volatile int ClangIncludeFixerPluginAnchorSource
bool ParseArgs(const CompilerInstance &CI, const std::vector< std::string > &Args) override