-
Notifications
You must be signed in to change notification settings - Fork 10.8k
/
IncludeFixer.h
85 lines (70 loc) · 3.08 KB
/
IncludeFixer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//===-- IncludeFixer.h - Include inserter -----------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_INCLUDEFIXER_H
#define LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_INCLUDEFIXER_H
#include "IncludeFixerContext.h"
#include "SymbolIndexManager.h"
#include "clang/Format/Format.h"
#include "clang/Tooling/Core/Replacement.h"
#include "clang/Tooling/Tooling.h"
#include <memory>
#include <vector>
namespace clang {
class CompilerInvocation;
class DiagnosticConsumer;
class FileManager;
class PCHContainerOperations;
namespace include_fixer {
class IncludeFixerActionFactory : public clang::tooling::ToolAction {
public:
/// \param SymbolIndexMgr A source for matching symbols to header files.
/// \param Context A context for the symbol being queried.
/// \param StyleName Fallback style for reformatting.
/// \param MinimizeIncludePaths whether inserted include paths are optimized.
IncludeFixerActionFactory(SymbolIndexManager &SymbolIndexMgr,
IncludeFixerContext &Context, StringRef StyleName,
bool MinimizeIncludePaths = true);
~IncludeFixerActionFactory() override;
bool
runInvocation(clang::CompilerInvocation *Invocation,
clang::FileManager *Files,
std::shared_ptr<clang::PCHContainerOperations> PCHContainerOps,
clang::DiagnosticConsumer *Diagnostics) override;
private:
/// The client to use to find cross-references.
SymbolIndexManager &SymbolIndexMgr;
/// The context that contains all information about the symbol being queried.
IncludeFixerContext &Context;
/// Whether inserted include paths should be optimized.
bool MinimizeIncludePaths;
/// The fallback format style for formatting after insertion if no
/// clang-format config file was found.
std::string FallbackStyle;
};
/// Create replacements for the header being inserted. The replacements will
/// insert a header before the first #include in \p Code, and sort all headers
/// with the given clang-format style.
///
/// \param Code The source code.
/// \param FilePath The source file path.
/// \param Header The header being inserted.
/// \param FirstIncludeOffset The insertion point for new include directives.
/// The default value -1U means inserting the header at the first line, and if
/// there is no #include block, it will create a header block by inserting a
/// newline.
/// \param Style clang-format style being used.
///
/// \return Replacements for inserting and sorting headers.
std::vector<clang::tooling::Replacement> createInsertHeaderReplacements(
StringRef Code, StringRef FilePath, StringRef Header,
unsigned FirstIncludeOffset = -1U,
const clang::format::FormatStyle &Style = clang::format::getLLVMStyle());
} // namespace include_fixer
} // namespace clang
#endif // LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_INCLUDEFIXER_H