| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
#ifndef LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_INCLUDEFIXER_H |
| 10 |
#define LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_INCLUDEFIXER_H |
| 11 |
|
| 12 |
#include "IncludeFixerContext.h" |
| 13 |
#include "SymbolIndexManager.h" |
| 14 |
#include "clang/Format/Format.h" |
| 15 |
#include "clang/Sema/ExternalSemaSource.h" |
| 16 |
#include "clang/Tooling/Core/Replacement.h" |
| 17 |
#include "clang/Tooling/Tooling.h" |
| 18 |
#include <memory> |
| 19 |
#include <vector> |
| 20 |
|
| 21 |
namespace clang { |
| 22 |
|
| 23 |
class CompilerInvocation; |
| 24 |
class DiagnosticConsumer; |
| 25 |
class FileManager; |
| 26 |
class PCHContainerOperations; |
| 27 |
|
| 28 |
namespace include_fixer { |
| 29 |
|
| 30 |
class IncludeFixerActionFactory : public clang::tooling::ToolAction { |
| 31 |
public: |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
IncludeFixerActionFactory(SymbolIndexManager &SymbolIndexMgr, |
| 37 |
std::vector<IncludeFixerContext> &Contexts, |
| 38 |
StringRef StyleName, |
| 39 |
bool MinimizeIncludePaths = true); |
| 40 |
|
| 41 |
~IncludeFixerActionFactory() override; |
| 42 |
|
| 43 |
bool |
| 44 |
runInvocation(std::shared_ptr<clang::CompilerInvocation> Invocation, |
| 45 |
clang::FileManager *Files, |
| 46 |
std::shared_ptr<clang::PCHContainerOperations> PCHContainerOps, |
| 47 |
clang::DiagnosticConsumer *Diagnostics) override; |
| 48 |
|
| 49 |
private: |
| 50 |
|
| 51 |
SymbolIndexManager &SymbolIndexMgr; |
| 52 |
|
| 53 |
|
| 54 |
std::vector<IncludeFixerContext> &Contexts; |
| 55 |
|
| 56 |
|
| 57 |
bool MinimizeIncludePaths; |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
std::string FallbackStyle; |
| 62 |
}; |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
llvm::Expected<tooling::Replacements> createIncludeFixerReplacements( |
| 79 |
StringRef Code, const IncludeFixerContext &Context, |
| 80 |
const format::FormatStyle &Style = format::getLLVMStyle(), |
| 81 |
bool AddQualifiers = true); |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
class IncludeFixerSemaSource : public clang::ExternalSemaSource { |
| 86 |
public: |
| 87 |
explicit IncludeFixerSemaSource(SymbolIndexManager &SymbolIndexMgr, |
| 88 |
bool MinimizeIncludePaths, |
| 89 |
bool GenerateDiagnostics) |
| 90 |
: SymbolIndexMgr(SymbolIndexMgr), |
| 91 |
MinimizeIncludePaths(MinimizeIncludePaths), |
| 92 |
GenerateDiagnostics(GenerateDiagnostics) {} |
| 93 |
|
| 94 |
void setCompilerInstance(CompilerInstance *CI) { this->CI = CI; } |
| 95 |
void setFilePath(StringRef FilePath) { |
| 96 |
this->FilePath = std::string(FilePath); |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
bool MaybeDiagnoseMissingCompleteType(clang::SourceLocation Loc, |
| 102 |
clang::QualType T) override; |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
clang::TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo, |
| 107 |
int LookupKind, Scope *S, CXXScopeSpec *SS, |
| 108 |
CorrectionCandidateCallback &CCC, |
| 109 |
DeclContext *MemberContext, |
| 110 |
bool EnteringContext, |
| 111 |
const ObjCObjectPointerType *OPT) override; |
| 112 |
|
| 113 |
|
| 114 |
std::string minimizeInclude(StringRef Include, |
| 115 |
const clang::SourceManager &SourceManager, |
| 116 |
clang::HeaderSearch &HeaderSearch) const; |
| 117 |
|
| 118 |
|
| 119 |
IncludeFixerContext getIncludeFixerContext( |
| 120 |
const clang::SourceManager &SourceManager, |
| 121 |
clang::HeaderSearch &HeaderSearch, |
| 122 |
ArrayRef<find_all_symbols::SymbolInfo> MatchedSymbols) const; |
| 123 |
|
| 124 |
|
| 125 |
ArrayRef<find_all_symbols::SymbolInfo> getMatchedSymbols() const { |
| 126 |
return MatchedSymbols; |
| 127 |
} |
| 128 |
|
| 129 |
private: |
| 130 |
|
| 131 |
std::vector<find_all_symbols::SymbolInfo> |
| 132 |
query(StringRef Query, StringRef ScopedQualifiers, tooling::Range Range); |
| 133 |
|
| 134 |
CompilerInstance *CI; |
| 135 |
|
| 136 |
|
| 137 |
SymbolIndexManager &SymbolIndexMgr; |
| 138 |
|
| 139 |
|
| 140 |
std::vector<IncludeFixerContext::QuerySymbolInfo> QuerySymbolInfos; |
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
std::vector<find_all_symbols::SymbolInfo> MatchedSymbols; |
| 146 |
|
| 147 |
|
| 148 |
std::string FilePath; |
| 149 |
|
| 150 |
|
| 151 |
bool MinimizeIncludePaths = true; |
| 152 |
|
| 153 |
|
| 154 |
bool GenerateDiagnostics = false; |
| 155 |
}; |
| 156 |
} |
| 157 |
} |
| 158 |
|
| 159 |
#endif |