2016-04-20 20:43:43 +08:00
|
|
|
//===-- 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
|
|
|
|
|
2016-05-31 17:31:51 +08:00
|
|
|
#include "IncludeFixerContext.h"
|
2016-05-13 17:27:54 +08:00
|
|
|
#include "SymbolIndexManager.h"
|
2016-05-31 17:31:51 +08:00
|
|
|
#include "clang/Format/Format.h"
|
2016-04-20 20:43:43 +08:00
|
|
|
#include "clang/Tooling/Core/Replacement.h"
|
|
|
|
#include "clang/Tooling/Tooling.h"
|
2016-05-03 01:49:00 +08:00
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
2016-04-20 20:43:43 +08:00
|
|
|
|
|
|
|
namespace clang {
|
2016-05-03 01:49:00 +08:00
|
|
|
|
|
|
|
class CompilerInvocation;
|
|
|
|
class DiagnosticConsumer;
|
|
|
|
class FileManager;
|
|
|
|
class PCHContainerOperations;
|
|
|
|
|
2016-04-20 20:43:43 +08:00
|
|
|
namespace include_fixer {
|
|
|
|
|
|
|
|
class IncludeFixerActionFactory : public clang::tooling::ToolAction {
|
|
|
|
public:
|
2016-05-13 17:27:54 +08:00
|
|
|
/// \param SymbolIndexMgr A source for matching symbols to header files.
|
2016-05-31 17:31:51 +08:00
|
|
|
/// \param Context A context for the symbol being queried.
|
2016-05-19 16:21:09 +08:00
|
|
|
/// \param StyleName Fallback style for reformatting.
|
2016-04-28 19:21:29 +08:00
|
|
|
/// \param MinimizeIncludePaths whether inserted include paths are optimized.
|
2016-05-31 17:31:51 +08:00
|
|
|
IncludeFixerActionFactory(SymbolIndexManager &SymbolIndexMgr,
|
|
|
|
IncludeFixerContext &Context, StringRef StyleName,
|
|
|
|
bool MinimizeIncludePaths = true);
|
2016-05-19 16:21:09 +08:00
|
|
|
|
2016-05-03 01:49:00 +08:00
|
|
|
~IncludeFixerActionFactory() override;
|
2016-04-20 20:43:43 +08:00
|
|
|
|
|
|
|
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.
|
2016-05-13 17:27:54 +08:00
|
|
|
SymbolIndexManager &SymbolIndexMgr;
|
2016-04-20 20:43:43 +08:00
|
|
|
|
2016-05-31 17:31:51 +08:00
|
|
|
/// The context that contains all information about the symbol being queried.
|
|
|
|
IncludeFixerContext &Context;
|
2016-04-28 19:21:29 +08:00
|
|
|
|
|
|
|
/// Whether inserted include paths should be optimized.
|
|
|
|
bool MinimizeIncludePaths;
|
2016-05-19 16:21:09 +08:00
|
|
|
|
|
|
|
/// The fallback format style for formatting after insertion if no
|
|
|
|
/// clang-format config file was found.
|
|
|
|
std::string FallbackStyle;
|
2016-04-20 20:43:43 +08:00
|
|
|
};
|
|
|
|
|
2016-05-31 22:48:45 +08:00
|
|
|
/// Create replacements, which are generated by clang-format, for the header
|
|
|
|
/// insertion.
|
2016-05-31 17:31:51 +08:00
|
|
|
///
|
|
|
|
/// \param Code The source code.
|
|
|
|
/// \param FilePath The source file path.
|
|
|
|
/// \param Header The header being inserted.
|
|
|
|
/// \param Style clang-format style being used.
|
|
|
|
///
|
|
|
|
/// \return Replacements for inserting and sorting headers.
|
2016-05-31 21:52:59 +08:00
|
|
|
tooling::Replacements createInsertHeaderReplacements(
|
2016-05-31 17:31:51 +08:00
|
|
|
StringRef Code, StringRef FilePath, StringRef Header,
|
|
|
|
const clang::format::FormatStyle &Style = clang::format::getLLVMStyle());
|
|
|
|
|
2016-04-20 20:43:43 +08:00
|
|
|
} // namespace include_fixer
|
|
|
|
} // namespace clang
|
|
|
|
|
|
|
|
#endif // LLVM_CLANG_TOOLS_EXTRA_INCLUDE_FIXER_INCLUDEFIXER_H
|