9#include "../IncludeFixer.h"
10#include "../YamlSymbolIndex.h"
11#include "clang/Frontend/CompilerInstance.h"
12#include "clang/Frontend/FrontendPluginRegistry.h"
13#include "clang/Parse/ParseAST.h"
14#include "clang/Sema/Sema.h"
15#include "llvm/Support/Path.h"
18namespace include_fixer {
26 struct ASTConsumerManagerWrapper :
public ASTConsumer {
27 ASTConsumerManagerWrapper(std::shared_ptr<SymbolIndexManager> SIM)
28 : SymbolIndexMgr(std::move(SIM)) {}
29 std::shared_ptr<SymbolIndexManager> SymbolIndexMgr;
39 std::unique_ptr<clang::ASTConsumer>
41 CI.setExternalSemaSource(SemaSource);
42 SemaSource->setFilePath(InFile);
43 SemaSource->setCompilerInstance(&
CI);
44 return std::make_unique<ASTConsumerManagerWrapper>(SymbolIndexMgr);
50 const std::vector<std::string> &
Args)
override {
51 StringRef DB =
"yaml";
56 for (StringRef Arg :
Args) {
57 if (Arg.starts_with(
"-db="))
58 DB = Arg.substr(strlen(
"-db="));
59 else if (Arg.starts_with(
"-input="))
60 Input = Arg.substr(strlen(
"-input="));
63 std::string InputFile =
64 std::string(
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);
80 return std::move(*SymbolIdx);
83 SymbolIndexMgr->addSymbolIndex(std::move(CreateYamlIdx));
88 std::shared_ptr<SymbolIndexManager> SymbolIndexMgr;
89 IntrusiveRefCntPtr<IncludeFixerSemaSource> SemaSource;
98static clang::FrontendPluginRegistry::Add<
100 X(
"clang-include-fixer",
"clang-include-fixer");
volatile int ClangIncludeFixerPluginAnchorSource
llvm::StringRef Directory
std::unique_ptr< CompilerInvocation > CI
The core include fixer plugin action.
void ExecuteAction() override
bool ParseArgs(const CompilerInstance &CI, const std::vector< std::string > &Args) override
ClangIncludeFixerPluginAction()
std::unique_ptr< clang::ASTConsumer > CreateASTConsumer(clang::CompilerInstance &CI, StringRef InFile) override
Handles callbacks from sema, does the include lookup and turns it into an IncludeFixerContext.
This class provides an interface for finding the header files corresponding to an identifier in the s...
static llvm::ErrorOr< std::unique_ptr< YamlSymbolIndex > > createFromFile(llvm::StringRef FilePath)
Create a new Yaml db from a file.
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.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//